From 8887a47dedf51e9b262fea43bd86ab442daad99e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Mon, 6 Sep 2010 19:01:50 +0000 Subject: [PATCH] Upgraded FFmpeg to the release version 0.6 (only some minor compile fixes to the code with regards to using the wrong #include scope in one file and disabling two apparently unmaintained asserts when compiling in DEBUG mode). I didn't yet test the GCC 2 build, but I need to get this into SVN since I am having some annoying file corruption troubles. In fact I am hoping I am not commiting broken files, but a few seconds ago everything was still building cleanly. One thing that definitely improved is the (disabled at the moment) AVI support. Every clip I tested so far plays, which can't be said about our native AVI reader. With the previous FFmpeg version (a random SVN revision is my guess), many old AVIs played completely broken. So far, I have not spotted any regressions git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38548 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/media/plugins/ffmpeg/Jamfile | 3 + src/add-ons/media/plugins/ffmpeg/config.h | 112 +- .../media/plugins/ffmpeg/libavcodec/4xm.c | 12 +- .../media/plugins/ffmpeg/libavcodec/8bps.c | 8 +- .../media/plugins/ffmpeg/libavcodec/8svx.c | 6 +- .../media/plugins/ffmpeg/libavcodec/Jamfile | 70 +- .../media/plugins/ffmpeg/libavcodec/aac.c | 708 +- .../media/plugins/ffmpeg/libavcodec/aac.h | 34 +- .../ffmpeg/libavcodec/aac_ac3_parser.c | 34 +- .../ffmpeg/libavcodec/aac_adtstoasc_bsf.c | 2 +- .../plugins/ffmpeg/libavcodec/aaccoder.c | 306 +- .../plugins/ffmpeg/libavcodec/aacdectab.h | 25 +- .../media/plugins/ffmpeg/libavcodec/aacenc.c | 22 +- .../media/plugins/ffmpeg/libavcodec/aacenc.h | 10 +- .../media/plugins/ffmpeg/libavcodec/aacpsy.c | 2 +- .../media/plugins/ffmpeg/libavcodec/aacsbr.c | 1766 +++ .../media/plugins/ffmpeg/libavcodec/aacsbr.h | 49 + .../plugins/ffmpeg/libavcodec/aacsbrdata.h | 614 + .../media/plugins/ffmpeg/libavcodec/aactab.c | 189 +- .../media/plugins/ffmpeg/libavcodec/aactab.h | 12 +- .../plugins/ffmpeg/libavcodec/aandcttab.c | 2 +- .../plugins/ffmpeg/libavcodec/aandcttab.h | 2 +- .../media/plugins/ffmpeg/libavcodec/aasc.c | 4 +- .../media/plugins/ffmpeg/libavcodec/ac3.c | 185 +- .../media/plugins/ffmpeg/libavcodec/ac3.h | 2 +- .../media/plugins/ffmpeg/libavcodec/ac3dec.c | 194 +- .../media/plugins/ffmpeg/libavcodec/ac3dec.h | 69 +- .../plugins/ffmpeg/libavcodec/ac3dec_data.c | 8 +- .../plugins/ffmpeg/libavcodec/ac3dec_data.h | 1 + .../media/plugins/ffmpeg/libavcodec/ac3enc.c | 12 +- .../media/plugins/ffmpeg/libavcodec/ac3tab.c | 6 +- .../plugins/ffmpeg/libavcodec/acelp_filters.c | 41 +- .../plugins/ffmpeg/libavcodec/acelp_filters.h | 24 +- .../ffmpeg/libavcodec/acelp_pitch_delay.c | 65 + .../ffmpeg/libavcodec/acelp_pitch_delay.h | 32 + .../plugins/ffmpeg/libavcodec/acelp_vectors.c | 113 + .../plugins/ffmpeg/libavcodec/acelp_vectors.h | 133 +- .../media/plugins/ffmpeg/libavcodec/adpcm.c | 22 +- .../media/plugins/ffmpeg/libavcodec/adx.h | 2 +- .../media/plugins/ffmpeg/libavcodec/adxdec.c | 4 +- .../media/plugins/ffmpeg/libavcodec/adxenc.c | 6 +- .../media/plugins/ffmpeg/libavcodec/alac.c | 130 +- .../media/plugins/ffmpeg/libavcodec/alacenc.c | 38 +- .../plugins/ffmpeg/libavcodec/allcodecs.c | 33 +- .../media/plugins/ffmpeg/libavcodec/alsdec.c | 1636 +++ .../plugins/ffmpeg/libavcodec/amrnbdata.h | 1672 +++ .../plugins/ffmpeg/libavcodec/amrnbdec.c | 1076 ++ .../media/plugins/ffmpeg/libavcodec/anm.c | 197 + .../media/plugins/ffmpeg/libavcodec/apedec.c | 116 +- .../plugins/ffmpeg/libavcodec/api-example.c | 51 +- .../media/plugins/ffmpeg/libavcodec/asv1.c | 43 +- .../media/plugins/ffmpeg/libavcodec/atrac.c | 120 + .../media/plugins/ffmpeg/libavcodec/atrac.h | 38 + .../media/plugins/ffmpeg/libavcodec/atrac1.c | 377 + .../plugins/ffmpeg/libavcodec/atrac1data.h | 64 + .../media/plugins/ffmpeg/libavcodec/atrac3.c | 91 +- .../plugins/ffmpeg/libavcodec/atrac3data.h | 13 +- .../plugins/ffmpeg/libavcodec/audioconvert.c | 19 +- .../plugins/ffmpeg/libavcodec/audioconvert.h | 6 +- .../media/plugins/ffmpeg/libavcodec/aura.c | 138 + .../media/plugins/ffmpeg/libavcodec/avcodec.h | 289 +- .../media/plugins/ffmpeg/libavcodec/avfft.c | 142 + .../media/plugins/ffmpeg/libavcodec/avfft.h | 99 + .../plugins/ffmpeg/libavcodec/avpacket.c | 16 +- .../media/plugins/ffmpeg/libavcodec/avs.c | 2 +- .../plugins/ffmpeg/libavcodec/beosthread.c | 5 +- .../plugins/ffmpeg/libavcodec/bethsoftvideo.c | 4 +- .../media/plugins/ffmpeg/libavcodec/bfi.c | 4 +- .../media/plugins/ffmpeg/libavcodec/bgmc.c | 567 + .../media/plugins/ffmpeg/libavcodec/bgmc.h | 56 + .../media/plugins/ffmpeg/libavcodec/bink.c | 1012 ++ .../plugins/ffmpeg/libavcodec/binkaudio.c | 311 + .../plugins/ffmpeg/libavcodec/binkdata.h | 614 + .../plugins/ffmpeg/libavcodec/binkidct.c | 112 + .../plugins/ffmpeg/libavcodec/bitstream.c | 248 +- .../media/plugins/ffmpeg/libavcodec/bmp.c | 27 +- .../media/plugins/ffmpeg/libavcodec/bmpenc.c | 4 +- .../media/plugins/ffmpeg/libavcodec/c93.c | 2 +- .../media/plugins/ffmpeg/libavcodec/cabac.c | 2 +- .../media/plugins/ffmpeg/libavcodec/cabac.h | 2 +- .../media/plugins/ffmpeg/libavcodec/cavs.c | 12 +- .../media/plugins/ffmpeg/libavcodec/cavs.h | 12 +- .../plugins/ffmpeg/libavcodec/cavs_parser.c | 2 +- .../media/plugins/ffmpeg/libavcodec/cavsdec.c | 13 +- .../media/plugins/ffmpeg/libavcodec/cavsdsp.c | 7 +- .../plugins/ffmpeg/libavcodec/cbrt_tablegen.c | 39 + .../plugins/ffmpeg/libavcodec/cbrt_tablegen.h | 51 + .../plugins/ffmpeg/libavcodec/cdgraphics.c | 381 + .../plugins/ffmpeg/libavcodec/celp_filters.c | 145 +- .../plugins/ffmpeg/libavcodec/celp_filters.h | 30 +- .../media/plugins/ffmpeg/libavcodec/cinepak.c | 4 +- .../media/plugins/ffmpeg/libavcodec/cljr.c | 6 +- .../plugins/ffmpeg/libavcodec/colorspace.h | 2 +- .../media/plugins/ffmpeg/libavcodec/cook.c | 11 +- .../plugins/ffmpeg/libavcodec/cookdata.h | 2 +- .../plugins/ffmpeg/libavcodec/costablegen.c | 56 + .../media/plugins/ffmpeg/libavcodec/cscd.c | 5 +- .../media/plugins/ffmpeg/libavcodec/cyuv.c | 50 +- .../media/plugins/ffmpeg/libavcodec/dca.c | 170 +- .../plugins/ffmpeg/libavcodec/dca_parser.c | 4 - .../media/plugins/ffmpeg/libavcodec/dcadata.h | 1232 +- .../media/plugins/ffmpeg/libavcodec/dcadsp.c | 51 + .../media/plugins/ffmpeg/libavcodec/dcadsp.h | 30 + .../plugins/ffmpeg/libavcodec/dct-test.c | 32 +- .../media/plugins/ffmpeg/libavcodec/dct.c | 210 + .../media/plugins/ffmpeg/libavcodec/dctref.c | 4 +- .../media/plugins/ffmpeg/libavcodec/dctref.h | 31 + .../media/plugins/ffmpeg/libavcodec/dirac.c | 284 + .../media/plugins/ffmpeg/libavcodec/dirac.h | 57 + .../plugins/ffmpeg/libavcodec/dirac_parser.c | 2 +- .../plugins/ffmpeg/libavcodec/dnxhd_parser.c | 2 +- .../plugins/ffmpeg/libavcodec/dnxhddec.c | 24 +- .../plugins/ffmpeg/libavcodec/dnxhdenc.c | 274 +- .../plugins/ffmpeg/libavcodec/dnxhdenc.h | 3 +- .../media/plugins/ffmpeg/libavcodec/dpcm.c | 2 +- .../media/plugins/ffmpeg/libavcodec/dpx.c | 3 +- .../plugins/ffmpeg/libavcodec/dsicinav.c | 6 +- .../media/plugins/ffmpeg/libavcodec/dsputil.c | 784 +- .../media/plugins/ffmpeg/libavcodec/dsputil.h | 342 +- .../media/plugins/ffmpeg/libavcodec/dv.c | 121 +- .../plugins/ffmpeg/libavcodec/dv_tablegen.c | 47 + .../plugins/ffmpeg/libavcodec/dv_tablegen.h | 96 + .../plugins/ffmpeg/libavcodec/dv_vlc_data.h | 259 + .../media/plugins/ffmpeg/libavcodec/dvbsub.c | 2 +- .../plugins/ffmpeg/libavcodec/dvbsubdec.c | 2 +- .../media/plugins/ffmpeg/libavcodec/dvdata.c | 285 + .../media/plugins/ffmpeg/libavcodec/dvdata.h | 467 +- .../plugins/ffmpeg/libavcodec/dvdsubdec.c | 2 +- .../plugins/ffmpeg/libavcodec/dvdsubenc.c | 2 +- .../media/plugins/ffmpeg/libavcodec/dwt.c | 843 ++ .../media/plugins/ffmpeg/libavcodec/dwt.h | 156 + .../media/plugins/ffmpeg/libavcodec/dxa.c | 8 +- .../media/plugins/ffmpeg/libavcodec/dxva2.c | 154 + .../media/plugins/ffmpeg/libavcodec/dxva2.h | 68 + .../plugins/ffmpeg/libavcodec/dxva2_h264.c | 437 + .../ffmpeg/libavcodec/dxva2_internal.h | 48 + .../plugins/ffmpeg/libavcodec/dxva2_vc1.c | 291 + .../media/plugins/ffmpeg/libavcodec/eac3dec.c | 105 +- .../plugins/ffmpeg/libavcodec/eac3dec_data.c | 41 +- .../plugins/ffmpeg/libavcodec/eac3dec_data.h | 1 + .../media/plugins/ffmpeg/libavcodec/eacmv.c | 6 +- .../media/plugins/ffmpeg/libavcodec/eaidct.c | 2 +- .../media/plugins/ffmpeg/libavcodec/eamad.c | 6 +- .../media/plugins/ffmpeg/libavcodec/eatgq.c | 6 +- .../media/plugins/ffmpeg/libavcodec/eatgv.c | 14 +- .../media/plugins/ffmpeg/libavcodec/eatqi.c | 6 +- .../media/plugins/ffmpeg/libavcodec/elbg.c | 15 +- .../ffmpeg/libavcodec/error_resilience.c | 151 +- .../plugins/ffmpeg/libavcodec/escape124.c | 2 +- .../media/plugins/ffmpeg/libavcodec/eval.c | 119 +- .../media/plugins/ffmpeg/libavcodec/eval.h | 40 +- .../media/plugins/ffmpeg/libavcodec/faandct.c | 2 +- .../media/plugins/ffmpeg/libavcodec/faandct.h | 2 +- .../plugins/ffmpeg/libavcodec/faxcompr.c | 15 +- .../plugins/ffmpeg/libavcodec/faxcompr.h | 7 +- .../plugins/ffmpeg/libavcodec/fft-test.c | 198 +- .../media/plugins/ffmpeg/libavcodec/fft.c | 100 +- .../media/plugins/ffmpeg/libavcodec/fft.h | 240 + .../media/plugins/ffmpeg/libavcodec/ffv1.c | 75 +- .../media/plugins/ffmpeg/libavcodec/flac.h | 2 +- .../media/plugins/ffmpeg/libavcodec/flacdec.c | 16 +- .../media/plugins/ffmpeg/libavcodec/flacenc.c | 69 +- .../media/plugins/ffmpeg/libavcodec/flashsv.c | 24 +- .../plugins/ffmpeg/libavcodec/flashsvenc.c | 10 +- .../plugins/ffmpeg/libavcodec/flicvideo.c | 4 +- .../media/plugins/ffmpeg/libavcodec/flv.h | 34 + .../media/plugins/ffmpeg/libavcodec/flvdec.c | 132 + .../media/plugins/ffmpeg/libavcodec/flvenc.c | 97 + .../media/plugins/ffmpeg/libavcodec/fraps.c | 4 +- .../media/plugins/ffmpeg/libavcodec/frwu.c | 123 + .../media/plugins/ffmpeg/libavcodec/g726.c | 6 +- .../media/plugins/ffmpeg/libavcodec/g729dec.c | 6 +- .../plugins/ffmpeg/libavcodec/get_bits.h | 68 +- .../media/plugins/ffmpeg/libavcodec/gif.c | 112 +- .../media/plugins/ffmpeg/libavcodec/gifdec.c | 2 +- .../media/plugins/ffmpeg/libavcodec/golomb.c | 2 +- .../media/plugins/ffmpeg/libavcodec/golomb.h | 10 +- .../media/plugins/ffmpeg/libavcodec/h261.c | 2 +- .../media/plugins/ffmpeg/libavcodec/h261.h | 2 +- .../plugins/ffmpeg/libavcodec/h261_parser.c | 2 +- .../plugins/ffmpeg/libavcodec/h261data.h | 2 +- .../media/plugins/ffmpeg/libavcodec/h261dec.c | 9 +- .../media/plugins/ffmpeg/libavcodec/h261enc.c | 7 +- .../media/plugins/ffmpeg/libavcodec/h263.c | 6083 +-------- .../media/plugins/ffmpeg/libavcodec/h263.h | 249 +- .../plugins/ffmpeg/libavcodec/h263_parser.c | 3 +- .../plugins/ffmpeg/libavcodec/h263data.h | 81 +- .../media/plugins/ffmpeg/libavcodec/h263dec.c | 194 +- .../media/plugins/ffmpeg/libavcodec/h264.c | 6012 +-------- .../media/plugins/ffmpeg/libavcodec/h264.h | 940 +- .../plugins/ffmpeg/libavcodec/h264_cabac.c | 1720 +++ .../plugins/ffmpeg/libavcodec/h264_cavlc.c | 1030 ++ .../plugins/ffmpeg/libavcodec/h264_direct.c | 590 + .../ffmpeg/libavcodec/h264_loopfilter.c | 752 ++ .../ffmpeg/libavcodec/h264_mp4toannexb_bsf.c | 15 +- .../plugins/ffmpeg/libavcodec/h264_mvpred.h | 236 + .../plugins/ffmpeg/libavcodec/h264_parser.c | 17 +- .../plugins/ffmpeg/libavcodec/h264_parser.h | 2 +- .../media/plugins/ffmpeg/libavcodec/h264_ps.c | 537 + .../plugins/ffmpeg/libavcodec/h264_refs.c | 694 + .../plugins/ffmpeg/libavcodec/h264_sei.c | 206 + .../plugins/ffmpeg/libavcodec/h264data.h | 949 +- .../media/plugins/ffmpeg/libavcodec/h264dsp.c | 320 + .../media/plugins/ffmpeg/libavcodec/h264dsp.h | 80 + .../plugins/ffmpeg/libavcodec/h264dspenc.c | 4 +- .../media/plugins/ffmpeg/libavcodec/h264enc.c | 4 +- .../plugins/ffmpeg/libavcodec/h264idct.c | 2 +- .../plugins/ffmpeg/libavcodec/h264pred.c | 4 +- .../plugins/ffmpeg/libavcodec/h264pred.h | 3 +- .../media/plugins/ffmpeg/libavcodec/huffman.c | 2 +- .../media/plugins/ffmpeg/libavcodec/huffman.h | 2 +- .../media/plugins/ffmpeg/libavcodec/huffyuv.c | 126 +- .../plugins/ffmpeg/libavcodec/idcinvideo.c | 4 +- .../media/plugins/ffmpeg/libavcodec/iff.c | 290 + .../media/plugins/ffmpeg/libavcodec/iff.h | 30 + .../plugins/ffmpeg/libavcodec/iirfilter.c | 2 +- .../plugins/ffmpeg/libavcodec/iirfilter.h | 2 +- .../media/plugins/ffmpeg/libavcodec/imc.c | 10 +- .../plugins/ffmpeg/libavcodec/imgconvert.c | 470 +- .../ffmpeg/libavcodec/imx_dump_header_bsf.c | 2 +- .../media/plugins/ffmpeg/libavcodec/indeo2.c | 19 +- .../media/plugins/ffmpeg/libavcodec/indeo3.c | 2 +- .../media/plugins/ffmpeg/libavcodec/indeo5.c | 827 ++ .../plugins/ffmpeg/libavcodec/indeo5data.h | 185 + .../plugins/ffmpeg/libavcodec/intelh263dec.c | 131 + .../plugins/ffmpeg/libavcodec/internal.h | 8 +- .../ffmpeg/libavcodec/interplayvideo.c | 506 +- .../media/plugins/ffmpeg/libavcodec/intrax8.c | 33 +- .../plugins/ffmpeg/libavcodec/intrax8dsp.c | 4 +- .../plugins/ffmpeg/libavcodec/ituh263dec.c | 1131 ++ .../plugins/ffmpeg/libavcodec/ituh263enc.c | 842 ++ .../plugins/ffmpeg/libavcodec/ivi_common.c | 1000 ++ .../plugins/ffmpeg/libavcodec/ivi_common.h | 342 + .../media/plugins/ffmpeg/libavcodec/ivi_dsp.c | 467 + .../media/plugins/ffmpeg/libavcodec/ivi_dsp.h | 170 + .../plugins/ffmpeg/libavcodec/jfdctfst.c | 6 +- .../plugins/ffmpeg/libavcodec/jfdctint.c | 6 +- .../media/plugins/ffmpeg/libavcodec/jpegls.c | 2 +- .../media/plugins/ffmpeg/libavcodec/jpegls.h | 2 +- .../plugins/ffmpeg/libavcodec/jpeglsdec.c | 4 +- .../plugins/ffmpeg/libavcodec/jpeglsdec.h | 2 +- .../plugins/ffmpeg/libavcodec/jpeglsenc.c | 6 +- .../media/plugins/ffmpeg/libavcodec/jrevdct.c | 2 +- .../media/plugins/ffmpeg/libavcodec/kgv1dec.c | 176 + .../media/plugins/ffmpeg/libavcodec/kmvc.c | 4 +- .../media/plugins/ffmpeg/libavcodec/lcldec.c | 10 +- .../media/plugins/ffmpeg/libavcodec/lclenc.c | 4 +- .../plugins/ffmpeg/libavcodec/libdirac.h | 2 +- .../ffmpeg/libavcodec/libdirac_libschro.c | 2 +- .../ffmpeg/libavcodec/libdirac_libschro.h | 2 +- .../plugins/ffmpeg/libavcodec/libdiracdec.c | 4 +- .../plugins/ffmpeg/libavcodec/libdiracenc.c | 6 +- .../media/plugins/ffmpeg/libavcodec/libfaac.c | 6 +- .../media/plugins/ffmpeg/libavcodec/libfaad.c | 8 +- .../media/plugins/ffmpeg/libavcodec/libgsm.c | 16 +- .../plugins/ffmpeg/libavcodec/libmp3lame.c | 11 +- .../ffmpeg/libavcodec/libopencore-amr.c | 8 +- .../plugins/ffmpeg/libavcodec/libopenjpeg.c | 18 +- .../ffmpeg/libavcodec/libschroedinger.c | 2 +- .../ffmpeg/libavcodec/libschroedinger.h | 2 +- .../ffmpeg/libavcodec/libschroedingerdec.c | 4 +- .../ffmpeg/libavcodec/libschroedingerenc.c | 6 +- .../plugins/ffmpeg/libavcodec/libspeexdec.c | 21 +- .../plugins/ffmpeg/libavcodec/libtheoraenc.c | 357 +- .../plugins/ffmpeg/libavcodec/libvorbis.c | 6 +- .../plugins/ffmpeg/libavcodec/libvpxdec.c | 124 + .../plugins/ffmpeg/libavcodec/libvpxenc.c | 489 + .../media/plugins/ffmpeg/libavcodec/libx264.c | 262 +- .../ffmpeg/libavcodec/libxvid_internal.h | 2 +- .../plugins/ffmpeg/libavcodec/libxvidff.c | 22 +- .../plugins/ffmpeg/libavcodec/ljpegenc.c | 6 +- .../media/plugins/ffmpeg/libavcodec/loco.c | 16 +- .../media/plugins/ffmpeg/libavcodec/lpc.c | 64 +- .../media/plugins/ffmpeg/libavcodec/lpc.h | 3 + .../media/plugins/ffmpeg/libavcodec/lsp.c | 52 +- .../media/plugins/ffmpeg/libavcodec/lsp.h | 41 +- .../media/plugins/ffmpeg/libavcodec/lzw.c | 2 +- .../media/plugins/ffmpeg/libavcodec/lzw.h | 13 +- .../media/plugins/ffmpeg/libavcodec/lzwenc.c | 19 +- .../media/plugins/ffmpeg/libavcodec/mace.c | 6 +- .../media/plugins/ffmpeg/libavcodec/mathops.h | 30 + .../media/plugins/ffmpeg/libavcodec/mdct.c | 88 +- .../plugins/ffmpeg/libavcodec/mdct_tablegen.c | 49 + .../plugins/ffmpeg/libavcodec/mdct_tablegen.h | 60 + .../media/plugins/ffmpeg/libavcodec/mdec.c | 16 +- .../media/plugins/ffmpeg/libavcodec/mimic.c | 4 +- .../media/plugins/ffmpeg/libavcodec/mjpeg.c | 2 +- .../media/plugins/ffmpeg/libavcodec/mjpeg.h | 2 +- .../plugins/ffmpeg/libavcodec/mjpeg_parser.c | 2 +- .../libavcodec/mjpega_dump_header_bsf.c | 2 +- .../plugins/ffmpeg/libavcodec/mjpegbdec.c | 4 +- .../plugins/ffmpeg/libavcodec/mjpegdec.c | 53 +- .../plugins/ffmpeg/libavcodec/mjpegdec.h | 8 +- .../plugins/ffmpeg/libavcodec/mjpegenc.c | 13 +- .../plugins/ffmpeg/libavcodec/mjpegenc.h | 2 +- .../media/plugins/ffmpeg/libavcodec/mlp.c | 11 +- .../media/plugins/ffmpeg/libavcodec/mlp.h | 8 +- .../plugins/ffmpeg/libavcodec/mlp_parser.c | 8 +- .../plugins/ffmpeg/libavcodec/mlp_parser.h | 2 +- .../media/plugins/ffmpeg/libavcodec/mlpdec.c | 67 +- .../media/plugins/ffmpeg/libavcodec/mlpdsp.c | 2 - .../media/plugins/ffmpeg/libavcodec/mmvideo.c | 11 +- .../plugins/ffmpeg/libavcodec/motion-test.c | 2 +- .../plugins/ffmpeg/libavcodec/motion_est.c | 227 +- .../ffmpeg/libavcodec/motion_est_template.c | 6 +- .../plugins/ffmpeg/libavcodec/motionpixels.c | 59 +- .../ffmpeg/libavcodec/motionpixels_tablegen.c | 41 + .../ffmpeg/libavcodec/motionpixels_tablegen.h | 91 + .../media/plugins/ffmpeg/libavcodec/mpc.c | 9 +- .../media/plugins/ffmpeg/libavcodec/mpc.h | 7 +- .../media/plugins/ffmpeg/libavcodec/mpc7.c | 37 +- .../media/plugins/ffmpeg/libavcodec/mpc8.c | 9 +- .../media/plugins/ffmpeg/libavcodec/mpeg12.c | 269 +- .../plugins/ffmpeg/libavcodec/mpeg12data.c | 2 +- .../plugins/ffmpeg/libavcodec/mpeg12data.h | 2 +- .../plugins/ffmpeg/libavcodec/mpeg12decdata.h | 33 +- .../plugins/ffmpeg/libavcodec/mpeg12enc.c | 17 +- .../plugins/ffmpeg/libavcodec/mpeg4audio.c | 55 +- .../plugins/ffmpeg/libavcodec/mpeg4audio.h | 9 +- .../plugins/ffmpeg/libavcodec/mpeg4data.h | 90 +- .../plugins/ffmpeg/libavcodec/mpeg4video.c | 171 + .../plugins/ffmpeg/libavcodec/mpeg4video.h | 202 + .../ffmpeg/libavcodec/mpeg4video_parser.c | 3 +- .../plugins/ffmpeg/libavcodec/mpeg4videodec.c | 2267 ++++ .../plugins/ffmpeg/libavcodec/mpeg4videoenc.c | 1352 ++ .../plugins/ffmpeg/libavcodec/mpegaudio.c | 2 +- .../plugins/ffmpeg/libavcodec/mpegaudio.h | 30 +- .../plugins/ffmpeg/libavcodec/mpegaudio3.h | 53 + .../ffmpeg/libavcodec/mpegaudio_tablegen.c | 51 + .../ffmpeg/libavcodec/mpegaudio_tablegen.h | 67 + .../plugins/ffmpeg/libavcodec/mpegaudiodata.c | 2 +- .../plugins/ffmpeg/libavcodec/mpegaudiodata.h | 2 +- .../plugins/ffmpeg/libavcodec/mpegaudiodec.c | 141 +- .../ffmpeg/libavcodec/mpegaudiodecheader.c | 3 +- .../ffmpeg/libavcodec/mpegaudiodecheader.h | 2 +- .../ffmpeg/libavcodec/mpegaudiodectab.h | 2 +- .../plugins/ffmpeg/libavcodec/mpegaudioenc.c | 9 +- .../plugins/ffmpeg/libavcodec/mpegaudiotab.h | 2 +- .../plugins/ffmpeg/libavcodec/mpegvideo.c | 236 +- .../plugins/ffmpeg/libavcodec/mpegvideo.h | 72 +- .../ffmpeg/libavcodec/mpegvideo_common.h | 36 +- .../plugins/ffmpeg/libavcodec/mpegvideo_enc.c | 156 +- .../ffmpeg/libavcodec/mpegvideo_parser.c | 14 +- .../ffmpeg/libavcodec/mpegvideo_xvmc.c | 10 +- .../media/plugins/ffmpeg/libavcodec/msmpeg4.c | 849 +- .../media/plugins/ffmpeg/libavcodec/msmpeg4.h | 6 +- .../plugins/ffmpeg/libavcodec/msmpeg4data.c | 14 +- .../plugins/ffmpeg/libavcodec/msmpeg4data.h | 15 +- .../media/plugins/ffmpeg/libavcodec/msrle.c | 4 +- .../plugins/ffmpeg/libavcodec/msrledec.c | 9 +- .../plugins/ffmpeg/libavcodec/msvideo1.c | 4 +- .../plugins/ffmpeg/libavcodec/nellymoser.c | 2 +- .../plugins/ffmpeg/libavcodec/nellymoser.h | 2 +- .../plugins/ffmpeg/libavcodec/nellymoserdec.c | 15 +- .../plugins/ffmpeg/libavcodec/nellymoserenc.c | 15 +- .../media/plugins/ffmpeg/libavcodec/nuv.c | 4 +- .../media/plugins/ffmpeg/libavcodec/opt.c | 10 +- .../media/plugins/ffmpeg/libavcodec/opt.h | 54 +- .../media/plugins/ffmpeg/libavcodec/options.c | 98 +- .../plugins/ffmpeg/libavcodec/os2thread.c | 7 +- .../media/plugins/ffmpeg/libavcodec/pamenc.c | 120 + .../media/plugins/ffmpeg/libavcodec/parser.c | 4 +- .../plugins/ffmpeg/libavcodec/pcm-mpeg.c | 310 + .../media/plugins/ffmpeg/libavcodec/pcm.c | 99 +- .../plugins/ffmpeg/libavcodec/pcm_tablegen.c | 45 + .../plugins/ffmpeg/libavcodec/pcm_tablegen.h | 119 + .../media/plugins/ffmpeg/libavcodec/pcx.c | 39 +- .../media/plugins/ffmpeg/libavcodec/pcxenc.c | 6 +- .../plugins/ffmpeg/libavcodec/pgssubdec.c | 465 + .../media/plugins/ffmpeg/libavcodec/png.h | 2 + .../media/plugins/ffmpeg/libavcodec/pngdec.c | 20 +- .../media/plugins/ffmpeg/libavcodec/pngenc.c | 4 +- .../media/plugins/ffmpeg/libavcodec/pnm.c | 53 +- .../media/plugins/ffmpeg/libavcodec/pnm.h | 3 + .../plugins/ffmpeg/libavcodec/pnm_parser.c | 63 +- .../media/plugins/ffmpeg/libavcodec/pnmdec.c | 268 + .../media/plugins/ffmpeg/libavcodec/pnmenc.c | 440 +- .../ffmpeg/libavcodec/ppc/check_altivec.c | 7 +- .../ffmpeg/libavcodec/ppc/dsputil_altivec.c | 59 +- .../ffmpeg/libavcodec/ppc/dsputil_altivec.h | 22 +- .../ffmpeg/libavcodec/ppc/dsputil_ppc.c | 27 +- .../ffmpeg/libavcodec/ppc/fdct_altivec.c | 2 +- .../ffmpeg/libavcodec/ppc/fft_altivec.c | 12 +- .../ffmpeg/libavcodec/ppc/float_altivec.c | 94 +- .../ffmpeg/libavcodec/ppc/gmc_altivec.c | 10 +- .../ffmpeg/libavcodec/ppc/h264_altivec.c | 89 +- .../libavcodec/ppc/h264_template_altivec.c | 8 +- .../ffmpeg/libavcodec/ppc/idct_altivec.c | 7 +- .../ffmpeg/libavcodec/ppc/int_altivec.c | 70 +- .../plugins/ffmpeg/libavcodec/ppc/mathops.h | 2 + .../ffmpeg/libavcodec/ppc/mpegvideo_altivec.c | 33 +- .../ffmpeg/libavcodec/ppc/util_altivec.h | 2 +- .../ffmpeg/libavcodec/ppc/vc1dsp_altivec.c | 1 + .../ffmpeg/libavcodec/ppc/vp3dsp_altivec.c | 1 + .../plugins/ffmpeg/libavcodec/psymodel.c | 7 +- .../media/plugins/ffmpeg/libavcodec/pthread.c | 21 +- .../media/plugins/ffmpeg/libavcodec/ptx.c | 2 +- .../plugins/ffmpeg/libavcodec/put_bits.h | 49 +- .../plugins/ffmpeg/libavcodec/qcelpdata.h | 12 +- .../plugins/ffmpeg/libavcodec/qcelpdec.c | 97 +- .../media/plugins/ffmpeg/libavcodec/qdm2.c | 87 +- .../plugins/ffmpeg/libavcodec/qdm2_tablegen.c | 57 + .../plugins/ffmpeg/libavcodec/qdm2_tablegen.h | 102 + .../plugins/ffmpeg/libavcodec/qdm2data.h | 2 +- .../media/plugins/ffmpeg/libavcodec/qdrw.c | 20 +- .../media/plugins/ffmpeg/libavcodec/qpeg.c | 4 +- .../media/plugins/ffmpeg/libavcodec/qtrle.c | 4 +- .../plugins/ffmpeg/libavcodec/qtrleenc.c | 8 +- .../media/plugins/ffmpeg/libavcodec/r210dec.c | 104 + .../media/plugins/ffmpeg/libavcodec/ra144.c | 19 +- .../media/plugins/ffmpeg/libavcodec/ra288.c | 6 +- .../plugins/ffmpeg/libavcodec/rangecoder.c | 2 +- .../plugins/ffmpeg/libavcodec/rangecoder.h | 2 +- .../plugins/ffmpeg/libavcodec/ratecontrol.c | 9 +- .../plugins/ffmpeg/libavcodec/ratecontrol.h | 4 +- .../media/plugins/ffmpeg/libavcodec/raw.c | 26 +- .../media/plugins/ffmpeg/libavcodec/raw.h | 2 +- .../media/plugins/ffmpeg/libavcodec/rawdec.c | 49 +- .../media/plugins/ffmpeg/libavcodec/rawenc.c | 6 +- .../media/plugins/ffmpeg/libavcodec/rdft.c | 94 +- .../plugins/ffmpeg/libavcodec/rectangle.h | 27 +- .../plugins/ffmpeg/libavcodec/resample.c | 4 +- .../plugins/ffmpeg/libavcodec/resample2.c | 10 +- .../media/plugins/ffmpeg/libavcodec/rl.h | 2 +- .../media/plugins/ffmpeg/libavcodec/rl2.c | 4 +- .../plugins/ffmpeg/libavcodec/roqaudioenc.c | 26 +- .../plugins/ffmpeg/libavcodec/roqvideo.c | 2 +- .../plugins/ffmpeg/libavcodec/roqvideodec.c | 4 +- .../plugins/ffmpeg/libavcodec/roqvideoenc.c | 14 +- .../media/plugins/ffmpeg/libavcodec/rpza.c | 4 +- .../media/plugins/ffmpeg/libavcodec/rtjpeg.h | 2 +- .../media/plugins/ffmpeg/libavcodec/rv10.c | 43 +- .../media/plugins/ffmpeg/libavcodec/rv10enc.c | 6 +- .../media/plugins/ffmpeg/libavcodec/rv20enc.c | 7 +- .../media/plugins/ffmpeg/libavcodec/rv30.c | 4 +- .../plugins/ffmpeg/libavcodec/rv30data.h | 2 +- .../media/plugins/ffmpeg/libavcodec/rv30dsp.c | 4 +- .../media/plugins/ffmpeg/libavcodec/rv34.c | 68 +- .../media/plugins/ffmpeg/libavcodec/rv34.h | 4 +- .../plugins/ffmpeg/libavcodec/rv34data.h | 2 +- .../media/plugins/ffmpeg/libavcodec/rv34vlc.h | 2 +- .../media/plugins/ffmpeg/libavcodec/rv40.c | 12 +- .../plugins/ffmpeg/libavcodec/rv40data.h | 2 +- .../media/plugins/ffmpeg/libavcodec/rv40dsp.c | 2 +- .../plugins/ffmpeg/libavcodec/rv40vlc2.h | 2 +- .../media/plugins/ffmpeg/libavcodec/sbr.h | 183 + .../media/plugins/ffmpeg/libavcodec/sgidec.c | 22 +- .../media/plugins/ffmpeg/libavcodec/sgienc.c | 101 +- .../media/plugins/ffmpeg/libavcodec/shorten.c | 4 +- .../plugins/ffmpeg/libavcodec/simple_idct.c | 2 +- .../plugins/ffmpeg/libavcodec/simple_idct.h | 2 +- .../media/plugins/ffmpeg/libavcodec/sipr.c | 588 + .../media/plugins/ffmpeg/libavcodec/sipr.h | 107 + .../media/plugins/ffmpeg/libavcodec/sipr16k.c | 280 + .../plugins/ffmpeg/libavcodec/sipr16kdata.h | 533 + .../plugins/ffmpeg/libavcodec/siprdata.h | 263 + .../media/plugins/ffmpeg/libavcodec/smacker.c | 11 +- .../media/plugins/ffmpeg/libavcodec/smc.c | 15 +- .../media/plugins/ffmpeg/libavcodec/snow.c | 3510 ++--- .../media/plugins/ffmpeg/libavcodec/snow.h | 98 +- .../media/plugins/ffmpeg/libavcodec/sonic.c | 8 +- .../media/plugins/ffmpeg/libavcodec/sp5xdec.c | 6 +- .../ffmpeg/libavcodec/sparc/dsputil_vis.c | 131 +- .../ffmpeg/libavcodec/sparc/dsputil_vis.h | 29 + .../ffmpeg/libavcodec/sparc/simple_idct_vis.c | 11 +- .../plugins/ffmpeg/libavcodec/sparc/vis.h | 4 +- .../media/plugins/ffmpeg/libavcodec/sunrast.c | 6 +- .../media/plugins/ffmpeg/libavcodec/svq1.c | 6 +- .../media/plugins/ffmpeg/libavcodec/svq1.h | 8 +- .../media/plugins/ffmpeg/libavcodec/svq1_cb.h | 20 +- .../media/plugins/ffmpeg/libavcodec/svq1dec.c | 37 +- .../media/plugins/ffmpeg/libavcodec/svq1enc.c | 29 +- .../plugins/ffmpeg/libavcodec/svq1enc_cb.h | 2 +- .../media/plugins/ffmpeg/libavcodec/svq3.c | 78 +- .../plugins/ffmpeg/libavcodec/synth_filter.c | 64 + .../plugins/ffmpeg/libavcodec/synth_filter.h | 37 + .../plugins/ffmpeg/libavcodec/tableprint.c | 40 + .../plugins/ffmpeg/libavcodec/tableprint.h | 74 + .../media/plugins/ffmpeg/libavcodec/targa.c | 3 +- .../plugins/ffmpeg/libavcodec/targaenc.c | 11 +- .../plugins/ffmpeg/libavcodec/tiertexseqv.c | 4 +- .../media/plugins/ffmpeg/libavcodec/tiff.c | 83 +- .../media/plugins/ffmpeg/libavcodec/tiff.h | 3 +- .../media/plugins/ffmpeg/libavcodec/tiffenc.c | 12 +- .../media/plugins/ffmpeg/libavcodec/tmv.c | 4 +- .../plugins/ffmpeg/libavcodec/truemotion1.c | 4 +- .../plugins/ffmpeg/libavcodec/truemotion2.c | 12 +- .../plugins/ffmpeg/libavcodec/truespeech.c | 4 +- .../media/plugins/ffmpeg/libavcodec/tscc.c | 13 +- .../media/plugins/ffmpeg/libavcodec/tta.c | 19 +- .../media/plugins/ffmpeg/libavcodec/twinvq.c | 1127 ++ .../plugins/ffmpeg/libavcodec/twinvq_data.h | 11137 ++++++++++++++++ .../media/plugins/ffmpeg/libavcodec/txd.c | 2 +- .../media/plugins/ffmpeg/libavcodec/ulti.c | 21 +- .../media/plugins/ffmpeg/libavcodec/utils.c | 236 +- .../media/plugins/ffmpeg/libavcodec/v210dec.c | 28 +- .../media/plugins/ffmpeg/libavcodec/v210enc.c | 15 +- .../media/plugins/ffmpeg/libavcodec/v210x.c | 17 +- .../media/plugins/ffmpeg/libavcodec/vaapi.c | 4 +- .../plugins/ffmpeg/libavcodec/vaapi_h264.c | 347 + .../ffmpeg/libavcodec/vaapi_internal.h | 4 +- .../plugins/ffmpeg/libavcodec/vaapi_mpeg2.c | 13 +- .../plugins/ffmpeg/libavcodec/vaapi_mpeg4.c | 16 +- .../plugins/ffmpeg/libavcodec/vaapi_vc1.c | 43 +- .../media/plugins/ffmpeg/libavcodec/vb.c | 42 +- .../media/plugins/ffmpeg/libavcodec/vc1.c | 8 +- .../media/plugins/ffmpeg/libavcodec/vc1.h | 2 + .../plugins/ffmpeg/libavcodec/vc1_parser.c | 2 +- .../media/plugins/ffmpeg/libavcodec/vc1data.c | 2 +- .../media/plugins/ffmpeg/libavcodec/vc1data.h | 2 +- .../media/plugins/ffmpeg/libavcodec/vc1dec.c | 25 +- .../media/plugins/ffmpeg/libavcodec/vc1dsp.c | 8 +- .../media/plugins/ffmpeg/libavcodec/vcr1.c | 17 +- .../media/plugins/ffmpeg/libavcodec/vdpau.c | 80 +- .../media/plugins/ffmpeg/libavcodec/vdpau.h | 11 +- .../ffmpeg/libavcodec/vdpau_internal.h | 4 + .../media/plugins/ffmpeg/libavcodec/vmdav.c | 6 +- .../media/plugins/ffmpeg/libavcodec/vmnc.c | 7 +- .../media/plugins/ffmpeg/libavcodec/vorbis.c | 162 +- .../media/plugins/ffmpeg/libavcodec/vorbis.h | 7 +- .../plugins/ffmpeg/libavcodec/vorbis_data.c | 4253 +++--- .../plugins/ffmpeg/libavcodec/vorbis_dec.c | 1292 +- .../plugins/ffmpeg/libavcodec/vorbis_enc.c | 419 +- .../ffmpeg/libavcodec/vorbis_enc_data.h | 669 +- .../media/plugins/ffmpeg/libavcodec/vp3.c | 1632 ++- .../media/plugins/ffmpeg/libavcodec/vp3dsp.c | 21 +- .../media/plugins/ffmpeg/libavcodec/vp5.c | 22 +- .../media/plugins/ffmpeg/libavcodec/vp56.c | 38 +- .../media/plugins/ffmpeg/libavcodec/vp56.h | 10 +- .../plugins/ffmpeg/libavcodec/vp56data.c | 2 +- .../plugins/ffmpeg/libavcodec/vp56data.h | 2 +- .../media/plugins/ffmpeg/libavcodec/vp56dsp.c | 88 + .../media/plugins/ffmpeg/libavcodec/vp56dsp.h | 34 + .../media/plugins/ffmpeg/libavcodec/vp5data.h | 2 +- .../media/plugins/ffmpeg/libavcodec/vp6.c | 46 +- .../media/plugins/ffmpeg/libavcodec/vp6data.h | 2 +- .../media/plugins/ffmpeg/libavcodec/vp6dsp.c | 2 +- .../plugins/ffmpeg/libavcodec/vqavideo.c | 4 +- .../plugins/ffmpeg/libavcodec/w32thread.c | 79 +- .../media/plugins/ffmpeg/libavcodec/wavpack.c | 204 +- .../media/plugins/ffmpeg/libavcodec/wma.c | 29 +- .../media/plugins/ffmpeg/libavcodec/wma.h | 20 +- .../media/plugins/ffmpeg/libavcodec/wmadata.h | 42 +- .../media/plugins/ffmpeg/libavcodec/wmadec.c | 234 +- .../media/plugins/ffmpeg/libavcodec/wmaenc.c | 10 +- .../plugins/ffmpeg/libavcodec/wmaprodata.h | 8 +- .../plugins/ffmpeg/libavcodec/wmaprodec.c | 1445 +- .../plugins/ffmpeg/libavcodec/wmavoice.c | 2030 +++ .../plugins/ffmpeg/libavcodec/wmavoice_data.h | 3259 +++++ .../media/plugins/ffmpeg/libavcodec/wmv2.h | 2 +- .../media/plugins/ffmpeg/libavcodec/wmv2dec.c | 5 +- .../media/plugins/ffmpeg/libavcodec/wmv2enc.c | 5 +- .../media/plugins/ffmpeg/libavcodec/wnv1.c | 21 +- .../media/plugins/ffmpeg/libavcodec/ws-snd1.c | 4 +- .../plugins/ffmpeg/libavcodec/x86/Jamfile | 3 + .../ffmpeg/libavcodec/x86/cavsdsp_mmx.c | 58 +- .../x86/dsputil_h264_template_mmx.c | 4 +- .../ffmpeg/libavcodec/x86/dsputil_mmx.c | 559 +- .../ffmpeg/libavcodec/x86/dsputil_mmx.h | 22 + .../libavcodec/x86/dsputil_mmx_avg_template.c | 16 +- .../libavcodec/x86/dsputil_mmx_rnd_template.c | 4 +- .../ffmpeg/libavcodec/x86/dsputil_yasm.nasm | 273 +- .../ffmpeg/libavcodec/x86/dsputilenc_mmx.c | 16 +- .../plugins/ffmpeg/libavcodec/x86/fdct_mmx.c | 30 +- .../media/plugins/ffmpeg/libavcodec/x86/fft.c | 44 + .../media/plugins/ffmpeg/libavcodec/x86/fft.h | 36 + .../plugins/ffmpeg/libavcodec/x86/fft_3dn2.c | 15 +- .../ffmpeg/libavcodec/x86/fft_mmx.nasm | 21 +- .../plugins/ffmpeg/libavcodec/x86/fft_sse.c | 15 +- .../plugins/ffmpeg/libavcodec/x86/h264_i386.h | 2 +- .../ffmpeg/libavcodec/x86/h264dsp_mmx.c | 226 +- .../plugins/ffmpeg/libavcodec/x86/idct_mmx.c | 38 +- .../ffmpeg/libavcodec/x86/idct_mmx_xvid.c | 9 +- .../ffmpeg/libavcodec/x86/idct_sse2_xvid.c | 23 +- .../plugins/ffmpeg/libavcodec/x86/idct_xvid.h | 2 +- .../x86/{flacdsp_mmx.c => lpc_mmx.c} | 23 +- .../plugins/ffmpeg/libavcodec/x86/mathops.h | 37 +- .../ffmpeg/libavcodec/x86/motion_est_mmx.c | 3 +- .../libavcodec/x86/mpegvideo_mmx_template.c | 2 +- .../ffmpeg/libavcodec/x86/rv40dsp_mmx.c | 2 +- .../ffmpeg/libavcodec/x86/simple_idct_mmx.c | 5 +- .../ffmpeg/libavcodec/x86/snowdsp_mmx.c | 40 +- .../ffmpeg/libavcodec/x86/vc1dsp_mmx.c | 7 +- .../ffmpeg/libavcodec/x86/vp3dsp_mmx.c | 44 +- .../ffmpeg/libavcodec/x86/vp3dsp_mmx.h | 1 + .../ffmpeg/libavcodec/x86/vp3dsp_sse2.c | 5 +- .../ffmpeg/libavcodec/x86/vp6dsp_mmx.c | 2 +- .../ffmpeg/libavcodec/x86/vp6dsp_sse2.c | 2 +- .../plugins/ffmpeg/libavcodec/x86/x86inc.asm | 10 +- .../media/plugins/ffmpeg/libavcodec/xan.c | 56 +- .../media/plugins/ffmpeg/libavcodec/xl.c | 16 +- .../media/plugins/ffmpeg/libavcodec/xsubdec.c | 2 +- .../media/plugins/ffmpeg/libavcodec/xsubenc.c | 4 +- .../media/plugins/ffmpeg/libavcodec/yop.c | 260 + .../media/plugins/ffmpeg/libavcodec/zmbv.c | 8 +- .../media/plugins/ffmpeg/libavcodec/zmbvenc.c | 43 +- .../media/plugins/ffmpeg/libavformat/4xm.c | 6 +- .../media/plugins/ffmpeg/libavformat/Jamfile | 32 + .../media/plugins/ffmpeg/libavformat/adts.h | 45 + .../plugins/ffmpeg/libavformat/adtsenc.c | 40 +- .../media/plugins/ffmpeg/libavformat/aea.c | 108 + .../media/plugins/ffmpeg/libavformat/aiff.h | 53 + .../plugins/ffmpeg/libavformat/aiffdec.c | 324 + .../plugins/ffmpeg/libavformat/aiffenc.c | 160 + .../plugins/ffmpeg/libavformat/allformats.c | 19 +- .../media/plugins/ffmpeg/libavformat/amr.c | 2 +- .../media/plugins/ffmpeg/libavformat/anm.c | 235 + .../media/plugins/ffmpeg/libavformat/apc.c | 2 +- .../media/plugins/ffmpeg/libavformat/ape.c | 14 +- .../media/plugins/ffmpeg/libavformat/apetag.c | 32 +- .../media/plugins/ffmpeg/libavformat/asf.c | 57 +- .../media/plugins/ffmpeg/libavformat/asf.h | 5 + .../media/plugins/ffmpeg/libavformat/asfdec.c | 118 +- .../media/plugins/ffmpeg/libavformat/asfenc.c | 111 +- .../media/plugins/ffmpeg/libavformat/assdec.c | 4 +- .../media/plugins/ffmpeg/libavformat/au.c | 14 +- .../ffmpeg/libavformat/audiointerleave.c | 8 +- .../media/plugins/ffmpeg/libavformat/avc.c | 17 +- .../plugins/ffmpeg/libavformat/avformat.h | 216 +- .../media/plugins/ffmpeg/libavformat/avi.c | 45 + .../media/plugins/ffmpeg/libavformat/avi.h | 9 + .../media/plugins/ffmpeg/libavformat/avidec.c | 198 +- .../media/plugins/ffmpeg/libavformat/avienc.c | 188 +- .../media/plugins/ffmpeg/libavformat/avio.c | 42 +- .../media/plugins/ffmpeg/libavformat/avio.h | 146 +- .../plugins/ffmpeg/libavformat/aviobuf.c | 94 +- .../plugins/ffmpeg/libavformat/avisynth.c | 4 +- .../plugins/ffmpeg/libavformat/avlanguage.c | 6 +- .../media/plugins/ffmpeg/libavformat/avs.c | 8 +- .../plugins/ffmpeg/libavformat/bethsoftvid.c | 6 +- .../media/plugins/ffmpeg/libavformat/bfi.c | 6 +- .../media/plugins/ffmpeg/libavformat/bink.c | 269 + .../media/plugins/ffmpeg/libavformat/c93.c | 26 +- .../media/plugins/ffmpeg/libavformat/caf.c | 58 + .../media/plugins/ffmpeg/libavformat/caf.h | 34 + .../media/plugins/ffmpeg/libavformat/cafdec.c | 379 + .../media/plugins/ffmpeg/libavformat/cdg.c | 66 + .../media/plugins/ffmpeg/libavformat/concat.c | 198 + .../media/plugins/ffmpeg/libavformat/cutils.c | 1 + .../media/plugins/ffmpeg/libavformat/daud.c | 2 +- .../media/plugins/ffmpeg/libavformat/dsicin.c | 30 +- .../media/plugins/ffmpeg/libavformat/dv.c | 31 +- .../media/plugins/ffmpeg/libavformat/dvenc.c | 12 +- .../media/plugins/ffmpeg/libavformat/dxa.c | 10 +- .../plugins/ffmpeg/libavformat/eacdata.c | 13 +- .../ffmpeg/libavformat/electronicarts.c | 19 +- .../media/plugins/ffmpeg/libavformat/ffmdec.c | 32 +- .../media/plugins/ffmpeg/libavformat/ffmenc.c | 20 +- .../media/plugins/ffmpeg/libavformat/file.c | 8 +- .../plugins/ffmpeg/libavformat/filmstripdec.c | 111 + .../plugins/ffmpeg/libavformat/filmstripenc.c | 85 + .../plugins/ffmpeg/libavformat/flacdec.c | 9 +- .../plugins/ffmpeg/libavformat/flacenc.c | 69 +- .../plugins/ffmpeg/libavformat/flacenc.h | 5 +- .../ffmpeg/libavformat/flacenc_header.c | 49 + .../media/plugins/ffmpeg/libavformat/flic.c | 78 +- .../media/plugins/ffmpeg/libavformat/flv.h | 2 +- .../media/plugins/ffmpeg/libavformat/flvdec.c | 118 +- .../media/plugins/ffmpeg/libavformat/flvenc.c | 39 +- .../media/plugins/ffmpeg/libavformat/gif.c | 4 +- .../media/plugins/ffmpeg/libavformat/gopher.c | 7 +- .../media/plugins/ffmpeg/libavformat/gxf.c | 28 +- .../media/plugins/ffmpeg/libavformat/gxfenc.c | 18 +- .../media/plugins/ffmpeg/libavformat/http.c | 96 +- .../plugins/ffmpeg/libavformat/httpauth.c | 321 + .../plugins/ffmpeg/libavformat/httpauth.h | 72 + .../media/plugins/ffmpeg/libavformat/id3v1.c | 40 +- .../media/plugins/ffmpeg/libavformat/id3v1.h | 4 +- .../media/plugins/ffmpeg/libavformat/id3v2.c | 137 +- .../media/plugins/ffmpeg/libavformat/id3v2.h | 9 + .../media/plugins/ffmpeg/libavformat/idcin.c | 19 +- .../media/plugins/ffmpeg/libavformat/idroq.c | 6 +- .../media/plugins/ffmpeg/libavformat/iff.c | 184 +- .../media/plugins/ffmpeg/libavformat/img2.c | 34 +- .../plugins/ffmpeg/libavformat/internal.h | 123 +- .../plugins/ffmpeg/libavformat/ipmovie.c | 37 +- .../media/plugins/ffmpeg/libavformat/isom.c | 49 +- .../media/plugins/ffmpeg/libavformat/isom.h | 14 +- .../media/plugins/ffmpeg/libavformat/iss.c | 4 +- .../media/plugins/ffmpeg/libavformat/iv8.c | 96 + .../media/plugins/ffmpeg/libavformat/libnut.c | 18 +- .../plugins/ffmpeg/libavformat/librtmp.c | 226 + .../media/plugins/ffmpeg/libavformat/lmlm4.c | 6 +- .../plugins/ffmpeg/libavformat/matroska.c | 7 +- .../plugins/ffmpeg/libavformat/matroskadec.c | 137 +- .../plugins/ffmpeg/libavformat/matroskaenc.c | 257 +- .../plugins/ffmpeg/libavformat/metadata.c | 35 +- .../plugins/ffmpeg/libavformat/metadata.h | 5 +- .../ffmpeg/libavformat/metadata_compat.c | 5 +- .../media/plugins/ffmpeg/libavformat/mm.c | 34 +- .../media/plugins/ffmpeg/libavformat/mmf.c | 2 +- .../media/plugins/ffmpeg/libavformat/mov.c | 608 +- .../media/plugins/ffmpeg/libavformat/movenc.c | 707 +- .../media/plugins/ffmpeg/libavformat/movenc.h | 120 + .../plugins/ffmpeg/libavformat/movenchint.c | 504 + .../media/plugins/ffmpeg/libavformat/mp3.c | 167 +- .../media/plugins/ffmpeg/libavformat/mpc.c | 8 +- .../media/plugins/ffmpeg/libavformat/mpc8.c | 52 +- .../media/plugins/ffmpeg/libavformat/mpeg.c | 61 +- .../plugins/ffmpeg/libavformat/mpegenc.c | 14 +- .../media/plugins/ffmpeg/libavformat/mpegts.c | 737 +- .../media/plugins/ffmpeg/libavformat/mpegts.h | 10 +- .../plugins/ffmpeg/libavformat/mpegtsenc.c | 285 +- .../plugins/ffmpeg/libavformat/msnwc_tcp.c | 6 +- .../media/plugins/ffmpeg/libavformat/mtv.c | 49 +- .../media/plugins/ffmpeg/libavformat/mvi.c | 5 +- .../media/plugins/ffmpeg/libavformat/mxf.c | 6 +- .../media/plugins/ffmpeg/libavformat/mxfdec.c | 15 +- .../media/plugins/ffmpeg/libavformat/mxfenc.c | 33 +- .../media/plugins/ffmpeg/libavformat/ncdec.c | 4 +- .../plugins/ffmpeg/libavformat/network.h | 97 +- .../media/plugins/ffmpeg/libavformat/nsvdec.c | 20 +- .../media/plugins/ffmpeg/libavformat/nut.c | 31 +- .../media/plugins/ffmpeg/libavformat/nut.h | 8 +- .../media/plugins/ffmpeg/libavformat/nutdec.c | 39 +- .../media/plugins/ffmpeg/libavformat/nutenc.c | 36 +- .../media/plugins/ffmpeg/libavformat/nuv.c | 8 +- .../media/plugins/ffmpeg/libavformat/oggdec.c | 193 +- .../media/plugins/ffmpeg/libavformat/oggdec.h | 59 +- .../media/plugins/ffmpeg/libavformat/oggenc.c | 364 +- .../ffmpeg/libavformat/oggparsedirac.c | 115 + .../plugins/ffmpeg/libavformat/oggparseflac.c | 6 +- .../plugins/ffmpeg/libavformat/oggparseogm.c | 110 +- .../ffmpeg/libavformat/oggparseskeleton.c | 87 + .../ffmpeg/libavformat/oggparsespeex.c | 72 +- .../ffmpeg/libavformat/oggparsetheora.c | 12 +- .../ffmpeg/libavformat/oggparsevorbis.c | 88 +- .../media/plugins/ffmpeg/libavformat/oma.c | 29 +- .../plugins/ffmpeg/libavformat/options.c | 10 +- .../plugins/ffmpeg/libavformat/os_support.c | 169 +- .../plugins/ffmpeg/libavformat/os_support.h | 4 +- .../ffmpeg/libavformat/output-example.c | 25 +- .../media/plugins/ffmpeg/libavformat/psxstr.c | 6 +- .../media/plugins/ffmpeg/libavformat/pva.c | 4 +- .../media/plugins/ffmpeg/libavformat/qcp.c | 4 +- .../media/plugins/ffmpeg/libavformat/r3d.c | 23 +- .../media/plugins/ffmpeg/libavformat/raw.c | 163 +- .../media/plugins/ffmpeg/libavformat/rdt.c | 17 +- .../media/plugins/ffmpeg/libavformat/riff.c | 48 +- .../media/plugins/ffmpeg/libavformat/riff.h | 4 +- .../media/plugins/ffmpeg/libavformat/rl2.c | 6 +- .../media/plugins/ffmpeg/libavformat/rm.c | 2 +- .../media/plugins/ffmpeg/libavformat/rm.h | 12 +- .../media/plugins/ffmpeg/libavformat/rmdec.c | 168 +- .../media/plugins/ffmpeg/libavformat/rmenc.c | 14 +- .../media/plugins/ffmpeg/libavformat/rpl.c | 16 +- .../plugins/ffmpeg/libavformat/rtmppkt.c | 203 +- .../plugins/ffmpeg/libavformat/rtmppkt.h | 20 +- .../plugins/ffmpeg/libavformat/rtmpproto.c | 547 +- .../media/plugins/ffmpeg/libavformat/rtp.c | 62 +- .../media/plugins/ffmpeg/libavformat/rtp.h | 2 +- .../media/plugins/ffmpeg/libavformat/rtpdec.c | 78 +- .../media/plugins/ffmpeg/libavformat/rtpdec.h | 27 +- .../plugins/ffmpeg/libavformat/rtpdec_amr.c | 186 + .../plugins/ffmpeg/libavformat/rtpdec_amr.h | 30 + .../plugins/ffmpeg/libavformat/rtpdec_asf.c | 281 + .../plugins/ffmpeg/libavformat/rtpdec_asf.h | 43 + .../plugins/ffmpeg/libavformat/rtpdec_h263.c | 108 + .../plugins/ffmpeg/libavformat/rtpdec_h263.h | 30 + .../plugins/ffmpeg/libavformat/rtpdec_h264.c | 420 + .../plugins/ffmpeg/libavformat/rtpdec_h264.h | 29 + .../plugins/ffmpeg/libavformat/rtpdec_xiph.c | 398 + .../plugins/ffmpeg/libavformat/rtpdec_xiph.h | 40 + .../media/plugins/ffmpeg/libavformat/rtpenc.c | 66 +- .../plugins/ffmpeg/libavformat/rtpenc_aac.c | 85 + .../plugins/ffmpeg/libavformat/rtpenc_amr.c | 66 + .../plugins/ffmpeg/libavformat/rtpenc_h263.c | 80 + .../plugins/ffmpeg/libavformat/rtpenc_h264.c | 2 +- .../plugins/ffmpeg/libavformat/rtpenc_mpv.c | 119 + .../plugins/ffmpeg/libavformat/rtpproto.c | 99 +- .../media/plugins/ffmpeg/libavformat/rtsp.c | 1511 ++- .../media/plugins/ffmpeg/libavformat/rtsp.h | 131 +- .../plugins/ffmpeg/libavformat/rtspenc.c | 182 + .../media/plugins/ffmpeg/libavformat/sdp.c | 83 +- .../media/plugins/ffmpeg/libavformat/seek.c | 518 + .../media/plugins/ffmpeg/libavformat/seek.h | 126 + .../plugins/ffmpeg/libavformat/segafilm.c | 6 +- .../plugins/ffmpeg/libavformat/sierravmd.c | 15 +- .../media/plugins/ffmpeg/libavformat/siff.c | 13 +- .../plugins/ffmpeg/libavformat/smacker.c | 20 +- .../media/plugins/ffmpeg/libavformat/sol.c | 2 +- .../media/plugins/ffmpeg/libavformat/soxdec.c | 18 +- .../media/plugins/ffmpeg/libavformat/soxenc.c | 2 +- .../media/plugins/ffmpeg/libavformat/spdif.c | 6 +- .../media/plugins/ffmpeg/libavformat/swf.h | 4 +- .../media/plugins/ffmpeg/libavformat/swfdec.c | 14 +- .../media/plugins/ffmpeg/libavformat/swfenc.c | 6 +- .../media/plugins/ffmpeg/libavformat/tcp.c | 45 +- .../media/plugins/ffmpeg/libavformat/thp.c | 4 +- .../plugins/ffmpeg/libavformat/tiertexseq.c | 6 +- .../media/plugins/ffmpeg/libavformat/tmv.c | 49 +- .../media/plugins/ffmpeg/libavformat/tta.c | 22 +- .../media/plugins/ffmpeg/libavformat/txd.c | 12 +- .../media/plugins/ffmpeg/libavformat/udp.c | 103 +- .../media/plugins/ffmpeg/libavformat/utils.c | 676 +- .../plugins/ffmpeg/libavformat/vc1test.c | 19 +- .../plugins/ffmpeg/libavformat/vc1testenc.c | 2 +- .../media/plugins/ffmpeg/libavformat/voc.c | 2 +- .../media/plugins/ffmpeg/libavformat/voc.h | 2 +- .../media/plugins/ffmpeg/libavformat/vocdec.c | 7 +- .../media/plugins/ffmpeg/libavformat/vocenc.c | 2 +- .../ffmpeg/libavformat/vorbiscomment.c | 73 + .../ffmpeg/libavformat/vorbiscomment.h | 57 + .../media/plugins/ffmpeg/libavformat/vqf.c | 16 +- .../media/plugins/ffmpeg/libavformat/wav.c | 284 +- .../plugins/ffmpeg/libavformat/wc3movie.c | 23 +- .../plugins/ffmpeg/libavformat/westwood.c | 8 +- .../media/plugins/ffmpeg/libavformat/wv.c | 49 +- .../media/plugins/ffmpeg/libavformat/xa.c | 23 +- .../media/plugins/ffmpeg/libavformat/yop.c | 216 + .../plugins/ffmpeg/libavformat/yuv4mpeg.c | 2 +- .../media/plugins/ffmpeg/libavutil/Jamfile | 2 + .../media/plugins/ffmpeg/libavutil/adler32.c | 3 +- .../media/plugins/ffmpeg/libavutil/adler32.h | 2 +- .../plugins/ffmpeg/libavutil/attributes.h | 113 + .../media/plugins/ffmpeg/libavutil/avconfig.h | 9 + .../media/plugins/ffmpeg/libavutil/avstring.c | 21 + .../media/plugins/ffmpeg/libavutil/avstring.h | 29 +- .../media/plugins/ffmpeg/libavutil/avutil.h | 32 +- .../media/plugins/ffmpeg/libavutil/base64.c | 2 +- .../media/plugins/ffmpeg/libavutil/bswap.h | 21 +- .../media/plugins/ffmpeg/libavutil/common.h | 191 +- .../media/plugins/ffmpeg/libavutil/crc.c | 1 + .../media/plugins/ffmpeg/libavutil/crc.h | 2 +- .../media/plugins/ffmpeg/libavutil/des.c | 8 +- .../media/plugins/ffmpeg/libavutil/error.c | 47 + .../media/plugins/ffmpeg/libavutil/error.h | 72 + .../media/plugins/ffmpeg/libavutil/fifo.c | 1 + .../media/plugins/ffmpeg/libavutil/fifo.h | 9 +- .../media/plugins/ffmpeg/libavutil/integer.c | 6 +- .../media/plugins/ffmpeg/libavutil/integer.h | 2 +- .../media/plugins/ffmpeg/libavutil/internal.h | 183 +- .../ffmpeg/libavutil/intfloat_readwrite.c | 5 +- .../ffmpeg/libavutil/intfloat_readwrite.h | 2 +- .../media/plugins/ffmpeg/libavutil/intmath.h | 98 + .../plugins/ffmpeg/libavutil/intreadwrite.h | 136 +- .../media/plugins/ffmpeg/libavutil/lfg.c | 36 +- .../media/plugins/ffmpeg/libavutil/lfg.h | 8 + .../media/plugins/ffmpeg/libavutil/libm.h | 96 + .../media/plugins/ffmpeg/libavutil/lls.c | 2 +- .../media/plugins/ffmpeg/libavutil/log.c | 31 +- .../media/plugins/ffmpeg/libavutil/log.h | 8 + .../plugins/ffmpeg/libavutil/mathematics.c | 33 +- .../plugins/ffmpeg/libavutil/mathematics.h | 22 +- .../media/plugins/ffmpeg/libavutil/md5.c | 1 + .../media/plugins/ffmpeg/libavutil/mem.c | 19 +- .../media/plugins/ffmpeg/libavutil/mem.h | 20 +- .../media/plugins/ffmpeg/libavutil/pca.c | 2 +- .../media/plugins/ffmpeg/libavutil/pca.h | 2 +- .../{libavcodec => libavutil}/pixdesc.c | 378 +- .../{libavcodec => libavutil}/pixdesc.h | 122 +- .../media/plugins/ffmpeg/libavutil/pixfmt.h | 48 +- .../plugins/ffmpeg/libavutil/random_seed.c | 5 +- .../media/plugins/ffmpeg/libavutil/rational.c | 4 +- .../media/plugins/ffmpeg/libavutil/rational.h | 4 +- .../media/plugins/ffmpeg/libavutil/sha.c | 6 +- .../media/plugins/ffmpeg/libavutil/timer.h | 2 +- .../media/plugins/ffmpeg/libavutil/tree.c | 14 +- .../media/plugins/ffmpeg/libavutil/tree.h | 15 +- .../media/plugins/ffmpeg/libavutil/utils.c | 14 +- .../plugins/ffmpeg/libavutil/x86/bswap.h | 4 +- .../plugins/ffmpeg/libavutil/x86/intmath.h | 35 + .../ffmpeg/libavutil/x86/intreadwrite.h | 97 + .../media/plugins/ffmpeg/libswscale/Jamfile | 1 + .../ffmpeg/libswscale/bfin/internal_bfin.S | 613 + .../ffmpeg/libswscale/bfin/swscale_bfin.c | 93 + .../ffmpeg/libswscale/bfin/yuv2rgb_bfin.c | 203 + .../ffmpeg/libswscale/mlib/yuv2rgb_mlib.c | 88 + .../libswscale/ppc/swscale_altivec_template.c | 8 +- .../ffmpeg/libswscale/ppc/yuv2rgb_altivec.c | 10 +- .../media/plugins/ffmpeg/libswscale/rgb2rgb.c | 173 +- .../media/plugins/ffmpeg/libswscale/rgb2rgb.h | 27 +- .../ffmpeg/libswscale/rgb2rgb_template.c | 192 +- .../media/plugins/ffmpeg/libswscale/swscale.c | 2247 +--- .../media/plugins/ffmpeg/libswscale/swscale.h | 75 +- .../ffmpeg/libswscale/swscale_internal.h | 279 +- .../ffmpeg/libswscale/swscale_template.c | 885 +- .../media/plugins/ffmpeg/libswscale/utils.c | 1591 +++ .../ffmpeg/libswscale/x86/yuv2rgb_mmx.c | 14 +- .../ffmpeg/libswscale/x86/yuv2rgb_template.c | 237 +- .../ffmpeg/libswscale/x86/yuv2rgb_template2.c | 459 + .../media/plugins/ffmpeg/libswscale/yuv2rgb.c | 101 +- 882 files changed, 94680 insertions(+), 35431 deletions(-) create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/aacsbr.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/aacsbr.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/aacsbrdata.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/alsdec.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/amrnbdata.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/amrnbdec.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/anm.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/atrac.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/atrac.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/atrac1.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/atrac1data.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/aura.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/avfft.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/avfft.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/bgmc.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/bgmc.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/bink.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/binkaudio.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/binkdata.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/binkidct.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/cbrt_tablegen.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/cbrt_tablegen.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/cdgraphics.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/costablegen.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/dcadsp.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/dcadsp.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/dct.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/dctref.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/dirac.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/dirac.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/dv_tablegen.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/dv_tablegen.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/dv_vlc_data.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/dvdata.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/dwt.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/dwt.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/dxva2.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/dxva2.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/dxva2_h264.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/dxva2_internal.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/dxva2_vc1.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/fft.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/flv.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/flvdec.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/flvenc.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/frwu.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/h264_cabac.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/h264_cavlc.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/h264_direct.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/h264_loopfilter.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/h264_mvpred.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/h264_ps.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/h264_refs.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/h264_sei.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/h264dsp.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/h264dsp.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/iff.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/iff.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/indeo5.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/indeo5data.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/intelh263dec.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/ituh263dec.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/ituh263enc.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/ivi_common.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/ivi_common.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/ivi_dsp.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/ivi_dsp.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/kgv1dec.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/libvpxdec.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/libvpxenc.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/mdct_tablegen.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/mdct_tablegen.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/motionpixels_tablegen.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/motionpixels_tablegen.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg4video.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg4video.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg4videodec.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg4videoenc.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudio3.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudio_tablegen.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudio_tablegen.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/pamenc.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/pcm-mpeg.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/pcm_tablegen.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/pcm_tablegen.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/pgssubdec.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/pnmdec.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/qdm2_tablegen.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/qdm2_tablegen.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/r210dec.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/sbr.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/sipr.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/sipr.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/sipr16k.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/sipr16kdata.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/siprdata.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/sparc/dsputil_vis.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/synth_filter.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/synth_filter.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/tableprint.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/tableprint.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/twinvq.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/twinvq_data.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/vaapi_h264.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/vp56dsp.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/vp56dsp.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/wmavoice.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/wmavoice_data.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/x86/fft.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/x86/fft.h rename src/add-ons/media/plugins/ffmpeg/libavcodec/x86/{flacdsp_mmx.c => lpc_mmx.c} (88%) create mode 100644 src/add-ons/media/plugins/ffmpeg/libavcodec/yop.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/adts.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/aea.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/aiff.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/aiffdec.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/aiffenc.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/anm.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/avi.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/bink.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/caf.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/caf.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/cafdec.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/cdg.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/concat.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/filmstripdec.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/filmstripenc.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/flacenc_header.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/httpauth.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/httpauth.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/iv8.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/librtmp.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/movenc.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/movenchint.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/oggparsedirac.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/oggparseskeleton.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_amr.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_amr.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_asf.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_asf.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_h263.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_h263.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_h264.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_h264.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_xiph.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_xiph.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/rtpenc_aac.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/rtpenc_amr.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/rtpenc_h263.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/rtpenc_mpv.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/rtspenc.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/seek.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/seek.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/vorbiscomment.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/vorbiscomment.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavformat/yop.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavutil/attributes.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavutil/avconfig.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavutil/error.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libavutil/error.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavutil/intmath.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavutil/libm.h rename src/add-ons/media/plugins/ffmpeg/{libavcodec => libavutil}/pixdesc.c (62%) rename src/add-ons/media/plugins/ffmpeg/{libavcodec => libavutil}/pixdesc.h (60%) create mode 100644 src/add-ons/media/plugins/ffmpeg/libavutil/x86/intmath.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libavutil/x86/intreadwrite.h create mode 100644 src/add-ons/media/plugins/ffmpeg/libswscale/bfin/internal_bfin.S create mode 100644 src/add-ons/media/plugins/ffmpeg/libswscale/bfin/swscale_bfin.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libswscale/bfin/yuv2rgb_bfin.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libswscale/mlib/yuv2rgb_mlib.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libswscale/utils.c create mode 100644 src/add-ons/media/plugins/ffmpeg/libswscale/x86/yuv2rgb_template2.c diff --git a/src/add-ons/media/plugins/ffmpeg/Jamfile b/src/add-ons/media/plugins/ffmpeg/Jamfile index cc7672fe14..8e37d1f5d3 100644 --- a/src/add-ons/media/plugins/ffmpeg/Jamfile +++ b/src/add-ons/media/plugins/ffmpeg/Jamfile @@ -63,6 +63,7 @@ if $(TARGET_ARCH) = x86 { HAIKU_FFMPEG_DEFINES += ARCH_SPARC=0 ; HAIKU_FFMPEG_DEFINES += HAVE_AMD3DNOW=$(HAIKU_FFMPEG_USE_AMD3DNOW) ; HAIKU_FFMPEG_DEFINES += HAVE_AMD3DNOWEXT=$(HAIKU_FFMPEG_USE_AMD3DNOWEXT) ; + HAIKU_FFMPEG_DEFINES += HAVE_BIGENDIAN=0 ; HAIKU_FFMPEG_DEFINES += HAVE_MMX=$(HAIKU_FFMPEG_USE_MMX) ; HAIKU_FFMPEG_DEFINES += HAVE_MMX2=$(HAIKU_FFMPEG_USE_MMX2) ; HAIKU_FFMPEG_DEFINES += HAVE_SSE=$(HAIKU_FFMPEG_USE_SSE) ; @@ -76,6 +77,7 @@ if $(TARGET_ARCH) = x86 { HAIKU_FFMPEG_DEFINES += HAVE_AMD3DNOW=0 HAVE_AMD3DNOWEXT=0 ; HAIKU_FFMPEG_DEFINES += HAVE_MMX=0 HAVE_MMX2=0 HAVE_SSE=0 HAVE_SSSE3=0 ; HAIKU_FFMPEG_DEFINES += HAVE_ALTIVEC=1 ; + HAIKU_FFMPEG_DEFINES += HAVE_BIGENDIAN=1 ; HAIKU_FFMPEG_DEFINES += HAVE_VIS=0 ; } else if $(TARGET_ARCH) = sparc { HAIKU_FFMPEG_DEFINES += ARCH_X86=0 ARCH_X86_32=0 ; @@ -84,6 +86,7 @@ if $(TARGET_ARCH) = x86 { HAIKU_FFMPEG_DEFINES += HAVE_AMD3DNOW=0 HAVE_AMD3DNOWEXT=0 ; HAIKU_FFMPEG_DEFINES += HAVE_MMX=0 HAVE_MMX2=0 HAVE_SSE=0 HAVE_SSSE3=0 ; HAIKU_FFMPEG_DEFINES += HAVE_ALTIVEC=0 ; + HAIKU_FFMPEG_DEFINES += HAVE_BIGENDIAN=1 ; HAIKU_FFMPEG_DEFINES += HAVE_VIS=1 ; } diff --git a/src/add-ons/media/plugins/ffmpeg/config.h b/src/add-ons/media/plugins/ffmpeg/config.h index b88e3f92f7..37f1c4a7c2 100644 --- a/src/add-ons/media/plugins/ffmpeg/config.h +++ b/src/add-ons/media/plugins/ffmpeg/config.h @@ -2,7 +2,14 @@ #ifndef FFMPEG_CONFIG_H #define FFMPEG_CONFIG_H #define FFMPEG_CONFIGURATION "--prefix=/boot/common --enable-shared --disable-debug --disable-mmx --disable-demuxer=audio-beos --disable-muxer=audio-beos" +#define FFMPEG_LICENSE "nonfree and unredistributable" #define FFMPEG_DATADIR "/boot/common/share/ffmpeg" +#define CC_TYPE "gcc" +#define CC_VERSION __VERSION__ +#define restrict __restrict__ +#define ASMALIGN(ZEROBITS) ".align 1 << " #ZEROBITS "\n\t" +#define EXTERN_PREFIX "" +#define EXTERN_ASM #define ARCH_ALPHA 0 #define ARCH_ARM 0 #define ARCH_AVR32 0 @@ -20,6 +27,7 @@ #define ARCH_SH4 0 // #define ARCH_SPARC 0 #define ARCH_SPARC64 0 +#define ARCH_TOMI 0 // #define ARCH_X86 1 // #define ARCH_X86_32 1 #define ARCH_X86_64 0 @@ -39,6 +47,7 @@ // #define HAVE_SSE 0 // #define HAVE_SSSE3 1 // #define HAVE_VIS 0 +// #define HAVE_BIGENDIAN 0 #define HAVE_BEOSTHREADS 0 #define HAVE_OS2THREADS 0 #define HAVE_PTHREADS 1 @@ -46,6 +55,7 @@ #define HAVE_ALSA_ASOUNDLIB_H 0 // #define HAVE_ALTIVEC_H 0 #define HAVE_ARPA_INET_H 1 +#define HAVE_ATTRIBUTE_MAY_ALIAS 1 #define HAVE_ATTRIBUTE_PACKED 1 #define HAVE_BIGENDIAN 0 #define HAVE_BSWAP 1 @@ -65,13 +75,19 @@ #define HAVE_EBP_AVAILABLE 1 // We use position independant code so no EBX #define HAVE_EBX_AVAILABLE 0 +#define HAVE_EXP2 0 +#define HAVE_EXP2F 0 #define HAVE_FAST_64BIT 0 +#define HAVE_FAST_CLZ 0 #define HAVE_FAST_CMOV 0 #define HAVE_FAST_UNALIGNED 1 #define HAVE_FORK 1 +#define HAVE_GETADDRINFO 0 #define HAVE_GETHRTIME 0 +#define HAVE_GETPROCESSMEMORYINFO 0 #define HAVE_GETPROCESSTIMES 0 #define HAVE_GETRUSAGE 1 +#define HAVE_STRUCT_RUSAGE_RU_MAXRSS 0 #define HAVE_INET_ATON 0 #define HAVE_INLINE_ASM 1 #define HAVE_ISATTY 1 @@ -79,7 +95,11 @@ #define HAVE_LIBDC1394_1 0 #define HAVE_LIBDC1394_2 0 #define HAVE_LLRINT 1 +#define HAVE_LLRINTF 1 +#define HAVE_LOCAL_ALIGNED_16 1 +#define HAVE_LOCAL_ALIGNED_8 1 #define HAVE_LOG2 1 +#define HAVE_LOG2F 1 #define HAVE_LOONGSON 0 #define HAVE_LRINT 1 #define HAVE_LRINTF 1 @@ -99,6 +119,16 @@ #define HAVE_SOCKLEN_T 1 #define HAVE_SOUNDCARD_H 0 #define HAVE_POLL_H 1 +#define HAVE_SETRLIMIT 1 +#define HAVE_STRERROR_R 1 +#define HAVE_STRUCT_ADDRINFO 1 +#define HAVE_STRUCT_IPV6_MREQ 0 +#define HAVE_STRUCT_SOCKADDR_IN6 0 +#define HAVE_STRUCT_SOCKADDR_SA_LEN 1 +#define HAVE_STRUCT_SOCKADDR_STORAGE 1 +#define HAVE_SYMVER 1 +#define HAVE_SYMVER_GNU_ASM 1 +#define HAVE_SYMVER_ASM_LABEL 0 #define HAVE_SYS_MMAN_H 1 #define HAVE_SYS_RESOURCE_H 1 #define HAVE_SYS_SELECT_H 1 @@ -118,29 +148,37 @@ #define CONFIG_DEMUXERS 1 #define CONFIG_ENCODERS 1 #define CONFIG_FILTERS 1 -#define CONFIG_HWACCELS 1 +#define CONFIG_HWACCELS 0 #define CONFIG_INDEVS 0 #define CONFIG_MUXERS 1 #define CONFIG_OUTDEVS 0 #define CONFIG_PARSERS 1 #define CONFIG_PROTOCOLS 1 #define CONFIG_AANDCT 1 +#define CONFIG_AVCODEC 1 +#define CONFIG_AVDEVICE 0 #define CONFIG_AVFILTER 0 #define CONFIG_AVFILTER_LAVF 0 +#define CONFIG_AVFORMAT 1 #define CONFIG_AVISYNTH 0 #define CONFIG_BEOS_NETSERVER 0 #define CONFIG_BZLIB 0 +#define CONFIG_DCT 1 +#define CONFIG_DOC 0 +#define CONFIG_DWT 1 +#define CONFIG_DXVA2 0 #define CONFIG_FASTDIV 1 #define CONFIG_FFMPEG 0 #define CONFIG_FFPLAY 0 +#define CONFIG_FFPROBE 0 #define CONFIG_FFSERVER 0 #define CONFIG_FFT 1 #define CONFIG_GOLOMB 1 //#define CONFIG_GPL 0 // defined in Jamfile depending on build config #define CONFIG_GPROF 0 #define CONFIG_GRAY 0 -#define CONFIG_HARDCODED_TABLES 1 -#define CONFIG_IPV6 0 +#define CONFIG_H264DSP 1 +#define CONFIG_HARDCODED_TABLES 0 #define CONFIG_LIBDC1394 0 #define CONFIG_LIBDIRAC 0 #define CONFIG_LIBFAAC 0 @@ -152,12 +190,16 @@ #define CONFIG_LIBOPENCORE_AMRNB 0 #define CONFIG_LIBOPENCORE_AMRWB 0 #define CONFIG_LIBOPENJPEG 0 +#define CONFIG_LIBRTMP 0 #define CONFIG_LIBSCHROEDINGER 0 #define CONFIG_LIBSPEEX 0 #define CONFIG_LIBTHEORA 0 #define CONFIG_LIBVORBIS 0 +#define CONFIG_LIBVPX 0 #define CONFIG_LIBX264 0 #define CONFIG_LIBXVID 0 +#define CONFIG_LPC 1 +#define CONFIG_LSP 1 #define CONFIG_MDCT 1 #define CONFIG_MEMALIGN_HACK 0 #define CONFIG_MLIB 0 @@ -171,25 +213,33 @@ #define CONFIG_RUNTIME_CPUDETECT 0 #define CONFIG_SHARED 0 #define CONFIG_SMALL 0 +#define CONFIG_SRAM 0 #define CONFIG_STATIC 1 +#define CONFIG_SWSCALE 1 #define CONFIG_SWSCALE_ALPHA 1 #define CONFIG_VAAPI 0 #define CONFIG_VDPAU 0 #define CONFIG_VERSION3 0 #define CONFIG_X11GRAB 0 #define CONFIG_ZLIB 1 +#define CONFIG_AVUTIL 1 #define CONFIG_GPLV3 0 #define CONFIG_LGPLV3 0 #define CONFIG_AASC_DECODER 1 #define CONFIG_AMV_DECODER 1 +#define CONFIG_ANM_DECODER 1 #define CONFIG_ASV1_DECODER 1 #define CONFIG_ASV2_DECODER 1 +#define CONFIG_AURA_DECODER 1 +#define CONFIG_AURA2_DECODER 1 #define CONFIG_AVS_DECODER 1 #define CONFIG_BETHSOFTVID_DECODER 1 #define CONFIG_BFI_DECODER 1 +#define CONFIG_BINK_DECODER 1 #define CONFIG_BMP_DECODER 1 #define CONFIG_C93_DECODER 1 #define CONFIG_CAVS_DECODER 0 +#define CONFIG_CDGRAPHICS_DECODER 1 #define CONFIG_CINEPAK_DECODER 1 #define CONFIG_CLJR_DECODER 1 #define CONFIG_CSCD_DECODER 1 @@ -215,6 +265,7 @@ #define CONFIG_FLV_DECODER 1 #define CONFIG_FOURXM_DECODER 1 #define CONFIG_FRAPS_DECODER 1 +#define CONFIG_FRWU_DECODER 1 #define CONFIG_GIF_DECODER 1 #define CONFIG_H261_DECODER 1 #define CONFIG_H263_DECODER 1 @@ -223,10 +274,14 @@ #define CONFIG_H264_VDPAU_DECODER 0 #define CONFIG_HUFFYUV_DECODER 1 #define CONFIG_IDCIN_DECODER 1 +#define CONFIG_IFF_BYTERUN1_DECODER 1 +#define CONFIG_IFF_ILBM_DECODER 1 #define CONFIG_INDEO2_DECODER 1 #define CONFIG_INDEO3_DECODER 1 +#define CONFIG_INDEO5_DECODER 1 #define CONFIG_INTERPLAY_VIDEO_DECODER 1 #define CONFIG_JPEGLS_DECODER 1 +#define CONFIG_KGV1_DECODER 1 #define CONFIG_KMVC_DECODER 1 #define CONFIG_LOCO_DECODER 1 #define CONFIG_MDEC_DECODER 1 @@ -239,6 +294,7 @@ #define CONFIG_MPEG1VIDEO_DECODER 1 #define CONFIG_MPEG2VIDEO_DECODER 1 #define CONFIG_MPEG4_DECODER 1 +#define CONFIG_MPEG4_VDPAU_DECODER 0 #define CONFIG_MPEGVIDEO_DECODER 1 #define CONFIG_MPEG_VDPAU_DECODER 0 #define CONFIG_MPEG1_VDPAU_DECODER 0 @@ -260,6 +316,7 @@ #define CONFIG_QDRAW_DECODER 1 #define CONFIG_QPEG_DECODER 1 #define CONFIG_QTRLE_DECODER 1 +#define CONFIG_R210_DECODER 1 #define CONFIG_RAWVIDEO_DECODER 1 #define CONFIG_RL2_DECODER 1 #define CONFIG_ROQ_DECODER 1 @@ -308,13 +365,19 @@ #define CONFIG_WNV1_DECODER 1 #define CONFIG_XAN_WC3_DECODER 1 #define CONFIG_XL_DECODER 1 +#define CONFIG_YOP_DECODER 1 #define CONFIG_ZLIB_DECODER 1 #define CONFIG_ZMBV_DECODER 1 #define CONFIG_AAC_DECODER 1 #define CONFIG_AC3_DECODER 1 #define CONFIG_ALAC_DECODER 1 +#define CONFIG_ALS_DECODER 1 +#define CONFIG_AMRNB_DECODER 1 #define CONFIG_APE_DECODER 1 +#define CONFIG_ATRAC1_DECODER 1 #define CONFIG_ATRAC3_DECODER 1 +#define CONFIG_BINKAUDIO_DCT_DECODER 1 +#define CONFIG_BINKAUDIO_RDFT_DECODER 1 #define CONFIG_COOK_DECODER 1 #define CONFIG_DCA_DECODER 1 #define CONFIG_DSICINAUDIO_DECODER 1 @@ -337,18 +400,23 @@ #define CONFIG_RA_144_DECODER 1 #define CONFIG_RA_288_DECODER 1 #define CONFIG_SHORTEN_DECODER 1 +#define CONFIG_SIPR_DECODER 1 #define CONFIG_SMACKAUD_DECODER 1 #define CONFIG_SONIC_DECODER 1 #define CONFIG_TRUEHD_DECODER 1 #define CONFIG_TRUESPEECH_DECODER 1 #define CONFIG_TTA_DECODER 1 +#define CONFIG_TWINVQ_DECODER 1 #define CONFIG_VMDAUDIO_DECODER 1 #define CONFIG_VORBIS_DECODER 1 #define CONFIG_WAVPACK_DECODER 1 +#define CONFIG_WMAPRO_DECODER 1 #define CONFIG_WMAV1_DECODER 1 #define CONFIG_WMAV2_DECODER 1 +#define CONFIG_WMAVOICE_DECODER 1 #define CONFIG_WS_SND1_DECODER 1 #define CONFIG_PCM_ALAW_DECODER 1 +#define CONFIG_PCM_BLURAY_DECODER 1 #define CONFIG_PCM_DVD_DECODER 1 #define CONFIG_PCM_F32BE_DECODER 1 #define CONFIG_PCM_F32LE_DECODER 1 @@ -406,6 +474,7 @@ #define CONFIG_ADPCM_YAMAHA_DECODER 1 #define CONFIG_DVBSUB_DECODER 1 #define CONFIG_DVDSUB_DECODER 1 +#define CONFIG_PGSSUB_DECODER 1 #define CONFIG_XSUB_DECODER 1 #define CONFIG_LIBDIRAC_DECODER 0 #define CONFIG_LIBFAAD_DECODER 0 @@ -416,6 +485,7 @@ #define CONFIG_LIBOPENJPEG_DECODER 0 #define CONFIG_LIBSCHROEDINGER_DECODER 0 #define CONFIG_LIBSPEEX_DECODER 0 +#define CONFIG_LIBVPX_DECODER 0 #define CONFIG_ASV1_ENCODER 0 #define CONFIG_ASV2_ENCODER 0 #define CONFIG_BMP_ENCODER 0 @@ -514,12 +584,17 @@ #define CONFIG_LIBSCHROEDINGER_ENCODER 0 #define CONFIG_LIBTHEORA_ENCODER 0 #define CONFIG_LIBVORBIS_ENCODER 0 +#define CONFIG_LIBVPX_ENCODER 0 #define CONFIG_LIBX264_ENCODER 0 #define CONFIG_LIBXVID_ENCODER 0 #define CONFIG_H263_VAAPI_HWACCEL 0 +#define CONFIG_H264_DXVA2_HWACCEL 0 +#define CONFIG_H264_VAAPI_HWACCEL 0 #define CONFIG_MPEG2_VAAPI_HWACCEL 0 #define CONFIG_MPEG4_VAAPI_HWACCEL 0 +#define CONFIG_VC1_DXVA2_HWACCEL 0 #define CONFIG_VC1_VAAPI_HWACCEL 0 +#define CONFIG_WMV3_DXVA2_HWACCEL 0 #define CONFIG_WMV3_VAAPI_HWACCEL 0 #define CONFIG_AAC_PARSER 1 #define CONFIG_AC3_PARSER 1 @@ -553,8 +628,10 @@ #define CONFIG_TEXT2MOVSUB_BSF 1 #define CONFIG_AAC_DEMUXER 1 #define CONFIG_AC3_DEMUXER 1 +#define CONFIG_AEA_DEMUXER 1 #define CONFIG_AIFF_DEMUXER 1 #define CONFIG_AMR_DEMUXER 1 +#define CONFIG_ANM_DEMUXER 1 #define CONFIG_APC_DEMUXER 1 #define CONFIG_APE_DEMUXER 1 #define CONFIG_ASF_DEMUXER 1 @@ -565,8 +642,11 @@ #define CONFIG_AVS_DEMUXER 1 #define CONFIG_BETHSOFTVID_DEMUXER 1 #define CONFIG_BFI_DEMUXER 1 +#define CONFIG_BINK_DEMUXER 1 #define CONFIG_C93_DEMUXER 1 +#define CONFIG_CAF_DEMUXER 1 #define CONFIG_CAVSVIDEO_DEMUXER 1 +#define CONFIG_CDG_DEMUXER 1 #define CONFIG_DAUD_DEMUXER 1 #define CONFIG_DIRAC_DEMUXER 1 #define CONFIG_DNXHD_DEMUXER 1 @@ -578,6 +658,7 @@ #define CONFIG_EA_CDATA_DEMUXER 1 #define CONFIG_EAC3_DEMUXER 1 #define CONFIG_FFM_DEMUXER 1 +#define CONFIG_FILMSTRIP_DEMUXER 1 #define CONFIG_FLAC_DEMUXER 1 #define CONFIG_FLIC_DEMUXER 1 #define CONFIG_FLV_DEMUXER 1 @@ -594,6 +675,7 @@ #define CONFIG_INGENIENT_DEMUXER 1 #define CONFIG_IPMOVIE_DEMUXER 1 #define CONFIG_ISS_DEMUXER 1 +#define CONFIG_IV8_DEMUXER 1 #define CONFIG_LMLM4_DEMUXER 0 #define CONFIG_M4V_DEMUXER 1 #define CONFIG_MATROSKA_DEMUXER 1 @@ -643,7 +725,6 @@ #define CONFIG_QCP_DEMUXER 0 #define CONFIG_R3D_DEMUXER 1 #define CONFIG_RAWVIDEO_DEMUXER 1 -#define CONFIG_REDIR_DEMUXER 0 #define CONFIG_RL2_DEMUXER 1 #define CONFIG_RM_DEMUXER 1 #define CONFIG_ROQ_DEMUXER 1 @@ -676,6 +757,7 @@ #define CONFIG_WSVQA_DEMUXER 1 #define CONFIG_WV_DEMUXER 1 #define CONFIG_XA_DEMUXER 1 +#define CONFIG_YOP_DEMUXER 1 #define CONFIG_YUV4MPEGPIPE_DEMUXER 1 #define CONFIG_LIBNUT_DEMUXER 0 #define CONFIG_AC3_MUXER 0 @@ -696,6 +778,7 @@ #define CONFIG_DV_MUXER 0 #define CONFIG_EAC3_MUXER 0 #define CONFIG_FFM_MUXER 0 +#define CONFIG_FILMSTRIP_MUXER 0 #define CONFIG_FLAC_MUXER 0 #define CONFIG_FLV_MUXER 0 #define CONFIG_FRAMECRC_MUXER 0 @@ -756,6 +839,7 @@ #define CONFIG_RM_MUXER 0 #define CONFIG_ROQ_MUXER 0 #define CONFIG_RTP_MUXER 0 +#define CONFIG_RTSP_MUXER 0 #define CONFIG_SOX_MUXER 0 #define CONFIG_SPDIF_MUXER 0 #define CONFIG_SWF_MUXER 0 @@ -765,17 +849,34 @@ #define CONFIG_VC1T_MUXER 0 #define CONFIG_VOC_MUXER 0 #define CONFIG_WAV_MUXER 1 +#define CONFIG_WEBM_MUXER 1 #define CONFIG_YUV4MPEGPIPE_MUXER 0 #define CONFIG_LIBNUT_MUXER 0 +#define CONFIG_ASPECT_FILTER 1 #define CONFIG_CROP_FILTER 1 +#define CONFIG_FORMAT_FILTER 1 +#define CONFIG_NOFORMAT_FILTER 1 +#define CONFIG_NULL_FILTER 1 +#define CONFIG_PIXELASPECT_FILTER 1 +#define CONFIG_SCALE_FILTER 1 +#define CONFIG_SLICIFY_FILTER 1 +#define CONFIG_UNSHARP_FILTER 1 +#define CONFIG_VFLIP_FILTER 1 +#define CONFIG_NULLSRC_FILTER 1 +#define CONFIG_NULLSINK_FILTER 1 #define CONFIG_FILE_PROTOCOL 0 #define CONFIG_GOPHER_PROTOCOL 0 #define CONFIG_HTTP_PROTOCOL 0 #define CONFIG_PIPE_PROTOCOL 0 #define CONFIG_RTMP_PROTOCOL 0 +#define CONFIG_RTMPT_PROTOCOL 0 +#define CONFIG_RTMPE_PROTOCOL 0 +#define CONFIG_RTMPTE_PROTOCOL 0 +#define CONFIG_RTMPS_PROTOCOL 0 #define CONFIG_RTP_PROTOCOL 0 #define CONFIG_TCP_PROTOCOL 0 #define CONFIG_UDP_PROTOCOL 0 +#define CONFIG_CONCAT_PROTOCOL 0 #define CONFIG_ALSA_INDEV 0 #define CONFIG_AUDIO_BEOS_INDEV 0 #define CONFIG_BKTR_INDEV 0 @@ -790,7 +891,4 @@ #define CONFIG_ALSA_OUTDEV 0 #define CONFIG_AUDIO_BEOS_OUTDEV 0 #define CONFIG_OSS_OUTDEV 0 -#define restrict __restrict__ -#define ASMALIGN(ZEROBITS) ".align 1 << " #ZEROBITS "\n\t" -#define EXTERN_PREFIX "" #endif /* FFMPEG_CONFIG_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/4xm.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/4xm.c index 9bd026b5a2..219850302c 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/4xm.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/4xm.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/4xm.c + * @file * 4XM codec. */ @@ -137,7 +137,7 @@ typedef struct FourXContext{ int mv[256]; VLC pre_vlc; int last_dc; - DECLARE_ALIGNED_8(DCTELEM, block[6][64]); + DECLARE_ALIGNED(16, DCTELEM, block)[6][64]; void *bitstream_buffer; unsigned int bitstream_buffer_size; int version; @@ -815,7 +815,7 @@ static av_cold int decode_init(AVCodecContext *avctx){ init_vlcs(f); if(f->version>2) avctx->pix_fmt= PIX_FMT_RGB565; - else avctx->pix_fmt= PIX_FMT_RGB555; + else avctx->pix_fmt= PIX_FMT_BGR555; return 0; } @@ -832,13 +832,17 @@ static av_cold int decode_end(AVCodecContext *avctx){ f->cfrm[i].allocated_size= 0; } free_vlc(&f->pre_vlc); + if(f->current_picture.data[0]) + avctx->release_buffer(avctx, &f->current_picture); + if(f->last_picture.data[0]) + avctx->release_buffer(avctx, &f->last_picture); return 0; } AVCodec fourxm_decoder = { "4xm", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_4XM, sizeof(FourXContext), decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/8bps.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/8bps.c index 28187b0360..ff5795533b 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/8bps.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/8bps.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/8bps.c + * @file * QT 8BPS Video Decoder by Roberto Togni * For more information about the 8BPS format, visit: * http://www.pcisys.net/~melanson/codecs/ @@ -159,10 +159,6 @@ static av_cold int decode_init(AVCodecContext *avctx) c->pic.data[0] = NULL; - if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) { - return 1; - } - switch (avctx->bits_per_coded_sample) { case 8: avctx->pix_fmt = PIX_FMT_PAL8; @@ -225,7 +221,7 @@ static av_cold int decode_end(AVCodecContext *avctx) AVCodec eightbps_decoder = { "8bps", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_8BPS, sizeof(EightBpsContext), decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/8svx.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/8svx.c index c139e5d40b..6e09b11e03 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/8svx.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/8svx.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/8svx.c + * @file * 8svx audio decoder * @author Jaikrishnan Menon * supports: fibonacci delta encoding @@ -94,7 +94,7 @@ static av_cold int eightsvx_decode_init(AVCodecContext *avctx) AVCodec eightsvx_fib_decoder = { .name = "8svx_fib", - .type = CODEC_TYPE_AUDIO, + .type = AVMEDIA_TYPE_AUDIO, .id = CODEC_ID_8SVX_FIB, .priv_data_size = sizeof (EightSvxContext), .init = eightsvx_decode_init, @@ -104,7 +104,7 @@ AVCodec eightsvx_fib_decoder = { AVCodec eightsvx_exp_decoder = { .name = "8svx_exp", - .type = CODEC_TYPE_AUDIO, + .type = AVMEDIA_TYPE_AUDIO, .id = CODEC_ID_8SVX_EXP, .priv_data_size = sizeof (EightSvxContext), .init = eightsvx_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/Jamfile b/src/add-ons/media/plugins/ffmpeg/libavcodec/Jamfile index 0ee38df9e5..0568c5bdec 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/Jamfile +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/Jamfile @@ -23,6 +23,7 @@ StaticLibrary libavcodec.a : aac_ac3_parser.c aac_adtstoasc_bsf.c aac_parser.c + aacsbr.c aactab.c aandcttab.c aasc.c @@ -39,15 +40,26 @@ StaticLibrary libavcodec.a : adxdec.c alac.c allcodecs.c + alsdec.c + amrnbdec.c + anm.c apedec.c asv1.c + atrac.c + atrac1.c atrac3.c audioconvert.c + aura.c + avfft.c avpacket.c avs.c beosthread.c bethsoftvideo.c + bgmc.c bfi.c + bink.c + binkaudio.c + binkidct.c bitstream.c bitstream_filter.c bmp.c @@ -57,15 +69,21 @@ StaticLibrary libavcodec.a : cavs_parser.c cavsdec.c cavsdsp.c +# cbrt_tablegen.c + cdgraphics.c celp_filters.c celp_math.c cinepak.c cljr.c cook.c +# costablegen.c cscd.c cyuv.c dca.c dca_parser.c + dcadsp.c + dct.c + dirac.c dirac_parser.c dnxhd_parser.c dnxhddata.c @@ -75,12 +93,18 @@ StaticLibrary libavcodec.a : dsputil.c dump_extradata_bsf.c dv.c +# dv_tablegen.c dvbsub.c dvbsub_parser.c dvbsubdec.c + dvdata.c dvdsub_parser.c dvdsubdec.c + dwt.c dxa.c +# dxva2.c +# dxva2_h264.c +# dxva2_vc1.c eac3dec.c eac3dec_data.c eacmv.c @@ -103,7 +127,10 @@ StaticLibrary libavcodec.a : flacdec.c flashsv.c flicvideo.c + flvenc.c + flvdec.c fraps.c + frwu.c g726.c # g729dec.c gif.c @@ -116,27 +143,43 @@ StaticLibrary libavcodec.a : h263_parser.c h263dec.c h264.c + h264_cabac.c + h264_cavlc.c + h264_direct.c + h264_loopfilter.c h264_mp4toannexb_bsf.c h264_parser.c + h264_ps.c + h264_refs.c + h264_sei.c + h264dsp.c # h264dspenc.c h264idct.c h264pred.c huffman.c huffyuv.c idcinvideo.c + iff.c imc.c imgconvert.c imx_dump_header_bsf.c indeo2.c indeo3.c + indeo5.c + intelh263dec.c interplayvideo.c intrax8.c intrax8dsp.c + ituh263dec.c + ituh263enc.c + ivi_common.c + ivi_dsp.c jfdctfst.c jfdctint.c jpegls.c jpeglsdec.c jrevdct.c + kgv1dec.c kmvc.c lcldec.c # lclenc.c @@ -148,6 +191,7 @@ StaticLibrary libavcodec.a : # lzwenc.c mace.c mdct.c +# mdct_tablegen.c mdec.c mimic.c mjpeg.c @@ -163,6 +207,7 @@ StaticLibrary libavcodec.a : mmvideo.c motion_est.c motionpixels.c +# motionpixels_tablegen.c movsub_bsf.c mp3_header_compress_bsf.c mp3_header_decompress_bsf.c @@ -170,12 +215,16 @@ StaticLibrary libavcodec.a : mpc7.c mpc8.c mpeg4audio.c + mpeg4video.c mpeg4video_parser.c + mpeg4videoenc.c + mpeg4videodec.c mpeg12.c mpeg12data.c mpeg12enc.c mpegaudio.c mpegaudio_parser.c +# mpegaudio_tablegen.c mpegaudiodata.c mpegaudiodec.c mpegaudiodecheader.c @@ -195,21 +244,28 @@ StaticLibrary libavcodec.a : nuv.c opt.c options.c + pamenc.c parser.c pcm.c + pcm-mpeg.c +# pcm_tablegen.c pcx.c + pgssubdec.c png.c pngdec.c pnm.c pnm_parser.c + pnmdec.c # pnmenc.c pthread.c ptx.c qcelpdec.c qdm2.c +# qdm2_tablegen.c qdrw.c qpeg.c qtrle.c + r210dec.c ra144.c ra288.c rangecoder.c @@ -239,15 +295,19 @@ StaticLibrary libavcodec.a : sgidec.c shorten.c simple_idct.c + sipr.c + sipr16k.c smacker.c smc.c -# snow.c + snow.c sonic.c sp5xdec.c sunrast.c svq1.c svq1dec.c -# svq3.c - Included by h264 + svq3.c + synth_filter.c + tableprint.c targa.c tiertexseqv.c tiff.c @@ -257,9 +317,11 @@ StaticLibrary libavcodec.a : truespeech.c tscc.c tta.c + twinvq.c txd.c ulti.c utils.c +# vaapi_h264.c vb.c vc1.c vc1dec.c @@ -278,12 +340,15 @@ StaticLibrary libavcodec.a : vp5.c vp56.c vp56data.c + vp56dsp.c vp6.c vp6dsp.c vqavideo.c wavpack.c wma.c wmadec.c + wmaprodec.c + wmavoice.c wmv2.c wmv2dec.c wnv1.c @@ -292,6 +357,7 @@ StaticLibrary libavcodec.a : xiph.c xl.c xsubdec.c + yop.c zmbv.c ; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/aac.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/aac.c index 8f9249d7f3..3330e1cefe 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/aac.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/aac.c @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/aac.c + * @file * AAC decoder * @author Oded Shimon ( ods15 ods15 dyndns org ) * @author Maxim Gavrilov ( maxim.gavrilov gmail com ) @@ -62,7 +62,7 @@ * N MIDI * N Harmonic and Individual Lines plus Noise * N Text-To-Speech Interface - * N (in progress) Spectral Band Replication + * Y Spectral Band Replication * Y (not in this code) Layer-1 * Y (not in this code) Layer-2 * Y (not in this code) Layer-3 @@ -80,11 +80,15 @@ #include "internal.h" #include "get_bits.h" #include "dsputil.h" +#include "fft.h" #include "lpc.h" #include "aac.h" #include "aactab.h" #include "aacdectab.h" +#include "cbrt_tablegen.h" +#include "sbr.h" +#include "aacsbr.h" #include "mpeg4audio.h" #include "aac_parser.h" @@ -93,6 +97,10 @@ #include #include +#if ARCH_ARM +# include "arm/aac.h" +#endif + union float754 { float f; uint32_t i; @@ -101,10 +109,10 @@ union float754 { static VLC vlc_scalefactors; static VLC vlc_spectral[11]; +static const char overread_err[] = "Input buffer exhausted before END element found\n"; static ChannelElement *get_che(AACContext *ac, int type, int elem_id) { - static const int8_t tags_per_config[16] = { 0, 1, 1, 2, 3, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0 }; if (ac->tag_che_map[type][elem_id]) { return ac->tag_che_map[type][elem_id]; } @@ -153,6 +161,41 @@ 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 FFmpeg channel layout. + * + * @param che_pos current channel position configuration + * @param type channel element type + * @param id channel element id + * @param channels count of the number of channels in the configuration + * + * @return Returns error status. 0 - OK, !0 - error + */ +static av_cold int che_configure(AACContext *ac, + enum ChannelPosition che_pos[4][MAX_ELEM_ID], + int type, int id, + int *channels) +{ + if (che_pos[type][id]) { + if (!ac->che[type][id] && !(ac->che[type][id] = av_mallocz(sizeof(ChannelElement)))) + return AVERROR(ENOMEM); + ff_aac_sbr_ctx_init(&ac->che[type][id]->sbr); + if (type != TYPE_CCE) { + ac->output_data[(*channels)++] = ac->che[type][id]->ch[0].ret; + if (type == TYPE_CPE) { + ac->output_data[(*channels)++] = ac->che[type][id]->ch[1].ret; + } + } + } else { + if (ac->che[type][id]) + ff_aac_sbr_ctx_close(&ac->che[type][id]->sbr); + av_freep(&ac->che[type][id]); + } + return 0; +} + /** * Configure output channel order based on the current program configuration element. * @@ -161,52 +204,55 @@ static ChannelElement *get_che(AACContext *ac, int type, int elem_id) * * @return Returns error status. 0 - OK, !0 - error */ -static int output_configure(AACContext *ac, +static av_cold int output_configure(AACContext *ac, enum ChannelPosition che_pos[4][MAX_ELEM_ID], enum ChannelPosition new_che_pos[4][MAX_ELEM_ID], - int channel_config) + int channel_config, enum OCStatus oc_type) { AVCodecContext *avctx = ac->avccontext; - int i, type, channels = 0; + int i, type, channels = 0, ret; memcpy(che_pos, new_che_pos, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0])); - /* Allocate or free elements depending on if they are in the - * current program configuration. - * - * Set up default 1:1 output mapping. - * - * For a 5.1 stream the output order will be: - * [ Center ] [ Front Left ] [ Front Right ] [ LFE ] [ Surround Left ] [ Surround Right ] - */ - - for (i = 0; i < MAX_ELEM_ID; i++) { - for (type = 0; type < 4; type++) { - if (che_pos[type][i]) { - if (!ac->che[type][i] && !(ac->che[type][i] = av_mallocz(sizeof(ChannelElement)))) - return AVERROR(ENOMEM); - if (type != TYPE_CCE) { - ac->output_data[channels++] = ac->che[type][i]->ch[0].ret; - if (type == TYPE_CPE) { - ac->output_data[channels++] = ac->che[type][i]->ch[1].ret; - } - } - } else - av_freep(&ac->che[type][i]); - } - } - if (channel_config) { + for (i = 0; i < tags_per_config[channel_config]; i++) { + if ((ret = che_configure(ac, che_pos, + aac_channel_layout_map[channel_config - 1][i][0], + aac_channel_layout_map[channel_config - 1][i][1], + &channels))) + return ret; + } + memset(ac->tag_che_map, 0, 4 * MAX_ELEM_ID * sizeof(ac->che[0][0])); ac->tags_mapped = 0; + + avctx->channel_layout = aac_channel_layout[channel_config - 1]; } else { + /* Allocate or free elements depending on if they are in the + * current program configuration. + * + * Set up default 1:1 output mapping. + * + * For a 5.1 stream the output order will be: + * [ Center ] [ Front Left ] [ Front Right ] [ LFE ] [ Surround Left ] [ Surround Right ] + */ + + for (i = 0; i < MAX_ELEM_ID; i++) { + for (type = 0; type < 4; type++) { + if ((ret = che_configure(ac, che_pos, type, i, &channels))) + return ret; + } + } + memcpy(ac->tag_che_map, ac->che, 4 * MAX_ELEM_ID * sizeof(ac->che[0][0])); ac->tags_mapped = 4 * MAX_ELEM_ID; + + avctx->channel_layout = 0; } avctx->channels = channels; - ac->output_configured = 1; + ac->output_configured = oc_type; return 0; } @@ -240,6 +286,7 @@ static int decode_pce(AACContext *ac, enum ChannelPosition new_che_pos[4][MAX_EL GetBitContext *gb) { int num_front, num_side, num_back, num_lfe, num_assoc_data, num_cc, sampling_index; + int comment_len; skip_bits(gb, 2); // object_type @@ -274,7 +321,12 @@ static int decode_pce(AACContext *ac, enum ChannelPosition new_che_pos[4][MAX_EL align_get_bits(gb); /* comment field, first byte is length */ - skip_bits_long(gb, 8 * get_bits(gb, 8)); + comment_len = get_bits(gb, 8) * 8; + if (get_bits_left(gb) < comment_len) { + av_log(ac->avccontext, AV_LOG_ERROR, overread_err); + return -1; + } + skip_bits_long(gb, comment_len); return 0; } @@ -286,7 +338,7 @@ static int decode_pce(AACContext *ac, enum ChannelPosition new_che_pos[4][MAX_EL * * @return Returns error status. 0 - OK, !0 - error */ -static int set_default_channel_config(AACContext *ac, +static av_cold int set_default_channel_config(AACContext *ac, enum ChannelPosition new_che_pos[4][MAX_ELEM_ID], int channel_config) { @@ -357,7 +409,7 @@ static int decode_ga_specific_config(AACContext *ac, GetBitContext *gb, if ((ret = set_default_channel_config(ac, new_che_pos, channel_config))) return ret; } - if ((ret = output_configure(ac, ac->che_pos, new_che_pos, channel_config))) + if ((ret = output_configure(ac, ac->che_pos, new_che_pos, channel_config, OC_GLOBAL_HDR))) return ret; if (extension_flag) { @@ -432,7 +484,7 @@ static av_always_inline int lcg_random(int previous_val) return previous_val * 1664525 + 1013904223; } -static void reset_predict_state(PredictorState *ps) +static av_always_inline void reset_predict_state(PredictorState *ps) { ps->r0 = 0.0f; ps->r1 = 0.0f; @@ -462,29 +514,28 @@ static av_cold int aac_decode_init(AVCodecContext *avccontext) int i; ac->avccontext = avccontext; + ac->m4ac.sample_rate = avccontext->sample_rate; if (avccontext->extradata_size > 0) { if (decode_audio_specific_config(ac, avccontext->extradata, avccontext->extradata_size)) return -1; - avccontext->sample_rate = ac->m4ac.sample_rate; - } else if (avccontext->channels > 0) { - ac->m4ac.sample_rate = avccontext->sample_rate; } avccontext->sample_fmt = SAMPLE_FMT_S16; - avccontext->frame_size = 1024; - AAC_INIT_VLC_STATIC( 0, 144); - AAC_INIT_VLC_STATIC( 1, 114); - AAC_INIT_VLC_STATIC( 2, 188); - AAC_INIT_VLC_STATIC( 3, 180); - AAC_INIT_VLC_STATIC( 4, 172); - AAC_INIT_VLC_STATIC( 5, 140); - AAC_INIT_VLC_STATIC( 6, 168); - AAC_INIT_VLC_STATIC( 7, 114); - AAC_INIT_VLC_STATIC( 8, 262); - AAC_INIT_VLC_STATIC( 9, 248); - AAC_INIT_VLC_STATIC(10, 384); + AAC_INIT_VLC_STATIC( 0, 304); + AAC_INIT_VLC_STATIC( 1, 270); + AAC_INIT_VLC_STATIC( 2, 550); + AAC_INIT_VLC_STATIC( 3, 300); + AAC_INIT_VLC_STATIC( 4, 328); + AAC_INIT_VLC_STATIC( 5, 294); + AAC_INIT_VLC_STATIC( 6, 306); + AAC_INIT_VLC_STATIC( 7, 268); + AAC_INIT_VLC_STATIC( 8, 510); + AAC_INIT_VLC_STATIC( 9, 366); + AAC_INIT_VLC_STATIC(10, 462); + + ff_aac_sbr_init(); dsputil_init(&ac->dsp, avccontext); @@ -494,7 +545,7 @@ static av_cold int aac_decode_init(AVCodecContext *avccontext) // 32768 - Required to scale values to the correct range for the bias method // for float to int16 conversion. - if (ac->dsp.float_to_int16 == ff_float_to_int16_c) { + if (ac->dsp.float_to_int16_interleave == ff_float_to_int16_interleave_c) { ac->add_bias = 385.0f; ac->sf_scale = 1. / (-1024. * 32768.); ac->sf_offset = 0; @@ -519,8 +570,10 @@ static av_cold int aac_decode_init(AVCodecContext *avccontext) // window initialization ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024); ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128); - ff_sine_window_init(ff_sine_1024, 1024); - ff_sine_window_init(ff_sine_128, 128); + ff_init_ff_sine_windows(10); + ff_init_ff_sine_windows( 7); + + cbrt_tableinit(); return 0; } @@ -528,7 +581,7 @@ static av_cold int aac_decode_init(AVCodecContext *avccontext) /** * Skip data_stream_element; reference: table 4.10. */ -static void skip_data_stream_element(GetBitContext *gb) +static int skip_data_stream_element(AACContext *ac, GetBitContext *gb) { int byte_align = get_bits1(gb); int count = get_bits(gb, 8); @@ -536,7 +589,13 @@ static void skip_data_stream_element(GetBitContext *gb) count += get_bits(gb, 8); if (byte_align) align_get_bits(gb); + + if (get_bits_left(gb) < 8 * count) { + av_log(ac->avccontext, AV_LOG_ERROR, overread_err); + return -1; + } skip_bits_long(gb, 8 * count); + return 0; } static int decode_prediction(AACContext *ac, IndividualChannelStream *ics, @@ -645,7 +704,7 @@ static int decode_band_types(AACContext *ac, enum BandType band_type[120], for (g = 0; g < ics->num_window_groups; g++) { int k = 0; while (k < ics->max_sfb) { - uint8_t sect_len = k; + uint8_t sect_end = k; int sect_len_incr; int sect_band_type = get_bits(gb, 4); if (sect_band_type == 12) { @@ -653,17 +712,21 @@ static int decode_band_types(AACContext *ac, enum BandType band_type[120], return -1; } while ((sect_len_incr = get_bits(gb, bits)) == (1 << bits) - 1) - sect_len += sect_len_incr; - sect_len += sect_len_incr; - if (sect_len > ics->max_sfb) { - av_log(ac->avccontext, AV_LOG_ERROR, - "Number of bands (%d) exceeds limit (%d).\n", - sect_len, ics->max_sfb); + sect_end += sect_len_incr; + sect_end += sect_len_incr; + if (get_bits_left(gb) < 0) { + av_log(ac->avccontext, AV_LOG_ERROR, overread_err); return -1; } - for (; k < sect_len; k++) { + if (sect_end > ics->max_sfb) { + av_log(ac->avccontext, AV_LOG_ERROR, + "Number of bands (%d) exceeds limit (%d).\n", + sect_end, ics->max_sfb); + return -1; + } + for (; k < sect_end; k++) { band_type [idx] = sect_band_type; - band_type_run_end[idx++] = sect_len; + band_type_run_end[idx++] = sect_end; } } } @@ -781,7 +844,7 @@ static int decode_tns(AACContext *ac, TemporalNoiseShaping *tns, tns->length[w][filt] = get_bits(gb, 6 - 2 * is8); if ((tns->order[w][filt] = get_bits(gb, 5 - 2 * is8)) > tns_max_order) { - av_log(ac->avccontext, AV_LOG_ERROR, "TNS filter order %d is greater than maximum %d.", + av_log(ac->avccontext, AV_LOG_ERROR, "TNS filter order %d is greater than maximum %d.\n", tns->order[w][filt], tns_max_order); tns->order[w][filt] = 0; return -1; @@ -820,6 +883,74 @@ static void decode_mid_side_stereo(ChannelElement *cpe, GetBitContext *gb, } } +#ifndef VMUL2 +static inline float *VMUL2(float *dst, const float *v, unsigned idx, + const float *scale) +{ + float s = *scale; + *dst++ = v[idx & 15] * s; + *dst++ = v[idx>>4 & 15] * s; + return dst; +} +#endif + +#ifndef VMUL4 +static inline float *VMUL4(float *dst, const float *v, unsigned idx, + const float *scale) +{ + float s = *scale; + *dst++ = v[idx & 3] * s; + *dst++ = v[idx>>2 & 3] * s; + *dst++ = v[idx>>4 & 3] * s; + *dst++ = v[idx>>6 & 3] * s; + return dst; +} +#endif + +#ifndef VMUL2S +static inline float *VMUL2S(float *dst, const float *v, unsigned idx, + unsigned sign, const float *scale) +{ + union float754 s0, s1; + + s0.f = s1.f = *scale; + s0.i ^= sign >> 1 << 31; + s1.i ^= sign << 31; + + *dst++ = v[idx & 15] * s0.f; + *dst++ = v[idx>>4 & 15] * s1.f; + + return dst; +} +#endif + +#ifndef VMUL4S +static inline float *VMUL4S(float *dst, const float *v, unsigned idx, + unsigned sign, const float *scale) +{ + unsigned nz = idx >> 12; + union float754 s = { .f = *scale }; + union float754 t; + + t.i = s.i ^ (sign & 1<<31); + *dst++ = v[idx & 3] * t.f; + + sign <<= nz & 1; nz >>= 1; + t.i = s.i ^ (sign & 1<<31); + *dst++ = v[idx>>2 & 3] * t.f; + + sign <<= nz & 1; nz >>= 1; + t.i = s.i ^ (sign & 1<<31); + *dst++ = v[idx>>4 & 3] * t.f; + + sign <<= nz & 1; nz >>= 1; + t.i = s.i ^ (sign & 1<<31); + *dst++ = v[idx>>6 & 3] * t.f; + + return dst; +} +#endif + /** * Decode spectral data; reference: table 4.50. * Dequantize and scale spectral data; reference: 4.6.3.3. @@ -833,7 +964,7 @@ static void decode_mid_side_stereo(ChannelElement *cpe, GetBitContext *gb, * @return Returns error status. 0 - OK, !0 - error */ static int decode_spectrum_and_dequant(AACContext *ac, float coef[1024], - GetBitContext *gb, float sf[120], + GetBitContext *gb, const float sf[120], int pulse_present, const Pulse *pulse, const IndividualChannelStream *ics, enum BandType band_type[120]) @@ -842,103 +973,228 @@ static int decode_spectrum_and_dequant(AACContext *ac, float coef[1024], const int c = 1024 / ics->num_windows; const uint16_t *offsets = ics->swb_offset; float *coef_base = coef; - static const float sign_lookup[] = { 1.0f, -1.0f }; + int err_idx; for (g = 0; g < ics->num_windows; g++) memset(coef + g * 128 + offsets[ics->max_sfb], 0, sizeof(float) * (c - offsets[ics->max_sfb])); for (g = 0; g < ics->num_window_groups; g++) { + unsigned g_len = ics->group_len[g]; + for (i = 0; i < ics->max_sfb; i++, idx++) { - const int cur_band_type = band_type[idx]; - const int dim = cur_band_type >= FIRST_PAIR_BT ? 2 : 4; - const int is_cb_unsigned = IS_CODEBOOK_UNSIGNED(cur_band_type); + const unsigned cbt_m1 = band_type[idx] - 1; + float *cfo = coef + offsets[i]; + int off_len = offsets[i + 1] - offsets[i]; int group; - if (cur_band_type == ZERO_BT || cur_band_type == INTENSITY_BT2 || cur_band_type == INTENSITY_BT) { - for (group = 0; group < ics->group_len[g]; group++) { - memset(coef + group * 128 + offsets[i], 0, (offsets[i + 1] - offsets[i]) * sizeof(float)); + + if (cbt_m1 >= INTENSITY_BT2 - 1) { + for (group = 0; group < g_len; group++, cfo+=128) { + memset(cfo, 0, off_len * sizeof(float)); } - } else if (cur_band_type == NOISE_BT) { - for (group = 0; group < ics->group_len[g]; group++) { + } else if (cbt_m1 == NOISE_BT - 1) { + for (group = 0; group < g_len; group++, cfo+=128) { float scale; - float band_energy = 0; - for (k = offsets[i]; k < offsets[i + 1]; k++) { + float band_energy; + + for (k = 0; k < off_len; k++) { ac->random_state = lcg_random(ac->random_state); - coef[group * 128 + k] = ac->random_state; - band_energy += coef[group * 128 + k] * coef[group * 128 + k]; + cfo[k] = ac->random_state; } + + band_energy = ac->dsp.scalarproduct_float(cfo, cfo, off_len); scale = sf[idx] / sqrtf(band_energy); - for (k = offsets[i]; k < offsets[i + 1]; k++) { - coef[group * 128 + k] *= scale; - } + ac->dsp.vector_fmul_scalar(cfo, cfo, scale, off_len); } } else { - for (group = 0; group < ics->group_len[g]; group++) { - for (k = offsets[i]; k < offsets[i + 1]; k += dim) { - const int index = get_vlc2(gb, vlc_spectral[cur_band_type - 1].table, 6, 3); - const int coef_tmp_idx = (group << 7) + k; - const float *vq_ptr; - int j; - if (index >= ff_aac_spectral_sizes[cur_band_type - 1]) { - av_log(ac->avccontext, AV_LOG_ERROR, - "Read beyond end of ff_aac_codebook_vectors[%d][]. index %d >= %d\n", - cur_band_type - 1, index, ff_aac_spectral_sizes[cur_band_type - 1]); - return -1; - } - vq_ptr = &ff_aac_codebook_vectors[cur_band_type - 1][index * dim]; - if (is_cb_unsigned) { - if (vq_ptr[0]) - coef[coef_tmp_idx ] = sign_lookup[get_bits1(gb)]; - if (vq_ptr[1]) - coef[coef_tmp_idx + 1] = sign_lookup[get_bits1(gb)]; - if (dim == 4) { - if (vq_ptr[2]) - coef[coef_tmp_idx + 2] = sign_lookup[get_bits1(gb)]; - if (vq_ptr[3]) - coef[coef_tmp_idx + 3] = sign_lookup[get_bits1(gb)]; + const float *vq = ff_aac_codebook_vector_vals[cbt_m1]; + const uint16_t *cb_vector_idx = ff_aac_codebook_vector_idx[cbt_m1]; + VLC_TYPE (*vlc_tab)[2] = vlc_spectral[cbt_m1].table; + const int cb_size = ff_aac_spectral_sizes[cbt_m1]; + OPEN_READER(re, gb); + + switch (cbt_m1 >> 1) { + case 0: + for (group = 0; group < g_len; group++, cfo+=128) { + float *cf = cfo; + int len = off_len; + + do { + int code; + unsigned cb_idx; + + UPDATE_CACHE(re, gb); + GET_VLC(code, re, gb, vlc_tab, 8, 2); + + if (code >= cb_size) { + err_idx = code; + goto err_cb_overflow; } - if (cur_band_type == ESC_BT) { - for (j = 0; j < 2; j++) { - if (vq_ptr[j] == 64.0f) { - int n = 4; - /* The total length of escape_sequence must be < 22 bits according - to the specification (i.e. max is 11111111110xxxxxxxxxx). */ - while (get_bits1(gb) && n < 15) n++; - if (n == 15) { - av_log(ac->avccontext, AV_LOG_ERROR, "error in spectral data, ESC overflow\n"); - return -1; - } - n = (1 << n) + get_bits(gb, n); - coef[coef_tmp_idx + j] *= cbrtf(n) * n; - } else - coef[coef_tmp_idx + j] *= vq_ptr[j]; - } - } else { - coef[coef_tmp_idx ] *= vq_ptr[0]; - coef[coef_tmp_idx + 1] *= vq_ptr[1]; - if (dim == 4) { - coef[coef_tmp_idx + 2] *= vq_ptr[2]; - coef[coef_tmp_idx + 3] *= vq_ptr[3]; + + cb_idx = cb_vector_idx[code]; + cf = VMUL4(cf, vq, cb_idx, sf + idx); + } while (len -= 4); + } + break; + + case 1: + for (group = 0; group < g_len; group++, cfo+=128) { + float *cf = cfo; + int len = off_len; + + do { + int code; + unsigned nnz; + unsigned cb_idx; + uint32_t bits; + + UPDATE_CACHE(re, gb); + GET_VLC(code, re, gb, vlc_tab, 8, 2); + + if (code >= cb_size) { + err_idx = code; + goto err_cb_overflow; + } + +#if MIN_CACHE_BITS < 20 + UPDATE_CACHE(re, gb); +#endif + cb_idx = cb_vector_idx[code]; + nnz = cb_idx >> 8 & 15; + bits = SHOW_UBITS(re, gb, nnz) << (32-nnz); + LAST_SKIP_BITS(re, gb, nnz); + cf = VMUL4S(cf, vq, cb_idx, bits, sf + idx); + } while (len -= 4); + } + break; + + case 2: + for (group = 0; group < g_len; group++, cfo+=128) { + float *cf = cfo; + int len = off_len; + + do { + int code; + unsigned cb_idx; + + UPDATE_CACHE(re, gb); + GET_VLC(code, re, gb, vlc_tab, 8, 2); + + if (code >= cb_size) { + err_idx = code; + goto err_cb_overflow; + } + + cb_idx = cb_vector_idx[code]; + cf = VMUL2(cf, vq, cb_idx, sf + idx); + } while (len -= 2); + } + break; + + case 3: + case 4: + for (group = 0; group < g_len; group++, cfo+=128) { + float *cf = cfo; + int len = off_len; + + do { + int code; + unsigned nnz; + unsigned cb_idx; + unsigned sign; + + UPDATE_CACHE(re, gb); + GET_VLC(code, re, gb, vlc_tab, 8, 2); + + if (code >= cb_size) { + err_idx = code; + goto err_cb_overflow; + } + + cb_idx = cb_vector_idx[code]; + nnz = cb_idx >> 8 & 15; + sign = SHOW_UBITS(re, gb, nnz) << (cb_idx >> 12); + LAST_SKIP_BITS(re, gb, nnz); + cf = VMUL2S(cf, vq, cb_idx, sign, sf + idx); + } while (len -= 2); + } + break; + + default: + for (group = 0; group < g_len; group++, cfo+=128) { + float *cf = cfo; + uint32_t *icf = (uint32_t *) cf; + int len = off_len; + + do { + int code; + unsigned nzt, nnz; + unsigned cb_idx; + uint32_t bits; + int j; + + UPDATE_CACHE(re, gb); + GET_VLC(code, re, gb, vlc_tab, 8, 2); + + if (!code) { + *icf++ = 0; + *icf++ = 0; + continue; + } + + if (code >= cb_size) { + err_idx = code; + goto err_cb_overflow; + } + + cb_idx = cb_vector_idx[code]; + nnz = cb_idx >> 12; + nzt = cb_idx >> 8; + bits = SHOW_UBITS(re, gb, nnz) << (32-nnz); + LAST_SKIP_BITS(re, gb, nnz); + + for (j = 0; j < 2; j++) { + if (nzt & 1< 8) { + av_log(ac->avccontext, AV_LOG_ERROR, "error in spectral data, ESC overflow\n"); + return -1; + } + +#if MIN_CACHE_BITS < 21 + LAST_SKIP_BITS(re, gb, b + 1); + UPDATE_CACHE(re, gb); +#else + SKIP_BITS(re, gb, b + 1); +#endif + b += 4; + n = (1 << b) + SHOW_UBITS(re, gb, b); + LAST_SKIP_BITS(re, gb, b); + *icf++ = cbrt_tab[n] | (bits & 1<<31); + bits <<= 1; + } else { + unsigned v = ((const uint32_t*)vq)[cb_idx & 15]; + *icf++ = (bits & 1<<31) | v; + bits <<= !!v; } + cb_idx >>= 4; } - } else { - coef[coef_tmp_idx ] = vq_ptr[0]; - coef[coef_tmp_idx + 1] = vq_ptr[1]; - if (dim == 4) { - coef[coef_tmp_idx + 2] = vq_ptr[2]; - coef[coef_tmp_idx + 3] = vq_ptr[3]; - } - } - coef[coef_tmp_idx ] *= sf[idx]; - coef[coef_tmp_idx + 1] *= sf[idx]; - if (dim == 4) { - coef[coef_tmp_idx + 2] *= sf[idx]; - coef[coef_tmp_idx + 3] *= sf[idx]; - } + } while (len -= 2); + + ac->dsp.vector_fmul_scalar(cfo, cfo, sf[idx], off_len); } } + + CLOSE_READER(re, gb); } } - coef += ics->group_len[g] << 7; + coef += g_len << 7; } if (pulse_present) { @@ -958,6 +1214,12 @@ static int decode_spectrum_and_dequant(AACContext *ac, float coef[1024], } } return 0; + +err_cb_overflow: + av_log(ac->avccontext, AV_LOG_ERROR, + "Read beyond end of ff_aac_codebook_vectors[%d][]. index %d >= %d\n", + band_type[idx], err_idx, ff_aac_spectral_sizes[band_type[idx]]); + return -1; } static av_always_inline float flt16_round(float pf) @@ -984,7 +1246,7 @@ static av_always_inline float flt16_trunc(float pf) return pun.f; } -static void predict(AACContext *ac, PredictorState *ps, float *coef, +static av_always_inline void predict(AACContext *ac, PredictorState *ps, float *coef, int output_enable) { const float a = 0.953125; // 61.0 / 64 @@ -1103,23 +1365,21 @@ static int decode_ics(AACContext *ac, SingleChannelElement *sce, /** * Mid/Side stereo decoding; reference: 4.6.8.1.3. */ -static void apply_mid_side_stereo(ChannelElement *cpe) +static void apply_mid_side_stereo(AACContext *ac, ChannelElement *cpe) { const IndividualChannelStream *ics = &cpe->ch[0].ics; float *ch0 = cpe->ch[0].coeffs; float *ch1 = cpe->ch[1].coeffs; - int g, i, k, group, idx = 0; + int g, i, group, idx = 0; const uint16_t *offsets = ics->swb_offset; for (g = 0; g < ics->num_window_groups; g++) { for (i = 0; i < ics->max_sfb; i++, idx++) { if (cpe->ms_mask[idx] && cpe->ch[0].band_type[idx] < NOISE_BT && cpe->ch[1].band_type[idx] < NOISE_BT) { for (group = 0; group < ics->group_len[g]; group++) { - for (k = offsets[i]; k < offsets[i + 1]; k++) { - float tmp = ch0[group * 128 + k] - ch1[group * 128 + k]; - ch0[group * 128 + k] += ch1[group * 128 + k]; - ch1[group * 128 + k] = tmp; - } + ac->dsp.butterflies_float(ch0 + group * 128 + offsets[i], + ch1 + group * 128 + offsets[i], + offsets[i+1] - offsets[i]); } } } @@ -1200,7 +1460,7 @@ static int decode_cpe(AACContext *ac, GetBitContext *gb, ChannelElement *cpe) if (common_window) { if (ms_present) - apply_mid_side_stereo(cpe); + apply_mid_side_stereo(ac, cpe); if (ac->m4ac.object_type == AOT_AAC_MAIN) { apply_prediction(ac, &cpe->ch[0]); apply_prediction(ac, &cpe->ch[1]); @@ -1285,23 +1545,6 @@ static int decode_cce(AACContext *ac, GetBitContext *gb, ChannelElement *che) return 0; } -/** - * Decode Spectral Band Replication extension data; reference: table 4.55. - * - * @param crc flag indicating the presence of CRC checksum - * @param cnt length of TYPE_FIL syntactic element in bytes - * - * @return Returns number of bytes consumed from the TYPE_FIL element. - */ -static int decode_sbr_extension(AACContext *ac, GetBitContext *gb, - int crc, int cnt) -{ - // TODO : sbr_extension implementation - av_log_missing_feature(ac->avccontext, "SBR", 0); - skip_bits_long(gb, 8 * cnt - 4); // -4 due to reading extension type - return cnt; -} - /** * Parse whether channels are to be excluded from Dynamic Range Compression; reference: table 4.53. * @@ -1382,7 +1625,8 @@ static int decode_dynamic_range(DynamicRangeControl *che_drc, * * @return Returns number of bytes consumed */ -static int decode_extension_payload(AACContext *ac, GetBitContext *gb, int cnt) +static int decode_extension_payload(AACContext *ac, GetBitContext *gb, int cnt, + ChannelElement *che, enum RawDataBlockType elem_type) { int crc_flag = 0; int res = cnt; @@ -1390,7 +1634,21 @@ static int decode_extension_payload(AACContext *ac, GetBitContext *gb, int cnt) case EXT_SBR_DATA_CRC: crc_flag++; case EXT_SBR_DATA: - res = decode_sbr_extension(ac, gb, crc_flag, cnt); + if (!che) { + av_log(ac->avccontext, AV_LOG_ERROR, "SBR was found before the first channel element.\n"); + return res; + } else if (!ac->m4ac.sbr) { + av_log(ac->avccontext, AV_LOG_ERROR, "SBR signaled to be not-present but was found in the bitstream.\n"); + skip_bits_long(gb, 8 * cnt - 4); + return res; + } else if (ac->m4ac.sbr == -1 && ac->output_configured == OC_LOCKED) { + av_log(ac->avccontext, AV_LOG_ERROR, "Implicit SBR was found with a first occurrence after the first frame.\n"); + skip_bits_long(gb, 8 * cnt - 4); + return res; + } else { + ac->m4ac.sbr = 1; + } + res = ff_decode_sbr_extension(ac, &che->sbr, gb, crc_flag, cnt, elem_type); break; case EXT_DYNAMIC_RANGE: res = decode_dynamic_range(&ac->che_drc, gb, cnt); @@ -1454,7 +1712,7 @@ static void apply_tns(float coef[1024], TemporalNoiseShaping *tns, /** * Conduct IMDCT and windowing. */ -static void imdct_and_windowing(AACContext *ac, SingleChannelElement *sce) +static void imdct_and_windowing(AACContext *ac, SingleChannelElement *sce, float bias) { IndividualChannelStream *ics = &sce->ics; float *in = sce->coeffs; @@ -1486,29 +1744,29 @@ static void imdct_and_windowing(AACContext *ac, SingleChannelElement *sce) */ if ((ics->window_sequence[1] == ONLY_LONG_SEQUENCE || ics->window_sequence[1] == LONG_STOP_SEQUENCE) && (ics->window_sequence[0] == ONLY_LONG_SEQUENCE || ics->window_sequence[0] == LONG_START_SEQUENCE)) { - ac->dsp.vector_fmul_window( out, saved, buf, lwindow_prev, ac->add_bias, 512); + ac->dsp.vector_fmul_window( out, saved, buf, lwindow_prev, bias, 512); } else { for (i = 0; i < 448; i++) - out[i] = saved[i] + ac->add_bias; + out[i] = saved[i] + bias; if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { - ac->dsp.vector_fmul_window(out + 448 + 0*128, saved + 448, buf + 0*128, swindow_prev, ac->add_bias, 64); - ac->dsp.vector_fmul_window(out + 448 + 1*128, buf + 0*128 + 64, buf + 1*128, swindow, ac->add_bias, 64); - ac->dsp.vector_fmul_window(out + 448 + 2*128, buf + 1*128 + 64, buf + 2*128, swindow, ac->add_bias, 64); - ac->dsp.vector_fmul_window(out + 448 + 3*128, buf + 2*128 + 64, buf + 3*128, swindow, ac->add_bias, 64); - ac->dsp.vector_fmul_window(temp, buf + 3*128 + 64, buf + 4*128, swindow, ac->add_bias, 64); + ac->dsp.vector_fmul_window(out + 448 + 0*128, saved + 448, buf + 0*128, swindow_prev, bias, 64); + ac->dsp.vector_fmul_window(out + 448 + 1*128, buf + 0*128 + 64, buf + 1*128, swindow, bias, 64); + ac->dsp.vector_fmul_window(out + 448 + 2*128, buf + 1*128 + 64, buf + 2*128, swindow, bias, 64); + ac->dsp.vector_fmul_window(out + 448 + 3*128, buf + 2*128 + 64, buf + 3*128, swindow, bias, 64); + ac->dsp.vector_fmul_window(temp, buf + 3*128 + 64, buf + 4*128, swindow, bias, 64); memcpy( out + 448 + 4*128, temp, 64 * sizeof(float)); } else { - ac->dsp.vector_fmul_window(out + 448, saved + 448, buf, swindow_prev, ac->add_bias, 64); + ac->dsp.vector_fmul_window(out + 448, saved + 448, buf, swindow_prev, bias, 64); for (i = 576; i < 1024; i++) - out[i] = buf[i-512] + ac->add_bias; + out[i] = buf[i-512] + bias; } } // buffer update if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { for (i = 0; i < 64; i++) - saved[i] = temp[64 + i] - ac->add_bias; + saved[i] = temp[64 + i] - bias; ac->dsp.vector_fmul_window(saved + 64, buf + 4*128 + 64, buf + 5*128, swindow, 0, 64); ac->dsp.vector_fmul_window(saved + 192, buf + 5*128 + 64, buf + 6*128, swindow, 0, 64); ac->dsp.vector_fmul_window(saved + 320, buf + 6*128 + 64, buf + 7*128, swindow, 0, 64); @@ -1571,8 +1829,9 @@ static void apply_independent_coupling(AACContext *ac, const float bias = ac->add_bias; const float *src = cce->ch[0].ret; float *dest = target->ret; + const int len = 1024 << (ac->m4ac.sbr == 1); - for (i = 0; i < 1024; i++) + for (i = 0; i < len; i++) dest[i] += gain * (src[i] - bias); } @@ -1618,6 +1877,7 @@ static void apply_channel_coupling(AACContext *ac, ChannelElement *cc, static void spectral_to_sample(AACContext *ac) { int i, type; + float imdct_bias = (ac->m4ac.sbr <= 0) ? ac->add_bias : 0.0f; for (type = 3; type >= 0; type--) { for (i = 0; i < MAX_ELEM_ID; i++) { ChannelElement *che = ac->che[type][i]; @@ -1630,10 +1890,15 @@ static void spectral_to_sample(AACContext *ac) apply_tns(che->ch[1].coeffs, &che->ch[1].tns, &che->ch[1].ics, 1); if (type <= TYPE_CPE) apply_channel_coupling(ac, che, type, i, BETWEEN_TNS_AND_IMDCT, apply_dependent_coupling); - if (type != TYPE_CCE || che->coup.coupling_point == AFTER_IMDCT) - imdct_and_windowing(ac, &che->ch[0]); - if (type == TYPE_CPE) - imdct_and_windowing(ac, &che->ch[1]); + if (type != TYPE_CCE || che->coup.coupling_point == AFTER_IMDCT) { + imdct_and_windowing(ac, &che->ch[0], imdct_bias); + if (type == TYPE_CPE) { + imdct_and_windowing(ac, &che->ch[1], imdct_bias); + } + if (ac->m4ac.sbr > 0) { + ff_sbr_apply(ac, &che->sbr, type, che->ch[0].ret, che->ch[1].ret); + } + } if (type <= TYPE_CCE) apply_channel_coupling(ac, che, type, i, AFTER_IMDCT, apply_independent_coupling); } @@ -1648,18 +1913,24 @@ static int parse_adts_frame_header(AACContext *ac, GetBitContext *gb) size = ff_aac_parse_header(gb, &hdr_info); if (size > 0) { - if (!ac->output_configured && hdr_info.chan_config) { + if (ac->output_configured != OC_LOCKED && 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; if (set_default_channel_config(ac, new_che_pos, hdr_info.chan_config)) return -7; - if (output_configure(ac, ac->che_pos, new_che_pos, 1)) + if (output_configure(ac, ac->che_pos, new_che_pos, hdr_info.chan_config, OC_TRIAL_FRAME)) return -7; + } else if (ac->output_configured != OC_LOCKED) { + ac->output_configured = OC_NONE; } + if (ac->output_configured != OC_LOCKED) + ac->m4ac.sbr = -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; + if (!ac->avccontext->sample_rate) + ac->avccontext->sample_rate = hdr_info.sample_rate; if (hdr_info.num_aac_frames == 1) { if (!hdr_info.crc_absent) skip_bits(gb, 16); @@ -1677,10 +1948,13 @@ static int aac_decode_frame(AVCodecContext *avccontext, void *data, const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; AACContext *ac = avccontext->priv_data; - ChannelElement *che = NULL; + ChannelElement *che = NULL, *che_prev = NULL; GetBitContext gb; - enum RawDataBlockType elem_type; + enum RawDataBlockType elem_type, elem_type_prev = TYPE_END; int err, elem_id, data_size_tmp; + int buf_consumed; + int samples = 1024, multiplier; + int buf_offset; init_get_bits(&gb, buf, buf_size * 8); @@ -1723,8 +1997,7 @@ static int aac_decode_frame(AVCodecContext *avccontext, void *data, break; case TYPE_DSE: - skip_data_stream_element(&gb); - err = 0; + err = skip_data_stream_element(ac, &gb); break; case TYPE_PCE: { @@ -1732,19 +2005,23 @@ static int aac_decode_frame(AVCodecContext *avccontext, void *data, memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0])); if ((err = decode_pce(ac, new_che_pos, &gb))) break; - if (ac->output_configured) + if (ac->output_configured > OC_TRIAL_PCE) av_log(avccontext, AV_LOG_ERROR, "Not evaluating a further program_config_element as this construct is dubious at best.\n"); else - err = output_configure(ac, ac->che_pos, new_che_pos, 0); + err = output_configure(ac, ac->che_pos, new_che_pos, 0, OC_TRIAL_PCE); break; } case TYPE_FIL: if (elem_id == 15) elem_id += get_bits(&gb, 8) - 1; + if (get_bits_left(&gb) < 8 * elem_id) { + av_log(avccontext, AV_LOG_ERROR, overread_err); + return -1; + } while (elem_id > 0) - elem_id -= decode_extension_payload(ac, &gb, elem_id); + elem_id -= decode_extension_payload(ac, &gb, elem_id, che_prev, elem_type_prev); err = 0; /* FIXME */ break; @@ -1753,19 +2030,28 @@ static int aac_decode_frame(AVCodecContext *avccontext, void *data, break; } + che_prev = che; + elem_type_prev = elem_type; + if (err) return err; + + if (get_bits_left(&gb) < 3) { + av_log(avccontext, AV_LOG_ERROR, overread_err); + return -1; + } } spectral_to_sample(ac); - if (!ac->is_saved) { - ac->is_saved = 1; - *data_size = 0; - return buf_size; + multiplier = (ac->m4ac.sbr == 1) ? ac->m4ac.ext_sample_rate > ac->m4ac.sample_rate : 0; + samples <<= multiplier; + if (ac->output_configured < OC_LOCKED) { + avccontext->sample_rate = ac->m4ac.sample_rate << multiplier; + avccontext->frame_size = samples; } - data_size_tmp = 1024 * avccontext->channels * sizeof(int16_t); + data_size_tmp = samples * avccontext->channels * sizeof(int16_t); if (*data_size < data_size_tmp) { av_log(avccontext, AV_LOG_ERROR, "Output buffer too small (%d) or trying to output too many samples (%d) for this frame.\n", @@ -1774,9 +2060,17 @@ static int aac_decode_frame(AVCodecContext *avccontext, void *data, } *data_size = data_size_tmp; - ac->dsp.float_to_int16_interleave(data, (const float **)ac->output_data, 1024, avccontext->channels); + ac->dsp.float_to_int16_interleave(data, (const float **)ac->output_data, samples, avccontext->channels); - return buf_size; + if (ac->output_configured) + ac->output_configured = OC_LOCKED; + + buf_consumed = (get_bits_count(&gb) + 7) >> 3; + for (buf_offset = buf_consumed; buf_offset < buf_size; buf_offset++) + if (buf[buf_offset]) + break; + + return buf_size > buf_offset ? buf_consumed : buf_size; } static av_cold int aac_decode_close(AVCodecContext *avccontext) @@ -1785,8 +2079,11 @@ static av_cold int aac_decode_close(AVCodecContext *avccontext) int i, type; for (i = 0; i < MAX_ELEM_ID; i++) { - for (type = 0; type < 4; type++) + for (type = 0; type < 4; type++) { + if (ac->che[type][i]) + ff_aac_sbr_ctx_close(&ac->che[type][i]->sbr); av_freep(&ac->che[type][i]); + } } ff_mdct_end(&ac->mdct); @@ -1796,7 +2093,7 @@ static av_cold int aac_decode_close(AVCodecContext *avccontext) AVCodec aac_decoder = { "aac", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_AAC, sizeof(AACContext), aac_decode_init, @@ -1804,7 +2101,8 @@ AVCodec aac_decoder = { aac_decode_close, aac_decode_frame, .long_name = NULL_IF_CONFIG_SMALL("Advanced Audio Coding"), - .sample_fmts = (enum SampleFormat[]) { + .sample_fmts = (const enum SampleFormat[]) { SAMPLE_FMT_S16,SAMPLE_FMT_NONE }, + .channel_layouts = aac_channel_layout, }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/aac.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/aac.h index cd295499ed..1a8aa6c145 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/aac.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/aac.h @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/aac.h + * @file * AAC definitions and structures * @author Oded Shimon ( ods15 ods15 dyndns org ) * @author Maxim Gavrilov ( maxim.gavrilov gmail com ) @@ -32,12 +32,14 @@ #include "avcodec.h" #include "dsputil.h" +#include "fft.h" #include "mpeg4audio.h" +#include "sbr.h" #include #define AAC_INIT_VLC_STATIC(num, size) \ - INIT_VLC_STATIC(&vlc_spectral[num], 6, ff_aac_spectral_sizes[num], \ + INIT_VLC_STATIC(&vlc_spectral[num], 8, ff_aac_spectral_sizes[num], \ ff_aac_spectral_bits[num], sizeof( ff_aac_spectral_bits[num][0]), sizeof( ff_aac_spectral_bits[num][0]), \ ff_aac_spectral_codes[num], sizeof(ff_aac_spectral_codes[num][0]), sizeof(ff_aac_spectral_codes[num][0]), \ size); @@ -102,6 +104,17 @@ enum CouplingPoint { AFTER_IMDCT = 3, }; +/** + * 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 +}; + /** * Predictor State */ @@ -203,9 +216,9 @@ typedef struct { float sf[120]; ///< scalefactors int sf_idx[128]; ///< scalefactor indices (used by encoder) uint8_t zeroes[128]; ///< band is not coded (used by encoder) - DECLARE_ALIGNED_16(float, coeffs[1024]); ///< coefficients for IMDCT - DECLARE_ALIGNED_16(float, saved[1024]); ///< overlap - DECLARE_ALIGNED_16(float, ret[1024]); ///< PCM output + DECLARE_ALIGNED(16, float, coeffs)[1024]; ///< coefficients for IMDCT + DECLARE_ALIGNED(16, float, saved)[1024]; ///< overlap + DECLARE_ALIGNED(16, float, ret)[2048]; ///< PCM output PredictorState predictor_state[MAX_PREDICTORS]; } SingleChannelElement; @@ -221,6 +234,7 @@ typedef struct { SingleChannelElement ch[2]; // CCE specific ChannelCoupling coup; + SpectralBandReplication sbr; } ChannelElement; /** @@ -250,15 +264,15 @@ typedef struct { * @defgroup temporary aligned temporary buffers (We do not want to have these on the stack.) * @{ */ - DECLARE_ALIGNED_16(float, buf_mdct[1024]); + DECLARE_ALIGNED(16, float, buf_mdct)[1024]; /** @} */ /** * @defgroup tables Computed / set up during initialization. * @{ */ - MDCTContext mdct; - MDCTContext mdct_small; + FFTContext mdct; + FFTContext mdct_small; DSPContext dsp; int random_state; /** @} */ @@ -273,9 +287,9 @@ typedef struct { int sf_offset; ///< offset into pow2sf_tab as appropriate for dsp.float_to_int16 /** @} */ - DECLARE_ALIGNED(16, float, temp[128]); + DECLARE_ALIGNED(16, float, temp)[128]; - int output_configured; + enum OCStatus output_configured; } AACContext; #endif /* AVCODEC_AAC_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/aac_ac3_parser.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/aac_ac3_parser.c index 85993c09b7..87911619eb 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/aac_ac3_parser.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/aac_ac3_parser.c @@ -71,24 +71,32 @@ get_next: *poutbuf_size = buf_size; /* update codec info */ - avctx->sample_rate = s->sample_rate; if(s->codec_id) avctx->codec_id = s->codec_id; - /* allow downmixing to stereo (or mono for AC-3) */ - if(avctx->request_channels > 0 && - avctx->request_channels < s->channels && - (avctx->request_channels <= 2 || - (avctx->request_channels == 1 && - (avctx->codec_id == CODEC_ID_AC3 || - avctx->codec_id == CODEC_ID_EAC3)))) { - avctx->channels = avctx->request_channels; - } else if (avctx->codec_id != CODEC_ID_AAC || s->channels) { - avctx->channels = s->channels; - avctx->channel_layout = s->channel_layout; + /* Due to backwards compatible HE-AAC the sample rate, channel count, + and total number of samples found in an AAC ADTS header are not + reliable. Bit rate is still accurate because the total frame duration in + seconds is still correct (as is the number of bits in the frame). */ + if (avctx->codec_id != CODEC_ID_AAC) { + avctx->sample_rate = s->sample_rate; + + /* allow downmixing to stereo (or mono for AC-3) */ + if(avctx->request_channels > 0 && + avctx->request_channels < s->channels && + (avctx->request_channels <= 2 || + (avctx->request_channels == 1 && + (avctx->codec_id == CODEC_ID_AC3 || + avctx->codec_id == CODEC_ID_EAC3)))) { + avctx->channels = avctx->request_channels; + } else { + avctx->channels = s->channels; + avctx->channel_layout = s->channel_layout; + } + avctx->frame_size = s->samples; } + avctx->bit_rate = s->bit_rate; - avctx->frame_size = s->samples; return i; } diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/aac_adtstoasc_bsf.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/aac_adtstoasc_bsf.c index 96876dd62f..9d53a011c8 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/aac_adtstoasc_bsf.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/aac_adtstoasc_bsf.c @@ -84,7 +84,7 @@ static int aac_adtstoasc_filter(AVBitStreamFilterContext *bsfc, buf += get_bits_count(&gb)/8; } avctx->extradata_size = 2 + pce_size; - avctx->extradata = av_malloc(avctx->extradata_size); + avctx->extradata = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); init_put_bits(&pb, avctx->extradata, avctx->extradata_size); put_bits(&pb, 5, hdr.object_type); diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/aaccoder.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/aaccoder.c index be954dd9f8..0957469957 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/aaccoder.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/aaccoder.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/aaccoder.c + * @file * AAC coefficients encoder */ @@ -100,7 +100,8 @@ static const uint8_t aac_cb_maxval[12] = {0, 1, 1, 2, 2, 4, 4, 7, 7, 12, 12, 16} * * @return quantization distortion */ -static float quantize_band_cost(struct AACEncContext *s, const float *in, +static float quantize_and_encode_band_cost(struct AACEncContext *s, + PutBitContext *pb, const float *in, const float *scaled, int size, int scale_idx, int cb, const float lambda, const float uplim, int *bits) @@ -121,15 +122,19 @@ static float quantize_band_cost(struct AACEncContext *s, const float *in, if (!cb) { for (i = 0; i < size; i++) - cost += in[i]*in[i]*lambda; + cost += in[i]*in[i]; if (bits) *bits = 0; - return cost; + return cost * lambda; } #ifndef USE_REALLY_FULL_SEARCH offs[0] = 1; for (i = 1; i < dim; i++) offs[i] = offs[i-1]*range; + if (!scaled) { + abs_pow34_v(s->scoefs, in, size); + scaled = s->scoefs; + } quantize_bands(s->qcoefs, in, scaled, size, Q34, !IS_CODEBOOK_UNSIGNED(cb), maxval); #endif /* USE_REALLY_FULL_SEARCH */ for (i = 0; i < size; i += dim) { @@ -141,10 +146,10 @@ static float quantize_band_cost(struct AACEncContext *s, const float *in, int (*quants)[2] = &s->qcoefs[i]; mincost = 0.0f; for (j = 0; j < dim; j++) - mincost += in[i+j]*in[i+j]*lambda; + mincost += in[i+j]*in[i+j]; minidx = IS_CODEBOOK_UNSIGNED(cb) ? 0 : 40; minbits = ff_aac_spectral_bits[cb-1][minidx]; - mincost += minbits; + mincost = mincost * lambda + minbits; for (j = 0; j < (1<= CLIPPED_ESCAPE) { di = t - CLIPPED_ESCAPE; curbits += 21; } else { int c = av_clip(quant(t, Q), 0, 8191); - di = t - c*cbrt(c)*IQ; + di = t - c*cbrtf(c)*IQ; curbits += av_log2(c)*2 - 4 + 1; } } else { @@ -192,18 +198,18 @@ static float quantize_band_cost(struct AACEncContext *s, const float *in, } if (vec[k] != 0.0f) curbits++; - rd += di*di*lambda; + rd += di*di; } } else { for (k = 0; k < dim; k++) { float di = in[i+k] - vec[k]*IQ; - rd += di*di*lambda; + rd += di*di; } } - rd += curbits; + rd = rd * lambda + curbits; if (rd < mincost) { mincost = rd; - minidx = j; + minidx = curidx; minbits = curbits; } } @@ -211,117 +217,7 @@ static float quantize_band_cost(struct AACEncContext *s, const float *in, resbits += minbits; if (cost >= uplim) return uplim; - } - - if (bits) - *bits = resbits; - return cost; -} - -static void quantize_and_encode_band(struct AACEncContext *s, PutBitContext *pb, - const float *in, int size, int scale_idx, - int cb, const float lambda) -{ - const float IQ = ff_aac_pow2sf_tab[200 + scale_idx - SCALE_ONE_POS + SCALE_DIV_512]; - const float Q = ff_aac_pow2sf_tab[200 - scale_idx + SCALE_ONE_POS - SCALE_DIV_512]; - const float CLIPPED_ESCAPE = 165140.0f*IQ; - const int dim = (cb < FIRST_PAIR_BT) ? 4 : 2; - int i, j, k; -#ifndef USE_REALLY_FULL_SEARCH - const float Q34 = sqrtf(Q * sqrtf(Q)); - const int range = aac_cb_range[cb]; - const int maxval = aac_cb_maxval[cb]; - int offs[4]; - float *scaled = s->scoefs; -#endif /* USE_REALLY_FULL_SEARCH */ - -//START_TIMER - if (!cb) - return; - -#ifndef USE_REALLY_FULL_SEARCH - offs[0] = 1; - for (i = 1; i < dim; i++) - offs[i] = offs[i-1]*range; - abs_pow34_v(scaled, in, size); - quantize_bands(s->qcoefs, in, scaled, size, Q34, !IS_CODEBOOK_UNSIGNED(cb), maxval); -#endif /* USE_REALLY_FULL_SEARCH */ - for (i = 0; i < size; i += dim) { - float mincost; - int minidx = 0; - int minbits = 0; - const float *vec; -#ifndef USE_REALLY_FULL_SEARCH - int (*quants)[2] = &s->qcoefs[i]; - mincost = 0.0f; - for (j = 0; j < dim; j++) - mincost += in[i+j]*in[i+j]*lambda; - minidx = IS_CODEBOOK_UNSIGNED(cb) ? 0 : 40; - minbits = ff_aac_spectral_bits[cb-1][minidx]; - mincost += minbits; - for (j = 0; j < (1<= CLIPPED_ESCAPE) { - di = t - CLIPPED_ESCAPE; - curbits += 21; - } else { - int c = av_clip(quant(t, Q), 0, 8191); - di = t - c*cbrt(c)*IQ; - curbits += av_log2(c)*2 - 4 + 1; - } - } else { - di = t - vec[k]*IQ; - } - if (vec[k] != 0.0f) - curbits++; - rd += di*di*lambda; - } - } else { - for (k = 0; k < dim; k++) { - float di = in[i+k] - vec[k]*IQ; - rd += di*di*lambda; - } - } - rd += curbits; - if (rd < mincost) { - mincost = rd; - minidx = curidx; - minbits = curbits; - } - } + if (pb) { put_bits(pb, ff_aac_spectral_bits[cb-1][minidx], ff_aac_spectral_codes[cb-1][minidx]); if (IS_CODEBOOK_UNSIGNED(cb)) for (j = 0; j < dim; j++) @@ -338,8 +234,28 @@ static void quantize_and_encode_band(struct AACEncContext *s, PutBitContext *pb, } } } + } } -//STOP_TIMER("quantize_and_encode") + + if (bits) + *bits = resbits; + return cost; +} +static float quantize_band_cost(struct AACEncContext *s, const float *in, + const float *scaled, int size, int scale_idx, + int cb, const float lambda, const float uplim, + int *bits) +{ + return quantize_and_encode_band_cost(s, NULL, in, scaled, size, scale_idx, + cb, lambda, uplim, bits); +} + +static void quantize_and_encode_band(struct AACEncContext *s, PutBitContext *pb, + const float *in, int size, int scale_idx, + int cb, const float lambda) +{ + quantize_and_encode_band_cost(s, pb, in, NULL, size, scale_idx, cb, lambda, + INFINITY, NULL); } /** @@ -463,31 +379,36 @@ typedef struct TrellisPath { int max_val; } TrellisPath; +#define TRELLIS_STAGES 121 +#define TRELLIS_STATES 256 + static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, const float lambda) { int q, w, w2, g, start = 0; - int i; + int i, j; int idx; - TrellisPath paths[256*121]; - int bandaddr[121]; + TrellisPath paths[TRELLIS_STAGES][TRELLIS_STATES]; + int bandaddr[TRELLIS_STAGES]; int minq; float mincost; - for (i = 0; i < 256; i++) { - paths[i].cost = 0.0f; - paths[i].prev = -1; - paths[i].min_val = i; - paths[i].max_val = i; + for (i = 0; i < TRELLIS_STATES; i++) { + paths[0][i].cost = 0.0f; + paths[0][i].prev = -1; + paths[0][i].min_val = i; + paths[0][i].max_val = i; } - for (i = 256; i < 256*121; i++) { - paths[i].cost = INFINITY; - paths[i].prev = -2; - paths[i].min_val = INT_MAX; - paths[i].max_val = 0; + for (j = 1; j < TRELLIS_STAGES; j++) { + for (i = 0; i < TRELLIS_STATES; i++) { + paths[j][i].cost = INFINITY; + paths[j][i].prev = -2; + paths[j][i].min_val = INT_MAX; + paths[j][i].max_val = 0; + } } - idx = 256; + idx = 1; abs_pow34_v(s->scoefs, sce->coeffs, 1024); for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { start = w*128; @@ -496,7 +417,7 @@ static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s, float qmin, qmax; int nz = 0; - bandaddr[idx >> 8] = w * 16 + g; + bandaddr[idx] = w * 16 + g; qmin = INT_MAX; qmax = 0.0f; for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) { @@ -536,66 +457,67 @@ static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s, dist = FFMIN(dist, dists[i]); minrd = FFMIN(minrd, dist); - for (i = FFMAX(q - SCALE_MAX_DIFF, 0); i < FFMIN(q + SCALE_MAX_DIFF, 256); i++) { + for (i = FFMAX(q - SCALE_MAX_DIFF, 0); i < FFMIN(q + SCALE_MAX_DIFF, TRELLIS_STATES); i++) { float cost; int minv, maxv; - if (isinf(paths[idx - 256 + i].cost)) + if (isinf(paths[idx - 1][i].cost)) continue; - cost = paths[idx - 256 + i].cost + dist + cost = paths[idx - 1][i].cost + dist + ff_aac_scalefactor_bits[q - i + SCALE_DIFF_ZERO]; - minv = FFMIN(paths[idx - 256 + i].min_val, q); - maxv = FFMAX(paths[idx - 256 + i].max_val, q); - if (cost < paths[idx + q].cost && maxv-minv < SCALE_MAX_DIFF) { - paths[idx + q].cost = cost; - paths[idx + q].prev = idx - 256 + i; - paths[idx + q].min_val = minv; - paths[idx + q].max_val = maxv; + minv = FFMIN(paths[idx - 1][i].min_val, q); + maxv = FFMAX(paths[idx - 1][i].max_val, q); + if (cost < paths[idx][q].cost && maxv-minv < SCALE_MAX_DIFF) { + paths[idx][q].cost = cost; + paths[idx][q].prev = i; + paths[idx][q].min_val = minv; + paths[idx][q].max_val = maxv; } } } } else { - for (q = 0; q < 256; q++) { - if (!isinf(paths[idx - 256 + q].cost)) { - paths[idx + q].cost = paths[idx - 256 + q].cost + 1; - paths[idx + q].prev = idx - 256 + q; - paths[idx + q].min_val = FFMIN(paths[idx - 256 + q].min_val, q); - paths[idx + q].max_val = FFMAX(paths[idx - 256 + q].max_val, q); + for (q = 0; q < TRELLIS_STATES; q++) { + if (!isinf(paths[idx - 1][q].cost)) { + paths[idx][q].cost = paths[idx - 1][q].cost + 1; + paths[idx][q].prev = q; + paths[idx][q].min_val = FFMIN(paths[idx - 1][q].min_val, q); + paths[idx][q].max_val = FFMAX(paths[idx - 1][q].max_val, q); continue; } - for (i = FFMAX(q - SCALE_MAX_DIFF, 0); i < FFMIN(q + SCALE_MAX_DIFF, 256); i++) { + for (i = FFMAX(q - SCALE_MAX_DIFF, 0); i < FFMIN(q + SCALE_MAX_DIFF, TRELLIS_STATES); i++) { float cost; int minv, maxv; - if (isinf(paths[idx - 256 + i].cost)) + if (isinf(paths[idx - 1][i].cost)) continue; - cost = paths[idx - 256 + i].cost + ff_aac_scalefactor_bits[q - i + SCALE_DIFF_ZERO]; - minv = FFMIN(paths[idx - 256 + i].min_val, q); - maxv = FFMAX(paths[idx - 256 + i].max_val, q); - if (cost < paths[idx + q].cost && maxv-minv < SCALE_MAX_DIFF) { - paths[idx + q].cost = cost; - paths[idx + q].prev = idx - 256 + i; - paths[idx + q].min_val = minv; - paths[idx + q].max_val = maxv; + cost = paths[idx - 1][i].cost + ff_aac_scalefactor_bits[q - i + SCALE_DIFF_ZERO]; + minv = FFMIN(paths[idx - 1][i].min_val, q); + maxv = FFMAX(paths[idx - 1][i].max_val, q); + if (cost < paths[idx][q].cost && maxv-minv < SCALE_MAX_DIFF) { + paths[idx][q].cost = cost; + paths[idx][q].prev = i; + paths[idx][q].min_val = minv; + paths[idx][q].max_val = maxv; } } } } sce->zeroes[w*16+g] = !nz; start += sce->ics.swb_sizes[g]; - idx += 256; + idx++; } } - idx -= 256; - mincost = paths[idx].cost; - minq = idx; - for (i = 1; i < 256; i++) { - if (paths[idx + i].cost < mincost) { - mincost = paths[idx + i].cost; - minq = idx + i; + idx--; + mincost = paths[idx][0].cost; + minq = 0; + for (i = 1; i < TRELLIS_STATES; i++) { + if (paths[idx][i].cost < mincost) { + mincost = paths[idx][i].cost; + minq = i; } } - while (minq >= 256) { - sce->sf_idx[bandaddr[minq>>8]] = minq & 0xFF; - minq = paths[minq].prev; + while (idx) { + sce->sf_idx[bandaddr[idx]] = minq; + minq = paths[idx][minq].prev; + idx--; } //set the same quantizers inside window groups for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) @@ -841,7 +763,7 @@ static void search_for_quantizers_faac(AVCodecContext *avctx, AACEncContext *s, const float *scaled = s->scoefs + start; const int size = sce->ics.swb_sizes[g]; int scf, prev_scf, step; - int min_scf = 0, max_scf = 255; + int min_scf = -1, max_scf = 256; float curdiff; if (maxq[w*16+g] < 21.544) { sce->zeroes[w*16+g] = 1; @@ -875,21 +797,23 @@ static void search_for_quantizers_faac(AVCodecContext *avctx, AACEncContext *s, } prev_scf = scf; curdiff = fabsf(dist - uplim[w*16+g]); - if (curdiff == 0.0f) + if (curdiff <= 1.0f) step = 0; else - step = fabsf(log2(curdiff)); + step = log2(curdiff); if (dist > uplim[w*16+g]) step = -step; + scf += step; + scf = av_clip_uint8(scf); + step = scf - prev_scf; if (FFABS(step) <= 1 || (step > 0 && scf >= max_scf) || (step < 0 && scf <= min_scf)) { - sce->sf_idx[w*16+g] = scf; + sce->sf_idx[w*16+g] = av_clip(scf, min_scf, max_scf); break; } - scf += step; if (step > 0) - min_scf = scf; + min_scf = prev_scf; else - max_scf = scf; + max_scf = prev_scf; } start += size; } @@ -1013,24 +937,24 @@ AACCoefficientsEncoder ff_aac_coders[] = { search_for_quantizers_faac, encode_window_bands_info, quantize_and_encode_band, -// search_for_ms, + search_for_ms, }, { search_for_quantizers_anmr, encode_window_bands_info, quantize_and_encode_band, -// search_for_ms, + search_for_ms, }, { search_for_quantizers_twoloop, encode_window_bands_info, quantize_and_encode_band, -// search_for_ms, + search_for_ms, }, { search_for_quantizers_fast, encode_window_bands_info, quantize_and_encode_band, -// search_for_ms, + search_for_ms, }, }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/aacdectab.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/aacdectab.h index b6d80f20c1..b74f100112 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/aacdectab.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/aacdectab.h @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/aacdectab.h + * @file * AAC decoder data * @author Oded Shimon ( ods15 ods15 dyndns org ) * @author Maxim Gavrilov ( maxim.gavrilov gmail com ) @@ -69,4 +69,27 @@ static const float * const tns_tmp2_map[4] = { }; // @} +static const int8_t tags_per_config[16] = { 0, 1, 1, 2, 3, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0 }; + +static const uint8_t aac_channel_layout_map[7][5][2] = { + { { TYPE_SCE, 0 }, }, + { { TYPE_CPE, 0 }, }, + { { TYPE_CPE, 0 }, { TYPE_SCE, 0 }, }, + { { TYPE_CPE, 0 }, { TYPE_SCE, 0 }, { TYPE_SCE, 1 }, }, + { { TYPE_CPE, 0 }, { TYPE_SCE, 0 }, { TYPE_CPE, 1 }, }, + { { TYPE_CPE, 0 }, { TYPE_SCE, 0 }, { TYPE_LFE, 0 }, { TYPE_CPE, 1 }, }, + { { TYPE_CPE, 0 }, { TYPE_SCE, 0 }, { TYPE_LFE, 0 }, { TYPE_CPE, 2 }, { TYPE_CPE, 1 }, }, +}; + +static const int64_t aac_channel_layout[8] = { + CH_LAYOUT_MONO, + CH_LAYOUT_STEREO, + CH_LAYOUT_SURROUND, + CH_LAYOUT_4POINT0, + CH_LAYOUT_5POINT0_BACK, + CH_LAYOUT_5POINT1_BACK, + CH_LAYOUT_7POINT1_WIDE, + 0, +}; + #endif /* AVCODEC_AACDECTAB_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/aacenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/aacenc.c index dfa519059c..90dff15dd5 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/aacenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/aacenc.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/aacenc.c + * @file * AAC encoder */ @@ -170,6 +170,14 @@ static av_cold int aac_encode_init(AVCodecContext *avctx) av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels: %d\n", avctx->channels); return -1; } + if (avctx->profile != FF_PROFILE_UNKNOWN && avctx->profile != FF_PROFILE_AAC_LOW) { + av_log(avctx, AV_LOG_ERROR, "Unsupported profile %d\n", avctx->profile); + return -1; + } + if (1024.0 * avctx->bit_rate / avctx->sample_rate > 6144 * avctx->channels) { + av_log(avctx, AV_LOG_ERROR, "Too many bits per frame requested\n"); + return -1; + } s->samplerate_index = i; dsputil_init(&s->dsp, avctx); @@ -178,8 +186,8 @@ static av_cold int aac_encode_init(AVCodecContext *avctx) // window init ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024); ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128); - ff_sine_window_init(ff_sine_1024, 1024); - ff_sine_window_init(ff_sine_128, 128); + ff_init_ff_sine_windows(10); + ff_init_ff_sine_windows(7); s->samples = av_malloc(2 * 1024 * avctx->channels * sizeof(s->samples[0])); s->cpe = av_mallocz(sizeof(ChannelElement) * aac_chan_configs[avctx->channels-1][0]); @@ -553,6 +561,7 @@ static int aac_encode_frame(AVCodecContext *avctx, chans = tag == TYPE_CPE ? 2 : 1; cpe = &s->cpe[i]; for (j = 0; j < chans; j++) { + s->cur_channel = start_ch + j; s->coder->search_for_quantizers(avctx, s, &cpe->ch[j], s->lambda); } cpe->common_window = 0; @@ -568,6 +577,7 @@ static int aac_encode_frame(AVCodecContext *avctx, } } } + s->cur_channel = start_ch; if (cpe->common_window && s->coder->search_for_ms) s->coder->search_for_ms(s, cpe, s->lambda); adjust_frame_information(s, cpe, chans); @@ -629,13 +639,13 @@ static av_cold int aac_encode_end(AVCodecContext *avctx) AVCodec aac_encoder = { "aac", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_AAC, sizeof(AACEncContext), aac_encode_init, aac_encode_frame, aac_encode_end, - .capabilities = CODEC_CAP_SMALL_LAST_FRAME | CODEC_CAP_DELAY, - .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, + .capabilities = CODEC_CAP_SMALL_LAST_FRAME | CODEC_CAP_DELAY | CODEC_CAP_EXPERIMENTAL, + .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, .long_name = NULL_IF_CONFIG_SMALL("Advanced Audio Coding"), }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/aacenc.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/aacenc.h index 01d9836fd3..e99be98048 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/aacenc.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/aacenc.h @@ -49,10 +49,10 @@ extern AACCoefficientsEncoder ff_aac_coders[]; */ typedef struct AACEncContext { PutBitContext pb; - MDCTContext mdct1024; ///< long (1024 samples) frame transform context - MDCTContext mdct128; ///< short (128 samples) frame transform context + FFTContext mdct1024; ///< long (1024 samples) frame transform context + FFTContext mdct128; ///< short (128 samples) frame transform context DSPContext dsp; - DECLARE_ALIGNED_16(FFTSample, output[2048]); ///< temporary buffer for MDCT input coefficients + DECLARE_ALIGNED(16, FFTSample, output)[2048]; ///< temporary buffer for MDCT input coefficients int16_t* samples; ///< saved preprocessed input int samplerate_index; ///< MPEG-4 samplerate index @@ -64,8 +64,8 @@ typedef struct AACEncContext { int cur_channel; int last_frame; float lambda; - DECLARE_ALIGNED_16(int, qcoefs[96][2]); ///< quantized coefficients - DECLARE_ALIGNED_16(float, scoefs[1024]); ///< scaled coefficients + DECLARE_ALIGNED(16, int, qcoefs)[96][2]; ///< quantized coefficients + DECLARE_ALIGNED(16, float, scoefs)[1024]; ///< scaled coefficients } AACEncContext; #endif /* AVCODEC_AACENC_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/aacpsy.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/aacpsy.c index 1200134baf..53dac3dbfd 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/aacpsy.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/aacpsy.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/aacpsy.c + * @file * AAC encoder psychoacoustic model */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/aacsbr.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/aacsbr.c new file mode 100644 index 0000000000..0de81a5025 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/aacsbr.c @@ -0,0 +1,1766 @@ +/* + * AAC Spectral Band Replication decoding functions + * Copyright (c) 2008-2009 Robert Swain ( rob opendot cl ) + * Copyright (c) 2009-2010 Alex Converse + * + * 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 + * AAC Spectral Band Replication decoding functions + * @author Robert Swain ( rob opendot cl ) + */ + +#include "aac.h" +#include "sbr.h" +#include "aacsbr.h" +#include "aacsbrdata.h" +#include "fft.h" + +#include +#include + +#define ENVELOPE_ADJUSTMENT_OFFSET 2 +#define NOISE_FLOOR_OFFSET 6.0f + +/** + * SBR VLC tables + */ +enum { + T_HUFFMAN_ENV_1_5DB, + F_HUFFMAN_ENV_1_5DB, + T_HUFFMAN_ENV_BAL_1_5DB, + F_HUFFMAN_ENV_BAL_1_5DB, + T_HUFFMAN_ENV_3_0DB, + F_HUFFMAN_ENV_3_0DB, + T_HUFFMAN_ENV_BAL_3_0DB, + F_HUFFMAN_ENV_BAL_3_0DB, + T_HUFFMAN_NOISE_3_0DB, + T_HUFFMAN_NOISE_BAL_3_0DB, +}; + +/** + * bs_frame_class - frame class of current SBR frame (14496-3 sp04 p98) + */ +enum { + FIXFIX, + FIXVAR, + VARFIX, + VARVAR, +}; + +enum { + EXTENSION_ID_PS = 2, +}; + +static VLC vlc_sbr[10]; +static const int8_t vlc_sbr_lav[10] = + { 60, 60, 24, 24, 31, 31, 12, 12, 31, 12 }; +static DECLARE_ALIGNED(16, float, analysis_cos_pre)[64]; +static DECLARE_ALIGNED(16, float, analysis_sin_pre)[64]; +static DECLARE_ALIGNED(16, float, analysis_cossin_post)[32][2]; +static const DECLARE_ALIGNED(16, float, zero64)[64]; + +#define SBR_INIT_VLC_STATIC(num, size) \ + INIT_VLC_STATIC(&vlc_sbr[num], 9, sbr_tmp[num].table_size / sbr_tmp[num].elem_size, \ + sbr_tmp[num].sbr_bits , 1, 1, \ + sbr_tmp[num].sbr_codes, sbr_tmp[num].elem_size, sbr_tmp[num].elem_size, \ + size) + +#define SBR_VLC_ROW(name) \ + { name ## _codes, name ## _bits, sizeof(name ## _codes), sizeof(name ## _codes[0]) } + +av_cold void ff_aac_sbr_init(void) +{ + int n, k; + static const struct { + const void *sbr_codes, *sbr_bits; + const unsigned int table_size, elem_size; + } sbr_tmp[] = { + SBR_VLC_ROW(t_huffman_env_1_5dB), + SBR_VLC_ROW(f_huffman_env_1_5dB), + SBR_VLC_ROW(t_huffman_env_bal_1_5dB), + SBR_VLC_ROW(f_huffman_env_bal_1_5dB), + SBR_VLC_ROW(t_huffman_env_3_0dB), + SBR_VLC_ROW(f_huffman_env_3_0dB), + SBR_VLC_ROW(t_huffman_env_bal_3_0dB), + SBR_VLC_ROW(f_huffman_env_bal_3_0dB), + SBR_VLC_ROW(t_huffman_noise_3_0dB), + SBR_VLC_ROW(t_huffman_noise_bal_3_0dB), + }; + + // SBR VLC table initialization + SBR_INIT_VLC_STATIC(0, 1098); + SBR_INIT_VLC_STATIC(1, 1092); + SBR_INIT_VLC_STATIC(2, 768); + SBR_INIT_VLC_STATIC(3, 1026); + SBR_INIT_VLC_STATIC(4, 1058); + SBR_INIT_VLC_STATIC(5, 1052); + SBR_INIT_VLC_STATIC(6, 544); + SBR_INIT_VLC_STATIC(7, 544); + SBR_INIT_VLC_STATIC(8, 592); + SBR_INIT_VLC_STATIC(9, 512); + + for (n = 0; n < 64; n++) { + float pre = M_PI * n / 64; + analysis_cos_pre[n] = cosf(pre); + analysis_sin_pre[n] = sinf(pre); + } + for (k = 0; k < 32; k++) { + float post = M_PI * (k + 0.5) / 128; + analysis_cossin_post[k][0] = 4.0 * cosf(post); + analysis_cossin_post[k][1] = -4.0 * sinf(post); + } + for (n = 1; n < 320; n++) + sbr_qmf_window_us[320 + n] = sbr_qmf_window_us[320 - n]; + sbr_qmf_window_us[384] = -sbr_qmf_window_us[384]; + sbr_qmf_window_us[512] = -sbr_qmf_window_us[512]; + + for (n = 0; n < 320; n++) + sbr_qmf_window_ds[n] = sbr_qmf_window_us[2*n]; +} + +av_cold void ff_aac_sbr_ctx_init(SpectralBandReplication *sbr) +{ + 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); + sbr->data[1].synthesis_filterbank_samples_offset = SBR_SYNTHESIS_BUF_SIZE - (1280 - 128); + ff_mdct_init(&sbr->mdct, 7, 1, 1.0/64); + ff_rdft_init(&sbr->rdft, 6, IDFT_R2C); +} + +av_cold void ff_aac_sbr_ctx_close(SpectralBandReplication *sbr) +{ + ff_mdct_end(&sbr->mdct); + ff_rdft_end(&sbr->rdft); +} + +static int qsort_comparison_function_int16(const void *a, const void *b) +{ + return *(const int16_t *)a - *(const int16_t *)b; +} + +static inline int in_table_int16(const int16_t *table, int last_el, int16_t needle) +{ + int i; + for (i = 0; i <= last_el; i++) + if (table[i] == needle) + return 1; + return 0; +} + +/// Limiter Frequency Band Table (14496-3 sp04 p198) +static void sbr_make_f_tablelim(SpectralBandReplication *sbr) +{ + int k; + if (sbr->bs_limiter_bands > 0) { + static const float bands_warped[3] = { 1.32715174233856803909f, //2^(0.49/1.2) + 1.18509277094158210129f, //2^(0.49/2) + 1.11987160404675912501f }; //2^(0.49/3) + const float lim_bands_per_octave_warped = bands_warped[sbr->bs_limiter_bands - 1]; + int16_t patch_borders[7]; + uint16_t *in = sbr->f_tablelim + 1, *out = sbr->f_tablelim; + + patch_borders[0] = sbr->kx[1]; + for (k = 1; k <= sbr->num_patches; k++) + patch_borders[k] = patch_borders[k-1] + sbr->patch_num_subbands[k-1]; + + memcpy(sbr->f_tablelim, sbr->f_tablelow, + (sbr->n[0] + 1) * sizeof(sbr->f_tablelow[0])); + if (sbr->num_patches > 1) + memcpy(sbr->f_tablelim + sbr->n[0] + 1, patch_borders + 1, + (sbr->num_patches - 1) * sizeof(patch_borders[0])); + + qsort(sbr->f_tablelim, sbr->num_patches + sbr->n[0], + sizeof(sbr->f_tablelim[0]), + qsort_comparison_function_int16); + + sbr->n_lim = sbr->n[0] + sbr->num_patches - 1; + while (out < sbr->f_tablelim + sbr->n_lim) { + if (*in >= *out * lim_bands_per_octave_warped) { + *++out = *in++; + } else if (*in == *out || + !in_table_int16(patch_borders, sbr->num_patches, *in)) { + in++; + sbr->n_lim--; + } else if (!in_table_int16(patch_borders, sbr->num_patches, *out)) { + *out = *in++; + sbr->n_lim--; + } else { + *++out = *in++; + } + } + } else { + sbr->f_tablelim[0] = sbr->f_tablelow[0]; + sbr->f_tablelim[1] = sbr->f_tablelow[sbr->n[0]]; + sbr->n_lim = 1; + } +} + +static unsigned int read_sbr_header(SpectralBandReplication *sbr, GetBitContext *gb) +{ + unsigned int cnt = get_bits_count(gb); + uint8_t bs_header_extra_1; + uint8_t bs_header_extra_2; + int old_bs_limiter_bands = sbr->bs_limiter_bands; + SpectrumParameters old_spectrum_params; + + sbr->start = 1; + + // Save last spectrum parameters variables to compare to new ones + memcpy(&old_spectrum_params, &sbr->spectrum_params, sizeof(SpectrumParameters)); + + sbr->bs_amp_res_header = get_bits1(gb); + sbr->spectrum_params.bs_start_freq = get_bits(gb, 4); + sbr->spectrum_params.bs_stop_freq = get_bits(gb, 4); + sbr->spectrum_params.bs_xover_band = get_bits(gb, 3); + skip_bits(gb, 2); // bs_reserved + + bs_header_extra_1 = get_bits1(gb); + bs_header_extra_2 = get_bits1(gb); + + if (bs_header_extra_1) { + sbr->spectrum_params.bs_freq_scale = get_bits(gb, 2); + sbr->spectrum_params.bs_alter_scale = get_bits1(gb); + sbr->spectrum_params.bs_noise_bands = get_bits(gb, 2); + } else { + sbr->spectrum_params.bs_freq_scale = 2; + sbr->spectrum_params.bs_alter_scale = 1; + sbr->spectrum_params.bs_noise_bands = 2; + } + + // Check if spectrum parameters changed + if (memcmp(&old_spectrum_params, &sbr->spectrum_params, sizeof(SpectrumParameters))) + sbr->reset = 1; + + if (bs_header_extra_2) { + sbr->bs_limiter_bands = get_bits(gb, 2); + sbr->bs_limiter_gains = get_bits(gb, 2); + sbr->bs_interpol_freq = get_bits1(gb); + sbr->bs_smoothing_mode = get_bits1(gb); + } else { + sbr->bs_limiter_bands = 2; + sbr->bs_limiter_gains = 2; + sbr->bs_interpol_freq = 1; + sbr->bs_smoothing_mode = 1; + } + + if (sbr->bs_limiter_bands != old_bs_limiter_bands && !sbr->reset) + sbr_make_f_tablelim(sbr); + + return get_bits_count(gb) - cnt; +} + +static int array_min_int16(const int16_t *array, int nel) +{ + int i, min = array[0]; + for (i = 1; i < nel; i++) + min = FFMIN(array[i], min); + return min; +} + +static void make_bands(int16_t* bands, int start, int stop, int num_bands) +{ + int k, previous, present; + float base, prod; + + base = powf((float)stop / start, 1.0f / num_bands); + prod = start; + previous = start; + + for (k = 0; k < num_bands-1; k++) { + prod *= base; + present = lrintf(prod); + bands[k] = present - previous; + previous = present; + } + bands[num_bands-1] = stop - previous; +} + +static int check_n_master(AVCodecContext *avccontext, int n_master, int bs_xover_band) +{ + // Requirements (14496-3 sp04 p205) + if (n_master <= 0) { + av_log(avccontext, AV_LOG_ERROR, "Invalid n_master: %d\n", n_master); + return -1; + } + if (bs_xover_band >= n_master) { + av_log(avccontext, AV_LOG_ERROR, + "Invalid bitstream, crossover band index beyond array bounds: %d\n", + bs_xover_band); + return -1; + } + return 0; +} + +/// Master Frequency Band Table (14496-3 sp04 p194) +static int sbr_make_f_master(AACContext *ac, SpectralBandReplication *sbr, + SpectrumParameters *spectrum) +{ + unsigned int temp, max_qmf_subbands; + unsigned int start_min, stop_min; + int k; + const int8_t *sbr_offset_ptr; + int16_t stop_dk[13]; + + if (sbr->sample_rate < 32000) { + temp = 3000; + } else if (sbr->sample_rate < 64000) { + temp = 4000; + } else + temp = 5000; + + start_min = ((temp << 7) + (sbr->sample_rate >> 1)) / sbr->sample_rate; + stop_min = ((temp << 8) + (sbr->sample_rate >> 1)) / sbr->sample_rate; + + switch (sbr->sample_rate) { + case 16000: + sbr_offset_ptr = sbr_offset[0]; + break; + case 22050: + sbr_offset_ptr = sbr_offset[1]; + break; + case 24000: + sbr_offset_ptr = sbr_offset[2]; + break; + case 32000: + sbr_offset_ptr = sbr_offset[3]; + break; + case 44100: case 48000: case 64000: + sbr_offset_ptr = sbr_offset[4]; + break; + case 88200: case 96000: case 128000: case 176400: case 192000: + sbr_offset_ptr = sbr_offset[5]; + break; + default: + av_log(ac->avccontext, AV_LOG_ERROR, + "Unsupported sample rate for SBR: %d\n", sbr->sample_rate); + return -1; + } + + sbr->k[0] = start_min + sbr_offset_ptr[spectrum->bs_start_freq]; + + if (spectrum->bs_stop_freq < 14) { + sbr->k[2] = stop_min; + make_bands(stop_dk, stop_min, 64, 13); + qsort(stop_dk, 13, sizeof(stop_dk[0]), qsort_comparison_function_int16); + for (k = 0; k < spectrum->bs_stop_freq; k++) + sbr->k[2] += stop_dk[k]; + } else if (spectrum->bs_stop_freq == 14) { + sbr->k[2] = 2*sbr->k[0]; + } else if (spectrum->bs_stop_freq == 15) { + sbr->k[2] = 3*sbr->k[0]; + } else { + av_log(ac->avccontext, AV_LOG_ERROR, + "Invalid bs_stop_freq: %d\n", spectrum->bs_stop_freq); + return -1; + } + sbr->k[2] = FFMIN(64, sbr->k[2]); + + // Requirements (14496-3 sp04 p205) + if (sbr->sample_rate <= 32000) { + max_qmf_subbands = 48; + } else if (sbr->sample_rate == 44100) { + max_qmf_subbands = 35; + } else if (sbr->sample_rate >= 48000) + max_qmf_subbands = 32; + + if (sbr->k[2] - sbr->k[0] > max_qmf_subbands) { + av_log(ac->avccontext, AV_LOG_ERROR, + "Invalid bitstream, too many QMF subbands: %d\n", sbr->k[2] - sbr->k[0]); + return -1; + } + + if (!spectrum->bs_freq_scale) { + unsigned int dk; + int k2diff; + + dk = spectrum->bs_alter_scale + 1; + sbr->n_master = ((sbr->k[2] - sbr->k[0] + (dk&2)) >> dk) << 1; + if (check_n_master(ac->avccontext, sbr->n_master, sbr->spectrum_params.bs_xover_band)) + return -1; + + for (k = 1; k <= sbr->n_master; k++) + sbr->f_master[k] = dk; + + k2diff = sbr->k[2] - sbr->k[0] - sbr->n_master * dk; + if (k2diff < 0) { + sbr->f_master[1]--; + sbr->f_master[2]-= (k2diff < 1); + } else if (k2diff) { + sbr->f_master[sbr->n_master]++; + } + + sbr->f_master[0] = sbr->k[0]; + for (k = 1; k <= sbr->n_master; k++) + sbr->f_master[k] += sbr->f_master[k - 1]; + + } else { + int half_bands = 7 - spectrum->bs_freq_scale; // bs_freq_scale = {1,2,3} + int two_regions, num_bands_0; + int vdk0_max, vdk1_min; + int16_t vk0[49]; + + if (49 * sbr->k[2] > 110 * sbr->k[0]) { + two_regions = 1; + sbr->k[1] = 2 * sbr->k[0]; + } else { + two_regions = 0; + sbr->k[1] = sbr->k[2]; + } + + num_bands_0 = lrintf(half_bands * log2f(sbr->k[1] / (float)sbr->k[0])) * 2; + + if (num_bands_0 <= 0) { // Requirements (14496-3 sp04 p205) + av_log(ac->avccontext, AV_LOG_ERROR, "Invalid num_bands_0: %d\n", num_bands_0); + return -1; + } + + vk0[0] = 0; + + make_bands(vk0+1, sbr->k[0], sbr->k[1], num_bands_0); + + qsort(vk0 + 1, num_bands_0, sizeof(vk0[1]), qsort_comparison_function_int16); + vdk0_max = vk0[num_bands_0]; + + vk0[0] = sbr->k[0]; + for (k = 1; k <= num_bands_0; k++) { + if (vk0[k] <= 0) { // Requirements (14496-3 sp04 p205) + av_log(ac->avccontext, AV_LOG_ERROR, "Invalid vDk0[%d]: %d\n", k, vk0[k]); + return -1; + } + vk0[k] += vk0[k-1]; + } + + if (two_regions) { + int16_t vk1[49]; + float invwarp = spectrum->bs_alter_scale ? 0.76923076923076923077f + : 1.0f; // bs_alter_scale = {0,1} + int num_bands_1 = lrintf(half_bands * invwarp * + log2f(sbr->k[2] / (float)sbr->k[1])) * 2; + + make_bands(vk1+1, sbr->k[1], sbr->k[2], num_bands_1); + + vdk1_min = array_min_int16(vk1 + 1, num_bands_1); + + if (vdk1_min < vdk0_max) { + int change; + qsort(vk1 + 1, num_bands_1, sizeof(vk1[1]), qsort_comparison_function_int16); + change = FFMIN(vdk0_max - vk1[1], (vk1[num_bands_1] - vk1[1]) >> 1); + vk1[1] += change; + vk1[num_bands_1] -= change; + } + + qsort(vk1 + 1, num_bands_1, sizeof(vk1[1]), qsort_comparison_function_int16); + + vk1[0] = sbr->k[1]; + for (k = 1; k <= num_bands_1; k++) { + if (vk1[k] <= 0) { // Requirements (14496-3 sp04 p205) + av_log(ac->avccontext, AV_LOG_ERROR, "Invalid vDk1[%d]: %d\n", k, vk1[k]); + return -1; + } + vk1[k] += vk1[k-1]; + } + + sbr->n_master = num_bands_0 + num_bands_1; + if (check_n_master(ac->avccontext, sbr->n_master, sbr->spectrum_params.bs_xover_band)) + return -1; + memcpy(&sbr->f_master[0], vk0, + (num_bands_0 + 1) * sizeof(sbr->f_master[0])); + memcpy(&sbr->f_master[num_bands_0 + 1], vk1 + 1, + num_bands_1 * sizeof(sbr->f_master[0])); + + } else { + sbr->n_master = num_bands_0; + if (check_n_master(ac->avccontext, sbr->n_master, sbr->spectrum_params.bs_xover_band)) + return -1; + memcpy(sbr->f_master, vk0, (num_bands_0 + 1) * sizeof(sbr->f_master[0])); + } + } + + return 0; +} + +/// High Frequency Generation - Patch Construction (14496-3 sp04 p216 fig. 4.46) +static int sbr_hf_calc_npatches(AACContext *ac, SpectralBandReplication *sbr) +{ + int i, k, sb = 0; + int msb = sbr->k[0]; + int usb = sbr->kx[1]; + int goal_sb = ((1000 << 11) + (sbr->sample_rate >> 1)) / sbr->sample_rate; + + sbr->num_patches = 0; + + if (goal_sb < sbr->kx[1] + sbr->m[1]) { + for (k = 0; sbr->f_master[k] < goal_sb; k++) ; + } else + k = sbr->n_master; + + do { + int odd = 0; + for (i = k; i == k || sb > (sbr->k[0] - 1 + msb - odd); i--) { + sb = sbr->f_master[i]; + odd = (sb + sbr->k[0]) & 1; + } + + // Requirements (14496-3 sp04 p205) sets the maximum number of patches to 5. + // After this check the final number of patches can still be six which is + // illegal however the Coding Technologies decoder check stream has a final + // count of 6 patches + if (sbr->num_patches > 5) { + av_log(ac->avccontext, AV_LOG_ERROR, "Too many patches: %d\n", sbr->num_patches); + return -1; + } + + sbr->patch_num_subbands[sbr->num_patches] = FFMAX(sb - usb, 0); + sbr->patch_start_subband[sbr->num_patches] = sbr->k[0] - odd - sbr->patch_num_subbands[sbr->num_patches]; + + if (sbr->patch_num_subbands[sbr->num_patches] > 0) { + usb = sb; + msb = sb; + sbr->num_patches++; + } else + msb = sbr->kx[1]; + + if (sbr->f_master[k] - sb < 3) + k = sbr->n_master; + } while (sb != sbr->kx[1] + sbr->m[1]); + + if (sbr->patch_num_subbands[sbr->num_patches-1] < 3 && sbr->num_patches > 1) + sbr->num_patches--; + + return 0; +} + +/// Derived Frequency Band Tables (14496-3 sp04 p197) +static int sbr_make_f_derived(AACContext *ac, SpectralBandReplication *sbr) +{ + int k, temp; + + sbr->n[1] = sbr->n_master - sbr->spectrum_params.bs_xover_band; + sbr->n[0] = (sbr->n[1] + 1) >> 1; + + memcpy(sbr->f_tablehigh, &sbr->f_master[sbr->spectrum_params.bs_xover_band], + (sbr->n[1] + 1) * sizeof(sbr->f_master[0])); + sbr->m[1] = sbr->f_tablehigh[sbr->n[1]] - sbr->f_tablehigh[0]; + sbr->kx[1] = sbr->f_tablehigh[0]; + + // Requirements (14496-3 sp04 p205) + if (sbr->kx[1] + sbr->m[1] > 64) { + av_log(ac->avccontext, AV_LOG_ERROR, + "Stop frequency border too high: %d\n", sbr->kx[1] + sbr->m[1]); + return -1; + } + if (sbr->kx[1] > 32) { + av_log(ac->avccontext, AV_LOG_ERROR, "Start frequency border too high: %d\n", sbr->kx[1]); + return -1; + } + + sbr->f_tablelow[0] = sbr->f_tablehigh[0]; + temp = sbr->n[1] & 1; + for (k = 1; k <= sbr->n[0]; k++) + sbr->f_tablelow[k] = sbr->f_tablehigh[2 * k - temp]; + + sbr->n_q = FFMAX(1, lrintf(sbr->spectrum_params.bs_noise_bands * + log2f(sbr->k[2] / (float)sbr->kx[1]))); // 0 <= bs_noise_bands <= 3 + if (sbr->n_q > 5) { + av_log(ac->avccontext, AV_LOG_ERROR, "Too many noise floor scale factors: %d\n", sbr->n_q); + return -1; + } + + sbr->f_tablenoise[0] = sbr->f_tablelow[0]; + temp = 0; + for (k = 1; k <= sbr->n_q; k++) { + temp += (sbr->n[0] - temp) / (sbr->n_q + 1 - k); + sbr->f_tablenoise[k] = sbr->f_tablelow[temp]; + } + + if (sbr_hf_calc_npatches(ac, sbr) < 0) + return -1; + + sbr_make_f_tablelim(sbr); + + sbr->data[0].f_indexnoise = 0; + sbr->data[1].f_indexnoise = 0; + + return 0; +} + +static av_always_inline void get_bits1_vector(GetBitContext *gb, uint8_t *vec, + int elements) +{ + int i; + for (i = 0; i < elements; i++) { + vec[i] = get_bits1(gb); + } +} + +/** ceil(log2(index+1)) */ +static const int8_t ceil_log2[] = { + 0, 1, 2, 2, 3, 3, +}; + +static int read_sbr_grid(AACContext *ac, SpectralBandReplication *sbr, + GetBitContext *gb, SBRData *ch_data) +{ + int i; + unsigned bs_pointer = 0; + // frameLengthFlag ? 15 : 16; 960 sample length frames unsupported; this value is numTimeSlots + int abs_bord_trail = 16; + int num_rel_lead, num_rel_trail; + unsigned bs_num_env_old = ch_data->bs_num_env; + + ch_data->bs_freq_res[0] = ch_data->bs_freq_res[ch_data->bs_num_env]; + ch_data->bs_amp_res = sbr->bs_amp_res_header; + ch_data->t_env_num_env_old = ch_data->t_env[bs_num_env_old]; + + switch (ch_data->bs_frame_class = get_bits(gb, 2)) { + case FIXFIX: + ch_data->bs_num_env = 1 << get_bits(gb, 2); + num_rel_lead = ch_data->bs_num_env - 1; + if (ch_data->bs_num_env == 1) + ch_data->bs_amp_res = 0; + + if (ch_data->bs_num_env > 4) { + av_log(ac->avccontext, AV_LOG_ERROR, + "Invalid bitstream, too many SBR envelopes in FIXFIX type SBR frame: %d\n", + ch_data->bs_num_env); + return -1; + } + + ch_data->t_env[0] = 0; + ch_data->t_env[ch_data->bs_num_env] = abs_bord_trail; + + abs_bord_trail = (abs_bord_trail + (ch_data->bs_num_env >> 1)) / + ch_data->bs_num_env; + for (i = 0; i < num_rel_lead; i++) + ch_data->t_env[i + 1] = ch_data->t_env[i] + abs_bord_trail; + + ch_data->bs_freq_res[1] = get_bits1(gb); + for (i = 1; i < ch_data->bs_num_env; i++) + ch_data->bs_freq_res[i + 1] = ch_data->bs_freq_res[1]; + break; + case FIXVAR: + abs_bord_trail += get_bits(gb, 2); + num_rel_trail = get_bits(gb, 2); + ch_data->bs_num_env = num_rel_trail + 1; + ch_data->t_env[0] = 0; + ch_data->t_env[ch_data->bs_num_env] = abs_bord_trail; + + for (i = 0; i < num_rel_trail; i++) + ch_data->t_env[ch_data->bs_num_env - 1 - i] = + ch_data->t_env[ch_data->bs_num_env - i] - 2 * get_bits(gb, 2) - 2; + + bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env]); + + for (i = 0; i < ch_data->bs_num_env; i++) + ch_data->bs_freq_res[ch_data->bs_num_env - i] = get_bits1(gb); + break; + case VARFIX: + ch_data->t_env[0] = get_bits(gb, 2); + num_rel_lead = get_bits(gb, 2); + ch_data->bs_num_env = num_rel_lead + 1; + ch_data->t_env[ch_data->bs_num_env] = abs_bord_trail; + + for (i = 0; i < num_rel_lead; i++) + ch_data->t_env[i + 1] = ch_data->t_env[i] + 2 * get_bits(gb, 2) + 2; + + bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env]); + + get_bits1_vector(gb, ch_data->bs_freq_res + 1, ch_data->bs_num_env); + break; + case VARVAR: + ch_data->t_env[0] = get_bits(gb, 2); + abs_bord_trail += get_bits(gb, 2); + num_rel_lead = get_bits(gb, 2); + num_rel_trail = get_bits(gb, 2); + ch_data->bs_num_env = num_rel_lead + num_rel_trail + 1; + + if (ch_data->bs_num_env > 5) { + av_log(ac->avccontext, AV_LOG_ERROR, + "Invalid bitstream, too many SBR envelopes in VARVAR type SBR frame: %d\n", + ch_data->bs_num_env); + return -1; + } + + ch_data->t_env[ch_data->bs_num_env] = abs_bord_trail; + + for (i = 0; i < num_rel_lead; i++) + ch_data->t_env[i + 1] = ch_data->t_env[i] + 2 * get_bits(gb, 2) + 2; + for (i = 0; i < num_rel_trail; i++) + ch_data->t_env[ch_data->bs_num_env - 1 - i] = + ch_data->t_env[ch_data->bs_num_env - i] - 2 * get_bits(gb, 2) - 2; + + bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env]); + + get_bits1_vector(gb, ch_data->bs_freq_res + 1, ch_data->bs_num_env); + break; + } + + if (bs_pointer > ch_data->bs_num_env + 1) { + av_log(ac->avccontext, AV_LOG_ERROR, + "Invalid bitstream, bs_pointer points to a middle noise border outside the time borders table: %d\n", + bs_pointer); + return -1; + } + + for (i = 1; i <= ch_data->bs_num_env; i++) { + if (ch_data->t_env[i-1] > ch_data->t_env[i]) { + av_log(ac->avccontext, AV_LOG_ERROR, "Non monotone time borders\n"); + return -1; + } + } + + ch_data->bs_num_noise = (ch_data->bs_num_env > 1) + 1; + + ch_data->t_q[0] = ch_data->t_env[0]; + ch_data->t_q[ch_data->bs_num_noise] = ch_data->t_env[ch_data->bs_num_env]; + if (ch_data->bs_num_noise > 1) { + unsigned int idx; + if (ch_data->bs_frame_class == FIXFIX) { + idx = ch_data->bs_num_env >> 1; + } else if (ch_data->bs_frame_class & 1) { // FIXVAR or VARVAR + idx = ch_data->bs_num_env - FFMAX(bs_pointer - 1, 1); + } else { // VARFIX + if (!bs_pointer) + idx = 1; + else if (bs_pointer == 1) + idx = ch_data->bs_num_env - 1; + else // bs_pointer > 1 + idx = bs_pointer - 1; + } + ch_data->t_q[1] = ch_data->t_env[idx]; + } + + ch_data->e_a[0] = -(ch_data->e_a[1] != bs_num_env_old); // l_APrev + ch_data->e_a[1] = -1; + if ((ch_data->bs_frame_class & 1) && bs_pointer) { // FIXVAR or VARVAR and bs_pointer != 0 + ch_data->e_a[1] = ch_data->bs_num_env + 1 - bs_pointer; + } else if ((ch_data->bs_frame_class == 2) && (bs_pointer > 1)) // VARFIX and bs_pointer > 1 + ch_data->e_a[1] = bs_pointer - 1; + + return 0; +} + +static void copy_sbr_grid(SBRData *dst, const SBRData *src) { + //These variables are saved from the previous frame rather than copied + dst->bs_freq_res[0] = dst->bs_freq_res[dst->bs_num_env]; + dst->t_env_num_env_old = dst->t_env[dst->bs_num_env]; + dst->e_a[0] = -(dst->e_a[1] != dst->bs_num_env); + + //These variables are read from the bitstream and therefore copied + memcpy(dst->bs_freq_res+1, src->bs_freq_res+1, sizeof(dst->bs_freq_res)-sizeof(*dst->bs_freq_res)); + memcpy(dst->t_env, src->t_env, sizeof(dst->t_env)); + memcpy(dst->t_q, src->t_q, sizeof(dst->t_q)); + dst->bs_num_env = src->bs_num_env; + dst->bs_amp_res = src->bs_amp_res; + dst->bs_num_noise = src->bs_num_noise; + dst->bs_frame_class = src->bs_frame_class; + dst->e_a[1] = src->e_a[1]; +} + +/// Read how the envelope and noise floor data is delta coded +static void read_sbr_dtdf(SpectralBandReplication *sbr, GetBitContext *gb, + SBRData *ch_data) +{ + get_bits1_vector(gb, ch_data->bs_df_env, ch_data->bs_num_env); + get_bits1_vector(gb, ch_data->bs_df_noise, ch_data->bs_num_noise); +} + +/// Read inverse filtering data +static void read_sbr_invf(SpectralBandReplication *sbr, GetBitContext *gb, + SBRData *ch_data) +{ + int i; + + memcpy(ch_data->bs_invf_mode[1], ch_data->bs_invf_mode[0], 5 * sizeof(uint8_t)); + for (i = 0; i < sbr->n_q; i++) + ch_data->bs_invf_mode[0][i] = get_bits(gb, 2); +} + +static void read_sbr_envelope(SpectralBandReplication *sbr, GetBitContext *gb, + SBRData *ch_data, int ch) +{ + int bits; + int i, j, k; + VLC_TYPE (*t_huff)[2], (*f_huff)[2]; + int t_lav, f_lav; + const int delta = (ch == 1 && sbr->bs_coupling == 1) + 1; + const int odd = sbr->n[1] & 1; + + if (sbr->bs_coupling && ch) { + if (ch_data->bs_amp_res) { + bits = 5; + t_huff = vlc_sbr[T_HUFFMAN_ENV_BAL_3_0DB].table; + t_lav = vlc_sbr_lav[T_HUFFMAN_ENV_BAL_3_0DB]; + f_huff = vlc_sbr[F_HUFFMAN_ENV_BAL_3_0DB].table; + f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_BAL_3_0DB]; + } else { + bits = 6; + t_huff = vlc_sbr[T_HUFFMAN_ENV_BAL_1_5DB].table; + t_lav = vlc_sbr_lav[T_HUFFMAN_ENV_BAL_1_5DB]; + f_huff = vlc_sbr[F_HUFFMAN_ENV_BAL_1_5DB].table; + f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_BAL_1_5DB]; + } + } else { + if (ch_data->bs_amp_res) { + bits = 6; + t_huff = vlc_sbr[T_HUFFMAN_ENV_3_0DB].table; + t_lav = vlc_sbr_lav[T_HUFFMAN_ENV_3_0DB]; + f_huff = vlc_sbr[F_HUFFMAN_ENV_3_0DB].table; + f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_3_0DB]; + } else { + bits = 7; + t_huff = vlc_sbr[T_HUFFMAN_ENV_1_5DB].table; + t_lav = vlc_sbr_lav[T_HUFFMAN_ENV_1_5DB]; + f_huff = vlc_sbr[F_HUFFMAN_ENV_1_5DB].table; + f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_1_5DB]; + } + } + + for (i = 0; i < ch_data->bs_num_env; i++) { + if (ch_data->bs_df_env[i]) { + // bs_freq_res[0] == bs_freq_res[bs_num_env] from prev frame + if (ch_data->bs_freq_res[i + 1] == ch_data->bs_freq_res[i]) { + for (j = 0; j < sbr->n[ch_data->bs_freq_res[i + 1]]; j++) + ch_data->env_facs[i + 1][j] = ch_data->env_facs[i][j] + delta * (get_vlc2(gb, t_huff, 9, 3) - t_lav); + } else if (ch_data->bs_freq_res[i + 1]) { + for (j = 0; j < sbr->n[ch_data->bs_freq_res[i + 1]]; j++) { + k = (j + odd) >> 1; // find k such that f_tablelow[k] <= f_tablehigh[j] < f_tablelow[k + 1] + ch_data->env_facs[i + 1][j] = ch_data->env_facs[i][k] + delta * (get_vlc2(gb, t_huff, 9, 3) - t_lav); + } + } else { + for (j = 0; j < sbr->n[ch_data->bs_freq_res[i + 1]]; j++) { + k = j ? 2*j - odd : 0; // find k such that f_tablehigh[k] == f_tablelow[j] + ch_data->env_facs[i + 1][j] = ch_data->env_facs[i][k] + delta * (get_vlc2(gb, t_huff, 9, 3) - t_lav); + } + } + } else { + ch_data->env_facs[i + 1][0] = delta * get_bits(gb, bits); // bs_env_start_value_balance + for (j = 1; j < sbr->n[ch_data->bs_freq_res[i + 1]]; j++) + ch_data->env_facs[i + 1][j] = ch_data->env_facs[i + 1][j - 1] + delta * (get_vlc2(gb, f_huff, 9, 3) - f_lav); + } + } + + //assign 0th elements of env_facs from last elements + memcpy(ch_data->env_facs[0], ch_data->env_facs[ch_data->bs_num_env], + sizeof(ch_data->env_facs[0])); +} + +static void read_sbr_noise(SpectralBandReplication *sbr, GetBitContext *gb, + SBRData *ch_data, int ch) +{ + int i, j; + VLC_TYPE (*t_huff)[2], (*f_huff)[2]; + int t_lav, f_lav; + int delta = (ch == 1 && sbr->bs_coupling == 1) + 1; + + if (sbr->bs_coupling && ch) { + t_huff = vlc_sbr[T_HUFFMAN_NOISE_BAL_3_0DB].table; + t_lav = vlc_sbr_lav[T_HUFFMAN_NOISE_BAL_3_0DB]; + f_huff = vlc_sbr[F_HUFFMAN_ENV_BAL_3_0DB].table; + f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_BAL_3_0DB]; + } else { + t_huff = vlc_sbr[T_HUFFMAN_NOISE_3_0DB].table; + t_lav = vlc_sbr_lav[T_HUFFMAN_NOISE_3_0DB]; + f_huff = vlc_sbr[F_HUFFMAN_ENV_3_0DB].table; + f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_3_0DB]; + } + + for (i = 0; i < ch_data->bs_num_noise; i++) { + if (ch_data->bs_df_noise[i]) { + for (j = 0; j < sbr->n_q; j++) + ch_data->noise_facs[i + 1][j] = ch_data->noise_facs[i][j] + delta * (get_vlc2(gb, t_huff, 9, 2) - t_lav); + } else { + ch_data->noise_facs[i + 1][0] = delta * get_bits(gb, 5); // bs_noise_start_value_balance or bs_noise_start_value_level + for (j = 1; j < sbr->n_q; j++) + ch_data->noise_facs[i + 1][j] = ch_data->noise_facs[i + 1][j - 1] + delta * (get_vlc2(gb, f_huff, 9, 3) - f_lav); + } + } + + //assign 0th elements of noise_facs from last elements + memcpy(ch_data->noise_facs[0], ch_data->noise_facs[ch_data->bs_num_noise], + sizeof(ch_data->noise_facs[0])); +} + +static void read_sbr_extension(AACContext *ac, SpectralBandReplication *sbr, + GetBitContext *gb, + int bs_extension_id, int *num_bits_left) +{ +//TODO - implement ps_data for parametric stereo parsing + switch (bs_extension_id) { + case EXTENSION_ID_PS: + if (!ac->m4ac.ps) { + av_log(ac->avccontext, AV_LOG_ERROR, "Parametric Stereo signaled to be not-present but was found in the bitstream.\n"); + skip_bits_long(gb, *num_bits_left); // bs_fill_bits + *num_bits_left = 0; + } else { +#if 0 + *num_bits_left -= ff_ps_data(gb, ps); +#else + av_log_missing_feature(ac->avccontext, "Parametric Stereo is", 0); + skip_bits_long(gb, *num_bits_left); // bs_fill_bits + *num_bits_left = 0; +#endif + } + break; + default: + av_log_missing_feature(ac->avccontext, "Reserved SBR extensions are", 1); + skip_bits_long(gb, *num_bits_left); // bs_fill_bits + *num_bits_left = 0; + break; + } +} + +static int read_sbr_single_channel_element(AACContext *ac, + SpectralBandReplication *sbr, + GetBitContext *gb) +{ + if (get_bits1(gb)) // bs_data_extra + skip_bits(gb, 4); // bs_reserved + + if (read_sbr_grid(ac, sbr, gb, &sbr->data[0])) + return -1; + read_sbr_dtdf(sbr, gb, &sbr->data[0]); + read_sbr_invf(sbr, gb, &sbr->data[0]); + read_sbr_envelope(sbr, gb, &sbr->data[0], 0); + read_sbr_noise(sbr, gb, &sbr->data[0], 0); + + if ((sbr->data[0].bs_add_harmonic_flag = get_bits1(gb))) + get_bits1_vector(gb, sbr->data[0].bs_add_harmonic, sbr->n[1]); + + return 0; +} + +static int read_sbr_channel_pair_element(AACContext *ac, + SpectralBandReplication *sbr, + GetBitContext *gb) +{ + if (get_bits1(gb)) // bs_data_extra + skip_bits(gb, 8); // bs_reserved + + if ((sbr->bs_coupling = get_bits1(gb))) { + if (read_sbr_grid(ac, sbr, gb, &sbr->data[0])) + return -1; + copy_sbr_grid(&sbr->data[1], &sbr->data[0]); + read_sbr_dtdf(sbr, gb, &sbr->data[0]); + read_sbr_dtdf(sbr, gb, &sbr->data[1]); + read_sbr_invf(sbr, gb, &sbr->data[0]); + memcpy(sbr->data[1].bs_invf_mode[1], sbr->data[1].bs_invf_mode[0], sizeof(sbr->data[1].bs_invf_mode[0])); + memcpy(sbr->data[1].bs_invf_mode[0], sbr->data[0].bs_invf_mode[0], sizeof(sbr->data[1].bs_invf_mode[0])); + read_sbr_envelope(sbr, gb, &sbr->data[0], 0); + read_sbr_noise(sbr, gb, &sbr->data[0], 0); + read_sbr_envelope(sbr, gb, &sbr->data[1], 1); + read_sbr_noise(sbr, gb, &sbr->data[1], 1); + } else { + if (read_sbr_grid(ac, sbr, gb, &sbr->data[0]) || + read_sbr_grid(ac, sbr, gb, &sbr->data[1])) + return -1; + read_sbr_dtdf(sbr, gb, &sbr->data[0]); + read_sbr_dtdf(sbr, gb, &sbr->data[1]); + read_sbr_invf(sbr, gb, &sbr->data[0]); + read_sbr_invf(sbr, gb, &sbr->data[1]); + read_sbr_envelope(sbr, gb, &sbr->data[0], 0); + read_sbr_envelope(sbr, gb, &sbr->data[1], 1); + read_sbr_noise(sbr, gb, &sbr->data[0], 0); + read_sbr_noise(sbr, gb, &sbr->data[1], 1); + } + + if ((sbr->data[0].bs_add_harmonic_flag = get_bits1(gb))) + get_bits1_vector(gb, sbr->data[0].bs_add_harmonic, sbr->n[1]); + if ((sbr->data[1].bs_add_harmonic_flag = get_bits1(gb))) + get_bits1_vector(gb, sbr->data[1].bs_add_harmonic, sbr->n[1]); + + return 0; +} + +static unsigned int read_sbr_data(AACContext *ac, SpectralBandReplication *sbr, + GetBitContext *gb, int id_aac) +{ + unsigned int cnt = get_bits_count(gb); + + if (id_aac == TYPE_SCE || id_aac == TYPE_CCE) { + if (read_sbr_single_channel_element(ac, sbr, gb)) { + sbr->start = 0; + return get_bits_count(gb) - cnt; + } + } else if (id_aac == TYPE_CPE) { + if (read_sbr_channel_pair_element(ac, sbr, gb)) { + sbr->start = 0; + return get_bits_count(gb) - cnt; + } + } else { + av_log(ac->avccontext, AV_LOG_ERROR, + "Invalid bitstream - cannot apply SBR to element type %d\n", id_aac); + sbr->start = 0; + return get_bits_count(gb) - cnt; + } + if (get_bits1(gb)) { // bs_extended_data + int num_bits_left = get_bits(gb, 4); // bs_extension_size + if (num_bits_left == 15) + num_bits_left += get_bits(gb, 8); // bs_esc_count + + num_bits_left <<= 3; + while (num_bits_left > 7) { + num_bits_left -= 2; + read_sbr_extension(ac, sbr, gb, get_bits(gb, 2), &num_bits_left); // bs_extension_id + } + } + + return get_bits_count(gb) - cnt; +} + +static void sbr_reset(AACContext *ac, SpectralBandReplication *sbr) +{ + int err; + err = sbr_make_f_master(ac, sbr, &sbr->spectrum_params); + if (err >= 0) + err = sbr_make_f_derived(ac, sbr); + if (err < 0) { + av_log(ac->avccontext, AV_LOG_ERROR, + "SBR reset failed. Switching SBR to pure upsampling mode.\n"); + sbr->start = 0; + } +} + +/** + * Decode Spectral Band Replication extension data; reference: table 4.55. + * + * @param crc flag indicating the presence of CRC checksum + * @param cnt length of TYPE_FIL syntactic element in bytes + * + * @return Returns number of bytes consumed from the TYPE_FIL element. + */ +int ff_decode_sbr_extension(AACContext *ac, SpectralBandReplication *sbr, + GetBitContext *gb_host, int crc, int cnt, int id_aac) +{ + unsigned int num_sbr_bits = 0, num_align_bits; + unsigned bytes_read; + GetBitContext gbc = *gb_host, *gb = &gbc; + skip_bits_long(gb_host, cnt*8 - 4); + + sbr->reset = 0; + + if (!sbr->sample_rate) + sbr->sample_rate = 2 * ac->m4ac.sample_rate; //TODO use the nominal sample rate for arbitrary sample rate support + if (!ac->m4ac.ext_sample_rate) + ac->m4ac.ext_sample_rate = 2 * ac->m4ac.sample_rate; + + if (crc) { + skip_bits(gb, 10); // bs_sbr_crc_bits; TODO - implement CRC check + num_sbr_bits += 10; + } + + //Save some state from the previous frame. + sbr->kx[0] = sbr->kx[1]; + sbr->m[0] = sbr->m[1]; + + num_sbr_bits++; + if (get_bits1(gb)) // bs_header_flag + num_sbr_bits += read_sbr_header(sbr, gb); + + if (sbr->reset) + sbr_reset(ac, sbr); + + if (sbr->start) + num_sbr_bits += read_sbr_data(ac, sbr, gb, id_aac); + + num_align_bits = ((cnt << 3) - 4 - num_sbr_bits) & 7; + bytes_read = ((num_sbr_bits + num_align_bits + 4) >> 3); + + if (bytes_read > cnt) { + av_log(ac->avccontext, AV_LOG_ERROR, + "Expected to read %d SBR bytes actually read %d.\n", cnt, bytes_read); + } + return cnt; +} + +/// Dequantization and stereo decoding (14496-3 sp04 p203) +static void sbr_dequant(SpectralBandReplication *sbr, int id_aac) +{ + int k, e; + int ch; + + if (id_aac == TYPE_CPE && sbr->bs_coupling) { + float alpha = sbr->data[0].bs_amp_res ? 1.0f : 0.5f; + float pan_offset = sbr->data[0].bs_amp_res ? 12.0f : 24.0f; + for (e = 1; e <= sbr->data[0].bs_num_env; e++) { + for (k = 0; k < sbr->n[sbr->data[0].bs_freq_res[e]]; k++) { + float temp1 = exp2f(sbr->data[0].env_facs[e][k] * alpha + 7.0f); + float temp2 = exp2f((pan_offset - sbr->data[1].env_facs[e][k]) * alpha); + float fac = temp1 / (1.0f + temp2); + sbr->data[0].env_facs[e][k] = fac; + sbr->data[1].env_facs[e][k] = fac * temp2; + } + } + for (e = 1; e <= sbr->data[0].bs_num_noise; e++) { + for (k = 0; k < sbr->n_q; k++) { + float temp1 = exp2f(NOISE_FLOOR_OFFSET - sbr->data[0].noise_facs[e][k] + 1); + float temp2 = exp2f(12 - sbr->data[1].noise_facs[e][k]); + float fac = temp1 / (1.0f + temp2); + sbr->data[0].noise_facs[e][k] = fac; + sbr->data[1].noise_facs[e][k] = fac * temp2; + } + } + } else { // SCE or one non-coupled CPE + for (ch = 0; ch < (id_aac == TYPE_CPE) + 1; ch++) { + float alpha = sbr->data[ch].bs_amp_res ? 1.0f : 0.5f; + for (e = 1; e <= sbr->data[ch].bs_num_env; e++) + for (k = 0; k < sbr->n[sbr->data[ch].bs_freq_res[e]]; k++) + sbr->data[ch].env_facs[e][k] = + exp2f(alpha * sbr->data[ch].env_facs[e][k] + 6.0f); + for (e = 1; e <= sbr->data[ch].bs_num_noise; e++) + for (k = 0; k < sbr->n_q; k++) + sbr->data[ch].noise_facs[e][k] = + exp2f(NOISE_FLOOR_OFFSET - sbr->data[ch].noise_facs[e][k]); + } + } +} + +/** + * Analysis QMF Bank (14496-3 sp04 p206) + * + * @param x pointer to the beginning of the first sample window + * @param W array of complex-valued samples split into subbands + */ +static void sbr_qmf_analysis(DSPContext *dsp, RDFTContext *rdft, const float *in, float *x, + float z[320], float W[2][32][32][2], + float scale) +{ + int i, k; + memcpy(W[0], W[1], sizeof(W[0])); + memcpy(x , x+1024, (320-32)*sizeof(x[0])); + if (scale != 1.0f) + dsp->vector_fmul_scalar(x+288, in, scale, 1024); + else + memcpy(x+288, in, 1024*sizeof(*x)); + for (i = 0; i < 32; i++) { // numTimeSlots*RATE = 16*2 as 960 sample frames + // are not supported + float re, im; + dsp->vector_fmul_reverse(z, sbr_qmf_window_ds, x, 320); + for (k = 0; k < 64; k++) { + float f = z[k] + z[k + 64] + z[k + 128] + z[k + 192] + z[k + 256]; + z[k] = f * analysis_cos_pre[k]; + z[k+64] = f; + } + ff_rdft_calc(rdft, z); + re = z[0] * 0.5f; + im = 0.5f * dsp->scalarproduct_float(z+64, analysis_sin_pre, 64); + W[1][i][0][0] = re * analysis_cossin_post[0][0] - im * analysis_cossin_post[0][1]; + W[1][i][0][1] = re * analysis_cossin_post[0][1] + im * analysis_cossin_post[0][0]; + for (k = 1; k < 32; k++) { + re = z[2*k ] - re; + im = z[2*k+1] - im; + W[1][i][k][0] = re * analysis_cossin_post[k][0] - im * analysis_cossin_post[k][1]; + W[1][i][k][1] = re * analysis_cossin_post[k][1] + im * analysis_cossin_post[k][0]; + } + x += 32; + } +} + +/** + * Synthesis QMF Bank (14496-3 sp04 p206) and Downsampled Synthesis QMF Bank + * (14496-3 sp04 p206) + */ +static void sbr_qmf_synthesis(DSPContext *dsp, FFTContext *mdct, + float *out, float X[2][32][64], + float mdct_buf[2][64], + float *v0, int *v_off, const unsigned int div, + float bias, float scale) +{ + int i, n; + const float *sbr_qmf_window = div ? sbr_qmf_window_ds : sbr_qmf_window_us; + int scale_and_bias = scale != 1.0f || bias != 0.0f; + float *v; + for (i = 0; i < 32; i++) { + if (*v_off == 0) { + int saved_samples = (1280 - 128) >> div; + memcpy(&v0[SBR_SYNTHESIS_BUF_SIZE - saved_samples], v0, saved_samples * sizeof(float)); + *v_off = SBR_SYNTHESIS_BUF_SIZE - saved_samples - (128 >> div); + } else { + *v_off -= 128 >> div; + } + v = v0 + *v_off; + for (n = 1; n < 64 >> div; n+=2) { + X[1][i][n] = -X[1][i][n]; + } + if (div) { + memset(X[0][i]+32, 0, 32*sizeof(float)); + memset(X[1][i]+32, 0, 32*sizeof(float)); + } + ff_imdct_half(mdct, mdct_buf[0], X[0][i]); + ff_imdct_half(mdct, mdct_buf[1], X[1][i]); + if (div) { + for (n = 0; n < 32; n++) { + v[ n] = -mdct_buf[0][63 - 2*n] + mdct_buf[1][2*n ]; + v[ 63 - n] = mdct_buf[0][62 - 2*n] + mdct_buf[1][2*n + 1]; + } + } else { + for (n = 0; n < 64; n++) { + v[ n] = -mdct_buf[0][63 - n] + mdct_buf[1][ n ]; + v[127 - n] = mdct_buf[0][63 - n] + mdct_buf[1][ n ]; + } + } + dsp->vector_fmul_add(out, v , sbr_qmf_window , zero64, 64 >> div); + dsp->vector_fmul_add(out, v + ( 192 >> div), sbr_qmf_window + ( 64 >> div), out , 64 >> div); + dsp->vector_fmul_add(out, v + ( 256 >> div), sbr_qmf_window + (128 >> div), out , 64 >> div); + dsp->vector_fmul_add(out, v + ( 448 >> div), sbr_qmf_window + (192 >> div), out , 64 >> div); + dsp->vector_fmul_add(out, v + ( 512 >> div), sbr_qmf_window + (256 >> div), out , 64 >> div); + dsp->vector_fmul_add(out, v + ( 704 >> div), sbr_qmf_window + (320 >> div), out , 64 >> div); + dsp->vector_fmul_add(out, v + ( 768 >> div), sbr_qmf_window + (384 >> div), out , 64 >> div); + dsp->vector_fmul_add(out, v + ( 960 >> div), sbr_qmf_window + (448 >> div), out , 64 >> div); + dsp->vector_fmul_add(out, v + (1024 >> div), sbr_qmf_window + (512 >> div), out , 64 >> div); + dsp->vector_fmul_add(out, v + (1216 >> div), sbr_qmf_window + (576 >> div), out , 64 >> div); + if (scale_and_bias) + for (n = 0; n < 64 >> div; n++) + out[n] = out[n] * scale + bias; + out += 64 >> div; + } +} + +static void autocorrelate(const float x[40][2], float phi[3][2][2], int lag) +{ + int i; + float real_sum = 0.0f; + float imag_sum = 0.0f; + if (lag) { + for (i = 1; i < 38; i++) { + real_sum += x[i][0] * x[i+lag][0] + x[i][1] * x[i+lag][1]; + imag_sum += x[i][0] * x[i+lag][1] - x[i][1] * x[i+lag][0]; + } + phi[2-lag][1][0] = real_sum + x[ 0][0] * x[lag][0] + x[ 0][1] * x[lag][1]; + phi[2-lag][1][1] = imag_sum + x[ 0][0] * x[lag][1] - x[ 0][1] * x[lag][0]; + if (lag == 1) { + phi[0][0][0] = real_sum + x[38][0] * x[39][0] + x[38][1] * x[39][1]; + phi[0][0][1] = imag_sum + x[38][0] * x[39][1] - x[38][1] * x[39][0]; + } + } else { + for (i = 1; i < 38; i++) { + real_sum += x[i][0] * x[i][0] + x[i][1] * x[i][1]; + } + phi[2][1][0] = real_sum + x[ 0][0] * x[ 0][0] + x[ 0][1] * x[ 0][1]; + phi[1][0][0] = real_sum + x[38][0] * x[38][0] + x[38][1] * x[38][1]; + } +} + +/** High Frequency Generation (14496-3 sp04 p214+) and Inverse Filtering + * (14496-3 sp04 p214) + * Warning: This routine does not seem numerically stable. + */ +static void sbr_hf_inverse_filter(float (*alpha0)[2], float (*alpha1)[2], + const float X_low[32][40][2], int k0) +{ + int k; + for (k = 0; k < k0; k++) { + float phi[3][2][2], dk; + + autocorrelate(X_low[k], phi, 0); + autocorrelate(X_low[k], phi, 1); + autocorrelate(X_low[k], phi, 2); + + dk = phi[2][1][0] * phi[1][0][0] - + (phi[1][1][0] * phi[1][1][0] + phi[1][1][1] * phi[1][1][1]) / 1.000001f; + + if (!dk) { + alpha1[k][0] = 0; + alpha1[k][1] = 0; + } else { + float temp_real, temp_im; + temp_real = phi[0][0][0] * phi[1][1][0] - + phi[0][0][1] * phi[1][1][1] - + phi[0][1][0] * phi[1][0][0]; + temp_im = phi[0][0][0] * phi[1][1][1] + + phi[0][0][1] * phi[1][1][0] - + phi[0][1][1] * phi[1][0][0]; + + alpha1[k][0] = temp_real / dk; + alpha1[k][1] = temp_im / dk; + } + + if (!phi[1][0][0]) { + alpha0[k][0] = 0; + alpha0[k][1] = 0; + } else { + float temp_real, temp_im; + temp_real = phi[0][0][0] + alpha1[k][0] * phi[1][1][0] + + alpha1[k][1] * phi[1][1][1]; + temp_im = phi[0][0][1] + alpha1[k][1] * phi[1][1][0] - + alpha1[k][0] * phi[1][1][1]; + + alpha0[k][0] = -temp_real / phi[1][0][0]; + alpha0[k][1] = -temp_im / phi[1][0][0]; + } + + if (alpha1[k][0] * alpha1[k][0] + alpha1[k][1] * alpha1[k][1] >= 16.0f || + alpha0[k][0] * alpha0[k][0] + alpha0[k][1] * alpha0[k][1] >= 16.0f) { + alpha1[k][0] = 0; + alpha1[k][1] = 0; + alpha0[k][0] = 0; + alpha0[k][1] = 0; + } + } +} + +/// Chirp Factors (14496-3 sp04 p214) +static void sbr_chirp(SpectralBandReplication *sbr, SBRData *ch_data) +{ + int i; + float new_bw; + static const float bw_tab[] = { 0.0f, 0.75f, 0.9f, 0.98f }; + + for (i = 0; i < sbr->n_q; i++) { + if (ch_data->bs_invf_mode[0][i] + ch_data->bs_invf_mode[1][i] == 1) { + new_bw = 0.6f; + } else + new_bw = bw_tab[ch_data->bs_invf_mode[0][i]]; + + if (new_bw < ch_data->bw_array[i]) { + new_bw = 0.75f * new_bw + 0.25f * ch_data->bw_array[i]; + } else + new_bw = 0.90625f * new_bw + 0.09375f * ch_data->bw_array[i]; + ch_data->bw_array[i] = new_bw < 0.015625f ? 0.0f : new_bw; + } +} + +/// Generate the subband filtered lowband +static int sbr_lf_gen(AACContext *ac, SpectralBandReplication *sbr, + float X_low[32][40][2], const float W[2][32][32][2]) +{ + int i, k; + const int t_HFGen = 8; + const int i_f = 32; + memset(X_low, 0, 32*sizeof(*X_low)); + for (k = 0; k < sbr->kx[1]; k++) { + for (i = t_HFGen; i < i_f + t_HFGen; i++) { + X_low[k][i][0] = W[1][i - t_HFGen][k][0]; + X_low[k][i][1] = W[1][i - t_HFGen][k][1]; + } + } + for (k = 0; k < sbr->kx[0]; k++) { + for (i = 0; i < t_HFGen; i++) { + X_low[k][i][0] = W[0][i + i_f - t_HFGen][k][0]; + X_low[k][i][1] = W[0][i + i_f - t_HFGen][k][1]; + } + } + return 0; +} + +/// High Frequency Generator (14496-3 sp04 p215) +static int sbr_hf_gen(AACContext *ac, SpectralBandReplication *sbr, + float X_high[64][40][2], const float X_low[32][40][2], + const float (*alpha0)[2], const float (*alpha1)[2], + const float bw_array[5], const uint8_t *t_env, + int bs_num_env) +{ + int i, j, x; + int g = 0; + int k = sbr->kx[1]; + for (j = 0; j < sbr->num_patches; j++) { + for (x = 0; x < sbr->patch_num_subbands[j]; x++, k++) { + float alpha[4]; + const int p = sbr->patch_start_subband[j] + x; + while (g <= sbr->n_q && k >= sbr->f_tablenoise[g]) + g++; + g--; + + if (g < 0) { + av_log(ac->avccontext, AV_LOG_ERROR, + "ERROR : no subband found for frequency %d\n", k); + return -1; + } + + alpha[0] = alpha1[p][0] * bw_array[g] * bw_array[g]; + alpha[1] = alpha1[p][1] * bw_array[g] * bw_array[g]; + alpha[2] = alpha0[p][0] * bw_array[g]; + alpha[3] = alpha0[p][1] * bw_array[g]; + + for (i = 2 * t_env[0]; i < 2 * t_env[bs_num_env]; i++) { + const int idx = i + ENVELOPE_ADJUSTMENT_OFFSET; + X_high[k][idx][0] = + X_low[p][idx - 2][0] * alpha[0] - + X_low[p][idx - 2][1] * alpha[1] + + X_low[p][idx - 1][0] * alpha[2] - + X_low[p][idx - 1][1] * alpha[3] + + X_low[p][idx][0]; + X_high[k][idx][1] = + X_low[p][idx - 2][1] * alpha[0] + + X_low[p][idx - 2][0] * alpha[1] + + X_low[p][idx - 1][1] * alpha[2] + + X_low[p][idx - 1][0] * alpha[3] + + X_low[p][idx][1]; + } + } + } + if (k < sbr->m[1] + sbr->kx[1]) + memset(X_high + k, 0, (sbr->m[1] + sbr->kx[1] - k) * sizeof(*X_high)); + + return 0; +} + +/// Generate the subband filtered lowband +static int sbr_x_gen(SpectralBandReplication *sbr, float X[2][32][64], + const float X_low[32][40][2], const float Y[2][38][64][2], + int ch) +{ + int k, i; + const int i_f = 32; + const int i_Temp = FFMAX(2*sbr->data[ch].t_env_num_env_old - i_f, 0); + memset(X, 0, 2*sizeof(*X)); + for (k = 0; k < sbr->kx[0]; k++) { + for (i = 0; i < i_Temp; i++) { + X[0][i][k] = X_low[k][i + ENVELOPE_ADJUSTMENT_OFFSET][0]; + X[1][i][k] = X_low[k][i + ENVELOPE_ADJUSTMENT_OFFSET][1]; + } + } + for (; k < sbr->kx[0] + sbr->m[0]; k++) { + for (i = 0; i < i_Temp; i++) { + X[0][i][k] = Y[0][i + i_f][k][0]; + X[1][i][k] = Y[0][i + i_f][k][1]; + } + } + + for (k = 0; k < sbr->kx[1]; k++) { + for (i = i_Temp; i < i_f; i++) { + X[0][i][k] = X_low[k][i + ENVELOPE_ADJUSTMENT_OFFSET][0]; + X[1][i][k] = X_low[k][i + ENVELOPE_ADJUSTMENT_OFFSET][1]; + } + } + for (; k < sbr->kx[1] + sbr->m[1]; k++) { + for (i = i_Temp; i < i_f; i++) { + X[0][i][k] = Y[1][i][k][0]; + X[1][i][k] = Y[1][i][k][1]; + } + } + return 0; +} + +/** High Frequency Adjustment (14496-3 sp04 p217) and Mapping + * (14496-3 sp04 p217) + */ +static void sbr_mapping(AACContext *ac, SpectralBandReplication *sbr, + SBRData *ch_data, int e_a[2]) +{ + int e, i, m; + + memset(ch_data->s_indexmapped[1], 0, 7*sizeof(ch_data->s_indexmapped[1])); + for (e = 0; e < ch_data->bs_num_env; e++) { + const unsigned int ilim = sbr->n[ch_data->bs_freq_res[e + 1]]; + uint16_t *table = ch_data->bs_freq_res[e + 1] ? sbr->f_tablehigh : sbr->f_tablelow; + int k; + + 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]; + + // ch_data->bs_num_noise > 1 => 2 noise floors + k = (ch_data->bs_num_noise > 1) && (ch_data->t_env[e] >= ch_data->t_q[1]); + for (i = 0; i < sbr->n_q; i++) + for (m = sbr->f_tablenoise[i]; m < sbr->f_tablenoise[i + 1]; m++) + sbr->q_mapped[e][m - sbr->kx[1]] = ch_data->noise_facs[k+1][i]; + + for (i = 0; i < sbr->n[1]; i++) { + if (ch_data->bs_add_harmonic_flag) { + const unsigned int m_midpoint = + (sbr->f_tablehigh[i] + sbr->f_tablehigh[i + 1]) >> 1; + + ch_data->s_indexmapped[e + 1][m_midpoint - sbr->kx[1]] = ch_data->bs_add_harmonic[i] * + (e >= e_a[1] || (ch_data->s_indexmapped[0][m_midpoint - sbr->kx[1]] == 1)); + } + } + + for (i = 0; i < ilim; i++) { + int additional_sinusoid_present = 0; + for (m = table[i]; m < table[i + 1]; m++) { + if (ch_data->s_indexmapped[e + 1][m - sbr->kx[1]]) { + additional_sinusoid_present = 1; + break; + } + } + memset(&sbr->s_mapped[e][table[i] - sbr->kx[1]], additional_sinusoid_present, + (table[i + 1] - table[i]) * sizeof(sbr->s_mapped[e][0])); + } + } + + memcpy(ch_data->s_indexmapped[0], ch_data->s_indexmapped[ch_data->bs_num_env], sizeof(ch_data->s_indexmapped[0])); +} + +/// Estimation of current envelope (14496-3 sp04 p218) +static void sbr_env_estimate(float (*e_curr)[48], float X_high[64][40][2], + SpectralBandReplication *sbr, SBRData *ch_data) +{ + int e, i, m; + + if (sbr->bs_interpol_freq) { + for (e = 0; e < ch_data->bs_num_env; e++) { + const float recip_env_size = 0.5f / (ch_data->t_env[e + 1] - ch_data->t_env[e]); + int ilb = ch_data->t_env[e] * 2 + ENVELOPE_ADJUSTMENT_OFFSET; + int iub = ch_data->t_env[e + 1] * 2 + ENVELOPE_ADJUSTMENT_OFFSET; + + for (m = 0; m < sbr->m[1]; m++) { + float sum = 0.0f; + + for (i = ilb; i < iub; i++) { + sum += X_high[m + sbr->kx[1]][i][0] * X_high[m + sbr->kx[1]][i][0] + + X_high[m + sbr->kx[1]][i][1] * X_high[m + sbr->kx[1]][i][1]; + } + e_curr[e][m] = sum * recip_env_size; + } + } + } else { + int k, p; + + for (e = 0; e < ch_data->bs_num_env; e++) { + const int env_size = 2 * (ch_data->t_env[e + 1] - ch_data->t_env[e]); + int ilb = ch_data->t_env[e] * 2 + ENVELOPE_ADJUSTMENT_OFFSET; + int iub = ch_data->t_env[e + 1] * 2 + ENVELOPE_ADJUSTMENT_OFFSET; + const uint16_t *table = ch_data->bs_freq_res[e + 1] ? sbr->f_tablehigh : sbr->f_tablelow; + + for (p = 0; p < sbr->n[ch_data->bs_freq_res[e + 1]]; p++) { + float sum = 0.0f; + const int den = env_size * (table[p + 1] - table[p]); + + for (k = table[p]; k < table[p + 1]; k++) { + for (i = ilb; i < iub; i++) { + sum += X_high[k][i][0] * X_high[k][i][0] + + X_high[k][i][1] * X_high[k][i][1]; + } + } + sum /= den; + for (k = table[p]; k < table[p + 1]; k++) { + e_curr[e][k - sbr->kx[1]] = sum; + } + } + } + } +} + +/** + * Calculation of levels of additional HF signal components (14496-3 sp04 p219) + * and Calculation of gain (14496-3 sp04 p219) + */ +static void sbr_gain_calc(AACContext *ac, SpectralBandReplication *sbr, + SBRData *ch_data, const int e_a[2]) +{ + int e, k, m; + // max gain limits : -3dB, 0dB, 3dB, inf dB (limiter off) + static const float limgain[4] = { 0.70795, 1.0, 1.41254, 10000000000 }; + + for (e = 0; e < ch_data->bs_num_env; e++) { + int delta = !((e == e_a[1]) || (e == e_a[0])); + for (k = 0; k < sbr->n_lim; k++) { + float gain_boost, gain_max; + float sum[2] = { 0.0f, 0.0f }; + for (m = sbr->f_tablelim[k] - sbr->kx[1]; m < sbr->f_tablelim[k + 1] - sbr->kx[1]; m++) { + const float temp = sbr->e_origmapped[e][m] / (1.0f + sbr->q_mapped[e][m]); + sbr->q_m[e][m] = sqrtf(temp * sbr->q_mapped[e][m]); + sbr->s_m[e][m] = sqrtf(temp * ch_data->s_indexmapped[e + 1][m]); + if (!sbr->s_mapped[e][m]) { + sbr->gain[e][m] = sqrtf(sbr->e_origmapped[e][m] / + ((1.0f + sbr->e_curr[e][m]) * + (1.0f + sbr->q_mapped[e][m] * delta))); + } else { + sbr->gain[e][m] = sqrtf(sbr->e_origmapped[e][m] * sbr->q_mapped[e][m] / + ((1.0f + sbr->e_curr[e][m]) * + (1.0f + sbr->q_mapped[e][m]))); + } + } + for (m = sbr->f_tablelim[k] - sbr->kx[1]; m < sbr->f_tablelim[k + 1] - sbr->kx[1]; m++) { + sum[0] += sbr->e_origmapped[e][m]; + sum[1] += sbr->e_curr[e][m]; + } + gain_max = limgain[sbr->bs_limiter_gains] * sqrtf((FLT_EPSILON + sum[0]) / (FLT_EPSILON + sum[1])); + gain_max = FFMIN(100000, gain_max); + for (m = sbr->f_tablelim[k] - sbr->kx[1]; m < sbr->f_tablelim[k + 1] - sbr->kx[1]; m++) { + float q_m_max = sbr->q_m[e][m] * gain_max / sbr->gain[e][m]; + sbr->q_m[e][m] = FFMIN(sbr->q_m[e][m], q_m_max); + sbr->gain[e][m] = FFMIN(sbr->gain[e][m], gain_max); + } + sum[0] = sum[1] = 0.0f; + for (m = sbr->f_tablelim[k] - sbr->kx[1]; m < sbr->f_tablelim[k + 1] - sbr->kx[1]; m++) { + sum[0] += sbr->e_origmapped[e][m]; + sum[1] += sbr->e_curr[e][m] * sbr->gain[e][m] * sbr->gain[e][m] + + sbr->s_m[e][m] * sbr->s_m[e][m] + + (delta && !sbr->s_m[e][m]) * sbr->q_m[e][m] * sbr->q_m[e][m]; + } + gain_boost = sqrtf((FLT_EPSILON + sum[0]) / (FLT_EPSILON + sum[1])); + gain_boost = FFMIN(1.584893192, gain_boost); + for (m = sbr->f_tablelim[k] - sbr->kx[1]; m < sbr->f_tablelim[k + 1] - sbr->kx[1]; m++) { + sbr->gain[e][m] *= gain_boost; + sbr->q_m[e][m] *= gain_boost; + sbr->s_m[e][m] *= gain_boost; + } + } + } +} + +/// Assembling HF Signals (14496-3 sp04 p220) +static void sbr_hf_assemble(float Y[2][38][64][2], const float X_high[64][40][2], + SpectralBandReplication *sbr, SBRData *ch_data, + const int e_a[2]) +{ + int e, i, j, m; + const int h_SL = 4 * !sbr->bs_smoothing_mode; + const int kx = sbr->kx[1]; + const int m_max = sbr->m[1]; + static const float h_smooth[5] = { + 0.33333333333333, + 0.30150283239582, + 0.21816949906249, + 0.11516383427084, + 0.03183050093751, + }; + static const int8_t phi[2][4] = { + { 1, 0, -1, 0}, // real + { 0, 1, 0, -1}, // imaginary + }; + float (*g_temp)[48] = ch_data->g_temp, (*q_temp)[48] = ch_data->q_temp; + int indexnoise = ch_data->f_indexnoise; + int indexsine = ch_data->f_indexsine; + memcpy(Y[0], Y[1], sizeof(Y[0])); + + if (sbr->reset) { + for (i = 0; i < h_SL; i++) { + memcpy(g_temp[i + 2*ch_data->t_env[0]], sbr->gain[0], m_max * sizeof(sbr->gain[0][0])); + memcpy(q_temp[i + 2*ch_data->t_env[0]], sbr->q_m[0], m_max * sizeof(sbr->q_m[0][0])); + } + } else if (h_SL) { + memcpy(g_temp[2*ch_data->t_env[0]], g_temp[2*ch_data->t_env_num_env_old], 4*sizeof(g_temp[0])); + memcpy(q_temp[2*ch_data->t_env[0]], q_temp[2*ch_data->t_env_num_env_old], 4*sizeof(q_temp[0])); + } + + for (e = 0; e < ch_data->bs_num_env; e++) { + for (i = 2 * ch_data->t_env[e]; i < 2 * ch_data->t_env[e + 1]; i++) { + memcpy(g_temp[h_SL + i], sbr->gain[e], m_max * sizeof(sbr->gain[0][0])); + memcpy(q_temp[h_SL + i], sbr->q_m[e], m_max * sizeof(sbr->q_m[0][0])); + } + } + + for (e = 0; e < ch_data->bs_num_env; e++) { + for (i = 2 * ch_data->t_env[e]; i < 2 * ch_data->t_env[e + 1]; i++) { + int phi_sign = (1 - 2*(kx & 1)); + + if (h_SL && e != e_a[0] && e != e_a[1]) { + for (m = 0; m < m_max; m++) { + const int idx1 = i + h_SL; + float g_filt = 0.0f; + for (j = 0; j <= h_SL; j++) + g_filt += g_temp[idx1 - j][m] * h_smooth[j]; + Y[1][i][m + kx][0] = + X_high[m + kx][i + ENVELOPE_ADJUSTMENT_OFFSET][0] * g_filt; + Y[1][i][m + kx][1] = + X_high[m + kx][i + ENVELOPE_ADJUSTMENT_OFFSET][1] * g_filt; + } + } else { + for (m = 0; m < m_max; m++) { + const float g_filt = g_temp[i + h_SL][m]; + Y[1][i][m + kx][0] = + X_high[m + kx][i + ENVELOPE_ADJUSTMENT_OFFSET][0] * g_filt; + Y[1][i][m + kx][1] = + X_high[m + kx][i + ENVELOPE_ADJUSTMENT_OFFSET][1] * g_filt; + } + } + + if (e != e_a[0] && e != e_a[1]) { + for (m = 0; m < m_max; m++) { + indexnoise = (indexnoise + 1) & 0x1ff; + if (sbr->s_m[e][m]) { + Y[1][i][m + kx][0] += + sbr->s_m[e][m] * phi[0][indexsine]; + Y[1][i][m + kx][1] += + sbr->s_m[e][m] * (phi[1][indexsine] * phi_sign); + } else { + float q_filt; + if (h_SL) { + const int idx1 = i + h_SL; + q_filt = 0.0f; + for (j = 0; j <= h_SL; j++) + q_filt += q_temp[idx1 - j][m] * h_smooth[j]; + } else { + q_filt = q_temp[i][m]; + } + Y[1][i][m + kx][0] += + q_filt * sbr_noise_table[indexnoise][0]; + Y[1][i][m + kx][1] += + q_filt * sbr_noise_table[indexnoise][1]; + } + phi_sign = -phi_sign; + } + } else { + indexnoise = (indexnoise + m_max) & 0x1ff; + for (m = 0; m < m_max; m++) { + Y[1][i][m + kx][0] += + sbr->s_m[e][m] * phi[0][indexsine]; + Y[1][i][m + kx][1] += + sbr->s_m[e][m] * (phi[1][indexsine] * phi_sign); + phi_sign = -phi_sign; + } + } + indexsine = (indexsine + 1) & 3; + } + } + ch_data->f_indexnoise = indexnoise; + ch_data->f_indexsine = indexsine; +} + +void ff_sbr_apply(AACContext *ac, SpectralBandReplication *sbr, int id_aac, + float* L, float* R) +{ + int downsampled = ac->m4ac.ext_sample_rate < sbr->sample_rate; + int ch; + int nch = (id_aac == TYPE_CPE) ? 2 : 1; + + if (sbr->start) { + sbr_dequant(sbr, id_aac); + } + for (ch = 0; ch < nch; ch++) { + /* decode channel */ + sbr_qmf_analysis(&ac->dsp, &sbr->rdft, ch ? R : L, sbr->data[ch].analysis_filterbank_samples, + (float*)sbr->qmf_filter_scratch, + sbr->data[ch].W, 1/(-1024 * ac->sf_scale)); + sbr_lf_gen(ac, sbr, sbr->X_low, sbr->data[ch].W); + if (sbr->start) { + sbr_hf_inverse_filter(sbr->alpha0, sbr->alpha1, sbr->X_low, sbr->k[0]); + sbr_chirp(sbr, &sbr->data[ch]); + sbr_hf_gen(ac, sbr, sbr->X_high, sbr->X_low, sbr->alpha0, sbr->alpha1, + sbr->data[ch].bw_array, sbr->data[ch].t_env, + sbr->data[ch].bs_num_env); + + // hf_adj + sbr_mapping(ac, sbr, &sbr->data[ch], sbr->data[ch].e_a); + sbr_env_estimate(sbr->e_curr, sbr->X_high, sbr, &sbr->data[ch]); + sbr_gain_calc(ac, sbr, &sbr->data[ch], sbr->data[ch].e_a); + sbr_hf_assemble(sbr->data[ch].Y, sbr->X_high, sbr, &sbr->data[ch], + sbr->data[ch].e_a); + } + + /* synthesis */ + sbr_x_gen(sbr, sbr->X[ch], sbr->X_low, sbr->data[ch].Y, ch); + } + sbr_qmf_synthesis(&ac->dsp, &sbr->mdct, L, sbr->X[0], sbr->qmf_filter_scratch, + sbr->data[0].synthesis_filterbank_samples, + &sbr->data[0].synthesis_filterbank_samples_offset, + downsampled, + ac->add_bias, -1024 * ac->sf_scale); + if (nch == 2) + sbr_qmf_synthesis(&ac->dsp, &sbr->mdct, R, sbr->X[1], sbr->qmf_filter_scratch, + sbr->data[1].synthesis_filterbank_samples, + &sbr->data[1].synthesis_filterbank_samples_offset, + downsampled, + ac->add_bias, -1024 * ac->sf_scale); +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/aacsbr.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/aacsbr.h new file mode 100644 index 0000000000..6b10ed43e4 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/aacsbr.h @@ -0,0 +1,49 @@ +/* + * AAC Spectral Band Replication function declarations + * Copyright (c) 2008-2009 Robert Swain ( rob opendot cl ) + * Copyright (c) 2010 Alex Converse + * + * 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 + * AAC Spectral Band Replication function declarations + * @author Robert Swain ( rob opendot cl ) + */ + +#ifndef AVCODEC_AACSBR_H +#define AVCODEC_AACSBR_H + +#include "get_bits.h" +#include "aac.h" +#include "sbr.h" + +/** Initialize SBR. */ +av_cold void ff_aac_sbr_init(void); +/** Initialize one SBR context. */ +av_cold void ff_aac_sbr_ctx_init(SpectralBandReplication *sbr); +/** Close one SBR context. */ +av_cold void ff_aac_sbr_ctx_close(SpectralBandReplication *sbr); +/** Decode one SBR element. */ +int ff_decode_sbr_extension(AACContext *ac, SpectralBandReplication *sbr, + GetBitContext *gb, int crc, int cnt, int id_aac); +/** Apply one SBR element to one AAC element. */ +void ff_sbr_apply(AACContext *ac, SpectralBandReplication *sbr, int id_aac, + float* L, float *R); + +#endif /* AVCODEC_AACSBR_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/aacsbrdata.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/aacsbrdata.h new file mode 100644 index 0000000000..5d33a60888 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/aacsbrdata.h @@ -0,0 +1,614 @@ +/* + * AAC Spectral Band Replication decoding data + * Copyright (c) 2008-2009 Robert Swain ( rob opendot cl ) + * + * 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 + * AAC Spectral Band Replication decoding data + * @author Robert Swain ( rob opendot cl ) + */ + +#ifndef AVCODEC_AACSBRDATA_H +#define AVCODEC_AACSBRDATA_H + +#include +#include "libavutil/mem.h" + +///< Huffman tables for SBR + +static const uint8_t t_huffman_env_1_5dB_bits[121] = { + 18, 18, 18, 18, 18, 18, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 17, 18, 16, 17, 18, 17, + 16, 16, 16, 16, 15, 14, 14, 13, + 13, 12, 11, 10, 9, 8, 7, 6, + 5, 4, 3, 2, 2, 3, 4, 5, + 6, 7, 8, 9, 10, 12, 13, 14, + 14, 15, 16, 17, 16, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, + 19, +}; + +static const uint32_t t_huffman_env_1_5dB_codes[121] = { + 0x3ffd6, 0x3ffd7, 0x3ffd8, 0x3ffd9, 0x3ffda, 0x3ffdb, 0x7ffb8, 0x7ffb9, + 0x7ffba, 0x7ffbb, 0x7ffbc, 0x7ffbd, 0x7ffbe, 0x7ffbf, 0x7ffc0, 0x7ffc1, + 0x7ffc2, 0x7ffc3, 0x7ffc4, 0x7ffc5, 0x7ffc6, 0x7ffc7, 0x7ffc8, 0x7ffc9, + 0x7ffca, 0x7ffcb, 0x7ffcc, 0x7ffcd, 0x7ffce, 0x7ffcf, 0x7ffd0, 0x7ffd1, + 0x7ffd2, 0x7ffd3, 0x1ffe6, 0x3ffd4, 0x0fff0, 0x1ffe9, 0x3ffd5, 0x1ffe7, + 0x0fff1, 0x0ffec, 0x0ffed, 0x0ffee, 0x07ff4, 0x03ff9, 0x03ff7, 0x01ffa, + 0x01ff9, 0x00ffb, 0x007fc, 0x003fc, 0x001fd, 0x000fd, 0x0007d, 0x0003d, + 0x0001d, 0x0000d, 0x00005, 0x00001, 0x00000, 0x00004, 0x0000c, 0x0001c, + 0x0003c, 0x0007c, 0x000fc, 0x001fc, 0x003fd, 0x00ffa, 0x01ff8, 0x03ff6, + 0x03ff8, 0x07ff5, 0x0ffef, 0x1ffe8, 0x0fff2, 0x7ffd4, 0x7ffd5, 0x7ffd6, + 0x7ffd7, 0x7ffd8, 0x7ffd9, 0x7ffda, 0x7ffdb, 0x7ffdc, 0x7ffdd, 0x7ffde, + 0x7ffdf, 0x7ffe0, 0x7ffe1, 0x7ffe2, 0x7ffe3, 0x7ffe4, 0x7ffe5, 0x7ffe6, + 0x7ffe7, 0x7ffe8, 0x7ffe9, 0x7ffea, 0x7ffeb, 0x7ffec, 0x7ffed, 0x7ffee, + 0x7ffef, 0x7fff0, 0x7fff1, 0x7fff2, 0x7fff3, 0x7fff4, 0x7fff5, 0x7fff6, + 0x7fff7, 0x7fff8, 0x7fff9, 0x7fffa, 0x7fffb, 0x7fffc, 0x7fffd, 0x7fffe, + 0x7ffff, +}; + +static const uint8_t f_huffman_env_1_5dB_bits[121] = { + 19, 19, 20, 20, 20, 20, 20, 20, + 20, 19, 20, 20, 20, 20, 19, 20, + 19, 19, 20, 18, 20, 20, 20, 19, + 20, 20, 20, 19, 20, 19, 18, 19, + 18, 18, 17, 18, 17, 17, 17, 16, + 16, 16, 15, 15, 14, 13, 13, 12, + 12, 11, 10, 9, 9, 8, 7, 6, + 5, 4, 3, 2, 2, 3, 4, 5, + 6, 8, 8, 9, 10, 11, 11, 11, + 12, 12, 13, 13, 14, 14, 16, 16, + 17, 17, 18, 18, 18, 18, 18, 18, + 18, 20, 19, 20, 20, 20, 20, 20, + 20, 19, 20, 20, 20, 20, 19, 20, + 18, 20, 20, 19, 19, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, + 20, +}; + +static const uint32_t f_huffman_env_1_5dB_codes[121] = { + 0x7ffe7, 0x7ffe8, 0xfffd2, 0xfffd3, 0xfffd4, 0xfffd5, 0xfffd6, 0xfffd7, + 0xfffd8, 0x7ffda, 0xfffd9, 0xfffda, 0xfffdb, 0xfffdc, 0x7ffdb, 0xfffdd, + 0x7ffdc, 0x7ffdd, 0xfffde, 0x3ffe4, 0xfffdf, 0xfffe0, 0xfffe1, 0x7ffde, + 0xfffe2, 0xfffe3, 0xfffe4, 0x7ffdf, 0xfffe5, 0x7ffe0, 0x3ffe8, 0x7ffe1, + 0x3ffe0, 0x3ffe9, 0x1ffef, 0x3ffe5, 0x1ffec, 0x1ffed, 0x1ffee, 0x0fff4, + 0x0fff3, 0x0fff0, 0x07ff7, 0x07ff6, 0x03ffa, 0x01ffa, 0x01ff9, 0x00ffa, + 0x00ff8, 0x007f9, 0x003fb, 0x001fc, 0x001fa, 0x000fb, 0x0007c, 0x0003c, + 0x0001c, 0x0000c, 0x00005, 0x00001, 0x00000, 0x00004, 0x0000d, 0x0001d, + 0x0003d, 0x000fa, 0x000fc, 0x001fb, 0x003fa, 0x007f8, 0x007fa, 0x007fb, + 0x00ff9, 0x00ffb, 0x01ff8, 0x01ffb, 0x03ff8, 0x03ff9, 0x0fff1, 0x0fff2, + 0x1ffea, 0x1ffeb, 0x3ffe1, 0x3ffe2, 0x3ffea, 0x3ffe3, 0x3ffe6, 0x3ffe7, + 0x3ffeb, 0xfffe6, 0x7ffe2, 0xfffe7, 0xfffe8, 0xfffe9, 0xfffea, 0xfffeb, + 0xfffec, 0x7ffe3, 0xfffed, 0xfffee, 0xfffef, 0xffff0, 0x7ffe4, 0xffff1, + 0x3ffec, 0xffff2, 0xffff3, 0x7ffe5, 0x7ffe6, 0xffff4, 0xffff5, 0xffff6, + 0xffff7, 0xffff8, 0xffff9, 0xffffa, 0xffffb, 0xffffc, 0xffffd, 0xffffe, + 0xfffff, +}; + +static const uint8_t t_huffman_env_bal_1_5dB_bits[49] = { + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 12, 11, 9, 7, 5, 3, + 1, 2, 4, 6, 8, 11, 12, 15, + 16, 16, 16, 16, 16, 16, 16, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, +}; + +static const uint32_t t_huffman_env_bal_1_5dB_codes[49] = { + 0x0ffe4, 0x0ffe5, 0x0ffe6, 0x0ffe7, 0x0ffe8, 0x0ffe9, 0x0ffea, 0x0ffeb, + 0x0ffec, 0x0ffed, 0x0ffee, 0x0ffef, 0x0fff0, 0x0fff1, 0x0fff2, 0x0fff3, + 0x0fff4, 0x0ffe2, 0x00ffc, 0x007fc, 0x001fe, 0x0007e, 0x0001e, 0x00006, + 0x00000, 0x00002, 0x0000e, 0x0003e, 0x000fe, 0x007fd, 0x00ffd, 0x07ff0, + 0x0ffe3, 0x0fff5, 0x0fff6, 0x0fff7, 0x0fff8, 0x0fff9, 0x0fffa, 0x1fff6, + 0x1fff7, 0x1fff8, 0x1fff9, 0x1fffa, 0x1fffb, 0x1fffc, 0x1fffd, 0x1fffe, + 0x1ffff, +}; + +static const uint8_t f_huffman_env_bal_1_5dB_bits[49] = { + 18, 18, 18, 18, 18, 18, 18, 18, + 18, 18, 18, 18, 18, 18, 18, 16, + 17, 14, 11, 11, 8, 7, 4, 2, + 1, 3, 5, 6, 9, 11, 12, 15, + 16, 18, 18, 18, 18, 18, 18, 18, + 18, 18, 18, 18, 18, 18, 18, 19, + 19, +}; + +static const uint32_t f_huffman_env_bal_1_5dB_codes[49] = { + 0x3ffe2, 0x3ffe3, 0x3ffe4, 0x3ffe5, 0x3ffe6, 0x3ffe7, 0x3ffe8, 0x3ffe9, + 0x3ffea, 0x3ffeb, 0x3ffec, 0x3ffed, 0x3ffee, 0x3ffef, 0x3fff0, 0x0fff7, + 0x1fff0, 0x03ffc, 0x007fe, 0x007fc, 0x000fe, 0x0007e, 0x0000e, 0x00002, + 0x00000, 0x00006, 0x0001e, 0x0003e, 0x001fe, 0x007fd, 0x00ffe, 0x07ffa, + 0x0fff6, 0x3fff1, 0x3fff2, 0x3fff3, 0x3fff4, 0x3fff5, 0x3fff6, 0x3fff7, + 0x3fff8, 0x3fff9, 0x3fffa, 0x3fffb, 0x3fffc, 0x3fffd, 0x3fffe, 0x7fffe, + 0x7ffff, +}; + +static const uint8_t t_huffman_env_3_0dB_bits[63] = { + 18, 18, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, + 19, 17, 16, 16, 16, 14, 14, 14, + 13, 12, 11, 8, 6, 4, 2, 1, + 3, 5, 7, 9, 11, 13, 14, 14, + 15, 16, 17, 18, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, +}; + +static const uint32_t t_huffman_env_3_0dB_codes[63] = { + 0x3ffed, 0x3ffee, 0x7ffde, 0x7ffdf, 0x7ffe0, 0x7ffe1, 0x7ffe2, 0x7ffe3, + 0x7ffe4, 0x7ffe5, 0x7ffe6, 0x7ffe7, 0x7ffe8, 0x7ffe9, 0x7ffea, 0x7ffeb, + 0x7ffec, 0x1fff4, 0x0fff7, 0x0fff9, 0x0fff8, 0x03ffb, 0x03ffa, 0x03ff8, + 0x01ffa, 0x00ffc, 0x007fc, 0x000fe, 0x0003e, 0x0000e, 0x00002, 0x00000, + 0x00006, 0x0001e, 0x0007e, 0x001fe, 0x007fd, 0x01ffb, 0x03ff9, 0x03ffc, + 0x07ffa, 0x0fff6, 0x1fff5, 0x3ffec, 0x7ffed, 0x7ffee, 0x7ffef, 0x7fff0, + 0x7fff1, 0x7fff2, 0x7fff3, 0x7fff4, 0x7fff5, 0x7fff6, 0x7fff7, 0x7fff8, + 0x7fff9, 0x7fffa, 0x7fffb, 0x7fffc, 0x7fffd, 0x7fffe, 0x7ffff, +}; + +static const uint8_t f_huffman_env_3_0dB_bits[63] = { + 20, 20, 20, 20, 20, 20, 20, 18, + 19, 19, 19, 19, 18, 18, 20, 19, + 17, 18, 17, 16, 16, 15, 14, 12, + 11, 10, 9, 8, 6, 4, 2, 1, + 3, 5, 8, 9, 10, 11, 12, 13, + 14, 15, 15, 16, 16, 17, 17, 18, + 18, 18, 20, 19, 19, 19, 20, 19, + 19, 20, 20, 20, 20, 20, 20, +}; + +static const uint32_t f_huffman_env_3_0dB_codes[63] = { + 0xffff0, 0xffff1, 0xffff2, 0xffff3, 0xffff4, 0xffff5, 0xffff6, 0x3fff3, + 0x7fff5, 0x7ffee, 0x7ffef, 0x7fff6, 0x3fff4, 0x3fff2, 0xffff7, 0x7fff0, + 0x1fff5, 0x3fff0, 0x1fff4, 0x0fff7, 0x0fff6, 0x07ff8, 0x03ffb, 0x00ffd, + 0x007fd, 0x003fd, 0x001fd, 0x000fd, 0x0003e, 0x0000e, 0x00002, 0x00000, + 0x00006, 0x0001e, 0x000fc, 0x001fc, 0x003fc, 0x007fc, 0x00ffc, 0x01ffc, + 0x03ffa, 0x07ff9, 0x07ffa, 0x0fff8, 0x0fff9, 0x1fff6, 0x1fff7, 0x3fff5, + 0x3fff6, 0x3fff1, 0xffff8, 0x7fff1, 0x7fff2, 0x7fff3, 0xffff9, 0x7fff7, + 0x7fff4, 0xffffa, 0xffffb, 0xffffc, 0xffffd, 0xffffe, 0xfffff, +}; + +static const uint8_t t_huffman_env_bal_3_0dB_bits[25] = { + 13, 13, 13, 13, 13, 13, 13, 12, + 8, 7, 4, 3, 1, 2, 5, 6, + 9, 13, 13, 13, 13, 13, 13, 14, + 14, +}; + +static const uint16_t t_huffman_env_bal_3_0dB_codes[25] = { + 0x1ff2, 0x1ff3, 0x1ff4, 0x1ff5, 0x1ff6, 0x1ff7, 0x1ff8, 0x0ff8, + 0x00fe, 0x007e, 0x000e, 0x0006, 0x0000, 0x0002, 0x001e, 0x003e, + 0x01fe, 0x1ff9, 0x1ffa, 0x1ffb, 0x1ffc, 0x1ffd, 0x1ffe, 0x3ffe, + 0x3fff, +}; + +static const uint8_t f_huffman_env_bal_3_0dB_bits[25] = { + 13, 13, 13, 13, 13, 14, 14, 11, + 8, 7, 4, 2, 1, 3, 5, 6, + 9, 12, 13, 14, 14, 14, 14, 14, + 14, +}; + +static const uint16_t f_huffman_env_bal_3_0dB_codes[25] = { + 0x1ff7, 0x1ff8, 0x1ff9, 0x1ffa, 0x1ffb, 0x3ff8, 0x3ff9, 0x07fc, + 0x00fe, 0x007e, 0x000e, 0x0002, 0x0000, 0x0006, 0x001e, 0x003e, + 0x01fe, 0x0ffa, 0x1ff6, 0x3ffa, 0x3ffb, 0x3ffc, 0x3ffd, 0x3ffe, + 0x3fff, +}; + +static const uint8_t t_huffman_noise_3_0dB_bits[63] = { + 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, 11, 8, 6, 4, 3, 1, + 2, 5, 8, 10, 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, 14, 14, +}; + +static const uint16_t t_huffman_noise_3_0dB_codes[63] = { + 0x1fce, 0x1fcf, 0x1fd0, 0x1fd1, 0x1fd2, 0x1fd3, 0x1fd4, 0x1fd5, + 0x1fd6, 0x1fd7, 0x1fd8, 0x1fd9, 0x1fda, 0x1fdb, 0x1fdc, 0x1fdd, + 0x1fde, 0x1fdf, 0x1fe0, 0x1fe1, 0x1fe2, 0x1fe3, 0x1fe4, 0x1fe5, + 0x1fe6, 0x1fe7, 0x07f2, 0x00fd, 0x003e, 0x000e, 0x0006, 0x0000, + 0x0002, 0x001e, 0x00fc, 0x03f8, 0x1fcc, 0x1fe8, 0x1fe9, 0x1fea, + 0x1feb, 0x1fec, 0x1fcd, 0x1fed, 0x1fee, 0x1fef, 0x1ff0, 0x1ff1, + 0x1ff2, 0x1ff3, 0x1ff4, 0x1ff5, 0x1ff6, 0x1ff7, 0x1ff8, 0x1ff9, + 0x1ffa, 0x1ffb, 0x1ffc, 0x1ffd, 0x1ffe, 0x3ffe, 0x3fff, +}; + +static const uint8_t t_huffman_noise_bal_3_0dB_bits[25] = { + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 5, 2, 1, 3, 6, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, +}; + +static const uint8_t t_huffman_noise_bal_3_0dB_codes[25] = { + 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, + 0xf4, 0xf5, 0x1c, 0x02, 0x00, 0x06, 0x3a, 0xf6, + 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, + 0xff, +}; + +static const int8_t sbr_offset[6][16] = { + {-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7}, // fs_sbr = 16000 Hz + {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13}, // fs_sbr = 22050 Hz + {-5, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16}, // fs_sbr = 24000 Hz + {-6, -4, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16}, // fs_sbr = 32000 Hz + {-4, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16, 20}, // 44100 Hz <= fs_sbr <= 64000 Hz + {-2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 16, 20, 24}, // 64000 Hz < fs_sbr +}; + +///< window coefficients for analysis/synthesis QMF banks +static DECLARE_ALIGNED(16, float, sbr_qmf_window_ds)[320]; +static DECLARE_ALIGNED(16, float, sbr_qmf_window_us)[640] = { + 0.0000000000, -0.0005525286, -0.0005617692, -0.0004947518, + -0.0004875227, -0.0004893791, -0.0005040714, -0.0005226564, + -0.0005466565, -0.0005677802, -0.0005870930, -0.0006132747, + -0.0006312493, -0.0006540333, -0.0006777690, -0.0006941614, + -0.0007157736, -0.0007255043, -0.0007440941, -0.0007490598, + -0.0007681371, -0.0007724848, -0.0007834332, -0.0007779869, + -0.0007803664, -0.0007801449, -0.0007757977, -0.0007630793, + -0.0007530001, -0.0007319357, -0.0007215391, -0.0006917937, + -0.0006650415, -0.0006341594, -0.0005946118, -0.0005564576, + -0.0005145572, -0.0004606325, -0.0004095121, -0.0003501175, + -0.0002896981, -0.0002098337, -0.0001446380, -0.0000617334, + 0.0000134949, 0.0001094383, 0.0002043017, 0.0002949531, + 0.0004026540, 0.0005107388, 0.0006239376, 0.0007458025, + 0.0008608443, 0.0009885988, 0.0011250155, 0.0012577884, + 0.0013902494, 0.0015443219, 0.0016868083, 0.0018348265, + 0.0019841140, 0.0021461583, 0.0023017254, 0.0024625616, + 0.0026201758, 0.0027870464, 0.0029469447, 0.0031125420, + 0.0032739613, 0.0034418874, 0.0036008268, 0.0037603922, + 0.0039207432, 0.0040819753, 0.0042264269, 0.0043730719, + 0.0045209852, 0.0046606460, 0.0047932560, 0.0049137603, + 0.0050393022, 0.0051407353, 0.0052461166, 0.0053471681, + 0.0054196775, 0.0054876040, 0.0055475714, 0.0055938023, + 0.0056220643, 0.0056455196, 0.0056389199, 0.0056266114, + 0.0055917128, 0.0055404363, 0.0054753783, 0.0053838975, + 0.0052715758, 0.0051382275, 0.0049839687, 0.0048109469, + 0.0046039530, 0.0043801861, 0.0041251642, 0.0038456408, + 0.0035401246, 0.0032091885, 0.0028446757, 0.0024508540, + 0.0020274176, 0.0015784682, 0.0010902329, 0.0005832264, + 0.0000276045, -0.0005464280, -0.0011568135, -0.0018039472, + -0.0024826723, -0.0031933778, -0.0039401124, -0.0047222596, + -0.0055337211, -0.0063792293, -0.0072615816, -0.0081798233, + -0.0091325329, -0.0101150215, -0.0111315548, -0.0121849995, + 0.0132718220, 0.0143904666, 0.0155405553, 0.0167324712, + 0.0179433381, 0.0191872431, 0.0204531793, 0.0217467550, + 0.0230680169, 0.0244160992, 0.0257875847, 0.0271859429, + 0.0286072173, 0.0300502657, 0.0315017608, 0.0329754081, + 0.0344620948, 0.0359697560, 0.0374812850, 0.0390053679, + 0.0405349170, 0.0420649094, 0.0436097542, 0.0451488405, + 0.0466843027, 0.0482165720, 0.0497385755, 0.0512556155, + 0.0527630746, 0.0542452768, 0.0557173648, 0.0571616450, + 0.0585915683, 0.0599837480, 0.0613455171, 0.0626857808, + 0.0639715898, 0.0652247106, 0.0664367512, 0.0676075985, + 0.0687043828, 0.0697630244, 0.0707628710, 0.0717002673, + 0.0725682583, 0.0733620255, 0.0741003642, 0.0747452558, + 0.0753137336, 0.0758008358, 0.0761992479, 0.0764992170, + 0.0767093490, 0.0768173975, 0.0768230011, 0.0767204924, + 0.0765050718, 0.0761748321, 0.0757305756, 0.0751576255, + 0.0744664394, 0.0736406005, 0.0726774642, 0.0715826364, + 0.0703533073, 0.0689664013, 0.0674525021, 0.0657690668, + 0.0639444805, 0.0619602779, 0.0598166570, 0.0575152691, + 0.0550460034, 0.0524093821, 0.0495978676, 0.0466303305, + 0.0434768782, 0.0401458278, 0.0366418116, 0.0329583930, + 0.0290824006, 0.0250307561, 0.0207997072, 0.0163701258, + 0.0117623832, 0.0069636862, 0.0019765601, -0.0032086896, + -0.0085711749, -0.0141288827, -0.0198834129, -0.0258227288, + -0.0319531274, -0.0382776572, -0.0447806821, -0.0514804176, + -0.0583705326, -0.0654409853, -0.0726943300, -0.0801372934, + -0.0877547536, -0.0955533352, -0.1035329531, -0.1116826931, + -0.1200077984, -0.1285002850, -0.1371551761, -0.1459766491, + -0.1549607071, -0.1640958855, -0.1733808172, -0.1828172548, + -0.1923966745, -0.2021250176, -0.2119735853, -0.2219652696, + -0.2320690870, -0.2423016884, -0.2526480309, -0.2631053299, + -0.2736634040, -0.2843214189, -0.2950716717, -0.3059098575, + -0.3168278913, -0.3278113727, -0.3388722693, -0.3499914122, + 0.3611589903, 0.3723795546, 0.3836350013, 0.3949211761, + 0.4062317676, 0.4175696896, 0.4289119920, 0.4402553754, + 0.4515996535, 0.4629308085, 0.4742453214, 0.4855253091, + 0.4967708254, 0.5079817500, 0.5191234970, 0.5302240895, + 0.5412553448, 0.5522051258, 0.5630789140, 0.5738524131, + 0.5845403235, 0.5951123086, 0.6055783538, 0.6159109932, + 0.6261242695, 0.6361980107, 0.6461269695, 0.6559016302, + 0.6655139880, 0.6749663190, 0.6842353293, 0.6933282376, + 0.7022388719, 0.7109410426, 0.7194462634, 0.7277448900, + 0.7358211758, 0.7436827863, 0.7513137456, 0.7587080760, + 0.7658674865, 0.7727780881, 0.7794287519, 0.7858353120, + 0.7919735841, 0.7978466413, 0.8034485751, 0.8087695004, + 0.8138191270, 0.8185776004, 0.8230419890, 0.8272275347, + 0.8311038457, 0.8346937361, 0.8379717337, 0.8409541392, + 0.8436238281, 0.8459818469, 0.8480315777, 0.8497805198, + 0.8511971524, 0.8523047035, 0.8531020949, 0.8535720573, + 0.8537385600, +}; + +static const float sbr_noise_table[512][2] = { +{-0.99948153278296, -0.59483417516607}, { 0.97113454393991, -0.67528515225647}, +{ 0.14130051758487, -0.95090983575689}, {-0.47005496701697, -0.37340549728647}, +{ 0.80705063769351, 0.29653668284408}, {-0.38981478896926, 0.89572605717087}, +{-0.01053049862020, -0.66959058036166}, {-0.91266367957293, -0.11522938140034}, +{ 0.54840422910309, 0.75221367176302}, { 0.40009252867955, -0.98929400334421}, +{-0.99867974711855, -0.88147068645358}, {-0.95531076805040, 0.90908757154593}, +{-0.45725933317144, -0.56716323646760}, {-0.72929675029275, -0.98008272727324}, +{ 0.75622801399036, 0.20950329995549}, { 0.07069442601050, -0.78247898470706}, +{ 0.74496252926055, -0.91169004445807}, {-0.96440182703856, -0.94739918296622}, +{ 0.30424629369539, -0.49438267012479}, { 0.66565033746925, 0.64652935542491}, +{ 0.91697008020594, 0.17514097332009}, {-0.70774918760427, 0.52548653416543}, +{-0.70051415345560, -0.45340028808763}, {-0.99496513054797, -0.90071908066973}, +{ 0.98164490790123, -0.77463155528697}, {-0.54671580548181, -0.02570928536004}, +{-0.01689629065389, 0.00287506445732}, {-0.86110349531986, 0.42548583726477}, +{-0.98892980586032, -0.87881132267556}, { 0.51756627678691, 0.66926784710139}, +{-0.99635026409640, -0.58107730574765}, {-0.99969370862163, 0.98369989360250}, +{ 0.55266258627194, 0.59449057465591}, { 0.34581177741673, 0.94879421061866}, +{ 0.62664209577999, -0.74402970906471}, {-0.77149701404973, -0.33883658042801}, +{-0.91592244254432, 0.03687901376713}, {-0.76285492357887, -0.91371867919124}, +{ 0.79788337195331, -0.93180971199849}, { 0.54473080610200, -0.11919206037186}, +{-0.85639281671058, 0.42429854760451}, {-0.92882402971423, 0.27871809078609}, +{-0.11708371046774, -0.99800843444966}, { 0.21356749817493, -0.90716295627033}, +{-0.76191692573909, 0.99768118356265}, { 0.98111043100884, -0.95854459734407}, +{-0.85913269895572, 0.95766566168880}, {-0.93307242253692, 0.49431757696466}, +{ 0.30485754879632, -0.70540034357529}, { 0.85289650925190, 0.46766131791044}, +{ 0.91328082618125, -0.99839597361769}, {-0.05890199924154, 0.70741827819497}, +{ 0.28398686150148, 0.34633555702188}, { 0.95258164539612, -0.54893416026939}, +{-0.78566324168507, -0.75568541079691}, {-0.95789495447877, -0.20423194696966}, +{ 0.82411158711197, 0.96654618432562}, {-0.65185446735885, -0.88734990773289}, +{-0.93643603134666, 0.99870790442385}, { 0.91427159529618, -0.98290505544444}, +{-0.70395684036886, 0.58796798221039}, { 0.00563771969365, 0.61768196727244}, +{ 0.89065051931895, 0.52783352697585}, {-0.68683707712762, 0.80806944710339}, +{ 0.72165342518718, -0.69259857349564}, {-0.62928247730667, 0.13627037407335}, +{ 0.29938434065514, -0.46051329682246}, {-0.91781958879280, -0.74012716684186}, +{ 0.99298717043688, 0.40816610075661}, { 0.82368298622748, -0.74036047190173}, +{-0.98512833386833, -0.99972330709594}, {-0.95915368242257, -0.99237800466040}, +{-0.21411126572790, -0.93424819052545}, {-0.68821476106884, -0.26892306315457}, +{ 0.91851997982317, 0.09358228901785}, {-0.96062769559127, 0.36099095133739}, +{ 0.51646184922287, -0.71373332873917}, { 0.61130721139669, 0.46950141175917}, +{ 0.47336129371299, -0.27333178296162}, { 0.90998308703519, 0.96715662938132}, +{ 0.44844799194357, 0.99211574628306}, { 0.66614891079092, 0.96590176169121}, +{ 0.74922239129237, -0.89879858826087}, {-0.99571588506485, 0.52785521494349}, +{ 0.97401082477563, -0.16855870075190}, { 0.72683747733879, -0.48060774432251}, +{ 0.95432193457128, 0.68849603408441}, {-0.72962208425191, -0.76608443420917}, +{-0.85359479233537, 0.88738125901579}, {-0.81412430338535, -0.97480768049637}, +{-0.87930772356786, 0.74748307690436}, {-0.71573331064977, -0.98570608178923}, +{ 0.83524300028228, 0.83702537075163}, {-0.48086065601423, -0.98848504923531}, +{ 0.97139128574778, 0.80093621198236}, { 0.51992825347895, 0.80247631400510}, +{-0.00848591195325, -0.76670128000486}, {-0.70294374303036, 0.55359910445577}, +{-0.95894428168140, -0.43265504344783}, { 0.97079252950321, 0.09325857238682}, +{-0.92404293670797, 0.85507704027855}, {-0.69506469500450, 0.98633412625459}, +{ 0.26559203620024, 0.73314307966524}, { 0.28038443336943, 0.14537913654427}, +{-0.74138124825523, 0.99310339807762}, {-0.01752795995444, -0.82616635284178}, +{-0.55126773094930, -0.98898543862153}, { 0.97960898850996, -0.94021446752851}, +{-0.99196309146936, 0.67019017358456}, {-0.67684928085260, 0.12631491649378}, +{ 0.09140039465500, -0.20537731453108}, {-0.71658965751996, -0.97788200391224}, +{ 0.81014640078925, 0.53722648362443}, { 0.40616991671205, -0.26469008598449}, +{-0.67680188682972, 0.94502052337695}, { 0.86849774348749, -0.18333598647899}, +{-0.99500381284851, -0.02634122068550}, { 0.84329189340667, 0.10406957462213}, +{-0.09215968531446, 0.69540012101253}, { 0.99956173327206, -0.12358542001404}, +{-0.79732779473535, -0.91582524736159}, { 0.96349973642406, 0.96640458041000}, +{-0.79942778496547, 0.64323902822857}, {-0.11566039853896, 0.28587846253726}, +{-0.39922954514662, 0.94129601616966}, { 0.99089197565987, -0.92062625581587}, +{ 0.28631285179909, -0.91035047143603}, {-0.83302725605608, -0.67330410892084}, +{ 0.95404443402072, 0.49162765398743}, {-0.06449863579434, 0.03250560813135}, +{-0.99575054486311, 0.42389784469507}, {-0.65501142790847, 0.82546114655624}, +{-0.81254441908887, -0.51627234660629}, {-0.99646369485481, 0.84490533520752}, +{ 0.00287840603348, 0.64768261158166}, { 0.70176989408455, -0.20453028573322}, +{ 0.96361882270190, 0.40706967140989}, {-0.68883758192426, 0.91338958840772}, +{-0.34875585502238, 0.71472290693300}, { 0.91980081243087, 0.66507455644919}, +{-0.99009048343881, 0.85868021604848}, { 0.68865791458395, 0.55660316809678}, +{-0.99484402129368, -0.20052559254934}, { 0.94214511408023, -0.99696425367461}, +{-0.67414626793544, 0.49548221180078}, {-0.47339353684664, -0.85904328834047}, +{ 0.14323651387360, -0.94145598222488}, {-0.29268293575672, 0.05759224927952}, +{ 0.43793861458754, -0.78904969892724}, {-0.36345126374441, 0.64874435357162}, +{-0.08750604656825, 0.97686944362527}, {-0.96495267812511, -0.53960305946511}, +{ 0.55526940659947, 0.78891523734774}, { 0.73538215752630, 0.96452072373404}, +{-0.30889773919437, -0.80664389776860}, { 0.03574995626194, -0.97325616900959}, +{ 0.98720684660488, 0.48409133691962}, {-0.81689296271203, -0.90827703628298}, +{ 0.67866860118215, 0.81284503870856}, {-0.15808569732583, 0.85279555024382}, +{ 0.80723395114371, -0.24717418514605}, { 0.47788757329038, -0.46333147839295}, +{ 0.96367554763201, 0.38486749303242}, {-0.99143875716818, -0.24945277239809}, +{ 0.83081876925833, -0.94780851414763}, {-0.58753191905341, 0.01290772389163}, +{ 0.95538108220960, -0.85557052096538}, {-0.96490920476211, -0.64020970923102}, +{-0.97327101028521, 0.12378128133110}, { 0.91400366022124, 0.57972471346930}, +{-0.99925837363824, 0.71084847864067}, {-0.86875903507313, -0.20291699203564}, +{-0.26240034795124, -0.68264554369108}, {-0.24664412953388, -0.87642273115183}, +{ 0.02416275806869, 0.27192914288905}, { 0.82068619590515, -0.85087787994476}, +{ 0.88547373760759, -0.89636802901469}, {-0.18173078152226, -0.26152145156800}, +{ 0.09355476558534, 0.54845123045604}, {-0.54668414224090, 0.95980774020221}, +{ 0.37050990604091, -0.59910140383171}, {-0.70373594262891, 0.91227665827081}, +{-0.34600785879594, -0.99441426144200}, {-0.68774481731008, -0.30238837956299}, +{-0.26843291251234, 0.83115668004362}, { 0.49072334613242, -0.45359708737775}, +{ 0.38975993093975, 0.95515358099121}, {-0.97757125224150, 0.05305894580606}, +{-0.17325552859616, -0.92770672250494}, { 0.99948035025744, 0.58285545563426}, +{-0.64946246527458, 0.68645507104960}, {-0.12016920576437, -0.57147322153312}, +{-0.58947456517751, -0.34847132454388}, {-0.41815140454465, 0.16276422358861}, +{ 0.99885650204884, 0.11136095490444}, {-0.56649614128386, -0.90494866361587}, +{ 0.94138021032330, 0.35281916733018}, {-0.75725076534641, 0.53650549640587}, +{ 0.20541973692630, -0.94435144369918}, { 0.99980371023351, 0.79835913565599}, +{ 0.29078277605775, 0.35393777921520}, {-0.62858772103030, 0.38765693387102}, +{ 0.43440904467688, -0.98546330463232}, {-0.98298583762390, 0.21021524625209}, +{ 0.19513029146934, -0.94239832251867}, {-0.95476662400101, 0.98364554179143}, +{ 0.93379635304810, -0.70881994583682}, {-0.85235410573336, -0.08342347966410}, +{-0.86425093011245, -0.45795025029466}, { 0.38879779059045, 0.97274429344593}, +{ 0.92045124735495, -0.62433652524220}, { 0.89162532251878, 0.54950955570563}, +{-0.36834336949252, 0.96458298020975}, { 0.93891760988045, -0.89968353740388}, +{ 0.99267657565094, -0.03757034316958}, {-0.94063471614176, 0.41332338538963}, +{ 0.99740224117019, -0.16830494996370}, {-0.35899413170555, -0.46633226649613}, +{ 0.05237237274947, -0.25640361602661}, { 0.36703583957424, -0.38653265641875}, +{ 0.91653180367913, -0.30587628726597}, { 0.69000803499316, 0.90952171386132}, +{-0.38658751133527, 0.99501571208985}, {-0.29250814029851, 0.37444994344615}, +{-0.60182204677608, 0.86779651036123}, {-0.97418588163217, 0.96468523666475}, +{ 0.88461574003963, 0.57508405276414}, { 0.05198933055162, 0.21269661669964}, +{-0.53499621979720, 0.97241553731237}, {-0.49429560226497, 0.98183865291903}, +{-0.98935142339139, -0.40249159006933}, {-0.98081380091130, -0.72856895534041}, +{-0.27338148835532, 0.99950922447209}, { 0.06310802338302, -0.54539587529618}, +{-0.20461677199539, -0.14209977628489}, { 0.66223843141647, 0.72528579940326}, +{-0.84764345483665, 0.02372316801261}, {-0.89039863483811, 0.88866581484602}, +{ 0.95903308477986, 0.76744927173873}, { 0.73504123909879, -0.03747203173192}, +{-0.31744434966056, -0.36834111883652}, {-0.34110827591623, 0.40211222807691}, +{ 0.47803883714199, -0.39423219786288}, { 0.98299195879514, 0.01989791390047}, +{-0.30963073129751, -0.18076720599336}, { 0.99992588229018, -0.26281872094289}, +{-0.93149731080767, -0.98313162570490}, { 0.99923472302773, -0.80142993767554}, +{-0.26024169633417, -0.75999759855752}, {-0.35712514743563, 0.19298963768574}, +{-0.99899084509530, 0.74645156992493}, { 0.86557171579452, 0.55593866696299}, +{ 0.33408042438752, 0.86185953874709}, { 0.99010736374716, 0.04602397576623}, +{-0.66694269691195, -0.91643611810148}, { 0.64016792079480, 0.15649530836856}, +{ 0.99570534804836, 0.45844586038111}, {-0.63431466947340, 0.21079116459234}, +{-0.07706847005931, -0.89581437101329}, { 0.98590090577724, 0.88241721133981}, +{ 0.80099335254678, -0.36851896710853}, { 0.78368131392666, 0.45506999802597}, +{ 0.08707806671691, 0.80938994918745}, {-0.86811883080712, 0.39347308654705}, +{-0.39466529740375, -0.66809432114456}, { 0.97875325649683, -0.72467840967746}, +{-0.95038560288864, 0.89563219587625}, { 0.17005239424212, 0.54683053962658}, +{-0.76910792026848, -0.96226617549298}, { 0.99743281016846, 0.42697157037567}, +{ 0.95437383549973, 0.97002324109952}, { 0.99578905365569, -0.54106826257356}, +{ 0.28058259829990, -0.85361420634036}, { 0.85256524470573, -0.64567607735589}, +{-0.50608540105128, -0.65846015480300}, {-0.97210735183243, -0.23095213067791}, +{ 0.95424048234441, -0.99240147091219}, {-0.96926570524023, 0.73775654896574}, +{ 0.30872163214726, 0.41514960556126}, {-0.24523839572639, 0.63206633394807}, +{-0.33813265086024, -0.38661779441897}, {-0.05826828420146, -0.06940774188029}, +{-0.22898461455054, 0.97054853316316}, {-0.18509915019881, 0.47565762892084}, +{-0.10488238045009, -0.87769947402394}, {-0.71886586182037, 0.78030982480538}, +{ 0.99793873738654, 0.90041310491497}, { 0.57563307626120, -0.91034337352097}, +{ 0.28909646383717, 0.96307783970534}, { 0.42188998312520, 0.48148651230437}, +{ 0.93335049681047, -0.43537023883588}, {-0.97087374418267, 0.86636445711364}, +{ 0.36722871286923, 0.65291654172961}, {-0.81093025665696, 0.08778370229363}, +{-0.26240603062237, -0.92774095379098}, { 0.83996497984604, 0.55839849139647}, +{-0.99909615720225, -0.96024605713970}, { 0.74649464155061, 0.12144893606462}, +{-0.74774595569805, -0.26898062008959}, { 0.95781667469567, -0.79047927052628}, +{ 0.95472308713099, -0.08588776019550}, { 0.48708332746299, 0.99999041579432}, +{ 0.46332038247497, 0.10964126185063}, {-0.76497004940162, 0.89210929242238}, +{ 0.57397389364339, 0.35289703373760}, { 0.75374316974495, 0.96705214651335}, +{-0.59174397685714, -0.89405370422752}, { 0.75087906691890, -0.29612672982396}, +{-0.98607857336230, 0.25034911730023}, {-0.40761056640505, -0.90045573444695}, +{ 0.66929266740477, 0.98629493401748}, {-0.97463695257310, -0.00190223301301}, +{ 0.90145509409859, 0.99781390365446}, {-0.87259289048043, 0.99233587353666}, +{-0.91529461447692, -0.15698707534206}, {-0.03305738840705, -0.37205262859764}, +{ 0.07223051368337, -0.88805001733626}, { 0.99498012188353, 0.97094358113387}, +{-0.74904939500519, 0.99985483641521}, { 0.04585228574211, 0.99812337444082}, +{-0.89054954257993, -0.31791913188064}, {-0.83782144651251, 0.97637632547466}, +{ 0.33454804933804, -0.86231516800408}, {-0.99707579362824, 0.93237990079441}, +{-0.22827527843994, 0.18874759397997}, { 0.67248046289143, -0.03646211390569}, +{-0.05146538187944, -0.92599700120679}, { 0.99947295749905, 0.93625229707912}, +{ 0.66951124390363, 0.98905825623893}, {-0.99602956559179, -0.44654715757688}, +{ 0.82104905483590, 0.99540741724928}, { 0.99186510988782, 0.72023001312947}, +{-0.65284592392918, 0.52186723253637}, { 0.93885443798188, -0.74895312615259}, +{ 0.96735248738388, 0.90891816978629}, {-0.22225968841114, 0.57124029781228}, +{-0.44132783753414, -0.92688840659280}, {-0.85694974219574, 0.88844532719844}, +{ 0.91783042091762, -0.46356892383970}, { 0.72556974415690, -0.99899555770747}, +{-0.99711581834508, 0.58211560180426}, { 0.77638976371966, 0.94321834873819}, +{ 0.07717324253925, 0.58638399856595}, {-0.56049829194163, 0.82522301569036}, +{ 0.98398893639988, 0.39467440420569}, { 0.47546946844938, 0.68613044836811}, +{ 0.65675089314631, 0.18331637134880}, { 0.03273375457980, -0.74933109564108}, +{-0.38684144784738, 0.51337349030406}, {-0.97346267944545, -0.96549364384098}, +{-0.53282156061942, -0.91423265091354}, { 0.99817310731176, 0.61133572482148}, +{-0.50254500772635, -0.88829338134294}, { 0.01995873238855, 0.85223515096765}, +{ 0.99930381973804, 0.94578896296649}, { 0.82907767600783, -0.06323442598128}, +{-0.58660709669728, 0.96840773806582}, {-0.17573736667267, -0.48166920859485}, +{ 0.83434292401346, -0.13023450646997}, { 0.05946491307025, 0.20511047074866}, +{ 0.81505484574602, -0.94685947861369}, {-0.44976380954860, 0.40894572671545}, +{-0.89746474625671, 0.99846578838537}, { 0.39677256130792, -0.74854668609359}, +{-0.07588948563079, 0.74096214084170}, { 0.76343198951445, 0.41746629422634}, +{-0.74490104699626, 0.94725911744610}, { 0.64880119792759, 0.41336660830571}, +{ 0.62319537462542, -0.93098313552599}, { 0.42215817594807, -0.07712787385208}, +{ 0.02704554141885, -0.05417518053666}, { 0.80001773566818, 0.91542195141039}, +{-0.79351832348816, -0.36208897989136}, { 0.63872359151636, 0.08128252493444}, +{ 0.52890520960295, 0.60048872455592}, { 0.74238552914587, 0.04491915291044}, +{ 0.99096131449250, -0.19451182854402}, {-0.80412329643109, -0.88513818199457}, +{-0.64612616129736, 0.72198674804544}, { 0.11657770663191, -0.83662833815041}, +{-0.95053182488101, -0.96939905138082}, {-0.62228872928622, 0.82767262846661}, +{ 0.03004475787316, -0.99738896333384}, {-0.97987214341034, 0.36526129686425}, +{-0.99986980746200, -0.36021610299715}, { 0.89110648599879, -0.97894250343044}, +{ 0.10407960510582, 0.77357793811619}, { 0.95964737821728, -0.35435818285502}, +{ 0.50843233159162, 0.96107691266205}, { 0.17006334670615, -0.76854025314829}, +{ 0.25872675063360, 0.99893303933816}, {-0.01115998681937, 0.98496019742444}, +{-0.79598702973261, 0.97138411318894}, {-0.99264708948101, -0.99542822402536}, +{-0.99829663752818, 0.01877138824311}, {-0.70801016548184, 0.33680685948117}, +{-0.70467057786826, 0.93272777501857}, { 0.99846021905254, -0.98725746254433}, +{-0.63364968534650, -0.16473594423746}, {-0.16258217500792, -0.95939125400802}, +{-0.43645594360633, -0.94805030113284}, {-0.99848471702976, 0.96245166923809}, +{-0.16796458968998, -0.98987511890470}, {-0.87979225745213, -0.71725725041680}, +{ 0.44183099021786, -0.93568974498761}, { 0.93310180125532, -0.99913308068246}, +{-0.93941931782002, -0.56409379640356}, {-0.88590003188677, 0.47624600491382}, +{ 0.99971463703691, -0.83889954253462}, {-0.75376385639978, 0.00814643438625}, +{ 0.93887685615875, -0.11284528204636}, { 0.85126435782309, 0.52349251543547}, +{ 0.39701421446381, 0.81779634174316}, {-0.37024464187437, -0.87071656222959}, +{-0.36024828242896, 0.34655735648287}, {-0.93388812549209, -0.84476541096429}, +{-0.65298804552119, -0.18439575450921}, { 0.11960319006843, 0.99899346780168}, +{ 0.94292565553160, 0.83163906518293}, { 0.75081145286948, -0.35533223142265}, +{ 0.56721979748394, -0.24076836414499}, { 0.46857766746029, -0.30140233457198}, +{ 0.97312313923635, -0.99548191630031}, {-0.38299976567017, 0.98516909715427}, +{ 0.41025800019463, 0.02116736935734}, { 0.09638062008048, 0.04411984381457}, +{-0.85283249275397, 0.91475563922421}, { 0.88866808958124, -0.99735267083226}, +{-0.48202429536989, -0.96805608884164}, { 0.27572582416567, 0.58634753335832}, +{-0.65889129659168, 0.58835634138583}, { 0.98838086953732, 0.99994349600236}, +{-0.20651349620689, 0.54593044066355}, {-0.62126416356920, -0.59893681700392}, +{ 0.20320105410437, -0.86879180355289}, {-0.97790548600584, 0.96290806999242}, +{ 0.11112534735126, 0.21484763313301}, {-0.41368337314182, 0.28216837680365}, +{ 0.24133038992960, 0.51294362630238}, {-0.66393410674885, -0.08249679629081}, +{-0.53697829178752, -0.97649903936228}, {-0.97224737889348, 0.22081333579837}, +{ 0.87392477144549, -0.12796173740361}, { 0.19050361015753, 0.01602615387195}, +{-0.46353441212724, -0.95249041539006}, {-0.07064096339021, -0.94479803205886}, +{-0.92444085484466, -0.10457590187436}, {-0.83822593578728, -0.01695043208885}, +{ 0.75214681811150, -0.99955681042665}, {-0.42102998829339, 0.99720941999394}, +{-0.72094786237696, -0.35008961934255}, { 0.78843311019251, 0.52851398958271}, +{ 0.97394027897442, -0.26695944086561}, { 0.99206463477946, -0.57010120849429}, +{ 0.76789609461795, -0.76519356730966}, {-0.82002421836409, -0.73530179553767}, +{ 0.81924990025724, 0.99698425250579}, {-0.26719850873357, 0.68903369776193}, +{-0.43311260380975, 0.85321815947490}, { 0.99194979673836, 0.91876249766422}, +{-0.80692001248487, -0.32627540663214}, { 0.43080003649976, -0.21919095636638}, +{ 0.67709491937357, -0.95478075822906}, { 0.56151770568316, -0.70693811747778}, +{ 0.10831862810749, -0.08628837174592}, { 0.91229417540436, -0.65987351408410}, +{-0.48972893932274, 0.56289246362686}, {-0.89033658689697, -0.71656563987082}, +{ 0.65269447475094, 0.65916004833932}, { 0.67439478141121, -0.81684380846796}, +{-0.47770832416973, -0.16789556203025}, {-0.99715979260878, -0.93565784007648}, +{-0.90889593602546, 0.62034397054380}, {-0.06618622548177, -0.23812217221359}, +{ 0.99430266919728, 0.18812555317553}, { 0.97686402381843, -0.28664534366620}, +{ 0.94813650221268, -0.97506640027128}, {-0.95434497492853, -0.79607978501983}, +{-0.49104783137150, 0.32895214359663}, { 0.99881175120751, 0.88993983831354}, +{ 0.50449166760303, -0.85995072408434}, { 0.47162891065108, -0.18680204049569}, +{-0.62081581361840, 0.75000676218956}, {-0.43867015250812, 0.99998069244322}, +{ 0.98630563232075, -0.53578899600662}, {-0.61510362277374, -0.89515019899997}, +{-0.03841517601843, -0.69888815681179}, {-0.30102157304644, -0.07667808922205}, +{ 0.41881284182683, 0.02188098922282}, {-0.86135454941237, 0.98947480909359}, +{ 0.67226861393788, -0.13494389011014}, {-0.70737398842068, -0.76547349325992}, +{ 0.94044946687963, 0.09026201157416}, {-0.82386352534327, 0.08924768823676}, +{-0.32070666698656, 0.50143421908753}, { 0.57593163224487, -0.98966422921509}, +{-0.36326018419965, 0.07440243123228}, { 0.99979044674350, -0.14130287347405}, +{-0.92366023326932, -0.97979298068180}, {-0.44607178518598, -0.54233252016394}, +{ 0.44226800932956, 0.71326756742752}, { 0.03671907158312, 0.63606389366675}, +{ 0.52175424682195, -0.85396826735705}, {-0.94701139690956, -0.01826348194255}, +{-0.98759606946049, 0.82288714303073}, { 0.87434794743625, 0.89399495655433}, +{-0.93412041758744, 0.41374052024363}, { 0.96063943315511, 0.93116709541280}, +{ 0.97534253457837, 0.86150930812689}, { 0.99642466504163, 0.70190043427512}, +{-0.94705089665984, -0.29580042814306}, { 0.91599807087376, -0.98147830385781}, +}; + +#endif /* AVCODEC_AACSBRDATA_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/aactab.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/aactab.c index 8d7fa62380..eaa5486822 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/aactab.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/aactab.c @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/aactab.c + * @file * AAC data * @author Oded Shimon ( ods15 ods15 dyndns org ) * @author Maxim Gavrilov ( maxim.gavrilov gmail com ) @@ -32,8 +32,8 @@ #include -DECLARE_ALIGNED(16, float, ff_aac_kbd_long_1024[1024]); -DECLARE_ALIGNED(16, float, ff_aac_kbd_short_128[128]); +DECLARE_ALIGNED(16, float, ff_aac_kbd_long_1024)[1024]; +DECLARE_ALIGNED(16, float, ff_aac_kbd_short_128)[128]; const uint8_t ff_aac_num_swb_1024[] = { 41, 41, 47, 49, 49, 51, 47, 47, 43, 43, 43, 40, 40 @@ -409,7 +409,7 @@ const uint16_t ff_aac_spectral_sizes[11] = { * 64.0f is a special value indicating the existence of an escape code in the * bitstream. */ -static const float codebook_vector0[324] = { +static const DECLARE_ALIGNED(16, float, codebook_vector0)[324] = { -1.0000000, -1.0000000, -1.0000000, -1.0000000, -1.0000000, -1.0000000, -1.0000000, 0.0000000, -1.0000000, -1.0000000, -1.0000000, 1.0000000, @@ -493,7 +493,7 @@ static const float codebook_vector0[324] = { 1.0000000, 1.0000000, 1.0000000, 1.0000000, }; -static const float codebook_vector2[324] = { +static const DECLARE_ALIGNED(16, float, codebook_vector2)[324] = { 0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000, 1.0000000, 0.0000000, 0.0000000, 0.0000000, 2.5198421, @@ -577,7 +577,7 @@ static const float codebook_vector2[324] = { 2.5198421, 2.5198421, 2.5198421, 2.5198421, }; -static const float codebook_vector4[162] = { +static const DECLARE_ALIGNED(16, float, codebook_vector4)[162] = { -6.3496042, -6.3496042, -6.3496042, -4.3267487, -6.3496042, -2.5198421, -6.3496042, -1.0000000, -6.3496042, 0.0000000, -6.3496042, 1.0000000, @@ -621,7 +621,7 @@ static const float codebook_vector4[162] = { 6.3496042, 6.3496042, }; -static const float codebook_vector6[128] = { +static const DECLARE_ALIGNED(16, float, codebook_vector6)[128] = { 0.0000000, 0.0000000, 0.0000000, 1.0000000, 0.0000000, 2.5198421, 0.0000000, 4.3267487, 0.0000000, 6.3496042, 0.0000000, 8.5498797, @@ -656,7 +656,7 @@ static const float codebook_vector6[128] = { 13.3905183, 10.9027236, 13.3905183, 13.3905183, }; -static const float codebook_vector8[338] = { +static const DECLARE_ALIGNED(16, float, codebook_vector8)[338] = { 0.0000000, 0.0000000, 0.0000000, 1.0000000, 0.0000000, 2.5198421, 0.0000000, 4.3267487, 0.0000000, 6.3496042, 0.0000000, 8.5498797, @@ -744,7 +744,7 @@ static const float codebook_vector8[338] = { 27.4731418, 27.4731418, }; -static const float codebook_vector10[578] = { +static const DECLARE_ALIGNED(16, float, codebook_vector10)[578] = { 0.0000000, 0.0000000, 0.0000000, 1.0000000, 0.0000000, 2.5198421, 0.0000000, 4.3267487, 0.0000000, 6.3496042, 0.0000000, 8.5498797, @@ -899,6 +899,173 @@ const float * const ff_aac_codebook_vectors[] = { codebook_vector8, codebook_vector10, }; +static const float codebook_vector0_vals[] = { + -1.0000000, 0.0000000, 1.0000000 +}; + +/* + * bits 0:1, 2:3, 4:5, 6:7 index into _vals array + * 8:11 number of non-zero values + * 12:15 bit mask of non-zero values + */ +static const uint16_t codebook_vector02_idx[] = { + 0x0000, 0x8140, 0x8180, 0x4110, 0xc250, 0xc290, 0x4120, 0xc260, 0xc2a0, + 0x2104, 0xa244, 0xa284, 0x6214, 0xe354, 0xe394, 0x6224, 0xe364, 0xe3a4, + 0x2108, 0xa248, 0xa288, 0x6218, 0xe358, 0xe398, 0x6228, 0xe368, 0xe3a8, + 0x1101, 0x9241, 0x9281, 0x5211, 0xd351, 0xd391, 0x5221, 0xd361, 0xd3a1, + 0x3205, 0xb345, 0xb385, 0x7315, 0xf455, 0xf495, 0x7325, 0xf465, 0xf4a5, + 0x3209, 0xb349, 0xb389, 0x7319, 0xf459, 0xf499, 0x7329, 0xf469, 0xf4a9, + 0x1102, 0x9242, 0x9282, 0x5212, 0xd352, 0xd392, 0x5222, 0xd362, 0xd3a2, + 0x3206, 0xb346, 0xb386, 0x7316, 0xf456, 0xf496, 0x7326, 0xf466, 0xf4a6, + 0x320a, 0xb34a, 0xb38a, 0x731a, 0xf45a, 0xf49a, 0x732a, 0xf46a, 0xf4aa, +}; + +static const float codebook_vector4_vals[] = { + -6.3496042, -4.3267487, + -2.5198421, -1.0000000, + 0.0000000, 1.0000000, + 2.5198421, 4.3267487, + 6.3496042, +}; + +/* + * bits 0:3, 4:7 index into _vals array + */ +static const uint16_t codebook_vector4_idx[] = { + 0x0000, 0x0010, 0x0020, 0x0030, 0x0040, 0x0050, 0x0060, 0x0070, 0x0080, + 0x0001, 0x0011, 0x0021, 0x0031, 0x0041, 0x0051, 0x0061, 0x0071, 0x0081, + 0x0002, 0x0012, 0x0022, 0x0032, 0x0042, 0x0052, 0x0062, 0x0072, 0x0082, + 0x0003, 0x0013, 0x0023, 0x0033, 0x0043, 0x0053, 0x0063, 0x0073, 0x0083, + 0x0004, 0x0014, 0x0024, 0x0034, 0x0044, 0x0054, 0x0064, 0x0074, 0x0084, + 0x0005, 0x0015, 0x0025, 0x0035, 0x0045, 0x0055, 0x0065, 0x0075, 0x0085, + 0x0006, 0x0016, 0x0026, 0x0036, 0x0046, 0x0056, 0x0066, 0x0076, 0x0086, + 0x0007, 0x0017, 0x0027, 0x0037, 0x0047, 0x0057, 0x0067, 0x0077, 0x0087, + 0x0008, 0x0018, 0x0028, 0x0038, 0x0048, 0x0058, 0x0068, 0x0078, 0x0088, +}; + +/* + * bits 0:3, 4:7 index into _vals array + * 8:11 number of non-zero values + * 12:15 1: only second value non-zero + * 0: other cases + */ +static const uint16_t codebook_vector6_idx[] = { + 0x0000, 0x0110, 0x0120, 0x0130, 0x0140, 0x0150, 0x0160, 0x0170, + 0x1101, 0x0211, 0x0221, 0x0231, 0x0241, 0x0251, 0x0261, 0x0271, + 0x1102, 0x0212, 0x0222, 0x0232, 0x0242, 0x0252, 0x0262, 0x0272, + 0x1103, 0x0213, 0x0223, 0x0233, 0x0243, 0x0253, 0x0263, 0x0273, + 0x1104, 0x0214, 0x0224, 0x0234, 0x0244, 0x0254, 0x0264, 0x0274, + 0x1105, 0x0215, 0x0225, 0x0235, 0x0245, 0x0255, 0x0265, 0x0275, + 0x1106, 0x0216, 0x0226, 0x0236, 0x0246, 0x0256, 0x0266, 0x0276, + 0x1107, 0x0217, 0x0227, 0x0237, 0x0247, 0x0257, 0x0267, 0x0277, +}; + +/* + * bits 0:3, 4:7 index into _vals array + * 8:11 number of non-zero values + * 12:15 1: only second value non-zero + * 0: other cases + */ +static const uint16_t codebook_vector8_idx[] = { + 0x0000, 0x0110, 0x0120, 0x0130, 0x0140, 0x0150, 0x0160, + 0x0170, 0x0180, 0x0190, 0x01a0, 0x01b0, 0x01c0, + 0x1101, 0x0211, 0x0221, 0x0231, 0x0241, 0x0251, 0x0261, + 0x0271, 0x0281, 0x0291, 0x02a1, 0x02b1, 0x02c1, + 0x1102, 0x0212, 0x0222, 0x0232, 0x0242, 0x0252, 0x0262, + 0x0272, 0x0282, 0x0292, 0x02a2, 0x02b2, 0x02c2, + 0x1103, 0x0213, 0x0223, 0x0233, 0x0243, 0x0253, 0x0263, + 0x0273, 0x0283, 0x0293, 0x02a3, 0x02b3, 0x02c3, + 0x1104, 0x0214, 0x0224, 0x0234, 0x0244, 0x0254, 0x0264, + 0x0274, 0x0284, 0x0294, 0x02a4, 0x02b4, 0x02c4, + 0x1105, 0x0215, 0x0225, 0x0235, 0x0245, 0x0255, 0x0265, + 0x0275, 0x0285, 0x0295, 0x02a5, 0x02b5, 0x02c5, + 0x1106, 0x0216, 0x0226, 0x0236, 0x0246, 0x0256, 0x0266, + 0x0276, 0x0286, 0x0296, 0x02a6, 0x02b6, 0x02c6, + 0x1107, 0x0217, 0x0227, 0x0237, 0x0247, 0x0257, 0x0267, + 0x0277, 0x0287, 0x0297, 0x02a7, 0x02b7, 0x02c7, + 0x1108, 0x0218, 0x0228, 0x0238, 0x0248, 0x0258, 0x0268, + 0x0278, 0x0288, 0x0298, 0x02a8, 0x02b8, 0x02c8, + 0x1109, 0x0219, 0x0229, 0x0239, 0x0249, 0x0259, 0x0269, + 0x0279, 0x0289, 0x0299, 0x02a9, 0x02b9, 0x02c9, + 0x110a, 0x021a, 0x022a, 0x023a, 0x024a, 0x025a, 0x026a, + 0x027a, 0x028a, 0x029a, 0x02aa, 0x02ba, 0x02ca, + 0x110b, 0x021b, 0x022b, 0x023b, 0x024b, 0x025b, 0x026b, + 0x027b, 0x028b, 0x029b, 0x02ab, 0x02bb, 0x02cb, + 0x110c, 0x021c, 0x022c, 0x023c, 0x024c, 0x025c, 0x026c, + 0x027c, 0x028c, 0x029c, 0x02ac, 0x02bc, 0x02cc, +}; + +static const float codebook_vector10_vals[] = { + 0.0000000, 1.0000000, + 2.5198421, 4.3267487, + 6.3496042, 8.5498797, + 10.9027236, 13.3905183, + 16.0000000, 18.7207544, + 21.5443469, 24.4637810, + 27.4731418, 30.5673509, + 33.7419917, 36.9931811, +}; + +/* + * bits 0:3, 4:7 index into _vals array + * 8:9 bit mask of escape-coded entries + * 12:15 number of non-zero values + */ +static const uint16_t codebook_vector10_idx[] = { + 0x0000, 0x1010, 0x1020, 0x1030, 0x1040, 0x1050, 0x1060, 0x1070, + 0x1080, 0x1090, 0x10a0, 0x10b0, 0x10c0, 0x10d0, 0x10e0, 0x10f0, 0x1200, + 0x1001, 0x2011, 0x2021, 0x2031, 0x2041, 0x2051, 0x2061, 0x2071, + 0x2081, 0x2091, 0x20a1, 0x20b1, 0x20c1, 0x20d1, 0x20e1, 0x20f1, 0x2201, + 0x1002, 0x2012, 0x2022, 0x2032, 0x2042, 0x2052, 0x2062, 0x2072, + 0x2082, 0x2092, 0x20a2, 0x20b2, 0x20c2, 0x20d2, 0x20e2, 0x20f2, 0x2202, + 0x1003, 0x2013, 0x2023, 0x2033, 0x2043, 0x2053, 0x2063, 0x2073, + 0x2083, 0x2093, 0x20a3, 0x20b3, 0x20c3, 0x20d3, 0x20e3, 0x20f3, 0x2203, + 0x1004, 0x2014, 0x2024, 0x2034, 0x2044, 0x2054, 0x2064, 0x2074, + 0x2084, 0x2094, 0x20a4, 0x20b4, 0x20c4, 0x20d4, 0x20e4, 0x20f4, 0x2204, + 0x1005, 0x2015, 0x2025, 0x2035, 0x2045, 0x2055, 0x2065, 0x2075, + 0x2085, 0x2095, 0x20a5, 0x20b5, 0x20c5, 0x20d5, 0x20e5, 0x20f5, 0x2205, + 0x1006, 0x2016, 0x2026, 0x2036, 0x2046, 0x2056, 0x2066, 0x2076, + 0x2086, 0x2096, 0x20a6, 0x20b6, 0x20c6, 0x20d6, 0x20e6, 0x20f6, 0x2206, + 0x1007, 0x2017, 0x2027, 0x2037, 0x2047, 0x2057, 0x2067, 0x2077, + 0x2087, 0x2097, 0x20a7, 0x20b7, 0x20c7, 0x20d7, 0x20e7, 0x20f7, 0x2207, + 0x1008, 0x2018, 0x2028, 0x2038, 0x2048, 0x2058, 0x2068, 0x2078, + 0x2088, 0x2098, 0x20a8, 0x20b8, 0x20c8, 0x20d8, 0x20e8, 0x20f8, 0x2208, + 0x1009, 0x2019, 0x2029, 0x2039, 0x2049, 0x2059, 0x2069, 0x2079, + 0x2089, 0x2099, 0x20a9, 0x20b9, 0x20c9, 0x20d9, 0x20e9, 0x20f9, 0x2209, + 0x100a, 0x201a, 0x202a, 0x203a, 0x204a, 0x205a, 0x206a, 0x207a, + 0x208a, 0x209a, 0x20aa, 0x20ba, 0x20ca, 0x20da, 0x20ea, 0x20fa, 0x220a, + 0x100b, 0x201b, 0x202b, 0x203b, 0x204b, 0x205b, 0x206b, 0x207b, + 0x208b, 0x209b, 0x20ab, 0x20bb, 0x20cb, 0x20db, 0x20eb, 0x20fb, 0x220b, + 0x100c, 0x201c, 0x202c, 0x203c, 0x204c, 0x205c, 0x206c, 0x207c, + 0x208c, 0x209c, 0x20ac, 0x20bc, 0x20cc, 0x20dc, 0x20ec, 0x20fc, 0x220c, + 0x100d, 0x201d, 0x202d, 0x203d, 0x204d, 0x205d, 0x206d, 0x207d, + 0x208d, 0x209d, 0x20ad, 0x20bd, 0x20cd, 0x20dd, 0x20ed, 0x20fd, 0x220d, + 0x100e, 0x201e, 0x202e, 0x203e, 0x204e, 0x205e, 0x206e, 0x207e, + 0x208e, 0x209e, 0x20ae, 0x20be, 0x20ce, 0x20de, 0x20ee, 0x20fe, 0x220e, + 0x100f, 0x201f, 0x202f, 0x203f, 0x204f, 0x205f, 0x206f, 0x207f, + 0x208f, 0x209f, 0x20af, 0x20bf, 0x20cf, 0x20df, 0x20ef, 0x20ff, 0x220f, + 0x1100, 0x2110, 0x2120, 0x2130, 0x2140, 0x2150, 0x2160, 0x2170, + 0x2180, 0x2190, 0x21a0, 0x21b0, 0x21c0, 0x21d0, 0x21e0, 0x21f0, 0x2300, +}; + +const float *const ff_aac_codebook_vector_vals[] = { + codebook_vector0_vals, codebook_vector0_vals, + codebook_vector10_vals, codebook_vector10_vals, + codebook_vector4_vals, codebook_vector4_vals, + codebook_vector10_vals, codebook_vector10_vals, + codebook_vector10_vals, codebook_vector10_vals, + codebook_vector10_vals, +}; + +const uint16_t *const ff_aac_codebook_vector_idx[] = { + codebook_vector02_idx, codebook_vector02_idx, + codebook_vector02_idx, codebook_vector02_idx, + codebook_vector4_idx, codebook_vector4_idx, + codebook_vector6_idx, codebook_vector6_idx, + codebook_vector8_idx, codebook_vector8_idx, + codebook_vector10_idx, +}; + /* @name swb_offsets * Sample offset into the window indicating the beginning of a scalefactor * window band @@ -1003,7 +1170,7 @@ static const uint16_t swb_offset_128_8[] = { 36, 44, 52, 60, 72, 88, 108, 128 }; -const uint16_t *ff_swb_offset_1024[] = { +const uint16_t * const ff_swb_offset_1024[] = { swb_offset_1024_96, swb_offset_1024_96, swb_offset_1024_64, swb_offset_1024_48, swb_offset_1024_48, swb_offset_1024_32, swb_offset_1024_24, swb_offset_1024_24, swb_offset_1024_16, @@ -1011,7 +1178,7 @@ const uint16_t *ff_swb_offset_1024[] = { swb_offset_1024_8 }; -const uint16_t *ff_swb_offset_128[] = { +const uint16_t * const ff_swb_offset_128[] = { /* The last entry on the following row is swb_offset_128_64 but is a duplicate of swb_offset_128_96. */ swb_offset_128_96, swb_offset_128_96, swb_offset_128_96, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/aactab.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/aactab.h index fd0929c9c3..283d6c3a2d 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/aactab.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/aactab.h @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/aactab.h + * @file * AAC data declarations * @author Oded Shimon ( ods15 ods15 dyndns org ) * @author Maxim Gavrilov ( maxim.gavrilov gmail com ) @@ -43,8 +43,8 @@ /* @name window coefficients * @{ */ -DECLARE_ALIGNED(16, extern float, ff_aac_kbd_long_1024[1024]); -DECLARE_ALIGNED(16, extern float, ff_aac_kbd_short_128[128]); +DECLARE_ALIGNED(16, extern float, ff_aac_kbd_long_1024)[1024]; +DECLARE_ALIGNED(16, extern float, ff_aac_kbd_short_128)[128]; // @} /* @name number of scalefactor window bands for long and short transform windows respectively @@ -64,9 +64,11 @@ extern const uint8_t * const ff_aac_spectral_bits [11]; extern const uint16_t ff_aac_spectral_sizes[11]; extern const float *ff_aac_codebook_vectors[]; +extern const float *ff_aac_codebook_vector_vals[]; +extern const uint16_t *ff_aac_codebook_vector_idx[]; -extern const uint16_t *ff_swb_offset_1024[13]; -extern const uint16_t *ff_swb_offset_128 [13]; +extern const uint16_t * const ff_swb_offset_1024[13]; +extern const uint16_t * const ff_swb_offset_128 [13]; extern const uint8_t ff_tns_max_bands_1024[13]; extern const uint8_t ff_tns_max_bands_128 [13]; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/aandcttab.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/aandcttab.c index ef05342dc5..87c50b37cf 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/aandcttab.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/aandcttab.c @@ -17,7 +17,7 @@ */ /** - * @file libavcodec/aandcttab.c + * @file * AAN (Arai Agui Aakajima) (I)DCT tables */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/aandcttab.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/aandcttab.h index ed1c3c3465..d774828a4d 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/aandcttab.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/aandcttab.h @@ -17,7 +17,7 @@ */ /** - * @file libavcodec/aandcttab.h + * @file * AAN (Arai Agui Nakajima) (I)DCT tables */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/aasc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/aasc.c index 46f64f7e9e..82bd2bfd3d 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/aasc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/aasc.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/aasc.c + * @file * Autodesk RLE Video Decoder by Konstantin Shishkov */ @@ -111,7 +111,7 @@ static av_cold int aasc_decode_end(AVCodecContext *avctx) AVCodec aasc_decoder = { "aasc", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_AASC, sizeof(AascContext), aasc_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ac3.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/ac3.c index 84862c69e9..3fce5bcfb9 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/ac3.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ac3.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/ac3.c + * @file * Common code between the AC-3 encoder and decoder. */ @@ -28,8 +28,51 @@ #include "ac3.h" #include "get_bits.h" +#if CONFIG_HARDCODED_TABLES + +/** + * Starting frequency coefficient bin for each critical band. + */ +static const uint8_t band_start_tab[51] = { + 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, 31, + 34, 37, 40, 43, 46, 49, 55, 61, 67, 73, + 79, 85, 97, 109, 121, 133, 157, 181, 205, 229, 253 +}; + +/** + * Maps each frequency coefficient bin to the critical band that contains it. + */ +static const uint8_t bin_to_band_tab[253] = { + 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, 28, 28, 29, 29, 29, 30, 30, 30, + 31, 31, 31, 32, 32, 32, 33, 33, 33, 34, 34, 34, + 35, 35, 35, 35, 35, 35, 36, 36, 36, 36, 36, 36, + 37, 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, 38, + 39, 39, 39, 39, 39, 39, 40, 40, 40, 40, 40, 40, + 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, + 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, + 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, + 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, + 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, + 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, + 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, + 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, + 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, + 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, + 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, + 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, + 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49 +}; + +#else /* CONFIG_HARDCODED_TABLES */ static uint8_t band_start_tab[51]; static uint8_t bin_to_band_tab[253]; +#endif static inline int calc_lowcomp1(int a, int b0, int b1, int c) { @@ -55,29 +98,27 @@ static inline int calc_lowcomp(int a, int b0, int b1, int bin) void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd, int16_t *band_psd) { - int bin, i, j, k, end1, v; + int bin, band; /* exponent mapping to PSD */ - for(bin=start;bin> 1, 255); - v = FFMAX(v, psd[j]) + ff_ac3_log_add_tab[adr]; - j++; + int adr = FFMIN(max - ((v + psd[bin] + 1) >> 1), 255); + v = max + ff_ac3_log_add_tab[adr]; } - band_psd[k]=v; - k++; - } while (end > band_start_tab[k]); + band_psd[band++] = v; + } while (end > band_start_tab[band]); } int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd, @@ -87,75 +128,71 @@ int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd, int16_t *mask) { int16_t excite[50]; /* excitation */ - int bin, k; - int bndstrt, bndend, begin, end1, tmp; + int band; + int band_start, band_end, begin, end1; int lowcomp, fastleak, slowleak; /* excitation function */ - bndstrt = bin_to_band_tab[start]; - bndend = bin_to_band_tab[end-1] + 1; + band_start = bin_to_band_tab[start]; + band_end = bin_to_band_tab[end-1] + 1; - if (bndstrt == 0) { + if (band_start == 0) { lowcomp = 0; lowcomp = calc_lowcomp1(lowcomp, band_psd[0], band_psd[1], 384); excite[0] = band_psd[0] - fast_gain - lowcomp; lowcomp = calc_lowcomp1(lowcomp, band_psd[1], band_psd[2], 384); excite[1] = band_psd[1] - fast_gain - lowcomp; begin = 7; - for (bin = 2; bin < 7; bin++) { - if (!(is_lfe && bin == 6)) - lowcomp = calc_lowcomp1(lowcomp, band_psd[bin], band_psd[bin+1], 384); - fastleak = band_psd[bin] - fast_gain; - slowleak = band_psd[bin] - s->slow_gain; - excite[bin] = fastleak - lowcomp; - if (!(is_lfe && bin == 6)) { - if (band_psd[bin] <= band_psd[bin+1]) { - begin = bin + 1; + for (band = 2; band < 7; band++) { + if (!(is_lfe && band == 6)) + lowcomp = calc_lowcomp1(lowcomp, band_psd[band], band_psd[band+1], 384); + fastleak = band_psd[band] - fast_gain; + slowleak = band_psd[band] - s->slow_gain; + excite[band] = fastleak - lowcomp; + if (!(is_lfe && band == 6)) { + if (band_psd[band] <= band_psd[band+1]) { + begin = band + 1; break; } } } - end1=bndend; - if (end1 > 22) end1=22; - - for (bin = begin; bin < end1; bin++) { - if (!(is_lfe && bin == 6)) - lowcomp = calc_lowcomp(lowcomp, band_psd[bin], band_psd[bin+1], bin); - - fastleak = FFMAX(fastleak - s->fast_decay, band_psd[bin] - fast_gain); - slowleak = FFMAX(slowleak - s->slow_decay, band_psd[bin] - s->slow_gain); - excite[bin] = FFMAX(fastleak - lowcomp, slowleak); + end1 = FFMIN(band_end, 22); + for (band = begin; band < end1; band++) { + if (!(is_lfe && band == 6)) + lowcomp = calc_lowcomp(lowcomp, band_psd[band], band_psd[band+1], band); + fastleak = FFMAX(fastleak - s->fast_decay, band_psd[band] - fast_gain); + slowleak = FFMAX(slowleak - s->slow_decay, band_psd[band] - s->slow_gain); + excite[band] = FFMAX(fastleak - lowcomp, slowleak); } begin = 22; } else { /* coupling channel */ - begin = bndstrt; - + begin = band_start; fastleak = (s->cpl_fast_leak << 8) + 768; slowleak = (s->cpl_slow_leak << 8) + 768; } - for (bin = begin; bin < bndend; bin++) { - fastleak = FFMAX(fastleak - s->fast_decay, band_psd[bin] - fast_gain); - slowleak = FFMAX(slowleak - s->slow_decay, band_psd[bin] - s->slow_gain); - excite[bin] = FFMAX(fastleak, slowleak); + for (band = begin; band < band_end; band++) { + fastleak = FFMAX(fastleak - s->fast_decay, band_psd[band] - fast_gain); + slowleak = FFMAX(slowleak - s->slow_decay, band_psd[band] - s->slow_gain); + excite[band] = FFMAX(fastleak, slowleak); } /* compute masking curve */ - for (bin = bndstrt; bin < bndend; bin++) { - tmp = s->db_per_bit - band_psd[bin]; + for (band = band_start; band < band_end; band++) { + int tmp = s->db_per_bit - band_psd[band]; if (tmp > 0) { - excite[bin] += tmp >> 2; + excite[band] += tmp >> 2; } - mask[bin] = FFMAX(ff_ac3_hearing_threshold_tab[bin >> s->sr_shift][s->sr_code], excite[bin]); + mask[band] = FFMAX(ff_ac3_hearing_threshold_tab[band >> s->sr_shift][s->sr_code], excite[band]); } /* delta bit allocation */ if (dba_mode == DBA_REUSE || dba_mode == DBA_NEW) { - int band, seg, delta; + int i, seg, delta; if (dba_nsegs >= 8) return -1; band = 0; @@ -168,9 +205,8 @@ int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd, } else { delta = (dba_values[seg] - 4) << 7; } - for (k = 0; k < dba_lengths[seg]; k++) { - mask[band] += delta; - band++; + for (i = 0; i < dba_lengths[seg]; i++) { + mask[band++] += delta; } } } @@ -181,25 +217,24 @@ void ff_ac3_bit_alloc_calc_bap(int16_t *mask, int16_t *psd, int start, int end, int snr_offset, int floor, const uint8_t *bap_tab, uint8_t *bap) { - int i, j, k, end1, v, address; + int bin, band; /* special case, if snr offset is -960, set all bap's to zero */ - if(snr_offset == -960) { + if (snr_offset == -960) { memset(bap, 0, 256); return; } - i = start; - j = bin_to_band_tab[start]; + bin = start; + band = bin_to_band_tab[start]; do { - v = (FFMAX(mask[j] - snr_offset - floor, 0) & 0x1FE0) + floor; - end1 = FFMIN(band_start_tab[j] + ff_ac3_critical_band_size_tab[j], end); - for (k = i; k < end1; k++) { - address = av_clip((psd[i] - v) >> 5, 0, 63); - bap[i] = bap_tab[address]; - i++; + int m = (FFMAX(mask[band] - snr_offset - floor, 0) & 0x1FE0) + floor; + int band_end = FFMIN(band_start_tab[band+1], end); + for (; bin < band_end; bin++) { + int address = av_clip((psd[bin] - m) >> 5, 0, 63); + bap[bin] = bap_tab[address]; } - } while (end > band_start_tab[j++]); + } while (end > band_start_tab[band++]); } /* AC-3 bit allocation. The algorithm is the one described in the AC-3 @@ -218,8 +253,8 @@ void ac3_parametric_bit_allocation(AC3BitAllocParameters *s, uint8_t *bap, ff_ac3_bit_alloc_calc_psd(exp, start, end, psd, band_psd); ff_ac3_bit_alloc_calc_mask(s, band_psd, start, end, fast_gain, is_lfe, - dba_mode, dba_nsegs, dba_offsets, dba_lengths, dba_values, - mask); + dba_mode, dba_nsegs, dba_offsets, dba_lengths, + dba_values, mask); ff_ac3_bit_alloc_calc_bap(mask, psd, start, end, snr_offset, s->floor, ff_ac3_bap_tab, bap); @@ -232,15 +267,15 @@ void ac3_parametric_bit_allocation(AC3BitAllocParameters *s, uint8_t *bap, */ av_cold void ac3_common_init(void) { - int i, j, k, l, v; +#if !CONFIG_HARDCODED_TABLES /* compute bndtab and masktab from bandsz */ - k = 0; - l = 0; - for(i=0;i<50;i++) { - band_start_tab[i] = l; - v = ff_ac3_critical_band_size_tab[i]; - for(j=0;jerror_recognition >= FF_ER_CAREFUL) { s->input_buffer = av_mallocz(AC3_FRAME_BUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE); if (!s->input_buffer) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); } avctx->sample_fmt = SAMPLE_FMT_S16; @@ -412,20 +412,25 @@ static int decode_exponents(GetBitContext *gbc, int exp_strategy, int ngrps, */ static void calc_transform_coeffs_cpl(AC3DecodeContext *s) { - int i, j, ch, bnd; + int bin, band, ch; - i = s->start_freq[CPL_CH]; - for(bnd=0; bndnum_cpl_bands; bnd++) { - for (j = 0; j < s->cpl_band_sizes[bnd]; j++,i++) { - for(ch=1; ch<=s->fbw_channels; ch++) { - if(s->channel_in_cpl[ch]) { - s->fixed_coeffs[ch][i] = ((int64_t)s->fixed_coeffs[CPL_CH][i] * - (int64_t)s->cpl_coords[ch][bnd]) >> 23; - if (ch == 2 && s->phase_flags[bnd]) - s->fixed_coeffs[ch][i] = -s->fixed_coeffs[ch][i]; + bin = s->start_freq[CPL_CH]; + for (band = 0; band < s->num_cpl_bands; band++) { + int band_start = bin; + int band_end = bin + s->cpl_band_sizes[band]; + for (ch = 1; ch <= s->fbw_channels; ch++) { + if (s->channel_in_cpl[ch]) { + int cpl_coord = s->cpl_coords[ch][band] << 5; + for (bin = band_start; bin < band_end; bin++) { + s->fixed_coeffs[ch][bin] = MULH(s->fixed_coeffs[CPL_CH][bin] << 4, cpl_coord); + } + if (ch == 2 && s->phase_flags[band]) { + for (bin = band_start; bin < band_end; bin++) + s->fixed_coeffs[2][bin] = -s->fixed_coeffs[2][bin]; } } } + bin = band_end; } } @@ -598,7 +603,6 @@ static void do_rematrixing(AC3DecodeContext *s) { int bnd, i; int end, bndend; - int tmp0, tmp1; end = FFMIN(s->end_freq[1], s->end_freq[2]); @@ -606,10 +610,9 @@ static void do_rematrixing(AC3DecodeContext *s) if(s->rematrixing_flags[bnd]) { bndend = FFMIN(end, ff_ac3_rematrix_band_tab[bnd+1]); for(i=ff_ac3_rematrix_band_tab[bnd]; ifixed_coeffs[1][i]; - tmp1 = s->fixed_coeffs[2][i]; - s->fixed_coeffs[1][i] = tmp0 + tmp1; - s->fixed_coeffs[2][i] = tmp0 - tmp1; + int tmp0 = s->fixed_coeffs[1][i]; + s->fixed_coeffs[1][i] += s->fixed_coeffs[2][i]; + s->fixed_coeffs[2][i] = tmp0 - s->fixed_coeffs[2][i]; } } } @@ -812,14 +815,105 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) /* spectral extension strategy */ if (s->eac3 && (!blk || get_bits1(gbc))) { - if (get_bits1(gbc)) { - av_log_missing_feature(s->avctx, "Spectral extension", 1); - return -1; + s->spx_in_use = get_bits1(gbc); + if (s->spx_in_use) { + int dst_start_freq, dst_end_freq, src_start_freq, + start_subband, end_subband; + + /* determine which channels use spx */ + if (s->channel_mode == AC3_CHMODE_MONO) { + s->channel_uses_spx[1] = 1; + } else { + for (ch = 1; ch <= fbw_channels; ch++) + s->channel_uses_spx[ch] = get_bits1(gbc); + } + + /* get the frequency bins of the spx copy region and the spx start + and end subbands */ + dst_start_freq = get_bits(gbc, 2); + start_subband = get_bits(gbc, 3) + 2; + if (start_subband > 7) + start_subband += start_subband - 7; + end_subband = get_bits(gbc, 3) + 5; + if (end_subband > 7) + end_subband += end_subband - 7; + dst_start_freq = dst_start_freq * 12 + 25; + src_start_freq = start_subband * 12 + 25; + dst_end_freq = end_subband * 12 + 25; + + /* check validity of spx ranges */ + if (start_subband >= end_subband) { + av_log(s->avctx, AV_LOG_ERROR, "invalid spectral extension " + "range (%d >= %d)\n", start_subband, end_subband); + return -1; + } + if (dst_start_freq >= src_start_freq) { + av_log(s->avctx, AV_LOG_ERROR, "invalid spectral extension " + "copy start bin (%d >= %d)\n", dst_start_freq, src_start_freq); + return -1; + } + + s->spx_dst_start_freq = dst_start_freq; + s->spx_src_start_freq = src_start_freq; + s->spx_dst_end_freq = dst_end_freq; + + decode_band_structure(gbc, blk, s->eac3, 0, + start_subband, end_subband, + ff_eac3_default_spx_band_struct, + &s->num_spx_bands, + s->spx_band_sizes); + } else { + for (ch = 1; ch <= fbw_channels; ch++) { + s->channel_uses_spx[ch] = 0; + s->first_spx_coords[ch] = 1; + } } - /* TODO: parse spectral extension strategy info */ } - /* TODO: spectral extension coordinates */ + /* spectral extension coordinates */ + if (s->spx_in_use) { + for (ch = 1; ch <= fbw_channels; ch++) { + if (s->channel_uses_spx[ch]) { + if (s->first_spx_coords[ch] || get_bits1(gbc)) { + float spx_blend; + int bin, master_spx_coord; + + s->first_spx_coords[ch] = 0; + spx_blend = get_bits(gbc, 5) * (1.0f/32); + master_spx_coord = get_bits(gbc, 2) * 3; + + bin = s->spx_src_start_freq; + for (bnd = 0; bnd < s->num_spx_bands; bnd++) { + int bandsize; + int spx_coord_exp, spx_coord_mant; + float nratio, sblend, nblend, spx_coord; + + /* calculate blending factors */ + bandsize = s->spx_band_sizes[bnd]; + nratio = ((float)((bin + (bandsize >> 1))) / s->spx_dst_end_freq) - spx_blend; + nratio = av_clipf(nratio, 0.0f, 1.0f); + nblend = sqrtf(3.0f * nratio); // noise is scaled by sqrt(3) to give unity variance + sblend = sqrtf(1.0f - nratio); + bin += bandsize; + + /* decode spx coordinates */ + spx_coord_exp = get_bits(gbc, 4); + spx_coord_mant = get_bits(gbc, 2); + if (spx_coord_exp == 15) spx_coord_mant <<= 1; + else spx_coord_mant += 4; + spx_coord_mant <<= (25 - spx_coord_exp - master_spx_coord); + spx_coord = spx_coord_mant * (1.0f/(1<<23)); + + /* multiply noise and signal blending factors by spx coordinate */ + s->spx_noise_blend [ch][bnd] = nblend * spx_coord; + s->spx_signal_blend[ch][bnd] = sblend * spx_coord; + } + } + } else { + s->first_spx_coords[ch] = 1; + } + } + } /* coupling strategy */ if (s->eac3 ? s->cpl_strategy_exists[blk] : get_bits1(gbc)) { @@ -856,9 +950,9 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) s->phase_flags_in_use = get_bits1(gbc); /* coupling frequency range */ - /* TODO: modify coupling end freq if spectral extension is used */ cpl_start_subband = get_bits(gbc, 4); - cpl_end_subband = get_bits(gbc, 4) + 3; + cpl_end_subband = s->spx_in_use ? (s->spx_src_start_freq - 37) / 12 : + get_bits(gbc, 4) + 3; if (cpl_start_subband >= cpl_end_subband) { av_log(s->avctx, AV_LOG_ERROR, "invalid coupling range (%d >= %d)\n", cpl_start_subband, cpl_end_subband); @@ -931,13 +1025,16 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) if (channel_mode == AC3_CHMODE_STEREO) { if ((s->eac3 && !blk) || get_bits1(gbc)) { s->num_rematrixing_bands = 4; - if(cpl_in_use && s->start_freq[CPL_CH] <= 61) + if (cpl_in_use && s->start_freq[CPL_CH] <= 61) { s->num_rematrixing_bands -= 1 + (s->start_freq[CPL_CH] == 37); + } else if (s->spx_in_use && s->spx_src_start_freq <= 61) { + s->num_rematrixing_bands--; + } for(bnd=0; bndnum_rematrixing_bands; bnd++) s->rematrixing_flags[bnd] = get_bits1(gbc); } else if (!blk) { - av_log(s->avctx, AV_LOG_ERROR, "new rematrixing strategy must be present in block 0\n"); - return -1; + av_log(s->avctx, AV_LOG_WARNING, "Warning: new rematrixing strategy not present in block 0\n"); + s->num_rematrixing_bands = 0; } } @@ -957,6 +1054,8 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) int prev = s->end_freq[ch]; if (s->channel_in_cpl[ch]) s->end_freq[ch] = s->start_freq[CPL_CH]; + else if (s->channel_uses_spx[ch]) + s->end_freq[ch] = s->spx_src_start_freq; else { int bandwidth_code = get_bits(gbc, 6); if (bandwidth_code > 60) { @@ -1153,8 +1252,6 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) /* TODO: generate enhanced coupling coordinates and uncouple */ - /* TODO: apply spectral extension */ - /* recover coefficients if rematrixing is in use */ if(s->channel_mode == AC3_CHMODE_STEREO) do_rematrixing(s); @@ -1163,13 +1260,18 @@ static int decode_audio_block(AC3DecodeContext *s, int blk) for(ch=1; ch<=s->channels; ch++) { float gain = s->mul_bias / 4194304.0f; if(s->channel_mode == AC3_CHMODE_DUALMONO) { - gain *= s->dynamic_range[ch-1]; + gain *= s->dynamic_range[2-ch]; } else { gain *= s->dynamic_range[0]; } s->dsp.int32_to_float_fmul_scalar(s->transform_coeffs[ch], s->fixed_coeffs[ch], gain, 256); } + /* apply spectral extension to high frequency bins */ + if (s->spx_in_use && CONFIG_EAC3_DECODER) { + ff_eac3_apply_spectral_extension(s); + } + /* downmix and MDCT. order depends on whether block switching is used for any channel in this block. this is because coefficients for the long and short transforms cannot be mixed. */ @@ -1233,21 +1335,7 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size, *data_size = 0; err = parse_frame_header(s); - /* check that reported frame size fits in input buffer */ - if(s->frame_size > buf_size) { - av_log(avctx, AV_LOG_ERROR, "incomplete frame\n"); - err = AAC_AC3_PARSE_ERROR_FRAME_SIZE; - } - - /* check for crc mismatch */ - if(err != AAC_AC3_PARSE_ERROR_FRAME_SIZE && avctx->error_recognition >= FF_ER_CAREFUL) { - if(av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, &buf[2], s->frame_size-2)) { - av_log(avctx, AV_LOG_ERROR, "frame CRC mismatch\n"); - err = AAC_AC3_PARSE_ERROR_CRC; - } - } - - if(err && err != AAC_AC3_PARSE_ERROR_CRC) { + if (err) { switch(err) { case AAC_AC3_PARSE_ERROR_SYNC: av_log(avctx, AV_LOG_ERROR, "frame sync error\n"); @@ -1275,6 +1363,18 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size, av_log(avctx, AV_LOG_ERROR, "invalid header\n"); break; } + } else { + /* check that reported frame size fits in input buffer */ + if (s->frame_size > buf_size) { + av_log(avctx, AV_LOG_ERROR, "incomplete frame\n"); + err = AAC_AC3_PARSE_ERROR_FRAME_SIZE; + } else if (avctx->error_recognition >= FF_ER_CAREFUL) { + /* check for crc mismatch */ + if (av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, &buf[2], s->frame_size-2)) { + av_log(avctx, AV_LOG_ERROR, "frame CRC mismatch\n"); + err = AAC_AC3_PARSE_ERROR_CRC; + } + } } /* if frame is ok, set audio parameters */ @@ -1320,7 +1420,7 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size, out_samples += 256 * s->out_channels; } *data_size = s->num_blocks * 256 * avctx->channels * sizeof (int16_t); - return s->frame_size; + return FFMIN(buf_size, s->frame_size); } /** @@ -1339,7 +1439,7 @@ static av_cold int ac3_decode_end(AVCodecContext *avctx) AVCodec ac3_decoder = { .name = "ac3", - .type = CODEC_TYPE_AUDIO, + .type = AVMEDIA_TYPE_AUDIO, .id = CODEC_ID_AC3, .priv_data_size = sizeof (AC3DecodeContext), .init = ac3_decode_init, @@ -1351,7 +1451,7 @@ AVCodec ac3_decoder = { #if CONFIG_EAC3_DECODER AVCodec eac3_decoder = { .name = "eac3", - .type = CODEC_TYPE_AUDIO, + .type = AVMEDIA_TYPE_AUDIO, .id = CODEC_ID_EAC3, .priv_data_size = sizeof (AC3DecodeContext), .init = ac3_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ac3dec.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/ac3dec.h index 52eb0ef9aa..8c0d442fc0 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/ac3dec.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ac3dec.h @@ -20,8 +20,31 @@ */ /** - * @file libavcodec/ac3.h + * @file * Common code between the AC-3 and E-AC-3 decoders. + * + * Summary of MDCT Coefficient Grouping: + * The individual MDCT coefficient indices are often referred to in the + * (E-)AC-3 specification as frequency bins. These bins are grouped together + * into subbands of 12 coefficients each. The subbands are grouped together + * into bands as defined in the bitstream by the band structures, which + * determine the number of bands and the size of each band. The full spectrum + * of 256 frequency bins is divided into 1 DC bin + 21 subbands = 253 bins. + * This system of grouping coefficients is used for channel bandwidth, stereo + * rematrixing, channel coupling, enhanced coupling, and spectral extension. + * + * +-+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+-+ + * |1| |12| | [12|12|12|12] | | | | | | | | | | | | |3| + * +-+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+-+ + * ~~~ ~~~~ ~~~~~~~~~~~~~ ~~~ + * | | | | + * | | | 3 unused frequency bins--+ + * | | | + * | | +--1 band containing 4 subbands + * | | + * | +--1 subband of 12 frequency bins + * | + * +--DC frequency bin */ #ifndef AVCODEC_AC3DEC_H @@ -31,6 +54,7 @@ #include "ac3.h" #include "get_bits.h" #include "dsputil.h" +#include "fft.h" /* override ac3.h to include coupling channel */ #undef AC3_MAX_CHANNELS @@ -42,6 +66,7 @@ #define AC3_MAX_COEFS 256 #define AC3_BLOCK_SIZE 256 #define MAX_BLOCKS 6 +#define SPX_MAX_BANDS 17 typedef struct { AVCodecContext *avctx; ///< parent context @@ -88,6 +113,22 @@ typedef struct { int cpl_coords[AC3_MAX_CHANNELS][18]; ///< coupling coordinates (cplco) ///@} +///@defgroup spx spectral extension +///@{ + int spx_in_use; ///< spectral extension in use (spxinu) + uint8_t channel_uses_spx[AC3_MAX_CHANNELS]; ///< channel uses spectral extension (chinspx) + int8_t spx_atten_code[AC3_MAX_CHANNELS]; ///< spx attenuation code (spxattencod) + int spx_src_start_freq; ///< spx start frequency bin + int spx_dst_end_freq; ///< spx end frequency bin + int spx_dst_start_freq; ///< spx starting frequency bin for copying (copystartmant) + ///< the copy region ends at the start of the spx region. + int num_spx_bands; ///< number of spx bands (nspxbnds) + uint8_t spx_band_sizes[SPX_MAX_BANDS]; ///< number of bins in each spx band + uint8_t first_spx_coords[AC3_MAX_CHANNELS]; ///< first spx coordinates states (firstspxcos) + float spx_noise_blend[AC3_MAX_CHANNELS][SPX_MAX_BANDS]; ///< spx noise blending factor (nblendfact) + float spx_signal_blend[AC3_MAX_CHANNELS][SPX_MAX_BANDS];///< spx signal blending factor (sblendfact) +///@} + ///@defgroup aht adaptive hybrid transform int channel_uses_aht[AC3_MAX_CHANNELS]; ///< channel AHT in use (chahtinu) int pre_mantissa[AC3_MAX_CHANNELS][AC3_MAX_COEFS][MAX_BLOCKS]; ///< pre-IDCT mantissas @@ -146,8 +187,8 @@ typedef struct { ///@defgroup imdct IMDCT int block_switch[AC3_MAX_CHANNELS]; ///< block switch flags (blksw) - MDCTContext imdct_512; ///< for 512 sample IMDCT - MDCTContext imdct_256; ///< for 256 sample IMDCT + FFTContext imdct_512; ///< for 512 sample IMDCT + FFTContext imdct_256; ///< for 256 sample IMDCT ///@} ///@defgroup opt optimization @@ -157,12 +198,12 @@ typedef struct { ///@} ///@defgroup arrays aligned arrays - DECLARE_ALIGNED_16(int, fixed_coeffs[AC3_MAX_CHANNELS][AC3_MAX_COEFS]); ///> fixed-point transform coefficients - DECLARE_ALIGNED_16(float, transform_coeffs[AC3_MAX_CHANNELS][AC3_MAX_COEFS]); ///< transform coefficients - DECLARE_ALIGNED_16(float, delay[AC3_MAX_CHANNELS][AC3_BLOCK_SIZE]); ///< delay - added to the next block - DECLARE_ALIGNED_16(float, window[AC3_BLOCK_SIZE]); ///< window coefficients - DECLARE_ALIGNED_16(float, tmp_output[AC3_BLOCK_SIZE]); ///< temporary storage for output before windowing - DECLARE_ALIGNED_16(float, output[AC3_MAX_CHANNELS][AC3_BLOCK_SIZE]); ///< output after imdct transform and windowing + DECLARE_ALIGNED(16, int, fixed_coeffs)[AC3_MAX_CHANNELS][AC3_MAX_COEFS]; ///> fixed-point transform coefficients + DECLARE_ALIGNED(16, float, transform_coeffs)[AC3_MAX_CHANNELS][AC3_MAX_COEFS]; ///< transform coefficients + DECLARE_ALIGNED(16, float, delay)[AC3_MAX_CHANNELS][AC3_BLOCK_SIZE]; ///< delay - added to the next block + DECLARE_ALIGNED(16, float, window)[AC3_BLOCK_SIZE]; ///< window coefficients + DECLARE_ALIGNED(16, float, tmp_output)[AC3_BLOCK_SIZE]; ///< temporary storage for output before windowing + DECLARE_ALIGNED(16, float, output)[AC3_MAX_CHANNELS][AC3_BLOCK_SIZE]; ///< output after imdct transform and windowing ///@} } AC3DecodeContext; @@ -178,4 +219,14 @@ int ff_eac3_parse_header(AC3DecodeContext *s); */ void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch); +void ff_ac3_downmix_c(float (*samples)[256], float (*matrix)[2], + int out_ch, int in_ch, int len); + +/** + * Apply spectral extension to each channel by copying lower frequency + * coefficients to higher frequency bins and applying side information to + * approximate the original high frequency signal. + */ +void ff_eac3_apply_spectral_extension(AC3DecodeContext *s); + #endif /* AVCODEC_AC3DEC_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ac3dec_data.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/ac3dec_data.c index 907a3aed80..ea13d3de51 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/ac3dec_data.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ac3dec_data.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/ac3dec_data.c + * @file * Tables taken directly from the AC-3 spec. */ @@ -64,3 +64,9 @@ const uint8_t ff_eac3_hebap_tab[64] = { */ const uint8_t ff_eac3_default_cpl_band_struct[18] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1 }; + +/** + * Table E2.15 Default Spectral Extension Banding Structure + */ +const uint8_t ff_eac3_default_spx_band_struct[17] = +{ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ac3dec_data.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/ac3dec_data.h index 8d9db0518d..9ed7c73188 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/ac3dec_data.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ac3dec_data.h @@ -29,5 +29,6 @@ extern const uint8_t ff_ac3_rematrix_band_tab[5]; extern const uint8_t ff_eac3_hebap_tab[64]; extern const uint8_t ff_eac3_default_cpl_band_struct[18]; +extern const uint8_t ff_eac3_default_spx_band_struct[17]; #endif /* AVCODEC_AC3DEC_DATA_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ac3enc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/ac3enc.c index 5384fdc4c9..e30e1bdbb9 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/ac3enc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ac3enc.c @@ -20,14 +20,14 @@ */ /** - * @file libavcodec/ac3enc.c + * @file * The simplest AC-3 encoder. */ //#define DEBUG //#define DEBUG_BITALLOC #include "libavutil/crc.h" #include "avcodec.h" -#include "get_bits.h" // for ff_reverse +#include "libavutil/common.h" /* for av_reverse */ #include "put_bits.h" #include "ac3.h" #include "audioconvert.h" @@ -138,7 +138,7 @@ static void fft(IComplex *z, int ln) /* reverse */ for(j=0;j> (8 - ln); + int k = av_reverse[j] >> (8 - ln); if (k < j) FFSWAP(IComplex, z[k], z[j]); } @@ -1393,16 +1393,16 @@ void test_ac3(void) AVCodec ac3_encoder = { "ac3", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_AC3, sizeof(AC3EncodeContext), AC3_encode_init, AC3_encode_frame, AC3_encode_close, NULL, - .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, + .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"), - .channel_layouts = (int64_t[]){ + .channel_layouts = (const int64_t[]){ CH_LAYOUT_MONO, CH_LAYOUT_STEREO, CH_LAYOUT_2_1, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ac3tab.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/ac3tab.c index ba7b204b21..4f28fb3d39 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/ac3tab.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ac3tab.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/ac3tab.c + * @file * tables taken directly from the AC-3 spec. */ @@ -108,7 +108,7 @@ const uint16_t ff_ac3_channel_layout_tab[8] = { */ const uint8_t ff_ac3_enc_channel_map[8][2][6] = { COMMON_CHANNEL_MAP - { { 0, 1, 2, 3, 4, }, { 0, 1, 3, 4, 2, } }, + { { 0, 1, 2, 3, }, { 0, 1, 3, 4, 2, } }, { { 0, 2, 1, 3, 4, }, { 0, 2, 1, 4, 5, 3 } }, }; @@ -118,7 +118,7 @@ const uint8_t ff_ac3_enc_channel_map[8][2][6] = { */ const uint8_t ff_ac3_dec_channel_map[8][2][6] = { COMMON_CHANNEL_MAP - { { 0, 1, 2, 3, 4, }, { 0, 1, 4, 2, 3, } }, + { { 0, 1, 2, 3, }, { 0, 1, 4, 2, 3, } }, { { 0, 2, 1, 3, 4, }, { 0, 2, 1, 5, 3, 4 } }, }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/acelp_filters.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/acelp_filters.c index 2db69d595d..31f0e86f5b 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/acelp_filters.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/acelp_filters.c @@ -45,7 +45,7 @@ void ff_acelp_interpolate(int16_t* out, const int16_t* in, { int n, i; - assert(pitch_delay_frac >= 0 && pitch_delay_frac < precision); + assert(frac_pos >= 0 && frac_pos < precision); for (n = 0; n < length; n++) { int idx = 0; @@ -73,6 +73,26 @@ void ff_acelp_interpolate(int16_t* out, const int16_t* in, } } +void ff_acelp_interpolatef(float *out, const float *in, + const float *filter_coeffs, int precision, + int frac_pos, int filter_length, int length) +{ + int n, i; + + for (n = 0; n < length; n++) { + int idx = 0; + float v = 0; + + for (i = 0; i < filter_length;) { + v += in[n + i] * filter_coeffs[idx + frac_pos]; + idx += precision; + i++; + v += in[n - i] * filter_coeffs[idx - frac_pos]; + } + out[n] = v; + } +} + void ff_acelp_high_pass_filter(int16_t* out, int hpf_f[2], const int16_t* in, int length) @@ -94,7 +114,7 @@ void ff_acelp_high_pass_filter(int16_t* out, int hpf_f[2], } } -void ff_acelp_apply_order_2_transfer_function(float *buf, +void ff_acelp_apply_order_2_transfer_function(float *out, const float *in, const float zero_coeffs[2], const float pole_coeffs[2], float gain, float mem[2], int n) @@ -103,10 +123,23 @@ void ff_acelp_apply_order_2_transfer_function(float *buf, float tmp; for (i = 0; i < n; i++) { - tmp = gain * buf[i] - pole_coeffs[0] * mem[0] - pole_coeffs[1] * mem[1]; - buf[i] = tmp + zero_coeffs[0] * mem[0] + zero_coeffs[1] * mem[1]; + tmp = gain * in[i] - pole_coeffs[0] * mem[0] - pole_coeffs[1] * mem[1]; + out[i] = tmp + zero_coeffs[0] * mem[0] + zero_coeffs[1] * mem[1]; mem[1] = mem[0]; mem[0] = tmp; } } + +void ff_tilt_compensation(float *mem, float tilt, float *samples, int size) +{ + float new_tilt_mem = samples[size - 1]; + int i; + + for (i = size - 1; i > 0; i--) + samples[i] -= tilt * samples[i - 1]; + + samples[0] -= tilt * *mem; + *mem = new_tilt_mem; +} + diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/acelp_filters.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/acelp_filters.h index 2cbe9bb17d..09b5da45be 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/acelp_filters.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/acelp_filters.h @@ -55,6 +55,14 @@ void ff_acelp_interpolate(int16_t* out, const int16_t* in, const int16_t* filter_coeffs, int precision, int frac_pos, int filter_length, int length); +/** + * Floating point version of ff_acelp_interpolate() + */ +void ff_acelp_interpolatef(float *out, const float *in, + const float *filter_coeffs, int precision, + int frac_pos, int filter_length, int length); + + /** * high-pass filtering and upscaling (4.2.5 of G.729). * @param out [out] output buffer for filtered speech data @@ -84,17 +92,29 @@ void ff_acelp_high_pass_filter(int16_t* out, int hpf_f[2], /** * Apply an order 2 rational transfer function in-place. * - * @param samples [in/out] + * @param out output buffer for filtered speech samples + * @param in input buffer containing speech data (may be the same as out) * @param zero_coeffs z^-1 and z^-2 coefficients of the numerator * @param pole_coeffs z^-1 and z^-2 coefficients of the denominator * @param gain scale factor for final output * @param mem intermediate values used by filter (should be 0 initially) * @param n number of samples */ -void ff_acelp_apply_order_2_transfer_function(float *samples, +void ff_acelp_apply_order_2_transfer_function(float *out, const float *in, const float zero_coeffs[2], const float pole_coeffs[2], float gain, float mem[2], int n); +/** + * Apply tilt compensation filter, 1 - tilt * z-1. + * + * @param mem pointer to the filter's state (one single float) + * @param tilt tilt factor + * @param samples array where the filter is applied + * @param size the size of the samples array + */ +void ff_tilt_compensation(float *mem, float tilt, float *samples, int size); + + #endif /* AVCODEC_ACELP_FILTERS_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/acelp_pitch_delay.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/acelp_pitch_delay.c index ac929c4689..cddf7262b6 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/acelp_pitch_delay.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/acelp_pitch_delay.c @@ -119,3 +119,68 @@ int16_t ff_acelp_decode_gain_code( return mr_energy >> 12; #endif } + +float ff_amr_set_fixed_gain(float fixed_gain_factor, float fixed_mean_energy, + float *prediction_error, float energy_mean, + const float *pred_table) +{ + // Equations 66-69: + // ^g_c = ^gamma_gc * 100.05 (predicted dB + mean dB - dB of fixed vector) + // Note 10^(0.05 * -10log(average x2)) = 1/sqrt((average x2)). + float val = fixed_gain_factor * + exp2f(M_LOG2_10 * 0.05 * + (ff_dot_productf(pred_table, prediction_error, 4) + + energy_mean)) / + sqrtf(fixed_mean_energy); + + // update quantified prediction error energy history + memmove(&prediction_error[0], &prediction_error[1], + 3 * sizeof(prediction_error[0])); + prediction_error[3] = 20.0 * log10f(fixed_gain_factor); + + return val; +} + +void ff_decode_pitch_lag(int *lag_int, int *lag_frac, int pitch_index, + const int prev_lag_int, const int subframe, + int third_as_first, int resolution) +{ + /* Note n * 10923 >> 15 is floor(x/3) for 0 <= n <= 32767 */ + if (subframe == 0 || (subframe == 2 && third_as_first)) { + + if (pitch_index < 197) + pitch_index += 59; + else + pitch_index = 3 * pitch_index - 335; + + } else { + if (resolution == 4) { + int search_range_min = av_clip(prev_lag_int - 5, PITCH_DELAY_MIN, + PITCH_DELAY_MAX - 9); + + // decoding with 4-bit resolution + if (pitch_index < 4) { + // integer only precision for [search_range_min, search_range_min+3] + pitch_index = 3 * (pitch_index + search_range_min) + 1; + } else if (pitch_index < 12) { + // 1/3 fractional precision for [search_range_min+3 1/3, search_range_min+5 2/3] + pitch_index += 3 * search_range_min + 7; + } else { + // integer only precision for [search_range_min+6, search_range_min+9] + pitch_index = 3 * (pitch_index + search_range_min - 6) + 1; + } + } else { + // decoding with 5 or 6 bit resolution, 1/3 fractional precision + pitch_index--; + + if (resolution == 5) { + pitch_index += 3 * av_clip(prev_lag_int - 10, PITCH_DELAY_MIN, + PITCH_DELAY_MAX - 19); + } else + pitch_index += 3 * av_clip(prev_lag_int - 5, PITCH_DELAY_MIN, + PITCH_DELAY_MAX - 9); + } + } + *lag_int = pitch_index * 10923 >> 15; + *lag_frac = pitch_index - 3 * *lag_int - 1; +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/acelp_pitch_delay.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/acelp_pitch_delay.h index 2504a9e3dd..2413145beb 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/acelp_pitch_delay.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/acelp_pitch_delay.h @@ -220,4 +220,36 @@ int16_t ff_acelp_decode_gain_code( int subframe_size, int max_pred_order); +/** + * Calculate fixed gain (part of section 6.1.3 of AMR spec) + * + * @param fixed_gain_factor gain correction factor + * @param fixed_energy decoded algebraic codebook vector energy + * @param prediction_error vector of the quantified predictor errors of + * the four previous subframes. It is updated by this function. + * @param energy_mean desired mean innovation energy + * @param pred_table table of four moving average coefficients + */ +float ff_amr_set_fixed_gain(float fixed_gain_factor, float fixed_mean_energy, + float *prediction_error, float energy_mean, + const float *pred_table); + + +/** + * Decode the adaptive codebook index to the integer and fractional parts + * of the pitch lag for one subframe at 1/3 fractional precision. + * + * The choice of pitch lag is described in 3GPP TS 26.090 section 5.6.1. + * + * @param lag_int integer part of pitch lag of the current subframe + * @param lag_frac fractional part of pitch lag of the current subframe + * @param pitch_index parsed adaptive codebook (pitch) index + * @param prev_lag_int integer part of pitch lag for the previous subframe + * @param subframe current subframe number + * @param third_as_first treat the third frame the same way as the first + */ +void ff_decode_pitch_lag(int *lag_int, int *lag_frac, int pitch_index, + const int prev_lag_int, const int subframe, + int third_as_first, int resolution); + #endif /* AVCODEC_ACELP_PITCH_DELAY_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/acelp_vectors.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/acelp_vectors.c index 5443006718..e41e5facb6 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/acelp_vectors.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/acelp_vectors.c @@ -23,6 +23,7 @@ #include #include "avcodec.h" #include "acelp_vectors.h" +#include "celp_math.h" const uint8_t ff_fc_2pulses_9bits_track1[16] = { @@ -102,6 +103,35 @@ static uint8_t gray_decode[32] = }; #endif +const float ff_pow_0_7[10] = { + 0.700000, 0.490000, 0.343000, 0.240100, 0.168070, + 0.117649, 0.082354, 0.057648, 0.040354, 0.028248 +}; + +const float ff_pow_0_75[10] = { + 0.750000, 0.562500, 0.421875, 0.316406, 0.237305, + 0.177979, 0.133484, 0.100113, 0.075085, 0.056314 +}; + +const float ff_pow_0_55[10] = { + 0.550000, 0.302500, 0.166375, 0.091506, 0.050328, + 0.027681, 0.015224, 0.008373, 0.004605, 0.002533 +}; + +const float ff_b60_sinc[61] = { + 0.898529 , 0.865051 , 0.769257 , 0.624054 , 0.448639 , 0.265289 , + 0.0959167 , -0.0412598 , -0.134338 , -0.178986 , -0.178528 , -0.142609 , +-0.0849304 , -0.0205078 , 0.0369568 , 0.0773926 , 0.0955200 , 0.0912781 , + 0.0689392 , 0.0357056 , 0. , -0.0305481 , -0.0504150 , -0.0570068 , +-0.0508423 , -0.0350037 , -0.0141602 , 0.00665283, 0.0230713 , 0.0323486 , + 0.0335388 , 0.0275879 , 0.0167847 , 0.00411987, -0.00747681, -0.0156860 , +-0.0193481 , -0.0183716 , -0.0137634 , -0.00704956, 0. , 0.00582886 , + 0.00939941, 0.0103760 , 0.00903320, 0.00604248, 0.00238037, -0.00109863 , +-0.00366211, -0.00497437, -0.00503540, -0.00402832, -0.00241089, -0.000579834, + 0.00103760, 0.00222778, 0.00277710, 0.00271606, 0.00213623, 0.00115967 , + 0. +}; + void ff_acelp_fc_pulse_per_track( int16_t* fc_v, const uint8_t *tab1, @@ -126,6 +156,27 @@ void ff_acelp_fc_pulse_per_track( fc_v[tab2[pulse_indexes]] += (pulse_signs & 1) ? 8191 : -8192; } +void ff_decode_10_pulses_35bits(const int16_t *fixed_index, + AMRFixed *fixed_sparse, + const uint8_t *gray_decode, + int half_pulse_count, int bits) +{ + int i; + int mask = (1 << bits) - 1; + + fixed_sparse->no_repeat_mask = 0; + fixed_sparse->n = 2 * half_pulse_count; + for (i = 0; i < half_pulse_count; i++) { + const int pos1 = gray_decode[fixed_index[2*i+1] & mask] + i; + const int pos2 = gray_decode[fixed_index[2*i ] & mask] + i; + const float sign = (fixed_index[2*i+1] & (1 << bits)) ? -1.0 : 1.0; + fixed_sparse->x[2*i+1] = pos1; + fixed_sparse->x[2*i ] = pos2; + fixed_sparse->y[2*i+1] = sign; + fixed_sparse->y[2*i ] = pos2 < pos1 ? -sign : sign; + } +} + void ff_acelp_weighted_vector_sum( int16_t* out, const int16_t *in_a, @@ -155,3 +206,65 @@ void ff_weighted_vector_sumf(float *out, const float *in_a, const float *in_b, out[i] = weight_coeff_a * in_a[i] + weight_coeff_b * in_b[i]; } + +void ff_adaptive_gain_control(float *out, const float *in, float speech_energ, + int size, float alpha, float *gain_mem) +{ + int i; + float postfilter_energ = ff_dot_productf(in, in, size); + float gain_scale_factor = 1.0; + float mem = *gain_mem; + + if (postfilter_energ) + gain_scale_factor = sqrt(speech_energ / postfilter_energ); + + gain_scale_factor *= 1.0 - alpha; + + for (i = 0; i < size; i++) { + mem = alpha * mem + gain_scale_factor; + out[i] = in[i] * mem; + } + + *gain_mem = mem; +} + +void ff_scale_vector_to_given_sum_of_squares(float *out, const float *in, + float sum_of_squares, const int n) +{ + int i; + float scalefactor = ff_dot_productf(in, in, n); + if (scalefactor) + scalefactor = sqrt(sum_of_squares / scalefactor); + for (i = 0; i < n; i++) + out[i] = in[i] * scalefactor; +} + +void ff_set_fixed_vector(float *out, const AMRFixed *in, float scale, int size) +{ + int i; + + for (i=0; i < in->n; i++) { + int x = in->x[i], repeats = !((in->no_repeat_mask >> i) & 1); + float y = in->y[i] * scale; + + do { + out[x] += y; + y *= in->pitch_fac; + x += in->pitch_lag; + } while (x < size && repeats); + } +} + +void ff_clear_fixed_vector(float *out, const AMRFixed *in, int size) +{ + int i; + + for (i=0; i < in->n; i++) { + int x = in->x[i], repeats = !((in->no_repeat_mask >> i) & 1); + + do { + out[x] = 0.0; + x += in->pitch_lag; + } while (x < size && repeats); + } +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/acelp_vectors.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/acelp_vectors.h index 3a47a7b61c..ba3437fc10 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/acelp_vectors.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/acelp_vectors.h @@ -25,6 +25,16 @@ #include +/** Sparse representation for the algebraic codebook (fixed) vector */ +typedef struct { + int n; + int x[10]; + float y[10]; + int no_repeat_mask; + int pitch_lag; + float pitch_fac; +} AMRFixed; + /** * Track|Pulse| Positions * ------------------------------------------------------------------------- @@ -102,6 +112,26 @@ extern const uint8_t ff_fc_2pulses_9bits_track1_gray[16]; */ extern const uint8_t ff_fc_2pulses_9bits_track2_gray[32]; +/** + * b60 hamming windowed sinc function coefficients + */ +extern const float ff_b60_sinc[61]; + +/** + * Table of pow(0.7,n) + */ +extern const float ff_pow_0_7[10]; + +/** + * Table of pow(0.75,n) + */ +extern const float ff_pow_0_75[10]; + +/** + * Table of pow(0.55,n) + */ +extern const float ff_pow_0_55[10]; + /** * Decode fixed-codebook vector (3.8 and D.5.8 of G.729, 5.7.1 of AMR). * @param fc_v [out] decoded fixed codebook vector (2.13) @@ -116,14 +146,31 @@ extern const uint8_t ff_fc_2pulses_9bits_track2_gray[32]; * * Used in G.729 @8k, G.729 @4.4k, G.729 @6.4k, AMR @7.95k, AMR @7.40k */ -void ff_acelp_fc_pulse_per_track( - int16_t* fc_v, - const uint8_t *tab1, - const uint8_t *tab2, - int pulse_indexes, - int pulse_signs, - int pulse_count, - int bits); +void ff_acelp_fc_pulse_per_track(int16_t* fc_v, + const uint8_t *tab1, + const uint8_t *tab2, + int pulse_indexes, + int pulse_signs, + int pulse_count, + int bits); + +/** + * Decode the algebraic codebook index to pulse positions and signs and + * construct the algebraic codebook vector for MODE_12k2. + * + * @note: The positions and signs are explicitly coded in MODE_12k2. + * + * @param fixed_index positions of the ten pulses + * @param fixed_sparse pointer to the algebraic codebook vector + * @param gray_decode gray decoding table + * @param half_pulse_count number of couples of pulses + * @param bits length of one pulse index in bits + */ +void ff_decode_10_pulses_35bits(const int16_t *fixed_index, + AMRFixed *fixed_sparse, + const uint8_t *gray_decode, + int half_pulse_count, int bits); + /** * weighted sum of two vectors with rounding. @@ -140,15 +187,14 @@ void ff_acelp_fc_pulse_per_track( * * out[i] = (in_a[i]*weight_a + in_b[i]*weight_b + rounder) >> shift */ -void ff_acelp_weighted_vector_sum( - int16_t* out, - const int16_t *in_a, - const int16_t *in_b, - int16_t weight_coeff_a, - int16_t weight_coeff_b, - int16_t rounder, - int shift, - int length); +void ff_acelp_weighted_vector_sum(int16_t* out, + const int16_t *in_a, + const int16_t *in_b, + int16_t weight_coeff_a, + int16_t weight_coeff_b, + int16_t rounder, + int shift, + int length); /** * float implementation of weighted sum of two vectors. @@ -162,6 +208,57 @@ void ff_acelp_weighted_vector_sum( * @note It is safe to pass the same buffer for out and in_a or in_b. */ void ff_weighted_vector_sumf(float *out, const float *in_a, const float *in_b, - float weight_coeff_a, float weight_coeff_b, int length); + float weight_coeff_a, float weight_coeff_b, + int length); + +/** + * Adaptive gain control (as used in AMR postfiltering) + * + * @param out output buffer for filtered speech data + * @param in the input speech buffer (may be the same as out) + * @param speech_energ input energy + * @param size the input buffer size + * @param alpha exponential filter factor + * @param gain_mem a pointer to the filter memory (single float of size) + */ +void ff_adaptive_gain_control(float *out, const float *in, float speech_energ, + int size, float alpha, float *gain_mem); + +/** + * Set the sum of squares of a signal by scaling + * + * @param out output samples + * @param in input samples + * @param sum_of_squares new sum of squares + * @param n number of samples + * + * @note If the input is zero (or its energy underflows), the output is zero. + * This is the behavior of AGC in the AMR reference decoder. The QCELP + * reference decoder seems to have undefined behavior. + * + * TIA/EIA/IS-733 2.4.8.3-2/3/4/5, 2.4.8.6 + * 3GPP TS 26.090 6.1 (6) + */ +void ff_scale_vector_to_given_sum_of_squares(float *out, const float *in, + float sum_of_squares, const int n); + +/** + * Add fixed vector to an array from a sparse representation + * + * @param out fixed vector with pitch sharpening + * @param in sparse fixed vector + * @param scale number to multiply the fixed vector by + * @param size the output vector size + */ +void ff_set_fixed_vector(float *out, const AMRFixed *in, float scale, int size); + +/** + * Clear array values set by set_fixed_vector + * + * @param out fixed vector to be cleared + * @param in sparse fixed vector + * @param size the output vector size + */ +void ff_clear_fixed_vector(float *out, const AMRFixed *in, int size); #endif /* AVCODEC_ACELP_VECTORS_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/adpcm.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/adpcm.c index d8908d34d2..68bd656aa6 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/adpcm.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/adpcm.c @@ -24,7 +24,7 @@ #include "bytestream.h" /** - * @file libavcodec/adpcm.c + * @file * ADPCM codecs. * First version by Francois Revol (revol@free.fr) * Fringe ADPCM codecs (e.g., DK3, DK4, Westwood) @@ -86,10 +86,12 @@ static const int AdaptationTable[] = { 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 }; @@ -152,6 +154,8 @@ typedef struct ADPCMContext { #if CONFIG_ENCODERS static av_cold int adpcm_encode_init(AVCodecContext *avctx) { + uint8_t *extradata; + int i; if (avctx->channels > 2) return -1; /* only stereo or mono =) */ @@ -175,6 +179,16 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) 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; @@ -1624,14 +1638,14 @@ static int adpcm_decode_frame(AVCodecContext *avctx, #define ADPCM_ENCODER(id,name,long_name_) \ AVCodec name ## _encoder = { \ #name, \ - CODEC_TYPE_AUDIO, \ + AVMEDIA_TYPE_AUDIO, \ id, \ sizeof(ADPCMContext), \ adpcm_encode_init, \ adpcm_encode_frame, \ adpcm_encode_close, \ NULL, \ - .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, \ + .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, \ .long_name = NULL_IF_CONFIG_SMALL(long_name_), \ }; #else @@ -1642,7 +1656,7 @@ AVCodec name ## _encoder = { \ #define ADPCM_DECODER(id,name,long_name_) \ AVCodec name ## _decoder = { \ #name, \ - CODEC_TYPE_AUDIO, \ + AVMEDIA_TYPE_AUDIO, \ id, \ sizeof(ADPCMContext), \ adpcm_decode_init, \ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/adx.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/adx.h index cb6e6020dd..0fa1003ffc 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/adx.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/adx.h @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/adx.h + * @file * SEGA CRI adx codecs. * * Reference documents: diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/adxdec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/adxdec.c index 94ee793cfa..adb22fcfe5 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/adxdec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/adxdec.c @@ -24,7 +24,7 @@ #include "adx.h" /** - * @file libavcodec/adxdec.c + * @file * SEGA CRI adx codecs. * * Reference documents: @@ -168,7 +168,7 @@ static int adx_decode_frame(AVCodecContext *avctx, AVCodec adpcm_adx_decoder = { "adpcm_adx", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_ADPCM_ADX, sizeof(ADXContext), adx_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/adxenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/adxenc.c index 7c5a95d564..116b746ed0 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/adxenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/adxenc.c @@ -24,7 +24,7 @@ #include "adx.h" /** - * @file libavcodec/adxenc.c + * @file * SEGA CRI adx codecs. * * Reference documents: @@ -185,13 +185,13 @@ static int adx_encode_frame(AVCodecContext *avctx, AVCodec adpcm_adx_encoder = { "adpcm_adx", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_ADPCM_ADX, sizeof(ADXContext), adx_encode_init, adx_encode_frame, adx_encode_close, NULL, - .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, + .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, .long_name = NULL_IF_CONFIG_SMALL("SEGA CRI ADX ADPCM"), }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/alac.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/alac.c index 5c48a4b28f..50fc7a1a3f 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/alac.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/alac.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/alac.c + * @file * ALAC (Apple Lossless Audio Codec) decoder * @author 2005 David Hammerton * @@ -77,6 +77,8 @@ typedef struct { int32_t *outputsamples_buffer[MAX_CHANNELS]; + int32_t *wasted_bits_buffer[MAX_CHANNELS]; + /* stuff from setinfo */ uint32_t setinfo_max_samples_per_frame; /* 0x1000 = 4096 */ /* max samples per frame? */ uint8_t setinfo_sample_size; /* 0x10 */ @@ -85,6 +87,7 @@ typedef struct { uint8_t setinfo_rice_kmodifier; /* 0x0e */ /* end setinfo stuff */ + int wasted_bits; } ALACContext; static void allocate_buffers(ALACContext *alac) @@ -96,6 +99,8 @@ static void allocate_buffers(ALACContext *alac) alac->outputsamples_buffer[chan] = av_malloc(alac->setinfo_max_samples_per_frame * 4); + + alac->wasted_bits_buffer[chan] = av_malloc(alac->setinfo_max_samples_per_frame * 4); } } @@ -398,6 +403,56 @@ static void reconstruct_stereo_16(int32_t *buffer[MAX_CHANNELS], } } +static void decorrelate_stereo_24(int32_t *buffer[MAX_CHANNELS], + int32_t *buffer_out, + int32_t *wasted_bits_buffer[MAX_CHANNELS], + int wasted_bits, + int numchannels, int numsamples, + uint8_t interlacing_shift, + uint8_t interlacing_leftweight) +{ + int i; + + if (numsamples <= 0) + return; + + /* weighted interlacing */ + if (interlacing_leftweight) { + for (i = 0; i < numsamples; i++) { + int32_t a, b; + + a = buffer[0][i]; + b = buffer[1][i]; + + a -= (b * interlacing_leftweight) >> interlacing_shift; + b += a; + + if (wasted_bits) { + b = (b << wasted_bits) | wasted_bits_buffer[0][i]; + a = (a << wasted_bits) | wasted_bits_buffer[1][i]; + } + + buffer_out[i * numchannels] = b << 8; + buffer_out[i * numchannels + 1] = a << 8; + } + } else { + for (i = 0; i < numsamples; i++) { + int32_t left, right; + + left = buffer[0][i]; + right = buffer[1][i]; + + if (wasted_bits) { + left = (left << wasted_bits) | wasted_bits_buffer[0][i]; + right = (right << wasted_bits) | wasted_bits_buffer[1][i]; + } + + buffer_out[i * numchannels] = left << 8; + buffer_out[i * numchannels + 1] = right << 8; + } + } +} + static int alac_decode_frame(AVCodecContext *avctx, void *outbuffer, int *outputsize, AVPacket *avpkt) @@ -410,7 +465,6 @@ static int alac_decode_frame(AVCodecContext *avctx, unsigned int outputsamples; int hassize; unsigned int readsamplesize; - int wasted_bytes; int isnotcompressed; uint8_t interlacing_shift; uint8_t interlacing_leftweight; @@ -452,7 +506,7 @@ static int alac_decode_frame(AVCodecContext *avctx, /* the output sample size is stored soon */ hassize = get_bits1(&alac->gb); - wasted_bytes = get_bits(&alac->gb, 2); /* unknown ? */ + alac->wasted_bits = get_bits(&alac->gb, 2) << 3; /* whether the frame is compressed */ isnotcompressed = get_bits1(&alac->gb); @@ -467,13 +521,25 @@ static int alac_decode_frame(AVCodecContext *avctx, } else outputsamples = alac->setinfo_max_samples_per_frame; + switch (alac->setinfo_sample_size) { + case 16: avctx->sample_fmt = SAMPLE_FMT_S16; + alac->bytespersample = channels << 1; + break; + case 24: avctx->sample_fmt = SAMPLE_FMT_S32; + alac->bytespersample = channels << 2; + break; + default: av_log(avctx, AV_LOG_ERROR, "Sample depth %d is not supported.\n", + alac->setinfo_sample_size); + return -1; + } + if(outputsamples > *outputsize / alac->bytespersample){ av_log(avctx, AV_LOG_ERROR, "sample buffer too small\n"); return -1; } *outputsize = outputsamples * alac->bytespersample; - readsamplesize = alac->setinfo_sample_size - (wasted_bytes * 8) + channels - 1; + readsamplesize = alac->setinfo_sample_size - (alac->wasted_bits) + channels - 1; if (readsamplesize > MIN_CACHE_BITS) { av_log(avctx, AV_LOG_ERROR, "readsamplesize too big (%d)\n", readsamplesize); return -1; @@ -503,9 +569,13 @@ static int alac_decode_frame(AVCodecContext *avctx, predictor_coef_table[chan][i] = (int16_t)get_bits(&alac->gb, 16); } - if (wasted_bytes) - av_log(avctx, AV_LOG_ERROR, "FIXME: unimplemented, unhandling of wasted_bytes\n"); - + if (alac->wasted_bits) { + int i, ch; + for (i = 0; i < outputsamples; i++) { + for (ch = 0; ch < channels; ch++) + alac->wasted_bits_buffer[ch][i] = get_bits(&alac->gb, alac->wasted_bits); + } + } for (chan = 0; chan < channels; chan++) { bastardized_rice_decompress(alac, alac->predicterror_buffer[chan], @@ -538,6 +608,7 @@ static int alac_decode_frame(AVCodecContext *avctx, } else { /* not compressed, easy case */ int i, chan; + if (alac->setinfo_sample_size <= 16) { for (i = 0; i < outputsamples; i++) for (chan = 0; chan < channels; chan++) { int32_t audiobits; @@ -546,7 +617,17 @@ static int alac_decode_frame(AVCodecContext *avctx, alac->outputsamples_buffer[chan][i] = audiobits; } - /* wasted_bytes = 0; */ + } else { + for (i = 0; i < outputsamples; i++) { + for (chan = 0; chan < channels; chan++) { + alac->outputsamples_buffer[chan][i] = get_bits(&alac->gb, + alac->setinfo_sample_size); + alac->outputsamples_buffer[chan][i] = sign_extend(alac->outputsamples_buffer[chan][i], + alac->setinfo_sample_size); + } + } + } + alac->wasted_bits = 0; interlacing_shift = 0; interlacing_leftweight = 0; } @@ -565,19 +646,25 @@ static int alac_decode_frame(AVCodecContext *avctx, } else { int i; for (i = 0; i < outputsamples; i++) { - int16_t sample = alac->outputsamples_buffer[0][i]; - ((int16_t*)outbuffer)[i * alac->numchannels] = sample; + ((int16_t*)outbuffer)[i] = alac->outputsamples_buffer[0][i]; } } break; - case 20: case 24: - // It is not clear if there exist any encoder that creates 24 bit ALAC - // files. iTunes convert 24 bit raw files to 16 bit before encoding. - case 32: - av_log(avctx, AV_LOG_ERROR, "FIXME: unimplemented sample size %i\n", alac->setinfo_sample_size); - break; - default: + if (channels == 2) { + decorrelate_stereo_24(alac->outputsamples_buffer, + outbuffer, + alac->wasted_bits_buffer, + alac->wasted_bits, + alac->numchannels, + outputsamples, + interlacing_shift, + interlacing_leftweight); + } else { + int i; + for (i = 0; i < outputsamples; i++) + ((int32_t *)outbuffer)[i] = alac->outputsamples_buffer[0][i] << 8; + } break; } @@ -594,8 +681,6 @@ static av_cold int alac_decode_init(AVCodecContext * avctx) alac->context_initialized = 0; alac->numchannels = alac->avctx->channels; - alac->bytespersample = 2 * alac->numchannels; - avctx->sample_fmt = SAMPLE_FMT_S16; return 0; } @@ -606,8 +691,9 @@ static av_cold int alac_decode_close(AVCodecContext *avctx) int chan; for (chan = 0; chan < MAX_CHANNELS; chan++) { - av_free(alac->predicterror_buffer[chan]); - av_free(alac->outputsamples_buffer[chan]); + av_freep(&alac->predicterror_buffer[chan]); + av_freep(&alac->outputsamples_buffer[chan]); + av_freep(&alac->wasted_bits_buffer[chan]); } return 0; @@ -615,7 +701,7 @@ static av_cold int alac_decode_close(AVCodecContext *avctx) AVCodec alac_decoder = { "alac", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_ALAC, sizeof(ALACContext), alac_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/alacenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/alacenc.c index f8a18b9556..0876633cbd 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/alacenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/alacenc.c @@ -20,7 +20,6 @@ */ #include "avcodec.h" -#include "get_bits.h" #include "put_bits.h" #include "dsputil.h" #include "lpc.h" @@ -123,7 +122,7 @@ static void write_frame_header(AlacEncodeContext *s, int is_verbatim) put_bits(&s->pbctx, 1, 1); // Sample count is in the header put_bits(&s->pbctx, 2, 0); // FIXME: Wasted bytes field put_bits(&s->pbctx, 1, is_verbatim); // Audio block is verbatim - put_bits(&s->pbctx, 32, s->avctx->frame_size); // No. of samples in the frame + put_bits32(&s->pbctx, s->avctx->frame_size); // No. of samples in the frame } static void calc_predictor_params(AlacEncodeContext *s, int ch) @@ -132,12 +131,27 @@ static void calc_predictor_params(AlacEncodeContext *s, int ch) int shift[MAX_LPC_ORDER]; int opt_order; - opt_order = ff_lpc_calc_coefs(&s->dspctx, s->sample_buf[ch], s->avctx->frame_size, s->min_prediction_order, s->max_prediction_order, - ALAC_MAX_LPC_PRECISION, coefs, shift, 1, ORDER_METHOD_EST, ALAC_MAX_LPC_SHIFT, 1); + if (s->compression_level == 1) { + s->lpc[ch].lpc_order = 6; + s->lpc[ch].lpc_quant = 6; + s->lpc[ch].lpc_coeff[0] = 160; + s->lpc[ch].lpc_coeff[1] = -190; + s->lpc[ch].lpc_coeff[2] = 170; + s->lpc[ch].lpc_coeff[3] = -130; + s->lpc[ch].lpc_coeff[4] = 80; + s->lpc[ch].lpc_coeff[5] = -25; + } else { + opt_order = ff_lpc_calc_coefs(&s->dspctx, s->sample_buf[ch], + s->avctx->frame_size, + s->min_prediction_order, + s->max_prediction_order, + ALAC_MAX_LPC_PRECISION, coefs, shift, 1, + ORDER_METHOD_EST, ALAC_MAX_LPC_SHIFT, 1); - s->lpc[ch].lpc_order = opt_order; - s->lpc[ch].lpc_quant = shift[opt_order-1]; - memcpy(s->lpc[ch].lpc_coeff, coefs[opt_order-1], opt_order*sizeof(int)); + s->lpc[ch].lpc_order = opt_order; + s->lpc[ch].lpc_quant = shift[opt_order-1]; + memcpy(s->lpc[ch].lpc_coeff, coefs[opt_order-1], opt_order*sizeof(int)); + } } static int estimate_stereo_mode(int32_t *left_ch, int32_t *right_ch, int n) @@ -375,9 +389,9 @@ static av_cold int alac_encode_init(AVCodecContext *avctx) // Set default compression level if(avctx->compression_level == FF_COMPRESSION_DEFAULT) - s->compression_level = 1; + s->compression_level = 2; else - s->compression_level = av_clip(avctx->compression_level, 0, 1); + s->compression_level = av_clip(avctx->compression_level, 0, 2); // Initialize default Rice parameters s->rc.history_mult = 40; @@ -385,8 +399,7 @@ static av_cold int alac_encode_init(AVCodecContext *avctx) s->rc.k_modifier = 14; s->rc.rice_modifier = 4; - s->max_coded_frame_size = (ALAC_FRAME_HEADER_SIZE + ALAC_FRAME_FOOTER_SIZE + - avctx->frame_size*avctx->channels*avctx->bits_per_coded_sample)>>3; + s->max_coded_frame_size = 8 + (avctx->frame_size*avctx->channels*avctx->bits_per_coded_sample>>3); s->write_sample_size = avctx->bits_per_coded_sample + avctx->channels - 1; // FIXME: consider wasted_bytes @@ -507,12 +520,13 @@ static av_cold int alac_encode_close(AVCodecContext *avctx) AVCodec alac_encoder = { "alac", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_ALAC, sizeof(AlacEncodeContext), alac_encode_init, alac_encode_frame, alac_encode_close, .capabilities = CODEC_CAP_SMALL_LAST_FRAME, + .sample_fmts = (const enum SampleFormat[]){ SAMPLE_FMT_S16, SAMPLE_FMT_NONE}, .long_name = NULL_IF_CONFIG_SMALL("ALAC (Apple Lossless Audio Codec)"), }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/allcodecs.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/allcodecs.c index c289523a8f..aa3001c546 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/allcodecs.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/allcodecs.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/allcodecs.c + * @file * Provides registration of all codecs, parsers and bitstream filters for libavcodec. */ @@ -55,22 +55,31 @@ void avcodec_register_all(void) /* hardware accelerators */ REGISTER_HWACCEL (H263_VAAPI, h263_vaapi); + REGISTER_HWACCEL (H264_DXVA2, h264_dxva2); + REGISTER_HWACCEL (H264_VAAPI, h264_vaapi); REGISTER_HWACCEL (MPEG2_VAAPI, mpeg2_vaapi); REGISTER_HWACCEL (MPEG4_VAAPI, mpeg4_vaapi); + REGISTER_HWACCEL (VC1_DXVA2, vc1_dxva2); REGISTER_HWACCEL (VC1_VAAPI, vc1_vaapi); + REGISTER_HWACCEL (WMV3_DXVA2, wmv3_dxva2); REGISTER_HWACCEL (WMV3_VAAPI, wmv3_vaapi); /* video codecs */ REGISTER_DECODER (AASC, aasc); REGISTER_DECODER (AMV, amv); + REGISTER_DECODER (ANM, anm); REGISTER_ENCDEC (ASV1, asv1); REGISTER_ENCDEC (ASV2, asv2); + REGISTER_DECODER (AURA, aura); + REGISTER_DECODER (AURA2, aura2); REGISTER_DECODER (AVS, avs); REGISTER_DECODER (BETHSOFTVID, bethsoftvid); REGISTER_DECODER (BFI, bfi); + REGISTER_DECODER (BINK, bink); REGISTER_ENCDEC (BMP, bmp); REGISTER_DECODER (C93, c93); REGISTER_DECODER (CAVS, cavs); + REGISTER_DECODER (CDGRAPHICS, cdgraphics); REGISTER_DECODER (CINEPAK, cinepak); REGISTER_DECODER (CLJR, cljr); REGISTER_DECODER (CSCD, cscd); @@ -96,6 +105,7 @@ void avcodec_register_all(void) REGISTER_ENCDEC (FLV, flv); REGISTER_DECODER (FOURXM, fourxm); REGISTER_DECODER (FRAPS, fraps); + REGISTER_DECODER (FRWU, frwu); REGISTER_ENCDEC (GIF, gif); REGISTER_ENCDEC (H261, h261); REGISTER_ENCDEC (H263, h263); @@ -105,10 +115,14 @@ void avcodec_register_all(void) REGISTER_DECODER (H264_VDPAU, h264_vdpau); REGISTER_ENCDEC (HUFFYUV, huffyuv); REGISTER_DECODER (IDCIN, idcin); + REGISTER_DECODER (IFF_BYTERUN1, iff_byterun1); + REGISTER_DECODER (IFF_ILBM, iff_ilbm); REGISTER_DECODER (INDEO2, indeo2); REGISTER_DECODER (INDEO3, indeo3); + REGISTER_DECODER (INDEO5, indeo5); REGISTER_DECODER (INTERPLAY_VIDEO, interplay_video); REGISTER_ENCDEC (JPEGLS, jpegls); + REGISTER_DECODER (KGV1, kgv1); REGISTER_DECODER (KMVC, kmvc); REGISTER_ENCODER (LJPEG, ljpeg); REGISTER_DECODER (LOCO, loco); @@ -122,6 +136,7 @@ void avcodec_register_all(void) REGISTER_ENCDEC (MPEG1VIDEO, mpeg1video); REGISTER_ENCDEC (MPEG2VIDEO, mpeg2video); REGISTER_ENCDEC (MPEG4, mpeg4); + REGISTER_DECODER (MPEG4_VDPAU, mpeg4_vdpau); REGISTER_DECODER (MPEGVIDEO, mpegvideo); REGISTER_DECODER (MPEG_VDPAU, mpeg_vdpau); REGISTER_DECODER (MPEG1_VDPAU, mpeg1_vdpau); @@ -143,6 +158,7 @@ void avcodec_register_all(void) REGISTER_DECODER (QDRAW, qdraw); REGISTER_DECODER (QPEG, qpeg); REGISTER_ENCDEC (QTRLE, qtrle); + REGISTER_DECODER (R210, r210); REGISTER_ENCDEC (RAWVIDEO, rawvideo); REGISTER_DECODER (RL2, rl2); REGISTER_ENCDEC (ROQ, roq); @@ -191,6 +207,7 @@ void avcodec_register_all(void) REGISTER_DECODER (WNV1, wnv1); REGISTER_DECODER (XAN_WC3, xan_wc3); REGISTER_DECODER (XL, xl); + REGISTER_DECODER (YOP, yop); REGISTER_ENCDEC (ZLIB, zlib); REGISTER_ENCDEC (ZMBV, zmbv); @@ -198,8 +215,13 @@ void avcodec_register_all(void) REGISTER_ENCDEC (AAC, aac); REGISTER_ENCDEC (AC3, ac3); REGISTER_ENCDEC (ALAC, alac); + REGISTER_DECODER (ALS, als); + REGISTER_DECODER (AMRNB, amrnb); REGISTER_DECODER (APE, ape); + REGISTER_DECODER (ATRAC1, atrac1); REGISTER_DECODER (ATRAC3, atrac3); + REGISTER_DECODER (BINKAUDIO_DCT, binkaudio_dct); + REGISTER_DECODER (BINKAUDIO_RDFT, binkaudio_rdft); REGISTER_DECODER (COOK, cook); REGISTER_DECODER (DCA, dca); REGISTER_DECODER (DSICINAUDIO, dsicinaudio); @@ -222,21 +244,26 @@ void avcodec_register_all(void) REGISTER_DECODER (RA_144, ra_144); REGISTER_DECODER (RA_288, ra_288); 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); + REGISTER_DECODER (TWINVQ, twinvq); REGISTER_DECODER (VMDAUDIO, vmdaudio); - REGISTER_ENCDEC (VORBIS, vorbis); + REGISTER_DECODER (VORBIS, vorbis); REGISTER_DECODER (WAVPACK, wavpack); + REGISTER_DECODER (WMAPRO, wmapro); REGISTER_ENCDEC (WMAV1, wmav1); REGISTER_ENCDEC (WMAV2, wmav2); + REGISTER_DECODER (WMAVOICE, wmavoice); REGISTER_DECODER (WS_SND1, ws_snd1); /* PCM codecs */ REGISTER_ENCDEC (PCM_ALAW, pcm_alaw); + REGISTER_DECODER (PCM_BLURAY, pcm_bluray); REGISTER_DECODER (PCM_DVD, pcm_dvd); REGISTER_ENCDEC (PCM_F32BE, pcm_f32be); REGISTER_ENCDEC (PCM_F32LE, pcm_f32le); @@ -300,6 +327,7 @@ void avcodec_register_all(void) /* subtitles */ REGISTER_ENCDEC (DVBSUB, dvbsub); REGISTER_ENCDEC (DVDSUB, dvdsub); + REGISTER_DECODER (PGSSUB, pgssub); REGISTER_ENCDEC (XSUB, xsub); /* external libraries */ @@ -316,6 +344,7 @@ void avcodec_register_all(void) REGISTER_DECODER (LIBSPEEX, libspeex); REGISTER_ENCODER (LIBTHEORA, libtheora); REGISTER_ENCODER (LIBVORBIS, libvorbis); + REGISTER_ENCDEC (LIBVPX, libvpx); REGISTER_ENCODER (LIBX264, libx264); REGISTER_ENCODER (LIBXVID, libxvid); diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/alsdec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/alsdec.c new file mode 100644 index 0000000000..2058a85384 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/alsdec.c @@ -0,0 +1,1636 @@ +/* + * MPEG-4 ALS decoder + * Copyright (c) 2009 Thilo Borgmann + * + * 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 + * MPEG-4 ALS decoder + * @author Thilo Borgmann + */ + + +//#define DEBUG + + +#include "avcodec.h" +#include "get_bits.h" +#include "unary.h" +#include "mpeg4audio.h" +#include "bytestream.h" +#include "bgmc.h" + +#include + +/** Rice parameters and corresponding index offsets for decoding the + * indices of scaled PARCOR values. The table choosen is set globally + * by the encoder and stored in ALSSpecificConfig. + */ +static const int8_t parcor_rice_table[3][20][2] = { + { {-52, 4}, {-29, 5}, {-31, 4}, { 19, 4}, {-16, 4}, + { 12, 3}, { -7, 3}, { 9, 3}, { -5, 3}, { 6, 3}, + { -4, 3}, { 3, 3}, { -3, 2}, { 3, 2}, { -2, 2}, + { 3, 2}, { -1, 2}, { 2, 2}, { -1, 2}, { 2, 2} }, + { {-58, 3}, {-42, 4}, {-46, 4}, { 37, 5}, {-36, 4}, + { 29, 4}, {-29, 4}, { 25, 4}, {-23, 4}, { 20, 4}, + {-17, 4}, { 16, 4}, {-12, 4}, { 12, 3}, {-10, 4}, + { 7, 3}, { -4, 4}, { 3, 3}, { -1, 3}, { 1, 3} }, + { {-59, 3}, {-45, 5}, {-50, 4}, { 38, 4}, {-39, 4}, + { 32, 4}, {-30, 4}, { 25, 3}, {-23, 3}, { 20, 3}, + {-20, 3}, { 16, 3}, {-13, 3}, { 10, 3}, { -7, 3}, + { 3, 3}, { 0, 3}, { -1, 3}, { 2, 3}, { -1, 2} } +}; + + +/** Scaled PARCOR values used for the first two PARCOR coefficients. + * To be indexed by the Rice coded indices. + * Generated by: parcor_scaled_values[i] = 32 + ((i * (i+1)) << 7) - (1 << 20) + * Actual values are divided by 32 in order to be stored in 16 bits. + */ +static const int16_t parcor_scaled_values[] = { + -1048544 / 32, -1048288 / 32, -1047776 / 32, -1047008 / 32, + -1045984 / 32, -1044704 / 32, -1043168 / 32, -1041376 / 32, + -1039328 / 32, -1037024 / 32, -1034464 / 32, -1031648 / 32, + -1028576 / 32, -1025248 / 32, -1021664 / 32, -1017824 / 32, + -1013728 / 32, -1009376 / 32, -1004768 / 32, -999904 / 32, + -994784 / 32, -989408 / 32, -983776 / 32, -977888 / 32, + -971744 / 32, -965344 / 32, -958688 / 32, -951776 / 32, + -944608 / 32, -937184 / 32, -929504 / 32, -921568 / 32, + -913376 / 32, -904928 / 32, -896224 / 32, -887264 / 32, + -878048 / 32, -868576 / 32, -858848 / 32, -848864 / 32, + -838624 / 32, -828128 / 32, -817376 / 32, -806368 / 32, + -795104 / 32, -783584 / 32, -771808 / 32, -759776 / 32, + -747488 / 32, -734944 / 32, -722144 / 32, -709088 / 32, + -695776 / 32, -682208 / 32, -668384 / 32, -654304 / 32, + -639968 / 32, -625376 / 32, -610528 / 32, -595424 / 32, + -580064 / 32, -564448 / 32, -548576 / 32, -532448 / 32, + -516064 / 32, -499424 / 32, -482528 / 32, -465376 / 32, + -447968 / 32, -430304 / 32, -412384 / 32, -394208 / 32, + -375776 / 32, -357088 / 32, -338144 / 32, -318944 / 32, + -299488 / 32, -279776 / 32, -259808 / 32, -239584 / 32, + -219104 / 32, -198368 / 32, -177376 / 32, -156128 / 32, + -134624 / 32, -112864 / 32, -90848 / 32, -68576 / 32, + -46048 / 32, -23264 / 32, -224 / 32, 23072 / 32, + 46624 / 32, 70432 / 32, 94496 / 32, 118816 / 32, + 143392 / 32, 168224 / 32, 193312 / 32, 218656 / 32, + 244256 / 32, 270112 / 32, 296224 / 32, 322592 / 32, + 349216 / 32, 376096 / 32, 403232 / 32, 430624 / 32, + 458272 / 32, 486176 / 32, 514336 / 32, 542752 / 32, + 571424 / 32, 600352 / 32, 629536 / 32, 658976 / 32, + 688672 / 32, 718624 / 32, 748832 / 32, 779296 / 32, + 810016 / 32, 840992 / 32, 872224 / 32, 903712 / 32, + 935456 / 32, 967456 / 32, 999712 / 32, 1032224 / 32 +}; + + +/** Gain values of p(0) for long-term prediction. + * To be indexed by the Rice coded indices. + */ +static const uint8_t ltp_gain_values [4][4] = { + { 0, 8, 16, 24}, + {32, 40, 48, 56}, + {64, 70, 76, 82}, + {88, 92, 96, 100} +}; + + +/** Inter-channel weighting factors for multi-channel correlation. + * To be indexed by the Rice coded indices. + */ +static const int16_t mcc_weightings[] = { + 204, 192, 179, 166, 153, 140, 128, 115, + 102, 89, 76, 64, 51, 38, 25, 12, + 0, -12, -25, -38, -51, -64, -76, -89, + -102, -115, -128, -140, -153, -166, -179, -192 +}; + + +/** Tail codes used in arithmetic coding using block Gilbert-Moore codes. + */ +static const uint8_t tail_code[16][6] = { + { 74, 44, 25, 13, 7, 3}, + { 68, 42, 24, 13, 7, 3}, + { 58, 39, 23, 13, 7, 3}, + {126, 70, 37, 19, 10, 5}, + {132, 70, 37, 20, 10, 5}, + {124, 70, 38, 20, 10, 5}, + {120, 69, 37, 20, 11, 5}, + {116, 67, 37, 20, 11, 5}, + {108, 66, 36, 20, 10, 5}, + {102, 62, 36, 20, 10, 5}, + { 88, 58, 34, 19, 10, 5}, + {162, 89, 49, 25, 13, 7}, + {156, 87, 49, 26, 14, 7}, + {150, 86, 47, 26, 14, 7}, + {142, 84, 47, 26, 14, 7}, + {131, 79, 46, 26, 14, 7} +}; + + +enum RA_Flag { + RA_FLAG_NONE, + RA_FLAG_FRAMES, + RA_FLAG_HEADER +}; + + +typedef struct { + uint32_t samples; ///< number of samples, 0xFFFFFFFF if unknown + int resolution; ///< 000 = 8-bit; 001 = 16-bit; 010 = 24-bit; 011 = 32-bit + int floating; ///< 1 = IEEE 32-bit floating-point, 0 = integer + int frame_length; ///< frame length for each frame (last frame may differ) + int ra_distance; ///< distance between RA frames (in frames, 0...255) + enum RA_Flag ra_flag; ///< indicates where the size of ra units is stored + int adapt_order; ///< adaptive order: 1 = on, 0 = off + int coef_table; ///< table index of Rice code parameters + int long_term_prediction; ///< long term prediction (LTP): 1 = on, 0 = off + int max_order; ///< maximum prediction order (0..1023) + int block_switching; ///< number of block switching levels + int bgmc; ///< "Block Gilbert-Moore Code": 1 = on, 0 = off (Rice coding only) + int sb_part; ///< sub-block partition + int joint_stereo; ///< joint stereo: 1 = on, 0 = off + int mc_coding; ///< extended inter-channel coding (multi channel coding): 1 = on, 0 = off + int chan_config; ///< indicates that a chan_config_info field is present + int chan_sort; ///< channel rearrangement: 1 = on, 0 = off + int rlslms; ///< use "Recursive Least Square-Least Mean Square" predictor: 1 = on, 0 = off + int chan_config_info; ///< mapping of channels to loudspeaker locations. Unused until setting channel configuration is implemented. + int *chan_pos; ///< original channel positions +} ALSSpecificConfig; + + +typedef struct { + int stop_flag; + int master_channel; + int time_diff_flag; + int time_diff_sign; + int time_diff_index; + int weighting[6]; +} ALSChannelData; + + +typedef struct { + AVCodecContext *avctx; + ALSSpecificConfig sconf; + GetBitContext gb; + unsigned int cur_frame_length; ///< length of the current frame to decode + unsigned int frame_id; ///< the frame ID / number of the current frame + unsigned int js_switch; ///< if true, joint-stereo decoding is enforced + unsigned int num_blocks; ///< number of blocks used in the current frame + unsigned int s_max; ///< maximum Rice parameter allowed in entropy coding + uint8_t *bgmc_lut; ///< pointer at lookup tables used for BGMC + unsigned int *bgmc_lut_status; ///< pointer at lookup table status flags used for BGMC + int ltp_lag_length; ///< number of bits used for ltp lag value + int *use_ltp; ///< contains use_ltp flags for all channels + int *ltp_lag; ///< contains ltp lag values for all channels + int **ltp_gain; ///< gain values for ltp 5-tap filter for a channel + int *ltp_gain_buffer; ///< contains all gain values for ltp 5-tap filter + int32_t **quant_cof; ///< quantized parcor coefficients for a channel + int32_t *quant_cof_buffer; ///< contains all quantized parcor coefficients + int32_t **lpc_cof; ///< coefficients of the direct form prediction filter for a channel + int32_t *lpc_cof_buffer; ///< contains all coefficients of the direct form prediction filter + int32_t *lpc_cof_reversed_buffer; ///< temporary buffer to set up a reversed versio of lpc_cof_buffer + ALSChannelData **chan_data; ///< channel data for multi-channel correlation + ALSChannelData *chan_data_buffer; ///< contains channel data for all channels + int *reverted_channels; ///< stores a flag for each reverted channel + int32_t *prev_raw_samples; ///< contains unshifted raw samples from the previous block + int32_t **raw_samples; ///< decoded raw samples for each channel + int32_t *raw_buffer; ///< contains all decoded raw samples including carryover samples +} ALSDecContext; + + +typedef struct { + unsigned int block_length; ///< number of samples within the block + unsigned int ra_block; ///< if true, this is a random access block + int const_block; ///< if true, this is a constant value block + int32_t const_val; ///< the sample value of a constant block + int js_blocks; ///< true if this block contains a difference signal + unsigned int shift_lsbs; ///< shift of values for this block + unsigned int opt_order; ///< prediction order of this block + int store_prev_samples;///< if true, carryover samples have to be stored + int *use_ltp; ///< if true, long-term prediction is used + int *ltp_lag; ///< lag value for long-term prediction + int *ltp_gain; ///< gain values for ltp 5-tap filter + int32_t *quant_cof; ///< quantized parcor coefficients + int32_t *lpc_cof; ///< coefficients of the direct form prediction + int32_t *raw_samples; ///< decoded raw samples / residuals for this block + int32_t *prev_raw_samples; ///< contains unshifted raw samples from the previous block + int32_t *raw_other; ///< decoded raw samples of the other channel of a channel pair +} ALSBlockData; + + +static av_cold void dprint_specific_config(ALSDecContext *ctx) +{ +#ifdef DEBUG + AVCodecContext *avctx = ctx->avctx; + ALSSpecificConfig *sconf = &ctx->sconf; + + dprintf(avctx, "resolution = %i\n", sconf->resolution); + dprintf(avctx, "floating = %i\n", sconf->floating); + dprintf(avctx, "frame_length = %i\n", sconf->frame_length); + dprintf(avctx, "ra_distance = %i\n", sconf->ra_distance); + dprintf(avctx, "ra_flag = %i\n", sconf->ra_flag); + dprintf(avctx, "adapt_order = %i\n", sconf->adapt_order); + dprintf(avctx, "coef_table = %i\n", sconf->coef_table); + dprintf(avctx, "long_term_prediction = %i\n", sconf->long_term_prediction); + dprintf(avctx, "max_order = %i\n", sconf->max_order); + dprintf(avctx, "block_switching = %i\n", sconf->block_switching); + dprintf(avctx, "bgmc = %i\n", sconf->bgmc); + dprintf(avctx, "sb_part = %i\n", sconf->sb_part); + dprintf(avctx, "joint_stereo = %i\n", sconf->joint_stereo); + dprintf(avctx, "mc_coding = %i\n", sconf->mc_coding); + dprintf(avctx, "chan_config = %i\n", sconf->chan_config); + dprintf(avctx, "chan_sort = %i\n", sconf->chan_sort); + dprintf(avctx, "RLSLMS = %i\n", sconf->rlslms); + dprintf(avctx, "chan_config_info = %i\n", sconf->chan_config_info); +#endif +} + + +/** Reads an ALSSpecificConfig from a buffer into the output struct. + */ +static av_cold int read_specific_config(ALSDecContext *ctx) +{ + GetBitContext gb; + uint64_t ht_size; + int i, config_offset, crc_enabled; + MPEG4AudioConfig m4ac; + ALSSpecificConfig *sconf = &ctx->sconf; + AVCodecContext *avctx = ctx->avctx; + uint32_t als_id, header_size, trailer_size; + + init_get_bits(&gb, avctx->extradata, avctx->extradata_size * 8); + + config_offset = ff_mpeg4audio_get_config(&m4ac, avctx->extradata, + avctx->extradata_size); + + if (config_offset < 0) + return -1; + + skip_bits_long(&gb, config_offset); + + if (get_bits_left(&gb) < (30 << 3)) + return -1; + + // read the fixed items + als_id = get_bits_long(&gb, 32); + avctx->sample_rate = m4ac.sample_rate; + skip_bits_long(&gb, 32); // sample rate already known + sconf->samples = get_bits_long(&gb, 32); + avctx->channels = m4ac.channels; + skip_bits(&gb, 16); // number of channels already knwon + skip_bits(&gb, 3); // skip file_type + sconf->resolution = get_bits(&gb, 3); + sconf->floating = get_bits1(&gb); + skip_bits1(&gb); // skip msb_first + sconf->frame_length = get_bits(&gb, 16) + 1; + sconf->ra_distance = get_bits(&gb, 8); + sconf->ra_flag = get_bits(&gb, 2); + sconf->adapt_order = get_bits1(&gb); + sconf->coef_table = get_bits(&gb, 2); + sconf->long_term_prediction = get_bits1(&gb); + sconf->max_order = get_bits(&gb, 10); + sconf->block_switching = get_bits(&gb, 2); + sconf->bgmc = get_bits1(&gb); + sconf->sb_part = get_bits1(&gb); + sconf->joint_stereo = get_bits1(&gb); + sconf->mc_coding = get_bits1(&gb); + sconf->chan_config = get_bits1(&gb); + sconf->chan_sort = get_bits1(&gb); + crc_enabled = get_bits1(&gb); + sconf->rlslms = get_bits1(&gb); + skip_bits(&gb, 5); // skip 5 reserved bits + skip_bits1(&gb); // skip aux_data_enabled + + + // check for ALSSpecificConfig struct + if (als_id != MKBETAG('A','L','S','\0')) + return -1; + + ctx->cur_frame_length = sconf->frame_length; + + // read channel config + if (sconf->chan_config) + sconf->chan_config_info = get_bits(&gb, 16); + // TODO: use this to set avctx->channel_layout + + + // read channel sorting + if (sconf->chan_sort && avctx->channels > 1) { + int chan_pos_bits = av_ceil_log2(avctx->channels); + int bits_needed = avctx->channels * chan_pos_bits + 7; + if (get_bits_left(&gb) < bits_needed) + return -1; + + if (!(sconf->chan_pos = av_malloc(avctx->channels * sizeof(*sconf->chan_pos)))) + return AVERROR(ENOMEM); + + for (i = 0; i < avctx->channels; i++) + sconf->chan_pos[i] = get_bits(&gb, chan_pos_bits); + + align_get_bits(&gb); + // TODO: use this to actually do channel sorting + } else { + sconf->chan_sort = 0; + } + + + // read fixed header and trailer sizes, + // if size = 0xFFFFFFFF then there is no data field! + if (get_bits_left(&gb) < 64) + return -1; + + header_size = get_bits_long(&gb, 32); + trailer_size = get_bits_long(&gb, 32); + if (header_size == 0xFFFFFFFF) + header_size = 0; + if (trailer_size == 0xFFFFFFFF) + trailer_size = 0; + + ht_size = ((int64_t)(header_size) + (int64_t)(trailer_size)) << 3; + + + // skip the header and trailer data + if (get_bits_left(&gb) < ht_size) + return -1; + + if (ht_size > INT32_MAX) + return -1; + + skip_bits_long(&gb, ht_size); + + + // skip the crc data + if (crc_enabled) { + if (get_bits_left(&gb) < 32) + return -1; + + skip_bits_long(&gb, 32); + } + + + // no need to read the rest of ALSSpecificConfig (ra_unit_size & aux data) + + dprint_specific_config(ctx); + + return 0; +} + + +/** Checks the ALSSpecificConfig for unsupported features. + */ +static int check_specific_config(ALSDecContext *ctx) +{ + ALSSpecificConfig *sconf = &ctx->sconf; + int error = 0; + + // report unsupported feature and set error value + #define MISSING_ERR(cond, str, errval) \ + { \ + if (cond) { \ + av_log_missing_feature(ctx->avctx, str, 0); \ + error = errval; \ + } \ + } + + MISSING_ERR(sconf->floating, "Floating point decoding", -1); + MISSING_ERR(sconf->rlslms, "Adaptive RLS-LMS prediction", -1); + MISSING_ERR(sconf->chan_sort, "Channel sorting", 0); + + return error; +} + + +/** Parses the bs_info field to extract the block partitioning used in + * block switching mode, refer to ISO/IEC 14496-3, section 11.6.2. + */ +static void parse_bs_info(const uint32_t bs_info, unsigned int n, + unsigned int div, unsigned int **div_blocks, + unsigned int *num_blocks) +{ + if (n < 31 && ((bs_info << n) & 0x40000000)) { + // if the level is valid and the investigated bit n is set + // then recursively check both children at bits (2n+1) and (2n+2) + n *= 2; + div += 1; + parse_bs_info(bs_info, n + 1, div, div_blocks, num_blocks); + parse_bs_info(bs_info, n + 2, div, div_blocks, num_blocks); + } else { + // else the bit is not set or the last level has been reached + // (bit implicitly not set) + **div_blocks = div; + (*div_blocks)++; + (*num_blocks)++; + } +} + + +/** Reads and decodes a Rice codeword. + */ +static int32_t decode_rice(GetBitContext *gb, unsigned int k) +{ + int max = get_bits_left(gb) - k; + int q = get_unary(gb, 0, max); + int r = k ? get_bits1(gb) : !(q & 1); + + if (k > 1) { + q <<= (k - 1); + q += get_bits_long(gb, k - 1); + } else if (!k) { + q >>= 1; + } + return r ? q : ~q; +} + + +/** Converts PARCOR coefficient k to direct filter coefficient. + */ +static void parcor_to_lpc(unsigned int k, const int32_t *par, int32_t *cof) +{ + int i, j; + + for (i = 0, j = k - 1; i < j; i++, j--) { + int tmp1 = ((MUL64(par[k], cof[j]) + (1 << 19)) >> 20); + cof[j] += ((MUL64(par[k], cof[i]) + (1 << 19)) >> 20); + cof[i] += tmp1; + } + if (i == j) + cof[i] += ((MUL64(par[k], cof[j]) + (1 << 19)) >> 20); + + cof[k] = par[k]; +} + + +/** Reads block switching field if necessary and sets actual block sizes. + * Also assures that the block sizes of the last frame correspond to the + * actual number of samples. + */ +static void get_block_sizes(ALSDecContext *ctx, unsigned int *div_blocks, + uint32_t *bs_info) +{ + ALSSpecificConfig *sconf = &ctx->sconf; + GetBitContext *gb = &ctx->gb; + unsigned int *ptr_div_blocks = div_blocks; + unsigned int b; + + if (sconf->block_switching) { + unsigned int bs_info_len = 1 << (sconf->block_switching + 2); + *bs_info = get_bits_long(gb, bs_info_len); + *bs_info <<= (32 - bs_info_len); + } + + ctx->num_blocks = 0; + parse_bs_info(*bs_info, 0, 0, &ptr_div_blocks, &ctx->num_blocks); + + // The last frame may have an overdetermined block structure given in + // the bitstream. In that case the defined block structure would need + // more samples than available to be consistent. + // The block structure is actually used but the block sizes are adapted + // to fit the actual number of available samples. + // Example: 5 samples, 2nd level block sizes: 2 2 2 2. + // This results in the actual block sizes: 2 2 1 0. + // This is not specified in 14496-3 but actually done by the reference + // codec RM22 revision 2. + // This appears to happen in case of an odd number of samples in the last + // frame which is actually not allowed by the block length switching part + // of 14496-3. + // The ALS conformance files feature an odd number of samples in the last + // frame. + + for (b = 0; b < ctx->num_blocks; b++) + div_blocks[b] = ctx->sconf.frame_length >> div_blocks[b]; + + if (ctx->cur_frame_length != ctx->sconf.frame_length) { + unsigned int remaining = ctx->cur_frame_length; + + for (b = 0; b < ctx->num_blocks; b++) { + if (remaining <= div_blocks[b]) { + div_blocks[b] = remaining; + ctx->num_blocks = b + 1; + break; + } + + remaining -= div_blocks[b]; + } + } +} + + +/** Reads the block data for a constant block + */ +static void read_const_block_data(ALSDecContext *ctx, ALSBlockData *bd) +{ + ALSSpecificConfig *sconf = &ctx->sconf; + AVCodecContext *avctx = ctx->avctx; + GetBitContext *gb = &ctx->gb; + + bd->const_val = 0; + bd->const_block = get_bits1(gb); // 1 = constant value, 0 = zero block (silence) + bd->js_blocks = get_bits1(gb); + + // skip 5 reserved bits + skip_bits(gb, 5); + + if (bd->const_block) { + unsigned int const_val_bits = sconf->floating ? 24 : avctx->bits_per_raw_sample; + bd->const_val = get_sbits_long(gb, const_val_bits); + } + + // ensure constant block decoding by reusing this field + bd->const_block = 1; +} + + +/** Decodes the block data for a constant block + */ +static void decode_const_block_data(ALSDecContext *ctx, ALSBlockData *bd) +{ + int smp = bd->block_length; + int32_t val = bd->const_val; + int32_t *dst = bd->raw_samples; + + // write raw samples into buffer + for (; smp; smp--) + *dst++ = val; +} + + +/** Reads the block data for a non-constant block + */ +static int read_var_block_data(ALSDecContext *ctx, ALSBlockData *bd) +{ + ALSSpecificConfig *sconf = &ctx->sconf; + AVCodecContext *avctx = ctx->avctx; + GetBitContext *gb = &ctx->gb; + unsigned int k; + unsigned int s[8]; + unsigned int sx[8]; + unsigned int sub_blocks, log2_sub_blocks, sb_length; + unsigned int start = 0; + unsigned int opt_order; + int sb; + int32_t *quant_cof = bd->quant_cof; + int32_t *current_res; + + + // ensure variable block decoding by reusing this field + bd->const_block = 0; + + bd->opt_order = 1; + bd->js_blocks = get_bits1(gb); + + opt_order = bd->opt_order; + + // determine the number of subblocks for entropy decoding + if (!sconf->bgmc && !sconf->sb_part) { + log2_sub_blocks = 0; + } else { + if (sconf->bgmc && sconf->sb_part) + log2_sub_blocks = get_bits(gb, 2); + else + log2_sub_blocks = 2 * get_bits1(gb); + } + + sub_blocks = 1 << log2_sub_blocks; + + // do not continue in case of a damaged stream since + // block_length must be evenly divisible by sub_blocks + if (bd->block_length & (sub_blocks - 1)) { + av_log(avctx, AV_LOG_WARNING, + "Block length is not evenly divisible by the number of subblocks.\n"); + return -1; + } + + sb_length = bd->block_length >> log2_sub_blocks; + + if (sconf->bgmc) { + s[0] = get_bits(gb, 8 + (sconf->resolution > 1)); + for (k = 1; k < sub_blocks; k++) + s[k] = s[k - 1] + decode_rice(gb, 2); + + for (k = 0; k < sub_blocks; k++) { + sx[k] = s[k] & 0x0F; + s [k] >>= 4; + } + } else { + s[0] = get_bits(gb, 4 + (sconf->resolution > 1)); + for (k = 1; k < sub_blocks; k++) + s[k] = s[k - 1] + decode_rice(gb, 0); + } + + if (get_bits1(gb)) + bd->shift_lsbs = get_bits(gb, 4) + 1; + + bd->store_prev_samples = (bd->js_blocks && bd->raw_other) || bd->shift_lsbs; + + + if (!sconf->rlslms) { + if (sconf->adapt_order) { + int opt_order_length = av_ceil_log2(av_clip((bd->block_length >> 3) - 1, + 2, sconf->max_order + 1)); + bd->opt_order = get_bits(gb, opt_order_length); + } else { + bd->opt_order = sconf->max_order; + } + + opt_order = bd->opt_order; + + if (opt_order) { + int add_base; + + if (sconf->coef_table == 3) { + add_base = 0x7F; + + // read coefficient 0 + quant_cof[0] = 32 * parcor_scaled_values[get_bits(gb, 7)]; + + // read coefficient 1 + if (opt_order > 1) + quant_cof[1] = -32 * parcor_scaled_values[get_bits(gb, 7)]; + + // read coefficients 2 to opt_order + for (k = 2; k < opt_order; k++) + quant_cof[k] = get_bits(gb, 7); + } else { + int k_max; + add_base = 1; + + // read coefficient 0 to 19 + k_max = FFMIN(opt_order, 20); + for (k = 0; k < k_max; k++) { + int rice_param = parcor_rice_table[sconf->coef_table][k][1]; + int offset = parcor_rice_table[sconf->coef_table][k][0]; + quant_cof[k] = decode_rice(gb, rice_param) + offset; + } + + // read coefficients 20 to 126 + k_max = FFMIN(opt_order, 127); + for (; k < k_max; k++) + quant_cof[k] = decode_rice(gb, 2) + (k & 1); + + // read coefficients 127 to opt_order + for (; k < opt_order; k++) + quant_cof[k] = decode_rice(gb, 1); + + quant_cof[0] = 32 * parcor_scaled_values[quant_cof[0] + 64]; + + if (opt_order > 1) + quant_cof[1] = -32 * parcor_scaled_values[quant_cof[1] + 64]; + } + + for (k = 2; k < opt_order; k++) + quant_cof[k] = (quant_cof[k] << 14) + (add_base << 13); + } + } + + // read LTP gain and lag values + if (sconf->long_term_prediction) { + *bd->use_ltp = get_bits1(gb); + + if (*bd->use_ltp) { + int r, c; + + bd->ltp_gain[0] = decode_rice(gb, 1) << 3; + bd->ltp_gain[1] = decode_rice(gb, 2) << 3; + + r = get_unary(gb, 0, 4); + c = get_bits(gb, 2); + bd->ltp_gain[2] = ltp_gain_values[r][c]; + + bd->ltp_gain[3] = decode_rice(gb, 2) << 3; + bd->ltp_gain[4] = decode_rice(gb, 1) << 3; + + *bd->ltp_lag = get_bits(gb, ctx->ltp_lag_length); + *bd->ltp_lag += FFMAX(4, opt_order + 1); + } + } + + // read first value and residuals in case of a random access block + if (bd->ra_block) { + if (opt_order) + bd->raw_samples[0] = decode_rice(gb, avctx->bits_per_raw_sample - 4); + if (opt_order > 1) + bd->raw_samples[1] = decode_rice(gb, FFMIN(s[0] + 3, ctx->s_max)); + if (opt_order > 2) + bd->raw_samples[2] = decode_rice(gb, FFMIN(s[0] + 1, ctx->s_max)); + + start = FFMIN(opt_order, 3); + } + + // read all residuals + if (sconf->bgmc) { + unsigned int delta[sub_blocks]; + unsigned int k [sub_blocks]; + unsigned int b = av_clip((av_ceil_log2(bd->block_length) - 3) >> 1, 0, 5); + unsigned int i = start; + + // read most significant bits + unsigned int high; + unsigned int low; + unsigned int value; + + ff_bgmc_decode_init(gb, &high, &low, &value); + + current_res = bd->raw_samples + start; + + for (sb = 0; sb < sub_blocks; sb++, i = 0) { + k [sb] = s[sb] > b ? s[sb] - b : 0; + delta[sb] = 5 - s[sb] + k[sb]; + + ff_bgmc_decode(gb, sb_length, current_res, + delta[sb], sx[sb], &high, &low, &value, ctx->bgmc_lut, ctx->bgmc_lut_status); + + current_res += sb_length; + } + + ff_bgmc_decode_end(gb); + + + // read least significant bits and tails + i = start; + current_res = bd->raw_samples + start; + + for (sb = 0; sb < sub_blocks; sb++, i = 0) { + unsigned int cur_tail_code = tail_code[sx[sb]][delta[sb]]; + unsigned int cur_k = k[sb]; + unsigned int cur_s = s[sb]; + + for (; i < sb_length; i++) { + int32_t res = *current_res; + + if (res == cur_tail_code) { + unsigned int max_msb = (2 + (sx[sb] > 2) + (sx[sb] > 10)) + << (5 - delta[sb]); + + res = decode_rice(gb, cur_s); + + if (res >= 0) { + res += (max_msb ) << cur_k; + } else { + res -= (max_msb - 1) << cur_k; + } + } else { + if (res > cur_tail_code) + res--; + + if (res & 1) + res = -res; + + res >>= 1; + + if (cur_k) { + res <<= cur_k; + res |= get_bits_long(gb, cur_k); + } + } + + *current_res++ = res; + } + } + } else { + current_res = bd->raw_samples + start; + + for (sb = 0; sb < sub_blocks; sb++, start = 0) + for (; start < sb_length; start++) + *current_res++ = decode_rice(gb, s[sb]); + } + + if (!sconf->mc_coding || ctx->js_switch) + align_get_bits(gb); + + return 0; +} + + +/** Decodes the block data for a non-constant block + */ +static int decode_var_block_data(ALSDecContext *ctx, ALSBlockData *bd) +{ + ALSSpecificConfig *sconf = &ctx->sconf; + unsigned int block_length = bd->block_length; + unsigned int smp = 0; + unsigned int k; + int opt_order = bd->opt_order; + int sb; + int64_t y; + int32_t *quant_cof = bd->quant_cof; + int32_t *lpc_cof = bd->lpc_cof; + int32_t *raw_samples = bd->raw_samples; + int32_t *raw_samples_end = bd->raw_samples + bd->block_length; + int32_t *lpc_cof_reversed = ctx->lpc_cof_reversed_buffer; + + // reverse long-term prediction + if (*bd->use_ltp) { + int ltp_smp; + + for (ltp_smp = FFMAX(*bd->ltp_lag - 2, 0); ltp_smp < block_length; ltp_smp++) { + int center = ltp_smp - *bd->ltp_lag; + int begin = FFMAX(0, center - 2); + int end = center + 3; + int tab = 5 - (end - begin); + int base; + + y = 1 << 6; + + for (base = begin; base < end; base++, tab++) + y += MUL64(bd->ltp_gain[tab], raw_samples[base]); + + raw_samples[ltp_smp] += y >> 7; + } + } + + // reconstruct all samples from residuals + if (bd->ra_block) { + for (smp = 0; smp < opt_order; smp++) { + y = 1 << 19; + + for (sb = 0; sb < smp; sb++) + y += MUL64(lpc_cof[sb], raw_samples[-(sb + 1)]); + + *raw_samples++ -= y >> 20; + parcor_to_lpc(smp, quant_cof, lpc_cof); + } + } else { + for (k = 0; k < opt_order; k++) + parcor_to_lpc(k, quant_cof, lpc_cof); + + // store previous samples in case that they have to be altered + if (bd->store_prev_samples) + memcpy(bd->prev_raw_samples, raw_samples - sconf->max_order, + sizeof(*bd->prev_raw_samples) * sconf->max_order); + + // reconstruct difference signal for prediction (joint-stereo) + if (bd->js_blocks && bd->raw_other) { + int32_t *left, *right; + + if (bd->raw_other > raw_samples) { // D = R - L + left = raw_samples; + right = bd->raw_other; + } else { // D = R - L + left = bd->raw_other; + right = raw_samples; + } + + for (sb = -1; sb >= -sconf->max_order; sb--) + raw_samples[sb] = right[sb] - left[sb]; + } + + // reconstruct shifted signal + if (bd->shift_lsbs) + for (sb = -1; sb >= -sconf->max_order; sb--) + raw_samples[sb] >>= bd->shift_lsbs; + } + + // reverse linear prediction coefficients for efficiency + lpc_cof = lpc_cof + opt_order; + + for (sb = 0; sb < opt_order; sb++) + lpc_cof_reversed[sb] = lpc_cof[-(sb + 1)]; + + // reconstruct raw samples + raw_samples = bd->raw_samples + smp; + lpc_cof = lpc_cof_reversed + opt_order; + + for (; raw_samples < raw_samples_end; raw_samples++) { + y = 1 << 19; + + for (sb = -opt_order; sb < 0; sb++) + y += MUL64(lpc_cof[sb], raw_samples[sb]); + + *raw_samples -= y >> 20; + } + + raw_samples = bd->raw_samples; + + // restore previous samples in case that they have been altered + if (bd->store_prev_samples) + memcpy(raw_samples - sconf->max_order, bd->prev_raw_samples, + sizeof(*raw_samples) * sconf->max_order); + + return 0; +} + + +/** Reads the block data. + */ +static int read_block(ALSDecContext *ctx, ALSBlockData *bd) +{ + GetBitContext *gb = &ctx->gb; + + // read block type flag and read the samples accordingly + if (get_bits1(gb)) { + if (read_var_block_data(ctx, bd)) + return -1; + } else { + read_const_block_data(ctx, bd); + } + + return 0; +} + + +/** Decodes the block data. + */ +static int decode_block(ALSDecContext *ctx, ALSBlockData *bd) +{ + unsigned int smp; + + // read block type flag and read the samples accordingly + if (bd->const_block) + decode_const_block_data(ctx, bd); + else if (decode_var_block_data(ctx, bd)) + return -1; + + // TODO: read RLSLMS extension data + + if (bd->shift_lsbs) + for (smp = 0; smp < bd->block_length; smp++) + bd->raw_samples[smp] <<= bd->shift_lsbs; + + return 0; +} + + +/** Reads and decodes block data successively. + */ +static int read_decode_block(ALSDecContext *ctx, ALSBlockData *bd) +{ + int ret; + + ret = read_block(ctx, bd); + + if (ret) + return ret; + + ret = decode_block(ctx, bd); + + return ret; +} + + +/** Computes the number of samples left to decode for the current frame and + * sets these samples to zero. + */ +static void zero_remaining(unsigned int b, unsigned int b_max, + const unsigned int *div_blocks, int32_t *buf) +{ + unsigned int count = 0; + + while (b < b_max) + count += div_blocks[b]; + + if (count) + memset(buf, 0, sizeof(*buf) * count); +} + + +/** Decodes blocks independently. + */ +static int decode_blocks_ind(ALSDecContext *ctx, unsigned int ra_frame, + unsigned int c, const unsigned int *div_blocks, + unsigned int *js_blocks) +{ + unsigned int b; + ALSBlockData bd; + + memset(&bd, 0, sizeof(ALSBlockData)); + + bd.ra_block = ra_frame; + bd.use_ltp = ctx->use_ltp; + bd.ltp_lag = ctx->ltp_lag; + bd.ltp_gain = ctx->ltp_gain[0]; + bd.quant_cof = ctx->quant_cof[0]; + bd.lpc_cof = ctx->lpc_cof[0]; + bd.prev_raw_samples = ctx->prev_raw_samples; + bd.raw_samples = ctx->raw_samples[c]; + + + for (b = 0; b < ctx->num_blocks; b++) { + bd.shift_lsbs = 0; + bd.block_length = div_blocks[b]; + + if (read_decode_block(ctx, &bd)) { + // damaged block, write zero for the rest of the frame + zero_remaining(b, ctx->num_blocks, div_blocks, bd.raw_samples); + return -1; + } + bd.raw_samples += div_blocks[b]; + bd.ra_block = 0; + } + + return 0; +} + + +/** Decodes blocks dependently. + */ +static int decode_blocks(ALSDecContext *ctx, unsigned int ra_frame, + unsigned int c, const unsigned int *div_blocks, + unsigned int *js_blocks) +{ + ALSSpecificConfig *sconf = &ctx->sconf; + unsigned int offset = 0; + unsigned int b; + ALSBlockData bd[2]; + + memset(bd, 0, 2 * sizeof(ALSBlockData)); + + bd[0].ra_block = ra_frame; + bd[0].use_ltp = ctx->use_ltp; + bd[0].ltp_lag = ctx->ltp_lag; + bd[0].ltp_gain = ctx->ltp_gain[0]; + bd[0].quant_cof = ctx->quant_cof[0]; + bd[0].lpc_cof = ctx->lpc_cof[0]; + bd[0].prev_raw_samples = ctx->prev_raw_samples; + bd[0].js_blocks = *js_blocks; + + bd[1].ra_block = ra_frame; + bd[1].use_ltp = ctx->use_ltp; + bd[1].ltp_lag = ctx->ltp_lag; + bd[1].ltp_gain = ctx->ltp_gain[0]; + bd[1].quant_cof = ctx->quant_cof[0]; + bd[1].lpc_cof = ctx->lpc_cof[0]; + bd[1].prev_raw_samples = ctx->prev_raw_samples; + bd[1].js_blocks = *(js_blocks + 1); + + // decode all blocks + for (b = 0; b < ctx->num_blocks; b++) { + unsigned int s; + + bd[0].shift_lsbs = 0; + bd[1].shift_lsbs = 0; + + bd[0].block_length = div_blocks[b]; + bd[1].block_length = div_blocks[b]; + + bd[0].raw_samples = ctx->raw_samples[c ] + offset; + bd[1].raw_samples = ctx->raw_samples[c + 1] + offset; + + bd[0].raw_other = bd[1].raw_samples; + bd[1].raw_other = bd[0].raw_samples; + + if(read_decode_block(ctx, &bd[0]) || read_decode_block(ctx, &bd[1])) { + // damaged block, write zero for the rest of the frame + zero_remaining(b, ctx->num_blocks, div_blocks, bd[0].raw_samples); + zero_remaining(b, ctx->num_blocks, div_blocks, bd[1].raw_samples); + return -1; + } + + // reconstruct joint-stereo blocks + if (bd[0].js_blocks) { + if (bd[1].js_blocks) + av_log(ctx->avctx, AV_LOG_WARNING, "Invalid channel pair!\n"); + + for (s = 0; s < div_blocks[b]; s++) + bd[0].raw_samples[s] = bd[1].raw_samples[s] - bd[0].raw_samples[s]; + } else if (bd[1].js_blocks) { + for (s = 0; s < div_blocks[b]; s++) + bd[1].raw_samples[s] = bd[1].raw_samples[s] + bd[0].raw_samples[s]; + } + + offset += div_blocks[b]; + bd[0].ra_block = 0; + bd[1].ra_block = 0; + } + + // store carryover raw samples, + // the others channel raw samples are stored by the calling function. + memmove(ctx->raw_samples[c] - sconf->max_order, + ctx->raw_samples[c] - sconf->max_order + sconf->frame_length, + sizeof(*ctx->raw_samples[c]) * sconf->max_order); + + return 0; +} + + +/** Reads the channel data. + */ +static int read_channel_data(ALSDecContext *ctx, ALSChannelData *cd, int c) +{ + GetBitContext *gb = &ctx->gb; + ALSChannelData *current = cd; + unsigned int channels = ctx->avctx->channels; + int entries = 0; + + while (entries < channels && !(current->stop_flag = get_bits1(gb))) { + current->master_channel = get_bits_long(gb, av_ceil_log2(channels)); + + if (current->master_channel >= channels) { + av_log(ctx->avctx, AV_LOG_ERROR, "Invalid master channel!\n"); + return -1; + } + + if (current->master_channel != c) { + current->time_diff_flag = get_bits1(gb); + current->weighting[0] = mcc_weightings[av_clip(decode_rice(gb, 1) + 16, 0, 32)]; + current->weighting[1] = mcc_weightings[av_clip(decode_rice(gb, 2) + 14, 0, 32)]; + current->weighting[2] = mcc_weightings[av_clip(decode_rice(gb, 1) + 16, 0, 32)]; + + if (current->time_diff_flag) { + current->weighting[3] = mcc_weightings[av_clip(decode_rice(gb, 1) + 16, 0, 32)]; + current->weighting[4] = mcc_weightings[av_clip(decode_rice(gb, 1) + 16, 0, 32)]; + current->weighting[5] = mcc_weightings[av_clip(decode_rice(gb, 1) + 16, 0, 32)]; + + current->time_diff_sign = get_bits1(gb); + current->time_diff_index = get_bits(gb, ctx->ltp_lag_length - 3) + 3; + } + } + + current++; + entries++; + } + + if (entries == channels) { + av_log(ctx->avctx, AV_LOG_ERROR, "Damaged channel data!\n"); + return -1; + } + + align_get_bits(gb); + return 0; +} + + +/** Recursively reverts the inter-channel correlation for a block. + */ +static int revert_channel_correlation(ALSDecContext *ctx, ALSBlockData *bd, + ALSChannelData **cd, int *reverted, + unsigned int offset, int c) +{ + ALSChannelData *ch = cd[c]; + unsigned int dep = 0; + unsigned int channels = ctx->avctx->channels; + + if (reverted[c]) + return 0; + + reverted[c] = 1; + + while (dep < channels && !ch[dep].stop_flag) { + revert_channel_correlation(ctx, bd, cd, reverted, offset, + ch[dep].master_channel); + + dep++; + } + + if (dep == channels) { + av_log(ctx->avctx, AV_LOG_WARNING, "Invalid channel correlation!\n"); + return -1; + } + + bd->use_ltp = ctx->use_ltp + c; + bd->ltp_lag = ctx->ltp_lag + c; + bd->ltp_gain = ctx->ltp_gain[c]; + bd->lpc_cof = ctx->lpc_cof[c]; + bd->quant_cof = ctx->quant_cof[c]; + bd->raw_samples = ctx->raw_samples[c] + offset; + + dep = 0; + while (!ch[dep].stop_flag) { + unsigned int smp; + unsigned int begin = 1; + unsigned int end = bd->block_length - 1; + int64_t y; + int32_t *master = ctx->raw_samples[ch[dep].master_channel] + offset; + + if (ch[dep].time_diff_flag) { + int t = ch[dep].time_diff_index; + + if (ch[dep].time_diff_sign) { + t = -t; + begin -= t; + } else { + end -= t; + } + + for (smp = begin; smp < end; smp++) { + y = (1 << 6) + + MUL64(ch[dep].weighting[0], master[smp - 1 ]) + + MUL64(ch[dep].weighting[1], master[smp ]) + + MUL64(ch[dep].weighting[2], master[smp + 1 ]) + + MUL64(ch[dep].weighting[3], master[smp - 1 + t]) + + MUL64(ch[dep].weighting[4], master[smp + t]) + + MUL64(ch[dep].weighting[5], master[smp + 1 + t]); + + bd->raw_samples[smp] += y >> 7; + } + } else { + for (smp = begin; smp < end; smp++) { + y = (1 << 6) + + MUL64(ch[dep].weighting[0], master[smp - 1]) + + MUL64(ch[dep].weighting[1], master[smp ]) + + MUL64(ch[dep].weighting[2], master[smp + 1]); + + bd->raw_samples[smp] += y >> 7; + } + } + + dep++; + } + + return 0; +} + + +/** Reads the frame data. + */ +static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame) +{ + ALSSpecificConfig *sconf = &ctx->sconf; + AVCodecContext *avctx = ctx->avctx; + GetBitContext *gb = &ctx->gb; + unsigned int div_blocks[32]; ///< block sizes. + unsigned int c; + unsigned int js_blocks[2]; + + uint32_t bs_info = 0; + + // skip the size of the ra unit if present in the frame + if (sconf->ra_flag == RA_FLAG_FRAMES && ra_frame) + skip_bits_long(gb, 32); + + if (sconf->mc_coding && sconf->joint_stereo) { + ctx->js_switch = get_bits1(gb); + align_get_bits(gb); + } + + if (!sconf->mc_coding || ctx->js_switch) { + int independent_bs = !sconf->joint_stereo; + + for (c = 0; c < avctx->channels; c++) { + js_blocks[0] = 0; + js_blocks[1] = 0; + + get_block_sizes(ctx, div_blocks, &bs_info); + + // if joint_stereo and block_switching is set, independent decoding + // is signaled via the first bit of bs_info + if (sconf->joint_stereo && sconf->block_switching) + if (bs_info >> 31) + independent_bs = 2; + + // if this is the last channel, it has to be decoded independently + if (c == avctx->channels - 1) + independent_bs = 1; + + if (independent_bs) { + if (decode_blocks_ind(ctx, ra_frame, c, div_blocks, js_blocks)) + return -1; + + independent_bs--; + } else { + if (decode_blocks(ctx, ra_frame, c, div_blocks, js_blocks)) + return -1; + + c++; + } + + // store carryover raw samples + memmove(ctx->raw_samples[c] - sconf->max_order, + ctx->raw_samples[c] - sconf->max_order + sconf->frame_length, + sizeof(*ctx->raw_samples[c]) * sconf->max_order); + } + } else { // multi-channel coding + ALSBlockData bd; + int b; + int *reverted_channels = ctx->reverted_channels; + unsigned int offset = 0; + + for (c = 0; c < avctx->channels; c++) + if (ctx->chan_data[c] < ctx->chan_data_buffer) { + av_log(ctx->avctx, AV_LOG_ERROR, "Invalid channel data!\n"); + return -1; + } + + memset(&bd, 0, sizeof(ALSBlockData)); + memset(reverted_channels, 0, sizeof(*reverted_channels) * avctx->channels); + + bd.ra_block = ra_frame; + bd.prev_raw_samples = ctx->prev_raw_samples; + + get_block_sizes(ctx, div_blocks, &bs_info); + + for (b = 0; b < ctx->num_blocks; b++) { + bd.shift_lsbs = 0; + bd.block_length = div_blocks[b]; + + for (c = 0; c < avctx->channels; c++) { + bd.use_ltp = ctx->use_ltp + c; + bd.ltp_lag = ctx->ltp_lag + c; + bd.ltp_gain = ctx->ltp_gain[c]; + bd.lpc_cof = ctx->lpc_cof[c]; + bd.quant_cof = ctx->quant_cof[c]; + bd.raw_samples = ctx->raw_samples[c] + offset; + bd.raw_other = NULL; + + read_block(ctx, &bd); + if (read_channel_data(ctx, ctx->chan_data[c], c)) + return -1; + } + + for (c = 0; c < avctx->channels; c++) + if (revert_channel_correlation(ctx, &bd, ctx->chan_data, + reverted_channels, offset, c)) + return -1; + + for (c = 0; c < avctx->channels; c++) { + bd.use_ltp = ctx->use_ltp + c; + bd.ltp_lag = ctx->ltp_lag + c; + bd.ltp_gain = ctx->ltp_gain[c]; + bd.lpc_cof = ctx->lpc_cof[c]; + bd.quant_cof = ctx->quant_cof[c]; + bd.raw_samples = ctx->raw_samples[c] + offset; + decode_block(ctx, &bd); + } + + memset(reverted_channels, 0, avctx->channels * sizeof(*reverted_channels)); + offset += div_blocks[b]; + bd.ra_block = 0; + } + + // store carryover raw samples + for (c = 0; c < avctx->channels; c++) + memmove(ctx->raw_samples[c] - sconf->max_order, + ctx->raw_samples[c] - sconf->max_order + sconf->frame_length, + sizeof(*ctx->raw_samples[c]) * sconf->max_order); + } + + // TODO: read_diff_float_data + + return 0; +} + + +/** Decodes an ALS frame. + */ +static int decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + AVPacket *avpkt) +{ + ALSDecContext *ctx = avctx->priv_data; + ALSSpecificConfig *sconf = &ctx->sconf; + const uint8_t *buffer = avpkt->data; + int buffer_size = avpkt->size; + int invalid_frame, size; + unsigned int c, sample, ra_frame, bytes_read, shift; + + init_get_bits(&ctx->gb, buffer, buffer_size * 8); + + // In the case that the distance between random access frames is set to zero + // (sconf->ra_distance == 0) no frame is treated as a random access frame. + // For the first frame, if prediction is used, all samples used from the + // previous frame are assumed to be zero. + ra_frame = sconf->ra_distance && !(ctx->frame_id % sconf->ra_distance); + + // the last frame to decode might have a different length + if (sconf->samples != 0xFFFFFFFF) + ctx->cur_frame_length = FFMIN(sconf->samples - ctx->frame_id * (uint64_t) sconf->frame_length, + sconf->frame_length); + else + ctx->cur_frame_length = sconf->frame_length; + + // decode the frame data + if ((invalid_frame = read_frame_data(ctx, ra_frame) < 0)) + av_log(ctx->avctx, AV_LOG_WARNING, + "Reading frame data failed. Skipping RA unit.\n"); + + ctx->frame_id++; + + // check for size of decoded data + size = ctx->cur_frame_length * avctx->channels * + (av_get_bits_per_sample_format(avctx->sample_fmt) >> 3); + + if (size > *data_size) { + av_log(avctx, AV_LOG_ERROR, "Decoded data exceeds buffer size.\n"); + return -1; + } + + *data_size = size; + + // transform decoded frame into output format + #define INTERLEAVE_OUTPUT(bps) \ + { \ + int##bps##_t *dest = (int##bps##_t*) data; \ + shift = bps - ctx->avctx->bits_per_raw_sample; \ + for (sample = 0; sample < ctx->cur_frame_length; sample++) \ + for (c = 0; c < avctx->channels; c++) \ + *dest++ = ctx->raw_samples[c][sample] << shift; \ + } + + if (ctx->avctx->bits_per_raw_sample <= 16) { + INTERLEAVE_OUTPUT(16) + } else { + INTERLEAVE_OUTPUT(32) + } + + bytes_read = invalid_frame ? buffer_size : + (get_bits_count(&ctx->gb) + 7) >> 3; + + return bytes_read; +} + + +/** Uninitializes the ALS decoder. + */ +static av_cold int decode_end(AVCodecContext *avctx) +{ + ALSDecContext *ctx = avctx->priv_data; + + av_freep(&ctx->sconf.chan_pos); + + ff_bgmc_end(&ctx->bgmc_lut, &ctx->bgmc_lut_status); + + av_freep(&ctx->use_ltp); + av_freep(&ctx->ltp_lag); + av_freep(&ctx->ltp_gain); + av_freep(&ctx->ltp_gain_buffer); + av_freep(&ctx->quant_cof); + av_freep(&ctx->lpc_cof); + av_freep(&ctx->quant_cof_buffer); + av_freep(&ctx->lpc_cof_buffer); + av_freep(&ctx->lpc_cof_reversed_buffer); + av_freep(&ctx->prev_raw_samples); + av_freep(&ctx->raw_samples); + av_freep(&ctx->raw_buffer); + av_freep(&ctx->chan_data); + av_freep(&ctx->chan_data_buffer); + av_freep(&ctx->reverted_channels); + + return 0; +} + + +/** Initializes the ALS decoder. + */ +static av_cold int decode_init(AVCodecContext *avctx) +{ + unsigned int c; + unsigned int channel_size; + int num_buffers; + ALSDecContext *ctx = avctx->priv_data; + ALSSpecificConfig *sconf = &ctx->sconf; + ctx->avctx = avctx; + + if (!avctx->extradata) { + av_log(avctx, AV_LOG_ERROR, "Missing required ALS extradata.\n"); + return -1; + } + + if (read_specific_config(ctx)) { + av_log(avctx, AV_LOG_ERROR, "Reading ALSSpecificConfig failed.\n"); + decode_end(avctx); + return -1; + } + + if (check_specific_config(ctx)) { + decode_end(avctx); + return -1; + } + + if (sconf->bgmc) + ff_bgmc_init(avctx, &ctx->bgmc_lut, &ctx->bgmc_lut_status); + + if (sconf->floating) { + avctx->sample_fmt = SAMPLE_FMT_FLT; + avctx->bits_per_raw_sample = 32; + } else { + avctx->sample_fmt = sconf->resolution > 1 + ? SAMPLE_FMT_S32 : SAMPLE_FMT_S16; + avctx->bits_per_raw_sample = (sconf->resolution + 1) * 8; + } + + // set maximum Rice parameter for progressive decoding based on resolution + // This is not specified in 14496-3 but actually done by the reference + // codec RM22 revision 2. + ctx->s_max = sconf->resolution > 1 ? 31 : 15; + + // set lag value for long-term prediction + ctx->ltp_lag_length = 8 + (avctx->sample_rate >= 96000) + + (avctx->sample_rate >= 192000); + + // allocate quantized parcor coefficient buffer + num_buffers = sconf->mc_coding ? avctx->channels : 1; + + ctx->quant_cof = av_malloc(sizeof(*ctx->quant_cof) * num_buffers); + ctx->lpc_cof = av_malloc(sizeof(*ctx->lpc_cof) * num_buffers); + ctx->quant_cof_buffer = av_malloc(sizeof(*ctx->quant_cof_buffer) * + num_buffers * sconf->max_order); + ctx->lpc_cof_buffer = av_malloc(sizeof(*ctx->lpc_cof_buffer) * + num_buffers * sconf->max_order); + ctx->lpc_cof_reversed_buffer = av_malloc(sizeof(*ctx->lpc_cof_buffer) * + sconf->max_order); + + if (!ctx->quant_cof || !ctx->lpc_cof || + !ctx->quant_cof_buffer || !ctx->lpc_cof_buffer || + !ctx->lpc_cof_reversed_buffer) { + av_log(avctx, AV_LOG_ERROR, "Allocating buffer memory failed.\n"); + return AVERROR(ENOMEM); + } + + // assign quantized parcor coefficient buffers + for (c = 0; c < num_buffers; c++) { + ctx->quant_cof[c] = ctx->quant_cof_buffer + c * sconf->max_order; + ctx->lpc_cof[c] = ctx->lpc_cof_buffer + c * sconf->max_order; + } + + // allocate and assign lag and gain data buffer for ltp mode + ctx->use_ltp = av_mallocz(sizeof(*ctx->use_ltp) * num_buffers); + ctx->ltp_lag = av_malloc (sizeof(*ctx->ltp_lag) * num_buffers); + ctx->ltp_gain = av_malloc (sizeof(*ctx->ltp_gain) * num_buffers); + ctx->ltp_gain_buffer = av_malloc (sizeof(*ctx->ltp_gain_buffer) * + num_buffers * 5); + + if (!ctx->use_ltp || !ctx->ltp_lag || + !ctx->ltp_gain || !ctx->ltp_gain_buffer) { + av_log(avctx, AV_LOG_ERROR, "Allocating buffer memory failed.\n"); + decode_end(avctx); + return AVERROR(ENOMEM); + } + + for (c = 0; c < num_buffers; c++) + ctx->ltp_gain[c] = ctx->ltp_gain_buffer + c * 5; + + // allocate and assign channel data buffer for mcc mode + if (sconf->mc_coding) { + ctx->chan_data_buffer = av_malloc(sizeof(*ctx->chan_data_buffer) * + num_buffers * num_buffers); + ctx->chan_data = av_malloc(sizeof(*ctx->chan_data) * + num_buffers); + ctx->reverted_channels = av_malloc(sizeof(*ctx->reverted_channels) * + num_buffers); + + if (!ctx->chan_data_buffer || !ctx->chan_data || !ctx->reverted_channels) { + av_log(avctx, AV_LOG_ERROR, "Allocating buffer memory failed.\n"); + decode_end(avctx); + return AVERROR(ENOMEM); + } + + for (c = 0; c < num_buffers; c++) + ctx->chan_data[c] = ctx->chan_data_buffer + c * num_buffers; + } else { + ctx->chan_data = NULL; + ctx->chan_data_buffer = NULL; + ctx->reverted_channels = NULL; + } + + avctx->frame_size = sconf->frame_length; + channel_size = sconf->frame_length + sconf->max_order; + + ctx->prev_raw_samples = av_malloc (sizeof(*ctx->prev_raw_samples) * sconf->max_order); + ctx->raw_buffer = av_mallocz(sizeof(*ctx-> raw_buffer) * avctx->channels * channel_size); + ctx->raw_samples = av_malloc (sizeof(*ctx-> raw_samples) * avctx->channels); + + // allocate previous raw sample buffer + if (!ctx->prev_raw_samples || !ctx->raw_buffer|| !ctx->raw_samples) { + av_log(avctx, AV_LOG_ERROR, "Allocating buffer memory failed.\n"); + decode_end(avctx); + return AVERROR(ENOMEM); + } + + // assign raw samples buffers + ctx->raw_samples[0] = ctx->raw_buffer + sconf->max_order; + for (c = 1; c < avctx->channels; c++) + ctx->raw_samples[c] = ctx->raw_samples[c - 1] + channel_size; + + return 0; +} + + +/** Flushes (resets) the frame ID after seeking. + */ +static av_cold void flush(AVCodecContext *avctx) +{ + ALSDecContext *ctx = avctx->priv_data; + + ctx->frame_id = 0; +} + + +AVCodec als_decoder = { + "als", + AVMEDIA_TYPE_AUDIO, + CODEC_ID_MP4ALS, + sizeof(ALSDecContext), + decode_init, + NULL, + decode_end, + decode_frame, + .flush = flush, + .capabilities = CODEC_CAP_SUBFRAMES, + .long_name = NULL_IF_CONFIG_SMALL("MPEG-4 Audio Lossless Coding (ALS)"), +}; + diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/amrnbdata.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/amrnbdata.h new file mode 100644 index 0000000000..2f21439896 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/amrnbdata.h @@ -0,0 +1,1672 @@ +/* + * AMR narrowband data and definitions + * Copyright (c) 2006-2007 Robert Swain + * Copyright (c) 2009 Colin McQuillan + * + * 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 + * AMR narrowband data and definitions + */ + +#ifndef AVCODEC_AMRNBDATA_H +#define AVCODEC_AMRNBDATA_H + +#include + +#include "libavutil/common.h" /* offsetof */ + +#define AMR_SUBFRAME_SIZE 40 ///< samples per subframe + +/** Frame type (Table 1a in 3GPP TS 26.101) */ +enum Mode { + MODE_4k75 = 0, ///< 4.75 kbit/s + MODE_5k15, ///< 5.15 kbit/s + MODE_5k9, ///< 5.90 kbit/s + MODE_6k7, ///< 6.70 kbit/s + MODE_7k4, ///< 7.40 kbit/s + MODE_7k95, ///< 7.95 kbit/s + MODE_10k2, ///< 10.2 kbit/s + MODE_12k2, ///< 12.2 kbit/s + MODE_DTX, ///< silent frame + N_MODES, ///< number of modes + NO_DATA = 15 ///< no transmission +}; + +#define LP_FILTER_ORDER 10 ///< linear predictive coding filter order + +/** + * AMRNB unpacked data subframe + */ +typedef struct { + uint16_t p_lag; ///< index to decode the pitch lag + uint16_t p_gain; ///< index to decode the pitch gain + uint16_t fixed_gain; ///< index to decode the fixed gain factor, for MODE_12k2 and MODE_7k95 + uint16_t pulses[10]; ///< pulses: 10 for MODE_12k2, 7 for MODE_10k2, and index and sign for others +} AMRNBSubframe; + +/** + * AMRNB unpacked data frame + */ +typedef struct { + uint16_t lsf[5]; ///< lsf parameters: 5 parameters for MODE_12k2, only 3 for other modes + AMRNBSubframe subframe[4]; ///< unpacked data for each subframe +} AMRNBFrame; + +/** The index of a frame parameter */ +#define AMR_BIT(field) (offsetof(AMRNBFrame, field) >> 1) +/** The index of a subframe-specific parameter */ +#define AMR_OF(frame_num, variable) AMR_BIT(subframe[frame_num].variable) + +// The following order* tables are used to convert AMR frame parameters to and +// from a bitstream. See 3GPP TS 26.101 for more information. +// Each field in AMRNBFrame is stored as: +// * one byte for the number of bits in the field +// * one byte for the field index +// * then, one byte for each bit of the field (from most-significant to least) +// of the position of that bit in the AMR frame. +static const uint8_t order_MODE_4k75[] = { + 8, AMR_BIT(lsf[0]), 7, 6, 5, 4, 3, 2, 1, 0, + 8, AMR_BIT(lsf[1]), 15, 14, 13, 12, 11, 10, 9, 8, + 7, AMR_BIT(lsf[2]), 51, 35, 34, 50, 33, 49, 32, + 8, AMR_OF(0,p_lag), 23, 22, 21, 20, 19, 18, 43, 42, + 8, AMR_OF(0,p_gain), 54, 55, 40, 41, 24, 25, 26, 27, + 7, AMR_OF(0,pulses[0]), 92, 68, 67, 84, 66, 65, 80, + 2, AMR_OF(0,pulses[1]), 53, 52, + 4, AMR_OF(1,p_lag), 17, 16, 48, 63, + 7, AMR_OF(1,pulses[0]), 91, 64, 79, 83, 78, 77, 95, + 2, AMR_OF(1,pulses[1]), 62, 61, + 4, AMR_OF(2,p_lag), 31, 30, 60, 59, + 8, AMR_OF(2,p_gain), 44, 45, 46, 47, 36, 37, 38, 39, + 7, AMR_OF(2,pulses[0]), 90, 76, 75, 82, 74, 73, 94, + 2, AMR_OF(2,pulses[1]), 58, 57, + 4, AMR_OF(3,p_lag), 29, 28, 56, 71, + 7, AMR_OF(3,pulses[0]), 89, 72, 87, 81, 86, 85, 93, + 2, AMR_OF(3,pulses[1]), 70, 69, + 0 +}; + +static const uint8_t order_MODE_5k15[] = { + 8, AMR_BIT(lsf[0]), 0, 1, 2, 3, 4, 5, 6, 7, + 8, AMR_BIT(lsf[1]), 8, 9, 10, 11, 12, 13, 14, 15, + 7, AMR_BIT(lsf[2]), 70, 51, 43, 71, 50, 60, 49, + 8, AMR_OF(0,p_lag), 23, 22, 21, 20, 19, 47, 54, 59, + 6, AMR_OF(0,p_gain), 48, 42, 35, 29, 30, 31, + 7, AMR_OF(0,pulses[0]), 92, 84, 82, 100, 79, 72, 88, + 2, AMR_OF(0,pulses[1]), 67, 68, + 4, AMR_OF(1,p_lag), 18, 46, 53, 58, + 6, AMR_OF(1,p_gain), 63, 41, 34, 26, 27, 28, + 7, AMR_OF(1,pulses[0]), 91, 83, 81, 99, 78, 87, 103, + 2, AMR_OF(1,pulses[1]), 65, 66, + 4, AMR_OF(2,p_lag), 17, 45, 52, 57, + 6, AMR_OF(2,p_gain), 62, 40, 33, 39, 24, 25, + 7, AMR_OF(2,pulses[0]), 90, 80, 95, 98, 77, 86, 102, + 2, AMR_OF(2,pulses[1]), 75, 64, + 4, AMR_OF(3,p_lag), 16, 44, 56, 69, + 6, AMR_OF(3,p_gain), 61, 55, 32, 36, 37, 38, + 7, AMR_OF(3,pulses[0]), 89, 94, 93, 97, 76, 85, 101, + 2, AMR_OF(3,pulses[1]), 73, 74, + 0 +}; + +static const uint8_t order_MODE_5k9[] = { + 8, AMR_BIT(lsf[0]), 7, 6, 0, 3, 5, 4, 2, 1, + 9, AMR_BIT(lsf[1]), 13, 12, 8, 11, 10, 15, 9, 14, 23, + 9, AMR_BIT(lsf[2]), 71, 56, 60, 70, 59, 57, 58, 69, 76, + 8, AMR_OF(0,p_lag), 16, 18, 22, 20, 30, 38, 44, 42, + 6, AMR_OF(0,p_gain), 75, 48, 52, 40, 34, 26, + 9, AMR_OF(0,pulses[0]), 101, 89, 93, 117, 105, 81, 85, 109, 97, + 2, AMR_OF(0,pulses[1]), 67, 78, + 4, AMR_OF(1,p_lag), 28, 36, 46, 87, + 6, AMR_OF(1,p_gain), 74, 63, 51, 55, 33, 25, + 9, AMR_OF(1,pulses[0]), 100, 88, 92, 116, 104, 80, 84, 108, 96, + 2, AMR_OF(1,pulses[1]), 64, 79, + 8, AMR_OF(2,p_lag), 31, 17, 21, 19, 29, 37, 43, 41, + 6, AMR_OF(2,p_gain), 73, 62, 50, 54, 32, 24, + 9, AMR_OF(2,pulses[0]), 99, 103, 91, 115, 119, 95, 83, 107, 111, + 2, AMR_OF(2,pulses[1]), 66, 77, + 4, AMR_OF(3,p_lag), 27, 35, 45, 86, + 6, AMR_OF(3,p_gain), 72, 61, 49, 53, 47, 39, + 9, AMR_OF(3,pulses[0]), 98, 102, 90, 114, 118, 94, 82, 106, 110, + 2, AMR_OF(3,pulses[1]), 65, 68, + 0 +}; + +static const uint8_t order_MODE_6k7[] = { + 8, AMR_BIT(lsf[0]), 7, 6, 15, 4, 5, 3, 2, 0, + 9, AMR_BIT(lsf[1]), 14, 13, 8, 12, 10, 1, 9, 11, 29, + 9, AMR_BIT(lsf[2]), 57, 58, 50, 56, 60, 59, 49, 71, 70, + 8, AMR_OF(0,p_lag), 17, 19, 23, 21, 31, 24, 32, 52, + 7, AMR_OF(0,p_gain), 36, 82, 69, 46, 42, 48, 77, + 11, AMR_OF(0,pulses[0]), 109, 97, 133, 121, 101, 89, 125, 113, 93, 117, + 105, + 3, AMR_OF(0,pulses[1]), 81, 73, 65, + 4, AMR_OF(1,p_lag), 28, 26, 38, 54, + 7, AMR_OF(1,p_gain), 35, 83, 68, 45, 41, 63, 76, + 11, AMR_OF(1,pulses[0]), 108, 96, 132, 120, 100, 88, 124, 112, 92, 116, + 104, + 3, AMR_OF(1,pulses[1]), 80, 72, 64, + 8, AMR_OF(2,p_lag), 16, 18, 22, 20, 30, 39, 47, 51, + 7, AMR_OF(2,p_gain), 34, 84, 67, 44, 40, 62, 75, + 11, AMR_OF(2,pulses[0]), 107, 111, 131, 135, 99, 103, 123, 127, 91, 115, + 119, + 3, AMR_OF(2,pulses[1]), 95, 87, 79, + 4, AMR_OF(3,p_lag), 27, 25, 37, 53, + 7, AMR_OF(3,p_gain), 33, 85, 66, 43, 55, 61, 74, + 11, AMR_OF(3,pulses[0]), 106, 110, 130, 134, 98, 102, 122, 126, 90, 114, + 118, + 3, AMR_OF(3,pulses[1]), 94, 86, 78, + 0 +}; + +static const uint8_t order_MODE_7k4[] = { + 8, AMR_BIT(lsf[0]), 7, 6, 5, 4, 3, 2, 1, 0, + 9, AMR_BIT(lsf[1]), 15, 14, 13, 12, 11, 10, 9, 8, 23, + 9, AMR_BIT(lsf[2]), 53, 52, 51, 58, 40, 55, 54, 57, 56, + 8, AMR_OF(0,p_lag), 22, 20, 18, 16, 30, 50, 95, 94, + 7, AMR_OF(0,p_gain), 28, 24, 73, 36, 32, 62, 67, + 13, AMR_OF(0,pulses[0]), 127, 123, 135, 131, 143, 139, 151, 103, 102, 101, + 100, 99, 98, + 4, AMR_OF(0,pulses[1]), 83, 75, 79, 71, + 5, AMR_OF(1,p_lag), 44, 42, 49, 93, 92, + 7, AMR_OF(1,p_gain), 27, 39, 72, 35, 47, 61, 66, + 13, AMR_OF(1,pulses[0]), 126, 122, 134, 130, 142, 138, 150, 97, 96, 111, + 110, 109, 108, + 4, AMR_OF(1,pulses[1]), 82, 74, 78, 70, + 8, AMR_OF(2,p_lag), 21, 19, 17, 31, 29, 48, 91, 90, + 7, AMR_OF(2,p_gain), 26, 38, 87, 34, 46, 60, 65, + 13, AMR_OF(2,pulses[0]), 125, 121, 133, 129, 141, 137, 149, 107, 106, 105, + 104, 119, 118, + 4, AMR_OF(2,pulses[1]), 81, 85, 77, 69, + 5, AMR_OF(3,p_lag), 43, 41, 63, 89, 88, + 7, AMR_OF(3,p_gain), 25, 37, 86, 33, 45, 59, 64, + 13, AMR_OF(3,pulses[0]), 124, 120, 132, 128, 140, 136, 148, 117, 116, 115, + 114, 113, 112, + 4, AMR_OF(3,pulses[1]), 80, 84, 76, 68, + 0 +}; + +static const uint8_t order_MODE_7k95[] = { + 9, AMR_BIT(lsf[0]), 67, 68, 1, 2, 3, 4, 5, 6, 7, + 9, AMR_BIT(lsf[1]), 14, 13, 9, 12, 11, 0, 10, 15, 8, + 9, AMR_BIT(lsf[2]), 18, 19, 23, 17, 22, 20, 21, 66, 65, + 8, AMR_OF(0,p_lag), 44, 42, 40, 54, 52, 56, 64, 78, + 4, AMR_OF(0,p_gain), 36, 32, 72, 80, + 5, AMR_OF(0,fixed_gain), 16, 28, 24, 60, 84, + 13, AMR_OF(0,pulses[0]), 135, 109, 144, 156, 120, 97, 148, 121, 101, 122, + 123, 89, 124, + 4, AMR_OF(0,pulses[1]), 125, 126, 127, 112, + 6, AMR_OF(1,p_lag), 50, 48, 62, 70, 76, 74, + 4, AMR_OF(1,p_gain), 35, 47, 87, 95, + 5, AMR_OF(1,fixed_gain), 31, 27, 39, 59, 83, + 13, AMR_OF(1,pulses[0]), 129, 108, 159, 155, 130, 96, 147, 131, 100, 132, + 133, 88, 134, + 4, AMR_OF(1,pulses[1]), 113, 114, 115, 116, + 8, AMR_OF(2,p_lag), 43, 41, 55, 53, 51, 71, 79, 77, + 4, AMR_OF(2,p_gain), 34, 46, 86, 94, + 5, AMR_OF(2,fixed_gain), 30, 26, 38, 58, 82, + 13, AMR_OF(2,pulses[0]), 139, 107, 158, 154, 140, 111, 146, 141, 99, 142, + 143, 103, 128, + 4, AMR_OF(2,pulses[1]), 105, 90, 91, 92, + 6, AMR_OF(3,p_lag), 49, 63, 61, 69, 75, 73, + 4, AMR_OF(3,p_gain), 33, 45, 85, 93, + 5, AMR_OF(3,fixed_gain), 29, 25, 37, 57, 81, + 13, AMR_OF(3,pulses[0]), 149, 106, 157, 153, 150, 110, 145, 151, 98, 136, + 137, 102, 138, + 4, AMR_OF(3,pulses[1]), 117, 118, 119, 104, + 0 +}; + +static const uint8_t order_MODE_10k2[] = { + 8, AMR_BIT(lsf[0]), 0, 1, 2, 3, 4, 5, 6, 7, + 9, AMR_BIT(lsf[1]), 23, 8, 9, 10, 11, 12, 13, 14, 15, + 9, AMR_BIT(lsf[2]), 57, 58, 62, 56, 60, 59, 61, 71, 70, + 8, AMR_OF(0,p_lag), 22, 21, 20, 19, 18, 17, 42, 41, + 7, AMR_OF(0,p_gain), 38, 50, 84, 37, 36, 85, 83, + 1, AMR_OF(0,pulses[0]), 66, + 1, AMR_OF(0,pulses[1]), 67, + 1, AMR_OF(0,pulses[2]), 68, + 1, AMR_OF(0,pulses[3]), 69, + 10, AMR_OF(0,pulses[4]), 145, 144, 156, 153, 154, 163, 161, 192, 206, 195, + 10, AMR_OF(0,pulses[5]), 158, 159, 157, 152, 155, 165, 160, 205, 204, 194, + 7, AMR_OF(0,pulses[6]), 167, 166, 162, 164, 196, 207, 193, + 5, AMR_OF(1,p_lag), 26, 25, 54, 53, 89, + 7, AMR_OF(1,p_gain), 35, 49, 81, 34, 33, 82, 80, + 1, AMR_OF(1,pulses[0]), 78, + 1, AMR_OF(1,pulses[1]), 79, + 1, AMR_OF(1,pulses[2]), 64, + 1, AMR_OF(1,pulses[3]), 65, + 10, AMR_OF(1,pulses[4]), 103, 102, 98, 111, 96, 105, 119, 185, 199, 188, + 10, AMR_OF(1,pulses[5]), 100, 101, 99, 110, 97, 107, 118, 198, 197, 187, + 7, AMR_OF(1,pulses[6]), 109, 108, 104, 106, 189, 184, 186, + 8, AMR_OF(2,p_lag), 16, 31, 30, 29, 28, 27, 40, 55, + 7, AMR_OF(2,p_gain), 32, 48, 94, 47, 46, 95, 93, + 1, AMR_OF(2,pulses[0]), 74, + 1, AMR_OF(2,pulses[1]), 75, + 1, AMR_OF(2,pulses[2]), 76, + 1, AMR_OF(2,pulses[3]), 77, + 10, AMR_OF(2,pulses[4]), 117, 116, 112, 125, 126, 135, 133, 178, 176, 181, + 10, AMR_OF(2,pulses[5]), 114, 115, 113, 124, 127, 121, 132, 191, 190, 180, + 7, AMR_OF(2,pulses[6]), 123, 122, 134, 120, 182, 177, 179, + 5, AMR_OF(3,p_lag), 24, 39, 52, 51, 88, + 7, AMR_OF(3,p_gain), 45, 63, 91, 44, 43, 92, 90, + 1, AMR_OF(3,pulses[0]), 86, + 1, AMR_OF(3,pulses[1]), 87, + 1, AMR_OF(3,pulses[2]), 72, + 1, AMR_OF(3,pulses[3]), 73, + 10, AMR_OF(3,pulses[4]), 131, 130, 142, 139, 140, 149, 147, 171, 169, 174, + 10, AMR_OF(3,pulses[5]), 128, 129, 143, 138, 141, 151, 146, 168, 183, 173, + 7, AMR_OF(3,pulses[6]), 137, 136, 148, 150, 175, 170, 172, + 0 +}; + +static const uint8_t order_MODE_12k2[] = { + 7, AMR_BIT(lsf[0]), 7, 6, 5, 4, 3, 2, 1, + 8, AMR_BIT(lsf[1]), 0, 15, 14, 13, 12, 11, 10, 9, + 9, AMR_BIT(lsf[2]), 23, 22, 21, 20, 19, 18, 17, 16, 8, + 8, AMR_BIT(lsf[3]), 31, 30, 29, 28, 27, 86, 85, 84, + 6, AMR_BIT(lsf[4]), 83, 82, 81, 80, 127, 126, + 9, AMR_OF(0,p_lag), 26, 24, 38, 36, 34, 32, 46, 44, 42, + 4, AMR_OF(0,p_gain), 40, 52, 48, 95, + 5, AMR_OF(0,fixed_gain), 60, 56, 68, 91, 111, + 3, AMR_OF(0,pulses[0]), 191, 176, 177, + 4, AMR_OF(0,pulses[1]), 103, 123, 124, 125, + 3, AMR_OF(0,pulses[2]), 188, 189, 190, + 4, AMR_OF(0,pulses[3]), 99, 120, 121, 122, + 3, AMR_OF(0,pulses[4]), 185, 186, 187, + 4, AMR_OF(0,pulses[5]), 107, 133, 134, 135, + 3, AMR_OF(0,pulses[6]), 198, 199, 184, + 4, AMR_OF(0,pulses[7]), 119, 130, 131, 132, + 3, AMR_OF(0,pulses[8]), 195, 196, 197, + 4, AMR_OF(0,pulses[9]), 115, 143, 128, 129, + 6, AMR_OF(1,p_lag), 64, 78, 76, 74, 72, 245, + 4, AMR_OF(1,p_gain), 55, 51, 63, 94, + 5, AMR_OF(1,fixed_gain), 59, 71, 67, 90, 110, + 3, AMR_OF(1,pulses[0]), 192, 193, 194, + 4, AMR_OF(1,pulses[1]), 102, 140, 141, 142, + 3, AMR_OF(1,pulses[2]), 205, 206, 207, + 4, AMR_OF(1,pulses[3]), 98, 137, 138, 139, + 3, AMR_OF(1,pulses[4]), 202, 203, 204, + 4, AMR_OF(1,pulses[5]), 106, 150, 151, 136, + 3, AMR_OF(1,pulses[6]), 215, 200, 201, + 4, AMR_OF(1,pulses[7]), 118, 147, 148, 149, + 3, AMR_OF(1,pulses[8]), 212, 213, 214, + 4, AMR_OF(1,pulses[9]), 114, 144, 145, 146, + 9, AMR_OF(2,p_lag), 25, 39, 37, 35, 33, 47, 45, 43, 41, + 4, AMR_OF(2,p_gain), 54, 50, 62, 93, + 5, AMR_OF(2,fixed_gain), 58, 70, 66, 89, 109, + 3, AMR_OF(2,pulses[0]), 209, 210, 211, + 4, AMR_OF(2,pulses[1]), 101, 157, 158, 159, + 3, AMR_OF(2,pulses[2]), 222, 223, 208, + 4, AMR_OF(2,pulses[3]), 97, 154, 155, 156, + 3, AMR_OF(2,pulses[4]), 219, 220, 221, + 4, AMR_OF(2,pulses[5]), 105, 167, 152, 153, + 3, AMR_OF(2,pulses[6]), 216, 217, 218, + 4, AMR_OF(2,pulses[7]), 117, 164, 165, 166, + 3, AMR_OF(2,pulses[8]), 229, 230, 231, + 4, AMR_OF(2,pulses[9]), 113, 161, 162, 163, + 6, AMR_OF(3,p_lag), 79, 77, 75, 73, 87, 244, + 4, AMR_OF(3,p_gain), 53, 49, 61, 92, + 5, AMR_OF(3,fixed_gain), 57, 69, 65, 88, 108, + 3, AMR_OF(3,pulses[0]), 226, 227, 228, + 4, AMR_OF(3,pulses[1]), 100, 174, 175, 160, + 3, AMR_OF(3,pulses[2]), 239, 224, 225, + 4, AMR_OF(3,pulses[3]), 96, 171, 172, 173, + 3, AMR_OF(3,pulses[4]), 236, 237, 238, + 4, AMR_OF(3,pulses[5]), 104, 168, 169, 170, + 3, AMR_OF(3,pulses[6]), 233, 234, 235, + 4, AMR_OF(3,pulses[7]), 116, 181, 182, 183, + 3, AMR_OF(3,pulses[8]), 246, 247, 232, + 4, AMR_OF(3,pulses[9]), 112, 178, 179, 180, + 0 +}; + +/** + * position of the bitmapping data for each packet type in + * the AMRNBFrame + */ +static const uint8_t * const amr_unpacking_bitmaps_per_mode[N_MODES] = { + order_MODE_4k75, + order_MODE_5k15, + order_MODE_5k9, + order_MODE_6k7, + order_MODE_7k4, + order_MODE_7k95, + order_MODE_10k2, + order_MODE_12k2, +}; + +/** number of bytes for each mode */ +static const uint8_t frame_sizes_nb[N_MODES] = { + 12, 13, 15, 17, 19, 20, 26, 31, 5 +}; + +/** + * Base-5 representation for values 0-124 + * + * This is useful for decoding pulse positions in 10.2 kbit/s frames. + * Safe values are provided for out of range positions 125-127. + */ +static const uint8_t base_five_table[128][3] = { + {0, 0, 0}, {0, 0, 1}, {0, 0, 2}, {0, 0, 3}, {0, 0, 4}, {0, 1, 0}, {0, 1, 1}, + {0, 1, 2}, {0, 1, 3}, {0, 1, 4}, {0, 2, 0}, {0, 2, 1}, {0, 2, 2}, {0, 2, 3}, + {0, 2, 4}, {0, 3, 0}, {0, 3, 1}, {0, 3, 2}, {0, 3, 3}, {0, 3, 4}, {0, 4, 0}, + {0, 4, 1}, {0, 4, 2}, {0, 4, 3}, {0, 4, 4}, {1, 0, 0}, {1, 0, 1}, {1, 0, 2}, + {1, 0, 3}, {1, 0, 4}, {1, 1, 0}, {1, 1, 1}, {1, 1, 2}, {1, 1, 3}, {1, 1, 4}, + {1, 2, 0}, {1, 2, 1}, {1, 2, 2}, {1, 2, 3}, {1, 2, 4}, {1, 3, 0}, {1, 3, 1}, + {1, 3, 2}, {1, 3, 3}, {1, 3, 4}, {1, 4, 0}, {1, 4, 1}, {1, 4, 2}, {1, 4, 3}, + {1, 4, 4}, {2, 0, 0}, {2, 0, 1}, {2, 0, 2}, {2, 0, 3}, {2, 0, 4}, {2, 1, 0}, + {2, 1, 1}, {2, 1, 2}, {2, 1, 3}, {2, 1, 4}, {2, 2, 0}, {2, 2, 1}, {2, 2, 2}, + {2, 2, 3}, {2, 2, 4}, {2, 3, 0}, {2, 3, 1}, {2, 3, 2}, {2, 3, 3}, {2, 3, 4}, + {2, 4, 0}, {2, 4, 1}, {2, 4, 2}, {2, 4, 3}, {2, 4, 4}, {3, 0, 0}, {3, 0, 1}, + {3, 0, 2}, {3, 0, 3}, {3, 0, 4}, {3, 1, 0}, {3, 1, 1}, {3, 1, 2}, {3, 1, 3}, + {3, 1, 4}, {3, 2, 0}, {3, 2, 1}, {3, 2, 2}, {3, 2, 3}, {3, 2, 4}, {3, 3, 0}, + {3, 3, 1}, {3, 3, 2}, {3, 3, 3}, {3, 3, 4}, {3, 4, 0}, {3, 4, 1}, {3, 4, 2}, + {3, 4, 3}, {3, 4, 4}, {4, 0, 0}, {4, 0, 1}, {4, 0, 2}, {4, 0, 3}, {4, 0, 4}, + {4, 1, 0}, {4, 1, 1}, {4, 1, 2}, {4, 1, 3}, {4, 1, 4}, {4, 2, 0}, {4, 2, 1}, + {4, 2, 2}, {4, 2, 3}, {4, 2, 4}, {4, 3, 0}, {4, 3, 1}, {4, 3, 2}, {4, 3, 3}, + {4, 3, 4}, {4, 4, 0}, {4, 4, 1}, {4, 4, 2}, {4, 4, 3}, {4, 4, 4}, {0, 0, 0}, + {0, 0, 0}, {0, 0, 0} +}; + +/** + * Values for the lsp vector from the 4th subframe of the + * previous subframe values. + * + * @note: Taken from Decoder_amr_reset in Q15 using val/1000 + */ +static const int8_t lsp_sub4_init[LP_FILTER_ORDER] = { + 30, 26, 21, 15, 8, 0, -8, -15, -21, -26 +}; + +/** + * Mean lsp values. + * + * @note: Taken from Decoder_amr_reset in Q15 + */ +static const int16_t lsp_avg_init[LP_FILTER_ORDER] = { + 1384, 2077, 3420, 5108, 6742, 8122, 9863, 11092, 12714, 13701 +}; + +// LSF tables + +// These are stored as integers to save space. The values are taken from +// q_plsf_3.tab and q_plsf_5.tab in 3GPP TS 26.090. + +static const int16_t lsf_3_3_MODE_5k15[128][4] = { +{ 419, 163, -30, -262}, { -455, -789,-1430, -721}, { 1006, 664, 269, 25}, +{ 619, 260, 183, 96}, { -968,-1358, -388, 135}, { -693, 835, 456, 154}, +{ 1105, 703, 569, 363}, { 1625, 1326, 985, 748}, { -220, 219, 76, -208}, +{-1455,-1662, 49, 149}, { -964, -172, -752, -336}, { 625, 209, -250, -66}, +{-1017, -838, -2, 317}, {-2168,-1485, -138, 123}, {-1876,-2099, -521, 85}, +{ -967, -366, -695, -881}, { -921,-1011, -763, -949}, { -124, -256, -352, -660}, +{ 178, 463, 354, 304}, {-1744, -591, -282, 79}, {-2249, 175, 867, 499}, +{ -138, -180, -181, -21}, {-2291,-1241, -460, -520}, { -771, 451, -10, -308}, +{ 271, -65, 4, 214}, { -279, -435, -43, -348}, { -670, 35, -65, -211}, +{ 806, 535, 85, 297}, { 57, 239, 722, 493}, { 225, 661, 840, 547}, +{ -540, -376, 14, 349}, { 469, 721, 331, 162}, { -544, -752, -62, -10}, +{ 398, -88, 724, 701}, { -19, -533, -94, 601}, { 136, -71, -681, -747}, +{ -166, -344, 261, -50}, { 161, -52, 485, 337}, {-1675, 50, 190, -93}, +{-2282, -231, -194, -82}, { -95, -595, -154, 128}, { 894, 501, 588, 457}, +{ -345, 206, 122, 110}, { -631, -227, -569, 3}, { 408, 239, 397, 226}, +{ -197, -2, 128, 491}, { 1281, 904, 292, 215}, { 538, 306, 259, 509}, +{ -677,-1047, 13, 321}, { -679, -588, -358, -212}, { -558, 243, 646, 479}, +{ 486, 342, 634, 532}, { 107, 802, 331, 136}, { -112, -398,-1031, -286}, +{ -326, -705, 288, 272}, { 1299, 1144, 1178, 860}, { -423, 121, -385, -148}, +{ -295, -302, -834, -819}, { 16, -24, -201, -476}, { 555, 91, -245, 294}, +{ -38, -379, -962,-1221}, {-1191,-1518, -273, -395}, { -390,-1013, -645, 573}, +{-1843,-1030, 505, 468}, { 744, 947, 609, 493}, { -689,-1172, -628, -135}, +{-1026, 195, 411, 196}, { 1582, 1147, 575, 337}, {-1239, -777, -648, -142}, +{ 595, 825, 967, 735}, {-1206, -970, -81, -342}, { -745, 13, -72, 375}, +{ 454, 19, 1407, 921}, {-1647, -172, 861, 562}, { 928, 1537, 1063, 740}, +{-2472, -952, 264, 82}, { -502, -965,-1334, 123}, { 867, 1236, 534, 171}, +{-2320, -460, 780, 363}, {-1190, -617, 252, -61}, { -174, 34, 1011, 788}, +{-2333, 247, 423, 153}, { -16, -355, 262, 449}, {-1576,-1073, -544, -371}, +{ -615, -305, 1051, 805}, { 687, 528, 6, -182}, { 935, 875, 1002, 809}, +{ 199, 257, 126, 76}, { -584,-1138, 599, 556}, {-1105,-1391,-1591, -519}, +{ -977,-1325, 108, 347}, { -722, -975, 365, 101}, { -145, 681, 249, -153}, +{ 0, -334, -570, 159}, { 412, 285, -336, -617}, { -953, -966, 887, 689}, +{-1251, 84, -185, -398}, { -592, 433, 1044, 653}, { 85, 329, -40, 361}, +{ -433, -705, 466, 574}, { -154, 654, 592, 290}, { -167, 72, 349, 175}, +{ 674, 297, 977, 720}, { 1235, 1204, 757, 488}, { -400, -269, 538, 372}, +{-1350,-1387,-1194, -91}, { 1262, 876, 775, 700}, { -599, -38, -430, -722}, +{ 1976, 1630, 991, 608}, { 111, 276, -226, -96}, { -947, -388, -11, -7}, +{ -303, -531, -839, 338}, { 1734, 1710, 1405, 1013}, { -516, -855, -645, 210}, +{ -688, -416, 513, 230}, { -822, -637,-1146, -320}, { -952, -658, -694, 183}, +{ -114, -623, 818, 674}, { -191, -204, 731, 635}, { 51, 1221, 883, 576}, +{ -954, -431, 826, 598}, { -342, -755, -900, -407}, {-1126, -354, -206, -512}, +{ -547, -810, -357, -620}, { 66, 515, -73, -410}, { -872, -945,-1444,-1227}, +{ 191, -17, -544, -231}, {-1540, -544, -901, -886} +}; + +static const int16_t lsf_3_1_MODE_7k95[512][3] = { +{ -890,-1550,-2541}, { -819, -970, 175}, { -826,-1234, -762}, +{ -599, -22, 634}, { -811, -987, -902}, { -323, 203, 26}, +{ -383, -235, -781}, { -399, 1262, 906}, { -932,-1399,-1380}, +{ -624, 93, 87}, { -414, -539, -691}, { 37, 633, 510}, +{ -387, -476,-1330}, { 399, 66, 263}, { -407, -49, -335}, +{ -417, 1041, 1865}, { -779,-1089,-1440}, { -746, -858, 832}, +{ -581, -759, -371}, { -673, -506, 2088}, { -560, -634,-1179}, +{ 271, 241, 14}, { -438, -244, -397}, { 463, 1202, 1047}, +{ -606, -797,-1438}, { -51, -323, 481}, { -224, -584, -527}, +{ 494, 881, 682}, { -433, -306,-1002}, { 554, 659, 222}, +{ 171, -160, -353}, { 681, 1798, 1565}, { -852,-1181,-1695}, +{ -336, -666, 114}, { -581, -756, -744}, { -195, 375, 497}, +{ -465, -804,-1098}, { 154, 282, -131}, { -50, -191, -719}, +{ 323, 732, 1542}, { -722, -819,-1404}, { 105, -250, 185}, +{ -178, -502, -742}, { 321, 510, 1111}, { -323, -567, -966}, +{ 127, 484, 338}, { -160, 52, -338}, { 732, 1367, 1554}, +{ -626, -802,-1696}, { -286, -586, 676}, { -695, -343, -370}, +{ -490, 295, 1893}, { -630, -574,-1014}, { -80, 645, -69}, +{ -6, -318, -364}, { 782, 1450, 1038}, { -313, -733,-1395}, +{ 120, 60, 477}, { -264, -585, -123}, { 711, 1245, 633}, +{ -91, -355,-1016}, { 771, 758, 261}, { 253, 81, -474}, +{ 930, 2215, 1720}, { -808,-1099,-1925}, { -560, -782, 169}, +{ -804,-1074, -188}, { -626, -55, 1405}, { -694, -716,-1194}, +{ -660, 354, 329}, { -514, -55, -543}, { 366, 1033, 1182}, +{ -658, -959,-1357}, { -55, -184, 93}, { -605, -286, -662}, +{ 404, 449, 827}, { -286, -350,-1263}, { 628, 306, 227}, +{ -16, 147, -623}, { 186, 923, 2146}, { -674, -890,-1606}, +{ -443, -228, 339}, { -369, -790, -409}, { 231, 86, 1469}, +{ -448, -581,-1061}, { 594, 450, -177}, { -124, -170, -447}, +{ 671, 1159, 1404}, { -476, -667,-1511}, { -77, -138, 716}, +{ -177, -372, -381}, { 451, 934, 915}, { -250, -432, -822}, +{ 272, 828, 446}, { 26, 19, -31}, { 698, 1692, 2168}, +{ -646, -977,-1924}, { -179, -473, 268}, { -379, -745, -691}, +{ 11, 127, 1033}, { -488, -917, -825}, { 61, 323, 135}, +{ 147, -145, -686}, { 685, 786, 1682}, { -506, -848,-1297}, +{ 35, 90, 222}, { -23, -346, -670}, { 455, 591, 1287}, +{ -203, -593,-1086}, { 652, 352, 437}, { 39, 63, -457}, +{ 841, 1265, 2105}, { -520, -882,-1584}, { -328, -711, 1421}, +{ -596, -342, -70}, { 209, 173, 1928}, { -423, -598, -921}, +{ 421, 605, -38}, { -2, -245, -127}, { 896, 1969, 1135}, +{ -379, -518,-1579}, { 173, 118, 753}, { -55, -381, -52}, +{ 985, 1021, 753}, { -2, -291, -891}, { 753, 992, 423}, +{ 264, 131, -196}, { 895, 2274, 2543}, { -635,-1088,-2499}, +{ -529, -982, 526}, { -764, -830, -548}, { -436, 316, 599}, +{ -675, -940, -746}, { -57, 236, -11}, { -201, -81, -798}, +{ 16, 845, 1558}, { -737, -985,-1212}, { -468, 17, 290}, +{ -279, -584, -700}, { 183, 822, 705}, { -265, -492,-1187}, +{ 421, 152, 468}, { -390, 166, -268}, { 39, 1550, 1868}, +{ -635, -966,-1571}, { -453, -492, 910}, { -284,-1027, -75}, +{ -181, -133, 1852}, { -445, -624,-1174}, { 420, 367, -49}, +{ -389, -212, -169}, { 707, 1073, 1208}, { -539, -710,-1449}, +{ 83, -163, 484}, { -236, -543, -355}, { 338, 1175, 814}, +{ -246, -309, -958}, { 606, 760, 60}, { 166, -8, -163}, +{ -306, 1849, 2563}, { -747,-1025,-1783}, { -419, -446, 209}, +{ -718, -566, -534}, { -506, 693, 857}, { -463, -697,-1082}, +{ 325, 431, -206}, { -15, -8, -763}, { 545, 919, 1518}, +{ -611, -783,-1313}, { 256, -55, 208}, { -165, -348, -662}, +{ 321, 680, 930}, { -326, -429, -951}, { 484, 446, 570}, +{ -197, 72, -73}, { 909, 1455, 1741}, { -563, -737,-1974}, +{ -124, -416, 718}, { -478, -404, -314}, { -16, 446, 1636}, +{ -551, -537, -750}, { -58, 638, 214}, { 55, -185, -271}, +{ 1148, 1301, 1212}, { -483, -671,-1264}, { 117, 285, 543}, +{ -204, -391, -111}, { 513, 1538, 854}, { -114, -190, -978}, +{ 877, 595, 464}, { 260, 260, -311}, { 748, 2283, 2216}, +{ -517, -945,-2171}, { -326, -708, 378}, { -812, -691, -232}, +{ -560, 687, 1409}, { -732, -690, -836}, { -359, 645, 386}, +{ -265, 62, -678}, { 145, 1644, 1208}, { -555, -988,-1233}, +{ -78, 14, 114}, { -327, -358, -489}, { 392, 677, 697}, +{ -201, -236,-1140}, { 693, 449, 178}, { -243, 256, -433}, +{ 611, 1385, 2456}, { -612, -901,-1464}, { -307, -17, 499}, +{ -315, -667, -254}, { 256, 428, 1463}, { -486, -422,-1056}, +{ 655, 370, 18}, { -102, -185, -276}, { 755, 1578, 1335}, +{ -488, -603,-1418}, { 182, -93, 870}, { -73, -458, -348}, +{ 835, 862, 957}, { -282, -333, -746}, { 547, 839, 428}, +{ 273, -89, 13}, { 940, 1708, 2576}, { -418,-1084,-1758}, +{ -44, -358, 259}, { -497, -643, -560}, { 99, 557, 961}, +{ -421, -766, -917}, { 295, 326, 184}, { 175, 15, -626}, +{ 532, 878, 1981}, { -443, -768,-1275}, { 221, 156, 268}, +{ 39, -363, -505}, { 695, 772, 1140}, { -162, -459, -912}, +{ 709, 444, 658}, { 25, 303, -312}, { 1268, 1410, 1715}, +{ -297, -766,-1836}, { -263, -108, 1070}, { -406, -13, -129}, +{ 57, 438, 2734}, { -374, -487, -835}, { 304, 696, 164}, +{ 104, -235, 5}, { 1611, 1900, 1399}, { -229, -582,-1325}, +{ 405, 192, 817}, { -87, -438, 111}, { 1028, 1199, 993}, +{ 68, -175, -934}, { 1033, 1117, 451}, { 478, 200, -248}, +{ 2127, 2696, 2042}, { -835,-1323,-2131}, { -799, -692, 466}, +{ -812,-1032, -469}, { -622, 288, 920}, { -701, -841,-1070}, +{ -411, 512, 8}, { -390, -91, -744}, { -30, 1043, 1161}, +{ -822,-1148,-1156}, { -294, -46, 110}, { -411, -374, -678}, +{ 214, 531, 668}, { -406, -420,-1194}, { 487, 232, 303}, +{ -318, 91, -472}, { 123, 1232, 2445}, { -722, -952,-1495}, +{ -738, -675, 1332}, { -543, -606, -211}, { -95, -98, 1508}, +{ -549, -514,-1193}, { 473, 211, 73}, { -288, -112, -389}, +{ 537, 1332, 1258}, { -567, -755,-1545}, { 71, -283, 632}, +{ -170, -481, -493}, { 681, 1002, 817}, { -356, -331, -877}, +{ 419, 706, 346}, { 241, -34, -326}, { 377, 1950, 1883}, +{ -727,-1075,-1625}, { -233, -543, 116}, { -524, -806, -585}, +{ -73, 478, 729}, { -288, -925,-1143}, { 173, 447, -52}, +{ 68, -229, -606}, { 449, 529, 1797}, { -591, -875,-1363}, +{ 183, -144, 324}, { -103, -452, -666}, { 623, 488, 1176}, +{ -238, -511,-1004}, { 326, 552, 458}, { 136, 108, -319}, +{ 626, 1343, 1883}, { -490, -646,-1730}, { -186, -449, 984}, +{ -738, -76, -170}, { -550, 755, 2560}, { -496, -510, -947}, +{ 210, 694, -52}, { 84, -322, -199}, { 1090, 1625, 1224}, +{ -376, -603,-1396}, { 343, 74, 632}, { -175, -502, -32}, +{ 972, 1332, 734}, { 52, -295,-1113}, { 1065, 918, 160}, +{ 393, 107, -397}, { 1214, 2649, 1741}, { -632,-1201,-1891}, +{ -719, -277, 353}, { -651, -880, -122}, { -211, 209, 1338}, +{ -562, -714,-1059}, { -208, 388, 159}, { -320, -61, -551}, +{ 293, 1092, 1443}, { -648, -865,-1253}, { -49, -143, 305}, +{ -401, -227, -585}, { 561, 532, 927}, { -117, -443,-1188}, +{ 507, 436, 292}, { -79, 233, -458}, { 671, 1025, 2396}, +{ -633, -842,-1525}, { -308, -286, 640}, { -373, -621, -407}, +{ 418, 253, 1305}, { -315, -581,-1137}, { 572, 685, -281}, +{ 61, -68, -371}, { 991, 1101, 1498}, { -493, -683,-1362}, +{ -47, 164, 704}, { -256, -314, -268}, { 631, 949, 1052}, +{ -118, -348, -833}, { 68, 1180, 568}, { 152, 117, 34}, +{ 1113, 1902, 2239}, { -601, -959,-1706}, { -143, -489, 480}, +{ -332, -655, -574}, { 54, 353, 1192}, { -462, -652, -796}, +{ 150, 549, 112}, { 195, -111, -515}, { 679, 1108, 1647}, +{ -558, -749,-1217}, { -9, 272, 341}, { -53, -265, -535}, +{ 489, 843, 1298}, { -120, -482,-1032}, { 632, 543, 408}, +{ 179, 306, -526}, { 1124, 1464, 2244}, { -417, -786,-1562}, +{ -224, -384, 1364}, { -377, -459, -25}, { 385, 489, 2174}, +{ -332, -651, -829}, { 544, 553, 61}, { 22, -113, -89}, +{ 1128, 1725, 1524}, { -216, -373,-1653}, { 161, 316, 908}, +{ -165, -222, -67}, { 1362, 1175, 789}, { 73, -252, -767}, +{ 738, 932, 616}, { 362, 246, -126}, { 787, 2654, 3027}, +{ -691,-1106,-2190}, { -565, -588, 524}, { -590, -979, -490}, +{ -263, 397, 982}, { -577, -837, -945}, { -22, 435, -49}, +{ -190, -118, -629}, { -88, 1240, 1513}, { -636,-1051,-1019}, +{ -291, 189, 259}, { -257, -470, -629}, { 145, 945, 894}, +{ -326, -364,-1094}, { 543, 260, 630}, { -202, 189, -209}, +{ 357, 1379, 2091}, { -569,-1075,-1449}, { -714, -239, 919}, +{ -420, -705, -84}, { -109, -114, 2407}, { -413, -529,-1177}, +{ 482, 368, 131}, { -186, -72, -131}, { 861, 1255, 1220}, +{ -611, -658,-1341}, { 227, -121, 631}, { -176, -489, -218}, +{ 745, 1175, 957}, { -321, -148, -936}, { 671, 966, 216}, +{ 340, -3, -143}, { 469, 1848, 2437}, { -729, -961,-1683}, +{ -213, -254, 321}, { -511, -438, -521}, { -126, 725, 903}, +{ -340, -685,-1032}, { 316, 480, 20}, { 23, -89, -551}, +{ 353, 1051, 1789}, { -544, -757,-1364}, { 298, -25, 436}, +{ -100, -392, -519}, { 467, 754, 1078}, { -210, -398,-1078}, +{ 620, 658, 630}, { 33, 147, -178}, { 921, 1687, 1921}, +{ -325, -528,-1978}, { 2, -285, 910}, { -371, -490, -230}, +{ 0, 597, 2010}, { -496, -395, -834}, { 37, 945, 245}, +{ 181, -160, -144}, { 1481, 1373, 1357}, { -355, -601,-1270}, +{ 298, 322, 672}, { -193, -336, 77}, { 1089, 1533, 922}, +{ 177, -39,-1125}, { 996, 781, 536}, { 456, 366, -432}, +{ 1415, 2440, 2279}, { -466, -758,-2325}, { -303, -509, 387}, +{ -727, -557, 66}, { -145, 643, 1248}, { -544, -676, -916}, +{ -225, 862, 588}, { -152, 40, -533}, { 423, 1423, 1558}, +{ -572, -843,-1145}, { -128, 85, 461}, { -238, -257, -584}, +{ 605, 748, 861}, { 24, -202,-1409}, { 797, 487, 303}, +{ -181, 364, -182}, { 616, 1378, 2942}, { -494, -852,-1441}, +{ -292, 61, 812}, { -84, -723, -182}, { 555, 532, 1506}, +{ -365, -493,-1057}, { 822, 588, 11}, { -14, -18, -230}, +{ 1001, 1401, 1451}, { -474, -569,-1292}, { 302, 62, 1062}, +{ -70, -376, -222}, { 982, 974, 1149}, { -196, -234, -795}, +{ 479, 1098, 499}, { 362, 58, 70}, { 1147, 2069, 2857}, +{ -487, -878,-1824}, { 73, -288, 348}, { -358, -500, -508}, +{ 199, 721, 1242}, { -78, -697, -795}, { 361, 536, 196}, +{ 374, 110, -735}, { 847, 1051, 1896}, { -366, -713,-1182}, +{ 315, 320, 429}, { 72, -215, -450}, { 759, 886, 1363}, +{ -30, -428, -834}, { 861, 627, 796}, { 118, 468, -279}, +{ 1355, 1883, 1893}, { -188, -642,-1612}, { 63, -175, 1198}, +{ -418, -211, 51}, { 414, 587, 2601}, { -234, -557, -858}, +{ 424, 889, 222}, { 136, -101, 83}, { 1413, 2278, 1383}, +{ -84, -445,-1389}, { 414, 313, 1045}, { 29, -343, 65}, +{ 1552, 1647, 980}, { 183, -91, -829}, { 1273, 1413, 360}, +{ 553, 272, -107}, { 1587, 3149, 2603} +}; + +static const int16_t lsf_3_1[256][3] = { +{ 6, 82, -131}, { 154, -56, -735}, { 183, -65, -265}, +{ 9, -210, -361}, { 113, 718, 1817}, { 1010, 1214, 1573}, +{ 857, 1333, 2276}, { 827, 1568, 1933}, { 717, 1989, 2206}, +{ 838, 1172, 1823}, { 721, 1000, 2154}, { 286, 476, 1509}, +{ -247, -531, 230}, { 147, -82, 569}, { 26, -177, -944}, +{ -27, -273, 692}, { -164, -264, -183}, { 224, 790, 1039}, +{ 899, 946, 601}, { 485, 771, 1150}, { 524, 677, 903}, +{ -140, 375, 778}, { 410, 676, 429}, { 301, 530, 1009}, +{ 719, 646, 38}, { 226, 367, 40}, { 145, -45, -505}, +{ 290, 121, -121}, { 302, 127, 166}, { -124, -383, -956}, +{ -358, -455, -977}, { 715, 878, 894}, { 978, 923, 211}, +{ 477, 272, 64}, { 188, -78, 17}, { -143, -65, 38}, +{ 643, 586, 621}, { -134, -426, -651}, { 347, 545, 2820}, +{ 1188, 2726, 2442}, { 142, -80, 1735}, { 283, 130, 461}, +{ -262, -399,-1145}, { -411, 155, 430}, { 329, 375, 779}, +{ 53, -226, -139}, { -129, -236, 1682}, { 285, 744, 1327}, +{ 738, 697, 1664}, { 312, 409, 266}, { 325, 720, 135}, +{ 1, 221, 453}, { 8, 203, 145}, { 299, 640, 760}, +{ 29, 468, 638}, { 103, 429, 379}, { 420, 954, 932}, +{ 1326, 1210, 1258}, { 704, 1012, 1152}, { -166, -444, -266}, +{ -316, -130, -376}, { 191, 1151, 1904}, { -240, -543,-1260}, +{ -112, 268, 1207}, { 70, 1062, 1583}, { 278, 1360, 1574}, +{ -258, -272, -768}, { 19, 563, 2240}, { -3, -265, 135}, +{ -295, -591, -388}, { 140, 354, -206}, { -260, -504, -795}, +{ -433, -718,-1319}, { 109, 331, 962}, { -429, -87, 652}, +{ -296, 426, 1019}, { -239, 775, 851}, { 489, 1334, 1073}, +{ -334, -332, 25}, { 543, 1206, 1807}, { 326, 61, 727}, +{ 578, 849, 1405}, { -208, -277, 329}, { -152, 64, 669}, +{ -434, -678, -727}, { -454, -71, 251}, { 605, 480, 254}, +{ -482, 11, 996}, { -289, 395, 486}, { 722, 1049, 1440}, +{ -30, -316, -786}, { -106, -115, -619}, { 861, 1474, 1412}, +{ 1055, 1366, 1184}, { 812, 1237, 925}, { 42, -251, -576}, +{ 342, 141, -454}, { -168, -80, 1359}, { -342, -656,-1763}, +{ 100, 821, 725}, { 990, 747, 800}, { 332, 440, 568}, +{ 663, 379, 852}, { 112, 165, -369}, { 597, 910, 282}, +{ -8, 834, 1281}, { -352, 572, 695}, { 462, 2246, 1806}, +{ 345, 190, 1374}, { 416, 915, 2166}, { 168, -82, 280}, +{ -516, -446, 840}, { 47, 533, 44}, { -362, -711,-1143}, +{ 22, 193, 1472}, { -85, 233, 1813}, { -62, 579, 1504}, +{ 550, 944, 1749}, { 723, 650, 1148}, { 972, 884, 1395}, +{ -425, 643, 0}, { 1000, 952, 1098}, { 249, 1446, 672}, +{ -334, -87, 2172}, { -554, 1882, 2672}, { 140, 1826, 1853}, +{ 920, 1749, 2590}, { 1076, 1933, 2038}, { -137, -443,-1555}, +{ 1269, 1174, 468}, { -493, -122, 1521}, { -451, 1033, 1214}, +{ 482, 1695, 1118}, { 815, 649, 384}, { -446, -692, 107}, +{ -319, -605, -118}, { -207, -505, 525}, { -468, -12, 2736}, +{ 75, 1934, 1305}, { 880, 2358, 2267}, { 1285, 1575, 2004}, +{ -48, -304,-1186}, { -435, -461, -251}, { -366, -404, -547}, +{ -289, -605, -597}, { -538, -810, -165}, { -120, 3, 356}, +{ 639, 1241, 1502}, { 96, 177, 750}, { -435, -585,-1174}, +{ -356, 109, -79}, { -485, 288, 2005}, { 9, 1116, 731}, +{ 880, 2134, 946}, { -265, 1585, 1065}, { 1157, 1210, 843}, +{ -498, -668, 431}, { 374, 321, -229}, { 1440, 2101, 1381}, +{ 449, 461, 1155}, { -105, 39, -384}, { -263, 367, 182}, +{ -371, -660, 773}, { -188, 1151, 971}, { 1333, 1632, 1435}, +{ 774, 1267, 1221}, { -482, -832,-1489}, { -237, -210, 860}, +{ 890, 1615, 1064}, { 472, 1062, 1192}, { 185, 1077, 989}, +{ -568, -992,-1704}, { -449, -902,-2043}, { -142, -377, -458}, +{ -210, -554,-1029}, { -11, 1133, 2265}, { -329, -675, -893}, +{ -250, 657, 1187}, { 519, 1510, 1779}, { 520, 539, 1403}, +{ 527, 1421, 1302}, { -563, -871,-1248}, { -147, -463, 879}, +{ -76, 2334, 2840}, { 563, 2573, 2385}, { 632, 1926, 2920}, +{ 719, 2023, 1840}, { -545, -723, 1108}, { 129, -125, 884}, +{ 1417, 1632, 925}, { -94, 1566, 1751}, { -341, 1533, 1551}, +{ 591, 395, -274}, { -76, 981, 2831}, { 153, 2985, 1844}, +{ 1032, 2565, 2749}, { 1508, 2832, 1879}, { 791, 1199, 538}, +{ -190, -453, 1489}, { -278, -548, 1158}, { -245, 1941, 2044}, +{ 1024, 1560, 1650}, { 512, 253, 466}, { -62, -323, 1151}, +{ -473, -376, 507}, { -433, 1380, 2162}, { 899, 1943, 1445}, +{ 134, 704, 440}, { 460, 525, -28}, { -450, 279, 1338}, +{ 0, 971, 252}, { -445, -627, -991}, { -348, -602,-1424}, +{ 398, 712, 1656}, { -107, 314, -178}, { 93, 2226, 2238}, +{ 518, 849, 656}, { -462, -711, -447}, { 174, -34, 1191}, +{ -119, 42, 1005}, { -372, 274, 758}, { 1036, 2352, 1838}, +{ 675, 1724, 1498}, { 430, 1286, 2133}, { -129, -439, 0}, +{ -373, 800, 2144}, { 6, 1587, 2478}, { 478, 596, 2128}, +{ -428, -736, 1505}, { 385, 178, 980}, { 139, 449, 1225}, +{ -526, -842, -982}, { 145, 1554, 1242}, { 623, 1448, 656}, +{ 349, 1016, 1482}, { 31, -280, 415}, { -316, 724, 1641}, +{ 360, 1058, 556}, { -436, -358, 1201}, { -355, 1123, 1939}, +{ 401, 1584, 2248}, { -527,-1012, 355}, { 233, 238, 2233}, +{ -550, -897, -639}, { -365, -501, 1957}, { 389, 1860, 1621}, +{ 162, 1132, 1264}, { -237, 1174, 1390}, { -640, -411, 116}, +{ -228, 1694, 2298}, { 1639, 2186, 2267}, { 562, 1273, 2658}, +{ 323, 338, 1774}, { 578, 1107, 852}, { 22, 594, 934}, +{ -143, 718, 446} +}; + + +static const int16_t lsf_3_2[512][3] = { +{ 50, 71, -9}, { -338, -698,-1407}, { 102, -138, -820}, +{ -310, -469,-1147}, { 414, 67, -267}, { 1060, 814, 1441}, +{ 1548, 1360, 1272}, { 1754, 1895, 1661}, { 2019, 2133, 1820}, +{ 1808, 2318, 1845}, { 644, -93, 454}, { 858, 329, -136}, +{ 489, -258, -128}, { -198, -745, -41}, { -52, -265, -985}, +{ 346, 137, 479}, {-1741, -748, -684}, {-1163,-1725, -367}, +{ -895,-1145, -784}, { -488, -946, -968}, { -85, -390, -725}, +{ 215, -340, -171}, { 1020, 916, 1969}, { 564, 179, 746}, +{ 662, 977, 1734}, { 887, 622, 914}, { 939, 856, 1165}, +{ 309, 688, 803}, { 917, 161, 570}, { 118, -20, -283}, +{ -816, -42, 204}, {-1228, -325, -462}, { -963, -202, -143}, +{ -988, -484, -361}, { -702, -978, -477}, { -302, -790,-1188}, +{ -100, -786,-1088}, {-1054, -947,-1684}, { -202, -843, -782}, +{-1039,-1378, -901}, { -624, -110, -85}, { 356, 213, -10}, +{ -493, 364, 774}, { 425, 822, 479}, { -83, 557, 520}, +{ -992,-1560, -572}, { -603, -741, -26}, { -502, -638, -903}, +{ 209, 306, 147}, { -316, -593, -596}, { -85, -211, -225}, +{ -918, -529, 117}, { 233, -439, -738}, { 1101, 751, 633}, +{ 1457, 1716, 1511}, { 1765, 1457, 910}, { 1122, 1156, 849}, +{ 1354, 868, 470}, { -871,-1150,-1796}, { -871, -861, -992}, +{ -118, 155, 212}, {-1051, -849, -606}, {-1117,-1849,-2750}, +{-1019,-1427,-1869}, { 370, -184, -414}, { 959, 493, 104}, +{ 958, 1039, 543}, { 154, 653, 201}, { 1249, 507, 150}, +{ 663, 503, 230}, { 623, 777, 675}, { 659, 88, -110}, +{ 843, 244, 224}, { 382, 541, 302}, { 724, 433, 666}, +{ 1166, 734, 341}, { -138, 20, -397}, {-1183, -424, -46}, +{ -321, -352, -124}, { 1333, 1021, 1080}, { 262, 366, 723}, +{ 922, 283, -551}, { 31, -636, -611}, { -689, -697, -415}, +{ -952, -779, -201}, {-1329, -598, -359}, { -953,-1285, 166}, +{ 493, 305, 221}, { 846, 703, 610}, { 840, 936, 774}, +{ -723,-1324,-1261}, { -357,-1025,-1388}, {-1096,-1376, -365}, +{-1416,-1881, -608}, {-1798,-1727, -674}, { -545,-1173, -703}, +{ 678, 786, 148}, { -123, 696, 1288}, { 644, 350, -10}, +{ 414, 614, 15}, { 137, 344, -211}, { -814,-1512, -819}, +{ -391, -930, -588}, { 47, -591, -898}, { -909,-1097, -163}, +{-1272,-1167, -157}, {-1464,-1525, -389}, {-1274,-1188, -624}, +{ 671, 213, 454}, { 124, -274, -525}, { -729, -496, -152}, +{-1344, 122, 135}, {-2905, -589, -394}, {-1728, 441, -50}, +{ 1476, 904, 787}, { 316, 236, -440}, { -347, 217, 413}, +{ -911, -917, 121}, { -455, -932, 202}, { -92, -465, -375}, +{ 488, 390, 474}, { 876, 729, 316}, {-1815,-1312, -669}, +{ 87, 962, 432}, { 563, -249,-1058}, { 250, 285, 1105}, +{ 1141, 427, 696}, {-1038,-1664,-1582}, { -948, 346, 160}, +{ -309, -272, -858}, { 670, 624, 1250}, { -944, -408, -666}, +{ -606, -320, -384}, { -492, 230, 65}, { 334, -50, -16}, +{ -16, -690,-1397}, { 1791, 1716, 1399}, { 2478, 2063, 1404}, +{ 1245, 1471, 1426}, { -382,-1037, -2}, { 173, -398, 1145}, +{ 1491, 2024, 1801}, { 772, 1274, 1506}, { 1429, 1735, 2001}, +{ 1079, 1218, 1273}, {-1154,-1851,-1329}, { -808,-1133,-1096}, +{ -451,-1033,-1722}, { 65, 578, -84}, {-1476,-2434,-1778}, +{ -765,-1366, -494}, { -218, -594, -931}, { 337, -236, 562}, +{ 2357, 2662, 1938}, { 1489, 1276, 874}, { 189, 358, 374}, +{-1519,-2281,-2346}, { -967,-1271,-2095}, { -628,-1188,-1542}, +{ 1661, 1043, 546}, { 565, 1061, 732}, { -64, -836, -434}, +{ -436, -96, 203}, { 1078, 1216, 1636}, { 907, 1534, 986}, +{ 326, 965, 845}, { 142, -84, 197}, { 470, 2379, 1570}, +{ 1133, 470, 1214}, { 395, 1376, 1200}, { 1125, 1042, 348}, +{ -543,-1234, -376}, { -215, -181, 481}, {-1947,-1621, -210}, +{ -750,-1185, 390}, { 29, -399, 27}, { 820, 1236, 755}, +{ 695, 979, 409}, { -174, 1197, 1035}, { 912, 1356, 1846}, +{ -992,-1437, 484}, {-1485,-1700, 208}, { -412, 1204, 1432}, +{ -271, 896, 1144}, { -416, 1777, 1434}, {-1696,-2644, -204}, +{-1789,-1551, 1033}, {-1656,-1559, 1303}, {-1253,-1589, 1081}, +{ -669,-1095, -66}, { -682, 320, -345}, { 659, 305, 1069}, +{-1292, -804, -19}, {-1635,-1291, 29}, {-1683, -497, 71}, +{ -287, -7, -100}, { -494, -962, -237}, { 852, 1881, 1740}, +{-1217,-1387, 227}, { -660, 302, 373}, { 96, 1087, 1257}, +{-1074,-1669, 160}, { 485, 2076, 1798}, { -934, -220, 552}, +{ -596, -612, 237}, { 336, 1720, 879}, { 643, 629, 434}, +{ 1267, 522, 1633}, { 15, 244, -441}, { 1475, 717, 184}, +{ 1819, 1590, 1709}, { 988, 261, 937}, { 2093, 2345, 1520}, +{ 2139, 1858, 1606}, { -577, -579,-1203}, { -956, 135, -488}, +{ -464, 51, -338}, { -629, -348, -723}, { 1146, 2073, 1442}, +{ 2192, 1466, 911}, {-1444,-1572,-2278}, { 1400, 710, 1297}, +{ 1335, 633, 928}, { 1434, 2194, 2594}, { 2422, 2204, 1881}, +{ 982, 2242, 1854}, { 380, 792, 1145}, { -63, -539, 414}, +{ -252, -964, -314}, {-1261, -683, -780}, { -831, -526,-1005}, +{-1666,-1135, -424}, {-1611, -452, -299}, { 1268, 1048, 642}, +{ 1147, 853, 856}, { -675, -336, 139}, { 2268, 1343, 1418}, +{ 29, 768, 797}, {-1224, 423, 564}, {-1318,-1082, 245}, +{-1302, -812, 573}, {-1298,-1617, 646}, { -968, 834, 723}, +{ 993, 1652, 2027}, { -191, -817, 432}, { 662, 60, 198}, +{ 626, 997, 1330}, { 1648, 1963, 1289}, {-1597, -93, -45}, +{-1088, 37, -84}, { 1653, 2607, 2337}, { 1065, 2040, 2377}, +{ 1139, 2326, 2118}, { 859, 357, 1510}, { 664, 1227, 1099}, +{ 479, 1360, 912}, { 1897, 1754, 2019}, { 1168, 1909, 1784}, +{ 399, 34, 256}, { -593, -304,-1053}, { 547, 1694, 1407}, +{ 647, -99, -341}, { 1492, 1647, 1190}, { 38, -644, -212}, +{ 395, 846, 222}, { -704, -765, -716}, { -724,-1964,-2804}, +{ -150, 291, -82}, { 1233, 1459, 1007}, { -140, -155, 153}, +{ 439, 297, 1568}, {-1529, -410, -636}, { 1536, 455, -237}, +{-1328, -139, -260}, { 531, 554, 868}, { 269, 1264, 606}, +{ -233, 883, 463}, { 742, 600, -120}, { -73, 421, 212}, +{ -439, -58, 804}, {-1286,-1241, 728}, { 294, -490, 50}, +{ -591, -905,-1254}, { 42, -687, 147}, { -25, 273, 596}, +{ -311, 1213, 601}, { -754, 849, 584}, { 429, 607, 587}, +{ -602, -166, 461}, { -796, -823, 777}, { 1380, 910, 1755}, +{ 119, 1417, 972}, { -219, -880,-1596}, {-1049,-1010, 438}, +{ -713,-1379, 78}, { 0, -447,-1179}, {-1136,-1319,-1573}, +{ 2248, 1767, 1309}, { 946, 1583, 1432}, { 1150, 482, 436}, +{ -469,-1108, 618}, { -447, -966, 1088}, {-1252,-1515, -114}, +{-1104,-2008, -579}, { 210, 613, 497}, {-1975,-1437, 642}, +{-1269, -856, 1011}, {-1646,-1185, 1063}, {-1555, -672, 1204}, +{-1692,-1114, 623}, { -979,-1326,-1277}, { 539, -147, 894}, +{-1354, -897, -434}, { 888, 475, 428}, { 153, -384, 338}, +{-1492, -511, 359}, { -974,-1115, -470}, { 105, -550, 677}, +{ -937,-1145, 877}, { 380, -260, 210}, { 1685, 924, 1256}, +{ 1775, 1190, 1095}, { 1419, 631, 533}, { 627, 299, -347}, +{ -411, -534, 647}, { -650, 29, -595}, { -378,-1367, 1563}, +{ 1402, 1121, 1465}, { 1089, 1410, 648}, {-2096,-1090, -6}, +{ 311, -194, -869}, { -639, -831, 416}, {-1162,-1224, 1349}, +{-1247, -941, 1813}, {-2193,-1987, 453}, { -619,-1367, -956}, +{-1606,-1972,-1507}, {-1175,-1057,-1104}, { -377, 601, 201}, +{ 1876, 825, 374}, { -430,-1323, 29}, {-1397,-1249,-1331}, +{-1007,-1504, 960}, {-1401,-2009, 197}, {-1379,-1949, -236}, +{-1077, 123, 422}, { 615, 1269, 546}, { -306, 1526, 904}, +{ 1194, 1788, 1177}, { -626, -884,-1526}, { 199, 766, 1504}, +{-1065, 862, 197}, {-1034,-1773, -887}, { -800, 145, 599}, +{-1134, -519, 626}, {-1205,-1926, 500}, { -910,-1041,-1395}, +{-1476,-1567, -969}, { -523, 842, 34}, { 1794, 646, 862}, +{-1207,-1888,-1002}, { -78, -9, -672}, { 1044, 759, 80}, +{ -600, 1139, 1019}, { 57, 2000, 1422}, { -833, 1414, 1121}, +{-1202, 1630, 1260}, { -461, 1420, 1244}, { 1537, 975, 253}, +{ -283, 324, -359}, { 599, -195, 106}, { 588, 62, -587}, +{ -757, 645, 205}, { 51, 1201, 758}, {-1209, 673, -390}, +{ -624, 1581, 941}, { -151, 1023, 735}, { 2820, 1301, 690}, +{ -302, 524, -99}, { -900,-1588,-1189}, { 1084, 251, 238}, +{ 2014, 1792, 1010}, { 1245, 1633, 1741}, {-1227,-1540,-1208}, +{ -621, 456, -109}, { 40, -65, 788}, { -805, -699,-1350}, +{ -583, 904, 832}, { -801, 532, 594}, { 1972, 1408, 1351}, +{-1177,-1880,-2114}, { -773, 568, 948}, {-1015, 1079, 1260}, +{-1111, 482, -130}, { 1778, 1044, 780}, {-1491, 245, 912}, +{ -316,-1141, -917}, { -536,-1442,-2346}, { -785,-1546,-1988}, +{-2003, 257, 909}, {-1849, -633,-1209}, {-1538,-1918,-1054}, +{ 1606, 2239, 1576}, { -567,-1500,-1544}, {-1279, 195, 1369}, +{ -817, 293, 1219}, { -525, 630, 1197}, {-1698,-2425,-1840}, +{ -303, 731, 747}, {-1169, -251, 269}, { -950, -75, 1684}, +{-1182, -453, 1005}, {-1599, 585, 378}, {-2075, -571, -427}, +{ -529,-1159,-1171}, { -283, -205, -564}, { -796, 1246, 717}, +{ 2277, 927, 539}, { -454, 559, 440}, { -717, 1460, 1615}, +{-1030, 1052, 1610}, {-1169, -138, 847}, { 226, 39, -612}, +{-1251, -106, -729}, { -651, 968, 1302}, { -714, -636, 1727}, +{ 353, 1069, 410}, { -798, -156, 1099}, { -574, 918, 446}, +{-1310, 1012, 466}, { 1408, 1591, 765}, { 1429, 1380, 1757}, +{ 1949, 1956, 2378}, { 1578, 2047, 2148}, { 916, 98, -7}, +{ 1893, 1418, 2141}, { 348, 1405, 1579}, { 152, 1134, 1801}, +{ -267, 154, 1395}, {-1166, 469, 1054}, {-1142, -405,-1073}, +{-1341,-2264,-1581}, { -364, 869, 1706}, {-1162, 549, 1550}, +{-1225,-1932,-1666}, {-1485,-1977,-2055}, {-1727, -906, -98}, +{-1897, 233, 1492}, { 892, 108, -331}, {-1728,-1170,-1700}, +{-1060, 1980, 1790}, {-1070,-1741,-1909}, { -11, 1539, 1317}, +{-1600, 94, 497}, { 421, 443, -197}, {-1578, -349, -994}, +{ -599, -539, 1140}, { -965,-1419, -129}, {-1341, 175, -447}, +{ -375, 1311, 2055}, { -371, -650, -307}, {-1073, 605, 365}, +{-2057, -113, 430}, { 652, 914, 967}, {-1012,-1586,-2323}, +{ 1505, 1248, 559}, { 262, -486, -401}, {-1727, 1342, 1546}, +{ 50, 56, 432}, { -330, 119, -604}, {-1517,-1080, -810}, +{ 946, 1127, 1055}, {-1400,-1703,-1712}, {-1270, -704,-1317}, +{ 807, 1821, 1143}, { 2760, 1606, 2171}, { 1120, 409, -150}, +{ -147, 404, 959}, { 2439, 1911, 2189}, { -906, -141, -866}, +{ -904, -142, -458}, { -557, -708,-1679}, { -830,-1431,-1583}, +{-1842,-1346,-1086}, {-1604, -272, 915}, {-1196, 772, 1056}, +{ -638,-1234,-1897}, { -500, -81, -822}, {-1289,-1613, -735}, +{ -117, 785, 168}, {-1090, 1133, 922}, {-1096, -746, 1384}, +{ 287, -547,-1063}, {-1376,-2201,-1204}, {-2176,-1570,-1757}, +{-1511,-2241, -771}, {-1737, 1099, 830}, {-1588, 724, 1243}, +{-1542, 693, 805}, {-1690, -240, 1665}, {-1700, -4, -668}, +{ 2149, 816, 1042}, { -818,-1841, 22}, { -764, -507, 449}, +{-1151, -617, 289}, { -843,-1596, -240}, { 498, -234, -657}, +{ -752, 480, 1678}, { -319, -481, 193}, { -811, 171, -119}, +{-2128, -202, -848}, { 1717, 1140, 1700} +}; + +static const int16_t lsf_3_3[512][4] = { +{ 67, -17, 66, -12}, {-1690, -581, -104, -272}, {-1076,-1186,-1845, -376}, +{-1140, -926, -420, -58}, { -259, -656,-1134, -553}, { 1788, 1227, 455, 129}, +{ 462, 441, -240, -528}, { 840, 514, 130, -75}, { 1114, 623, 153, 216}, +{ 1068, 564, -6, -276}, { 1119, 727, 190, -68}, { 704, 306, 119, -264}, +{ 329, 61, -100, 156}, { 364, 123, 183, -208}, { -171, -123, 220, -65}, +{ -306, -62, 402, 17}, { -660, -938, -266, 0}, { 385, 235, 276, 285}, +{ 320, 268, -336, -200}, { -724, 17, -84, 381}, { -544, 429, 494, 519}, +{ -117, 288, 304, 329}, { 643, 157, 701, 508}, { 1200, 625, 796, 608}, +{ 998, 421, 492, 632}, { 1204, 780, 446, 132}, { 1257, 844, 547, 449}, +{ 829, 658, 541, 470}, { 1132, 1258, 918, 639}, { 547, 51, 423, 279}, +{ 9, 392, 83, 94}, { 542, 543, 229, -147}, { -198, 129, 194, -185}, +{ -863,-1321, -302, 30}, { -597, -629, -19, 114}, { -900,-1081, 466, 353}, +{-1483,-1573, 15, -143}, {-1708,-2059, -751, 196}, {-1876,-2067, -642, -258}, +{-2335,-1470, -450, -564}, { -584, -186, -872, -414}, {-1805, -988,-1125,-1310}, +{ -726,-1129, 28, 169}, {-1039, -864, -718, -246}, { 484, 36, -233, -49}, +{ 265, 67, 289, 467}, { 178, 543, 810, 540}, { 84, 282, 672, 703}, +{ -975, -777, 129, 287}, { -938, -227, 955, 595}, {-1617, -289, 836, 649}, +{-1847, -215, 1106, 718}, {-2034,-1085, 650, 440}, {-2101, -529, 907, 575}, +{-2011, -336, 670, 204}, {-2389, -692, 360, 137}, {-2156,-2204, -9, 280}, +{ -266, 119, 39, 193}, { 78, -59, -120, 226}, { -975, -858, -781,-1095}, +{ -619, -413, -451, -842}, {-1216,-1321, -813, -883}, {-1376,-1615, -394, -428}, +{ -737,-1113, -549, -790}, { -880, -975, -967, -642}, { -985, -886,-1273,-1361}, +{ -473, -804,-1401,-1407}, { 160, -265, -919, -275}, { -248, -250, -718, -380}, +{ 97, -103, -375, -229}, { -415, -193, -135, -555}, { 628, 361, 119, 216}, +{ 579, 364, 391, 209}, { 634, 522, -154, -148}, { 526, 389, 170, 33}, +{ 105, 267, 64, 380}, {-1503,-1000, -30, -369}, {-1070, 58, 647, 223}, +{-1520, -291, 621, 307}, {-1531, 156, 762, 404}, {-2029, 141, 734, 499}, +{-1849, -650, 306, 512}, { -187, -104, -59, 438}, { 134, -230, 156, -186}, +{ -61, -260, -16, 10}, { -569, -3, -421, -297}, {-1725, -521, -346, 178}, +{-1362, -59, -44, 157}, {-2146, -461, -470, -349}, {-2170, -1, -369, -121}, +{-1579, -373, -900,-1015}, {-1117, -591, -613, -784}, { -561, 122, -75, -449}, +{ -4, -171, -123, -372}, { 192, 168, -76, -132}, { 252, -107, 340, 210}, +{ 392, 509, 272, 181}, { -109, 145, 218, 119}, { -416, -263, 485, 265}, +{ -181, -8, -286, 226}, { -244, -218, 69, -290}, { -158, 191, -1, -64}, +{ -592, -90, 213, -96}, { 255, 435, 178, -80}, { -369, -18, -33, -80}, +{ -42, 415, 140, -222}, { 1143, 651, 649, 329}, { 767, 556, 249, 235}, +{ 948, 413, 442, 279}, { 141, 339, 356, 557}, { -470, -170, 99, 237}, +{ -569, -800, 352, 565}, { 282, 473, 470, 332}, { -199, -690,-1284, -917}, +{ -193, -426, -800,-1122}, { -26, -371, -490, -193}, { 637, 595, 519, 330}, +{ 408, -115, 79, 12}, { 477, 87, -103, -376}, { -666, -347, -277, -291}, +{ -510, -481, 169, 297}, { -829, -738, -205, -171}, { -320, -540, 328, 283}, +{ -859, -958, 442, -2}, { 556, 686, 130, 56}, { 1383, 1012, 755, 427}, +{ 612, 741, 628, 553}, { -339, -796, 134, 277}, { -633,-1085, -2, -246}, +{ -880,-1035,-1607,-1064}, { -994, -474,-1138, -488}, { -414, -795, 73, -206}, +{ -8, -139, 439, 204}, { -176, -578, 23, 131}, { -269, -757, -191, 245}, +{ -109, -338, 112, 316}, { 120, -406, -118, 611}, { -180, -186, -645, 115}, +{ -173, 34, -518, -489}, { -151, 61, -583, -844}, { 220, -138, -681,-1020}, +{ 391, -17, -598, -321}, { 157, -295, 129, 155}, { -926, -875, -987, 285}, +{ 241, -83, -125, -125}, { 620, 597, 432, 92}, { 393, 78, 409, 61}, +{ -393, -739, -413, -748}, { 83, 54, 361, 27}, {-1084, 130, -337, -694}, +{-1565, 297, 318, -19}, {-1873, 36, 51, -317}, {-2323, -246, 231, -84}, +{-2306, -783, 40, -179}, {-2233, -930, -474, -462}, { -754, -86, -288, -626}, +{-2411, -455, -63, 171}, {-1099,-1094, -26, -143}, {-1193, -455, -406, -381}, +{ -605, -210, -96, -51}, { -580, -476, -276, -15}, {-1195, -634,-1203, -881}, +{ -378, -221, -669, -952}, { 594, 178, -403, -676}, { 763, 327, 601, 290}, +{ 172, 300, 203, 157}, { -56, -336, 356, 24}, { -228, -296, -259, -29}, +{ -186, 263, 416, 14}, { -353, 373, -12, -216}, { 257, 96, 174, 57}, +{-1526, -616, -954, -499}, { -497, -152, -333, 125}, { 105, 200, 179, -97}, +{ -331, -224, 765, 697}, { 760, 256, 301, 59}, { 455, -85, 204, 288}, +{ -514, 240, 251, -109}, { 256, 417, -34, -413}, { 101, 430, 384, 156}, +{ -31, -10, 206, 426}, { 589, 145, 143, 71}, { 808, 906, 333, 349}, +{ 986, 938, 589, 331}, { 1300, 824, 187, 509}, { 1062, 653, 379, 466}, +{ 1462, 937, 401, 274}, { 787, 861, 265, 2}, { 609, 553, 28, 305}, +{ 926, 340, 106, 386}, { 241, -267, -147, 225}, { -178, -534, 347, 502}, +{ -643, -381, 397, 30}, { -651, -733, -435, 398}, { -407, -726, -484, -248}, +{ -789, -914, -438, -476}, { -498, -390, 75, -295}, { -964, -590, -606, 150}, +{ -121, -49, -155, -78}, { 935, 550, 389, 38}, { -321, 127, 424, 315}, +{ -285, -113, 283, 259}, { 658, 203, 322, 486}, { 903, 505, 748, 417}, +{ 611, 423, 555, 512}, { 239, -83, -578, -19}, { -339, -731, 349, 13}, +{ -934,-1399, -114, -360}, { 107, 692, 182, 90}, {-1243,-1538,-1551, -725}, +{ -568, -903,-1363, -525}, { -517, -853, -861,-1004}, { -168, -690, -835, 63}, +{ -137, -556, -547, 144}, { -286, -817, 485, 319}, { -147, -408, 526, 246}, +{ -347, -434, 297, -28}, { -290, -471,-1110,-1285}, { -460, -359, -988, -794}, +{ 1347, 1299, 690, 523}, { 1216, 1068, 1094, 757}, { 825, 1140, 752, 494}, +{ 1252, 1365, 1195, 898}, { 521, 1053, 532, 432}, { -334, -216, -313, -263}, +{ -160, 52, -472, -155}, { 127, 136, -380, 44}, { 851, 410, -162, -489}, +{ 123, -255, -796, -667}, { 1090, 917, 789, 493}, { 1397, 1197, 558, 202}, +{ -51, -118, -342, -701}, { 83, 108, -42, -441}, { 61, 95, 287, 256}, +{ -27, 89, 524, 531}, { 351, 227, 592, 545}, { 697, 155, -164, 307}, +{ 638, 274, -489, -50}, { 754, 240, -166, -124}, { -116, -579,-1212, -63}, +{ 190, -295,-1040,-1296}, { 147, -376, -177, -113}, { 841, 1241, 1051, 668}, +{ 2, 293, 551, 304}, {-1096, -953, -248, 376}, { -750, -965, 87, 516}, +{ -275, -516, 689, 391}, { -379, -643, 876, 594}, { -390,-1013, -645, 573}, +{ -107, -568, -689, -826}, {-1025, -27, -328, -203}, { 861, 749, 548, 233}, +{-1660,-1043, 451, 108}, { -660, -620, 430, 236}, { 21, -396,-1158, -631}, +{ 1372, 1298, 967, 577}, { 1125, 1125, 589, 454}, { -323, -865, -467, 153}, +{ -468, -699, -804, -509}, { -392, -718, -204, -35}, { -603,-1093, -567, -162}, +{ -505,-1004, -102, 350}, { 219, 224, 423, 252}, { 395, 591, 608, 363}, +{ -746, -96, 373, 172}, { 171, 295, 714, 339}, { 233, 77, 107, 277}, +{ 157, 153, -499, -356}, { 1547, 1073, 576, 494}, { -292, -339, -504, -592}, +{ -903, -72, -619, -481}, {-1594,-1117, -567, -254}, { -793, -507, -564, -291}, +{ -492, -532, 502, 560}, { -382, 427, 600, 230}, { -227, 477, 251, 75}, +{ 285, 842, 813, 476}, {-1310,-1333, 186, 377}, { -587, -917, 643, 381}, +{-1186, -553, 411, 82}, {-1127, -820, -174, -540}, { -604, 119, 543, 205}, +{ -380, 657, 909, 567}, { 112, -298, -374, 114}, { -857, -251, 56, 159}, +{ 401, 345, -34, -140}, { -111, -607, 41, 614}, { 355, -114, -77, 474}, +{ 578, 56, 1450, 924}, { 1098, 1420, 741, 400}, { 246, 22, 588, 313}, +{ -121, 327, 831, 472}, {-1138, -608, 856, 552}, {-1241,-1072, 638, 600}, +{ -358, 254, -333, -303}, { -646, 739, 358, 74}, { 1226, 1671, 1221, 849}, +{ 2241, 1624, 983, 636}, { 1841, 1477, 749, 384}, { 350, 263, 87, 128}, +{-1902, -941, -144, -64}, {-1734, -255, 288, -31}, {-2644,-1238, 366, 235}, +{-1643,-1092,-1344, -304}, { -541,-1075,-1116, 123}, {-1178, -252, -816, -180}, +{-1016, 533, 565, 233}, { -487, -430, -188, 334}, { 867, 1236, 534, 171}, +{-1590,-1607, 635, 630}, {-2196, 310, 924, 412}, {-2358, -328, 956, 529}, +{-2639, -377, 630, 278}, {-2602, 317, 799, 299}, {-2406, 133, 340, 31}, +{-2156,-1468, 131, 125}, {-1184, -490, -139, 46}, { -744, 447, 891, 564}, +{ 67, -451, 646, 604}, { -553, -429, -876, 396}, { 162, -66, 1305, 915}, +{ 479, 579, 1088, 794}, { 450, 278, 566, 324}, {-1057, -154, 148, -177}, +{-2545, 168, 1070, 592}, {-2351, -42, 819, 345}, {-2344, -707, 721, 250}, +{-2175,-1497, -309, 122}, { -78, -73, 120, 173}, { -4, 262, -263, -261}, +{ -431, -64, -405, -732}, {-2609, 116, -83, -193}, {-1525, -944, -477, -725}, +{ -508, 307, 170, 172}, { 832, 417, 832, 686}, { -225, 177, 894, 818}, +{ -482, -389, 1279, 1039}, { -383, 201, -350, 40}, { 730, 635, 226, 526}, +{ 503, 462, 338, 398}, { 535, 714, 40, -282}, { 1482, 1471, 1085, 731}, +{ 1561, 1072, 909, 693}, { 1419, 1282, 889, 879}, { 1153, 728, 1186, 840}, +{ -226, 1130, 949, 689}, { -494, -986,-1556, -128}, { -568, -721, -713, -26}, +{ 317, 524, 70, 135}, { -405, -865,-1766, -652}, { -174, -801, 885, 773}, +{ -153, -91, 1099, 751}, { -506,-1149, 853, 646}, { 241, 782, 519, 539}, +{ 1853, 1700, 1101, 684}, {-1249,-1486, -464, 188}, { -893,-1409,-1312, -341}, +{ -135, 438, -175, 18}, { 1111, 976, 319, 208}, {-1430,-1768, 83, 458}, +{ -530,-1000, 307, 129}, { -840, -15, -29, -356}, { -911, -924,-1147, -242}, +{ -119, -528, 127, -133}, { -761, -765, 190, -83}, { -315, 895, 522, 231}, +{ -222, 102, -63, -428}, { 316, 699, 379, 70}, { 25, 716, 314, -108}, +{ 507, 874, 566, 238}, { 108, 941, 519, 195}, { 425, -60, -427, 257}, +{ 139, -103, -630, 446}, { 334, 370, 412, 48}, { -172, -690, -283, 557}, +{ 187, -286, 158, 483}, { 140, 270, -344, -631}, { 924, 579, -116, 132}, +{ 142, 466, -68, -64}, { 230, -145, -302, -542}, { -803, -912, 1018, 737}, +{ -773, 1015, 630, 297}, {-2596, 95, 445, 336}, {-2122, 491, 510, 191}, +{-1253, 161, -2, -324}, {-1450, -633, -712, -105}, { -842, -254, -411, 100}, +{ -640, -290, 1010, 763}, { -650, 313, 1169, 730}, { 140, 505, 1030, 766}, +{ 772, 287, 1067, 823}, { 495, 749, 305, 323}, { -164, 462, 78, 399}, +{ -342, -874, 69, 597}, { -16, 620, 621, 337}, { -138, -444, -265, 218}, +{ 84, -450, 953, 666}, { -222, -803, 541, 604}, { -921,-1376, 244, 116}, +{ -841, -723, 630, 588}, { 140, 663, 294, 368}, { 935, 1046, 881, 759}, +{ 1746, 1464, 916, 628}, { 436, 963, 281, 1}, { -119, 74, 542, 213}, +{ 1, -567, 301, 241}, { 260, 435, 222, 396}, { 936, 957, 1108, 703}, +{ 510, 506, 808, 478}, { 601, 694, 960, 620}, { 972, 741, 980, 600}, +{ 834, 717, 767, 684}, { 643, 972, 935, 638}, { 501, 661, 720, 851}, +{ -105, -632, -303, -117}, { -429, 130, 789, 442}, { -522, -188, 704, 373}, +{ -759, 42, 814, 523}, { -531,-1137, 373, 578}, { -682,-1203, -455, 285}, +{-1163,-1577,-1098, 44}, { 81, -82, 712, 363}, { 477, 246, 954, 622}, +{ 1604, 1622, 1277, 891}, { 1409, 859, 924, 892}, { 774, 1041, 947, 1142}, +{ 40, -546, -75, 288}, { -616, -106, -697, -26}, { -169, -160, -891, -739}, +{ -279, -384,-1029, -350}, { 1781, 1308, 1046, 816}, { 1580, 1533, 1472, 1178}, +{ 1505, 1076, 1216, 899}, { 890, 904, 564, 654}, { 920, 692, 1021, 856}, +{ -493, 132, 177, 505}, { 71, 195, -28, 97}, { 456, 351, -164, 88}, +{ 439, 278, -40, 350}, { 1395, 949, 234, -95}, { -805, -472, 38, -163}, +{ 367, -98, 489, 523}, { 1025, 1178, 1212, 906}, { 319, 1314, 814, 461}, +{ -123, -543, -804, 447}, { -748, -324, -897,-1127}, { -737, -501, -789, -713}, +{ 715, 777, 1239, 922}, { 1949, 1939, 1368, 865}, { 730, 880, 758, 388}, +{ -871, 454, 17, -251}, { -381, -810,-1583, 239}, { -521, -966, -792, 259}, +{ -890,-1358, -770, -73}, { 166, 349, -212, 323}, { -840, -301, 473, 435}, +{ -679, -464, 728, 351}, { -156, -199, 667, 432}, { 29, -252, 415, 480}, +{ -731, -379, 145, 559}, { -528, -631,-1158, -159}, { 445, 273, 123, 639}, +{ 373, -126, 800, 568}, { 84, -162, 720, 712}, { -830, -536, -185, 222}, +{ 408, 452, 501, 771}, { -897,-1355, -67, 442}, { -792,-1406, 566, 602}, +{ 167, -326, 509, 330}, { -95, -626, -730, -344}, { 1668, 1217, 779, 455}, +{ 1316, 828, 584, 719}, { 404, -31, 1013, 789}, { 89, 107, 891, 549}, +{ 871, 1581, 917, 671}, { 866, 1479, 1289, 854}, { 391, 1068, 1122, 812}, +{ 78, -562, 345, 563}, { 429, -103, 417, 787}, { -122, -437, 411, 788}, +{ -913, -417, 602, 754}, { -226, -16, 151, 760}, { -700, 118, -104, -14}, +{-1128, 48, 284, 393}, { -390, -419, -639, -116}, { -910, 306, 316, -13}, +{ 1207, 984, 821, 669}, {-1195, -693, 140, -213}, { -884, -416, -199, -558}, +{ -616, 245, -404, -664}, { 262, 56, -617, -724}, { -85, -491, -320, -656}, +{ -570, -831, -129, -528}, {-1506, -63, -367, -385}, { -358, -321, 4, 51}, +{ -366, -214, 319, 511}, { 146, 671, -17, -291}, { -110, 464, -139, -496}, +{ -202, 220, -312, -631}, { -660, -73, -655, -820}, { -662, -653,-1288, -857}, +{ -430, -953, -959, -264}, { -49, -468, -72, -381}, { -350, -563, -193, -407}, +{ 55, -408, -803, 11}, { -309, 649, 188, -198}, { -512, 461, -79, -458}, +{-1318, -263, -134, -523}, {-1657, -435, -495, -765}, { 57, -347, -414, 434}, +{-1141, -242, -664, -857}, { 34, -68, -707, -338} +}; + +static const int16_t lsf_5_1[128][4] = { +{ -451,-1065, -529,-1305}, { -450, -756, -497, -863}, { -384, -619, -413, -669}, +{ -317, -538, -331, -556}, { -414, -508, -424, -378}, { -274, -324, -434, -614}, +{ -226, -500, -232, -514}, { -263, -377, -298, -410}, { -151, -710, -174, -818}, +{ -149, -412, -156, -429}, { -288, -462, -186, -203}, { -170, -302, -191, -321}, +{ -131, -147, -297, -395}, { -228, -214, -245, -192}, { -67, -316, -71, -327}, +{ -104, -205, -94, -183}, { -143, -38, -193, -95}, { 16, -76, -124, -248}, +{ 23, -237, 24, -244}, { 18, -136, 44, -111}, { -33, -24, -25, 0}, +{ 149, 19, 23, -143}, { 158, -169, 174, -181}, { 133, -55, 165, -26}, +{ 111, 84, 98, 75}, { 87, 183, -115, -11}, { -8, 130, 11, 170}, +{ 254, 77, 205, 17}, { 183, 112, 262, 194}, { 202, 287, 95, 189}, +{ -42, -105, 234, 179}, { 39, 186, 163, 345}, { 332, 199, 299, 161}, +{ -54, 285, -78, 281}, { -133, 141, -182, 111}, { 249, 341, 271, 364}, +{ 93, 403, 75, 391}, { 92, 510, -138, 220}, { -185, -29, -34, 361}, +{ -115, 320, 3, 554}, { 99, 286, 218, 591}, { -245, 406, -268, 453}, +{ 0, 580, 25, 606}, { 275, 532, 148, 450}, { -73, 739, -285, 518}, +{ -288, 94, -203, 674}, { -140, -74, 205, 714}, { -114, 299, 176, 923}, +{ 182, 557, 240, 705}, { -16, 513, 485, 593}, { 293, 384, 451, 617}, +{ -38, 50, 563, 529}, { 303, 209, 459, 363}, { 433, 452, 450, 454}, +{ 367, 606, 477, 741}, { 432, 353, 368, 267}, { 361, 716, 273, 583}, +{ 453, 166, 510, 172}, { 201, 629, 274, 191}, { 568, 639, 302, 298}, +{ 634, 387, 643, 350}, { 587, 560, 612, 565}, { 600, 788, 487, 672}, +{ 512, 1015, 321, 333}, { 357, 854, -125, 413}, { 474, 712, 17, -151}, +{ 564, 285, 270, -241}, { 971, 889, 489, 220}, { 510, 896, 549, 924}, +{ 327, 825, 290, 911}, { 540, 1108, 158, 805}, { 199, 957, 511, 730}, +{ 100, 874, 13, 791}, { 435, 632, 676, 972}, { 249, 900, 467, 1218}, +{ 781, 1074, 585, 785}, { -23, 669, 267, 1043}, { 619, 1084, 615, 1145}, +{ 622, 905, 916, 1049}, { 80, 331, 584, 1075}, { 89, 639, 988, 961}, +{ 770, 720, 798, 699}, { 492, 447, 899, 627}, { 271, 1188, 725, 1333}, +{ 87, 603, 832, 1603}, { 616, 1127, 890, 1505}, { 1000, 1156, 866, 1009}, +{ 995, 827, 1149, 858}, { 817, 1450, 773, 1320}, { 500, 1389, 312, 1153}, +{ -20, 1084, 64, 1283}, { 2, 1172, 399, 1869}, { 514, 1706, 502, 1636}, +{ 886, 1522, 416, 600}, { 1131, 1350, 1275, 1390}, { 889, 1795, 914, 1766}, +{ 227, 1183, 1250, 1826}, { 505, 1854, 919, 2353}, { -199, 431, 152, 1735}, +{ -213, -28, 392, 1334}, { -153, -52, 978, 1151}, { -323, -400, 813, 1703}, +{ -136, 84, 1449, 2015}, { -331, -143, -137, 1192}, { -256, 534, -157, 1031}, +{ -307, -439, 542, 731}, { -329, -420, -97, 616}, { -362, -168, -322, 366}, +{ -247, -110, -211, 89}, { -196, -309, 20, 59}, { -364, -463, -286, 89}, +{ -336, 175, -432, 141}, { -379, -190, -434, -196}, { -79, 150, -278, -227}, +{ -280, 166, -555, -422}, { -155, 541, -366, 54}, { -29, -83, -301, -774}, +{ 186, 628, -397, -264}, { 242, 293, -197, -585}, { 124, 410, 53, -133}, +{ 10, 340, -570,-1065}, { 65, -446, 68, -493}, { 383, 937, -357, -711}, +{ -359, -250, -677,-1068}, { 292, -26, 363, 6}, { 607, 1313, -127, -10}, +{ 1513, 1886, 713, 972}, { 1469, 2181, 1443, 2016} +}; + +static const int16_t lsf_5_2[256][4] = { +{-1631,-1600,-1796,-2290}, {-1027,-1770,-1100,-2025}, {-1277,-1388,-1367,-1534}, +{ -947,-1461, -972,-1524}, { -999,-1222,-1020,-1172}, { -815, -987, -992,-1371}, +{-1216,-1006,-1289,-1094}, { -744,-1268, -755,-1293}, { -862, -923, -905, -984}, +{ -678,-1051, -685,-1050}, {-1087, -985,-1062, -679}, { -989, -641,-1127, -976}, +{ -762, -654, -890, -806}, { -833,-1091, -706, -629}, { -621, -806, -640, -812}, +{ -775, -634, -779, -543}, { -996, -565,-1075, -580}, { -546, -611, -572, -619}, +{ -760, -290, -879, -526}, { -823, -462, -795, -253}, { -553, -415, -589, -439}, +{ -533, -340, -692, -935}, { -505, -772, -702,-1131}, { -263, -306, -971, -483}, +{ -445, -74, -555, -548}, { -614, -129, -693, -234}, { -396, -246, -475, -250}, +{ -265, -404, -376, -514}, { -417, -510, -300, -313}, { -334, -664, -463, -814}, +{ -386, -704, -337, -615}, { -234, -201, -233, -239}, { -167, -567, -203, -619}, +{ -147, -415, -115, -352}, { -166, -750, -171, -761}, { -270, -879, -264, -903}, +{ -367, -744, 43, -475}, { 14, -653, 43, -670}, { 11, -448, -59, -521}, +{ -126, -119, -155, -613}, { -42, -863, -27, -931}, { 136, -483, 183, -468}, +{ 55, -298, 55, -304}, { 313, -609, 313, -720}, { 322, -167, 100, -541}, +{ -3, -119, -111, -187}, { 233, -236, 260, -234}, { 26, -165, 134, -45}, +{ -40, -549, 360, -203}, { 378, -388, 450, -383}, { 275, 20, 182, -103}, +{ 246, -111, 431, 37}, { 462, -146, 487, -157}, { -284, -59, 503, -184}, +{ 24, 53, -3, 54}, { 122, 259, 333, 66}, { 484, 104, 436, 68}, +{ 195, 116, 190, 206}, { 269, -9, 482, 352}, { 382, 285, 399, 277}, +{ 452, 256, 69, 186}, { 13, 297, -13, 259}, { -95, 30, 56, 394}, +{ 196, 425, 205, 456}, { 281, 577, 15, 191}, { 375, 290, 407, 576}, +{ -56, 227, 544, 405}, { 0, 549, -92, 528}, { -229, 351, -245, 338}, +{ -362, 435, 167, 527}, { -75, 302, 91, 824}, { 129, 599, 496, 679}, +{ 186, 749, 153, 737}, { -281, 600, -348, 615}, { -236, 769, 41, 881}, +{ 38, 890, -220, 841}, { -357, 883, -393, 903}, { -634, 474, -444, 850}, +{ -175, 678, -493, 242}, { -519, 785, -714, 582}, { -541, 366, -543, 434}, +{ -597, 500, -765, 222}, { -702, 917, -743, 962}, { -869, 501, -899, 548}, +{ -379, 200, -435, 157}, { -819, 214, -861, 157}, { -614, 40, -632, 94}, +{ -883, -54, -741, 516}, { -501, 298, -614, -171}, { -870, -161, -865, -23}, +{ -818, 93,-1015, -267}, { -662, -359, -549, 2}, { -442, -121, -377, 0}, +{ -227, 33, -414, -126}, { -129, 212, -934, 34}, {-1082, -282,-1119, -268}, +{ -710, -825, -420, -191}, {-1076, -928, -917, -93}, { -628, -358, 97, 7}, +{ -206, -393, -101, 24}, { -203, 38, -168, 83}, { -599, -423, -279, 426}, +{ -700, 118, -75, 206}, { -981, -673, -680, 417}, { -367, 37, -279, 474}, +{ -129, -318, 319, 296}, { -626, -39, 343, 602}, { -696, -39, -303, 940}, +{ 104, 233, -380, 137}, { -36, 269, -75, -214}, { 120, 43, -529, -477}, +{ 459, 164, -202, -229}, { -49, -167, 609, 792}, { 98, -220, 915, 148}, +{ 293, 283, 869, 91}, { 575, 394, 326, -78}, { 717, 67, 365, -323}, +{ 616, -36, 731, 27}, { 619, 238, 632, 273}, { 448, 99, 801, 476}, +{ 869, 273, 685, 64}, { 789, 72, 1021, 217}, { 793, 459, 734, 360}, +{ 646, 480, 360, 322}, { 429, 464, 638, 430}, { 756, 363, 1000, 404}, +{ 683, 528, 602, 615}, { 655, 413, 946, 687}, { 937, 602, 904, 604}, +{ 555, 737, 786, 662}, { 467, 654, 362, 589}, { 929, 710, 498, 478}, +{ 415, 420, 693, 883}, { 813, 683, 781, 925}, { 913, 939, 726, 732}, +{ 491, 853, 531, 948}, { 734, 963, 315, 808}, { 761, 755, 1144, 760}, +{ 655, 1076, 826, 1057}, { 1091, 838, 1003, 808}, { 1047, 1133, 659, 1101}, +{ 992, 1050, 1074, 1075}, { 971, 694, 1226, 1054}, { 571, 841, 884, 1404}, +{ 1379, 1096, 1080, 861}, { 1231, 735, 1284, 760}, { 1272, 991, 1367, 1053}, +{ 1257, 700, 1050, 534}, { 988, 453, 1264, 599}, { 1140, 679, 1621, 815}, +{ 1384, 521, 1317, 393}, { 1564, 805, 1448, 686}, { 1068, 648, 875, 307}, +{ 1083, 361, 1047, 317}, { 1417, 964, 675, 571}, { 1152, 79, 1114, -47}, +{ 1530, 311, 1721, 314}, { 1166, 689, 514, -94}, { 349, 282, 1412, 328}, +{ 1025, 487, -65, 57}, { 805, 970, 36, 62}, { 769, -263, 791, -346}, +{ 637, 699, -137, 620}, { 534, 541, -735, 194}, { 711, 300, -268, -863}, +{ 926, 769, -708, -428}, { 506, 174, -892, -630}, { 435, 547,-1435, -258}, +{ 621, 471,-1018,-1368}, { -393, 521, -920, -686}, { -25, 20, -982,-1156}, +{ 340, 9,-1558,-1135}, { -352, 48,-1579, -402}, { -887, 6,-1156, -888}, +{ -548, -352,-1643,-1168}, { -159, 610,-2024, -963}, { -225, 193,-1656,-1960}, +{ -245, -493, -964,-1680}, { -936, -635,-1299,-1744}, {-1388, -604,-1540, -835}, +{-1397, -135,-1588, -290}, {-1670, -712,-2011,-1632}, {-1663, -27,-2258, -811}, +{-1157, 184,-1265, 189}, {-1367, 586,-2011, 201}, { -790, 712,-1210, 3}, +{-1033, 808,-1251, 830}, { -111, 635,-1636, 447}, { -463, -949, -445, -928}, +{ -504,-1162, -501,-1211}, { 144, -351, -372,-1052}, { -283,-1059, -279,-1123}, +{ -575,-1438, -587,-1614}, { -935, -984, 229, 690}, { -921, -719, -403, 1362}, +{ -685, -465, 874, 397}, { -509, -46, 317, 1334}, { -485, 456, 813, 439}, +{ -411, 339, 898, 1067}, { -425, 46, 1441, 497}, { -909, -800, 1465, 1046}, +{ -254, -321, 1430, 1165}, { 68, 350, 1034, 666}, { 370, 11, 1311, 790}, +{ 143, 232, 1041, 1562}, { -114, 663, 1616, 1078}, { 454, 579, 1275, 1040}, +{ -76, 909, 752, 1067}, { 153, 512, 348, 1214}, { 614, 385, 1843, 808}, +{ 269, 1034, 203, 1086}, { 652, 1017, 1783, 1130}, { 429, 1327, 387, 1384}, +{ -49, 1183, -72, 1215}, { -416, 1001, 544, 1749}, { -352, 1223, -502, 1199}, +{ -589, 569, -227, 1630}, { -142, 1578, -230, 1715}, { -714, 1288, -838, 1398}, +{ 1131, 1357, -208, 1232}, { 437, 965, -929, 818}, { 811, 1410, 859, 1507}, +{ 164, 1212, 1387, 1793}, { 484, 1874, 456, 2063}, { 996, 1170, 1326, 1402}, +{ 1316, 1360, 1135, 1262}, { 1234, 1618, 1361, 1768}, { 1421, 1227, 1584, 1347}, +{ 854, 672, 1685, 1566}, { 1139, 1270, 2016, 1825}, { 1773, 1581, 1532, 1460}, +{ 1487, 946, 1659, 1021}, { 1744, 1212, 1392, 977}, { 1772, 1161, 1826, 1164}, +{ 1718, 1429, 1973, 1591}, { 1185, 864, 2132, 1061}, { 1799, 814, 1838, 757}, +{ 2104, 1315, 2054, 1258}, { 2113, 915, 2331, 930}, { 1467, 1147, 2590, 1439}, +{ 2245, 1744, 2090, 1620}, { 2358, 1454, 2666, 1506}, { 1876, 1837, 2070, 1975}, +{ 1739, 1577, 682, 1289}, { 1584, 2045, 1454, 2098}, { 2498, 2004, 2711, 2066}, +{ 726, 1588, 2756, 2336}, { 228, 847, 2456, 1659}, { 36, 301, 1942, 1957}, +{ -446, -96, 2154, 1396}, { 1533, 1101, 14, 608}, { -923, -732, 1383, 1982}, +{ 1345, 952, -680, 321}, { 1281, 1268,-1594, 365}, { 941, 946,-1737, -822}, +{ 2374, 2787, 1821, 2788} +}; + +static const int16_t lsf_5_3[256][4] = { +{-1812,-2275,-1879,-2537}, {-1640,-1848,-1695,-2004}, {-1220,-1912,-1221,-2106}, +{-1559,-1588,-1573,-1556}, {-1195,-1615,-1224,-1727}, {-1359,-1151,-1616,-1948}, +{-1274,-1391,-1305,-1403}, {-1607,-1179,-1676,-1311}, {-1443,-1478,-1367, -898}, +{-1256,-1059,-1331,-1134}, { -982,-1133,-1149,-1504}, {-1080,-1308,-1020,-1183}, +{ -980,-1486, -967,-1495}, { -988, -922,-1047,-1077}, { -838,-1179, -858,-1222}, +{-1131,-1041,-1064, -767}, { -872,-1157, -701, -880}, { -706, -906, -774,-1016}, +{ -578,-1080, -801,-1478}, { -591,-1111, -592,-1146}, { -713,-1388, -640,-1376}, +{ -597,-1059, -416, -903}, { -686, -832, -661, -708}, { -444, -868, -490, -921}, +{ -374, -776, -619,-1170}, { -585, -549, -769, -795}, { -435, -659, -530, -741}, +{ -498, -837, -357, -597}, { -279, -871, -243, -887}, { -282, -665, -280, -667}, +{ -165, -560, -394, -903}, { -362, -410, -448, -583}, { -409, -574, -313, -357}, +{ -637, -548, -570, -436}, { -896, -504, -382, -757}, { -58, -481, -165, -618}, +{ -191, -374, -234, -382}, { -222, -683, -25, -480}, { -418, -359, -730, -353}, +{ -324, -157, -432, -322}, { -394, -303, -284, -104}, { -601, -289, -556, -196}, +{ -588, -150, -659, -608}, { -473, -24, -68, -448}, { -474, -8, -506, -45}, +{ -748, -184, -844, -252}, { -901, -91, -584, -97}, { -652, 138, -764, -131}, +{ -678, -12, -670, 165}, { -259, -3, -840, -107}, { -909, 37, -992, 44}, +{ -854, -415, -839, 13}, {-1001, -271,-1026, -309}, { -798, -478, -832, -488}, +{ -943, 168,-1112, -387}, {-1185, -101,-1183, -40}, { -941, -316,-1030, -770}, +{-1044, -625,-1081, -538}, {-1224, -299,-1312, -436}, {-1197, -663,-1167, -161}, +{-1216, -690,-1237, -831}, {-1432, -720,-1403, -493}, { -898, -740, -922, -801}, +{-1102, -402,-1579, -964}, {-1061, -638,-1269,-1438}, {-1499, -934,-1502, -895}, +{-1598, -564,-1723, -717}, { -606, -597,-1166,-1085}, {-1369, -468,-1946,-1493}, +{-1838, -953,-1932, -931}, {-1499, -188,-1635, -421}, {-1457, -338,-1448, -22}, +{-1942, -422,-2006, -249}, { -496, -114,-1910, -755}, {-1289, 174,-1451, -109}, +{ -482, -257,-1221, -508}, {-1617, 151,-1694, 208}, { -654, 107,-1651, 29}, +{-1141, 279,-1215, 306}, {-1228, -506, -730, -175}, {-1236, -101, -969, 551}, +{ -870, 278, -823, 315}, { -563, 376,-1051, 228}, { -507, 280, -599, 281}, +{ -758, 253, -305, 379}, { -755, -134, -611, 660}, { -824, 536, -817, 646}, +{ -413, 49, -341, 177}, { -453, 526, -482, 589}, { -71, 339, -657, 264}, +{ -244, 295, -237, 315}, { -387, 569, -506, -9}, { -377, 14, -160, 661}, +{ -216, 40, -308, -46}, { 95, 214, -242, 167}, { -86, 192, -56, 27}, +{ -76, 31, 36, 309}, { -106, -182, -113, 74}, { -441, -22, 23, 139}, +{ 81, -11, 44, 15}, { -87, -137, -118, -207}, { -158, -58, 272, -92}, +{ -156, -441, 8, -136}, { 128, -221, 101, -218}, { 40, -197, -76, -456}, +{ 9, -445, 33, -423}, { 226, 60, 73, -222}, { 156, -399, 280, -318}, +{ 245, -341, 166, -499}, { 339, -190, 327, -219}, { 325, -137, -89, -596}, +{ 100, -627, 144, -677}, { 487, 28, 252, -391}, { 214, -41, 282, -28}, +{ 99, -286, 331, 49}, { 459, -388, 565, -369}, { 436, 28, 336, -9}, +{ 397, -167, 618, 34}, { 596, -17, 561, -140}, { 299, 79, 522, 125}, +{ 203, 2, 244, 288}, { 255, 211, 175, 82}, { 596, 187, 517, 108}, +{ 381, 255, 365, 297}, { 497, 352, 327, -82}, { 25, 210, 371, 245}, +{ 261, 3, 545, 449}, { 140, 294, 44, 295}, { 212, 347, 244, 494}, +{ 331, 528, 201, 307}, { 349, 411, 613, 284}, { 614, 413, 464, 322}, +{ 624, 397, 97, 200}, { -160, 384, 149, 362}, { 495, 525, 269, 585}, +{ 33, 491, -121, 433}, { 427, 611, 498, 516}, { 171, 443, 497, 666}, +{ 440, 275, 566, 575}, { 146, 639, 155, 670}, { -33, 173, 212, 696}, +{ -166, 601, -191, 695}, { -489, 503, 175, 742}, { 214, 476, 372, 1083}, +{ 578, 530, 586, 777}, { 425, 874, 315, 841}, { 374, 848, -165, 565}, +{ 35, 991, -39, 1062}, { 329, 712, 786, 840}, { 645, 795, 661, 676}, +{ 571, 918, 632, 1079}, { 673, 817, 318, 388}, { 874, 1012, 564, 848}, +{ 880, 620, 557, 479}, { 671, 453, 692, 468}, { 840, 642, 844, 645}, +{ 506, 428, 897, 567}, { 837, 387, 962, 499}, { 691, 561, 939, 926}, +{ 783, 296, 790, 268}, { 1028, 530, 874, 329}, { 548, 143, 675, 291}, +{ 503, 66, 1041, 359}, { 786, 97, 805, 33}, { 837, 470, 511, 49}, +{ 1092, 327, 1174, 323}, { 3, 242, 872, 474}, { 689, 429, 1329, 678}, +{ 1042, 620, 1109, 664}, { 321, 193, 889, 950}, { 1153, 874, 893, 635}, +{ 877, 862, 948, 913}, { 1293, 665, 1320, 639}, { 997, 793, 1402, 1030}, +{ 1176, 1012, 1110, 959}, { 1410, 925, 1403, 915}, { 543, 862, 1116, 1222}, +{ 835, 1190, 835, 1190}, { 959, 1148, 1147, 1376}, { 1300, 1193, 1415, 1231}, +{ 1335, 1341, 746, 1092}, { 1711, 1283, 1389, 1073}, { 1334, 1566, 1153, 1475}, +{ 1645, 1137, 1825, 1220}, { 1056, 1382, 1521, 1730}, { 1632, 1545, 1620, 1542}, +{ 855, 1596, 865, 1667}, { 693, 885, 1716, 1519}, { 1167, 1296, 2209, 1760}, +{ 1952, 1493, 2020, 1482}, { 1534, 1866, 1694, 2008}, { 1566, 748, 1761, 825}, +{ 294, 1392, 1084, 2058}, { 621, 1315, 365, 1287}, { 198, 1028, 488, 1408}, +{ 249, 403, 1014, 1561}, { 324, 363, 1645, 1044}, { 193, 367, 2034, 1859}, +{ -251, 579, 750, 994}, { -243, 30, 1325, 879}, { -28, -169, 624, 917}, +{ -453, 159, 186, 1370}, { -614, 6, 537, 392}, { -94, -291, 781, 229}, +{ -128, -298, 245, 491}, { -701, -648, 972, 789}, { -501, -640, 178, 255}, +{ -365, -390, -255, 317}, { -958, -294, -191, 228}, { -775, -447, 157, -237}, +{ -657, -720, -407, 92}, { -117, -611, 334, -230}, { -679,-1084, -144, -317}, +{ -901, -861, -738, -360}, { -85, -727, -90, -787}, { 100, -22, -391, -263}, +{ -56, -73, -337, -754}, { 5, -189, -706, -624}, { 89, -344, -135,-1113}, +{ -353, -237, -684,-1135}, { -275,-1102, -269,-1203}, { 152, 145, -722,-1232}, +{ 49, 80,-1248, -776}, { -248, 391, -732, -547}, { 469, 218, -255, -864}, +{ 69, 366, -166, -485}, { -688, 191,-1212,-1196}, { -170, -169,-1308,-1631}, +{ 321, 470,-1419,-1243}, { -64, 272,-1361, -248}, { 492, 565, -721, -609}, +{ 195, 485, -573, -133}, { 427, 202, -171, -118}, { 199, 575, 2, -31}, +{ 694, 755,-1366, -39}, { 552, 557, -489, 271}, { 680, 537, 13, -453}, +{ 855, 954, -133, -52}, { -81, 738,-1169, 637}, { 1055, 1059, -95, 676}, +{ 1259, 1081, 489, 305}, { -449, 954, -534, 996}, { -969, 866,-1058, 1059}, +{-1294, 618,-1416, 617}, { -458, 1366, -159, 1821}, { -774, -528, -14, 1110}, +{-1202, -901, -772, 433}, {-1256,-1255,-1011, -302}, { -602, -585, -759,-1618}, +{ -760,-1549, -840,-1921}, { -816, -539,-1769,-2235}, { -227, -36,-2034,-1831}, +{-2107,-1126,-2471,-1816}, {-1470, 252,-2701, -415}, { -571, -467, 1509, 1554}, +{ 2180, 1975, 2326, 2020} +}; + +static const int16_t lsf_5_4[256][4] = { +{-1857,-1681,-1857,-1755}, {-2056,-1150,-2134,-1654}, {-1619,-1099,-1704,-1131}, +{-1345,-1608,-1359,-1638}, {-1338,-1293,-1325,-1265}, {-1664,-1649,-1487, -851}, +{-1346,-1832,-1413,-2188}, {-1282, -681,-1785,-1649}, { -966,-1082,-1183,-1676}, +{-1054,-1073,-1142,-1158}, {-1207, -744,-1274, -997}, { -934,-1383, -927,-1416}, +{-1010,-1305, -783, -955}, {-1049, -900, -993, -817}, { -737, -823, -972,-1189}, +{ -738,-1094, -738,-1154}, { -784, -801, -810, -786}, { -892, -520,-1000, -818}, +{ -644, -965, -577, -882}, { -541, -694, -671, -917}, { -595, -642, -646, -615}, +{ -956, -621, -925, -515}, { -727, -483, -815, -485}, { -840, -578, -440, -713}, +{ -578, -325, -657, -670}, { -386, -570, -441, -666}, { -514, -787, -392, -529}, +{ -522, -453, -487, -423}, { -616, -585, -617, -157}, { -662, -268, -680, -348}, +{ -322, -323, -632, -444}, { -304, -430, -332, -458}, { -277, -468, -659, -793}, +{ -319, -636, -227, -554}, { -373, -347, -334, -210}, { -456, -192, -530, -242}, +{ -216, -198, -366, -370}, { -338, -161, -409, -748}, { -107, -380, -294, -643}, +{ -223, -665, -234, -741}, { -141, -496, -130, -510}, { -139, -327, -172, -305}, +{ -306, -580, -164, -263}, { -262, -172, -67, -402}, { 31, -366, -10, -436}, +{ -86, -527, 71, -377}, { -22, -609, -12, -678}, { -67, -319, 63, -191}, +{ 35, -181, -39, -242}, { 126, -167, -140, -544}, { 155, -297, 174, -297}, +{ 38, -8, 117, -380}, { 197, -452, 240, -522}, { 223, -103, 110, -187}, +{ 87, -155, 169, -47}, { 157, 26, -83, -100}, { 128, 80, 209, -62}, +{ 6, 7, 22, 5}, { 318, -20, 248, -45}, { -200, -63, 156, -69}, +{ 250, -183, 369, -126}, { -113, -76, -142, -122}, { -64, -254, -31, 35}, +{ -177, -71, -7, 171}, { 93, 27, 108, 212}, { -330, -209, -123, -70}, +{ -279, 95, -96, 20}, { -188, -61, -314, 87}, { -300, -78, -354, -134}, +{ 11, 122, -140, 122}, { -275, 152, -293, 140}, { -82, 138, -321, -111}, +{ -480, -156, -359, 76}, { -254, -40, -635, -96}, { -522, 79, -507, 8}, +{ -268, 303, -539, 68}, { -446, 61, -522, 306}, { 111, 189, -435, 122}, +{ -379, 166, -571, -398}, { -632, -74, -747, -95}, { -455, 194, -952, 83}, +{ -798, 192, -755, 192}, { -781, -162, -619, 234}, { -663, -297, -488, -109}, +{ -964, -132, -838, -68}, { -843, 58,-1112, -86}, { -805, -299, -944, -253}, +{ -778, -50, -965, -549}, { -352, -98, -992, -343}, {-1117, -315,-1117, -307}, +{-1155, -374, -637, -230}, {-1166, -43,-1299, -100}, { -925, -393,-1274, -600}, +{ -689, -130,-1479, -312}, {-1321, -254,-1464, -442}, {-1292, -613,-1261, -503}, +{-1501, -368,-1322, 26}, {-1432, -66,-1743, -161}, {-1644, -467,-1760, -548}, +{-1393, -568,-1556, -871}, {-1495,-1034,-1387, -571}, {-1917, -528,-1783, -123}, +{-1897, -231,-2054, -323}, {-2052, -906,-1976, -567}, {-1917, -620,-2047, -989}, +{-1077, -370,-2031, -704}, {-2355, -749,-2740,-1089}, {-1909, 159,-2012, 248}, +{ -626, -123,-2339, -962}, { -669, -408,-1379,-1174}, { -452, -364,-1044, -735}, +{ -132, 183,-1620, -752}, { -547, -307, -777,-1261}, { -98, 41, -880,-1091}, +{ -257, 97,-1602,-1833}, { 31, -26, -644, -561}, { -180, -546, -385,-1095}, +{ -410, -802, -414, -827}, { -457, -970, -490,-1109}, { -215, -916, -144, -937}, +{ -493,-1269, -517,-1507}, { 181, 101, -332, -889}, { -836, -937, -559, -429}, +{ -629, -547, -183, -337}, { -545, -82, -250, -286}, { 5, -132, -348, -252}, +{ -293, -472, -158, 100}, { -29, 197, -236, -424}, { -861, -213, -140, -7}, +{ -427, -443, 187, -97}, { -684, -736, -293, 258}, { -368, -152, -150, 392}, +{ -609, 175, -142, 299}, { -138, 152, -119, 329}, { -486, -52, 293, 198}, +{ -183, 117, 175, 331}, { -58, -274, 231, 300}, { -288, 330, -305, 372}, +{ -111, 409, -9, 423}, { 83, 256, 67, 367}, { -19, 248, 91, 113}, +{ -35, 406, -191, 154}, { 238, 296, 5, 197}, { 141, 221, 313, 198}, +{ 211, 421, 244, 334}, { 88, 426, -243, 454}, { 202, 552, -5, 403}, +{ 291, 185, 219, 301}, { 251, 138, 128, 69}, { 197, 288, -140, -61}, +{ 188, 361, 197, 598}, { 442, 273, 290, 143}, { 472, 482, 157, 370}, +{ 415, 321, 372, 385}, { 402, 552, 155, 24}, { 550, 263, -11, 21}, +{ 360, 227, 147, -254}, { 424, 97, 366, -13}, { 375, 141, 449, 232}, +{ 396, 507, 474, 272}, { 701, 324, 362, -47}, { 587, 148, 543, 69}, +{ 400, -51, 561, 59}, { 220, -10, 352, 147}, { 206, 211, 653, 185}, +{ 563, 297, 565, 284}, { 594, 121, 766, 192}, { 398, 118, 642, 434}, +{ 233, 264, 481, 467}, { 129, -165, 699, 239}, { 90, 26, 342, 474}, +{ -55, 27, 388, 94}, { -172, 0, 725, 379}, { -60, 337, 370, 465}, +{ 95, 319, 806, 595}, { 78, 260, 497, 851}, { 210, 560, 458, 574}, +{ -464, 202, 497, 625}, { -202, 152, 48, 712}, { -20, 566, 100, 715}, +{ 455, 468, 411, 605}, { 319, 646, 195, 615}, { 401, 538, 680, 739}, +{ 201, 667, 434, 954}, { 454, 425, 646, 491}, { 606, 681, 416, 508}, +{ 497, 822, 426, 815}, { 660, 647, 628, 716}, { 697, 466, 618, 457}, +{ 685, 460, 365, 309}, { 721, 567, 836, 601}, { 609, 300, 825, 459}, +{ 943, 687, 681, 533}, { 915, 598, 591, 243}, { 876, 451, 874, 420}, +{ 786, 317, 732, 220}, { 922, 317, 1108, 367}, { 531, 466, 1028, 649}, +{ 1053, 615, 1034, 553}, { 829, 602, 1021, 799}, { 927, 803, 878, 763}, +{ 799, 496, 1373, 773}, { 585, 770, 803, 930}, { 1099, 793, 1222, 862}, +{ 1209, 895, 1025, 727}, { 772, 845, 1172, 1115}, { 867, 1021, 830, 1013}, +{ 841, 910, 506, 703}, { 1239, 1077, 620, 819}, { 1196, 1083, 1155, 1081}, +{ 1142, 907, 1547, 1121}, { 1309, 648, 1343, 612}, { 1484, 988, 1479, 937}, +{ 985, 1328, 955, 1341}, { 429, 910, 841, 1338}, { 564, 1179, 412, 1156}, +{ 1427, 1320, 1434, 1330}, { 640, 760, 1726, 1410}, { 190, 555, 1073, 1005}, +{ 426, 257, 839, 980}, { 235, 231, 1520, 1167}, { 109, 293, 1014, 1569}, +{ 305, 142, 1148, 539}, { -291, -108, 1213, 972}, { 22, -216, 667, 828}, +{ -482, 438, 453, 1431}, { -581, -422, 789, 387}, { -358, -454, 174, 780}, +{ -36, -372, 390, -134}, { -629, 160, -306, 751}, {-1258, -331, 177, 522}, +{ -248, 574, -251, 639}, { -531, 407, -596, 394}, { -419, 789, -617, 801}, +{ -986, 399, -857, 727}, { -7, 518, -703, 310}, {-1143, -24,-1002, 287}, +{ -960, 363,-1299, 312}, {-1534, 245,-1557, 305}, { 28, 153, -859, -175}, +{ -33, 332,-1398, -154}, { 212, 410, -593, -197}, {-1092, -704, -904, -65}, +{ 282, 367, -918, -686}, { 345, 93, -258, -357}, { 696, 644, -693, -28}, +{ 448, 493, -273, 193}, { 527, 546, -243, -513}, { 384, -136, 273, -353}, +{ 512, -142, 537, -198}, { 941, 750, 83, 248}, { 578, 861, -56, 592}, +{ 842, 44, 892, 24}, { 33, 890, -16, 982}, { 831, 1398, 1535, 1898}, +{ 1716, 1376, 1948, 1465} +}; + +static const int16_t lsf_5_5[64][4] = { +{-1002, -929,-1096,-1203}, { -641, -931, -604, -961}, { -779, -673, -835, -788}, +{ -416, -664, -458, -766}, { -652, -521, -662, -495}, {-1023, -509,-1023, -428}, +{ -444, -552, -368, -449}, { -479, -211,-1054, -903}, { -316, -249, -569, -591}, +{ -569, -275, -541, -191}, { -716, -188, -842, -264}, { -333, -248, -318, -228}, +{ -275, 1, -567, -228}, { -115, -221, -238, -374}, { -197, -507, -222, -579}, +{ -258, -432, -61, -244}, { -345, 2, -338, 39}, { -215, -169, -58, 0}, +{ -56, -6, -203, -131}, { 1, -186, -5, -211}, { 6, -380, 11, -418}, +{ -116, 131, -134, 113}, { 89, -4, 71, -2}, { -19, -192, 262, 24}, +{ 189, 151, -133, -109}, { 186, -153, 166, -219}, { 37, 139, 193, 171}, +{ 337, 124, 158, -61}, { 141, 226, -13, 190}, { 231, 34, 354, 109}, +{ 316, 201, 244, 164}, { 330, -85, 390, -84}, { 254, 327, 257, 335}, +{ 491, 147, 476, 105}, { 54, 77, 437, 370}, { 421, 314, 449, 342}, +{ 329, 126, 673, 292}, { 571, 388, 243, 193}, { 653, 320, 621, 280}, +{ 194, 380, 517, 581}, { 45, 323, 111, 422}, { 489, 395, 734, 534}, +{ 622, 546, 486, 502}, { 318, 572, 189, 550}, { 385, 422, -157, 153}, +{ -125, 382, -197, 386}, { -263, 334, 228, 697}, { -188, 1, 51, 297}, +{ -507, 213, -376, 397}, { -24, 255, -547, 89}, { -502, -94, 387, 179}, +{ -620, 68, -684, 112}, { -642, -350, -260, 172}, { -438, -324, 264, 648}, +{ -964, -4,-1121, 7}, { -134, 134,-1133, -306}, { 143, 96, -420, -497}, +{-1221, -350,-1527, -685}, { -161, 72, 873, 691}, { 732, 283, 921, 353}, +{ 334, 475, 1095, 821}, { 864, 524, 843, 497}, { 714, 711, 788, 750}, +{ 1076, 714, 1204, 753} +}; + +static const float lsf_3_mean[LP_FILTER_ORDER] = { + 377.441, 554.688, 922.363, 1339.84, 1702.15, + 2046.390, 2452.880, 2741.460, 3116.70, 3348.14 +}; + +static const float lsf_5_mean[LP_FILTER_ORDER] = { + 337.891, 507.080, 834.961, 1247.07, 1646.00, + 1982.910, 2407.960, 2708.010, 3104.00, 3344.97 +}; + +/** Prediction factor table for modes other than 12.2kbit/s */ +static const float pred_fac[LP_FILTER_ORDER] = { + 0.291626, 0.328644, 0.383636, 0.405640, 0.438873, + 0.355560, 0.323120, 0.298065, 0.262238, 0.197876, +}; + +// fixed tables + +/** + * number of pulses per mode + */ +static const uint8_t pulses_nb_per_mode[] = {2, 2, 2, 3, 4, 4, 8, 10}; + +/** track start positions for algebraic code book routines */ +static const uint8_t track_position[16] = { + 0, 2, 0, 3, 0, 2, 0, 3, 1, 3, 2, 4, 1, 4, 1, 4 +}; + +/** 3-bit Gray code to binary lookup table */ +static const uint8_t gray_decode[8] = { 0, 5, 15, 10, 25, 30, 20, 35 }; + + +// gain tables + +/** scalar quantized pitch gain table for 7.95 and 12.2 kbps modes */ +static const uint16_t qua_gain_pit[16] = { + 0, 3277, 6556, 8192, 9830, 11469, 12288, 13107, + 13926, 14746, 15565, 16384, 17203, 18022, 18842, 19661 +}; + +/** scalar quantized fixed gain table for 7.95 and 12.2 kbps modes */ +static const uint16_t qua_gain_code[32] = { + 159, 206, 268, 349, 419, 482, 554, 637, + 733, 842, 969, 1114, 1281, 1473, 1694, 1948, + 2241, 2577, 2963, 3408, 3919, 4507, 5183, 5960, + 6855, 7883, 9065, 10425, 12510, 16263, 21142, 27485 +}; + +/** desired mean innovation energy, indexed by active mode */ +static const float energy_mean[8] = { + 33.0, 33.0, 33.0, 28.75, 30.0, 36.0, 33.0, 36.0 +}; + +/** 4-tap moving average prediction coefficients in reverse order */ +static const float energy_pred_fac[4] = { 0.19, 0.34, 0.58, 0.68 }; + +/** gain table for 4.75 kbps mode + * + * first index has even/odd indexes for subframes 0,2/1,3 + * second index is {pitch_gain, fixed_gain_factor} */ +static const uint16_t gains_MODE_4k75[512][2] = { +{ 812, 128}, { 542, 140}, { 2873, 1135}, { 2266, 3402}, { 2067, 563}, +{12677, 647}, { 4132, 1798}, { 5601, 5285}, { 7689, 374}, { 3735, 441}, +{10912, 2638}, {11807, 2494}, {20490, 797}, { 5218, 675}, { 6724, 8354}, +{ 5282, 1696}, { 1488, 428}, { 5882, 452}, { 5332, 4072}, { 3583, 1268}, +{ 2469, 901}, {15894, 1005}, {14982, 3271}, {10331, 4858}, { 3635, 2021}, +{ 2596, 835}, {12360, 4892}, {12206, 1704}, {13432, 1604}, { 9118, 2341}, +{ 3968, 1538}, { 5479, 9936}, { 3795, 417}, { 1359, 414}, { 3640, 1569}, +{ 7995, 3541}, {11405, 645}, { 8552, 635}, { 4056, 1377}, {16608, 6124}, +{11420, 700}, { 2007, 607}, {12415, 1578}, {11119, 4654}, {13680, 1708}, +{11990, 1229}, { 7996, 7297}, {13231, 5715}, { 2428, 1159}, { 2073, 1941}, +{ 6218, 6121}, { 3546, 1804}, { 8925, 1802}, { 8679, 1580}, {13935, 3576}, +{13313, 6237}, { 6142, 1130}, { 5994, 1734}, {14141, 4662}, {11271, 3321}, +{12226, 1551}, {13931, 3015}, { 5081,10464}, { 9444, 6706}, { 1689, 683}, +{ 1436, 1306}, { 7212, 3933}, { 4082, 2713}, { 7793, 704}, {15070, 802}, +{ 6299, 5212}, { 4337, 5357}, { 6676, 541}, { 6062, 626}, {13651, 3700}, +{11498, 2408}, {16156, 716}, {12177, 751}, { 8065,11489}, { 6314, 2256}, +{ 4466, 496}, { 7293, 523}, {10213, 3833}, { 8394, 3037}, { 8403, 966}, +{14228, 1880}, { 8703, 5409}, {16395, 4863}, { 7420, 1979}, { 6089, 1230}, +{ 9371, 4398}, {14558, 3363}, {13559, 2873}, {13163, 1465}, { 5534, 1678}, +{13138,14771}, { 7338, 600}, { 1318, 548}, { 4252, 3539}, {10044, 2364}, +{10587, 622}, {13088, 669}, {14126, 3526}, { 5039, 9784}, {15338, 619}, +{ 3115, 590}, {16442, 3013}, {15542, 4168}, {15537, 1611}, {15405, 1228}, +{16023, 9299}, { 7534, 4976}, { 1990, 1213}, {11447, 1157}, {12512, 5519}, +{ 9475, 2644}, { 7716, 2034}, {13280, 2239}, {16011, 5093}, { 8066, 6761}, +{10083, 1413}, { 5002, 2347}, {12523, 5975}, {15126, 2899}, {18264, 2289}, +{15827, 2527}, {16265,10254}, {14651,11319}, { 1797, 337}, { 3115, 397}, +{ 3510, 2928}, { 4592, 2670}, { 7519, 628}, {11415, 656}, { 5946, 2435}, +{ 6544, 7367}, { 8238, 829}, { 4000, 863}, {10032, 2492}, {16057, 3551}, +{18204, 1054}, { 6103, 1454}, { 5884, 7900}, {18752, 3468}, { 1864, 544}, +{ 9198, 683}, {11623, 4160}, { 4594, 1644}, { 3158, 1157}, {15953, 2560}, +{12349, 3733}, {17420, 5260}, { 6106, 2004}, { 2917, 1742}, {16467, 5257}, +{16787, 1680}, {17205, 1759}, { 4773, 3231}, { 7386, 6035}, {14342,10012}, +{ 4035, 442}, { 4194, 458}, { 9214, 2242}, { 7427, 4217}, {12860, 801}, +{11186, 825}, {12648, 2084}, {12956, 6554}, { 9505, 996}, { 6629, 985}, +{10537, 2502}, {15289, 5006}, {12602, 2055}, {15484, 1653}, {16194, 6921}, +{14231, 5790}, { 2626, 828}, { 5615, 1686}, {13663, 5778}, { 3668, 1554}, +{11313, 2633}, { 9770, 1459}, {14003, 4733}, {15897, 6291}, { 6278, 1870}, +{ 7910, 2285}, {16978, 4571}, {16576, 3849}, {15248, 2311}, {16023, 3244}, +{14459,17808}, {11847, 2763}, { 1981, 1407}, { 1400, 876}, { 4335, 3547}, +{ 4391, 4210}, { 5405, 680}, {17461, 781}, { 6501, 5118}, { 8091, 7677}, +{ 7355, 794}, { 8333, 1182}, {15041, 3160}, {14928, 3039}, {20421, 880}, +{14545, 852}, {12337,14708}, { 6904, 1920}, { 4225, 933}, { 8218, 1087}, +{10659, 4084}, {10082, 4533}, { 2735, 840}, {20657, 1081}, {16711, 5966}, +{15873, 4578}, {10871, 2574}, { 3773, 1166}, {14519, 4044}, {20699, 2627}, +{15219, 2734}, {15274, 2186}, { 6257, 3226}, {13125,19480}, { 7196, 930}, +{ 2462, 1618}, { 4515, 3092}, {13852, 4277}, {10460, 833}, {17339, 810}, +{16891, 2289}, {15546, 8217}, {13603, 1684}, { 3197, 1834}, {15948, 2820}, +{15812, 5327}, {17006, 2438}, {16788, 1326}, {15671, 8156}, {11726, 8556}, +{ 3762, 2053}, { 9563, 1317}, {13561, 6790}, {12227, 1936}, { 8180, 3550}, +{13287, 1778}, {16299, 6599}, {16291, 7758}, { 8521, 2551}, { 7225, 2645}, +{18269, 7489}, {16885, 2248}, {17882, 2884}, {17265, 3328}, { 9417,20162}, +{11042, 8320}, { 1286, 620}, { 1431, 583}, { 5993, 2289}, { 3978, 3626}, +{ 5144, 752}, {13409, 830}, { 5553, 2860}, {11764, 5908}, {10737, 560}, +{ 5446, 564}, {13321, 3008}, {11946, 3683}, {19887, 798}, { 9825, 728}, +{13663, 8748}, { 7391, 3053}, { 2515, 778}, { 6050, 833}, { 6469, 5074}, +{ 8305, 2463}, { 6141, 1865}, {15308, 1262}, {14408, 4547}, {13663, 4515}, +{ 3137, 2983}, { 2479, 1259}, {15088, 4647}, {15382, 2607}, {14492, 2392}, +{12462, 2537}, { 7539, 2949}, {12909,12060}, { 5468, 684}, { 3141, 722}, +{ 5081, 1274}, {12732, 4200}, {15302, 681}, { 7819, 592}, { 6534, 2021}, +{16478, 8737}, {13364, 882}, { 5397, 899}, {14656, 2178}, {14741, 4227}, +{14270, 1298}, {13929, 2029}, {15477, 7482}, {15815, 4572}, { 2521, 2013}, +{ 5062, 1804}, { 5159, 6582}, { 7130, 3597}, {10920, 1611}, {11729, 1708}, +{16903, 3455}, {16268, 6640}, { 9306, 1007}, { 9369, 2106}, {19182, 5037}, +{12441, 4269}, {15919, 1332}, {15357, 3512}, {11898,14141}, {16101, 6854}, +{ 2010, 737}, { 3779, 861}, {11454, 2880}, { 3564, 3540}, { 9057, 1241}, +{12391, 896}, { 8546, 4629}, {11561, 5776}, { 8129, 589}, { 8218, 588}, +{18728, 3755}, {12973, 3149}, {15729, 758}, {16634, 754}, {15222,11138}, +{15871, 2208}, { 4673, 610}, {10218, 678}, {15257, 4146}, { 5729, 3327}, +{ 8377, 1670}, {19862, 2321}, {15450, 5511}, {14054, 5481}, { 5728, 2888}, +{ 7580, 1346}, {14384, 5325}, {16236, 3950}, {15118, 3744}, {15306, 1435}, +{14597, 4070}, {12301,15696}, { 7617, 1699}, { 2170, 884}, { 4459, 4567}, +{18094, 3306}, {12742, 815}, {14926, 907}, {15016, 4281}, {15518, 8368}, +{17994, 1087}, { 2358, 865}, {16281, 3787}, {15679, 4596}, {16356, 1534}, +{16584, 2210}, {16833, 9697}, {15929, 4513}, { 3277, 1085}, { 9643, 2187}, +{11973, 6068}, { 9199, 4462}, { 8955, 1629}, {10289, 3062}, {16481, 5155}, +{15466, 7066}, {13678, 2543}, { 5273, 2277}, {16746, 6213}, {16655, 3408}, +{20304, 3363}, {18688, 1985}, {14172,12867}, {15154,15703}, { 4473, 1020}, +{ 1681, 886}, { 4311, 4301}, { 8952, 3657}, { 5893, 1147}, {11647, 1452}, +{15886, 2227}, { 4582, 6644}, { 6929, 1205}, { 6220, 799}, {12415, 3409}, +{15968, 3877}, {19859, 2109}, { 9689, 2141}, {14742, 8830}, {14480, 2599}, +{ 1817, 1238}, { 7771, 813}, {19079, 4410}, { 5554, 2064}, { 3687, 2844}, +{17435, 2256}, {16697, 4486}, {16199, 5388}, { 8028, 2763}, { 3405, 2119}, +{17426, 5477}, {13698, 2786}, {19879, 2720}, { 9098, 3880}, {18172, 4833}, +{17336,12207}, { 5116, 996}, { 4935, 988}, { 9888, 3081}, { 6014, 5371}, +{15881, 1667}, { 8405, 1183}, {15087, 2366}, {19777, 7002}, {11963, 1562}, +{ 7279, 1128}, {16859, 1532}, {15762, 5381}, {14708, 2065}, {20105, 2155}, +{17158, 8245}, {17911, 6318}, { 5467, 1504}, { 4100, 2574}, {17421, 6810}, +{ 5673, 2888}, {16636, 3382}, { 8975, 1831}, {20159, 4737}, {19550, 7294}, +{ 6658, 2781}, {11472, 3321}, {19397, 5054}, {18878, 4722}, {16439, 2373}, +{20430, 4386}, {11353,26526}, {11593, 3068}, { 2866, 1566}, { 5108, 1070}, +{ 9614, 4915}, { 4939, 3536}, { 7541, 878}, {20717, 851}, { 6938, 4395}, +{16799, 7733}, {10137, 1019}, { 9845, 964}, {15494, 3955}, {15459, 3430}, +{18863, 982}, {20120, 963}, {16876,12887}, {14334, 4200}, { 6599, 1220}, +{ 9222, 814}, {16942, 5134}, { 5661, 4898}, { 5488, 1798}, {20258, 3962}, +{17005, 6178}, {17929, 5929}, { 9365, 3420}, { 7474, 1971}, {19537, 5177}, +{19003, 3006}, {16454, 3788}, {16070, 2367}, { 8664, 2743}, { 9445,26358}, +{10856, 1287}, { 3555, 1009}, { 5606, 3622}, {19453, 5512}, {12453, 797}, +{20634, 911}, {15427, 3066}, {17037,10275}, {18883, 2633}, { 3913, 1268}, +{19519, 3371}, {18052, 5230}, {19291, 1678}, {19508, 3172}, {18072,10754}, +{16625, 6845}, { 3134, 2298}, {10869, 2437}, {15580, 6913}, {12597, 3381}, +{11116, 3297}, {16762, 2424}, {18853, 6715}, {17171, 9887}, {12743, 2605}, +{ 8937, 3140}, {19033, 7764}, {18347, 3880}, {20475, 3682}, {19602, 3380}, +{13044,19373}, {10526,23124} +}; + +/** gain table for 6.70, 7.40 and 10.2 kbps modes + * + * second index is {pitch_gain, fixed_gain_factor} */ +static const uint16_t gains_high[128][2] = { +{ 577, 662}, { 806, 1836}, { 3109, 1052}, { 4181, 1387}, { 2373, 1425}, +{ 3248, 1985}, { 1827, 2320}, { 941, 3314}, { 2351, 2977}, { 3616, 2420}, +{ 3451, 3096}, { 2955, 4301}, { 1848, 4500}, { 3884, 5416}, { 1187, 7210}, +{ 3083, 9000}, { 7384, 883}, { 5962, 1506}, { 5155, 2134}, { 7944, 2009}, +{ 6507, 2250}, { 7670, 2752}, { 5952, 3016}, { 4898, 3764}, { 6989, 3588}, +{ 8174, 3978}, { 6064, 4404}, { 7709, 5087}, { 5523, 6021}, { 7769, 7126}, +{ 6060, 7938}, { 5594,11487}, {10581, 1356}, { 9049, 1597}, { 9794, 2035}, +{ 8946, 2415}, {10296, 2584}, { 9407, 2734}, { 8700, 3218}, { 9757, 3395}, +{10177, 3892}, { 9170, 4528}, {10152, 5004}, { 9114, 5735}, {10500, 6266}, +{10110, 7631}, { 8844, 8727}, { 8956,12496}, {12924, 976}, {11435, 1755}, +{12138, 2328}, {11388, 2368}, {10700, 3064}, {12332, 2861}, {11722, 3327}, +{11270, 3700}, {10861, 4413}, {12082, 4533}, {11283, 5205}, {11960, 6305}, +{11167, 7534}, {12128, 8329}, {10969,10777}, {10300,17376}, {13899, 1681}, +{12580, 2045}, {13265, 2439}, {14033, 2989}, {13452, 3098}, {12396, 3658}, +{13510, 3780}, {12880, 4272}, {13533, 4861}, {12667, 5457}, {13854, 6106}, +{13031, 6483}, {13557, 7721}, {12957, 9311}, {13714,11551}, {12591,15206}, +{15113, 1540}, {15072, 2333}, {14527, 2511}, {14692, 3199}, {15382, 3560}, +{14133, 3960}, {15102, 4236}, {14332, 4824}, {14846, 5451}, {15306, 6083}, +{14329, 6888}, {15060, 7689}, {14406, 9426}, {15387, 9741}, {14824,14271}, +{13600,24939}, {16396, 1969}, {16817, 2832}, {15713, 2843}, {16104, 3336}, +{16384, 3963}, {16940, 4579}, {15711, 4599}, {16222, 5448}, {16832, 6382}, +{15745, 7141}, {16326, 7469}, {16611, 8624}, {17028,10418}, {15905,11817}, +{16878,14690}, {16515,20870}, {18142, 2083}, {19401, 3178}, {17508, 3426}, +{20054, 4027}, {18069, 4249}, {18952, 5066}, {17711, 5402}, {19835, 6192}, +{17950, 7014}, {21318, 7877}, {17910, 9289}, {19144, 9290}, {20517,11381}, +{18075,14485}, {19999,17882}, {18842,32764} +}; + +/** gain table for 5.15 and 5.90 kbps modes + * + * second index is {pitch_gain, fixed_gain_factor} */ +static const uint16_t gains_low[64][2] = { +{10813,28753}, {20480, 2785}, {18841, 6594}, { 6225, 7413}, {17203,10444}, +{21626, 1269}, {21135, 4423}, {11304, 1556}, {19005,12820}, {17367, 2498}, +{17858, 4833}, { 9994, 2498}, {17530, 7864}, {14254, 1884}, {15892, 3153}, +{ 6717, 1802}, {18186,20193}, {18022, 3031}, {16711, 5857}, { 8847, 4014}, +{15892, 8970}, {18022, 1392}, {16711, 4096}, { 8192, 655}, {15237,13926}, +{14254, 3112}, {14090, 4669}, { 5406, 2703}, {13434, 6553}, {12451, 901}, +{12451, 2662}, { 3768, 655}, {14745,23511}, {19169, 2457}, {20152, 5079}, +{ 6881, 4096}, {20480, 8560}, {19660, 737}, {19005, 4259}, { 7864, 2088}, +{11468,12288}, {15892, 1474}, {15728, 4628}, { 9175, 1433}, {16056, 7004}, +{14827, 737}, {15073, 2252}, { 5079, 1228}, {13271,17326}, {16547, 2334}, +{15073, 5816}, { 3932, 3686}, {14254, 8601}, {16875, 778}, {15073, 3809}, +{ 6062, 614}, { 9338, 9256}, {13271, 1761}, {13271, 3522}, { 2457, 1966}, +{11468, 5529}, {10485, 737}, {11632, 3194}, { 1474, 778} +}; + + +// pre-processing tables + +/** impulse response filter tables converted to float from Q15 int32_t + * used for anti-sparseness processing */ +static const float ir_filter_strong_MODE_7k95[AMR_SUBFRAME_SIZE] = { + 0.817169, 0.024445, 0.076447, -0.020844, -0.042175, 0.017761, 0.018433, +-0.038879, 0.107147, -0.179871, 0.138367, -0.015228, -0.059204, 0.091888, +-0.154358, 0.171326, -0.060730, -0.032379, -0.044525, 0.135559, -0.021362, +-0.162811, 0.140656, 0.013794, -0.017975, -0.102295, 0.090118, 0.038666, +-0.036987, -0.079041, 0.052826, 0.112000, -0.136566, -0.029755, 0.134003, +-0.077423, 0.028961, -0.041595, -0.029877, 0.174988, +}; + +static const float ir_filter_strong[AMR_SUBFRAME_SIZE] = { + 0.448303, 0.351501, 0.038696, -0.084259, -0.173065, 0.229309, -0.001068, +-0.085663, -0.092773, 0.147186, 0.090088, -0.257080, 0.115509, 0.044403, + 0.066498, -0.263580, 0.245697, -0.064178, -0.044373, 0.023712, 0.033813, +-0.072784, 0.068787, -0.011078, -0.020569, -0.064178, 0.184509, -0.173370, + 0.032715, 0.095306, -0.154358, 0.162109, -0.071075, -0.113770, 0.211304, +-0.118683, 0.020599, -0.054169, 0.000885, 0.309601, +}; + +static const float ir_filter_medium[AMR_SUBFRAME_SIZE] = { + 0.923889, 0.116913, -0.123169, 0.090698, -0.031982, -0.030579, 0.075592, +-0.092865, 0.085907, -0.068085, 0.053497, -0.049164, 0.052307, -0.054169, + 0.047089, -0.030762, 0.013092, -0.005157, 0.014404, -0.038574, 0.066406, +-0.082581, 0.076996, -0.049469, 0.010498, 0.025208, -0.046661, 0.052612, +-0.050568, 0.051910, -0.062958, 0.080688, -0.093384, 0.088409, -0.060364, + 0.016998, 0.023804, -0.041779, 0.025696, 0.019989, +}; + +static const float *ir_filters_lookup[2] = { + ir_filter_strong, ir_filter_medium +}; +static const float *ir_filters_lookup_MODE_7k95[2] = { + ir_filter_strong_MODE_7k95, ir_filter_medium +}; + +// High-pass coefficients + +static const float highpass_zeros[2] = { -2.0, 1.0 }; +static const float highpass_poles[2] = { -1.933105469, 0.935913085 }; +static const float highpass_gain = 0.939819335; + +#endif /* AVCODEC_AMRNBDATA_H */ + diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/amrnbdec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/amrnbdec.c new file mode 100644 index 0000000000..d3fa7653f8 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/amrnbdec.c @@ -0,0 +1,1076 @@ +/* + * AMR narrowband decoder + * Copyright (c) 2006-2007 Robert Swain + * Copyright (c) 2009 Colin McQuillan + * + * 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 + * AMR narrowband decoder + * + * This decoder uses floats for simplicity and so is not bit-exact. One + * difference is that differences in phase can accumulate. The test sequences + * in 3GPP TS 26.074 can still be useful. + * + * - Comparing this file's output to the output of the ref decoder gives a + * PSNR of 30 to 80. Plotting the output samples shows a difference in + * phase in some areas. + * + * - Comparing both decoders against their input, this decoder gives a similar + * PSNR. If the test sequence homing frames are removed (this decoder does + * not detect them), the PSNR is at least as good as the reference on 140 + * out of 169 tests. + */ + + +#include +#include + +#include "avcodec.h" +#include "get_bits.h" +#include "libavutil/common.h" +#include "celp_math.h" +#include "celp_filters.h" +#include "acelp_filters.h" +#include "acelp_vectors.h" +#include "acelp_pitch_delay.h" +#include "lsp.h" + +#include "amrnbdata.h" + +#define AMR_BLOCK_SIZE 160 ///< samples per frame +#define AMR_SAMPLE_BOUND 32768.0 ///< threshold for synthesis overflow + +/** + * Scale from constructed speech to [-1,1] + * + * AMR is designed to produce 16-bit PCM samples (3GPP TS 26.090 4.2) but + * upscales by two (section 6.2.2). + * + * Fundamentally, this scale is determined by energy_mean through + * the fixed vector contribution to the excitation vector. + */ +#define AMR_SAMPLE_SCALE (2.0 / 32768.0) + +/** Prediction factor for 12.2kbit/s mode */ +#define PRED_FAC_MODE_12k2 0.65 + +#define LSF_R_FAC (8000.0 / 32768.0) ///< LSF residual tables to Hertz +#define MIN_LSF_SPACING (50.0488 / 8000.0) ///< Ensures stability of LPC filter +#define PITCH_LAG_MIN_MODE_12k2 18 ///< Lower bound on decoded lag search in 12.2kbit/s mode + +/** Initial energy in dB. Also used for bad frames (unimplemented). */ +#define MIN_ENERGY -14.0 + +/** Maximum sharpening factor + * + * The specification says 0.8, which should be 13107, but the reference C code + * uses 13017 instead. (Amusingly the same applies to SHARP_MAX in g729dec.c.) + */ +#define SHARP_MAX 0.79449462890625 + +/** Number of impulse response coefficients used for tilt factor */ +#define AMR_TILT_RESPONSE 22 +/** Tilt factor = 1st reflection coefficient * gamma_t */ +#define AMR_TILT_GAMMA_T 0.8 +/** Adaptive gain control factor used in post-filter */ +#define AMR_AGC_ALPHA 0.9 + +typedef struct AMRContext { + AMRNBFrame frame; ///< decoded AMR parameters (lsf coefficients, codebook indexes, etc) + uint8_t bad_frame_indicator; ///< bad frame ? 1 : 0 + enum Mode cur_frame_mode; + + int16_t prev_lsf_r[LP_FILTER_ORDER]; ///< residual LSF vector from previous subframe + double lsp[4][LP_FILTER_ORDER]; ///< lsp vectors from current frame + double prev_lsp_sub4[LP_FILTER_ORDER]; ///< lsp vector for the 4th subframe of the previous frame + + float lsf_q[4][LP_FILTER_ORDER]; ///< Interpolated LSF vector for fixed gain smoothing + float lsf_avg[LP_FILTER_ORDER]; ///< vector of averaged lsf vector + + float lpc[4][LP_FILTER_ORDER]; ///< lpc coefficient vectors for 4 subframes + + uint8_t pitch_lag_int; ///< integer part of pitch lag from current subframe + + float excitation_buf[PITCH_DELAY_MAX + LP_FILTER_ORDER + 1 + AMR_SUBFRAME_SIZE]; ///< current excitation and all necessary excitation history + float *excitation; ///< pointer to the current excitation vector in excitation_buf + + float pitch_vector[AMR_SUBFRAME_SIZE]; ///< adaptive code book (pitch) vector + float fixed_vector[AMR_SUBFRAME_SIZE]; ///< algebraic codebook (fixed) vector (must be kept zero between frames) + + float prediction_error[4]; ///< quantified prediction errors {20log10(^gamma_gc)} for previous four subframes + float pitch_gain[5]; ///< quantified pitch gains for the current and previous four subframes + float fixed_gain[5]; ///< quantified fixed gains for the current and previous four subframes + + float beta; ///< previous pitch_gain, bounded by [0.0,SHARP_MAX] + uint8_t diff_count; ///< the number of subframes for which diff has been above 0.65 + uint8_t hang_count; ///< the number of subframes since a hangover period started + + float prev_sparse_fixed_gain; ///< previous fixed gain; used by anti-sparseness processing to determine "onset" + uint8_t prev_ir_filter_nr; ///< previous impulse response filter "impNr": 0 - strong, 1 - medium, 2 - none + uint8_t ir_filter_onset; ///< flag for impulse response filter strength + + float postfilter_mem[10]; ///< previous intermediate values in the formant filter + float tilt_mem; ///< previous input to tilt compensation filter + float postfilter_agc; ///< previous factor used for adaptive gain control + float high_pass_mem[2]; ///< previous intermediate values in the high-pass filter + + float samples_in[LP_FILTER_ORDER + AMR_SUBFRAME_SIZE]; ///< floating point samples + +} AMRContext; + +/** Double version of ff_weighted_vector_sumf() */ +static void weighted_vector_sumd(double *out, const double *in_a, + const double *in_b, double weight_coeff_a, + double weight_coeff_b, int length) +{ + int i; + + for (i = 0; i < length; i++) + out[i] = weight_coeff_a * in_a[i] + + weight_coeff_b * in_b[i]; +} + +static av_cold int amrnb_decode_init(AVCodecContext *avctx) +{ + AMRContext *p = avctx->priv_data; + int i; + + avctx->sample_fmt = SAMPLE_FMT_FLT; + + // p->excitation always points to the same position in p->excitation_buf + p->excitation = &p->excitation_buf[PITCH_DELAY_MAX + LP_FILTER_ORDER + 1]; + + for (i = 0; i < LP_FILTER_ORDER; i++) { + p->prev_lsp_sub4[i] = lsp_sub4_init[i] * 1000 / (float)(1 << 15); + p->lsf_avg[i] = p->lsf_q[3][i] = lsp_avg_init[i] / (float)(1 << 15); + } + + for (i = 0; i < 4; i++) + p->prediction_error[i] = MIN_ENERGY; + + return 0; +} + + +/** + * Unpack an RFC4867 speech frame into the AMR frame mode and parameters. + * + * The order of speech bits is specified by 3GPP TS 26.101. + * + * @param p the context + * @param buf pointer to the input buffer + * @param buf_size size of the input buffer + * + * @return the frame mode + */ +static enum Mode unpack_bitstream(AMRContext *p, const uint8_t *buf, + int buf_size) +{ + GetBitContext gb; + enum Mode mode; + + init_get_bits(&gb, buf, buf_size * 8); + + // Decode the first octet. + skip_bits(&gb, 1); // padding bit + mode = get_bits(&gb, 4); // frame type + p->bad_frame_indicator = !get_bits1(&gb); // quality bit + skip_bits(&gb, 2); // two padding bits + + if (mode < MODE_DTX) { + uint16_t *data = (uint16_t *)&p->frame; + const uint8_t *order = amr_unpacking_bitmaps_per_mode[mode]; + int field_size; + + memset(&p->frame, 0, sizeof(AMRNBFrame)); + buf++; + while ((field_size = *order++)) { + int field = 0; + int field_offset = *order++; + while (field_size--) { + int bit = *order++; + field <<= 1; + field |= buf[bit >> 3] >> (bit & 7) & 1; + } + data[field_offset] = field; + } + } + + return mode; +} + + +/// @defgroup amr_lpc_decoding AMR pitch LPC coefficient decoding functions +/// @{ + +/** + * Convert an lsf vector into an lsp vector. + * + * @param lsf input lsf vector + * @param lsp output lsp vector + */ +static void lsf2lsp(const float *lsf, double *lsp) +{ + int i; + + for (i = 0; i < LP_FILTER_ORDER; i++) + lsp[i] = cos(2.0 * M_PI * lsf[i]); +} + +/** + * Interpolate the LSF vector (used for fixed gain smoothing). + * The interpolation is done over all four subframes even in MODE_12k2. + * + * @param[in,out] lsf_q LSFs in [0,1] for each subframe + * @param[in] lsf_new New LSFs in [0,1] for subframe 4 + */ +static void interpolate_lsf(float lsf_q[4][LP_FILTER_ORDER], float *lsf_new) +{ + int i; + + for (i = 0; i < 4; i++) + ff_weighted_vector_sumf(lsf_q[i], lsf_q[3], lsf_new, + 0.25 * (3 - i), 0.25 * (i + 1), + LP_FILTER_ORDER); +} + +/** + * Decode a set of 5 split-matrix quantized lsf indexes into an lsp vector. + * + * @param p the context + * @param lsp output LSP vector + * @param lsf_no_r LSF vector without the residual vector added + * @param lsf_quantizer pointers to LSF dictionary tables + * @param quantizer_offset offset in tables + * @param sign for the 3 dictionary table + * @param update store data for computing the next frame's LSFs + */ +static void lsf2lsp_for_mode12k2(AMRContext *p, double lsp[LP_FILTER_ORDER], + const float lsf_no_r[LP_FILTER_ORDER], + const int16_t *lsf_quantizer[5], + const int quantizer_offset, + const int sign, const int update) +{ + int16_t lsf_r[LP_FILTER_ORDER]; // residual LSF vector + float lsf_q[LP_FILTER_ORDER]; // quantified LSF vector + int i; + + for (i = 0; i < LP_FILTER_ORDER >> 1; i++) + memcpy(&lsf_r[i << 1], &lsf_quantizer[i][quantizer_offset], + 2 * sizeof(*lsf_r)); + + if (sign) { + lsf_r[4] *= -1; + lsf_r[5] *= -1; + } + + if (update) + memcpy(p->prev_lsf_r, lsf_r, LP_FILTER_ORDER * sizeof(float)); + + for (i = 0; i < LP_FILTER_ORDER; i++) + lsf_q[i] = lsf_r[i] * (LSF_R_FAC / 8000.0) + lsf_no_r[i] * (1.0 / 8000.0); + + ff_set_min_dist_lsf(lsf_q, MIN_LSF_SPACING, LP_FILTER_ORDER); + + if (update) + interpolate_lsf(p->lsf_q, lsf_q); + + lsf2lsp(lsf_q, lsp); +} + +/** + * Decode a set of 5 split-matrix quantized lsf indexes into 2 lsp vectors. + * + * @param p pointer to the AMRContext + */ +static void lsf2lsp_5(AMRContext *p) +{ + const uint16_t *lsf_param = p->frame.lsf; + float lsf_no_r[LP_FILTER_ORDER]; // LSFs without the residual vector + const int16_t *lsf_quantizer[5]; + int i; + + lsf_quantizer[0] = lsf_5_1[lsf_param[0]]; + lsf_quantizer[1] = lsf_5_2[lsf_param[1]]; + lsf_quantizer[2] = lsf_5_3[lsf_param[2] >> 1]; + lsf_quantizer[3] = lsf_5_4[lsf_param[3]]; + lsf_quantizer[4] = lsf_5_5[lsf_param[4]]; + + for (i = 0; i < LP_FILTER_ORDER; i++) + lsf_no_r[i] = p->prev_lsf_r[i] * LSF_R_FAC * PRED_FAC_MODE_12k2 + lsf_5_mean[i]; + + lsf2lsp_for_mode12k2(p, p->lsp[1], lsf_no_r, lsf_quantizer, 0, lsf_param[2] & 1, 0); + lsf2lsp_for_mode12k2(p, p->lsp[3], lsf_no_r, lsf_quantizer, 2, lsf_param[2] & 1, 1); + + // interpolate LSP vectors at subframes 1 and 3 + weighted_vector_sumd(p->lsp[0], p->prev_lsp_sub4, p->lsp[1], 0.5, 0.5, LP_FILTER_ORDER); + weighted_vector_sumd(p->lsp[2], p->lsp[1] , p->lsp[3], 0.5, 0.5, LP_FILTER_ORDER); +} + +/** + * Decode a set of 3 split-matrix quantized lsf indexes into an lsp vector. + * + * @param p pointer to the AMRContext + */ +static void lsf2lsp_3(AMRContext *p) +{ + const uint16_t *lsf_param = p->frame.lsf; + int16_t lsf_r[LP_FILTER_ORDER]; // residual LSF vector + float lsf_q[LP_FILTER_ORDER]; // quantified LSF vector + const int16_t *lsf_quantizer; + int i, j; + + lsf_quantizer = (p->cur_frame_mode == MODE_7k95 ? lsf_3_1_MODE_7k95 : lsf_3_1)[lsf_param[0]]; + memcpy(lsf_r, lsf_quantizer, 3 * sizeof(*lsf_r)); + + lsf_quantizer = lsf_3_2[lsf_param[1] << (p->cur_frame_mode <= MODE_5k15)]; + memcpy(lsf_r + 3, lsf_quantizer, 3 * sizeof(*lsf_r)); + + lsf_quantizer = (p->cur_frame_mode <= MODE_5k15 ? lsf_3_3_MODE_5k15 : lsf_3_3)[lsf_param[2]]; + memcpy(lsf_r + 6, lsf_quantizer, 4 * sizeof(*lsf_r)); + + // calculate mean-removed LSF vector and add mean + for (i = 0; i < LP_FILTER_ORDER; i++) + lsf_q[i] = (lsf_r[i] + p->prev_lsf_r[i] * pred_fac[i]) * (LSF_R_FAC / 8000.0) + lsf_3_mean[i] * (1.0 / 8000.0); + + ff_set_min_dist_lsf(lsf_q, MIN_LSF_SPACING, LP_FILTER_ORDER); + + // store data for computing the next frame's LSFs + interpolate_lsf(p->lsf_q, lsf_q); + memcpy(p->prev_lsf_r, lsf_r, LP_FILTER_ORDER * sizeof(*lsf_r)); + + lsf2lsp(lsf_q, p->lsp[3]); + + // interpolate LSP vectors at subframes 1, 2 and 3 + for (i = 1; i <= 3; i++) + for(j = 0; j < LP_FILTER_ORDER; j++) + p->lsp[i-1][j] = p->prev_lsp_sub4[j] + + (p->lsp[3][j] - p->prev_lsp_sub4[j]) * 0.25 * i; +} + +/// @} + + +/// @defgroup amr_pitch_vector_decoding AMR pitch vector decoding functions +/// @{ + +/** + * Like ff_decode_pitch_lag(), but with 1/6 resolution + */ +static void decode_pitch_lag_1_6(int *lag_int, int *lag_frac, int pitch_index, + const int prev_lag_int, const int subframe) +{ + if (subframe == 0 || subframe == 2) { + if (pitch_index < 463) { + *lag_int = (pitch_index + 107) * 10923 >> 16; + *lag_frac = pitch_index - *lag_int * 6 + 105; + } else { + *lag_int = pitch_index - 368; + *lag_frac = 0; + } + } else { + *lag_int = ((pitch_index + 5) * 10923 >> 16) - 1; + *lag_frac = pitch_index - *lag_int * 6 - 3; + *lag_int += av_clip(prev_lag_int - 5, PITCH_LAG_MIN_MODE_12k2, + PITCH_DELAY_MAX - 9); + } +} + +static void decode_pitch_vector(AMRContext *p, + const AMRNBSubframe *amr_subframe, + const int subframe) +{ + int pitch_lag_int, pitch_lag_frac; + enum Mode mode = p->cur_frame_mode; + + if (p->cur_frame_mode == MODE_12k2) { + decode_pitch_lag_1_6(&pitch_lag_int, &pitch_lag_frac, + amr_subframe->p_lag, p->pitch_lag_int, + subframe); + } else + ff_decode_pitch_lag(&pitch_lag_int, &pitch_lag_frac, + amr_subframe->p_lag, + p->pitch_lag_int, subframe, + mode != MODE_4k75 && mode != MODE_5k15, + mode <= MODE_6k7 ? 4 : (mode == MODE_7k95 ? 5 : 6)); + + p->pitch_lag_int = pitch_lag_int; // store previous lag in a uint8_t + + pitch_lag_frac <<= (p->cur_frame_mode != MODE_12k2); + + pitch_lag_int += pitch_lag_frac > 0; + + /* Calculate the pitch vector by interpolating the past excitation at the + pitch lag using a b60 hamming windowed sinc function. */ + ff_acelp_interpolatef(p->excitation, p->excitation + 1 - pitch_lag_int, + ff_b60_sinc, 6, + pitch_lag_frac + 6 - 6*(pitch_lag_frac > 0), + 10, AMR_SUBFRAME_SIZE); + + memcpy(p->pitch_vector, p->excitation, AMR_SUBFRAME_SIZE * sizeof(float)); +} + +/// @} + + +/// @defgroup amr_algebraic_code_book AMR algebraic code book (fixed) vector decoding functions +/// @{ + +/** + * Decode a 10-bit algebraic codebook index from a 10.2 kbit/s frame. + */ +static void decode_10bit_pulse(int code, int pulse_position[8], + int i1, int i2, int i3) +{ + // coded using 7+3 bits with the 3 LSBs being, individually, the LSB of 1 of + // the 3 pulses and the upper 7 bits being coded in base 5 + const uint8_t *positions = base_five_table[code >> 3]; + pulse_position[i1] = (positions[2] << 1) + ( code & 1); + pulse_position[i2] = (positions[1] << 1) + ((code >> 1) & 1); + pulse_position[i3] = (positions[0] << 1) + ((code >> 2) & 1); +} + +/** + * Decode the algebraic codebook index to pulse positions and signs and + * construct the algebraic codebook vector for MODE_10k2. + * + * @param fixed_index positions of the eight pulses + * @param fixed_sparse pointer to the algebraic codebook vector + */ +static void decode_8_pulses_31bits(const int16_t *fixed_index, + AMRFixed *fixed_sparse) +{ + int pulse_position[8]; + int i, temp; + + decode_10bit_pulse(fixed_index[4], pulse_position, 0, 4, 1); + decode_10bit_pulse(fixed_index[5], pulse_position, 2, 6, 5); + + // coded using 5+2 bits with the 2 LSBs being, individually, the LSB of 1 of + // the 2 pulses and the upper 5 bits being coded in base 5 + temp = ((fixed_index[6] >> 2) * 25 + 12) >> 5; + pulse_position[3] = temp % 5; + pulse_position[7] = temp / 5; + if (pulse_position[7] & 1) + pulse_position[3] = 4 - pulse_position[3]; + pulse_position[3] = (pulse_position[3] << 1) + ( fixed_index[6] & 1); + pulse_position[7] = (pulse_position[7] << 1) + ((fixed_index[6] >> 1) & 1); + + fixed_sparse->n = 8; + for (i = 0; i < 4; i++) { + const int pos1 = (pulse_position[i] << 2) + i; + const int pos2 = (pulse_position[i + 4] << 2) + i; + const float sign = fixed_index[i] ? -1.0 : 1.0; + fixed_sparse->x[i ] = pos1; + fixed_sparse->x[i + 4] = pos2; + fixed_sparse->y[i ] = sign; + fixed_sparse->y[i + 4] = pos2 < pos1 ? -sign : sign; + } +} + +/** + * Decode the algebraic codebook index to pulse positions and signs, + * then construct the algebraic codebook vector. + * + * nb of pulses | bits encoding pulses + * For MODE_4k75 or MODE_5k15, 2 | 1-3, 4-6, 7 + * MODE_5k9, 2 | 1, 2-4, 5-6, 7-9 + * MODE_6k7, 3 | 1-3, 4, 5-7, 8, 9-11 + * MODE_7k4 or MODE_7k95, 4 | 1-3, 4-6, 7-9, 10, 11-13 + * + * @param fixed_sparse pointer to the algebraic codebook vector + * @param pulses algebraic codebook indexes + * @param mode mode of the current frame + * @param subframe current subframe number + */ +static void decode_fixed_sparse(AMRFixed *fixed_sparse, const uint16_t *pulses, + const enum Mode mode, const int subframe) +{ + assert(MODE_4k75 <= mode && mode <= MODE_12k2); + + if (mode == MODE_12k2) { + ff_decode_10_pulses_35bits(pulses, fixed_sparse, gray_decode, 5, 3); + } else if (mode == MODE_10k2) { + decode_8_pulses_31bits(pulses, fixed_sparse); + } else { + int *pulse_position = fixed_sparse->x; + int i, pulse_subset; + const int fixed_index = pulses[0]; + + if (mode <= MODE_5k15) { + pulse_subset = ((fixed_index >> 3) & 8) + (subframe << 1); + pulse_position[0] = ( fixed_index & 7) * 5 + track_position[pulse_subset]; + pulse_position[1] = ((fixed_index >> 3) & 7) * 5 + track_position[pulse_subset + 1]; + fixed_sparse->n = 2; + } else if (mode == MODE_5k9) { + pulse_subset = ((fixed_index & 1) << 1) + 1; + pulse_position[0] = ((fixed_index >> 1) & 7) * 5 + pulse_subset; + pulse_subset = (fixed_index >> 4) & 3; + pulse_position[1] = ((fixed_index >> 6) & 7) * 5 + pulse_subset + (pulse_subset == 3 ? 1 : 0); + fixed_sparse->n = pulse_position[0] == pulse_position[1] ? 1 : 2; + } else if (mode == MODE_6k7) { + pulse_position[0] = (fixed_index & 7) * 5; + pulse_subset = (fixed_index >> 2) & 2; + pulse_position[1] = ((fixed_index >> 4) & 7) * 5 + pulse_subset + 1; + pulse_subset = (fixed_index >> 6) & 2; + pulse_position[2] = ((fixed_index >> 8) & 7) * 5 + pulse_subset + 2; + fixed_sparse->n = 3; + } else { // mode <= MODE_7k95 + pulse_position[0] = gray_decode[ fixed_index & 7]; + pulse_position[1] = gray_decode[(fixed_index >> 3) & 7] + 1; + pulse_position[2] = gray_decode[(fixed_index >> 6) & 7] + 2; + pulse_subset = (fixed_index >> 9) & 1; + pulse_position[3] = gray_decode[(fixed_index >> 10) & 7] + pulse_subset + 3; + fixed_sparse->n = 4; + } + for (i = 0; i < fixed_sparse->n; i++) + fixed_sparse->y[i] = (pulses[1] >> i) & 1 ? 1.0 : -1.0; + } +} + +/** + * Apply pitch lag to obtain the sharpened fixed vector (section 6.1.2) + * + * @param p the context + * @param subframe unpacked amr subframe + * @param mode mode of the current frame + * @param fixed_sparse sparse respresentation of the fixed vector + */ +static void pitch_sharpening(AMRContext *p, int subframe, enum Mode mode, + AMRFixed *fixed_sparse) +{ + // The spec suggests the current pitch gain is always used, but in other + // modes the pitch and codebook gains are joinly quantized (sec 5.8.2) + // so the codebook gain cannot depend on the quantized pitch gain. + if (mode == MODE_12k2) + p->beta = FFMIN(p->pitch_gain[4], 1.0); + + fixed_sparse->pitch_lag = p->pitch_lag_int; + fixed_sparse->pitch_fac = p->beta; + + // Save pitch sharpening factor for the next subframe + // MODE_4k75 only updates on the 2nd and 4th subframes - this follows from + // the fact that the gains for two subframes are jointly quantized. + if (mode != MODE_4k75 || subframe & 1) + p->beta = av_clipf(p->pitch_gain[4], 0.0, SHARP_MAX); +} +/// @} + + +/// @defgroup amr_gain_decoding AMR gain decoding functions +/// @{ + +/** + * fixed gain smoothing + * Note that where the spec specifies the "spectrum in the q domain" + * in section 6.1.4, in fact frequencies should be used. + * + * @param p the context + * @param lsf LSFs for the current subframe, in the range [0,1] + * @param lsf_avg averaged LSFs + * @param mode mode of the current frame + * + * @return fixed gain smoothed + */ +static float fixed_gain_smooth(AMRContext *p , const float *lsf, + const float *lsf_avg, const enum Mode mode) +{ + float diff = 0.0; + int i; + + for (i = 0; i < LP_FILTER_ORDER; i++) + diff += fabs(lsf_avg[i] - lsf[i]) / lsf_avg[i]; + + // If diff is large for ten subframes, disable smoothing for a 40-subframe + // hangover period. + p->diff_count++; + if (diff <= 0.65) + p->diff_count = 0; + + if (p->diff_count > 10) { + p->hang_count = 0; + p->diff_count--; // don't let diff_count overflow + } + + if (p->hang_count < 40) { + p->hang_count++; + } else if (mode < MODE_7k4 || mode == MODE_10k2) { + const float smoothing_factor = av_clipf(4.0 * diff - 1.6, 0.0, 1.0); + const float fixed_gain_mean = (p->fixed_gain[0] + p->fixed_gain[1] + + p->fixed_gain[2] + p->fixed_gain[3] + + p->fixed_gain[4]) * 0.2; + return smoothing_factor * p->fixed_gain[4] + + (1.0 - smoothing_factor) * fixed_gain_mean; + } + return p->fixed_gain[4]; +} + +/** + * Decode pitch gain and fixed gain factor (part of section 6.1.3). + * + * @param p the context + * @param amr_subframe unpacked amr subframe + * @param mode mode of the current frame + * @param subframe current subframe number + * @param fixed_gain_factor decoded gain correction factor + */ +static void decode_gains(AMRContext *p, const AMRNBSubframe *amr_subframe, + const enum Mode mode, const int subframe, + float *fixed_gain_factor) +{ + if (mode == MODE_12k2 || mode == MODE_7k95) { + p->pitch_gain[4] = qua_gain_pit [amr_subframe->p_gain ] + * (1.0 / 16384.0); + *fixed_gain_factor = qua_gain_code[amr_subframe->fixed_gain] + * (1.0 / 2048.0); + } else { + const uint16_t *gains; + + if (mode >= MODE_6k7) { + gains = gains_high[amr_subframe->p_gain]; + } else if (mode >= MODE_5k15) { + gains = gains_low [amr_subframe->p_gain]; + } else { + // gain index is only coded in subframes 0,2 for MODE_4k75 + gains = gains_MODE_4k75[(p->frame.subframe[subframe & 2].p_gain << 1) + (subframe & 1)]; + } + + p->pitch_gain[4] = gains[0] * (1.0 / 16384.0); + *fixed_gain_factor = gains[1] * (1.0 / 4096.0); + } +} + +/// @} + + +/// @defgroup amr_pre_processing AMR pre-processing functions +/// @{ + +/** + * Circularly convolve a sparse fixed vector with a phase dispersion impulse + * response filter (D.6.2 of G.729 and 6.1.5 of AMR). + * + * @param out vector with filter applied + * @param in source vector + * @param filter phase filter coefficients + * + * out[n] = sum(i,0,len-1){ in[i] * filter[(len + n - i)%len] } + */ +static void apply_ir_filter(float *out, const AMRFixed *in, + const float *filter) +{ + float filter1[AMR_SUBFRAME_SIZE], //!< filters at pitch lag*1 and *2 + filter2[AMR_SUBFRAME_SIZE]; + int lag = in->pitch_lag; + float fac = in->pitch_fac; + int i; + + if (lag < AMR_SUBFRAME_SIZE) { + ff_celp_circ_addf(filter1, filter, filter, lag, fac, + AMR_SUBFRAME_SIZE); + + if (lag < AMR_SUBFRAME_SIZE >> 1) + ff_celp_circ_addf(filter2, filter, filter1, lag, fac, + AMR_SUBFRAME_SIZE); + } + + memset(out, 0, sizeof(float) * AMR_SUBFRAME_SIZE); + for (i = 0; i < in->n; i++) { + int x = in->x[i]; + float y = in->y[i]; + const float *filterp; + + if (x >= AMR_SUBFRAME_SIZE - lag) { + filterp = filter; + } else if (x >= AMR_SUBFRAME_SIZE - (lag << 1)) { + filterp = filter1; + } else + filterp = filter2; + + ff_celp_circ_addf(out, out, filterp, x, y, AMR_SUBFRAME_SIZE); + } +} + +/** + * Reduce fixed vector sparseness by smoothing with one of three IR filters. + * Also know as "adaptive phase dispersion". + * + * This implements 3GPP TS 26.090 section 6.1(5). + * + * @param p the context + * @param fixed_sparse algebraic codebook vector + * @param fixed_vector unfiltered fixed vector + * @param fixed_gain smoothed gain + * @param out space for modified vector if necessary + */ +static const float *anti_sparseness(AMRContext *p, AMRFixed *fixed_sparse, + const float *fixed_vector, + float fixed_gain, float *out) +{ + int ir_filter_nr; + + if (p->pitch_gain[4] < 0.6) { + ir_filter_nr = 0; // strong filtering + } else if (p->pitch_gain[4] < 0.9) { + ir_filter_nr = 1; // medium filtering + } else + ir_filter_nr = 2; // no filtering + + // detect 'onset' + if (fixed_gain > 2.0 * p->prev_sparse_fixed_gain) { + p->ir_filter_onset = 2; + } else if (p->ir_filter_onset) + p->ir_filter_onset--; + + if (!p->ir_filter_onset) { + int i, count = 0; + + for (i = 0; i < 5; i++) + if (p->pitch_gain[i] < 0.6) + count++; + if (count > 2) + ir_filter_nr = 0; + + if (ir_filter_nr > p->prev_ir_filter_nr + 1) + ir_filter_nr--; + } else if (ir_filter_nr < 2) + ir_filter_nr++; + + // Disable filtering for very low level of fixed_gain. + // Note this step is not specified in the technical description but is in + // the reference source in the function Ph_disp. + if (fixed_gain < 5.0) + ir_filter_nr = 2; + + if (p->cur_frame_mode != MODE_7k4 && p->cur_frame_mode < MODE_10k2 + && ir_filter_nr < 2) { + apply_ir_filter(out, fixed_sparse, + (p->cur_frame_mode == MODE_7k95 ? + ir_filters_lookup_MODE_7k95 : + ir_filters_lookup)[ir_filter_nr]); + fixed_vector = out; + } + + // update ir filter strength history + p->prev_ir_filter_nr = ir_filter_nr; + p->prev_sparse_fixed_gain = fixed_gain; + + return fixed_vector; +} + +/// @} + + +/// @defgroup amr_synthesis AMR synthesis functions +/// @{ + +/** + * Conduct 10th order linear predictive coding synthesis. + * + * @param p pointer to the AMRContext + * @param lpc pointer to the LPC coefficients + * @param fixed_gain fixed codebook gain for synthesis + * @param fixed_vector algebraic codebook vector + * @param samples pointer to the output speech samples + * @param overflow 16-bit overflow flag + */ +static int synthesis(AMRContext *p, float *lpc, + float fixed_gain, const float *fixed_vector, + float *samples, uint8_t overflow) +{ + int i; + float excitation[AMR_SUBFRAME_SIZE]; + + // if an overflow has been detected, the pitch vector is scaled down by a + // factor of 4 + if (overflow) + for (i = 0; i < AMR_SUBFRAME_SIZE; i++) + p->pitch_vector[i] *= 0.25; + + ff_weighted_vector_sumf(excitation, p->pitch_vector, fixed_vector, + p->pitch_gain[4], fixed_gain, AMR_SUBFRAME_SIZE); + + // emphasize pitch vector contribution + if (p->pitch_gain[4] > 0.5 && !overflow) { + float energy = ff_dot_productf(excitation, excitation, + AMR_SUBFRAME_SIZE); + float pitch_factor = + p->pitch_gain[4] * + (p->cur_frame_mode == MODE_12k2 ? + 0.25 * FFMIN(p->pitch_gain[4], 1.0) : + 0.5 * FFMIN(p->pitch_gain[4], SHARP_MAX)); + + for (i = 0; i < AMR_SUBFRAME_SIZE; i++) + excitation[i] += pitch_factor * p->pitch_vector[i]; + + ff_scale_vector_to_given_sum_of_squares(excitation, excitation, energy, + AMR_SUBFRAME_SIZE); + } + + ff_celp_lp_synthesis_filterf(samples, lpc, excitation, AMR_SUBFRAME_SIZE, + LP_FILTER_ORDER); + + // detect overflow + for (i = 0; i < AMR_SUBFRAME_SIZE; i++) + if (fabsf(samples[i]) > AMR_SAMPLE_BOUND) { + return 1; + } + + return 0; +} + +/// @} + + +/// @defgroup amr_update AMR update functions +/// @{ + +/** + * Update buffers and history at the end of decoding a subframe. + * + * @param p pointer to the AMRContext + */ +static void update_state(AMRContext *p) +{ + memcpy(p->prev_lsp_sub4, p->lsp[3], LP_FILTER_ORDER * sizeof(p->lsp[3][0])); + + memmove(&p->excitation_buf[0], &p->excitation_buf[AMR_SUBFRAME_SIZE], + (PITCH_DELAY_MAX + LP_FILTER_ORDER + 1) * sizeof(float)); + + memmove(&p->pitch_gain[0], &p->pitch_gain[1], 4 * sizeof(float)); + memmove(&p->fixed_gain[0], &p->fixed_gain[1], 4 * sizeof(float)); + + memmove(&p->samples_in[0], &p->samples_in[AMR_SUBFRAME_SIZE], + LP_FILTER_ORDER * sizeof(float)); +} + +/// @} + + +/// @defgroup amr_postproc AMR Post processing functions +/// @{ + +/** + * Get the tilt factor of a formant filter from its transfer function + * + * @param lpc_n LP_FILTER_ORDER coefficients of the numerator + * @param lpc_d LP_FILTER_ORDER coefficients of the denominator + */ +static float tilt_factor(float *lpc_n, float *lpc_d) +{ + float rh0, rh1; // autocorrelation at lag 0 and 1 + + // LP_FILTER_ORDER prior zeros are needed for ff_celp_lp_synthesis_filterf + float impulse_buffer[LP_FILTER_ORDER + AMR_TILT_RESPONSE] = { 0 }; + float *hf = impulse_buffer + LP_FILTER_ORDER; // start of impulse response + + hf[0] = 1.0; + memcpy(hf + 1, lpc_n, sizeof(float) * LP_FILTER_ORDER); + ff_celp_lp_synthesis_filterf(hf, lpc_d, hf, AMR_TILT_RESPONSE, + LP_FILTER_ORDER); + + rh0 = ff_dot_productf(hf, hf, AMR_TILT_RESPONSE); + rh1 = ff_dot_productf(hf, hf + 1, AMR_TILT_RESPONSE - 1); + + // The spec only specifies this check for 12.2 and 10.2 kbit/s + // modes. But in the ref source the tilt is always non-negative. + return rh1 >= 0.0 ? rh1 / rh0 * AMR_TILT_GAMMA_T : 0.0; +} + +/** + * Perform adaptive post-filtering to enhance the quality of the speech. + * See section 6.2.1. + * + * @param p pointer to the AMRContext + * @param lpc interpolated LP coefficients for this subframe + * @param buf_out output of the filter + */ +static void postfilter(AMRContext *p, float *lpc, float *buf_out) +{ + int i; + float *samples = p->samples_in + LP_FILTER_ORDER; // Start of input + + float speech_gain = ff_dot_productf(samples, samples, + AMR_SUBFRAME_SIZE); + + float pole_out[AMR_SUBFRAME_SIZE + LP_FILTER_ORDER]; // Output of pole filter + const float *gamma_n, *gamma_d; // Formant filter factor table + float lpc_n[LP_FILTER_ORDER], lpc_d[LP_FILTER_ORDER]; // Transfer function coefficients + + if (p->cur_frame_mode == MODE_12k2 || p->cur_frame_mode == MODE_10k2) { + gamma_n = ff_pow_0_7; + gamma_d = ff_pow_0_75; + } else { + gamma_n = ff_pow_0_55; + gamma_d = ff_pow_0_7; + } + + for (i = 0; i < LP_FILTER_ORDER; i++) { + lpc_n[i] = lpc[i] * gamma_n[i]; + lpc_d[i] = lpc[i] * gamma_d[i]; + } + + memcpy(pole_out, p->postfilter_mem, sizeof(float) * LP_FILTER_ORDER); + ff_celp_lp_synthesis_filterf(pole_out + LP_FILTER_ORDER, lpc_d, samples, + AMR_SUBFRAME_SIZE, LP_FILTER_ORDER); + memcpy(p->postfilter_mem, pole_out + AMR_SUBFRAME_SIZE, + sizeof(float) * LP_FILTER_ORDER); + + ff_celp_lp_zero_synthesis_filterf(buf_out, lpc_n, + pole_out + LP_FILTER_ORDER, + AMR_SUBFRAME_SIZE, LP_FILTER_ORDER); + + ff_tilt_compensation(&p->tilt_mem, tilt_factor(lpc_n, lpc_d), buf_out, + AMR_SUBFRAME_SIZE); + + ff_adaptive_gain_control(buf_out, buf_out, speech_gain, AMR_SUBFRAME_SIZE, + AMR_AGC_ALPHA, &p->postfilter_agc); +} + +/// @} + +static int amrnb_decode_frame(AVCodecContext *avctx, void *data, int *data_size, + AVPacket *avpkt) +{ + + AMRContext *p = avctx->priv_data; // pointer to private data + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + float *buf_out = data; // pointer to the output data buffer + int i, subframe; + float fixed_gain_factor; + AMRFixed fixed_sparse = {0}; // fixed vector up to anti-sparseness processing + float spare_vector[AMR_SUBFRAME_SIZE]; // extra stack space to hold result from anti-sparseness processing + float synth_fixed_gain; // the fixed gain that synthesis should use + const float *synth_fixed_vector; // pointer to the fixed vector that synthesis should use + + 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); + return -1; + } + + if (p->cur_frame_mode == MODE_12k2) { + lsf2lsp_5(p); + } else + lsf2lsp_3(p); + + for (i = 0; i < 4; i++) + ff_acelp_lspd2lpc(p->lsp[i], p->lpc[i], 5); + + for (subframe = 0; subframe < 4; subframe++) { + const AMRNBSubframe *amr_subframe = &p->frame.subframe[subframe]; + + decode_pitch_vector(p, amr_subframe, subframe); + + decode_fixed_sparse(&fixed_sparse, amr_subframe->pulses, + p->cur_frame_mode, subframe); + + // The fixed gain (section 6.1.3) depends on the fixed vector + // (section 6.1.2), but the fixed vector calculation uses + // pitch sharpening based on the on the pitch gain (section 6.1.3). + // So the correct order is: pitch gain, pitch sharpening, fixed gain. + decode_gains(p, amr_subframe, p->cur_frame_mode, subframe, + &fixed_gain_factor); + + pitch_sharpening(p, subframe, p->cur_frame_mode, &fixed_sparse); + + ff_set_fixed_vector(p->fixed_vector, &fixed_sparse, 1.0, + AMR_SUBFRAME_SIZE); + + p->fixed_gain[4] = + ff_amr_set_fixed_gain(fixed_gain_factor, + ff_dot_productf(p->fixed_vector, p->fixed_vector, + AMR_SUBFRAME_SIZE)/AMR_SUBFRAME_SIZE, + p->prediction_error, + energy_mean[p->cur_frame_mode], energy_pred_fac); + + // The excitation feedback is calculated without any processing such + // as fixed gain smoothing. This isn't mentioned in the specification. + for (i = 0; i < AMR_SUBFRAME_SIZE; i++) + p->excitation[i] *= p->pitch_gain[4]; + ff_set_fixed_vector(p->excitation, &fixed_sparse, p->fixed_gain[4], + AMR_SUBFRAME_SIZE); + + // In the ref decoder, excitation is stored with no fractional bits. + // This step prevents buzz in silent periods. The ref encoder can + // emit long sequences with pitch factor greater than one. This + // creates unwanted feedback if the excitation vector is nonzero. + // (e.g. test sequence T19_795.COD in 3GPP TS 26.074) + for (i = 0; i < AMR_SUBFRAME_SIZE; i++) + p->excitation[i] = truncf(p->excitation[i]); + + // Smooth fixed gain. + // The specification is ambiguous, but in the reference source, the + // smoothed value is NOT fed back into later fixed gain smoothing. + synth_fixed_gain = fixed_gain_smooth(p, p->lsf_q[subframe], + p->lsf_avg, p->cur_frame_mode); + + synth_fixed_vector = anti_sparseness(p, &fixed_sparse, p->fixed_vector, + synth_fixed_gain, spare_vector); + + if (synthesis(p, p->lpc[subframe], synth_fixed_gain, + synth_fixed_vector, &p->samples_in[LP_FILTER_ORDER], 0)) + // overflow detected -> rerun synthesis scaling pitch vector down + // by a factor of 4, skipping pitch vector contribution emphasis + // and adaptive gain control + synthesis(p, p->lpc[subframe], synth_fixed_gain, + synth_fixed_vector, &p->samples_in[LP_FILTER_ORDER], 1); + + postfilter(p, p->lpc[subframe], buf_out + subframe * AMR_SUBFRAME_SIZE); + + // update buffers and history + ff_clear_fixed_vector(p->fixed_vector, &fixed_sparse, AMR_SUBFRAME_SIZE); + update_state(p); + } + + ff_acelp_apply_order_2_transfer_function(buf_out, buf_out, highpass_zeros, + highpass_poles, + highpass_gain * AMR_SAMPLE_SCALE, + p->high_pass_mem, AMR_BLOCK_SIZE); + + /* Update averaged lsf vector (used for fixed gain smoothing). + * + * Note that lsf_avg should not incorporate the current frame's LSFs + * for fixed_gain_smooth. + * The specification has an incorrect formula: the reference decoder uses + * qbar(n-1) rather than qbar(n) in section 6.1(4) equation 71. */ + ff_weighted_vector_sumf(p->lsf_avg, p->lsf_avg, p->lsf_q[3], + 0.84, 0.16, LP_FILTER_ORDER); + + /* report how many samples we got */ + *data_size = AMR_BLOCK_SIZE * sizeof(float); + + /* return the amount of bytes consumed if everything was OK */ + return frame_sizes_nb[p->cur_frame_mode] + 1; // +7 for rounding and +8 for TOC +} + + +AVCodec amrnb_decoder = { + .name = "amrnb", + .type = AVMEDIA_TYPE_AUDIO, + .id = CODEC_ID_AMR_NB, + .priv_data_size = sizeof(AMRContext), + .init = amrnb_decode_init, + .decode = amrnb_decode_frame, + .long_name = NULL_IF_CONFIG_SMALL("Adaptive Multi-Rate NarrowBand"), + .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_FLT,SAMPLE_FMT_NONE}, +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/anm.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/anm.c new file mode 100644 index 0000000000..f38486188c --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/anm.c @@ -0,0 +1,197 @@ +/* + * Deluxe Paint Animation decoder + * Copyright (c) 2009 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 + */ + +/** + * @file + * Deluxe Paint Animation decoder + */ + +#include "avcodec.h" +#include "bytestream.h" + +typedef struct AnmContext { + AVFrame frame; + int x; ///< x coordinate position +} AnmContext; + +static av_cold int decode_init(AVCodecContext *avctx) +{ + AnmContext *s = avctx->priv_data; + const uint8_t *buf; + int i; + + avctx->pix_fmt = PIX_FMT_PAL8; + + if (avctx->extradata_size != 16*8 + 4*256) + return -1; + + 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); + + return 0; +} + +/** + * Perform decode operation + * @param dst, dst_end Destination image buffer + * @param buf, buf_end Source buffer (optional, see below) + * @param pixel Fill color (optional, see below) + * @param count Pixel count + * @param x Pointer to x-axis counter + * @param width Image width + * @param linesize Destination image buffer linesize + * @return non-zero if destination buffer is exhausted + * + * a copy operation is achieved when 'buf' is set + * a fill operation is acheived when 'buf' is null and pixel is >= 0 + * a skip operation is acheived when 'buf' is null and pixel is < 0 + */ +static inline int op(uint8_t **dst, const uint8_t *dst_end, + const uint8_t **buf, const uint8_t *buf_end, + int pixel, int count, + int *x, int width, int linesize) +{ + int remaining = width - *x; + while(count > 0) { + int striplen = FFMIN(count, remaining); + if (buf) { + striplen = FFMIN(striplen, buf_end - *buf); + memcpy(*dst, *buf, striplen); + *buf += striplen; + } else if (pixel >= 0) + memset(*dst, pixel, striplen); + *dst += striplen; + remaining -= striplen; + count -= striplen; + if (remaining <= 0) { + *dst += linesize - width; + remaining = width; + } + if (linesize > 0) { + if (*dst >= dst_end) goto exhausted; + } else { + if (*dst <= dst_end) goto exhausted; + } + } + *x = width - remaining; + return 0; + +exhausted: + *x = width - remaining; + return 1; +} + +static int decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + AVPacket *avpkt) +{ + AnmContext *s = avctx->priv_data; + const uint8_t *buf = avpkt->data; + const int buf_size = avpkt->size; + const uint8_t *buf_end = buf + buf_size; + uint8_t *dst, *dst_end; + int count; + + if(avctx->reget_buffer(avctx, &s->frame) < 0){ + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } + dst = s->frame.data[0]; + dst_end = s->frame.data[0] + s->frame.linesize[0]*avctx->height; + + if (buf[0] != 0x42) { + av_log_ask_for_sample(avctx, "unknown record type\n"); + return buf_size; + } + if (buf[1]) { + av_log_ask_for_sample(avctx, "padding bytes not supported\n"); + return buf_size; + } + buf += 4; + + s->x = 0; + do { + /* if statements are ordered by probability */ +#define OP(buf, pixel, count) \ + op(&dst, dst_end, (buf), buf_end, (pixel), (count), &s->x, avctx->width, s->frame.linesize[0]) + + int type = bytestream_get_byte(&buf); + count = type & 0x7F; + type >>= 7; + if (count) { + if (OP(type ? NULL : &buf, -1, count)) break; + } else if (!type) { + int pixel; + count = bytestream_get_byte(&buf); /* count==0 gives nop */ + pixel = bytestream_get_byte(&buf); + if (OP(NULL, pixel, count)) break; + } else { + int pixel; + type = bytestream_get_le16(&buf); + count = type & 0x3FFF; + type >>= 14; + if (!count) { + if (type == 0) + break; // stop + if (type == 2) { + av_log_ask_for_sample(avctx, "unknown opcode"); + return AVERROR_INVALIDDATA; + } + continue; + } + pixel = type == 3 ? bytestream_get_byte(&buf) : -1; + if (type == 1) count += 0x4000; + if (OP(type == 2 ? &buf : NULL, pixel, count)) break; + } + } while (buf + 1 < buf_end); + + *data_size = sizeof(AVFrame); + *(AVFrame*)data = s->frame; + return buf_size; +} + +static av_cold int decode_end(AVCodecContext *avctx) +{ + AnmContext *s = avctx->priv_data; + if (s->frame.data[0]) + avctx->release_buffer(avctx, &s->frame); + return 0; +} + +AVCodec anm_decoder = { + "anm", + AVMEDIA_TYPE_VIDEO, + CODEC_ID_ANM, + sizeof(AnmContext), + decode_init, + NULL, + decode_end, + decode_frame, + CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Deluxe Paint Animation"), +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/apedec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/apedec.c index 9b8d707135..a90a07fa7d 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/apedec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/apedec.c @@ -27,7 +27,7 @@ #include "bytestream.h" /** - * @file libavcodec/apedec.c + * @file * Monkey's Audio lossless audio decoder */ @@ -211,6 +211,7 @@ static av_cold int ape_decode_close(AVCodecContext * avctx) for (i = 0; i < APE_FILTER_LEVELS; i++) av_freep(&s->filterbuf[i]); + av_freep(&s->data); return 0; } @@ -408,8 +409,24 @@ static inline int ape_decode_value(APEContext * ctx, APERice *rice) overflow |= range_decode_bits(ctx, 16); } - base = range_decode_culfreq(ctx, pivot); - range_decode_update(ctx, 1, base); + if (pivot < 0x10000) { + base = range_decode_culfreq(ctx, pivot); + range_decode_update(ctx, 1, base); + } else { + int base_hi = pivot, base_lo; + int bbits = 0; + + while (base_hi & ~0xFFFF) { + base_hi >>= 1; + bbits++; + } + base_hi = range_decode_culfreq(ctx, base_hi + 1); + range_decode_update(ctx, 1, base_hi); + base_lo = range_decode_culfreq(ctx, 1 << bbits); + range_decode_update(ctx, 1, base_lo); + + base = (base_hi << bbits) + base_lo; + } x = base + overflow * pivot; } @@ -501,9 +518,9 @@ static inline int APESIGN(int32_t x) { return (x < 0) - (x > 0); } -static int predictor_update_filter(APEPredictor *p, const int decoded, const int filter, const int delayA, const int delayB, const int adaptA, const int adaptB) +static av_always_inline int predictor_update_filter(APEPredictor *p, const int decoded, const int filter, const int delayA, const int delayB, const int adaptA, const int adaptB) { - int32_t predictionA, predictionB; + int32_t predictionA, predictionB, sign; p->buf[delayA] = p->lastA[filter]; p->buf[adaptA] = APESIGN(p->buf[delayA]); @@ -531,48 +548,32 @@ static int predictor_update_filter(APEPredictor *p, const int decoded, const int p->lastA[filter] = decoded + ((predictionA + (predictionB >> 1)) >> 10); p->filterA[filter] = p->lastA[filter] + ((p->filterA[filter] * 31) >> 5); - if (!decoded) // no need updating filter coefficients - return p->filterA[filter]; + sign = APESIGN(decoded); + p->coeffsA[filter][0] += p->buf[adaptA ] * sign; + p->coeffsA[filter][1] += p->buf[adaptA - 1] * sign; + p->coeffsA[filter][2] += p->buf[adaptA - 2] * sign; + p->coeffsA[filter][3] += p->buf[adaptA - 3] * sign; + p->coeffsB[filter][0] += p->buf[adaptB ] * sign; + p->coeffsB[filter][1] += p->buf[adaptB - 1] * sign; + p->coeffsB[filter][2] += p->buf[adaptB - 2] * sign; + p->coeffsB[filter][3] += p->buf[adaptB - 3] * sign; + p->coeffsB[filter][4] += p->buf[adaptB - 4] * sign; - if (decoded > 0) { - p->coeffsA[filter][0] -= p->buf[adaptA ]; - p->coeffsA[filter][1] -= p->buf[adaptA - 1]; - p->coeffsA[filter][2] -= p->buf[adaptA - 2]; - p->coeffsA[filter][3] -= p->buf[adaptA - 3]; - - p->coeffsB[filter][0] -= p->buf[adaptB ]; - p->coeffsB[filter][1] -= p->buf[adaptB - 1]; - p->coeffsB[filter][2] -= p->buf[adaptB - 2]; - p->coeffsB[filter][3] -= p->buf[adaptB - 3]; - p->coeffsB[filter][4] -= p->buf[adaptB - 4]; - } else { - p->coeffsA[filter][0] += p->buf[adaptA ]; - p->coeffsA[filter][1] += p->buf[adaptA - 1]; - p->coeffsA[filter][2] += p->buf[adaptA - 2]; - p->coeffsA[filter][3] += p->buf[adaptA - 3]; - - p->coeffsB[filter][0] += p->buf[adaptB ]; - p->coeffsB[filter][1] += p->buf[adaptB - 1]; - p->coeffsB[filter][2] += p->buf[adaptB - 2]; - p->coeffsB[filter][3] += p->buf[adaptB - 3]; - p->coeffsB[filter][4] += p->buf[adaptB - 4]; - } return p->filterA[filter]; } static void predictor_decode_stereo(APEContext * ctx, int count) { - int32_t predictionA, predictionB; APEPredictor *p = &ctx->predictor; int32_t *decoded0 = ctx->decoded0; int32_t *decoded1 = ctx->decoded1; while (count--) { /* Predictor Y */ - predictionA = predictor_update_filter(p, *decoded0, 0, YDELAYA, YDELAYB, YADAPTCOEFFSA, YADAPTCOEFFSB); - predictionB = predictor_update_filter(p, *decoded1, 1, XDELAYA, XDELAYB, XADAPTCOEFFSA, XADAPTCOEFFSB); - *(decoded0++) = predictionA; - *(decoded1++) = predictionB; + *decoded0 = predictor_update_filter(p, *decoded0, 0, YDELAYA, YDELAYB, YADAPTCOEFFSA, YADAPTCOEFFSB); + decoded0++; + *decoded1 = predictor_update_filter(p, *decoded1, 1, XDELAYA, XDELAYB, XADAPTCOEFFSA, XADAPTCOEFFSB); + decoded1++; /* Combined */ p->buf++; @@ -589,7 +590,7 @@ static void predictor_decode_mono(APEContext * ctx, int count) { APEPredictor *p = &ctx->predictor; int32_t *decoded0 = ctx->decoded0; - int32_t predictionA, currentA, A; + int32_t predictionA, currentA, A, sign; currentA = p->lastA[0]; @@ -609,17 +610,11 @@ static void predictor_decode_mono(APEContext * ctx, int count) p->buf[YADAPTCOEFFSA] = APESIGN(p->buf[YDELAYA ]); p->buf[YADAPTCOEFFSA - 1] = APESIGN(p->buf[YDELAYA - 1]); - if (A > 0) { - p->coeffsA[0][0] -= p->buf[YADAPTCOEFFSA ]; - p->coeffsA[0][1] -= p->buf[YADAPTCOEFFSA - 1]; - p->coeffsA[0][2] -= p->buf[YADAPTCOEFFSA - 2]; - p->coeffsA[0][3] -= p->buf[YADAPTCOEFFSA - 3]; - } else if (A < 0) { - p->coeffsA[0][0] += p->buf[YADAPTCOEFFSA ]; - p->coeffsA[0][1] += p->buf[YADAPTCOEFFSA - 1]; - p->coeffsA[0][2] += p->buf[YADAPTCOEFFSA - 2]; - p->coeffsA[0][3] += p->buf[YADAPTCOEFFSA - 3]; - } + sign = APESIGN(A); + p->coeffsA[0][0] += p->buf[YADAPTCOEFFSA ] * sign; + p->coeffsA[0][1] += p->buf[YADAPTCOEFFSA - 1] * sign; + p->coeffsA[0][2] += p->buf[YADAPTCOEFFSA - 2] * sign; + p->coeffsA[0][3] += p->buf[YADAPTCOEFFSA - 3] * sign; p->buf++; @@ -654,22 +649,16 @@ static void init_filter(APEContext * ctx, APEFilter *f, int16_t * buf, int order do_init_filter(&f[1], buf + order * 3 + HISTORY_SIZE, order); } -static inline void do_apply_filter(APEContext * ctx, int version, APEFilter *f, int32_t *data, int count, int order, int fracbits) +static void do_apply_filter(APEContext * ctx, int version, APEFilter *f, int32_t *data, int count, int order, int fracbits) { int res; int absres; while (count--) { /* round fixedpoint scalar product */ - res = (ctx->dsp.scalarproduct_int16(f->delay - order, f->coeffs, order, 0) + (1 << (fracbits - 1))) >> fracbits; - - if (*data < 0) - ctx->dsp.add_int16(f->coeffs, f->adaptcoeffs - order, order); - else if (*data > 0) - ctx->dsp.sub_int16(f->coeffs, f->adaptcoeffs - order, order); - + res = ctx->dsp.scalarproduct_and_madd_int16(f->coeffs, f->delay - order, f->adaptcoeffs - order, order, APESIGN(*data)); + res = (res + (1 << (fracbits - 1))) >> fracbits; res += *data; - *data++ = res; /* Update the output history */ @@ -684,14 +673,9 @@ static inline void do_apply_filter(APEContext * ctx, int version, APEFilter *f, /* Version 3.98 and later files */ /* Update the adaption coefficients */ - absres = (res < 0 ? -res : res); - - if (absres > (f->avg * 3)) - *f->adaptcoeffs = ((res >> 25) & 64) - 32; - else if (absres > (f->avg * 4) / 3) - *f->adaptcoeffs = ((res >> 26) & 32) - 16; - else if (absres > 0) - *f->adaptcoeffs = ((res >> 27) & 16) - 8; + absres = FFABS(res); + if (absres) + *f->adaptcoeffs = ((res & (1<<31)) - (1<<30)) >> (25 + (absres <= f->avg*3) + (absres <= f->avg*4/3)); else *f->adaptcoeffs = 0; @@ -871,6 +855,7 @@ static int ape_decode_frame(AVCodecContext * avctx, ape_unpack_mono(s, blockstodecode); else ape_unpack_stereo(s, blockstodecode); + emms_c(); if(s->error || s->ptr > s->data_end){ s->samples=0; @@ -894,12 +879,13 @@ static int ape_decode_frame(AVCodecContext * avctx, AVCodec ape_decoder = { "ape", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_APE, sizeof(APEContext), ape_decode_init, NULL, ape_decode_close, ape_decode_frame, + .capabilities = CODEC_CAP_SUBFRAMES, .long_name = NULL_IF_CONFIG_SMALL("Monkey's Audio"), }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/api-example.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/api-example.c index 763c228093..f34075e666 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/api-example.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/api-example.c @@ -19,7 +19,7 @@ */ /** - * @file libavcodec/apiexample.c + * @file * avcodec API use example. * * Note that this library only handles codecs (mpeg, mpeg4, etc...), @@ -35,10 +35,12 @@ #undef HAVE_AV_CONFIG_H #endif -#include "avcodec.h" +#include "libavcodec/avcodec.h" #include "libavutil/mathematics.h" #define INBUF_SIZE 4096 +#define AUDIO_INBUF_SIZE 20480 +#define AUDIO_REFILL_THRESH 4096 /* * Audio encoding example @@ -118,7 +120,7 @@ static void audio_decode_example(const char *outfilename, const char *filename) int out_size, len; FILE *f, *outfile; uint8_t *outbuf; - uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE]; + uint8_t inbuf[AUDIO_INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE]; AVPacket avpkt; av_init_packet(&avpkt); @@ -155,25 +157,32 @@ static void audio_decode_example(const char *outfilename, const char *filename) /* decode until eof */ avpkt.data = inbuf; - for(;;) { - avpkt.size = fread(inbuf, 1, INBUF_SIZE, f); - if (avpkt.size == 0) - break; + avpkt.size = fread(inbuf, 1, AUDIO_INBUF_SIZE, f); - avpkt.data = inbuf; - while (avpkt.size > 0) { - out_size = AVCODEC_MAX_AUDIO_FRAME_SIZE; - len = avcodec_decode_audio3(c, (short *)outbuf, &out_size, &avpkt); - if (len < 0) { - fprintf(stderr, "Error while decoding\n"); - exit(1); - } - if (out_size > 0) { - /* if a frame has been decoded, output it */ - fwrite(outbuf, 1, out_size, outfile); - } - avpkt.size -= len; - avpkt.data += len; + while (avpkt.size > 0) { + out_size = AVCODEC_MAX_AUDIO_FRAME_SIZE; + len = avcodec_decode_audio3(c, (short *)outbuf, &out_size, &avpkt); + if (len < 0) { + fprintf(stderr, "Error while decoding\n"); + exit(1); + } + if (out_size > 0) { + /* if a frame has been decoded, output it */ + fwrite(outbuf, 1, out_size, outfile); + } + avpkt.size -= len; + avpkt.data += len; + if (avpkt.size < AUDIO_REFILL_THRESH) { + /* Refill the input buffer, to avoid trying to decode + * incomplete frames. Instead of this, one could also use + * a parser, or use a proper container format through + * libavformat. */ + memmove(inbuf, avpkt.data, avpkt.size); + avpkt.data = inbuf; + len = fread(avpkt.data + avpkt.size, 1, + AUDIO_INBUF_SIZE - avpkt.size, f); + if (len > 0) + avpkt.size += len; } } diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/asv1.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/asv1.c index 10fbac24bc..211a13faf8 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/asv1.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/asv1.c @@ -20,12 +20,12 @@ */ /** - * @file libavcodec/asv1.c + * @file * ASUS V1/V2 codec. */ #include "avcodec.h" -#include "get_bits.h" +#include "libavutil/common.h" #include "put_bits.h" #include "dsputil.h" #include "mpeg12data.h" @@ -48,9 +48,9 @@ typedef struct ASV1Context{ int mb_height; int mb_width2; int mb_height2; - DECLARE_ALIGNED_16(DCTELEM, block[6][64]); - DECLARE_ALIGNED_8(uint16_t, intra_matrix[64]); - DECLARE_ALIGNED_8(int, q_intra_matrix[64]); + DECLARE_ALIGNED(16, DCTELEM, block)[6][64]; + uint16_t intra_matrix[64]; + int q_intra_matrix[64]; uint8_t *bitstream_buffer; unsigned int bitstream_buffer_size; } ASV1Context; @@ -140,11 +140,11 @@ static av_cold void init_vlcs(ASV1Context *a){ //FIXME write a reversed bitstream reader to avoid the double reverse static inline int asv2_get_bits(GetBitContext *gb, int n){ - return ff_reverse[ get_bits(gb, n) << (8-n) ]; + return av_reverse[ get_bits(gb, n) << (8-n) ]; } static inline void asv2_put_bits(PutBitContext *pb, int n, int v){ - put_bits(pb, n, ff_reverse[ v << (8-n) ]); + put_bits(pb, n, av_reverse[ v << (8-n) ]); } static inline int asv1_get_level(GetBitContext *gb){ @@ -394,7 +394,7 @@ static int decode_frame(AVCodecContext *avctx, int buf_size = avpkt->size; ASV1Context * const a = avctx->priv_data; AVFrame *picture = data; - AVFrame * const p= (AVFrame*)&a->picture; + AVFrame * const p= &a->picture; int mb_x, mb_y; if(p->data[0]) @@ -417,7 +417,7 @@ static int decode_frame(AVCodecContext *avctx, else{ int i; for(i=0; ibitstream_buffer[i]= ff_reverse[ buf[i] ]; + a->bitstream_buffer[i]= av_reverse[ buf[i] ]; } init_get_bits(&a->gb, a->bitstream_buffer, buf_size*8); @@ -474,7 +474,7 @@ for(i=0; iavctx->extradata_size; i++){ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ ASV1Context * const a = avctx->priv_data; AVFrame *pict = data; - AVFrame * const p= (AVFrame*)&a->picture; + AVFrame * const p= &a->picture; int size; int mb_x, mb_y; @@ -519,7 +519,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, else{ int i; for(i=0; i<4*size; i++) - buf[i]= ff_reverse[ buf[i] ]; + buf[i]= av_reverse[ buf[i] ]; } return size*4; @@ -536,13 +536,13 @@ static av_cold void common_init(AVCodecContext *avctx){ a->mb_width2 = (avctx->width + 0) / 16; a->mb_height2 = (avctx->height + 0) / 16; - avctx->coded_frame= (AVFrame*)&a->picture; + avctx->coded_frame= &a->picture; a->avctx= avctx; } static av_cold int decode_init(AVCodecContext *avctx){ ASV1Context * const a = avctx->priv_data; - AVFrame *p= (AVFrame*)&a->picture; + AVFrame *p= &a->picture; int i; const int scale= avctx->codec_id == CODEC_ID_ASV1 ? 1 : 2; @@ -551,7 +551,7 @@ static av_cold int decode_init(AVCodecContext *avctx){ ff_init_scantable(a->dsp.idct_permutation, &a->scantable, scantab); avctx->pix_fmt= PIX_FMT_YUV420P; - a->inv_qscale= ((uint8_t*)avctx->extradata)[0]; + a->inv_qscale= avctx->extradata[0]; if(a->inv_qscale == 0){ av_log(avctx, AV_LOG_ERROR, "illegal qscale 0\n"); if(avctx->codec_id == CODEC_ID_ASV1) @@ -607,12 +607,15 @@ static av_cold int decode_end(AVCodecContext *avctx){ av_freep(&a->picture.qscale_table); a->bitstream_buffer_size=0; + if(a->picture.data[0]) + avctx->release_buffer(avctx, &a->picture); + return 0; } AVCodec asv1_decoder = { "asv1", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_ASV1, sizeof(ASV1Context), decode_init, @@ -625,7 +628,7 @@ AVCodec asv1_decoder = { AVCodec asv2_decoder = { "asv2", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_ASV2, sizeof(ASV1Context), decode_init, @@ -639,13 +642,13 @@ AVCodec asv2_decoder = { #if CONFIG_ASV1_ENCODER AVCodec asv1_encoder = { "asv1", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_ASV1, sizeof(ASV1Context), encode_init, encode_frame, //encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, .long_name= NULL_IF_CONFIG_SMALL("ASUS V1"), }; #endif @@ -653,13 +656,13 @@ AVCodec asv1_encoder = { #if CONFIG_ASV2_ENCODER AVCodec asv2_encoder = { "asv2", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_ASV2, sizeof(ASV1Context), encode_init, encode_frame, //encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, .long_name= NULL_IF_CONFIG_SMALL("ASUS V2"), }; #endif diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/atrac.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/atrac.c new file mode 100644 index 0000000000..e398cee7b8 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/atrac.c @@ -0,0 +1,120 @@ +/* + * Atrac common functions + * Copyright (c) 2006-2008 Maxim Poliakovski + * Copyright (c) 2006-2008 Benjamin Larsson + * + * 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 + */ + +#include +#include +#include + +#include "avcodec.h" +#include "dsputil.h" +#include "atrac.h" + +float sf_table[64]; +float qmf_window[48]; + +static const float qmf_48tap_half[24] = { + -0.00001461907, -0.00009205479,-0.000056157569,0.00030117269, + 0.0002422519, -0.00085293897,-0.0005205574, 0.0020340169, + 0.00078333891, -0.0042153862, -0.00075614988, 0.0078402944, + -0.000061169922,-0.01344162, 0.0024626821, 0.021736089, + -0.007801671, -0.034090221, 0.01880949, 0.054326009, + -0.043596379, -0.099384367, 0.13207909, 0.46424159 +}; + +/** + * Generate common tables + */ + +void atrac_generate_tables(void) +{ + int i; + float s; + + /* Generate scale factors */ + if (!sf_table[63]) + for (i=0 ; i<64 ; i++) + sf_table[i] = pow(2.0, (i - 15) / 3.0); + + /* Generate the QMF window. */ + if (!qmf_window[47]) + for (i=0 ; i<24; i++) { + s = qmf_48tap_half[i] * 2.0; + qmf_window[i] = qmf_window[47 - i] = s; + } +} + + +/** + * Quadrature mirror synthesis filter. + * + * @param inlo lower part of spectrum + * @param inhi higher part of spectrum + * @param nIn size of spectrum buffer + * @param pOut out buffer + * @param delayBuf delayBuf buffer + * @param temp temp buffer + */ + + +void atrac_iqmf (float *inlo, float *inhi, unsigned int nIn, float *pOut, float *delayBuf, float *temp) +{ + int i, j; + float *p1, *p3; + + memcpy(temp, delayBuf, 46*sizeof(float)); + + p3 = temp + 46; + + /* loop1 */ + for(i=0; i +#include +#include + +#include "avcodec.h" +#include "get_bits.h" +#include "dsputil.h" +#include "fft.h" + +#include "atrac.h" +#include "atrac1data.h" + +#define AT1_MAX_BFU 52 ///< max number of block floating units in a sound unit +#define AT1_SU_SIZE 212 ///< number of bytes in a sound unit +#define AT1_SU_SAMPLES 512 ///< number of samples in a sound unit +#define AT1_FRAME_SIZE AT1_SU_SIZE * 2 +#define AT1_SU_MAX_BITS AT1_SU_SIZE * 8 +#define AT1_MAX_CHANNELS 2 + +#define AT1_QMF_BANDS 3 +#define IDX_LOW_BAND 0 +#define IDX_MID_BAND 1 +#define IDX_HIGH_BAND 2 + +/** + * Sound unit struct, one unit is used per channel + */ +typedef struct { + int log2_block_count[AT1_QMF_BANDS]; ///< log2 number of blocks in a band + int num_bfus; ///< number of Block Floating Units + float* spectrum[2]; + DECLARE_ALIGNED(16, float, spec1)[AT1_SU_SAMPLES]; ///< mdct buffer + DECLARE_ALIGNED(16, float, spec2)[AT1_SU_SAMPLES]; ///< mdct buffer + DECLARE_ALIGNED(16, float, fst_qmf_delay)[46]; ///< delay line for the 1st stacked QMF filter + DECLARE_ALIGNED(16, float, snd_qmf_delay)[46]; ///< delay line for the 2nd stacked QMF filter + DECLARE_ALIGNED(16, float, last_qmf_delay)[256+23]; ///< delay line for the last stacked QMF filter +} AT1SUCtx; + +/** + * The atrac1 context, holds all needed parameters for decoding + */ +typedef struct { + AT1SUCtx SUs[AT1_MAX_CHANNELS]; ///< channel sound unit + DECLARE_ALIGNED(16, float, spec)[AT1_SU_SAMPLES]; ///< the mdct spectrum buffer + + DECLARE_ALIGNED(16, float, low)[256]; + DECLARE_ALIGNED(16, float, mid)[256]; + DECLARE_ALIGNED(16, float, high)[512]; + float* bands[3]; + DECLARE_ALIGNED(16, float, out_samples)[AT1_MAX_CHANNELS][AT1_SU_SAMPLES]; + FFTContext mdct_ctx[3]; + int channels; + DSPContext dsp; +} AT1Ctx; + +/** size of the transform in samples in the long mode for each QMF band */ +static const uint16_t samples_per_band[3] = {128, 128, 256}; +static const uint8_t mdct_long_nbits[3] = {7, 7, 8}; + + +static void at1_imdct(AT1Ctx *q, float *spec, float *out, int nbits, + int rev_spec) +{ + FFTContext* mdct_context = &q->mdct_ctx[nbits - 5 - (nbits > 6)]; + int transf_size = 1 << nbits; + + if (rev_spec) { + int i; + for (i = 0; i < transf_size / 2; i++) + FFSWAP(float, spec[i], spec[transf_size - 1 - i]); + } + ff_imdct_half(mdct_context, out, spec); +} + + +static int at1_imdct_block(AT1SUCtx* su, AT1Ctx *q) +{ + int band_num, band_samples, log2_block_count, nbits, num_blocks, block_size; + unsigned int start_pos, ref_pos = 0, pos = 0; + + for (band_num = 0; band_num < AT1_QMF_BANDS; band_num++) { + float *prev_buf; + int j; + + band_samples = samples_per_band[band_num]; + log2_block_count = su->log2_block_count[band_num]; + + /* number of mdct blocks in the current QMF band: 1 - for long mode */ + /* 4 for short mode(low/middle bands) and 8 for short mode(high band)*/ + num_blocks = 1 << log2_block_count; + + if (num_blocks == 1) { + /* mdct block size in samples: 128 (long mode, low & mid bands), */ + /* 256 (long mode, high band) and 32 (short mode, all bands) */ + block_size = band_samples >> log2_block_count; + + /* calc transform size in bits according to the block_size_mode */ + nbits = mdct_long_nbits[band_num] - log2_block_count; + + if (nbits != 5 && nbits != 7 && nbits != 8) + return -1; + } else { + block_size = 32; + nbits = 5; + } + + start_pos = 0; + prev_buf = &su->spectrum[1][ref_pos + band_samples - 16]; + for (j=0; j < num_blocks; j++) { + at1_imdct(q, &q->spec[pos], &su->spectrum[0][ref_pos + start_pos], nbits, band_num); + + /* overlap and window */ + q->dsp.vector_fmul_window(&q->bands[band_num][start_pos], prev_buf, + &su->spectrum[0][ref_pos + start_pos], ff_sine_32, 0, 16); + + prev_buf = &su->spectrum[0][ref_pos+start_pos + 16]; + start_pos += block_size; + pos += block_size; + } + + if (num_blocks == 1) + memcpy(q->bands[band_num] + 32, &su->spectrum[0][ref_pos + 16], 240 * sizeof(float)); + + ref_pos += band_samples; + } + + /* Swap buffers so the mdct overlap works */ + FFSWAP(float*, su->spectrum[0], su->spectrum[1]); + + return 0; +} + +/** + * Parse the block size mode byte + */ + +static int at1_parse_bsm(GetBitContext* gb, int log2_block_cnt[AT1_QMF_BANDS]) +{ + int log2_block_count_tmp, i; + + for (i = 0; i < 2; i++) { + /* low and mid band */ + log2_block_count_tmp = get_bits(gb, 2); + if (log2_block_count_tmp & 1) + return -1; + log2_block_cnt[i] = 2 - log2_block_count_tmp; + } + + /* high band */ + log2_block_count_tmp = get_bits(gb, 2); + if (log2_block_count_tmp != 0 && log2_block_count_tmp != 3) + return -1; + log2_block_cnt[IDX_HIGH_BAND] = 3 - log2_block_count_tmp; + + skip_bits(gb, 2); + return 0; +} + + +static int at1_unpack_dequant(GetBitContext* gb, AT1SUCtx* su, + float spec[AT1_SU_SAMPLES]) +{ + int bits_used, band_num, bfu_num, i; + uint8_t idwls[AT1_MAX_BFU]; ///< the word length indexes for each BFU + uint8_t idsfs[AT1_MAX_BFU]; ///< the scalefactor indexes for each BFU + + /* parse the info byte (2nd byte) telling how much BFUs were coded */ + su->num_bfus = bfu_amount_tab1[get_bits(gb, 3)]; + + /* calc number of consumed bits: + num_BFUs * (idwl(4bits) + idsf(6bits)) + log2_block_count(8bits) + info_byte(8bits) + + info_byte_copy(8bits) + log2_block_count_copy(8bits) */ + bits_used = su->num_bfus * 10 + 32 + + bfu_amount_tab2[get_bits(gb, 2)] + + (bfu_amount_tab3[get_bits(gb, 3)] << 1); + + /* get word length index (idwl) for each BFU */ + for (i = 0; i < su->num_bfus; i++) + idwls[i] = get_bits(gb, 4); + + /* get scalefactor index (idsf) for each BFU */ + for (i = 0; i < su->num_bfus; i++) + idsfs[i] = get_bits(gb, 6); + + /* zero idwl/idsf for empty BFUs */ + for (i = su->num_bfus; i < AT1_MAX_BFU; i++) + idwls[i] = idsfs[i] = 0; + + /* read in the spectral data and reconstruct MDCT spectrum of this channel */ + for (band_num = 0; band_num < AT1_QMF_BANDS; band_num++) { + for (bfu_num = bfu_bands_t[band_num]; bfu_num < bfu_bands_t[band_num+1]; bfu_num++) { + int pos; + + int num_specs = specs_per_bfu[bfu_num]; + int word_len = !!idwls[bfu_num] + idwls[bfu_num]; + float scale_factor = sf_table[idsfs[bfu_num]]; + bits_used += word_len * num_specs; /* add number of bits consumed by current BFU */ + + /* check for bitstream overflow */ + if (bits_used > AT1_SU_MAX_BITS) + return -1; + + /* get the position of the 1st spec according to the block size mode */ + pos = su->log2_block_count[band_num] ? bfu_start_short[bfu_num] : bfu_start_long[bfu_num]; + + if (word_len) { + float max_quant = 1.0 / (float)((1 << (word_len - 1)) - 1); + + for (i = 0; i < num_specs; i++) { + /* read in a quantized spec and convert it to + * signed int and then inverse quantization + */ + spec[pos+i] = get_sbits(gb, word_len) * scale_factor * max_quant; + } + } else { /* word_len = 0 -> empty BFU, zero all specs in the emty BFU */ + memset(&spec[pos], 0, num_specs * sizeof(float)); + } + } + } + + return 0; +} + + +static void at1_subband_synthesis(AT1Ctx *q, AT1SUCtx* su, float *pOut) +{ + float temp[256]; + float iqmf_temp[512 + 46]; + + /* combine low and middle bands */ + atrac_iqmf(q->bands[0], q->bands[1], 128, temp, su->fst_qmf_delay, iqmf_temp); + + /* delay the signal of the high band by 23 samples */ + memcpy( su->last_qmf_delay, &su->last_qmf_delay[256], sizeof(float) * 23); + memcpy(&su->last_qmf_delay[23], q->bands[2], sizeof(float) * 256); + + /* combine (low + middle) and high bands */ + atrac_iqmf(temp, su->last_qmf_delay, 256, pOut, su->snd_qmf_delay, iqmf_temp); +} + + +static int atrac1_decode_frame(AVCodecContext *avctx, void *data, + int *data_size, AVPacket *avpkt) +{ + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + AT1Ctx *q = avctx->priv_data; + int ch, ret, i; + GetBitContext gb; + float* samples = data; + + + if (buf_size < 212 * q->channels) { + av_log(q,AV_LOG_ERROR,"Not enought data to decode!\n"); + return -1; + } + + for (ch = 0; ch < q->channels; ch++) { + AT1SUCtx* su = &q->SUs[ch]; + + init_get_bits(&gb, &buf[212 * ch], 212 * 8); + + /* parse block_size_mode, 1st byte */ + ret = at1_parse_bsm(&gb, su->log2_block_count); + if (ret < 0) + return ret; + + ret = at1_unpack_dequant(&gb, su, q->spec); + if (ret < 0) + return ret; + + ret = at1_imdct_block(su, q); + if (ret < 0) + return ret; + at1_subband_synthesis(q, su, q->out_samples[ch]); + } + + /* interleave; FIXME, should create/use a DSP function */ + if (q->channels == 1) { + /* mono */ + memcpy(samples, q->out_samples[0], AT1_SU_SAMPLES * 4); + } else { + /* stereo */ + for (i = 0; i < AT1_SU_SAMPLES; i++) { + samples[i * 2] = q->out_samples[0][i]; + samples[i * 2 + 1] = q->out_samples[1][i]; + } + } + + *data_size = q->channels * AT1_SU_SAMPLES * sizeof(*samples); + return avctx->block_align; +} + + +static av_cold int atrac1_decode_init(AVCodecContext *avctx) +{ + AT1Ctx *q = avctx->priv_data; + + avctx->sample_fmt = SAMPLE_FMT_FLT; + + q->channels = avctx->channels; + + /* Init the mdct transforms */ + ff_mdct_init(&q->mdct_ctx[0], 6, 1, -1.0/ (1 << 15)); + ff_mdct_init(&q->mdct_ctx[1], 8, 1, -1.0/ (1 << 15)); + ff_mdct_init(&q->mdct_ctx[2], 9, 1, -1.0/ (1 << 15)); + + ff_init_ff_sine_windows(5); + + atrac_generate_tables(); + + dsputil_init(&q->dsp, avctx); + + q->bands[0] = q->low; + q->bands[1] = q->mid; + q->bands[2] = q->high; + + /* Prepare the mdct overlap buffers */ + q->SUs[0].spectrum[0] = q->SUs[0].spec1; + q->SUs[0].spectrum[1] = q->SUs[0].spec2; + q->SUs[1].spectrum[0] = q->SUs[1].spec1; + q->SUs[1].spectrum[1] = q->SUs[1].spec2; + + return 0; +} + + +static av_cold int atrac1_decode_end(AVCodecContext * avctx) { + AT1Ctx *q = avctx->priv_data; + + ff_mdct_end(&q->mdct_ctx[0]); + ff_mdct_end(&q->mdct_ctx[1]); + ff_mdct_end(&q->mdct_ctx[2]); + return 0; +} + + +AVCodec atrac1_decoder = { + .name = "atrac1", + .type = AVMEDIA_TYPE_AUDIO, + .id = CODEC_ID_ATRAC1, + .priv_data_size = sizeof(AT1Ctx), + .init = atrac1_decode_init, + .close = atrac1_decode_end, + .decode = atrac1_decode_frame, + .long_name = NULL_IF_CONFIG_SMALL("Atrac 1 (Adaptive TRansform Acoustic Coding)"), +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/atrac1data.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/atrac1data.h new file mode 100644 index 0000000000..ebebe4b105 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/atrac1data.h @@ -0,0 +1,64 @@ +/* + * Atrac 1 compatible decoder data + * Copyright (c) 2009 Maxim Poliakovski + * Copyright (c) 2009 Benjamin Larsson + * + * 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 + * Atrac 1 compatible decoder data + */ + +#ifndef AVCODEC_ATRAC1DATA_H +#define AVCODEC_ATRAC1DATA_H + +#include + +static const uint8_t bfu_amount_tab1[8] = {20, 28, 32, 36, 40, 44, 48, 52}; +static const uint8_t bfu_amount_tab2[4] = { 0, 112, 176, 208}; +static const uint8_t bfu_amount_tab3[8] = { 0, 24, 36, 48, 72, 108, 132, 156}; + +/** number of BFUs in each QMF band */ +static const uint8_t bfu_bands_t[4] = {0, 20, 36, 52}; + +/** number of spectral lines in each BFU + * block floating unit = group of spectral frequencies having the + * same quantization parameters like word length and scale factor + */ +static const uint8_t specs_per_bfu[52] = { + 8, 8, 8, 8, 4, 4, 4, 4, 8, 8, 8, 8, 6, 6, 6, 6, 6, 6, 6, 6, // low band + 6, 6, 6, 6, 7, 7, 7, 7, 9, 9, 9, 9, 10, 10, 10, 10, // midle band + 12, 12, 12, 12, 12, 12, 12, 12, 20, 20, 20, 20, 20, 20, 20, 20 // high band +}; + +/** start position of each BFU in the MDCT spectrum for the long mode */ +static const uint16_t bfu_start_long[52] = { + 0, 8, 16, 24, 32, 36, 40, 44, 48, 56, 64, 72, 80, 86, 92, 98, 104, 110, 116, 122, + 128, 134, 140, 146, 152, 159, 166, 173, 180, 189, 198, 207, 216, 226, 236, 246, + 256, 268, 280, 292, 304, 316, 328, 340, 352, 372, 392, 412, 432, 452, 472, 492, +}; + +/** start position of each BFU in the MDCT spectrum for the short mode */ +static const uint16_t bfu_start_short[52] = { + 0, 32, 64, 96, 8, 40, 72, 104, 12, 44, 76, 108, 20, 52, 84, 116, 26, 58, 90, 122, + 128, 160, 192, 224, 134, 166, 198, 230, 141, 173, 205, 237, 150, 182, 214, 246, + 256, 288, 320, 352, 384, 416, 448, 480, 268, 300, 332, 364, 396, 428, 460, 492 +}; + +#endif /* AVCODEC_ATRAC1DATA_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/atrac3.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/atrac3.c index 9aa725b2a2..5179c345cf 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/atrac3.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/atrac3.c @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/atrac3.c + * @file * Atrac 3 compatible decoder. * This decoder handles Sony's ATRAC3 data. * @@ -40,7 +40,9 @@ #include "get_bits.h" #include "dsputil.h" #include "bytestream.h" +#include "fft.h" +#include "atrac.h" #include "atrac3data.h" #define JOINT_STEREO 0x12 @@ -72,8 +74,8 @@ typedef struct { int gcBlkSwitch; gain_block gainBlock[2]; - DECLARE_ALIGNED_16(float, spectrum[1024]); - DECLARE_ALIGNED_16(float, IMDCT_buf[1024]); + DECLARE_ALIGNED(16, float, spectrum)[1024]; + DECLARE_ALIGNED(16, float, IMDCT_buf)[1024]; float delayBuf1[46]; ///pUnits[i].delayBuf1, q->tempBuf); - iqmf (p4, p3, 256, p3, q->pUnits[i].delayBuf2, q->tempBuf); - iqmf (p1, p3, 512, p1, q->pUnits[i].delayBuf3, q->tempBuf); + atrac_iqmf (p1, p2, 256, p1, q->pUnits[i].delayBuf1, q->tempBuf); + atrac_iqmf (p4, p3, 256, p3, q->pUnits[i].delayBuf2, q->tempBuf); + atrac_iqmf (p1, p3, 512, p1, q->pUnits[i].delayBuf3, q->tempBuf); p1 +=1024; } @@ -1038,9 +977,7 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx) init_atrac3_transforms(q); - /* Generate the scale factors. */ - for (i=0 ; i<64 ; i++) - SFTable[i] = pow(2.0, (i - 15) / 3.0); + atrac_generate_tables(); /* Generate gain tables. */ for (i=0 ; i<16 ; i++) @@ -1079,7 +1016,7 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx) AVCodec atrac3_decoder = { .name = "atrac3", - .type = CODEC_TYPE_AUDIO, + .type = AVMEDIA_TYPE_AUDIO, .id = CODEC_ID_ATRAC3, .priv_data_size = sizeof(ATRAC3Context), .init = atrac3_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/atrac3data.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/atrac3data.h index e71dc35560..b5aa71f8ca 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/atrac3data.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/atrac3data.h @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/atrac3data.h + * @file * Atrac 3 AKA RealAudio 8 compatible decoder data */ @@ -127,17 +127,6 @@ static const uint16_t subbandTab[33] = { 256, 288, 320, 352, 384, 416, 448, 480, 512, 576, 640, 704, 768, 896, 1024 }; -/* transform data */ - -static const float qmf_48tap_half[24] = { - -0.00001461907, -0.00009205479, -0.000056157569, 0.00030117269, - 0.0002422519,-0.00085293897, -0.0005205574, 0.0020340169, - 0.00078333891, -0.0042153862, -0.00075614988, 0.0078402944, - -0.000061169922, -0.01344162, 0.0024626821, 0.021736089, - -0.007801671, -0.034090221, 0.01880949, 0.054326009, - -0.043596379, -0.099384367, 0.13207909, 0.46424159 -}; - /* joint stereo related tables */ static const float matrixCoeffs[8] = {0.0, 2.0, 2.0, 2.0, 0.0, 0.0, 1.0, 1.0}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/audioconvert.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/audioconvert.c index 91ea7abdc4..d022bc9ee3 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/audioconvert.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/audioconvert.c @@ -20,12 +20,13 @@ */ /** - * @file libavcodec/audioconvert.c + * @file * audio conversion * @author Michael Niedermayer */ #include "libavutil/avstring.h" +#include "libavutil/libm.h" #include "avcodec.h" #include "audioconvert.h" @@ -79,7 +80,7 @@ static const char* const channel_names[]={ [30] = "DR", }; -const char *get_channel_name(int channel_id) +static const char *get_channel_name(int channel_id) { if (channel_id<0 || channel_id>=FF_ARRAY_ELEMS(channel_names)) return NULL; @@ -209,7 +210,7 @@ if(ctx->fmt_pair == ofmt + SAMPLE_FMT_NB*ifmt){\ } //FIXME put things below under ifdefs so we do not waste space for cases no codec will need -//FIXME rounding and clipping ? +//FIXME rounding ? CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_U8 , *(const uint8_t*)pi) else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_U8 , (*(const uint8_t*)pi - 0x80)<<8) @@ -226,14 +227,14 @@ if(ctx->fmt_pair == ofmt + SAMPLE_FMT_NB*ifmt){\ else CONV(SAMPLE_FMT_S32, int32_t, SAMPLE_FMT_S32, *(const int32_t*)pi) else CONV(SAMPLE_FMT_FLT, float , SAMPLE_FMT_S32, *(const int32_t*)pi*(1.0 / (1<<31))) else CONV(SAMPLE_FMT_DBL, double , SAMPLE_FMT_S32, *(const int32_t*)pi*(1.0 / (1<<31))) - else CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_FLT, lrintf(*(const float*)pi * (1<<7)) + 0x80) - else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_FLT, lrintf(*(const float*)pi * (1<<15))) - else CONV(SAMPLE_FMT_S32, int32_t, SAMPLE_FMT_FLT, lrintf(*(const float*)pi * (1<<31))) + else CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_FLT, av_clip_uint8( lrintf(*(const float*)pi * (1<<7)) + 0x80)) + else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_FLT, av_clip_int16( lrintf(*(const float*)pi * (1<<15)))) + else CONV(SAMPLE_FMT_S32, int32_t, SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float*)pi * (1U<<31)))) else CONV(SAMPLE_FMT_FLT, float , SAMPLE_FMT_FLT, *(const float*)pi) else CONV(SAMPLE_FMT_DBL, double , SAMPLE_FMT_FLT, *(const float*)pi) - else CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_DBL, lrint(*(const double*)pi * (1<<7)) + 0x80) - else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_DBL, lrint(*(const double*)pi * (1<<15))) - else CONV(SAMPLE_FMT_S32, int32_t, SAMPLE_FMT_DBL, lrint(*(const double*)pi * (1<<31))) + else CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_DBL, av_clip_uint8( lrint(*(const double*)pi * (1<<7)) + 0x80)) + else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_DBL, av_clip_int16( lrint(*(const double*)pi * (1<<15)))) + else CONV(SAMPLE_FMT_S32, int32_t, SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double*)pi * (1U<<31)))) else CONV(SAMPLE_FMT_FLT, float , SAMPLE_FMT_DBL, *(const double*)pi) else CONV(SAMPLE_FMT_DBL, double , SAMPLE_FMT_DBL, *(const double*)pi) else return -1; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/audioconvert.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/audioconvert.h index 46ba3d3929..81b6cded39 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/audioconvert.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/audioconvert.h @@ -24,7 +24,7 @@ #define AVCODEC_AUDIOCONVERT_H /** - * @file libavcodec/audioconvert.h + * @file * Audio format conversion routines */ @@ -103,9 +103,9 @@ void av_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] out_stride distance between consecutive input samples (measured in bytes) + * @param[in] out_stride distance between consecutive output samples (measured in bytes) * @param[in] in array of input buffers for each channel - * @param[in] in_stride distance between consecutive output samples (measured in bytes) + * @param[in] in_stride distance between consecutive input samples (measured in bytes) * @param len length of audio frame size (measured in samples) */ int av_audio_convert(AVAudioConvert *ctx, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/aura.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/aura.c new file mode 100644 index 0000000000..8942cdd576 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/aura.c @@ -0,0 +1,138 @@ +/* + * Aura 2 decoder + * + * 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 + * Aura 2 decoder + */ + +#include "avcodec.h" + +typedef struct AuraDecodeContext { + AVCodecContext *avctx; + AVFrame frame; +} AuraDecodeContext; + +static av_cold int aura_decode_init(AVCodecContext *avctx) +{ + AuraDecodeContext *s = avctx->priv_data; + + s->avctx = avctx; + /* width needs to be divisible by 4 for this codec to work */ + if (avctx->width & 0x3) + return -1; + avctx->pix_fmt = PIX_FMT_YUV422P; + + return 0; +} + +static int aura_decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + AVPacket *pkt) +{ + AuraDecodeContext *s=avctx->priv_data; + + uint8_t *Y, *U, *V; + uint8_t val; + int x, y; + const uint8_t *buf = pkt->data; + + /* prediction error tables (make it clear that they are signed values) */ + const int8_t *delta_table = (const int8_t*)buf + 16; + + if (pkt->size != 48 + avctx->height * avctx->width) { + av_log(avctx, AV_LOG_ERROR, "got a buffer with %d bytes when %d were expected\n", + pkt->size, 48 + avctx->height * avctx->width); + return -1; + } + + /* pixel data starts 48 bytes in, after 3x16-byte tables */ + buf += 48; + + if(s->frame.data[0]) + avctx->release_buffer(avctx, &s->frame); + + s->frame.buffer_hints = FF_BUFFER_HINTS_VALID; + s->frame.reference = 0; + if(avctx->get_buffer(avctx, &s->frame) < 0) { + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } + + Y = s->frame.data[0]; + U = s->frame.data[1]; + V = s->frame.data[2]; + + /* iterate through each line in the height */ + for (y = 0; y < avctx->height; y++) { + /* reset predictors */ + val = *buf++; + U[0] = val & 0xF0; + Y[0] = val << 4; + val = *buf++; + V[0] = val & 0xF0; + Y[1] = Y[0] + delta_table[val & 0xF]; + Y += 2; U++; V++; + + /* iterate through the remaining pixel groups (4 pixels/group) */ + for (x = 1; x < (avctx->width >> 1); x++) { + val = *buf++; + U[0] = U[-1] + delta_table[val >> 4]; + Y[0] = Y[-1] + delta_table[val & 0xF]; + val = *buf++; + V[0] = V[-1] + delta_table[val >> 4]; + Y[1] = Y[ 0] + delta_table[val & 0xF]; + Y += 2; U++; V++; + } + Y += s->frame.linesize[0] - avctx->width; + U += s->frame.linesize[1] - (avctx->width >> 1); + V += s->frame.linesize[2] - (avctx->width >> 1); + } + + *data_size=sizeof(AVFrame); + *(AVFrame*)data= s->frame; + + return pkt->size; +} + +static av_cold int aura_decode_end(AVCodecContext *avctx) +{ + AuraDecodeContext *s = avctx->priv_data; + + if (s->frame.data[0]) + avctx->release_buffer(avctx, &s->frame); + + return 0; +} + +AVCodec 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, + .long_name = NULL_IF_CONFIG_SMALL("Auravision Aura 2"), +}; + diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/avcodec.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/avcodec.h index 8eb7c3c27c..974e87cc53 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/avcodec.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/avcodec.h @@ -22,7 +22,7 @@ #define AVCODEC_AVCODEC_H /** - * @file libavcodec/avcodec.h + * @file * external API header */ @@ -30,8 +30,8 @@ #include "libavutil/avutil.h" #define LIBAVCODEC_VERSION_MAJOR 52 -#define LIBAVCODEC_VERSION_MINOR 32 -#define LIBAVCODEC_VERSION_MICRO 0 +#define LIBAVCODEC_VERSION_MINOR 72 +#define LIBAVCODEC_VERSION_MICRO 2 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \ @@ -125,7 +125,9 @@ enum CodecID { CODEC_ID_QDRAW, CODEC_ID_VIXL, CODEC_ID_QPEG, +#if LIBAVCODEC_VERSION_MAJOR < 53 CODEC_ID_XVID, +#endif CODEC_ID_PNG, CODEC_ID_PPM, CODEC_ID_PBM, @@ -198,6 +200,17 @@ enum CodecID { CODEC_ID_V210, CODEC_ID_DPX, CODEC_ID_MAD, + CODEC_ID_FRWU, + CODEC_ID_FLASHSV2, + CODEC_ID_CDGRAPHICS, + CODEC_ID_R210, + CODEC_ID_ANM, + CODEC_ID_BINKVIDEO, + CODEC_ID_IFF_ILBM, + CODEC_ID_IFF_BYTERUN1, + CODEC_ID_KGV1, + CODEC_ID_YOP, + CODEC_ID_VP8, /* various PCM "codecs" */ CODEC_ID_PCM_S16LE= 0x10000, @@ -224,6 +237,7 @@ enum CodecID { CODEC_ID_PCM_F32LE, CODEC_ID_PCM_F64BE, CODEC_ID_PCM_F64LE, + CODEC_ID_PCM_BLURAY, /* various ADPCM codecs */ CODEC_ID_ADPCM_IMA_QT= 0x11000, @@ -319,6 +333,9 @@ enum CodecID { CODEC_ID_TWINVQ, CODEC_ID_TRUEHD, CODEC_ID_MP4ALS, + CODEC_ID_ATRAC1, + CODEC_ID_BINKAUDIO_RDFT, + CODEC_ID_BINKAUDIO_DCT, /* subtitle codecs */ CODEC_ID_DVD_SUBTITLE= 0x17000, @@ -327,6 +344,8 @@ enum CodecID { CODEC_ID_XSUB, CODEC_ID_SSA, CODEC_ID_MOV_TEXT, + CODEC_ID_HDMV_PGS_SUBTITLE, + CODEC_ID_DVB_TELETEXT, /* other specific kind of codecs (generally used for attachments) */ CODEC_ID_TTF= 0x18000, @@ -337,15 +356,17 @@ enum CodecID { * stream (only used by libavformat) */ }; -enum CodecType { - CODEC_TYPE_UNKNOWN = -1, - CODEC_TYPE_VIDEO, - CODEC_TYPE_AUDIO, - CODEC_TYPE_DATA, - CODEC_TYPE_SUBTITLE, - CODEC_TYPE_ATTACHMENT, - CODEC_TYPE_NB -}; +#if LIBAVCODEC_VERSION_MAJOR < 53 +#define CodecType AVMediaType + +#define CODEC_TYPE_UNKNOWN AVMEDIA_TYPE_UNKNOWN +#define CODEC_TYPE_VIDEO AVMEDIA_TYPE_VIDEO +#define CODEC_TYPE_AUDIO AVMEDIA_TYPE_AUDIO +#define CODEC_TYPE_DATA AVMEDIA_TYPE_DATA +#define CODEC_TYPE_SUBTITLE AVMEDIA_TYPE_SUBTITLE +#define CODEC_TYPE_ATTACHMENT AVMEDIA_TYPE_ATTACHMENT +#define CODEC_TYPE_NB AVMEDIA_TYPE_NB +#endif /** * all in native-endian format @@ -382,6 +403,11 @@ enum SampleFormat { #define CH_STEREO_LEFT 0x20000000 ///< Stereo downmix. #define CH_STEREO_RIGHT 0x40000000 ///< See CH_STEREO_LEFT. +/** Channel mask value used for AVCodecContext.request_channel_layout + to indicate that the user requests the channel order of the decoder output + to be the native codec channel order. */ +#define CH_LAYOUT_NATIVE 0x8000000000000000LL + /* Audio channel convenience macros */ #define CH_LAYOUT_MONO (CH_FRONT_CENTER) #define CH_LAYOUT_STEREO (CH_FRONT_LEFT|CH_FRONT_RIGHT) @@ -394,6 +420,7 @@ enum SampleFormat { #define CH_LAYOUT_5POINT1 (CH_LAYOUT_5POINT0|CH_LOW_FREQUENCY) #define CH_LAYOUT_5POINT0_BACK (CH_LAYOUT_SURROUND|CH_BACK_LEFT|CH_BACK_RIGHT) #define CH_LAYOUT_5POINT1_BACK (CH_LAYOUT_5POINT0_BACK|CH_LOW_FREQUENCY) +#define CH_LAYOUT_7POINT0 (CH_LAYOUT_5POINT0|CH_BACK_LEFT|CH_BACK_RIGHT) #define CH_LAYOUT_7POINT1 (CH_LAYOUT_5POINT1|CH_BACK_LEFT|CH_BACK_RIGHT) #define CH_LAYOUT_7POINT1_WIDE (CH_LAYOUT_5POINT1_BACK|\ CH_FRONT_LEFT_OF_CENTER|CH_FRONT_RIGHT_OF_CENTER) @@ -568,6 +595,9 @@ typedef struct RcOverride{ #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. /* Unsupported options : * Syntax Arithmetic coding (SAC) @@ -578,8 +608,9 @@ typedef struct RcOverride{ #define CODEC_CAP_DRAW_HORIZ_BAND 0x0001 ///< Decoder can use draw_horiz_band callback. /** - * Codec uses get_buffer() for allocating buffers. - * direct rendering method 1 + * Codec uses get_buffer() for allocating buffers and supports custom allocators. + * If not set, it might not use get_buffer() at all or use operations that + * assume the buffer was allocated by avcodec_default_get_buffer. */ #define CODEC_CAP_DR1 0x0002 /* If 'parse_only' field is true, then avcodec_parse_frame() can be used. */ @@ -601,6 +632,23 @@ typedef struct RcOverride{ * Codec can export data for HW decoding (VDPAU). */ #define CODEC_CAP_HWACCEL_VDPAU 0x0080 +/** + * Codec can output multiple frames per AVPacket + * Normally demuxers return one frame at a time, demuxers which do not do + * are connected to a parser to split what they return into proper frames. + * This flag is reserved to the very rare category of codecs which have a + * bitstream that cannot be split into frames without timeconsuming + * operations like full decoding. Demuxers carring such bitstreams thus + * may return multiple frames in a packet. This has many disadvantages like + * prohibiting stream copy in many cases thus it should only be considered + * as a last resort. + */ +#define CODEC_CAP_SUBFRAMES 0x0100 +/** + * Codec is experimental and is thus avoided in favor of non experimental + * encoders + */ +#define CODEC_CAP_EXPERIMENTAL 0x0200 //The following defines may change, don't expect compatibility if you use them. #define MB_TYPE_INTRA4x4 0x0001 @@ -860,7 +908,8 @@ typedef struct AVPanScan{ short *dct_coeff;\ \ /**\ - * motion referece frame index\ + * motion reference frame index\ + * the order in which these are stored can depend on the codec.\ * - encoding: Set by user.\ * - decoding: Set by libavcodec.\ */\ @@ -885,6 +934,7 @@ typedef struct AVPanScan{ #define FF_QSCALE_TYPE_MPEG1 0 #define FF_QSCALE_TYPE_MPEG2 1 #define FF_QSCALE_TYPE_H264 2 +#define FF_QSCALE_TYPE_VP56 3 #define FF_BUFFER_TYPE_INTERNAL 1 #define FF_BUFFER_TYPE_USER 2 ///< direct rendering buffers (image is (de)allocated by user) @@ -1235,7 +1285,7 @@ typedef struct AVCodecContext { void *opaque; char codec_name[32]; - enum CodecType codec_type; /* see CODEC_TYPE_xxx */ + enum AVMediaType codec_type; /* see AVMEDIA_TYPE_xxx */ enum CodecID codec_id; /* see CODEC_ID_xxx */ /** @@ -1274,6 +1324,7 @@ typedef struct AVCodecContext { #define FF_BUG_HPEL_CHROMA 2048 #define FF_BUG_DC_CLIP 4096 #define FF_BUG_MS 8192 ///< Work around various bugs in Microsoft's broken decoders. +#define FF_BUG_TRUNCATED 16384 //#define FF_BUG_FAKE_SCALABILITY 16 //Autodetection should work 100%. /** @@ -1331,7 +1382,7 @@ typedef struct AVCodecContext { /** * Called at the beginning of each frame to get a buffer for it. * If pic.reference is set then the frame will be read later by libavcodec. - * avcodec_align_dimensions() should be used to find the required width and + * avcodec_align_dimensions2() should be used to find the required width and * height, as they normally need to be rounded up to the next multiple of 16. * if CODEC_CAP_DR1 is not set then get_buffer() must call * avcodec_default_get_buffer() instead of providing buffers allocated by @@ -1540,6 +1591,7 @@ typedef struct AVCodecContext { #define FF_IDCT_EA 21 #define FF_IDCT_SIMPLENEON 22 #define FF_IDCT_SIMPLEALPHA 23 +#define FF_IDCT_BINK 24 /** * slice count @@ -2095,11 +2147,21 @@ typedef struct AVCodecContext { */ int profile; #define FF_PROFILE_UNKNOWN -99 + #define FF_PROFILE_AAC_MAIN 0 #define FF_PROFILE_AAC_LOW 1 #define FF_PROFILE_AAC_SSR 2 #define FF_PROFILE_AAC_LTP 3 +#define FF_PROFILE_H264_BASELINE 66 +#define FF_PROFILE_H264_MAIN 77 +#define FF_PROFILE_H264_EXTENDED 88 +#define FF_PROFILE_H264_HIGH 100 +#define FF_PROFILE_H264_HIGH_10 110 +#define FF_PROFILE_H264_HIGH_422 122 +#define FF_PROFILE_H264_HIGH_444 244 +#define FF_PROFILE_H264_CAVLC_444 44 + /** * level * - encoding: Set by user. @@ -2517,7 +2579,79 @@ typedef struct AVCodecContext { * - encoding: Set by user * - decoding: Set by libavcodec */ - enum AVChromaLocation chroma_sample_location; + enum AVChromaLocation chroma_sample_location; + + /** + * The codec may call this to execute several independent things. + * It will return only after finishing all tasks. + * The user may replace this with some multithreaded implementation, + * the default implementation will execute the parts serially. + * Also see avcodec_thread_init and e.g. the --enable-pthread configure option. + * @param c context passed also to func + * @param count the number of things to execute + * @param arg2 argument passed unchanged to func + * @param ret return values of executed functions, must have space for "count" values. May be NULL. + * @param func function that will be called count times, with jobnr from 0 to count-1. + * threadnr will be in the range 0 to c->thread_count-1 < MAX_THREADS and so that no + * two instances of func executing at the same time will have the same threadnr. + * @return always 0 currently, but code should handle a future improvement where when any call to func + * returns < 0 no further calls to func may be done and < 0 is returned. + * - encoding: Set by libavcodec, user can override. + * - decoding: Set by libavcodec, user can override. + */ + int (*execute2)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count); + + /** + * explicit P-frame weighted prediction analysis method + * 0: off + * 1: fast blind weighting (one reference duplicate with -1 offset) + * 2: smart weighting (full fade detection analysis) + * - encoding: Set by user. + * - decoding: unused + */ + int weighted_p_pred; + + /** + * AQ mode + * 0: Disabled + * 1: Variance AQ (complexity mask) + * 2: Auto-variance AQ (experimental) + * - encoding: Set by user + * - decoding: unused + */ + int aq_mode; + + /** + * AQ strength + * Reduces blocking and blurring in flat and textured areas. + * - encoding: Set by user + * - decoding: unused + */ + float aq_strength; + + /** + * PSY RD + * Strength of psychovisual optimization + * - encoding: Set by user + * - decoding: unused + */ + float psy_rd; + + /** + * PSY trellis + * Strength of psychovisual optimization + * - encoding: Set by user + * - decoding: unused + */ + float psy_trellis; + + /** + * RC lookahead + * Number of frames for frametype and ratecontrol lookahead + * - encoding: Set by user + * - decoding: unused + */ + int rc_lookahead; } AVCodecContext; /** @@ -2531,7 +2665,7 @@ typedef struct AVCodec { * This is the primary way to find a codec from the user perspective. */ const char *name; - enum CodecType type; + enum AVMediaType type; enum CodecID id; int priv_data_size; int (*init)(AVCodecContext *); @@ -2575,9 +2709,9 @@ typedef struct AVHWAccel { /** * Type of codec implemented by the hardware accelerator. * - * See CODEC_TYPE_xxx + * See AVMEDIA_TYPE_xxx */ - enum CodecType type; + enum AVMediaType type; /** * Codec implemented by the hardware accelerator. @@ -2923,6 +3057,7 @@ void avcodec_get_chroma_sub_sample(enum PixelFormat pix_fmt, int *h_shift, int * const char *avcodec_get_pix_fmt_name(enum PixelFormat pix_fmt); void avcodec_set_dimensions(AVCodecContext *s, int width, int height); +#if LIBAVCODEC_VERSION_MAJOR < 53 /** * Returns the pixel format corresponding to the name name. * @@ -2933,9 +3068,18 @@ void avcodec_set_dimensions(AVCodecContext *s, int width, int height); * then for "gray16le". * * Finally if no pixel format has been found, returns PIX_FMT_NONE. + * + * @deprecated Deprecated in favor of av_get_pix_fmt(). */ -enum PixelFormat avcodec_get_pix_fmt(const char* name); -unsigned int avcodec_pix_fmt_to_codec_tag(enum PixelFormat p); +attribute_deprecated enum PixelFormat avcodec_get_pix_fmt(const char* name); +#endif + +/** + * Returns a value representing the fourCC code associated to the + * pixel format pix_fmt, or 0 if no associated fourCC code can be + * found. + */ +unsigned int avcodec_pix_fmt_to_codec_tag(enum PixelFormat pix_fmt); #define FF_LOSS_RESOLUTION 0x0001 /**< loss due to resolution change */ #define FF_LOSS_DEPTH 0x0002 /**< loss due to color depth change */ @@ -3031,6 +3175,16 @@ AVCodec *av_codec_next(AVCodec *c); */ unsigned avcodec_version(void); +/** + * Returns the libavcodec build-time configuration. + */ +const char *avcodec_configuration(void); + +/** + * Returns the libavcodec license. + */ +const char *avcodec_license(void); + /** * Initializes libavcodec. * @@ -3095,7 +3249,7 @@ 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! */ -void avcodec_get_context_defaults2(AVCodecContext *s, enum CodecType); +void avcodec_get_context_defaults2(AVCodecContext *s, enum AVMediaType); /** * Allocates an AVCodecContext and sets its fields to default values. The @@ -3108,7 +3262,20 @@ 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! */ -AVCodecContext *avcodec_alloc_context2(enum CodecType); +AVCodecContext *avcodec_alloc_context2(enum AVMediaType); + +/** + * Copy the settings of the source AVCodecContext into the destination + * AVCodecContext. The resulting destination codec context will be + * unopened, i.e. you are required to call avcodec_open() before you + * 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 + * @param src source codec context + * @return AVERROR() on error (e.g. memory allocation error), 0 on success + */ +int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src); /** * Sets the fields of the given AVFrame to default values. @@ -3129,7 +3296,36 @@ AVFrame *avcodec_alloc_frame(void); int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic); void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic); int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic); + +/** + * Returns the amount of padding in pixels which the get_buffer callback must + * provide around the edge of the image for codecs which do not have the + * CODEC_FLAG_EMU_EDGE flag. + * + * @return Required padding in pixels. + */ +unsigned avcodec_get_edge_width(void); +/** + * Modifies width and height values so that they will result in a memory + * buffer that is acceptable for the codec if you do not use any horizontal + * padding. + * + * May only be used if a codec with CODEC_CAP_DR1 has been opened. + * If CODEC_FLAG_EMU_EDGE is not set, the dimensions must have been increased + * according to avcodec_get_edge_width() before. + */ void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height); +/** + * Modifies width and height values so that they will result in a memory + * buffer that is acceptable for the codec if you also ensure that all + * line sizes are a multiple of the respective linesize_align[i]. + * + * May only be used if a codec with CODEC_CAP_DR1 has been opened. + * If CODEC_FLAG_EMU_EDGE is not set, the dimensions must have been increased + * according to avcodec_get_edge_width() before. + */ +void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height, + int linesize_align[4]); /** * Checks if the given dimension of a picture is valid, meaning that all @@ -3144,8 +3340,8 @@ enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum int avcodec_thread_init(AVCodecContext *s, int thread_count); void avcodec_thread_free(AVCodecContext *s); -int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size); int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size); +int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int, int),void *arg, int *ret, int count); //FIXME func typedef /** @@ -3199,9 +3395,11 @@ attribute_deprecated int avcodec_decode_audio2(AVCodecContext *avctx, int16_t *s /** * Decodes the audio frame of size avpkt->size from avpkt->data into samples. * Some decoders may support multiple frames in a single AVPacket, such - * decoders would then just decode the first frame. + * decoders would then just decode the first frame. In this case, + * avcodec_decode_audio3 has to be called again with an AVPacket that contains + * the remaining data in order to decode the second frame etc. * If no frame - * could be decompressed, frame_size_ptr is zero. Otherwise, it is the + * could be outputted, frame_size_ptr is zero. Otherwise, it is the * decompressed frame size in bytes. * * @warning You must set frame_size_ptr to the allocated size of the @@ -3231,7 +3429,7 @@ attribute_deprecated int avcodec_decode_audio2(AVCodecContext *avctx, int16_t *s * data and size, some decoders might in addition need other fields. * All decoders are designed to use the least fields possible though. * @return On error a negative value is returned, otherwise the number of bytes - * used or zero if no frame could be decompressed. + * used or zero if no frame data was decompressed (used) from the input AVPacket. */ int avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples, int *frame_size_ptr, @@ -3276,14 +3474,16 @@ attribute_deprecated int avcodec_decode_video(AVCodecContext *avctx, AVFrame *pi * 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 - * feeded with avpkt->data=NULL, avpkt->size=0 at the end to return the remaining frames. + * 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. + * Use avcodec_alloc_frame to get an AVFrame, the codec will + * allocate memory for the actual bitmap. * @param[in] avpkt The input AVpacket containing the input buffer. * You can create such packet with av_init_packet() and by then setting * data and size, some decoders might in addition need other fields like - * flags&PKT_FLAG_KEY. All decoders are designed to use the least + * flags&AV_PKT_FLAG_KEY. All decoders are designed to use the least * fields possible. * @param[in,out] got_picture_ptr Zero if no frame could be decompressed, otherwise, it is nonzero. * @return On error a negative value is returned, otherwise the number of bytes @@ -3670,6 +3870,13 @@ int av_picture_crop(AVPicture *dst, const AVPicture *src, int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width, enum PixelFormat pix_fmt, int padtop, int padbottom, int padleft, int padright, int *color); +/** + * Encodes extradata length to a buffer. Used by xiph codecs. + * + * @param s buffer to write to; must be at least (v/255+1) bytes long + * @param v size of extradata in bytes + * @return number of bytes written to the buffer. + */ unsigned int av_xiphlacing(unsigned char *s, unsigned int v); /** @@ -3696,26 +3903,6 @@ int av_parse_video_frame_size(int *width_ptr, int *height_ptr, const char *str); */ int av_parse_video_frame_rate(AVRational *frame_rate, const char *str); -/* error handling */ -#if EINVAL > 0 -#define AVERROR(e) (-(e)) /**< Returns a negative error code from a POSIX error code, to return from library functions. */ -#define AVUNERROR(e) (-(e)) /**< Returns a POSIX error code from a library function error return value. */ -#else -/* Some platforms have E* and errno already negated. */ -#define AVERROR(e) (e) -#define AVUNERROR(e) (e) -#endif -#define AVERROR_UNKNOWN AVERROR(EINVAL) /**< unknown error */ -#define AVERROR_IO AVERROR(EIO) /**< I/O error */ -#define AVERROR_NUMEXPECTED AVERROR(EDOM) /**< Number syntax expected in filename. */ -#define AVERROR_INVALIDDATA AVERROR(EINVAL) /**< invalid data found */ -#define AVERROR_NOMEM AVERROR(ENOMEM) /**< not enough memory */ -#define AVERROR_NOFMT AVERROR(EILSEQ) /**< unknown format */ -#define AVERROR_NOTSUPP AVERROR(ENOSYS) /**< Operation not supported. */ -#define AVERROR_NOENT AVERROR(ENOENT) /**< No such file or directory. */ -#define AVERROR_EOF AVERROR(EPIPE) /**< End of file. */ -#define AVERROR_PATCHWELCOME -MKTAG('P','A','W','E') /**< Not yet implemented in FFmpeg. Patches welcome. */ - /** * Logs a generic warning message about a missing feature. This function is * intended to be used internally by FFmpeg (libavcodec, libavformat, etc.) diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/avfft.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/avfft.c new file mode 100644 index 0000000000..25fc4e0955 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/avfft.c @@ -0,0 +1,142 @@ +/* + * 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/mem.h" +#include "avfft.h" +#include "fft.h" + +/* FFT */ + +FFTContext *av_fft_init(int nbits, int inverse) +{ + FFTContext *s = av_malloc(sizeof(*s)); + + if (s) + ff_fft_init(s, nbits, inverse); + + return s; +} + +void av_fft_permute(FFTContext *s, FFTComplex *z) +{ + s->fft_permute(s, z); +} + +void av_fft_calc(FFTContext *s, FFTComplex *z) +{ + s->fft_calc(s, z); +} + +void av_fft_end(FFTContext *s) +{ + if (s) { + ff_fft_end(s); + av_free(s); + } +} + +#if CONFIG_MDCT + +FFTContext *av_mdct_init(int nbits, int inverse, double scale) +{ + FFTContext *s = av_malloc(sizeof(*s)); + + if (s) + ff_mdct_init(s, nbits, inverse, scale); + + return s; +} + +void av_imdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input) +{ + s->imdct_calc(s, output, input); +} + +void av_imdct_half(FFTContext *s, FFTSample *output, const FFTSample *input) +{ + s->imdct_half(s, output, input); +} + +void av_mdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input) +{ + s->mdct_calc(s, output, input); +} + +void av_mdct_end(FFTContext *s) +{ + if (s) { + ff_mdct_end(s); + av_free(s); + } +} + +#endif /* CONFIG_MDCT */ + +#if CONFIG_RDFT + +RDFTContext *av_rdft_init(int nbits, enum RDFTransformType trans) +{ + RDFTContext *s = av_malloc(sizeof(*s)); + + if (s) + ff_rdft_init(s, nbits, trans); + + return s; +} + +void av_rdft_calc(RDFTContext *s, FFTSample *data) +{ + ff_rdft_calc(s, data); +} + +void av_rdft_end(RDFTContext *s) +{ + if (s) { + ff_rdft_end(s); + av_free(s); + } +} + +#endif /* CONFIG_RDFT */ + +#if CONFIG_DCT + +DCTContext *av_dct_init(int nbits, enum DCTTransformType inverse) +{ + DCTContext *s = av_malloc(sizeof(*s)); + + if (s) + ff_dct_init(s, nbits, inverse); + + return s; +} + +void av_dct_calc(DCTContext *s, FFTSample *data) +{ + ff_dct_calc(s, data); +} + +void av_dct_end(DCTContext *s) +{ + if (s) { + ff_dct_end(s); + av_free(s); + } +} + +#endif /* CONFIG_DCT */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/avfft.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/avfft.h new file mode 100644 index 0000000000..623f0a33b5 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/avfft.h @@ -0,0 +1,99 @@ +/* + * 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_AVFFT_H +#define AVCODEC_AVFFT_H + +typedef float FFTSample; + +typedef struct FFTComplex { + FFTSample re, im; +} FFTComplex; + +typedef struct FFTContext FFTContext; + +/** + * Set up a complex FFT. + * @param nbits log2 of the length of the input array + * @param inverse if 0 perform the forward transform, if 1 perform the inverse + */ +FFTContext *av_fft_init(int nbits, int inverse); + +/** + * Do the permutation needed BEFORE calling ff_fft_calc(). + */ +void av_fft_permute(FFTContext *s, FFTComplex *z); + +/** + * Do a complex FFT with the parameters defined in av_fft_init(). The + * input data must be permuted before. No 1.0/sqrt(n) normalization is done. + */ +void av_fft_calc(FFTContext *s, FFTComplex *z); + +void av_fft_end(FFTContext *s); + +FFTContext *av_mdct_init(int nbits, int inverse, double scale); +void av_imdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input); +void av_imdct_half(FFTContext *s, FFTSample *output, const FFTSample *input); +void av_mdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input); +void av_mdct_end(FFTContext *s); + +/* Real Discrete Fourier Transform */ + +enum RDFTransformType { + DFT_R2C, + IDFT_C2R, + IDFT_R2C, + DFT_C2R, +}; + +typedef struct RDFTContext RDFTContext; + +/** + * Set up a real FFT. + * @param nbits log2 of the length of the input array + * @param trans the type of transform + */ +RDFTContext *av_rdft_init(int nbits, enum RDFTransformType trans); +void av_rdft_calc(RDFTContext *s, FFTSample *data); +void av_rdft_end(RDFTContext *s); + +/* Discrete Cosine Transform */ + +typedef struct DCTContext DCTContext; + +enum DCTTransformType { + DCT_II = 0, + DCT_III, + DCT_I, + DST_I, +}; + +/** + * Sets up DCT. + * @param nbits size of the input array: + * (1 << nbits) for DCT-II, DCT-III and DST-I + * (1 << nbits) + 1 for DCT-I + * + * @note the first element of the input of DST-I is ignored + */ +DCTContext *av_dct_init(int nbits, enum DCTTransformType type); +void av_dct_calc(DCTContext *s, FFTSample *data); +void av_dct_end (DCTContext *s); + +#endif /* AVCODEC_AVFFT_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/avpacket.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/avpacket.c index 5bea639d66..c51260face 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/avpacket.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/avpacket.c @@ -47,18 +47,20 @@ void av_init_packet(AVPacket *pkt) int av_new_packet(AVPacket *pkt, int size) { - uint8_t *data; - if((unsigned)size > (unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE) - return AVERROR(ENOMEM); - data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); - if (!data) - return AVERROR(ENOMEM); - memset(data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE); + uint8_t *data= NULL; + if((unsigned)size < (unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE) + data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); + if (data){ + memset(data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE); + }else + size=0; av_init_packet(pkt); pkt->data = data; pkt->size = size; pkt->destruct = av_destruct_packet; + if(!data) + return AVERROR(ENOMEM); return 0; } diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/avs.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/avs.c index a53a068c15..f65a25a8e3 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/avs.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/avs.c @@ -152,7 +152,7 @@ static av_cold int avs_decode_init(AVCodecContext * avctx) AVCodec avs_decoder = { "avs", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_AVS, sizeof(AvsContext), avs_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/beosthread.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/beosthread.c index e2fd97777d..44fe492c4b 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/beosthread.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/beosthread.c @@ -92,7 +92,7 @@ void avcodec_thread_free(AVCodecContext *s){ av_freep(&s->thread_opaque); } -int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size){ +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; @@ -123,6 +123,9 @@ int avcodec_thread_init(AVCodecContext *s, int thread_count){ s->thread_count= thread_count; + if (thread_count <= 1) + return 0; + assert(!s->thread_opaque); c= av_mallocz(sizeof(ThreadContext)*thread_count); s->thread_opaque= c; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/bethsoftvideo.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/bethsoftvideo.c index 6b4a5acabd..0ba39e63a5 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/bethsoftvideo.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/bethsoftvideo.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/bethsoftvideo.c + * @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 @@ -132,7 +132,7 @@ static av_cold int bethsoftvid_decode_end(AVCodecContext *avctx) AVCodec bethsoftvid_decoder = { .name = "bethsoftvid", - .type = CODEC_TYPE_VIDEO, + .type = AVMEDIA_TYPE_VIDEO, .id = CODEC_ID_BETHSOFTVID, .priv_data_size = sizeof(BethsoftvidContext), .init = bethsoftvid_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/bfi.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/bfi.c index 31b914927e..91c8f6d24d 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/bfi.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/bfi.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/bfi.c + * @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 @@ -173,7 +173,7 @@ static av_cold int bfi_decode_close(AVCodecContext * avctx) AVCodec bfi_decoder = { .name = "bfi", - .type = CODEC_TYPE_VIDEO, + .type = AVMEDIA_TYPE_VIDEO, .id = CODEC_ID_BFI, .priv_data_size = sizeof(BFIContext), .init = bfi_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/bgmc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/bgmc.c new file mode 100644 index 0000000000..86b807bc2f --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/bgmc.c @@ -0,0 +1,567 @@ +/* + * Block Gilbert-Moore decoder + * Copyright (c) 2010 Thilo Borgmann + * + * 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 + * Block Gilbert-Moore decoder as used by MPEG-4 ALS + * @author Thilo Borgmann + */ + + +#include "bgmc.h" + + +#define FREQ_BITS 14 // bits used by frequency counters +#define VALUE_BITS 18 // bits used to represent the values +#define TOP_VALUE ((1 << VALUE_BITS) - 1) // maximum value +#define FIRST_QTR (TOP_VALUE / 4 + 1) // first quarter of values maximum value +#define HALF (2 * FIRST_QTR) // first half of values maximum value +#define THIRD_QTR (3 * FIRST_QTR) // third quarter of values maximum value + +#define LUT_BITS (FREQ_BITS - 8) // number of bits used to index lookup tables +#define LUT_SIZE (1 << LUT_BITS) // size of the lookup tables +#define LUT_BUFF 4 // number of buffered lookup tables + + +/** Cumulative frequency tables for block Gilbert-Moore coding. + */ +static const uint16_t cf_tables_1[3][129] = { + { + 16384, 16066, 15748, 15431, 15114, 14799, 14485, 14173, 13861, 13552, + 13243, 12939, 12635, 12336, 12038, 11745, 11452, 11161, 10870, 10586, + 10303, 10027, 9751, 9483, 9215, 8953, 8692, 8440, 8189, 7946, + 7704, 7472, 7240, 7008, 6776, 6554, 6333, 6122, 5912, 5711, + 5512, 5320, 5128, 4947, 4766, 4595, 4425, 4264, 4104, 3946, + 3788, 3640, 3493, 3355, 3218, 3090, 2963, 2842, 2721, 2609, + 2498, 2395, 2292, 2196, 2100, 2004, 1908, 1820, 1732, 1651, + 1570, 1497, 1424, 1355, 1287, 1223, 1161, 1100, 1044, 988, + 938, 888, 839, 790, 746, 702, 662, 623, 588, 553, + 520, 488, 459, 431, 405, 380, 357, 334, 311, 288, + 268, 248, 230, 213, 197, 182, 168, 154, 142, 130, + 119, 108, 99, 90, 81, 72, 64, 56, 49, 42, + 36, 30, 25, 20, 15, 11, 7, 3, 0 + }, + { + 16384, 16080, 15776, 15473, 15170, 14868, 14567, 14268, 13970, 13674, + 13378, 13086, 12794, 12505, 12218, 11936, 11654, 11373, 11092, 10818, + 10544, 10276, 10008, 9749, 9490, 9236, 8982, 8737, 8492, 8256, + 8020, 7792, 7564, 7336, 7108, 6888, 6669, 6459, 6249, 6050, + 5852, 5660, 5468, 5286, 5104, 4931, 4760, 4598, 4436, 4275, + 4115, 3965, 3816, 3674, 3534, 3403, 3272, 3147, 3023, 2907, + 2792, 2684, 2577, 2476, 2375, 2274, 2173, 2079, 1986, 1897, + 1810, 1724, 1645, 1567, 1493, 1419, 1351, 1284, 1222, 1161, + 1105, 1050, 995, 941, 891, 842, 797, 753, 713, 673, + 636, 599, 566, 533, 503, 473, 446, 419, 392, 365, + 340, 316, 294, 272, 253, 234, 216, 199, 184, 169, + 155, 142, 130, 118, 106, 95, 85, 75, 66, 57, + 49, 41, 34, 27, 21, 15, 10, 5, 0 + }, + { + 16384, 16092, 15801, 15510, 15219, 14930, 14641, 14355, 14069, 13785, + 13501, 13219, 12938, 12661, 12384, 12112, 11841, 11571, 11301, 11037, + 10773, 10514, 10256, 10005, 9754, 9508, 9263, 9025, 8787, 8557, + 8327, 8103, 7879, 7655, 7431, 7215, 7000, 6792, 6585, 6387, + 6190, 5998, 5807, 5625, 5445, 5272, 5100, 4937, 4774, 4613, + 4452, 4301, 4150, 4007, 3865, 3731, 3597, 3469, 3341, 3218, + 3099, 2981, 2869, 2758, 2652, 2546, 2440, 2334, 2234, 2134, + 2041, 1949, 1864, 1779, 1699, 1620, 1547, 1474, 1407, 1340, + 1278, 1217, 1157, 1097, 1043, 989, 940, 891, 846, 801, + 759, 718, 680, 643, 609, 575, 543, 511, 479, 447, + 418, 389, 363, 337, 314, 291, 270, 249, 230, 212, + 195, 179, 164, 149, 135, 121, 108, 96, 85, 74, + 64, 54, 45, 36, 28, 20, 13, 6, 0 + } +}; + + +static const uint16_t cf_tables_2[8][193] = { + { + 16384, 16104, 15825, 15546, 15268, 14991, 14714, 14439, 14164, 13891, + 13620, 13350, 13081, 12815, 12549, 12287, 12025, 11765, 11505, 11250, + 10996, 10746, 10497, 10254, 10011, 9772, 9534, 9303, 9072, 8848, + 8624, 8406, 8188, 7970, 7752, 7539, 7327, 7123, 6919, 6724, + 6529, 6339, 6150, 5970, 5790, 5618, 5446, 5282, 5119, 4957, + 4795, 4642, 4490, 4345, 4201, 4065, 3929, 3798, 3669, 3547, + 3425, 3310, 3196, 3086, 2976, 2866, 2756, 2650, 2545, 2447, + 2350, 2260, 2170, 2085, 2000, 1921, 1843, 1770, 1698, 1632, + 1566, 1501, 1436, 1376, 1316, 1261, 1207, 1157, 1108, 1061, + 1015, 973, 931, 893, 855, 819, 783, 747, 711, 677, + 644, 614, 584, 557, 530, 505, 480, 458, 436, 416, + 396, 378, 360, 343, 326, 310, 295, 281, 267, 255, + 243, 232, 221, 211, 201, 192, 183, 174, 166, 158, + 150, 142, 134, 126, 119, 112, 106, 100, 95, 90, + 85, 80, 76, 72, 69, 66, 63, 60, 57, 54, + 51, 48, 46, 44, 42, 40, 38, 36, 34, 33, + 32, 31, 30, 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 + }, + { + 16384, 16116, 15849, 15582, 15316, 15050, 14785, 14521, 14257, 13995, + 13734, 13476, 13218, 12963, 12708, 12457, 12206, 11956, 11706, 11460, + 11215, 10975, 10735, 10500, 10265, 10034, 9803, 9579, 9355, 9136, + 8917, 8703, 8489, 8275, 8061, 7853, 7645, 7444, 7244, 7051, + 6858, 6671, 6484, 6305, 6127, 5956, 5785, 5622, 5459, 5298, + 5137, 4983, 4830, 4684, 4539, 4401, 4263, 4131, 3999, 3874, + 3750, 3632, 3515, 3401, 3287, 3173, 3059, 2949, 2840, 2737, + 2635, 2539, 2444, 2354, 2264, 2181, 2098, 2020, 1943, 1872, + 1801, 1731, 1661, 1596, 1532, 1472, 1412, 1357, 1303, 1251, + 1200, 1153, 1106, 1063, 1020, 979, 938, 897, 856, 818, + 780, 746, 712, 681, 650, 621, 592, 566, 540, 517, + 494, 473, 452, 431, 410, 391, 373, 356, 340, 325, + 310, 296, 282, 270, 258, 247, 236, 225, 214, 203, + 192, 182, 172, 162, 153, 144, 136, 128, 121, 114, + 108, 102, 97, 92, 87, 82, 77, 73, 69, 65, + 62, 59, 56, 53, 50, 47, 45, 43, 41, 39, + 37, 35, 33, 31, 29, 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 + }, + { + 16384, 16128, 15872, 15617, 15362, 15107, 14853, 14600, 14347, 14096, + 13846, 13597, 13350, 13105, 12860, 12618, 12376, 12135, 11894, 11657, + 11421, 11189, 10957, 10730, 10503, 10279, 10056, 9838, 9620, 9407, + 9195, 8987, 8779, 8571, 8363, 8159, 7955, 7758, 7561, 7371, + 7182, 6997, 6812, 6635, 6459, 6289, 6120, 5957, 5795, 5634, + 5473, 5319, 5165, 5018, 4871, 4732, 4593, 4458, 4324, 4197, + 4071, 3951, 3831, 3714, 3597, 3480, 3363, 3250, 3138, 3032, + 2927, 2828, 2729, 2635, 2541, 2453, 2366, 2284, 2202, 2126, + 2050, 1975, 1900, 1830, 1761, 1697, 1633, 1574, 1515, 1459, + 1403, 1351, 1300, 1252, 1205, 1160, 1115, 1070, 1025, 982, + 939, 899, 860, 824, 789, 756, 723, 693, 663, 636, + 609, 584, 559, 535, 511, 489, 467, 447, 427, 409, + 391, 374, 358, 343, 328, 313, 300, 287, 274, 261, + 248, 235, 223, 211, 200, 189, 179, 169, 160, 151, + 143, 135, 128, 121, 115, 109, 103, 97, 92, 87, + 82, 77, 73, 69, 65, 61, 58, 55, 52, 49, + 46, 43, 40, 37, 35, 33, 31, 29, 27, 25, + 23, 21, 20, 19, 18, 17, 16, 15, 14, 13, + 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, + 2, 1, 0 + }, + { + 16384, 16139, 15894, 15649, 15405, 15162, 14919, 14677, 14435, 14195, + 13955, 13717, 13479, 13243, 13008, 12775, 12542, 12310, 12079, 11851, + 11623, 11399, 11176, 10956, 10737, 10521, 10305, 10094, 9883, 9677, + 9471, 9268, 9065, 8862, 8659, 8459, 8260, 8067, 7874, 7688, + 7502, 7321, 7140, 6965, 6790, 6621, 6452, 6290, 6128, 5968, + 5808, 5655, 5503, 5356, 5209, 5069, 4929, 4794, 4660, 4532, + 4404, 4282, 4160, 4041, 3922, 3803, 3684, 3568, 3452, 3343, + 3234, 3131, 3029, 2931, 2833, 2741, 2649, 2563, 2477, 2396, + 2316, 2236, 2157, 2083, 2009, 1940, 1871, 1807, 1743, 1683, + 1623, 1567, 1511, 1459, 1407, 1357, 1307, 1257, 1207, 1159, + 1111, 1067, 1023, 983, 943, 905, 868, 834, 800, 769, + 738, 709, 681, 653, 625, 600, 575, 552, 529, 508, + 487, 466, 447, 428, 410, 392, 376, 360, 344, 328, + 313, 298, 283, 268, 255, 242, 230, 218, 207, 196, + 186, 176, 167, 158, 150, 142, 135, 128, 121, 114, + 108, 102, 97, 92, 87, 82, 78, 74, 70, 66, + 62, 58, 54, 50, 47, 44, 41, 38, 35, 32, + 30, 28, 26, 24, 22, 20, 18, 16, 14, 13, + 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, + 2, 1, 0 + }, + { + 16384, 16149, 15915, 15681, 15447, 15214, 14981, 14749, 14517, 14286, + 14055, 13827, 13599, 13373, 13147, 12923, 12699, 12476, 12253, 12034, + 11815, 11599, 11383, 11171, 10959, 10750, 10541, 10337, 10133, 9933, + 9733, 9536, 9339, 9142, 8945, 8751, 8557, 8369, 8181, 7998, + 7816, 7638, 7460, 7288, 7116, 6950, 6785, 6625, 6465, 6306, + 6147, 5995, 5843, 5697, 5551, 5411, 5271, 5135, 5000, 4871, + 4742, 4618, 4495, 4374, 4253, 4132, 4011, 3893, 3775, 3663, + 3552, 3446, 3340, 3239, 3138, 3043, 2948, 2858, 2768, 2684, + 2600, 2516, 2433, 2355, 2278, 2205, 2133, 2065, 1997, 1932, + 1867, 1807, 1747, 1690, 1634, 1580, 1526, 1472, 1418, 1366, + 1314, 1266, 1218, 1174, 1130, 1088, 1047, 1009, 971, 936, + 901, 868, 836, 804, 772, 743, 714, 685, 658, 631, + 606, 582, 559, 536, 515, 494, 475, 456, 437, 418, + 399, 380, 362, 344, 328, 312, 297, 283, 270, 257, + 245, 233, 222, 211, 201, 191, 181, 172, 163, 155, + 147, 139, 132, 125, 119, 113, 107, 101, 96, 91, + 86, 81, 76, 71, 66, 62, 58, 54, 50, 46, + 43, 40, 37, 34, 31, 28, 26, 24, 22, 20, + 18, 16, 14, 12, 10, 8, 6, 5, 4, 3, + 2, 1, 0 + }, + { + 16384, 16159, 15934, 15709, 15485, 15261, 15038, 14816, 14594, 14373, + 14152, 13933, 13714, 13497, 13280, 13065, 12850, 12636, 12422, 12211, + 12000, 11791, 11583, 11378, 11173, 10971, 10769, 10571, 10373, 10179, + 9985, 9793, 9601, 9409, 9217, 9029, 8842, 8658, 8475, 8297, + 8120, 7946, 7773, 7604, 7435, 7271, 7108, 6950, 6792, 6634, + 6477, 6326, 6175, 6029, 5883, 5742, 5602, 5466, 5330, 5199, + 5068, 4943, 4818, 4696, 4574, 4452, 4330, 4211, 4093, 3979, + 3866, 3759, 3652, 3549, 3446, 3348, 3250, 3157, 3065, 2977, + 2889, 2802, 2716, 2634, 2553, 2476, 2399, 2326, 2254, 2185, + 2117, 2052, 1987, 1926, 1866, 1808, 1750, 1692, 1634, 1578, + 1522, 1470, 1418, 1369, 1321, 1275, 1229, 1187, 1145, 1105, + 1066, 1027, 991, 955, 919, 883, 850, 817, 786, 756, + 728, 700, 674, 648, 624, 600, 578, 556, 534, 512, + 490, 468, 447, 426, 407, 388, 371, 354, 338, 322, + 307, 293, 280, 267, 255, 243, 231, 219, 209, 199, + 189, 179, 170, 161, 153, 145, 138, 131, 124, 117, + 111, 105, 99, 93, 87, 81, 76, 71, 66, 61, + 57, 53, 49, 45, 42, 39, 36, 33, 30, 27, + 24, 21, 19, 17, 15, 13, 11, 9, 7, 5, + 3, 1, 0 + }, + { + 16384, 16169, 15954, 15739, 15524, 15310, 15096, 14883, 14670, 14458, + 14246, 14035, 13824, 13614, 13405, 13198, 12991, 12785, 12579, 12376, + 12173, 11972, 11772, 11574, 11377, 11182, 10987, 10795, 10603, 10414, + 10226, 10040, 9854, 9668, 9482, 9299, 9116, 8937, 8759, 8585, + 8411, 8241, 8071, 7906, 7741, 7580, 7419, 7263, 7107, 6952, + 6797, 6647, 6497, 6353, 6209, 6070, 5931, 5796, 5661, 5531, + 5401, 5275, 5150, 5027, 4904, 4781, 4658, 4538, 4419, 4304, + 4190, 4081, 3972, 3867, 3762, 3662, 3562, 3467, 3372, 3281, + 3191, 3101, 3012, 2928, 2844, 2764, 2684, 2608, 2533, 2460, + 2387, 2318, 2250, 2185, 2121, 2059, 1997, 1935, 1873, 1813, + 1754, 1698, 1642, 1588, 1535, 1483, 1433, 1384, 1338, 1292, + 1249, 1206, 1165, 1125, 1085, 1045, 1008, 971, 937, 903, + 871, 840, 810, 780, 752, 724, 698, 672, 647, 622, + 597, 572, 548, 524, 502, 480, 460, 440, 421, 403, + 386, 369, 353, 337, 323, 309, 295, 281, 268, 255, + 243, 231, 220, 209, 199, 189, 180, 171, 163, 155, + 147, 139, 131, 123, 116, 109, 102, 95, 89, 83, + 77, 72, 67, 62, 57, 52, 48, 44, 40, 36, + 32, 28, 25, 22, 19, 16, 13, 10, 8, 6, + 4, 2, 0 + }, + { + 16384, 16177, 15970, 15764, 15558, 15353, 15148, 14944, 14740, 14537, + 14334, 14132, 13930, 13729, 13529, 13330, 13131, 12933, 12735, 12539, + 12343, 12150, 11957, 11766, 11576, 11388, 11200, 11015, 10830, 10647, + 10465, 10285, 10105, 9925, 9745, 9568, 9391, 9218, 9045, 8876, + 8707, 8541, 8375, 8213, 8051, 7894, 7737, 7583, 7429, 7277, + 7125, 6977, 6830, 6687, 6544, 6406, 6268, 6133, 5998, 5868, + 5738, 5612, 5487, 5364, 5241, 5118, 4995, 4875, 4755, 4640, + 4525, 4414, 4304, 4198, 4092, 3990, 3888, 3790, 3693, 3600, + 3507, 3415, 3323, 3235, 3147, 3064, 2981, 2902, 2823, 2746, + 2670, 2594, 2522, 2450, 2382, 2314, 2248, 2182, 2116, 2050, + 1987, 1924, 1864, 1804, 1748, 1692, 1638, 1585, 1534, 1484, + 1437, 1390, 1346, 1302, 1258, 1215, 1174, 1133, 1095, 1057, + 1021, 986, 952, 918, 887, 856, 827, 798, 770, 742, + 714, 686, 659, 632, 607, 582, 559, 536, 514, 492, + 472, 452, 433, 415, 398, 381, 364, 348, 333, 318, + 304, 290, 277, 264, 252, 240, 229, 218, 208, 198, + 188, 178, 168, 158, 149, 140, 132, 124, 116, 108, + 101, 94, 87, 81, 75, 69, 64, 59, 54, 49, + 44, 39, 35, 31, 27, 23, 19, 15, 12, 9, + 6, 3, 0 + } +}; + + +static const uint16_t cf_tables_3[5][257] = { + { + 16384, 16187, 15990, 15793, 15597, 15401, 15205, 15009, 14813, 14618, + 14423, 14230, 14037, 13845, 13653, 13463, 13273, 13083, 12894, 12706, + 12518, 12332, 12146, 11962, 11778, 11597, 11416, 11237, 11059, 10882, + 10706, 10532, 10358, 10184, 10010, 9838, 9666, 9497, 9328, 9163, + 8999, 8837, 8675, 8517, 8359, 8205, 8051, 7901, 7751, 7602, + 7453, 7308, 7163, 7022, 6882, 6745, 6609, 6476, 6343, 6214, + 6085, 5960, 5835, 5712, 5589, 5466, 5343, 5223, 5103, 4987, + 4872, 4761, 4650, 4542, 4435, 4332, 4229, 4130, 4031, 3936, + 3841, 3747, 3653, 3563, 3473, 3387, 3302, 3220, 3138, 3059, + 2980, 2905, 2830, 2759, 2688, 2619, 2550, 2481, 2412, 2345, + 2278, 2215, 2152, 2092, 2032, 1974, 1917, 1863, 1809, 1758, + 1707, 1659, 1611, 1564, 1517, 1473, 1429, 1387, 1346, 1307, + 1268, 1230, 1193, 1158, 1123, 1090, 1058, 1026, 994, 962, + 930, 899, 869, 841, 813, 786, 760, 735, 710, 687, + 664, 643, 622, 602, 582, 562, 543, 525, 507, 490, + 473, 457, 442, 427, 412, 398, 385, 373, 361, 349, + 337, 325, 313, 301, 290, 279, 269, 259, 249, 240, + 231, 222, 214, 206, 199, 192, 185, 178, 171, 165, + 159, 153, 148, 143, 138, 133, 128, 123, 119, 115, + 111, 107, 103, 99, 95, 91, 87, 83, 80, 77, + 74, 71, 68, 65, 63, 61, 59, 57, 55, 53, + 51, 49, 47, 45, 43, 41, 40, 39, 38, 37, + 36, 35, 34, 33, 32, 31, 30, 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 + }, + { + 16384, 16195, 16006, 15817, 15629, 15441, 15253, 15065, 14878, 14692, + 14506, 14321, 14136, 13952, 13768, 13585, 13402, 13219, 13037, 12857, + 12677, 12499, 12321, 12144, 11967, 11792, 11617, 11444, 11271, 11100, + 10930, 10762, 10594, 10426, 10258, 10091, 9925, 9761, 9598, 9438, + 9278, 9120, 8963, 8809, 8655, 8504, 8354, 8207, 8060, 7914, + 7769, 7627, 7485, 7347, 7209, 7074, 6939, 6807, 6676, 6548, + 6420, 6296, 6172, 6050, 5928, 5806, 5684, 5564, 5444, 5328, + 5212, 5100, 4988, 4879, 4771, 4667, 4563, 4462, 4362, 4265, + 4169, 4073, 3978, 3886, 3795, 3707, 3619, 3535, 3451, 3369, + 3288, 3210, 3133, 3059, 2985, 2913, 2841, 2769, 2697, 2627, + 2557, 2490, 2424, 2360, 2297, 2237, 2177, 2119, 2062, 2007, + 1953, 1901, 1849, 1798, 1748, 1700, 1652, 1607, 1562, 1519, + 1476, 1435, 1394, 1355, 1317, 1281, 1245, 1210, 1175, 1140, + 1105, 1071, 1037, 1005, 973, 943, 913, 885, 857, 830, + 804, 779, 754, 731, 708, 685, 663, 642, 621, 601, + 581, 563, 545, 528, 511, 495, 479, 463, 448, 433, + 419, 405, 391, 377, 364, 351, 338, 326, 314, 302, + 291, 280, 270, 260, 251, 242, 234, 226, 218, 210, + 202, 195, 188, 181, 174, 168, 162, 156, 150, 144, + 139, 134, 129, 124, 119, 114, 109, 104, 100, 96, + 92, 88, 84, 80, 77, 74, 71, 68, 65, 62, + 59, 56, 54, 52, 50, 48, 46, 44, 42, 40, + 38, 36, 34, 33, 32, 31, 30, 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 + }, + { + 16384, 16203, 16022, 15842, 15662, 15482, 15302, 15122, 14942, 14763, + 14584, 14406, 14228, 14051, 13874, 13698, 13522, 13347, 13172, 12998, + 12824, 12652, 12480, 12310, 12140, 11971, 11803, 11637, 11471, 11307, + 11143, 10980, 10817, 10654, 10491, 10330, 10169, 10011, 9853, 9697, + 9542, 9389, 9236, 9086, 8936, 8789, 8642, 8498, 8355, 8212, + 8070, 7931, 7792, 7656, 7520, 7388, 7256, 7126, 6996, 6870, + 6744, 6621, 6498, 6377, 6256, 6135, 6014, 5895, 5776, 5660, + 5545, 5433, 5321, 5212, 5104, 4999, 4895, 4793, 4692, 4594, + 4496, 4400, 4304, 4211, 4118, 4028, 3939, 3853, 3767, 3684, + 3601, 3521, 3441, 3364, 3287, 3212, 3137, 3062, 2987, 2915, + 2843, 2773, 2704, 2638, 2572, 2508, 2445, 2384, 2324, 2266, + 2208, 2153, 2098, 2044, 1990, 1939, 1888, 1839, 1791, 1745, + 1699, 1655, 1611, 1569, 1527, 1487, 1448, 1409, 1370, 1331, + 1292, 1255, 1218, 1183, 1148, 1115, 1082, 1051, 1020, 990, + 960, 932, 904, 878, 852, 826, 801, 777, 753, 731, + 709, 687, 666, 645, 625, 605, 586, 567, 550, 533, + 516, 499, 482, 465, 449, 433, 418, 403, 389, 375, + 362, 349, 337, 325, 314, 303, 293, 283, 273, 263, + 254, 245, 236, 227, 219, 211, 204, 197, 190, 183, + 177, 171, 165, 159, 153, 147, 141, 135, 130, 125, + 120, 115, 110, 105, 101, 97, 93, 89, 85, 81, + 77, 74, 71, 68, 65, 62, 59, 56, 53, 51, + 49, 47, 45, 43, 41, 39, 37, 35, 33, 31, + 29, 27, 25, 23, 22, 21, 20, 19, 18, 17, + 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, + 6, 5, 4, 3, 2, 1, 0 + }, + { + 16384, 16210, 16036, 15863, 15690, 15517, 15344, 15172, 15000, 14828, + 14656, 14485, 14314, 14145, 13976, 13808, 13640, 13472, 13304, 13137, + 12970, 12804, 12639, 12475, 12312, 12149, 11987, 11827, 11667, 11508, + 11349, 11192, 11035, 10878, 10721, 10565, 10410, 10257, 10104, 9953, + 9802, 9654, 9506, 9359, 9213, 9070, 8927, 8787, 8647, 8508, + 8369, 8233, 8097, 7964, 7831, 7700, 7570, 7442, 7315, 7190, + 7065, 6943, 6821, 6701, 6581, 6461, 6341, 6223, 6105, 5990, + 5876, 5764, 5653, 5545, 5437, 5331, 5226, 5124, 5022, 4924, + 4826, 4729, 4632, 4538, 4444, 4353, 4262, 4174, 4087, 4002, + 3917, 3835, 3753, 3674, 3595, 3518, 3441, 3364, 3287, 3212, + 3138, 3066, 2995, 2926, 2858, 2792, 2726, 2662, 2599, 2538, + 2478, 2420, 2362, 2305, 2249, 2195, 2141, 2089, 2037, 1988, + 1939, 1891, 1844, 1799, 1754, 1711, 1668, 1626, 1584, 1542, + 1500, 1459, 1418, 1380, 1342, 1305, 1269, 1234, 1199, 1166, + 1133, 1102, 1071, 1041, 1012, 983, 954, 926, 899, 872, + 847, 822, 798, 774, 751, 728, 707, 686, 666, 646, + 627, 608, 589, 570, 552, 534, 517, 500, 484, 468, + 453, 438, 424, 410, 397, 384, 372, 360, 348, 336, + 325, 314, 303, 293, 283, 273, 264, 255, 246, 237, + 229, 221, 213, 205, 197, 189, 181, 174, 167, 160, + 154, 148, 142, 136, 131, 126, 121, 116, 111, 106, + 101, 97, 93, 89, 85, 81, 77, 73, 70, 67, + 64, 61, 58, 55, 52, 49, 46, 43, 40, 37, + 35, 33, 31, 29, 27, 25, 23, 21, 19, 17, + 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, + 6, 5, 4, 3, 2, 1, 0 + }, + { + 16384, 16218, 16052, 15886, 15720, 15554, 15389, 15224, 15059, 14895, + 14731, 14567, 14403, 14240, 14077, 13915, 13753, 13591, 13429, 13269, + 13109, 12950, 12791, 12633, 12476, 12320, 12164, 12009, 11854, 11701, + 11548, 11396, 11244, 11092, 10940, 10790, 10640, 10492, 10344, 10198, + 10052, 9908, 9764, 9622, 9481, 9342, 9203, 9066, 8929, 8793, + 8657, 8524, 8391, 8261, 8131, 8003, 7875, 7749, 7624, 7502, + 7380, 7260, 7140, 7022, 6904, 6786, 6668, 6551, 6435, 6322, + 6209, 6099, 5989, 5881, 5773, 5668, 5563, 5461, 5359, 5260, + 5161, 5063, 4965, 4871, 4777, 4686, 4595, 4506, 4417, 4331, + 4245, 4162, 4079, 3999, 3919, 3841, 3763, 3685, 3607, 3530, + 3454, 3380, 3307, 3236, 3166, 3097, 3029, 2963, 2897, 2834, + 2771, 2710, 2650, 2591, 2532, 2475, 2418, 2363, 2309, 2257, + 2205, 2155, 2105, 2057, 2009, 1963, 1918, 1873, 1828, 1783, + 1738, 1694, 1650, 1607, 1565, 1524, 1484, 1445, 1407, 1369, + 1333, 1297, 1263, 1229, 1197, 1165, 1134, 1103, 1073, 1043, + 1015, 987, 960, 933, 907, 882, 858, 834, 811, 788, + 766, 744, 722, 700, 679, 658, 638, 618, 599, 581, + 563, 545, 528, 511, 495, 480, 465, 451, 437, 423, + 410, 397, 384, 372, 360, 348, 337, 326, 315, 305, + 295, 285, 275, 265, 255, 245, 236, 227, 219, 211, + 203, 195, 188, 181, 174, 167, 161, 155, 149, 143, + 137, 131, 126, 121, 116, 111, 106, 101, 97, 93, + 89, 85, 81, 77, 73, 69, 65, 61, 58, 55, + 52, 49, 46, 43, 40, 37, 34, 32, 30, 28, + 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, + 6, 5, 4, 3, 2, 1, 0 + } +}; + + +static const uint16_t * const cf_table[16] = { + cf_tables_1[0], cf_tables_1[1], cf_tables_1[2], cf_tables_2[0], + cf_tables_2[1], cf_tables_2[2], cf_tables_2[3], cf_tables_2[4], + cf_tables_2[5], cf_tables_2[6], cf_tables_2[7], cf_tables_3[0], + cf_tables_3[1], cf_tables_3[2], cf_tables_3[3], cf_tables_3[4] +}; + + +/** Initializes a given lookup table using a given delta + */ +static void bgmc_lut_fillp(uint8_t *lut, unsigned int *lut_status, + unsigned int delta) +{ + unsigned int sx, i; + + for (sx = 0; sx < 16; sx++) + for (i = 0; i < LUT_SIZE; i++) { + unsigned int target = (i + 1) << (FREQ_BITS - LUT_BITS); + unsigned int symbol = 1 << delta; + + while (cf_table[sx][symbol] > target) + symbol += 1 << delta; + + *lut++ = symbol >> delta; + } + + *lut_status = delta; +} + + +/** Retunes the index of a suitable lookup table for a given delta + */ +static uint8_t* bgmc_lut_getp(uint8_t *lut, unsigned int *lut_status, + unsigned int delta) +{ + unsigned int i = av_clip(delta, 0, LUT_BUFF - 1); + + lut += (i * LUT_SIZE) << 4; + + if (lut_status[i] != delta) + bgmc_lut_fillp(lut, &lut_status[i], delta); + + return lut; +} + + +/** Initializes the lookup table arrays + */ +int ff_bgmc_init(AVCodecContext *avctx, uint8_t **cf_lut, unsigned int **cf_lut_status) +{ + *cf_lut = av_malloc(sizeof(*cf_lut ) * LUT_BUFF * 16 * LUT_SIZE); + *cf_lut_status = av_malloc(sizeof(*cf_lut_status) * LUT_BUFF); + + if (!cf_lut || !cf_lut_status) { + ff_bgmc_end(cf_lut, cf_lut_status); + av_log(avctx, AV_LOG_ERROR, "Allocating buffer memory failed.\n"); + return AVERROR(ENOMEM); + } + + return 0; +} + + +/** Releases the lookup table arrays + */ +void ff_bgmc_end(uint8_t **cf_lut, unsigned int **cf_lut_status) +{ + av_freep(cf_lut); + av_freep(cf_lut_status); +} + + +/** Initializes decoding and reads the first value + */ +void ff_bgmc_decode_init(GetBitContext *gb, + unsigned int *h, unsigned int *l, unsigned int *v) +{ + *h = TOP_VALUE; + *l = 0; + *v = get_bits_long(gb, VALUE_BITS); +} + + +/** Finish decoding + */ +void ff_bgmc_decode_end(GetBitContext *gb) +{ + skip_bits_long(gb, -(VALUE_BITS - 2)); +} + + +/** Reads and decodes a block Gilbert-Moore coded symbol + */ +void ff_bgmc_decode(GetBitContext *gb, unsigned int num, int32_t *dst, + unsigned int delta, unsigned int sx, + unsigned int *h, unsigned int *l, unsigned int *v, + uint8_t *cf_lut, unsigned int *cf_lut_status) +{ + unsigned int i; + uint8_t *lut = bgmc_lut_getp(cf_lut, cf_lut_status, delta); + + // read current state + unsigned int high = *h; + unsigned int low = *l; + unsigned int value = *v; + + lut += sx * LUT_SIZE; + + // decode num samples + for (i = 0; i < num; i++) { + unsigned int range = high - low + 1; + unsigned int target = (((value - low + 1) << FREQ_BITS) - 1) / range; + unsigned int symbol = lut[target >> (FREQ_BITS - LUT_BITS)] << delta; + + while (cf_table[sx][symbol] > target) + symbol += 1 << delta; + + symbol = (symbol >> delta) - 1; + + high = low + ((range * cf_table[sx][(symbol ) << delta] - (1 << FREQ_BITS)) >> FREQ_BITS); + low = low + ((range * cf_table[sx][(symbol + 1) << delta] ) >> FREQ_BITS); + + while (1) { + if (high >= HALF) { + if (low >= HALF) { + value -= HALF; + low -= HALF; + high -= HALF; + } else if (low >= FIRST_QTR && high < THIRD_QTR) { + value -= FIRST_QTR; + low -= FIRST_QTR; + high -= FIRST_QTR; + } else break; + } + + low *= 2; + high = 2 * high + 1; + value = 2 * value + get_bits1(gb); + } + + *dst++ = symbol; + } + + // save current state + *h = high; + *l = low; + *v = value; +} + diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/bgmc.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/bgmc.h new file mode 100644 index 0000000000..eab413b6a8 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/bgmc.h @@ -0,0 +1,56 @@ +/* + * Block Gilbert-Moore decoder + * Copyright (c) 2010 Thilo Borgmann + * + * 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 + * Block Gilbert-Moore decoder header + * @author Thilo Borgmann + */ + + +#ifndef AVCODEC_BGMC_H +#define AVCODEC_BGMC_H + + +#include "avcodec.h" +#include "get_bits.h" + + +int ff_bgmc_init(AVCodecContext *avctx, uint8_t **cf_lut, unsigned int **cf_lut_status); + + +void ff_bgmc_end(uint8_t **cf_lut, unsigned int **cf_lut_status); + + +void ff_bgmc_decode_init(GetBitContext *gb, + unsigned int *h, unsigned int *l, unsigned int *v); + + +void ff_bgmc_decode_end(GetBitContext *gb); + + +void ff_bgmc_decode(GetBitContext *gb, unsigned int num, int32_t *dst, + unsigned int delta, unsigned int sx, + unsigned int *h, unsigned int *l, unsigned int *v, + uint8_t *cf_lut, unsigned int *cf_lut_status); + + +#endif /* AVCODEC_BGMC_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/bink.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/bink.c new file mode 100644 index 0000000000..a988a34933 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/bink.c @@ -0,0 +1,1012 @@ +/* + * Bink video decoder + * 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 + */ + +#include "avcodec.h" +#include "dsputil.h" +#include "binkdata.h" +#include "mathops.h" + +#define ALT_BITSTREAM_READER_LE +#include "get_bits.h" + +#define BINK_FLAG_ALPHA 0x00100000 +#define BINK_FLAG_GRAY 0x00020000 + +static VLC bink_trees[16]; + +/** + * IDs for different data types used in Bink video codec + */ +enum Sources { + BINK_SRC_BLOCK_TYPES = 0, ///< 8x8 block types + BINK_SRC_SUB_BLOCK_TYPES, ///< 16x16 block types (a subset of 8x8 block types) + BINK_SRC_COLORS, ///< pixel values used for different block types + BINK_SRC_PATTERN, ///< 8-bit values for 2-colour pattern fill + BINK_SRC_X_OFF, ///< X components of motion value + BINK_SRC_Y_OFF, ///< Y components of motion value + BINK_SRC_INTRA_DC, ///< DC values for intrablocks with DCT + BINK_SRC_INTER_DC, ///< DC values for interblocks with DCT + BINK_SRC_RUN, ///< run lengths for special fill block + + BINK_NB_SRC +}; + +/** + * data needed to decode 4-bit Huffman-coded value + */ +typedef struct Tree { + int vlc_num; ///< tree number (in bink_trees[]) + uint8_t syms[16]; ///< leaf value to symbol mapping +} Tree; + +#define GET_HUFF(gb, tree) (tree).syms[get_vlc2(gb, bink_trees[(tree).vlc_num].table,\ + bink_trees[(tree).vlc_num].bits, 1)] + +/** + * data structure used for decoding single Bink data type + */ +typedef struct Bundle { + int len; ///< length of number of entries to decode (in bits) + Tree tree; ///< Huffman tree-related data + uint8_t *data; ///< buffer for decoded symbols + uint8_t *data_end; ///< buffer end + uint8_t *cur_dec; ///< pointer to the not yet decoded part of the buffer + uint8_t *cur_ptr; ///< pointer to the data that is not read from buffer yet +} Bundle; + +/* + * Decoder context + */ +typedef struct BinkContext { + AVCodecContext *avctx; + DSPContext dsp; + 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[BINK_NB_SRC]; ///< bundles for decoding all data types + Tree col_high[16]; ///< trees for decoding high nibble in "colours" data type + int col_lastval; ///< value of last decoded high nibble in "colours" data type +} BinkContext; + +/** + * Bink video block types + */ +enum BlockTypes { + SKIP_BLOCK = 0, ///< skipped block + SCALED_BLOCK, ///< block has size 16x16 + MOTION_BLOCK, ///< block is copied from previous frame with some offset + RUN_BLOCK, ///< block is composed from runs of colours with custom scan order + RESIDUE_BLOCK, ///< motion block with some difference added + INTRA_BLOCK, ///< intra DCT block + FILL_BLOCK, ///< block is filled with single colour + INTER_BLOCK, ///< motion block with DCT applied to the difference + PATTERN_BLOCK, ///< block is filled with two colours following custom pattern + RAW_BLOCK, ///< uncoded 8x8 block +}; + +/** + * Initializes length length in all bundles. + * + * @param c decoder context + * @param width plane width + * @param bw plane width in 8x8 blocks + */ +static void init_lengths(BinkContext *c, int width, int bw) +{ + c->bundle[BINK_SRC_BLOCK_TYPES].len = av_log2((width >> 3) + 511) + 1; + + c->bundle[BINK_SRC_SUB_BLOCK_TYPES].len = av_log2((width >> 4) + 511) + 1; + + c->bundle[BINK_SRC_COLORS].len = av_log2((width >> 3)*64 + 511) + 1; + + c->bundle[BINK_SRC_INTRA_DC].len = + c->bundle[BINK_SRC_INTER_DC].len = + c->bundle[BINK_SRC_X_OFF].len = + c->bundle[BINK_SRC_Y_OFF].len = av_log2((width >> 3) + 511) + 1; + + c->bundle[BINK_SRC_PATTERN].len = av_log2((bw << 3) + 511) + 1; + + c->bundle[BINK_SRC_RUN].len = av_log2((width >> 3)*48 + 511) + 1; +} + +/** + * Allocates memory for bundles. + * + * @param c decoder context + */ +static av_cold void init_bundles(BinkContext *c) +{ + int bw, bh, blocks; + int i; + + bw = (c->avctx->width + 7) >> 3; + bh = (c->avctx->height + 7) >> 3; + blocks = bw * bh; + + for (i = 0; i < BINK_NB_SRC; i++) { + c->bundle[i].data = av_malloc(blocks * 64); + c->bundle[i].data_end = c->bundle[i].data + blocks * 64; + } +} + +/** + * Frees memory used by bundles. + * + * @param c decoder context + */ +static av_cold void free_bundles(BinkContext *c) +{ + int i; + for (i = 0; i < BINK_NB_SRC; i++) + av_freep(&c->bundle[i].data); +} + +/** + * Merges two consequent lists of equal size depending on bits read. + * + * @param gb context for reading bits + * @param dst buffer where merged list will be written to + * @param src pointer to the head of the first list (the second lists starts at src+size) + * @param size input lists size + */ +static void merge(GetBitContext *gb, uint8_t *dst, uint8_t *src, int size) +{ + uint8_t *src2 = src + size; + int size2 = size; + + do { + if (!get_bits1(gb)) { + *dst++ = *src++; + size--; + } else { + *dst++ = *src2++; + size2--; + } + } while (size && size2); + + while (size--) + *dst++ = *src++; + while (size2--) + *dst++ = *src2++; +} + +/** + * Reads information about Huffman tree used to decode data. + * + * @param gb context for reading bits + * @param tree pointer for storing tree data + */ +static void read_tree(GetBitContext *gb, Tree *tree) +{ + uint8_t tmp1[16], tmp2[16], *in = tmp1, *out = tmp2; + int i, t, len; + + tree->vlc_num = get_bits(gb, 4); + if (!tree->vlc_num) { + for (i = 0; i < 16; i++) + tree->syms[i] = i; + return; + } + if (get_bits1(gb)) { + len = get_bits(gb, 3); + memset(tmp1, 0, sizeof(tmp1)); + for (i = 0; i <= len; i++) { + tree->syms[i] = get_bits(gb, 4); + tmp1[tree->syms[i]] = 1; + } + for (i = 0; i < 16; i++) + if (!tmp1[i]) + tree->syms[++len] = i; + } else { + len = get_bits(gb, 2); + for (i = 0; i < 16; i++) + in[i] = i; + for (i = 0; i <= len; i++) { + int size = 1 << i; + for (t = 0; t < 16; t += size << 1) + merge(gb, out + t, in + t, size); + FFSWAP(uint8_t*, in, out); + } + memcpy(tree->syms, in, 16); + } +} + +/** + * Prepares bundle for decoding data. + * + * @param gb context for reading bits + * @param c decoder context + * @param bundle_num number of the bundle to initialize + */ +static void read_bundle(GetBitContext *gb, BinkContext *c, int bundle_num) +{ + int i; + + if (bundle_num == BINK_SRC_COLORS) { + for (i = 0; i < 16; i++) + read_tree(gb, &c->col_high[i]); + c->col_lastval = 0; + } + if (bundle_num != BINK_SRC_INTRA_DC && bundle_num != BINK_SRC_INTER_DC) + read_tree(gb, &c->bundle[bundle_num].tree); + c->bundle[bundle_num].cur_dec = + c->bundle[bundle_num].cur_ptr = c->bundle[bundle_num].data; +} + +/** + * common check before starting decoding bundle data + * + * @param gb context for reading bits + * @param b bundle + * @param t variable where number of elements to decode will be stored + */ +#define CHECK_READ_VAL(gb, b, t) \ + if (!b->cur_dec || (b->cur_dec > b->cur_ptr)) \ + return 0; \ + t = get_bits(gb, b->len); \ + if (!t) { \ + b->cur_dec = NULL; \ + return 0; \ + } \ + +static int read_runs(AVCodecContext *avctx, GetBitContext *gb, Bundle *b) +{ + int t, v; + const uint8_t *dec_end; + + CHECK_READ_VAL(gb, b, t); + dec_end = b->cur_dec + t; + if (dec_end > b->data_end) { + av_log(avctx, AV_LOG_ERROR, "Run value went out of bounds\n"); + return -1; + } + if (get_bits1(gb)) { + v = get_bits(gb, 4); + memset(b->cur_dec, v, t); + b->cur_dec += t; + } else { + while (b->cur_dec < dec_end) + *b->cur_dec++ = GET_HUFF(gb, b->tree); + } + return 0; +} + +static int read_motion_values(AVCodecContext *avctx, GetBitContext *gb, Bundle *b) +{ + int t, sign, v; + const uint8_t *dec_end; + + CHECK_READ_VAL(gb, b, t); + dec_end = b->cur_dec + t; + if (dec_end > b->data_end) { + av_log(avctx, AV_LOG_ERROR, "Too many motion values\n"); + return -1; + } + if (get_bits1(gb)) { + v = get_bits(gb, 4); + if (v) { + sign = -get_bits1(gb); + v = (v ^ sign) - sign; + } + memset(b->cur_dec, v, t); + b->cur_dec += t; + } else { + do { + 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; +} + +const uint8_t bink_rlelens[4] = { 4, 8, 12, 32 }; + +static int read_block_types(AVCodecContext *avctx, GetBitContext *gb, Bundle *b) +{ + int t, v; + int last = 0; + const uint8_t *dec_end; + + CHECK_READ_VAL(gb, b, t); + dec_end = b->cur_dec + t; + if (dec_end > b->data_end) { + av_log(avctx, AV_LOG_ERROR, "Too many block type values\n"); + return -1; + } + if (get_bits1(gb)) { + v = get_bits(gb, 4); + memset(b->cur_dec, v, t); + b->cur_dec += t; + } else { + do { + v = GET_HUFF(gb, b->tree); + if (v < 12) { + last = v; + *b->cur_dec++ = v; + } else { + int run = bink_rlelens[v - 12]; + + memset(b->cur_dec, last, run); + b->cur_dec += run; + } + } while (b->cur_dec < dec_end); + } + return 0; +} + +static int read_patterns(AVCodecContext *avctx, GetBitContext *gb, Bundle *b) +{ + int t, v; + const uint8_t *dec_end; + + CHECK_READ_VAL(gb, b, t); + dec_end = b->cur_dec + t; + if (dec_end > b->data_end) { + av_log(avctx, AV_LOG_ERROR, "Too many pattern values\n"); + return -1; + } + while (b->cur_dec < dec_end) { + v = GET_HUFF(gb, b->tree); + v |= GET_HUFF(gb, b->tree) << 4; + *b->cur_dec++ = v; + } + + return 0; +} + +static int read_colors(GetBitContext *gb, Bundle *b, BinkContext *c) +{ + int t, sign, v; + const uint8_t *dec_end; + + CHECK_READ_VAL(gb, b, t); + dec_end = b->cur_dec + t; + if (dec_end > b->data_end) { + av_log(c->avctx, AV_LOG_ERROR, "Too many color values\n"); + return -1; + } + if (get_bits1(gb)) { + c->col_lastval = GET_HUFF(gb, c->col_high[c->col_lastval]); + v = GET_HUFF(gb, b->tree); + v = (c->col_lastval << 4) | v; + if (c->version < 'i') { + sign = ((int8_t) v) >> 7; + v = ((v & 0x7F) ^ sign) - sign; + v += 0x80; + } + memset(b->cur_dec, v, t); + b->cur_dec += t; + } else { + while (b->cur_dec < dec_end) { + c->col_lastval = GET_HUFF(gb, c->col_high[c->col_lastval]); + v = GET_HUFF(gb, b->tree); + v = (c->col_lastval << 4) | v; + if (c->version < 'i') { + sign = ((int8_t) v) >> 7; + v = ((v & 0x7F) ^ sign) - sign; + v += 0x80; + } + *b->cur_dec++ = v; + } + } + return 0; +} + +/** number of bits used to store first DC value in bundle */ +#define DC_START_BITS 11 + +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; + + CHECK_READ_VAL(gb, b, len); + v = get_bits(gb, start_bits - has_sign); + if (v && has_sign) { + sign = -get_bits1(gb); + v = (v ^ sign) - sign; + } + *dst++ = v; + len--; + for (i = 0; i < len; i += 8) { + len2 = FFMIN(len - i, 8); + bsize = get_bits(gb, 4); + if (bsize) { + for (j = 0; j < len2; j++) { + v2 = get_bits(gb, bsize); + if (v2) { + sign = -get_bits1(gb); + v2 = (v2 ^ sign) - sign; + } + v += v2; + *dst++ = v; + if (v < -32768 || v > 32767) { + av_log(avctx, AV_LOG_ERROR, "DC value went out of bounds: %d\n", v); + return -1; + } + } + } else { + for (j = 0; j < len2; j++) + *dst++ = v; + } + } + + b->cur_dec = (uint8_t*)dst; + return 0; +} + +/** + * Retrieves next value from bundle. + * + * @param c decoder context + * @param bundle bundle number + */ +static inline int get_value(BinkContext *c, int bundle) +{ + int16_t ret; + + if (bundle < BINK_SRC_X_OFF || bundle == BINK_SRC_RUN) + return *c->bundle[bundle].cur_ptr++; + if (bundle == BINK_SRC_X_OFF || bundle == BINK_SRC_Y_OFF) + return (int8_t)*c->bundle[bundle].cur_ptr++; + ret = *(int16_t*)c->bundle[bundle].cur_ptr; + c->bundle[bundle].cur_ptr += 2; + return ret; +} + +/** + * Reads 8x8 block of DCT coefficients. + * + * @param gb context for reading bits + * @param block place for storing coefficients + * @param scan scan order table + * @param is_intra tells what set of quantizer matrices to use + * @return 0 for success, negative value in other cases + */ +static int read_dct_coeffs(GetBitContext *gb, DCTELEM block[64], const uint8_t *scan, + int is_intra) +{ + int coef_list[128]; + int mode_list[128]; + int i, t, mask, bits, ccoef, mode, sign; + int list_start = 64, list_end = 64, list_pos; + int coef_count = 0; + int coef_idx[64]; + int quant_idx; + const uint32_t *quant; + + coef_list[list_end] = 4; mode_list[list_end++] = 0; + coef_list[list_end] = 24; mode_list[list_end++] = 0; + coef_list[list_end] = 44; mode_list[list_end++] = 0; + coef_list[list_end] = 1; mode_list[list_end++] = 3; + coef_list[list_end] = 2; mode_list[list_end++] = 3; + coef_list[list_end] = 3; mode_list[list_end++] = 3; + + bits = get_bits(gb, 4) - 1; + for (mask = 1 << bits; bits >= 0; mask >>= 1, bits--) { + list_pos = list_start; + while (list_pos < list_end) { + if (!(mode_list[list_pos] | coef_list[list_pos]) || !get_bits1(gb)) { + list_pos++; + continue; + } + ccoef = coef_list[list_pos]; + mode = mode_list[list_pos]; + switch (mode) { + case 0: + coef_list[list_pos] = ccoef + 4; + mode_list[list_pos] = 1; + case 2: + if (mode == 2) { + coef_list[list_pos] = 0; + mode_list[list_pos++] = 0; + } + for (i = 0; i < 4; i++, ccoef++) { + if (get_bits1(gb)) { + coef_list[--list_start] = ccoef; + mode_list[ list_start] = 3; + } else { + int t; + if (!bits) { + t = 1 - (get_bits1(gb) << 1); + } else { + t = get_bits(gb, bits) | mask; + sign = -get_bits1(gb); + t = (t ^ sign) - sign; + } + block[scan[ccoef]] = t; + coef_idx[coef_count++] = ccoef; + } + } + break; + case 1: + mode_list[list_pos] = 2; + for (i = 0; i < 3; i++) { + ccoef += 4; + coef_list[list_end] = ccoef; + mode_list[list_end++] = 2; + } + break; + case 3: + if (!bits) { + t = 1 - (get_bits1(gb) << 1); + } else { + t = get_bits(gb, bits) | mask; + sign = -get_bits1(gb); + t = (t ^ sign) - sign; + } + block[scan[ccoef]] = t; + coef_idx[coef_count++] = ccoef; + coef_list[list_pos] = 0; + mode_list[list_pos++] = 0; + break; + } + } + } + + quant_idx = get_bits(gb, 4); + quant = is_intra ? bink_intra_quant[quant_idx] + : bink_inter_quant[quant_idx]; + block[0] = (block[0] * quant[0]) >> 11; + for (i = 0; i < coef_count; i++) { + int idx = coef_idx[i]; + block[scan[idx]] = (block[scan[idx]] * quant[idx]) >> 11; + } + + return 0; +} + +/** + * Reads 8x8 block with residue after motion compensation. + * + * @param gb context for reading bits + * @param block place to store read data + * @param masks_count number of masks to decode + * @return 0 on success, negative value in other cases + */ +static int read_residue(GetBitContext *gb, DCTELEM block[64], int masks_count) +{ + int coef_list[128]; + int mode_list[128]; + int i, sign, mask, ccoef, mode; + int list_start = 64, list_end = 64, list_pos; + int nz_coeff[64]; + int nz_coeff_count = 0; + + coef_list[list_end] = 4; mode_list[list_end++] = 0; + coef_list[list_end] = 24; mode_list[list_end++] = 0; + coef_list[list_end] = 44; mode_list[list_end++] = 0; + coef_list[list_end] = 0; mode_list[list_end++] = 2; + + for (mask = 1 << get_bits(gb, 3); mask; mask >>= 1) { + for (i = 0; i < nz_coeff_count; i++) { + if (!get_bits1(gb)) + continue; + if (block[nz_coeff[i]] < 0) + block[nz_coeff[i]] -= mask; + else + block[nz_coeff[i]] += mask; + masks_count--; + if (masks_count < 0) + return 0; + } + list_pos = list_start; + while (list_pos < list_end) { + if (!(coef_list[list_pos] | mode_list[list_pos]) || !get_bits1(gb)) { + list_pos++; + continue; + } + ccoef = coef_list[list_pos]; + mode = mode_list[list_pos]; + switch (mode) { + case 0: + coef_list[list_pos] = ccoef + 4; + mode_list[list_pos] = 1; + case 2: + if (mode == 2) { + coef_list[list_pos] = 0; + mode_list[list_pos++] = 0; + } + for (i = 0; i < 4; i++, ccoef++) { + if (get_bits1(gb)) { + coef_list[--list_start] = ccoef; + mode_list[ list_start] = 3; + } else { + nz_coeff[nz_coeff_count++] = bink_scan[ccoef]; + sign = -get_bits1(gb); + block[bink_scan[ccoef]] = (mask ^ sign) - sign; + masks_count--; + if (masks_count < 0) + return 0; + } + } + break; + case 1: + mode_list[list_pos] = 2; + for (i = 0; i < 3; i++) { + ccoef += 4; + coef_list[list_end] = ccoef; + mode_list[list_end++] = 2; + } + break; + case 3: + nz_coeff[nz_coeff_count++] = bink_scan[ccoef]; + sign = -get_bits1(gb); + block[bink_scan[ccoef]] = (mask ^ sign) - sign; + coef_list[list_pos] = 0; + mode_list[list_pos++] = 0; + masks_count--; + if (masks_count < 0) + return 0; + break; + } + } + } + + return 0; +} + +static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, + int is_chroma) +{ + int blk; + int i, j, bx, by; + uint8_t *dst, *prev, *ref, *ref_start, *ref_end; + int v, col[2]; + const uint8_t *scan; + int xoff, yoff; + DECLARE_ALIGNED(16, DCTELEM, block[64]); + DECLARE_ALIGNED(16, uint8_t, ublock[64]); + int coordmap[64]; + + const int stride = c->pic.linesize[plane_idx]; + int bw = is_chroma ? (c->avctx->width + 15) >> 4 : (c->avctx->width + 7) >> 3; + int bh = is_chroma ? (c->avctx->height + 15) >> 4 : (c->avctx->height + 7) >> 3; + int width = c->avctx->width >> is_chroma; + + init_lengths(c, FFMAX(width, 8), bw); + 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] + + (bw - 1 + c->last.linesize[plane_idx] * (bh - 1)) * 8; + + for (i = 0; i < 64; i++) + coordmap[i] = (i & 7) + (i >> 3) * stride; + + for (by = 0; by < bh; by++) { + if (read_block_types(c->avctx, gb, &c->bundle[BINK_SRC_BLOCK_TYPES]) < 0) + return -1; + if (read_block_types(c->avctx, gb, &c->bundle[BINK_SRC_SUB_BLOCK_TYPES]) < 0) + return -1; + if (read_colors(gb, &c->bundle[BINK_SRC_COLORS], c) < 0) + return -1; + if (read_patterns(c->avctx, gb, &c->bundle[BINK_SRC_PATTERN]) < 0) + return -1; + if (read_motion_values(c->avctx, gb, &c->bundle[BINK_SRC_X_OFF]) < 0) + return -1; + if (read_motion_values(c->avctx, gb, &c->bundle[BINK_SRC_Y_OFF]) < 0) + return -1; + if (read_dcs(c->avctx, gb, &c->bundle[BINK_SRC_INTRA_DC], DC_START_BITS, 0) < 0) + return -1; + if (read_dcs(c->avctx, gb, &c->bundle[BINK_SRC_INTER_DC], DC_START_BITS, 1) < 0) + return -1; + if (read_runs(c->avctx, gb, &c->bundle[BINK_SRC_RUN]) < 0) + return -1; + + if (by == bh) + break; + dst = c->pic.data[plane_idx] + 8*by*stride; + prev = c->last.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 + if ((by & 1) && blk == SCALED_BLOCK) { + bx++; + dst += 8; + prev += 8; + continue; + } + switch (blk) { + case SKIP_BLOCK: + c->dsp.put_pixels_tab[1][0](dst, prev, stride, 8); + break; + case SCALED_BLOCK: + blk = get_value(c, BINK_SRC_SUB_BLOCK_TYPES); + switch (blk) { + case RUN_BLOCK: + scan = bink_patterns[get_bits(gb, 4)]; + i = 0; + do { + int run = get_value(c, BINK_SRC_RUN) + 1; + + i += run; + if (i > 64) { + av_log(c->avctx, AV_LOG_ERROR, "Run went out of bounds\n"); + return -1; + } + if (get_bits1(gb)) { + v = get_value(c, BINK_SRC_COLORS); + for (j = 0; j < run; j++) + ublock[*scan++] = v; + } else { + for (j = 0; j < run; j++) + ublock[*scan++] = get_value(c, BINK_SRC_COLORS); + } + } while (i < 63); + if (i == 63) + 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, 1); + c->dsp.idct(block); + c->dsp.put_pixels_nonclamped(block, ublock, 8); + break; + case FILL_BLOCK: + v = get_value(c, BINK_SRC_COLORS); + c->dsp.fill_block_tab[0](dst, v, stride, 16); + break; + case PATTERN_BLOCK: + for (i = 0; i < 2; i++) + col[i] = get_value(c, BINK_SRC_COLORS); + for (j = 0; j < 8; j++) { + v = get_value(c, BINK_SRC_PATTERN); + for (i = 0; i < 8; i++, v >>= 1) + ublock[i + j*8] = col[v & 1]; + } + break; + case RAW_BLOCK: + for (j = 0; j < 8; j++) + for (i = 0; i < 8; i++) + ublock[i + j*8] = get_value(c, BINK_SRC_COLORS); + break; + default: + av_log(c->avctx, AV_LOG_ERROR, "Incorrect 16x16 block type %d\n", blk); + return -1; + } + if (blk != FILL_BLOCK) + c->dsp.scale_block(ublock, dst, stride); + bx++; + dst += 8; + prev += 8; + break; + case MOTION_BLOCK: + xoff = get_value(c, BINK_SRC_X_OFF); + yoff = get_value(c, BINK_SRC_Y_OFF); + ref = prev + xoff + yoff * stride; + if (ref < ref_start || ref > ref_end) { + av_log(c->avctx, AV_LOG_ERROR, "Copy out of bounds @%d, %d\n", + bx*8 + xoff, by*8 + yoff); + return -1; + } + c->dsp.put_pixels_tab[1][0](dst, ref, stride, 8); + break; + case RUN_BLOCK: + scan = bink_patterns[get_bits(gb, 4)]; + i = 0; + do { + int run = get_value(c, BINK_SRC_RUN) + 1; + + i += run; + if (i > 64) { + av_log(c->avctx, AV_LOG_ERROR, "Run went out of bounds\n"); + return -1; + } + if (get_bits1(gb)) { + v = get_value(c, BINK_SRC_COLORS); + for (j = 0; j < run; j++) + dst[coordmap[*scan++]] = v; + } else { + for (j = 0; j < run; j++) + dst[coordmap[*scan++]] = get_value(c, BINK_SRC_COLORS); + } + } while (i < 63); + if (i == 63) + dst[coordmap[*scan++]] = get_value(c, BINK_SRC_COLORS); + break; + case RESIDUE_BLOCK: + xoff = get_value(c, BINK_SRC_X_OFF); + yoff = get_value(c, BINK_SRC_Y_OFF); + ref = prev + xoff + yoff * stride; + if (ref < ref_start || ref > ref_end) { + av_log(c->avctx, AV_LOG_ERROR, "Copy out of bounds @%d, %d\n", + bx*8 + xoff, by*8 + yoff); + return -1; + } + c->dsp.put_pixels_tab[1][0](dst, ref, stride, 8); + c->dsp.clear_block(block); + v = get_bits(gb, 7); + read_residue(gb, block, v); + 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, 1); + c->dsp.idct_put(dst, stride, block); + break; + case FILL_BLOCK: + v = get_value(c, BINK_SRC_COLORS); + c->dsp.fill_block_tab[1](dst, v, stride, 8); + break; + case INTER_BLOCK: + xoff = get_value(c, BINK_SRC_X_OFF); + 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, 0); + c->dsp.idct_add(dst, stride, block); + break; + case PATTERN_BLOCK: + for (i = 0; i < 2; i++) + col[i] = get_value(c, BINK_SRC_COLORS); + for (i = 0; i < 8; i++) { + v = get_value(c, BINK_SRC_PATTERN); + for (j = 0; j < 8; j++, v >>= 1) + dst[i*stride + j] = col[v & 1]; + } + break; + case RAW_BLOCK: + for (i = 0; i < 8; i++) + memcpy(dst + i*stride, c->bundle[BINK_SRC_COLORS].cur_ptr + i*8, 8); + c->bundle[BINK_SRC_COLORS].cur_ptr += 64; + break; + default: + av_log(c->avctx, AV_LOG_ERROR, "Unknown block type %d\n", blk); + return -1; + } + } + } + if (get_bits_count(gb) & 0x1F) //next plane data starts at 32-bit boundary + skip_bits_long(gb, 32 - (get_bits_count(gb) & 0x1F)); + + return 0; +} + +static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *pkt) +{ + BinkContext * const c = avctx->priv_data; + GetBitContext gb; + int plane, plane_idx; + int bits_count = pkt->size << 3; + + if(c->pic.data[0]) + avctx->release_buffer(avctx, &c->pic); + + if(avctx->get_buffer(avctx, &c->pic) < 0){ + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } + + init_get_bits(&gb, pkt->data, bits_count); + if (c->has_alpha) { + if (c->version >= 'i') + skip_bits_long(&gb, 32); + if (bink_decode_plane(c, &gb, 3, 0) < 0) + return -1; + } + if (c->version >= 'i') + skip_bits_long(&gb, 32); + + for (plane = 0; plane < 3; plane++) { + plane_idx = (!plane || !c->swap_planes) ? plane : (plane ^ 3); + + if (bink_decode_plane(c, &gb, plane_idx, !!plane) < 0) + return -1; + if (get_bits_count(&gb) >= bits_count) + break; + } + emms_c(); + + *data_size = sizeof(AVFrame); + *(AVFrame*)data = c->pic; + + FFSWAP(AVFrame, c->pic, c->last); + + /* always report that the buffer was completely consumed */ + return pkt->size; +} + +static av_cold int decode_init(AVCodecContext *avctx) +{ + BinkContext * const c = avctx->priv_data; + static VLC_TYPE table[16 * 128][2]; + int i; + int flags; + + c->version = avctx->codec_tag >> 24; + if (c->version < 'c') { + av_log(avctx, AV_LOG_ERROR, "Too old version '%c'\n", c->version); + return -1; + } + if (avctx->extradata_size < 4) { + av_log(avctx, AV_LOG_ERROR, "Extradata missing or too short\n"); + return -1; + } + flags = AV_RL32(avctx->extradata); + c->has_alpha = flags & BINK_FLAG_ALPHA; + c->swap_planes = c->version >= 'h'; + if (!bink_trees[15].table) { + for (i = 0; i < 16; i++) { + const int maxbits = bink_tree_lens[i][15]; + bink_trees[i].table = table + i*128; + bink_trees[i].table_allocated = 1 << maxbits; + init_vlc(&bink_trees[i], maxbits, 16, + bink_tree_lens[i], 1, 1, + bink_tree_bits[i], 1, 1, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE); + } + } + c->avctx = avctx; + + c->pic.data[0] = NULL; + + if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) { + return 1; + } + + avctx->pix_fmt = c->has_alpha ? PIX_FMT_YUVA420P : PIX_FMT_YUV420P; + + avctx->idct_algo = FF_IDCT_BINK; + dsputil_init(&c->dsp, avctx); + ff_init_scantable(c->dsp.idct_permutation, &c->scantable, bink_scan); + + init_bundles(c); + + return 0; +} + +static av_cold int decode_end(AVCodecContext *avctx) +{ + BinkContext * const c = avctx->priv_data; + + if (c->pic.data[0]) + avctx->release_buffer(avctx, &c->pic); + if (c->last.data[0]) + avctx->release_buffer(avctx, &c->last); + + free_bundles(c); + return 0; +} + +AVCodec bink_decoder = { + "binkvideo", + AVMEDIA_TYPE_VIDEO, + CODEC_ID_BINKVIDEO, + sizeof(BinkContext), + decode_init, + NULL, + decode_end, + decode_frame, + .long_name = NULL_IF_CONFIG_SMALL("Bink video"), +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/binkaudio.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/binkaudio.c new file mode 100644 index 0000000000..295b351898 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/binkaudio.c @@ -0,0 +1,311 @@ +/* + * Bink Audio decoder + * Copyright (c) 2007-2010 Peter Ross (pross@xvid.org) + * Copyright (c) 2009 Daniel Verkamp (daniel@drv.nu) + * + * 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 + * Bink Audio decoder + * + * Technical details here: + * http://wiki.multimedia.cx/index.php?title=Bink_Audio + */ + +#include "avcodec.h" +#define ALT_BITSTREAM_READER_LE +#include "get_bits.h" +#include "dsputil.h" +#include "fft.h" + +extern const uint16_t ff_wma_critical_freqs[25]; + +#define MAX_CHANNELS 2 +#define BINK_BLOCK_MAX_SIZE (MAX_CHANNELS << 11) + +typedef struct { + AVCodecContext *avctx; + GetBitContext gb; + DSPContext dsp; + int first; + int channels; + int frame_len; ///< transform size (samples) + int overlap_len; ///< overlap size (samples) + int block_size; + int num_bands; + unsigned int *bands; + float root; + DECLARE_ALIGNED(16, FFTSample, coeffs)[BINK_BLOCK_MAX_SIZE]; + DECLARE_ALIGNED(16, short, previous)[BINK_BLOCK_MAX_SIZE / 16]; ///< coeffs from previous audio block + float *coeffs_ptr[MAX_CHANNELS]; ///< pointers to the coeffs arrays for float_to_int16_interleave + union { + RDFTContext rdft; + DCTContext dct; + } trans; +} BinkAudioContext; + + +static av_cold int decode_init(AVCodecContext *avctx) +{ + BinkAudioContext *s = avctx->priv_data; + int sample_rate = avctx->sample_rate; + int sample_rate_half; + int i; + int frame_len_bits; + + s->avctx = avctx; + dsputil_init(&s->dsp, avctx); + + /* determine frame length */ + if (avctx->sample_rate < 22050) { + frame_len_bits = 9; + } else if (avctx->sample_rate < 44100) { + frame_len_bits = 10; + } else { + frame_len_bits = 11; + } + s->frame_len = 1 << frame_len_bits; + + if (s->channels > MAX_CHANNELS) { + av_log(s->avctx, AV_LOG_ERROR, "too many channels: %d\n", s->channels); + return -1; + } + + if (avctx->codec->id == CODEC_ID_BINKAUDIO_RDFT) { + // audio is already interleaved for the RDFT format variant + sample_rate *= avctx->channels; + s->frame_len *= avctx->channels; + s->channels = 1; + if (avctx->channels == 2) + frame_len_bits++; + } else { + s->channels = avctx->channels; + } + + s->overlap_len = s->frame_len / 16; + s->block_size = (s->frame_len - s->overlap_len) * s->channels; + sample_rate_half = (sample_rate + 1) / 2; + s->root = 2.0 / sqrt(s->frame_len); + + /* calculate number of bands */ + for (s->num_bands = 1; s->num_bands < 25; s->num_bands++) + if (sample_rate_half <= ff_wma_critical_freqs[s->num_bands - 1]) + break; + + s->bands = av_malloc((s->num_bands + 1) * sizeof(*s->bands)); + if (!s->bands) + return AVERROR(ENOMEM); + + /* populate bands data */ + s->bands[0] = 1; + for (i = 1; i < s->num_bands; i++) + s->bands[i] = ff_wma_critical_freqs[i - 1] * (s->frame_len / 2) / sample_rate_half; + s->bands[s->num_bands] = s->frame_len / 2; + + s->first = 1; + avctx->sample_fmt = SAMPLE_FMT_S16; + + for (i = 0; i < s->channels; i++) + s->coeffs_ptr[i] = s->coeffs + i * s->frame_len; + + if (CONFIG_BINKAUDIO_RDFT_DECODER && avctx->codec->id == CODEC_ID_BINKAUDIO_RDFT) + ff_rdft_init(&s->trans.rdft, frame_len_bits, DFT_C2R); + else if (CONFIG_BINKAUDIO_DCT_DECODER) + ff_dct_init(&s->trans.dct, frame_len_bits, DCT_III); + else + return -1; + + return 0; +} + +static float get_float(GetBitContext *gb) +{ + int power = get_bits(gb, 5); + float f = ldexpf(get_bits_long(gb, 23), power - 23); + if (get_bits1(gb)) + f = -f; + return f; +} + +static const uint8_t rle_length_tab[16] = { + 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 32, 64 +}; + +/** + * Decode Bink Audio block + * @param[out] out Output buffer (must contain s->block_size elements) + */ +static void decode_block(BinkAudioContext *s, short *out, int use_dct) +{ + int ch, i, j, k; + float q, quant[25]; + int width, coeff; + GetBitContext *gb = &s->gb; + + if (use_dct) + skip_bits(gb, 2); + + for (ch = 0; ch < s->channels; ch++) { + FFTSample *coeffs = s->coeffs_ptr[ch]; + q = 0.0f; + coeffs[0] = get_float(gb) * s->root; + coeffs[1] = get_float(gb) * s->root; + + for (i = 0; i < s->num_bands; i++) { + /* constant is result of 0.066399999/log10(M_E) */ + int value = get_bits(gb, 8); + quant[i] = expf(FFMIN(value, 95) * 0.15289164787221953823f) * s->root; + } + + // find band (k) + for (k = 0; s->bands[k] < 1; k++) { + q = quant[k]; + } + + // parse coefficients + i = 2; + while (i < s->frame_len) { + if (get_bits1(gb)) { + j = i + rle_length_tab[get_bits(gb, 4)] * 8; + } else { + j = i + 8; + } + + j = FFMIN(j, s->frame_len); + + width = get_bits(gb, 4); + if (width == 0) { + memset(coeffs + i, 0, (j - i) * sizeof(*coeffs)); + i = j; + while (s->bands[k] * 2 < i) + q = quant[k++]; + } else { + while (i < j) { + if (s->bands[k] * 2 == i) + q = quant[k++]; + coeff = get_bits(gb, width); + if (coeff) { + if (get_bits1(gb)) + coeffs[i] = -q * coeff; + else + coeffs[i] = q * coeff; + } else { + coeffs[i] = 0.0f; + } + i++; + } + } + } + + if (CONFIG_BINKAUDIO_DCT_DECODER && use_dct) { + coeffs[0] /= 0.5; + ff_dct_calc (&s->trans.dct, coeffs); + s->dsp.vector_fmul_scalar(coeffs, coeffs, s->frame_len / 2, s->frame_len); + } + else if (CONFIG_BINKAUDIO_RDFT_DECODER) + ff_rdft_calc(&s->trans.rdft, coeffs); + } + + if (s->dsp.float_to_int16_interleave == ff_float_to_int16_interleave_c) { + for (i = 0; i < s->channels; i++) + for (j = 0; j < s->frame_len; j++) + s->coeffs_ptr[i][j] = 385.0 + s->coeffs_ptr[i][j]*(1.0/32767.0); + } + s->dsp.float_to_int16_interleave(out, (const float **)s->coeffs_ptr, s->frame_len, s->channels); + + if (!s->first) { + int count = s->overlap_len * s->channels; + int shift = av_log2(count); + for (i = 0; i < count; i++) { + out[i] = (s->previous[i] * (count - i) + out[i] * i) >> shift; + } + } + + memcpy(s->previous, out + s->block_size, + s->overlap_len * s->channels * sizeof(*out)); + + s->first = 0; +} + +static av_cold int decode_end(AVCodecContext *avctx) +{ + BinkAudioContext * s = avctx->priv_data; + av_freep(&s->bands); + if (CONFIG_BINKAUDIO_RDFT_DECODER && avctx->codec->id == CODEC_ID_BINKAUDIO_RDFT) + ff_rdft_end(&s->trans.rdft); + else if (CONFIG_BINKAUDIO_DCT_DECODER) + ff_dct_end(&s->trans.dct); + return 0; +} + +static void get_bits_align32(GetBitContext *s) +{ + int n = (-get_bits_count(s)) & 31; + if (n) skip_bits(s, n); +} + +static int decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + AVPacket *avpkt) +{ + BinkAudioContext *s = avctx->priv_data; + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + short *samples = data; + short *samples_end = (short*)((uint8_t*)data + *data_size); + int reported_size; + GetBitContext *gb = &s->gb; + + init_get_bits(gb, buf, buf_size * 8); + + reported_size = get_bits_long(gb, 32); + while (get_bits_count(gb) / 8 < buf_size && + samples + s->block_size <= samples_end) { + decode_block(s, samples, avctx->codec->id == CODEC_ID_BINKAUDIO_DCT); + samples += s->block_size; + get_bits_align32(gb); + } + + *data_size = FFMIN(reported_size, (uint8_t*)samples - (uint8_t*)data); + return buf_size; +} + +AVCodec binkaudio_rdft_decoder = { + "binkaudio_rdft", + AVMEDIA_TYPE_AUDIO, + CODEC_ID_BINKAUDIO_RDFT, + sizeof(BinkAudioContext), + decode_init, + NULL, + decode_end, + decode_frame, + .long_name = NULL_IF_CONFIG_SMALL("Bink Audio (RDFT)") +}; + +AVCodec binkaudio_dct_decoder = { + "binkaudio_dct", + AVMEDIA_TYPE_AUDIO, + CODEC_ID_BINKAUDIO_DCT, + sizeof(BinkAudioContext), + decode_init, + NULL, + decode_end, + decode_frame, + .long_name = NULL_IF_CONFIG_SMALL("Bink Audio (DCT)") +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/binkdata.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/binkdata.h new file mode 100644 index 0000000000..1ca34a6843 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/binkdata.h @@ -0,0 +1,614 @@ +/* + * Bink video decoder + * Copyright (C) 2009 Kostya 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 + */ + +#ifndef AVCODEC_BINKDATA_H +#define AVCODEC_BINKDATA_H + +#include + +/** Bink DCT and residue 8x8 block scan order */ +static const uint8_t bink_scan[64] = { + 0, 1, 8, 9, 2, 3, 10, 11, + 4, 5, 12, 13, 6, 7, 14, 15, + 20, 21, 28, 29, 22, 23, 30, 31, + 16, 17, 24, 25, 32, 33, 40, 41, + 34, 35, 42, 43, 48, 49, 56, 57, + 50, 51, 58, 59, 18, 19, 26, 27, + 36, 37, 44, 45, 38, 39, 46, 47, + 52, 53, 60, 61, 54, 55, 62, 63 +}; + +static const uint8_t bink_tree_bits[16][16] = { + { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, + }, + { + 0x00, 0x01, 0x03, 0x05, 0x07, 0x09, 0x0B, 0x0D, + 0x0F, 0x13, 0x15, 0x17, 0x19, 0x1B, 0x1D, 0x1F, + }, + { + 0x00, 0x02, 0x01, 0x09, 0x05, 0x15, 0x0D, 0x1D, + 0x03, 0x13, 0x0B, 0x1B, 0x07, 0x17, 0x0F, 0x1F, + }, + { + 0x00, 0x02, 0x06, 0x01, 0x09, 0x05, 0x0D, 0x1D, + 0x03, 0x13, 0x0B, 0x1B, 0x07, 0x17, 0x0F, 0x1F, + }, + { + 0x00, 0x04, 0x02, 0x06, 0x01, 0x09, 0x05, 0x0D, + 0x03, 0x13, 0x0B, 0x1B, 0x07, 0x17, 0x0F, 0x1F, + }, + { + 0x00, 0x04, 0x02, 0x0A, 0x06, 0x0E, 0x01, 0x09, + 0x05, 0x0D, 0x03, 0x0B, 0x07, 0x17, 0x0F, 0x1F, + }, + { + 0x00, 0x02, 0x0A, 0x06, 0x0E, 0x01, 0x09, 0x05, + 0x0D, 0x03, 0x0B, 0x1B, 0x07, 0x17, 0x0F, 0x1F, + }, + { + 0x00, 0x01, 0x05, 0x03, 0x13, 0x0B, 0x1B, 0x3B, + 0x07, 0x27, 0x17, 0x37, 0x0F, 0x2F, 0x1F, 0x3F, + }, + { + 0x00, 0x01, 0x03, 0x13, 0x0B, 0x2B, 0x1B, 0x3B, + 0x07, 0x27, 0x17, 0x37, 0x0F, 0x2F, 0x1F, 0x3F, + }, + { + 0x00, 0x01, 0x05, 0x0D, 0x03, 0x13, 0x0B, 0x1B, + 0x07, 0x27, 0x17, 0x37, 0x0F, 0x2F, 0x1F, 0x3F, + }, + { + 0x00, 0x02, 0x01, 0x05, 0x0D, 0x03, 0x13, 0x0B, + 0x1B, 0x07, 0x17, 0x37, 0x0F, 0x2F, 0x1F, 0x3F, + }, + { + 0x00, 0x01, 0x09, 0x05, 0x0D, 0x03, 0x13, 0x0B, + 0x1B, 0x07, 0x17, 0x37, 0x0F, 0x2F, 0x1F, 0x3F, + }, + { + 0x00, 0x02, 0x01, 0x03, 0x13, 0x0B, 0x1B, 0x3B, + 0x07, 0x27, 0x17, 0x37, 0x0F, 0x2F, 0x1F, 0x3F, + }, + { + 0x00, 0x01, 0x05, 0x03, 0x07, 0x27, 0x17, 0x37, + 0x0F, 0x4F, 0x2F, 0x6F, 0x1F, 0x5F, 0x3F, 0x7F, + }, + { + 0x00, 0x01, 0x05, 0x03, 0x07, 0x17, 0x37, 0x77, + 0x0F, 0x4F, 0x2F, 0x6F, 0x1F, 0x5F, 0x3F, 0x7F, + }, + { + 0x00, 0x02, 0x01, 0x05, 0x03, 0x07, 0x27, 0x17, + 0x37, 0x0F, 0x2F, 0x6F, 0x1F, 0x5F, 0x3F, 0x7F, + }, +}; + +static const uint8_t bink_tree_lens[16][16] = { + { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 }, + { 1, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 }, + { 2, 2, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 }, + { 2, 3, 3, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 }, + { 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5 }, + { 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5 }, + { 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5 }, + { 1, 3, 3, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6 }, + { 1, 2, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6 }, + { 1, 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6 }, + { 2, 2, 3, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6 }, + { 1, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6 }, + { 2, 2, 2, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6 }, + { 1, 3, 3, 3, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7 }, + { 1, 3, 3, 3, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 }, + { 2, 2, 3, 3, 3, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7 }, +}; + +static const uint8_t bink_patterns[16][64] = { + { + 0x00, 0x08, 0x10, 0x18, 0x20, 0x28, 0x30, 0x38, + 0x39, 0x31, 0x29, 0x21, 0x19, 0x11, 0x09, 0x01, + 0x02, 0x0A, 0x12, 0x1A, 0x22, 0x2A, 0x32, 0x3A, + 0x3B, 0x33, 0x2B, 0x23, 0x1B, 0x13, 0x0B, 0x03, + 0x04, 0x0C, 0x14, 0x1C, 0x24, 0x2C, 0x34, 0x3C, + 0x3D, 0x35, 0x2D, 0x25, 0x1D, 0x15, 0x0D, 0x05, + 0x06, 0x0E, 0x16, 0x1E, 0x26, 0x2E, 0x36, 0x3E, + 0x3F, 0x37, 0x2F, 0x27, 0x1F, 0x17, 0x0F, 0x07, + }, + { + 0x3B, 0x3A, 0x39, 0x38, 0x30, 0x31, 0x32, 0x33, + 0x2B, 0x2A, 0x29, 0x28, 0x20, 0x21, 0x22, 0x23, + 0x1B, 0x1A, 0x19, 0x18, 0x10, 0x11, 0x12, 0x13, + 0x0B, 0x0A, 0x09, 0x08, 0x00, 0x01, 0x02, 0x03, + 0x04, 0x05, 0x06, 0x07, 0x0F, 0x0E, 0x0D, 0x0C, + 0x14, 0x15, 0x16, 0x17, 0x1F, 0x1E, 0x1D, 0x1C, + 0x24, 0x25, 0x26, 0x27, 0x2F, 0x2E, 0x2D, 0x2C, + 0x34, 0x35, 0x36, 0x37, 0x3F, 0x3E, 0x3D, 0x3C, + }, + { + 0x19, 0x11, 0x12, 0x1A, 0x1B, 0x13, 0x0B, 0x03, + 0x02, 0x0A, 0x09, 0x01, 0x00, 0x08, 0x10, 0x18, + 0x20, 0x28, 0x30, 0x38, 0x39, 0x31, 0x29, 0x2A, + 0x32, 0x3A, 0x3B, 0x33, 0x2B, 0x23, 0x22, 0x21, + 0x1D, 0x15, 0x16, 0x1E, 0x1F, 0x17, 0x0F, 0x07, + 0x06, 0x0E, 0x0D, 0x05, 0x04, 0x0C, 0x14, 0x1C, + 0x24, 0x2C, 0x34, 0x3C, 0x3D, 0x35, 0x2D, 0x2E, + 0x36, 0x3E, 0x3F, 0x37, 0x2F, 0x27, 0x26, 0x25, + }, + { + 0x03, 0x0B, 0x02, 0x0A, 0x01, 0x09, 0x00, 0x08, + 0x10, 0x18, 0x11, 0x19, 0x12, 0x1A, 0x13, 0x1B, + 0x23, 0x2B, 0x22, 0x2A, 0x21, 0x29, 0x20, 0x28, + 0x30, 0x38, 0x31, 0x39, 0x32, 0x3A, 0x33, 0x3B, + 0x3C, 0x34, 0x3D, 0x35, 0x3E, 0x36, 0x3F, 0x37, + 0x2F, 0x27, 0x2E, 0x26, 0x2D, 0x25, 0x2C, 0x24, + 0x1C, 0x14, 0x1D, 0x15, 0x1E, 0x16, 0x1F, 0x17, + 0x0F, 0x07, 0x0E, 0x06, 0x0D, 0x05, 0x0C, 0x04, + }, + { + 0x18, 0x19, 0x10, 0x11, 0x08, 0x09, 0x00, 0x01, + 0x02, 0x03, 0x0A, 0x0B, 0x12, 0x13, 0x1A, 0x1B, + 0x1C, 0x1D, 0x14, 0x15, 0x0C, 0x0D, 0x04, 0x05, + 0x06, 0x07, 0x0E, 0x0F, 0x16, 0x17, 0x1E, 0x1F, + 0x27, 0x26, 0x2F, 0x2E, 0x37, 0x36, 0x3F, 0x3E, + 0x3D, 0x3C, 0x35, 0x34, 0x2D, 0x2C, 0x25, 0x24, + 0x23, 0x22, 0x2B, 0x2A, 0x33, 0x32, 0x3B, 0x3A, + 0x39, 0x38, 0x31, 0x30, 0x29, 0x28, 0x21, 0x20, + }, + { + 0x00, 0x01, 0x02, 0x03, 0x08, 0x09, 0x0A, 0x0B, + 0x10, 0x11, 0x12, 0x13, 0x18, 0x19, 0x1A, 0x1B, + 0x20, 0x21, 0x22, 0x23, 0x28, 0x29, 0x2A, 0x2B, + 0x30, 0x31, 0x32, 0x33, 0x38, 0x39, 0x3A, 0x3B, + 0x04, 0x05, 0x06, 0x07, 0x0C, 0x0D, 0x0E, 0x0F, + 0x14, 0x15, 0x16, 0x17, 0x1C, 0x1D, 0x1E, 0x1F, + 0x24, 0x25, 0x26, 0x27, 0x2C, 0x2D, 0x2E, 0x2F, + 0x34, 0x35, 0x36, 0x37, 0x3C, 0x3D, 0x3E, 0x3F, + }, + { + 0x06, 0x07, 0x0F, 0x0E, 0x0D, 0x05, 0x0C, 0x04, + 0x03, 0x0B, 0x02, 0x0A, 0x09, 0x01, 0x00, 0x08, + 0x10, 0x18, 0x11, 0x19, 0x12, 0x1A, 0x13, 0x1B, + 0x14, 0x1C, 0x15, 0x1D, 0x16, 0x1E, 0x17, 0x1F, + 0x27, 0x2F, 0x26, 0x2E, 0x25, 0x2D, 0x24, 0x2C, + 0x23, 0x2B, 0x22, 0x2A, 0x21, 0x29, 0x20, 0x28, + 0x31, 0x30, 0x38, 0x39, 0x3A, 0x32, 0x3B, 0x33, + 0x3C, 0x34, 0x3D, 0x35, 0x36, 0x37, 0x3F, 0x3E, + }, + { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x1F, 0x1E, 0x1D, 0x1C, 0x1B, 0x1A, 0x19, 0x18, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, + 0x2F, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29, 0x28, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, + 0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38, + }, + { + 0x00, 0x08, 0x09, 0x01, 0x02, 0x03, 0x0B, 0x0A, + 0x12, 0x13, 0x1B, 0x1A, 0x19, 0x11, 0x10, 0x18, + 0x20, 0x28, 0x29, 0x21, 0x22, 0x23, 0x2B, 0x2A, + 0x32, 0x31, 0x30, 0x38, 0x39, 0x3A, 0x3B, 0x33, + 0x34, 0x3C, 0x3D, 0x3E, 0x3F, 0x37, 0x36, 0x35, + 0x2D, 0x2C, 0x24, 0x25, 0x26, 0x2E, 0x2F, 0x27, + 0x1F, 0x17, 0x16, 0x1E, 0x1D, 0x1C, 0x14, 0x15, + 0x0D, 0x0C, 0x04, 0x05, 0x06, 0x0E, 0x0F, 0x07, + }, + { + 0x18, 0x19, 0x10, 0x11, 0x08, 0x09, 0x00, 0x01, + 0x02, 0x03, 0x0A, 0x0B, 0x12, 0x13, 0x1A, 0x1B, + 0x1C, 0x1D, 0x14, 0x15, 0x0C, 0x0D, 0x04, 0x05, + 0x06, 0x07, 0x0E, 0x0F, 0x16, 0x17, 0x1E, 0x1F, + 0x26, 0x27, 0x2E, 0x2F, 0x36, 0x37, 0x3E, 0x3F, + 0x3C, 0x3D, 0x34, 0x35, 0x2C, 0x2D, 0x24, 0x25, + 0x22, 0x23, 0x2A, 0x2B, 0x32, 0x33, 0x3A, 0x3B, + 0x38, 0x39, 0x30, 0x31, 0x28, 0x29, 0x20, 0x21, + }, + { + 0x00, 0x08, 0x01, 0x09, 0x02, 0x0A, 0x03, 0x0B, + 0x13, 0x1B, 0x12, 0x1A, 0x11, 0x19, 0x10, 0x18, + 0x20, 0x28, 0x21, 0x29, 0x22, 0x2A, 0x23, 0x2B, + 0x33, 0x3B, 0x32, 0x3A, 0x31, 0x39, 0x30, 0x38, + 0x3C, 0x34, 0x3D, 0x35, 0x3E, 0x36, 0x3F, 0x37, + 0x2F, 0x27, 0x2E, 0x26, 0x2D, 0x25, 0x2C, 0x24, + 0x1F, 0x17, 0x1E, 0x16, 0x1D, 0x15, 0x1C, 0x14, + 0x0C, 0x04, 0x0D, 0x05, 0x0E, 0x06, 0x0F, 0x07, + }, + { + 0x00, 0x08, 0x10, 0x18, 0x19, 0x1A, 0x1B, 0x13, + 0x0B, 0x03, 0x02, 0x01, 0x09, 0x11, 0x12, 0x0A, + 0x04, 0x0C, 0x14, 0x1C, 0x1D, 0x1E, 0x1F, 0x17, + 0x0F, 0x07, 0x06, 0x05, 0x0D, 0x15, 0x16, 0x0E, + 0x24, 0x2C, 0x34, 0x3C, 0x3D, 0x3E, 0x3F, 0x37, + 0x2F, 0x27, 0x26, 0x25, 0x2D, 0x35, 0x36, 0x2E, + 0x20, 0x28, 0x30, 0x38, 0x39, 0x3A, 0x3B, 0x33, + 0x2B, 0x23, 0x22, 0x21, 0x29, 0x31, 0x32, 0x2A, + }, + { + 0x00, 0x08, 0x09, 0x01, 0x02, 0x03, 0x0B, 0x0A, + 0x13, 0x1B, 0x1A, 0x12, 0x11, 0x10, 0x18, 0x19, + 0x21, 0x20, 0x28, 0x29, 0x2A, 0x22, 0x23, 0x2B, + 0x33, 0x3B, 0x3A, 0x32, 0x31, 0x39, 0x38, 0x30, + 0x34, 0x3C, 0x3D, 0x35, 0x36, 0x3E, 0x3F, 0x37, + 0x2F, 0x27, 0x26, 0x2E, 0x2D, 0x2C, 0x24, 0x25, + 0x1D, 0x1C, 0x14, 0x15, 0x16, 0x1E, 0x1F, 0x17, + 0x0E, 0x0F, 0x07, 0x06, 0x05, 0x0D, 0x0C, 0x04, + }, + { + 0x18, 0x10, 0x08, 0x00, 0x01, 0x02, 0x03, 0x0B, + 0x13, 0x1B, 0x1A, 0x19, 0x11, 0x0A, 0x09, 0x12, + 0x1C, 0x14, 0x0C, 0x04, 0x05, 0x06, 0x07, 0x0F, + 0x17, 0x1F, 0x1E, 0x1D, 0x15, 0x0E, 0x0D, 0x16, + 0x3C, 0x34, 0x2C, 0x24, 0x25, 0x26, 0x27, 0x2F, + 0x37, 0x3F, 0x3E, 0x3D, 0x35, 0x2E, 0x2D, 0x36, + 0x38, 0x30, 0x28, 0x20, 0x21, 0x22, 0x23, 0x2B, + 0x33, 0x3B, 0x3A, 0x39, 0x31, 0x2A, 0x29, 0x32, + }, + { + 0x00, 0x08, 0x09, 0x01, 0x02, 0x0A, 0x12, 0x11, + 0x10, 0x18, 0x19, 0x1A, 0x1B, 0x13, 0x0B, 0x03, + 0x07, 0x06, 0x0E, 0x0F, 0x17, 0x16, 0x15, 0x0D, + 0x05, 0x04, 0x0C, 0x14, 0x1C, 0x1D, 0x1E, 0x1F, + 0x3F, 0x3E, 0x36, 0x37, 0x2F, 0x2E, 0x2D, 0x35, + 0x3D, 0x3C, 0x34, 0x2C, 0x24, 0x25, 0x26, 0x27, + 0x38, 0x30, 0x31, 0x39, 0x3A, 0x32, 0x2A, 0x29, + 0x28, 0x20, 0x21, 0x22, 0x23, 0x2B, 0x33, 0x3B, + }, + { + 0x00, 0x01, 0x08, 0x09, 0x10, 0x11, 0x18, 0x19, + 0x20, 0x21, 0x28, 0x29, 0x30, 0x31, 0x38, 0x39, + 0x3A, 0x3B, 0x32, 0x33, 0x2A, 0x2B, 0x22, 0x23, + 0x1A, 0x1B, 0x12, 0x13, 0x0A, 0x0B, 0x02, 0x03, + 0x04, 0x05, 0x0C, 0x0D, 0x14, 0x15, 0x1C, 0x1D, + 0x24, 0x25, 0x2C, 0x2D, 0x34, 0x35, 0x3C, 0x3D, + 0x3E, 0x3F, 0x36, 0x37, 0x2E, 0x2F, 0x26, 0x27, + 0x1E, 0x1F, 0x16, 0x17, 0x0E, 0x0F, 0x06, 0x07, + } +}; + +static const uint32_t bink_intra_quant[16][64] = { +{ + 0x010000, 0x016315, 0x01E83D, 0x02A535, 0x014E7B, 0x016577, 0x02F1E6, 0x02724C, + 0x010000, 0x00EEDA, 0x024102, 0x017F9B, 0x00BE80, 0x00611E, 0x01083C, 0x00A552, + 0x021F88, 0x01DC53, 0x027FAD, 0x01F697, 0x014819, 0x00A743, 0x015A31, 0x009688, + 0x02346F, 0x030EE5, 0x01FBFA, 0x02C096, 0x01D000, 0x028396, 0x019247, 0x01F9AA, + 0x02346F, 0x01FBFA, 0x01DC53, 0x0231B8, 0x012F12, 0x01E06C, 0x00CB10, 0x0119A8, + 0x01C48C, 0x019748, 0x014E86, 0x0122AF, 0x02C628, 0x027F20, 0x0297B5, 0x023F32, + 0x025000, 0x01AB6B, 0x01D122, 0x0159B3, 0x012669, 0x008D43, 0x00EE1F, 0x0075ED, + 0x01490C, 0x010288, 0x00F735, 0x00EF51, 0x00E0F1, 0x0072AD, 0x00A4D8, 0x006517, +}, +{ + 0x015555, 0x01D971, 0x028AFC, 0x0386F1, 0x01BDF9, 0x01DC9F, 0x03ED33, 0x034311, + 0x015555, 0x013E78, 0x030158, 0x01FF7A, 0x00FE00, 0x00817D, 0x01604F, 0x00DC6D, + 0x02D4B5, 0x027B19, 0x0354E7, 0x029E1F, 0x01B577, 0x00DF04, 0x01CD96, 0x00C8B6, + 0x02F095, 0x0413DC, 0x02A54E, 0x03AB73, 0x026AAB, 0x035A1E, 0x02185E, 0x02A238, + 0x02F095, 0x02A54E, 0x027B19, 0x02ECF5, 0x019418, 0x028090, 0x010EC0, 0x01778A, + 0x025B66, 0x021F0B, 0x01BE09, 0x018394, 0x03B2E0, 0x03542A, 0x0374F1, 0x02FEEE, + 0x031555, 0x0239E4, 0x026C2D, 0x01CCEE, 0x01888C, 0x00BC59, 0x013D7E, 0x009D3C, + 0x01B6BB, 0x0158B5, 0x01499C, 0x013F17, 0x012BEC, 0x0098E6, 0x00DBCB, 0x0086C9, +}, +{ + 0x01AAAB, 0x024FCE, 0x032DBB, 0x0468AD, 0x022D78, 0x0253C7, 0x04E87F, 0x0413D5, + 0x01AAAB, 0x018E16, 0x03C1AE, 0x027F58, 0x013D80, 0x00A1DC, 0x01B863, 0x011388, + 0x0389E2, 0x0319DF, 0x042A21, 0x0345A7, 0x0222D4, 0x0116C5, 0x0240FC, 0x00FAE3, + 0x03ACBA, 0x0518D3, 0x034EA1, 0x04964F, 0x030555, 0x0430A5, 0x029E76, 0x034AC5, + 0x03ACBA, 0x034EA1, 0x0319DF, 0x03A833, 0x01F91E, 0x0320B4, 0x015270, 0x01D56D, + 0x02F23F, 0x02A6CE, 0x022D8B, 0x01E479, 0x049F98, 0x042935, 0x04522D, 0x03BEA9, + 0x03DAAB, 0x02C85D, 0x030738, 0x02402A, 0x01EAAF, 0x00EB6F, 0x018CDE, 0x00C48A, + 0x022469, 0x01AEE2, 0x019C02, 0x018EDD, 0x0176E7, 0x00BF20, 0x0112BE, 0x00A87B, +}, +{ + 0x020000, 0x02C62A, 0x03D07A, 0x054A69, 0x029CF6, 0x02CAEF, 0x05E3CC, 0x04E499, + 0x020000, 0x01DDB4, 0x048204, 0x02FF36, 0x017D01, 0x00C23C, 0x021077, 0x014AA3, + 0x043F0F, 0x03B8A6, 0x04FF5A, 0x03ED2E, 0x029032, 0x014E86, 0x02B461, 0x012D11, + 0x0468DF, 0x061DCA, 0x03F7F5, 0x05812C, 0x03A000, 0x05072C, 0x03248D, 0x03F353, + 0x0468DF, 0x03F7F5, 0x03B8A6, 0x046370, 0x025E24, 0x03C0D8, 0x019620, 0x02334F, + 0x038919, 0x032E91, 0x029D0D, 0x02455E, 0x058C50, 0x04FE3F, 0x052F69, 0x047E65, + 0x04A000, 0x0356D6, 0x03A243, 0x02B365, 0x024CD2, 0x011A85, 0x01DC3E, 0x00EBD9, + 0x029218, 0x020510, 0x01EE69, 0x01DEA2, 0x01C1E2, 0x00E559, 0x0149B0, 0x00CA2D, +}, +{ + 0x02AAAB, 0x03B2E3, 0x0515F8, 0x070DE2, 0x037BF2, 0x03B93E, 0x07DA65, 0x068621, + 0x02AAAB, 0x027CF0, 0x0602B1, 0x03FEF3, 0x01FC01, 0x0102FA, 0x02C09F, 0x01B8DA, + 0x05A96A, 0x04F632, 0x06A9CE, 0x053C3E, 0x036AED, 0x01BE09, 0x039B2D, 0x01916B, + 0x05E129, 0x0827B8, 0x054A9C, 0x0756E5, 0x04D555, 0x06B43B, 0x0430BC, 0x05446F, + 0x05E129, 0x054A9C, 0x04F632, 0x05D9EB, 0x032830, 0x050121, 0x021D80, 0x02EF14, + 0x04B6CC, 0x043E16, 0x037C11, 0x030728, 0x0765C0, 0x06A855, 0x06E9E2, 0x05FDDB, + 0x062AAB, 0x0473C8, 0x04D85A, 0x0399DC, 0x031118, 0x0178B2, 0x027AFD, 0x013A77, + 0x036D76, 0x02B16A, 0x029337, 0x027E2E, 0x0257D8, 0x0131CC, 0x01B796, 0x010D91, +}, +{ + 0x038000, 0x04DACA, 0x06ACD5, 0x094238, 0x0492AE, 0x04E322, 0x0A4EA5, 0x08900C, + 0x038000, 0x0343FB, 0x07E388, 0x053E9F, 0x029AC1, 0x0153E8, 0x039CD0, 0x02429E, + 0x076E5B, 0x068322, 0x08BEDE, 0x06DF11, 0x047C57, 0x02496B, 0x04BBAB, 0x020EDD, + 0x07B786, 0x0AB421, 0x06F1ED, 0x09A20D, 0x065800, 0x08CC8E, 0x057FF7, 0x06E9D2, + 0x07B786, 0x06F1ED, 0x068322, 0x07AE04, 0x0424BF, 0x06917B, 0x02C6B8, 0x03D9CB, + 0x062FEB, 0x05917D, 0x0492D7, 0x03F964, 0x09B58C, 0x08BCEF, 0x0912F8, 0x07DD30, + 0x081800, 0x05D7F7, 0x065BF6, 0x04B9F1, 0x040670, 0x01EE69, 0x03416C, 0x019CBC, + 0x047FAA, 0x0388DC, 0x036138, 0x03459C, 0x03134C, 0x01915C, 0x0240F5, 0x0161CF, +}, +{ + 0x040000, 0x058C54, 0x07A0F4, 0x0A94D3, 0x0539EC, 0x0595DD, 0x0BC798, 0x09C932, + 0x040000, 0x03BB68, 0x090409, 0x05FE6D, 0x02FA01, 0x018477, 0x0420EE, 0x029547, + 0x087E1F, 0x07714C, 0x09FEB5, 0x07DA5D, 0x052064, 0x029D0D, 0x0568C3, 0x025A21, + 0x08D1BE, 0x0C3B94, 0x07EFEA, 0x0B0258, 0x074000, 0x0A0E59, 0x06491A, 0x07E6A7, + 0x08D1BE, 0x07EFEA, 0x07714C, 0x08C6E0, 0x04BC48, 0x0781B1, 0x032C3F, 0x04669F, + 0x071232, 0x065D22, 0x053A1A, 0x048ABC, 0x0B18A0, 0x09FC7F, 0x0A5ED3, 0x08FCC9, + 0x094000, 0x06ADAC, 0x074487, 0x0566CA, 0x0499A5, 0x02350B, 0x03B87B, 0x01D7B3, + 0x052430, 0x040A20, 0x03DCD3, 0x03BD45, 0x0383C5, 0x01CAB3, 0x029361, 0x01945A, +}, +{ + 0x050000, 0x06EF69, 0x098931, 0x0D3A07, 0x068867, 0x06FB55, 0x0EB97E, 0x0C3B7E, + 0x050000, 0x04AA42, 0x0B450B, 0x077E08, 0x03B881, 0x01E595, 0x05292A, 0x033A99, + 0x0A9DA7, 0x094D9F, 0x0C7E62, 0x09D0F4, 0x06687D, 0x034450, 0x06C2F4, 0x02F0AA, + 0x0B062D, 0x0F4A78, 0x09EBE4, 0x0DC2EE, 0x091000, 0x0C91EF, 0x07DB61, 0x09E050, + 0x0B062D, 0x09EBE4, 0x094D9F, 0x0AF898, 0x05EB59, 0x09621D, 0x03F74F, 0x058046, + 0x08D6BE, 0x07F46A, 0x0688A0, 0x05AD6B, 0x0DDEC8, 0x0C7B9F, 0x0CF687, 0x0B3BFB, + 0x0B9000, 0x085917, 0x0915A8, 0x06C07D, 0x05C00E, 0x02C24D, 0x04A69A, 0x024D9F, + 0x066D3C, 0x050CA7, 0x04D407, 0x04AC96, 0x0464B6, 0x023D5F, 0x033839, 0x01F971, +}, +{ + 0x060000, 0x08527E, 0x0B716E, 0x0FDF3C, 0x07D6E1, 0x0860CC, 0x11AB63, 0x0EADCB, + 0x060000, 0x05991C, 0x0D860D, 0x08FDA3, 0x047702, 0x0246B3, 0x063165, 0x03DFEA, + 0x0CBD2E, 0x0B29F1, 0x0EFE0F, 0x0BC78B, 0x07B096, 0x03EB93, 0x081D24, 0x038732, + 0x0D3A9C, 0x12595D, 0x0BE7DF, 0x108384, 0x0AE000, 0x0F1585, 0x096DA8, 0x0BD9FA, + 0x0D3A9C, 0x0BE7DF, 0x0B29F1, 0x0D2A50, 0x071A6B, 0x0B4289, 0x04C25F, 0x0699EE, + 0x0A9B4A, 0x098BB2, 0x07D727, 0x06D01A, 0x10A4F0, 0x0EFABE, 0x0F8E3C, 0x0D7B2E, + 0x0DE000, 0x0A0482, 0x0AE6CA, 0x081A2F, 0x06E677, 0x034F90, 0x0594B9, 0x02C38C, + 0x07B649, 0x060F2F, 0x05CB3C, 0x059BE7, 0x0545A7, 0x02B00C, 0x03DD11, 0x025E87, +}, +{ + 0x080000, 0x0B18A8, 0x0F41E8, 0x1529A5, 0x0A73D7, 0x0B2BBB, 0x178F2F, 0x139264, + 0x080000, 0x0776CF, 0x120812, 0x0BFCD9, 0x05F402, 0x0308EF, 0x0841DC, 0x052A8E, + 0x10FC3E, 0x0EE297, 0x13FD69, 0x0FB4B9, 0x0A40C8, 0x053A1A, 0x0AD186, 0x04B442, + 0x11A37B, 0x187727, 0x0FDFD4, 0x1604B0, 0x0E8000, 0x141CB1, 0x0C9235, 0x0FCD4D, + 0x11A37B, 0x0FDFD4, 0x0EE297, 0x118DC0, 0x09788F, 0x0F0362, 0x06587F, 0x08CD3D, + 0x0E2463, 0x0CBA43, 0x0A7434, 0x091577, 0x163140, 0x13F8FE, 0x14BDA5, 0x11F992, + 0x128000, 0x0D5B58, 0x0E890D, 0x0ACD94, 0x093349, 0x046A15, 0x0770F7, 0x03AF65, + 0x0A4861, 0x08143F, 0x07B9A6, 0x077A89, 0x070789, 0x039565, 0x0526C2, 0x0328B4, +}, +{ + 0x0C0000, 0x10A4FD, 0x16E2DB, 0x1FBE78, 0x0FADC3, 0x10C198, 0x2356C7, 0x1D5B96, + 0x0C0000, 0x0B3237, 0x1B0C1A, 0x11FB46, 0x08EE03, 0x048D66, 0x0C62CA, 0x07BFD5, + 0x197A5D, 0x1653E3, 0x1DFC1E, 0x178F16, 0x0F612C, 0x07D727, 0x103A49, 0x070E64, + 0x1A7539, 0x24B2BB, 0x17CFBD, 0x210709, 0x15C000, 0x1E2B0A, 0x12DB4F, 0x17B3F4, + 0x1A7539, 0x17CFBD, 0x1653E3, 0x1A54A0, 0x0E34D7, 0x168513, 0x0984BE, 0x0D33DC, + 0x153695, 0x131765, 0x0FAE4E, 0x0DA033, 0x2149E1, 0x1DF57D, 0x1F1C78, 0x1AF65B, + 0x1BC000, 0x140904, 0x15CD94, 0x10345E, 0x0DCCEE, 0x069F20, 0x0B2972, 0x058718, + 0x0F6C91, 0x0C1E5E, 0x0B9678, 0x0B37CE, 0x0A8B4E, 0x056018, 0x07BA22, 0x04BD0E, +}, +{ + 0x110000, 0x179466, 0x206C0C, 0x2CF87F, 0x16362A, 0x17BCED, 0x321044, 0x299714, + 0x110000, 0x0FDC79, 0x265125, 0x19794E, 0x0CA685, 0x0672FB, 0x118BF4, 0x0AFA6D, + 0x241804, 0x1FA181, 0x2A7A80, 0x21600A, 0x15C9A9, 0x0B1B77, 0x16FD3C, 0x09FF0D, + 0x257B66, 0x33FD33, 0x21BBA2, 0x2EC9F7, 0x1ED000, 0x2ABCF9, 0x1AB6B0, 0x219444, + 0x257B66, 0x21BBA2, 0x1FA181, 0x254D38, 0x142030, 0x1FE730, 0x0D7C0E, 0x12B423, + 0x1E0D52, 0x1B0BCF, 0x1636EE, 0x134D9E, 0x2F28A9, 0x2A711B, 0x2C12FF, 0x263256, + 0x275000, 0x1C621B, 0x1EE33C, 0x16F4DB, 0x138CFB, 0x09616E, 0x0FD00C, 0x07D4B7, + 0x15D9CE, 0x112B06, 0x106A80, 0x0FE464, 0x0EF004, 0x079D77, 0x0AF25B, 0x06B67F, +}, +{ + 0x160000, 0x1E83CF, 0x29F53D, 0x3A3286, 0x1CBE90, 0x1EB842, 0x40C9C2, 0x35D293, + 0x160000, 0x1486BA, 0x319630, 0x20F756, 0x105F06, 0x085891, 0x16B51E, 0x0E3506, + 0x2EB5AA, 0x28EF20, 0x36F8E1, 0x2B30FE, 0x1C3225, 0x0E5FC7, 0x1DC030, 0x0CEFB7, + 0x308193, 0x4347AC, 0x2BA786, 0x3C8CE5, 0x27E000, 0x374EE7, 0x229212, 0x2B7494, + 0x308193, 0x2BA786, 0x28EF20, 0x3045D0, 0x1A0B89, 0x29494D, 0x11735D, 0x183469, + 0x26E410, 0x230039, 0x1CBF8F, 0x18FB09, 0x3D0771, 0x36ECBA, 0x390986, 0x316E52, + 0x32E000, 0x24BB33, 0x27F8E4, 0x1DB557, 0x194D09, 0x0C23BB, 0x1476A6, 0x0A2256, + 0x1C470A, 0x1637AD, 0x153E87, 0x1490FA, 0x1354B9, 0x09DAD6, 0x0E2A94, 0x08AFF0, +}, +{ + 0x1C0000, 0x26D64D, 0x3566AA, 0x4A11C2, 0x249572, 0x27190E, 0x527525, 0x44805E, + 0x1C0000, 0x1A1FD6, 0x3F1C3E, 0x29F4F9, 0x14D607, 0x0A9F44, 0x1CE683, 0x1214F0, + 0x3B72D9, 0x341911, 0x45F6F0, 0x36F889, 0x23E2BB, 0x124B5B, 0x25DD54, 0x1076E9, + 0x3DBC30, 0x55A109, 0x378F64, 0x4D1069, 0x32C000, 0x46646C, 0x2BFFB9, 0x374E8E, + 0x3DBC30, 0x378F64, 0x341911, 0x3D7020, 0x2125F5, 0x348BD6, 0x1635BC, 0x1ECE57, + 0x317F5B, 0x2C8BEB, 0x2496B6, 0x1FCB22, 0x4DAC61, 0x45E778, 0x4897C2, 0x3EE97F, + 0x40C000, 0x2EBFB5, 0x32DFAE, 0x25CF86, 0x203380, 0x0F734B, 0x1A0B5F, 0x0CE5E2, + 0x23FD53, 0x1C46DC, 0x1B09C4, 0x1A2CE1, 0x189A60, 0x0C8AE2, 0x1207A5, 0x0B0E77, +}, +{ + 0x220000, 0x2F28CC, 0x40D818, 0x59F0FE, 0x2C6C53, 0x2F79DA, 0x642089, 0x532E29, + 0x220000, 0x1FB8F1, 0x4CA24B, 0x32F29C, 0x194D09, 0x0CE5F7, 0x2317E8, 0x15F4DB, + 0x483007, 0x3F4303, 0x54F4FF, 0x42C014, 0x2B9351, 0x1636EE, 0x2DFA79, 0x13FE1A, + 0x4AF6CC, 0x67FA67, 0x437743, 0x5D93EE, 0x3DA000, 0x5579F1, 0x356D61, 0x432888, + 0x4AF6CC, 0x437743, 0x3F4303, 0x4A9A70, 0x284060, 0x3FCE60, 0x1AF81B, 0x256845, + 0x3C1AA5, 0x36179D, 0x2C6DDD, 0x269B3C, 0x5E5152, 0x54E237, 0x5825FE, 0x4C64AD, + 0x4EA000, 0x38C437, 0x3DC678, 0x2DE9B5, 0x2719F7, 0x12C2DB, 0x1FA018, 0x0FA96E, + 0x2BB39B, 0x22560C, 0x20D500, 0x1FC8C8, 0x1DE007, 0x0F3AEE, 0x15E4B7, 0x0D6CFE, +}, +{ + 0x2C0000, 0x3D079E, 0x53EA79, 0x74650C, 0x397D20, 0x3D7083, 0x819383, 0x6BA525, + 0x2C0000, 0x290D75, 0x632C61, 0x41EEAC, 0x20BE0C, 0x10B121, 0x2D6A3B, 0x1C6A0C, + 0x5D6B54, 0x51DE40, 0x6DF1C2, 0x5661FB, 0x38644B, 0x1CBF8F, 0x3B8060, 0x19DF6D, + 0x610326, 0x868F57, 0x574F0B, 0x7919CA, 0x4FC000, 0x6E9DCE, 0x452423, 0x56E928, + 0x610326, 0x574F0B, 0x51DE40, 0x608BA0, 0x341713, 0x52929A, 0x22E6BA, 0x3068D2, + 0x4DC821, 0x460071, 0x397F1E, 0x31F611, 0x7A0EE2, 0x6DD974, 0x72130C, 0x62DCA3, + 0x65C000, 0x497665, 0x4FF1C9, 0x3B6AAE, 0x329A12, 0x184776, 0x28ED4D, 0x1444AC, + 0x388E14, 0x2C6F5A, 0x2A7D0F, 0x2921F4, 0x26A973, 0x13B5AD, 0x1C5528, 0x115FDF, +}, +}; + +static const uint32_t bink_inter_quant[16][64] = { +{ + 0x010000, 0x017946, 0x01A5A9, 0x0248DC, 0x016363, 0x0152A7, 0x0243EC, 0x0209EA, + 0x012000, 0x00E248, 0x01BBDA, 0x015CBC, 0x00A486, 0x0053E0, 0x00F036, 0x008095, + 0x01B701, 0x016959, 0x01B0B9, 0x0153FD, 0x00F8E7, 0x007EE4, 0x00EA30, 0x007763, + 0x01B701, 0x0260EB, 0x019DE9, 0x023E1B, 0x017000, 0x01FE6E, 0x012DB5, 0x01A27B, + 0x01E0D1, 0x01B0B9, 0x018A33, 0x01718D, 0x00D87A, 0x014449, 0x007B9A, 0x00AB71, + 0x013178, 0x0112EA, 0x00AD08, 0x009BB9, 0x023D97, 0x020437, 0x021CCC, 0x01E6B4, + 0x018000, 0x012DB5, 0x0146D9, 0x0100CE, 0x00CFD2, 0x006E5C, 0x00B0E4, 0x005A2D, + 0x00E9CC, 0x00B7B1, 0x00846F, 0x006B85, 0x008337, 0x0042E5, 0x004A10, 0x002831, +}, +{ + 0x015555, 0x01F708, 0x023237, 0x030BD0, 0x01D9D9, 0x01C389, 0x03053B, 0x02B7E3, + 0x018000, 0x012DB5, 0x024FCE, 0x01D0FA, 0x00DB5D, 0x006FD5, 0x014048, 0x00AB71, + 0x024957, 0x01E1CC, 0x0240F7, 0x01C551, 0x014BDE, 0x00A92F, 0x013840, 0x009F2F, + 0x024957, 0x032BE4, 0x0227E1, 0x02FD7A, 0x01EAAB, 0x02A893, 0x019247, 0x022DF9, + 0x028116, 0x0240F7, 0x020D99, 0x01ECBC, 0x0120A3, 0x01B061, 0x00A4CE, 0x00E497, + 0x01974B, 0x016E8E, 0x00E6B5, 0x00CFA2, 0x02FCC9, 0x02B04A, 0x02D110, 0x0288F1, + 0x020000, 0x019247, 0x01B3CC, 0x015668, 0x011518, 0x009325, 0x00EBDA, 0x00783D, + 0x0137BB, 0x00F4ED, 0x00B093, 0x008F5C, 0x00AEF4, 0x005931, 0x0062BF, 0x003597, +}, +{ + 0x01AAAB, 0x0274CB, 0x02BEC4, 0x03CEC4, 0x02504F, 0x02346C, 0x03C689, 0x0365DC, + 0x01E000, 0x017922, 0x02E3C1, 0x024539, 0x011235, 0x008BCA, 0x01905A, 0x00D64D, + 0x02DBAD, 0x025A40, 0x02D134, 0x0236A5, 0x019ED6, 0x00D37B, 0x018650, 0x00C6FB, + 0x02DBAD, 0x03F6DD, 0x02B1D9, 0x03BCD8, 0x026555, 0x0352B8, 0x01F6D8, 0x02B977, + 0x03215C, 0x02D134, 0x029100, 0x0267EB, 0x0168CC, 0x021C7A, 0x00CE01, 0x011DBD, + 0x01FD1E, 0x01CA31, 0x012062, 0x01038A, 0x03BBFB, 0x035C5C, 0x038554, 0x032B2D, + 0x028000, 0x01F6D8, 0x0220C0, 0x01AC02, 0x015A5E, 0x00B7EF, 0x0126D1, 0x00964C, + 0x0185A9, 0x013228, 0x00DCB8, 0x00B333, 0x00DAB2, 0x006F7D, 0x007B6F, 0x0042FC, +}, +{ + 0x020000, 0x02F28D, 0x034B52, 0x0491B8, 0x02C6C5, 0x02A54E, 0x0487D8, 0x0413D5, + 0x024000, 0x01C48F, 0x0377B5, 0x02B977, 0x01490C, 0x00A7BF, 0x01E06C, 0x01012A, + 0x036E03, 0x02D2B3, 0x036172, 0x02A7FA, 0x01F1CE, 0x00FDC7, 0x01D460, 0x00EEC7, + 0x036E03, 0x04C1D6, 0x033BD1, 0x047C37, 0x02E000, 0x03FCDD, 0x025B6A, 0x0344F5, + 0x03C1A1, 0x036172, 0x031466, 0x02E31B, 0x01B0F5, 0x028892, 0x00F735, 0x0156E2, + 0x0262F1, 0x0225D5, 0x015A10, 0x013772, 0x047B2D, 0x04086E, 0x043998, 0x03CD69, + 0x030000, 0x025B6A, 0x028DB3, 0x02019B, 0x019FA3, 0x00DCB8, 0x0161C7, 0x00B45B, + 0x01D398, 0x016F63, 0x0108DD, 0x00D70A, 0x01066F, 0x0085C9, 0x00941F, 0x005062, +}, +{ + 0x02AAAB, 0x03EE11, 0x04646D, 0x0617A0, 0x03B3B2, 0x038713, 0x060A75, 0x056FC6, + 0x030000, 0x025B6A, 0x049F9B, 0x03A1F4, 0x01B6BB, 0x00DFAA, 0x028090, 0x0156E2, + 0x0492AE, 0x03C399, 0x0481ED, 0x038AA2, 0x0297BD, 0x01525F, 0x027080, 0x013E5E, + 0x0492AE, 0x0657C8, 0x044FC1, 0x05FAF4, 0x03D555, 0x055126, 0x03248D, 0x045BF2, + 0x05022D, 0x0481ED, 0x041B33, 0x03D979, 0x024147, 0x0360C3, 0x01499C, 0x01C92E, + 0x032E96, 0x02DD1C, 0x01CD6A, 0x019F43, 0x05F991, 0x056093, 0x05A220, 0x0511E1, + 0x040000, 0x03248D, 0x036799, 0x02ACCF, 0x022A2F, 0x01264B, 0x01D7B5, 0x00F079, + 0x026F75, 0x01E9D9, 0x016127, 0x011EB8, 0x015DE9, 0x00B262, 0x00C57F, 0x006B2D, +}, +{ + 0x038000, 0x052876, 0x05C3CF, 0x07FF02, 0x04DBD9, 0x04A148, 0x07EDBA, 0x0722B4, + 0x03F000, 0x0317FB, 0x06117C, 0x04C491, 0x023FD5, 0x01258F, 0x0348BD, 0x01C209, + 0x060085, 0x04F0B9, 0x05EA87, 0x04A5F5, 0x036728, 0x01BC1C, 0x0333A8, 0x01A1DB, + 0x060085, 0x085336, 0x05A8AE, 0x07D960, 0x050800, 0x06FA82, 0x041FF9, 0x05B8AE, + 0x0692DA, 0x05EA87, 0x0563B2, 0x050D6E, 0x02F5AD, 0x046F00, 0x01B09C, 0x02580C, + 0x042D25, 0x03C235, 0x025D9B, 0x022108, 0x07D78F, 0x070EC1, 0x0764CA, 0x06A777, + 0x054000, 0x041FF9, 0x0477F9, 0x0382D0, 0x02D75E, 0x018242, 0x026B1D, 0x013B9F, + 0x03324A, 0x0282ED, 0x01CF83, 0x017851, 0x01CB42, 0x00EA21, 0x010336, 0x008CAC, +}, +{ + 0x040000, 0x05E519, 0x0696A4, 0x092370, 0x058D8A, 0x054A9C, 0x090FB0, 0x0827AA, + 0x048000, 0x03891F, 0x06EF69, 0x0572EE, 0x029218, 0x014F7E, 0x03C0D8, 0x020254, + 0x06DC05, 0x05A565, 0x06C2E4, 0x054FF3, 0x03E39B, 0x01FB8E, 0x03A8C0, 0x01DD8D, + 0x06DC05, 0x0983AC, 0x0677A2, 0x08F86E, 0x05C000, 0x07F9B9, 0x04B6D4, 0x0689EB, + 0x078343, 0x06C2E4, 0x0628CC, 0x05C635, 0x0361EA, 0x051124, 0x01EE69, 0x02ADC5, + 0x04C5E1, 0x044BAA, 0x02B41F, 0x026EE5, 0x08F65A, 0x0810DD, 0x087330, 0x079AD1, + 0x060000, 0x04B6D4, 0x051B65, 0x040337, 0x033F47, 0x01B970, 0x02C38F, 0x0168B6, + 0x03A730, 0x02DEC6, 0x0211BA, 0x01AE14, 0x020CDD, 0x010B93, 0x01283E, 0x00A0C4, +}, +{ + 0x050000, 0x075E60, 0x083C4D, 0x0B6C4C, 0x06F0ED, 0x069D43, 0x0B539C, 0x0A3194, + 0x05A000, 0x046B67, 0x08AB44, 0x06CFAA, 0x03369E, 0x01A35E, 0x04B10F, 0x0282E8, + 0x089307, 0x070EBF, 0x08739C, 0x06A3F0, 0x04DC82, 0x027A72, 0x0492F0, 0x0254F0, + 0x089307, 0x0BE497, 0x08158B, 0x0B3689, 0x073000, 0x09F827, 0x05E489, 0x082C66, + 0x096413, 0x08739C, 0x07B2FF, 0x0737C2, 0x043A64, 0x06556D, 0x026A04, 0x035936, + 0x05F75A, 0x055E94, 0x036127, 0x030A9E, 0x0B33F1, 0x0A1514, 0x0A8FFC, 0x098186, + 0x078000, 0x05E489, 0x06623F, 0x050405, 0x040F19, 0x0227CC, 0x037473, 0x01C2E3, + 0x0490FC, 0x039677, 0x029629, 0x021999, 0x029015, 0x014E78, 0x01724E, 0x00C8F5, +}, +{ + 0x060000, 0x08D7A6, 0x09E1F6, 0x0DB528, 0x085450, 0x07EFEA, 0x0D9788, 0x0C3B7E, + 0x06C000, 0x054DAE, 0x0A671E, 0x082C66, 0x03DB24, 0x01F73E, 0x05A145, 0x03037D, + 0x0A4A08, 0x087818, 0x0A2455, 0x07F7ED, 0x05D569, 0x02F955, 0x057D20, 0x02CC54, + 0x0A4A08, 0x0E4582, 0x09B373, 0x0D74A5, 0x08A000, 0x0BF696, 0x07123E, 0x09CEE0, + 0x0B44E4, 0x0A2455, 0x093D32, 0x08A950, 0x0512DF, 0x0799B6, 0x02E59E, 0x0404A7, + 0x0728D2, 0x06717F, 0x040E2F, 0x03A657, 0x0D7187, 0x0C194B, 0x0CACC8, 0x0B683A, + 0x090000, 0x07123E, 0x07A918, 0x0604D2, 0x04DEEA, 0x029629, 0x042556, 0x021D11, + 0x057AC8, 0x044E28, 0x031A97, 0x02851E, 0x03134C, 0x01915C, 0x01BC5D, 0x00F126, +}, +{ + 0x080000, 0x0BCA33, 0x0D2D48, 0x1246E0, 0x0B1B15, 0x0A9538, 0x121F5F, 0x104F53, + 0x090000, 0x07123E, 0x0DDED2, 0x0AE5DD, 0x052430, 0x029EFD, 0x0781B1, 0x0404A7, + 0x0DB80B, 0x0B4ACB, 0x0D85C7, 0x0A9FE7, 0x07C736, 0x03F71D, 0x075180, 0x03BB1A, + 0x0DB80B, 0x130757, 0x0CEF44, 0x11F0DC, 0x0B8000, 0x0FF372, 0x096DA8, 0x0D13D6, + 0x0F0686, 0x0D85C7, 0x0C5198, 0x0B8C6A, 0x06C3D4, 0x0A2248, 0x03DCD3, 0x055B8A, + 0x098BC3, 0x089754, 0x05683E, 0x04DDC9, 0x11ECB4, 0x1021B9, 0x10E661, 0x0F35A3, + 0x0C0000, 0x096DA8, 0x0A36CB, 0x08066E, 0x067E8E, 0x0372E1, 0x05871E, 0x02D16B, + 0x074E60, 0x05BD8B, 0x042374, 0x035C28, 0x0419BB, 0x021726, 0x02507C, 0x014188, +}, +{ + 0x0C0000, 0x11AF4C, 0x13C3EC, 0x1B6A50, 0x10A89F, 0x0FDFD4, 0x1B2F0F, 0x1876FD, + 0x0D8000, 0x0A9B5D, 0x14CE3C, 0x1058CB, 0x07B649, 0x03EE7B, 0x0B4289, 0x0606FB, + 0x149410, 0x10F030, 0x1448AB, 0x0FEFDA, 0x0BAAD2, 0x05F2AB, 0x0AFA40, 0x0598A7, + 0x149410, 0x1C8B03, 0x1366E6, 0x1AE949, 0x114000, 0x17ED2B, 0x0E247C, 0x139DC1, + 0x1689C8, 0x1448AB, 0x127A63, 0x11529F, 0x0A25BE, 0x0F336D, 0x05CB3C, 0x08094E, + 0x0E51A4, 0x0CE2FE, 0x081C5D, 0x074CAE, 0x1AE30E, 0x183296, 0x195991, 0x16D074, + 0x120000, 0x0E247C, 0x0F5230, 0x0C09A5, 0x09BDD5, 0x052C51, 0x084AAC, 0x043A21, + 0x0AF590, 0x089C51, 0x06352E, 0x050A3B, 0x062698, 0x0322B9, 0x0378BA, 0x01E24D, +}, +{ + 0x110000, 0x190DAC, 0x1C0039, 0x26D69C, 0x17998C, 0x167D16, 0x2682AB, 0x22A891, + 0x132000, 0x0F06C3, 0x1D797F, 0x172876, 0x0AECE7, 0x0591D9, 0x0FF398, 0x0889E3, + 0x1D2717, 0x17FEEF, 0x1CBC47, 0x1693CA, 0x108754, 0x086D1D, 0x0F8D30, 0x07ED98, + 0x1D2717, 0x286F9A, 0x1B7C71, 0x261FD3, 0x187000, 0x21E552, 0x140904, 0x1BCA27, + 0x1FEDDC, 0x1CBC47, 0x1A2D62, 0x188A62, 0x0E6022, 0x1588DA, 0x083540, 0x0B6284, + 0x1448FE, 0x124192, 0x0B7D84, 0x0A574B, 0x2616FF, 0x2247AA, 0x23E98D, 0x2051FA, + 0x198000, 0x140904, 0x15B46F, 0x110DAA, 0x0DCCEE, 0x07541E, 0x0BBF1F, 0x05FD04, + 0x0F868B, 0x0C32C8, 0x08CB57, 0x0723D4, 0x08B6AD, 0x047130, 0x04EB08, 0x02AB42, +}, +{ + 0x160000, 0x206C0C, 0x243C86, 0x3242E8, 0x1E8A79, 0x1D1A59, 0x31D646, 0x2CDA25, + 0x18C000, 0x13722A, 0x2624C3, 0x1DF820, 0x0E2385, 0x073537, 0x14A4A7, 0x0B0CCC, + 0x25BA1D, 0x1F0DAE, 0x252FE4, 0x1D37BB, 0x1563D6, 0x0AE78E, 0x142021, 0x0A4288, + 0x25BA1D, 0x345430, 0x2391FB, 0x31565C, 0x1FA000, 0x2BDD7A, 0x19ED8D, 0x23F68C, + 0x2951EF, 0x252FE4, 0x21E061, 0x1FC224, 0x129A87, 0x1BDE47, 0x0A9F44, 0x0EBBBA, + 0x1A4058, 0x17A026, 0x0EDEAB, 0x0D61E9, 0x314AEF, 0x2C5CBE, 0x2E798A, 0x29D380, + 0x210000, 0x19ED8D, 0x1C16AE, 0x1611AE, 0x11DC06, 0x097BEA, 0x0F3391, 0x07BFE7, + 0x141787, 0x0FC93E, 0x0B617F, 0x093D6D, 0x0B46C1, 0x05BFA8, 0x065D55, 0x037437, +}, +{ + 0x1C0000, 0x2943B2, 0x2E1E7C, 0x3FF810, 0x26DEC9, 0x250A43, 0x3F6DCE, 0x3915A3, + 0x1F8000, 0x18BFD8, 0x308BE1, 0x262485, 0x11FEA9, 0x092C75, 0x1A45EB, 0x0E1049, + 0x300425, 0x2785C6, 0x2F5439, 0x252FA8, 0x1B393F, 0x0DE0E4, 0x199D41, 0x0D0EDC, + 0x300425, 0x4299B2, 0x2D456E, 0x3ECB00, 0x284000, 0x37D40F, 0x20FFCB, 0x2DC56D, + 0x3496D3, 0x2F5439, 0x2B1D93, 0x286B74, 0x17AD66, 0x2377FE, 0x0D84E2, 0x12C062, + 0x21692A, 0x1E11A5, 0x12ECDA, 0x110840, 0x3EBC76, 0x387608, 0x3B2652, 0x353BBA, + 0x2A0000, 0x20FFCB, 0x23BFC6, 0x1C1681, 0x16BAF1, 0x0C1213, 0x1358E8, 0x09DCF8, + 0x19924F, 0x141767, 0x0E7C16, 0x0BC28A, 0x0E5A0D, 0x075104, 0x0819B2, 0x04655D, +}, +{ + 0x220000, 0x321B58, 0x380072, 0x4DAD38, 0x2F3318, 0x2CFA2D, 0x4D0556, 0x455122, + 0x264000, 0x1E0D86, 0x3AF2FE, 0x2E50EB, 0x15D9CE, 0x0B23B2, 0x1FE730, 0x1113C7, + 0x3A4E2D, 0x2FFDDF, 0x39788E, 0x2D2795, 0x210EA8, 0x10DA39, 0x1F1A61, 0x0FDB2F, + 0x3A4E2D, 0x50DF33, 0x36F8E1, 0x4C3FA5, 0x30E000, 0x43CAA5, 0x281209, 0x37944D, + 0x3FDBB7, 0x39788E, 0x345AC4, 0x3114C3, 0x1CC044, 0x2B11B4, 0x106A80, 0x16C509, + 0x2891FC, 0x248324, 0x16FB08, 0x14AE97, 0x4C2DFD, 0x448F54, 0x47D31B, 0x40A3F5, + 0x330000, 0x281209, 0x2B68DF, 0x221B53, 0x1B99DB, 0x0EA83B, 0x177E3E, 0x0BFA09, + 0x1F0D17, 0x18658F, 0x1196AE, 0x0E47A8, 0x116D5A, 0x08E260, 0x09D60F, 0x055684, +}, +{ + 0x2C0000, 0x40D818, 0x48790C, 0x6485D0, 0x3D14F2, 0x3A34B2, 0x63AC8D, 0x59B44A, + 0x318000, 0x26E454, 0x4C4986, 0x3BF03F, 0x1C470A, 0x0E6A6E, 0x29494D, 0x161998, + 0x4B743A, 0x3E1B5C, 0x4A5FC7, 0x3A6F75, 0x2AC7AC, 0x15CF1D, 0x284041, 0x148510, + 0x4B743A, 0x68A861, 0x4723F6, 0x62ACB8, 0x3F4000, 0x57BAF3, 0x33DB1A, 0x47ED19, + 0x52A3DE, 0x4A5FC7, 0x43C0C2, 0x3F8448, 0x25350D, 0x37BC8E, 0x153E87, 0x1D7775, + 0x3480B0, 0x2F404C, 0x1DBD56, 0x1AC3D2, 0x6295DE, 0x58B97B, 0x5CF313, 0x53A701, + 0x420000, 0x33DB1A, 0x382D5C, 0x2C235D, 0x23B80D, 0x12F7D4, 0x1E6723, 0x0F7FCF, + 0x282F0E, 0x1F927D, 0x16C2FF, 0x127AD9, 0x168D83, 0x0B7F50, 0x0CBAAA, 0x06E86E, +}, +}; + +#endif /* AVCODEC_BINKDATA_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/binkidct.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/binkidct.c new file mode 100644 index 0000000000..160926e163 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/binkidct.c @@ -0,0 +1,112 @@ +/* + * Bink IDCT algorithm + * Copyright (c) 2009 Kostya 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 + * Bink IDCT algorithm + */ + +#include "dsputil.h" + +#define A1 2896 /* (1/sqrt(2))<<12 */ +#define A2 2217 +#define A3 3784 +#define A4 -5352 + +#define IDCT_TRANSFORM(dest,s0,s1,s2,s3,s4,s5,s6,s7,d0,d1,d2,d3,d4,d5,d6,d7,munge,src) {\ + const int a0 = (src)[s0] + (src)[s4]; \ + const int a1 = (src)[s0] - (src)[s4]; \ + const int a2 = (src)[s2] + (src)[s6]; \ + const int a3 = (A1*((src)[s2] - (src)[s6])) >> 11; \ + const int a4 = (src)[s5] + (src)[s3]; \ + const int a5 = (src)[s5] - (src)[s3]; \ + const int a6 = (src)[s1] + (src)[s7]; \ + const int a7 = (src)[s1] - (src)[s7]; \ + const int b0 = a4 + a6; \ + const int b1 = (A3*(a5 + a7)) >> 11; \ + const int b2 = ((A4*a5) >> 11) - b0 + b1; \ + const int b3 = (A1*(a6 - a4) >> 11) - b2; \ + const int b4 = ((A2*a7) >> 11) + b3 - b1; \ + (dest)[d0] = munge(a0+a2 +b0); \ + (dest)[d1] = munge(a1+a3-a2+b2); \ + (dest)[d2] = munge(a1-a3+a2+b3); \ + (dest)[d3] = munge(a0-a2 -b4); \ + (dest)[d4] = munge(a0-a2 +b4); \ + (dest)[d5] = munge(a1-a3+a2-b3); \ + (dest)[d6] = munge(a1+a3-a2-b2); \ + (dest)[d7] = munge(a0+a2 -b0); \ +} +/* end IDCT_TRANSFORM macro */ + +#define MUNGE_NONE(x) (x) +#define IDCT_COL(dest,src) IDCT_TRANSFORM(dest,0,8,16,24,32,40,48,56,0,8,16,24,32,40,48,56,MUNGE_NONE,src) + +#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(DCTELEM *dest, const DCTELEM *src) +{ + if ((src[8]|src[16]|src[24]|src[32]|src[40]|src[48]|src[56])==0) { + dest[0] = + dest[8] = + dest[16] = + dest[24] = + dest[32] = + dest[40] = + dest[48] = + dest[56] = src[0]; + } else { + IDCT_COL(dest, src); + } +} + +void ff_bink_idct_c(DCTELEM *block) +{ + int i; + DCTELEM temp[64]; + + for (i = 0; i < 8; i++) + bink_idct_col(&temp[i], &block[i]); + for (i = 0; i < 8; i++) { + IDCT_ROW( (&block[8*i]), (&temp[8*i]) ); + } +} + +void ff_bink_idct_add_c(uint8_t *dest, int linesize, DCTELEM *block) +{ + int i, j; + + ff_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) +{ + int i; + DCTELEM temp[64]; + for (i = 0; i < 8; i++) + bink_idct_col(&temp[i], &block[i]); + for (i = 0; i < 8; i++) { + IDCT_ROW( (&dest[i*linesize]), (&temp[8*i]) ); + } +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/bitstream.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/bitstream.c index 3706f43124..0d7a2dbc85 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/bitstream.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/bitstream.c @@ -2,6 +2,7 @@ * Common bit i/o utils * Copyright (c) 2000, 2001 Fabrice Bellard * Copyright (c) 2002-2004 Michael Niedermayer + * Copyright (c) 2010 Loren Merritt * * alternative bitstream reader & writer by Michael Niedermayer * @@ -23,7 +24,7 @@ */ /** - * @file libavcodec/bitstream.c + * @file * bitstream api. */ @@ -38,25 +39,6 @@ const uint8_t ff_log2_run[32]={ 8, 9,10,11,12,13,14,15 }; -#if LIBAVCODEC_VERSION_MAJOR < 53 -/** - * Same as av_mallocz_static(), but does a realloc. - * - * @param[in] ptr The block of memory to reallocate. - * @param[in] size The requested size. - * @return Block of memory of requested size. - * @deprecated. Code which uses ff_realloc_static is broken/misdesigned - * and should correctly use static arrays - */ -attribute_deprecated av_alloc_size(2) -static void *ff_realloc_static(void *ptr, unsigned int size); - -static void *ff_realloc_static(void *ptr, unsigned int size) -{ - return av_realloc(ptr, size); -} -#endif - void align_put_bits(PutBitContext *s) { #ifdef ALT_BITSTREAM_WRITER @@ -66,14 +48,14 @@ void align_put_bits(PutBitContext *s) #endif } -void ff_put_string(PutBitContext * pbc, const char *s, int terminate_string) +void ff_put_string(PutBitContext *pb, const char *string, int terminate_string) { - while(*s){ - put_bits(pbc, 8, *s); - s++; + while(*string){ + put_bits(pb, 8, *string); + string++; } if(terminate_string) - put_bits(pbc, 8, 0); + put_bits(pb, 8, 0); } void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length) @@ -124,123 +106,137 @@ static int alloc_table(VLC *vlc, int size, int use_static) index = vlc->table_size; vlc->table_size += size; if (vlc->table_size > vlc->table_allocated) { - if(use_static>1) + if(use_static) abort(); //cant do anything, init_vlc() is used with too little memory vlc->table_allocated += (1 << vlc->bits); - if(use_static) - vlc->table = ff_realloc_static(vlc->table, - sizeof(VLC_TYPE) * 2 * vlc->table_allocated); - else - vlc->table = av_realloc(vlc->table, - sizeof(VLC_TYPE) * 2 * vlc->table_allocated); + vlc->table = av_realloc(vlc->table, + sizeof(VLC_TYPE) * 2 * vlc->table_allocated); if (!vlc->table) return -1; } return index; } -static int build_table(VLC *vlc, int table_nb_bits, - int nb_codes, - const void *bits, int bits_wrap, int bits_size, - const void *codes, int codes_wrap, int codes_size, - const void *symbols, int symbols_wrap, int symbols_size, - uint32_t code_prefix, int n_prefix, int flags) +static av_always_inline uint32_t bitswap_32(uint32_t x) { + return av_reverse[x&0xFF]<<24 + | av_reverse[(x>>8)&0xFF]<<16 + | av_reverse[(x>>16)&0xFF]<<8 + | av_reverse[x>>24]; +} + +typedef struct { + uint8_t bits; + uint16_t symbol; + /** codeword, with the first bit-to-be-read in the msb + * (even if intended for a little-endian bitstream reader) */ + uint32_t code; +} VLCcode; + +static int compare_vlcspec(const void *a, const void *b) { - int i, j, k, n, table_size, table_index, nb, n1, index, code_prefix2, symbol; + const VLCcode *sa=a, *sb=b; + return (sa->code >> 1) - (sb->code >> 1); +} + +/** + * Build VLC decoding tables suitable for use with get_vlc(). + * + * @param vlc the context to be initted + * + * @param table_nb_bits max length of vlc codes to store directly in this table + * (Longer codes are delegated to subtables.) + * + * @param nb_codes number of elements in codes[] + * + * @param codes descriptions of the vlc codes + * These must be ordered such that codes going into the same subtable are contiguous. + * Sorting by VLCcode.code is sufficient, though not necessary. + */ +static int build_table(VLC *vlc, int table_nb_bits, int nb_codes, + VLCcode *codes, int flags) +{ + int table_size, table_index, index, code_prefix, symbol, subtable_bits; + int i, j, k, n, nb, inc; uint32_t code; VLC_TYPE (*table)[2]; table_size = 1 << table_nb_bits; - table_index = alloc_table(vlc, table_size, flags & (INIT_VLC_USE_STATIC|INIT_VLC_USE_NEW_STATIC)); + table_index = alloc_table(vlc, table_size, flags & INIT_VLC_USE_NEW_STATIC); #ifdef DEBUG_VLC - av_log(NULL,AV_LOG_DEBUG,"new table index=%d size=%d code_prefix=%x n=%d\n", - table_index, table_size, code_prefix, n_prefix); + av_log(NULL,AV_LOG_DEBUG,"new table index=%d size=%d\n", + table_index, table_size); #endif if (table_index < 0) return -1; table = &vlc->table[table_index]; - for(i=0;i=32 ? 0xffffffff : (1 << n_prefix)-1); - else - code_prefix2= code >> n; - if (n > 0 && code_prefix2 == code_prefix) { - if (n <= table_nb_bits) { - /* no need to add another table */ - j = (code << (table_nb_bits - n)) & (table_size - 1); - nb = 1 << (table_nb_bits - n); - for(k=0;k> n_prefix) + (k<> (32 - table_nb_bits); + nb = 1 << (table_nb_bits - n); + inc = 1; + if (flags & INIT_VLC_LE) { + j = bitswap_32(code); + inc = 1 << n; + } + for (k = 0; k < nb; k++) { #ifdef DEBUG_VLC - av_log(NULL, AV_LOG_DEBUG, "%4x: code=%d n=%d\n", - j, i, n); + av_log(NULL, AV_LOG_DEBUG, "%4x: code=%d n=%d\n", + j, i, n); #endif - if (table[j][1] /*bits*/ != 0) { - av_log(NULL, AV_LOG_ERROR, "incorrect codes\n"); - return -1; - } - table[j][1] = n; //bits - table[j][0] = symbol; - j++; + if (table[j][1] /*bits*/ != 0) { + av_log(NULL, AV_LOG_ERROR, "incorrect codes\n"); + return -1; } - } else { - n -= table_nb_bits; - j = (code >> ((flags & INIT_VLC_LE) ? n_prefix : n)) & ((1 << table_nb_bits) - 1); + table[j][1] = n; //bits + table[j][0] = symbol; + j += inc; + } + } else { + /* fill auxiliary table recursively */ + n -= table_nb_bits; + code_prefix = code >> (32 - table_nb_bits); + subtable_bits = n; + codes[i].bits = n; + codes[i].code = code << table_nb_bits; + for (k = i+1; k < nb_codes; k++) { + n = codes[k].bits - table_nb_bits; + if (n <= 0) + break; + code = codes[k].code; + if (code >> (32 - table_nb_bits) != code_prefix) + break; + codes[k].bits = n; + codes[k].code = code << table_nb_bits; + subtable_bits = FFMAX(subtable_bits, n); + } + subtable_bits = FFMIN(subtable_bits, table_nb_bits); + j = (flags & INIT_VLC_LE) ? bitswap_32(code_prefix) >> (32 - table_nb_bits) : code_prefix; + table[j][1] = -subtable_bits; #ifdef DEBUG_VLC - av_log(NULL,AV_LOG_DEBUG,"%4x: n=%d (subtable)\n", - j, n); + av_log(NULL,AV_LOG_DEBUG,"%4x: n=%d (subtable)\n", + j, codes[i].bits + table_nb_bits); #endif - /* compute table size */ - n1 = -table[j][1]; //bits - if (n > n1) - n1 = n; - table[j][1] = -n1; //bits - } - } - } - - /* second pass : fill auxillary tables recursively */ - for(i=0;i table_nb_bits) { - n = table_nb_bits; - table[i][1] = -n; //bits - } - index = build_table(vlc, n, nb_codes, - bits, bits_wrap, bits_size, - codes, codes_wrap, codes_size, - symbols, symbols_wrap, symbols_size, - (flags & INIT_VLC_LE) ? (code_prefix | (i << n_prefix)) : ((code_prefix << table_nb_bits) | i), - n_prefix + table_nb_bits, flags); + index = build_table(vlc, subtable_bits, k-i, codes+i, flags); if (index < 0) return -1; /* note: realloc has been done, so reload tables */ table = &vlc->table[table_index]; - table[i][0] = index; //code + table[j][0] = index; //code + i = k-1; } } return table_index; @@ -279,6 +275,9 @@ int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, const void *symbols, int symbols_wrap, int symbols_size, int flags) { + VLCcode buf[nb_codes]; + int i, j; + vlc->bits = nb_bits; if(flags & INIT_VLC_USE_NEW_STATIC){ if(vlc->table_size && vlc->table_size == vlc->table_allocated){ @@ -286,26 +285,41 @@ int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, }else if(vlc->table_size){ abort(); // fatal error, we are called on a partially initialized table } - }else if(!(flags & INIT_VLC_USE_STATIC)) { + }else { vlc->table = NULL; vlc->table_allocated = 0; vlc->table_size = 0; - } else { - /* Static tables are initially always NULL, return - if vlc->table != NULL to avoid double allocation */ - if(vlc->table) - return 0; } #ifdef DEBUG_VLC av_log(NULL,AV_LOG_DEBUG,"build table nb_codes=%d\n", nb_codes); #endif - if (build_table(vlc, nb_bits, nb_codes, - bits, bits_wrap, bits_size, - codes, codes_wrap, codes_size, - symbols, symbols_wrap, symbols_size, - 0, 0, flags) < 0) { + assert(symbols_size <= 2 || !symbols); + j = 0; +#define COPY(condition)\ + for (i = 0; i < nb_codes; i++) {\ + GET_DATA(buf[j].bits, bits, i, bits_wrap, bits_size);\ + if (!(condition))\ + continue;\ + GET_DATA(buf[j].code, codes, i, codes_wrap, codes_size);\ + if (flags & INIT_VLC_LE)\ + buf[j].code = bitswap_32(buf[j].code);\ + else\ + buf[j].code <<= 32 - buf[j].bits;\ + if (symbols)\ + GET_DATA(buf[j].symbol, symbols, i, symbols_wrap, symbols_size)\ + else\ + buf[j].symbol = i;\ + j++;\ + } + COPY(buf[j].bits > nb_bits); + // qsort is the slowest part of init_vlc, and could probably be improved or avoided + qsort(buf, j, sizeof(VLCcode), compare_vlcspec); + COPY(buf[j].bits && buf[j].bits <= nb_bits); + nb_codes = j; + + if (build_table(vlc, nb_bits, nb_codes, buf, flags) < 0) { av_freep(&vlc->table); return -1; } diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/bmp.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/bmp.c index cadaeee543..da7bb787d0 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/bmp.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/bmp.c @@ -231,18 +231,37 @@ static int bmp_decode_frame(AVCodecContext *avctx, } if(avctx->pix_fmt == PIX_FMT_PAL8){ + int colors = 1 << depth; + if(ihsize >= 36){ + int t; + buf = buf0 + 46; + t = bytestream_get_le32(&buf); + if(t < 0 || t > (1 << depth)){ + av_log(avctx, AV_LOG_ERROR, "Incorrect number of colors - %X for bitdepth %d\n", t, depth); + }else if(t){ + colors = t; + } + } buf = buf0 + 14 + ihsize; //palette location - if((hsize-ihsize-14)>>depth < 4){ // OS/2 bitmap, 3 bytes per palette entry - for(i = 0; i < (1 << depth); i++) + 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); }else{ - for(i = 0; i < (1 << depth); i++) + for(i = 0; i < colors; i++) ((uint32_t*)p->data[1])[i] = bytestream_get_le32(&buf); } buf = buf0 + hsize; } if(comp == BMP_RLE4 || comp == BMP_RLE8){ + if(height < 0){ + p->data[0] += p->linesize[0] * (avctx->height - 1); + p->linesize[0] = -p->linesize[0]; + } ff_msrle_decode(avctx, (AVPicture*)p, depth, buf, dsize); + if(height < 0){ + p->data[0] += p->linesize[0] * (avctx->height - 1); + p->linesize[0] = -p->linesize[0]; + } }else{ switch(depth){ case 1: @@ -318,7 +337,7 @@ static av_cold int bmp_decode_end(AVCodecContext *avctx) AVCodec bmp_decoder = { "bmp", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_BMP, sizeof(BMPContext), bmp_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/bmpenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/bmpenc.c index 578813af60..ee85f3cfae 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/bmpenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/bmpenc.c @@ -133,13 +133,13 @@ static int bmp_encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_s AVCodec bmp_encoder = { "bmp", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_BMP, sizeof(BMPContext), bmp_encode_init, bmp_encode_frame, NULL, //encode_end, - .pix_fmts = (enum PixelFormat[]){ + .pix_fmts = (const enum PixelFormat[]){ PIX_FMT_BGR24, PIX_FMT_RGB555, PIX_FMT_RGB565, PIX_FMT_RGB8, PIX_FMT_BGR8, PIX_FMT_RGB4_BYTE, PIX_FMT_BGR4_BYTE, PIX_FMT_GRAY8, PIX_FMT_PAL8, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/c93.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/c93.c index 0e362cad98..d713ff8e26 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/c93.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/c93.c @@ -244,7 +244,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, AVCodec c93_decoder = { "c93", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_C93, sizeof(C93DecoderContext), decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/cabac.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/cabac.c index 9a3bdafb8f..7b5e5b1de4 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/cabac.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/cabac.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/cabac.c + * @file * Context Adaptive Binary Arithmetic Coder. */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/cabac.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/cabac.h index 2794626c35..0af77e426f 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/cabac.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/cabac.h @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/cabac.h + * @file * Context Adaptive Binary Arithmetic Coder. */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/cavs.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/cavs.c index a201fe26c2..ff6c86964a 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/cavs.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/cavs.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/cavs.c + * @file * Chinese AVS video (AVS1-P2, JiZhun profile) decoder * @author Stefan Gehrer */ @@ -73,7 +73,7 @@ static inline int get_bs(cavs_vector *mvP, cavs_vector *mvQ, int b) { * */ void ff_cavs_filter(AVSContext *h, enum cavs_mb mb_type) { - DECLARE_ALIGNED_8(uint8_t, bs[8]); + uint8_t bs[8]; int qp_avg, alpha, beta, tc; int i; @@ -93,9 +93,9 @@ void ff_cavs_filter(AVSContext *h, enum cavs_mb mb_type) { if(!h->loop_filter_disable) { /* determine bs */ if(mb_type == I_8X8) - *((uint64_t *)bs) = 0x0202020202020202ULL; + memset(bs,2,8); else{ - *((uint64_t *)bs) = 0; + memset(bs,0,8); if(ff_cavs_partition_flags[mb_type] & SPLITV){ bs[2] = get_bs(&h->mv[MV_FWD_X0], &h->mv[MV_FWD_X1], mb_type > P_8X8); bs[3] = get_bs(&h->mv[MV_FWD_X2], &h->mv[MV_FWD_X3], mb_type > P_8X8); @@ -109,7 +109,7 @@ void ff_cavs_filter(AVSContext *h, enum cavs_mb mb_type) { bs[4] = get_bs(&h->mv[MV_FWD_B2], &h->mv[MV_FWD_X0], mb_type > P_8X8); bs[5] = get_bs(&h->mv[MV_FWD_B3], &h->mv[MV_FWD_X1], mb_type > P_8X8); } - if( *((uint64_t *)bs) ) { + if(AV_RN64(bs)) { if(h->flags & A_AVAIL) { qp_avg = (h->qp + h->left_qp + 1) >> 1; SET_PARAMS; @@ -572,7 +572,7 @@ void ff_cavs_init_mb(AVSContext *h) { /** * save predictors for later macroblocks and increase * macroblock address - * @returns 0 if end of frame is reached, 1 otherwise + * @return 0 if end of frame is reached, 1 otherwise */ int ff_cavs_next_mb(AVSContext *h) { int i; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/cavs.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/cavs.h index 5ae664dd33..729c83ea7b 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/cavs.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/cavs.h @@ -136,7 +136,7 @@ enum cavs_mv_loc { MV_BWD_X3 }; -DECLARE_ALIGNED_8(typedef, struct) { +DECLARE_ALIGNED(8, typedef, struct) { int16_t x; int16_t y; int16_t dist; @@ -160,6 +160,7 @@ typedef struct { int aspect_ratio; int mb_width, mb_height; int pic_type; + int stream_revision; ///<0 for samples from 2006, 1 for rm52j encoder int progressive; int pic_structure; int skip_mode_flag; ///< select between skip_count or one skip_flag per MB @@ -247,8 +248,13 @@ static inline void modify_pred(const int_fast8_t *mod_table, int *mode) { } static inline void set_intra_mode_default(AVSContext *h) { - h->pred_mode_Y[3] = h->pred_mode_Y[6] = INTRA_L_LP; - h->top_pred_Y[h->mbx*2+0] = h->top_pred_Y[h->mbx*2+1] = INTRA_L_LP; + if(h->stream_revision > 0) { + h->pred_mode_Y[3] = h->pred_mode_Y[6] = NOT_AVAIL; + h->top_pred_Y[h->mbx*2+0] = h->top_pred_Y[h->mbx*2+1] = NOT_AVAIL; + } else { + h->pred_mode_Y[3] = h->pred_mode_Y[6] = INTRA_L_LP; + h->top_pred_Y[h->mbx*2+0] = h->top_pred_Y[h->mbx*2+1] = INTRA_L_LP; + } } static inline void set_mvs(cavs_vector *mv, enum cavs_block size) { diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/cavs_parser.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/cavs_parser.c index 6d19e1fd82..8e9c35b7a7 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/cavs_parser.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/cavs_parser.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/cavs_parser.c + * @file * Chinese AVS video (AVS1-P2, JiZhun profile) parser * @author Stefan Gehrer */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/cavsdec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/cavsdec.c index 458fcf2bb5..9d6307c217 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/cavsdec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/cavsdec.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/cavsdec.c + * @file * Chinese AVS video (AVS1-P2, JiZhun profile) decoder * @author Stefan Gehrer */ @@ -483,6 +483,15 @@ static int decode_pic(AVSContext *h) { h->pic_type = FF_I_TYPE; if(get_bits1(&s->gb)) skip_bits(&s->gb,24);//time_code + /* old sample clips were all progressive and no low_delay, + bump stream revision if detected otherwise */ + if((s->low_delay) || !(show_bits(&s->gb,9) & 1)) + h->stream_revision = 1; + /* similarly test top_field_first and repeat_first_field */ + else if(show_bits(&s->gb,11) & 3) + h->stream_revision = 1; + if(h->stream_revision > 0) + skip_bits(&s->gb,1); //marker_bit } /* release last B frame */ if(h->picture.data[0]) @@ -702,7 +711,7 @@ static int cavs_decode_frame(AVCodecContext * avctx,void *data, int *data_size, AVCodec cavs_decoder = { "cavs", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_CAVS, sizeof(AVSContext), ff_cavs_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/cavsdsp.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/cavsdsp.c index 69d3bd2323..808f62b69f 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/cavsdsp.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/cavsdsp.c @@ -510,12 +510,7 @@ CAVS_MC(put_, 16) CAVS_MC(avg_, 8) CAVS_MC(avg_, 16) -void ff_put_cavs_qpel8_mc00_c(uint8_t *dst, uint8_t *src, int stride); -void ff_avg_cavs_qpel8_mc00_c(uint8_t *dst, uint8_t *src, int stride); -void ff_put_cavs_qpel16_mc00_c(uint8_t *dst, uint8_t *src, int stride); -void ff_avg_cavs_qpel16_mc00_c(uint8_t *dst, uint8_t *src, int stride); - -void ff_cavsdsp_init(DSPContext* c, AVCodecContext *avctx) { +av_cold void ff_cavsdsp_init(DSPContext* c, AVCodecContext *avctx) { #define dspfunc(PFX, IDX, NUM) \ c->PFX ## _pixels_tab[IDX][ 0] = ff_ ## PFX ## NUM ## _mc00_c; \ c->PFX ## _pixels_tab[IDX][ 1] = ff_ ## PFX ## NUM ## _mc10_c; \ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/cbrt_tablegen.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/cbrt_tablegen.c new file mode 100644 index 0000000000..dbbd632693 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/cbrt_tablegen.c @@ -0,0 +1,39 @@ +/* + * Generate a header file for hardcoded AAC cube-root table + * + * Copyright (c) 2010 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 +#define CONFIG_HARDCODED_TABLES 0 +#include "cbrt_tablegen.h" +#include "tableprint.h" + +int main(void) +{ + cbrt_tableinit(); + + write_fileheader(); + + printf("static const uint32_t cbrt_tab[1<<13] = {\n"); + write_uint32_array(cbrt_tab, 1 << 13); + printf("};\n"); + + return 0; +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/cbrt_tablegen.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/cbrt_tablegen.h new file mode 100644 index 0000000000..930e513705 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/cbrt_tablegen.h @@ -0,0 +1,51 @@ +/* + * Header file for hardcoded AAC cube-root table + * + * Copyright (c) 2010 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 + */ + +#ifndef CBRT_TABLEGEN_H +#define CBRT_TABLEGEN_H + +#include +#include + +#if CONFIG_HARDCODED_TABLES +#define cbrt_tableinit() +#include "libavcodec/cbrt_tables.h" +#else +static uint32_t cbrt_tab[1 << 13]; + +static void cbrt_tableinit(void) +{ + if (!cbrt_tab[(1<<13) - 1]) { + int i; + for (i = 0; i < 1<<13; i++) { + union { + float f; + uint32_t i; + } f; + f.f = cbrtf(i) * i; + cbrt_tab[i] = f.i; + } + } +} +#endif /* CONFIG_HARDCODED_TABLES */ + +#endif /* CBRT_TABLEGEN_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/cdgraphics.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/cdgraphics.c new file mode 100644 index 0000000000..c174aa9d98 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/cdgraphics.c @@ -0,0 +1,381 @@ +/* + * CD Graphics Video Decoder + * Copyright (c) 2009 Michael Tison + * + * 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 "bytestream.h" + +/** + * @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 + */ + +/// default screen sizes +#define CDG_FULL_WIDTH 300 +#define CDG_FULL_HEIGHT 216 +#define CDG_DISPLAY_WIDTH 294 +#define CDG_DISPLAY_HEIGHT 204 +#define CDG_BORDER_WIDTH 6 +#define CDG_BORDER_HEIGHT 12 + +/// masks +#define CDG_COMMAND 0x09 +#define CDG_MASK 0x3F + +/// instruction codes +#define CDG_INST_MEMORY_PRESET 1 +#define CDG_INST_BORDER_PRESET 2 +#define CDG_INST_TILE_BLOCK 6 +#define CDG_INST_SCROLL_PRESET 20 +#define CDG_INST_SCROLL_COPY 24 +#define CDG_INST_LOAD_PAL_LO 30 +#define CDG_INST_LOAD_PAL_HIGH 31 +#define CDG_INST_TILE_BLOCK_XOR 38 + +/// data sizes +#define CDG_PACKET_SIZE 24 +#define CDG_DATA_SIZE 16 +#define CDG_TILE_HEIGHT 12 +#define CDG_TILE_WIDTH 6 +#define CDG_MINIMUM_PKT_SIZE 6 +#define CDG_MINIMUM_SCROLL_SIZE 3 +#define CDG_HEADER_SIZE 8 +#define CDG_PALETTE_SIZE 16 + +typedef struct CDGraphicsContext { + AVFrame frame; + int hscroll; + int vscroll; +} CDGraphicsContext; + +static void cdg_init_frame(AVFrame *frame) +{ + avcodec_get_frame_defaults(frame); + frame->reference = 3; + frame->buffer_hints = FF_BUFFER_HINTS_VALID | + FF_BUFFER_HINTS_READABLE | + FF_BUFFER_HINTS_PRESERVE | + FF_BUFFER_HINTS_REUSABLE; +} + +static av_cold int cdg_decode_init(AVCodecContext *avctx) +{ + CDGraphicsContext *cc = avctx->priv_data; + + cdg_init_frame(&cc->frame); + + avctx->width = CDG_FULL_WIDTH; + avctx->height = CDG_FULL_HEIGHT; + avctx->pix_fmt = PIX_FMT_PAL8; + + return 0; +} + +static void cdg_border_preset(CDGraphicsContext *cc, uint8_t *data) +{ + int y; + int lsize = cc->frame.linesize[0]; + uint8_t *buf = cc->frame.data[0]; + int color = data[0] & 0x0F; + + if (!(data[1] & 0x0F)) { + /// fill the top and bottom borders + memset(buf, color, CDG_BORDER_HEIGHT * lsize); + memset(buf + (CDG_FULL_HEIGHT - CDG_BORDER_HEIGHT) * lsize, + color, CDG_BORDER_HEIGHT * lsize); + + /// fill the side borders + for (y = CDG_BORDER_HEIGHT; y < CDG_FULL_HEIGHT - CDG_BORDER_HEIGHT; y++) { + memset(buf + y * lsize, color, CDG_BORDER_WIDTH); + memset(buf + CDG_FULL_WIDTH - CDG_BORDER_WIDTH + y * lsize, + color, CDG_BORDER_WIDTH); + } + } +} + +static void cdg_load_palette(CDGraphicsContext *cc, uint8_t *data, int low) +{ + uint8_t r, g, b; + uint16_t color; + int i; + int array_offset = low ? 0 : 8; + uint32_t *palette = (uint32_t *) cc->frame.data[1]; + + for (i = 0; i < 8; i++) { + color = (data[2 * i] << 6) + (data[2 * i + 1] & 0x3F); + r = ((color >> 8) & 0x000F) * 17; + g = ((color >> 4) & 0x000F) * 17; + b = ((color ) & 0x000F) * 17; + palette[i + array_offset] = r << 16 | g << 8 | b; + } + cc->frame.palette_has_changed = 1; +} + +static int cdg_tile_block(CDGraphicsContext *cc, uint8_t *data, int b) +{ + unsigned ci, ri; + int color; + int x, y; + int ai; + int stride = cc->frame.linesize[0]; + uint8_t *buf = cc->frame.data[0]; + + ri = (data[2] & 0x1F) * CDG_TILE_HEIGHT + cc->vscroll; + ci = (data[3] & 0x3F) * CDG_TILE_WIDTH + cc->hscroll; + + if (ri > (CDG_FULL_HEIGHT - CDG_TILE_HEIGHT)) + return AVERROR(EINVAL); + if (ci > (CDG_FULL_WIDTH - CDG_TILE_WIDTH)) + return AVERROR(EINVAL); + + for (y = 0; y < CDG_TILE_HEIGHT; y++) { + for (x = 0; x < CDG_TILE_WIDTH; x++) { + if (!((data[4 + y] >> (5 - x)) & 0x01)) + color = data[0] & 0x0F; + else + color = data[1] & 0x0F; + + ai = ci + x + (stride * (ri + y)); + if (b) + color ^= buf[ai]; + buf[ai] = color; + } + } + + return 0; +} + +#define UP 2 +#define DOWN 1 +#define LEFT 2 +#define RIGHT 1 + +static void cdg_copy_rect_buf(int out_tl_x, int out_tl_y, uint8_t *out, + int in_tl_x, int in_tl_y, uint8_t *in, + int w, int h, int stride) +{ + int y; + + in += in_tl_x + in_tl_y * stride; + out += out_tl_x + out_tl_y * stride; + for (y = 0; y < h; y++) + memcpy(out + y * stride, in + y * stride, w); +} + +static void cdg_fill_rect_preset(int tl_x, int tl_y, uint8_t *out, + int color, int w, int h, int stride) +{ + int y; + + for (y = tl_y; y < tl_y + h; y++) + memset(out + tl_x + y * stride, color, w); +} + +static void cdg_fill_wrapper(int out_tl_x, int out_tl_y, uint8_t *out, + int in_tl_x, int in_tl_y, uint8_t *in, + int color, int w, int h, int stride, int roll) +{ + if (roll) { + cdg_copy_rect_buf(out_tl_x, out_tl_y, out, in_tl_x, in_tl_y, + in, w, h, stride); + } else { + cdg_fill_rect_preset(out_tl_x, out_tl_y, out, color, w, h, stride); + } +} + +static void cdg_scroll(CDGraphicsContext *cc, uint8_t *data, + AVFrame *new_frame, int roll_over) +{ + int color; + int hscmd, h_off, hinc, vscmd, v_off, vinc; + int y; + int stride = cc->frame.linesize[0]; + uint8_t *in = cc->frame.data[0]; + uint8_t *out = new_frame->data[0]; + + color = data[0] & 0x0F; + hscmd = (data[1] & 0x30) >> 4; + vscmd = (data[2] & 0x30) >> 4; + + h_off = FFMIN(data[1] & 0x07, CDG_BORDER_WIDTH - 1); + v_off = FFMIN(data[2] & 0x07, CDG_BORDER_HEIGHT - 1); + + /// find the difference and save the offset for cdg_tile_block usage + hinc = h_off - cc->hscroll; + vinc = v_off - cc->vscroll; + cc->hscroll = h_off; + cc->vscroll = v_off; + + if (vscmd == UP) + vinc -= 12; + if (vscmd == DOWN) + vinc += 12; + if (hscmd == LEFT) + hinc -= 6; + if (hscmd == RIGHT) + hinc += 6; + + if (!hinc && !vinc) + return; + + memcpy(new_frame->data[1], cc->frame.data[1], CDG_PALETTE_SIZE * 4); + + for (y = FFMAX(0, vinc); y < FFMIN(CDG_FULL_HEIGHT + vinc, CDG_FULL_HEIGHT); y++) + memcpy(out + FFMAX(0, hinc) + stride * y, + in + FFMAX(0, hinc) - hinc + (y - vinc) * stride, + FFMIN(stride + hinc, stride)); + + if (vinc > 0) + cdg_fill_wrapper(0, 0, out, + 0, CDG_FULL_HEIGHT - vinc, in, color, + stride, vinc, stride, roll_over); + else if (vinc < 0) + cdg_fill_wrapper(0, CDG_FULL_HEIGHT + vinc, out, + 0, 0, in, color, + stride, -1 * vinc, stride, roll_over); + + if (hinc > 0) + cdg_fill_wrapper(0, 0, out, + CDG_FULL_WIDTH - hinc, 0, in, color, + hinc, CDG_FULL_HEIGHT, stride, roll_over); + else if (hinc < 0) + cdg_fill_wrapper(CDG_FULL_WIDTH + hinc, 0, out, + 0, 0, in, color, + -1 * hinc, CDG_FULL_HEIGHT, stride, roll_over); + +} + +static int cdg_decode_frame(AVCodecContext *avctx, + void *data, int *data_size, AVPacket *avpkt) +{ + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + int ret; + uint8_t command, inst; + uint8_t cdg_data[CDG_DATA_SIZE]; + AVFrame new_frame; + CDGraphicsContext *cc = avctx->priv_data; + + if (buf_size < CDG_MINIMUM_PKT_SIZE) { + av_log(avctx, AV_LOG_ERROR, "buffer too small for decoder\n"); + return AVERROR(EINVAL); + } + + ret = avctx->reget_buffer(avctx, &cc->frame); + if (ret) { + av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); + return ret; + } + + command = bytestream_get_byte(&buf); + inst = bytestream_get_byte(&buf); + inst &= CDG_MASK; + buf += 2; /// skipping 2 unneeded bytes + bytestream_get_buffer(&buf, cdg_data, buf_size - CDG_HEADER_SIZE); + + if ((command & CDG_MASK) == CDG_COMMAND) { + switch (inst) { + case CDG_INST_MEMORY_PRESET: + if (!(cdg_data[1] & 0x0F)) + memset(cc->frame.data[0], cdg_data[0] & 0x0F, + cc->frame.linesize[0] * CDG_FULL_HEIGHT); + break; + case CDG_INST_LOAD_PAL_LO: + case CDG_INST_LOAD_PAL_HIGH: + if (buf_size - CDG_HEADER_SIZE < CDG_DATA_SIZE) { + av_log(avctx, AV_LOG_ERROR, "buffer too small for loading palette\n"); + return AVERROR(EINVAL); + } + + cdg_load_palette(cc, cdg_data, inst == CDG_INST_LOAD_PAL_LO); + break; + case CDG_INST_BORDER_PRESET: + cdg_border_preset(cc, cdg_data); + break; + case CDG_INST_TILE_BLOCK_XOR: + case CDG_INST_TILE_BLOCK: + if (buf_size - CDG_HEADER_SIZE < CDG_DATA_SIZE) { + av_log(avctx, AV_LOG_ERROR, "buffer too small for drawing tile\n"); + return AVERROR(EINVAL); + } + + ret = cdg_tile_block(cc, cdg_data, inst == CDG_INST_TILE_BLOCK_XOR); + if (ret) { + av_log(avctx, AV_LOG_ERROR, "tile is out of range\n"); + return ret; + } + break; + case CDG_INST_SCROLL_PRESET: + case CDG_INST_SCROLL_COPY: + if (buf_size - CDG_HEADER_SIZE < CDG_MINIMUM_SCROLL_SIZE) { + av_log(avctx, AV_LOG_ERROR, "buffer too small for scrolling\n"); + return AVERROR(EINVAL); + } + + cdg_init_frame(&new_frame); + ret = avctx->get_buffer(avctx, &new_frame); + if (ret) { + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return ret; + } + + cdg_scroll(cc, cdg_data, &new_frame, inst == CDG_INST_SCROLL_COPY); + avctx->release_buffer(avctx, &cc->frame); + cc->frame = new_frame; + break; + default: + break; + } + + *data_size = sizeof(AVFrame); + } else { + *data_size = 0; + buf_size = 0; + } + + *(AVFrame *) data = cc->frame; + return buf_size; +} + +static av_cold int cdg_decode_end(AVCodecContext *avctx) +{ + CDGraphicsContext *cc = avctx->priv_data; + + if (cc->frame.data[0]) + avctx->release_buffer(avctx, &cc->frame); + + return 0; +} + +AVCodec cdgraphics_decoder = { + "cdgraphics", + AVMEDIA_TYPE_VIDEO, + CODEC_ID_CDGRAPHICS, + sizeof(CDGraphicsContext), + cdg_decode_init, + NULL, + cdg_decode_end, + cdg_decode_frame, + CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("CD Graphics video"), +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/celp_filters.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/celp_filters.c index d54e2fa709..26a62eed14 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/celp_filters.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/celp_filters.c @@ -25,10 +25,8 @@ #include "avcodec.h" #include "celp_filters.h" -void ff_celp_convolve_circ(int16_t* fc_out, - const int16_t* fc_in, - const int16_t* filter, - int len) +void ff_celp_convolve_circ(int16_t* fc_out, const int16_t* fc_in, + const int16_t* filter, int len) { int i, k; @@ -57,22 +55,16 @@ void ff_celp_circ_addf(float *out, const float *in, out[k] = in[k] + fac * lagged[ k - lag]; } -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 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 i,n; - // Avoids a +1 in the inner loop. - filter_length++; - for (n = 0; n < buffer_length; n++) { int sum = rounder; - for (i = 1; i < filter_length; i++) + for (i = 1; i <= filter_length; i++) sum -= filter_coeffs[i-1] * out[n-i]; sum = (sum >> 12) + in[n]; @@ -88,38 +80,131 @@ int ff_celp_lp_synthesis_filter(int16_t *out, return 0; } -void ff_celp_lp_synthesis_filterf(float *out, - const float* filter_coeffs, - const float* in, - int buffer_length, +void ff_celp_lp_synthesis_filterf(float *out, const float *filter_coeffs, + const float* in, int buffer_length, int filter_length) { int i,n; - // Avoids a +1 in the inner loop. - filter_length++; - +#if 0 // Unoptimized code path for improved readability for (n = 0; n < buffer_length; n++) { out[n] = in[n]; - for (i = 1; i < filter_length; i++) + for (i = 1; i <= filter_length; i++) out[n] -= filter_coeffs[i-1] * out[n-i]; } +#else + float out0, out1, out2, out3; + float old_out0, old_out1, old_out2, old_out3; + float a,b,c; + + a = filter_coeffs[0]; + b = filter_coeffs[1]; + c = filter_coeffs[2]; + b -= filter_coeffs[0] * filter_coeffs[0]; + c -= filter_coeffs[1] * filter_coeffs[0]; + c -= filter_coeffs[0] * b; + + old_out0 = out[-4]; + old_out1 = out[-3]; + old_out2 = out[-2]; + old_out3 = out[-1]; + for (n = 0; n <= buffer_length - 4; n+=4) { + float tmp0,tmp1,tmp2,tmp3; + float val; + + out0 = in[0]; + out1 = in[1]; + out2 = in[2]; + out3 = in[3]; + + out0 -= filter_coeffs[2] * old_out1; + out1 -= filter_coeffs[2] * old_out2; + out2 -= filter_coeffs[2] * old_out3; + + out0 -= filter_coeffs[1] * old_out2; + out1 -= filter_coeffs[1] * old_out3; + + out0 -= filter_coeffs[0] * old_out3; + + val = filter_coeffs[3]; + + out0 -= val * old_out0; + out1 -= val * old_out1; + out2 -= val * old_out2; + out3 -= val * old_out3; + + old_out3 = out[-5]; + + for (i = 5; i <= filter_length; i += 2) { + val = filter_coeffs[i-1]; + + out0 -= val * old_out3; + out1 -= val * old_out0; + out2 -= val * old_out1; + out3 -= val * old_out2; + + old_out2 = out[-i-1]; + + val = filter_coeffs[i]; + + out0 -= val * old_out2; + out1 -= val * old_out3; + out2 -= val * old_out0; + out3 -= val * old_out1; + + FFSWAP(float, old_out0, old_out2); + old_out1 = old_out3; + old_out3 = out[-i-2]; + } + + tmp0 = out0; + tmp1 = out1; + tmp2 = out2; + tmp3 = out3; + + out3 -= a * tmp2; + out2 -= a * tmp1; + out1 -= a * tmp0; + + out3 -= b * tmp1; + out2 -= b * tmp0; + + out3 -= c * tmp0; + + + out[0] = out0; + out[1] = out1; + out[2] = out2; + out[3] = out3; + + old_out0 = out0; + old_out1 = out1; + old_out2 = out2; + old_out3 = out3; + + out += 4; + in += 4; + } + + out -= n; + in -= n; + for (; n < buffer_length; n++) { + out[n] = in[n]; + for (i = 1; i <= filter_length; i++) + out[n] -= filter_coeffs[i-1] * out[n-i]; + } +#endif } -void ff_celp_lp_zero_synthesis_filterf(float *out, - const float* filter_coeffs, - const float* in, - int buffer_length, +void ff_celp_lp_zero_synthesis_filterf(float *out, const float *filter_coeffs, + const float *in, int buffer_length, int filter_length) { int i,n; - // Avoids a +1 in the inner loop. - filter_length++; - for (n = 0; n < buffer_length; n++) { out[n] = in[n]; - for (i = 1; i < filter_length; i++) + for (i = 1; i <= filter_length; i++) out[n] += filter_coeffs[i-1] * in[n-i]; } } diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/celp_filters.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/celp_filters.h index d9db95d454..7b64fc0306 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/celp_filters.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/celp_filters.h @@ -36,10 +36,8 @@ * * \note fc_in and fc_out should not overlap! */ -void ff_celp_convolve_circ(int16_t* fc_out, - const int16_t* fc_in, - const int16_t* filter, - int len); +void ff_celp_convolve_circ(int16_t *fc_out, const int16_t *fc_in, + const int16_t *filter, int len); /** * Add an array to a rotated array. @@ -74,12 +72,9 @@ void ff_celp_circ_addf(float *out, const float *in, * * Routine applies 1/A(z) filter to given speech data. */ -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 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); /** @@ -90,17 +85,16 @@ int ff_celp_lp_synthesis_filter(int16_t *out, * @param filter_coeffs filter coefficients. * @param in input signal * @param buffer_length amount of data to process - * @param filter_length filter length (10 for 10th order LP filter) + * @param filter_length filter length (10 for 10th order LP filter). Must be + * greater than 4 and even. * * @note Output buffer must contain filter_length samples of past * speech data before pointer. * * Routine applies 1/A(z) filter to given speech data. */ -void ff_celp_lp_synthesis_filterf(float *out, - const float* filter_coeffs, - const float* in, - int buffer_length, +void ff_celp_lp_synthesis_filterf(float *out, const float *filter_coeffs, + const float *in, int buffer_length, int filter_length); /** @@ -118,10 +112,8 @@ void ff_celp_lp_synthesis_filterf(float *out, * * Routine applies A(z) filter to given speech data. */ -void ff_celp_lp_zero_synthesis_filterf(float *out, - const float* filter_coeffs, - const float* in, - int buffer_length, +void ff_celp_lp_zero_synthesis_filterf(float *out, const float *filter_coeffs, + const float *in, int buffer_length, int filter_length); #endif /* AVCODEC_CELP_FILTERS_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/cinepak.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/cinepak.c index 45ca1a93e3..8e7aa5aa99 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/cinepak.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/cinepak.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/cinepak.c + * @file * Cinepak video decoder * by Ewald Snel * For more information on the Cinepak algorithm, visit: @@ -457,7 +457,7 @@ static av_cold int cinepak_decode_end(AVCodecContext *avctx) AVCodec cinepak_decoder = { "cinepak", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_CINEPAK, sizeof(CinepakContext), cinepak_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/cljr.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/cljr.c index 2164bf20f4..47809c0ce4 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/cljr.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/cljr.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/cljr.c + * @file * Cirrus Logic AccuPak codec. */ @@ -137,7 +137,7 @@ static av_cold int encode_init(AVCodecContext *avctx){ AVCodec cljr_decoder = { "cljr", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_CLJR, sizeof(CLJRContext), decode_init, @@ -151,7 +151,7 @@ AVCodec cljr_decoder = { #if CONFIG_CLJR_ENCODER AVCodec cljr_encoder = { "cljr", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_CLJR, sizeof(CLJRContext), encode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/colorspace.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/colorspace.h index cdadbb3d1c..4ec081e9d2 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/colorspace.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/colorspace.h @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/colorspace.h + * @file * Various defines for YUV<->RGB conversion */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/cook.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/cook.c index b90949fb70..e406e6510e 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/cook.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/cook.c @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/cook.c + * @file * Cook compatible decoder. Bastardization of the G.722.1 standard. * This decoder handles RealNetworks, RealAudio G2 data. * Cook is identified by the codec name cook in RM files. @@ -52,6 +52,7 @@ #include "get_bits.h" #include "dsputil.h" #include "bytestream.h" +#include "fft.h" #include "cookdata.h" @@ -136,7 +137,7 @@ typedef struct cook { AVLFG random_state; /* transform data */ - MDCTContext mdct_ctx; + FFTContext mdct_ctx; float* mlt_window; /* VLC data */ @@ -150,7 +151,7 @@ typedef struct cook { /* data buffers */ uint8_t* decoded_bytes_buffer; - DECLARE_ALIGNED_16(float,mono_mdct_output[2048]); + DECLARE_ALIGNED(16, float,mono_mdct_output)[2048]; float decode_buffer_1[1024]; float decode_buffer_2[1024]; float decode_buffer_0[1060]; /* static allocation for joint decode */ @@ -1101,7 +1102,7 @@ static av_cold int cook_decode_init(AVCodecContext *avctx) q->bit_rate = avctx->bit_rate; /* Initialize RNG. */ - av_lfg_init(&q->random_state, ff_random_get_seed()); + av_lfg_init(&q->random_state, 0); while(edata_ptr < edata_ptr_end){ /* 8 for mono, 16 for stereo, ? for multichannel @@ -1287,7 +1288,7 @@ static av_cold int cook_decode_init(AVCodecContext *avctx) AVCodec cook_decoder = { .name = "cook", - .type = CODEC_TYPE_AUDIO, + .type = AVMEDIA_TYPE_AUDIO, .id = CODEC_ID_COOK, .priv_data_size = sizeof(COOKContext), .init = cook_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/cookdata.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/cookdata.h index e2e81fbab6..15e8e9519f 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/cookdata.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/cookdata.h @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/cookdata.h + * @file * Cook AKA RealAudio G2 compatible decoderdata */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/costablegen.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/costablegen.c new file mode 100644 index 0000000000..bfcd6356a0 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/costablegen.c @@ -0,0 +1,56 @@ +/* + * Generate a header file for hardcoded ff_cos_* tables + * + * Copyright (c) 2009 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 +#include +#include + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif +#define BITS 16 +#define FLOATFMT "%.18e" + +int main(int argc, char *argv[]) +{ + int i, j; + int do_sin = argc == 2 && !strcmp(argv[1], "sin"); + double (*func)(double) = do_sin ? sin : cos; + + printf("/* This file was generated by libavcodec/costablegen */\n"); + printf("#include \"libavcodec/fft.h\"\n"); + for (i = 4; i <= BITS; i++) { + int m = 1 << i; + double freq = 2*M_PI/m; + printf("%s(%i) = {\n ", do_sin ? "SINTABLE" : "COSTABLE", m); + for (j = 0; j < m/2 - 1; j++) { + int idx = j > m/4 ? m/2 - j : j; + if (do_sin && j >= m/4) + idx = m/4 - j; + printf(" "FLOATFMT",", func(idx*freq)); + if ((j & 3) == 3) + printf("\n "); + } + printf(" "FLOATFMT"\n};\n", func(do_sin ? -(m/4 - 1)*freq : freq)); + } + return 0; +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/cscd.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/cscd.c index e58cf7861d..e4f4b8f825 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/cscd.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/cscd.c @@ -216,9 +216,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, static av_cold int decode_init(AVCodecContext *avctx) { CamStudioContext *c = avctx->priv_data; - if (avcodec_check_dimensions(avctx, avctx->height, avctx->width) < 0) { - return 1; - } switch (avctx->bits_per_coded_sample) { case 16: avctx->pix_fmt = PIX_FMT_RGB555; break; case 24: avctx->pix_fmt = PIX_FMT_BGR24; break; @@ -252,7 +249,7 @@ static av_cold int decode_end(AVCodecContext *avctx) { AVCodec cscd_decoder = { "camstudio", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_CSCD, sizeof(CamStudioContext), decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/cyuv.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/cyuv.c index 41be0c661b..db7e690be7 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/cyuv.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/cyuv.c @@ -24,7 +24,7 @@ */ /** - * @file libavcodec/cyuv.c + * @file * Creative YUV (CYUV) Video Decoder. */ @@ -82,26 +82,29 @@ static int cyuv_decode_frame(AVCodecContext *avctx, unsigned char cur_byte; int pixel_groups; + if (avctx->codec_id == CODEC_ID_AURA) { + y_table = u_table; + u_table = v_table; + } /* sanity check the buffer size: A buffer has 3x16-bytes tables * followed by (height) lines each with 3 bytes to represent groups * of 4 pixels. Thus, the total size of the buffer ought to be: * (3 * 16) + height * (width * 3 / 4) */ if (buf_size != 48 + s->height * (s->width * 3 / 4)) { - av_log(avctx, AV_LOG_ERROR, "ffmpeg: cyuv: got a buffer with %d bytes when %d were expected\n", - buf_size, - 48 + s->height * (s->width * 3 / 4)); - return -1; + av_log(avctx, AV_LOG_ERROR, "got a buffer with %d bytes when %d were expected\n", + buf_size, 48 + s->height * (s->width * 3 / 4)); + return -1; } /* pixel data starts 48 bytes in, after 3x16-byte tables */ stream_ptr = 48; - if(s->frame.data[0]) + if (s->frame.data[0]) avctx->release_buffer(avctx, &s->frame); s->frame.buffer_hints = FF_BUFFER_HINTS_VALID; s->frame.reference = 0; - if(avctx->get_buffer(avctx, &s->frame) < 0) { + if (avctx->get_buffer(avctx, &s->frame) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return -1; } @@ -164,17 +167,44 @@ static int cyuv_decode_frame(AVCodecContext *avctx, return buf_size; } +static av_cold int cyuv_decode_end(AVCodecContext *avctx) +{ + CyuvDecodeContext *s = avctx->priv_data; + + if (s->frame.data[0]) + avctx->release_buffer(avctx, &s->frame); + + return 0; +} + +#if CONFIG_AURA_DECODER +AVCodec 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, + .long_name = NULL_IF_CONFIG_SMALL("Auravision AURA"), +}; +#endif + +#if CONFIG_CYUV_DECODER AVCodec cyuv_decoder = { "cyuv", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_CYUV, sizeof(CyuvDecodeContext), cyuv_decode_init, NULL, - NULL, + cyuv_decode_end, cyuv_decode_frame, CODEC_CAP_DR1, NULL, .long_name = NULL_IF_CONFIG_SMALL("Creative YUV (CYUV)"), }; - +#endif diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dca.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/dca.c index b42d3df083..10bc956e98 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/dca.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dca.c @@ -22,21 +22,22 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/** - * @file libavcodec/dca.c - */ - #include #include #include +#include "libavutil/intmath.h" +#include "libavutil/intreadwrite.h" #include "avcodec.h" #include "dsputil.h" +#include "fft.h" #include "get_bits.h" #include "put_bits.h" #include "dcadata.h" #include "dcahuff.h" #include "dca.h" +#include "synth_filter.h" +#include "dcadsp.h" //#define TRACE @@ -227,15 +228,16 @@ typedef struct { /* Subband samples history (for ADPCM) */ float subband_samples_hist[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][4]; - DECLARE_ALIGNED_16(float, subband_fir_hist[DCA_PRIM_CHANNELS_MAX][512]); - float subband_fir_noidea[DCA_PRIM_CHANNELS_MAX][32]; + DECLARE_ALIGNED(16, float, subband_fir_hist)[DCA_PRIM_CHANNELS_MAX][512]; + DECLARE_ALIGNED(16, float, subband_fir_noidea)[DCA_PRIM_CHANNELS_MAX][32]; int hist_index[DCA_PRIM_CHANNELS_MAX]; + DECLARE_ALIGNED(16, float, raXin)[32]; int output; ///< type of output float add_bias; ///< output bias float scale_bias; ///< output scale - DECLARE_ALIGNED_16(float, samples[1536]); /* 6 * 256 = 1536, might only need 5 */ + DECLARE_ALIGNED(16, float, samples)[1536]; /* 6 * 256 = 1536, might only need 5 */ const float *samples_chanptr[6]; uint8_t dca_buffer[DCA_MAX_FRAME_SIZE]; @@ -249,7 +251,9 @@ typedef struct { int debug_flag; ///< used for suppressing repeated error messages output DSPContext dsp; - MDCTContext imdct; + FFTContext imdct; + SynthFilterContext synth; + DCADSPContext dcadsp; } DCAContext; static const uint16_t dca_vlc_offs[] = { @@ -608,7 +612,7 @@ static int dca_subframe_header(DCAContext * s) s->joint_scale_factor[j][k] = scale; /*joint_scale_table[scale]; */ } - if (!s->debug_flag & 0x02) { + if (!(s->debug_flag & 0x02)) { av_log(s->avctx, AV_LOG_DEBUG, "Joint stereo coding not supported\n"); s->debug_flag |= 0x02; @@ -750,12 +754,9 @@ static void qmf_32_subbands(DCAContext * s, int chans, float scale, float bias) { const float *prCoeff; - int i, j; - DECLARE_ALIGNED_16(float, raXin[32]); - - int hist_index= s->hist_index[chans]; - float *subband_fir_hist2 = s->subband_fir_noidea[chans]; + int i; + int sb_act = s->subband_activity[chans]; int subindex; scale *= sqrt(1/8.0); @@ -768,48 +769,24 @@ static void qmf_32_subbands(DCAContext * s, int chans, /* Reconstructed channel sample index */ for (subindex = 0; subindex < 8; subindex++) { - float *subband_fir_hist = s->subband_fir_hist[chans] + hist_index; /* Load in one sample from each subband and clear inactive subbands */ - for (i = 0; i < s->subband_activity[chans]; i++){ - if((i-1)&2) raXin[i] = -samples_in[i][subindex]; - else raXin[i] = samples_in[i][subindex]; + for (i = 0; i < sb_act; i++){ + uint32_t v = AV_RN32A(&samples_in[i][subindex]) ^ ((i-1)&2)<<30; + AV_WN32A(&s->raXin[i], v); } for (; i < 32; i++) - raXin[i] = 0.0; + s->raXin[i] = 0.0; - ff_imdct_half(&s->imdct, subband_fir_hist, raXin); - - /* Multiply by filter coefficients */ - for (i = 0; i < 16; i++){ - float a= subband_fir_hist2[i ]; - float b= subband_fir_hist2[i+16]; - float c= 0; - float d= 0; - for (j = 0; j < 512-hist_index; j += 64){ - a += prCoeff[i+j ]*(-subband_fir_hist[15-i+j]); - b += prCoeff[i+j+16]*( subband_fir_hist[ i+j]); - c += prCoeff[i+j+32]*( subband_fir_hist[16+i+j]); - d += prCoeff[i+j+48]*( subband_fir_hist[31-i+j]); - } - for ( ; j < 512; j += 64){ - a += prCoeff[i+j ]*(-subband_fir_hist[15-i+j-512]); - b += prCoeff[i+j+16]*( subband_fir_hist[ i+j-512]); - c += prCoeff[i+j+32]*( subband_fir_hist[16+i+j-512]); - d += prCoeff[i+j+48]*( subband_fir_hist[31-i+j-512]); - } - samples_out[i ] = a * scale + bias; - samples_out[i+16] = b * scale + bias; - subband_fir_hist2[i ] = c; - subband_fir_hist2[i+16] = d; - } + s->synth.synth_filter_float(&s->imdct, + s->subband_fir_hist[chans], &s->hist_index[chans], + s->subband_fir_noidea[chans], prCoeff, + samples_out, s->raXin, scale, bias); samples_out+= 32; - hist_index = (hist_index-32)&511; } - s->hist_index[chans]= hist_index; } -static void lfe_interpolation_fir(int decimation_select, +static void lfe_interpolation_fir(DCAContext *s, int decimation_select, int num_deci_sample, float *samples_in, float *samples_out, float scale, float bias) @@ -822,30 +799,24 @@ static void lfe_interpolation_fir(int decimation_select, * samples_out: An array holding interpolated samples */ - int decifactor, k, j; + int decifactor; const float *prCoeff; - - int interp_index = 0; /* Index to the interpolated samples */ int deciindex; /* Select decimation filter */ if (decimation_select == 1) { - decifactor = 128; + decifactor = 64; prCoeff = lfe_fir_128; } else { - decifactor = 64; + decifactor = 32; prCoeff = lfe_fir_64; } /* Interpolation */ for (deciindex = 0; deciindex < num_deci_sample; deciindex++) { - /* One decimated sample generates decifactor interpolated ones */ - for (k = 0; k < decifactor; k++) { - float rTmp = 0.0; - //FIXME the coeffs are symetric, fix that - for (j = 0; j < 512 / decifactor; j++) - rTmp += samples_in[deciindex - j] * prCoeff[k + j * decifactor]; - samples_out[interp_index++] = (rTmp * scale) + bias; - } + s->dcadsp.lfe_fir(samples_out, samples_in, prCoeff, decifactor, + scale, bias); + samples_in++; + samples_out += 2 * decifactor; } } @@ -920,8 +891,9 @@ static int decode_blockcode(int code, int levels, int *values) int offset = (levels - 1) >> 1; for (i = 0; i < 4; i++) { - values[i] = (code % levels) - offset; - code /= levels; + int div = FASTDIV(code, levels); + values[i] = code - offset - div*levels; + code = div; } if (code == 0) @@ -943,7 +915,8 @@ static int dca_subsubframe(DCAContext * s) const float *quant_step_table; /* FIXME */ - float subband_samples[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][8]; + LOCAL_ALIGNED_16(float, subband_samples, [DCA_PRIM_CHANNELS_MAX], [DCA_SUBBANDS][8]); + LOCAL_ALIGNED_16(int, block, [8]); /* * Audio data @@ -963,7 +936,6 @@ static int dca_subsubframe(DCAContext * s) int abits = s->bitalloc[k][l]; float quant_step_size = quant_step_table[abits]; - float rscale; /* * Determine quantization index code book and its type @@ -977,45 +949,39 @@ static int dca_subsubframe(DCAContext * s) */ if(!abits){ memset(subband_samples[k][l], 0, 8 * sizeof(subband_samples[0][0][0])); - }else if(abits >= 11 || !dca_smpl_bitalloc[abits].vlc[sel].table){ - if(abits <= 7){ - /* Block code */ - int block_code1, block_code2, size, levels; - int block[8]; + } else { + /* Deal with transients */ + int sfi = s->transition_mode[k][l] && subsubframe >= s->transition_mode[k][l]; + float rscale = quant_step_size * s->scale_factor[k][l][sfi] * s->scalefactor_adj[k][sel]; - size = abits_sizes[abits-1]; - levels = abits_levels[abits-1]; + if(abits >= 11 || !dca_smpl_bitalloc[abits].vlc[sel].table){ + if(abits <= 7){ + /* Block code */ + int block_code1, block_code2, size, levels; - block_code1 = get_bits(&s->gb, size); - /* FIXME Should test return value */ - decode_blockcode(block_code1, levels, block); - block_code2 = get_bits(&s->gb, size); - decode_blockcode(block_code2, levels, &block[4]); - for (m = 0; m < 8; m++) - subband_samples[k][l][m] = block[m]; + size = abits_sizes[abits-1]; + levels = abits_levels[abits-1]; + + block_code1 = get_bits(&s->gb, size); + /* FIXME Should test return value */ + decode_blockcode(block_code1, levels, block); + block_code2 = get_bits(&s->gb, size); + decode_blockcode(block_code2, levels, &block[4]); + }else{ + /* no coding */ + for (m = 0; m < 8; m++) + block[m] = get_sbits(&s->gb, abits - 3); + } }else{ - /* no coding */ + /* Huffman coded */ for (m = 0; m < 8; m++) - subband_samples[k][l][m] = get_sbits(&s->gb, abits - 3); + block[m] = get_bitalloc(&s->gb, &dca_smpl_bitalloc[abits], sel); } - }else{ - /* Huffman coded */ - for (m = 0; m < 8; m++) - subband_samples[k][l][m] = get_bitalloc(&s->gb, &dca_smpl_bitalloc[abits], sel); + + s->dsp.int32_to_float_fmul_scalar(subband_samples[k][l], + block, rscale, 8); } - /* Deal with transients */ - if (s->transition_mode[k][l] && - subsubframe >= s->transition_mode[k][l]) - rscale = quant_step_size * s->scale_factor[k][l][1]; - else - rscale = quant_step_size * s->scale_factor[k][l][0]; - - rscale *= s->scalefactor_adj[k][sel]; - - for (m = 0; m < 8; m++) - subband_samples[k][l][m] *= rscale; - /* * Inverse ADPCM if in prediction mode */ @@ -1094,7 +1060,7 @@ static int dca_subsubframe(DCAContext * s) if (s->output & DCA_LFE) { int lfe_samples = 2 * s->lfe * s->subsubframes; - lfe_interpolation_fir(s->lfe, 2 * s->lfe, + lfe_interpolation_fir(s, s->lfe, 2 * s->lfe, s->lfe_data + lfe_samples + 2 * s->lfe * subsubframe, &s->samples[256 * dca_lfe_index[s->amode]], @@ -1270,6 +1236,10 @@ static int dca_decode_frame(AVCodecContext * avctx, } else s->channel_order_tab = dca_channel_reorder_nolfe[s->amode]; + if (s->prim_channels > 0 && + s->channel_order_tab[s->prim_channels - 1] < 0) + return -1; + if(avctx->request_channels == 2 && s->prim_channels > 2) { channels = 2; s->output = DCA_STEREO; @@ -1319,12 +1289,14 @@ static av_cold int dca_decode_init(AVCodecContext * avctx) dsputil_init(&s->dsp, avctx); ff_mdct_init(&s->imdct, 6, 1, 1.0); + ff_synth_filter_init(&s->synth); + ff_dcadsp_init(&s->dcadsp); for(i = 0; i < 6; i++) s->samples_chanptr[i] = s->samples + i * 256; avctx->sample_fmt = SAMPLE_FMT_S16; - if(s->dsp.float_to_int16 == ff_float_to_int16_c) { + if(s->dsp.float_to_int16_interleave == ff_float_to_int16_interleave_c) { s->add_bias = 385.0f; s->scale_bias = 1.0 / 32768.0; } else { @@ -1351,7 +1323,7 @@ static av_cold int dca_decode_end(AVCodecContext * avctx) AVCodec dca_decoder = { .name = "dca", - .type = CODEC_TYPE_AUDIO, + .type = AVMEDIA_TYPE_AUDIO, .id = CODEC_ID_DTS, .priv_data_size = sizeof(DCAContext), .init = dca_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dca_parser.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/dca_parser.c index 49b2ecd3f5..01c559709a 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/dca_parser.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dca_parser.c @@ -22,10 +22,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/** - * @file libavcodec/dca_parser.c - */ - #include "parser.h" #include "dca.h" diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dcadata.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/dcadata.h index 1ee7c5837a..fbd22ab211 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/dcadata.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dcadata.h @@ -20,14 +20,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/** - * @file libavcodec/dcadata.h - */ - #ifndef AVCODEC_DCADATA_H #define AVCODEC_DCADATA_H #include +#include "libavutil/mem.h" /* Generic tables */ @@ -6282,7 +6279,7 @@ static const int8_t high_freq_vq[1024][32] = /* FIR filter coefficients, they can be cut on half and maybe use float instead of double*/ -static const float fir_32bands_perfect[] = +DECLARE_ALIGNED(16, static const float, fir_32bands_perfect)[] = { +1.135985195E-010, +7.018770981E-011, @@ -6798,7 +6795,7 @@ static const float fir_32bands_perfect[] = -1.135985195E-010 }; -static const float fir_32bands_nonperfect[] = +DECLARE_ALIGNED(16, static const float, fir_32bands_nonperfect)[] = { -1.390191784E-007, -1.693738625E-007, @@ -7314,1039 +7311,204 @@ static const float fir_32bands_nonperfect[] = +1.390191784E-007 }; -//FIXME the coeffs are symmetric -static const float lfe_fir_64[] = +DECLARE_ALIGNED(16, static const float, lfe_fir_64)[] = { -2.6584343868307770E-004, -8.1793652498163280E-005, -9.4393239123746760E-005, -1.0821702744578940E-004, -1.2333714403212070E-004, -1.3974857574794440E-004, -1.5759580128360540E-004, -1.7699223826639360E-004, -1.9817386055365200E-004, -2.2118473134469240E-004, -2.4602311896160240E-004, -2.7261159266345200E-004, -3.0138631700538100E-004, -3.3283955417573450E-004, -3.6589911906048660E-004, -4.0182814700528980E-004, -4.4018754852004350E-004, -4.8127761692740020E-004, -5.2524596685543660E-004, -5.7215924607589840E-004, -6.2221300322562460E-004, -6.7555153509601950E-004, -7.3241489008069040E-004, -7.9285167157649990E-004, -8.5701106581836940E-004, -9.2511920956894760E-004, -9.9747709464281800E-004, -1.0739302961155770E-003, -1.1550235794857140E-003, -1.2406768510118130E-003, -1.3312589144334200E-003, -1.4268938684836030E-003, -1.5278297942131760E-003, -1.6342115122824910E-003, -1.7463274998590350E-003, -1.8643775256350640E-003, -1.9886041991412640E-003, -2.1191518753767010E-003, -2.2563596721738580E-003, -2.4004334118217230E-003, -2.5515670422464610E-003, -2.7100932784378530E-003, -2.8761904686689380E-003, -3.0501529108732940E-003, -3.2322725746780640E-003, -3.4227769356220960E-003, -3.6219672765582800E-003, -3.8300913292914630E-003, -4.0474990382790560E-003, -4.2744171805679800E-003, -4.5111598446965220E-003, -4.7580120153725150E-003, -5.0153112970292570E-003, -5.2832840010523800E-003, -5.5623454973101620E-003, -5.8526843786239620E-003, -6.1547122895717620E-003, -6.4686913974583150E-003, -6.7949919030070300E-003, -7.1338820271193980E-003, -7.4857366271317010E-003, -7.8508658334612850E-003, -8.2296309992671010E-003, -8.6223213002085690E-003, -9.0293306857347480E-003, -9.4509534537792200E-003, -9.8875602707266800E-003, -1.0339494794607160E-002, -1.0807084850966930E-002, -1.1290682479739190E-002, -1.1790650896728040E-002, -1.2307321652770040E-002, -1.2841059826314450E-002, -1.3392185792326930E-002, -1.3961089774966240E-002, -1.4548087492585180E-002, -1.5153550542891020E-002, -1.5777811408042910E-002, -1.6421230509877200E-002, -1.7084129154682160E-002, -1.7766902223229410E-002, -1.8469827249646190E-002, -1.9193304702639580E-002, -1.9937623292207720E-002, -2.0703161135315900E-002, -2.1490212529897690E-002, -2.2299138829112050E-002, -2.3130238056182860E-002, -2.3983856663107870E-002, -2.4860285222530360E-002, -2.5759860873222350E-002, -2.6682861149311060E-002, -2.7629608288407320E-002, -2.8600392863154410E-002, -2.9595496132969860E-002, -3.0615204945206640E-002, -3.1659796833992000E-002, -3.2729536294937140E-002, -3.3824689686298370E-002, -3.4945506602525710E-002, -3.6092240363359450E-002, -3.7265110760927200E-002, -3.8464374840259550E-002, -3.9690230041742320E-002, -4.0942888706922530E-002, -4.2222552001476290E-002, -4.3529424816370010E-002, -4.4863656163215640E-002, -4.6225443482398990E-002, -4.7614917159080510E-002, -4.9032241106033330E-002, -5.0477534532547000E-002, -5.1950931549072270E-002, -5.3452525287866590E-002, -5.4982420057058330E-002, -5.6540694087743760E-002, -5.8127421885728840E-002, -5.9742655605077740E-002, -6.1386436223983760E-002, -6.3058786094188690E-002, -6.4759708940982820E-002, -6.6489234566688540E-002, -6.8247318267822270E-002, -7.0033922791481020E-002, -7.1849010884761810E-002, -7.3692522943019870E-002, -7.5564362108707430E-002, -7.7464438974857330E-002, -7.9392634332180020E-002, -8.1348828971385960E-002, -8.3332858979702000E-002, -8.5344567894935610E-002, -8.7383769452571870E-002, -8.9450262486934660E-002, -9.1543838381767280E-002, -9.3664251267910000E-002, -9.5811240375041960E-002, -9.7984537482261660E-002, -1.0018386691808700E-001, -1.0240890830755230E-001, -1.0465932637453080E-001, -1.0693479329347610E-001, -1.0923493653535840E-001, -1.1155936866998670E-001, -1.1390769481658940E-001, -1.1627949774265290E-001, -1.1867434531450270E-001, -1.2109176814556120E-001, -1.2353130429983140E-001, -1.2599244713783260E-001, -1.2847468256950380E-001, -1.3097748160362240E-001, -1.3350030779838560E-001, -1.3604259490966800E-001, -1.3860376179218290E-001, -1.4118319749832150E-001, -1.4378026127815250E-001, -1.4639437198638920E-001, -1.4902481436729430E-001, -1.5167096257209780E-001, -1.5433208644390100E-001, -1.5700751543045040E-001, -1.5969651937484740E-001, -1.6239835321903230E-001, -1.6511227190494540E-001, -1.6783750057220460E-001, -1.7057323455810550E-001, -1.7331869900226590E-001, -1.7607308924198150E-001, -1.7883554100990300E-001, -1.8160524964332580E-001, -1.8438133597373960E-001, -1.8716295063495640E-001, -1.8994916975498200E-001, -1.9273911416530610E-001, -1.9553191959857940E-001, -1.9832661747932440E-001, -2.0112232863903040E-001, -2.0391805469989780E-001, -2.0671287178993220E-001, -2.0950584113597870E-001, -2.1229594945907590E-001, -2.1508227288722990E-001, -2.1786379814147950E-001, -2.2063951194286350E-001, -2.2340846061706540E-001, -2.2616961598396300E-001, -2.2892196476459500E-001, -2.3166447877883910E-001, -2.3439615964889520E-001, -2.3711597919464110E-001, -2.3982289433479310E-001, -2.4251587688922880E-001, -2.4519388377666480E-001, -2.4785590171813960E-001, -2.5050088763237000E-001, -2.5312781333923340E-001, -2.5573557615280150E-001, -2.5832322239875800E-001, -2.6088967919349670E-001, -2.6343390345573420E-001, -2.6595494151115420E-001, -2.6845166087150580E-001, -2.7092313766479490E-001, -2.7336826920509340E-001, -2.7578607201576240E-001, -2.7817553281784060E-001, -2.8053569793701170E-001, -2.8286558389663700E-001, -2.8516408801078800E-001, -2.8743034601211550E-001, -2.8966337442398070E-001, -2.9186218976974480E-001, -2.9402589797973640E-001, -2.9615348577499390E-001, -2.9824411869049070E-001, -3.0029675364494320E-001, -3.0231067538261420E-001, -3.0428490042686460E-001, -3.0621853470802300E-001, -3.0811080336570740E-001, -3.0996081233024600E-001, -3.1176769733428960E-001, -3.1353080272674560E-001, -3.1524917483329780E-001, -3.1692212820053100E-001, -3.1854888796806340E-001, -3.2012873888015740E-001, -3.2166096568107600E-001, -3.2314485311508180E-001, -3.2457971572875980E-001, -3.2596495747566220E-001, -3.2729989290237420E-001, -3.2858389616012580E-001, -3.2981643080711360E-001, -3.3099696040153500E-001, -3.3212485909461980E-001, -3.3319962024688720E-001, -3.3422079682350160E-001, -3.3518791198730470E-001, -3.3610042929649360E-001, -3.3695802092552180E-001, -3.3776029944419860E-001, -3.3850681781768800E-001, -3.3919724822044380E-001, -3.3983129262924200E-001, -3.4040865302085880E-001, -3.4092903137207030E-001, -3.4139221906661980E-001, -3.4179797768592840E-001, -3.4214612841606140E-001, -3.4243649244308470E-001, -3.4266895055770880E-001, -3.4284341335296630E-001, -3.4295973181724550E-001, -3.4301793575286860E-001, -3.4301793575286860E-001, -3.4295973181724550E-001, -3.4284341335296630E-001, -3.4266895055770880E-001, -3.4243649244308470E-001, -3.4214612841606140E-001, -3.4179797768592840E-001, -3.4139221906661980E-001, -3.4092903137207030E-001, -3.4040865302085880E-001, -3.3983129262924200E-001, -3.3919724822044380E-001, -3.3850681781768800E-001, -3.3776029944419860E-001, -3.3695802092552180E-001, -3.3610042929649360E-001, -3.3518791198730470E-001, -3.3422079682350160E-001, -3.3319962024688720E-001, -3.3212485909461980E-001, -3.3099696040153500E-001, -3.2981643080711360E-001, -3.2858389616012580E-001, -3.2729989290237420E-001, -3.2596495747566220E-001, -3.2457971572875980E-001, -3.2314485311508180E-001, -3.2166096568107600E-001, -3.2012873888015740E-001, -3.1854888796806340E-001, -3.1692212820053100E-001, -3.1524917483329780E-001, -3.1353080272674560E-001, -3.1176769733428960E-001, -3.0996081233024600E-001, -3.0811080336570740E-001, -3.0621853470802300E-001, -3.0428490042686460E-001, -3.0231067538261420E-001, -3.0029675364494320E-001, -2.9824411869049070E-001, -2.9615348577499390E-001, -2.9402589797973640E-001, -2.9186218976974480E-001, -2.8966337442398070E-001, -2.8743034601211550E-001, -2.8516408801078800E-001, -2.8286558389663700E-001, -2.8053569793701170E-001, -2.7817553281784060E-001, -2.7578607201576240E-001, -2.7336826920509340E-001, -2.7092313766479490E-001, -2.6845166087150580E-001, -2.6595494151115420E-001, -2.6343390345573420E-001, -2.6088967919349670E-001, -2.5832322239875800E-001, -2.5573557615280150E-001, -2.5312781333923340E-001, -2.5050088763237000E-001, -2.4785590171813960E-001, -2.4519388377666480E-001, -2.4251587688922880E-001, -2.3982289433479310E-001, -2.3711597919464110E-001, -2.3439615964889520E-001, -2.3166447877883910E-001, -2.2892196476459500E-001, -2.2616961598396300E-001, -2.2340846061706540E-001, -2.2063951194286350E-001, -2.1786379814147950E-001, -2.1508227288722990E-001, -2.1229594945907590E-001, -2.0950584113597870E-001, -2.0671287178993220E-001, -2.0391805469989780E-001, -2.0112232863903040E-001, -1.9832661747932440E-001, -1.9553191959857940E-001, -1.9273911416530610E-001, -1.8994916975498200E-001, -1.8716295063495640E-001, -1.8438133597373960E-001, -1.8160524964332580E-001, -1.7883554100990300E-001, -1.7607308924198150E-001, -1.7331869900226590E-001, -1.7057323455810550E-001, -1.6783750057220460E-001, -1.6511227190494540E-001, -1.6239835321903230E-001, -1.5969651937484740E-001, -1.5700751543045040E-001, -1.5433208644390100E-001, -1.5167096257209780E-001, -1.4902481436729430E-001, -1.4639437198638920E-001, -1.4378026127815250E-001, -1.4118319749832150E-001, -1.3860376179218290E-001, -1.3604259490966800E-001, -1.3350030779838560E-001, -1.3097748160362240E-001, -1.2847468256950380E-001, -1.2599244713783260E-001, -1.2353130429983140E-001, -1.2109176814556120E-001, -1.1867434531450270E-001, -1.1627949774265290E-001, -1.1390769481658940E-001, -1.1155936866998670E-001, -1.0923493653535840E-001, -1.0693479329347610E-001, -1.0465932637453080E-001, -1.0240890830755230E-001, -1.0018386691808700E-001, -9.7984537482261660E-002, -9.5811240375041960E-002, -9.3664251267910000E-002, -9.1543838381767280E-002, -8.9450262486934660E-002, -8.7383769452571870E-002, -8.5344567894935610E-002, -8.3332858979702000E-002, -8.1348828971385960E-002, -7.9392634332180020E-002, -7.7464438974857330E-002, -7.5564362108707430E-002, -7.3692522943019870E-002, -7.1849010884761810E-002, -7.0033922791481020E-002, -6.8247318267822270E-002, -6.6489234566688540E-002, -6.4759708940982820E-002, -6.3058786094188690E-002, -6.1386436223983760E-002, -5.9742655605077740E-002, -5.8127421885728840E-002, -5.6540694087743760E-002, -5.4982420057058330E-002, -5.3452525287866590E-002, -5.1950931549072270E-002, -5.0477534532547000E-002, -4.9032241106033330E-002, -4.7614917159080510E-002, -4.6225443482398990E-002, -4.4863656163215640E-002, -4.3529424816370010E-002, -4.2222552001476290E-002, -4.0942888706922530E-002, -3.9690230041742320E-002, -3.8464374840259550E-002, -3.7265110760927200E-002, -3.6092240363359450E-002, -3.4945506602525710E-002, -3.3824689686298370E-002, -3.2729536294937140E-002, -3.1659796833992000E-002, -3.0615204945206640E-002, -2.9595496132969860E-002, -2.8600392863154410E-002, -2.7629608288407320E-002, -2.6682861149311060E-002, -2.5759860873222350E-002, -2.4860285222530360E-002, -2.3983856663107870E-002, -2.3130238056182860E-002, -2.2299138829112050E-002, -2.1490212529897690E-002, -2.0703161135315900E-002, -1.9937623292207720E-002, -1.9193304702639580E-002, -1.8469827249646190E-002, -1.7766902223229410E-002, -1.7084129154682160E-002, -1.6421230509877200E-002, -1.5777811408042910E-002, -1.5153550542891020E-002, -1.4548087492585180E-002, -1.3961089774966240E-002, -1.3392185792326930E-002, -1.2841059826314450E-002, -1.2307321652770040E-002, -1.1790650896728040E-002, -1.1290682479739190E-002, -1.0807084850966930E-002, -1.0339494794607160E-002, -9.8875602707266800E-003, -9.4509534537792200E-003, -9.0293306857347480E-003, -8.6223213002085690E-003, -8.2296309992671010E-003, -7.8508658334612850E-003, -7.4857366271317010E-003, -7.1338820271193980E-003, -6.7949919030070300E-003, -6.4686913974583150E-003, -6.1547122895717620E-003, -5.8526843786239620E-003, -5.5623454973101620E-003, -5.2832840010523800E-003, -5.0153112970292570E-003, -4.7580120153725150E-003, -4.5111598446965220E-003, -4.2744171805679800E-003, -4.0474990382790560E-003, -3.8300913292914630E-003, -3.6219672765582800E-003, -3.4227769356220960E-003, -3.2322725746780640E-003, -3.0501529108732940E-003, -2.8761904686689380E-003, -2.7100932784378530E-003, -2.5515670422464610E-003, -2.4004334118217230E-003, -2.2563596721738580E-003, -2.1191518753767010E-003, -1.9886041991412640E-003, -1.8643775256350640E-003, -1.7463274998590350E-003, -1.6342115122824910E-003, -1.5278297942131760E-003, -1.4268938684836030E-003, -1.3312589144334200E-003, -1.2406768510118130E-003, -1.1550235794857140E-003, -1.0739302961155770E-003, -9.9747709464281800E-004, -9.2511920956894760E-004, -8.5701106581836940E-004, -7.9285167157649990E-004, -7.3241489008069040E-004, -6.7555153509601950E-004, -6.2221300322562460E-004, -5.7215924607589840E-004, -5.2524596685543660E-004, -4.8127761692740020E-004, -4.4018754852004350E-004, -4.0182814700528980E-004, -3.6589911906048660E-004, -3.3283955417573450E-004, -3.0138631700538100E-004, -2.7261159266345200E-004, -2.4602311896160240E-004, -2.2118473134469240E-004, -1.9817386055365200E-004, -1.7699223826639360E-004, -1.5759580128360540E-004, -1.3974857574794440E-004, -1.2333714403212070E-004, -1.0821702744578940E-004, -9.4393239123746760E-005, -8.1793652498163280E-005, -2.6584343868307770E-004 + 2.658434386830777e-4, 9.029330685734748e-3, + 7.939263433218002e-2, 2.425158768892288e-1, + 3.430179357528686e-1, 2.398228943347931e-1, + 7.746443897485733e-2, 8.622321300208569e-3, + 8.179365249816328e-5, 9.450953453779220e-3, + 8.134882897138596e-2, 2.451938837766648e-1, + 3.429597318172455e-1, 2.371159791946411e-1, + 7.556436210870743e-2, 8.229630999267101e-3, + 9.439323912374676e-5, 9.887560270726680e-3, + 8.333285897970200e-2, 2.478559017181396e-1, + 3.428434133529663e-1, 2.343961596488952e-1, + 7.369252294301987e-2, 7.850865833461285e-3, + 1.082170274457894e-4, 1.033949479460716e-2, + 8.534456789493561e-2, 2.505008876323700e-1, + 3.426689505577088e-1, 2.316644787788391e-1, + 7.184901088476181e-2, 7.485736627131701e-3, + 1.233371440321207e-4, 1.080708485096693e-2, + 8.738376945257187e-2, 2.531278133392334e-1, + 3.424364924430847e-1, 2.289219647645950e-1, + 7.003392279148102e-2, 7.133882027119398e-3, + 1.397485757479444e-4, 1.129068247973919e-2, + 8.945026248693466e-2, 2.557355761528015e-1, + 3.421461284160614e-1, 2.261696159839630e-1, + 6.824731826782227e-2, 6.794991903007030e-3, + 1.575958012836054e-4, 1.179065089672804e-2, + 9.154383838176728e-2, 2.583232223987580e-1, + 3.417979776859284e-1, 2.234084606170654e-1, + 6.648923456668854e-2, 6.468691397458315e-3, + 1.769922382663936e-4, 1.230732165277004e-2, + 9.366425126791000e-2, 2.608896791934967e-1, + 3.413922190666198e-1, 2.206395119428635e-1, + 6.475970894098282e-2, 6.154712289571762e-3, + 1.981738605536520e-4, 1.284105982631445e-2, + 9.581124037504196e-2, 2.634339034557342e-1, + 3.409290313720703e-1, 2.178637981414795e-1, + 6.305878609418869e-2, 5.852684378623962e-3, + 2.211847313446924e-4, 1.339218579232693e-2, + 9.798453748226166e-2, 2.659549415111542e-1, + 3.404086530208588e-1, 2.150822728872299e-1, + 6.138643622398376e-2, 5.562345497310162e-3, + 2.460231189616024e-4, 1.396108977496624e-2, + 1.001838669180870e-1, 2.684516608715058e-1, + 3.398312926292420e-1, 2.122959494590759e-1, + 5.974265560507774e-2, 5.283284001052380e-3, + 2.726115926634520e-4, 1.454808749258518e-2, + 1.024089083075523e-1, 2.709231376647949e-1, + 3.391972482204438e-1, 2.095058411359787e-1, + 5.812742188572884e-2, 5.015311297029257e-3, + 3.013863170053810e-4, 1.515355054289102e-2, + 1.046593263745308e-1, 2.733682692050934e-1, + 3.385068178176880e-1, 2.067128717899322e-1, + 5.654069408774376e-2, 4.758012015372515e-3, + 3.328395541757345e-4, 1.577781140804291e-2, + 1.069347932934761e-1, 2.757860720157624e-1, + 3.377602994441986e-1, 2.039180546998978e-1, + 5.498242005705833e-2, 4.511159844696522e-3, + 3.658991190604866e-4, 1.642123050987720e-2, + 1.092349365353584e-1, 2.781755328178406e-1, + 3.369580209255218e-1, 2.011223286390304e-1, + 5.345252528786659e-2, 4.274417180567980e-3, + 4.018281470052898e-4, 1.708412915468216e-2, + 1.115593686699867e-1, 2.805356979370117e-1, + 3.361004292964936e-1, 1.983266174793244e-1, + 5.195093154907227e-2, 4.047499038279056e-3, + 4.401875485200435e-4, 1.776690222322941e-2, + 1.139076948165894e-1, 2.828655838966370e-1, + 3.351879119873047e-1, 1.955319195985794e-1, + 5.047753453254700e-2, 3.830091329291463e-3, + 4.812776169274002e-4, 1.846982724964619e-2, + 1.162794977426529e-1, 2.851640880107880e-1, + 3.342207968235016e-1, 1.927391141653061e-1, + 4.903224110603333e-2, 3.621967276558280e-3, + 5.252459668554366e-4, 1.919330470263958e-2, + 1.186743453145027e-1, 2.874303460121155e-1, + 3.331996202468872e-1, 1.899491697549820e-1, + 4.761491715908051e-2, 3.422776935622096e-3, + 5.721592460758984e-4, 1.993762329220772e-2, + 1.210917681455612e-1, 2.896633744239807e-1, + 3.321248590946198e-1, 1.871629506349564e-1, + 4.622544348239899e-2, 3.232272574678064e-3, + 6.222130032256246e-4, 2.070316113531590e-2, + 1.235313042998314e-1, 2.918621897697448e-1, + 3.309969604015350e-1, 1.843813359737396e-1, + 4.486365616321564e-2, 3.050152910873294e-3, + 6.755515350960195e-4, 2.149021252989769e-2, + 1.259924471378326e-1, 2.940258979797364e-1, + 3.298164308071136e-1, 1.816052496433258e-1, + 4.352942481637001e-2, 2.876190468668938e-3, + 7.324148900806904e-4, 2.229913882911205e-2, + 1.284746825695038e-1, 2.961534857749939e-1, + 3.285838961601258e-1, 1.788355410099030e-1, + 4.222255200147629e-2, 2.710093278437853e-3, + 7.928516715764999e-4, 2.313023805618286e-2, + 1.309774816036224e-1, 2.982441186904907e-1, + 3.272998929023742e-1, 1.760730892419815e-1, + 4.094288870692253e-2, 2.551567042246461e-3, + 8.570110658183694e-4, 2.398385666310787e-2, + 1.335003077983856e-1, 3.002967536449432e-1, + 3.259649574756622e-1, 1.733186990022659e-1, + 3.969023004174232e-2, 2.400433411821723e-3, + 9.251192095689476e-4, 2.486028522253036e-2, + 1.360425949096680e-1, 3.023106753826142e-1, + 3.245797157287598e-1, 1.705732345581055e-1, + 3.846437484025955e-2, 2.256359672173858e-3, + 9.974770946428180e-4, 2.575986087322235e-2, + 1.386037617921829e-1, 3.042849004268646e-1, + 3.231448531150818e-1, 1.678375005722046e-1, + 3.726511076092720e-2, 2.119151875376701e-3, + 1.073930296115577e-3, 2.668286114931106e-2, + 1.411831974983215e-1, 3.062185347080230e-1, + 3.216609656810760e-1, 1.651122719049454e-1, + 3.609224036335945e-2, 1.988604199141264e-3, + 1.155023579485714e-3, 2.762960828840732e-2, + 1.437802612781525e-1, 3.081108033657074e-1, + 3.201287388801574e-1, 1.623983532190323e-1, + 3.494550660252571e-2, 1.864377525635064e-3, + 1.240676851011813e-3, 2.860039286315441e-2, + 1.463943719863892e-1, 3.099608123302460e-1, + 3.185488879680634e-1, 1.596965193748474e-1, + 3.382468968629837e-2, 1.746327499859035e-3, + 1.331258914433420e-3, 2.959549613296986e-2, + 1.490248143672943e-1, 3.117676973342896e-1, + 3.169221282005310e-1, 1.570075154304504e-1, + 3.272953629493714e-2, 1.634211512282491e-3, + 1.426893868483603e-3, 3.061520494520664e-2, + 1.516709625720978e-1, 3.135308027267456e-1, + 3.152491748332978e-1, 1.543320864439010e-1, + 3.165979683399200e-2, 1.527829794213176e-3, }; -//FIXME the coeffs are symmetric - -static const float lfe_fir_128[] = +DECLARE_ALIGNED(16, static const float, lfe_fir_128)[] = { -0.00053168571, -0.00016358691, -0.00018878609, -0.00021643363, -0.00024667382, -0.00027949660, -0.00031519096, -0.00035398375, -0.00039634691, -0.00044236859, -0.00049204525, -0.00054522208, -0.00060277141, -0.00066567765, -0.00073179678, -0.00080365466, -0.00088037323, -0.00096255314, -0.00105048984, -0.00114431616, -0.00124442333, -0.00135110028, -0.00146482687, -0.00158570008, -0.00171401864, -0.00185023469, -0.00199495023, -0.00214785640, -0.00231004250, -0.00248134881, -0.00266251224, -0.00285378192, -0.00305565330, -0.00326841651, -0.00349264755, -0.00372874714, -0.00397720048, -0.00423829490, -0.00451271003, -0.00480085658, -0.00510312291, -0.00542017492, -0.00575236930, -0.00610029325, -0.00646453211, -0.00684553990, -0.00724391919, -0.00766016589, -0.00809498038, -0.00854881573, -0.00902230106, -0.00951600447, -0.01003060210, -0.01056654565, -0.01112466771, -0.01170534454, -0.01230939943, -0.01293735672, -0.01358995494, -0.01426773332, -0.01497144438, -0.01570170000, -0.01645922661, -0.01724460535, -0.01805862412, -0.01890186779, -0.01977507770, -0.02067894675, -0.02161412500, -0.02258131653, -0.02358125709, -0.02461459488, -0.02568206564, -0.02678431384, -0.02792212367, -0.02909611352, -0.03030703776, -0.03155555204, -0.03284239396, -0.03416819125, -0.03553372994, -0.03693958372, -0.03838652745, -0.03987516090, -0.04140623659, -0.04298033938, -0.04459818453, -0.04626038298, -0.04796761274, -0.04972046614, -0.05151961371, -0.05336561054, -0.05525910854, -0.05720067024, -0.05919086933, -0.06123027951, -0.06331945211, -0.06545893103, -0.06764923781, -0.06989086419, -0.07218432426, -0.07453006506, -0.07692859322, -0.07938029617, -0.08188561350, -0.08444493264, -0.08705867827, -0.08972713351, -0.09245070815, -0.09522963315, -0.09806428105, -0.10095486045, -0.10390164703, -0.10690483451, -0.10996460915, -0.11308115721, -0.11625462025, -0.11948505789, -0.12277261168, -0.12611730397, -0.12951917946, -0.13297818601, -0.13649433851, -0.14006754756, -0.14369773865, -0.14738474786, -0.15112841129, -0.15492856503, -0.15878495574, -0.16269733012, -0.16666537523, -0.17068879306, -0.17476719618, -0.17890018225, -0.18308731914, -0.18732811511, -0.19162209332, -0.19596865773, -0.20036731660, -0.20481738448, -0.20931822062, -0.21386915445, -0.21846942604, -0.22311829031, -0.22781492770, -0.23255851865, -0.23734821379, -0.24218304455, -0.24706205726, -0.25198432803, -0.25694879889, -0.26195442677, -0.26700007915, -0.27208462358, -0.27720692754, -0.28236576915, -0.28755992651, -0.29278811812, -0.29804900289, -0.30334126949, -0.30866351724, -0.31401440501, -0.31939238310, -0.32479602098, -0.33022382855, -0.33567428589, -0.34114575386, -0.34663668275, -0.35214546323, -0.35767036676, -0.36320972443, -0.36876192689, -0.37432509661, -0.37989753485, -0.38547745347, -0.39106300473, -0.39665243030, -0.40224379301, -0.40783521533, -0.41342487931, -0.41901078820, -0.42459106445, -0.43016362190, -0.43572667241, -0.44127810001, -0.44681602716, -0.45233830810, -0.45784294605, -0.46332800388, -0.46879136562, -0.47423094511, -0.47964480519, -0.48503074050, -0.49038675427, -0.49571081996, -0.50100076199, -0.50625455379, -0.51147013903, -0.51664537191, -0.52177828550, -0.52686679363, -0.53190881014, -0.53690224886, -0.54184508324, -0.54673534632, -0.55157101154, -0.55634999275, -0.56107026339, -0.56572991610, -0.57032698393, -0.57485944033, -0.57932555676, -0.58372318745, -0.58805054426, -0.59230577946, -0.59648692608, -0.60059231520, -0.60462015867, -0.60856848955, -0.61243581772, -0.61622029543, -0.61992025375, -0.62353414297, -0.62706029415, -0.63049703836, -0.63384294510, -0.63709646463, -0.64025616646, -0.64332056046, -0.64628833532, -0.64915806055, -0.65192854404, -0.65459835529, -0.65716648102, -0.65963155031, -0.66199249029, -0.66424828768, -0.66639786959, -0.66844022274, -0.67037439346, -0.67219948769, -0.67391467094, -0.67551922798, -0.67701220512, -0.67839306593, -0.67966115475, -0.68081587553, -0.68185669184, -0.68278300762, -0.68359452486, -0.68429082632, -0.68487155437, -0.68533653021, -0.68568539619, -0.68591803312, -0.68603444099, -0.68603444099, -0.68591803312, -0.68568539619, -0.68533653021, -0.68487155437, -0.68429082632, -0.68359452486, -0.68278300762, -0.68185669184, -0.68081587553, -0.67966115475, -0.67839306593, -0.67701220512, -0.67551922798, -0.67391467094, -0.67219948769, -0.67037439346, -0.66844022274, -0.66639786959, -0.66424828768, -0.66199249029, -0.65963155031, -0.65716648102, -0.65459835529, -0.65192854404, -0.64915806055, -0.64628833532, -0.64332056046, -0.64025616646, -0.63709646463, -0.63384294510, -0.63049703836, -0.62706029415, -0.62353414297, -0.61992025375, -0.61622029543, -0.61243581772, -0.60856848955, -0.60462015867, -0.60059231520, -0.59648692608, -0.59230577946, -0.58805054426, -0.58372318745, -0.57932555676, -0.57485944033, -0.57032698393, -0.56572991610, -0.56107026339, -0.55634999275, -0.55157101154, -0.54673534632, -0.54184508324, -0.53690224886, -0.53190881014, -0.52686679363, -0.52177828550, -0.51664537191, -0.51147013903, -0.50625455379, -0.50100076199, -0.49571081996, -0.49038675427, -0.48503074050, -0.47964480519, -0.47423094511, -0.46879136562, -0.46332800388, -0.45784294605, -0.45233830810, -0.44681602716, -0.44127810001, -0.43572667241, -0.43016362190, -0.42459106445, -0.41901078820, -0.41342487931, -0.40783521533, -0.40224379301, -0.39665243030, -0.39106300473, -0.38547745347, -0.37989753485, -0.37432509661, -0.36876192689, -0.36320972443, -0.35767036676, -0.35214546323, -0.34663668275, -0.34114575386, -0.33567428589, -0.33022382855, -0.32479602098, -0.31939238310, -0.31401440501, -0.30866351724, -0.30334126949, -0.29804900289, -0.29278811812, -0.28755992651, -0.28236576915, -0.27720692754, -0.27208462358, -0.26700007915, -0.26195442677, -0.25694879889, -0.25198432803, -0.24706205726, -0.24218304455, -0.23734821379, -0.23255851865, -0.22781492770, -0.22311829031, -0.21846942604, -0.21386915445, -0.20931822062, -0.20481738448, -0.20036731660, -0.19596865773, -0.19162209332, -0.18732811511, -0.18308731914, -0.17890018225, -0.17476719618, -0.17068879306, -0.16666537523, -0.16269733012, -0.15878495574, -0.15492856503, -0.15112841129, -0.14738474786, -0.14369773865, -0.14006754756, -0.13649433851, -0.13297818601, -0.12951917946, -0.12611730397, -0.12277261168, -0.11948505789, -0.11625462025, -0.11308115721, -0.10996460915, -0.10690483451, -0.10390164703, -0.10095486045, -0.09806428105, -0.09522963315, -0.09245070815, -0.08972713351, -0.08705867827, -0.08444493264, -0.08188561350, -0.07938029617, -0.07692859322, -0.07453006506, -0.07218432426, -0.06989086419, -0.06764923781, -0.06545893103, -0.06331945211, -0.06123027951, -0.05919086933, -0.05720067024, -0.05525910854, -0.05336561054, -0.05151961371, -0.04972046614, -0.04796761274, -0.04626038298, -0.04459818453, -0.04298033938, -0.04140623659, -0.03987516090, -0.03838652745, -0.03693958372, -0.03553372994, -0.03416819125, -0.03284239396, -0.03155555204, -0.03030703776, -0.02909611352, -0.02792212367, -0.02678431384, -0.02568206564, -0.02461459488, -0.02358125709, -0.02258131653, -0.02161412500, -0.02067894675, -0.01977507770, -0.01890186779, -0.01805862412, -0.01724460535, -0.01645922661, -0.01570170000, -0.01497144438, -0.01426773332, -0.01358995494, -0.01293735672, -0.01230939943, -0.01170534454, -0.01112466771, -0.01056654565, -0.01003060210, -0.00951600447, -0.00902230106, -0.00854881573, -0.00809498038, -0.00766016589, -0.00724391919, -0.00684553990, -0.00646453211, -0.00610029325, -0.00575236930, -0.00542017492, -0.00510312291, -0.00480085658, -0.00451271003, -0.00423829490, -0.00397720048, -0.00372874714, -0.00349264755, -0.00326841651, -0.00305565330, -0.00285378192, -0.00266251224, -0.00248134881, -0.00231004250, -0.00214785640, -0.00199495023, -0.00185023469, -0.00171401864, -0.00158570008, -0.00146482687, -0.00135110028, -0.00124442333, -0.00114431616, -0.00105048984, -0.00096255314, -0.00088037323, -0.00080365466, -0.00073179678, -0.00066567765, -0.00060277141, -0.00054522208, -0.00049204525, -0.00044236859, -0.00039634691, -0.00035398375, -0.00031519096, -0.00027949660, -0.00024667382, -0.00021643363, -0.00018878609, -0.00016358691, -0.00053168571 + 0.00053168571, 0.15878495574, 0.68603444099, 0.15492856503, + 0.00016358691, 0.16269733012, 0.68591803312, 0.15112841129, + 0.00018878609, 0.16666537523, 0.68568539619, 0.14738474786, + 0.00021643363, 0.17068879306, 0.68533653021, 0.14369773865, + 0.00024667382, 0.17476719618, 0.68487155437, 0.14006754756, + 0.00027949660, 0.17890018225, 0.68429082632, 0.13649433851, + 0.00031519096, 0.18308731914, 0.68359452486, 0.13297818601, + 0.00035398375, 0.18732811511, 0.68278300762, 0.12951917946, + 0.00039634691, 0.19162209332, 0.68185669184, 0.12611730397, + 0.00044236859, 0.19596865773, 0.68081587553, 0.12277261168, + 0.00049204525, 0.20036731660, 0.67966115475, 0.11948505789, + 0.00054522208, 0.20481738448, 0.67839306593, 0.11625462025, + 0.00060277141, 0.20931822062, 0.67701220512, 0.11308115721, + 0.00066567765, 0.21386915445, 0.67551922798, 0.10996460915, + 0.00073179678, 0.21846942604, 0.67391467094, 0.10690483451, + 0.00080365466, 0.22311829031, 0.67219948769, 0.10390164703, + 0.00088037323, 0.22781492770, 0.67037439346, 0.10095486045, + 0.00096255314, 0.23255851865, 0.66844022274, 0.09806428105, + 0.00105048984, 0.23734821379, 0.66639786959, 0.09522963315, + 0.00114431616, 0.24218304455, 0.66424828768, 0.09245070815, + 0.00124442333, 0.24706205726, 0.66199249029, 0.08972713351, + 0.00135110028, 0.25198432803, 0.65963155031, 0.08705867827, + 0.00146482687, 0.25694879889, 0.65716648102, 0.08444493264, + 0.00158570008, 0.26195442677, 0.65459835529, 0.08188561350, + 0.00171401864, 0.26700007915, 0.65192854404, 0.07938029617, + 0.00185023469, 0.27208462358, 0.64915806055, 0.07692859322, + 0.00199495023, 0.27720692754, 0.64628833532, 0.07453006506, + 0.00214785640, 0.28236576915, 0.64332056046, 0.07218432426, + 0.00231004250, 0.28755992651, 0.64025616646, 0.06989086419, + 0.00248134881, 0.29278811812, 0.63709646463, 0.06764923781, + 0.00266251224, 0.29804900289, 0.63384294510, 0.06545893103, + 0.00285378192, 0.30334126949, 0.63049703836, 0.06331945211, + 0.00305565330, 0.30866351724, 0.62706029415, 0.06123027951, + 0.00326841651, 0.31401440501, 0.62353414297, 0.05919086933, + 0.00349264755, 0.31939238310, 0.61992025375, 0.05720067024, + 0.00372874714, 0.32479602098, 0.61622029543, 0.05525910854, + 0.00397720048, 0.33022382855, 0.61243581772, 0.05336561054, + 0.00423829490, 0.33567428589, 0.60856848955, 0.05151961371, + 0.00451271003, 0.34114575386, 0.60462015867, 0.04972046614, + 0.00480085658, 0.34663668275, 0.60059231520, 0.04796761274, + 0.00510312291, 0.35214546323, 0.59648692608, 0.04626038298, + 0.00542017492, 0.35767036676, 0.59230577946, 0.04459818453, + 0.00575236930, 0.36320972443, 0.58805054426, 0.04298033938, + 0.00610029325, 0.36876192689, 0.58372318745, 0.04140623659, + 0.00646453211, 0.37432509661, 0.57932555676, 0.03987516090, + 0.00684553990, 0.37989753485, 0.57485944033, 0.03838652745, + 0.00724391919, 0.38547745347, 0.57032698393, 0.03693958372, + 0.00766016589, 0.39106300473, 0.56572991610, 0.03553372994, + 0.00809498038, 0.39665243030, 0.56107026339, 0.03416819125, + 0.00854881573, 0.40224379301, 0.55634999275, 0.03284239396, + 0.00902230106, 0.40783521533, 0.55157101154, 0.03155555204, + 0.00951600447, 0.41342487931, 0.54673534632, 0.03030703776, + 0.01003060210, 0.41901078820, 0.54184508324, 0.02909611352, + 0.01056654565, 0.42459106445, 0.53690224886, 0.02792212367, + 0.01112466771, 0.43016362190, 0.53190881014, 0.02678431384, + 0.01170534454, 0.43572667241, 0.52686679363, 0.02568206564, + 0.01230939943, 0.44127810001, 0.52177828550, 0.02461459488, + 0.01293735672, 0.44681602716, 0.51664537191, 0.02358125709, + 0.01358995494, 0.45233830810, 0.51147013903, 0.02258131653, + 0.01426773332, 0.45784294605, 0.50625455379, 0.02161412500, + 0.01497144438, 0.46332800388, 0.50100076199, 0.02067894675, + 0.01570170000, 0.46879136562, 0.49571081996, 0.01977507770, + 0.01645922661, 0.47423094511, 0.49038675427, 0.01890186779, + 0.01724460535, 0.47964480519, 0.48503074050, 0.01805862412, }; /* 10^-(dB/20), with dB being a list of dB values ranging from 0 to -72 */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dcadsp.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/dcadsp.c new file mode 100644 index 0000000000..af48e3ce42 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dcadsp.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2004 Gildas Bazin + * Copyright (c) 2010 Mans Rullgard + * + * 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 "dcadsp.h" + +static void dca_lfe_fir_c(float *out, const float *in, const float *coefs, + int decifactor, float scale, float bias) +{ + float *out2 = out + decifactor; + const float *cf0 = coefs; + const float *cf1 = coefs + 256; + int j, k; + + /* One decimated sample generates 2*decifactor interpolated ones */ + for (k = 0; k < decifactor; k++) { + float v0 = 0.0; + float v1 = 0.0; + for (j = 0; j < 256 / decifactor; j++) { + float s = in[-j]; + v0 += s * *cf0++; + v1 += s * *--cf1; + } + *out++ = (v0 * scale) + bias; + *out2++ = (v1 * scale) + bias; + } +} + +void ff_dcadsp_init(DCADSPContext *s) +{ + s->lfe_fir = dca_lfe_fir_c; + if (ARCH_ARM) ff_dcadsp_init_arm(s); +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dcadsp.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/dcadsp.h new file mode 100644 index 0000000000..20020ae06c --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dcadsp.h @@ -0,0 +1,30 @@ +/* + * 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_DCADSP_H +#define AVCODEC_DCADSP_H + +typedef struct DCADSPContext { + void (*lfe_fir)(float *out, const float *in, const float *coefs, + int decifactor, float scale, float bias); +} DCADSPContext; + +void ff_dcadsp_init(DCADSPContext *s); +void ff_dcadsp_init_arm(DCADSPContext *s); + +#endif /* AVCODEC_DCADSP_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dct-test.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/dct-test.c index 419464cf54..4f0a0c6996 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/dct-test.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dct-test.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/dct-test.c + * @file * DCT test (c) 2001 Fabrice Bellard * Started from sample code by Juan J. Sierralta P. */ @@ -40,16 +40,10 @@ #include "faandct.h" #include "faanidct.h" #include "x86/idct_xvid.h" +#include "dctref.h" #undef printf -void *fast_memcpy(void *a, const void *b, size_t c){return memcpy(a,b,c);}; - -/* reference fdct/idct */ -void ff_ref_fdct(DCTELEM *block); -void ff_ref_idct(DCTELEM *block); -void ff_ref_dct_init(void); - void ff_mmx_idct(DCTELEM *data); void ff_mmxext_idct(DCTELEM *data); @@ -64,9 +58,9 @@ void fdct_altivec(DCTELEM *block); //void idct_altivec(DCTELEM *block);?? no routine // ARM -void j_rev_dct_ARM(DCTELEM *data); -void simple_idct_ARM(DCTELEM *data); -void simple_idct_armv5te(DCTELEM *data); +void ff_j_rev_dct_arm(DCTELEM *data); +void ff_simple_idct_arm(DCTELEM *data); +void ff_simple_idct_armv5te(DCTELEM *data); void ff_simple_idct_armv6(DCTELEM *data); void ff_simple_idct_neon(DCTELEM *data); @@ -126,10 +120,10 @@ struct algo algos[] = { #endif #if ARCH_ARM - {"SIMPLE-ARM", 1, simple_idct_ARM, ff_ref_idct, NO_PERM }, - {"INT-ARM", 1, j_rev_dct_ARM, ff_ref_idct, MMX_PERM }, + {"SIMPLE-ARM", 1, ff_simple_idct_arm, ff_ref_idct, NO_PERM }, + {"INT-ARM", 1, ff_j_rev_dct_arm, ff_ref_idct, MMX_PERM }, #if HAVE_ARMV5TE - {"SIMPLE-ARMV5TE", 1, simple_idct_armv5te, ff_ref_idct, NO_PERM }, + {"SIMPLE-ARMV5TE", 1, ff_simple_idct_armv5te, ff_ref_idct, NO_PERM }, #endif #if HAVE_ARMV6 {"SIMPLE-ARMV6", 1, ff_simple_idct_armv6, ff_ref_idct, MMX_PERM }, @@ -186,9 +180,9 @@ 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]); +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) { @@ -384,8 +378,8 @@ static void dct_error(const char *name, int is_idct, #endif } -DECLARE_ALIGNED(8, static uint8_t, img_dest[64]); -DECLARE_ALIGNED(8, static uint8_t, img_dest1[64]); +DECLARE_ALIGNED(8, static uint8_t, img_dest)[64]; +DECLARE_ALIGNED(8, static uint8_t, img_dest1)[64]; static void idct248_ref(uint8_t *dest, int linesize, int16_t *block) { diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dct.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/dct.c new file mode 100644 index 0000000000..0840feca0a --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dct.c @@ -0,0 +1,210 @@ +/* + * (I)DCT Transforms + * Copyright (c) 2009 Peter Ross + * Copyright (c) 2010 Alex Converse + * Copyright (c) 2010 Vitor Sessak + * + * 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 St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * (Inverse) Discrete Cosine Transforms. These are also known as the + * type II and type III DCTs respectively. + */ + +#include +#include "libavutil/mathematics.h" +#include "fft.h" + +/* sin((M_PI * x / (2*n)) */ +#define SIN(s,n,x) (s->costab[(n) - (x)]) + +/* cos((M_PI * x / (2*n)) */ +#define COS(s,n,x) (s->costab[x]) + +static void ff_dst_calc_I_c(DCTContext *ctx, FFTSample *data) +{ + int n = 1 << ctx->nbits; + int i; + + data[0] = 0; + for(i = 1; i < n/2; i++) { + float tmp1 = data[i ]; + float tmp2 = data[n - i]; + float s = SIN(ctx, n, 2*i); + + s *= tmp1 + tmp2; + tmp1 = (tmp1 - tmp2) * 0.5f; + data[i ] = s + tmp1; + data[n - i] = s - tmp1; + } + + data[n/2] *= 2; + ff_rdft_calc(&ctx->rdft, data); + + data[0] *= 0.5f; + + for(i = 1; i < n-2; i += 2) { + data[i + 1] += data[i - 1]; + data[i ] = -data[i + 2]; + } + + data[n-1] = 0; +} + +static void ff_dct_calc_I_c(DCTContext *ctx, FFTSample *data) +{ + int n = 1 << ctx->nbits; + int i; + float next = -0.5f * (data[0] - data[n]); + + for(i = 0; i < n/2; i++) { + float tmp1 = data[i ]; + float tmp2 = data[n - i]; + float s = SIN(ctx, n, 2*i); + float c = COS(ctx, n, 2*i); + + c *= tmp1 - tmp2; + s *= tmp1 - tmp2; + + next += c; + + tmp1 = (tmp1 + tmp2) * 0.5f; + data[i ] = tmp1 - s; + data[n - i] = tmp1 + s; + } + + ff_rdft_calc(&ctx->rdft, data); + data[n] = data[1]; + data[1] = next; + + for(i = 3; i <= n; i += 2) + data[i] = data[i - 2] - data[i]; +} + +static void ff_dct_calc_III_c(DCTContext *ctx, FFTSample *data) +{ + int n = 1 << ctx->nbits; + int i; + + float next = data[n - 1]; + float inv_n = 1.0f / n; + + for (i = n - 2; i >= 2; i -= 2) { + float val1 = data[i ]; + float val2 = data[i - 1] - data[i + 1]; + float c = COS(ctx, n, i); + float s = SIN(ctx, n, i); + + data[i ] = c * val1 + s * val2; + data[i + 1] = s * val1 - c * val2; + } + + data[1] = 2 * next; + + ff_rdft_calc(&ctx->rdft, data); + + for (i = 0; i < n / 2; i++) { + float tmp1 = data[i ] * inv_n; + float tmp2 = data[n - i - 1] * inv_n; + float csc = ctx->csc2[i] * (tmp1 - tmp2); + + tmp1 += tmp2; + data[i ] = tmp1 + csc; + data[n - i - 1] = tmp1 - csc; + } +} + +static void ff_dct_calc_II_c(DCTContext *ctx, FFTSample *data) +{ + int n = 1 << ctx->nbits; + int i; + float next; + + for (i=0; i < n/2; i++) { + float tmp1 = data[i ]; + float tmp2 = data[n - i - 1]; + float s = SIN(ctx, n, 2*i + 1); + + s *= tmp1 - tmp2; + tmp1 = (tmp1 + tmp2) * 0.5f; + + data[i ] = tmp1 + s; + data[n-i-1] = tmp1 - s; + } + + ff_rdft_calc(&ctx->rdft, data); + + next = data[1] * 0.5; + data[1] *= -1; + + for (i = n - 2; i >= 0; i -= 2) { + float inr = data[i ]; + float ini = data[i + 1]; + float c = COS(ctx, n, i); + float s = SIN(ctx, n, i); + + data[i ] = c * inr + s * ini; + + data[i+1] = next; + + next += s * inr - c * ini; + } +} + +void ff_dct_calc(DCTContext *s, FFTSample *data) +{ + s->dct_calc(s, data); +} + +av_cold int ff_dct_init(DCTContext *s, int nbits, enum DCTTransformType inverse) +{ + int n = 1 << nbits; + int i; + + s->nbits = nbits; + s->inverse = inverse; + + ff_init_ff_cos_tabs(nbits+2); + + s->costab = ff_cos_tabs[nbits+2]; + + s->csc2 = av_malloc(n/2 * sizeof(FFTSample)); + + if (ff_rdft_init(&s->rdft, nbits, inverse == DCT_III) < 0) { + av_free(s->csc2); + return -1; + } + + for (i = 0; i < n/2; i++) + s->csc2[i] = 0.5 / sin((M_PI / (2*n) * (2*i + 1))); + + switch(inverse) { + case DCT_I : s->dct_calc = ff_dct_calc_I_c; break; + case DCT_II : s->dct_calc = ff_dct_calc_II_c ; break; + case DCT_III: s->dct_calc = ff_dct_calc_III_c; break; + case DST_I : s->dct_calc = ff_dst_calc_I_c; break; + } + return 0; +} + +av_cold void ff_dct_end(DCTContext *s) +{ + ff_rdft_end(&s->rdft); + av_free(s->csc2); +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dctref.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/dctref.c index faad057a9a..851014b664 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/dctref.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dctref.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/dctref.c + * @file * reference discrete cosine transform (double precision) * * @author Dylan Yudaken (dyudaken at gmail) @@ -30,6 +30,8 @@ */ #include "libavutil/mathematics.h" +#include "dctref.h" + static double coefficients[8 * 8]; /** diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dctref.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/dctref.h new file mode 100644 index 0000000000..adbaf689e2 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dctref.h @@ -0,0 +1,31 @@ +/* + * reference discrete cosine transform (double precision) + * Copyright (C) 2009 Dylan Yudaken + * + * 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_DCTREF_H +#define AVCODEC_DCTREF_H + +#include "dsputil.h" + +void ff_ref_fdct(DCTELEM *block); +void ff_ref_idct(DCTELEM *block); +void ff_ref_dct_init(void); + +#endif diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dirac.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/dirac.c new file mode 100644 index 0000000000..c65a51f964 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dirac.c @@ -0,0 +1,284 @@ +/* + * Copyright (C) 2007 Marco Gerards + * Copyright (C) 2009 David Conrad + * + * 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 + * Dirac Decoder + * @author Marco Gerards + */ + +#include "dirac.h" +#include "avcodec.h" +#include "golomb.h" +#include "mpeg12data.h" + +// defaults for source parameters +static const dirac_source_params dirac_source_parameters_defaults[] = { + { 640, 480, 2, 0, 0, 1, 1, 640, 480, 0, 0, 1, 0 }, + { 176, 120, 2, 0, 0, 9, 2, 176, 120, 0, 0, 1, 1 }, + { 176, 144, 2, 0, 1, 10, 3, 176, 144, 0, 0, 1, 2 }, + { 352, 240, 2, 0, 0, 9, 2, 352, 240, 0, 0, 1, 1 }, + { 352, 288, 2, 0, 1, 10, 3, 352, 288, 0, 0, 1, 2 }, + { 704, 480, 2, 0, 0, 9, 2, 704, 480, 0, 0, 1, 1 }, + { 704, 576, 2, 0, 1, 10, 3, 704, 576, 0, 0, 1, 2 }, + { 720, 480, 1, 1, 0, 4, 2, 704, 480, 8, 0, 3, 1 }, + { 720, 576, 1, 1, 1, 3, 3, 704, 576, 8, 0, 3, 2 }, + + { 1280, 720, 1, 0, 1, 7, 1, 1280, 720, 0, 0, 3, 3 }, + { 1280, 720, 1, 0, 1, 6, 1, 1280, 720, 0, 0, 3, 3 }, + { 1920, 1080, 1, 1, 1, 4, 1, 1920, 1080, 0, 0, 3, 3 }, + { 1920, 1080, 1, 1, 1, 3, 1, 1920, 1080, 0, 0, 3, 3 }, + { 1920, 1080, 1, 0, 1, 7, 1, 1920, 1080, 0, 0, 3, 3 }, + { 1920, 1080, 1, 0, 1, 6, 1, 1920, 1080, 0, 0, 3, 3 }, + { 2048, 1080, 0, 0, 1, 2, 1, 2048, 1080, 0, 0, 4, 4 }, + { 4096, 2160, 0, 0, 1, 2, 1, 4096, 2160, 0, 0, 4, 4 }, + + { 3840, 2160, 1, 0, 1, 7, 1, 3840, 2160, 0, 0, 3, 3 }, + { 3840, 2160, 1, 0, 1, 6, 1, 3840, 2160, 0, 0, 3, 3 }, + { 7680, 4320, 1, 0, 1, 7, 1, 3840, 2160, 0, 0, 3, 3 }, + { 7680, 4320, 1, 0, 1, 6, 1, 3840, 2160, 0, 0, 3, 3 }, +}; + +static const AVRational dirac_preset_aspect_ratios[] = { + {1, 1}, + {10, 11}, + {12, 11}, + {40, 33}, + {16, 11}, + {4, 3}, +}; + +static const AVRational dirac_frame_rate[] = { + {15000, 1001}, + {25, 2}, +}; + +static const struct { + uint8_t bitdepth; + enum AVColorRange color_range; +} pixel_range_presets[] = { + {8, AVCOL_RANGE_JPEG}, + {8, AVCOL_RANGE_MPEG}, + {10, AVCOL_RANGE_MPEG}, + {12, AVCOL_RANGE_MPEG}, +}; + +static const enum AVColorPrimaries dirac_primaries[] = { + AVCOL_PRI_BT709, + AVCOL_PRI_SMPTE170M, + AVCOL_PRI_BT470BG, +}; + +static const struct { + enum AVColorPrimaries color_primaries; + enum AVColorSpace colorspace; + enum AVColorTransferCharacteristic color_trc; +} dirac_color_presets[] = { + { AVCOL_PRI_BT709, AVCOL_SPC_BT709, AVCOL_TRC_BT709 }, + { AVCOL_PRI_SMPTE170M, AVCOL_SPC_BT470BG, AVCOL_TRC_BT709 }, + { AVCOL_PRI_BT470BG, AVCOL_SPC_BT470BG, AVCOL_TRC_BT709 }, + { AVCOL_PRI_BT709, AVCOL_SPC_BT709, AVCOL_TRC_BT709 }, + { AVCOL_PRI_BT709, AVCOL_SPC_BT709, AVCOL_TRC_UNSPECIFIED /* DCinema */ }, +}; + +static const enum PixelFormat dirac_pix_fmt[2][3] = { + { PIX_FMT_YUV444P, PIX_FMT_YUV422P, PIX_FMT_YUV420P }, + { PIX_FMT_YUVJ444P, PIX_FMT_YUVJ422P, PIX_FMT_YUVJ420P }, +}; + +static int parse_source_parameters(AVCodecContext *avctx, GetBitContext *gb, + dirac_source_params *source) +{ + AVRational frame_rate = (AVRational){0,0}; + unsigned luma_depth = 8, luma_offset = 16; + int idx; + + if (get_bits1(gb)) { + source->width = svq3_get_ue_golomb(gb); + source->height = svq3_get_ue_golomb(gb); + } + + // chroma subsampling + if (get_bits1(gb)) + source->chroma_format = svq3_get_ue_golomb(gb); + if (source->chroma_format > 2) { + av_log(avctx, AV_LOG_ERROR, "Unknown chroma format %d\n", + source->chroma_format); + return -1; + } + + if (get_bits1(gb)) + source->interlaced = svq3_get_ue_golomb(gb); + if (source->interlaced > 1) + return -1; + + // frame rate + if (get_bits1(gb)) { + source->frame_rate_index = svq3_get_ue_golomb(gb); + + if (source->frame_rate_index > 10) + return -1; + + if (!source->frame_rate_index) { + frame_rate.num = svq3_get_ue_golomb(gb); + frame_rate.den = svq3_get_ue_golomb(gb); + } + } + if (source->frame_rate_index > 0) { + if (source->frame_rate_index <= 8) + frame_rate = ff_frame_rate_tab[source->frame_rate_index]; + else + frame_rate = dirac_frame_rate[source->frame_rate_index-9]; + } + av_reduce(&avctx->time_base.num, &avctx->time_base.den, + frame_rate.den, frame_rate.num, 1<<30); + + // aspect ratio + if (get_bits1(gb)) { + source->aspect_ratio_index = svq3_get_ue_golomb(gb); + + if (source->aspect_ratio_index > 6) + return -1; + + if (!source->aspect_ratio_index) { + avctx->sample_aspect_ratio.num = svq3_get_ue_golomb(gb); + avctx->sample_aspect_ratio.den = svq3_get_ue_golomb(gb); + } + } + if (source->aspect_ratio_index > 0) + avctx->sample_aspect_ratio = + dirac_preset_aspect_ratios[source->aspect_ratio_index-1]; + + if (get_bits1(gb)) { + source->clean_width = svq3_get_ue_golomb(gb); + source->clean_height = svq3_get_ue_golomb(gb); + source->clean_left_offset = svq3_get_ue_golomb(gb); + source->clean_right_offset = svq3_get_ue_golomb(gb); + } + + // Override signal range. + if (get_bits1(gb)) { + source->pixel_range_index = svq3_get_ue_golomb(gb); + + if (source->pixel_range_index > 4) + return -1; + + // This assumes either fullrange or MPEG levels only + if (!source->pixel_range_index) { + luma_offset = svq3_get_ue_golomb(gb); + luma_depth = av_log2(svq3_get_ue_golomb(gb))+1; + svq3_get_ue_golomb(gb); // chroma offset + svq3_get_ue_golomb(gb); // chroma excursion + + avctx->color_range = luma_offset ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG; + } + } + if (source->pixel_range_index > 0) { + idx = source->pixel_range_index-1; + luma_depth = pixel_range_presets[idx].bitdepth; + avctx->color_range = pixel_range_presets[idx].color_range; + } + + if (luma_depth > 8) + av_log(avctx, AV_LOG_WARNING, "Bitdepth greater than 8"); + + avctx->pix_fmt = dirac_pix_fmt[!luma_offset][source->chroma_format]; + + // color spec + if (get_bits1(gb)) { + idx = source->color_spec_index = svq3_get_ue_golomb(gb); + + if (source->color_spec_index > 4) + return -1; + + avctx->color_primaries = dirac_color_presets[idx].color_primaries; + avctx->colorspace = dirac_color_presets[idx].colorspace; + avctx->color_trc = dirac_color_presets[idx].color_trc; + + if (!source->color_spec_index) { + if (get_bits1(gb)) { + idx = svq3_get_ue_golomb(gb); + if (idx < 3) + avctx->color_primaries = dirac_primaries[idx]; + } + + if (get_bits1(gb)) { + idx = svq3_get_ue_golomb(gb); + if (!idx) + avctx->colorspace = AVCOL_SPC_BT709; + else if (idx == 1) + avctx->colorspace = AVCOL_SPC_BT470BG; + } + + if (get_bits1(gb) && !svq3_get_ue_golomb(gb)) + avctx->color_trc = AVCOL_TRC_BT709; + } + } else { + idx = source->color_spec_index; + avctx->color_primaries = dirac_color_presets[idx].color_primaries; + avctx->colorspace = dirac_color_presets[idx].colorspace; + avctx->color_trc = dirac_color_presets[idx].color_trc; + } + + return 0; +} + +int ff_dirac_parse_sequence_header(AVCodecContext *avctx, GetBitContext *gb, + dirac_source_params *source) +{ + unsigned version_major, version_minor; + unsigned video_format, picture_coding_mode; + + version_major = svq3_get_ue_golomb(gb); + version_minor = svq3_get_ue_golomb(gb); + avctx->profile = svq3_get_ue_golomb(gb); + avctx->level = svq3_get_ue_golomb(gb); + video_format = svq3_get_ue_golomb(gb); + + if (version_major < 2) + av_log(avctx, AV_LOG_WARNING, "Stream is old and may not work\n"); + else if (version_major > 2) + av_log(avctx, AV_LOG_WARNING, "Stream may have unhandled features\n"); + + if (video_format > 20) + return -1; + + // Fill in defaults for the source parameters. + *source = dirac_source_parameters_defaults[video_format]; + + // Override the defaults. + if (parse_source_parameters(avctx, gb, source)) + return -1; + + if (avcodec_check_dimensions(avctx, source->width, source->height)) + return -1; + + avcodec_set_dimensions(avctx, source->width, source->height); + + // currently only used to signal field coding + picture_coding_mode = svq3_get_ue_golomb(gb); + if (picture_coding_mode != 0) { + av_log(avctx, AV_LOG_ERROR, "Unsupported picture coding mode %d", + picture_coding_mode); + return -1; + } + return 0; +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dirac.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/dirac.h new file mode 100644 index 0000000000..09c5581013 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dirac.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2007 Marco Gerards + * Copyright (C) 2009 David Conrad + * + * 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_DIRAC_H +#define AVCODEC_DIRAC_H + +/** + * @file + * Interfaces to Dirac Decoder/Encoder + * @author Marco Gerards + */ + +#include "avcodec.h" +#include "get_bits.h" + +typedef struct { + unsigned width; + unsigned height; + uint8_t chroma_format; ///< 0: 444 1: 422 2: 420 + + uint8_t interlaced; + uint8_t top_field_first; + + uint8_t frame_rate_index; ///< index into dirac_frame_rate[] + uint8_t aspect_ratio_index; ///< index into dirac_aspect_ratio[] + + uint16_t clean_width; + uint16_t clean_height; + uint16_t clean_left_offset; + uint16_t clean_right_offset; + + uint8_t pixel_range_index; ///< index into dirac_pixel_range_presets[] + 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); + +#endif /* AVCODEC_DIRAC_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dirac_parser.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/dirac_parser.c index 1dcb8a51d4..c82f0e673d 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/dirac_parser.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dirac_parser.c @@ -22,7 +22,7 @@ */ /** - * @file libavcodec/dirac_parser.c + * @file * Dirac Parser * @author Marco Gerards */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dnxhd_parser.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/dnxhd_parser.c index 8a5d792565..6149a2daab 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/dnxhd_parser.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dnxhd_parser.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/dnxhd_parser.c + * @file * DNxHD/VC-3 parser */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dnxhddec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/dnxhddec.c index ed349d2b64..8b7c343d09 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/dnxhddec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dnxhddec.c @@ -39,8 +39,8 @@ typedef struct { VLC ac_vlc, dc_vlc, run_vlc; int last_dc[3]; DSPContext dsp; - DECLARE_ALIGNED_16(DCTELEM, blocks[8][64]); - DECLARE_ALIGNED_8(ScanTable, scantable); + DECLARE_ALIGNED(16, DCTELEM, blocks)[8][64]; + ScanTable scantable; const CIDEntry *cid_table; } DNXHDContext; @@ -126,12 +126,17 @@ static int dnxhd_decode_header(DNXHDContext *ctx, const uint8_t *buf, int buf_si ctx->mb_width = ctx->width>>4; ctx->mb_height = buf[0x16d]; - if (ctx->mb_height > 68) { - av_log(ctx->avctx, AV_LOG_ERROR, "mb height too big\n"); + dprintf(ctx->avctx, "mb width %d, mb height %d\n", ctx->mb_width, ctx->mb_height); + + if ((ctx->height+15)>>4 == ctx->mb_height && ctx->picture.interlaced_frame) + ctx->height <<= 1; + + if (ctx->mb_height > 68 || + (ctx->mb_height<picture.interlaced_frame) > (ctx->height+15)>>4) { + av_log(ctx->avctx, AV_LOG_ERROR, "mb height too big: %d\n", ctx->mb_height); return -1; } - dprintf(ctx->avctx, "mb width %d, mb height %d\n", ctx->mb_width, ctx->mb_height); for (i = 0; i < ctx->mb_height; i++) { ctx->mb_scan_index[i] = AV_RB32(buf + 0x170 + (i<<2)); dprintf(ctx->avctx, "mb scan index %d\n", ctx->mb_scan_index[i]); @@ -292,6 +297,13 @@ static int dnxhd_decode_frame(AVCodecContext *avctx, void *data, int *data_size, if (dnxhd_decode_header(ctx, buf, buf_size, first_field) < 0) return -1; + if ((avctx->width || avctx->height) && + (ctx->width != avctx->width || ctx->height != avctx->height)) { + av_log(avctx, AV_LOG_WARNING, "frame size changed: %dx%d -> %dx%d\n", + avctx->width, avctx->height, ctx->width, ctx->height); + first_field = 1; + } + avctx->pix_fmt = PIX_FMT_YUV422P; if (avcodec_check_dimensions(avctx, ctx->width, ctx->height)) return -1; @@ -334,7 +346,7 @@ static av_cold int dnxhd_decode_close(AVCodecContext *avctx) AVCodec dnxhd_decoder = { "dnxhd", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_DNXHD, sizeof(DNXHDContext), dnxhd_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dnxhdenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/dnxhdenc.c index 54ccec4296..6b089299e9 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/dnxhdenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dnxhdenc.c @@ -55,10 +55,10 @@ static int dnxhd_init_vlc(DNXHDEncContext *ctx) int i, j, level, run; int max_level = 1<<(ctx->cid_table->bit_depth+2); - CHECKED_ALLOCZ(ctx->vlc_codes, max_level*4*sizeof(*ctx->vlc_codes)); - CHECKED_ALLOCZ(ctx->vlc_bits, max_level*4*sizeof(*ctx->vlc_bits)); - CHECKED_ALLOCZ(ctx->run_codes, 63*2); - CHECKED_ALLOCZ(ctx->run_bits, 63); + 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); ctx->vlc_codes += max_level*2; ctx->vlc_bits += max_level*2; @@ -111,10 +111,10 @@ static int dnxhd_init_qmat(DNXHDEncContext *ctx, int lbias, int cbias) uint16_t weight_matrix[64] = {1,}; // convert_matrix needs uint16_t* int qscale, i; - CHECKED_ALLOCZ(ctx->qmatrix_l, (ctx->m.avctx->qmax+1) * 64 * sizeof(int)); - CHECKED_ALLOCZ(ctx->qmatrix_c, (ctx->m.avctx->qmax+1) * 64 * sizeof(int)); - CHECKED_ALLOCZ(ctx->qmatrix_l16, (ctx->m.avctx->qmax+1) * 64 * 2 * sizeof(uint16_t)); - CHECKED_ALLOCZ(ctx->qmatrix_c16, (ctx->m.avctx->qmax+1) * 64 * 2 * sizeof(uint16_t)); + 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]]; @@ -142,9 +142,9 @@ static int dnxhd_init_qmat(DNXHDEncContext *ctx, int lbias, int cbias) static int dnxhd_init_rc(DNXHDEncContext *ctx) { - CHECKED_ALLOCZ(ctx->mb_rc, 8160*ctx->m.avctx->qmax*sizeof(RCEntry)); + FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->mb_rc, 8160*ctx->m.avctx->qmax*sizeof(RCEntry), fail); if (ctx->m.avctx->mb_decision != FF_MB_DECISION_RD) - CHECKED_ALLOCZ(ctx->mb_cmp, ctx->m.mb_num*sizeof(RCCMPEntry)); + FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->mb_cmp, ctx->m.mb_num*sizeof(RCCMPEntry), fail); ctx->frame_bits = (ctx->cid_table->coding_unit_size - 640 - 4) * 8; ctx->qscale = 1; @@ -203,15 +203,16 @@ static int dnxhd_encode_init(AVCodecContext *avctx) if (dnxhd_init_rc(ctx) < 0) return -1; - CHECKED_ALLOCZ(ctx->slice_size, ctx->m.mb_height*sizeof(uint32_t)); - CHECKED_ALLOCZ(ctx->mb_bits, ctx->m.mb_num *sizeof(uint16_t)); - CHECKED_ALLOCZ(ctx->mb_qscale, ctx->m.mb_num *sizeof(uint8_t)); + 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); ctx->frame.key_frame = 1; ctx->frame.pict_type = FF_I_TYPE; ctx->m.avctx->coded_frame = &ctx->frame; - if (avctx->thread_count > MAX_THREADS || (avctx->thread_count > ctx->m.mb_height)) { + if (avctx->thread_count > MAX_THREADS) { av_log(avctx, AV_LOG_ERROR, "too many threads\n"); return -1; } @@ -222,13 +223,8 @@ static int dnxhd_encode_init(AVCodecContext *avctx) memcpy(ctx->thread[i], ctx, sizeof(DNXHDEncContext)); } - for (i = 0; i < avctx->thread_count; i++) { - ctx->thread[i]->m.start_mb_y = (ctx->m.mb_height*(i ) + avctx->thread_count/2) / avctx->thread_count; - ctx->thread[i]->m.end_mb_y = (ctx->m.mb_height*(i+1) + avctx->thread_count/2) / avctx->thread_count; - } - return 0; - fail: //for CHECKED_ALLOCZ + fail: //for FF_ALLOCZ_OR_GOTO return -1; } @@ -237,6 +233,8 @@ static int dnxhd_write_header(AVCodecContext *avctx, uint8_t *buf) DNXHDEncContext *ctx = avctx->priv_data; const uint8_t header_prefix[5] = { 0x00,0x00,0x02,0x80,0x01 }; + memset(buf, 0, 640); + memcpy(buf, header_prefix, 5); buf[5] = ctx->interlaced ? ctx->cur_field+2 : 0x01; buf[6] = 0x80; // crc flag off @@ -395,98 +393,97 @@ static av_always_inline int dnxhd_switch_matrix(DNXHDEncContext *ctx, int i) } } -static int dnxhd_calc_bits_thread(AVCodecContext *avctx, void *arg) +static int dnxhd_calc_bits_thread(AVCodecContext *avctx, void *arg, int jobnr, int threadnr) { - DNXHDEncContext *ctx = *(void**)arg; - int mb_y, mb_x; - int qscale = ctx->thread[0]->qscale; + DNXHDEncContext *ctx = avctx->priv_data; + int mb_y = jobnr, mb_x; + int qscale = ctx->qscale; + LOCAL_ALIGNED_16(DCTELEM, block, [64]); + ctx = ctx->thread[threadnr]; - for (mb_y = ctx->m.start_mb_y; mb_y < ctx->m.end_mb_y; mb_y++) { - ctx->m.last_dc[0] = - ctx->m.last_dc[1] = - ctx->m.last_dc[2] = 1024; + ctx->m.last_dc[0] = + ctx->m.last_dc[1] = + ctx->m.last_dc[2] = 1024; - for (mb_x = 0; mb_x < ctx->m.mb_width; mb_x++) { - unsigned mb = mb_y * ctx->m.mb_width + mb_x; - int ssd = 0; - int ac_bits = 0; - int dc_bits = 0; - int i; + for (mb_x = 0; mb_x < ctx->m.mb_width; mb_x++) { + unsigned mb = mb_y * ctx->m.mb_width + mb_x; + int ssd = 0; + int ac_bits = 0; + int dc_bits = 0; + int i; - dnxhd_get_blocks(ctx, mb_x, mb_y); + dnxhd_get_blocks(ctx, mb_x, mb_y); - for (i = 0; i < 8; i++) { - DECLARE_ALIGNED_16(DCTELEM, block[64]); - DCTELEM *src_block = ctx->blocks[i]; - int overflow, nbits, diff, last_index; - int n = dnxhd_switch_matrix(ctx, i); + for (i = 0; i < 8; i++) { + DCTELEM *src_block = ctx->blocks[i]; + int overflow, nbits, diff, last_index; + int n = dnxhd_switch_matrix(ctx, i); - memcpy(block, src_block, sizeof(block)); - last_index = ctx->m.dct_quantize((MpegEncContext*)ctx, block, i, qscale, &overflow); - ac_bits += dnxhd_calc_ac_bits(ctx, block, last_index); + memcpy(block, src_block, 64*sizeof(*block)); + last_index = ctx->m.dct_quantize((MpegEncContext*)ctx, block, 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); - dc_bits += ctx->cid_table->dc_bits[nbits] + nbits; + diff = block[0] - ctx->m.last_dc[n]; + if (diff < 0) nbits = av_log2_16bit(-2*diff); + else nbits = av_log2_16bit( 2*diff); + dc_bits += ctx->cid_table->dc_bits[nbits] + nbits; - ctx->m.last_dc[n] = block[0]; + ctx->m.last_dc[n] = block[0]; - if (avctx->mb_decision == FF_MB_DECISION_RD || !RC_VARIANCE) { - dnxhd_unquantize_c(ctx, block, i, qscale, last_index); - ctx->m.dsp.idct(block); - ssd += dnxhd_ssd_block(block, src_block); - } + if (avctx->mb_decision == FF_MB_DECISION_RD || !RC_VARIANCE) { + dnxhd_unquantize_c(ctx, block, i, qscale, last_index); + ctx->m.dsp.idct(block); + ssd += dnxhd_ssd_block(block, src_block); } - ctx->mb_rc[qscale][mb].ssd = ssd; - ctx->mb_rc[qscale][mb].bits = ac_bits+dc_bits+12+8*ctx->vlc_bits[0]; } + ctx->mb_rc[qscale][mb].ssd = ssd; + ctx->mb_rc[qscale][mb].bits = ac_bits+dc_bits+12+8*ctx->vlc_bits[0]; } return 0; } -static int dnxhd_encode_thread(AVCodecContext *avctx, void *arg) +static int dnxhd_encode_thread(AVCodecContext *avctx, void *arg, int jobnr, int threadnr) { - DNXHDEncContext *ctx = *(void**)arg; - int mb_y, mb_x; + DNXHDEncContext *ctx = avctx->priv_data; + int mb_y = jobnr, mb_x; + ctx = ctx->thread[threadnr]; + init_put_bits(&ctx->m.pb, (uint8_t *)arg + 640 + ctx->slice_offs[jobnr], ctx->slice_size[jobnr]); - for (mb_y = ctx->m.start_mb_y; mb_y < ctx->m.end_mb_y; mb_y++) { - ctx->m.last_dc[0] = - ctx->m.last_dc[1] = - ctx->m.last_dc[2] = 1024; - 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]; - int i; + ctx->m.last_dc[0] = + ctx->m.last_dc[1] = + ctx->m.last_dc[2] = 1024; + 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]; + int i; - put_bits(&ctx->m.pb, 12, qscale<<1); + put_bits(&ctx->m.pb, 12, qscale<<1); - dnxhd_get_blocks(ctx, mb_x, mb_y); + dnxhd_get_blocks(ctx, mb_x, mb_y); - for (i = 0; i < 8; i++) { - DCTELEM *block = ctx->blocks[i]; - int last_index, overflow; - int n = dnxhd_switch_matrix(ctx, i); - last_index = ctx->m.dct_quantize((MpegEncContext*)ctx, block, i, qscale, &overflow); - //START_TIMER; - dnxhd_encode_block(ctx, block, last_index, n); - //STOP_TIMER("encode_block"); - } + for (i = 0; i < 8; i++) { + DCTELEM *block = ctx->blocks[i]; + int last_index, overflow; + int n = dnxhd_switch_matrix(ctx, i); + last_index = ctx->m.dct_quantize((MpegEncContext*)ctx, block, i, qscale, &overflow); + //START_TIMER; + dnxhd_encode_block(ctx, block, last_index, n); + //STOP_TIMER("encode_block"); } - if (put_bits_count(&ctx->m.pb)&31) - put_bits(&ctx->m.pb, 32-(put_bits_count(&ctx->m.pb)&31), 0); } + if (put_bits_count(&ctx->m.pb)&31) + put_bits(&ctx->m.pb, 32-(put_bits_count(&ctx->m.pb)&31), 0); flush_put_bits(&ctx->m.pb); return 0; } -static void dnxhd_setup_threads_slices(DNXHDEncContext *ctx, uint8_t *buf) +static void dnxhd_setup_threads_slices(DNXHDEncContext *ctx) { int mb_y, mb_x; - int i, offset = 0; - for (i = 0; i < ctx->m.avctx->thread_count; i++) { - int thread_size = 0; - for (mb_y = ctx->thread[i]->m.start_mb_y; mb_y < ctx->thread[i]->m.end_mb_y; mb_y++) { + int offset = 0; + 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; @@ -494,26 +491,23 @@ static void dnxhd_setup_threads_slices(DNXHDEncContext *ctx, uint8_t *buf) } 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]; - } - init_put_bits(&ctx->thread[i]->m.pb, buf + 640 + offset, thread_size); + thread_size = ctx->slice_size[mb_y]; offset += thread_size; } } -static int dnxhd_mb_var_thread(AVCodecContext *avctx, void *arg) +static int dnxhd_mb_var_thread(AVCodecContext *avctx, void *arg, int jobnr, int threadnr) { - DNXHDEncContext *ctx = *(void**)arg; - int mb_y, mb_x; - for (mb_y = ctx->m.start_mb_y; mb_y < ctx->m.end_mb_y; mb_y++) { - 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; - } + 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; } return 0; } @@ -526,7 +520,7 @@ static int dnxhd_encode_rdo(AVCodecContext *avctx, DNXHDEncContext *ctx) for (q = 1; q < avctx->qmax; q++) { ctx->qscale = q; - avctx->execute(avctx, dnxhd_calc_bits_thread, (void**)&ctx->thread[0], NULL, avctx->thread_count, sizeof(void*)); + avctx->execute2(avctx, dnxhd_calc_bits_thread, NULL, NULL, ctx->m.mb_height); } up_step = down_step = 2<lambda; @@ -580,9 +574,11 @@ static int dnxhd_encode_rdo(AVCodecContext *avctx, DNXHDEncContext *ctx) last_higher = FFMAX(lambda, last_higher); if (last_lower != INT_MAX) lambda = (lambda+last_lower)>>1; + else if ((int64_t)lambda + up_step > INT_MAX) + return -1; else lambda += up_step; - up_step *= 5; + up_step = FFMIN((int64_t)up_step*5, INT_MAX); down_step = 1<qscale = qscale; // XXX avoid recalculating bits - ctx->m.avctx->execute(ctx->m.avctx, dnxhd_calc_bits_thread, (void**)&ctx->thread[0], NULL, ctx->m.avctx->thread_count, sizeof(void*)); + ctx->m.avctx->execute2(ctx->m.avctx, dnxhd_calc_bits_thread, NULL, NULL, ctx->m.mb_height); for (y = 0; y < ctx->m.mb_height; y++) { for (x = 0; x < ctx->m.mb_width; x++) bits += ctx->mb_rc[qscale][y*ctx->m.mb_width+x].bits; @@ -649,9 +645,60 @@ static int dnxhd_find_qscale(DNXHDEncContext *ctx) return 0; } -static int dnxhd_rc_cmp(const void *a, const void *b) +#define BUCKET_BITS 8 +#define RADIX_PASSES 4 +#define NBUCKETS (1 << BUCKET_BITS) + +static inline int get_bucket(int value, int shift) { - return ((const RCCMPEntry *)b)->value - ((const RCCMPEntry *)a)->value; + value >>= shift; + value &= NBUCKETS - 1; + return NBUCKETS - 1 - value; +} + +static void radix_count(const RCCMPEntry *data, int size, int buckets[RADIX_PASSES][NBUCKETS]) +{ + int i, j; + memset(buckets, 0, sizeof(buckets[0][0]) * RADIX_PASSES * NBUCKETS); + for (i = 0; i < size; i++) { + int v = data[i].value; + for (j = 0; j < RADIX_PASSES; j++) { + buckets[j][get_bucket(v, 0)]++; + v >>= BUCKET_BITS; + } + assert(!v); + } + for (j = 0; j < RADIX_PASSES; j++) { + int offset = size; + for (i = NBUCKETS - 1; i >= 0; i--) + buckets[j][i] = offset -= buckets[j][i]; + assert(!buckets[j][0]); + } +} + +static void radix_sort_pass(RCCMPEntry *dst, const RCCMPEntry *data, int size, int buckets[NBUCKETS], int pass) +{ + int shift = pass * BUCKET_BITS; + int i; + for (i = 0; i < size; i++) { + int v = get_bucket(data[i].value, shift); + int pos = buckets[v]++; + dst[pos] = data[i]; + } +} + +static void radix_sort(RCCMPEntry *data, int size) +{ + int buckets[RADIX_PASSES][NBUCKETS]; + RCCMPEntry *tmp = av_malloc(sizeof(*tmp) * size); + radix_count(data, size, buckets); + radix_sort_pass(tmp, data, size, buckets[0], 0); + radix_sort_pass(data, tmp, size, buckets[1], 1); + if (buckets[2][NBUCKETS - 1] || buckets[3][NBUCKETS - 1]) { + radix_sort_pass(tmp, data, size, buckets[2], 2); + radix_sort_pass(data, tmp, size, buckets[3], 3); + } + av_free(tmp); } static int dnxhd_encode_fast(AVCodecContext *avctx, DNXHDEncContext *ctx) @@ -679,8 +726,8 @@ static int dnxhd_encode_fast(AVCodecContext *avctx, DNXHDEncContext *ctx) } if (!ret) { if (RC_VARIANCE) - avctx->execute(avctx, dnxhd_mb_var_thread, (void**)&ctx->thread[0], NULL, avctx->thread_count, sizeof(void*)); - qsort(ctx->mb_cmp, ctx->m.mb_num, sizeof(RCEntry), dnxhd_rc_cmp); + avctx->execute2(avctx, dnxhd_mb_var_thread, NULL, NULL, ctx->m.mb_height); + radix_sort(ctx->mb_cmp, ctx->m.mb_num); for (x = 0; x < ctx->m.mb_num && max_bits > ctx->frame_bits; x++) { int mb = ctx->mb_cmp[x].mb; max_bits -= ctx->mb_rc[ctx->qscale][mb].bits - ctx->mb_rc[ctx->qscale+1][mb].bits; @@ -738,11 +785,12 @@ static int dnxhd_encode_picture(AVCodecContext *avctx, unsigned char *buf, int b else ret = dnxhd_encode_fast(avctx, ctx); if (ret < 0) { - av_log(avctx, AV_LOG_ERROR, "picture could not fit ratecontrol constraints\n"); + av_log(avctx, AV_LOG_ERROR, + "picture could not fit ratecontrol constraints, increase qmax\n"); return -1; } - dnxhd_setup_threads_slices(ctx, buf); + dnxhd_setup_threads_slices(ctx); offset = 0; for (i = 0; i < ctx->m.mb_height; i++) { @@ -751,7 +799,10 @@ static int dnxhd_encode_picture(AVCodecContext *avctx, unsigned char *buf, int b assert(!(ctx->slice_size[i] & 3)); } - avctx->execute(avctx, dnxhd_encode_thread, (void**)&ctx->thread[0], NULL, avctx->thread_count, sizeof(void*)); + avctx->execute2(avctx, dnxhd_encode_thread, buf, NULL, ctx->m.mb_height); + + assert(640 + offset + 4 <= ctx->cid_table->coding_unit_size); + memset(buf + 640 + offset, 0, ctx->cid_table->coding_unit_size - 4 - offset - 640); AV_WB32(buf + ctx->cid_table->coding_unit_size - 4, 0x600DC0DE); // EOF @@ -784,6 +835,7 @@ static int dnxhd_encode_end(AVCodecContext *avctx) av_freep(&ctx->mb_rc); av_freep(&ctx->mb_cmp); av_freep(&ctx->slice_size); + av_freep(&ctx->slice_offs); av_freep(&ctx->qmatrix_c); av_freep(&ctx->qmatrix_l); @@ -798,12 +850,12 @@ static int dnxhd_encode_end(AVCodecContext *avctx) AVCodec dnxhd_encoder = { "dnxhd", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_DNXHD, sizeof(DNXHDEncContext), dnxhd_encode_init, dnxhd_encode_picture, dnxhd_encode_end, - .pix_fmts = (enum PixelFormat[]){PIX_FMT_YUV422P, PIX_FMT_NONE}, + .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV422P, PIX_FMT_NONE}, .long_name = NULL_IF_CONFIG_SMALL("VC3/DNxHD"), }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dnxhdenc.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/dnxhdenc.h index 6f9f647ef0..eaf33d5cb9 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/dnxhdenc.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dnxhdenc.h @@ -46,6 +46,7 @@ typedef struct DNXHDEncContext { const CIDEntry *cid_table; uint8_t *msip; ///< Macroblock Scan Indexes Payload uint32_t *slice_size; + uint32_t *slice_offs; struct DNXHDEncContext *thread[MAX_THREADS]; @@ -54,7 +55,7 @@ typedef struct DNXHDEncContext { int interlaced; int cur_field; - DECLARE_ALIGNED_16(DCTELEM, blocks[8][64]); + DECLARE_ALIGNED(16, DCTELEM, blocks)[8][64]; int (*qmatrix_c) [64]; int (*qmatrix_l) [64]; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dpcm.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/dpcm.c index 69c7002ad7..7c5351686e 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/dpcm.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dpcm.c @@ -301,7 +301,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, #define DPCM_DECODER(id, name, long_name_) \ AVCodec name ## _decoder = { \ #name, \ - CODEC_TYPE_AUDIO, \ + AVMEDIA_TYPE_AUDIO, \ id, \ sizeof(DPCMContext), \ dpcm_decode_init, \ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dpx.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/dpx.c index fec12f94ca..94a91816c5 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/dpx.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dpx.c @@ -92,6 +92,7 @@ static int decode_frame(AVCodecContext *avctx, // Need to end in 0x323 to read the bits per color buf += 3; + avctx->bits_per_raw_sample = bits_per_color = buf[0]; switch (descriptor) { @@ -215,7 +216,7 @@ static av_cold int decode_end(AVCodecContext *avctx) AVCodec dpx_decoder = { "dpx", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_DPX, sizeof(DPXContext), decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dsicinav.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/dsicinav.c index 6e5ff12446..895b6237d7 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/dsicinav.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dsicinav.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/dsicinav.c + * @file * Delphine Software International CIN audio/video decoders */ @@ -345,7 +345,7 @@ static int cinaudio_decode_frame(AVCodecContext *avctx, AVCodec dsicinvideo_decoder = { "dsicinvideo", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_DSICINVIDEO, sizeof(CinVideoContext), cinvideo_decode_init, @@ -358,7 +358,7 @@ AVCodec dsicinvideo_decoder = { AVCodec dsicinaudio_decoder = { "dsicinaudio", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_DSICINAUDIO, sizeof(CinAudioContext), cinaudio_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dsputil.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/dsputil.c index 8efe9edf19..07013240c0 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/dsputil.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dsputil.c @@ -23,7 +23,7 @@ */ /** - * @file libavcodec/dsputil.c + * @file * DSP utils */ @@ -33,26 +33,12 @@ #include "faandct.h" #include "faanidct.h" #include "mathops.h" -#include "h263.h" -#include "snow.h" - -/* snow.c */ -void ff_spatial_dwt(int *buffer, int width, int height, int stride, int type, int decomposition_count); - -/* vorbis.c */ -void vorbis_inverse_coupling(float *mag, float *ang, int blocksize); - -/* ac3dec.c */ -void ff_ac3_downmix_c(float (*samples)[256], float (*matrix)[2], int out_ch, int in_ch, int len); - -/* flacenc.c */ -void ff_flac_compute_autocorr(const int32_t *data, int len, int lag, double *autoc); - -/* pngdec.c */ -void ff_add_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp); - -/* eaidct.c */ -void ff_ea_idct_put_c(uint8_t *dest, int linesize, DCTELEM *block); +#include "mpegvideo.h" +#include "config.h" +#include "lpc.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, }; @@ -86,7 +72,7 @@ const uint8_t ff_zigzag248_direct[64] = { }; /* not permutated inverse zigzag_direct + 1 for MMX quantizer */ -DECLARE_ALIGNED_8(uint16_t, inv_zigzag_direct16[64]) = {0, }; +DECLARE_ALIGNED(16, uint16_t, inv_zigzag_direct16)[64]; const uint8_t ff_alternate_horizontal_scan[64] = { 0, 1, 2, 3, 8, 9, 16, 17, @@ -110,8 +96,9 @@ const uint8_t ff_alternate_vertical_scan[64] = { 38, 46, 54, 62, 39, 47, 55, 63, }; -/* a*inverse[b]>>32 == a/b for all 0<=a<=65536 && 2<=b<=255 */ -const uint32_t ff_inverse[256]={ +/* a*inverse[b]>>32 == a/b for all 0<=a<=16909558 && 2<=b<=256 + * for a>16909558, is an overestimate by less than 1 part in 1<<24 */ +const uint32_t ff_inverse[257]={ 0, 4294967295U,2147483648U,1431655766, 1073741824, 858993460, 715827883, 613566757, 536870912, 477218589, 429496730, 390451573, 357913942, 330382100, 306783379, 286331154, 268435456, 252645136, 238609295, 226050911, 214748365, 204522253, 195225787, 186737709, @@ -144,6 +131,7 @@ const uint32_t ff_inverse[256]={ 18512791, 18433337, 18354562, 18276457, 18199014, 18122225, 18046082, 17970575, 17895698, 17821442, 17747799, 17674763, 17602325, 17530479, 17459217, 17388532, 17318417, 17248865, 17179870, 17111424, 17043522, 16976156, 16909321, 16843010, + 16777216 }; /* Input permutation for the simple_idct_mmx */ @@ -340,102 +328,6 @@ static int sse16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) return s; } - -#if CONFIG_SNOW_ENCODER //dwt is in snow.c -static inline int w_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int w, int h, int type){ - int s, i, j; - const int dec_count= w==8 ? 3 : 4; - int tmp[32*32]; - int level, ori; - static const int scale[2][2][4][4]={ - { - { - // 9/7 8x8 dec=3 - {268, 239, 239, 213}, - { 0, 224, 224, 152}, - { 0, 135, 135, 110}, - },{ - // 9/7 16x16 or 32x32 dec=4 - {344, 310, 310, 280}, - { 0, 320, 320, 228}, - { 0, 175, 175, 136}, - { 0, 129, 129, 102}, - } - },{ - { - // 5/3 8x8 dec=3 - {275, 245, 245, 218}, - { 0, 230, 230, 156}, - { 0, 138, 138, 113}, - },{ - // 5/3 16x16 or 32x32 dec=4 - {352, 317, 317, 286}, - { 0, 328, 328, 233}, - { 0, 180, 180, 140}, - { 0, 132, 132, 105}, - } - } - }; - - for (i = 0; i < h; i++) { - for (j = 0; j < w; j+=4) { - tmp[32*i+j+0] = (pix1[j+0] - pix2[j+0])<<4; - tmp[32*i+j+1] = (pix1[j+1] - pix2[j+1])<<4; - tmp[32*i+j+2] = (pix1[j+2] - pix2[j+2])<<4; - tmp[32*i+j+3] = (pix1[j+3] - pix2[j+3])<<4; - } - pix1 += line_size; - pix2 += line_size; - } - - ff_spatial_dwt(tmp, w, h, 32, type, dec_count); - - s=0; - assert(w==h); - for(level=0; level>(dec_count-level); - int sx= (ori&1) ? size : 0; - int stride= 32<<(dec_count-level); - int sy= (ori&2) ? stride>>1 : 0; - - for(i=0; i=0); - return s>>9; -} - -static int w53_8_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){ - return w_c(v, pix1, pix2, line_size, 8, h, 1); -} - -static int w97_8_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){ - return w_c(v, pix1, pix2, line_size, 8, h, 0); -} - -static int w53_16_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){ - return w_c(v, pix1, pix2, line_size, 16, h, 1); -} - -static int w97_16_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){ - return w_c(v, pix1, pix2, line_size, 16, h, 0); -} - -int w53_32_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){ - return w_c(v, pix1, pix2, line_size, 32, h, 1); -} - -int w97_32_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){ - return w_c(v, pix1, pix2, line_size, 32, h, 0); -} -#endif - /* draw the edges of width 'w' of an image of size width, height */ //FIXME check that this is ok for mpeg4 interlaced static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w) @@ -653,6 +545,27 @@ static void 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; + } +} + static void add_pixels_clamped_c(const DCTELEM *block, uint8_t *restrict pixels, int line_size) { @@ -744,6 +657,42 @@ static int sum_abs_dctelem_c(DCTELEM *block) return sum; } +static void fill_block16_c(uint8_t *block, uint8_t value, int line_size, int h) +{ + int i; + + for (i = 0; i < h; i++) { + memset(block, value, 16); + block += line_size; + } +} + +static void fill_block8_c(uint8_t *block, uint8_t value, int line_size, int h) +{ + int i; + + for (i = 0; i < h; i++) { + memset(block, value, 8); + block += line_size; + } +} + +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; + } +} + #if 0 #define PIXOP2(OPNAME, OP) \ @@ -2648,76 +2597,6 @@ H264_MC(avg_, 16) #undef op2_put #endif -#define op_scale1(x) block[x] = av_clip_uint8( (block[x]*weight + offset) >> log2_denom ) -#define op_scale2(x) dst[x] = av_clip_uint8( (src[x]*weights + dst[x]*weightd + offset) >> (log2_denom+1)) -#define H264_WEIGHT(W,H) \ -static void weight_h264_pixels ## W ## x ## H ## _c(uint8_t *block, int stride, int log2_denom, int weight, int offset){ \ - int y; \ - offset <<= log2_denom; \ - if(log2_denom) offset += 1<<(log2_denom-1); \ - for(y=0; y> 1 ) ) >> 1) - p1, -tc0[i], tc0[i] ); - tc++; - } - if( FFABS( q2 - q0 ) < beta ) { - pix[ xstride] = q1 + av_clip( (( q2 + ( ( p0 + q0 + 1 ) >> 1 ) ) >> 1) - q1, -tc0[i], tc0[i] ); - tc++; - } - - i_delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); - pix[-xstride] = av_clip_uint8( p0 + i_delta ); /* p0' */ - pix[0] = av_clip_uint8( q0 - i_delta ); /* q0' */ - } - pix += ystride; - } - } -} -static void h264_v_loop_filter_luma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) -{ - h264_loop_filter_luma_c(pix, stride, 1, alpha, beta, tc0); -} -static void h264_h_loop_filter_luma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) -{ - h264_loop_filter_luma_c(pix, 1, stride, alpha, beta, tc0); -} - -static inline void h264_loop_filter_luma_intra_c(uint8_t *pix, int xstride, int ystride, int alpha, int beta) -{ - int d; - for( d = 0; d < 16; d++ ) { - const int p2 = pix[-3*xstride]; - const int p1 = pix[-2*xstride]; - const int p0 = pix[-1*xstride]; - - const int q0 = pix[ 0*xstride]; - const int q1 = pix[ 1*xstride]; - const int q2 = pix[ 2*xstride]; - - if( FFABS( p0 - q0 ) < alpha && - FFABS( p1 - p0 ) < beta && - FFABS( q1 - q0 ) < beta ) { - - if(FFABS( p0 - q0 ) < (( alpha >> 2 ) + 2 )){ - if( FFABS( p2 - p0 ) < beta) - { - const int p3 = pix[-4*xstride]; - /* p0', p1', p2' */ - pix[-1*xstride] = ( p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4 ) >> 3; - pix[-2*xstride] = ( p2 + p1 + p0 + q0 + 2 ) >> 2; - pix[-3*xstride] = ( 2*p3 + 3*p2 + p1 + p0 + q0 + 4 ) >> 3; - } else { - /* p0' */ - pix[-1*xstride] = ( 2*p1 + p0 + q1 + 2 ) >> 2; - } - if( FFABS( q2 - q0 ) < beta) - { - const int q3 = pix[3*xstride]; - /* q0', q1', q2' */ - pix[0*xstride] = ( p1 + 2*p0 + 2*q0 + 2*q1 + q2 + 4 ) >> 3; - pix[1*xstride] = ( p0 + q0 + q1 + q2 + 2 ) >> 2; - pix[2*xstride] = ( 2*q3 + 3*q2 + q1 + q0 + p0 + 4 ) >> 3; - } else { - /* q0' */ - pix[0*xstride] = ( 2*q1 + q0 + p1 + 2 ) >> 2; - } - }else{ - /* p0', q0' */ - pix[-1*xstride] = ( 2*p1 + p0 + q1 + 2 ) >> 2; - pix[ 0*xstride] = ( 2*q1 + q0 + p1 + 2 ) >> 2; - } - } - pix += ystride; - } -} -static void h264_v_loop_filter_luma_intra_c(uint8_t *pix, int stride, int alpha, int beta) -{ - h264_loop_filter_luma_intra_c(pix, stride, 1, alpha, beta); -} -static void h264_h_loop_filter_luma_intra_c(uint8_t *pix, int stride, int alpha, int beta) -{ - h264_loop_filter_luma_intra_c(pix, 1, stride, alpha, beta); -} - -static inline void h264_loop_filter_chroma_c(uint8_t *pix, int xstride, int ystride, int alpha, int beta, int8_t *tc0) -{ - int i, d; - for( i = 0; i < 4; i++ ) { - const int tc = tc0[i]; - if( tc <= 0 ) { - pix += 2*ystride; - continue; - } - for( d = 0; d < 2; d++ ) { - const int p0 = pix[-1*xstride]; - const int p1 = pix[-2*xstride]; - const int q0 = pix[0]; - const int q1 = pix[1*xstride]; - - if( FFABS( p0 - q0 ) < alpha && - FFABS( p1 - p0 ) < beta && - FFABS( q1 - q0 ) < beta ) { - - int delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); - - pix[-xstride] = av_clip_uint8( p0 + delta ); /* p0' */ - pix[0] = av_clip_uint8( q0 - delta ); /* q0' */ - } - pix += ystride; - } - } -} -static void h264_v_loop_filter_chroma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) -{ - h264_loop_filter_chroma_c(pix, stride, 1, alpha, beta, tc0); -} -static void h264_h_loop_filter_chroma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) -{ - h264_loop_filter_chroma_c(pix, 1, stride, alpha, beta, tc0); -} - -static inline void h264_loop_filter_chroma_intra_c(uint8_t *pix, int xstride, int ystride, int alpha, int beta) -{ - int d; - for( d = 0; d < 8; d++ ) { - const int p0 = pix[-1*xstride]; - const int p1 = pix[-2*xstride]; - const int q0 = pix[0]; - const int q1 = pix[1*xstride]; - - if( FFABS( p0 - q0 ) < alpha && - FFABS( p1 - p0 ) < beta && - FFABS( q1 - q0 ) < beta ) { - - pix[-xstride] = ( 2*p1 + p0 + q1 + 2 ) >> 2; /* p0' */ - pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; /* q0' */ - } - pix += ystride; - } -} -static void h264_v_loop_filter_chroma_intra_c(uint8_t *pix, int stride, int alpha, int beta) -{ - h264_loop_filter_chroma_intra_c(pix, stride, 1, alpha, beta); -} -static void h264_h_loop_filter_chroma_intra_c(uint8_t *pix, int stride, int alpha, int beta) -{ - h264_loop_filter_chroma_intra_c(pix, 1, stride, alpha, beta); -} - static inline int pix_abs16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) { int s, i; @@ -3497,7 +3188,7 @@ void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type){ case FF_CMP_NSSE: cmp[i]= c->nsse[i]; break; -#if CONFIG_SNOW_ENCODER +#if CONFIG_DWT case FF_CMP_W53: cmp[i]= c->w53[i]; break; @@ -3571,7 +3262,7 @@ static void diff_bytes_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){ dst[i+0] = src1[i+0]-src2[i+0]; } -static void add_hfyu_median_prediction_c(uint8_t *dst, uint8_t *src1, uint8_t *diff, int w, int *left, int *left_top){ +static void add_hfyu_median_prediction_c(uint8_t *dst, const uint8_t *src1, const uint8_t *diff, int w, int *left, int *left_top){ int i; uint8_t l, lt; @@ -3588,7 +3279,7 @@ static void add_hfyu_median_prediction_c(uint8_t *dst, uint8_t *src1, uint8_t *d *left_top= lt; } -static void sub_hfyu_median_prediction_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w, int *left, int *left_top){ +static void sub_hfyu_median_prediction_c(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int w, int *left, int *left_top){ int i; uint8_t l, lt; @@ -3606,6 +3297,66 @@ static void sub_hfyu_median_prediction_c(uint8_t *dst, uint8_t *src1, uint8_t *s *left_top= lt; } +static int add_hfyu_left_prediction_c(uint8_t *dst, const uint8_t *src, int w, int acc){ + int i; + + for(i=0; iintra_scantable.permutated; - DECLARE_ALIGNED_8 (uint64_t, aligned_temp[sizeof(DCTELEM)*64/8]); - DECLARE_ALIGNED_8 (uint64_t, aligned_src1[8]); - DECLARE_ALIGNED_8 (uint64_t, aligned_src2[8]); - DCTELEM * const temp= (DCTELEM*)aligned_temp; - uint8_t * const lsrc1 = (uint8_t*)aligned_src1; - uint8_t * const lsrc2 = (uint8_t*)aligned_src2; + LOCAL_ALIGNED_16(DCTELEM, temp, [64]); + LOCAL_ALIGNED_16(uint8_t, lsrc1, [64]); + LOCAL_ALIGNED_16(uint8_t, lsrc2, [64]); int i, last, run, bits, level, distortion, start_i; const int esc_length= s->ac_esc_length; uint8_t * length; @@ -3909,8 +3654,7 @@ static int rd8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int static int bit8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){ MpegEncContext * const s= (MpegEncContext *)c; const uint8_t *scantable= s->intra_scantable.permutated; - DECLARE_ALIGNED_8 (uint64_t, aligned_temp[sizeof(DCTELEM)*64/8]); - DCTELEM * const temp= (DCTELEM*)aligned_temp; + LOCAL_ALIGNED_16(DCTELEM, temp, [64]); int i, last, run, bits, level, start_i; const int esc_length= s->ac_esc_length; uint8_t * length; @@ -4066,10 +3810,10 @@ static void vector_fmul_reverse_c(float *dst, const float *src0, const float *sr dst[i] = src0[i] * src1[-i]; } -void ff_vector_fmul_add_add_c(float *dst, const float *src0, const float *src1, const float *src2, int src3, int len, int step){ +static void vector_fmul_add_c(float *dst, const float *src0, const float *src1, const float *src2, int len){ int i; for(i=0; i mini) return mini; + else if((a^(1<<31)) > maxisign) return maxi; + else return a; +} + +static void vector_clipf_c_opposite_sign(float *dst, const float *src, float *min, float *max, int len){ + int i; + uint32_t mini = *(uint32_t*)min; + uint32_t maxi = *(uint32_t*)max; + uint32_t maxisign = maxi ^ (1<<31); + uint32_t *dsti = (uint32_t*)dst; + const uint32_t *srci = (const uint32_t*)src; + for(i=0; i 0) { + vector_clipf_c_opposite_sign(dst, src, &min, &max, len); + } else { + for(i=0; i < len; i+=8) { + dst[i ] = av_clipf(src[i ], min, max); + dst[i + 1] = av_clipf(src[i + 1], min, max); + dst[i + 2] = av_clipf(src[i + 2], min, max); + dst[i + 3] = av_clipf(src[i + 3], min, max); + dst[i + 4] = av_clipf(src[i + 4], min, max); + dst[i + 5] = av_clipf(src[i + 5], min, max); + dst[i + 6] = av_clipf(src[i + 6], min, max); + dst[i + 7] = av_clipf(src[i + 7], min, max); + } + } +} + static av_always_inline int float_to_int16_one(const float *src){ int_fast32_t tmp = *(const int32_t*)src; if(tmp & 0xf0000){ @@ -4124,18 +3987,6 @@ void ff_float_to_int16_interleave_c(int16_t *dst, const float **src, long len, i } } -static void add_int16_c(int16_t * v1, int16_t * v2, int order) -{ - while (order--) - *v1++ += *v2++; -} - -static void sub_int16_c(int16_t * v1, int16_t * v2, int order) -{ - while (order--) - *v1++ -= *v2++; -} - static int32_t scalarproduct_int16_c(int16_t * v1, int16_t * v2, int order, int shift) { int res = 0; @@ -4146,6 +3997,16 @@ static int32_t scalarproduct_int16_c(int16_t * v1, int16_t * v2, int order, int return res; } +static int32_t scalarproduct_and_madd_int16_c(int16_t *v1, int16_t *v2, int16_t *v3, int order, int mul) +{ + int res = 0; + while (order--) { + res += *v1 * *v2++; + *v1++ += mul * *v3++; + } + return res; +} + #define W0 2048 #define W1 2841 /* 2048*sqrt (2)*cos (1*pi/16) */ #define W2 2676 /* 2048*sqrt (2)*cos (2*pi/16) */ @@ -4279,7 +4140,7 @@ static void ff_jref_idct1_add(uint8_t *dest, int line_size, DCTELEM *block) static void just_return(void *mem av_unused, int stride av_unused, int h av_unused) { return; } /* init static data */ -void dsputil_static_init(void) +av_cold void dsputil_static_init(void) { int i; @@ -4298,7 +4159,7 @@ void dsputil_static_init(void) int ff_check_alignment(void){ static int did_fail=0; - DECLARE_ALIGNED_16(int, aligned); + DECLARE_ALIGNED(16, int, aligned); if((intptr_t)&aligned & 15){ if(!did_fail){ @@ -4316,7 +4177,7 @@ int ff_check_alignment(void){ return 0; } -void dsputil_init(DSPContext* c, AVCodecContext *avctx) +av_cold void dsputil_init(DSPContext* c, AVCodecContext *avctx) { int i; @@ -4382,6 +4243,11 @@ 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; @@ -4390,21 +4256,11 @@ void dsputil_init(DSPContext* c, AVCodecContext *avctx) } } - if (CONFIG_H264_DECODER) { - c->h264_idct_add= ff_h264_idct_add_c; - c->h264_idct8_add= ff_h264_idct8_add_c; - c->h264_idct_dc_add= ff_h264_idct_dc_add_c; - c->h264_idct8_dc_add= ff_h264_idct8_dc_add_c; - c->h264_idct_add16 = ff_h264_idct_add16_c; - c->h264_idct8_add4 = ff_h264_idct8_add4_c; - c->h264_idct_add8 = ff_h264_idct_add8_c; - c->h264_idct_add16intra= ff_h264_idct_add16intra_c; - } - c->get_pixels = get_pixels_c; c->diff_pixels = diff_pixels_c; c->put_pixels_clamped = put_pixels_clamped_c; c->put_signed_pixels_clamped = put_signed_pixels_clamped_c; + c->put_pixels_nonclamped = put_pixels_nonclamped_c; c->add_pixels_clamped = add_pixels_clamped_c; c->add_pixels8 = add_pixels8_c; c->add_pixels4 = add_pixels4_c; @@ -4416,6 +4272,10 @@ void dsputil_init(DSPContext* c, AVCodecContext *avctx) c->pix_sum = pix_sum_c; c->pix_norm1 = pix_norm1_c; + 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; c->pix_abs[0][1] = pix_abs16_x2_c; @@ -4518,27 +4378,6 @@ void dsputil_init(DSPContext* c, AVCodecContext *avctx) c->put_no_rnd_vc1_chroma_pixels_tab[0]= put_no_rnd_vc1_chroma_mc8_c; c->avg_no_rnd_vc1_chroma_pixels_tab[0]= avg_no_rnd_vc1_chroma_mc8_c; - c->weight_h264_pixels_tab[0]= weight_h264_pixels16x16_c; - c->weight_h264_pixels_tab[1]= weight_h264_pixels16x8_c; - c->weight_h264_pixels_tab[2]= weight_h264_pixels8x16_c; - c->weight_h264_pixels_tab[3]= weight_h264_pixels8x8_c; - c->weight_h264_pixels_tab[4]= weight_h264_pixels8x4_c; - c->weight_h264_pixels_tab[5]= weight_h264_pixels4x8_c; - c->weight_h264_pixels_tab[6]= weight_h264_pixels4x4_c; - c->weight_h264_pixels_tab[7]= weight_h264_pixels4x2_c; - c->weight_h264_pixels_tab[8]= weight_h264_pixels2x4_c; - c->weight_h264_pixels_tab[9]= weight_h264_pixels2x2_c; - c->biweight_h264_pixels_tab[0]= biweight_h264_pixels16x16_c; - c->biweight_h264_pixels_tab[1]= biweight_h264_pixels16x8_c; - c->biweight_h264_pixels_tab[2]= biweight_h264_pixels8x16_c; - c->biweight_h264_pixels_tab[3]= biweight_h264_pixels8x8_c; - c->biweight_h264_pixels_tab[4]= biweight_h264_pixels8x4_c; - c->biweight_h264_pixels_tab[5]= biweight_h264_pixels4x8_c; - c->biweight_h264_pixels_tab[6]= biweight_h264_pixels4x4_c; - c->biweight_h264_pixels_tab[7]= biweight_h264_pixels4x2_c; - c->biweight_h264_pixels_tab[8]= biweight_h264_pixels2x4_c; - c->biweight_h264_pixels_tab[9]= biweight_h264_pixels2x2_c; - c->draw_edges = draw_edges_c; #if CONFIG_CAVS_DECODER @@ -4602,11 +4441,8 @@ void dsputil_init(DSPContext* c, AVCodecContext *avctx) c->vsse[5]= vsse_intra8_c; c->nsse[0]= nsse16_c; c->nsse[1]= nsse8_c; -#if CONFIG_SNOW_ENCODER - c->w53[0]= w53_16_c; - c->w53[1]= w53_8_c; - c->w97[0]= w97_16_c; - c->w97[1]= w97_8_c; +#if CONFIG_DWT + ff_dsputil_init_dwt(c); #endif c->ssd_int8_vs_int16 = ssd_int8_vs_int16_c; @@ -4616,22 +4452,14 @@ void dsputil_init(DSPContext* c, AVCodecContext *avctx) 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; + c->add_hfyu_left_prediction = add_hfyu_left_prediction_c; + c->add_hfyu_left_prediction_bgr32 = add_hfyu_left_prediction_bgr32_c; c->bswap_buf= bswap_buf; #if CONFIG_PNG_DECODER c->add_png_paeth_prediction= ff_add_png_paeth_prediction; #endif - c->h264_v_loop_filter_luma= h264_v_loop_filter_luma_c; - c->h264_h_loop_filter_luma= h264_h_loop_filter_luma_c; - c->h264_v_loop_filter_luma_intra= h264_v_loop_filter_luma_intra_c; - c->h264_h_loop_filter_luma_intra= h264_h_loop_filter_luma_intra_c; - c->h264_v_loop_filter_chroma= h264_v_loop_filter_chroma_c; - c->h264_h_loop_filter_chroma= h264_h_loop_filter_chroma_c; - c->h264_v_loop_filter_chroma_intra= h264_v_loop_filter_chroma_intra_c; - c->h264_h_loop_filter_chroma_intra= h264_h_loop_filter_chroma_intra_c; - c->h264_loop_filter_strength= NULL; - - if (CONFIG_ANY_H263) { + if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) { c->h263_h_loop_filter= h263_h_loop_filter_c; c->h263_v_loop_filter= h263_v_loop_filter_c; } @@ -4639,6 +4467,7 @@ void dsputil_init(DSPContext* c, AVCodecContext *avctx) if (CONFIG_VP3_DECODER) { c->vp3_h_loop_filter= ff_vp3_h_loop_filter_c; c->vp3_v_loop_filter= ff_vp3_v_loop_filter_c; + c->vp3_idct_dc_add= ff_vp3_idct_dc_add_c; } if (CONFIG_VP6_DECODER) { c->vp6_filter_diag4= ff_vp6_filter_diag4_c; @@ -4649,31 +4478,34 @@ void dsputil_init(DSPContext* c, AVCodecContext *avctx) c->try_8x8basis= try_8x8basis_c; c->add_8x8basis= add_8x8basis_c; -#if CONFIG_SNOW_DECODER - c->vertical_compose97i = ff_snow_vertical_compose97i; - c->horizontal_compose97i = ff_snow_horizontal_compose97i; - c->inner_add_yblock = ff_snow_inner_add_yblock; -#endif - #if CONFIG_VORBIS_DECODER c->vorbis_inverse_coupling = vorbis_inverse_coupling; #endif #if CONFIG_AC3_DECODER c->ac3_downmix = ff_ac3_downmix_c; #endif -#if CONFIG_FLAC_ENCODER - c->flac_compute_autocorr = ff_flac_compute_autocorr; +#if CONFIG_LPC + c->lpc_compute_autocorr = ff_lpc_compute_autocorr; #endif c->vector_fmul = vector_fmul_c; c->vector_fmul_reverse = vector_fmul_reverse_c; - c->vector_fmul_add_add = ff_vector_fmul_add_add_c; + c->vector_fmul_add = vector_fmul_add_c; c->vector_fmul_window = ff_vector_fmul_window_c; c->int32_to_float_fmul_scalar = int32_to_float_fmul_scalar_c; + c->vector_clipf = vector_clipf_c; c->float_to_int16 = ff_float_to_int16_c; c->float_to_int16_interleave = ff_float_to_int16_interleave_c; - c->add_int16 = add_int16_c; - c->sub_int16 = sub_int16_c; c->scalarproduct_int16 = scalarproduct_int16_c; + c->scalarproduct_and_madd_int16 = scalarproduct_and_madd_int16_c; + 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->shrink[0]= ff_img_copy_plane; c->shrink[1]= ff_shrink22; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dsputil.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/dsputil.h index 2d15bd3538..fd2d07f6e6 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/dsputil.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dsputil.h @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/dsputil.h + * @file * DSP utils. * note, many functions in here may use MMX which trashes the FPU state, it is * absolutely necessary to call emms_c() between dsp & float/double code @@ -37,8 +37,6 @@ //#define DEBUG /* dct code */ typedef short DCTELEM; -typedef int DWTELEM; -typedef short IDWTELEM; void fdct_ifast (DCTELEM *data); void fdct_ifast248 (DCTELEM *data); @@ -66,8 +64,6 @@ void ff_h264_idct_add16intra_c(uint8_t *dst, const int *blockoffset, DCTELEM *bl void ff_h264_idct8_add4_c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]); void ff_h264_idct_add8_c(uint8_t **dest, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]); -void ff_vector_fmul_add_add_c(float *dst, const float *src0, const float *src1, - const float *src2, int src3, int blocksize, int step); void ff_vector_fmul_window_c(float *dst, const float *src0, const float *src1, const float *win, float add_bias, int len); void ff_float_to_int16_c(int16_t *dst, const float *src, long len); @@ -90,6 +86,7 @@ extern uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP]; void ff_vp3_idct_c(DCTELEM *block/* align 16*/); void ff_vp3_idct_put_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/); void ff_vp3_idct_add_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/); +void ff_vp3_idct_dc_add_c(uint8_t *dest/*align 8*/, int line_size, const DCTELEM *block/*align 16*/); 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); @@ -98,6 +95,24 @@ void ff_vp3_h_loop_filter_c(uint8_t *src, int stride, int *bounding_values); void ff_vp6_filter_diag4_c(uint8_t *dst, uint8_t *src, int stride, const int16_t *h_weights, const int16_t *v_weights); +/* 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); + +/* CAVS functions */ +void ff_put_cavs_qpel8_mc00_c(uint8_t *dst, uint8_t *src, int stride); +void ff_avg_cavs_qpel8_mc00_c(uint8_t *dst, uint8_t *src, int stride); +void ff_put_cavs_qpel16_mc00_c(uint8_t *dst, uint8_t *src, int stride); +void ff_avg_cavs_qpel16_mc00_c(uint8_t *dst, uint8_t *src, int stride); + +/* VC1 functions */ +void ff_put_vc1_mspel_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int rnd); +void ff_avg_vc1_mspel_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int rnd); + +/* EA functions */ +void ff_ea_idct_put_c(uint8_t *dest, int linesize, DCTELEM *block); + /* 1/2^n downscaling functions from imgconvert.c */ void ff_img_copy_plane(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height); void ff_shrink22(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height); @@ -135,8 +150,8 @@ typedef void (*op_pixels_func)(uint8_t *block/*align width (8 or 16)*/, const ui typedef void (*tpel_mc_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, int line_size, int w, int h); typedef void (*qpel_mc_func)(uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride); 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 (*op_fill_func)(uint8_t *block/*align width (8 or 16)*/, uint8_t value, int line_size, int h); #define DEF_OLD_QPEL(name)\ void ff_put_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\ @@ -167,10 +182,6 @@ static void a(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ // although currently h<4 is not used as functions with width <8 are neither used nor implemented typedef int (*me_cmp_func)(void /*MpegEncContext*/ *s, uint8_t *blk1/*align width (8 or 16)*/, uint8_t *blk2/*align 1*/, int line_size, int h)/* __attribute__ ((const))*/; - -// for snow slices -typedef struct slice_buffer_s slice_buffer; - /** * Scantable. */ @@ -180,7 +191,7 @@ typedef struct ScanTable{ uint8_t raster_end[64]; #if ARCH_PPC /** Used by dct_quantize_altivec to find last-non-zero */ - DECLARE_ALIGNED(16, uint8_t, inverse[64]); + DECLARE_ALIGNED(16, uint8_t, inverse)[64]; #endif } ScanTable; @@ -199,6 +210,7 @@ typedef struct DSPContext { 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); @@ -327,9 +339,6 @@ typedef struct DSPContext { qpel_mc_func put_2tap_qpel_pixels_tab[4][16]; qpel_mc_func avg_2tap_qpel_pixels_tab[4][16]; - h264_weight_func weight_h264_pixels_tab[10]; - h264_biweight_func biweight_h264_pixels_tab[10]; - /* AVS specific */ qpel_mc_func put_cavs_qpel_pixels_tab[2][16]; qpel_mc_func avg_cavs_qpel_pixels_tab[2][16]; @@ -349,25 +358,14 @@ typedef struct DSPContext { * subtract huffyuv's variant of median prediction * note, this might read from src1[-1], src2[-1] */ - void (*sub_hfyu_median_prediction)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w, int *left, int *left_top); - void (*add_hfyu_median_prediction)(uint8_t *dst, uint8_t *top, uint8_t *diff, int w, int *left, int *left_top); + void (*sub_hfyu_median_prediction)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int w, int *left, int *left_top); + void (*add_hfyu_median_prediction)(uint8_t *dst, const uint8_t *top, const uint8_t *diff, int w, int *left, int *left_top); + 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 (*h264_v_loop_filter_luma)(uint8_t *pix/*align 16*/, int stride, int alpha, int beta, int8_t *tc0); - void (*h264_h_loop_filter_luma)(uint8_t *pix/*align 4 */, int stride, int alpha, int beta, int8_t *tc0); - /* v/h_loop_filter_luma_intra: align 16 */ - void (*h264_v_loop_filter_luma_intra)(uint8_t *pix, int stride, int alpha, int beta); - void (*h264_h_loop_filter_luma_intra)(uint8_t *pix, int stride, int alpha, int beta); - void (*h264_v_loop_filter_chroma)(uint8_t *pix/*align 8*/, int stride, int alpha, int beta, int8_t *tc0); - void (*h264_h_loop_filter_chroma)(uint8_t *pix/*align 4*/, int stride, int alpha, int beta, int8_t *tc0); - void (*h264_v_loop_filter_chroma_intra)(uint8_t *pix/*align 8*/, int stride, int alpha, int beta); - void (*h264_h_loop_filter_chroma_intra)(uint8_t *pix/*align 8*/, int stride, int alpha, int beta); - // h264_loop_filter_strength: simd only. the C version is inlined in h264.c - void (*h264_loop_filter_strength)(int16_t bS[2][4][4], uint8_t nnz[40], int8_t ref[2][40], int16_t mv[2][40][2], - int bidir, int edges, int step, int mask_mv0, int mask_mv1, int field); - void (*h263_v_loop_filter)(uint8_t *src, int stride, int qscale); void (*h263_h_loop_filter)(uint8_t *src, int stride, int qscale); @@ -376,6 +374,7 @@ typedef struct DSPContext { void (*x8_v_loop_filter)(uint8_t *src, int stride, int qscale); void (*x8_h_loop_filter)(uint8_t *src, int stride, int qscale); + void (*vp3_idct_dc_add)(uint8_t *dest/*align 8*/, int line_size, const DCTELEM *block/*align 16*/); void (*vp3_v_loop_filter)(uint8_t *src, int stride, int *bounding_values); void (*vp3_h_loop_filter)(uint8_t *src, int stride, int *bounding_values); @@ -386,16 +385,67 @@ typedef struct DSPContext { void (*vorbis_inverse_coupling)(float *mag, float *ang, int blocksize); void (*ac3_downmix)(float (*samples)[256], float (*matrix)[2], int out_ch, int in_ch, int len); /* no alignment needed */ - void (*flac_compute_autocorr)(const int32_t *data, int len, int lag, double *autoc); + void (*lpc_compute_autocorr)(const int32_t *data, int len, int lag, double *autoc); /* assume len is a multiple of 8, and arrays are 16-byte aligned */ void (*vector_fmul)(float *dst, const float *src, int len); void (*vector_fmul_reverse)(float *dst, const float *src0, const float *src1, int len); /* assume len is a multiple of 8, and src arrays are 16-byte aligned */ - void (*vector_fmul_add_add)(float *dst, const float *src0, const float *src1, const float *src2, int src3, int len, int step); + void (*vector_fmul_add)(float *dst, const float *src0, const float *src1, const float *src2, int len); /* assume len is a multiple of 4, and arrays are 16-byte aligned */ void (*vector_fmul_window)(float *dst, const float *src0, const float *src1, const float *win, float add_bias, int len); /* assume len is a multiple of 8, and arrays are 16-byte aligned */ void (*int32_to_float_fmul_scalar)(float *dst, const int *src, float mul, int len); + void (*vector_clipf)(float *dst /* align 16 */, const float *src /* align 16 */, float min, float max, int len /* align 16 */); + /** + * Multiply a vector of floats by a scalar float. 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 mul scalar value + * @param len length of vector, multiple of 4 + */ + 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 + * @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 + */ + void (*sv_fmul_scalar[2])(float *dst, const float **sv, + float mul, int len); + /** + * Calculate the scalar product of two vectors of floats. + * @param v1 first vector, 16-byte aligned + * @param v2 second vector, 16-byte aligned + * @param len length of vectors, multiple of 4 + */ + float (*scalarproduct_float)(const float *v1, const float *v2, int len); + /** + * Calculate the sum and difference of two vectors of floats. + * @param v1 first input vector, sum output, 16-byte aligned + * @param v2 second input vector, difference output, 16-byte aligned + * @param len length of vectors, multiple of 4 + */ + void (*butterflies_float)(float *restrict v1, float *restrict v2, int len); /* C version: convert floats from the range [384.0,386.0] to ints in [-32768,32767] * simd versions: convert floats from [-32768.0,32767.0] without rescaling and arrays are 16byte aligned */ @@ -451,26 +501,6 @@ typedef struct DSPContext { void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, int w); #define EDGE_WIDTH 16 - /* h264 functions */ - /* NOTE!!! if you implement any of h264_idct8_add, h264_idct8_add4 then you must implement all of them - NOTE!!! if you implement any of h264_idct_add, h264_idct_add16, h264_idct_add16intra, h264_idct_add8 then you must implement all of them - The reason for above, is that no 2 out of one list may use a different permutation. - */ - void (*h264_idct_add)(uint8_t *dst/*align 4*/, DCTELEM *block/*align 16*/, int stride); - void (*h264_idct8_add)(uint8_t *dst/*align 8*/, DCTELEM *block/*align 16*/, int stride); - void (*h264_idct_dc_add)(uint8_t *dst/*align 4*/, DCTELEM *block/*align 16*/, int stride); - void (*h264_idct8_dc_add)(uint8_t *dst/*align 8*/, DCTELEM *block/*align 16*/, int stride); - void (*h264_dct)(DCTELEM block[4][4]); - void (*h264_idct_add16)(uint8_t *dst/*align 16*/, const int *blockoffset, DCTELEM *block/*align 16*/, int stride, const uint8_t nnzc[6*8]); - void (*h264_idct8_add4)(uint8_t *dst/*align 16*/, const int *blockoffset, DCTELEM *block/*align 16*/, int stride, const uint8_t nnzc[6*8]); - void (*h264_idct_add8)(uint8_t **dst/*align 16*/, const int *blockoffset, DCTELEM *block/*align 16*/, int stride, const uint8_t nnzc[6*8]); - void (*h264_idct_add16intra)(uint8_t *dst/*align 16*/, const int *blockoffset, DCTELEM *block/*align 16*/, int stride, const uint8_t nnzc[6*8]); - - /* snow wavelet */ - void (*vertical_compose97i)(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width); - void (*horizontal_compose97i)(IDWTELEM *b, int width); - void (*inner_add_yblock)(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h, int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8); - void (*prefetch)(void *mem, int stride, int h); void (*shrink[4])(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height); @@ -509,23 +539,19 @@ typedef struct DSPContext { void (*x8_setup_spatial_compensation)(uint8_t *src, uint8_t *dst, int linesize, int * range, int * sum, int edges); - /* ape functions */ - /** - * Add contents of the second vector to the first one. - * @param len length of vectors, should be multiple of 16 - */ - void (*add_int16)(int16_t *v1/*align 16*/, int16_t *v2, int len); - /** - * Add contents of the second vector to the first one. - * @param len length of vectors, should be multiple of 16 - */ - void (*sub_int16)(int16_t *v1/*align 16*/, int16_t *v2, int len); /** * Calculate scalar product of two vectors. * @param len length of vectors, should be multiple of 16 * @param shift number of bits to discard from product */ int32_t (*scalarproduct_int16)(int16_t *v1, int16_t *v2/*align 16*/, int len, int shift); + /* ape functions */ + /** + * Calculate scalar product of v1 and v2, + * and v1[i] += v3[i] * mul + * @param len length of vectors, should be multiple of 16 + */ + int32_t (*scalarproduct_and_madd_int16)(int16_t *v1/*align 16*/, int16_t *v2, int16_t *v3, int len, int mul); /* rv30 functions */ qpel_mc_func put_rv30_tpel_pixels_tab[4][16]; @@ -536,6 +562,10 @@ typedef struct DSPContext { 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); @@ -597,6 +627,7 @@ static inline int get_penalty_factor(int lambda, int lambda2, int type){ /* should be defined by architectures supporting one or more MultiMedia extension */ int mm_support(void); +extern int mm_flags; void dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx); void dsputil_init_arm(DSPContext* c, AVCodecContext *avctx); @@ -608,18 +639,19 @@ void dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx); void dsputil_init_sh4(DSPContext* c, AVCodecContext *avctx); void dsputil_init_vis(DSPContext* c, AVCodecContext *avctx); -#define DECLARE_ALIGNED_16(t, v) DECLARE_ALIGNED(16, t, v) +void ff_dsputil_init_dwt(DSPContext *c); +void ff_cavsdsp_init(DSPContext* c, AVCodecContext *avctx); +void ff_rv30dsp_init(DSPContext* c, AVCodecContext *avctx); +void ff_rv40dsp_init(DSPContext* c, AVCodecContext *avctx); +void ff_vc1dsp_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 HAVE_MMX #undef emms_c -extern int mm_flags; - -void add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size); -void put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size); -void put_signed_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size); - static inline void emms(void) { __asm__ volatile ("emms;":::"memory"); @@ -632,27 +664,18 @@ static inline void emms(void) emms();\ } -void dsputil_init_pix_mmx(DSPContext* c, AVCodecContext *avctx); - #elif ARCH_ARM -extern int mm_flags; - #if HAVE_NEON -# define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(16, t, v) # define STRIDE_ALIGN 16 #endif #elif ARCH_PPC -extern int mm_flags; - -#define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(16, t, v) #define STRIDE_ALIGN 16 #elif HAVE_MMI -#define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(16, t, v) #define STRIDE_ALIGN 16 #else @@ -662,160 +685,31 @@ extern int mm_flags; #endif -#ifndef DECLARE_ALIGNED_8 -# define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(8, t, v) -#endif - #ifndef STRIDE_ALIGN # define STRIDE_ALIGN 8 #endif +#define LOCAL_ALIGNED(a, t, v, s, ...) \ + uint8_t la_##v[sizeof(t s __VA_ARGS__) + (a)]; \ + t (*v) __VA_ARGS__ = (void *)FFALIGN((uintptr_t)la_##v, a) + +#if HAVE_LOCAL_ALIGNED_8 +# define LOCAL_ALIGNED_8(t, v, s, ...) DECLARE_ALIGNED(8, t, v) s __VA_ARGS__ +#else +# define LOCAL_ALIGNED_8(t, v, s, ...) LOCAL_ALIGNED(8, t, v, s, __VA_ARGS__) +#endif + +#if HAVE_LOCAL_ALIGNED_16 +# define LOCAL_ALIGNED_16(t, v, s, ...) DECLARE_ALIGNED(16, t, v) s __VA_ARGS__ +#else +# define LOCAL_ALIGNED_16(t, v, s, ...) LOCAL_ALIGNED(16, t, v, s, __VA_ARGS__) +#endif + /* PSNR */ void get_psnr(uint8_t *orig_image[3], uint8_t *coded_image[3], int orig_linesize[3], int coded_linesize, AVCodecContext *avctx); -/* FFT computation */ - -/* NOTE: soon integer code will be added, so you must use the - FFTSample type */ -typedef float FFTSample; - -struct MDCTContext; - -typedef struct FFTComplex { - FFTSample re, im; -} FFTComplex; - -typedef struct FFTContext { - int nbits; - int inverse; - uint16_t *revtab; - FFTComplex *exptab; - FFTComplex *exptab1; /* only used by SSE code */ - FFTComplex *tmp_buf; - void (*fft_permute)(struct FFTContext *s, FFTComplex *z); - void (*fft_calc)(struct FFTContext *s, FFTComplex *z); - void (*imdct_calc)(struct MDCTContext *s, FFTSample *output, const FFTSample *input); - void (*imdct_half)(struct MDCTContext *s, FFTSample *output, const FFTSample *input); -} FFTContext; - -extern FFTSample* ff_cos_tabs[13]; - -/** - * Sets up a complex FFT. - * @param nbits log2 of the length of the input array - * @param inverse if 0 perform the forward transform, if 1 perform the inverse - */ -int ff_fft_init(FFTContext *s, int nbits, int inverse); -void ff_fft_permute_c(FFTContext *s, FFTComplex *z); -void ff_fft_permute_sse(FFTContext *s, FFTComplex *z); -void ff_fft_calc_c(FFTContext *s, FFTComplex *z); -void ff_fft_calc_sse(FFTContext *s, FFTComplex *z); -void ff_fft_calc_3dn(FFTContext *s, FFTComplex *z); -void ff_fft_calc_3dn2(FFTContext *s, FFTComplex *z); -void ff_fft_calc_altivec(FFTContext *s, FFTComplex *z); - -/** - * Do the permutation needed BEFORE calling ff_fft_calc(). - */ -static inline void ff_fft_permute(FFTContext *s, FFTComplex *z) -{ - s->fft_permute(s, z); -} -/** - * Do a complex FFT with the parameters defined in ff_fft_init(). The - * input data must be permuted before. No 1.0/sqrt(n) normalization is done. - */ -static inline void ff_fft_calc(FFTContext *s, FFTComplex *z) -{ - s->fft_calc(s, z); -} -void ff_fft_end(FFTContext *s); - -/* MDCT computation */ - -typedef struct MDCTContext { - int n; /* size of MDCT (i.e. number of input data * 2) */ - int nbits; /* n = 2^nbits */ - /* pre/post rotation tables */ - FFTSample *tcos; - FFTSample *tsin; - FFTContext fft; -} MDCTContext; - -static inline void ff_imdct_calc(MDCTContext *s, FFTSample *output, const FFTSample *input) -{ - s->fft.imdct_calc(s, output, input); -} -static inline void ff_imdct_half(MDCTContext *s, FFTSample *output, const FFTSample *input) -{ - s->fft.imdct_half(s, output, input); -} - -/** - * Generate a Kaiser-Bessel Derived Window. - * @param window pointer to half window - * @param alpha determines window shape - * @param n size of half window - */ -void ff_kbd_window_init(float *window, float alpha, int n); - -/** - * Generate a sine window. - * @param window pointer to half window - * @param n size of half window - */ -void ff_sine_window_init(float *window, int n); -extern float ff_sine_128 [ 128]; -extern float ff_sine_256 [ 256]; -extern float ff_sine_512 [ 512]; -extern float ff_sine_1024[1024]; -extern float ff_sine_2048[2048]; -extern float ff_sine_4096[4096]; -extern float *ff_sine_windows[6]; - -int ff_mdct_init(MDCTContext *s, int nbits, int inverse, double scale); -void ff_imdct_calc_c(MDCTContext *s, FFTSample *output, const FFTSample *input); -void ff_imdct_half_c(MDCTContext *s, FFTSample *output, const FFTSample *input); -void ff_imdct_calc_3dn(MDCTContext *s, FFTSample *output, const FFTSample *input); -void ff_imdct_half_3dn(MDCTContext *s, FFTSample *output, const FFTSample *input); -void ff_imdct_calc_3dn2(MDCTContext *s, FFTSample *output, const FFTSample *input); -void ff_imdct_half_3dn2(MDCTContext *s, FFTSample *output, const FFTSample *input); -void ff_imdct_calc_sse(MDCTContext *s, FFTSample *output, const FFTSample *input); -void ff_imdct_half_sse(MDCTContext *s, FFTSample *output, const FFTSample *input); -void ff_mdct_calc(MDCTContext *s, FFTSample *out, const FFTSample *input); -void ff_mdct_end(MDCTContext *s); - -/* Real Discrete Fourier Transform */ - -enum RDFTransformType { - RDFT, - IRDFT, - RIDFT, - IRIDFT, -}; - -typedef struct { - int nbits; - int inverse; - int sign_convention; - - /* pre/post rotation tables */ - FFTSample *tcos; - FFTSample *tsin; - FFTContext fft; -} RDFTContext; - -/** - * Sets up a real FFT. - * @param nbits log2 of the length of the input array - * @param trans the type of transform - */ -int ff_rdft_init(RDFTContext *s, int nbits, enum RDFTransformType trans); -void ff_rdft_calc(RDFTContext *s, FFTSample *data); -void ff_rdft_end(RDFTContext *s); - #define WRAPPER8_16(name8, name16)\ static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\ return name8(s, dst , src , stride, h)\ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dv.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/dv.c index 96d8c39489..ea1f66179c 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/dv.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dv.c @@ -34,7 +34,7 @@ */ /** - * @file libavcodec/dv.c + * @file * DV codec. */ #define ALT_BITSTREAM_READER @@ -44,6 +44,7 @@ #include "put_bits.h" #include "simple_idct.h" #include "dvdata.h" +#include "dv_tablegen.h" //#undef NDEBUG //#include @@ -64,21 +65,8 @@ typedef struct DVVideoContext { #define TEX_VLC_BITS 9 -#if CONFIG_SMALL -#define DV_VLC_MAP_RUN_SIZE 15 -#define DV_VLC_MAP_LEV_SIZE 23 -#else -#define DV_VLC_MAP_RUN_SIZE 64 -#define DV_VLC_MAP_LEV_SIZE 512 //FIXME sign was removed so this should be /2 but needs check -#endif - /* XXX: also include quantization */ static RL_VLC_ELEM dv_rl_vlc[1184]; -/* VLC encoding lookup table */ -static struct dv_vlc_pair { - uint32_t vlc; - uint8_t size; -} dv_vlc_map[DV_VLC_MAP_RUN_SIZE][DV_VLC_MAP_LEV_SIZE]; static inline int dv_work_pool_size(const DVprofile *d) { @@ -238,7 +226,7 @@ static int dv_init_dynamic_tables(const DVprofile *d) } else { iweight1 = &dv_iweight_1080_y[0]; iweight2 = &dv_iweight_1080_c[0]; - } + } if (DV_PROFILE_IS_HD(d)) { for (c = 0; c < 4; c++) { for (s = 0; s < 16; s++) { @@ -256,12 +244,12 @@ static int dv_init_dynamic_tables(const DVprofile *d) for (; i < dv_quant_areas[c]; i++) { *factor1 = iweight1[i] << (dv_quant_shifts[s][c] + 1); *factor2++ = (*factor1++) << 1; - } - } + } + } + } } } } -} return 0; } @@ -325,47 +313,7 @@ static av_cold int dvvideo_init(AVCodecContext *avctx) } free_vlc(&dv_vlc); - for (i = 0; i < NB_DV_VLC - 1; i++) { - if (dv_vlc_run[i] >= DV_VLC_MAP_RUN_SIZE) - continue; -#if CONFIG_SMALL - if (dv_vlc_level[i] >= DV_VLC_MAP_LEV_SIZE) - continue; -#endif - - if (dv_vlc_map[dv_vlc_run[i]][dv_vlc_level[i]].size != 0) - continue; - - dv_vlc_map[dv_vlc_run[i]][dv_vlc_level[i]].vlc = - dv_vlc_bits[i] << (!!dv_vlc_level[i]); - dv_vlc_map[dv_vlc_run[i]][dv_vlc_level[i]].size = - dv_vlc_len[i] + (!!dv_vlc_level[i]); - } - for (i = 0; i < DV_VLC_MAP_RUN_SIZE; i++) { -#if CONFIG_SMALL - for (j = 1; j < DV_VLC_MAP_LEV_SIZE; j++) { - if (dv_vlc_map[i][j].size == 0) { - dv_vlc_map[i][j].vlc = dv_vlc_map[0][j].vlc | - (dv_vlc_map[i-1][0].vlc << (dv_vlc_map[0][j].size)); - dv_vlc_map[i][j].size = dv_vlc_map[i-1][0].size + - dv_vlc_map[0][j].size; - } - } -#else - for (j = 1; j < DV_VLC_MAP_LEV_SIZE/2; j++) { - if (dv_vlc_map[i][j].size == 0) { - dv_vlc_map[i][j].vlc = dv_vlc_map[0][j].vlc | - (dv_vlc_map[i-1][0].vlc << (dv_vlc_map[0][j].size)); - dv_vlc_map[i][j].size = dv_vlc_map[i-1][0].size + - dv_vlc_map[0][j].size; - } - dv_vlc_map[i][((uint16_t)(-j))&0x1ff].vlc = - dv_vlc_map[i][j].vlc | 1; - dv_vlc_map[i][((uint16_t)(-j))&0x1ff].size = - dv_vlc_map[i][j].size; - } -#endif - } + dv_vlc_map_tableinit(); } /* Generic DSP setup */ @@ -398,6 +346,17 @@ static av_cold int dvvideo_init(AVCodecContext *avctx) return 0; } +static av_cold int dvvideo_init_encoder(AVCodecContext *avctx) +{ + if (!ff_dv_codec_profile(avctx)) { + av_log(avctx, AV_LOG_ERROR, "Found no DV profile for %ix%i %s video\n", + avctx->width, avctx->height, avcodec_get_pix_fmt_name(avctx->pix_fmt)); + return -1; + } + + return dvvideo_init(avctx); +} + // #define VLC_DEBUG // #define printf(...) av_log(NULL, AV_LOG_ERROR, __VA_ARGS__) @@ -416,11 +375,6 @@ static const int vs_total_ac_bits = (100 * 4 + 68*2) * 5; /* see dv_88_areas and dv_248_areas for details */ static const int mb_area_start[5] = { 1, 6, 21, 43, 64 }; -static inline int get_bits_left(GetBitContext *s) -{ - return s->size_in_bits - get_bits_count(s); -} - static inline int put_bits_left(PutBitContext* s) { return (s->buf_end - s->buf) * 8 - put_bits_count(s); @@ -526,16 +480,16 @@ static int dv_decode_video_segment(AVCodecContext *avctx, void *arg) PutBitContext pb, vs_pb; GetBitContext gb; BlockInfo mb_data[5 * DV_MAX_BPM], *mb, *mb1; - DECLARE_ALIGNED_16(DCTELEM, sblock[5*DV_MAX_BPM][64]); - DECLARE_ALIGNED_8(uint8_t, mb_bit_buffer[80 + 4]); /* allow some slack */ - DECLARE_ALIGNED_8(uint8_t, vs_bit_buffer[5 * 80 + 4]); /* allow some slack */ + LOCAL_ALIGNED_16(DCTELEM, sblock, [5*DV_MAX_BPM], [64]); + LOCAL_ALIGNED_16(uint8_t, mb_bit_buffer, [80 + 4]); /* allow some slack */ + LOCAL_ALIGNED_16(uint8_t, vs_bit_buffer, [5 * 80 + 4]); /* allow some slack */ const int log2_blocksize = 3-s->avctx->lowres; int is_field_mode[5]; assert((((int)mb_bit_buffer) & 7) == 0); assert((((int)vs_bit_buffer) & 7) == 0); - memset(sblock, 0, sizeof(sblock)); + memset(sblock, 0, 5*DV_MAX_BPM*sizeof(*sblock)); /* pass 1 : read DC and AC coefficients in blocks */ buf_ptr = &s->buf[work_chunk->buf_offset*80]; @@ -631,7 +585,7 @@ static int dv_decode_video_segment(AVCodecContext *avctx, void *arg) dv_decode_ac(&gb, mb, block); } if (mb->pos >= 64 && mb->pos < 127) - av_log(NULL, AV_LOG_ERROR, "AC EOB marker is absent pos=%d\n", mb->pos); + av_log(avctx, AV_LOG_ERROR, "AC EOB marker is absent pos=%d\n", mb->pos); block += 64; mb++; } @@ -827,7 +781,7 @@ static av_always_inline int dv_init_enc_block(EncBlockInfo* bi, uint8_t *data, i { const int *weight; const uint8_t* zigzag_scan; - DECLARE_ALIGNED_16(DCTELEM, blk[64]); + LOCAL_ALIGNED_16(DCTELEM, blk, [64]); int i, area; /* We offer two different methods for class number assignment: the method suggested in SMPTE 314M Table 22, and an improved @@ -860,7 +814,7 @@ static av_always_inline int dv_init_enc_block(EncBlockInfo* bi, uint8_t *data, i } else { /* We rely on the fact that encoding all zeros leads to an immediate EOB, which is precisely what the spec calls for in the "dummy" blocks. */ - memset(blk, 0, sizeof(blk)); + memset(blk, 0, 64*sizeof(*blk)); bi->dct_mode = 0; } bi->mb[0] = blk[0]; @@ -1099,11 +1053,20 @@ static int dv_encode_video_segment(AVCodecContext *avctx, void *arg) if (enc_blks[j].partial_bit_count) pb = dv_encode_ac(&enc_blks[j], pb, &pbs[s->sys->bpm*5]); if (enc_blks[j].partial_bit_count) - av_log(NULL, AV_LOG_ERROR, "ac bitstream overflow\n"); + av_log(avctx, AV_LOG_ERROR, "ac bitstream overflow\n"); } - for (j=0; j<5*s->sys->bpm; j++) + for (j=0; j<5*s->sys->bpm; j++) { + int pos; + int size = pbs[j].size_in_bits >> 3; flush_put_bits(&pbs[j]); + pos = put_bits_count(&pbs[j]) >> 3; + if (pos > size) { + av_log(avctx, AV_LOG_ERROR, "bitstream written beyond buffer size\n"); + return -1; + } + memset(pbs[j].buf + pos, 0xff, size - pos); + } return 0; } @@ -1119,7 +1082,7 @@ static int dvvideo_decode_frame(AVCodecContext *avctx, int buf_size = avpkt->size; DVVideoContext *s = avctx->priv_data; - s->sys = dv_frame_profile(s->sys, buf, buf_size); + s->sys = ff_dv_frame_profile(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 */ @@ -1284,7 +1247,7 @@ static int dvvideo_encode_frame(AVCodecContext *c, uint8_t *buf, int buf_size, { DVVideoContext *s = c->priv_data; - s->sys = dv_codec_profile(c); + s->sys = ff_dv_codec_profile(c); if (!s->sys || buf_size < s->sys->frame_size || dv_init_dynamic_tables(s->sys)) return -1; @@ -1319,12 +1282,12 @@ static int dvvideo_close(AVCodecContext *c) #if CONFIG_DVVIDEO_ENCODER AVCodec dvvideo_encoder = { "dvvideo", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_DVVIDEO, sizeof(DVVideoContext), - dvvideo_init, + dvvideo_init_encoder, dvvideo_encode_frame, - .pix_fmts = (enum PixelFormat[]) {PIX_FMT_YUV411P, PIX_FMT_YUV422P, PIX_FMT_YUV420P, PIX_FMT_NONE}, + .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)"), }; #endif // CONFIG_DVVIDEO_ENCODER @@ -1332,7 +1295,7 @@ AVCodec dvvideo_encoder = { #if CONFIG_DVVIDEO_DECODER AVCodec dvvideo_decoder = { "dvvideo", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_DVVIDEO, sizeof(DVVideoContext), dvvideo_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dv_tablegen.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/dv_tablegen.c new file mode 100644 index 0000000000..0e2b39dfb2 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dv_tablegen.c @@ -0,0 +1,47 @@ +/* + * Generate a header file for hardcoded DV tables + * + * Copyright (c) 2010 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 +#define CONFIG_HARDCODED_TABLES 0 +#ifndef CONFIG_SMALL +#error CONFIG_SMALL must be defined to generate tables +#endif +#include "dv_tablegen.h" +#include "tableprint.h" +#include + +WRITE_1D_FUNC_ARGV(vlc_pair, struct dv_vlc_pair, 7, + "{0x%"PRIx32", %"PRId8"}", data[i].vlc, data[i].size) +WRITE_2D_FUNC(vlc_pair, struct dv_vlc_pair) + +int main(void) +{ + dv_vlc_map_tableinit(); + + write_fileheader(); + + printf("static const struct dv_vlc_pair dv_vlc_map[DV_VLC_MAP_RUN_SIZE][DV_VLC_MAP_LEV_SIZE] = {\n"); + write_vlc_pair_2d_array(dv_vlc_map, DV_VLC_MAP_RUN_SIZE, DV_VLC_MAP_LEV_SIZE); + printf("};\n"); + + return 0; +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dv_tablegen.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/dv_tablegen.h new file mode 100644 index 0000000000..ee6e8220af --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dv_tablegen.h @@ -0,0 +1,96 @@ +/* + * Header file for hardcoded DV tables + * + * Copyright (c) 2010 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 + */ + +#ifndef DV_TABLEGEN_H +#define DV_TABLEGEN_H + +#include +#include "dv_vlc_data.h" + +#if CONFIG_SMALL +#define DV_VLC_MAP_RUN_SIZE 15 +#define DV_VLC_MAP_LEV_SIZE 23 +#else +#define DV_VLC_MAP_RUN_SIZE 64 +#define DV_VLC_MAP_LEV_SIZE 512 //FIXME sign was removed so this should be /2 but needs check +#endif + +/* VLC encoding lookup table */ +struct dv_vlc_pair { + uint32_t vlc; + uint32_t size; +}; + +#if CONFIG_HARDCODED_TABLES +#define dv_vlc_map_tableinit() +#include "libavcodec/dv_tables.h" +#else +static struct dv_vlc_pair dv_vlc_map[DV_VLC_MAP_RUN_SIZE][DV_VLC_MAP_LEV_SIZE]; + +static void dv_vlc_map_tableinit(void) +{ + int i, j; + for (i = 0; i < NB_DV_VLC - 1; i++) { + if (dv_vlc_run[i] >= DV_VLC_MAP_RUN_SIZE) + continue; +#if CONFIG_SMALL + if (dv_vlc_level[i] >= DV_VLC_MAP_LEV_SIZE) + continue; +#endif + + if (dv_vlc_map[dv_vlc_run[i]][dv_vlc_level[i]].size != 0) + continue; + + dv_vlc_map[dv_vlc_run[i]][dv_vlc_level[i]].vlc = + dv_vlc_bits[i] << (!!dv_vlc_level[i]); + dv_vlc_map[dv_vlc_run[i]][dv_vlc_level[i]].size = + dv_vlc_len[i] + (!!dv_vlc_level[i]); + } + for (i = 0; i < DV_VLC_MAP_RUN_SIZE; i++) { +#if CONFIG_SMALL + for (j = 1; j < DV_VLC_MAP_LEV_SIZE; j++) { + if (dv_vlc_map[i][j].size == 0) { + dv_vlc_map[i][j].vlc = dv_vlc_map[0][j].vlc | + (dv_vlc_map[i-1][0].vlc << (dv_vlc_map[0][j].size)); + dv_vlc_map[i][j].size = dv_vlc_map[i-1][0].size + + dv_vlc_map[0][j].size; + } + } +#else + for (j = 1; j < DV_VLC_MAP_LEV_SIZE/2; j++) { + if (dv_vlc_map[i][j].size == 0) { + dv_vlc_map[i][j].vlc = dv_vlc_map[0][j].vlc | + (dv_vlc_map[i-1][0].vlc << (dv_vlc_map[0][j].size)); + dv_vlc_map[i][j].size = dv_vlc_map[i-1][0].size + + dv_vlc_map[0][j].size; + } + dv_vlc_map[i][((uint16_t)(-j))&0x1ff].vlc = + dv_vlc_map[i][j].vlc | 1; + dv_vlc_map[i][((uint16_t)(-j))&0x1ff].size = + dv_vlc_map[i][j].size; + } +#endif + } +} +#endif /* CONFIG_HARDCODED_TABLES */ + +#endif /* DV_TABLEGEN_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dv_vlc_data.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/dv_vlc_data.h new file mode 100644 index 0000000000..c23c564613 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dv_vlc_data.h @@ -0,0 +1,259 @@ +/* + * VLC constants for DV codec + * Copyright (c) 2002 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 + */ + +/** + * @file + * VLC constants for DV codec. + */ + +#ifndef AVCODEC_DV_VLC_DATA_H +#define AVCODEC_DV_VLC_DATA_H + +#include + +#define NB_DV_VLC 409 + +/* + * There's a catch about the following three tables: the mapping they establish + * between (run, level) and vlc is not 1-1. So you have to watch out for that + * when building misc. tables. E.g. (1, 0) can be either 0x7cf or 0x1f82. + */ +static const uint16_t dv_vlc_bits[409] = { + 0x0000, 0x0002, 0x0007, 0x0008, 0x0009, 0x0014, 0x0015, 0x0016, + 0x0017, 0x0030, 0x0031, 0x0032, 0x0033, 0x0068, 0x0069, 0x006a, + 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, 0x00e0, 0x00e1, 0x00e2, + 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x00ea, + 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, 0x01e0, 0x01e1, 0x01e2, + 0x01e3, 0x01e4, 0x01e5, 0x01e6, 0x01e7, 0x01e8, 0x01e9, 0x01ea, + 0x01eb, 0x01ec, 0x01ed, 0x01ee, 0x01ef, 0x03e0, 0x03e1, 0x03e2, + 0x03e3, 0x03e4, 0x03e5, 0x03e6, 0x07ce, 0x07cf, 0x07d0, 0x07d1, + 0x07d2, 0x07d3, 0x07d4, 0x07d5, 0x0fac, 0x0fad, 0x0fae, 0x0faf, + 0x0fb0, 0x0fb1, 0x0fb2, 0x0fb3, 0x0fb4, 0x0fb5, 0x0fb6, 0x0fb7, + 0x0fb8, 0x0fb9, 0x0fba, 0x0fbb, 0x0fbc, 0x0fbd, 0x0fbe, 0x0fbf, + 0x1f80, 0x1f81, 0x1f82, 0x1f83, 0x1f84, 0x1f85, 0x1f86, 0x1f87, + 0x1f88, 0x1f89, 0x1f8a, 0x1f8b, 0x1f8c, 0x1f8d, 0x1f8e, 0x1f8f, + 0x1f90, 0x1f91, 0x1f92, 0x1f93, 0x1f94, 0x1f95, 0x1f96, 0x1f97, + 0x1f98, 0x1f99, 0x1f9a, 0x1f9b, 0x1f9c, 0x1f9d, 0x1f9e, 0x1f9f, + 0x1fa0, 0x1fa1, 0x1fa2, 0x1fa3, 0x1fa4, 0x1fa5, 0x1fa6, 0x1fa7, + 0x1fa8, 0x1fa9, 0x1faa, 0x1fab, 0x1fac, 0x1fad, 0x1fae, 0x1faf, + 0x1fb0, 0x1fb1, 0x1fb2, 0x1fb3, 0x1fb4, 0x1fb5, 0x1fb6, 0x1fb7, + 0x1fb8, 0x1fb9, 0x1fba, 0x1fbb, 0x1fbc, 0x1fbd, 0x1fbe, 0x1fbf, + 0x7f00, 0x7f01, 0x7f02, 0x7f03, 0x7f04, 0x7f05, 0x7f06, 0x7f07, + 0x7f08, 0x7f09, 0x7f0a, 0x7f0b, 0x7f0c, 0x7f0d, 0x7f0e, 0x7f0f, + 0x7f10, 0x7f11, 0x7f12, 0x7f13, 0x7f14, 0x7f15, 0x7f16, 0x7f17, + 0x7f18, 0x7f19, 0x7f1a, 0x7f1b, 0x7f1c, 0x7f1d, 0x7f1e, 0x7f1f, + 0x7f20, 0x7f21, 0x7f22, 0x7f23, 0x7f24, 0x7f25, 0x7f26, 0x7f27, + 0x7f28, 0x7f29, 0x7f2a, 0x7f2b, 0x7f2c, 0x7f2d, 0x7f2e, 0x7f2f, + 0x7f30, 0x7f31, 0x7f32, 0x7f33, 0x7f34, 0x7f35, 0x7f36, 0x7f37, + 0x7f38, 0x7f39, 0x7f3a, 0x7f3b, 0x7f3c, 0x7f3d, 0x7f3e, 0x7f3f, + 0x7f40, 0x7f41, 0x7f42, 0x7f43, 0x7f44, 0x7f45, 0x7f46, 0x7f47, + 0x7f48, 0x7f49, 0x7f4a, 0x7f4b, 0x7f4c, 0x7f4d, 0x7f4e, 0x7f4f, + 0x7f50, 0x7f51, 0x7f52, 0x7f53, 0x7f54, 0x7f55, 0x7f56, 0x7f57, + 0x7f58, 0x7f59, 0x7f5a, 0x7f5b, 0x7f5c, 0x7f5d, 0x7f5e, 0x7f5f, + 0x7f60, 0x7f61, 0x7f62, 0x7f63, 0x7f64, 0x7f65, 0x7f66, 0x7f67, + 0x7f68, 0x7f69, 0x7f6a, 0x7f6b, 0x7f6c, 0x7f6d, 0x7f6e, 0x7f6f, + 0x7f70, 0x7f71, 0x7f72, 0x7f73, 0x7f74, 0x7f75, 0x7f76, 0x7f77, + 0x7f78, 0x7f79, 0x7f7a, 0x7f7b, 0x7f7c, 0x7f7d, 0x7f7e, 0x7f7f, + 0x7f80, 0x7f81, 0x7f82, 0x7f83, 0x7f84, 0x7f85, 0x7f86, 0x7f87, + 0x7f88, 0x7f89, 0x7f8a, 0x7f8b, 0x7f8c, 0x7f8d, 0x7f8e, 0x7f8f, + 0x7f90, 0x7f91, 0x7f92, 0x7f93, 0x7f94, 0x7f95, 0x7f96, 0x7f97, + 0x7f98, 0x7f99, 0x7f9a, 0x7f9b, 0x7f9c, 0x7f9d, 0x7f9e, 0x7f9f, + 0x7fa0, 0x7fa1, 0x7fa2, 0x7fa3, 0x7fa4, 0x7fa5, 0x7fa6, 0x7fa7, + 0x7fa8, 0x7fa9, 0x7faa, 0x7fab, 0x7fac, 0x7fad, 0x7fae, 0x7faf, + 0x7fb0, 0x7fb1, 0x7fb2, 0x7fb3, 0x7fb4, 0x7fb5, 0x7fb6, 0x7fb7, + 0x7fb8, 0x7fb9, 0x7fba, 0x7fbb, 0x7fbc, 0x7fbd, 0x7fbe, 0x7fbf, + 0x7fc0, 0x7fc1, 0x7fc2, 0x7fc3, 0x7fc4, 0x7fc5, 0x7fc6, 0x7fc7, + 0x7fc8, 0x7fc9, 0x7fca, 0x7fcb, 0x7fcc, 0x7fcd, 0x7fce, 0x7fcf, + 0x7fd0, 0x7fd1, 0x7fd2, 0x7fd3, 0x7fd4, 0x7fd5, 0x7fd6, 0x7fd7, + 0x7fd8, 0x7fd9, 0x7fda, 0x7fdb, 0x7fdc, 0x7fdd, 0x7fde, 0x7fdf, + 0x7fe0, 0x7fe1, 0x7fe2, 0x7fe3, 0x7fe4, 0x7fe5, 0x7fe6, 0x7fe7, + 0x7fe8, 0x7fe9, 0x7fea, 0x7feb, 0x7fec, 0x7fed, 0x7fee, 0x7fef, + 0x7ff0, 0x7ff1, 0x7ff2, 0x7ff3, 0x7ff4, 0x7ff5, 0x7ff6, 0x7ff7, + 0x7ff8, 0x7ff9, 0x7ffa, 0x7ffb, 0x7ffc, 0x7ffd, 0x7ffe, 0x7fff, + 0x0006, +}; + +static const uint8_t dv_vlc_len[409] = { + 2, 3, 4, 4, 4, 5, 5, 5, + 5, 6, 6, 6, 6, 7, 7, 7, + 7, 7, 7, 7, 7, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 10, 10, 10, + 10, 10, 10, 10, 11, 11, 11, 11, + 11, 11, 11, 11, 12, 12, 12, 12, + 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, 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, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 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, 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, 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, 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, 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, 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, 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, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, + 4, +}; + +static const uint8_t dv_vlc_run[409] = { + 0, 0, 1, 0, 0, 2, 1, 0, + 0, 3, 4, 0, 0, 5, 6, 2, + 1, 1, 0, 0, 0, 7, 8, 9, + 10, 3, 4, 2, 1, 1, 1, 0, + 0, 0, 0, 0, 0, 11, 12, 13, + 14, 5, 6, 3, 4, 2, 2, 1, + 0, 0, 0, 0, 0, 5, 3, 3, + 2, 1, 1, 1, 0, 1, 6, 4, + 3, 1, 1, 1, 2, 3, 4, 5, + 7, 8, 9, 10, 7, 8, 4, 3, + 2, 2, 2, 2, 2, 1, 1, 1, + 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, + 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, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, +127, +}; + +static const uint8_t dv_vlc_level[409] = { + 1, 2, 1, 3, 4, 1, 2, 5, + 6, 1, 1, 7, 8, 1, 1, 2, + 3, 4, 9, 10, 11, 1, 1, 1, + 1, 2, 2, 3, 5, 6, 7, 12, + 13, 14, 15, 16, 17, 1, 1, 1, + 1, 2, 2, 3, 3, 4, 5, 8, + 18, 19, 20, 21, 22, 3, 4, 5, + 6, 9, 10, 11, 0, 0, 3, 4, + 6, 12, 13, 14, 0, 0, 0, 0, + 2, 2, 2, 2, 3, 3, 5, 7, + 7, 8, 9, 10, 11, 15, 16, 17, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 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, 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, 65, 66, 67, 68, 69, 70, 71, + 72, 73, 74, 75, 76, 77, 78, 79, + 80, 81, 82, 83, 84, 85, 86, 87, + 88, 89, 90, 91, 92, 93, 94, 95, + 96, 97, 98, 99, 100, 101, 102, 103, + 104, 105, 106, 107, 108, 109, 110, 111, + 112, 113, 114, 115, 116, 117, 118, 119, + 120, 121, 122, 123, 124, 125, 126, 127, + 128, 129, 130, 131, 132, 133, 134, 135, + 136, 137, 138, 139, 140, 141, 142, 143, + 144, 145, 146, 147, 148, 149, 150, 151, + 152, 153, 154, 155, 156, 157, 158, 159, + 160, 161, 162, 163, 164, 165, 166, 167, + 168, 169, 170, 171, 172, 173, 174, 175, + 176, 177, 178, 179, 180, 181, 182, 183, + 184, 185, 186, 187, 188, 189, 190, 191, + 192, 193, 194, 195, 196, 197, 198, 199, + 200, 201, 202, 203, 204, 205, 206, 207, + 208, 209, 210, 211, 212, 213, 214, 215, + 216, 217, 218, 219, 220, 221, 222, 223, + 224, 225, 226, 227, 228, 229, 230, 231, + 232, 233, 234, 235, 236, 237, 238, 239, + 240, 241, 242, 243, 244, 245, 246, 247, + 248, 249, 250, 251, 252, 253, 254, 255, + 0, +}; + +#endif /* AVCODEC_DV_VLC_DATA_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dvbsub.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/dvbsub.c index 3788d55933..0f098266d8 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/dvbsub.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dvbsub.c @@ -404,7 +404,7 @@ static int dvbsub_encode(AVCodecContext *avctx, AVCodec dvbsub_encoder = { "dvbsub", - CODEC_TYPE_SUBTITLE, + AVMEDIA_TYPE_SUBTITLE, CODEC_ID_DVB_SUBTITLE, sizeof(DVBSubtitleContext), NULL, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dvbsubdec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/dvbsubdec.c index b810ef9e49..54c74b5b41 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/dvbsubdec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dvbsubdec.c @@ -1413,7 +1413,7 @@ static int dvbsub_decode(AVCodecContext *avctx, AVCodec dvbsub_decoder = { "dvbsub", - CODEC_TYPE_SUBTITLE, + AVMEDIA_TYPE_SUBTITLE, CODEC_ID_DVB_SUBTITLE, sizeof(DVBSubContext), dvbsub_init_decoder, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dvdata.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/dvdata.c new file mode 100644 index 0000000000..7232bafe0d --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dvdata.c @@ -0,0 +1,285 @@ +/* + * Constants for DV codec + * Copyright (c) 2002 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 + */ + +/** + * @file + * Constants for DV codec. + */ + +#include "libavutil/rational.h" +#include "avcodec.h" +#include "dvdata.h" + +static DVwork_chunk work_chunks_dv25pal [1*12*27]; +static DVwork_chunk work_chunks_dv25pal411[1*12*27]; +static DVwork_chunk work_chunks_dv25ntsc [1*10*27]; +static DVwork_chunk work_chunks_dv50pal [2*12*27]; +static DVwork_chunk work_chunks_dv50ntsc [2*10*27]; +static DVwork_chunk work_chunks_dv100palp [2*12*27]; +static DVwork_chunk work_chunks_dv100ntscp[2*10*27]; +static DVwork_chunk work_chunks_dv100pali [4*12*27]; +static DVwork_chunk work_chunks_dv100ntsci[4*10*27]; + +static uint32_t dv_idct_factor_sd [2*2*22*64]; +static uint32_t dv_idct_factor_hd1080[2*4*16*64]; +static uint32_t dv_idct_factor_hd720 [2*4*16*64]; + +static const DVprofile dv_profiles[] = { + { .dsf = 0, + .video_stype = 0x0, + .frame_size = 120000, /* IEC 61834, SMPTE-314M - 525/60 (NTSC) */ + .difseg_size = 10, + .n_difchan = 1, + .time_base = { 1001, 30000 }, + .ltc_divisor = 30, + .height = 480, + .width = 720, + .sar = {{10, 11}, {40, 33}}, + .work_chunks = &work_chunks_dv25ntsc[0], + .idct_factor = &dv_idct_factor_sd[0], + .pix_fmt = PIX_FMT_YUV411P, + .bpm = 6, + .block_sizes = block_sizes_dv2550, + .audio_stride = 90, + .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */ + .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */ + .audio_shuffle = dv_audio_shuffle525, + }, + { .dsf = 1, + .video_stype = 0x0, + .frame_size = 144000, /* IEC 61834 - 625/50 (PAL) */ + .difseg_size = 12, + .n_difchan = 1, + .time_base = { 1, 25 }, + .ltc_divisor = 25, + .height = 576, + .width = 720, + .sar = {{59, 54}, {118, 81}}, + .work_chunks = &work_chunks_dv25pal[0], + .idct_factor = &dv_idct_factor_sd[0], + .pix_fmt = PIX_FMT_YUV420P, + .bpm = 6, + .block_sizes = block_sizes_dv2550, + .audio_stride = 108, + .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */ + .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 }, + .audio_shuffle = dv_audio_shuffle625, + }, + { .dsf = 1, + .video_stype = 0x0, + .frame_size = 144000, /* SMPTE-314M - 625/50 (PAL) */ + .difseg_size = 12, + .n_difchan = 1, + .time_base = { 1, 25 }, + .ltc_divisor = 25, + .height = 576, + .width = 720, + .sar = {{59, 54}, {118, 81}}, + .work_chunks = &work_chunks_dv25pal411[0], + .idct_factor = &dv_idct_factor_sd[0], + .pix_fmt = PIX_FMT_YUV411P, + .bpm = 6, + .block_sizes = block_sizes_dv2550, + .audio_stride = 108, + .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */ + .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 }, + .audio_shuffle = dv_audio_shuffle625, + }, + { .dsf = 0, + .video_stype = 0x4, + .frame_size = 240000, /* SMPTE-314M - 525/60 (NTSC) 50 Mbps */ + .difseg_size = 10, /* also known as "DVCPRO50" */ + .n_difchan = 2, + .time_base = { 1001, 30000 }, + .ltc_divisor = 30, + .height = 480, + .width = 720, + .sar = {{10, 11}, {40, 33}}, + .work_chunks = &work_chunks_dv50ntsc[0], + .idct_factor = &dv_idct_factor_sd[0], + .pix_fmt = PIX_FMT_YUV422P, + .bpm = 6, + .block_sizes = block_sizes_dv2550, + .audio_stride = 90, + .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */ + .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */ + .audio_shuffle = dv_audio_shuffle525, + }, + { .dsf = 1, + .video_stype = 0x4, + .frame_size = 288000, /* SMPTE-314M - 625/50 (PAL) 50 Mbps */ + .difseg_size = 12, /* also known as "DVCPRO50" */ + .n_difchan = 2, + .time_base = { 1, 25 }, + .ltc_divisor = 25, + .height = 576, + .width = 720, + .sar = {{59, 54}, {118, 81}}, + .work_chunks = &work_chunks_dv50pal[0], + .idct_factor = &dv_idct_factor_sd[0], + .pix_fmt = PIX_FMT_YUV422P, + .bpm = 6, + .block_sizes = block_sizes_dv2550, + .audio_stride = 108, + .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */ + .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 }, + .audio_shuffle = dv_audio_shuffle625, + }, + { .dsf = 0, + .video_stype = 0x14, + .frame_size = 480000, /* SMPTE-370M - 1080i60 100 Mbps */ + .difseg_size = 10, /* also known as "DVCPRO HD" */ + .n_difchan = 4, + .time_base = { 1001, 30000 }, + .ltc_divisor = 30, + .height = 1080, + .width = 1280, + .sar = {{1, 1}, {3, 2}}, + .work_chunks = &work_chunks_dv100ntsci[0], + .idct_factor = &dv_idct_factor_hd1080[0], + .pix_fmt = PIX_FMT_YUV422P, + .bpm = 8, + .block_sizes = block_sizes_dv100, + .audio_stride = 90, + .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */ + .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */ + .audio_shuffle = dv_audio_shuffle525, + }, + { .dsf = 1, + .video_stype = 0x14, + .frame_size = 576000, /* SMPTE-370M - 1080i50 100 Mbps */ + .difseg_size = 12, /* also known as "DVCPRO HD" */ + .n_difchan = 4, + .time_base = { 1, 25 }, + .ltc_divisor = 25, + .height = 1080, + .width = 1440, + .sar = {{1, 1}, {4, 3}}, + .work_chunks = &work_chunks_dv100pali[0], + .idct_factor = &dv_idct_factor_hd1080[0], + .pix_fmt = PIX_FMT_YUV422P, + .bpm = 8, + .block_sizes = block_sizes_dv100, + .audio_stride = 108, + .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */ + .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 }, + .audio_shuffle = dv_audio_shuffle625, + }, + { .dsf = 0, + .video_stype = 0x18, + .frame_size = 240000, /* SMPTE-370M - 720p60 100 Mbps */ + .difseg_size = 10, /* also known as "DVCPRO HD" */ + .n_difchan = 2, + .time_base = { 1001, 60000 }, + .ltc_divisor = 60, + .height = 720, + .width = 960, + .sar = {{1, 1}, {4, 3}}, + .work_chunks = &work_chunks_dv100ntscp[0], + .idct_factor = &dv_idct_factor_hd720[0], + .pix_fmt = PIX_FMT_YUV422P, + .bpm = 8, + .block_sizes = block_sizes_dv100, + .audio_stride = 90, + .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */ + .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */ + .audio_shuffle = dv_audio_shuffle525, + }, + { .dsf = 1, + .video_stype = 0x18, + .frame_size = 288000, /* SMPTE-370M - 720p50 100 Mbps */ + .difseg_size = 12, /* also known as "DVCPRO HD" */ + .n_difchan = 2, + .time_base = { 1, 50 }, + .ltc_divisor = 50, + .height = 720, + .width = 960, + .sar = {{1, 1}, {4, 3}}, + .work_chunks = &work_chunks_dv100palp[0], + .idct_factor = &dv_idct_factor_hd720[0], + .pix_fmt = PIX_FMT_YUV422P, + .bpm = 8, + .block_sizes = block_sizes_dv100, + .audio_stride = 90, + .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */ + .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 }, + .audio_shuffle = dv_audio_shuffle625, + }, + { .dsf = 1, + .video_stype = 0x1, + .frame_size = 144000, /* IEC 61883-5 - 625/50 (PAL) */ + .difseg_size = 12, + .n_difchan = 1, + .time_base = { 1, 25 }, + .ltc_divisor = 25, + .height = 576, + .width = 720, + .sar = {{59, 54}, {118, 81}}, + .work_chunks = &work_chunks_dv25pal[0], + .idct_factor = &dv_idct_factor_sd[0], + .pix_fmt = PIX_FMT_YUV420P, + .bpm = 6, + .block_sizes = block_sizes_dv2550, + .audio_stride = 108, + .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */ + .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 }, + .audio_shuffle = dv_audio_shuffle625, + } +}; + +const DVprofile* ff_dv_frame_profile(const DVprofile *sys, + const uint8_t* frame, unsigned buf_size) +{ + int i; + + int dsf = (frame[3] & 0x80) >> 7; + + int stype = frame[80*5 + 48 + 3] & 0x1f; + + /* 576i50 25Mbps 4:1:1 is a special case */ + if (dsf == 1 && stype == 0 && frame[5] & 0x07) { + return &dv_profiles[2]; + } + + for (i=0; iframe_size) + return sys; + + return NULL; +} + +const DVprofile* ff_dv_codec_profile(AVCodecContext* codec) +{ + int i; + + for (i=0; iheight == dv_profiles[i].height && + codec->pix_fmt == dv_profiles[i].pix_fmt && + codec->width == dv_profiles[i].width) + return &dv_profiles[i]; + + return NULL; +} + diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dvdata.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/dvdata.h index a32b863c5d..90f4059839 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/dvdata.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dvdata.h @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/dvdata.h + * @file * Constants for DV codec. */ @@ -65,233 +65,6 @@ typedef struct DVprofile { const uint8_t (*audio_shuffle)[9]; /* PCM shuffling table */ } DVprofile; -#define NB_DV_VLC 409 - -/* - * There's a catch about the following three tables: the mapping they establish - * between (run, level) and vlc is not 1-1. So you have to watch out for that - * when building misc. tables. E.g. (1, 0) can be either 0x7cf or 0x1f82. - */ -static const uint16_t dv_vlc_bits[409] = { - 0x0000, 0x0002, 0x0007, 0x0008, 0x0009, 0x0014, 0x0015, 0x0016, - 0x0017, 0x0030, 0x0031, 0x0032, 0x0033, 0x0068, 0x0069, 0x006a, - 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, 0x00e0, 0x00e1, 0x00e2, - 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x00ea, - 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, 0x01e0, 0x01e1, 0x01e2, - 0x01e3, 0x01e4, 0x01e5, 0x01e6, 0x01e7, 0x01e8, 0x01e9, 0x01ea, - 0x01eb, 0x01ec, 0x01ed, 0x01ee, 0x01ef, 0x03e0, 0x03e1, 0x03e2, - 0x03e3, 0x03e4, 0x03e5, 0x03e6, 0x07ce, 0x07cf, 0x07d0, 0x07d1, - 0x07d2, 0x07d3, 0x07d4, 0x07d5, 0x0fac, 0x0fad, 0x0fae, 0x0faf, - 0x0fb0, 0x0fb1, 0x0fb2, 0x0fb3, 0x0fb4, 0x0fb5, 0x0fb6, 0x0fb7, - 0x0fb8, 0x0fb9, 0x0fba, 0x0fbb, 0x0fbc, 0x0fbd, 0x0fbe, 0x0fbf, - 0x1f80, 0x1f81, 0x1f82, 0x1f83, 0x1f84, 0x1f85, 0x1f86, 0x1f87, - 0x1f88, 0x1f89, 0x1f8a, 0x1f8b, 0x1f8c, 0x1f8d, 0x1f8e, 0x1f8f, - 0x1f90, 0x1f91, 0x1f92, 0x1f93, 0x1f94, 0x1f95, 0x1f96, 0x1f97, - 0x1f98, 0x1f99, 0x1f9a, 0x1f9b, 0x1f9c, 0x1f9d, 0x1f9e, 0x1f9f, - 0x1fa0, 0x1fa1, 0x1fa2, 0x1fa3, 0x1fa4, 0x1fa5, 0x1fa6, 0x1fa7, - 0x1fa8, 0x1fa9, 0x1faa, 0x1fab, 0x1fac, 0x1fad, 0x1fae, 0x1faf, - 0x1fb0, 0x1fb1, 0x1fb2, 0x1fb3, 0x1fb4, 0x1fb5, 0x1fb6, 0x1fb7, - 0x1fb8, 0x1fb9, 0x1fba, 0x1fbb, 0x1fbc, 0x1fbd, 0x1fbe, 0x1fbf, - 0x7f00, 0x7f01, 0x7f02, 0x7f03, 0x7f04, 0x7f05, 0x7f06, 0x7f07, - 0x7f08, 0x7f09, 0x7f0a, 0x7f0b, 0x7f0c, 0x7f0d, 0x7f0e, 0x7f0f, - 0x7f10, 0x7f11, 0x7f12, 0x7f13, 0x7f14, 0x7f15, 0x7f16, 0x7f17, - 0x7f18, 0x7f19, 0x7f1a, 0x7f1b, 0x7f1c, 0x7f1d, 0x7f1e, 0x7f1f, - 0x7f20, 0x7f21, 0x7f22, 0x7f23, 0x7f24, 0x7f25, 0x7f26, 0x7f27, - 0x7f28, 0x7f29, 0x7f2a, 0x7f2b, 0x7f2c, 0x7f2d, 0x7f2e, 0x7f2f, - 0x7f30, 0x7f31, 0x7f32, 0x7f33, 0x7f34, 0x7f35, 0x7f36, 0x7f37, - 0x7f38, 0x7f39, 0x7f3a, 0x7f3b, 0x7f3c, 0x7f3d, 0x7f3e, 0x7f3f, - 0x7f40, 0x7f41, 0x7f42, 0x7f43, 0x7f44, 0x7f45, 0x7f46, 0x7f47, - 0x7f48, 0x7f49, 0x7f4a, 0x7f4b, 0x7f4c, 0x7f4d, 0x7f4e, 0x7f4f, - 0x7f50, 0x7f51, 0x7f52, 0x7f53, 0x7f54, 0x7f55, 0x7f56, 0x7f57, - 0x7f58, 0x7f59, 0x7f5a, 0x7f5b, 0x7f5c, 0x7f5d, 0x7f5e, 0x7f5f, - 0x7f60, 0x7f61, 0x7f62, 0x7f63, 0x7f64, 0x7f65, 0x7f66, 0x7f67, - 0x7f68, 0x7f69, 0x7f6a, 0x7f6b, 0x7f6c, 0x7f6d, 0x7f6e, 0x7f6f, - 0x7f70, 0x7f71, 0x7f72, 0x7f73, 0x7f74, 0x7f75, 0x7f76, 0x7f77, - 0x7f78, 0x7f79, 0x7f7a, 0x7f7b, 0x7f7c, 0x7f7d, 0x7f7e, 0x7f7f, - 0x7f80, 0x7f81, 0x7f82, 0x7f83, 0x7f84, 0x7f85, 0x7f86, 0x7f87, - 0x7f88, 0x7f89, 0x7f8a, 0x7f8b, 0x7f8c, 0x7f8d, 0x7f8e, 0x7f8f, - 0x7f90, 0x7f91, 0x7f92, 0x7f93, 0x7f94, 0x7f95, 0x7f96, 0x7f97, - 0x7f98, 0x7f99, 0x7f9a, 0x7f9b, 0x7f9c, 0x7f9d, 0x7f9e, 0x7f9f, - 0x7fa0, 0x7fa1, 0x7fa2, 0x7fa3, 0x7fa4, 0x7fa5, 0x7fa6, 0x7fa7, - 0x7fa8, 0x7fa9, 0x7faa, 0x7fab, 0x7fac, 0x7fad, 0x7fae, 0x7faf, - 0x7fb0, 0x7fb1, 0x7fb2, 0x7fb3, 0x7fb4, 0x7fb5, 0x7fb6, 0x7fb7, - 0x7fb8, 0x7fb9, 0x7fba, 0x7fbb, 0x7fbc, 0x7fbd, 0x7fbe, 0x7fbf, - 0x7fc0, 0x7fc1, 0x7fc2, 0x7fc3, 0x7fc4, 0x7fc5, 0x7fc6, 0x7fc7, - 0x7fc8, 0x7fc9, 0x7fca, 0x7fcb, 0x7fcc, 0x7fcd, 0x7fce, 0x7fcf, - 0x7fd0, 0x7fd1, 0x7fd2, 0x7fd3, 0x7fd4, 0x7fd5, 0x7fd6, 0x7fd7, - 0x7fd8, 0x7fd9, 0x7fda, 0x7fdb, 0x7fdc, 0x7fdd, 0x7fde, 0x7fdf, - 0x7fe0, 0x7fe1, 0x7fe2, 0x7fe3, 0x7fe4, 0x7fe5, 0x7fe6, 0x7fe7, - 0x7fe8, 0x7fe9, 0x7fea, 0x7feb, 0x7fec, 0x7fed, 0x7fee, 0x7fef, - 0x7ff0, 0x7ff1, 0x7ff2, 0x7ff3, 0x7ff4, 0x7ff5, 0x7ff6, 0x7ff7, - 0x7ff8, 0x7ff9, 0x7ffa, 0x7ffb, 0x7ffc, 0x7ffd, 0x7ffe, 0x7fff, - 0x0006, -}; - -static const uint8_t dv_vlc_len[409] = { - 2, 3, 4, 4, 4, 5, 5, 5, - 5, 6, 6, 6, 6, 7, 7, 7, - 7, 7, 7, 7, 7, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 10, 10, 10, - 10, 10, 10, 10, 11, 11, 11, 11, - 11, 11, 11, 11, 12, 12, 12, 12, - 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, 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, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 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, 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, 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, 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, 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, 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, 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, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, - 4, -}; - -static const uint8_t dv_vlc_run[409] = { - 0, 0, 1, 0, 0, 2, 1, 0, - 0, 3, 4, 0, 0, 5, 6, 2, - 1, 1, 0, 0, 0, 7, 8, 9, - 10, 3, 4, 2, 1, 1, 1, 0, - 0, 0, 0, 0, 0, 11, 12, 13, - 14, 5, 6, 3, 4, 2, 2, 1, - 0, 0, 0, 0, 0, 5, 3, 3, - 2, 1, 1, 1, 0, 1, 6, 4, - 3, 1, 1, 1, 2, 3, 4, 5, - 7, 8, 9, 10, 7, 8, 4, 3, - 2, 2, 2, 2, 2, 1, 1, 1, - 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, - 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, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, -127, -}; - -static const uint8_t dv_vlc_level[409] = { - 1, 2, 1, 3, 4, 1, 2, 5, - 6, 1, 1, 7, 8, 1, 1, 2, - 3, 4, 9, 10, 11, 1, 1, 1, - 1, 2, 2, 3, 5, 6, 7, 12, - 13, 14, 15, 16, 17, 1, 1, 1, - 1, 2, 2, 3, 3, 4, 5, 8, - 18, 19, 20, 21, 22, 3, 4, 5, - 6, 9, 10, 11, 0, 0, 3, 4, - 6, 12, 13, 14, 0, 0, 0, 0, - 2, 2, 2, 2, 3, 3, 5, 7, - 7, 8, 9, 10, 11, 15, 16, 17, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 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, 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, 65, 66, 67, 68, 69, 70, 71, - 72, 73, 74, 75, 76, 77, 78, 79, - 80, 81, 82, 83, 84, 85, 86, 87, - 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 99, 100, 101, 102, 103, - 104, 105, 106, 107, 108, 109, 110, 111, - 112, 113, 114, 115, 116, 117, 118, 119, - 120, 121, 122, 123, 124, 125, 126, 127, - 128, 129, 130, 131, 132, 133, 134, 135, - 136, 137, 138, 139, 140, 141, 142, 143, - 144, 145, 146, 147, 148, 149, 150, 151, - 152, 153, 154, 155, 156, 157, 158, 159, - 160, 161, 162, 163, 164, 165, 166, 167, - 168, 169, 170, 171, 172, 173, 174, 175, - 176, 177, 178, 179, 180, 181, 182, 183, - 184, 185, 186, 187, 188, 189, 190, 191, - 192, 193, 194, 195, 196, 197, 198, 199, - 200, 201, 202, 203, 204, 205, 206, 207, - 208, 209, 210, 211, 212, 213, 214, 215, - 216, 217, 218, 219, 220, 221, 222, 223, - 224, 225, 226, 227, 228, 229, 230, 231, - 232, 233, 234, 235, 236, 237, 238, 239, - 240, 241, 242, 243, 244, 245, 246, 247, - 248, 249, 250, 251, 252, 253, 254, 255, - 0, -}; - /* unquant tables (not used directly) */ static const uint8_t dv_quant_shifts[22][4] = { { 3,3,4,4 }, @@ -460,203 +233,6 @@ static const uint8_t block_sizes_dv100[8] = { 80, 80, 80, 80, 80, 80, 64, 64, }; -static DVwork_chunk work_chunks_dv25pal [1*12*27]; -static DVwork_chunk work_chunks_dv25pal411[1*12*27]; -static DVwork_chunk work_chunks_dv25ntsc [1*10*27]; -static DVwork_chunk work_chunks_dv50pal [2*12*27]; -static DVwork_chunk work_chunks_dv50ntsc [2*10*27]; -static DVwork_chunk work_chunks_dv100palp [2*12*27]; -static DVwork_chunk work_chunks_dv100ntscp[2*10*27]; -static DVwork_chunk work_chunks_dv100pali [4*12*27]; -static DVwork_chunk work_chunks_dv100ntsci[4*10*27]; - -static uint32_t dv_idct_factor_sd [2*2*22*64]; -static uint32_t dv_idct_factor_hd1080[2*4*16*64]; -static uint32_t dv_idct_factor_hd720 [2*4*16*64]; - -static const DVprofile dv_profiles[] = { - { .dsf = 0, - .video_stype = 0x0, - .frame_size = 120000, /* IEC 61834, SMPTE-314M - 525/60 (NTSC) */ - .difseg_size = 10, - .n_difchan = 1, - .time_base = { 1001, 30000 }, - .ltc_divisor = 30, - .height = 480, - .width = 720, - .sar = {{10, 11}, {40, 33}}, - .work_chunks = &work_chunks_dv25ntsc[0], - .idct_factor = &dv_idct_factor_sd[0], - .pix_fmt = PIX_FMT_YUV411P, - .bpm = 6, - .block_sizes = block_sizes_dv2550, - .audio_stride = 90, - .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */ - .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */ - .audio_shuffle = dv_audio_shuffle525, - }, - { .dsf = 1, - .video_stype = 0x0, - .frame_size = 144000, /* IEC 61834 - 625/50 (PAL) */ - .difseg_size = 12, - .n_difchan = 1, - .time_base = { 1, 25 }, - .ltc_divisor = 25, - .height = 576, - .width = 720, - .sar = {{59, 54}, {118, 81}}, - .work_chunks = &work_chunks_dv25pal[0], - .idct_factor = &dv_idct_factor_sd[0], - .pix_fmt = PIX_FMT_YUV420P, - .bpm = 6, - .block_sizes = block_sizes_dv2550, - .audio_stride = 108, - .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */ - .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 }, - .audio_shuffle = dv_audio_shuffle625, - }, - { .dsf = 1, - .video_stype = 0x0, - .frame_size = 144000, /* SMPTE-314M - 625/50 (PAL) */ - .difseg_size = 12, - .n_difchan = 1, - .time_base = { 1, 25 }, - .ltc_divisor = 25, - .height = 576, - .width = 720, - .sar = {{59, 54}, {118, 81}}, - .work_chunks = &work_chunks_dv25pal411[0], - .idct_factor = &dv_idct_factor_sd[0], - .pix_fmt = PIX_FMT_YUV411P, - .bpm = 6, - .block_sizes = block_sizes_dv2550, - .audio_stride = 108, - .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */ - .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 }, - .audio_shuffle = dv_audio_shuffle625, - }, - { .dsf = 0, - .video_stype = 0x4, - .frame_size = 240000, /* SMPTE-314M - 525/60 (NTSC) 50 Mbps */ - .difseg_size = 10, /* also known as "DVCPRO50" */ - .n_difchan = 2, - .time_base = { 1001, 30000 }, - .ltc_divisor = 30, - .height = 480, - .width = 720, - .sar = {{10, 11}, {40, 33}}, - .work_chunks = &work_chunks_dv50ntsc[0], - .idct_factor = &dv_idct_factor_sd[0], - .pix_fmt = PIX_FMT_YUV422P, - .bpm = 6, - .block_sizes = block_sizes_dv2550, - .audio_stride = 90, - .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */ - .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */ - .audio_shuffle = dv_audio_shuffle525, - }, - { .dsf = 1, - .video_stype = 0x4, - .frame_size = 288000, /* SMPTE-314M - 625/50 (PAL) 50 Mbps */ - .difseg_size = 12, /* also known as "DVCPRO50" */ - .n_difchan = 2, - .time_base = { 1, 25 }, - .ltc_divisor = 25, - .height = 576, - .width = 720, - .sar = {{59, 54}, {118, 81}}, - .work_chunks = &work_chunks_dv50pal[0], - .idct_factor = &dv_idct_factor_sd[0], - .pix_fmt = PIX_FMT_YUV422P, - .bpm = 6, - .block_sizes = block_sizes_dv2550, - .audio_stride = 108, - .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */ - .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 }, - .audio_shuffle = dv_audio_shuffle625, - }, - { .dsf = 0, - .video_stype = 0x14, - .frame_size = 480000, /* SMPTE-370M - 1080i60 100 Mbps */ - .difseg_size = 10, /* also known as "DVCPRO HD" */ - .n_difchan = 4, - .time_base = { 1001, 30000 }, - .ltc_divisor = 30, - .height = 1080, - .width = 1280, - .sar = {{1, 1}, {1, 1}}, - .work_chunks = &work_chunks_dv100ntsci[0], - .idct_factor = &dv_idct_factor_hd1080[0], - .pix_fmt = PIX_FMT_YUV422P, - .bpm = 8, - .block_sizes = block_sizes_dv100, - .audio_stride = 90, - .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */ - .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */ - .audio_shuffle = dv_audio_shuffle525, - }, - { .dsf = 1, - .video_stype = 0x14, - .frame_size = 576000, /* SMPTE-370M - 1080i50 100 Mbps */ - .difseg_size = 12, /* also known as "DVCPRO HD" */ - .n_difchan = 4, - .time_base = { 1, 25 }, - .ltc_divisor = 25, - .height = 1080, - .width = 1440, - .sar = {{1, 1}, {1, 1}}, - .work_chunks = &work_chunks_dv100pali[0], - .idct_factor = &dv_idct_factor_hd1080[0], - .pix_fmt = PIX_FMT_YUV422P, - .bpm = 8, - .block_sizes = block_sizes_dv100, - .audio_stride = 108, - .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */ - .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 }, - .audio_shuffle = dv_audio_shuffle625, - }, - { .dsf = 0, - .video_stype = 0x18, - .frame_size = 240000, /* SMPTE-370M - 720p60 100 Mbps */ - .difseg_size = 10, /* also known as "DVCPRO HD" */ - .n_difchan = 2, - .time_base = { 1001, 60000 }, - .ltc_divisor = 60, - .height = 720, - .width = 960, - .sar = {{1, 1}, {1, 1}}, - .work_chunks = &work_chunks_dv100ntscp[0], - .idct_factor = &dv_idct_factor_hd720[0], - .pix_fmt = PIX_FMT_YUV422P, - .bpm = 8, - .block_sizes = block_sizes_dv100, - .audio_stride = 90, - .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */ - .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */ - .audio_shuffle = dv_audio_shuffle525, - }, - { .dsf = 1, - .video_stype = 0x18, - .frame_size = 288000, /* SMPTE-370M - 720p50 100 Mbps */ - .difseg_size = 12, /* also known as "DVCPRO HD" */ - .n_difchan = 2, - .time_base = { 1, 50 }, - .ltc_divisor = 50, - .height = 720, - .width = 960, - .sar = {{1, 1}, {1, 1}}, - .work_chunks = &work_chunks_dv100palp[0], - .idct_factor = &dv_idct_factor_hd720[0], - .pix_fmt = PIX_FMT_YUV422P, - .bpm = 8, - .block_sizes = block_sizes_dv100, - .audio_stride = 90, - .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */ - .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 }, - .audio_shuffle = dv_audio_shuffle625, - } -}; - enum dv_section_type { dv_sect_header = 0x1f, dv_sect_subcode = 0x3f, @@ -698,44 +274,9 @@ enum dv_pack_type { */ #define DV_MAX_BPM 8 -static inline -const DVprofile* dv_frame_profile(const DVprofile *sys, - const uint8_t* frame, unsigned buf_size) -{ - int i; - - int dsf = (frame[3] & 0x80) >> 7; - - int stype = frame[80*5 + 48 + 3] & 0x1f; - - /* 576i50 25Mbps 4:1:1 is a special case */ - if (dsf == 1 && stype == 0 && frame[5] & 0x07) { - return &dv_profiles[2]; - } - - for (i=0; iframe_size) - return sys; - - return NULL; -} - -static const DVprofile* dv_codec_profile(AVCodecContext* codec) -{ - int i; - - for (i=0; iheight == dv_profiles[i].height && - codec->pix_fmt == dv_profiles[i].pix_fmt && - codec->width == dv_profiles[i].width) - return &dv_profiles[i]; - - return NULL; -} +const DVprofile* ff_dv_frame_profile(const DVprofile *sys, + const uint8_t* frame, unsigned buf_size); +const DVprofile* ff_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/src/add-ons/media/plugins/ffmpeg/libavcodec/dvdsubdec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/dvdsubdec.c index 142241217c..75b52566d3 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/dvdsubdec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dvdsubdec.c @@ -488,7 +488,7 @@ static int dvdsub_decode(AVCodecContext *avctx, AVCodec dvdsub_decoder = { "dvdsub", - CODEC_TYPE_SUBTITLE, + AVMEDIA_TYPE_SUBTITLE, CODEC_ID_DVD_SUBTITLE, 0, NULL, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dvdsubenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/dvdsubenc.c index 4dc58e7bde..4ee0f37c9d 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/dvdsubenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dvdsubenc.c @@ -217,7 +217,7 @@ static int dvdsub_encode(AVCodecContext *avctx, AVCodec dvdsub_encoder = { "dvdsub", - CODEC_TYPE_SUBTITLE, + AVMEDIA_TYPE_SUBTITLE, CODEC_ID_DVD_SUBTITLE, 0, NULL, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dwt.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/dwt.c new file mode 100644 index 0000000000..2ecb04a4ee --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dwt.c @@ -0,0 +1,843 @@ +/* + * Copyright (C) 2004-2010 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 + */ + +#include "libavutil/attributes.h" +#include "dsputil.h" +#include "dwt.h" + +void ff_slice_buffer_init(slice_buffer * buf, int line_count, int max_allocated_lines, int line_width, IDWTELEM * base_buffer) +{ + int i; + + buf->base_buffer = base_buffer; + buf->line_count = line_count; + buf->line_width = line_width; + buf->data_count = max_allocated_lines; + buf->line = av_mallocz (sizeof(IDWTELEM *) * line_count); + buf->data_stack = av_malloc (sizeof(IDWTELEM *) * max_allocated_lines); + + for(i = 0; i < max_allocated_lines; i++){ + buf->data_stack[i] = av_malloc (sizeof(IDWTELEM) * line_width); + } + + buf->data_stack_top = max_allocated_lines - 1; +} + +IDWTELEM * ff_slice_buffer_load_line(slice_buffer * buf, int line) +{ + IDWTELEM * buffer; + + assert(buf->data_stack_top >= 0); +// assert(!buf->line[line]); + if (buf->line[line]) + return buf->line[line]; + + buffer = buf->data_stack[buf->data_stack_top]; + buf->data_stack_top--; + buf->line[line] = buffer; + + return buffer; +} + +void ff_slice_buffer_release(slice_buffer * buf, int line) +{ + IDWTELEM * buffer; + + assert(line >= 0 && line < buf->line_count); + assert(buf->line[line]); + + buffer = buf->line[line]; + buf->data_stack_top++; + buf->data_stack[buf->data_stack_top] = buffer; + buf->line[line] = NULL; +} + +void ff_slice_buffer_flush(slice_buffer * buf) +{ + int i; + for(i = 0; i < buf->line_count; i++){ + if (buf->line[i]) + ff_slice_buffer_release(buf, i); + } +} + +void ff_slice_buffer_destroy(slice_buffer * buf) +{ + int i; + ff_slice_buffer_flush(buf); + + for(i = buf->data_count - 1; i >= 0; i--){ + av_freep(&buf->data_stack[i]); + } + av_freep(&buf->data_stack); + av_freep(&buf->line); +} + +static inline int mirror(int v, int m){ + while((unsigned)v > (unsigned)m){ + v=-v; + if(v<0) v+= 2*m; + } + return v; +} + +static av_always_inline void +lift(DWTELEM *dst, DWTELEM *src, DWTELEM *ref, + int dst_step, int src_step, int ref_step, + int width, int mul, int add, int shift, + int highpass, int inverse){ + const int mirror_left= !highpass; + const int mirror_right= (width&1) ^ highpass; + const int w= (width>>1) - 1 + (highpass & width); + int i; + +#define LIFT(src, ref, inv) ((src) + ((inv) ? - (ref) : + (ref))) + if(mirror_left){ + dst[0] = LIFT(src[0], ((mul*2*ref[0]+add)>>shift), inverse); + dst += dst_step; + src += src_step; + } + + for(i=0; i>shift), + inverse); + } + + if(mirror_right){ + dst[w*dst_step] = + LIFT(src[w*src_step], + ((mul*2*ref[w*ref_step]+add)>>shift), + inverse); + } +} + +static av_always_inline void +inv_lift(IDWTELEM *dst, IDWTELEM *src, IDWTELEM *ref, + int dst_step, int src_step, int ref_step, + int width, int mul, int add, int shift, + int highpass, int inverse){ + const int mirror_left= !highpass; + const int mirror_right= (width&1) ^ highpass; + const int w= (width>>1) - 1 + (highpass & width); + int i; + +#define LIFT(src, ref, inv) ((src) + ((inv) ? - (ref) : + (ref))) + if(mirror_left){ + dst[0] = LIFT(src[0], ((mul*2*ref[0]+add)>>shift), inverse); + dst += dst_step; + src += src_step; + } + + for(i=0; i>shift), + inverse); + } + + if(mirror_right){ + dst[w*dst_step] = + LIFT(src[w*src_step], + ((mul*2*ref[w*ref_step]+add)>>shift), + inverse); + } +} + +#ifndef liftS +static av_always_inline void +liftS(DWTELEM *dst, DWTELEM *src, DWTELEM *ref, + int dst_step, int src_step, int ref_step, + int width, int mul, int add, int shift, + int highpass, int inverse){ + const int mirror_left= !highpass; + const int mirror_right= (width&1) ^ highpass; + const int w= (width>>1) - 1 + (highpass & width); + int i; + + assert(shift == 4); +#define LIFTS(src, ref, inv) \ + ((inv) ? \ + (src) + (((ref) + 4*(src))>>shift): \ + -((-16*(src) + (ref) + add/4 + 1 + (5<<25))/(5*4) - (1<<23))) + if(mirror_left){ + dst[0] = LIFTS(src[0], mul*2*ref[0]+add, inverse); + dst += dst_step; + src += src_step; + } + + for(i=0; i>1) - 1 + (highpass & width); + int i; + + assert(shift == 4); +#define LIFTS(src, ref, inv) \ + ((inv) ? \ + (src) + (((ref) + 4*(src))>>shift): \ + -((-16*(src) + (ref) + add/4 + 1 + (5<<25))/(5*4) - (1<<23))) + if(mirror_left){ + dst[0] = LIFTS(src[0], mul*2*ref[0]+add, inverse); + dst += dst_step; + src += src_step; + } + + for(i=0; i>1; + int x; + const int w2= (width+1)>>1; + + for(x=0; x>1; + A4 += (A1 + 1)>>1; + b[0+width2] = A1; + b[0 ] = A4; + for(x=1; x+1>1; + A2 += (A1 + A3 + 2)>>2; + b[x+width2] = A3; + b[x ] = A2; + + A1= temp[x+1+width2]; + A2= temp[x+2 ]; + A1 -= (A2 + A4)>>1; + A4 += (A1 + A3 + 2)>>2; + b[x+1+width2] = A1; + b[x+1 ] = A4; + } + A3= temp[width-1]; + A3 -= A2; + A2 += (A1 + A3 + 2)>>2; + b[width -1] = A3; + b[width2-1] = A2; + } +#else + lift(b+w2, temp+w2, temp, 1, 1, 1, width, -1, 0, 1, 1, 0); + lift(b , temp , b+w2, 1, 1, 1, width, 1, 2, 2, 0, 0); +#endif /* 0 */ +} + +static void vertical_decompose53iH0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){ + int i; + + for(i=0; i>1; + } +} + +static void vertical_decompose53iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){ + int i; + + for(i=0; i>2; + } +} + +static void spatial_decompose53i(DWTELEM *buffer, int width, int height, int stride){ + int y; + DWTELEM *b0= buffer + mirror(-2-1, height-1)*stride; + DWTELEM *b1= buffer + mirror(-2 , height-1)*stride; + + for(y=-2; y>1; + + lift (temp+w2, b +1, b , 1, 2, 2, width, W_AM, W_AO, W_AS, 1, 1); + liftS(temp , b , temp+w2, 1, 2, 1, width, W_BM, W_BO, W_BS, 0, 0); + lift (b +w2, temp+w2, temp , 1, 1, 1, width, W_CM, W_CO, W_CS, 1, 0); + lift (b , temp , b +w2, 1, 1, 1, width, W_DM, W_DO, W_DS, 0, 0); +} + + +static void vertical_decompose97iH0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){ + int i; + + for(i=0; i>W_AS; + } +} + +static void vertical_decompose97iH1(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){ + int i; + + for(i=0; i>W_CS; + } +} + +static void vertical_decompose97iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){ + int i; + + for(i=0; i>W_BS; +#else + b1[i] = (16*4*b1[i] - 4*(b0[i] + b2[i]) + W_BO*5 + (5<<27)) / (5*16) - (1<<23); +#endif + } +} + +static void vertical_decompose97iL1(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){ + int i; + + for(i=0; i>W_DS; + } +} + +static void spatial_decompose97i(DWTELEM *buffer, int width, int height, int stride){ + int y; + DWTELEM *b0= buffer + mirror(-4-1, height-1)*stride; + DWTELEM *b1= buffer + mirror(-4 , height-1)*stride; + DWTELEM *b2= buffer + mirror(-4+1, height-1)*stride; + DWTELEM *b3= buffer + mirror(-4+2, height-1)*stride; + + for(y=-4; y>level, height>>level, stride<>level, height>>level, stride<>1; + const int w2= (width+1)>>1; + int x; + + for(x=0; x>1); + for(x=2; x>2); + b[x-1] = temp[x-1] + ((b [x-2] + b [x ]+1)>>1); + } + if(width&1){ + b[x ] = temp[x ] - ((temp[x-1]+1)>>1); + b[x-1] = temp[x-1] + ((b [x-2] + b [x ]+1)>>1); + }else + b[x-1] = temp[x-1] + b[x-2]; +} + +static void vertical_compose53iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width){ + int i; + + for(i=0; i>1; + } +} + +static void vertical_compose53iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width){ + int i; + + for(i=0; i>2; + } +} + +static void spatial_compose53i_buffered_init(DWTCompose *cs, slice_buffer * sb, int height, int stride_line){ + cs->b0 = slice_buffer_get_line(sb, mirror(-1-1, height-1) * stride_line); + cs->b1 = slice_buffer_get_line(sb, mirror(-1 , height-1) * stride_line); + cs->y = -1; +} + +static void spatial_compose53i_init(DWTCompose *cs, IDWTELEM *buffer, int height, int stride){ + cs->b0 = buffer + mirror(-1-1, height-1)*stride; + cs->b1 = buffer + mirror(-1 , height-1)*stride; + cs->y = -1; +} + +static void spatial_compose53i_dy_buffered(DWTCompose *cs, slice_buffer * sb, int width, int height, int stride_line){ + int y= cs->y; + + IDWTELEM *b0= cs->b0; + IDWTELEM *b1= cs->b1; + IDWTELEM *b2= slice_buffer_get_line(sb, mirror(y+1, height-1) * stride_line); + IDWTELEM *b3= slice_buffer_get_line(sb, mirror(y+2, height-1) * stride_line); + + if(y+1<(unsigned)height && y<(unsigned)height){ + int x; + + for(x=0; x>2; + b1[x] += (b0[x] + b2[x])>>1; + } + }else{ + if(y+1<(unsigned)height) vertical_compose53iL0(b1, b2, b3, width); + if(y+0<(unsigned)height) vertical_compose53iH0(b0, b1, b2, width); + } + + if(y-1<(unsigned)height) horizontal_compose53i(b0, width); + if(y+0<(unsigned)height) horizontal_compose53i(b1, width); + + cs->b0 = b2; + cs->b1 = b3; + cs->y += 2; +} + +static void spatial_compose53i_dy(DWTCompose *cs, IDWTELEM *buffer, int width, int height, int stride){ + int y= cs->y; + IDWTELEM *b0= cs->b0; + IDWTELEM *b1= cs->b1; + IDWTELEM *b2= buffer + mirror(y+1, height-1)*stride; + IDWTELEM *b3= buffer + mirror(y+2, height-1)*stride; + + if(y+1<(unsigned)height) vertical_compose53iL0(b1, b2, b3, width); + if(y+0<(unsigned)height) vertical_compose53iH0(b0, b1, b2, width); + + if(y-1<(unsigned)height) horizontal_compose53i(b0, width); + if(y+0<(unsigned)height) horizontal_compose53i(b1, width); + + cs->b0 = b2; + cs->b1 = b3; + cs->y += 2; +} + +static void av_unused spatial_compose53i(IDWTELEM *buffer, int width, int height, int stride){ + DWTCompose cs; + spatial_compose53i_init(&cs, buffer, height, stride); + while(cs.y <= height) + spatial_compose53i_dy(&cs, buffer, width, height, stride); +} + + +void ff_snow_horizontal_compose97i(IDWTELEM *b, int width){ + IDWTELEM temp[width]; + const int w2= (width+1)>>1; + +#if 0 //maybe more understadable but slower + inv_lift (temp , b , b +w2, 2, 1, 1, width, W_DM, W_DO, W_DS, 0, 1); + inv_lift (temp+1 , b +w2, temp , 2, 1, 2, width, W_CM, W_CO, W_CS, 1, 1); + + inv_liftS(b , temp , temp+1 , 2, 2, 2, width, W_BM, W_BO, W_BS, 0, 1); + inv_lift (b+1 , temp+1 , b , 2, 2, 2, width, W_AM, W_AO, W_AS, 1, 0); +#else + int x; + temp[0] = b[0] - ((3*b[w2]+2)>>2); + for(x=1; x<(width>>1); x++){ + temp[2*x ] = b[x ] - ((3*(b [x+w2-1] + b[x+w2])+4)>>3); + temp[2*x-1] = b[x+w2-1] - temp[2*x-2] - temp[2*x]; + } + if(width&1){ + temp[2*x ] = b[x ] - ((3*b [x+w2-1]+2)>>2); + temp[2*x-1] = b[x+w2-1] - temp[2*x-2] - temp[2*x]; + }else + temp[2*x-1] = b[x+w2-1] - 2*temp[2*x-2]; + + b[0] = temp[0] + ((2*temp[0] + temp[1]+4)>>3); + for(x=2; x>4); + b[x-1] = temp[x-1] + ((3*(b [x-2] + b [x ] ))>>1); + } + if(width&1){ + b[x ] = temp[x ] + ((2*temp[x ] + temp[x-1]+4)>>3); + b[x-1] = temp[x-1] + ((3*(b [x-2] + b [x ] ))>>1); + }else + b[x-1] = temp[x-1] + 3*b [x-2]; +#endif +} + +static void vertical_compose97iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width){ + int i; + + for(i=0; i>W_AS; + } +} + +static void vertical_compose97iH1(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width){ + int i; + + for(i=0; i>W_CS; + } +} + +static void vertical_compose97iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width){ + int i; + + for(i=0; i>W_BS; +#else + b1[i] += (W_BM*(b0[i] + b2[i])+4*b1[i]+W_BO)>>W_BS; +#endif + } +} + +static void vertical_compose97iL1(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width){ + int i; + + for(i=0; i>W_DS; + } +} + +void ff_snow_vertical_compose97i(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width){ + int i; + + for(i=0; i>W_DS; + b3[i] -= (W_CM*(b2[i] + b4[i])+W_CO)>>W_CS; +#ifdef liftS + b2[i] += (W_BM*(b1[i] + b3[i])+W_BO)>>W_BS; +#else + b2[i] += (W_BM*(b1[i] + b3[i])+4*b2[i]+W_BO)>>W_BS; +#endif + b1[i] += (W_AM*(b0[i] + b2[i])+W_AO)>>W_AS; + } +} + +static void spatial_compose97i_buffered_init(DWTCompose *cs, slice_buffer * sb, int height, int stride_line){ + cs->b0 = slice_buffer_get_line(sb, mirror(-3-1, height-1) * stride_line); + cs->b1 = slice_buffer_get_line(sb, mirror(-3 , height-1) * stride_line); + cs->b2 = slice_buffer_get_line(sb, mirror(-3+1, height-1) * stride_line); + cs->b3 = slice_buffer_get_line(sb, mirror(-3+2, height-1) * stride_line); + cs->y = -3; +} + +static void spatial_compose97i_init(DWTCompose *cs, IDWTELEM *buffer, int height, int stride){ + cs->b0 = buffer + mirror(-3-1, height-1)*stride; + cs->b1 = buffer + mirror(-3 , height-1)*stride; + cs->b2 = buffer + mirror(-3+1, height-1)*stride; + cs->b3 = buffer + mirror(-3+2, height-1)*stride; + cs->y = -3; +} + +static void spatial_compose97i_dy_buffered(DWTContext *dsp, DWTCompose *cs, slice_buffer * sb, int width, int height, int stride_line){ + int y = cs->y; + + IDWTELEM *b0= cs->b0; + IDWTELEM *b1= cs->b1; + IDWTELEM *b2= cs->b2; + IDWTELEM *b3= cs->b3; + IDWTELEM *b4= slice_buffer_get_line(sb, mirror(y + 3, height - 1) * stride_line); + IDWTELEM *b5= slice_buffer_get_line(sb, mirror(y + 4, height - 1) * stride_line); + + if(y>0 && y+4vertical_compose97i(b0, b1, b2, b3, b4, b5, width); + }else{ + if(y+3<(unsigned)height) vertical_compose97iL1(b3, b4, b5, width); + if(y+2<(unsigned)height) vertical_compose97iH1(b2, b3, b4, width); + if(y+1<(unsigned)height) vertical_compose97iL0(b1, b2, b3, width); + if(y+0<(unsigned)height) vertical_compose97iH0(b0, b1, b2, width); + } + + if(y-1<(unsigned)height) dsp->horizontal_compose97i(b0, width); + if(y+0<(unsigned)height) dsp->horizontal_compose97i(b1, width); + + cs->b0=b2; + cs->b1=b3; + cs->b2=b4; + cs->b3=b5; + cs->y += 2; +} + +static void spatial_compose97i_dy(DWTCompose *cs, IDWTELEM *buffer, int width, int height, int stride){ + int y = cs->y; + IDWTELEM *b0= cs->b0; + IDWTELEM *b1= cs->b1; + IDWTELEM *b2= cs->b2; + IDWTELEM *b3= cs->b3; + IDWTELEM *b4= buffer + mirror(y+3, height-1)*stride; + IDWTELEM *b5= buffer + mirror(y+4, height-1)*stride; + + if(y+3<(unsigned)height) vertical_compose97iL1(b3, b4, b5, width); + if(y+2<(unsigned)height) vertical_compose97iH1(b2, b3, b4, width); + if(y+1<(unsigned)height) vertical_compose97iL0(b1, b2, b3, width); + if(y+0<(unsigned)height) vertical_compose97iH0(b0, b1, b2, width); + + if(y-1<(unsigned)height) ff_snow_horizontal_compose97i(b0, width); + if(y+0<(unsigned)height) ff_snow_horizontal_compose97i(b1, width); + + cs->b0=b2; + cs->b1=b3; + cs->b2=b4; + cs->b3=b5; + cs->y += 2; +} + +static void av_unused spatial_compose97i(IDWTELEM *buffer, int width, int height, int stride){ + DWTCompose cs; + spatial_compose97i_init(&cs, buffer, height, stride); + while(cs.y <= height) + spatial_compose97i_dy(&cs, buffer, width, height, stride); +} + +void ff_spatial_idwt_buffered_init(DWTCompose *cs, slice_buffer * sb, int width, int height, int stride_line, int type, int decomposition_count){ + int level; + for(level=decomposition_count-1; level>=0; level--){ + switch(type){ + case DWT_97: spatial_compose97i_buffered_init(cs+level, sb, height>>level, stride_line<>level, stride_line<=0; level--){ + while(cs[level].y <= FFMIN((y>>level)+support, height>>level)){ + switch(type){ + case DWT_97: spatial_compose97i_dy_buffered(dsp, cs+level, slice_buf, width>>level, height>>level, stride_line<>level, height>>level, stride_line<=0; level--){ + switch(type){ + case DWT_97: spatial_compose97i_init(cs+level, buffer, height>>level, stride<>level, stride<=0; level--){ + while(cs[level].y <= FFMIN((y>>level)+support, height>>level)){ + switch(type){ + case DWT_97: spatial_compose97i_dy(cs+level, buffer, width>>level, height>>level, stride<>level, height>>level, stride<>(dec_count-level); + int sx= (ori&1) ? size : 0; + int stride= 32<<(dec_count-level); + int sy= (ori&2) ? stride>>1 : 0; + + for(i=0; i=0); + return s>>9; +} + +static int w53_8_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){ + return w_c(v, pix1, pix2, line_size, 8, h, 1); +} + +static int w97_8_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){ + return w_c(v, pix1, pix2, line_size, 8, h, 0); +} + +static int w53_16_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){ + return w_c(v, pix1, pix2, line_size, 16, h, 1); +} + +static int w97_16_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){ + return w_c(v, pix1, pix2, line_size, 16, h, 0); +} + +int ff_w53_32_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){ + return w_c(v, pix1, pix2, line_size, 32, h, 1); +} + +int ff_w97_32_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){ + return w_c(v, pix1, pix2, line_size, 32, h, 0); +} + +void ff_dsputil_init_dwt(DSPContext *c) +{ + c->w53[0]= w53_16_c; + c->w53[1]= w53_8_c; + c->w97[0]= w97_16_c; + c->w97[1]= w97_8_c; +} + +void ff_dwt_init(DWTContext *c) +{ + c->vertical_compose97i = ff_snow_vertical_compose97i; + c->horizontal_compose97i = ff_snow_horizontal_compose97i; + c->inner_add_yblock = ff_snow_inner_add_yblock; + + if (HAVE_MMX) ff_dwt_init_x86(c); +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dwt.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/dwt.h new file mode 100644 index 0000000000..8c3aa204d6 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dwt.h @@ -0,0 +1,156 @@ +/* + * Copyright (C) 2004-2010 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 + */ + +#ifndef AVCODEC_DWT_H +#define AVCODEC_DWT_H + +#include + +typedef int DWTELEM; +typedef short IDWTELEM; + +typedef struct { + IDWTELEM *b0; + IDWTELEM *b1; + IDWTELEM *b2; + IDWTELEM *b3; + int y; +} DWTCompose; + +/** Used to minimize the amount of memory used in order to optimize cache performance. **/ +typedef struct slice_buffer_s { + IDWTELEM * * line; ///< For use by idwt and predict_slices. + IDWTELEM * * data_stack; ///< Used for internal purposes. + int data_stack_top; + int line_count; + int line_width; + int data_count; + IDWTELEM * base_buffer; ///< Buffer that this structure is caching. +} slice_buffer; + +typedef struct DWTContext { + void (*vertical_compose97i)(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width); + void (*horizontal_compose97i)(IDWTELEM *b, int width); + void (*inner_add_yblock)(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h, int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8); +} DWTContext; + +#define MAX_DECOMPOSITIONS 8 + +#define DWT_97 0 +#define DWT_53 1 + +#define liftS lift +#if 1 +#define W_AM 3 +#define W_AO 0 +#define W_AS 1 + +#undef liftS +#define W_BM 1 +#define W_BO 8 +#define W_BS 4 + +#define W_CM 1 +#define W_CO 0 +#define W_CS 0 + +#define W_DM 3 +#define W_DO 4 +#define W_DS 3 +#elif 0 +#define W_AM 55 +#define W_AO 16 +#define W_AS 5 + +#define W_BM 3 +#define W_BO 32 +#define W_BS 6 + +#define W_CM 127 +#define W_CO 64 +#define W_CS 7 + +#define W_DM 7 +#define W_DO 8 +#define W_DS 4 +#elif 0 +#define W_AM 97 +#define W_AO 32 +#define W_AS 6 + +#define W_BM 63 +#define W_BO 512 +#define W_BS 10 + +#define W_CM 13 +#define W_CO 8 +#define W_CS 4 + +#define W_DM 15 +#define W_DO 16 +#define W_DS 5 + +#else + +#define W_AM 203 +#define W_AO 64 +#define W_AS 7 + +#define W_BM 217 +#define W_BO 2048 +#define W_BS 12 + +#define W_CM 113 +#define W_CO 64 +#define W_CS 7 + +#define W_DM 227 +#define W_DO 128 +#define W_DS 9 +#endif + +#define slice_buffer_get_line(slice_buf, line_num) ((slice_buf)->line[line_num] ? (slice_buf)->line[line_num] : ff_slice_buffer_load_line((slice_buf), (line_num))) +//#define slice_buffer_get_line(slice_buf, line_num) (ff_slice_buffer_load_line((slice_buf), (line_num))) + +void ff_slice_buffer_init(slice_buffer * buf, int line_count, int max_allocated_lines, int line_width, IDWTELEM * base_buffer); +void ff_slice_buffer_release(slice_buffer * buf, int line); +void ff_slice_buffer_flush(slice_buffer * buf); +void ff_slice_buffer_destroy(slice_buffer * buf); +IDWTELEM * ff_slice_buffer_load_line(slice_buffer * buf, int line); + +void ff_snow_vertical_compose97i(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width); +void ff_snow_horizontal_compose97i(IDWTELEM *b, int width); +void ff_snow_inner_add_yblock(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h, int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8); + +int ff_w53_32_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h); +int ff_w97_32_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h); + +void ff_spatial_dwt(int *buffer, int width, int height, int stride, int type, int decomposition_count); + +void ff_spatial_idwt_buffered_init(DWTCompose *cs, slice_buffer * sb, int width, int height, int stride_line, int type, int decomposition_count); +void ff_spatial_idwt_buffered_slice(DWTContext *dsp, DWTCompose *cs, slice_buffer * slice_buf, int width, int height, int stride_line, int type, int decomposition_count, int y); +void ff_spatial_idwt_init(DWTCompose *cs, IDWTELEM *buffer, int width, int height, int stride, int type, int decomposition_count); +void ff_spatial_idwt_slice(DWTCompose *cs, IDWTELEM *buffer, int width, int height, int stride, int type, int decomposition_count, int y); +void ff_spatial_idwt(IDWTELEM *buffer, int width, int height, int stride, int type, int decomposition_count); + +void ff_dwt_init(DWTContext *c); +void ff_dwt_init_x86(DWTContext *c); + +#endif /* AVCODEC_DWT_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dxa.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/dxa.c index 69aed3c89e..62e4e0ae82 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/dxa.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dxa.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/dxa.c + * @file * DXA Video decoder */ @@ -295,10 +295,6 @@ static av_cold int decode_init(AVCodecContext *avctx) c->avctx = avctx; avctx->pix_fmt = PIX_FMT_PAL8; - if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) { - return -1; - } - 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"); @@ -323,7 +319,7 @@ static av_cold int decode_end(AVCodecContext *avctx) AVCodec dxa_decoder = { "dxa", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_DXA, sizeof(DxaDecContext), decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dxva2.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/dxva2.c new file mode 100644 index 0000000000..3f14311c9a --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dxva2.c @@ -0,0 +1,154 @@ +/* + * DXVA2 HW acceleration. + * + * copyright (c) 2010 Laurent Aimar + * + * 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 "dxva2_internal.h" + +void *ff_dxva2_get_surface(const Picture *picture) +{ + return picture->data[3]; +} + +unsigned ff_dxva2_get_surface_index(const struct dxva_context *ctx, + const Picture *picture) +{ + void *surface = ff_dxva2_get_surface(picture); + unsigned i; + + for (i = 0; i < ctx->surface_count; i++) + if (ctx->surface[i] == surface) + return i; + + assert(0); + return 0; +} + +int ff_dxva2_commit_buffer(AVCodecContext *avctx, + struct dxva_context *ctx, + DXVA2_DecodeBufferDesc *dsc, + unsigned type, const void *data, unsigned size, + unsigned mb_count) +{ + void *dxva_data; + unsigned dxva_size; + int result; + + if (FAILED(IDirectXVideoDecoder_GetBuffer(ctx->decoder, type, + &dxva_data, &dxva_size))) { + av_log(avctx, AV_LOG_ERROR, "Failed to get a buffer for %d\n", type); + return -1; + } + if (size <= dxva_size) { + memcpy(dxva_data, data, size); + + memset(dsc, 0, sizeof(*dsc)); + dsc->CompressedBufferType = type; + dsc->DataSize = size; + dsc->NumMBsInBuffer = mb_count; + + result = 0; + } else { + av_log(avctx, AV_LOG_ERROR, "Buffer for type %d was too small\n", type); + result = -1; + } + if (FAILED(IDirectXVideoDecoder_ReleaseBuffer(ctx->decoder, type))) { + av_log(avctx, AV_LOG_ERROR, "Failed to release buffer type %d\n", type); + result = -1; + } + return result; +} + +int ff_dxva2_common_end_frame(AVCodecContext *avctx, MpegEncContext *s, + const void *pp, unsigned pp_size, + const void *qm, unsigned qm_size, + int (*commit_bs_si)(AVCodecContext *, + DXVA2_DecodeBufferDesc *bs, + DXVA2_DecodeBufferDesc *slice)) +{ + struct dxva_context *ctx = avctx->hwaccel_context; + unsigned buffer_count = 0; + DXVA2_DecodeBufferDesc buffer[4]; + DXVA2_DecodeExecuteParams exec; + int result; + + if (FAILED(IDirectXVideoDecoder_BeginFrame(ctx->decoder, + ff_dxva2_get_surface(s->current_picture_ptr), + NULL))) { + av_log(avctx, AV_LOG_ERROR, "Failed to begin frame\n"); + return -1; + } + + result = ff_dxva2_commit_buffer(avctx, ctx, &buffer[buffer_count], + DXVA2_PictureParametersBufferType, + pp, pp_size, 0); + if (result) { + av_log(avctx, AV_LOG_ERROR, + "Failed to add picture parameter buffer\n"); + goto end; + } + buffer_count++; + + if (qm_size > 0) { + result = ff_dxva2_commit_buffer(avctx, ctx, &buffer[buffer_count], + DXVA2_InverseQuantizationMatrixBufferType, + qm, qm_size, 0); + if (result) { + av_log(avctx, AV_LOG_ERROR, + "Failed to add inverse quantization matrix buffer\n"); + goto end; + } + buffer_count++; + } + + result = commit_bs_si(avctx, + &buffer[buffer_count + 0], + &buffer[buffer_count + 1]); + if (result) { + av_log(avctx, AV_LOG_ERROR, + "Failed to add bitstream or slice control buffer\n"); + goto end; + } + buffer_count += 2; + + /* TODO Film Grain when possible */ + + assert(buffer_count == 1 + (qm_size > 0) + 2); + + memset(&exec, 0, sizeof(exec)); + exec.NumCompBuffers = buffer_count; + exec.pCompressedBuffers = buffer; + exec.pExtensionData = NULL; + if (FAILED(IDirectXVideoDecoder_Execute(ctx->decoder, &exec))) { + av_log(avctx, AV_LOG_ERROR, "Failed to execute\n"); + result = -1; + } + +end: + if (FAILED(IDirectXVideoDecoder_EndFrame(ctx->decoder, NULL))) { + av_log(avctx, AV_LOG_ERROR, "Failed to end frame\n"); + result = -1; + } + + if (!result) + ff_draw_horiz_band(s, 0, s->avctx->height); + return result; +} + diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dxva2.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/dxva2.h new file mode 100644 index 0000000000..5c5fe21e2f --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dxva2.h @@ -0,0 +1,68 @@ +/* + * DXVA2 HW acceleration + * + * copyright (c) 2009 Laurent Aimar + * + * 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_DXVA_H +#define AVCODEC_DXVA_H + +#include + +#include + +/** + * This structure is used to provides the necessary configurations and data + * to the DXVA2 FFmpeg HWAccel implementation. + * + * The application must make it available as AVCodecContext.hwaccel_context. + */ +struct dxva_context { + /** + * DXVA2 decoder object + */ + IDirectXVideoDecoder *decoder; + + /** + * DXVA2 configuration used to create the decoder + */ + const DXVA2_ConfigPictureDecode *cfg; + + /** + * The number of surface in the surface array + */ + unsigned surface_count; + + /** + * The array of Direct3D surfaces used to create the decoder + */ + LPDIRECT3DSURFACE9 *surface; + + /** + * A bit field configuring the workarounds needed for using the decoder + */ + uint64_t workaround; + + /** + * Private to the FFmpeg AVHWAccel implementation + */ + unsigned report_id; +}; + +#endif /* AVCODEC_DXVA_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dxva2_h264.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/dxva2_h264.c new file mode 100644 index 0000000000..22c76df601 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dxva2_h264.c @@ -0,0 +1,437 @@ +/* + * DXVA2 H264 HW acceleration. + * + * copyright (c) 2009 Laurent Aimar + * + * 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 "dxva2_internal.h" +#include "h264.h" +#include "h264data.h" + +struct dxva2_picture_context { + DXVA_PicParams_H264 pp; + DXVA_Qmatrix_H264 qm; + unsigned slice_count; + DXVA_Slice_H264_Short slice_short[MAX_SLICES]; + DXVA_Slice_H264_Long slice_long[MAX_SLICES]; + const uint8_t *bitstream; + unsigned bitstream_size; +}; + +static void fill_picture_entry(DXVA_PicEntry_H264 *pic, + unsigned index, unsigned flag) +{ + assert((index&0x7f) == index && (flag&0x01) == flag); + pic->bPicEntry = index | (flag << 7); +} + +static void fill_picture_parameters(struct dxva_context *ctx, const H264Context *h, + DXVA_PicParams_H264 *pp) +{ + const MpegEncContext *s = &h->s; + const Picture *current_picture = s->current_picture_ptr; + int i; + + memset(pp, 0, sizeof(*pp)); + /* Configure current picture */ + fill_picture_entry(&pp->CurrPic, + ff_dxva2_get_surface_index(ctx, current_picture), + s->picture_structure == PICT_BOTTOM_FIELD); + /* Configure the set of references */ + pp->UsedForReferenceFlags = 0; + pp->NonExistingFrameFlags = 0; + for (i = 0; i < FF_ARRAY_ELEMS(pp->RefFrameList); i++) { + if (i < h->short_ref_count + h->long_ref_count) { + const Picture *r; + if (i < h->short_ref_count) { + r = h->short_ref[i]; + assert(!r->long_ref); + } else { + r = h->long_ref[i - h->short_ref_count]; + assert(r->long_ref); + } + fill_picture_entry(&pp->RefFrameList[i], + ff_dxva2_get_surface_index(ctx, r), + r->long_ref != 0); + + if ((r->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) + 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) + pp->UsedForReferenceFlags |= 1 << (2*i + 0); + if (r->reference & PICT_BOTTOM_FIELD) + pp->UsedForReferenceFlags |= 1 << (2*i + 1); + } else { + pp->RefFrameList[i].bPicEntry = 0xff; + pp->FieldOrderCntList[i][0] = 0; + pp->FieldOrderCntList[i][1] = 0; + pp->FrameNumList[i] = 0; + } + } + + pp->wFrameWidthInMbsMinus1 = s->mb_width - 1; + pp->wFrameHeightInMbsMinus1 = s->mb_height - 1; + pp->num_ref_frames = h->sps.ref_frame_count; + + 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 FFmpeg) */ + (0 << 3) | + (h->sps.chroma_format_idc << 4) | + ((h->nal_ref_idc != 0) << 6) | + (h->pps.constrained_intra_pred << 7) | + (h->pps.weighted_pred << 8) | + (h->pps.weighted_bipred_idc << 9) | + /* MbsConsecutiveFlag */ + (1 << 11) | + (h->sps.frame_mbs_only_flag << 12) | + (h->pps.transform_8x8_mode << 13) | + ((h->sps.level_idc >= 31) << 14) | + /* IntraPicFlag (Modified if we detect a non + * intra slice in decode_slice) */ + (1 << 15); + + 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 ? */ + pp->StatusReportFeedbackNumber = 1 + ctx->report_id++; + pp->CurrFieldOrderCnt[0] = 0; + if ((s->picture_structure & PICT_TOP_FIELD) && + current_picture->field_poc[0] != INT_MAX) + pp->CurrFieldOrderCnt[0] = current_picture->field_poc[0]; + pp->CurrFieldOrderCnt[1] = 0; + if ((s->picture_structure & PICT_BOTTOM_FIELD) && + current_picture->field_poc[1] != INT_MAX) + pp->CurrFieldOrderCnt[1] = current_picture->field_poc[1]; + pp->pic_init_qs_minus26 = h->pps.init_qs - 26; + pp->chroma_qp_index_offset = h->pps.chroma_qp_index_offset[0]; + pp->second_chroma_qp_index_offset = h->pps.chroma_qp_index_offset[1]; + pp->ContinuationFlag = 1; + pp->pic_init_qp_minus26 = h->pps.init_qp - 26; + pp->num_ref_idx_l0_active_minus1 = h->pps.ref_count[0] - 1; + pp->num_ref_idx_l1_active_minus1 = h->pps.ref_count[1] - 1; + pp->Reserved8BitsA = 0; + pp->frame_num = h->frame_num; + pp->log2_max_frame_num_minus4 = h->sps.log2_max_frame_num - 4; + pp->pic_order_cnt_type = h->sps.poc_type; + if (h->sps.poc_type == 0) + pp->log2_max_pic_order_cnt_lsb_minus4 = h->sps.log2_max_poc_lsb - 4; + else if (h->sps.poc_type == 1) + pp->delta_pic_order_always_zero_flag = h->sps.delta_pic_order_always_zero_flag; + pp->direct_8x8_inference_flag = h->sps.direct_8x8_inference_flag; + pp->entropy_coding_mode_flag = h->pps.cabac; + pp->pic_order_present_flag = h->pps.pic_order_present; + pp->num_slice_groups_minus1 = h->pps.slice_group_count - 1; + pp->slice_group_map_type = h->pps.mb_slice_group_map_type; + 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 FFmpeg */ + //pp->SliceGroupMap[810]; /* XXX not implemented by FFmpeg */ +} + +static void fill_scaling_lists(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]]; + + 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]]; +} + +static int is_slice_short(struct dxva_context *ctx) +{ + assert(ctx->cfg->ConfigBitstreamRaw == 1 || + ctx->cfg->ConfigBitstreamRaw == 2); + return ctx->cfg->ConfigBitstreamRaw == 2; +} + +static void fill_slice_short(DXVA_Slice_H264_Short *slice, + unsigned position, unsigned size) +{ + memset(slice, 0, sizeof(*slice)); + slice->BSNALunitDataLocation = position; + slice->SliceBytesInBuffer = size; + slice->wBadSliceChopping = 0; +} + +static void fill_slice_long(AVCodecContext *avctx, DXVA_Slice_H264_Long *slice, + unsigned position, unsigned size) +{ + const H264Context *h = avctx->priv_data; + struct dxva_context *ctx = avctx->hwaccel_context; + const MpegEncContext *s = &h->s; + unsigned list; + + memset(slice, 0, sizeof(*slice)); + slice->BSNALunitDataLocation = position; + slice->SliceBytesInBuffer = size; + slice->wBadSliceChopping = 0; + + slice->first_mb_in_slice = (s->mb_y >> FIELD_OR_MBAFF_PICTURE) * s->mb_width + s->mb_x; + slice->NumMbsForSlice = 0; /* XXX it is set once we have all slices */ + slice->BitOffsetToSliceData = get_bits_count(&s->gb) + 8; + slice->slice_type = ff_h264_get_slice_type(h); + if (h->slice_type_fixed) + slice->slice_type += 5; + slice->luma_log2_weight_denom = h->luma_log2_weight_denom; + slice->chroma_log2_weight_denom = h->chroma_log2_weight_denom; + if (h->list_count > 0) + slice->num_ref_idx_l0_active_minus1 = h->ref_count[0] - 1; + if (h->list_count > 1) + slice->num_ref_idx_l1_active_minus1 = h->ref_count[1] - 1; + slice->slice_alpha_c0_offset_div2 = h->slice_alpha_c0_offset / 2 - 26; + slice->slice_beta_offset_div2 = h->slice_beta_offset / 2 - 26; + slice->Reserved8Bits = 0; + + for (list = 0; list < 2; list++) { + unsigned i; + for (i = 0; i < FF_ARRAY_ELEMS(slice->RefPicList[list]); i++) { + if (list < h->list_count && i < h->ref_count[list]) { + const Picture *r = &h->ref_list[list][i]; + unsigned plane; + fill_picture_entry(&slice->RefPicList[list][i], + ff_dxva2_get_surface_index(ctx, r), + r->reference == PICT_BOTTOM_FIELD); + for (plane = 0; plane < 3; plane++) { + int w, o; + if (plane == 0 && h->luma_weight_flag[list]) { + w = h->luma_weight[i][list][0]; + o = h->luma_weight[i][list][1]; + } else if (plane >= 1 && h->chroma_weight_flag[list]) { + w = h->chroma_weight[i][list][plane-1][0]; + o = h->chroma_weight[i][list][plane-1][1]; + } else { + w = 1 << (plane == 0 ? h->luma_log2_weight_denom : + h->chroma_log2_weight_denom); + o = 0; + } + slice->Weights[list][i][plane][0] = w; + slice->Weights[list][i][plane][1] = o; + } + } else { + unsigned plane; + slice->RefPicList[list][i].bPicEntry = 0xff; + for (plane = 0; plane < 3; plane++) { + slice->Weights[list][i][plane][0] = 0; + slice->Weights[list][i][plane][1] = 0; + } + } + } + } + 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 == FF_B_TYPE) + slice->direct_spatial_mv_pred_flag = h->direct_spatial_mv_pred; + slice->cabac_init_idc = h->pps.cabac ? h->cabac_init_idc : 0; + if (h->deblocking_filter < 2) + slice->disable_deblocking_filter_idc = 1 - h->deblocking_filter; + else + slice->disable_deblocking_filter_idc = h->deblocking_filter; + slice->slice_id = h->current_slice - 1; +} + +static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, + DXVA2_DecodeBufferDesc *bs, + DXVA2_DecodeBufferDesc *sc) +{ + const H264Context *h = avctx->priv_data; + const MpegEncContext *s = &h->s; + 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; + DXVA_Slice_H264_Short *slice = NULL; + uint8_t *dxva_data, *current, *end; + unsigned dxva_size; + void *slice_data; + unsigned slice_size; + unsigned padding; + unsigned i; + + /* Create an annex B bitstream buffer with only slice NAL and finalize slice */ + if (FAILED(IDirectXVideoDecoder_GetBuffer(ctx->decoder, + DXVA2_BitStreamDateBufferType, + &dxva_data, &dxva_size))) + return -1; + current = dxva_data; + end = dxva_data + dxva_size; + + for (i = 0; i < ctx_pic->slice_count; i++) { + static const uint8_t start_code[] = { 0, 0, 1 }; + static const unsigned start_code_size = sizeof(start_code); + unsigned position, size; + + assert(offsetof(DXVA_Slice_H264_Short, BSNALunitDataLocation) == + offsetof(DXVA_Slice_H264_Long, BSNALunitDataLocation)); + assert(offsetof(DXVA_Slice_H264_Short, SliceBytesInBuffer) == + offsetof(DXVA_Slice_H264_Long, SliceBytesInBuffer)); + + if (is_slice_short(ctx)) + slice = &ctx_pic->slice_short[i]; + else + slice = (DXVA_Slice_H264_Short*)&ctx_pic->slice_long[i]; + + position = slice->BSNALunitDataLocation; + size = slice->SliceBytesInBuffer; + if (start_code_size + size > end - current) { + av_log(avctx, AV_LOG_ERROR, "Failed to build bitstream"); + break; + } + + slice->BSNALunitDataLocation = current - dxva_data; + slice->SliceBytesInBuffer = start_code_size + size; + + if (!is_slice_short(ctx)) { + DXVA_Slice_H264_Long *slice_long = (DXVA_Slice_H264_Long*)slice; + if (i < ctx_pic->slice_count - 1) + slice_long->NumMbsForSlice = + slice_long[1].first_mb_in_slice - slice_long[0].first_mb_in_slice; + else + slice_long->NumMbsForSlice = mb_count - slice_long->first_mb_in_slice; + } + + memcpy(current, start_code, start_code_size); + current += start_code_size; + + memcpy(current, &ctx_pic->bitstream[position], size); + current += size; + } + padding = FFMIN(128 - ((current - dxva_data) & 127), end - current); + if (slice && padding > 0) { + memset(current, 0, padding); + current += padding; + + slice->SliceBytesInBuffer += padding; + } + if (FAILED(IDirectXVideoDecoder_ReleaseBuffer(ctx->decoder, + DXVA2_BitStreamDateBufferType))) + return -1; + if (i < ctx_pic->slice_count) + return -1; + + memset(bs, 0, sizeof(*bs)); + bs->CompressedBufferType = DXVA2_BitStreamDateBufferType; + bs->DataSize = current - dxva_data; + bs->NumMBsInBuffer = mb_count; + + if (is_slice_short(ctx)) { + slice_data = ctx_pic->slice_short; + slice_size = ctx_pic->slice_count * sizeof(*ctx_pic->slice_short); + } else { + slice_data = ctx_pic->slice_long; + slice_size = ctx_pic->slice_count * sizeof(*ctx_pic->slice_long); + } + assert((bs->DataSize & 127) == 0); + return ff_dxva2_commit_buffer(avctx, ctx, sc, + DXVA2_SliceControlBufferType, + slice_data, slice_size, mb_count); +} + + +static int start_frame(AVCodecContext *avctx, + av_unused const uint8_t *buffer, + av_unused uint32_t size) +{ + 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; + + if (!ctx->decoder || !ctx->cfg || ctx->surface_count <= 0) + return -1; + assert(ctx_pic); + + /* Fill up DXVA_PicParams_H264 */ + fill_picture_parameters(ctx, h, &ctx_pic->pp); + + /* Fill up DXVA_Qmatrix_H264 */ + fill_scaling_lists(h, &ctx_pic->qm); + + ctx_pic->slice_count = 0; + ctx_pic->bitstream_size = 0; + ctx_pic->bitstream = NULL; + return 0; +} + +static int decode_slice(AVCodecContext *avctx, + const uint8_t *buffer, uint32_t size) +{ + 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; + unsigned position; + + if (ctx_pic->slice_count >= MAX_SLICES) + return -1; + + if (!ctx_pic->bitstream) + ctx_pic->bitstream = buffer; + ctx_pic->bitstream_size += size; + + position = buffer - ctx_pic->bitstream; + if (is_slice_short(ctx)) + fill_slice_short(&ctx_pic->slice_short[ctx_pic->slice_count], + position, size); + else + fill_slice_long(avctx, &ctx_pic->slice_long[ctx_pic->slice_count], + position, size); + ctx_pic->slice_count++; + + if (h->slice_type != FF_I_TYPE && h->slice_type != FF_SI_TYPE) + ctx_pic->pp.wBitFields &= ~(1 << 15); /* Set IntraPicFlag to 0 */ + return 0; +} + +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; + + if (ctx_pic->slice_count <= 0 || ctx_pic->bitstream_size <= 0) + return -1; + return ff_dxva2_common_end_frame(avctx, s, + &ctx_pic->pp, sizeof(ctx_pic->pp), + &ctx_pic->qm, sizeof(ctx_pic->qm), + commit_bitstream_and_slice_buffer); +} + +AVHWAccel h264_dxva2_hwaccel = { + .name = "h264_dxva2", + .type = AVMEDIA_TYPE_VIDEO, + .id = CODEC_ID_H264, + .pix_fmt = PIX_FMT_DXVA2_VLD, + .capabilities = 0, + .start_frame = start_frame, + .decode_slice = decode_slice, + .end_frame = end_frame, + .priv_data_size = sizeof(struct dxva2_picture_context), +}; + diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dxva2_internal.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/dxva2_internal.h new file mode 100644 index 0000000000..a9be7a07e7 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dxva2_internal.h @@ -0,0 +1,48 @@ +/* + * DXVA2 HW acceleration + * + * copyright (c) 2010 Laurent Aimar + * + * 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_DXVA_INTERNAL_H +#define AVCODEC_DXVA_INTERNAL_H + +#include "dxva2.h" +#include "avcodec.h" +#include "mpegvideo.h" + +void *ff_dxva2_get_surface(const Picture *picture); + +unsigned ff_dxva2_get_surface_index(const struct dxva_context *, + const Picture *picture); + +int ff_dxva2_commit_buffer(AVCodecContext *, struct dxva_context *, + DXVA2_DecodeBufferDesc *, + unsigned type, const void *data, unsigned size, + unsigned mb_count); + + +int ff_dxva2_common_end_frame(AVCodecContext *, MpegEncContext *, + const void *pp, unsigned pp_size, + const void *qm, unsigned qm_size, + int (*commit_bs_si)(AVCodecContext *, + DXVA2_DecodeBufferDesc *bs, + DXVA2_DecodeBufferDesc *slice)); + +#endif /* AVCODEC_DXVA_INTERNAL_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/dxva2_vc1.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/dxva2_vc1.c new file mode 100644 index 0000000000..a11121347a --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/dxva2_vc1.c @@ -0,0 +1,291 @@ +/* + * DXVA2 WMV3/VC-1 HW acceleration. + * + * copyright (c) 2010 Laurent Aimar + * + * 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 "dxva2_internal.h" +#include "vc1.h" +#include "vc1data.h" + +struct dxva2_picture_context { + DXVA_PictureParameters pp; + DXVA_SliceInfo si; + + const uint8_t *bitstream; + unsigned bitstream_size; +}; + +static void fill_picture_parameters(AVCodecContext *avctx, + struct dxva_context *ctx, const VC1Context *v, + DXVA_PictureParameters *pp) +{ + const MpegEncContext *s = &v->s; + const Picture *current_picture = s->current_picture_ptr; + + memset(pp, 0, sizeof(*pp)); + pp->wDecodedPictureIndex = + pp->wDeblockedPictureIndex = ff_dxva2_get_surface_index(ctx, current_picture); + if (s->pict_type != FF_I_TYPE) + pp->wForwardRefPictureIndex = ff_dxva2_get_surface_index(ctx, &s->last_picture); + else + pp->wForwardRefPictureIndex = 0xffff; + if (s->pict_type == FF_B_TYPE) + pp->wBackwardRefPictureIndex = ff_dxva2_get_surface_index(ctx, &s->next_picture); + else + pp->wBackwardRefPictureIndex = 0xffff; + if (v->profile == PROFILE_ADVANCED) { + /* It is the cropped width/height -1 of the frame */ + pp->wPicWidthInMBminus1 = avctx->width - 1; + pp->wPicHeightInMBminus1= avctx->height - 1; + } else { + /* It is the coded width/height in macroblock -1 of the frame */ + pp->wPicWidthInMBminus1 = s->mb_width - 1; + pp->wPicHeightInMBminus1= s->mb_height - 1; + } + pp->bMacroblockWidthMinus1 = 15; + pp->bMacroblockHeightMinus1 = 15; + pp->bBlockWidthMinus1 = 7; + pp->bBlockHeightMinus1 = 7; + pp->bBPPminus1 = 7; + if (s->picture_structure & PICT_TOP_FIELD) + pp->bPicStructure |= 0x01; + if (s->picture_structure & PICT_BOTTOM_FIELD) + pp->bPicStructure |= 0x02; + pp->bSecondField = v->interlace && v->fcm != 0x03 && !s->first_field; + pp->bPicIntra = s->pict_type == FF_I_TYPE; + pp->bPicBackwardPrediction = s->pict_type == FF_B_TYPE; + pp->bBidirectionalAveragingMode = (1 << 7) | + ((ctx->cfg->ConfigIntraResidUnsigned != 0) << 6) | + ((ctx->cfg->ConfigResidDiffAccelerator != 0) << 5) | + ((v->lumscale != 32 || v->lumshift != 0) << 4) | + ((v->profile == PROFILE_ADVANCED) << 3); + pp->bMVprecisionAndChromaRelation = ((v->mv_mode == MV_PMODE_1MV_HPEL_BILIN) << 3) | + (1 << 2) | + (0 << 1) | + (!s->quarter_sample ); + pp->bChromaFormat = v->chromaformat; + ctx->report_id++; + if (ctx->report_id >= (1 << 16)) + ctx->report_id = 1; + pp->bPicScanFixed = ctx->report_id >> 8; + pp->bPicScanMethod = ctx->report_id & 0xff; + pp->bPicReadbackRequests = 0; + pp->bRcontrol = v->rnd; + pp->bPicSpatialResid8 = (v->panscanflag << 7) | + (v->refdist_flag << 6) | + (s->loop_filter << 5) | + (v->fastuvmc << 4) | + (v->extended_mv << 3) | + (v->dquant << 1) | + (v->vstransform ); + pp->bPicOverflowBlocks = (v->quantizer_mode << 6) | + (v->multires << 5) | + (s->resync_marker << 4) | + (v->rangered << 3) | + (s->max_b_frames ); + pp->bPicExtrapolation = (!v->interlace || v->fcm == 0x00) ? 1 : 2; + pp->bPicDeblocked = ((v->profile != PROFILE_ADVANCED && v->rangeredfrm) << 5) | + (s->loop_filter << 1); + pp->bPicDeblockConfined = (v->postprocflag << 7) | + (v->broadcast << 6) | + (v->interlace << 5) | + (v->tfcntrflag << 4) | + (v->finterpflag << 3) | + ((s->pict_type != FF_B_TYPE) << 2) | + (v->psf << 1) | + (v->extended_dmv ); + if (s->pict_type != FF_I_TYPE) + pp->bPic4MVallowed = v->mv_mode == MV_PMODE_MIXED_MV || + (v->mv_mode == MV_PMODE_INTENSITY_COMP && + v->mv_mode2 == MV_PMODE_MIXED_MV); + if (v->profile == PROFILE_ADVANCED) + pp->bPicOBMC = (v->range_mapy_flag << 7) | + (v->range_mapy << 4) | + (v->range_mapuv_flag << 3) | + (v->range_mapuv ); + pp->bPicBinPB = 0; + pp->bMV_RPS = 0; + pp->bReservedBits = 0; + if (s->picture_structure == PICT_FRAME) { + pp->wBitstreamFcodes = v->lumscale; + pp->wBitstreamPCEelements = v->lumshift; + } else { + /* Syntax: (top_field_param << 8) | bottom_field_param */ + pp->wBitstreamFcodes = (v->lumscale << 8) | v->lumscale; + pp->wBitstreamPCEelements = (v->lumshift << 8) | v->lumshift; + } + pp->bBitstreamConcealmentNeed = 0; + pp->bBitstreamConcealmentMethod = 0; +} + +static void fill_slice(AVCodecContext *avctx, DXVA_SliceInfo *slice, + unsigned position, unsigned size) +{ + const VC1Context *v = avctx->priv_data; + const MpegEncContext *s = &v->s; + + memset(slice, 0, sizeof(*slice)); + slice->wHorizontalPosition = 0; + slice->wVerticalPosition = s->mb_y; + slice->dwSliceBitsInBuffer = 8 * size; + slice->dwSliceDataLocation = position; + slice->bStartCodeBitOffset = 0; + slice->bReservedBits = 0; + slice->wMBbitOffset = get_bits_count(&s->gb); + slice->wNumberMBsInSlice = s->mb_width * s->mb_height; /* XXX We assume 1 slice */ + slice->wQuantizerScaleCode = v->pq; + slice->wBadSliceChopping = 0; +} + +static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, + DXVA2_DecodeBufferDesc *bs, + DXVA2_DecodeBufferDesc *sc) +{ + 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; + + DXVA_SliceInfo *slice = &ctx_pic->si; + + static const uint8_t start_code[] = { 0, 0, 1, 0x0d }; + const unsigned start_code_size = avctx->codec_id == CODEC_ID_VC1 ? sizeof(start_code) : 0; + const unsigned slice_size = slice->dwSliceBitsInBuffer / 8; + const unsigned padding = 128 - ((start_code_size + slice_size) & 127); + const unsigned data_size = start_code_size + slice_size + padding; + + uint8_t *dxva_data; + unsigned dxva_size; + int result; + + if (FAILED(IDirectXVideoDecoder_GetBuffer(ctx->decoder, + DXVA2_BitStreamDateBufferType, + &dxva_data, &dxva_size))) + return -1; + + result = data_size <= dxva_size ? 0 : -1; + if (!result) { + if (start_code_size > 0) + memcpy(dxva_data, start_code, start_code_size); + memcpy(dxva_data + start_code_size, + ctx_pic->bitstream + slice->dwSliceDataLocation, slice_size); + if (padding > 0) + memset(dxva_data + start_code_size + slice_size, 0, padding); + slice->dwSliceBitsInBuffer = 8 * data_size; + } + if (FAILED(IDirectXVideoDecoder_ReleaseBuffer(ctx->decoder, + DXVA2_BitStreamDateBufferType))) + return -1; + if (result) + return result; + + memset(bs, 0, sizeof(*bs)); + bs->CompressedBufferType = DXVA2_BitStreamDateBufferType; + bs->DataSize = data_size; + bs->NumMBsInBuffer = s->mb_width * s->mb_height; + assert((bs->DataSize & 127) == 0); + + return ff_dxva2_commit_buffer(avctx, ctx, sc, + DXVA2_SliceControlBufferType, + slice, sizeof(*slice), bs->NumMBsInBuffer); +} + +static int start_frame(AVCodecContext *avctx, + av_unused const uint8_t *buffer, + av_unused uint32_t size) +{ + 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; + + if (!ctx->decoder || !ctx->cfg || ctx->surface_count <= 0) + return -1; + assert(ctx_pic); + + fill_picture_parameters(avctx, ctx, v, &ctx_pic->pp); + + ctx_pic->bitstream_size = 0; + ctx_pic->bitstream = NULL; + return 0; +} + +static int decode_slice(AVCodecContext *avctx, + const uint8_t *buffer, uint32_t size) +{ + 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; + + if (ctx_pic->bitstream_size > 0) + return -1; + + if (avctx->codec_id == CODEC_ID_VC1 && + size >= 4 && IS_MARKER(AV_RB32(buffer))) { + buffer += 4; + size -= 4; + } + + ctx_pic->bitstream_size = size; + ctx_pic->bitstream = buffer; + + fill_slice(avctx, &ctx_pic->si, 0, size); + return 0; +} + +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; + + if (ctx_pic->bitstream_size <= 0) + return -1; + + return ff_dxva2_common_end_frame(avctx, &v->s, + &ctx_pic->pp, sizeof(ctx_pic->pp), + NULL, 0, + commit_bitstream_and_slice_buffer); +} + +#if CONFIG_WMV3_DXVA2_HWACCEL +AVHWAccel wmv3_dxva2_hwaccel = { + .name = "wmv3_dxva2", + .type = AVMEDIA_TYPE_VIDEO, + .id = CODEC_ID_WMV3, + .pix_fmt = PIX_FMT_DXVA2_VLD, + .capabilities = 0, + .start_frame = start_frame, + .decode_slice = decode_slice, + .end_frame = end_frame, + .priv_data_size = sizeof(struct dxva2_picture_context), +}; +#endif + +AVHWAccel vc1_dxva2_hwaccel = { + .name = "vc1_dxva2", + .type = AVMEDIA_TYPE_VIDEO, + .id = CODEC_ID_VC1, + .pix_fmt = PIX_FMT_DXVA2_VLD, + .capabilities = 0, + .start_frame = start_frame, + .decode_slice = decode_slice, + .end_frame = end_frame, + .priv_data_size = sizeof(struct dxva2_picture_context), +}; + diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/eac3dec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/eac3dec.c index 3784ccfb1d..52d15c83f8 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/eac3dec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/eac3dec.c @@ -23,10 +23,6 @@ /* * There are several features of E-AC-3 that this decoder does not yet support. * - * Spectral Extension - * There is a patch to get this working for the two samples we have that - * use it, but it needs some minor changes in order to be accepted. - * * Enhanced Coupling * No known samples exist. If any ever surface, this feature should not be * too difficult to implement. @@ -67,6 +63,95 @@ typedef enum { #define EAC3_SR_CODE_REDUCED 3 +void ff_eac3_apply_spectral_extension(AC3DecodeContext *s) +{ + int bin, bnd, ch, i; + uint8_t wrapflag[SPX_MAX_BANDS]={1,0,}, num_copy_sections, copy_sizes[SPX_MAX_BANDS]; + float rms_energy[SPX_MAX_BANDS]; + + /* Set copy index mapping table. Set wrap flags to apply a notch filter at + wrap points later on. */ + bin = s->spx_dst_start_freq; + num_copy_sections = 0; + for (bnd = 0; bnd < s->num_spx_bands; bnd++) { + int copysize; + int bandsize = s->spx_band_sizes[bnd]; + if (bin + bandsize > s->spx_src_start_freq) { + copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq; + bin = s->spx_dst_start_freq; + wrapflag[bnd] = 1; + } + for (i = 0; i < bandsize; i += copysize) { + if (bin == s->spx_src_start_freq) { + copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq; + bin = s->spx_dst_start_freq; + } + copysize = FFMIN(bandsize - i, s->spx_src_start_freq - bin); + bin += copysize; + } + } + copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq; + + for (ch = 1; ch <= s->fbw_channels; ch++) { + if (!s->channel_uses_spx[ch]) + continue; + + /* Copy coeffs from normal bands to extension bands */ + bin = s->spx_src_start_freq; + for (i = 0; i < num_copy_sections; i++) { + memcpy(&s->transform_coeffs[ch][bin], + &s->transform_coeffs[ch][s->spx_dst_start_freq], + copy_sizes[i]*sizeof(float)); + bin += copy_sizes[i]; + } + + /* Calculate RMS energy for each SPX band. */ + bin = s->spx_src_start_freq; + for (bnd = 0; bnd < s->num_spx_bands; bnd++) { + int bandsize = s->spx_band_sizes[bnd]; + float accum = 0.0f; + for (i = 0; i < bandsize; i++) { + float coeff = s->transform_coeffs[ch][bin++]; + accum += coeff * coeff; + } + rms_energy[bnd] = sqrtf(accum / bandsize); + } + + /* Apply a notch filter at transitions between normal and extension + bands and at all wrap points. */ + if (s->spx_atten_code[ch] >= 0) { + const float *atten_tab = ff_eac3_spx_atten_tab[s->spx_atten_code[ch]]; + bin = s->spx_src_start_freq - 2; + for (bnd = 0; bnd < s->num_spx_bands; bnd++) { + if (wrapflag[bnd]) { + float *coeffs = &s->transform_coeffs[ch][bin]; + coeffs[0] *= atten_tab[0]; + coeffs[1] *= atten_tab[1]; + coeffs[2] *= atten_tab[2]; + coeffs[3] *= atten_tab[1]; + coeffs[4] *= atten_tab[0]; + } + bin += s->spx_band_sizes[bnd]; + } + } + + /* Apply noise-blended coefficient scaling based on previously + calculated RMS energy, blending factors, and SPX coordinates for + each band. */ + bin = s->spx_src_start_freq; + for (bnd = 0; bnd < s->num_spx_bands; bnd++) { + float nscale = s->spx_noise_blend[ch][bnd] * rms_energy[bnd] * (1.0f/(1<<31)); + float sscale = s->spx_signal_blend[ch][bnd]; + for (i = 0; i < s->spx_band_sizes[bnd]; i++) { + float noise = nscale * (int32_t)av_lfg_get(&s->dith_state); + s->transform_coeffs[ch][bin] *= sscale; + s->transform_coeffs[ch][bin++] += noise; + } + } + } +} + + /** lrint(M_SQRT2*cos(2*M_PI/12)*(1<<23)) */ #define COEFF_0 10273905LL @@ -492,12 +577,11 @@ int ff_eac3_parse_header(AC3DecodeContext *s) } /* spectral extension attenuation data */ - if (parse_spx_atten_data) { - av_log_missing_feature(s->avctx, "Spectral extension attenuation", 1); - for (ch = 1; ch <= s->fbw_channels; ch++) { - if (get_bits1(gbc)) { // channel has spx attenuation - skip_bits(gbc, 5); // skip spx attenuation code - } + for (ch = 1; ch <= s->fbw_channels; ch++) { + if (parse_spx_atten_data && get_bits1(gbc)) { + s->spx_atten_code[ch] = get_bits(gbc, 5); + } else { + s->spx_atten_code[ch] = -1; } } @@ -514,6 +598,7 @@ int ff_eac3_parse_header(AC3DecodeContext *s) /* syntax state initialization */ for (ch = 1; ch <= s->fbw_channels; ch++) { + s->first_spx_coords[ch] = 1; s->first_cpl_coords[ch] = 1; } s->first_cpl_leak = 1; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/eac3dec_data.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/eac3dec_data.c index 6c6a551804..031702e9e9 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/eac3dec_data.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/eac3dec_data.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/eac3dec_data.c + * @file * Tables taken directly from the E-AC-3 spec. */ @@ -1093,3 +1093,42 @@ const uint8_t ff_eac3_frm_expstr[32][6] = { { EXP_D45, EXP_D45, EXP_D45, EXP_D45, EXP_D25, EXP_REUSE}, { EXP_D45, EXP_D45, EXP_D45, EXP_D45, EXP_D45, EXP_D45}, }; + +/** + * Table E.25: Spectral Extension Attenuation Table + * ff_eac3_spx_atten_tab[code][bin]=pow(2.0,(bin+1)*(code+1)/-15.0); + */ +const float ff_eac3_spx_atten_tab[32][3] = { + { 0.954841603910416503f, 0.911722488558216804f, 0.870550563296124125f }, + { 0.911722488558216804f, 0.831237896142787758f, 0.757858283255198995f }, + { 0.870550563296124125f, 0.757858283255198995f, 0.659753955386447100f }, + { 0.831237896142787758f, 0.690956439983888004f, 0.574349177498517438f }, + { 0.793700525984099792f, 0.629960524947436595f, 0.500000000000000000f }, + { 0.757858283255198995f, 0.574349177498517438f, 0.435275281648062062f }, + { 0.723634618720189082f, 0.523647061410313364f, 0.378929141627599553f }, + { 0.690956439983888004f, 0.477420801955208307f, 0.329876977693223550f }, + { 0.659753955386447100f, 0.435275281648062062f, 0.287174588749258719f }, + { 0.629960524947436595f, 0.396850262992049896f, 0.250000000000000000f }, + { 0.601512518041058319f, 0.361817309360094541f, 0.217637640824031003f }, + { 0.574349177498517438f, 0.329876977693223550f, 0.189464570813799776f }, + { 0.548412489847312945f, 0.300756259020529160f, 0.164938488846611775f }, + { 0.523647061410313364f, 0.274206244923656473f, 0.143587294374629387f }, + { 0.500000000000000000f, 0.250000000000000000f, 0.125000000000000000f }, + { 0.477420801955208307f, 0.227930622139554201f, 0.108818820412015502f }, + { 0.455861244279108402f, 0.207809474035696939f, 0.094732285406899888f }, + { 0.435275281648062062f, 0.189464570813799776f, 0.082469244423305887f }, + { 0.415618948071393879f, 0.172739109995972029f, 0.071793647187314694f }, + { 0.396850262992049896f, 0.157490131236859149f, 0.062500000000000000f }, + { 0.378929141627599553f, 0.143587294374629387f, 0.054409410206007751f }, + { 0.361817309360094541f, 0.130911765352578369f, 0.047366142703449930f }, + { 0.345478219991944002f, 0.119355200488802049f, 0.041234622211652958f }, + { 0.329876977693223550f, 0.108818820412015502f, 0.035896823593657347f }, + { 0.314980262473718298f, 0.099212565748012460f, 0.031250000000000000f }, + { 0.300756259020529160f, 0.090454327340023621f, 0.027204705103003875f }, + { 0.287174588749258719f, 0.082469244423305887f, 0.023683071351724965f }, + { 0.274206244923656473f, 0.075189064755132290f, 0.020617311105826479f }, + { 0.261823530705156682f, 0.068551561230914118f, 0.017948411796828673f }, + { 0.250000000000000000f, 0.062500000000000000f, 0.015625000000000000f }, + { 0.238710400977604098f, 0.056982655534888536f, 0.013602352551501938f }, + { 0.227930622139554201f, 0.051952368508924235f, 0.011841535675862483f } +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/eac3dec_data.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/eac3dec_data.h index 76dd154568..133183398f 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/eac3dec_data.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/eac3dec_data.h @@ -31,5 +31,6 @@ extern const int16_t ff_eac3_gaq_remap_2_4_b[9][2]; 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 */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/eacmv.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/eacmv.c index 3de08cc1a0..517b307271 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/eacmv.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/eacmv.c @@ -20,9 +20,9 @@ */ /** - * @file libavcodec/eacmv.c + * @file * Electronic Arts CMV Video Decoder - * by Peter Ross (suxen_drol at hotmail dot com) + * by Peter Ross (pross@xvid.org) * * Technical details here: * http://wiki.multimedia.cx/index.php?title=Electronic_Arts_CMV @@ -205,7 +205,7 @@ static av_cold int cmv_decode_end(AVCodecContext *avctx){ AVCodec eacmv_decoder = { "eacmv", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_CMV, sizeof(CmvContext), cmv_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/eaidct.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/eaidct.c index 9e7bcac3e8..9972e422ed 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/eaidct.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/eaidct.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/eaidct.c + * @file * Electronic Arts TGQ/TQI/MAD IDCT algorithm * @author Peter Ross */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/eamad.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/eamad.c index 7555e4a6a6..8fc5ef1362 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/eamad.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/eamad.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/eamad.c + * @file * Electronic Arts Madcow Video Decoder * by Peter Ross * @@ -46,7 +46,7 @@ typedef struct MadContext { AVFrame last_frame; void *bitstream_buf; unsigned int bitstream_buf_size; - DECLARE_ALIGNED_16(DCTELEM, block[64]); + DECLARE_ALIGNED(16, DCTELEM, block)[64]; } MadContext; static void bswap16_buf(uint16_t *dst, const uint16_t *src, int count) @@ -307,7 +307,7 @@ static av_cold int decode_end(AVCodecContext *avctx) AVCodec eamad_decoder = { "eamad", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_MAD, sizeof(MadContext), decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/eatgq.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/eatgq.c index 3c8be15911..7a985050c5 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/eatgq.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/eatgq.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/eatgq.c + * @file * Electronic Arts TGQ Video Decoder * @author Peter Ross * @@ -42,7 +42,7 @@ typedef struct TgqContext { int width,height; ScanTable scantable; int qtable[64]; - DECLARE_ALIGNED_16(DCTELEM, block[6][64]); + DECLARE_ALIGNED(16, DCTELEM, block)[6][64]; } TgqContext; static av_cold int tgq_decode_init(AVCodecContext *avctx){ @@ -245,7 +245,7 @@ static av_cold int tgq_decode_end(AVCodecContext *avctx){ AVCodec eatgq_decoder = { "eatgq", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_TGQ, sizeof(TgqContext), tgq_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/eatgv.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/eatgv.c index f2fa2fa982..8c6a654fad 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/eatgv.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/eatgv.c @@ -20,9 +20,9 @@ */ /** - * @file libavcodec/eatgv.c + * @file * Electronic Arts TGV Video Decoder - * by Peter Ross (suxen_drol at hotmail dot com) + * by Peter Ross (pross@xvid.org) * * Technical details here: * http://wiki.multimedia.cx/index.php?title=Electronic_Arts_TGV @@ -192,6 +192,10 @@ static int tgv_decode_inter(TgvContext * s, const uint8_t *buf, const uint8_t *b s->block_codebook[i][15-j] = tmp[get_bits(&gb, 2)]; } + if (get_bits_left(&gb) < vector_bits * + (s->avctx->height/4) * (s->avctx->width/4)) + return -1; + /* read vectors and build frame */ for(y=0; yavctx->height/4; y++) for(x=0; xavctx->width/4; x++) { @@ -284,11 +288,11 @@ static int tgv_decode_frame(AVCodecContext *avctx, /* allocate additional 12 bytes to accomodate av_memcpy_backptr() OUTBUF_PADDED optimisation */ s->frame.data[0] = av_malloc(s->width*s->height + 12); if (!s->frame.data[0]) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); s->frame.data[1] = av_malloc(AVPALETTE_SIZE); if (!s->frame.data[1]) { av_freep(&s->frame.data[0]); - return AVERROR_NOMEM; + return AVERROR(ENOMEM); } } memcpy(s->frame.data[1], s->palette, AVPALETTE_SIZE); @@ -331,7 +335,7 @@ static av_cold int tgv_decode_end(AVCodecContext *avctx) AVCodec eatgv_decoder = { "eatgv", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_TGV, sizeof(TgvContext), tgv_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/eatqi.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/eatqi.c index c1c98dfeb3..7f1901d309 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/eatqi.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/eatqi.c @@ -20,7 +20,7 @@ */ /** - * @file eatqi.c + * @file * Electronic Arts TQI Video Decoder * by Peter Ross * @@ -40,7 +40,7 @@ typedef struct TqiContext { AVFrame frame; void *bitstream_buf; unsigned int bitstream_buf_size; - DECLARE_ALIGNED_16(DCTELEM, block[6][64]); + DECLARE_ALIGNED(16, DCTELEM, block)[6][64]; } TqiContext; static av_cold int tqi_decode_init(AVCodecContext *avctx) @@ -156,7 +156,7 @@ static av_cold int tqi_decode_end(AVCodecContext *avctx) AVCodec eatqi_decoder = { "eatqi", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_TQI, sizeof(TqiContext), tqi_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/elbg.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/elbg.c index 85319db78e..d6a4ce7658 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/elbg.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/elbg.c @@ -19,7 +19,7 @@ */ /** - * @file libavcodec/elbg.c + * @file * Codebook Generator using the ELBG algorithm */ @@ -355,6 +355,7 @@ void ff_do_elbg(int *points, int dim, int numpoints, int *codebook, int *size_part = av_malloc(numCB*sizeof(int)); cell *list_buffer = av_malloc(numpoints*sizeof(cell)); cell *free_cells; + int best_dist, best_idx = 0; elbg->error = INT_MAX; elbg->dim = dim; @@ -380,14 +381,16 @@ void ff_do_elbg(int *points, int dim, int numpoints, int *codebook, /* This loop evaluate the actual Voronoi partition. It is the most costly part of the algorithm. */ for (i=0; i < numpoints; i++) { - dist_cb[i] = INT_MAX; + best_dist = distance_limited(elbg->points + i*elbg->dim, elbg->codebook + best_idx*elbg->dim, dim, INT_MAX); for (k=0; k < elbg->numCB; k++) { - dist = distance_limited(elbg->points + i*elbg->dim, elbg->codebook + k*elbg->dim, dim, dist_cb[i]); - if (dist < dist_cb[i]) { - dist_cb[i] = dist; - elbg->nearest_cb[i] = k; + dist = distance_limited(elbg->points + i*elbg->dim, elbg->codebook + k*elbg->dim, dim, best_dist); + if (dist < best_dist) { + best_dist = dist; + best_idx = k; } } + elbg->nearest_cb[i] = best_idx; + dist_cb[i] = best_dist; elbg->error += dist_cb[i]; elbg->utility[elbg->nearest_cb[i]] += dist_cb[i]; free_cells->index = i; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/error_resilience.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/error_resilience.c index a5cf9ad8a8..dc015b9f6a 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/error_resilience.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/error_resilience.c @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/error_resilience.c + * @file * Error resilience / concealment. */ @@ -30,13 +30,52 @@ #include "avcodec.h" #include "dsputil.h" #include "mpegvideo.h" +#include "h264.h" +#include "rectangle.h" -static void decode_mb(MpegEncContext *s){ +/* + * H264 redefines mb_intra so it is not mistakely used (its uninitialized in h264) + * but error concealment must support both h264 and h263 thus we must undo this + */ +#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 * 8 * s->uvlinesize) + s->mb_x * 8; - s->dest[2] = s->current_picture.data[2] + (s->mb_y * 8 * s->uvlinesize) + s->mb_x * 8; + 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); + if(CONFIG_H264_DECODER && s->codec_id == CODEC_ID_H264){ + H264Context *h= (void*)s; + h->mb_xy= s->mb_x + s->mb_y*s->mb_stride; + memset(h->non_zero_count_cache, 0, sizeof(h->non_zero_count_cache)); + 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(&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); + ff_h264_hl_decode_mb(h); + }else{ + assert(ref==0); MPV_decode_mb(s, s->block); + } +} + +/** + * @param stride the number of MVs to get to the next row + * @param mv_step the number of MVs per row or column in a macroblock + */ +static void set_mv_strides(MpegEncContext *s, int *mv_step, int *stride){ + if(s->codec_id == CODEC_ID_H264){ + H264Context *h= (void*)s; + assert(s->quarter_sample); + *mv_step= 4; + *stride= h->b_stride; + }else{ + *mv_step= 2; + *stride= s->b8_stride; + } } /** @@ -197,8 +236,11 @@ static void guess_dc(MpegEncContext *s, int16_t *dc, int w, int h, int stride, i * @param h height in 8 pixel blocks */ static void h_block_filter(MpegEncContext *s, uint8_t *dst, int w, int h, int stride, int is_luma){ - int b_x, b_y; + int b_x, b_y, mvx_stride, mvy_stride; uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; + set_mv_strides(s, &mvx_stride, &mvy_stride); + mvx_stride >>= is_luma; + mvy_stride *= mvx_stride; for(b_y=0; b_ycurrent_picture.motion_val[0][s->b8_stride*(b_y<<(1-is_luma)) + ( b_x <<(1-is_luma))]; - int16_t *right_mv= s->current_picture.motion_val[0][s->b8_stride*(b_y<<(1-is_luma)) + ((b_x+1)<<(1-is_luma))]; + 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)]; if(!(left_damage||right_damage)) continue; // both undamaged @@ -257,8 +299,11 @@ static void h_block_filter(MpegEncContext *s, uint8_t *dst, int w, int h, int st * @param h height in 8 pixel blocks */ static void v_block_filter(MpegEncContext *s, uint8_t *dst, int w, int h, int stride, int is_luma){ - int b_x, b_y; + int b_x, b_y, mvx_stride, mvy_stride; uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; + set_mv_strides(s, &mvx_stride, &mvy_stride); + mvx_stride >>= is_luma; + mvy_stride *= mvx_stride; for(b_y=0; b_ycurrent_picture.motion_val[0][s->b8_stride*( b_y <<(1-is_luma)) + (b_x<<(1-is_luma))]; - int16_t *bottom_mv= s->current_picture.motion_val[0][s->b8_stride*((b_y+1)<<(1-is_luma)) + (b_x<<(1-is_luma))]; + 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]; if(!(top_damage||bottom_damage)) continue; // both undamaged @@ -320,7 +365,9 @@ static void guess_mv(MpegEncContext *s){ const int mb_width = s->mb_width; const int mb_height= s->mb_height; int i, depth, num_avail; - int mb_x, mb_y; + int mb_x, mb_y, mot_step, mot_stride; + + set_mv_strides(s, &mot_step, &mot_stride); num_avail=0; for(i=0; imb_num; i++){ @@ -355,7 +402,7 @@ static void guess_mv(MpegEncContext *s){ s->mb_y= mb_y; s->mv[0][0][0]= 0; s->mv[0][0][1]= 0; - decode_mb(s); + decode_mb(s, 0); } } return; @@ -375,12 +422,12 @@ int score_sum=0; for(mb_x=0; mb_xmb_width; mb_x++){ const int mb_xy= mb_x + mb_y*s->mb_stride; int mv_predictor[8][2]={{0}}; + int ref[8]={0}; int pred_count=0; int j; int best_score=256*256*256*64; int best_pred=0; - const int mot_stride= s->b8_stride; - const int mot_index= mb_x*2 + mb_y*2*mot_stride; + const int mot_index= (mb_x + mb_y*mot_stride) * mot_step; int prev_x= s->current_picture.motion_val[0][mot_index][0]; int prev_y= s->current_picture.motion_val[0][mot_index][1]; @@ -407,62 +454,75 @@ 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 - 2][0]; - mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index - 2][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)]; pred_count++; } if(mb_x+1current_picture.motion_val[0][mot_index + 2][0]; - mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + 2][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)]; 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*2][0]; - mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index - mot_stride*2][1]; + 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)]; pred_count++; } if(mb_y+1current_picture.motion_val[0][mot_index + mot_stride*2][0]; - mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + mot_stride*2][1]; + 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)]; pred_count++; } if(pred_count==0) continue; if(pred_count>1){ - int sum_x=0, sum_y=0; - int max_x, max_y, min_x, min_y; + int sum_x=0, sum_y=0, sum_r=0; + int max_x, max_y, min_x, min_y, max_r, min_r; for(j=0; j=3){ - min_y= min_x= 99999; - max_y= max_x=-99999; + min_y= min_x= min_r= 99999; + max_y= max_x= max_r=-99999; }else{ - min_x=min_y=max_x=max_y=0; + min_x=min_y=max_x=max_y=min_r=max_r=0; } for(j=0; jcurrent_picture.motion_val[0][mot_index][0]; mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index][1]; + ref [pred_count] = s->current_picture.ref_index[0][4*mb_xy]; pred_count++; s->mv_dir = MV_DIR_FORWARD; @@ -489,7 +550,10 @@ int score_sum=0; 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]; - decode_mb(s); + if(ref[j]<0) //predictor intra or otherwise not available + continue; + + decode_mb(s, ref[j]); if(mb_x>0 && fixed[mb_xy-1]){ int k; @@ -518,11 +582,16 @@ int score_sum=0; } } score_sum+= best_score; -//FIXME no need to set s->current_picture.motion_val[0][mot_index][0] explicit - s->current_picture.motion_val[0][mot_index][0]= s->mv[0][0][0]= mv_predictor[best_pred][0]; - s->current_picture.motion_val[0][mot_index][1]= s->mv[0][0][1]= mv_predictor[best_pred][1]; + s->mv[0][0][0]= mv_predictor[best_pred][0]; + s->mv[0][0][1]= mv_predictor[best_pred][1]; - decode_mb(s); + for(i=0; icurrent_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]; + } + + decode_mb(s, ref[best_pred]); if(s->mv[0][0][0] != prev_x || s->mv[0][0][1] != prev_y){ @@ -561,6 +630,12 @@ static int is_intra_more_likely(MpegEncContext *s){ undamaged_count++; } + if(s->codec_id == CODEC_ID_H264){ + H264Context *h= (void*)s; + if(h->ref_count[0] <= 0 || !h->ref_list[0][0].data[0]) + return 1; + } + if(undamaged_count < 5) return 0; //almost all MBs damaged -> use temporal prediction //prevent dsp.sad() check, that requires access to the image @@ -685,13 +760,14 @@ void ff_er_frame_end(MpegEncContext *s){ if(!s->error_recognition || s->error_count==0 || s->avctx->lowres || s->avctx->hwaccel || s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU || + 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){ av_log(s->avctx, AV_LOG_ERROR, "Warning MVs not available\n"); for(i=0; i<2; i++){ - pic->ref_index[i]= av_mallocz(size * sizeof(uint8_t)); + pic->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; } @@ -699,11 +775,6 @@ void ff_er_frame_end(MpegEncContext *s){ s->current_picture= *s->current_picture_ptr; } - for(i=0; i<2; i++){ - if(pic->ref_index[i]) - memset(pic->ref_index[i], 0, size * sizeof(uint8_t)); - } - if(s->avctx->debug&FF_DEBUG_ER){ for(mb_y=0; mb_ymb_height; mb_y++){ for(mb_x=0; mb_xmb_width; mb_x++){ @@ -901,7 +972,7 @@ void ff_er_frame_end(MpegEncContext *s){ s->mb_x= mb_x; s->mb_y= mb_y; - decode_mb(s); + decode_mb(s, 0/*FIXME h264 partitioned slices need this set*/); } } @@ -943,7 +1014,7 @@ void ff_er_frame_end(MpegEncContext *s){ s->dsp.clear_blocks(s->block[0]); s->mb_x= mb_x; s->mb_y= mb_y; - decode_mb(s); + decode_mb(s, 0); } } }else diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/escape124.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/escape124.c index 80b1484b75..b51206a0b5 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/escape124.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/escape124.c @@ -374,7 +374,7 @@ static int escape124_decode_frame(AVCodecContext *avctx, AVCodec escape124_decoder = { "escape124", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_ESCAPE124, sizeof(Escape124Context), escape124_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/eval.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/eval.c index 1d52ba582b..ce4d0f515e 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/eval.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/eval.c @@ -1,6 +1,4 @@ /* - * simple arithmetic expression evaluator - * * Copyright (c) 2002-2006 Michael Niedermayer * Copyright (c) 2006 Oded Shimon * @@ -22,19 +20,13 @@ */ /** - * @file libavcodec/eval.c + * @file * simple arithmetic expression evaluator. * * see http://joe.hotchkiss.com/programming/eval/eval.html */ -#include -#include -#include -#include - -#include "libavutil/mathematics.h" -#include "avcodec.h" +#include "libavutil/avutil.h" #include "eval.h" typedef struct Parser{ @@ -42,10 +34,10 @@ typedef struct Parser{ char *s; const double *const_value; const char * const *const_name; // NULL terminated - double (**func1)(void *, double a); // NULL terminated - const char **func1_name; // NULL terminated - double (**func2)(void *, double a, double b); // NULL terminated - const char **func2_name; // NULL terminated + double (* const *func1)(void *, double a); // NULL terminated + const char * const *func1_name; // NULL terminated + double (* const *func2)(void *, double a, double b); // NULL terminated + const char * const *func2_name; // NULL terminated void *opaque; const char **error; #define VARS 10 @@ -115,7 +107,7 @@ static int strmatch(const char *s, const char *prefix){ return 1; } -struct ff_expr_s { +struct AVExpr { enum { e_value, e_const, e_func0, e_func1, e_func2, e_squish, e_gauss, e_ld, @@ -130,10 +122,10 @@ struct ff_expr_s { double (*func1)(void *, double); double (*func2)(void *, double, double); } a; - AVEvalExpr * param[2]; + struct AVExpr *param[2]; }; -static double eval_expr(Parser * p, AVEvalExpr * e) { +static double eval_expr(Parser * p, AVExpr * e) { switch (e->type) { case e_value: return e->value; case e_const: return e->value * p->const_value[e->a.const_index]; @@ -171,20 +163,23 @@ static double eval_expr(Parser * p, AVEvalExpr * e) { return NAN; } -static AVEvalExpr * parse_expr(Parser *p); +static AVExpr * parse_expr(Parser *p); -void ff_eval_free(AVEvalExpr * e) { +void ff_free_expr(AVExpr * e) { if (!e) return; - ff_eval_free(e->param[0]); - ff_eval_free(e->param[1]); + ff_free_expr(e->param[0]); + ff_free_expr(e->param[1]); av_freep(&e); } -static AVEvalExpr * parse_primary(Parser *p) { - AVEvalExpr * d = av_mallocz(sizeof(AVEvalExpr)); +static AVExpr * parse_primary(Parser *p) { + AVExpr * d = av_mallocz(sizeof(AVExpr)); char *next= p->s; int i; + if (!d) + return NULL; + /* number */ d->value = av_strtod(p->s, &next); if(next != p->s){ @@ -208,7 +203,7 @@ static AVEvalExpr * parse_primary(Parser *p) { if(p->s==NULL){ *p->error = "undefined constant or missing ("; p->s= next; - ff_eval_free(d); + ff_free_expr(d); return NULL; } p->s++; // "(" @@ -217,7 +212,7 @@ static AVEvalExpr * parse_primary(Parser *p) { d = parse_expr(p); if(p->s[0] != ')'){ *p->error = "missing )"; - ff_eval_free(d); + ff_free_expr(d); return NULL; } p->s++; // ")" @@ -230,7 +225,7 @@ static AVEvalExpr * parse_primary(Parser *p) { } if(p->s[0] != ')'){ *p->error = "missing )"; - ff_eval_free(d); + ff_free_expr(d); return NULL; } p->s++; // ")" @@ -256,8 +251,8 @@ static AVEvalExpr * parse_primary(Parser *p) { else if( strmatch(next, "eq" ) ) d->type = e_eq; else if( strmatch(next, "gte" ) ) d->type = e_gte; else if( strmatch(next, "gt" ) ) d->type = e_gt; - else if( strmatch(next, "lte" ) ) { AVEvalExpr * tmp = d->param[1]; d->param[1] = d->param[0]; d->param[0] = tmp; d->type = e_gt; } - else if( strmatch(next, "lt" ) ) { AVEvalExpr * tmp = d->param[1]; d->param[1] = d->param[0]; d->param[0] = tmp; d->type = e_gte; } + else if( strmatch(next, "lte" ) ) { AVExpr * tmp = d->param[1]; d->param[1] = d->param[0]; d->param[0] = tmp; d->type = e_gt; } + else if( strmatch(next, "lt" ) ) { AVExpr * tmp = d->param[1]; d->param[1] = d->param[0]; d->param[0] = tmp; d->type = e_gte; } else if( strmatch(next, "ld" ) ) d->type = e_ld; else if( strmatch(next, "st" ) ) d->type = e_st; else if( strmatch(next, "while" ) ) d->type = e_while; @@ -279,15 +274,17 @@ static AVEvalExpr * parse_primary(Parser *p) { } *p->error = "unknown function"; - ff_eval_free(d); + ff_free_expr(d); return NULL; } return d; } -static AVEvalExpr * new_eval_expr(int type, int value, AVEvalExpr *p0, AVEvalExpr *p1){ - AVEvalExpr * e = av_mallocz(sizeof(AVEvalExpr)); +static AVExpr * new_eval_expr(int type, int value, AVExpr *p0, AVExpr *p1){ + AVExpr * e = av_mallocz(sizeof(AVExpr)); + if (!e) + return NULL; e->type =type ; e->value =value ; e->param[0] =p0 ; @@ -295,44 +292,50 @@ static AVEvalExpr * new_eval_expr(int type, int value, AVEvalExpr *p0, AVEvalExp return e; } -static AVEvalExpr * parse_pow(Parser *p, int *sign){ +static AVExpr * parse_pow(Parser *p, int *sign){ *sign= (*p->s == '+') - (*p->s == '-'); p->s += *sign&1; return parse_primary(p); } -static AVEvalExpr * parse_factor(Parser *p){ +static AVExpr * parse_factor(Parser *p){ int sign, sign2; - AVEvalExpr * e = parse_pow(p, &sign); + AVExpr * e = parse_pow(p, &sign); while(p->s[0]=='^'){ p->s++; e= new_eval_expr(e_pow, 1, e, parse_pow(p, &sign2)); + if (!e) + return NULL; if (e->param[1]) e->param[1]->value *= (sign2|1); } if (e) e->value *= (sign|1); return e; } -static AVEvalExpr * parse_term(Parser *p){ - AVEvalExpr * e = parse_factor(p); +static AVExpr * parse_term(Parser *p){ + AVExpr * e = parse_factor(p); while(p->s[0]=='*' || p->s[0]=='/'){ int c= *p->s++; e= new_eval_expr(c == '*' ? e_mul : e_div, 1, e, parse_factor(p)); + if (!e) + return NULL; } return e; } -static AVEvalExpr * parse_subexpr(Parser *p) { - AVEvalExpr * e = parse_term(p); +static AVExpr * parse_subexpr(Parser *p) { + AVExpr * e = parse_term(p); while(*p->s == '+' || *p->s == '-') { e= new_eval_expr(e_add, 1, e, parse_term(p)); + if (!e) + return NULL; }; return e; } -static AVEvalExpr * parse_expr(Parser *p) { - AVEvalExpr * e; +static AVExpr * parse_expr(Parser *p) { + AVExpr * e; if(p->stack_index <= 0) //protect against stack overflows return NULL; @@ -343,6 +346,8 @@ static AVEvalExpr * parse_expr(Parser *p) { while(*p->s == ';') { p->s++; e= new_eval_expr(e_last, 1, e, parse_subexpr(p)); + if (!e) + return NULL; }; p->stack_index++; @@ -350,7 +355,7 @@ static AVEvalExpr * parse_expr(Parser *p) { return e; } -static int verify_expr(AVEvalExpr * e) { +static int verify_expr(AVExpr * e) { if (!e) return 0; switch (e->type) { case e_value: @@ -364,12 +369,12 @@ static int verify_expr(AVEvalExpr * e) { } } -AVEvalExpr * ff_parse(const char *s, const char * const *const_name, - double (**func1)(void *, double), const char **func1_name, - double (**func2)(void *, double, double), const char **func2_name, +AVExpr *ff_parse_expr(const char *s, const char * const *const_name, + double (* const *func1)(void *, double), const char * const *func1_name, + double (* const *func2)(void *, double, double), const char * const *func2_name, const char **error){ Parser p; - AVEvalExpr *e = NULL; + AVExpr *e = NULL; char *w = av_malloc(strlen(s) + 1); char *wp = w; @@ -391,7 +396,7 @@ AVEvalExpr * ff_parse(const char *s, const char * const *const_name, e = parse_expr(&p); if (!verify_expr(e)) { - ff_eval_free(e); + ff_free_expr(e); e = NULL; } end: @@ -399,7 +404,7 @@ end: return e; } -double ff_parse_eval(AVEvalExpr * e, const double *const_value, void *opaque) { +double ff_eval_expr(AVExpr * e, const double *const_value, void *opaque) { Parser p; p.const_value= const_value; @@ -407,15 +412,15 @@ double ff_parse_eval(AVEvalExpr * e, const double *const_value, void *opaque) { return eval_expr(&p, e); } -double ff_eval2(const char *s, const double *const_value, const char * const *const_name, - double (**func1)(void *, double), const char **func1_name, - double (**func2)(void *, double, double), const char **func2_name, +double ff_parse_and_eval_expr(const char *s, const double *const_value, const char * const *const_name, + double (* const *func1)(void *, double), const char * const *func1_name, + double (* const *func2)(void *, double, double), const char * const *func2_name, void *opaque, const char **error){ - AVEvalExpr * e = ff_parse(s, const_name, func1, func1_name, func2, func2_name, error); + AVExpr * e = ff_parse_expr(s, const_name, func1, func1_name, func2, func2_name, error); double d; if (!e) return NAN; - d = ff_parse_eval(e, const_value, opaque); - ff_eval_free(e); + d = ff_eval_expr(e, const_value, opaque); + ff_free_expr(e); return d; } @@ -433,13 +438,13 @@ static const char *const_names[]={ }; int main(void){ int i; - printf("%f == 12.7\n", ff_eval2("1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", const_values, const_names, NULL, NULL, NULL, NULL, NULL, NULL)); - printf("%f == 0.931322575\n", ff_eval2("80G/80Gi", const_values, const_names, NULL, NULL, NULL, NULL, NULL, NULL)); + printf("%f == 12.7\n", ff_parse_and_eval_expr("1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", const_values, const_names, NULL, NULL, NULL, NULL, NULL, NULL)); + printf("%f == 0.931322575\n", ff_parse_and_eval_expr("80G/80Gi", const_values, const_names, NULL, NULL, NULL, NULL, NULL, NULL)); for(i=0; i<1050; i++){ START_TIMER - ff_eval2("1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", const_values, const_names, NULL, NULL, NULL, NULL, NULL, NULL); - STOP_TIMER("ff_eval2") + ff_parse_and_eval_expr("1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", const_values, const_names, NULL, NULL, NULL, NULL, NULL, NULL); + STOP_TIMER("ff_parse_and_eval_expr") } return 0; } diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/eval.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/eval.h index 5481b1407c..50c16aff7c 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/eval.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/eval.h @@ -1,6 +1,4 @@ /* - * simple arithmetic expression evaluator - * * Copyright (c) 2002 Michael Niedermayer * * This file is part of FFmpeg. @@ -21,16 +19,19 @@ */ /** - * @file libavcodec/eval.h - * eval header. + * @file + * simple arithmetic expression evaluator */ #ifndef AVCODEC_EVAL_H #define AVCODEC_EVAL_H +typedef struct AVExpr AVExpr; + /** * Parses and evaluates an expression. - * Note, this is significantly slower than ff_parse_eval() + * Note, this is significantly slower than ff_eval_expr(). + * * @param s expression as a zero terminated string for example "1+2^3+5*5+sin(2/3)" * @param func1 NULL terminated array of function pointers for functions which take 1 argument * @param func2 NULL terminated array of function pointers for functions which take 2 arguments @@ -42,15 +43,14 @@ * @param opaque a pointer which will be passed to all functions from func1 and func2 * @return the value of the expression */ -double ff_eval2(const char *s, const double *const_value, const char * const *const_name, - double (**func1)(void *, double), const char **func1_name, - double (**func2)(void *, double, double), const char **func2_name, +double ff_parse_and_eval_expr(const char *s, const double *const_value, const char * const *const_name, + double (* const *func1)(void *, double), const char * const *func1_name, + double (* const *func2)(void *, double, double), const char * const *func2_name, void *opaque, const char **error); -typedef struct ff_expr_s AVEvalExpr; - /** - * Parses a expression. + * Parses an expression. + * * @param s expression as a zero terminated string for example "1+2^3+5*5+sin(2/3)" * @param func1 NULL terminated array of function pointers for functions which take 1 argument * @param func2 NULL terminated array of function pointers for functions which take 2 arguments @@ -58,21 +58,27 @@ typedef struct ff_expr_s AVEvalExpr; * @param func1_name NULL terminated array of zero terminated strings of func1 identifers * @param func2_name NULL terminated array of zero terminated strings of func2 identifers * @param error pointer to a char* which is set to an error message if something goes wrong - * @return AVEvalExpr which must be freed with ff_eval_free by the user when it is not needed anymore + * @return AVExpr which must be freed with ff_free_expr() by the user when it is not needed anymore * NULL if anything went wrong */ -AVEvalExpr * ff_parse(const char *s, const char * const *const_name, - double (**func1)(void *, double), const char **func1_name, - double (**func2)(void *, double, double), const char **func2_name, +AVExpr *ff_parse_expr(const char *s, const char * const *const_name, + double (* const *func1)(void *, double), const char * const *func1_name, + double (* const *func2)(void *, double, double), const char * const *func2_name, const char **error); + /** * Evaluates a previously parsed expression. + * * @param const_value a zero terminated array of values for the identifers from ff_parse const_name * @param opaque a pointer which will be passed to all functions from func1 and func2 * @return the value of the expression */ -double ff_parse_eval(AVEvalExpr * e, const double *const_value, void *opaque); -void ff_eval_free(AVEvalExpr * e); +double ff_eval_expr(AVExpr * e, const double *const_value, void *opaque); + +/** + * Frees a parsed expression previously created with ff_parse(). + */ +void ff_free_expr(AVExpr *e); /** * Parses the string in numstr and returns its value as a double. If diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/faandct.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/faandct.c index b16d46b48b..a986f65440 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/faandct.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/faandct.c @@ -19,7 +19,7 @@ */ /** - * @file libavcodec/faandct.c + * @file * @brief * Floating point AAN DCT * @author Michael Niedermayer diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/faandct.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/faandct.h index a69301c1d4..f43b62f168 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/faandct.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/faandct.h @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/faandct.h + * @file * @brief * Floating point AAN DCT * @author Michael Niedermayer diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/faxcompr.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/faxcompr.c index 9a9d1f5528..34aa576660 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/faxcompr.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/faxcompr.c @@ -21,7 +21,7 @@ /** * CCITT Fax Group 3 and 4 decompression - * @file libavcodec/faxcompr.c + * @file * @author Konstantin Shishkov */ #include "avcodec.h" @@ -253,6 +253,7 @@ static void put_line(uint8_t *dst, int size, int width, const int *runs) if(run) put_sbits(&pb, run, mode); } + flush_put_bits(&pb); } static int find_group3_syncmarker(GetBitContext *gb, int srcsize) @@ -268,8 +269,9 @@ static int find_group3_syncmarker(GetBitContext *gb, int srcsize) } int ff_ccitt_unpack(AVCodecContext *avctx, - const uint8_t *src, int srcsize, - uint8_t *dst, int height, int stride, enum TiffCompr compr) + const uint8_t *src, int srcsize, + uint8_t *dst, int height, int stride, + enum TiffCompr compr, int opts) { int j; GetBitContext gb; @@ -293,12 +295,15 @@ int ff_ccitt_unpack(AVCodecContext *avctx, return -1; } }else{ - if(find_group3_syncmarker(&gb, srcsize*8) < 0) + int g3d1 = (compr == TIFF_G3) && !(opts & 1); + if(compr!=TIFF_CCITT_RLE && find_group3_syncmarker(&gb, srcsize*8) < 0) break; - if(compr==TIFF_CCITT_RLE || get_bits1(&gb)) + if(compr==TIFF_CCITT_RLE || g3d1 || get_bits1(&gb)) ret = decode_group3_1d_line(avctx, &gb, avctx->width, runs, runend); else ret = decode_group3_2d_line(avctx, &gb, avctx->width, runs, runend, ref); + if(compr==TIFF_CCITT_RLE) + align_get_bits(&gb); } if(ret < 0){ put_line(dst, stride, avctx->width, ref); diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/faxcompr.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/faxcompr.h index 5f0a222e72..62f591ceee 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/faxcompr.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/faxcompr.h @@ -21,7 +21,7 @@ /** * CCITT Fax Group 3 and 4 decompression - * @file libavcodec/faxcompr.h + * @file * @author Konstantin Shishkov */ #ifndef AVCODEC_FAXCOMPR_H @@ -39,7 +39,8 @@ void ff_ccitt_unpack_init(void); * unpack data compressed with CCITT Group 3 1/2-D or Group 4 method */ int ff_ccitt_unpack(AVCodecContext *avctx, - const uint8_t *src, int srcsize, - uint8_t *dst, int height, int stride, enum TiffCompr compr); + const uint8_t *src, int srcsize, + uint8_t *dst, int height, int stride, + enum TiffCompr compr, int opts); #endif /* AVCODEC_FAXCOMPR_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/fft-test.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/fft-test.c index 421f8bb7bf..ae436029ed 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/fft-test.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/fft-test.c @@ -19,12 +19,14 @@ */ /** - * @file libavcodec/fft-test.c + * @file * FFT and MDCT tests. */ +#include "libavutil/mathematics.h" #include "libavutil/lfg.h" -#include "dsputil.h" +#include "libavutil/log.h" +#include "fft.h" #include #include #include @@ -53,7 +55,7 @@ static void fft_ref_init(int nbits, int inverse) n = 1 << nbits; exptab = av_malloc((n / 2) * sizeof(FFTComplex)); - for(i=0;i<(n/2);i++) { + for (i = 0; i < (n/2); i++) { alpha = 2 * M_PI * (float)i / (float)n; c1 = cos(alpha); s1 = sin(alpha); @@ -72,11 +74,11 @@ static void fft_ref(FFTComplex *tabr, FFTComplex *tab, int nbits) n = 1 << nbits; n2 = n >> 1; - for(i=0;i= n2) { c = -exptab[k - n2].re; @@ -99,9 +101,9 @@ static void imdct_ref(float *out, float *in, int nbits) int k, i, a; double sum, f; - for(i=0;i= 1e-3) { av_log(NULL, AV_LOG_ERROR, "ERROR %d: %f %f\n", @@ -168,6 +201,8 @@ static void help(void) "-h print this help\n" "-s speed test\n" "-m (I)MDCT test\n" + "-d (I)DCT test\n" + "-r (I)RDFT test\n" "-i inverse transform test\n" "-n b set the transform size to 2^b\n" "-f x set scale factor for output data of (I)MDCT to x\n" @@ -175,7 +210,12 @@ static void help(void) exit(1); } - +enum tf_transform { + TRANSFORM_FFT, + TRANSFORM_MDCT, + TRANSFORM_RDFT, + TRANSFORM_DCT, +}; int main(int argc, char **argv) { @@ -183,16 +223,20 @@ int main(int argc, char **argv) FFTSample *tab2; int it, i, c; int do_speed = 0; - int do_mdct = 0; + enum tf_transform transform = TRANSFORM_FFT; int do_inverse = 0; FFTContext s1, *s = &s1; - MDCTContext m1, *m = &m1; - int fft_nbits, fft_size; + FFTContext m1, *m = &m1; + RDFTContext r1, *r = &r1; + DCTContext d1, *d = &d1; + int fft_nbits, fft_size, fft_size_2; double scale = 1.0; + AVLFG prng; + av_lfg_init(&prng, 1); fft_nbits = 9; for(;;) { - c = getopt(argc, argv, "hsimn:f:"); + c = getopt(argc, argv, "hsimrdn:f:"); if (c == -1) break; switch(c) { @@ -206,7 +250,13 @@ int main(int argc, char **argv) do_inverse = 1; break; case 'm': - do_mdct = 1; + transform = TRANSFORM_MDCT; + break; + case 'r': + transform = TRANSFORM_RDFT; + break; + case 'd': + transform = TRANSFORM_DCT; break; case 'n': fft_nbits = atoi(optarg); @@ -218,39 +268,59 @@ int main(int argc, char **argv) } fft_size = 1 << fft_nbits; + fft_size_2 = fft_size >> 1; tab = av_malloc(fft_size * sizeof(FFTComplex)); tab1 = av_malloc(fft_size * sizeof(FFTComplex)); tab_ref = av_malloc(fft_size * sizeof(FFTComplex)); tab2 = av_malloc(fft_size * sizeof(FFTSample)); - if (do_mdct) { + switch (transform) { + case TRANSFORM_MDCT: av_log(NULL, AV_LOG_INFO,"Scale factor is set to %f\n", scale); if (do_inverse) av_log(NULL, AV_LOG_INFO,"IMDCT"); else av_log(NULL, AV_LOG_INFO,"MDCT"); ff_mdct_init(m, fft_nbits, do_inverse, scale); - } else { + break; + case TRANSFORM_FFT: if (do_inverse) av_log(NULL, AV_LOG_INFO,"IFFT"); else av_log(NULL, AV_LOG_INFO,"FFT"); ff_fft_init(s, fft_nbits, do_inverse); fft_ref_init(fft_nbits, do_inverse); + break; + case TRANSFORM_RDFT: + if (do_inverse) + av_log(NULL, AV_LOG_INFO,"IDFT_C2R"); + else + av_log(NULL, AV_LOG_INFO,"DFT_R2C"); + ff_rdft_init(r, fft_nbits, do_inverse ? IDFT_C2R : DFT_R2C); + fft_ref_init(fft_nbits, do_inverse); + break; + case TRANSFORM_DCT: + if (do_inverse) + av_log(NULL, AV_LOG_INFO,"DCT_III"); + else + av_log(NULL, AV_LOG_INFO,"DCT_II"); + ff_dct_init(d, fft_nbits, do_inverse ? DCT_III : DCT_II); + break; } av_log(NULL, AV_LOG_INFO," %d test\n", fft_size); /* generate random data */ - for(i=0;i +#include +#include "libavutil/mathematics.h" +#include "fft.h" /* cos(2*pi*x/n) for 0<=x<=n/4, followed by its reverse */ -DECLARE_ALIGNED_16(FFTSample, ff_cos_16[8]); -DECLARE_ALIGNED_16(FFTSample, ff_cos_32[16]); -DECLARE_ALIGNED_16(FFTSample, ff_cos_64[32]); -DECLARE_ALIGNED_16(FFTSample, ff_cos_128[64]); -DECLARE_ALIGNED_16(FFTSample, ff_cos_256[128]); -DECLARE_ALIGNED_16(FFTSample, ff_cos_512[256]); -DECLARE_ALIGNED_16(FFTSample, ff_cos_1024[512]); -DECLARE_ALIGNED_16(FFTSample, ff_cos_2048[1024]); -DECLARE_ALIGNED_16(FFTSample, ff_cos_4096[2048]); -DECLARE_ALIGNED_16(FFTSample, ff_cos_8192[4096]); -DECLARE_ALIGNED_16(FFTSample, ff_cos_16384[8192]); -DECLARE_ALIGNED_16(FFTSample, ff_cos_32768[16384]); -DECLARE_ALIGNED_16(FFTSample, ff_cos_65536[32768]); -FFTSample *ff_cos_tabs[] = { +#if !CONFIG_HARDCODED_TABLES +COSTABLE(16); +COSTABLE(32); +COSTABLE(64); +COSTABLE(128); +COSTABLE(256); +COSTABLE(512); +COSTABLE(1024); +COSTABLE(2048); +COSTABLE(4096); +COSTABLE(8192); +COSTABLE(16384); +COSTABLE(32768); +COSTABLE(65536); +#endif +COSTABLE_CONST FFTSample * const ff_cos_tabs[] = { + NULL, NULL, NULL, NULL, ff_cos_16, ff_cos_32, ff_cos_64, ff_cos_128, ff_cos_256, ff_cos_512, ff_cos_1024, ff_cos_2048, ff_cos_4096, ff_cos_8192, ff_cos_16384, ff_cos_32768, ff_cos_65536, }; @@ -58,11 +64,24 @@ static int split_radix_permutation(int i, int n, int inverse) else return split_radix_permutation(i, m, inverse)*4 - 1; } +av_cold void ff_init_ff_cos_tabs(int index) +{ +#if !CONFIG_HARDCODED_TABLES + int i; + int m = 1< 16) @@ -83,46 +102,21 @@ av_cold int ff_fft_init(FFTContext *s, int nbits, int inverse) s->fft_permute = ff_fft_permute_c; s->fft_calc = ff_fft_calc_c; +#if CONFIG_MDCT s->imdct_calc = ff_imdct_calc_c; s->imdct_half = ff_imdct_half_c; - s->exptab1 = NULL; - -#if HAVE_MMX && HAVE_YASM - has_vectors = mm_support(); - if (has_vectors & FF_MM_SSE && HAVE_SSE) { - /* SSE for P3/P4/K8 */ - s->imdct_calc = ff_imdct_calc_sse; - s->imdct_half = ff_imdct_half_sse; - s->fft_permute = ff_fft_permute_sse; - s->fft_calc = ff_fft_calc_sse; - } else if (has_vectors & FF_MM_3DNOWEXT && HAVE_AMD3DNOWEXT) { - /* 3DNowEx for K7 */ - s->imdct_calc = ff_imdct_calc_3dn2; - s->imdct_half = ff_imdct_half_3dn2; - s->fft_calc = ff_fft_calc_3dn2; - } else if (has_vectors & FF_MM_3DNOW && HAVE_AMD3DNOW) { - /* 3DNow! for K6-2/3 */ - s->imdct_calc = ff_imdct_calc_3dn; - s->imdct_half = ff_imdct_half_3dn; - s->fft_calc = ff_fft_calc_3dn; - } -#elif HAVE_ALTIVEC - has_vectors = mm_support(); - if (has_vectors & FF_MM_ALTIVEC) { - s->fft_calc = ff_fft_calc_altivec; - split_radix = 0; - } + s->mdct_calc = ff_mdct_calc_c; #endif + s->exptab1 = NULL; + s->split_radix = 1; - if (split_radix) { + if (ARCH_ARM) ff_fft_init_arm(s); + if (HAVE_ALTIVEC) ff_fft_init_altivec(s); + if (HAVE_MMX) ff_fft_init_mmx(s); + + if (s->split_radix) { for(j=4; j<=nbits; j++) { - int m = 1<revtab[-split_radix_permutation(i, n, s->inverse) & (n-1)] = i; @@ -362,7 +356,7 @@ DECL_FFT(16384,8192,4096) DECL_FFT(32768,16384,8192) DECL_FFT(65536,32768,16384) -static void (*fft_dispatch[])(FFTComplex*) = { +static void (* const fft_dispatch[])(FFTComplex*) = { fft4, fft8, fft16, fft32, fft64, fft128, fft256, fft512, fft1024, fft2048, fft4096, fft8192, fft16384, fft32768, fft65536, }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/fft.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/fft.h new file mode 100644 index 0000000000..1f5b2e86da --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/fft.h @@ -0,0 +1,240 @@ +/* + * Copyright (c) 2000, 2001, 2002 Fabrice Bellard + * Copyright (c) 2002-2004 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 + */ + +#ifndef AVCODEC_FFT_H +#define AVCODEC_FFT_H + +#include +#include "config.h" +#include "libavutil/mem.h" +#include "avfft.h" + +/* FFT computation */ + +struct FFTContext { + int nbits; + int inverse; + uint16_t *revtab; + FFTComplex *exptab; + FFTComplex *exptab1; /* only used by SSE code */ + FFTComplex *tmp_buf; + int mdct_size; /* size of MDCT (i.e. number of input data * 2) */ + int mdct_bits; /* n = 2^nbits */ + /* pre/post rotation tables */ + FFTSample *tcos; + FFTSample *tsin; + void (*fft_permute)(struct FFTContext *s, FFTComplex *z); + void (*fft_calc)(struct FFTContext *s, FFTComplex *z); + void (*imdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input); + void (*imdct_half)(struct FFTContext *s, FFTSample *output, const FFTSample *input); + void (*mdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input); + int split_radix; + int permutation; +#define FF_MDCT_PERM_NONE 0 +#define FF_MDCT_PERM_INTERLEAVE 1 +}; + +#if CONFIG_HARDCODED_TABLES +#define COSTABLE_CONST const +#define SINTABLE_CONST const +#define SINETABLE_CONST const +#else +#define COSTABLE_CONST +#define SINTABLE_CONST +#define SINETABLE_CONST +#endif + +#define COSTABLE(size) \ + COSTABLE_CONST DECLARE_ALIGNED(16, FFTSample, ff_cos_##size)[size/2] +#define SINTABLE(size) \ + SINTABLE_CONST DECLARE_ALIGNED(16, FFTSample, ff_sin_##size)[size/2] +#define SINETABLE(size) \ + SINETABLE_CONST DECLARE_ALIGNED(16, float, ff_sine_##size)[size] +extern COSTABLE(16); +extern COSTABLE(32); +extern COSTABLE(64); +extern COSTABLE(128); +extern COSTABLE(256); +extern COSTABLE(512); +extern COSTABLE(1024); +extern COSTABLE(2048); +extern COSTABLE(4096); +extern COSTABLE(8192); +extern COSTABLE(16384); +extern COSTABLE(32768); +extern COSTABLE(65536); +extern COSTABLE_CONST FFTSample* const ff_cos_tabs[17]; + +/** + * Initializes the cosine table in ff_cos_tabs[index] + * \param index index in ff_cos_tabs array of the table to initialize + */ +void ff_init_ff_cos_tabs(int index); + +extern SINTABLE(16); +extern SINTABLE(32); +extern SINTABLE(64); +extern SINTABLE(128); +extern SINTABLE(256); +extern SINTABLE(512); +extern SINTABLE(1024); +extern SINTABLE(2048); +extern SINTABLE(4096); +extern SINTABLE(8192); +extern SINTABLE(16384); +extern SINTABLE(32768); +extern SINTABLE(65536); + +/** + * Sets up a complex FFT. + * @param nbits log2 of the length of the input array + * @param inverse if 0 perform the forward transform, if 1 perform the inverse + */ +int ff_fft_init(FFTContext *s, int nbits, int inverse); +void ff_fft_permute_c(FFTContext *s, FFTComplex *z); +void ff_fft_calc_c(FFTContext *s, FFTComplex *z); + +void ff_fft_init_altivec(FFTContext *s); +void ff_fft_init_mmx(FFTContext *s); +void ff_fft_init_arm(FFTContext *s); + +/** + * Do the permutation needed BEFORE calling ff_fft_calc(). + */ +static inline void ff_fft_permute(FFTContext *s, FFTComplex *z) +{ + s->fft_permute(s, z); +} +/** + * Do a complex FFT with the parameters defined in ff_fft_init(). The + * input data must be permuted before. No 1.0/sqrt(n) normalization is done. + */ +static inline void ff_fft_calc(FFTContext *s, FFTComplex *z) +{ + s->fft_calc(s, z); +} +void ff_fft_end(FFTContext *s); + +/* MDCT computation */ + +static inline void ff_imdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input) +{ + s->imdct_calc(s, output, input); +} +static inline void ff_imdct_half(FFTContext *s, FFTSample *output, const FFTSample *input) +{ + s->imdct_half(s, output, input); +} + +static inline void ff_mdct_calc(FFTContext *s, FFTSample *output, + const FFTSample *input) +{ + s->mdct_calc(s, output, input); +} + +/** + * Generate a Kaiser-Bessel Derived Window. + * @param window pointer to half window + * @param alpha determines window shape + * @param n size of half window + */ +void ff_kbd_window_init(float *window, float alpha, int n); + +/** + * Generate a sine window. + * @param window pointer to half window + * @param n size of half window + */ +void ff_sine_window_init(float *window, int n); + +/** + * initialize the specified entry of ff_sine_windows + */ +void ff_init_ff_sine_windows(int index); +extern SINETABLE( 32); +extern SINETABLE( 64); +extern SINETABLE( 128); +extern SINETABLE( 256); +extern SINETABLE( 512); +extern SINETABLE(1024); +extern SINETABLE(2048); +extern SINETABLE(4096); +extern SINETABLE_CONST float * const ff_sine_windows[13]; + +int ff_mdct_init(FFTContext *s, int nbits, int inverse, double scale); +void ff_imdct_calc_c(FFTContext *s, FFTSample *output, const FFTSample *input); +void ff_imdct_half_c(FFTContext *s, FFTSample *output, const FFTSample *input); +void ff_mdct_calc_c(FFTContext *s, FFTSample *output, const FFTSample *input); +void ff_mdct_end(FFTContext *s); + +/* Real Discrete Fourier Transform */ + +struct RDFTContext { + int nbits; + int inverse; + int sign_convention; + + /* pre/post rotation tables */ + const FFTSample *tcos; + SINTABLE_CONST FFTSample *tsin; + FFTContext fft; + void (*rdft_calc)(struct RDFTContext *s, FFTSample *z); +}; + +/** + * Sets up a real FFT. + * @param nbits log2 of the length of the input array + * @param trans the type of transform + */ +int ff_rdft_init(RDFTContext *s, int nbits, enum RDFTransformType trans); +void ff_rdft_end(RDFTContext *s); + +void ff_rdft_init_arm(RDFTContext *s); + +static av_always_inline void ff_rdft_calc(RDFTContext *s, FFTSample *data) +{ + s->rdft_calc(s, data); +} + +/* Discrete Cosine Transform */ + +struct DCTContext { + int nbits; + int inverse; + RDFTContext rdft; + const float *costab; + FFTSample *csc2; + void (*dct_calc)(struct DCTContext *s, FFTSample *data); +}; + +/** + * Sets up DCT. + * @param nbits size of the input array: + * (1 << nbits) for DCT-II, DCT-III and DST-I + * (1 << nbits) + 1 for DCT-I + * + * @note the first element of the input of DST-I is ignored + */ +int ff_dct_init(DCTContext *s, int nbits, enum DCTTransformType type); +void ff_dct_calc(DCTContext *s, FFTSample *data); +void ff_dct_end (DCTContext *s); + +#endif /* AVCODEC_FFT_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ffv1.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/ffv1.c index 0c0062edcc..12056e1208 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/ffv1.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ffv1.c @@ -21,8 +21,8 @@ */ /** - * @file libavcodec/ffv1.c - * FF Video Codec 1 (an experimental lossless codec) + * @file + * FF Video Codec 1 (a lossless codec) */ #include "avcodec.h" @@ -186,6 +186,25 @@ static const int8_t quant13[256]={ -4,-4,-4,-4,-4,-4,-4,-4,-4,-3,-3,-3,-3,-2,-2,-1, }; +static const uint8_t ver2_state[256]= { + 0, 10, 10, 10, 10, 16, 16, 16, 28, 16, 16, 29, 42, 49, 20, 49, + 59, 25, 26, 26, 27, 31, 33, 33, 33, 34, 34, 37, 67, 38, 39, 39, + 40, 40, 41, 79, 43, 44, 45, 45, 48, 48, 64, 50, 51, 52, 88, 52, + 53, 74, 55, 57, 58, 58, 74, 60, 101, 61, 62, 84, 66, 66, 68, 69, + 87, 82, 71, 97, 73, 73, 82, 75, 111, 77, 94, 78, 87, 81, 83, 97, + 85, 83, 94, 86, 99, 89, 90, 99, 111, 92, 93, 134, 95, 98, 105, 98, + 105, 110, 102, 108, 102, 118, 103, 106, 106, 113, 109, 112, 114, 112, 116, 125, + 115, 116, 117, 117, 126, 119, 125, 121, 121, 123, 145, 124, 126, 131, 127, 129, + 165, 130, 132, 138, 133, 135, 145, 136, 137, 139, 146, 141, 143, 142, 144, 148, + 147, 155, 151, 149, 151, 150, 152, 157, 153, 154, 156, 168, 158, 162, 161, 160, + 172, 163, 169, 164, 166, 184, 167, 170, 177, 174, 171, 173, 182, 176, 180, 178, + 175, 189, 179, 181, 186, 183, 192, 185, 200, 187, 191, 188, 190, 197, 193, 196, + 197, 194, 195, 196, 198, 202, 199, 201, 210, 203, 207, 204, 205, 206, 208, 214, + 209, 211, 221, 212, 213, 215, 224, 216, 217, 218, 219, 220, 222, 228, 223, 225, + 226, 224, 227, 229, 240, 230, 231, 232, 233, 234, 235, 236, 238, 239, 237, 242, + 241, 243, 242, 244, 245, 246, 247, 248, 249, 250, 251, 252, 252, 253, 254, 255, +}; + typedef struct VlcState{ int16_t drift; uint16_t error_sum; @@ -212,9 +231,10 @@ typedef struct FFV1Context{ int picture_number; AVFrame picture; int plane_count; - int ac; ///< 1-> CABAC 0-> golomb rice + int ac; ///< 1=range coder <-> 0=golomb rice PlaneContext plane[MAX_PLANES]; int16_t quant_table[5][256]; + uint8_t state_transition[256]; int run_index; int colorspace; @@ -578,7 +598,13 @@ static void write_header(FFV1Context *f){ memset(state, 128, sizeof(state)); put_symbol(c, state, f->version, 0); - put_symbol(c, state, f->avctx->coder_type, 0); + put_symbol(c, state, f->ac, 0); + if(f->ac>1){ + for(i=1; i<256; i++){ + f->state_transition[i]=ver2_state[i]; + put_symbol(c, state, ver2_state[i] - c->one_state[i], 1); + } + } put_symbol(c, state, f->colorspace, 0); //YUV cs type if(f->version>0) put_symbol(c, state, f->avctx->bits_per_raw_sample, 0); @@ -617,7 +643,7 @@ static av_cold int encode_init(AVCodecContext *avctx) common_init(avctx); s->version=0; - s->ac= avctx->coder_type; + s->ac= avctx->coder_type ? 2:0; s->plane_count=2; for(i=0; i<256; i++){ @@ -669,15 +695,14 @@ static av_cold int encode_init(AVCodecContext *avctx) case PIX_FMT_YUV444P16: case PIX_FMT_YUV422P16: case PIX_FMT_YUV420P16: - if(avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){ - av_log(avctx, AV_LOG_ERROR, "More than 8 bit per component is still experimental and no gurantee is yet made for future compatibility\n" - "Use vstrict=-2 / -strict -2 to use it anyway.\n"); - return -1; - } if(avctx->bits_per_raw_sample <=8){ av_log(avctx, AV_LOG_ERROR, "bits_per_raw_sample invalid\n"); return -1; } + if(!s->ac){ + av_log(avctx, AV_LOG_ERROR, "bits_per_raw_sample of more than 8 needs -coder 1 currently\n"); + return -1; + } s->version= 1; case PIX_FMT_YUV444P: case PIX_FMT_YUV422P: @@ -736,7 +761,6 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, uint8_t keystate=128; ff_init_range_encoder(c, buf, buf_size); -// ff_init_cabac_states(c, ff_h264_lps_range, ff_h264_mps_state, ff_h264_lps_state, 64); ff_build_rac_states(c, 0.05*(1LL<<32), 256-8); *p = *pict; @@ -756,6 +780,12 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, used_count += ff_rac_terminate(c); //printf("pos=%d\n", used_count); init_put_bits(&f->pb, buf + used_count, buf_size - used_count); + }else if (f->ac>1){ + int i; + for(i=1; i<256; i++){ + c->one_state[i]= f->state_transition[i]; + c->zero_state[256-i]= 256-c->one_state[i]; + } } if(f->colorspace==0){ @@ -969,6 +999,11 @@ static int read_header(FFV1Context *f){ f->version= get_symbol(c, state, 0); f->ac= f->avctx->coder_type= get_symbol(c, state, 0); + if(f->ac>1){ + for(i=1; i<256; i++){ + f->state_transition[i]= get_symbol(c, state, 1) + c->one_state[i]; + } + } f->colorspace= get_symbol(c, state, 0); //YUV cs type if(f->version>0) f->avctx->bits_per_raw_sample= get_symbol(c, state, 0); @@ -1073,6 +1108,14 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac }else{ p->key_frame= 0; } + if(f->ac>1){ + int i; + for(i=1; i<256; i++){ + c->one_state[i]= f->state_transition[i]; + c->zero_state[256-i]= 256-c->one_state[i]; + } + } + if(!f->plane[0].state && !f->plane[0].vlc_state) return -1; @@ -1127,7 +1170,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac AVCodec ffv1_decoder = { "ffv1", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_FFV1, sizeof(FFV1Context), decode_init, @@ -1136,19 +1179,19 @@ AVCodec ffv1_decoder = { decode_frame, CODEC_CAP_DR1 /*| CODEC_CAP_DRAW_HORIZ_BAND*/, NULL, - .long_name= NULL_IF_CONFIG_SMALL("FFmpeg codec #1"), + .long_name= NULL_IF_CONFIG_SMALL("FFmpeg video codec #1"), }; #if CONFIG_FFV1_ENCODER AVCodec ffv1_encoder = { "ffv1", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_FFV1, sizeof(FFV1Context), encode_init, encode_frame, common_end, - .pix_fmts= (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}, - .long_name= NULL_IF_CONFIG_SMALL("FFmpeg codec #1"), + .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}, + .long_name= NULL_IF_CONFIG_SMALL("FFmpeg video codec #1"), }; #endif diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/flac.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/flac.h index 25494ed667..1b114635ec 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/flac.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/flac.h @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/flac.h + * @file * FLAC (Free Lossless Audio Codec) decoder/demuxer common functions */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/flacdec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/flacdec.c index d3a8b3327d..07acf6e81b 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/flacdec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/flacdec.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/flacdec.c + * @file * FLAC (Free Lossless Audio Codec) decoder * @author Alex Beregszaszi * @@ -125,6 +125,10 @@ static av_cold int flac_decode_init(AVCodecContext *avctx) /* initialize based on the demuxer-supplied streamdata header */ ff_flac_parse_streaminfo(avctx, (FLACStreaminfo *)s, streaminfo); + if (s->bps > 16) + avctx->sample_fmt = SAMPLE_FMT_S32; + else + avctx->sample_fmt = SAMPLE_FMT_S16; allocate_buffers(s); s->got_streaminfo = 1; @@ -186,10 +190,6 @@ void ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s, avctx->channels = s->channels; avctx->sample_rate = s->samplerate; avctx->bits_per_raw_sample = s->bps; - if (s->bps > 16) - avctx->sample_fmt = SAMPLE_FMT_S32; - else - avctx->sample_fmt = SAMPLE_FMT_S16; s->samples = get_bits_long(&gb, 32) << 4; s->samples |= get_bits(&gb, 4); @@ -799,14 +799,16 @@ static void flac_flush(AVCodecContext *avctx) AVCodec flac_decoder = { "flac", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_FLAC, sizeof(FLACContext), flac_decode_init, NULL, flac_decode_close, flac_decode_frame, - CODEC_CAP_DELAY, + CODEC_CAP_DELAY | CODEC_CAP_SUBFRAMES, /* FIXME: add a FLAC parser so that + we will not need to use either + of these capabilities */ .flush= flac_flush, .long_name= NULL_IF_CONFIG_SMALL("FLAC (Free Lossless Audio Codec)"), }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/flacenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/flacenc.c index 164e0c0324..89d40d5ac2 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/flacenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/flacenc.c @@ -352,7 +352,7 @@ static av_cold int flac_encode_init(AVCodecContext *avctx) /* initialize MD5 context */ s->md5ctx = av_malloc(av_md5_size); if(!s->md5ctx) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); av_md5_init(s->md5ctx); streaminfo = av_malloc(FLAC_STREAMINFO_SIZE); @@ -552,69 +552,6 @@ static uint32_t calc_rice_params_lpc(RiceContext *rc, int pmin, int pmax, return bits; } -/** - * Apply Welch window function to audio block - */ -static void apply_welch_window(const int32_t *data, int len, double *w_data) -{ - int i, n2; - double w; - double c; - - assert(!(len&1)); //the optimization in r11881 does not support odd len - //if someone wants odd len extend the change in r11881 - - n2 = (len >> 1); - c = 2.0 / (len - 1.0); - - w_data+=n2; - data+=n2; - for(i=0; i 0); @@ -1316,7 +1253,7 @@ static av_cold int flac_encode_close(AVCodecContext *avctx) AVCodec flac_encoder = { "flac", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_FLAC, sizeof(FlacEncodeContext), flac_encode_init, @@ -1324,6 +1261,6 @@ AVCodec flac_encoder = { flac_encode_close, NULL, .capabilities = CODEC_CAP_SMALL_LAST_FRAME | CODEC_CAP_DELAY, - .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, + .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, .long_name = NULL_IF_CONFIG_SMALL("FLAC (Free Lossless Audio Codec)"), }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/flashsv.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/flashsv.c index 20c85e3ac0..394ac0f82a 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/flashsv.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/flashsv.c @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/flashsv.c + * @file * Flash Screen Video decoder * @author Alex Beregszaszi * @author Benjamin Larsson @@ -113,9 +113,8 @@ static int flashsv_decode_frame(AVCodecContext *avctx, /* no supplementary picture */ if (buf_size == 0) return 0; - - if(s->frame.data[0]) - avctx->release_buffer(avctx, &s->frame); + if (buf_size < 4) + return -1; init_get_bits(&gb, buf, buf_size * 8); @@ -162,10 +161,10 @@ static int flashsv_decode_frame(AVCodecContext *avctx, h_blocks, v_blocks, h_part, v_part); s->frame.reference = 1; - s->frame.buffer_hints = FF_BUFFER_HINTS_VALID; - if (avctx->get_buffer(avctx, &s->frame) < 0) { - av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + 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; } /* loop over all block columns */ @@ -184,6 +183,11 @@ static int flashsv_decode_frame(AVCodecContext *avctx, /* get the size of the compressed zlib chunk */ int size = get_bits(&gb, 16); + if (8 * size > get_bits_left(&gb)) { + avctx->release_buffer(avctx, &s->frame); + s->frame.data[0] = NULL; + return -1; + } if (size == 0) { /* no change, don't do anything */ @@ -248,7 +252,7 @@ static av_cold int flashsv_decode_end(AVCodecContext *avctx) AVCodec flashsv_decoder = { "flashsv", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_FLASHSV, sizeof(FlashSVContext), flashsv_decode_init, @@ -256,6 +260,6 @@ AVCodec flashsv_decoder = { flashsv_decode_end, flashsv_decode_frame, CODEC_CAP_DR1, - .pix_fmts = (enum PixelFormat[]){PIX_FMT_BGR24, PIX_FMT_NONE}, + .pix_fmts = (const enum PixelFormat[]){PIX_FMT_BGR24, PIX_FMT_NONE}, .long_name = NULL_IF_CONFIG_SMALL("Flash Screen Video v1"), }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/flashsvenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/flashsvenc.c index f207f8d078..ff917e9370 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/flashsvenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/flashsvenc.c @@ -23,7 +23,7 @@ /* Encoding development sponsored by http://fh-campuswien.ac.at */ /** - * @file libavcodec/flashsvenc.c + * @file * Flash Screen Video encoder * @author Alex Beregszaszi * @author Benjamin Larsson @@ -108,10 +108,6 @@ static av_cold int flashsv_encode_init(AVCodecContext *avctx) return -1; } - if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) { - return -1; - } - // Needed if zlib unused or init aborted before deflateInit memset(&(s->zstream), 0, sizeof(z_stream)); @@ -286,13 +282,13 @@ static av_cold int flashsv_encode_end(AVCodecContext *avctx) AVCodec flashsv_encoder = { "flashsv", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_FLASHSV, sizeof(FlashSVContext), flashsv_encode_init, flashsv_encode_frame, flashsv_encode_end, - .pix_fmts = (enum PixelFormat[]){PIX_FMT_BGR24, PIX_FMT_NONE}, + .pix_fmts = (const enum PixelFormat[]){PIX_FMT_BGR24, PIX_FMT_NONE}, .long_name = NULL_IF_CONFIG_SMALL("Flash Screen Video"), }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/flicvideo.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/flicvideo.c index 2ee7837f60..429ded53b2 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/flicvideo.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/flicvideo.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/flicvideo.c + * @file * Autodesk Animator FLI/FLC Video Decoder * by Mike Melanson (melanson@pcisys.net) * for more information on the .fli/.flc file format and all of its many @@ -739,7 +739,7 @@ static av_cold int flic_decode_end(AVCodecContext *avctx) AVCodec flic_decoder = { "flic", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_FLIC, sizeof(FlicDecodeContext), flic_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/flv.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/flv.h new file mode 100644 index 0000000000..eb10f22608 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/flv.h @@ -0,0 +1,34 @@ +/* + * FLV specific private header. + * 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_FLV_H +#define AVCODEC_FLV_H + +#include "mpegvideo.h" +#include "get_bits.h" +#include "put_bits.h" + +void ff_flv_encode_picture_header(MpegEncContext * s, int picture_number); +void ff_flv2_encode_ac_esc(PutBitContext *pb, int slevel, int level, int run, int last); + +int ff_flv_decode_picture_header(MpegEncContext *s); +void ff_flv2_decode_ac_esc(GetBitContext *gb, int *level, int *run, int *last); + +#endif + diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/flvdec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/flvdec.c new file mode 100644 index 0000000000..cf9661ce1c --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/flvdec.c @@ -0,0 +1,132 @@ +/* + * FLV decoding. + * 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 "mpegvideo.h" +#include "h263.h" +#include "flv.h" + +void ff_flv2_decode_ac_esc(GetBitContext *gb, int *level, int *run, int *last){ + int is11 = get_bits1(gb); + *last = get_bits1(gb); + *run = get_bits(gb, 6); + if(is11){ + *level = get_sbits(gb, 11); + } else { + *level = get_sbits(gb, 7); + } +} + +int ff_flv_decode_picture_header(MpegEncContext *s) +{ + int format, width, height; + + /* picture header */ + if (get_bits_long(&s->gb, 17) != 1) { + av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n"); + return -1; + } + format = get_bits(&s->gb, 5); + if (format != 0 && format != 1) { + av_log(s->avctx, AV_LOG_ERROR, "Bad picture format\n"); + return -1; + } + s->h263_flv = format+1; + s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */ + format = get_bits(&s->gb, 3); + switch (format) { + case 0: + width = get_bits(&s->gb, 8); + height = get_bits(&s->gb, 8); + break; + case 1: + width = get_bits(&s->gb, 16); + height = get_bits(&s->gb, 16); + break; + case 2: + width = 352; + height = 288; + break; + case 3: + width = 176; + height = 144; + break; + case 4: + width = 128; + height = 96; + break; + case 5: + width = 320; + height = 240; + break; + case 6: + width = 160; + height = 120; + break; + default: + width = height = 0; + break; + } + if(avcodec_check_dimensions(s->avctx, width, height)) + return -1; + s->width = width; + s->height = height; + + s->pict_type = FF_I_TYPE + get_bits(&s->gb, 2); + s->dropable= s->pict_type > FF_P_TYPE; + if (s->dropable) + s->pict_type = FF_P_TYPE; + + skip_bits1(&s->gb); /* deblocking flag */ + s->chroma_qscale= s->qscale = get_bits(&s->gb, 5); + + s->h263_plus = 0; + + s->unrestricted_mv = 1; + s->h263_long_vectors = 0; + + /* PEI */ + while (get_bits1(&s->gb) != 0) { + skip_bits(&s->gb, 8); + } + s->f_code = 1; + + if(s->avctx->debug & FF_DEBUG_PICT_INFO){ + av_log(s->avctx, AV_LOG_DEBUG, "%c esc_type:%d, qp:%d num:%d\n", + s->dropable ? 'D' : av_get_pict_type_char(s->pict_type), s->h263_flv-1, s->qscale, s->picture_number); + } + + s->y_dc_scale_table= + s->c_dc_scale_table= ff_mpeg1_dc_scale_table; + + return 0; +} + +AVCodec 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, + .long_name= NULL_IF_CONFIG_SMALL("Flash Video (FLV) / Sorenson Spark / Sorenson H.263"), + .pix_fmts= ff_pixfmt_list_420, +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/flvenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/flvenc.c new file mode 100644 index 0000000000..bf320f2ffe --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/flvenc.c @@ -0,0 +1,97 @@ +/* + * FLV Encoding specific code. + * 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 "mpegvideo.h" +#include "h263.h" +#include "flv.h" + +void ff_flv_encode_picture_header(MpegEncContext * s, int picture_number) +{ + int format; + + 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 */ + put_bits(&s->pb, 8, (((int64_t)s->picture_number * 30 * s->avctx->time_base.num) / //FIXME use timestamp + s->avctx->time_base.den) & 0xff); /* TemporalReference */ + if (s->width == 352 && s->height == 288) + format = 2; + else if (s->width == 176 && s->height == 144) + format = 3; + else if (s->width == 128 && s->height == 96) + format = 4; + else if (s->width == 320 && s->height == 240) + format = 5; + else if (s->width == 160 && s->height == 120) + format = 6; + else if (s->width <= 255 && s->height <= 255) + format = 0; /* use 1 byte width & height */ + else + format = 1; /* use 2 bytes width & height */ + put_bits(&s->pb, 3, format); /* PictureSize */ + if (format == 0) { + put_bits(&s->pb, 8, s->width); + put_bits(&s->pb, 8, s->height); + } else if (format == 1) { + put_bits(&s->pb, 16, s->width); + put_bits(&s->pb, 16, s->height); + } + put_bits(&s->pb, 2, s->pict_type == FF_P_TYPE); /* PictureType */ + put_bits(&s->pb, 1, 1); /* DeblockingFlag: on */ + put_bits(&s->pb, 5, s->qscale); /* Quantizer */ + put_bits(&s->pb, 1, 0); /* ExtraInformation */ + + if(s->h263_aic){ + s->y_dc_scale_table= + s->c_dc_scale_table= ff_aic_dc_scale_table; + }else{ + s->y_dc_scale_table= + s->c_dc_scale_table= ff_mpeg1_dc_scale_table; + } +} + +void ff_flv2_encode_ac_esc(PutBitContext *pb, int slevel, int level, int run, int last){ + if(level < 64) { // 7-bit level + put_bits(pb, 1, 0); + put_bits(pb, 1, last); + put_bits(pb, 6, run); + + put_sbits(pb, 7, slevel); + } else { + /* 11-bit level */ + put_bits(pb, 1, 1); + put_bits(pb, 1, last); + put_bits(pb, 6, run); + + put_sbits(pb, 11, slevel); + } +} + +AVCodec flv_encoder = { + "flv", + AVMEDIA_TYPE_VIDEO, + CODEC_ID_FLV1, + sizeof(MpegEncContext), + MPV_encode_init, + MPV_encode_picture, + 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/src/add-ons/media/plugins/ffmpeg/libavcodec/fraps.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/fraps.c index da1bf0dd72..959ce92ea1 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/fraps.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/fraps.c @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/fraps.c + * @file * Lossless Fraps 'FPS1' decoder * @author Roine Gustafsson * @author Konstantin Shishkov @@ -366,7 +366,7 @@ static av_cold int decode_end(AVCodecContext *avctx) AVCodec fraps_decoder = { "fraps", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_FRAPS, sizeof(FrapsContext), decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/frwu.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/frwu.c new file mode 100644 index 0000000000..b685248b5f --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/frwu.c @@ -0,0 +1,123 @@ +/* + * Forward Uncompressed + * + * Copyright (c) 2009 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 "avcodec.h" +#include "bytestream.h" +#include "libavutil/intreadwrite.h" + +static av_cold int decode_init(AVCodecContext *avctx) +{ + if (avctx->width & 1) { + av_log(avctx, AV_LOG_ERROR, "FRWU needs even width\n"); + return -1; + } + avctx->pix_fmt = PIX_FMT_UYVY422; + + avctx->coded_frame = avcodec_alloc_frame(); + + return 0; +} + +static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, + AVPacket *avpkt) +{ + int field; + AVFrame *pic = avctx->coded_frame; + const uint8_t *buf = avpkt->data; + const uint8_t *buf_end = buf + avpkt->size; + + if (pic->data[0]) + avctx->release_buffer(avctx, pic); + + if (avpkt->size < avctx->width * 2 * avctx->height + 4 + 2*8) { + av_log(avctx, AV_LOG_ERROR, "Packet is too small.\n"); + return -1; + } + if (bytestream_get_le32(&buf) != AV_RL32("FRW1")) { + av_log(avctx, AV_LOG_ERROR, "incorrect marker\n"); + return -1; + } + + pic->reference = 0; + if (avctx->get_buffer(avctx, pic) < 0) + return -1; + + pic->pict_type = FF_I_TYPE; + pic->key_frame = 1; + pic->interlaced_frame = 1; + pic->top_field_first = 1; + + for (field = 0; field < 2; field++) { + int i; + int field_h = (avctx->height + !field) >> 1; + int field_size, min_field_size = avctx->width * 2 * field_h; + uint8_t *dst = pic->data[0]; + if (buf_end - buf < 8) + return -1; + buf += 4; // flags? 0x80 == bottom field maybe? + field_size = bytestream_get_le32(&buf); + if (field_size < min_field_size) { + av_log(avctx, AV_LOG_ERROR, "Field size %i is too small (required %i)\n", field_size, min_field_size); + return -1; + } + if (buf_end - buf < field_size) { + av_log(avctx, AV_LOG_ERROR, "Packet is too small, need %i, have %i\n", field_size, (int)(buf_end - buf)); + return -1; + } + if (field) + dst += pic->linesize[0]; + for (i = 0; i < field_h; i++) { + memcpy(dst, buf, avctx->width * 2); + buf += avctx->width * 2; + dst += pic->linesize[0] << 1; + } + buf += field_size - min_field_size; + } + + *data_size = sizeof(AVFrame); + *(AVFrame*)data = *pic; + + return avpkt->size; +} + +static av_cold int decode_close(AVCodecContext *avctx) +{ + AVFrame *pic = avctx->coded_frame; + if (pic->data[0]) + avctx->release_buffer(avctx, pic); + av_freep(&avctx->coded_frame); + + return 0; +} + +AVCodec frwu_decoder = { + "FRWU", + AVMEDIA_TYPE_VIDEO, + CODEC_ID_FRWU, + 0, + decode_init, + NULL, + decode_close, + decode_frame, + CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Forward Uncompressed"), +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/g726.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/g726.c index 3004041b08..5e0051171b 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/g726.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/g726.c @@ -387,21 +387,21 @@ static int g726_decode_frame(AVCodecContext *avctx, #if CONFIG_ADPCM_G726_ENCODER AVCodec adpcm_g726_encoder = { "g726", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_ADPCM_G726, sizeof(G726Context), g726_init, g726_encode_frame, g726_close, NULL, - .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, + .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, .long_name = NULL_IF_CONFIG_SMALL("G.726 ADPCM"), }; #endif AVCodec adpcm_g726_decoder = { "g726", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_ADPCM_G726, sizeof(G726Context), g726_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/g729dec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/g729dec.c index bebad4aa2e..3a6fb0fb7a 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/g729dec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/g729dec.c @@ -171,7 +171,7 @@ static av_cold int decoder_init(AVCodecContext * avctx) if (avctx->channels != 1) { av_log(avctx, AV_LOG_ERROR, "Only mono sound is supported (requested channels: %d).\n", avctx->channels); - return AVERROR_NOFMT; + return AVERROR(EINVAL); } /* Both 8kbit/s and 6.4kbit/s modes uses two subframes per frame. */ @@ -224,7 +224,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, 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); - return (AVERROR_NOFMT); + return AVERROR_INVALIDDATA; } for (i=0; i < buf_size; i++) @@ -315,7 +315,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVCodec g729_decoder = { "g729", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_G729, sizeof(G729Context), decoder_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/get_bits.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/get_bits.h index 877f909a74..556f542e69 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/get_bits.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/get_bits.h @@ -19,7 +19,7 @@ */ /** - * @file libavcodec/get_bits.h + * @file * bitstream reader API header. */ @@ -40,7 +40,7 @@ #endif #if !defined(LIBMPEG2_BITSTREAM_READER) && !defined(A32_BITSTREAM_READER) && !defined(ALT_BITSTREAM_READER) -# if ARCH_ARM +# if ARCH_ARM && !HAVE_FAST_UNALIGNED # define A32_BITSTREAM_READER # else # define ALT_BITSTREAM_READER @@ -49,29 +49,6 @@ # endif #endif -extern const uint8_t ff_reverse[256]; - -#if ARCH_X86 -// avoid +32 for shift optimization (gcc should do that ...) -static inline int32_t NEG_SSR32( int32_t a, int8_t s){ - __asm__ ("sarl %1, %0\n\t" - : "+r" (a) - : "ic" ((uint8_t)(-s)) - ); - return a; -} -static inline uint32_t NEG_USR32(uint32_t a, int8_t s){ - __asm__ ("shrl %1, %0\n\t" - : "+r" (a) - : "ic" ((uint8_t)(-s)) - ); - return a; -} -#else -# define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s))) -# define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s))) -#endif - /* bit input */ /* buffer, buffer_end and size_in_bits must be present and used by every reader */ typedef struct GetBitContext { @@ -145,7 +122,7 @@ LAST_SKIP_CACHE(name, gb, num) will remove the next num bits from the cache if it is needed for UPDATE_CACHE otherwise it will do nothing LAST_SKIP_BITS(name, gb, num) - is equivalent to SKIP_LAST_CACHE; SKIP_COUNTER + is equivalent to LAST_SKIP_CACHE; SKIP_COUNTER for examples see get_bits, show_bits, skip_bits, get_vlc */ @@ -154,7 +131,7 @@ for examples see get_bits, show_bits, skip_bits, get_vlc # define MIN_CACHE_BITS 25 # define OPEN_READER(name, gb)\ - int name##_index= (gb)->index;\ + unsigned int name##_index= (gb)->index;\ int name##_cache= 0;\ # define CLOSE_READER(name, gb)\ @@ -189,10 +166,10 @@ for examples see get_bits, show_bits, skip_bits, get_vlc # ifdef ALT_BITSTREAM_READER_LE # define SHOW_UBITS(name, gb, num)\ - ((name##_cache) & (NEG_USR32(0xffffffff,num))) + zero_extend(name##_cache, num) # define SHOW_SBITS(name, gb, num)\ - NEG_SSR32((name##_cache)<<(32-(num)), num) + sign_extend(name##_cache, num) # else # define SHOW_UBITS(name, gb, num)\ NEG_USR32(name##_cache, num) @@ -204,7 +181,7 @@ for examples see get_bits, show_bits, skip_bits, get_vlc # define GET_CACHE(name, gb)\ ((uint32_t)name##_cache) -static inline int get_bits_count(GetBitContext *s){ +static inline int get_bits_count(const GetBitContext *s){ return s->index; } @@ -258,7 +235,7 @@ static inline void skip_bits_long(GetBitContext *s, int n){ # define GET_CACHE(name, gb)\ ((uint32_t)name##_cache) -static inline int get_bits_count(GetBitContext *s){ +static inline int get_bits_count(const GetBitContext *s){ return (s->buffer_ptr - s->buffer)*8 - 16 + s->bit_count; } @@ -333,7 +310,7 @@ static inline void skip_bits_long(GetBitContext *s, int n){ # define GET_CACHE(name, gb)\ (name##_cache0) -static inline int get_bits_count(GetBitContext *s){ +static inline int get_bits_count(const GetBitContext *s){ return ((uint8_t*)s->buffer_ptr - s->buffer)*8 - 32 + s->bit_count; } @@ -415,7 +392,7 @@ static inline void skip_bits(GetBitContext *s, int n){ static inline unsigned int get_bits1(GetBitContext *s){ #ifdef ALT_BITSTREAM_READER - int index= s->index; + unsigned int index= s->index; uint8_t result= s->buffer[ index>>3 ]; #ifdef ALT_BITSTREAM_READER_LE result>>= (index&0x07); @@ -445,7 +422,7 @@ static inline void skip_bits1(GetBitContext *s){ * reads 0-32 bits. */ static inline unsigned int get_bits_long(GetBitContext *s, int n){ - if(n<=17) return get_bits(s, n); + if(n<=MIN_CACHE_BITS) return get_bits(s, n); else{ #ifdef ALT_BITSTREAM_READER_LE int ret= get_bits(s, 16); @@ -468,7 +445,7 @@ static inline int get_sbits_long(GetBitContext *s, int n) { * shows 0-32 bits. */ static inline unsigned int show_bits_long(GetBitContext *s, int n){ - if(n<=17) return show_bits(s, n); + if(n<=MIN_CACHE_BITS) return show_bits(s, n); else{ GetBitContext gb= *s; return get_bits_long(&gb, n); @@ -489,6 +466,9 @@ static inline int check_marker(GetBitContext *s, const char *msg) * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger then the actual read bits * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end * @param bit_size the size of the buffer in bits + * + * While GetBitContext stores the buffer size, for performance reasons you are + * responsible for checking for the buffer end yourself (take advantage of the padding)! */ static inline void init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size) @@ -535,7 +515,6 @@ int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, const void *codes, int codes_wrap, int codes_size, const void *symbols, int symbols_wrap, int symbols_size, int flags); -#define INIT_VLC_USE_STATIC 1 ///< VERY strongly deprecated and forbidden #define INIT_VLC_LE 2 #define INIT_VLC_USE_NEW_STATIC 4 void free_vlc(VLC *vlc); @@ -551,13 +530,14 @@ void free_vlc(VLC *vlc); /** * - * if the vlc code is invalid and max_depth=1 than no bits will be removed - * if the vlc code is invalid and max_depth>1 than the number of bits removed - * is undefined + * If the vlc code is invalid and max_depth=1, then no bits will be removed. + * If the vlc code is invalid and max_depth>1, then the number of bits removed + * is undefined. */ #define GET_VLC(code, name, gb, table, bits, max_depth)\ {\ - int n, index, nb_bits;\ + int n, nb_bits;\ + unsigned int index;\ \ index= SHOW_UBITS(name, gb, bits);\ code = table[index][0];\ @@ -588,7 +568,8 @@ void free_vlc(VLC *vlc); #define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)\ {\ - int n, index, nb_bits;\ + int n, nb_bits;\ + unsigned int index;\ \ index= SHOW_UBITS(name, gb, bits);\ level = table[index].level;\ @@ -702,4 +683,9 @@ static inline int decode210(GetBitContext *gb){ return 2 - get_bits1(gb); } +static inline int get_bits_left(GetBitContext *gb) +{ + return gb->size_in_bits - get_bits_count(gb); +} + #endif /* AVCODEC_GET_BITS_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/gif.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/gif.c index 8cd51c5b74..5114b89226 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/gif.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/gif.c @@ -43,6 +43,7 @@ #include "avcodec.h" #include "bytestream.h" +#include "lzw.h" /* The GIF format uses reversed order for bitstreams... */ /* at least they don't use PDP_ENDIAN :) */ @@ -50,21 +51,23 @@ #include "put_bits.h" -/* bitstream minipacket size */ -#define GIF_CHUNKS 100 +typedef struct { + AVFrame picture; + LZWState *lzw; + uint8_t *buf; +} GIFContext; /* GIF header */ -static int gif_image_write_header(uint8_t **bytestream, - int width, int height, - uint32_t *palette) +static int gif_image_write_header(AVCodecContext *avctx, + uint8_t **bytestream, uint32_t *palette) { int i; unsigned int v; bytestream_put_buffer(bytestream, "GIF", 3); bytestream_put_buffer(bytestream, "89a", 3); - bytestream_put_le16(bytestream, width); - bytestream_put_le16(bytestream, height); + bytestream_put_le16(bytestream, avctx->width); + bytestream_put_le16(bytestream, avctx->height); bytestream_put_byte(bytestream, 0xf7); /* flags: global clut, 256 entries */ bytestream_put_byte(bytestream, 0x1f); /* background color index */ @@ -79,74 +82,61 @@ static int gif_image_write_header(uint8_t **bytestream, return 0; } -static int gif_image_write_image(uint8_t **bytestream, - int x1, int y1, int width, int height, - const uint8_t *buf, int linesize, int pix_fmt) +static int gif_image_write_image(AVCodecContext *avctx, + uint8_t **bytestream, uint8_t *end, + const uint8_t *buf, int linesize) { - PutBitContext p; - uint8_t buffer[200]; /* 100 * 9 / 8 = 113 */ - int i, left, w; + GIFContext *s = avctx->priv_data; + int len, height; const uint8_t *ptr; /* image block */ bytestream_put_byte(bytestream, 0x2c); - bytestream_put_le16(bytestream, x1); - bytestream_put_le16(bytestream, y1); - bytestream_put_le16(bytestream, width); - bytestream_put_le16(bytestream, height); + bytestream_put_le16(bytestream, 0); + bytestream_put_le16(bytestream, 0); + bytestream_put_le16(bytestream, avctx->width); + bytestream_put_le16(bytestream, avctx->height); bytestream_put_byte(bytestream, 0x00); /* flags */ /* no local clut */ bytestream_put_byte(bytestream, 0x08); - left= width * height; + ff_lzw_encode_init(s->lzw, s->buf, avctx->width*avctx->height, + 12, FF_LZW_GIF, put_bits); - init_put_bits(&p, buffer, 130); - -/* - * the thing here is the bitstream is written as little packets, with a size byte before - * but it's still the same bitstream between packets (no flush !) - */ ptr = buf; - w = width; - while(left>0) { + for (height = avctx->height; height--;) { + len += ff_lzw_encode(s->lzw, ptr, avctx->width); + ptr += linesize; + } + len += ff_lzw_encode_flush(s->lzw, flush_put_bits); - put_bits(&p, 9, 0x0100); /* clear code */ - - for(i=(left 0) { - bytestream_put_byte(bytestream, put_bits_ptr(&p) - p.buf); /* byte count of the packet */ - bytestream_put_buffer(bytestream, p.buf, put_bits_ptr(&p) - p.buf); /* the actual buffer */ - p.buf_ptr = p.buf; /* dequeue the bytes off the bitstream */ - } - left-=GIF_CHUNKS; + ptr = s->buf; + while (len > 0) { + int size = FFMIN(255, len); + bytestream_put_byte(bytestream, size); + if (end - *bytestream < size) + return -1; + bytestream_put_buffer(bytestream, ptr, size); + ptr += size; + len -= size; } bytestream_put_byte(bytestream, 0x00); /* end of image block */ bytestream_put_byte(bytestream, 0x3b); return 0; } -typedef struct { - AVFrame picture; -} GIFContext; - static av_cold int gif_encode_init(AVCodecContext *avctx) { GIFContext *s = avctx->priv_data; avctx->coded_frame = &s->picture; + s->lzw = av_mallocz(ff_lzw_encode_state_size); + if (!s->lzw) + return AVERROR(ENOMEM); + s->buf = av_malloc(avctx->width*avctx->height*2); + if (!s->buf) + return AVERROR(ENOMEM); return 0; } @@ -157,23 +147,33 @@ static int gif_encode_frame(AVCodecContext *avctx, unsigned char *outbuf, int bu AVFrame *pict = data; AVFrame *const p = (AVFrame *)&s->picture; uint8_t *outbuf_ptr = outbuf; + uint8_t *end = outbuf + buf_size; *p = *pict; p->pict_type = FF_I_TYPE; p->key_frame = 1; - gif_image_write_header(&outbuf_ptr, avctx->width, avctx->height, (uint32_t *)pict->data[1]); - gif_image_write_image(&outbuf_ptr, 0, 0, avctx->width, avctx->height, pict->data[0], pict->linesize[0], PIX_FMT_PAL8); + gif_image_write_header(avctx, &outbuf_ptr, (uint32_t *)pict->data[1]); + gif_image_write_image(avctx, &outbuf_ptr, end, pict->data[0], pict->linesize[0]); return outbuf_ptr - outbuf; } +static int gif_encode_close(AVCodecContext *avctx) +{ + GIFContext *s = avctx->priv_data; + + av_freep(&s->lzw); + av_freep(&s->buf); + return 0; +} + AVCodec gif_encoder = { "gif", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_GIF, sizeof(GIFContext), gif_encode_init, gif_encode_frame, - NULL, //encode_end, - .pix_fmts= (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}, + 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/src/add-ons/media/plugins/ffmpeg/libavcodec/gifdec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/gifdec.c index 70da4e2a57..1daf1b7b1a 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/gifdec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/gifdec.c @@ -328,7 +328,7 @@ static av_cold int gif_decode_close(AVCodecContext *avctx) AVCodec gif_decoder = { "gif", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_GIF, sizeof(GifState), gif_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/golomb.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/golomb.c index ac9d8370cf..611598c6f1 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/golomb.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/golomb.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/golomb.c + * @file * @brief * exp golomb vlc stuff * @author Michael Niedermayer diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/golomb.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/golomb.h index 7044042c95..90eeb30b54 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/golomb.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/golomb.h @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/golomb.h + * @file * @brief * exp golomb vlc stuff * @author Michael Niedermayer and Alex Beregszaszi @@ -253,8 +253,12 @@ static inline int get_ur_golomb(GetBitContext *gb, int k, int limit, int esc_len return buf; }else{ - buf >>= 32 - limit - esc_len; - LAST_SKIP_BITS(re, gb, esc_len + limit); + LAST_SKIP_BITS(re, gb, limit); + UPDATE_CACHE(re, gb); + + buf = SHOW_UBITS(re, gb, esc_len); + + LAST_SKIP_BITS(re, gb, esc_len); CLOSE_READER(re, gb); return buf + limit - 1; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/h261.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/h261.c index 6093853f7c..562a151e90 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/h261.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/h261.c @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/h261.c + * @file * h261codec. */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/h261.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/h261.h index 43687d71e0..5b60dd65a3 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/h261.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/h261.h @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/h261.c + * @file * h261codec. */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/h261_parser.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/h261_parser.c index 47644b69b8..c32300d6ed 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/h261_parser.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/h261_parser.c @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/h261_parser.c + * @file * h261codec. */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/h261data.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/h261data.h index 81637aa70b..82bae163df 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/h261data.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/h261data.h @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/h261data.h + * @file * H.261 tables. */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/h261dec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/h261dec.c index d5dcc0b2c4..bb5f27d503 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/h261dec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/h261dec.c @@ -21,13 +21,14 @@ */ /** - * @file libavcodec/h261dec.c + * @file * H.261 decoder. */ #include "dsputil.h" #include "avcodec.h" #include "mpegvideo.h" +#include "h263.h" #include "h261.h" #include "h261data.h" @@ -170,7 +171,7 @@ static int ff_h261_resync(H261Context *h){ //OK, it is not where it is supposed to be ... s->gb= s->last_resync_gb; align_get_bits(&s->gb); - left= s->gb.size_in_bits - get_bits_count(&s->gb); + left= get_bits_left(&s->gb); for(;left>15+1+4+5; left-=8){ if(show_bits(&s->gb, 15)==0){ @@ -444,7 +445,7 @@ static int h261_decode_picture_header(H261Context *h){ int format, i; uint32_t startcode= 0; - for(i= s->gb.size_in_bits - get_bits_count(&s->gb); i>24; i-=1){ + for(i= get_bits_left(&s->gb); i>24; i-=1){ startcode = ((startcode << 1) | get_bits(&s->gb, 1)) & 0x000FFFFF; if(startcode == 0x10) @@ -642,7 +643,7 @@ static av_cold int h261_decode_end(AVCodecContext *avctx) AVCodec h261_decoder = { "h261", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_H261, sizeof(H261Context), h261_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/h261enc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/h261enc.c index af8969e031..d3f2219f69 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/h261enc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/h261enc.c @@ -21,13 +21,14 @@ */ /** - * @file libavcodec/h261enc.c + * @file * H.261 encoder. */ #include "dsputil.h" #include "avcodec.h" #include "mpegvideo.h" +#include "h263.h" #include "h261.h" #include "h261data.h" @@ -322,13 +323,13 @@ static void h261_encode_block(H261Context * h, DCTELEM * block, int n){ AVCodec h261_encoder = { "h261", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_H261, sizeof(H261Context), MPV_encode_init, MPV_encode_picture, MPV_encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, .long_name= NULL_IF_CONFIG_SMALL("H.261"), }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/h263.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/h263.c index a8c03339e6..50ea6ce2b8 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/h263.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/h263.c @@ -5,10 +5,6 @@ * Copyright (c) 2001 Juan J. Sierralta P * Copyright (c) 2002-2004 Michael Niedermayer * - * ac prediction encoding, B-frame support, error resilience, optimizations, - * qpel decoding, gmc decoding, interlaced decoding - * by Michael Niedermayer - * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or @@ -27,7 +23,7 @@ */ /** - * @file libavcodec/h263.c + * @file * h263/mpeg4 codec. */ @@ -37,651 +33,18 @@ #include "dsputil.h" #include "avcodec.h" #include "mpegvideo.h" +#include "h263.h" #include "h263data.h" -#include "mpeg4data.h" #include "mathops.h" #include "unary.h" +#include "flv.h" +#include "mpeg4video.h" //#undef NDEBUG //#include -#define INTRA_MCBPC_VLC_BITS 6 -#define INTER_MCBPC_VLC_BITS 7 -#define CBPY_VLC_BITS 6 -#define MV_VLC_BITS 9 -#define DC_VLC_BITS 9 -#define SPRITE_TRAJ_VLC_BITS 6 -#define MB_TYPE_B_VLC_BITS 4 -#define TEX_VLC_BITS 9 -#define H263_MBTYPE_B_VLC_BITS 6 -#define CBPC_B_VLC_BITS 3 +uint8_t ff_h263_static_rl_table_store[2][2][2*MAX_RUN + MAX_LEVEL + 3]; -static void h263_encode_block(MpegEncContext * s, DCTELEM * block, - int n); -static void h263p_encode_umotion(MpegEncContext * s, int val); -static inline void mpeg4_encode_block(MpegEncContext * s, DCTELEM * block, - int n, int dc, uint8_t *scan_table, - PutBitContext *dc_pb, PutBitContext *ac_pb); -static int mpeg4_get_block_length(MpegEncContext * s, DCTELEM * block, int n, int intra_dc, - uint8_t *scan_table); - -static int h263_decode_motion(MpegEncContext * s, int pred, int fcode); -static int h263p_decode_umotion(MpegEncContext * s, int pred); -static int h263_decode_block(MpegEncContext * s, DCTELEM * block, - int n, int coded); -static inline int mpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr); -static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block, - int n, int coded, int intra, int rvlc); - -static int h263_pred_dc(MpegEncContext * s, int n, int16_t **dc_val_ptr); -static void mpeg4_encode_visual_object_header(MpegEncContext * s); -static void mpeg4_encode_vol_header(MpegEncContext * s, int vo_number, int vol_number); - -static void mpeg4_decode_sprite_trajectory(MpegEncContext * s, GetBitContext *gb); -static inline int ff_mpeg4_pred_dc(MpegEncContext * s, int n, int level, int *dir_ptr, int encoding); - -#if CONFIG_ENCODERS -static uint8_t uni_DCtab_lum_len[512]; -static uint8_t uni_DCtab_chrom_len[512]; -static uint16_t uni_DCtab_lum_bits[512]; -static uint16_t uni_DCtab_chrom_bits[512]; - -static uint8_t mv_penalty[MAX_FCODE+1][MAX_MV*2+1]; -static uint8_t fcode_tab[MAX_MV*2+1]; -static uint8_t umv_fcode_tab[MAX_MV*2+1]; - -static uint32_t uni_mpeg4_intra_rl_bits[64*64*2*2]; -static uint8_t uni_mpeg4_intra_rl_len [64*64*2*2]; -static uint32_t uni_mpeg4_inter_rl_bits[64*64*2*2]; -static uint8_t uni_mpeg4_inter_rl_len [64*64*2*2]; -static uint8_t uni_h263_intra_aic_rl_len [64*64*2*2]; -static uint8_t uni_h263_inter_rl_len [64*64*2*2]; -//#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128 + (run)*256 + (level)) -//#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128*64 + (run) + (level)*64) -#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128*64 + (run)*128 + (level)) - -/* mpeg4 -inter -max level: 24/6 -max run: 53/63 - -intra -max level: 53/16 -max run: 29/41 -*/ -#endif - -static uint8_t static_rl_table_store[5][2][2*MAX_RUN + MAX_LEVEL + 3]; - -#if 0 //3IV1 is quite rare and it slows things down a tiny bit -#define IS_3IV1 s->codec_tag == AV_RL32("3IV1") -#else -#define IS_3IV1 0 -#endif - -int h263_get_picture_format(int width, int height) -{ - int format; - - if (width == 128 && height == 96) - format = 1; - else if (width == 176 && height == 144) - format = 2; - else if (width == 352 && height == 288) - format = 3; - else if (width == 704 && height == 576) - format = 4; - else if (width == 1408 && height == 1152) - format = 5; - else - format = 7; - return format; -} - -static void show_pict_info(MpegEncContext *s){ - av_log(s->avctx, AV_LOG_DEBUG, "qp:%d %c size:%d rnd:%d%s%s%s%s%s%s%s%s%s %d/%d\n", - s->qscale, av_get_pict_type_char(s->pict_type), - s->gb.size_in_bits, 1-s->no_rounding, - s->obmc ? " AP" : "", - s->umvplus ? " UMV" : "", - s->h263_long_vectors ? " LONG" : "", - s->h263_plus ? " +" : "", - s->h263_aic ? " AIC" : "", - s->alt_inter_vlc ? " AIV" : "", - s->modified_quant ? " MQ" : "", - s->loop_filter ? " LOOP" : "", - s->h263_slice_structured ? " SS" : "", - s->avctx->time_base.den, s->avctx->time_base.num - ); -} - -#if CONFIG_ENCODERS - -static void aspect_to_info(MpegEncContext * s, AVRational aspect){ - int i; - - if(aspect.num==0) aspect= (AVRational){1,1}; - - for(i=1; i<6; i++){ - if(av_cmp_q(pixel_aspect[i], aspect) == 0){ - s->aspect_ratio_info=i; - return; - } - } - - s->aspect_ratio_info= FF_ASPECT_EXTENDED; -} - -void ff_flv_encode_picture_header(MpegEncContext * s, int picture_number) -{ - int format; - - 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 */ - put_bits(&s->pb, 8, (((int64_t)s->picture_number * 30 * s->avctx->time_base.num) / //FIXME use timestamp - s->avctx->time_base.den) & 0xff); /* TemporalReference */ - if (s->width == 352 && s->height == 288) - format = 2; - else if (s->width == 176 && s->height == 144) - format = 3; - else if (s->width == 128 && s->height == 96) - format = 4; - else if (s->width == 320 && s->height == 240) - format = 5; - else if (s->width == 160 && s->height == 120) - format = 6; - else if (s->width <= 255 && s->height <= 255) - format = 0; /* use 1 byte width & height */ - else - format = 1; /* use 2 bytes width & height */ - put_bits(&s->pb, 3, format); /* PictureSize */ - if (format == 0) { - put_bits(&s->pb, 8, s->width); - put_bits(&s->pb, 8, s->height); - } else if (format == 1) { - put_bits(&s->pb, 16, s->width); - put_bits(&s->pb, 16, s->height); - } - put_bits(&s->pb, 2, s->pict_type == FF_P_TYPE); /* PictureType */ - put_bits(&s->pb, 1, 1); /* DeblockingFlag: on */ - put_bits(&s->pb, 5, s->qscale); /* Quantizer */ - put_bits(&s->pb, 1, 0); /* ExtraInformation */ - - if(s->h263_aic){ - s->y_dc_scale_table= - s->c_dc_scale_table= ff_aic_dc_scale_table; - }else{ - s->y_dc_scale_table= - s->c_dc_scale_table= ff_mpeg1_dc_scale_table; - } -} - -void h263_encode_picture_header(MpegEncContext * s, int picture_number) -{ - int format, coded_frame_rate, coded_frame_rate_base, i, temp_ref; - int best_clock_code=1; - int best_divisor=60; - int best_error= INT_MAX; - - if(s->h263_plus){ - for(i=0; i<2; i++){ - int div, error; - div= (s->avctx->time_base.num*1800000LL + 500LL*s->avctx->time_base.den) / ((1000LL+i)*s->avctx->time_base.den); - div= av_clip(div, 1, 127); - error= FFABS(s->avctx->time_base.num*1800000LL - (1000LL+i)*s->avctx->time_base.den*div); - if(error < best_error){ - best_error= error; - best_divisor= div; - best_clock_code= i; - } - } - } - s->custom_pcf= best_clock_code!=1 || best_divisor!=60; - coded_frame_rate= 1800000; - coded_frame_rate_base= (1000+best_clock_code)*best_divisor; - - align_put_bits(&s->pb); - - /* Update the pointer to last GOB */ - s->ptr_lastgob = put_bits_ptr(&s->pb); - put_bits(&s->pb, 22, 0x20); /* PSC */ - temp_ref= s->picture_number * (int64_t)coded_frame_rate * s->avctx->time_base.num / //FIXME use timestamp - (coded_frame_rate_base * (int64_t)s->avctx->time_base.den); - put_sbits(&s->pb, 8, temp_ref); /* TemporalReference */ - - put_bits(&s->pb, 1, 1); /* marker */ - put_bits(&s->pb, 1, 0); /* h263 id */ - put_bits(&s->pb, 1, 0); /* split screen off */ - put_bits(&s->pb, 1, 0); /* camera off */ - put_bits(&s->pb, 1, 0); /* freeze picture release off */ - - format = h263_get_picture_format(s->width, s->height); - if (!s->h263_plus) { - /* H.263v1 */ - put_bits(&s->pb, 3, format); - put_bits(&s->pb, 1, (s->pict_type == FF_P_TYPE)); - /* By now UMV IS DISABLED ON H.263v1, since the restrictions - of H.263v1 UMV implies to check the predicted MV after - calculation of the current MB to see if we're on the limits */ - put_bits(&s->pb, 1, 0); /* Unrestricted Motion Vector: off */ - put_bits(&s->pb, 1, 0); /* SAC: off */ - put_bits(&s->pb, 1, s->obmc); /* Advanced Prediction */ - put_bits(&s->pb, 1, 0); /* only I/P frames, no PB frame */ - put_bits(&s->pb, 5, s->qscale); - put_bits(&s->pb, 1, 0); /* Continuous Presence Multipoint mode: off */ - } else { - int ufep=1; - /* H.263v2 */ - /* H.263 Plus PTYPE */ - - put_bits(&s->pb, 3, 7); - put_bits(&s->pb,3,ufep); /* Update Full Extended PTYPE */ - if (format == 7) - put_bits(&s->pb,3,6); /* Custom Source Format */ - else - put_bits(&s->pb, 3, format); - - put_bits(&s->pb,1, s->custom_pcf); - put_bits(&s->pb,1, s->umvplus); /* Unrestricted Motion Vector */ - put_bits(&s->pb,1,0); /* SAC: off */ - put_bits(&s->pb,1,s->obmc); /* Advanced Prediction Mode */ - put_bits(&s->pb,1,s->h263_aic); /* Advanced Intra Coding */ - put_bits(&s->pb,1,s->loop_filter); /* Deblocking Filter */ - put_bits(&s->pb,1,s->h263_slice_structured); /* Slice Structured */ - put_bits(&s->pb,1,0); /* Reference Picture Selection: off */ - put_bits(&s->pb,1,0); /* Independent Segment Decoding: off */ - put_bits(&s->pb,1,s->alt_inter_vlc); /* Alternative Inter VLC */ - put_bits(&s->pb,1,s->modified_quant); /* Modified Quantization: */ - put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */ - put_bits(&s->pb,3,0); /* Reserved */ - - put_bits(&s->pb, 3, s->pict_type == FF_P_TYPE); - - put_bits(&s->pb,1,0); /* Reference Picture Resampling: off */ - put_bits(&s->pb,1,0); /* Reduced-Resolution Update: off */ - put_bits(&s->pb,1,s->no_rounding); /* Rounding Type */ - put_bits(&s->pb,2,0); /* Reserved */ - put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */ - - /* This should be here if PLUSPTYPE */ - put_bits(&s->pb, 1, 0); /* Continuous Presence Multipoint mode: off */ - - if (format == 7) { - /* Custom Picture Format (CPFMT) */ - aspect_to_info(s, s->avctx->sample_aspect_ratio); - - put_bits(&s->pb,4,s->aspect_ratio_info); - put_bits(&s->pb,9,(s->width >> 2) - 1); - put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */ - put_bits(&s->pb,9,(s->height >> 2)); - if (s->aspect_ratio_info == FF_ASPECT_EXTENDED){ - put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.num); - put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.den); - } - } - if(s->custom_pcf){ - if(ufep){ - put_bits(&s->pb, 1, best_clock_code); - put_bits(&s->pb, 7, best_divisor); - } - put_sbits(&s->pb, 2, temp_ref>>8); - } - - /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ - if (s->umvplus) -// put_bits(&s->pb,1,1); /* Limited according tables of Annex D */ -//FIXME check actual requested range - put_bits(&s->pb,2,1); /* unlimited */ - if(s->h263_slice_structured) - put_bits(&s->pb,2,0); /* no weird submodes */ - - put_bits(&s->pb, 5, s->qscale); - } - - put_bits(&s->pb, 1, 0); /* no PEI */ - - if(s->h263_slice_structured){ - put_bits(&s->pb, 1, 1); - - assert(s->mb_x == 0 && s->mb_y == 0); - ff_h263_encode_mba(s); - - put_bits(&s->pb, 1, 1); - } - - if(s->h263_aic){ - s->y_dc_scale_table= - s->c_dc_scale_table= ff_aic_dc_scale_table; - }else{ - s->y_dc_scale_table= - s->c_dc_scale_table= ff_mpeg1_dc_scale_table; - } -} - -/** - * Encodes a group of blocks header. - */ -void h263_encode_gob_header(MpegEncContext * s, int mb_line) -{ - put_bits(&s->pb, 17, 1); /* GBSC */ - - if(s->h263_slice_structured){ - put_bits(&s->pb, 1, 1); - - ff_h263_encode_mba(s); - - if(s->mb_num > 1583) - put_bits(&s->pb, 1, 1); - put_bits(&s->pb, 5, s->qscale); /* GQUANT */ - put_bits(&s->pb, 1, 1); - put_bits(&s->pb, 2, s->pict_type == FF_I_TYPE); /* GFID */ - }else{ - int gob_number= mb_line / s->gob_index; - - put_bits(&s->pb, 5, gob_number); /* GN */ - put_bits(&s->pb, 2, s->pict_type == FF_I_TYPE); /* GFID */ - put_bits(&s->pb, 5, s->qscale); /* GQUANT */ - } -} - -static inline int get_block_rate(MpegEncContext * s, DCTELEM block[64], int block_last_index, uint8_t scantable[64]){ - int last=0; - int j; - int rate=0; - - for(j=1; j<=block_last_index; j++){ - const int index= scantable[j]; - int level= block[index]; - if(level){ - level+= 64; - if((level&(~127)) == 0){ - if(jintra_ac_vlc_length [UNI_AC_ENC_INDEX(j-last-1, level)]; - else rate+= s->intra_ac_vlc_last_length[UNI_AC_ENC_INDEX(j-last-1, level)]; - }else - rate += s->ac_esc_length; - - last= j; - } - } - - return rate; -} - -static inline int decide_ac_pred(MpegEncContext * s, DCTELEM block[6][64], int dir[6], uint8_t *st[6], int zigzag_last_index[6]) -{ - int score= 0; - int i, n; - int8_t * const qscale_table= s->current_picture.qscale_table; - - memcpy(zigzag_last_index, s->block_last_index, sizeof(int)*6); - - for(n=0; n<6; n++){ - int16_t *ac_val, *ac_val1; - - score -= get_block_rate(s, block[n], s->block_last_index[n], s->intra_scantable.permutated); - - ac_val = s->ac_val[0][0] + s->block_index[n] * 16; - ac_val1= ac_val; - if(dir[n]){ - const int xy= s->mb_x + s->mb_y*s->mb_stride - s->mb_stride; - /* top prediction */ - ac_val-= s->block_wrap[n]*16; - if(s->mb_y==0 || s->qscale == qscale_table[xy] || n==2 || n==3){ - /* same qscale */ - for(i=1; i<8; i++){ - const int level= block[n][s->dsp.idct_permutation[i ]]; - block[n][s->dsp.idct_permutation[i ]] = level - ac_val[i+8]; - ac_val1[i ]= block[n][s->dsp.idct_permutation[i<<3]]; - ac_val1[i+8]= level; - } - }else{ - /* different qscale, we must rescale */ - for(i=1; i<8; i++){ - const int level= block[n][s->dsp.idct_permutation[i ]]; - block[n][s->dsp.idct_permutation[i ]] = level - ROUNDED_DIV(ac_val[i + 8]*qscale_table[xy], s->qscale); - ac_val1[i ]= block[n][s->dsp.idct_permutation[i<<3]]; - ac_val1[i+8]= level; - } - } - st[n]= s->intra_h_scantable.permutated; - }else{ - const int xy= s->mb_x-1 + s->mb_y*s->mb_stride; - /* left prediction */ - ac_val-= 16; - if(s->mb_x==0 || s->qscale == qscale_table[xy] || n==1 || n==3){ - /* same qscale */ - for(i=1; i<8; i++){ - const int level= block[n][s->dsp.idct_permutation[i<<3]]; - block[n][s->dsp.idct_permutation[i<<3]]= level - ac_val[i]; - ac_val1[i ]= level; - ac_val1[i+8]= block[n][s->dsp.idct_permutation[i ]]; - } - }else{ - /* different qscale, we must rescale */ - for(i=1; i<8; i++){ - const int level= block[n][s->dsp.idct_permutation[i<<3]]; - block[n][s->dsp.idct_permutation[i<<3]]= level - ROUNDED_DIV(ac_val[i]*qscale_table[xy], s->qscale); - ac_val1[i ]= level; - ac_val1[i+8]= block[n][s->dsp.idct_permutation[i ]]; - } - } - st[n]= s->intra_v_scantable.permutated; - } - - for(i=63; i>0; i--) //FIXME optimize - if(block[n][ st[n][i] ]) break; - s->block_last_index[n]= i; - - score += get_block_rate(s, block[n], s->block_last_index[n], st[n]); - } - - return score < 0; -} - -static inline void restore_ac_coeffs(MpegEncContext * s, DCTELEM block[6][64], int dir[6], uint8_t *st[6], int zigzag_last_index[6]) -{ - int i, n; - memcpy(s->block_last_index, zigzag_last_index, sizeof(int)*6); - - for(n=0; n<6; n++){ - int16_t *ac_val = s->ac_val[0][0] + s->block_index[n] * 16; - - st[n]= s->intra_scantable.permutated; - if(dir[n]){ - /* top prediction */ - for(i=1; i<8; i++){ - block[n][s->dsp.idct_permutation[i ]] = ac_val[i+8]; - } - }else{ - /* left prediction */ - for(i=1; i<8; i++){ - block[n][s->dsp.idct_permutation[i<<3]]= ac_val[i ]; - } - } - } -} - -/** - * init s->current_picture.qscale_table from s->lambda_table - */ -static void ff_init_qscale_tab(MpegEncContext *s){ - int8_t * const qscale_table= s->current_picture.qscale_table; - int i; - - for(i=0; imb_num; i++){ - unsigned int lam= s->lambda_table[ s->mb_index2xy[i] ]; - int qp= (lam*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7); - qscale_table[ s->mb_index2xy[i] ]= av_clip(qp, s->avctx->qmin, s->avctx->qmax); - } -} - -/** - * modify qscale so that encoding is acually possible in h263 (limit difference to -2..2) - */ -void ff_clean_h263_qscales(MpegEncContext *s){ - int i; - int8_t * const qscale_table= s->current_picture.qscale_table; - - ff_init_qscale_tab(s); - - for(i=1; imb_num; i++){ - if(qscale_table[ s->mb_index2xy[i] ] - qscale_table[ s->mb_index2xy[i-1] ] >2) - qscale_table[ s->mb_index2xy[i] ]= qscale_table[ s->mb_index2xy[i-1] ]+2; - } - for(i=s->mb_num-2; i>=0; i--){ - if(qscale_table[ s->mb_index2xy[i] ] - qscale_table[ s->mb_index2xy[i+1] ] >2) - qscale_table[ s->mb_index2xy[i] ]= qscale_table[ s->mb_index2xy[i+1] ]+2; - } - - if(s->codec_id != CODEC_ID_H263P){ - for(i=1; imb_num; i++){ - int mb_xy= s->mb_index2xy[i]; - - if(qscale_table[mb_xy] != qscale_table[s->mb_index2xy[i-1]] && (s->mb_type[mb_xy]&CANDIDATE_MB_TYPE_INTER4V)){ - s->mb_type[mb_xy]|= CANDIDATE_MB_TYPE_INTER; - } - } - } -} - -/** - * modify mb_type & qscale so that encoding is acually possible in mpeg4 - */ -void ff_clean_mpeg4_qscales(MpegEncContext *s){ - int i; - int8_t * const qscale_table= s->current_picture.qscale_table; - - ff_clean_h263_qscales(s); - - if(s->pict_type== FF_B_TYPE){ - int odd=0; - /* ok, come on, this isn't funny anymore, there's more code for handling this mpeg4 mess than for the actual adaptive quantization */ - - for(i=0; imb_num; i++){ - int mb_xy= s->mb_index2xy[i]; - odd += qscale_table[mb_xy]&1; - } - - if(2*odd > s->mb_num) odd=1; - else odd=0; - - for(i=0; imb_num; i++){ - int mb_xy= s->mb_index2xy[i]; - if((qscale_table[mb_xy]&1) != odd) - qscale_table[mb_xy]++; - if(qscale_table[mb_xy] > 31) - qscale_table[mb_xy]= 31; - } - - for(i=1; imb_num; i++){ - int mb_xy= s->mb_index2xy[i]; - if(qscale_table[mb_xy] != qscale_table[s->mb_index2xy[i-1]] && (s->mb_type[mb_xy]&CANDIDATE_MB_TYPE_DIRECT)){ - s->mb_type[mb_xy]|= CANDIDATE_MB_TYPE_BIDIR; - } - } - } -} - -#endif //CONFIG_ENCODERS - -#define tab_size ((signed)FF_ARRAY_ELEMS(s->direct_scale_mv[0])) -#define tab_bias (tab_size/2) - -void ff_mpeg4_init_direct_mv(MpegEncContext *s){ - int i; - for(i=0; idirect_scale_mv[0][i] = (i-tab_bias)*s->pb_time/s->pp_time; - s->direct_scale_mv[1][i] = (i-tab_bias)*(s->pb_time-s->pp_time)/s->pp_time; - } -} - -static inline void ff_mpeg4_set_one_direct_mv(MpegEncContext *s, int mx, int my, int i){ - int xy= s->block_index[i]; - uint16_t time_pp= s->pp_time; - uint16_t time_pb= s->pb_time; - int p_mx, p_my; - - p_mx= s->next_picture.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 - : s->direct_scale_mv[1][p_mx + tab_bias]; - }else{ - s->mv[0][i][0] = p_mx*time_pb/time_pp + mx; - 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]; - 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 - : s->direct_scale_mv[1][p_my + tab_bias]; - }else{ - s->mv[0][i][1] = p_my*time_pb/time_pp + my; - s->mv[1][i][1] = my ? s->mv[0][i][1] - p_my - : p_my*(time_pb - time_pp)/time_pp; - } -} - -#undef tab_size -#undef tab_bias - -/** - * - * @return the mb_type - */ -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]; - uint16_t time_pp; - uint16_t time_pb; - int i; - - //FIXME avoid divides - // try special case with shifts for 1 and 3 B-frames? - - if(IS_8X8(colocated_mb_type)){ - s->mv_type = MV_TYPE_8X8; - for(i=0; i<4; i++){ - ff_mpeg4_set_one_direct_mv(s, mx, my, i); - } - return MB_TYPE_DIRECT2 | MB_TYPE_8x8 | MB_TYPE_L0L1; - } 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][s->block_index[2*i]]; - s->field_select[0][i]= field_select; - s->field_select[1][i]= i; - if(s->top_field_first){ - time_pp= s->pp_field_time - field_select + i; - time_pb= s->pb_field_time - field_select + i; - }else{ - time_pp= s->pp_field_time + field_select - i; - time_pb= s->pb_field_time + field_select - i; - } - s->mv[0][i][0] = s->p_field_mv_table[i][0][mb_index][0]*time_pb/time_pp + mx; - s->mv[0][i][1] = s->p_field_mv_table[i][0][mb_index][1]*time_pb/time_pp + my; - s->mv[1][i][0] = mx ? s->mv[0][i][0] - s->p_field_mv_table[i][0][mb_index][0] - : s->p_field_mv_table[i][0][mb_index][0]*(time_pb - time_pp)/time_pp; - s->mv[1][i][1] = my ? s->mv[0][i][1] - s->p_field_mv_table[i][0][mb_index][1] - : s->p_field_mv_table[i][0][mb_index][1]*(time_pb - time_pp)/time_pp; - } - return MB_TYPE_DIRECT2 | MB_TYPE_16x8 | MB_TYPE_L0L1 | MB_TYPE_INTERLACED; - }else{ - ff_mpeg4_set_one_direct_mv(s, mx, my, 0); - s->mv[0][1][0] = s->mv[0][2][0] = s->mv[0][3][0] = s->mv[0][0][0]; - s->mv[0][1][1] = s->mv[0][2][1] = s->mv[0][3][1] = s->mv[0][0][1]; - s->mv[1][1][0] = s->mv[1][2][0] = s->mv[1][3][0] = s->mv[1][0][0]; - s->mv[1][1][1] = s->mv[1][2][1] = s->mv[1][3][1] = s->mv[1][0][1]; - if((s->avctx->workaround_bugs & FF_BUG_DIRECT_BLOCKSIZE) || !s->quarter_sample) - s->mv_type= MV_TYPE_16X16; - else - s->mv_type= MV_TYPE_8X8; - return MB_TYPE_DIRECT2 | MB_TYPE_16x16 | MB_TYPE_L0L1; //Note see prev line - } -} void ff_h263_update_motion_val(MpegEncContext * s){ const int mb_xy = s->mb_y * s->mb_stride + s->mb_x; @@ -708,10 +71,10 @@ 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][xy ]= - s->current_picture.ref_index[0][xy + 1]= s->field_select[0][0]; - s->current_picture.ref_index[0][xy + wrap ]= - s->current_picture.ref_index[0][xy + wrap + 1]= s->field_select[0][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]; } /* no update if 8X8 because it has been done during parsing */ @@ -735,732 +98,47 @@ void ff_h263_update_motion_val(MpegEncContext * s){ } } -#if CONFIG_ENCODERS - -static inline int h263_get_motion_length(MpegEncContext * s, int val, int f_code){ - int l, bit_size, code; - - if (val == 0) { - return mvtab[0][1]; - } else { - bit_size = f_code - 1; - /* modulo encoding */ - l= INT_BIT - 6 - bit_size; - val = (val<>l; - val--; - code = (val >> bit_size) + 1; - - return mvtab[code][1] + 1 + bit_size; - } -} - -static inline void ff_h263_encode_motion_vector(MpegEncContext * s, int x, int y, int f_code){ - if(s->flags2 & CODEC_FLAG2_NO_OUTPUT){ - skip_put_bits(&s->pb, - h263_get_motion_length(s, x, f_code) - +h263_get_motion_length(s, y, f_code)); - }else{ - ff_h263_encode_motion(s, x, f_code); - ff_h263_encode_motion(s, y, f_code); - } -} - -static inline int get_p_cbp(MpegEncContext * s, - DCTELEM block[6][64], - int motion_x, int motion_y){ - int cbp, i; - - if(s->flags & CODEC_FLAG_CBP_RD){ - int best_cbpy_score= INT_MAX; - int best_cbpc_score= INT_MAX; - int cbpc = (-1), cbpy= (-1); - const int offset= (s->mv_type==MV_TYPE_16X16 ? 0 : 16) + (s->dquant ? 8 : 0); - const int lambda= s->lambda2 >> (FF_LAMBDA_SHIFT - 6); - - for(i=0; i<4; i++){ - int score= inter_MCBPC_bits[i + offset] * lambda; - if(i&1) score += s->coded_score[5]; - if(i&2) score += s->coded_score[4]; - - if(score < best_cbpc_score){ - best_cbpc_score= score; - cbpc= i; - } - } - - for(i=0; i<16; i++){ - int score= cbpy_tab[i ^ 0xF][1] * lambda; - if(i&1) score += s->coded_score[3]; - if(i&2) score += s->coded_score[2]; - if(i&4) score += s->coded_score[1]; - if(i&8) score += s->coded_score[0]; - - if(score < best_cbpy_score){ - best_cbpy_score= score; - cbpy= i; - } - } - cbp= cbpc + 4*cbpy; - if ((motion_x | motion_y | s->dquant) == 0 && s->mv_type==MV_TYPE_16X16){ - if(best_cbpy_score + best_cbpc_score + 2*lambda >= 0) - cbp= 0; - } - - for (i = 0; i < 6; i++) { - if (s->block_last_index[i] >= 0 && ((cbp >> (5 - i))&1)==0 ){ - s->block_last_index[i]= -1; - s->dsp.clear_block(s->block[i]); - } - } - }else{ - cbp= 0; - for (i = 0; i < 6; i++) { - if (s->block_last_index[i] >= 0) - cbp |= 1 << (5 - i); - } - } - return cbp; -} - -static inline int get_b_cbp(MpegEncContext * s, DCTELEM block[6][64], - int motion_x, int motion_y, int mb_type){ - int cbp=0, i; - - if(s->flags & CODEC_FLAG_CBP_RD){ - int score=0; - const int lambda= s->lambda2 >> (FF_LAMBDA_SHIFT - 6); - - for(i=0; i<6; i++){ - if(s->coded_score[i] < 0){ - score += s->coded_score[i]; - cbp |= 1 << (5 - i); - } - } - - if(cbp){ - int zero_score= -6; - if ((motion_x | motion_y | s->dquant | mb_type) == 0){ - zero_score-= 4; //2*MV + mb_type + cbp bit - } - - zero_score*= lambda; - if(zero_score <= score){ - cbp=0; - } - } - - for (i = 0; i < 6; i++) { - if (s->block_last_index[i] >= 0 && ((cbp >> (5 - i))&1)==0 ){ - s->block_last_index[i]= -1; - s->dsp.clear_block(s->block[i]); - } - } - }else{ - for (i = 0; i < 6; i++) { - if (s->block_last_index[i] >= 0) - cbp |= 1 << (5 - i); - } - } - return cbp; -} - -static inline void mpeg4_encode_blocks(MpegEncContext * s, DCTELEM block[6][64], int intra_dc[6], - uint8_t **scan_table, PutBitContext *dc_pb, PutBitContext *ac_pb){ - int i; - - if(scan_table){ - if(s->flags2 & CODEC_FLAG2_NO_OUTPUT){ - for (i = 0; i < 6; i++) { - skip_put_bits(&s->pb, mpeg4_get_block_length(s, block[i], i, intra_dc[i], scan_table[i])); - } - }else{ - /* encode each block */ - for (i = 0; i < 6; i++) { - mpeg4_encode_block(s, block[i], i, intra_dc[i], scan_table[i], dc_pb, ac_pb); - } - } - }else{ - if(s->flags2 & CODEC_FLAG2_NO_OUTPUT){ - for (i = 0; i < 6; i++) { - skip_put_bits(&s->pb, mpeg4_get_block_length(s, block[i], i, 0, s->intra_scantable.permutated)); - } - }else{ - /* encode each block */ - for (i = 0; i < 6; i++) { - mpeg4_encode_block(s, block[i], i, 0, s->intra_scantable.permutated, dc_pb, ac_pb); - } - } - } -} - -static const int dquant_code[5]= {1,0,9,2,3}; - -void mpeg4_encode_mb(MpegEncContext * s, - DCTELEM block[6][64], - int motion_x, int motion_y) +int h263_pred_dc(MpegEncContext * s, int n, int16_t **dc_val_ptr) { - int cbpc, cbpy, pred_x, pred_y; - PutBitContext * const pb2 = s->data_partitioning ? &s->pb2 : &s->pb; - PutBitContext * const tex_pb = s->data_partitioning && s->pict_type!=FF_B_TYPE ? &s->tex_pb : &s->pb; - PutBitContext * const dc_pb = s->data_partitioning && s->pict_type!=FF_I_TYPE ? &s->pb2 : &s->pb; - const int interleaved_stats= (s->flags&CODEC_FLAG_PASS1) && !s->data_partitioning ? 1 : 0; + int x, y, wrap, a, c, pred_dc; + int16_t *dc_val; - // printf("**mb x=%d y=%d\n", s->mb_x, s->mb_y); - if (!s->mb_intra) { - int i, cbp; - - if(s->pict_type==FF_B_TYPE){ - static const int mb_type_table[8]= {-1, 3, 2, 1,-1,-1,-1, 0}; /* convert from mv_dir to type */ - int mb_type= mb_type_table[s->mv_dir]; - - if(s->mb_x==0){ - for(i=0; i<2; i++){ - s->last_mv[i][0][0]= - s->last_mv[i][0][1]= - s->last_mv[i][1][0]= - s->last_mv[i][1][1]= 0; - } - } - - assert(s->dquant>=-2 && s->dquant<=2); - assert((s->dquant&1)==0); - 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 & ... - s->skip_count++; - s->mv[0][0][0]= - s->mv[0][0][1]= - s->mv[1][0][0]= - s->mv[1][0][1]= 0; - s->mv_dir= MV_DIR_FORWARD; //doesn't matter - s->qscale -= s->dquant; -// s->mb_skipped=1; - - return; - } - - cbp= get_b_cbp(s, block, motion_x, motion_y, mb_type); - - if ((cbp | motion_x | motion_y | mb_type) ==0) { - /* direct MB with MV={0,0} */ - assert(s->dquant==0); - - put_bits(&s->pb, 1, 1); /* mb not coded modb1=1 */ - - if(interleaved_stats){ - s->misc_bits++; - s->last_bits++; - } - s->skip_count++; - return; - } - - put_bits(&s->pb, 1, 0); /* mb coded modb1=0 */ - put_bits(&s->pb, 1, cbp ? 0 : 1); /* modb2 */ //FIXME merge - put_bits(&s->pb, mb_type+1, 1); // this table is so simple that we don't need it :) - if(cbp) put_bits(&s->pb, 6, cbp); - - if(cbp && mb_type){ - if(s->dquant) - put_bits(&s->pb, 2, (s->dquant>>2)+3); - else - put_bits(&s->pb, 1, 0); - }else - s->qscale -= s->dquant; - - if(!s->progressive_sequence){ - if(cbp) - put_bits(&s->pb, 1, s->interlaced_dct); - if(mb_type) // not direct mode - put_bits(&s->pb, 1, s->mv_type == MV_TYPE_FIELD); - } - - if(interleaved_stats){ - s->misc_bits+= get_bits_diff(s); - } - - if(mb_type == 0){ - assert(s->mv_dir & MV_DIRECT); - ff_h263_encode_motion_vector(s, motion_x, motion_y, 1); - s->b_count++; - s->f_count++; - }else{ - assert(mb_type > 0 && mb_type < 4); - if(s->mv_type != MV_TYPE_FIELD){ - if(s->mv_dir & MV_DIR_FORWARD){ - ff_h263_encode_motion_vector(s, s->mv[0][0][0] - s->last_mv[0][0][0], - s->mv[0][0][1] - s->last_mv[0][0][1], s->f_code); - s->last_mv[0][0][0]= s->last_mv[0][1][0]= s->mv[0][0][0]; - s->last_mv[0][0][1]= s->last_mv[0][1][1]= s->mv[0][0][1]; - s->f_count++; - } - if(s->mv_dir & MV_DIR_BACKWARD){ - ff_h263_encode_motion_vector(s, s->mv[1][0][0] - s->last_mv[1][0][0], - s->mv[1][0][1] - s->last_mv[1][0][1], s->b_code); - s->last_mv[1][0][0]= s->last_mv[1][1][0]= s->mv[1][0][0]; - s->last_mv[1][0][1]= s->last_mv[1][1][1]= s->mv[1][0][1]; - s->b_count++; - } - }else{ - if(s->mv_dir & MV_DIR_FORWARD){ - put_bits(&s->pb, 1, s->field_select[0][0]); - put_bits(&s->pb, 1, s->field_select[0][1]); - } - if(s->mv_dir & MV_DIR_BACKWARD){ - put_bits(&s->pb, 1, s->field_select[1][0]); - put_bits(&s->pb, 1, s->field_select[1][1]); - } - if(s->mv_dir & MV_DIR_FORWARD){ - for(i=0; i<2; i++){ - ff_h263_encode_motion_vector(s, s->mv[0][i][0] - s->last_mv[0][i][0] , - s->mv[0][i][1] - s->last_mv[0][i][1]/2, s->f_code); - s->last_mv[0][i][0]= s->mv[0][i][0]; - s->last_mv[0][i][1]= s->mv[0][i][1]*2; - } - s->f_count++; - } - if(s->mv_dir & MV_DIR_BACKWARD){ - for(i=0; i<2; i++){ - ff_h263_encode_motion_vector(s, s->mv[1][i][0] - s->last_mv[1][i][0] , - s->mv[1][i][1] - s->last_mv[1][i][1]/2, s->b_code); - s->last_mv[1][i][0]= s->mv[1][i][0]; - s->last_mv[1][i][1]= s->mv[1][i][1]*2; - } - s->b_count++; - } - } - } - - if(interleaved_stats){ - s->mv_bits+= get_bits_diff(s); - } - - mpeg4_encode_blocks(s, block, NULL, NULL, NULL, &s->pb); - - if(interleaved_stats){ - s->p_tex_bits+= get_bits_diff(s); - } - - }else{ /* s->pict_type==FF_B_TYPE */ - cbp= get_p_cbp(s, block, motion_x, motion_y); - - if ((cbp | motion_x | motion_y | s->dquant) == 0 && s->mv_type==MV_TYPE_16X16) { - /* check if the B frames can skip it too, as we must skip it if we skip here - why didn't they just compress the skip-mb bits instead of reusing them ?! */ - if(s->max_b_frames>0){ - int i; - int x,y, offset; - uint8_t *p_pic; - - 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; - - s->mb_skipped=1; - for(i=0; imax_b_frames; i++){ - uint8_t *b_pic; - int diff; - Picture *pic= s->reordered_input_picture[i+1]; - - if(pic==NULL || pic->pict_type!=FF_B_TYPE) break; - - b_pic= pic->data[0] + offset; - if(pic->type != FF_BUFFER_TYPE_SHARED) - b_pic+= INPLACE_OFFSET; - 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; - } - } - }else - s->mb_skipped=1; - - if(s->mb_skipped==1){ - /* skip macroblock */ - put_bits(&s->pb, 1, 1); - - if(interleaved_stats){ - s->misc_bits++; - s->last_bits++; - } - s->skip_count++; - - return; - } - } - - put_bits(&s->pb, 1, 0); /* mb coded */ - cbpc = cbp & 3; - cbpy = cbp >> 2; - cbpy ^= 0xf; - if(s->mv_type==MV_TYPE_16X16){ - if(s->dquant) cbpc+= 8; - put_bits(&s->pb, - inter_MCBPC_bits[cbpc], - inter_MCBPC_code[cbpc]); - - put_bits(pb2, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); - if(s->dquant) - put_bits(pb2, 2, dquant_code[s->dquant+2]); - - if(!s->progressive_sequence){ - if(cbp) - put_bits(pb2, 1, s->interlaced_dct); - put_bits(pb2, 1, 0); - } - - if(interleaved_stats){ - s->misc_bits+= get_bits_diff(s); - } - - /* motion vectors: 16x16 mode */ - h263_pred_motion(s, 0, 0, &pred_x, &pred_y); - - ff_h263_encode_motion_vector(s, motion_x - pred_x, - motion_y - pred_y, s->f_code); - }else if(s->mv_type==MV_TYPE_FIELD){ - if(s->dquant) cbpc+= 8; - put_bits(&s->pb, - inter_MCBPC_bits[cbpc], - inter_MCBPC_code[cbpc]); - - put_bits(pb2, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); - if(s->dquant) - put_bits(pb2, 2, dquant_code[s->dquant+2]); - - assert(!s->progressive_sequence); - if(cbp) - put_bits(pb2, 1, s->interlaced_dct); - put_bits(pb2, 1, 1); - - if(interleaved_stats){ - s->misc_bits+= get_bits_diff(s); - } - - /* motion vectors: 16x8 interlaced mode */ - h263_pred_motion(s, 0, 0, &pred_x, &pred_y); - pred_y /=2; - - put_bits(&s->pb, 1, s->field_select[0][0]); - put_bits(&s->pb, 1, s->field_select[0][1]); - - ff_h263_encode_motion_vector(s, s->mv[0][0][0] - pred_x, - s->mv[0][0][1] - pred_y, s->f_code); - ff_h263_encode_motion_vector(s, s->mv[0][1][0] - pred_x, - s->mv[0][1][1] - pred_y, s->f_code); - }else{ - assert(s->mv_type==MV_TYPE_8X8); - put_bits(&s->pb, - inter_MCBPC_bits[cbpc+16], - inter_MCBPC_code[cbpc+16]); - put_bits(pb2, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); - - if(!s->progressive_sequence){ - if(cbp) - put_bits(pb2, 1, s->interlaced_dct); - } - - if(interleaved_stats){ - s->misc_bits+= get_bits_diff(s); - } - - for(i=0; i<4; i++){ - /* 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); - } - } - - if(interleaved_stats){ - s->mv_bits+= get_bits_diff(s); - } - - mpeg4_encode_blocks(s, block, NULL, NULL, NULL, tex_pb); - - if(interleaved_stats){ - s->p_tex_bits+= get_bits_diff(s); - } - s->f_count++; - } + /* find prediction */ + if (n < 4) { + x = 2 * s->mb_x + (n & 1); + y = 2 * s->mb_y + ((n & 2) >> 1); + wrap = s->b8_stride; + dc_val = s->dc_val[0]; } else { - int cbp; - int dc_diff[6]; //dc values with the dc prediction subtracted - int dir[6]; //prediction direction - int zigzag_last_index[6]; - uint8_t *scan_table[6]; - int i; - - for(i=0; i<6; i++){ - dc_diff[i]= ff_mpeg4_pred_dc(s, i, block[i][0], &dir[i], 1); - } - - if(s->flags & CODEC_FLAG_AC_PRED){ - s->ac_pred= decide_ac_pred(s, block, dir, scan_table, zigzag_last_index); - if(!s->ac_pred) - restore_ac_coeffs(s, block, dir, scan_table, zigzag_last_index); - }else{ - for(i=0; i<6; i++) - scan_table[i]= s->intra_scantable.permutated; - } - - /* compute cbp */ - cbp = 0; - for (i = 0; i < 6; i++) { - if (s->block_last_index[i] >= 1) - cbp |= 1 << (5 - i); - } - - cbpc = cbp & 3; - if (s->pict_type == FF_I_TYPE) { - if(s->dquant) cbpc+=4; - put_bits(&s->pb, - intra_MCBPC_bits[cbpc], - intra_MCBPC_code[cbpc]); - } else { - if(s->dquant) cbpc+=8; - put_bits(&s->pb, 1, 0); /* mb coded */ - put_bits(&s->pb, - inter_MCBPC_bits[cbpc + 4], - inter_MCBPC_code[cbpc + 4]); - } - put_bits(pb2, 1, s->ac_pred); - cbpy = cbp >> 2; - put_bits(pb2, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); - if(s->dquant) - put_bits(dc_pb, 2, dquant_code[s->dquant+2]); - - if(!s->progressive_sequence){ - put_bits(dc_pb, 1, s->interlaced_dct); - } - - if(interleaved_stats){ - s->misc_bits+= get_bits_diff(s); - } - - mpeg4_encode_blocks(s, block, dc_diff, scan_table, dc_pb, tex_pb); - - if(interleaved_stats){ - s->i_tex_bits+= get_bits_diff(s); - } - s->i_count++; - - /* restore ac coeffs & last_index stuff if we messed them up with the prediction */ - if(s->ac_pred) - restore_ac_coeffs(s, block, dir, scan_table, zigzag_last_index); + x = s->mb_x; + y = s->mb_y; + wrap = s->mb_stride; + dc_val = s->dc_val[n - 4 + 1]; } + /* B C + * A X + */ + a = dc_val[(x - 1) + (y) * wrap]; + c = dc_val[(x) + (y - 1) * wrap]; + + /* No prediction outside GOB boundary */ + if(s->first_slice_line && n!=3){ + if(n!=2) c= 1024; + if(n!=1 && s->mb_x == s->resync_mb_x) a= 1024; + } + /* just DC prediction */ + if (a != 1024 && c != 1024) + pred_dc = (a + c) >> 1; + else if (a != 1024) + pred_dc = a; + else + pred_dc = c; + + /* we assume pred is positive */ + *dc_val_ptr = &dc_val[x + y * wrap]; + return pred_dc; } -void h263_encode_mb(MpegEncContext * s, - DCTELEM block[6][64], - int motion_x, int motion_y) -{ - int cbpc, cbpy, i, cbp, pred_x, pred_y; - int16_t pred_dc; - int16_t rec_intradc[6]; - int16_t *dc_ptr[6]; - const int interleaved_stats= (s->flags&CODEC_FLAG_PASS1); - - //printf("**mb x=%d y=%d\n", s->mb_x, s->mb_y); - if (!s->mb_intra) { - /* compute cbp */ - cbp= get_p_cbp(s, block, motion_x, motion_y); - - if ((cbp | motion_x | motion_y | s->dquant | (s->mv_type - MV_TYPE_16X16)) == 0) { - /* skip macroblock */ - put_bits(&s->pb, 1, 1); - if(interleaved_stats){ - s->misc_bits++; - s->last_bits++; - } - s->skip_count++; - - return; - } - put_bits(&s->pb, 1, 0); /* mb coded */ - - cbpc = cbp & 3; - cbpy = cbp >> 2; - if(s->alt_inter_vlc==0 || cbpc!=3) - cbpy ^= 0xF; - if(s->dquant) cbpc+= 8; - if(s->mv_type==MV_TYPE_16X16){ - put_bits(&s->pb, - inter_MCBPC_bits[cbpc], - inter_MCBPC_code[cbpc]); - - put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); - if(s->dquant) - put_bits(&s->pb, 2, dquant_code[s->dquant+2]); - - if(interleaved_stats){ - s->misc_bits+= get_bits_diff(s); - } - - /* motion vectors: 16x16 mode */ - h263_pred_motion(s, 0, 0, &pred_x, &pred_y); - - if (!s->umvplus) { - ff_h263_encode_motion_vector(s, motion_x - pred_x, - motion_y - pred_y, 1); - } - else { - h263p_encode_umotion(s, motion_x - pred_x); - h263p_encode_umotion(s, motion_y - pred_y); - if (((motion_x - pred_x) == 1) && ((motion_y - pred_y) == 1)) - /* To prevent Start Code emulation */ - put_bits(&s->pb,1,1); - } - }else{ - put_bits(&s->pb, - inter_MCBPC_bits[cbpc+16], - inter_MCBPC_code[cbpc+16]); - put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); - if(s->dquant) - put_bits(&s->pb, 2, dquant_code[s->dquant+2]); - - if(interleaved_stats){ - s->misc_bits+= get_bits_diff(s); - } - - for(i=0; i<4; i++){ - /* 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]; - if (!s->umvplus) { - ff_h263_encode_motion_vector(s, motion_x - pred_x, - motion_y - pred_y, 1); - } - else { - h263p_encode_umotion(s, motion_x - pred_x); - h263p_encode_umotion(s, motion_y - pred_y); - if (((motion_x - pred_x) == 1) && ((motion_y - pred_y) == 1)) - /* To prevent Start Code emulation */ - put_bits(&s->pb,1,1); - } - } - } - - if(interleaved_stats){ - s->mv_bits+= get_bits_diff(s); - } - } else { - assert(s->mb_intra); - - cbp = 0; - if (s->h263_aic) { - /* Predict DC */ - for(i=0; i<6; i++) { - int16_t level = block[i][0]; - int scale; - - if(i<4) scale= s->y_dc_scale; - else scale= s->c_dc_scale; - - pred_dc = h263_pred_dc(s, i, &dc_ptr[i]); - level -= pred_dc; - /* Quant */ - if (level >= 0) - level = (level + (scale>>1))/scale; - else - level = (level - (scale>>1))/scale; - - /* AIC can change CBP */ - if (level == 0 && s->block_last_index[i] == 0) - s->block_last_index[i] = -1; - - if(!s->modified_quant){ - if (level < -127) - level = -127; - else if (level > 127) - level = 127; - } - - block[i][0] = level; - /* Reconstruction */ - rec_intradc[i] = scale*level + pred_dc; - /* Oddify */ - rec_intradc[i] |= 1; - //if ((rec_intradc[i] % 2) == 0) - // rec_intradc[i]++; - /* Clipping */ - if (rec_intradc[i] < 0) - rec_intradc[i] = 0; - else if (rec_intradc[i] > 2047) - rec_intradc[i] = 2047; - - /* Update AC/DC tables */ - *dc_ptr[i] = rec_intradc[i]; - if (s->block_last_index[i] >= 0) - cbp |= 1 << (5 - i); - } - }else{ - for(i=0; i<6; i++) { - /* compute cbp */ - if (s->block_last_index[i] >= 1) - cbp |= 1 << (5 - i); - } - } - - cbpc = cbp & 3; - if (s->pict_type == FF_I_TYPE) { - if(s->dquant) cbpc+=4; - put_bits(&s->pb, - intra_MCBPC_bits[cbpc], - intra_MCBPC_code[cbpc]); - } else { - if(s->dquant) cbpc+=8; - put_bits(&s->pb, 1, 0); /* mb coded */ - put_bits(&s->pb, - inter_MCBPC_bits[cbpc + 4], - inter_MCBPC_code[cbpc + 4]); - } - if (s->h263_aic) { - /* XXX: currently, we do not try to use ac prediction */ - put_bits(&s->pb, 1, 0); /* no AC prediction */ - } - cbpy = cbp >> 2; - put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); - if(s->dquant) - put_bits(&s->pb, 2, dquant_code[s->dquant+2]); - - if(interleaved_stats){ - s->misc_bits+= get_bits_diff(s); - } - } - - for(i=0; i<6; i++) { - /* encode each block */ - h263_encode_block(s, block[i], i); - - /* Update INTRADC for decoding */ - if (s->h263_aic && s->mb_intra) { - block[i][0] = rec_intradc[i]; - - } - } - - if(interleaved_stats){ - if (!s->mb_intra) { - s->p_tex_bits+= get_bits_diff(s); - s->f_count++; - }else{ - s->i_tex_bits+= get_bits_diff(s); - s->i_count++; - } - } -} -#endif - void ff_h263_loop_filter(MpegEncContext * s){ int qp_c; const int linesize = s->linesize; @@ -1548,50 +226,7 @@ void ff_h263_loop_filter(MpegEncContext * s){ } } -#if CONFIG_ENCODERS -static int h263_pred_dc(MpegEncContext * s, int n, int16_t **dc_val_ptr) -{ - int x, y, wrap, a, c, pred_dc; - int16_t *dc_val; - - /* find prediction */ - if (n < 4) { - x = 2 * s->mb_x + (n & 1); - y = 2 * s->mb_y + ((n & 2) >> 1); - wrap = s->b8_stride; - dc_val = s->dc_val[0]; - } else { - x = s->mb_x; - y = s->mb_y; - wrap = s->mb_stride; - dc_val = s->dc_val[n - 4 + 1]; - } - /* B C - * A X - */ - a = dc_val[(x - 1) + (y) * wrap]; - c = dc_val[(x) + (y - 1) * wrap]; - - /* No prediction outside GOB boundary */ - if(s->first_slice_line && n!=3){ - if(n!=2) c= 1024; - if(n!=1 && s->mb_x == s->resync_mb_x) a= 1024; - } - /* just DC prediction */ - if (a != 1024 && c != 1024) - pred_dc = (a + c) >> 1; - else if (a != 1024) - pred_dc = a; - else - pred_dc = c; - - /* we assume pred is positive */ - *dc_val_ptr = &dc_val[x + y * wrap]; - return pred_dc; -} -#endif /* CONFIG_ENCODERS */ - -static void h263_pred_acdc(MpegEncContext * s, DCTELEM *block, int n) +void h263_pred_acdc(MpegEncContext * s, DCTELEM *block, int n) { int x, y, wrap, a, c, pred_dc, scale, i; int16_t *dc_val, *ac_val, *ac_val1; @@ -1736,1210 +371,6 @@ int16_t *h263_pred_motion(MpegEncContext * s, int block, int dir, return *mot_val; } -#if CONFIG_ENCODERS -void ff_h263_encode_motion(MpegEncContext * s, int val, int f_code) -{ - int range, l, bit_size, sign, code, bits; - - if (val == 0) { - /* zero vector */ - code = 0; - put_bits(&s->pb, mvtab[code][1], mvtab[code][0]); - } else { - bit_size = f_code - 1; - range = 1 << bit_size; - /* modulo encoding */ - l= INT_BIT - 6 - bit_size; - val = (val<>l; - sign = val>>31; - val= (val^sign)-sign; - sign&=1; - - val--; - code = (val >> bit_size) + 1; - bits = val & (range - 1); - - put_bits(&s->pb, mvtab[code][1] + 1, (mvtab[code][0] << 1) | sign); - if (bit_size > 0) { - put_bits(&s->pb, bit_size, bits); - } - } -} - -/* Encode MV differences on H.263+ with Unrestricted MV mode */ -static void h263p_encode_umotion(MpegEncContext * s, int val) -{ - short sval = 0; - short i = 0; - short n_bits = 0; - short temp_val; - int code = 0; - int tcode; - - if ( val == 0) - put_bits(&s->pb, 1, 1); - else if (val == 1) - put_bits(&s->pb, 3, 0); - else if (val == -1) - put_bits(&s->pb, 3, 2); - else { - - sval = ((val < 0) ? (short)(-val):(short)val); - temp_val = sval; - - while (temp_val != 0) { - temp_val = temp_val >> 1; - n_bits++; - } - - i = n_bits - 1; - while (i > 0) { - tcode = (sval & (1 << (i-1))) >> (i-1); - tcode = (tcode << 1) | 1; - code = (code << 2) | tcode; - i--; - } - code = ((code << 1) | (val < 0)) << 1; - put_bits(&s->pb, (2*n_bits)+1, code); - //printf("\nVal = %d\tCode = %d", sval, code); - } -} - -static void init_mv_penalty_and_fcode(MpegEncContext *s) -{ - int f_code; - int mv; - - for(f_code=1; f_code<=MAX_FCODE; f_code++){ - for(mv=-MAX_MV; mv<=MAX_MV; mv++){ - int len; - - if(mv==0) len= mvtab[0][1]; - else{ - int val, bit_size, code; - - bit_size = f_code - 1; - - val=mv; - if (val < 0) - val = -val; - val--; - code = (val >> bit_size) + 1; - if(code<33){ - len= mvtab[code][1] + 1 + bit_size; - }else{ - len= mvtab[32][1] + av_log2(code>>5) + 2 + bit_size; - } - } - - mv_penalty[f_code][mv+MAX_MV]= len; - } - } - - for(f_code=MAX_FCODE; f_code>0; f_code--){ - for(mv=-(16<>= 1; - size++; - } - - if (level < 0) - l= (-level) ^ ((1 << size) - 1); - else - l= level; - - /* luminance */ - uni_code= DCtab_lum[size][0]; - uni_len = DCtab_lum[size][1]; - - if (size > 0) { - uni_code<<=size; uni_code|=l; - uni_len+=size; - if (size > 8){ - uni_code<<=1; uni_code|=1; - uni_len++; - } - } - uni_DCtab_lum_bits[level+256]= uni_code; - uni_DCtab_lum_len [level+256]= uni_len; - - /* chrominance */ - uni_code= DCtab_chrom[size][0]; - uni_len = DCtab_chrom[size][1]; - - if (size > 0) { - uni_code<<=size; uni_code|=l; - uni_len+=size; - if (size > 8){ - uni_code<<=1; uni_code|=1; - uni_len++; - } - } - uni_DCtab_chrom_bits[level+256]= uni_code; - uni_DCtab_chrom_len [level+256]= uni_len; - - } -} - -static void init_uni_mpeg4_rl_tab(RLTable *rl, uint32_t *bits_tab, uint8_t *len_tab){ - int slevel, run, last; - - assert(MAX_LEVEL >= 64); - assert(MAX_RUN >= 63); - - for(slevel=-64; slevel<64; slevel++){ - if(slevel==0) continue; - for(run=0; run<64; run++){ - for(last=0; last<=1; last++){ - const int index= UNI_MPEG4_ENC_INDEX(last, run, slevel+64); - int level= slevel < 0 ? -slevel : slevel; - int sign= slevel < 0 ? 1 : 0; - int bits, len, code; - int level1, run1; - - len_tab[index]= 100; - - /* ESC0 */ - code= get_rl_index(rl, last, run, level); - bits= rl->table_vlc[code][0]; - len= rl->table_vlc[code][1]; - bits=bits*2+sign; len++; - - if(code!=rl->n && len < len_tab[index]){ - bits_tab[index]= bits; - len_tab [index]= len; - } -#if 1 - /* ESC1 */ - bits= rl->table_vlc[rl->n][0]; - len= rl->table_vlc[rl->n][1]; - bits=bits*2; len++; //esc1 - level1= level - rl->max_level[last][run]; - if(level1>0){ - code= get_rl_index(rl, last, run, level1); - bits<<= rl->table_vlc[code][1]; - len += rl->table_vlc[code][1]; - bits += rl->table_vlc[code][0]; - bits=bits*2+sign; len++; - - if(code!=rl->n && len < len_tab[index]){ - bits_tab[index]= bits; - len_tab [index]= len; - } - } -#endif -#if 1 - /* ESC2 */ - bits= rl->table_vlc[rl->n][0]; - len= rl->table_vlc[rl->n][1]; - bits=bits*4+2; len+=2; //esc2 - run1 = run - rl->max_run[last][level] - 1; - if(run1>=0){ - code= get_rl_index(rl, last, run1, level); - bits<<= rl->table_vlc[code][1]; - len += rl->table_vlc[code][1]; - bits += rl->table_vlc[code][0]; - bits=bits*2+sign; len++; - - if(code!=rl->n && len < len_tab[index]){ - bits_tab[index]= bits; - len_tab [index]= len; - } - } -#endif - /* ESC3 */ - bits= rl->table_vlc[rl->n][0]; - len = rl->table_vlc[rl->n][1]; - bits=bits*4+3; len+=2; //esc3 - bits=bits*2+last; len++; - bits=bits*64+run; len+=6; - bits=bits*2+1; len++; //marker - bits=bits*4096+(slevel&0xfff); len+=12; - bits=bits*2+1; len++; //marker - - if(len < len_tab[index]){ - bits_tab[index]= bits; - len_tab [index]= len; - } - } - } - } -} - -static void init_uni_h263_rl_tab(RLTable *rl, uint32_t *bits_tab, uint8_t *len_tab){ - int slevel, run, last; - - assert(MAX_LEVEL >= 64); - assert(MAX_RUN >= 63); - - for(slevel=-64; slevel<64; slevel++){ - if(slevel==0) continue; - for(run=0; run<64; run++){ - for(last=0; last<=1; last++){ - const int index= UNI_MPEG4_ENC_INDEX(last, run, slevel+64); - int level= slevel < 0 ? -slevel : slevel; - int sign= slevel < 0 ? 1 : 0; - int bits, len, code; - - len_tab[index]= 100; - - /* ESC0 */ - code= get_rl_index(rl, last, run, level); - bits= rl->table_vlc[code][0]; - len= rl->table_vlc[code][1]; - bits=bits*2+sign; len++; - - if(code!=rl->n && len < len_tab[index]){ - if(bits_tab) bits_tab[index]= bits; - len_tab [index]= len; - } - /* ESC */ - bits= rl->table_vlc[rl->n][0]; - len = rl->table_vlc[rl->n][1]; - bits=bits*2+last; len++; - bits=bits*64+run; len+=6; - bits=bits*256+(level&0xff); len+=8; - - if(len < len_tab[index]){ - if(bits_tab) bits_tab[index]= bits; - len_tab [index]= len; - } - } - } - } -} - -void h263_encode_init(MpegEncContext *s) -{ - static int done = 0; - - if (!done) { - done = 1; - - init_uni_dc_tab(); - - init_rl(&rl_inter, static_rl_table_store[0]); - init_rl(&rl_intra, static_rl_table_store[1]); - init_rl(&rl_intra_aic, static_rl_table_store[2]); - - init_uni_mpeg4_rl_tab(&rl_intra, uni_mpeg4_intra_rl_bits, uni_mpeg4_intra_rl_len); - init_uni_mpeg4_rl_tab(&rl_inter, uni_mpeg4_inter_rl_bits, uni_mpeg4_inter_rl_len); - - init_uni_h263_rl_tab(&rl_intra_aic, NULL, uni_h263_intra_aic_rl_len); - init_uni_h263_rl_tab(&rl_inter , NULL, uni_h263_inter_rl_len); - - init_mv_penalty_and_fcode(s); - } - s->me.mv_penalty= mv_penalty; //FIXME exact table for msmpeg4 & h263p - - s->intra_ac_vlc_length =s->inter_ac_vlc_length = uni_h263_inter_rl_len; - s->intra_ac_vlc_last_length=s->inter_ac_vlc_last_length= uni_h263_inter_rl_len + 128*64; - if(s->h263_aic){ - s->intra_ac_vlc_length = uni_h263_intra_aic_rl_len; - s->intra_ac_vlc_last_length= uni_h263_intra_aic_rl_len + 128*64; - } - s->ac_esc_length= 7+1+6+8; - - // use fcodes >1 only for mpeg4 & h263 & h263p FIXME - switch(s->codec_id){ - case CODEC_ID_MPEG4: - s->fcode_tab= fcode_tab; - s->min_qcoeff= -2048; - s->max_qcoeff= 2047; - s->intra_ac_vlc_length = uni_mpeg4_intra_rl_len; - s->intra_ac_vlc_last_length= uni_mpeg4_intra_rl_len + 128*64; - s->inter_ac_vlc_length = uni_mpeg4_inter_rl_len; - s->inter_ac_vlc_last_length= uni_mpeg4_inter_rl_len + 128*64; - s->luma_dc_vlc_length= uni_DCtab_lum_len; - s->chroma_dc_vlc_length= uni_DCtab_chrom_len; - s->ac_esc_length= 7+2+1+6+1+12+1; - s->y_dc_scale_table= ff_mpeg4_y_dc_scale_table; - s->c_dc_scale_table= ff_mpeg4_c_dc_scale_table; - - if(s->flags & CODEC_FLAG_GLOBAL_HEADER){ - - s->avctx->extradata= av_malloc(1024); - init_put_bits(&s->pb, s->avctx->extradata, 1024); - - if(!(s->workaround_bugs & FF_BUG_MS)) - mpeg4_encode_visual_object_header(s); - mpeg4_encode_vol_header(s, 0, 0); - -// ff_mpeg4_stuffing(&s->pb); ? - flush_put_bits(&s->pb); - s->avctx->extradata_size= (put_bits_count(&s->pb)+7)>>3; - } - - break; - case CODEC_ID_H263P: - if(s->umvplus) - s->fcode_tab= umv_fcode_tab; - if(s->modified_quant){ - s->min_qcoeff= -2047; - s->max_qcoeff= 2047; - }else{ - s->min_qcoeff= -127; - s->max_qcoeff= 127; - } - break; - //Note for mpeg4 & h263 the dc-scale table will be set per frame as needed later - case CODEC_ID_FLV1: - if (s->h263_flv > 1) { - s->min_qcoeff= -1023; - s->max_qcoeff= 1023; - } else { - s->min_qcoeff= -127; - s->max_qcoeff= 127; - } - s->y_dc_scale_table= - s->c_dc_scale_table= ff_mpeg1_dc_scale_table; - break; - default: //nothing needed - default table already set in mpegvideo.c - s->min_qcoeff= -127; - s->max_qcoeff= 127; - s->y_dc_scale_table= - s->c_dc_scale_table= ff_mpeg1_dc_scale_table; - } -} - -/** - * encodes a 8x8 block. - * @param block the 8x8 block - * @param n block index (0-3 are luma, 4-5 are chroma) - */ -static void h263_encode_block(MpegEncContext * s, DCTELEM * block, int n) -{ - int level, run, last, i, j, last_index, last_non_zero, sign, slevel, code; - RLTable *rl; - - rl = &rl_inter; - if (s->mb_intra && !s->h263_aic) { - /* DC coef */ - level = block[0]; - /* 255 cannot be represented, so we clamp */ - if (level > 254) { - level = 254; - block[0] = 254; - } - /* 0 cannot be represented also */ - else if (level < 1) { - level = 1; - block[0] = 1; - } - if (level == 128) //FIXME check rv10 - put_bits(&s->pb, 8, 0xff); - else - put_bits(&s->pb, 8, level); - i = 1; - } else { - i = 0; - if (s->h263_aic && s->mb_intra) - rl = &rl_intra_aic; - - if(s->alt_inter_vlc && !s->mb_intra){ - int aic_vlc_bits=0; - int inter_vlc_bits=0; - int wrong_pos=-1; - int aic_code; - - last_index = s->block_last_index[n]; - last_non_zero = i - 1; - for (; i <= last_index; i++) { - j = s->intra_scantable.permutated[i]; - level = block[j]; - if (level) { - run = i - last_non_zero - 1; - last = (i == last_index); - - if(level<0) level= -level; - - code = get_rl_index(rl, last, run, level); - aic_code = get_rl_index(&rl_intra_aic, last, run, level); - inter_vlc_bits += rl->table_vlc[code][1]+1; - aic_vlc_bits += rl_intra_aic.table_vlc[aic_code][1]+1; - - if (code == rl->n) { - inter_vlc_bits += 1+6+8-1; - } - if (aic_code == rl_intra_aic.n) { - aic_vlc_bits += 1+6+8-1; - wrong_pos += run + 1; - }else - wrong_pos += wrong_run[aic_code]; - last_non_zero = i; - } - } - i = 0; - if(aic_vlc_bits < inter_vlc_bits && wrong_pos > 63) - rl = &rl_intra_aic; - } - } - - /* AC coefs */ - last_index = s->block_last_index[n]; - last_non_zero = i - 1; - for (; i <= last_index; i++) { - j = s->intra_scantable.permutated[i]; - level = block[j]; - if (level) { - run = i - last_non_zero - 1; - last = (i == last_index); - sign = 0; - slevel = level; - if (level < 0) { - sign = 1; - level = -level; - } - code = get_rl_index(rl, last, run, level); - put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); - if (code == rl->n) { - if(s->h263_flv <= 1){ - put_bits(&s->pb, 1, last); - put_bits(&s->pb, 6, run); - - assert(slevel != 0); - - if(level < 128) - put_sbits(&s->pb, 8, slevel); - else{ - put_bits(&s->pb, 8, 128); - put_sbits(&s->pb, 5, slevel); - put_sbits(&s->pb, 6, slevel>>5); - } - }else{ - if(level < 64) { // 7-bit level - put_bits(&s->pb, 1, 0); - put_bits(&s->pb, 1, last); - put_bits(&s->pb, 6, run); - - put_sbits(&s->pb, 7, slevel); - } else { - /* 11-bit level */ - put_bits(&s->pb, 1, 1); - put_bits(&s->pb, 1, last); - put_bits(&s->pb, 6, run); - - put_sbits(&s->pb, 11, slevel); - } - } - } else { - put_bits(&s->pb, 1, sign); - } - last_non_zero = i; - } - } -} - -/***************************************************/ -/** - * add mpeg4 stuffing bits (01...1) - */ -void ff_mpeg4_stuffing(PutBitContext * pbc) -{ - int length; - put_bits(pbc, 1, 0); - length= (-put_bits_count(pbc))&7; - if(length) put_bits(pbc, length, (1<pict_type==FF_B_TYPE){ - ff_mpeg4_init_direct_mv(s); - }else{ - s->last_time_base= s->time_base; - s->time_base= s->time/s->avctx->time_base.den; - } -} - -static void mpeg4_encode_gop_header(MpegEncContext * s){ - int hours, minutes, seconds; - int64_t time; - - put_bits(&s->pb, 16, 0); - put_bits(&s->pb, 16, GOP_STARTCODE); - - time= s->current_picture_ptr->pts; - if(s->reordered_input_picture[1]) - time= FFMIN(time, s->reordered_input_picture[1]->pts); - time= time*s->avctx->time_base.num; - - seconds= time/s->avctx->time_base.den; - minutes= seconds/60; seconds %= 60; - hours= minutes/60; minutes %= 60; - hours%=24; - - put_bits(&s->pb, 5, hours); - put_bits(&s->pb, 6, minutes); - put_bits(&s->pb, 1, 1); - put_bits(&s->pb, 6, seconds); - - 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); -} - -static void mpeg4_encode_visual_object_header(MpegEncContext * s){ - int profile_and_level_indication; - int vo_ver_id; - - if(s->avctx->profile != FF_PROFILE_UNKNOWN){ - profile_and_level_indication = s->avctx->profile << 4; - }else if(s->max_b_frames || s->quarter_sample){ - profile_and_level_indication= 0xF0; // adv simple - }else{ - profile_and_level_indication= 0x00; // simple - } - - if(s->avctx->level != FF_LEVEL_UNKNOWN){ - profile_and_level_indication |= s->avctx->level; - }else{ - profile_and_level_indication |= 1; //level 1 - } - - if(profile_and_level_indication>>4 == 0xF){ - vo_ver_id= 5; - }else{ - vo_ver_id= 1; - } - - //FIXME levels - - put_bits(&s->pb, 16, 0); - put_bits(&s->pb, 16, VOS_STARTCODE); - - put_bits(&s->pb, 8, profile_and_level_indication); - - put_bits(&s->pb, 16, 0); - put_bits(&s->pb, 16, VISUAL_OBJ_STARTCODE); - - put_bits(&s->pb, 1, 1); - put_bits(&s->pb, 4, vo_ver_id); - put_bits(&s->pb, 3, 1); //priority - - put_bits(&s->pb, 4, 1); //visual obj type== video obj - - put_bits(&s->pb, 1, 0); //video signal type == no clue //FIXME - - ff_mpeg4_stuffing(&s->pb); -} - -static void mpeg4_encode_vol_header(MpegEncContext * s, int vo_number, int vol_number) -{ - int vo_ver_id; - - if (!CONFIG_MPEG4_ENCODER) return; - - if(s->max_b_frames || s->quarter_sample){ - vo_ver_id= 5; - s->vo_type= ADV_SIMPLE_VO_TYPE; - }else{ - vo_ver_id= 1; - s->vo_type= SIMPLE_VO_TYPE; - } - - put_bits(&s->pb, 16, 0); - put_bits(&s->pb, 16, 0x100 + vo_number); /* video obj */ - put_bits(&s->pb, 16, 0); - put_bits(&s->pb, 16, 0x120 + vol_number); /* video obj layer */ - - put_bits(&s->pb, 1, 0); /* random access vol */ - put_bits(&s->pb, 8, s->vo_type); /* video obj type indication */ - if(s->workaround_bugs & FF_BUG_MS) { - put_bits(&s->pb, 1, 0); /* is obj layer id= no */ - } else { - put_bits(&s->pb, 1, 1); /* is obj layer id= yes */ - put_bits(&s->pb, 4, vo_ver_id); /* is obj layer ver id */ - put_bits(&s->pb, 3, 1); /* is obj layer priority */ - } - - aspect_to_info(s, s->avctx->sample_aspect_ratio); - - put_bits(&s->pb, 4, s->aspect_ratio_info);/* aspect ratio info */ - if (s->aspect_ratio_info == FF_ASPECT_EXTENDED){ - put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.num); - put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.den); - } - - if(s->workaround_bugs & FF_BUG_MS) { // - put_bits(&s->pb, 1, 0); /* vol control parameters= no @@@ */ - } else { - put_bits(&s->pb, 1, 1); /* vol control parameters= yes */ - put_bits(&s->pb, 2, 1); /* chroma format YUV 420/YV12 */ - put_bits(&s->pb, 1, s->low_delay); - put_bits(&s->pb, 1, 0); /* vbv parameters= no */ - } - - put_bits(&s->pb, 2, RECT_SHAPE); /* vol shape= rectangle */ - put_bits(&s->pb, 1, 1); /* marker bit */ - - put_bits(&s->pb, 16, s->avctx->time_base.den); - if (s->time_increment_bits < 1) - s->time_increment_bits = 1; - put_bits(&s->pb, 1, 1); /* marker bit */ - put_bits(&s->pb, 1, 0); /* fixed vop rate=no */ - put_bits(&s->pb, 1, 1); /* marker bit */ - put_bits(&s->pb, 13, s->width); /* vol width */ - put_bits(&s->pb, 1, 1); /* marker bit */ - put_bits(&s->pb, 13, s->height); /* vol height */ - put_bits(&s->pb, 1, 1); /* marker bit */ - put_bits(&s->pb, 1, s->progressive_sequence ? 0 : 1); - put_bits(&s->pb, 1, 1); /* obmc disable */ - if (vo_ver_id == 1) { - put_bits(&s->pb, 1, s->vol_sprite_usage); /* sprite enable */ - }else{ - put_bits(&s->pb, 2, s->vol_sprite_usage); /* sprite enable */ - } - - put_bits(&s->pb, 1, 0); /* not 8 bit == false */ - put_bits(&s->pb, 1, s->mpeg_quant); /* quant type= (0=h263 style)*/ - - if(s->mpeg_quant){ - ff_write_quant_matrix(&s->pb, s->avctx->intra_matrix); - ff_write_quant_matrix(&s->pb, s->avctx->inter_matrix); - } - - if (vo_ver_id != 1) - put_bits(&s->pb, 1, s->quarter_sample); - put_bits(&s->pb, 1, 1); /* complexity estimation disable */ - s->resync_marker= s->rtp_mode; - put_bits(&s->pb, 1, s->resync_marker ? 0 : 1);/* resync marker disable */ - put_bits(&s->pb, 1, s->data_partitioning ? 1 : 0); - if(s->data_partitioning){ - put_bits(&s->pb, 1, 0); /* no rvlc */ - } - - if (vo_ver_id != 1){ - put_bits(&s->pb, 1, 0); /* newpred */ - put_bits(&s->pb, 1, 0); /* reduced res vop */ - } - put_bits(&s->pb, 1, 0); /* scalability */ - - ff_mpeg4_stuffing(&s->pb); - - /* user data */ - if(!(s->flags & CODEC_FLAG_BITEXACT)){ - put_bits(&s->pb, 16, 0); - put_bits(&s->pb, 16, 0x1B2); /* user_data */ - ff_put_string(&s->pb, LIBAVCODEC_IDENT, 0); - } -} - -/* write mpeg4 VOP header */ -void mpeg4_encode_picture_header(MpegEncContext * s, int picture_number) -{ - int time_incr; - int time_div, time_mod; - - if(s->pict_type==FF_I_TYPE){ - if(!(s->flags&CODEC_FLAG_GLOBAL_HEADER)){ - if(s->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT) //HACK, the reference sw is buggy - mpeg4_encode_visual_object_header(s); - if(s->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT || picture_number==0) //HACK, the reference sw is buggy - mpeg4_encode_vol_header(s, 0, 0); - } - if(!(s->workaround_bugs & FF_BUG_MS)) - mpeg4_encode_gop_header(s); - } - - s->partitioned_frame= s->data_partitioning && s->pict_type!=FF_B_TYPE; - -//printf("num:%d rate:%d base:%d\n", s->picture_number, s->time_base.den, FRAME_RATE_BASE); - - put_bits(&s->pb, 16, 0); /* vop header */ - 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_incr= time_div - s->last_time_base; - assert(time_incr >= 0); - while(time_incr--) - put_bits(&s->pb, 1, 1); - - put_bits(&s->pb, 1, 0); - - put_bits(&s->pb, 1, 1); /* marker */ - put_bits(&s->pb, s->time_increment_bits, time_mod); /* time increment */ - put_bits(&s->pb, 1, 1); /* marker */ - put_bits(&s->pb, 1, 1); /* vop coded */ - if ( s->pict_type == FF_P_TYPE - || (s->pict_type == FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE)) { - put_bits(&s->pb, 1, s->no_rounding); /* rounding type */ - } - 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->alternate_scan); - } - //FIXME sprite stuff - - put_bits(&s->pb, 5, s->qscale); - - if (s->pict_type != FF_I_TYPE) - put_bits(&s->pb, 3, s->f_code); /* fcode_for */ - if (s->pict_type == FF_B_TYPE) - put_bits(&s->pb, 3, s->b_code); /* fcode_back */ - // printf("****frame %d\n", picture_number); -} - -#endif //CONFIG_ENCODERS - -/** - * predicts the dc. - * encoding quantized level -> quantized diff - * decoding quantized diff -> quantized level - * @param n block index (0-3 are luma, 4-5 are chroma) - * @param dir_ptr pointer to an integer where the prediction direction will be stored - */ -static inline int ff_mpeg4_pred_dc(MpegEncContext * s, int n, int level, int *dir_ptr, int encoding) -{ - int a, b, c, wrap, pred, scale, ret; - int16_t *dc_val; - - /* find prediction */ - if (n < 4) { - scale = s->y_dc_scale; - } else { - scale = s->c_dc_scale; - } - if(IS_3IV1) - scale= 8; - - wrap= s->block_wrap[n]; - dc_val = s->dc_val[0] + s->block_index[n]; - - /* B C - * A X - */ - a = dc_val[ - 1]; - b = dc_val[ - 1 - wrap]; - c = dc_val[ - wrap]; - - /* outside slice handling (we can't do that by memset as we need the dc for error resilience) */ - if(s->first_slice_line && n!=3){ - if(n!=2) b=c= 1024; - if(n!=1 && s->mb_x == s->resync_mb_x) b=a= 1024; - } - if(s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y+1){ - if(n==0 || n==4 || n==5) - b=1024; - } - - if (abs(a - b) < abs(b - c)) { - pred = c; - *dir_ptr = 1; /* top */ - } else { - pred = a; - *dir_ptr = 0; /* left */ - } - /* we assume pred is positive */ - pred = FASTDIV((pred + (scale >> 1)), scale); - - if(encoding){ - ret = level - pred; - }else{ - level += pred; - ret= level; - if(s->error_recognition>=3){ - if(level<0){ - av_log(s->avctx, AV_LOG_ERROR, "dc<0 at %dx%d\n", s->mb_x, s->mb_y); - return -1; - } - if(level*scale > 2048 + scale){ - av_log(s->avctx, AV_LOG_ERROR, "dc overflow at %dx%d\n", s->mb_x, s->mb_y); - return -1; - } - } - } - level *=scale; - if(level&(~2047)){ - if(level<0) - level=0; - else if(!(s->workaround_bugs&FF_BUG_DC_CLIP)) - level=2047; - } - dc_val[0]= level; - - return ret; -} - -/** - * predicts the ac. - * @param n block index (0-3 are luma, 4-5 are chroma) - * @param dir the ac prediction direction - */ -void mpeg4_pred_ac(MpegEncContext * s, DCTELEM *block, int n, - int dir) -{ - int i; - int16_t *ac_val, *ac_val1; - int8_t * const qscale_table= s->current_picture.qscale_table; - - /* find prediction */ - ac_val = s->ac_val[0][0] + s->block_index[n] * 16; - ac_val1 = ac_val; - if (s->ac_pred) { - if (dir == 0) { - const int xy= s->mb_x-1 + s->mb_y*s->mb_stride; - /* left prediction */ - ac_val -= 16; - - if(s->mb_x==0 || s->qscale == qscale_table[xy] || n==1 || n==3){ - /* same qscale */ - for(i=1;i<8;i++) { - block[s->dsp.idct_permutation[i<<3]] += ac_val[i]; - } - }else{ - /* different qscale, we must rescale */ - for(i=1;i<8;i++) { - block[s->dsp.idct_permutation[i<<3]] += ROUNDED_DIV(ac_val[i]*qscale_table[xy], s->qscale); - } - } - } else { - const int xy= s->mb_x + s->mb_y*s->mb_stride - s->mb_stride; - /* top prediction */ - ac_val -= 16 * s->block_wrap[n]; - - if(s->mb_y==0 || s->qscale == qscale_table[xy] || n==2 || n==3){ - /* same qscale */ - for(i=1;i<8;i++) { - block[s->dsp.idct_permutation[i]] += ac_val[i + 8]; - } - }else{ - /* different qscale, we must rescale */ - for(i=1;i<8;i++) { - block[s->dsp.idct_permutation[i]] += ROUNDED_DIV(ac_val[i + 8]*qscale_table[xy], s->qscale); - } - } - } - } - /* left copy */ - for(i=1;i<8;i++) - ac_val1[i ] = block[s->dsp.idct_permutation[i<<3]]; - - /* top copy */ - for(i=1;i<8;i++) - ac_val1[8 + i] = block[s->dsp.idct_permutation[i ]]; - -} - -#if CONFIG_ENCODERS - -/** - * encodes the dc value. - * @param n block index (0-3 are luma, 4-5 are chroma) - */ -static inline void mpeg4_encode_dc(PutBitContext * s, int level, int n) -{ -#if 1 -// if(level<-255 || level>255) printf("dc overflow\n"); - level+=256; - if (n < 4) { - /* luminance */ - put_bits(s, uni_DCtab_lum_len[level], uni_DCtab_lum_bits[level]); - } else { - /* chrominance */ - put_bits(s, uni_DCtab_chrom_len[level], uni_DCtab_chrom_bits[level]); - } -#else - int size, v; - /* find number of bits */ - size = 0; - v = abs(level); - while (v) { - v >>= 1; - size++; - } - - if (n < 4) { - /* luminance */ - put_bits(&s->pb, DCtab_lum[size][1], DCtab_lum[size][0]); - } else { - /* chrominance */ - put_bits(&s->pb, DCtab_chrom[size][1], DCtab_chrom[size][0]); - } - - /* encode remaining bits */ - if (size > 0) { - if (level < 0) - level = (-level) ^ ((1 << size) - 1); - put_bits(&s->pb, size, level); - if (size > 8) - put_bits(&s->pb, 1, 1); - } -#endif -} - -static inline int mpeg4_get_dc_length(int level, int n){ - if (n < 4) { - return uni_DCtab_lum_len[level + 256]; - } else { - return uni_DCtab_chrom_len[level + 256]; - } -} - -/** - * encodes a 8x8 block - * @param n block index (0-3 are luma, 4-5 are chroma) - */ -static inline void mpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n, int intra_dc, - uint8_t *scan_table, PutBitContext *dc_pb, PutBitContext *ac_pb) -{ - int i, last_non_zero; -#if 0 //variables for the outcommented version - int code, sign, last; -#endif - const RLTable *rl; - uint32_t *bits_tab; - uint8_t *len_tab; - const int last_index = s->block_last_index[n]; - - if (s->mb_intra) { //Note gcc (3.2.1 at least) will optimize this away - /* mpeg4 based DC predictor */ - mpeg4_encode_dc(dc_pb, intra_dc, n); - if(last_index<1) return; - i = 1; - rl = &rl_intra; - bits_tab= uni_mpeg4_intra_rl_bits; - len_tab = uni_mpeg4_intra_rl_len; - } else { - if(last_index<0) return; - i = 0; - rl = &rl_inter; - bits_tab= uni_mpeg4_inter_rl_bits; - len_tab = uni_mpeg4_inter_rl_len; - } - - /* AC coefs */ - last_non_zero = i - 1; -#if 1 - for (; i < last_index; i++) { - int level = block[ scan_table[i] ]; - if (level) { - int run = i - last_non_zero - 1; - level+=64; - if((level&(~127)) == 0){ - const int index= UNI_MPEG4_ENC_INDEX(0, run, level); - put_bits(ac_pb, len_tab[index], bits_tab[index]); - }else{ //ESC3 - put_bits(ac_pb, 7+2+1+6+1+12+1, (3<<23)+(3<<21)+(0<<20)+(run<<14)+(1<<13)+(((level-64)&0xfff)<<1)+1); - } - last_non_zero = i; - } - } - /*if(i<=last_index)*/{ - int level = block[ scan_table[i] ]; - int run = i - last_non_zero - 1; - level+=64; - if((level&(~127)) == 0){ - const int index= UNI_MPEG4_ENC_INDEX(1, run, level); - put_bits(ac_pb, len_tab[index], bits_tab[index]); - }else{ //ESC3 - put_bits(ac_pb, 7+2+1+6+1+12+1, (3<<23)+(3<<21)+(1<<20)+(run<<14)+(1<<13)+(((level-64)&0xfff)<<1)+1); - } - } -#else - for (; i <= last_index; i++) { - const int slevel = block[ scan_table[i] ]; - if (slevel) { - int level; - int run = i - last_non_zero - 1; - last = (i == last_index); - sign = 0; - level = slevel; - if (level < 0) { - sign = 1; - level = -level; - } - code = get_rl_index(rl, last, run, level); - put_bits(ac_pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); - if (code == rl->n) { - int level1, run1; - level1 = level - rl->max_level[last][run]; - if (level1 < 1) - goto esc2; - code = get_rl_index(rl, last, run, level1); - if (code == rl->n) { - esc2: - put_bits(ac_pb, 1, 1); - if (level > MAX_LEVEL) - goto esc3; - run1 = run - rl->max_run[last][level] - 1; - if (run1 < 0) - goto esc3; - code = get_rl_index(rl, last, run1, level); - if (code == rl->n) { - esc3: - /* third escape */ - put_bits(ac_pb, 1, 1); - put_bits(ac_pb, 1, last); - put_bits(ac_pb, 6, run); - put_bits(ac_pb, 1, 1); - put_sbits(ac_pb, 12, slevel); - put_bits(ac_pb, 1, 1); - } else { - /* second escape */ - put_bits(ac_pb, 1, 0); - put_bits(ac_pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); - put_bits(ac_pb, 1, sign); - } - } else { - /* first escape */ - put_bits(ac_pb, 1, 0); - put_bits(ac_pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); - put_bits(ac_pb, 1, sign); - } - } else { - put_bits(ac_pb, 1, sign); - } - last_non_zero = i; - } - } -#endif -} - -static int mpeg4_get_block_length(MpegEncContext * s, DCTELEM * block, int n, int intra_dc, - uint8_t *scan_table) -{ - int i, last_non_zero; - uint8_t *len_tab; - const int last_index = s->block_last_index[n]; - int len=0; - - if (s->mb_intra) { //Note gcc (3.2.1 at least) will optimize this away - /* mpeg4 based DC predictor */ - len += mpeg4_get_dc_length(intra_dc, n); - if(last_index<1) return len; - i = 1; - len_tab = uni_mpeg4_intra_rl_len; - } else { - if(last_index<0) return 0; - i = 0; - len_tab = uni_mpeg4_inter_rl_len; - } - - /* AC coefs */ - last_non_zero = i - 1; - for (; i < last_index; i++) { - int level = block[ scan_table[i] ]; - if (level) { - int run = i - last_non_zero - 1; - level+=64; - if((level&(~127)) == 0){ - const int index= UNI_MPEG4_ENC_INDEX(0, run, level); - len += len_tab[index]; - }else{ //ESC3 - len += 7+2+1+6+1+12+1; - } - last_non_zero = i; - } - } - /*if(i<=last_index)*/{ - int level = block[ scan_table[i] ]; - int run = i - last_non_zero - 1; - level+=64; - if((level&(~127)) == 0){ - const int index= UNI_MPEG4_ENC_INDEX(1, run, level); - len += len_tab[index]; - }else{ //ESC3 - len += 7+2+1+6+1+12+1; - } - } - - return len; -} - -#endif - - -/***********************************************/ -/* decoding */ - -static VLC intra_MCBPC_vlc; -static VLC inter_MCBPC_vlc; -static VLC cbpy_vlc; -static VLC mv_vlc; -static VLC dc_lum, dc_chrom; -static VLC sprite_trajectory; -static VLC mb_type_b_vlc; -static VLC h263_mbtype_b_vlc; -static VLC cbpc_b_vlc; - -/* init vlcs */ - -/* XXX: find a better solution to handle static init */ -void h263_decode_init_vlc(MpegEncContext *s) -{ - static int done = 0; - - if (!done) { - done = 1; - - INIT_VLC_STATIC(&intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 9, - intra_MCBPC_bits, 1, 1, - intra_MCBPC_code, 1, 1, 72); - INIT_VLC_STATIC(&inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 28, - inter_MCBPC_bits, 1, 1, - inter_MCBPC_code, 1, 1, 198); - INIT_VLC_STATIC(&cbpy_vlc, CBPY_VLC_BITS, 16, - &cbpy_tab[0][1], 2, 1, - &cbpy_tab[0][0], 2, 1, 64); - INIT_VLC_STATIC(&mv_vlc, MV_VLC_BITS, 33, - &mvtab[0][1], 2, 1, - &mvtab[0][0], 2, 1, 538); - init_rl(&rl_inter, static_rl_table_store[0]); - init_rl(&rl_intra, static_rl_table_store[1]); - init_rl(&rvlc_rl_inter, static_rl_table_store[3]); - init_rl(&rvlc_rl_intra, static_rl_table_store[4]); - init_rl(&rl_intra_aic, static_rl_table_store[2]); - INIT_VLC_RL(rl_inter, 554); - INIT_VLC_RL(rl_intra, 554); - INIT_VLC_RL(rvlc_rl_inter, 1072); - INIT_VLC_RL(rvlc_rl_intra, 1072); - INIT_VLC_RL(rl_intra_aic, 554); - INIT_VLC_STATIC(&dc_lum, DC_VLC_BITS, 10 /* 13 */, - &DCtab_lum[0][1], 2, 1, - &DCtab_lum[0][0], 2, 1, 512); - INIT_VLC_STATIC(&dc_chrom, DC_VLC_BITS, 10 /* 13 */, - &DCtab_chrom[0][1], 2, 1, - &DCtab_chrom[0][0], 2, 1, 512); - INIT_VLC_STATIC(&sprite_trajectory, SPRITE_TRAJ_VLC_BITS, 15, - &sprite_trajectory_tab[0][1], 4, 2, - &sprite_trajectory_tab[0][0], 4, 2, 128); - INIT_VLC_STATIC(&mb_type_b_vlc, MB_TYPE_B_VLC_BITS, 4, - &mb_type_b_tab[0][1], 2, 1, - &mb_type_b_tab[0][0], 2, 1, 16); - INIT_VLC_STATIC(&h263_mbtype_b_vlc, H263_MBTYPE_B_VLC_BITS, 15, - &h263_mbtype_b_tab[0][1], 2, 1, - &h263_mbtype_b_tab[0][0], 2, 1, 80); - INIT_VLC_STATIC(&cbpc_b_vlc, CBPC_B_VLC_BITS, 4, - &cbpc_b_tab[0][1], 2, 1, - &cbpc_b_tab[0][0], 2, 1, 8); - } -} /** * Get the GOB height based on picture height. @@ -2952,3427 +383,3 @@ int ff_h263_get_gob_height(MpegEncContext *s){ else return 4; } - -int ff_h263_decode_mba(MpegEncContext *s) -{ - int i, mb_pos; - - for(i=0; i<6; i++){ - if(s->mb_num-1 <= ff_mba_max[i]) break; - } - mb_pos= get_bits(&s->gb, ff_mba_length[i]); - s->mb_x= mb_pos % s->mb_width; - s->mb_y= mb_pos / s->mb_width; - - return mb_pos; -} - -void ff_h263_encode_mba(MpegEncContext *s) -{ - int i, mb_pos; - - for(i=0; i<6; i++){ - if(s->mb_num-1 <= ff_mba_max[i]) break; - } - mb_pos= s->mb_x + s->mb_width*s->mb_y; - put_bits(&s->pb, ff_mba_length[i], mb_pos); -} - -/** - * decodes the group of blocks header or slice header. - * @return <0 if an error occurred - */ -static int h263_decode_gob_header(MpegEncContext *s) -{ - unsigned int val, gfid, gob_number; - int left; - - /* Check for GOB Start Code */ - val = show_bits(&s->gb, 16); - if(val) - return -1; - - /* We have a GBSC probably with GSTUFF */ - skip_bits(&s->gb, 16); /* Drop the zeros */ - left= s->gb.size_in_bits - get_bits_count(&s->gb); - //MN: we must check the bits left or we might end in a infinite loop (or segfault) - for(;left>13; left--){ - if(get_bits1(&s->gb)) break; /* Seek the '1' bit */ - } - if(left<=13) - return -1; - - if(s->h263_slice_structured){ - if(get_bits1(&s->gb)==0) - return -1; - - ff_h263_decode_mba(s); - - if(s->mb_num > 1583) - if(get_bits1(&s->gb)==0) - return -1; - - s->qscale = get_bits(&s->gb, 5); /* SQUANT */ - if(get_bits1(&s->gb)==0) - return -1; - gfid = get_bits(&s->gb, 2); /* GFID */ - }else{ - gob_number = get_bits(&s->gb, 5); /* GN */ - s->mb_x= 0; - s->mb_y= s->gob_index* gob_number; - gfid = get_bits(&s->gb, 2); /* GFID */ - s->qscale = get_bits(&s->gb, 5); /* GQUANT */ - } - - if(s->mb_y >= s->mb_height) - return -1; - - if(s->qscale==0) - return -1; - - return 0; -} - -static inline void memsetw(short *tab, int val, int n) -{ - int i; - for(i=0;ipb); - uint8_t *end= s->pb.buf_end; - int size= end - start; - int pb_size = (((intptr_t)start + size/3)&(~3)) - (intptr_t)start; - int tex_size= (size - 2*pb_size)&(~3); - - set_put_bits_buffer_size(&s->pb, pb_size); - init_put_bits(&s->tex_pb, start + pb_size , tex_size); - init_put_bits(&s->pb2 , start + pb_size + tex_size, pb_size); -} - -void ff_mpeg4_merge_partitions(MpegEncContext *s) -{ - const int pb2_len = put_bits_count(&s->pb2 ); - const int tex_pb_len= put_bits_count(&s->tex_pb); - const int bits= put_bits_count(&s->pb); - - if(s->pict_type==FF_I_TYPE){ - put_bits(&s->pb, 19, DC_MARKER); - s->misc_bits+=19 + pb2_len + bits - s->last_bits; - s->i_tex_bits+= tex_pb_len; - }else{ - put_bits(&s->pb, 17, MOTION_MARKER); - s->misc_bits+=17 + pb2_len; - s->mv_bits+= bits - s->last_bits; - s->p_tex_bits+= tex_pb_len; - } - - flush_put_bits(&s->pb2); - 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); - s->last_bits= put_bits_count(&s->pb); -} - -#endif //CONFIG_ENCODERS - -int ff_mpeg4_get_video_packet_prefix_length(MpegEncContext *s){ - switch(s->pict_type){ - case FF_I_TYPE: - return 16; - case FF_P_TYPE: - case FF_S_TYPE: - return s->f_code+15; - case FF_B_TYPE: - return FFMAX3(s->f_code, s->b_code, 2) + 15; - default: - return -1; - } -} - -#if CONFIG_ENCODERS - -void ff_mpeg4_encode_video_packet_header(MpegEncContext *s) -{ - int mb_num_bits= av_log2(s->mb_num - 1) + 1; - - put_bits(&s->pb, ff_mpeg4_get_video_packet_prefix_length(s), 0); - put_bits(&s->pb, 1, 1); - - put_bits(&s->pb, mb_num_bits, s->mb_x + s->mb_y*s->mb_width); - put_bits(&s->pb, s->quant_precision, s->qscale); - put_bits(&s->pb, 1, 0); /* no HEC */ -} - -#endif //CONFIG_ENCODERS - -/** - * check if the next stuff is a resync marker or the end. - * @return 0 if not - */ -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){ - return 0; - } - - while(v<=0xFF){ - if(s->pict_type==FF_B_TYPE || (v>>(8-s->pict_type)!=1) || s->partitioned_frame) - break; - skip_bits(&s->gb, 8+s->pict_type); - bits_count+= 8+s->pict_type; - v= show_bits(&s->gb, 16); - } - - if(bits_count + 8 >= s->gb.size_in_bits){ - v>>=8; - v|= 0x7F >> (7-(bits_count&7)); - - if(v==0x7F) - return 1; - }else{ - if(v == ff_mpeg4_resync_prefix[bits_count&7]){ - int len; - GetBitContext gb= s->gb; - - skip_bits(&s->gb, 1); - align_get_bits(&s->gb); - - for(len=0; len<32; len++){ - if(get_bits1(&s->gb)) break; - } - - s->gb= gb; - - if(len>=ff_mpeg4_get_video_packet_prefix_length(s)) - return 1; - } - } - return 0; -} - -/** - * decodes the next video packet. - * @return <0 if something went wrong - */ -static int mpeg4_decode_video_packet_header(MpegEncContext *s) -{ - int mb_num_bits= av_log2(s->mb_num - 1) + 1; - int header_extension=0, mb_num, len; - - /* is there enough space left for a video packet + header */ - if( get_bits_count(&s->gb) > s->gb.size_in_bits-20) return -1; - - for(len=0; len<32; len++){ - if(get_bits1(&s->gb)) break; - } - - if(len!=ff_mpeg4_get_video_packet_prefix_length(s)){ - av_log(s->avctx, AV_LOG_ERROR, "marker does not match f_code\n"); - return -1; - } - - if(s->shape != RECT_SHAPE){ - header_extension= get_bits1(&s->gb); - //FIXME more stuff here - } - - mb_num= get_bits(&s->gb, mb_num_bits); - if(mb_num>=s->mb_num){ - 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 == FF_B_TYPE){ - while(s->next_picture.mbskip_table[ s->mb_index2xy[ mb_num ] ]) mb_num++; - 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; - - if(s->shape != BIN_ONLY_SHAPE){ - int qscale= get_bits(&s->gb, s->quant_precision); - if(qscale) - s->chroma_qscale=s->qscale= qscale; - } - - if(s->shape == RECT_SHAPE){ - header_extension= get_bits1(&s->gb); - } - if(header_extension){ - int time_increment; - int time_incr=0; - - while (get_bits1(&s->gb) != 0) - time_incr++; - - check_marker(&s->gb, "before time_increment in video packed header"); - time_increment= get_bits(&s->gb, s->time_increment_bits); - check_marker(&s->gb, "before vop_coding_type in video packed header"); - - skip_bits(&s->gb, 2); /* vop coding type */ - //FIXME not rect stuff here - - if(s->shape != BIN_ONLY_SHAPE){ - skip_bits(&s->gb, 3); /* intra dc vlc threshold */ -//FIXME don't just ignore everything - if(s->pict_type == FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE){ - mpeg4_decode_sprite_trajectory(s, &s->gb); - av_log(s->avctx, AV_LOG_ERROR, "untested\n"); - } - - //FIXME reduced res stuff here - - if (s->pict_type != FF_I_TYPE) { - int f_code = get_bits(&s->gb, 3); /* fcode_for */ - if(f_code==0){ - av_log(s->avctx, AV_LOG_ERROR, "Error, video packet header damaged (f_code=0)\n"); - } - } - if (s->pict_type == FF_B_TYPE) { - int b_code = get_bits(&s->gb, 3); - if(b_code==0){ - av_log(s->avctx, AV_LOG_ERROR, "Error, video packet header damaged (b_code=0)\n"); - } - } - } - } - //FIXME new-pred stuff - -//printf("parse ok %d %d %d %d\n", mb_num, s->mb_x + s->mb_y*s->mb_width, get_bits_count(gb), get_bits_count(&s->gb)); - - return 0; -} - -void ff_mpeg4_clean_buffers(MpegEncContext *s) -{ - int c_wrap, c_xy, l_wrap, l_xy; - - l_wrap= s->b8_stride; - l_xy= (2*s->mb_y-1)*l_wrap + s->mb_x*2 - 1; - c_wrap= s->mb_stride; - c_xy= (s->mb_y-1)*c_wrap + s->mb_x - 1; - -#if 0 - /* clean DC */ - memsetw(s->dc_val[0] + l_xy, 1024, l_wrap*2+1); - memsetw(s->dc_val[1] + c_xy, 1024, c_wrap+1); - memsetw(s->dc_val[2] + c_xy, 1024, c_wrap+1); -#endif - - /* clean AC */ - memset(s->ac_val[0] + l_xy, 0, (l_wrap*2+1)*16*sizeof(int16_t)); - memset(s->ac_val[1] + c_xy, 0, (c_wrap +1)*16*sizeof(int16_t)); - memset(s->ac_val[2] + c_xy, 0, (c_wrap +1)*16*sizeof(int16_t)); - - /* clean MV */ - // we can't clear the MVs as they might be needed by a b frame -// memset(s->motion_val + l_xy, 0, (l_wrap*2+1)*2*sizeof(int16_t)); -// memset(s->motion_val, 0, 2*sizeof(int16_t)*(2 + s->mb_width*2)*(2 + s->mb_height*2)); - s->last_mv[0][0][0]= - s->last_mv[0][0][1]= - s->last_mv[1][0][0]= - s->last_mv[1][0][1]= 0; -} - -/** - * finds the next resync_marker - * @param p pointer to buffer to scan - * @param end pointer to the end of the buffer - * @return pointer to the next resync_marker, or \p end if none was found - */ -const uint8_t *ff_h263_find_resync_marker(const uint8_t *restrict p, const uint8_t * restrict end) -{ - assert(p < end); - - end-=2; - p++; - for(;pcodec_id==CODEC_ID_MPEG4){ - skip_bits1(&s->gb); - align_get_bits(&s->gb); - } - - if(show_bits(&s->gb, 16)==0){ - pos= get_bits_count(&s->gb); - if(s->codec_id==CODEC_ID_MPEG4) - ret= mpeg4_decode_video_packet_header(s); - else - ret= h263_decode_gob_header(s); - if(ret>=0) - return pos; - } - //OK, it's not where it is supposed to be ... - s->gb= s->last_resync_gb; - align_get_bits(&s->gb); - left= s->gb.size_in_bits - get_bits_count(&s->gb); - - for(;left>16+1+5+5; left-=8){ - if(show_bits(&s->gb, 16)==0){ - GetBitContext bak= s->gb; - - pos= get_bits_count(&s->gb); - if(s->codec_id==CODEC_ID_MPEG4) - ret= mpeg4_decode_video_packet_header(s); - else - ret= h263_decode_gob_header(s); - if(ret>=0) - return pos; - - s->gb= bak; - } - skip_bits(&s->gb, 8); - } - - return -1; -} - -/** - * gets the average motion vector for a GMC MB. - * @param n either 0 for the x component or 1 for y - * @returns the average MV for a GMC MB - */ -static inline int get_amv(MpegEncContext *s, int n){ - int x, y, mb_v, sum, dx, dy, shift; - int len = 1 << (s->f_code + 4); - const int a= s->sprite_warping_accuracy; - - if(s->workaround_bugs & FF_BUG_AMV) - len >>= s->quarter_sample; - - if(s->real_sprite_warping_points==1){ - if(s->divx_version==500 && s->divx_build==413) - sum= s->sprite_offset[0][n] / (1<<(a - s->quarter_sample)); - else - sum= RSHIFT(s->sprite_offset[0][n]<quarter_sample, a); - }else{ - dx= s->sprite_delta[n][0]; - dy= s->sprite_delta[n][1]; - shift= s->sprite_shift[0]; - if(n) dy -= 1<<(shift + a + 1); - else dx -= 1<<(shift + a + 1); - mb_v= s->sprite_offset[0][n] + dx*s->mb_x*16 + dy*s->mb_y*16; - - sum=0; - for(y=0; y<16; y++){ - int v; - - v= mb_v + dy*y; - //XXX FIXME optimize - for(x=0; x<16; x++){ - sum+= v>>shift; - v+= dx; - } - } - sum= RSHIFT(sum, a+8-s->quarter_sample); - } - - if (sum < -len) sum= -len; - else if (sum >= len) sum= len-1; - - return sum; -} - -/** - * decodes first partition. - * @return number of MBs decoded or <0 if an error occurred - */ -static int mpeg4_decode_partition_a(MpegEncContext *s){ - int mb_num; - static const int8_t quant_tab[4] = { -1, -2, 1, 2 }; - - /* decode first partition */ - mb_num=0; - s->first_slice_line=1; - for(; s->mb_ymb_height; s->mb_y++){ - ff_init_block_index(s); - for(; s->mb_xmb_width; s->mb_x++){ - const int xy= s->mb_x + s->mb_y*s->mb_stride; - int cbpc; - int dir=0; - - mb_num++; - ff_update_block_index(s); - if(s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y+1) - s->first_slice_line=0; - - if(s->pict_type==FF_I_TYPE){ - int i; - - do{ - if(show_bits_long(&s->gb, 19)==DC_MARKER){ - return mb_num-1; - } - - cbpc = get_vlc2(&s->gb, intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2); - if (cbpc < 0){ - av_log(s->avctx, AV_LOG_ERROR, "cbpc corrupted at %d %d\n", s->mb_x, s->mb_y); - return -1; - } - }while(cbpc == 8); - - s->cbp_table[xy]= cbpc & 3; - s->current_picture.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->mbintra_table[xy]= 1; - for(i=0; i<6; i++){ - int dc_pred_dir; - int dc= mpeg4_decode_dc(s, i, &dc_pred_dir); - if(dc < 0){ - av_log(s->avctx, AV_LOG_ERROR, "DC corrupted at %d %d\n", s->mb_x, s->mb_y); - return -1; - } - dir<<=1; - if(dc_pred_dir) dir|=1; - } - 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]]; - const int stride= s->b8_stride*2; - -try_again: - bits= show_bits(&s->gb, 17); - if(bits==MOTION_MARKER){ - return mb_num-1; - } - skip_bits1(&s->gb); - if(bits&0x10000){ - /* skip mb */ - if(s->pict_type==FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE){ - s->current_picture.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; - mx=my=0; - } - mot_val[0 ]= mot_val[2 ]= - mot_val[0+stride]= mot_val[2+stride]= mx; - mot_val[1 ]= mot_val[3 ]= - mot_val[1+stride]= mot_val[3+stride]= my; - - if(s->mbintra_table[xy]) - ff_clean_intra_table_entries(s); - continue; - } - - cbpc = get_vlc2(&s->gb, inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2); - if (cbpc < 0){ - av_log(s->avctx, AV_LOG_ERROR, "cbpc corrupted at %d %d\n", s->mb_x, s->mb_y); - return -1; - } - if(cbpc == 20) - goto try_again; - - s->cbp_table[xy]= cbpc&(8+3); //8 is dquant - - s->mb_intra = ((cbpc & 4) != 0); - - if(s->mb_intra){ - s->current_picture.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; - mot_val[1 ]= mot_val[3 ]= - mot_val[1+stride]= mot_val[3+stride]= 0; - }else{ - if(s->mbintra_table[xy]) - ff_clean_intra_table_entries(s); - - if(s->pict_type==FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE && (cbpc & 16) == 0) - s->mcsel= get_bits1(&s->gb); - else s->mcsel= 0; - - if ((cbpc & 16) == 0) { - /* 16x16 motion prediction */ - - h263_pred_motion(s, 0, 0, &pred_x, &pred_y); - if(!s->mcsel){ - mx = h263_decode_motion(s, pred_x, s->f_code); - if (mx >= 0xffff) - return -1; - - 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; - } 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; - } - - mot_val[0 ]= mot_val[2 ] = - mot_val[0+stride]= mot_val[2+stride]= mx; - mot_val[1 ]= mot_val[3 ]= - mot_val[1+stride]= mot_val[3+stride]= my; - } else { - int i; - s->current_picture.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); - if (mx >= 0xffff) - return -1; - - my = h263_decode_motion(s, pred_y, s->f_code); - if (my >= 0xffff) - return -1; - mot_val[0] = mx; - mot_val[1] = my; - } - } - } - } - } - s->mb_x= 0; - } - - return mb_num; -} - -/** - * decode second partition. - * @return <0 if an error occurred - */ -static int mpeg4_decode_partition_b(MpegEncContext *s, int mb_count){ - int mb_num=0; - static const int8_t quant_tab[4] = { -1, -2, 1, 2 }; - - s->mb_x= s->resync_mb_x; - s->first_slice_line=1; - for(s->mb_y= s->resync_mb_y; mb_num < mb_count; s->mb_y++){ - ff_init_block_index(s); - for(; mb_num < mb_count && s->mb_xmb_width; s->mb_x++){ - const int xy= s->mb_x + s->mb_y*s->mb_stride; - - mb_num++; - ff_update_block_index(s); - if(s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y+1) - s->first_slice_line=0; - - if(s->pict_type==FF_I_TYPE){ - int ac_pred= get_bits1(&s->gb); - int cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); - if(cbpy<0){ - av_log(s->avctx, AV_LOG_ERROR, "cbpy corrupted at %d %d\n", s->mb_x, s->mb_y); - return -1; - } - - s->cbp_table[xy]|= cbpy<<2; - s->current_picture.mb_type[xy] |= ac_pred*MB_TYPE_ACPRED; - }else{ /* P || S_TYPE */ - if(IS_INTRA(s->current_picture.mb_type[xy])){ - int dir=0,i; - int ac_pred = get_bits1(&s->gb); - int cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); - - if(cbpy<0){ - av_log(s->avctx, AV_LOG_ERROR, "I cbpy corrupted at %d %d\n", s->mb_x, s->mb_y); - return -1; - } - - 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; - - for(i=0; i<6; i++){ - int dc_pred_dir; - int dc= mpeg4_decode_dc(s, i, &dc_pred_dir); - if(dc < 0){ - av_log(s->avctx, AV_LOG_ERROR, "DC corrupted at %d %d\n", s->mb_x, s->mb_y); - return -1; - } - dir<<=1; - if(dc_pred_dir) dir|=1; - } - 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->pred_dir_table[xy]= dir; - }else if(IS_SKIP(s->current_picture.mb_type[xy])){ - s->current_picture.qscale_table[xy]= s->qscale; - s->cbp_table[xy]= 0; - }else{ - int cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); - - if(cbpy<0){ - av_log(s->avctx, AV_LOG_ERROR, "P cbpy corrupted at %d %d\n", s->mb_x, s->mb_y); - return -1; - } - - 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->cbp_table[xy]&= 3; //remove dquant - s->cbp_table[xy]|= (cbpy^0xf)<<2; - } - } - } - if(mb_num >= mb_count) return 0; - s->mb_x= 0; - } - return 0; -} - -/** - * decodes the first & second partition - * @return <0 if error (and sets error type in the error_status_table) - */ -int ff_mpeg4_decode_partitions(MpegEncContext *s) -{ - int mb_num; - const int part_a_error= s->pict_type==FF_I_TYPE ? (DC_ERROR|MV_ERROR) : MV_ERROR; - const int part_a_end = s->pict_type==FF_I_TYPE ? (DC_END |MV_END) : MV_END; - - mb_num= mpeg4_decode_partition_a(s); - if(mb_num<0){ - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, part_a_error); - return -1; - } - - if(s->resync_mb_x + s->resync_mb_y*s->mb_width + mb_num > s->mb_num){ - av_log(s->avctx, AV_LOG_ERROR, "slice below monitor ...\n"); - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, part_a_error); - return -1; - } - - s->mb_num_left= mb_num; - - if(s->pict_type==FF_I_TYPE){ - while(show_bits(&s->gb, 9) == 1) - skip_bits(&s->gb, 9); - if(get_bits_long(&s->gb, 19)!=DC_MARKER){ - av_log(s->avctx, AV_LOG_ERROR, "marker missing after first I partition at %d %d\n", s->mb_x, s->mb_y); - return -1; - } - }else{ - while(show_bits(&s->gb, 10) == 1) - skip_bits(&s->gb, 10); - if(get_bits(&s->gb, 17)!=MOTION_MARKER){ - av_log(s->avctx, AV_LOG_ERROR, "marker missing after first P partition at %d %d\n", s->mb_x, s->mb_y); - return -1; - } - } - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, part_a_end); - - if( mpeg4_decode_partition_b(s, mb_num) < 0){ - if(s->pict_type==FF_P_TYPE) - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, DC_ERROR); - return -1; - }else{ - if(s->pict_type==FF_P_TYPE) - ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, DC_END); - } - - return 0; -} - -/** - * decode partition C of one MB. - * @return <0 if an error occurred - */ -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]; - 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->pict_type == FF_P_TYPE || s->pict_type==FF_S_TYPE) { - 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->mb_intra = IS_INTRA(mb_type); - - if (IS_SKIP(mb_type)) { - /* skip mb */ - for(i=0;i<6;i++) - s->block_last_index[i] = -1; - s->mv_dir = MV_DIR_FORWARD; - s->mv_type = MV_TYPE_16X16; - if(s->pict_type==FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE){ - s->mcsel=1; - s->mb_skipped = 0; - }else{ - s->mcsel=0; - s->mb_skipped = 1; - } - }else if(s->mb_intra){ - s->ac_pred = IS_ACPRED(s->current_picture.mb_type[xy]); - }else if(!s->mb_intra){ -// s->mcsel= 0; //FIXME do we need to init that - - s->mv_dir = MV_DIR_FORWARD; - if (IS_8X8(mb_type)) { - s->mv_type = MV_TYPE_8X8; - } else { - s->mv_type = MV_TYPE_16X16; - } - } - } else { /* I-Frame */ - s->mb_intra = 1; - s->ac_pred = IS_ACPRED(s->current_picture.mb_type[xy]); - } - - if (!IS_SKIP(mb_type)) { - int i; - s->dsp.clear_blocks(s->block[0]); - /* decode each block */ - for (i = 0; i < 6; i++) { - if(mpeg4_decode_block(s, block[i], i, cbp&32, s->mb_intra, s->rvlc) < 0){ - av_log(s->avctx, AV_LOG_ERROR, "texture corrupted at %d %d %d\n", s->mb_x, s->mb_y, s->mb_intra); - return -1; - } - cbp+=cbp; - } - } - - /* per-MB end of slice check */ - - if(--s->mb_num_left <= 0){ -//printf("%06X %d\n", show_bits(&s->gb, 24), s->gb.size_in_bits - get_bits_count(&s->gb)); - if(mpeg4_is_resync(s)) - return SLICE_END; - else - return SLICE_NOEND; - }else{ - if(mpeg4_is_resync(s)){ - const int delta= s->mb_x + 1 == s->mb_width ? 2 : 1; - if(s->cbp_table[xy+delta]) - return SLICE_END; - } - return SLICE_OK; - } -} - -/** - * read the next MVs for OBMC. yes this is a ugly hack, feel free to send a patch :) - */ -static void preview_obmc(MpegEncContext *s){ - GetBitContext gb= s->gb; - - int cbpc, i, pred_x, pred_y, mx, my; - int16_t *mot_val; - const int xy= s->mb_x + 1 + s->mb_y * s->mb_stride; - const int stride= s->b8_stride*2; - - for(i=0; i<4; i++) - s->block_index[i]+= 2; - for(i=4; i<6; i++) - s->block_index[i]+= 1; - s->mb_x++; - - assert(s->pict_type == FF_P_TYPE); - - do{ - if (get_bits1(&s->gb)) { - /* skip mb */ - mot_val = s->current_picture.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; - goto end; - } - cbpc = get_vlc2(&s->gb, inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2); - }while(cbpc == 20); - - if(cbpc & 4){ - s->current_picture.mb_type[xy]= MB_TYPE_INTRA; - }else{ - get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); - if (cbpc & 8) { - if(s->modified_quant){ - if(get_bits1(&s->gb)) skip_bits(&s->gb, 1); - else skip_bits(&s->gb, 5); - }else - skip_bits(&s->gb, 2); - } - - if ((cbpc & 16) == 0) { - s->current_picture.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) - mx = h263p_decode_umotion(s, pred_x); - else - mx = h263_decode_motion(s, pred_x, 1); - - if (s->umvplus) - my = h263p_decode_umotion(s, pred_y); - else - my = h263_decode_motion(s, pred_y, 1); - - mot_val[0 ]= mot_val[2 ]= - mot_val[0+stride]= mot_val[2+stride]= mx; - 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; - for(i=0;i<4;i++) { - mot_val = h263_pred_motion(s, i, 0, &pred_x, &pred_y); - if (s->umvplus) - mx = h263p_decode_umotion(s, pred_x); - else - mx = h263_decode_motion(s, pred_x, 1); - - if (s->umvplus) - my = h263p_decode_umotion(s, pred_y); - else - my = h263_decode_motion(s, pred_y, 1); - if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) - skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ - mot_val[0] = mx; - mot_val[1] = my; - } - } - } -end: - - for(i=0; i<4; i++) - s->block_index[i]-= 2; - for(i=4; i<6; i++) - s->block_index[i]-= 1; - s->mb_x--; - - s->gb= gb; -} - -static void h263_decode_dquant(MpegEncContext *s){ - static const int8_t quant_tab[4] = { -1, -2, 1, 2 }; - - if(s->modified_quant){ - if(get_bits1(&s->gb)) - s->qscale= modified_quant_tab[get_bits1(&s->gb)][ s->qscale ]; - else - s->qscale= get_bits(&s->gb, 5); - }else - s->qscale += quant_tab[get_bits(&s->gb, 2)]; - ff_set_qscale(s, s->qscale); -} - -static int h263_skip_b_part(MpegEncContext *s, int cbp) -{ - DECLARE_ALIGNED(16, DCTELEM, dblock[64]); - int i, mbi; - - /* we have to set s->mb_intra to zero to decode B-part of PB-frame correctly - * but real value should be restored in order to be used later (in OBMC condition) - */ - mbi = s->mb_intra; - s->mb_intra = 0; - for (i = 0; i < 6; i++) { - if (h263_decode_block(s, dblock, i, cbp&32) < 0) - return -1; - cbp+=cbp; - } - s->mb_intra = mbi; - return 0; -} - -static int h263_get_modb(GetBitContext *gb, int pb_frame, int *cbpb) -{ - int c, mv = 1; - - if (pb_frame < 3) { // h.263 Annex G and i263 PB-frame - c = get_bits1(gb); - if (pb_frame == 2 && c) - mv = !get_bits1(gb); - } else { // h.263 Annex M improved PB-frame - mv = get_unary(gb, 0, 4) + 1; - c = mv & 1; - mv = !!(mv & 2); - } - if(c) - *cbpb = get_bits(gb, 6); - return mv; -} - -int ff_h263_decode_mb(MpegEncContext *s, - DCTELEM block[6][64]) -{ - int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant; - int16_t *mot_val; - const int xy= s->mb_x + s->mb_y * s->mb_stride; - int cbpb = 0, pb_mv_count = 0; - - assert(!s->h263_pred); - - if (s->pict_type == FF_P_TYPE) { - do{ - if (get_bits1(&s->gb)) { - /* skip mb */ - s->mb_intra = 0; - for(i=0;i<6;i++) - 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->mv[0][0][0] = 0; - s->mv[0][0][1] = 0; - s->mb_skipped = !(s->obmc | s->loop_filter); - goto end; - } - cbpc = get_vlc2(&s->gb, inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2); - //fprintf(stderr, "\tCBPC: %d", cbpc); - if (cbpc < 0){ - av_log(s->avctx, AV_LOG_ERROR, "cbpc damaged at %d %d\n", s->mb_x, s->mb_y); - return -1; - } - }while(cbpc == 20); - - s->dsp.clear_blocks(s->block[0]); - - dquant = cbpc & 8; - s->mb_intra = ((cbpc & 4) != 0); - if (s->mb_intra) goto intra; - - if(s->pb_frame && get_bits1(&s->gb)) - pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb); - cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); - - if(s->alt_inter_vlc==0 || (cbpc & 3)!=3) - cbpy ^= 0xF; - - cbp = (cbpc & 3) | (cbpy << 2); - if (dquant) { - h263_decode_dquant(s); - } - - s->mv_dir = MV_DIR_FORWARD; - if ((cbpc & 16) == 0) { - s->current_picture.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); - if (s->umvplus) - mx = h263p_decode_umotion(s, pred_x); - else - mx = h263_decode_motion(s, pred_x, 1); - - if (mx >= 0xffff) - return -1; - - if (s->umvplus) - my = h263p_decode_umotion(s, pred_y); - else - my = h263_decode_motion(s, pred_y, 1); - - if (my >= 0xffff) - return -1; - s->mv[0][0][0] = mx; - s->mv[0][0][1] = my; - - 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->mv_type = MV_TYPE_8X8; - for(i=0;i<4;i++) { - mot_val = h263_pred_motion(s, i, 0, &pred_x, &pred_y); - if (s->umvplus) - mx = h263p_decode_umotion(s, pred_x); - else - mx = h263_decode_motion(s, pred_x, 1); - if (mx >= 0xffff) - return -1; - - if (s->umvplus) - my = h263p_decode_umotion(s, pred_y); - else - my = h263_decode_motion(s, pred_y, 1); - if (my >= 0xffff) - return -1; - s->mv[0][i][0] = mx; - s->mv[0][i][1] = my; - if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) - skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ - mot_val[0] = mx; - mot_val[1] = my; - } - } - } else if(s->pict_type==FF_B_TYPE) { - 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) ]; -// const int mv_xy= s->mb_x + 1 + s->mb_y * s->mb_stride; - - //FIXME ugly - mot_val0[0 ]= mot_val0[2 ]= mot_val0[0+2*stride]= mot_val0[2+2*stride]= - mot_val0[1 ]= mot_val0[3 ]= mot_val0[1+2*stride]= mot_val0[3+2*stride]= - mot_val1[0 ]= mot_val1[2 ]= mot_val1[0+2*stride]= mot_val1[2+2*stride]= - mot_val1[1 ]= mot_val1[3 ]= mot_val1[1+2*stride]= mot_val1[3+2*stride]= 0; - - do{ - mb_type= get_vlc2(&s->gb, h263_mbtype_b_vlc.table, H263_MBTYPE_B_VLC_BITS, 2); - if (mb_type < 0){ - av_log(s->avctx, AV_LOG_ERROR, "b mb_type damaged at %d %d\n", s->mb_x, s->mb_y); - return -1; - } - - mb_type= h263_mb_type_b_map[ mb_type ]; - }while(!mb_type); - - s->mb_intra = IS_INTRA(mb_type); - if(HAS_CBP(mb_type)){ - s->dsp.clear_blocks(s->block[0]); - cbpc = get_vlc2(&s->gb, cbpc_b_vlc.table, CBPC_B_VLC_BITS, 1); - if(s->mb_intra){ - dquant = IS_QUANT(mb_type); - goto intra; - } - - cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); - - if (cbpy < 0){ - av_log(s->avctx, AV_LOG_ERROR, "b cbpy damaged at %d %d\n", s->mb_x, s->mb_y); - return -1; - } - - if(s->alt_inter_vlc==0 || (cbpc & 3)!=3) - cbpy ^= 0xF; - - cbp = (cbpc & 3) | (cbpy << 2); - }else - cbp=0; - - assert(!s->mb_intra); - - if(IS_QUANT(mb_type)){ - h263_decode_dquant(s); - } - - if(IS_DIRECT(mb_type)){ - s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; - mb_type |= ff_mpeg4_set_direct_mv(s, 0, 0); - }else{ - s->mv_dir = 0; - s->mv_type= MV_TYPE_16X16; -//FIXME UMV - - if(USES_LIST(mb_type, 0)){ - int16_t *mot_val= h263_pred_motion(s, 0, 0, &mx, &my); - s->mv_dir = MV_DIR_FORWARD; - - mx = h263_decode_motion(s, mx, 1); - my = h263_decode_motion(s, my, 1); - - s->mv[0][0][0] = mx; - s->mv[0][0][1] = my; - mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx; - mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my; - } - - if(USES_LIST(mb_type, 1)){ - int16_t *mot_val= h263_pred_motion(s, 0, 1, &mx, &my); - s->mv_dir |= MV_DIR_BACKWARD; - - mx = h263_decode_motion(s, mx, 1); - my = h263_decode_motion(s, my, 1); - - s->mv[1][0][0] = mx; - s->mv[1][0][1] = my; - mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx; - mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my; - } - } - - s->current_picture.mb_type[xy]= mb_type; - } else { /* I-Frame */ - do{ - cbpc = get_vlc2(&s->gb, intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2); - if (cbpc < 0){ - av_log(s->avctx, AV_LOG_ERROR, "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y); - return -1; - } - }while(cbpc == 8); - - s->dsp.clear_blocks(s->block[0]); - - dquant = cbpc & 4; - s->mb_intra = 1; -intra: - s->current_picture.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->h263_aic_dir = get_bits1(&s->gb); - } - }else - s->ac_pred = 0; - - if(s->pb_frame && get_bits1(&s->gb)) - pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb); - cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); - if(cbpy<0){ - av_log(s->avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y); - return -1; - } - cbp = (cbpc & 3) | (cbpy << 2); - if (dquant) { - h263_decode_dquant(s); - } - - pb_mv_count += !!s->pb_frame; - } - - while(pb_mv_count--){ - h263_decode_motion(s, 0, 1); - h263_decode_motion(s, 0, 1); - } - - /* decode each block */ - for (i = 0; i < 6; i++) { - if (h263_decode_block(s, block[i], i, cbp&32) < 0) - return -1; - cbp+=cbp; - } - - if(s->pb_frame && h263_skip_b_part(s, cbpb) < 0) - return -1; - if(s->obmc && !s->mb_intra){ - if(s->pict_type == FF_P_TYPE && s->mb_x+1mb_width && s->mb_num_left != 1) - preview_obmc(s); - } -end: - - /* per-MB end of slice check */ - { - int v= show_bits(&s->gb, 16); - - if(get_bits_count(&s->gb) + 16 > s->gb.size_in_bits){ - v>>= get_bits_count(&s->gb) + 16 - s->gb.size_in_bits; - } - - if(v==0) - return SLICE_END; - } - - return SLICE_OK; -} - -int ff_mpeg4_decode_mb(MpegEncContext *s, - DCTELEM block[6][64]) -{ - int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant; - int16_t *mot_val; - static int8_t quant_tab[4] = { -1, -2, 1, 2 }; - const int xy= s->mb_x + s->mb_y * s->mb_stride; - - assert(s->h263_pred); - - if (s->pict_type == FF_P_TYPE || s->pict_type==FF_S_TYPE) { - do{ - if (get_bits1(&s->gb)) { - /* skip mb */ - s->mb_intra = 0; - for(i=0;i<6;i++) - s->block_last_index[i] = -1; - s->mv_dir = MV_DIR_FORWARD; - s->mv_type = MV_TYPE_16X16; - if(s->pict_type==FF_S_TYPE && 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->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->mcsel=0; - s->mv[0][0][0] = 0; - s->mv[0][0][1] = 0; - s->mb_skipped = 1; - } - goto end; - } - cbpc = get_vlc2(&s->gb, inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2); - //fprintf(stderr, "\tCBPC: %d", cbpc); - if (cbpc < 0){ - av_log(s->avctx, AV_LOG_ERROR, "cbpc damaged at %d %d\n", s->mb_x, s->mb_y); - return -1; - } - }while(cbpc == 20); - - s->dsp.clear_blocks(s->block[0]); - dquant = cbpc & 8; - s->mb_intra = ((cbpc & 4) != 0); - if (s->mb_intra) goto intra; - - if(s->pict_type==FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE && (cbpc & 16) == 0) - s->mcsel= get_bits1(&s->gb); - else s->mcsel= 0; - cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1) ^ 0x0F; - - cbp = (cbpc & 3) | (cbpy << 2); - if (dquant) { - ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]); - } - if((!s->progressive_sequence) && (cbp || (s->workaround_bugs&FF_BUG_XVID_ILACE))) - s->interlaced_dct= get_bits1(&s->gb); - - 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; - /* 16x16 global motion prediction */ - s->mv_type = MV_TYPE_16X16; - mx= get_amv(s, 0); - my= get_amv(s, 1); - 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; - /* 16x8 field motion prediction */ - s->mv_type= MV_TYPE_FIELD; - - s->field_select[0][0]= get_bits1(&s->gb); - s->field_select[0][1]= get_bits1(&s->gb); - - h263_pred_motion(s, 0, 0, &pred_x, &pred_y); - - for(i=0; i<2; i++){ - mx = h263_decode_motion(s, pred_x, s->f_code); - if (mx >= 0xffff) - return -1; - - my = h263_decode_motion(s, pred_y/2, s->f_code); - if (my >= 0xffff) - return -1; - - s->mv[0][i][0] = mx; - s->mv[0][i][1] = my; - } - }else{ - s->current_picture.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); - mx = h263_decode_motion(s, pred_x, s->f_code); - - if (mx >= 0xffff) - return -1; - - my = h263_decode_motion(s, pred_y, s->f_code); - - if (my >= 0xffff) - return -1; - s->mv[0][0][0] = mx; - s->mv[0][0][1] = my; - } - } else { - s->current_picture.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); - mx = h263_decode_motion(s, pred_x, s->f_code); - if (mx >= 0xffff) - return -1; - - my = h263_decode_motion(s, pred_y, s->f_code); - if (my >= 0xffff) - return -1; - s->mv[0][i][0] = mx; - s->mv[0][i][1] = my; - mot_val[0] = mx; - mot_val[1] = my; - } - } - } else if(s->pict_type==FF_B_TYPE) { - int modb1; // first bit of modb - int modb2; // second bit of modb - int mb_type; - - s->mb_intra = 0; //B-frames never contain intra blocks - s->mcsel=0; // ... true gmc blocks - - if(s->mb_x==0){ - for(i=0; i<2; i++){ - s->last_mv[i][0][0]= - s->last_mv[i][0][1]= - s->last_mv[i][1][0]= - s->last_mv[i][1][1]= 0; - } - } - - /* 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 - - if(s->mb_skipped){ - /* skip mb */ - for(i=0;i<6;i++) - s->block_last_index[i] = -1; - - s->mv_dir = MV_DIR_FORWARD; - s->mv_type = MV_TYPE_16X16; - s->mv[0][0][0] = 0; - 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; - goto end; - } - - modb1= get_bits1(&s->gb); - if(modb1){ - mb_type= MB_TYPE_DIRECT2 | MB_TYPE_SKIP | MB_TYPE_L0L1; //like MB_TYPE_B_DIRECT but no vectors coded - cbp=0; - }else{ - modb2= get_bits1(&s->gb); - mb_type= get_vlc2(&s->gb, mb_type_b_vlc.table, MB_TYPE_B_VLC_BITS, 1); - if(mb_type<0){ - av_log(s->avctx, AV_LOG_ERROR, "illegal MB_type\n"); - return -1; - } - mb_type= mb_type_b_map[ mb_type ]; - if(modb2) cbp= 0; - else{ - s->dsp.clear_blocks(s->block[0]); - cbp= get_bits(&s->gb, 6); - } - - if ((!IS_DIRECT(mb_type)) && cbp) { - if(get_bits1(&s->gb)){ - ff_set_qscale(s, s->qscale + get_bits1(&s->gb)*4 - 2); - } - } - - if(!s->progressive_sequence){ - if(cbp) - s->interlaced_dct= get_bits1(&s->gb); - - if(!IS_DIRECT(mb_type) && get_bits1(&s->gb)){ - mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED; - mb_type &= ~MB_TYPE_16x16; - - if(USES_LIST(mb_type, 0)){ - s->field_select[0][0]= get_bits1(&s->gb); - s->field_select[0][1]= get_bits1(&s->gb); - } - if(USES_LIST(mb_type, 1)){ - s->field_select[1][0]= get_bits1(&s->gb); - s->field_select[1][1]= get_bits1(&s->gb); - } - } - } - - s->mv_dir = 0; - if((mb_type & (MB_TYPE_DIRECT2|MB_TYPE_INTERLACED)) == 0){ - s->mv_type= MV_TYPE_16X16; - - if(USES_LIST(mb_type, 0)){ - s->mv_dir = MV_DIR_FORWARD; - - mx = h263_decode_motion(s, s->last_mv[0][0][0], s->f_code); - my = h263_decode_motion(s, s->last_mv[0][0][1], s->f_code); - s->last_mv[0][1][0]= s->last_mv[0][0][0]= s->mv[0][0][0] = mx; - s->last_mv[0][1][1]= s->last_mv[0][0][1]= s->mv[0][0][1] = my; - } - - if(USES_LIST(mb_type, 1)){ - s->mv_dir |= MV_DIR_BACKWARD; - - mx = h263_decode_motion(s, s->last_mv[1][0][0], s->b_code); - my = h263_decode_motion(s, s->last_mv[1][0][1], s->b_code); - s->last_mv[1][1][0]= s->last_mv[1][0][0]= s->mv[1][0][0] = mx; - s->last_mv[1][1][1]= s->last_mv[1][0][1]= s->mv[1][0][1] = my; - } - }else if(!IS_DIRECT(mb_type)){ - s->mv_type= MV_TYPE_FIELD; - - if(USES_LIST(mb_type, 0)){ - s->mv_dir = MV_DIR_FORWARD; - - for(i=0; i<2; i++){ - mx = h263_decode_motion(s, s->last_mv[0][i][0] , s->f_code); - my = h263_decode_motion(s, s->last_mv[0][i][1]/2, s->f_code); - s->last_mv[0][i][0]= s->mv[0][i][0] = mx; - s->last_mv[0][i][1]= (s->mv[0][i][1] = my)*2; - } - } - - if(USES_LIST(mb_type, 1)){ - s->mv_dir |= MV_DIR_BACKWARD; - - for(i=0; i<2; i++){ - mx = h263_decode_motion(s, s->last_mv[1][i][0] , s->b_code); - my = h263_decode_motion(s, s->last_mv[1][i][1]/2, s->b_code); - s->last_mv[1][i][0]= s->mv[1][i][0] = mx; - s->last_mv[1][i][1]= (s->mv[1][i][1] = my)*2; - } - } - } - } - - if(IS_DIRECT(mb_type)){ - if(IS_SKIP(mb_type)) - mx=my=0; - else{ - mx = h263_decode_motion(s, 0, 1); - my = h263_decode_motion(s, 0, 1); - } - - 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; - } else { /* I-Frame */ - do{ - cbpc = get_vlc2(&s->gb, intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2); - if (cbpc < 0){ - av_log(s->avctx, AV_LOG_ERROR, "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y); - return -1; - } - }while(cbpc == 8); - - dquant = cbpc & 4; - s->mb_intra = 1; -intra: - s->ac_pred = get_bits1(&s->gb); - if(s->ac_pred) - s->current_picture.mb_type[xy]= MB_TYPE_INTRA | MB_TYPE_ACPRED; - else - s->current_picture.mb_type[xy]= MB_TYPE_INTRA; - - cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); - if(cbpy<0){ - av_log(s->avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y); - return -1; - } - cbp = (cbpc & 3) | (cbpy << 2); - - s->use_intra_dc_vlc= s->qscale < s->intra_dc_threshold; - - if (dquant) { - ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]); - } - - if(!s->progressive_sequence) - s->interlaced_dct= get_bits1(&s->gb); - - s->dsp.clear_blocks(s->block[0]); - /* decode each block */ - for (i = 0; i < 6; i++) { - if (mpeg4_decode_block(s, block[i], i, cbp&32, 1, 0) < 0) - return -1; - cbp+=cbp; - } - goto end; - } - - /* decode each block */ - for (i = 0; i < 6; i++) { - if (mpeg4_decode_block(s, block[i], i, cbp&32, 0, 0) < 0) - return -1; - cbp+=cbp; - } -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; - if(s->pict_type==FF_B_TYPE && s->next_picture.mbskip_table[xy + delta]) - return SLICE_OK; - return SLICE_END; - } - } - - return SLICE_OK; -} - -static int h263_decode_motion(MpegEncContext * s, int pred, int f_code) -{ - int code, val, sign, shift, l; - code = get_vlc2(&s->gb, mv_vlc.table, MV_VLC_BITS, 2); - - if (code == 0) - return pred; - if (code < 0) - return 0xffff; - - sign = get_bits1(&s->gb); - shift = f_code - 1; - val = code; - if (shift) { - val = (val - 1) << shift; - val |= get_bits(&s->gb, shift); - val++; - } - if (sign) - val = -val; - val += pred; - - /* modulo decoding */ - if (!s->h263_long_vectors) { - l = INT_BIT - 5 - f_code; - val = (val<>l; - } else { - /* horrible h263 long vector mode */ - if (pred < -31 && val < -63) - val += 64; - if (pred > 32 && val > 63) - val -= 64; - - } - return val; -} - -/* Decodes RVLC of H.263+ UMV */ -static int h263p_decode_umotion(MpegEncContext * s, int pred) -{ - int code = 0, sign; - - if (get_bits1(&s->gb)) /* Motion difference = 0 */ - return pred; - - code = 2 + get_bits1(&s->gb); - - while (get_bits1(&s->gb)) - { - code <<= 1; - code += get_bits1(&s->gb); - } - sign = code & 1; - code >>= 1; - - code = (sign) ? (pred - code) : (pred + code); - dprintf(s->avctx,"H.263+ UMV Motion = %d\n", code); - return code; - -} - -static int h263_decode_block(MpegEncContext * s, DCTELEM * block, - int n, int coded) -{ - int code, level, i, j, last, run; - RLTable *rl = &rl_inter; - const uint8_t *scan_table; - GetBitContext gb= s->gb; - - scan_table = s->intra_scantable.permutated; - if (s->h263_aic && s->mb_intra) { - rl = &rl_intra_aic; - i = 0; - if (s->ac_pred) { - if (s->h263_aic_dir) - scan_table = s->intra_v_scantable.permutated; /* left */ - else - scan_table = s->intra_h_scantable.permutated; /* top */ - } - } else if (s->mb_intra) { - /* DC coef */ - if(s->codec_id == CODEC_ID_RV10){ -#if CONFIG_RV10_DECODER - if (s->rv10_version == 3 && s->pict_type == FF_I_TYPE) { - int component, diff; - component = (n <= 3 ? 0 : n - 4 + 1); - level = s->last_dc[component]; - if (s->rv10_first_dc_coded[component]) { - diff = rv_decode_dc(s, n); - if (diff == 0xffff) - return -1; - level += diff; - level = level & 0xff; /* handle wrap round */ - s->last_dc[component] = level; - } else { - s->rv10_first_dc_coded[component] = 1; - } - } else { - level = get_bits(&s->gb, 8); - if (level == 255) - level = 128; - } -#endif - }else{ - level = get_bits(&s->gb, 8); - if((level&0x7F) == 0){ - av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n", level, s->mb_x, s->mb_y); - if(s->error_recognition >= FF_ER_COMPLIANT) - return -1; - } - if (level == 255) - level = 128; - } - block[0] = level; - i = 1; - } else { - i = 0; - } - if (!coded) { - if (s->mb_intra && s->h263_aic) - goto not_coded; - s->block_last_index[n] = i - 1; - return 0; - } -retry: - for(;;) { - code = get_vlc2(&s->gb, rl->vlc.table, TEX_VLC_BITS, 2); - if (code < 0){ - av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n", s->mb_x, s->mb_y); - return -1; - } - if (code == rl->n) { - /* escape */ - if (s->h263_flv > 1) { - int is11 = get_bits1(&s->gb); - last = get_bits1(&s->gb); - run = get_bits(&s->gb, 6); - if(is11){ - level = get_sbits(&s->gb, 11); - } else { - level = get_sbits(&s->gb, 7); - } - } else { - last = get_bits1(&s->gb); - run = get_bits(&s->gb, 6); - level = (int8_t)get_bits(&s->gb, 8); - if(level == -128){ - if (s->codec_id == CODEC_ID_RV10) { - /* XXX: should patch encoder too */ - level = get_sbits(&s->gb, 12); - }else{ - level = get_bits(&s->gb, 5); - level |= get_sbits(&s->gb, 6)<<5; - } - } - } - } else { - run = rl->table_run[code]; - level = rl->table_level[code]; - last = code >= rl->last; - if (get_bits1(&s->gb)) - level = -level; - } - i += run; - if (i >= 64){ - if(s->alt_inter_vlc && rl == &rl_inter && !s->mb_intra){ - //Looks like a hack but no, it's the way it is supposed to work ... - rl = &rl_intra_aic; - i = 0; - s->gb= gb; - s->dsp.clear_block(block); - goto retry; - } - av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d i:%d\n", s->mb_x, s->mb_y, s->mb_intra); - return -1; - } - j = scan_table[i]; - block[j] = level; - if (last) - break; - i++; - } -not_coded: - if (s->mb_intra && s->h263_aic) { - h263_pred_acdc(s, block, n); - i = 63; - } - s->block_last_index[n] = i; - return 0; -} - -/** - * decodes the dc value. - * @param n block index (0-3 are luma, 4-5 are chroma) - * @param dir_ptr the prediction direction will be stored here - * @return the quantized dc - */ -static inline int mpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr) -{ - int level, code; - - if (n < 4) - code = get_vlc2(&s->gb, dc_lum.table, DC_VLC_BITS, 1); - else - code = get_vlc2(&s->gb, dc_chrom.table, DC_VLC_BITS, 1); - if (code < 0 || code > 9 /* && s->nbit<9 */){ - av_log(s->avctx, AV_LOG_ERROR, "illegal dc vlc\n"); - return -1; - } - if (code == 0) { - level = 0; - } else { - if(IS_3IV1){ - if(code==1) - level= 2*get_bits1(&s->gb)-1; - else{ - if(get_bits1(&s->gb)) - level = get_bits(&s->gb, code-1) + (1<<(code-1)); - else - level = -get_bits(&s->gb, code-1) - (1<<(code-1)); - } - }else{ - level = get_xbits(&s->gb, code); - } - - if (code > 8){ - if(get_bits1(&s->gb)==0){ /* marker */ - if(s->error_recognition>=2){ - av_log(s->avctx, AV_LOG_ERROR, "dc marker bit missing\n"); - return -1; - } - } - } - } - - return ff_mpeg4_pred_dc(s, n, level, dir_ptr, 0); -} - -/** - * decodes a block. - * @return <0 if an error occurred - */ -static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block, - int n, int coded, int intra, int rvlc) -{ - int level, i, last, run; - int dc_pred_dir; - RLTable * rl; - RL_VLC_ELEM * rl_vlc; - const uint8_t * scan_table; - int qmul, qadd; - - //Note intra & rvlc should be optimized away if this is inlined - - if(intra) { - if(s->use_intra_dc_vlc){ - /* DC coef */ - if(s->partitioned_frame){ - level = s->dc_val[0][ s->block_index[n] ]; - if(n<4) level= FASTDIV((level + (s->y_dc_scale>>1)), s->y_dc_scale); - else level= FASTDIV((level + (s->c_dc_scale>>1)), s->c_dc_scale); - dc_pred_dir= (s->pred_dir_table[s->mb_x + s->mb_y*s->mb_stride]<ac_pred) { - if (dc_pred_dir == 0) - scan_table = s->intra_v_scantable.permutated; /* left */ - else - scan_table = s->intra_h_scantable.permutated; /* top */ - } else { - scan_table = s->intra_scantable.permutated; - } - qmul=1; - qadd=0; - } else { - i = -1; - if (!coded) { - s->block_last_index[n] = i; - return 0; - } - if(rvlc) rl = &rvlc_rl_inter; - else rl = &rl_inter; - - scan_table = s->intra_scantable.permutated; - - if(s->mpeg_quant){ - qmul=1; - qadd=0; - if(rvlc){ - rl_vlc = rvlc_rl_inter.rl_vlc[0]; - }else{ - rl_vlc = rl_inter.rl_vlc[0]; - } - }else{ - qmul = s->qscale << 1; - qadd = (s->qscale - 1) | 1; - if(rvlc){ - rl_vlc = rvlc_rl_inter.rl_vlc[s->qscale]; - }else{ - rl_vlc = rl_inter.rl_vlc[s->qscale]; - } - } - } - { - OPEN_READER(re, &s->gb); - for(;;) { - UPDATE_CACHE(re, &s->gb); - GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 0); - if (level==0) { - /* escape */ - if(rvlc){ - if(SHOW_UBITS(re, &s->gb, 1)==0){ - av_log(s->avctx, AV_LOG_ERROR, "1. marker bit missing in rvlc esc\n"); - return -1; - }; SKIP_CACHE(re, &s->gb, 1); - - last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1); - run= SHOW_UBITS(re, &s->gb, 6); LAST_SKIP_CACHE(re, &s->gb, 6); - SKIP_COUNTER(re, &s->gb, 1+1+6); - UPDATE_CACHE(re, &s->gb); - - if(SHOW_UBITS(re, &s->gb, 1)==0){ - av_log(s->avctx, AV_LOG_ERROR, "2. marker bit missing in rvlc esc\n"); - return -1; - }; SKIP_CACHE(re, &s->gb, 1); - - level= SHOW_UBITS(re, &s->gb, 11); SKIP_CACHE(re, &s->gb, 11); - - if(SHOW_UBITS(re, &s->gb, 5)!=0x10){ - av_log(s->avctx, AV_LOG_ERROR, "reverse esc missing\n"); - return -1; - }; SKIP_CACHE(re, &s->gb, 5); - - level= level * qmul + qadd; - level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); LAST_SKIP_CACHE(re, &s->gb, 1); - SKIP_COUNTER(re, &s->gb, 1+11+5+1); - - i+= run + 1; - if(last) i+=192; - }else{ - int cache; - cache= GET_CACHE(re, &s->gb); - - if(IS_3IV1) - cache ^= 0xC0000000; - - if (cache&0x80000000) { - if (cache&0x40000000) { - /* third escape */ - SKIP_CACHE(re, &s->gb, 2); - last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1); - run= SHOW_UBITS(re, &s->gb, 6); LAST_SKIP_CACHE(re, &s->gb, 6); - SKIP_COUNTER(re, &s->gb, 2+1+6); - UPDATE_CACHE(re, &s->gb); - - if(IS_3IV1){ - level= SHOW_SBITS(re, &s->gb, 12); LAST_SKIP_BITS(re, &s->gb, 12); - }else{ - if(SHOW_UBITS(re, &s->gb, 1)==0){ - av_log(s->avctx, AV_LOG_ERROR, "1. marker bit missing in 3. esc\n"); - return -1; - }; SKIP_CACHE(re, &s->gb, 1); - - level= SHOW_SBITS(re, &s->gb, 12); SKIP_CACHE(re, &s->gb, 12); - - if(SHOW_UBITS(re, &s->gb, 1)==0){ - av_log(s->avctx, AV_LOG_ERROR, "2. marker bit missing in 3. esc\n"); - return -1; - }; LAST_SKIP_CACHE(re, &s->gb, 1); - - SKIP_COUNTER(re, &s->gb, 1+12+1); - } - -#if 0 - if(s->error_recognition >= FF_ER_COMPLIANT){ - const int abs_level= FFABS(level); - if(abs_level<=MAX_LEVEL && run<=MAX_RUN){ - const int run1= run - rl->max_run[last][abs_level] - 1; - if(abs_level <= rl->max_level[last][run]){ - av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, vlc encoding possible\n"); - return -1; - } - if(s->error_recognition > FF_ER_COMPLIANT){ - if(abs_level <= rl->max_level[last][run]*2){ - av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 1 encoding possible\n"); - return -1; - } - if(run1 >= 0 && abs_level <= rl->max_level[last][run1]){ - av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 2 encoding possible\n"); - return -1; - } - } - } - } -#endif - if (level>0) level= level * qmul + qadd; - else level= level * qmul - qadd; - - if((unsigned)(level + 2048) > 4095){ - if(s->error_recognition > FF_ER_COMPLIANT){ - if(level > 2560 || level<-2560){ - av_log(s->avctx, AV_LOG_ERROR, "|level| overflow in 3. esc, qp=%d\n", s->qscale); - return -1; - } - } - level= level<0 ? -2048 : 2047; - } - - i+= run + 1; - if(last) i+=192; - } else { - /* second escape */ -#if MIN_CACHE_BITS < 20 - LAST_SKIP_BITS(re, &s->gb, 2); - UPDATE_CACHE(re, &s->gb); -#else - SKIP_BITS(re, &s->gb, 2); -#endif - GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1); - i+= run + rl->max_run[run>>7][level/qmul] +1; //FIXME opt indexing - level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); - LAST_SKIP_BITS(re, &s->gb, 1); - } - } else { - /* first escape */ -#if MIN_CACHE_BITS < 19 - LAST_SKIP_BITS(re, &s->gb, 1); - UPDATE_CACHE(re, &s->gb); -#else - SKIP_BITS(re, &s->gb, 1); -#endif - GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1); - i+= run; - level = level + rl->max_level[run>>7][(run-1)&63] * qmul;//FIXME opt indexing - level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); - LAST_SKIP_BITS(re, &s->gb, 1); - } - } - } else { - i+= run; - level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); - LAST_SKIP_BITS(re, &s->gb, 1); - } - if (i > 62){ - i-= 192; - 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[scan_table[i]] = level; - break; - } - - block[scan_table[i]] = level; - } - CLOSE_READER(re, &s->gb); - } - not_coded: - if (intra) { - if(!s->use_intra_dc_vlc){ - block[0] = ff_mpeg4_pred_dc(s, n, block[0], &dc_pred_dir, 0); - - i -= i>>31; //if(i == -1) i=0; - } - - mpeg4_pred_ac(s, block, n, dc_pred_dir); - if (s->ac_pred) { - i = 63; /* XXX: not optimal */ - } - } - s->block_last_index[n] = i; - return 0; -} - -/* most is hardcoded. should extend to handle all h263 streams */ -int h263_decode_picture_header(MpegEncContext *s) -{ - int format, width, height, i; - uint32_t startcode; - - align_get_bits(&s->gb); - - startcode= get_bits(&s->gb, 22-8); - - for(i= s->gb.size_in_bits - get_bits_count(&s->gb); i>24; i-=8) { - startcode = ((startcode << 8) | get_bits(&s->gb, 8)) & 0x003FFFFF; - - if(startcode == 0x20) - break; - } - - if (startcode != 0x20) { - av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n"); - return -1; - } - /* temporal reference */ - 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->picture_number= (s->picture_number&~0xFF) + i; - - /* PTYPE starts here */ - if (get_bits1(&s->gb) != 1) { - /* marker */ - av_log(s->avctx, AV_LOG_ERROR, "Bad marker\n"); - return -1; - } - if (get_bits1(&s->gb) != 0) { - av_log(s->avctx, AV_LOG_ERROR, "Bad H263 id\n"); - return -1; /* h263 id */ - } - skip_bits1(&s->gb); /* split screen off */ - skip_bits1(&s->gb); /* camera off */ - skip_bits1(&s->gb); /* freeze picture release off */ - - format = get_bits(&s->gb, 3); - /* - 0 forbidden - 1 sub-QCIF - 10 QCIF - 7 extended PTYPE (PLUSPTYPE) - */ - - if (format != 7 && format != 6) { - s->h263_plus = 0; - /* H.263v1 */ - width = h263_format[format][0]; - height = h263_format[format][1]; - if (!width) - return -1; - - s->pict_type = FF_I_TYPE + get_bits1(&s->gb); - - s->h263_long_vectors = get_bits1(&s->gb); - - if (get_bits1(&s->gb) != 0) { - av_log(s->avctx, AV_LOG_ERROR, "H263 SAC not supported\n"); - return -1; /* SAC: off */ - } - s->obmc= get_bits1(&s->gb); /* Advanced prediction mode */ - s->unrestricted_mv = s->h263_long_vectors || s->obmc; - - s->pb_frame = get_bits1(&s->gb); - s->chroma_qscale= s->qscale = get_bits(&s->gb, 5); - skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */ - - s->width = width; - s->height = height; - s->avctx->sample_aspect_ratio= (AVRational){12,11}; - s->avctx->time_base= (AVRational){1001, 30000}; - } else { - int ufep; - - /* H.263v2 */ - s->h263_plus = 1; - ufep = get_bits(&s->gb, 3); /* Update Full Extended PTYPE */ - - /* ufep other than 0 and 1 are reserved */ - if (ufep == 1) { - /* OPPTYPE */ - format = get_bits(&s->gb, 3); - dprintf(s->avctx, "ufep=1, format: %d\n", format); - s->custom_pcf= get_bits1(&s->gb); - s->umvplus = get_bits1(&s->gb); /* Unrestricted Motion Vector */ - if (get_bits1(&s->gb) != 0) { - av_log(s->avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n"); - } - s->obmc= get_bits1(&s->gb); /* Advanced prediction mode */ - s->h263_aic = get_bits1(&s->gb); /* Advanced Intra Coding (AIC) */ - s->loop_filter= get_bits1(&s->gb); - s->unrestricted_mv = s->umvplus || s->obmc || s->loop_filter; - - s->h263_slice_structured= get_bits1(&s->gb); - if (get_bits1(&s->gb) != 0) { - av_log(s->avctx, AV_LOG_ERROR, "Reference Picture Selection not supported\n"); - } - if (get_bits1(&s->gb) != 0) { - av_log(s->avctx, AV_LOG_ERROR, "Independent Segment Decoding not supported\n"); - } - s->alt_inter_vlc= get_bits1(&s->gb); - s->modified_quant= get_bits1(&s->gb); - if(s->modified_quant) - s->chroma_qscale_table= ff_h263_chroma_qscale_table; - - skip_bits(&s->gb, 1); /* Prevent start code emulation */ - - skip_bits(&s->gb, 3); /* Reserved */ - } else if (ufep != 0) { - av_log(s->avctx, AV_LOG_ERROR, "Bad UFEP type (%d)\n", ufep); - return -1; - } - - /* MPPTYPE */ - s->pict_type = get_bits(&s->gb, 3); - switch(s->pict_type){ - case 0: s->pict_type= FF_I_TYPE;break; - case 1: s->pict_type= FF_P_TYPE;break; - case 2: s->pict_type= FF_P_TYPE;s->pb_frame = 3;break; - case 3: s->pict_type= FF_B_TYPE;break; - case 7: s->pict_type= FF_I_TYPE;break; //ZYGO - default: - return -1; - } - skip_bits(&s->gb, 2); - s->no_rounding = get_bits1(&s->gb); - skip_bits(&s->gb, 4); - - /* Get the picture dimensions */ - if (ufep) { - if (format == 6) { - /* Custom Picture Format (CPFMT) */ - s->aspect_ratio_info = get_bits(&s->gb, 4); - dprintf(s->avctx, "aspect: %d\n", s->aspect_ratio_info); - /* aspect ratios: - 0 - forbidden - 1 - 1:1 - 2 - 12:11 (CIF 4:3) - 3 - 10:11 (525-type 4:3) - 4 - 16:11 (CIF 16:9) - 5 - 40:33 (525-type 16:9) - 6-14 - reserved - */ - width = (get_bits(&s->gb, 9) + 1) * 4; - skip_bits1(&s->gb); - height = get_bits(&s->gb, 9) * 4; - dprintf(s->avctx, "\nH.263+ Custom picture: %dx%d\n",width,height); - if (s->aspect_ratio_info == FF_ASPECT_EXTENDED) { - /* aspected dimensions */ - s->avctx->sample_aspect_ratio.num= get_bits(&s->gb, 8); - s->avctx->sample_aspect_ratio.den= get_bits(&s->gb, 8); - }else{ - s->avctx->sample_aspect_ratio= pixel_aspect[s->aspect_ratio_info]; - } - } else { - width = h263_format[format][0]; - height = h263_format[format][1]; - s->avctx->sample_aspect_ratio= (AVRational){12,11}; - } - if ((width == 0) || (height == 0)) - return -1; - s->width = width; - s->height = height; - - if(s->custom_pcf){ - int gcd; - s->avctx->time_base.den= 1800000; - s->avctx->time_base.num= 1000 + get_bits1(&s->gb); - s->avctx->time_base.num*= get_bits(&s->gb, 7); - if(s->avctx->time_base.num == 0){ - av_log(s, AV_LOG_ERROR, "zero framerate\n"); - return -1; - } - gcd= av_gcd(s->avctx->time_base.den, s->avctx->time_base.num); - s->avctx->time_base.den /= gcd; - s->avctx->time_base.num /= gcd; -// av_log(s->avctx, AV_LOG_DEBUG, "%d/%d\n", s->avctx->time_base.den, s->avctx->time_base.num); - }else{ - s->avctx->time_base= (AVRational){1001, 30000}; - } - } - - if(s->custom_pcf){ - skip_bits(&s->gb, 2); //extended Temporal reference - } - - if (ufep) { - if (s->umvplus) { - if(get_bits1(&s->gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ - skip_bits1(&s->gb); - } - if(s->h263_slice_structured){ - if (get_bits1(&s->gb) != 0) { - av_log(s->avctx, AV_LOG_ERROR, "rectangular slices not supported\n"); - } - if (get_bits1(&s->gb) != 0) { - av_log(s->avctx, AV_LOG_ERROR, "unordered slices not supported\n"); - } - } - } - - s->qscale = get_bits(&s->gb, 5); - } - - s->mb_width = (s->width + 15) / 16; - s->mb_height = (s->height + 15) / 16; - s->mb_num = s->mb_width * s->mb_height; - - if (s->pb_frame) { - skip_bits(&s->gb, 3); /* Temporal reference for B-pictures */ - if (s->custom_pcf) - skip_bits(&s->gb, 2); //extended Temporal reference - skip_bits(&s->gb, 2); /* Quantization information for B-pictures */ - } - - /* PEI */ - while (get_bits1(&s->gb) != 0) { - skip_bits(&s->gb, 8); - } - - if(s->h263_slice_structured){ - if (get_bits1(&s->gb) != 1) { - av_log(s->avctx, AV_LOG_ERROR, "SEPB1 marker missing\n"); - return -1; - } - - ff_h263_decode_mba(s); - - if (get_bits1(&s->gb) != 1) { - av_log(s->avctx, AV_LOG_ERROR, "SEPB2 marker missing\n"); - return -1; - } - } - s->f_code = 1; - - if(s->h263_aic){ - s->y_dc_scale_table= - s->c_dc_scale_table= ff_aic_dc_scale_table; - }else{ - s->y_dc_scale_table= - s->c_dc_scale_table= ff_mpeg1_dc_scale_table; - } - - if(s->avctx->debug&FF_DEBUG_PICT_INFO){ - show_pict_info(s); - } -#if 1 - if (s->pict_type == FF_I_TYPE && s->codec_tag == AV_RL32("ZYGO")){ - int i,j; - for(i=0; i<85; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb)); - av_log(s->avctx, AV_LOG_DEBUG, "\n"); - for(i=0; i<13; i++){ - for(j=0; j<3; j++){ - int v= get_bits(&s->gb, 8); - v |= get_sbits(&s->gb, 8)<<8; - av_log(s->avctx, AV_LOG_DEBUG, " %5d", v); - } - av_log(s->avctx, AV_LOG_DEBUG, "\n"); - } - for(i=0; i<50; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb)); - } -#endif - - return 0; -} - -static void mpeg4_decode_sprite_trajectory(MpegEncContext * s, GetBitContext *gb) -{ - int i; - int a= 2<sprite_warping_accuracy; - int rho= 3-s->sprite_warping_accuracy; - int r=16/a; - const int vop_ref[4][2]= {{0,0}, {s->width,0}, {0, s->height}, {s->width, s->height}}; // only true for rectangle shapes - int d[4][2]={{0,0}, {0,0}, {0,0}, {0,0}}; - int sprite_ref[4][2]; - int virtual_ref[2][2]; - int w2, h2, w3, h3; - int alpha=0, beta=0; - int w= s->width; - int h= s->height; - int min_ab; - - for(i=0; inum_sprite_warping_points; i++){ - int length; - int x=0, y=0; - - length= get_vlc2(gb, sprite_trajectory.table, SPRITE_TRAJ_VLC_BITS, 3); - if(length){ - x= get_xbits(gb, length); - } - if(!(s->divx_version==500 && s->divx_build==413)) skip_bits1(gb); /* marker bit */ - - length= get_vlc2(gb, sprite_trajectory.table, SPRITE_TRAJ_VLC_BITS, 3); - if(length){ - y=get_xbits(gb, length); - } - skip_bits1(gb); /* marker bit */ -//printf("%d %d %d %d\n", x, y, i, s->sprite_warping_accuracy); - s->sprite_traj[i][0]= d[i][0]= x; - s->sprite_traj[i][1]= d[i][1]= y; - } - for(; i<4; i++) - s->sprite_traj[i][0]= s->sprite_traj[i][1]= 0; - - while((1<divx_version==500 && s->divx_build==413){ - sprite_ref[0][0]= a*vop_ref[0][0] + d[0][0]; - sprite_ref[0][1]= a*vop_ref[0][1] + d[0][1]; - sprite_ref[1][0]= a*vop_ref[1][0] + d[0][0] + d[1][0]; - sprite_ref[1][1]= a*vop_ref[1][1] + d[0][1] + d[1][1]; - sprite_ref[2][0]= a*vop_ref[2][0] + d[0][0] + d[2][0]; - sprite_ref[2][1]= a*vop_ref[2][1] + d[0][1] + d[2][1]; - } else { - sprite_ref[0][0]= (a>>1)*(2*vop_ref[0][0] + d[0][0]); - sprite_ref[0][1]= (a>>1)*(2*vop_ref[0][1] + d[0][1]); - sprite_ref[1][0]= (a>>1)*(2*vop_ref[1][0] + d[0][0] + d[1][0]); - sprite_ref[1][1]= (a>>1)*(2*vop_ref[1][1] + d[0][1] + d[1][1]); - sprite_ref[2][0]= (a>>1)*(2*vop_ref[2][0] + d[0][0] + d[2][0]); - sprite_ref[2][1]= (a>>1)*(2*vop_ref[2][1] + d[0][1] + d[2][1]); - } -/* sprite_ref[3][0]= (a>>1)*(2*vop_ref[3][0] + d[0][0] + d[1][0] + d[2][0] + d[3][0]); - sprite_ref[3][1]= (a>>1)*(2*vop_ref[3][1] + d[0][1] + d[1][1] + d[2][1] + d[3][1]); */ - -// this is mostly identical to the mpeg4 std (and is totally unreadable because of that ...) -// perhaps it should be reordered to be more readable ... -// the idea behind this virtual_ref mess is to be able to use shifts later per pixel instead of divides -// so the distance between points is converted from w&h based to w2&h2 based which are of the 2^x form - virtual_ref[0][0]= 16*(vop_ref[0][0] + w2) - + ROUNDED_DIV(((w - w2)*(r*sprite_ref[0][0] - 16*vop_ref[0][0]) + w2*(r*sprite_ref[1][0] - 16*vop_ref[1][0])),w); - virtual_ref[0][1]= 16*vop_ref[0][1] - + ROUNDED_DIV(((w - w2)*(r*sprite_ref[0][1] - 16*vop_ref[0][1]) + w2*(r*sprite_ref[1][1] - 16*vop_ref[1][1])),w); - virtual_ref[1][0]= 16*vop_ref[0][0] - + ROUNDED_DIV(((h - h2)*(r*sprite_ref[0][0] - 16*vop_ref[0][0]) + h2*(r*sprite_ref[2][0] - 16*vop_ref[2][0])),h); - virtual_ref[1][1]= 16*(vop_ref[0][1] + h2) - + ROUNDED_DIV(((h - h2)*(r*sprite_ref[0][1] - 16*vop_ref[0][1]) + h2*(r*sprite_ref[2][1] - 16*vop_ref[2][1])),h); - - switch(s->num_sprite_warping_points) - { - case 0: - s->sprite_offset[0][0]= 0; - s->sprite_offset[0][1]= 0; - s->sprite_offset[1][0]= 0; - s->sprite_offset[1][1]= 0; - s->sprite_delta[0][0]= a; - s->sprite_delta[0][1]= 0; - s->sprite_delta[1][0]= 0; - s->sprite_delta[1][1]= a; - s->sprite_shift[0]= 0; - s->sprite_shift[1]= 0; - break; - case 1: //GMC only - s->sprite_offset[0][0]= sprite_ref[0][0] - a*vop_ref[0][0]; - s->sprite_offset[0][1]= sprite_ref[0][1] - a*vop_ref[0][1]; - s->sprite_offset[1][0]= ((sprite_ref[0][0]>>1)|(sprite_ref[0][0]&1)) - a*(vop_ref[0][0]/2); - s->sprite_offset[1][1]= ((sprite_ref[0][1]>>1)|(sprite_ref[0][1]&1)) - a*(vop_ref[0][1]/2); - s->sprite_delta[0][0]= a; - s->sprite_delta[0][1]= 0; - s->sprite_delta[1][0]= 0; - s->sprite_delta[1][1]= a; - s->sprite_shift[0]= 0; - s->sprite_shift[1]= 0; - break; - case 2: - s->sprite_offset[0][0]= (sprite_ref[0][0]<<(alpha+rho)) - + (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-vop_ref[0][0]) - + ( r*sprite_ref[0][1] - virtual_ref[0][1])*(-vop_ref[0][1]) - + (1<<(alpha+rho-1)); - s->sprite_offset[0][1]= (sprite_ref[0][1]<<(alpha+rho)) - + (-r*sprite_ref[0][1] + virtual_ref[0][1])*(-vop_ref[0][0]) - + (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-vop_ref[0][1]) - + (1<<(alpha+rho-1)); - s->sprite_offset[1][0]= ( (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-2*vop_ref[0][0] + 1) - +( r*sprite_ref[0][1] - virtual_ref[0][1])*(-2*vop_ref[0][1] + 1) - +2*w2*r*sprite_ref[0][0] - - 16*w2 - + (1<<(alpha+rho+1))); - s->sprite_offset[1][1]= ( (-r*sprite_ref[0][1] + virtual_ref[0][1])*(-2*vop_ref[0][0] + 1) - +(-r*sprite_ref[0][0] + virtual_ref[0][0])*(-2*vop_ref[0][1] + 1) - +2*w2*r*sprite_ref[0][1] - - 16*w2 - + (1<<(alpha+rho+1))); - s->sprite_delta[0][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0]); - s->sprite_delta[0][1]= (+r*sprite_ref[0][1] - virtual_ref[0][1]); - s->sprite_delta[1][0]= (-r*sprite_ref[0][1] + virtual_ref[0][1]); - s->sprite_delta[1][1]= (-r*sprite_ref[0][0] + virtual_ref[0][0]); - - s->sprite_shift[0]= alpha+rho; - s->sprite_shift[1]= alpha+rho+2; - break; - case 3: - min_ab= FFMIN(alpha, beta); - w3= w2>>min_ab; - h3= h2>>min_ab; - s->sprite_offset[0][0]= (sprite_ref[0][0]<<(alpha+beta+rho-min_ab)) - + (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3*(-vop_ref[0][0]) - + (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3*(-vop_ref[0][1]) - + (1<<(alpha+beta+rho-min_ab-1)); - s->sprite_offset[0][1]= (sprite_ref[0][1]<<(alpha+beta+rho-min_ab)) - + (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3*(-vop_ref[0][0]) - + (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3*(-vop_ref[0][1]) - + (1<<(alpha+beta+rho-min_ab-1)); - s->sprite_offset[1][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3*(-2*vop_ref[0][0] + 1) - + (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3*(-2*vop_ref[0][1] + 1) - + 2*w2*h3*r*sprite_ref[0][0] - - 16*w2*h3 - + (1<<(alpha+beta+rho-min_ab+1)); - s->sprite_offset[1][1]= (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3*(-2*vop_ref[0][0] + 1) - + (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3*(-2*vop_ref[0][1] + 1) - + 2*w2*h3*r*sprite_ref[0][1] - - 16*w2*h3 - + (1<<(alpha+beta+rho-min_ab+1)); - s->sprite_delta[0][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3; - s->sprite_delta[0][1]= (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3; - s->sprite_delta[1][0]= (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3; - s->sprite_delta[1][1]= (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3; - - s->sprite_shift[0]= alpha + beta + rho - min_ab; - s->sprite_shift[1]= alpha + beta + rho - min_ab + 2; - break; - } - /* try to simplify the situation */ - if( s->sprite_delta[0][0] == a<sprite_shift[0] - && s->sprite_delta[0][1] == 0 - && s->sprite_delta[1][0] == 0 - && s->sprite_delta[1][1] == a<sprite_shift[0]) - { - s->sprite_offset[0][0]>>=s->sprite_shift[0]; - s->sprite_offset[0][1]>>=s->sprite_shift[0]; - s->sprite_offset[1][0]>>=s->sprite_shift[1]; - s->sprite_offset[1][1]>>=s->sprite_shift[1]; - s->sprite_delta[0][0]= a; - s->sprite_delta[0][1]= 0; - s->sprite_delta[1][0]= 0; - s->sprite_delta[1][1]= a; - s->sprite_shift[0]= 0; - s->sprite_shift[1]= 0; - s->real_sprite_warping_points=1; - } - else{ - int shift_y= 16 - s->sprite_shift[0]; - int shift_c= 16 - s->sprite_shift[1]; -//printf("shifts %d %d\n", shift_y, shift_c); - for(i=0; i<2; i++){ - s->sprite_offset[0][i]<<= shift_y; - s->sprite_offset[1][i]<<= shift_c; - s->sprite_delta[0][i]<<= shift_y; - s->sprite_delta[1][i]<<= shift_y; - s->sprite_shift[i]= 16; - } - s->real_sprite_warping_points= s->num_sprite_warping_points; - } -#if 0 -printf("vop:%d:%d %d:%d %d:%d, sprite:%d:%d %d:%d %d:%d, virtual: %d:%d %d:%d\n", - vop_ref[0][0], vop_ref[0][1], - vop_ref[1][0], vop_ref[1][1], - vop_ref[2][0], vop_ref[2][1], - sprite_ref[0][0], sprite_ref[0][1], - sprite_ref[1][0], sprite_ref[1][1], - sprite_ref[2][0], sprite_ref[2][1], - virtual_ref[0][0], virtual_ref[0][1], - virtual_ref[1][0], virtual_ref[1][1] - ); - -printf("offset: %d:%d , delta: %d %d %d %d, shift %d\n", - s->sprite_offset[0][0], s->sprite_offset[0][1], - s->sprite_delta[0][0], s->sprite_delta[0][1], - s->sprite_delta[1][0], s->sprite_delta[1][1], - s->sprite_shift[0] - ); -#endif -} - -static int mpeg4_decode_gop_header(MpegEncContext * s, GetBitContext *gb){ - int hours, minutes, seconds; - - 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 decode_vol_header(MpegEncContext *s, GetBitContext *gb){ - int width, height, vo_ver_id; - - /* vol header */ - skip_bits(gb, 1); /* random access */ - s->vo_type= get_bits(gb, 8); - if (get_bits1(gb) != 0) { /* is_ol_id */ - vo_ver_id = get_bits(gb, 4); /* vo_ver_id */ - skip_bits(gb, 3); /* vo_priority */ - } else { - vo_ver_id = 1; - } -//printf("vo type:%d\n",s->vo_type); - s->aspect_ratio_info= get_bits(gb, 4); - if(s->aspect_ratio_info == FF_ASPECT_EXTENDED){ - s->avctx->sample_aspect_ratio.num= get_bits(gb, 8); // par_width - s->avctx->sample_aspect_ratio.den= get_bits(gb, 8); // par_height - }else{ - s->avctx->sample_aspect_ratio= pixel_aspect[s->aspect_ratio_info]; - } - - if ((s->vol_control_parameters=get_bits1(gb))) { /* vol control parameter */ - int chroma_format= get_bits(gb, 2); - if(chroma_format!=CHROMA_420){ - av_log(s->avctx, AV_LOG_ERROR, "illegal chroma format\n"); - } - s->low_delay= get_bits1(gb); - if(get_bits1(gb)){ /* vbv parameters */ - get_bits(gb, 15); /* first_half_bitrate */ - skip_bits1(gb); /* marker */ - get_bits(gb, 15); /* latter_half_bitrate */ - skip_bits1(gb); /* marker */ - get_bits(gb, 15); /* first_half_vbv_buffer_size */ - skip_bits1(gb); /* marker */ - get_bits(gb, 3); /* latter_half_vbv_buffer_size */ - get_bits(gb, 11); /* first_half_vbv_occupancy */ - skip_bits1(gb); /* marker */ - get_bits(gb, 15); /* latter_half_vbv_occupancy */ - skip_bits1(gb); /* marker */ - } - }else{ - // set low delay flag only once the smartest? low delay detection won't be overriden - if(s->picture_number==0) - s->low_delay=0; - } - - s->shape = get_bits(gb, 2); /* vol shape */ - if(s->shape != RECT_SHAPE) av_log(s->avctx, AV_LOG_ERROR, "only rectangular vol supported\n"); - if(s->shape == GRAY_SHAPE && vo_ver_id != 1){ - av_log(s->avctx, AV_LOG_ERROR, "Gray shape not supported\n"); - skip_bits(gb, 4); //video_object_layer_shape_extension - } - - check_marker(gb, "before time_increment_resolution"); - - s->avctx->time_base.den = get_bits(gb, 16); - if(!s->avctx->time_base.den){ - av_log(s->avctx, AV_LOG_ERROR, "time_base.den==0\n"); - return -1; - } - - s->time_increment_bits = av_log2(s->avctx->time_base.den - 1) + 1; - if (s->time_increment_bits < 1) - s->time_increment_bits = 1; - - check_marker(gb, "before fixed_vop_rate"); - - if (get_bits1(gb) != 0) { /* fixed_vop_rate */ - s->avctx->time_base.num = get_bits(gb, s->time_increment_bits); - }else - s->avctx->time_base.num = 1; - - s->t_frame=0; - - if (s->shape != BIN_ONLY_SHAPE) { - if (s->shape == RECT_SHAPE) { - skip_bits1(gb); /* marker */ - width = get_bits(gb, 13); - skip_bits1(gb); /* marker */ - height = get_bits(gb, 13); - skip_bits1(gb); /* marker */ - if(width && height && !(s->width && s->codec_tag == AV_RL32("MP4S"))){ /* they should be non zero but who knows ... */ - s->width = width; - s->height = height; -// printf("width/height: %d %d\n", width, height); - } - } - - s->progressive_sequence= - s->progressive_frame= get_bits1(gb)^1; - s->interlaced_dct=0; - if(!get_bits1(gb) && (s->avctx->debug & FF_DEBUG_PICT_INFO)) - av_log(s->avctx, AV_LOG_INFO, "MPEG4 OBMC not supported (very likely buggy encoder)\n"); /* OBMC Disable */ - if (vo_ver_id == 1) { - s->vol_sprite_usage = get_bits1(gb); /* vol_sprite_usage */ - } else { - s->vol_sprite_usage = get_bits(gb, 2); /* vol_sprite_usage */ - } - if(s->vol_sprite_usage==STATIC_SPRITE) av_log(s->avctx, AV_LOG_ERROR, "Static Sprites not supported\n"); - if(s->vol_sprite_usage==STATIC_SPRITE || s->vol_sprite_usage==GMC_SPRITE){ - if(s->vol_sprite_usage==STATIC_SPRITE){ - s->sprite_width = get_bits(gb, 13); - skip_bits1(gb); /* marker */ - s->sprite_height= get_bits(gb, 13); - skip_bits1(gb); /* marker */ - s->sprite_left = get_bits(gb, 13); - skip_bits1(gb); /* marker */ - s->sprite_top = get_bits(gb, 13); - skip_bits1(gb); /* marker */ - } - s->num_sprite_warping_points= get_bits(gb, 6); - if(s->num_sprite_warping_points > 3){ - av_log(s->avctx, AV_LOG_ERROR, "%d sprite_warping_points\n", s->num_sprite_warping_points); - s->num_sprite_warping_points= 0; - return -1; - } - s->sprite_warping_accuracy = get_bits(gb, 2); - s->sprite_brightness_change= get_bits1(gb); - if(s->vol_sprite_usage==STATIC_SPRITE) - s->low_latency_sprite= get_bits1(gb); - } - // FIXME sadct disable bit if verid!=1 && shape not rect - - if (get_bits1(gb) == 1) { /* not_8_bit */ - s->quant_precision = get_bits(gb, 4); /* quant_precision */ - if(get_bits(gb, 4)!=8) av_log(s->avctx, AV_LOG_ERROR, "N-bit not supported\n"); /* bits_per_pixel */ - if(s->quant_precision!=5) av_log(s->avctx, AV_LOG_ERROR, "quant precision %d\n", s->quant_precision); - } else { - s->quant_precision = 5; - } - - // FIXME a bunch of grayscale shape things - - if((s->mpeg_quant=get_bits1(gb))){ /* vol_quant_type */ - int i, v; - - /* load default matrixes */ - for(i=0; i<64; i++){ - int j= s->dsp.idct_permutation[i]; - v= ff_mpeg4_default_intra_matrix[i]; - s->intra_matrix[j]= v; - s->chroma_intra_matrix[j]= v; - - v= ff_mpeg4_default_non_intra_matrix[i]; - s->inter_matrix[j]= v; - s->chroma_inter_matrix[j]= v; - } - - /* load custom intra matrix */ - if(get_bits1(gb)){ - int last=0; - for(i=0; i<64; i++){ - int j; - v= get_bits(gb, 8); - if(v==0) break; - - last= v; - j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ]; - s->intra_matrix[j]= v; - s->chroma_intra_matrix[j]= v; - } - - /* replicate last value */ - for(; i<64; i++){ - int j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ]; - s->intra_matrix[j]= last; - s->chroma_intra_matrix[j]= last; - } - } - - /* load custom non intra matrix */ - if(get_bits1(gb)){ - int last=0; - for(i=0; i<64; i++){ - int j; - v= get_bits(gb, 8); - if(v==0) break; - - last= v; - j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ]; - s->inter_matrix[j]= v; - s->chroma_inter_matrix[j]= v; - } - - /* replicate last value */ - for(; i<64; i++){ - int j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ]; - s->inter_matrix[j]= last; - s->chroma_inter_matrix[j]= last; - } - } - - // FIXME a bunch of grayscale shape things - } - - if(vo_ver_id != 1) - s->quarter_sample= get_bits1(gb); - else s->quarter_sample=0; - - if(!get_bits1(gb)){ - int pos= get_bits_count(gb); - int estimation_method= get_bits(gb, 2); - if(estimation_method<2){ - if(!get_bits1(gb)){ - s->cplx_estimation_trash_i += 8*get_bits1(gb); //opaque - s->cplx_estimation_trash_i += 8*get_bits1(gb); //transparent - s->cplx_estimation_trash_i += 8*get_bits1(gb); //intra_cae - s->cplx_estimation_trash_i += 8*get_bits1(gb); //inter_cae - s->cplx_estimation_trash_i += 8*get_bits1(gb); //no_update - s->cplx_estimation_trash_i += 8*get_bits1(gb); //upampling - } - if(!get_bits1(gb)){ - s->cplx_estimation_trash_i += 8*get_bits1(gb); //intra_blocks - s->cplx_estimation_trash_p += 8*get_bits1(gb); //inter_blocks - s->cplx_estimation_trash_p += 8*get_bits1(gb); //inter4v_blocks - s->cplx_estimation_trash_i += 8*get_bits1(gb); //not coded blocks - } - if(!check_marker(gb, "in complexity estimation part 1")){ - skip_bits_long(gb, pos - get_bits_count(gb)); - goto no_cplx_est; - } - if(!get_bits1(gb)){ - s->cplx_estimation_trash_i += 8*get_bits1(gb); //dct_coeffs - s->cplx_estimation_trash_i += 8*get_bits1(gb); //dct_lines - s->cplx_estimation_trash_i += 8*get_bits1(gb); //vlc_syms - s->cplx_estimation_trash_i += 4*get_bits1(gb); //vlc_bits - } - if(!get_bits1(gb)){ - s->cplx_estimation_trash_p += 8*get_bits1(gb); //apm - s->cplx_estimation_trash_p += 8*get_bits1(gb); //npm - s->cplx_estimation_trash_b += 8*get_bits1(gb); //interpolate_mc_q - s->cplx_estimation_trash_p += 8*get_bits1(gb); //forwback_mc_q - s->cplx_estimation_trash_p += 8*get_bits1(gb); //halfpel2 - s->cplx_estimation_trash_p += 8*get_bits1(gb); //halfpel4 - } - if(!check_marker(gb, "in complexity estimation part 2")){ - skip_bits_long(gb, pos - get_bits_count(gb)); - goto no_cplx_est; - } - if(estimation_method==1){ - s->cplx_estimation_trash_i += 8*get_bits1(gb); //sadct - s->cplx_estimation_trash_p += 8*get_bits1(gb); //qpel - } - }else - av_log(s->avctx, AV_LOG_ERROR, "Invalid Complexity estimation method %d\n", estimation_method); - }else{ -no_cplx_est: - s->cplx_estimation_trash_i= - s->cplx_estimation_trash_p= - s->cplx_estimation_trash_b= 0; - } - - s->resync_marker= !get_bits1(gb); /* resync_marker_disabled */ - - s->data_partitioning= get_bits1(gb); - if(s->data_partitioning){ - s->rvlc= get_bits1(gb); - } - - if(vo_ver_id != 1) { - s->new_pred= get_bits1(gb); - if(s->new_pred){ - av_log(s->avctx, AV_LOG_ERROR, "new pred not supported\n"); - skip_bits(gb, 2); /* requested upstream message type */ - skip_bits1(gb); /* newpred segment type */ - } - s->reduced_res_vop= get_bits1(gb); - if(s->reduced_res_vop) av_log(s->avctx, AV_LOG_ERROR, "reduced resolution VOP not supported\n"); - } - else{ - s->new_pred=0; - s->reduced_res_vop= 0; - } - - s->scalability= get_bits1(gb); - - if (s->scalability) { - GetBitContext bak= *gb; - int ref_layer_id; - int ref_layer_sampling_dir; - int h_sampling_factor_n; - int h_sampling_factor_m; - int v_sampling_factor_n; - int v_sampling_factor_m; - - s->hierachy_type= get_bits1(gb); - ref_layer_id= get_bits(gb, 4); - ref_layer_sampling_dir= get_bits1(gb); - h_sampling_factor_n= get_bits(gb, 5); - h_sampling_factor_m= get_bits(gb, 5); - v_sampling_factor_n= get_bits(gb, 5); - v_sampling_factor_m= get_bits(gb, 5); - s->enhancement_type= get_bits1(gb); - - if( h_sampling_factor_n==0 || h_sampling_factor_m==0 - || v_sampling_factor_n==0 || v_sampling_factor_m==0){ - -// fprintf(stderr, "illegal scalability header (VERY broken encoder), trying to workaround\n"); - s->scalability=0; - - *gb= bak; - }else - av_log(s->avctx, AV_LOG_ERROR, "scalability not supported\n"); - - // bin shape stuff FIXME - } - } - return 0; -} - -/** - * decodes the user data stuff in the header. - * Also initializes divx/xvid/lavc_version/build. - */ -static int decode_user_data(MpegEncContext *s, GetBitContext *gb){ - char buf[256]; - int i; - int e; - int ver = 0, build = 0, ver2 = 0, ver3 = 0; - char last; - - for(i=0; i<255 && get_bits_count(gb) < gb->size_in_bits; i++){ - if(show_bits(gb, 23) == 0) break; - buf[i]= get_bits(gb, 8); - } - buf[i]=0; - - /* divx detection */ - e=sscanf(buf, "DivX%dBuild%d%c", &ver, &build, &last); - if(e<2) - e=sscanf(buf, "DivX%db%d%c", &ver, &build, &last); - if(e>=2){ - s->divx_version= ver; - s->divx_build= build; - s->divx_packed= e==3 && last=='p'; - if(s->divx_packed && !s->showed_packed_warning) { - av_log(s->avctx, AV_LOG_WARNING, "Invalid and inefficient vfw-avi packed B frames detected\n"); - s->showed_packed_warning=1; - } - } - - /* ffmpeg detection */ - e=sscanf(buf, "FFmpe%*[^b]b%d", &build)+3; - if(e!=4) - e=sscanf(buf, "FFmpeg v%d.%d.%d / libavcodec build: %d", &ver, &ver2, &ver3, &build); - if(e!=4){ - e=sscanf(buf, "Lavc%d.%d.%d", &ver, &ver2, &ver3)+1; - if (e>1) - build= (ver<<16) + (ver2<<8) + ver3; - } - if(e!=4){ - if(strcmp(buf, "ffmpeg")==0){ - s->lavc_build= 4600; - } - } - if(e==4){ - s->lavc_build= build; - } - - /* Xvid detection */ - e=sscanf(buf, "XviD%d", &build); - if(e==1){ - s->xvid_build= build; - } - -//printf("User Data: %s\n", buf); - return 0; -} - -static int decode_vop_header(MpegEncContext *s, GetBitContext *gb){ - int time_incr, time_increment; - - s->pict_type = get_bits(gb, 2) + FF_I_TYPE; /* pict type: I = 0 , P = 1 */ - if(s->pict_type==FF_B_TYPE && s->low_delay && s->vol_control_parameters==0 && !(s->flags & CODEC_FLAG_LOW_DELAY)){ - av_log(s->avctx, AV_LOG_ERROR, "low_delay flag incorrectly, clearing it\n"); - s->low_delay=0; - } - - s->partitioned_frame= s->data_partitioning && s->pict_type!=FF_B_TYPE; - if(s->partitioned_frame) - s->decode_mb= mpeg4_decode_partitioned_mb; - else - s->decode_mb= ff_mpeg4_decode_mb; - - time_incr=0; - while (get_bits1(gb) != 0) - time_incr++; - - check_marker(gb, "before time_increment"); - - if(s->time_increment_bits==0 || !(show_bits(gb, s->time_increment_bits+1)&1)){ - av_log(s->avctx, AV_LOG_ERROR, "hmm, seems the headers are not complete, trying to guess time_increment_bits\n"); - - for(s->time_increment_bits=1 ;s->time_increment_bits<16; s->time_increment_bits++){ - if(show_bits(gb, s->time_increment_bits+1)&1) break; - } - - av_log(s->avctx, AV_LOG_ERROR, "my guess is %d bits ;)\n",s->time_increment_bits); - } - - if(IS_3IV1) time_increment= get_bits1(gb); //FIXME investigate further - else time_increment= get_bits(gb, s->time_increment_bits); - -// printf("%d %X\n", s->time_increment_bits, time_increment); -//av_log(s->avctx, AV_LOG_DEBUG, " type:%d modulo_time_base:%d increment:%d t_frame %d\n", s->pict_type, time_incr, time_increment, s->t_frame); - if(s->pict_type!=FF_B_TYPE){ - s->last_time_base= s->time_base; - s->time_base+= time_incr; - s->time= s->time_base*s->avctx->time_base.den + time_increment; - if(s->workaround_bugs&FF_BUG_UMP4){ - if(s->time < s->last_non_b_time){ -// fprintf(stderr, "header is not mpeg4 compatible, broken encoder, trying to workaround\n"); - s->time_base++; - s->time+= s->avctx->time_base.den; - } - } - s->pp_time= s->time - s->last_non_b_time; - s->last_non_b_time= s->time; - }else{ - s->time= (s->last_time_base + time_incr)*s->avctx->time_base.den + time_increment; - s->pb_time= s->pp_time - (s->last_non_b_time - s->time); - if(s->pp_time <=s->pb_time || s->pp_time <= s->pp_time - s->pb_time || s->pp_time<=0){ -// printf("messed up order, maybe after seeking? skipping current b frame\n"); - return FRAME_SKIPPED; - } - ff_mpeg4_init_direct_mv(s); - - if(s->t_frame==0) s->t_frame= s->pb_time; - if(s->t_frame==0) s->t_frame=1; // 1/0 protection - s->pp_field_time= ( ROUNDED_DIV(s->last_non_b_time, s->t_frame) - - ROUNDED_DIV(s->last_non_b_time - s->pp_time, s->t_frame))*2; - s->pb_field_time= ( ROUNDED_DIV(s->time, s->t_frame) - - ROUNDED_DIV(s->last_non_b_time - s->pp_time, s->t_frame))*2; - if(!s->progressive_sequence){ - if(s->pp_field_time <= s->pb_field_time || s->pb_field_time <= 1) - return FRAME_SKIPPED; - } - } -//av_log(s->avctx, AV_LOG_DEBUG, "last nonb %"PRId64" last_base %d time %"PRId64" pp %d pb %d t %d ppf %d pbf %d\n", s->last_non_b_time, s->last_time_base, s->time, s->pp_time, s->pb_time, s->t_frame, s->pp_field_time, s->pb_field_time); - - if(s->avctx->time_base.num) - s->current_picture_ptr->pts= (s->time + s->avctx->time_base.num/2) / s->avctx->time_base.num; - else - s->current_picture_ptr->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); - - check_marker(gb, "before vop_coded"); - - /* vop coded */ - if (get_bits1(gb) != 1){ - if(s->avctx->debug&FF_DEBUG_PICT_INFO) - av_log(s->avctx, AV_LOG_ERROR, "vop not coded\n"); - return FRAME_SKIPPED; - } -//printf("time %d %d %d || %"PRId64" %"PRId64" %"PRId64"\n", s->time_increment_bits, s->avctx->time_base.den, s->time_base, -//s->time, s->last_non_b_time, s->last_non_b_time - s->pp_time); - if (s->shape != BIN_ONLY_SHAPE && ( s->pict_type == FF_P_TYPE - || (s->pict_type == FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE))) { - /* rounding type for motion estimation */ - s->no_rounding = get_bits1(gb); - } else { - s->no_rounding = 0; - } -//FIXME reduced res stuff - - if (s->shape != RECT_SHAPE) { - if (s->vol_sprite_usage != 1 || s->pict_type != FF_I_TYPE) { - int width, height, hor_spat_ref, ver_spat_ref; - - width = get_bits(gb, 13); - skip_bits1(gb); /* marker */ - height = get_bits(gb, 13); - skip_bits1(gb); /* marker */ - hor_spat_ref = get_bits(gb, 13); /* hor_spat_ref */ - skip_bits1(gb); /* marker */ - ver_spat_ref = get_bits(gb, 13); /* ver_spat_ref */ - } - skip_bits1(gb); /* change_CR_disable */ - - if (get_bits1(gb) != 0) { - skip_bits(gb, 8); /* constant_alpha_value */ - } - } -//FIXME complexity estimation stuff - - if (s->shape != BIN_ONLY_SHAPE) { - skip_bits_long(gb, s->cplx_estimation_trash_i); - if(s->pict_type != FF_I_TYPE) - skip_bits_long(gb, s->cplx_estimation_trash_p); - if(s->pict_type == FF_B_TYPE) - skip_bits_long(gb, s->cplx_estimation_trash_b); - - s->intra_dc_threshold= mpeg4_dc_threshold[ get_bits(gb, 3) ]; - if(!s->progressive_sequence){ - s->top_field_first= get_bits1(gb); - s->alternate_scan= get_bits1(gb); - }else - s->alternate_scan= 0; - } - - 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); - ff_init_scantable(s->dsp.idct_permutation, &s->intra_h_scantable, ff_alternate_vertical_scan); - ff_init_scantable(s->dsp.idct_permutation, &s->intra_v_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); - ff_init_scantable(s->dsp.idct_permutation, &s->intra_h_scantable, ff_alternate_horizontal_scan); - ff_init_scantable(s->dsp.idct_permutation, &s->intra_v_scantable, ff_alternate_vertical_scan); - } - - if(s->pict_type == FF_S_TYPE && (s->vol_sprite_usage==STATIC_SPRITE || s->vol_sprite_usage==GMC_SPRITE)){ - mpeg4_decode_sprite_trajectory(s, gb); - if(s->sprite_brightness_change) av_log(s->avctx, AV_LOG_ERROR, "sprite_brightness_change not supported\n"); - if(s->vol_sprite_usage==STATIC_SPRITE) av_log(s->avctx, AV_LOG_ERROR, "static sprite not supported\n"); - } - - if (s->shape != BIN_ONLY_SHAPE) { - s->chroma_qscale= s->qscale = get_bits(gb, s->quant_precision); - if(s->qscale==0){ - av_log(s->avctx, AV_LOG_ERROR, "Error, header damaged or not MPEG4 header (qscale=0)\n"); - return -1; // makes no sense to continue, as there is nothing left from the image then - } - - if (s->pict_type != FF_I_TYPE) { - s->f_code = get_bits(gb, 3); /* fcode_for */ - if(s->f_code==0){ - av_log(s->avctx, AV_LOG_ERROR, "Error, header damaged or not MPEG4 header (f_code=0)\n"); - return -1; // makes no sense to continue, as the MV decoding will break very quickly - } - }else - s->f_code=1; - - if (s->pict_type == FF_B_TYPE) { - s->b_code = get_bits(gb, 3); - }else - s->b_code=1; - - if(s->avctx->debug&FF_DEBUG_PICT_INFO){ - av_log(s->avctx, AV_LOG_DEBUG, "qp:%d fc:%d,%d %s size:%d pro:%d alt:%d top:%d %spel part:%d resync:%d w:%d a:%d rnd:%d vot:%d%s dc:%d ce:%d/%d/%d\n", - s->qscale, s->f_code, s->b_code, - s->pict_type == FF_I_TYPE ? "I" : (s->pict_type == FF_P_TYPE ? "P" : (s->pict_type == FF_B_TYPE ? "B" : "S")), - gb->size_in_bits,s->progressive_sequence, s->alternate_scan, s->top_field_first, - s->quarter_sample ? "q" : "h", s->data_partitioning, s->resync_marker, s->num_sprite_warping_points, - s->sprite_warping_accuracy, 1-s->no_rounding, s->vo_type, s->vol_control_parameters ? " VOLC" : " ", s->intra_dc_threshold, s->cplx_estimation_trash_i, s->cplx_estimation_trash_p, s->cplx_estimation_trash_b); - } - - if(!s->scalability){ - if (s->shape!=RECT_SHAPE && s->pict_type!=FF_I_TYPE) { - skip_bits1(gb); // vop shape coding type - } - }else{ - if(s->enhancement_type){ - int load_backward_shape= get_bits1(gb); - if(load_backward_shape){ - av_log(s->avctx, AV_LOG_ERROR, "load backward shape isn't supported\n"); - } - } - skip_bits(gb, 2); //ref_select_code - } - } - /* detect buggy encoders which don't set the low_delay flag (divx4/xvid/opendivx)*/ - // note we cannot detect divx5 without b-frames easily (although it's buggy too) - if(s->vo_type==0 && s->vol_control_parameters==0 && s->divx_version==0 && s->picture_number==0){ - av_log(s->avctx, AV_LOG_ERROR, "looks like this file was encoded with (divx4/(old)xvid/opendivx) -> forcing low_delay flag\n"); - s->low_delay=1; - } - - s->picture_number++; // better than pic number==0 always ;) - - s->y_dc_scale_table= ff_mpeg4_y_dc_scale_table; //FIXME add short header support - s->c_dc_scale_table= ff_mpeg4_c_dc_scale_table; - - if(s->workaround_bugs&FF_BUG_EDGE){ - s->h_edge_pos= s->width; - s->v_edge_pos= s->height; - } - return 0; -} - -/** - * decode mpeg4 headers - * @return <0 if no VOP found (or a damaged one) - * FRAME_SKIPPED if a not coded VOP is found - * 0 if a VOP is found - */ -int ff_mpeg4_decode_picture_header(MpegEncContext * s, GetBitContext *gb) -{ - int startcode, v; - - /* search next start code */ - align_get_bits(gb); - - if(s->codec_tag == AV_RL32("WV1F") && show_bits(gb, 24) == 0x575630){ - skip_bits(gb, 24); - if(get_bits(gb, 8) == 0xF0) - goto end; - } - - startcode = 0xff; - for(;;) { - if(get_bits_count(gb) >= gb->size_in_bits){ - if(gb->size_in_bits==8 && (s->divx_version || s->xvid_build)){ - av_log(s->avctx, AV_LOG_ERROR, "frame skip %d\n", gb->size_in_bits); - return FRAME_SKIPPED; //divx bug - }else - return -1; //end of stream - } - - /* use the bits after the test */ - v = get_bits(gb, 8); - startcode = ((startcode << 8) | v) & 0xffffffff; - - if((startcode&0xFFFFFF00) != 0x100) - continue; //no startcode - - if(s->avctx->debug&FF_DEBUG_STARTCODE){ - av_log(s->avctx, AV_LOG_DEBUG, "startcode: %3X ", startcode); - if (startcode<=0x11F) av_log(s->avctx, AV_LOG_DEBUG, "Video Object Start"); - else if(startcode<=0x12F) av_log(s->avctx, AV_LOG_DEBUG, "Video Object Layer Start"); - else if(startcode<=0x13F) av_log(s->avctx, AV_LOG_DEBUG, "Reserved"); - else if(startcode<=0x15F) av_log(s->avctx, AV_LOG_DEBUG, "FGS bp start"); - else if(startcode<=0x1AF) av_log(s->avctx, AV_LOG_DEBUG, "Reserved"); - else if(startcode==0x1B0) av_log(s->avctx, AV_LOG_DEBUG, "Visual Object Seq Start"); - else if(startcode==0x1B1) av_log(s->avctx, AV_LOG_DEBUG, "Visual Object Seq End"); - else if(startcode==0x1B2) av_log(s->avctx, AV_LOG_DEBUG, "User Data"); - else if(startcode==0x1B3) av_log(s->avctx, AV_LOG_DEBUG, "Group of VOP start"); - else if(startcode==0x1B4) av_log(s->avctx, AV_LOG_DEBUG, "Video Session Error"); - else if(startcode==0x1B5) av_log(s->avctx, AV_LOG_DEBUG, "Visual Object Start"); - else if(startcode==0x1B6) av_log(s->avctx, AV_LOG_DEBUG, "Video Object Plane start"); - else if(startcode==0x1B7) av_log(s->avctx, AV_LOG_DEBUG, "slice start"); - else if(startcode==0x1B8) av_log(s->avctx, AV_LOG_DEBUG, "extension start"); - else if(startcode==0x1B9) av_log(s->avctx, AV_LOG_DEBUG, "fgs start"); - else if(startcode==0x1BA) av_log(s->avctx, AV_LOG_DEBUG, "FBA Object start"); - else if(startcode==0x1BB) av_log(s->avctx, AV_LOG_DEBUG, "FBA Object Plane start"); - else if(startcode==0x1BC) av_log(s->avctx, AV_LOG_DEBUG, "Mesh Object start"); - else if(startcode==0x1BD) av_log(s->avctx, AV_LOG_DEBUG, "Mesh Object Plane start"); - else if(startcode==0x1BE) av_log(s->avctx, AV_LOG_DEBUG, "Still Texture Object start"); - else if(startcode==0x1BF) av_log(s->avctx, AV_LOG_DEBUG, "Texture Spatial Layer start"); - else if(startcode==0x1C0) av_log(s->avctx, AV_LOG_DEBUG, "Texture SNR Layer start"); - else if(startcode==0x1C1) av_log(s->avctx, AV_LOG_DEBUG, "Texture Tile start"); - else if(startcode==0x1C2) av_log(s->avctx, AV_LOG_DEBUG, "Texture Shape Layer start"); - else if(startcode==0x1C3) av_log(s->avctx, AV_LOG_DEBUG, "stuffing start"); - else if(startcode<=0x1C5) av_log(s->avctx, AV_LOG_DEBUG, "reserved"); - else if(startcode<=0x1FF) av_log(s->avctx, AV_LOG_DEBUG, "System start"); - av_log(s->avctx, AV_LOG_DEBUG, " at %d\n", get_bits_count(gb)); - } - - if(startcode >= 0x120 && startcode <= 0x12F){ - if(decode_vol_header(s, gb) < 0) - return -1; - } - else if(startcode == USER_DATA_STARTCODE){ - decode_user_data(s, gb); - } - else if(startcode == GOP_STARTCODE){ - mpeg4_decode_gop_header(s, gb); - } - else if(startcode == VOP_STARTCODE){ - break; - } - - align_get_bits(gb); - startcode = 0xff; - } -end: - if(s->flags& CODEC_FLAG_LOW_DELAY) - s->low_delay=1; - s->avctx->has_b_frames= !s->low_delay; - return decode_vop_header(s, gb); -} - -/* don't understand why they choose a different header ! */ -int intel_h263_decode_picture_header(MpegEncContext *s) -{ - int format; - - /* picture header */ - if (get_bits_long(&s->gb, 22) != 0x20) { - av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n"); - return -1; - } - s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */ - - if (get_bits1(&s->gb) != 1) { - av_log(s->avctx, AV_LOG_ERROR, "Bad marker\n"); - return -1; /* marker */ - } - if (get_bits1(&s->gb) != 0) { - av_log(s->avctx, AV_LOG_ERROR, "Bad H263 id\n"); - return -1; /* h263 id */ - } - skip_bits1(&s->gb); /* split screen off */ - skip_bits1(&s->gb); /* camera off */ - skip_bits1(&s->gb); /* freeze picture release off */ - - format = get_bits(&s->gb, 3); - if (format != 7) { - av_log(s->avctx, AV_LOG_ERROR, "Intel H263 free format not supported\n"); - return -1; - } - s->h263_plus = 0; - - s->pict_type = FF_I_TYPE + get_bits1(&s->gb); - - s->unrestricted_mv = get_bits1(&s->gb); - s->h263_long_vectors = s->unrestricted_mv; - - if (get_bits1(&s->gb) != 0) { - av_log(s->avctx, AV_LOG_ERROR, "SAC not supported\n"); - return -1; /* SAC: off */ - } - s->obmc= get_bits1(&s->gb); - s->pb_frame = get_bits1(&s->gb); - - if(format == 7){ - format = get_bits(&s->gb, 3); - if(format == 0 || format == 7){ - av_log(s->avctx, AV_LOG_ERROR, "Wrong Intel H263 format\n"); - return -1; - } - if(get_bits(&s->gb, 2)) - av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n"); - s->loop_filter = get_bits1(&s->gb); - if(get_bits1(&s->gb)) - av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n"); - if(get_bits1(&s->gb)) - s->pb_frame = 2; - if(get_bits(&s->gb, 5)) - av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n"); - if(get_bits(&s->gb, 5) != 1) - av_log(s->avctx, AV_LOG_ERROR, "Invalid marker\n"); - } - if(format == 6){ - int ar = get_bits(&s->gb, 4); - skip_bits(&s->gb, 9); // display width - skip_bits1(&s->gb); - skip_bits(&s->gb, 9); // display height - if(ar == 15){ - skip_bits(&s->gb, 8); // aspect ratio - width - skip_bits(&s->gb, 8); // aspect ratio - height - } - } - - s->chroma_qscale= s->qscale = get_bits(&s->gb, 5); - skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */ - - if(s->pb_frame){ - skip_bits(&s->gb, 3); //temporal reference for B-frame - skip_bits(&s->gb, 2); //dbquant - } - - /* PEI */ - while (get_bits1(&s->gb) != 0) { - skip_bits(&s->gb, 8); - } - s->f_code = 1; - - s->y_dc_scale_table= - s->c_dc_scale_table= ff_mpeg1_dc_scale_table; - - if(s->avctx->debug&FF_DEBUG_PICT_INFO) - show_pict_info(s); - - return 0; -} - -int flv_h263_decode_picture_header(MpegEncContext *s) -{ - int format, width, height; - - /* picture header */ - if (get_bits_long(&s->gb, 17) != 1) { - av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n"); - return -1; - } - format = get_bits(&s->gb, 5); - if (format != 0 && format != 1) { - av_log(s->avctx, AV_LOG_ERROR, "Bad picture format\n"); - return -1; - } - s->h263_flv = format+1; - s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */ - format = get_bits(&s->gb, 3); - switch (format) { - case 0: - width = get_bits(&s->gb, 8); - height = get_bits(&s->gb, 8); - break; - case 1: - width = get_bits(&s->gb, 16); - height = get_bits(&s->gb, 16); - break; - case 2: - width = 352; - height = 288; - break; - case 3: - width = 176; - height = 144; - break; - case 4: - width = 128; - height = 96; - break; - case 5: - width = 320; - height = 240; - break; - case 6: - width = 160; - height = 120; - break; - default: - width = height = 0; - break; - } - if(avcodec_check_dimensions(s->avctx, width, height)) - return -1; - s->width = width; - s->height = height; - - s->pict_type = FF_I_TYPE + get_bits(&s->gb, 2); - s->dropable= s->pict_type > FF_P_TYPE; - if (s->dropable) - s->pict_type = FF_P_TYPE; - - skip_bits1(&s->gb); /* deblocking flag */ - s->chroma_qscale= s->qscale = get_bits(&s->gb, 5); - - s->h263_plus = 0; - - s->unrestricted_mv = 1; - s->h263_long_vectors = 0; - - /* PEI */ - while (get_bits1(&s->gb) != 0) { - skip_bits(&s->gb, 8); - } - s->f_code = 1; - - if(s->avctx->debug & FF_DEBUG_PICT_INFO){ - av_log(s->avctx, AV_LOG_DEBUG, "%c esc_type:%d, qp:%d num:%d\n", - s->dropable ? 'D' : av_get_pict_type_char(s->pict_type), s->h263_flv-1, s->qscale, s->picture_number); - } - - s->y_dc_scale_table= - s->c_dc_scale_table= ff_mpeg1_dc_scale_table; - - return 0; -} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/h263.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/h263.h index b89bf1b923..678588a171 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/h263.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/h263.h @@ -1,6 +1,5 @@ /* - * H263/MPEG4 backend for ffmpeg encoder and decoder - * copyright (c) 2007 Aurelien Jacobs + * H263 internal header * * This file is part of FFmpeg. * @@ -18,27 +17,235 @@ * 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 #define AVCODEC_H263_H -#include "config.h" -#include "msmpeg4.h" +#include +#include "libavutil/rational.h" +#include "get_bits.h" +#include "mpegvideo.h" +#include "rl.h" -#define CONFIG_ANY_H263_DECODER (CONFIG_H263_DECODER || \ - CONFIG_H263I_DECODER || \ - CONFIG_FLV_DECODER || \ - CONFIG_RV10_DECODER || \ - CONFIG_RV20_DECODER || \ - CONFIG_MPEG4_DECODER || \ - CONFIG_MSMPEG4_DECODER || \ - CONFIG_WMV_DECODER) -#define CONFIG_ANY_H263_ENCODER (CONFIG_H263_ENCODER || \ - CONFIG_H263P_ENCODER || \ - CONFIG_FLV_ENCODER || \ - CONFIG_MPEG4_ENCODER || \ - CONFIG_MSMPEG4_ENCODER || \ - CONFIG_WMV_ENCODER) -#define CONFIG_ANY_H263 (CONFIG_ANY_H263_DECODER || CONFIG_ANY_H263_ENCODER) +// The defines below define the number of bits that are read at once for +// reading vlc values. Changing these may improve speed and data cache needs +// be aware though that decreasing them may need the number of stages that is +// passed to get_vlc* to be increased. +#define INTRA_MCBPC_VLC_BITS 6 +#define INTER_MCBPC_VLC_BITS 7 +#define CBPY_VLC_BITS 6 +#define TEX_VLC_BITS 9 -#endif /* AVCODEC_H263_H */ +extern const AVRational ff_h263_pixel_aspect[16]; +extern const uint8_t ff_h263_cbpy_tab[16][2]; + +extern const uint8_t cbpc_b_tab[4][2]; + +extern const uint8_t mvtab[33][2]; + +extern const uint8_t ff_h263_intra_MCBPC_code[9]; +extern const uint8_t ff_h263_intra_MCBPC_bits[9]; + +extern const uint8_t ff_h263_inter_MCBPC_code[28]; +extern const uint8_t ff_h263_inter_MCBPC_bits[28]; +extern const uint8_t h263_mbtype_b_tab[15][2]; + +extern VLC ff_h263_intra_MCBPC_vlc; +extern VLC ff_h263_inter_MCBPC_vlc; +extern VLC ff_h263_cbpy_vlc; + +extern RLTable ff_h263_rl_inter; + +extern RLTable rl_intra_aic; + +extern const uint16_t h263_format[8][2]; +extern const uint8_t modified_quant_tab[2][32]; +extern uint16_t ff_mba_max[6]; +extern uint8_t ff_mba_length[7]; + +extern uint8_t ff_h263_static_rl_table_store[2][2][2*MAX_RUN + MAX_LEVEL + 3]; + + +int h263_decode_motion(MpegEncContext * s, int pred, int f_code); +av_const int ff_h263_aspect_to_info(AVRational aspect); +int ff_h263_decode_init(AVCodecContext *avctx); +int ff_h263_decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + AVPacket *avpkt); +int ff_h263_decode_end(AVCodecContext *avctx); +void h263_encode_mb(MpegEncContext *s, + DCTELEM block[6][64], + int motion_x, int motion_y); +void h263_encode_picture_header(MpegEncContext *s, int picture_number); +void h263_encode_gob_header(MpegEncContext * s, int mb_line); +int16_t *h263_pred_motion(MpegEncContext * s, int block, int dir, + int *px, int *py); +void h263_encode_init(MpegEncContext *s); +void h263_decode_init_vlc(MpegEncContext *s); +int h263_decode_picture_header(MpegEncContext *s); +int ff_h263_decode_gob_header(MpegEncContext *s); +void ff_h263_update_motion_val(MpegEncContext * s); +void ff_h263_loop_filter(MpegEncContext * s); +int ff_h263_decode_mba(MpegEncContext *s); +void ff_h263_encode_mba(MpegEncContext *s); +void ff_init_qscale_tab(MpegEncContext *s); +int h263_pred_dc(MpegEncContext * s, int n, int16_t **dc_val_ptr); +void h263_pred_acdc(MpegEncContext * s, DCTELEM *block, int n); + + +/** + * Prints picture info if FF_DEBUG_PICT_INFO is set. + */ +void ff_h263_show_pict_info(MpegEncContext *s); + +int ff_intel_h263_decode_picture_header(MpegEncContext *s); +int ff_h263_decode_mb(MpegEncContext *s, + DCTELEM block[6][64]); + +/** + * Returns the value of the 3bit "source format" syntax element. + * that represents some standard picture dimensions or indicates that + * width&height are explicitly stored later. + */ +int av_const h263_get_picture_format(int width, int height); + +void ff_clean_h263_qscales(MpegEncContext *s); +int ff_h263_resync(MpegEncContext *s); +const uint8_t *ff_h263_find_resync_marker(const uint8_t *p, const uint8_t *end); +int ff_h263_get_gob_height(MpegEncContext *s); +void ff_h263_encode_motion(MpegEncContext * s, int val, int f_code); + + +static inline int h263_get_motion_length(MpegEncContext * s, int val, int f_code){ + int l, bit_size, code; + + if (val == 0) { + return mvtab[0][1]; + } else { + bit_size = f_code - 1; + /* modulo encoding */ + l= INT_BIT - 6 - bit_size; + val = (val<>l; + val--; + code = (val >> bit_size) + 1; + + return mvtab[code][1] + 1 + bit_size; + } +} + +static inline void ff_h263_encode_motion_vector(MpegEncContext * s, int x, int y, int f_code){ + if(s->flags2 & CODEC_FLAG2_NO_OUTPUT){ + skip_put_bits(&s->pb, + h263_get_motion_length(s, x, f_code) + +h263_get_motion_length(s, y, f_code)); + }else{ + ff_h263_encode_motion(s, x, f_code); + ff_h263_encode_motion(s, y, f_code); + } +} + +static inline int get_p_cbp(MpegEncContext * s, + DCTELEM block[6][64], + int motion_x, int motion_y){ + int cbp, i; + + if(s->flags & CODEC_FLAG_CBP_RD){ + int best_cbpy_score= INT_MAX; + int best_cbpc_score= INT_MAX; + int cbpc = (-1), cbpy= (-1); + const int offset= (s->mv_type==MV_TYPE_16X16 ? 0 : 16) + (s->dquant ? 8 : 0); + const int lambda= s->lambda2 >> (FF_LAMBDA_SHIFT - 6); + + for(i=0; i<4; i++){ + int score= ff_h263_inter_MCBPC_bits[i + offset] * lambda; + if(i&1) score += s->coded_score[5]; + if(i&2) score += s->coded_score[4]; + + if(score < best_cbpc_score){ + best_cbpc_score= score; + cbpc= i; + } + } + + for(i=0; i<16; i++){ + int score= ff_h263_cbpy_tab[i ^ 0xF][1] * lambda; + if(i&1) score += s->coded_score[3]; + if(i&2) score += s->coded_score[2]; + if(i&4) score += s->coded_score[1]; + if(i&8) score += s->coded_score[0]; + + if(score < best_cbpy_score){ + best_cbpy_score= score; + cbpy= i; + } + } + cbp= cbpc + 4*cbpy; + if ((motion_x | motion_y | s->dquant) == 0 && s->mv_type==MV_TYPE_16X16){ + if(best_cbpy_score + best_cbpc_score + 2*lambda >= 0) + cbp= 0; + } + + for (i = 0; i < 6; i++) { + if (s->block_last_index[i] >= 0 && ((cbp >> (5 - i))&1)==0 ){ + s->block_last_index[i]= -1; + s->dsp.clear_block(s->block[i]); + } + } + }else{ + cbp= 0; + for (i = 0; i < 6; i++) { + if (s->block_last_index[i] >= 0) + cbp |= 1 << (5 - i); + } + } + return cbp; +} + +static inline int get_b_cbp(MpegEncContext * s, DCTELEM block[6][64], + int motion_x, int motion_y, int mb_type){ + int cbp=0, i; + + if(s->flags & CODEC_FLAG_CBP_RD){ + int score=0; + const int lambda= s->lambda2 >> (FF_LAMBDA_SHIFT - 6); + + for(i=0; i<6; i++){ + if(s->coded_score[i] < 0){ + score += s->coded_score[i]; + cbp |= 1 << (5 - i); + } + } + + if(cbp){ + int zero_score= -6; + if ((motion_x | motion_y | s->dquant | mb_type) == 0){ + zero_score-= 4; //2*MV + mb_type + cbp bit + } + + zero_score*= lambda; + if(zero_score <= score){ + cbp=0; + } + } + + for (i = 0; i < 6; i++) { + if (s->block_last_index[i] >= 0 && ((cbp >> (5 - i))&1)==0 ){ + s->block_last_index[i]= -1; + s->dsp.clear_block(s->block[i]); + } + } + }else{ + for (i = 0; i < 6; i++) { + if (s->block_last_index[i] >= 0) + cbp |= 1 << (5 - i); + } + } + return cbp; +} + +static inline void memsetw(short *tab, int val, int n) +{ + int i; + for(i=0;ichroma_sample_location = AVCHROMA_LOC_CENTER; break; case CODEC_ID_MPEG4: - s->decode_mb= ff_mpeg4_decode_mb; - s->time_increment_bits = 4; /* default value for broken headers */ - s->h263_pred = 1; - s->low_delay = 0; //default, might be overriden in the vol header during header parsing - avctx->chroma_sample_location = AVCHROMA_LOC_LEFT; break; case CODEC_ID_MSMPEG4V1: s->h263_msmpeg4 = 1; @@ -116,9 +115,6 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx) if (MPV_common_init(s) < 0) return -1; - if (CONFIG_MSMPEG4_DECODER && s->h263_msmpeg4) - ff_msmpeg4_decode_init(s); - else h263_decode_init_vlc(s); return 0; @@ -174,7 +170,7 @@ static int decode_slice(MpegEncContext *s){ if(s->partitioned_frame){ const int qscale= s->qscale; - if(s->codec_id==CODEC_ID_MPEG4){ + if(CONFIG_MPEG4_DECODER && s->codec_id==CODEC_ID_MPEG4){ if(ff_mpeg4_decode_partitions(s) < 0) return -1; } @@ -267,8 +263,8 @@ static int decode_slice(MpegEncContext *s){ /* try to detect the padding bug */ if( s->codec_id==CODEC_ID_MPEG4 && (s->workaround_bugs&FF_BUG_AUTODETECT) - && s->gb.size_in_bits - get_bits_count(&s->gb) >=0 - && s->gb.size_in_bits - get_bits_count(&s->gb) < 48 + && get_bits_left(&s->gb) >=0 + && get_bits_left(&s->gb) < 48 // && !s->resync_marker && !s->data_partitioning){ @@ -291,7 +287,7 @@ static int decode_slice(MpegEncContext *s){ } if(s->workaround_bugs&FF_BUG_AUTODETECT){ - if(s->padding_bug_score > -2 && !s->data_partitioning /*&& (s->divx_version || !s->resync_marker)*/) + if(s->padding_bug_score > -2 && !s->data_partitioning /*&& (s->divx_version>=0 || !s->resync_marker)*/) s->workaround_bugs |= FF_BUG_NO_PADDING; else s->workaround_bugs &= ~FF_BUG_NO_PADDING; @@ -299,7 +295,7 @@ static int decode_slice(MpegEncContext *s){ // handle formats which don't have unique end markers if(s->msmpeg4_version || (s->workaround_bugs&FF_BUG_NO_PADDING)){ //FIXME perhaps solve this more cleanly - int left= s->gb.size_in_bits - get_bits_count(&s->gb); + int left= get_bits_left(&s->gb); int max_extra=7; /* no markers in M$ crap */ @@ -324,7 +320,7 @@ static int decode_slice(MpegEncContext *s){ } av_log(s->avctx, AV_LOG_ERROR, "slice end not reached but screenspace end (%d left %06X, score= %d)\n", - s->gb.size_in_bits - get_bits_count(&s->gb), + get_bits_left(&s->gb), show_bits(&s->gb, 24), s->padding_bug_score); 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); @@ -403,7 +399,7 @@ retry: ret= ff_wmv2_decode_picture_header(s); } else if (CONFIG_MSMPEG4_DECODER && s->msmpeg4_version) { ret = msmpeg4_decode_picture_header(s); - } else if (s->h263_pred) { + } else if (CONFIG_MPEG4_DECODER && s->h263_pred) { if(s->avctx->extradata_size && s->picture_number==0){ GetBitContext gb; @@ -411,10 +407,10 @@ retry: ret = ff_mpeg4_decode_picture_header(s, &gb); } ret = ff_mpeg4_decode_picture_header(s, &s->gb); - } else if (s->codec_id == CODEC_ID_H263I) { - ret = intel_h263_decode_picture_header(s); - } else if (s->h263_flv) { - ret = flv_h263_decode_picture_header(s); + } else if (CONFIG_H263I_DECODER && s->codec_id == CODEC_ID_H263I) { + ret = ff_intel_h263_decode_picture_header(s); + } else if (CONFIG_FLV_DECODER && s->h263_flv) { + ret = ff_flv_decode_picture_header(s); } else { ret = h263_decode_picture_header(s); } @@ -429,26 +425,28 @@ retry: avctx->has_b_frames= !s->low_delay; - if(s->xvid_build==0 && s->divx_version==0 && s->lavc_build==0){ + if(s->xvid_build==-1 && s->divx_version==-1 && s->lavc_build==-1){ if(s->stream_codec_tag == AV_RL32("XVID") || s->codec_tag == AV_RL32("XVID") || s->codec_tag == AV_RL32("XVIX") || - s->codec_tag == AV_RL32("RMP4")) - s->xvid_build= -1; + s->codec_tag == AV_RL32("RMP4") || + s->codec_tag == AV_RL32("SIPP") + ) + s->xvid_build= 0; #if 0 if(s->codec_tag == AV_RL32("DIVX") && s->vo_type==0 && s->vol_control_parameters==1 && s->padding_bug_score > 0 && s->low_delay) // XVID with modified fourcc - s->xvid_build= -1; + s->xvid_build= 0; #endif } - if(s->xvid_build==0 && s->divx_version==0 && s->lavc_build==0){ + if(s->xvid_build==-1 && s->divx_version==-1 && s->lavc_build==-1){ if(s->codec_tag == AV_RL32("DIVX") && s->vo_type==0 && s->vol_control_parameters==0) s->divx_version= 400; //divx 4 } - if(s->xvid_build && s->divx_version){ + if(s->xvid_build>=0 && s->divx_version>=0){ s->divx_version= - s->divx_build= 0; + s->divx_build= -1; } if(s->workaround_bugs&FF_BUG_AUTODETECT){ @@ -467,16 +465,16 @@ retry: s->workaround_bugs|= FF_BUG_QPEL_CHROMA2; } - if(s->xvid_build && s->xvid_build<=3) + if(s->xvid_build<=3U) s->padding_bug_score= 256*256*256*64; - if(s->xvid_build && s->xvid_build<=1) + if(s->xvid_build<=1U) s->workaround_bugs|= FF_BUG_QPEL_CHROMA; - if(s->xvid_build && s->xvid_build<=12) + if(s->xvid_build<=12U) s->workaround_bugs|= FF_BUG_EDGE; - if(s->xvid_build && s->xvid_build<=32) + if(s->xvid_build<=32U) s->workaround_bugs|= FF_BUG_DC_CLIP; #define SET_QPEL_FUNC(postfix1, postfix2) \ @@ -484,30 +482,30 @@ retry: s->dsp.put_no_rnd_ ## postfix1 = ff_put_no_rnd_ ## postfix2;\ s->dsp.avg_ ## postfix1 = ff_avg_ ## postfix2; - if(s->lavc_build && s->lavc_build<4653) + if(s->lavc_build<4653U) s->workaround_bugs|= FF_BUG_STD_QPEL; - if(s->lavc_build && s->lavc_build<4655) + if(s->lavc_build<4655U) s->workaround_bugs|= FF_BUG_DIRECT_BLOCKSIZE; - if(s->lavc_build && s->lavc_build<4670){ + if(s->lavc_build<4670U){ s->workaround_bugs|= FF_BUG_EDGE; } - if(s->lavc_build && s->lavc_build<=4712) + if(s->lavc_build<=4712U) s->workaround_bugs|= FF_BUG_DC_CLIP; - if(s->divx_version) + if(s->divx_version>=0) s->workaround_bugs|= FF_BUG_DIRECT_BLOCKSIZE; //printf("padding_bug_score: %d\n", s->padding_bug_score); if(s->divx_version==501 && s->divx_build==20020416) s->padding_bug_score= 256*256*256*64; - if(s->divx_version && s->divx_version<500){ + if(s->divx_version<500U){ s->workaround_bugs|= FF_BUG_EDGE; } - if(s->divx_version) + if(s->divx_version>=0) s->workaround_bugs|= FF_BUG_HPEL_CHROMA; #if 0 if(s->divx_version==500) @@ -516,11 +514,11 @@ retry: /* very ugly XVID padding bug detection FIXME/XXX solve this differently * Let us hope this at least works. */ - if( s->resync_marker==0 && s->data_partitioning==0 && s->divx_version==0 + if( s->resync_marker==0 && s->data_partitioning==0 && s->divx_version==-1 && s->codec_id==CODEC_ID_MPEG4 && s->vo_type==0) s->workaround_bugs|= FF_BUG_NO_PADDING; - if(s->lavc_build && s->lavc_build<4609) //FIXME not sure about the version num but a 4609 file seems ok + if(s->lavc_build<4609U) //FIXME not sure about the version num but a 4609 file seems ok s->workaround_bugs|= FF_BUG_NO_PADDING; #endif } @@ -555,7 +553,7 @@ retry: #endif #if HAVE_MMX - if(s->codec_id == CODEC_ID_MPEG4 && s->xvid_build && avctx->idct_algo == FF_IDCT_AUTO && (mm_flags & FF_MM_MMX)){ + if(s->codec_id == CODEC_ID_MPEG4 && s->xvid_build>=0 && avctx->idct_algo == FF_IDCT_AUTO && (mm_flags & FF_MM_MMX)){ avctx->idct_algo= FF_IDCT_XVIDMMX; avctx->coded_width= 0; // force reinit // dsputil_init(&s->dsp, avctx); @@ -621,8 +619,13 @@ retry: if(MPV_frame_start(s, avctx) < 0) return -1; + if (CONFIG_MPEG4_VDPAU_DECODER && (s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)) { + ff_vdpau_mpeg4_decode_picture(s, s->gb.buffer, s->gb.buffer_end - s->gb.buffer); + goto frame_end; + } + if (avctx->hwaccel) { - if (avctx->hwaccel->start_frame(avctx, buf, buf_size) < 0) + if (avctx->hwaccel->start_frame(avctx, s->gb.buffer, s->gb.buffer_end - s->gb.buffer) < 0) return -1; } @@ -661,8 +664,10 @@ retry: s->error_status_table[s->mb_num-1]= AC_ERROR|DC_ERROR|MV_ERROR; } + assert(s->bitstream_buffer_size==0); +frame_end: /* divx 5.01+ bistream reorder stuff */ - if(s->codec_id==CODEC_ID_MPEG4 && s->bitstream_buffer_size==0 && s->divx_packed){ + if(s->codec_id==CODEC_ID_MPEG4 && s->divx_packed){ int current_pos= get_bits_count(&s->gb)>>3; int startcode_found=0; @@ -675,7 +680,7 @@ retry: } } } - if(s->gb.buffer == s->bitstream_buffer && buf_size>20){ //xvid style + if(s->gb.buffer == s->bitstream_buffer && buf_size>7 && s->xvid_build>=0){ //xvid style startcode_found=1; current_pos=0; } @@ -722,24 +727,9 @@ av_log(avctx, AV_LOG_DEBUG, "%"PRId64"\n", rdtsc()-time); return get_consumed_bytes(s, buf_size); } -AVCodec mpeg4_decoder = { - "mpeg4", - CODEC_TYPE_VIDEO, - CODEC_ID_MPEG4, - 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, - .flush= ff_mpeg_flush, - .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2"), - .pix_fmts= ff_hwaccel_pixfmt_list_420, -}; - AVCodec h263_decoder = { "h263", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_H263, sizeof(MpegEncContext), ff_h263_decode_init, @@ -751,87 +741,3 @@ AVCodec h263_decoder = { .long_name= NULL_IF_CONFIG_SMALL("H.263 / H.263-1996, H.263+ / H.263-1998 / H.263 version 2"), .pix_fmts= ff_hwaccel_pixfmt_list_420, }; - -AVCodec msmpeg4v1_decoder = { - "msmpeg4v1", - CODEC_TYPE_VIDEO, - CODEC_ID_MSMPEG4V1, - sizeof(MpegEncContext), - ff_h263_decode_init, - NULL, - ff_h263_decode_end, - ff_h263_decode_frame, - CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, - .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 1"), - .pix_fmts= ff_pixfmt_list_420, -}; - -AVCodec msmpeg4v2_decoder = { - "msmpeg4v2", - CODEC_TYPE_VIDEO, - CODEC_ID_MSMPEG4V2, - sizeof(MpegEncContext), - ff_h263_decode_init, - NULL, - ff_h263_decode_end, - ff_h263_decode_frame, - CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, - .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 2"), - .pix_fmts= ff_pixfmt_list_420, -}; - -AVCodec msmpeg4v3_decoder = { - "msmpeg4", - CODEC_TYPE_VIDEO, - CODEC_ID_MSMPEG4V3, - sizeof(MpegEncContext), - ff_h263_decode_init, - NULL, - ff_h263_decode_end, - ff_h263_decode_frame, - CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, - .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 3"), - .pix_fmts= ff_pixfmt_list_420, -}; - -AVCodec wmv1_decoder = { - "wmv1", - CODEC_TYPE_VIDEO, - CODEC_ID_WMV1, - sizeof(MpegEncContext), - ff_h263_decode_init, - NULL, - ff_h263_decode_end, - ff_h263_decode_frame, - CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, - .long_name= NULL_IF_CONFIG_SMALL("Windows Media Video 7"), - .pix_fmts= ff_pixfmt_list_420, -}; - -AVCodec h263i_decoder = { - "h263i", - CODEC_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, - .long_name = NULL_IF_CONFIG_SMALL("Intel H.263"), - .pix_fmts= ff_pixfmt_list_420, -}; - -AVCodec flv_decoder = { - "flv", - CODEC_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, - .long_name= NULL_IF_CONFIG_SMALL("Flash Video (FLV)"), - .pix_fmts= ff_pixfmt_list_420, -}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/h264.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264.c index bc770fc5fd..e4654f0435 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/h264.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/h264.c + * @file * H.264 / AVC / MPEG4 part10 codec. * @author Michael Niedermayer */ @@ -31,6 +31,7 @@ #include "mpegvideo.h" #include "h264.h" #include "h264data.h" +#include "h264_mvpred.h" #include "h264_parser.h" #include "golomb.h" #include "mathops.h" @@ -38,57 +39,10 @@ #include "vdpau_internal.h" #include "cabac.h" -#if ARCH_X86 -#include "x86/h264_i386.h" -#endif //#undef NDEBUG #include -/** - * Value of Picture.reference when Picture is not a reference picture, but - * is held for delayed output. - */ -#define DELAYED_PIC_REF 4 - -static VLC coeff_token_vlc[4]; -static VLC_TYPE coeff_token_vlc_tables[520+332+280+256][2]; -static const int coeff_token_vlc_tables_size[4]={520,332,280,256}; - -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 total_zeros_vlc[15]; -static VLC_TYPE total_zeros_vlc_tables[15][512][2]; -static const int total_zeros_vlc_tables_size = 512; - -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 run_vlc[6]; -static VLC_TYPE run_vlc_tables[6][8][2]; -static const int run_vlc_tables_size = 8; - -static VLC run7_vlc; -static VLC_TYPE run7_vlc_table[96][2]; -static const int run7_vlc_table_size = 96; - -static void svq3_luma_dc_dequant_idct_c(DCTELEM *block, int qp); -static void svq3_add_idct_c(uint8_t *dst, DCTELEM *block, int stride, int qp, int dc); -static void 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); -static void 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 Picture * remove_long(H264Context *h, int i, int ref_mask); - -static av_always_inline uint32_t pack16to32(int a, int b){ -#if HAVE_BIGENDIAN - return (b&0xFFFF) + (a<<16); -#else - return (a&0xFFFF) + (b<<16); -#endif -} - static const uint8_t rem6[52]={ 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, }; @@ -97,471 +51,19 @@ static const uint8_t div6[52]={ 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, }; -static const uint8_t left_block_options[4][8]={ - {0,1,2,3,7,10,8,11}, - {2,2,3,3,8,11,8,11}, - {0,0,1,1,7,10,7,10}, - {0,2,0,2,7,10,7,10} -}; +void ff_h264_write_back_intra_pred_mode(H264Context *h){ + int8_t *mode= h->intra4x4_pred_mode + h->mb2br_xy[h->mb_xy]; -#define LEVEL_TAB_BITS 8 -static int8_t cavlc_level_tab[7][1<s; - const int mb_xy= h->mb_xy; - int topleft_xy, top_xy, topright_xy, left_xy[2]; - int topleft_type, top_type, topright_type, left_type[2]; - const uint8_t * left_block; - int topleft_partition= -1; - int i; - - top_xy = mb_xy - (s->mb_stride << FIELD_PICTURE); - - //FIXME deblocking could skip the intra and nnz parts. - if(for_deblock && (h->slice_num == 1 || h->slice_table[mb_xy] == h->slice_table[top_xy]) && !FRAME_MBAFF) - return; - - /* 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[1] = left_xy[0] = mb_xy-1; - left_block = left_block_options[0]; - if(FRAME_MBAFF){ - const int pair_xy = s->mb_x + (s->mb_y & ~1)*s->mb_stride; - const int top_pair_xy = pair_xy - s->mb_stride; - const int topleft_pair_xy = top_pair_xy - 1; - const int topright_pair_xy = top_pair_xy + 1; - const int topleft_mb_field_flag = IS_INTERLACED(s->current_picture.mb_type[topleft_pair_xy]); - const int top_mb_field_flag = IS_INTERLACED(s->current_picture.mb_type[top_pair_xy]); - const int topright_mb_field_flag = IS_INTERLACED(s->current_picture.mb_type[topright_pair_xy]); - const int left_mb_field_flag = IS_INTERLACED(s->current_picture.mb_type[pair_xy-1]); - const int curr_mb_field_flag = IS_INTERLACED(mb_type); - const int bottom = (s->mb_y & 1); - tprintf(s->avctx, "fill_caches: curr_mb_field_flag:%d, left_mb_field_flag:%d, topleft_mb_field_flag:%d, top_mb_field_flag:%d, topright_mb_field_flag:%d\n", curr_mb_field_flag, left_mb_field_flag, topleft_mb_field_flag, top_mb_field_flag, topright_mb_field_flag); - - if (curr_mb_field_flag && (bottom || top_mb_field_flag)){ - top_xy -= s->mb_stride; - } - if (curr_mb_field_flag && (bottom || topleft_mb_field_flag)){ - topleft_xy -= s->mb_stride; - } else if(bottom && !curr_mb_field_flag && left_mb_field_flag) { - 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 - topleft_partition = 0; - } - if (curr_mb_field_flag && (bottom || topright_mb_field_flag)){ - topright_xy -= s->mb_stride; - } - if (left_mb_field_flag != curr_mb_field_flag) { - left_xy[1] = left_xy[0] = pair_xy - 1; - if (curr_mb_field_flag) { - left_xy[1] += s->mb_stride; - left_block = left_block_options[3]; - } else { - left_block= left_block_options[2 - bottom]; - } - } - } - - h->top_mb_xy = top_xy; - h->left_mb_xy[0] = left_xy[0]; - h->left_mb_xy[1] = left_xy[1]; - if(for_deblock){ - topleft_type = 0; - topright_type = 0; - top_type = h->slice_table[top_xy ] < 0xFFFF ? s->current_picture.mb_type[top_xy] : 0; - left_type[0] = h->slice_table[left_xy[0] ] < 0xFFFF ? s->current_picture.mb_type[left_xy[0]] : 0; - left_type[1] = h->slice_table[left_xy[1] ] < 0xFFFF ? s->current_picture.mb_type[left_xy[1]] : 0; - - if(MB_MBAFF && !IS_INTRA(mb_type)){ - int list; - for(list=0; listlist_count; list++){ - //These values where changed for ease of performing MC, we need to change them back - //FIXME maybe we can make MC and loop filter use the same values or prevent - //the MC code from changing ref_cache and rather use a temporary array. - if(USES_LIST(mb_type,list)){ - int8_t *ref = &s->current_picture.ref_index[list][h->mb2b8_xy[mb_xy]]; - *(uint32_t*)&h->ref_cache[list][scan8[ 0]] = - *(uint32_t*)&h->ref_cache[list][scan8[ 2]] = (pack16to32(ref[0],ref[1])&0x00FF00FF)*0x0101; - ref += h->b8_stride; - *(uint32_t*)&h->ref_cache[list][scan8[ 8]] = - *(uint32_t*)&h->ref_cache[list][scan8[10]] = (pack16to32(ref[0],ref[1])&0x00FF00FF)*0x0101; - } - } - } - }else{ - topleft_type = h->slice_table[topleft_xy ] == h->slice_num ? s->current_picture.mb_type[topleft_xy] : 0; - top_type = h->slice_table[top_xy ] == h->slice_num ? s->current_picture.mb_type[top_xy] : 0; - topright_type= h->slice_table[topright_xy] == h->slice_num ? s->current_picture.mb_type[topright_xy]: 0; - left_type[0] = h->slice_table[left_xy[0] ] == h->slice_num ? s->current_picture.mb_type[left_xy[0]] : 0; - left_type[1] = h->slice_table[left_xy[1] ] == h->slice_num ? s->current_picture.mb_type[left_xy[1]] : 0; - - 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[0])){ - if(IS_INTERLACED(mb_type)){ - if(!(left_type[0] & type_mask)){ - h->topleft_samples_available&= 0xDFFF; - h->left_samples_available&= 0x5FFF; - } - if(!(left_type[1] & type_mask)){ - h->topleft_samples_available&= 0xFF5F; - h->left_samples_available&= 0xFF5F; - } - }else{ - int left_typei = h->slice_table[left_xy[0] + s->mb_stride ] == h->slice_num - ? s->current_picture.mb_type[left_xy[0] + s->mb_stride] : 0; - assert(left_xy[0] == left_xy[1]); - if(!((left_typei & type_mask) && (left_type[0] & type_mask))){ - h->topleft_samples_available&= 0xDF5F; - h->left_samples_available&= 0x5F5F; - } - } - }else{ - if(!(left_type[0] & 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)){ - h->intra4x4_pred_mode_cache[4+8*0]= h->intra4x4_pred_mode[top_xy][4]; - h->intra4x4_pred_mode_cache[5+8*0]= h->intra4x4_pred_mode[top_xy][5]; - h->intra4x4_pred_mode_cache[6+8*0]= h->intra4x4_pred_mode[top_xy][6]; - h->intra4x4_pred_mode_cache[7+8*0]= h->intra4x4_pred_mode[top_xy][3]; - }else{ - int pred; - if(!(top_type & type_mask)) - pred= -1; - else{ - pred= 2; - } - 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]= pred; - } - for(i=0; i<2; i++){ - if(IS_INTRA4x4(left_type[i])){ - h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= h->intra4x4_pred_mode[left_xy[i]][left_block[0+2*i]]; - h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= h->intra4x4_pred_mode[left_xy[i]][left_block[1+2*i]]; - }else{ - int pred; - if(!(left_type[i] & type_mask)) - pred= -1; - else{ - pred= 2; - } - h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= - h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= pred; - } - } - } - } - } - - -/* -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) - if(top_type){ - h->non_zero_count_cache[4+8*0]= h->non_zero_count[top_xy][4]; - h->non_zero_count_cache[5+8*0]= h->non_zero_count[top_xy][5]; - h->non_zero_count_cache[6+8*0]= h->non_zero_count[top_xy][6]; - h->non_zero_count_cache[7+8*0]= h->non_zero_count[top_xy][3]; - - h->non_zero_count_cache[1+8*0]= h->non_zero_count[top_xy][9]; - h->non_zero_count_cache[2+8*0]= h->non_zero_count[top_xy][8]; - - h->non_zero_count_cache[1+8*3]= h->non_zero_count[top_xy][12]; - h->non_zero_count_cache[2+8*3]= h->non_zero_count[top_xy][11]; - - }else{ - h->non_zero_count_cache[4+8*0]= - h->non_zero_count_cache[5+8*0]= - h->non_zero_count_cache[6+8*0]= - h->non_zero_count_cache[7+8*0]= - - h->non_zero_count_cache[1+8*0]= - h->non_zero_count_cache[2+8*0]= - - h->non_zero_count_cache[1+8*3]= - h->non_zero_count_cache[2+8*3]= h->pps.cabac && !IS_INTRA(mb_type) ? 0 : 64; - - } - - for (i=0; i<2; i++) { - if(left_type[i]){ - h->non_zero_count_cache[3+8*1 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[0+2*i]]; - h->non_zero_count_cache[3+8*2 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[1+2*i]]; - h->non_zero_count_cache[0+8*1 + 8*i]= h->non_zero_count[left_xy[i]][left_block[4+2*i]]; - h->non_zero_count_cache[0+8*4 + 8*i]= h->non_zero_count[left_xy[i]][left_block[5+2*i]]; - }else{ - h->non_zero_count_cache[3+8*1 + 2*8*i]= - h->non_zero_count_cache[3+8*2 + 2*8*i]= - h->non_zero_count_cache[0+8*1 + 8*i]= - h->non_zero_count_cache[0+8*4 + 8*i]= h->pps.cabac && !IS_INTRA(mb_type) ? 0 : 64; - } - } - - if( h->pps.cabac ) { - // top_cbp - if(top_type) { - h->top_cbp = h->cbp_table[top_xy]; - } else if(IS_INTRA(mb_type)) { - h->top_cbp = 0x1C0; - } else { - h->top_cbp = 0; - } - // left_cbp - if (left_type[0]) { - h->left_cbp = h->cbp_table[left_xy[0]] & 0x1f0; - } else if(IS_INTRA(mb_type)) { - h->left_cbp = 0x1C0; - } else { - h->left_cbp = 0; - } - if (left_type[0]) { - h->left_cbp |= ((h->cbp_table[left_xy[0]]>>((left_block[0]&(~1))+1))&0x1) << 1; - } - if (left_type[1]) { - h->left_cbp |= ((h->cbp_table[left_xy[1]]>>((left_block[2]&(~1))+1))&0x1) << 3; - } - } - -#if 1 - if(IS_INTER(mb_type) || IS_DIRECT(mb_type)){ - int list; - for(list=0; listlist_count; list++){ - if(!USES_LIST(mb_type, list) && !IS_DIRECT(mb_type) && !h->deblocking_filter){ - /*if(!h->mv_cache_clean[list]){ - memset(h->mv_cache [list], 0, 8*5*2*sizeof(int16_t)); //FIXME clean only input? clean at all? - memset(h->ref_cache[list], PART_NOT_AVAILABLE, 8*5*sizeof(int8_t)); - h->mv_cache_clean[list]= 1; - }*/ - continue; - } - h->mv_cache_clean[list]= 0; - - if(USES_LIST(top_type, list)){ - const int b_xy= h->mb2b_xy[top_xy] + 3*h->b_stride; - const int b8_xy= h->mb2b8_xy[top_xy] + h->b8_stride; - *(uint32_t*)h->mv_cache[list][scan8[0] + 0 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + 0]; - *(uint32_t*)h->mv_cache[list][scan8[0] + 1 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + 1]; - *(uint32_t*)h->mv_cache[list][scan8[0] + 2 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + 2]; - *(uint32_t*)h->mv_cache[list][scan8[0] + 3 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + 3]; - h->ref_cache[list][scan8[0] + 0 - 1*8]= - h->ref_cache[list][scan8[0] + 1 - 1*8]= s->current_picture.ref_index[list][b8_xy + 0]; - h->ref_cache[list][scan8[0] + 2 - 1*8]= - h->ref_cache[list][scan8[0] + 3 - 1*8]= s->current_picture.ref_index[list][b8_xy + 1]; - }else{ - *(uint32_t*)h->mv_cache [list][scan8[0] + 0 - 1*8]= - *(uint32_t*)h->mv_cache [list][scan8[0] + 1 - 1*8]= - *(uint32_t*)h->mv_cache [list][scan8[0] + 2 - 1*8]= - *(uint32_t*)h->mv_cache [list][scan8[0] + 3 - 1*8]= 0; - *(uint32_t*)&h->ref_cache[list][scan8[0] + 0 - 1*8]= ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE)&0xFF)*0x01010101; - } - - for(i=0; i<2; i++){ - int cache_idx = scan8[0] - 1 + i*2*8; - if(USES_LIST(left_type[i], list)){ - const int b_xy= h->mb2b_xy[left_xy[i]] + 3; - const int b8_xy= h->mb2b8_xy[left_xy[i]] + 1; - *(uint32_t*)h->mv_cache[list][cache_idx ]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[0+i*2]]; - *(uint32_t*)h->mv_cache[list][cache_idx+8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[1+i*2]]; - h->ref_cache[list][cache_idx ]= s->current_picture.ref_index[list][b8_xy + h->b8_stride*(left_block[0+i*2]>>1)]; - h->ref_cache[list][cache_idx+8]= s->current_picture.ref_index[list][b8_xy + h->b8_stride*(left_block[1+i*2]>>1)]; - }else{ - *(uint32_t*)h->mv_cache [list][cache_idx ]= - *(uint32_t*)h->mv_cache [list][cache_idx+8]= 0; - h->ref_cache[list][cache_idx ]= - h->ref_cache[list][cache_idx+8]= left_type[i] ? LIST_NOT_USED : PART_NOT_AVAILABLE; - } - } - - if(for_deblock || ((IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred) && !FRAME_MBAFF)) - continue; - - if(USES_LIST(topleft_type, list)){ - const int b_xy = h->mb2b_xy[topleft_xy] + 3 + h->b_stride + (topleft_partition & 2*h->b_stride); - const int b8_xy= h->mb2b8_xy[topleft_xy] + 1 + (topleft_partition & h->b8_stride); - *(uint32_t*)h->mv_cache[list][scan8[0] - 1 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy]; - h->ref_cache[list][scan8[0] - 1 - 1*8]= s->current_picture.ref_index[list][b8_xy]; - }else{ - *(uint32_t*)h->mv_cache[list][scan8[0] - 1 - 1*8]= 0; - h->ref_cache[list][scan8[0] - 1 - 1*8]= topleft_type ? LIST_NOT_USED : PART_NOT_AVAILABLE; - } - - if(USES_LIST(topright_type, list)){ - const int b_xy= h->mb2b_xy[topright_xy] + 3*h->b_stride; - const int b8_xy= h->mb2b8_xy[topright_xy] + h->b8_stride; - *(uint32_t*)h->mv_cache[list][scan8[0] + 4 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy]; - h->ref_cache[list][scan8[0] + 4 - 1*8]= s->current_picture.ref_index[list][b8_xy]; - }else{ - *(uint32_t*)h->mv_cache [list][scan8[0] + 4 - 1*8]= 0; - h->ref_cache[list][scan8[0] + 4 - 1*8]= topright_type ? LIST_NOT_USED : PART_NOT_AVAILABLE; - } - - if((IS_SKIP(mb_type) || IS_DIRECT(mb_type)) && !FRAME_MBAFF) - continue; - - h->ref_cache[list][scan8[5 ]+1] = - h->ref_cache[list][scan8[7 ]+1] = - h->ref_cache[list][scan8[13]+1] = //FIXME remove past 3 (init somewhere else) - h->ref_cache[list][scan8[4 ]] = - h->ref_cache[list][scan8[12]] = PART_NOT_AVAILABLE; - *(uint32_t*)h->mv_cache [list][scan8[5 ]+1]= - *(uint32_t*)h->mv_cache [list][scan8[7 ]+1]= - *(uint32_t*)h->mv_cache [list][scan8[13]+1]= //FIXME remove past 3 (init somewhere else) - *(uint32_t*)h->mv_cache [list][scan8[4 ]]= - *(uint32_t*)h->mv_cache [list][scan8[12]]= 0; - - if( h->pps.cabac ) { - /* XXX beurk, Load mvd */ - if(USES_LIST(top_type, list)){ - const int b_xy= h->mb2b_xy[top_xy] + 3*h->b_stride; - *(uint32_t*)h->mvd_cache[list][scan8[0] + 0 - 1*8]= *(uint32_t*)h->mvd_table[list][b_xy + 0]; - *(uint32_t*)h->mvd_cache[list][scan8[0] + 1 - 1*8]= *(uint32_t*)h->mvd_table[list][b_xy + 1]; - *(uint32_t*)h->mvd_cache[list][scan8[0] + 2 - 1*8]= *(uint32_t*)h->mvd_table[list][b_xy + 2]; - *(uint32_t*)h->mvd_cache[list][scan8[0] + 3 - 1*8]= *(uint32_t*)h->mvd_table[list][b_xy + 3]; - }else{ - *(uint32_t*)h->mvd_cache [list][scan8[0] + 0 - 1*8]= - *(uint32_t*)h->mvd_cache [list][scan8[0] + 1 - 1*8]= - *(uint32_t*)h->mvd_cache [list][scan8[0] + 2 - 1*8]= - *(uint32_t*)h->mvd_cache [list][scan8[0] + 3 - 1*8]= 0; - } - if(USES_LIST(left_type[0], list)){ - const int b_xy= h->mb2b_xy[left_xy[0]] + 3; - *(uint32_t*)h->mvd_cache[list][scan8[0] - 1 + 0*8]= *(uint32_t*)h->mvd_table[list][b_xy + h->b_stride*left_block[0]]; - *(uint32_t*)h->mvd_cache[list][scan8[0] - 1 + 1*8]= *(uint32_t*)h->mvd_table[list][b_xy + h->b_stride*left_block[1]]; - }else{ - *(uint32_t*)h->mvd_cache [list][scan8[0] - 1 + 0*8]= - *(uint32_t*)h->mvd_cache [list][scan8[0] - 1 + 1*8]= 0; - } - if(USES_LIST(left_type[1], list)){ - const int b_xy= h->mb2b_xy[left_xy[1]] + 3; - *(uint32_t*)h->mvd_cache[list][scan8[0] - 1 + 2*8]= *(uint32_t*)h->mvd_table[list][b_xy + h->b_stride*left_block[2]]; - *(uint32_t*)h->mvd_cache[list][scan8[0] - 1 + 3*8]= *(uint32_t*)h->mvd_table[list][b_xy + h->b_stride*left_block[3]]; - }else{ - *(uint32_t*)h->mvd_cache [list][scan8[0] - 1 + 2*8]= - *(uint32_t*)h->mvd_cache [list][scan8[0] - 1 + 3*8]= 0; - } - *(uint32_t*)h->mvd_cache [list][scan8[5 ]+1]= - *(uint32_t*)h->mvd_cache [list][scan8[7 ]+1]= - *(uint32_t*)h->mvd_cache [list][scan8[13]+1]= //FIXME remove past 3 (init somewhere else) - *(uint32_t*)h->mvd_cache [list][scan8[4 ]]= - *(uint32_t*)h->mvd_cache [list][scan8[12]]= 0; - - if(h->slice_type_nos == FF_B_TYPE){ - fill_rectangle(&h->direct_cache[scan8[0]], 4, 4, 8, 0, 1); - - if(IS_DIRECT(top_type)){ - *(uint32_t*)&h->direct_cache[scan8[0] - 1*8]= 0x01010101; - }else if(IS_8X8(top_type)){ - int b8_xy = h->mb2b8_xy[top_xy] + h->b8_stride; - h->direct_cache[scan8[0] + 0 - 1*8]= h->direct_table[b8_xy]; - h->direct_cache[scan8[0] + 2 - 1*8]= h->direct_table[b8_xy + 1]; - }else{ - *(uint32_t*)&h->direct_cache[scan8[0] - 1*8]= 0; - } - - if(IS_DIRECT(left_type[0])) - h->direct_cache[scan8[0] - 1 + 0*8]= 1; - else if(IS_8X8(left_type[0])) - h->direct_cache[scan8[0] - 1 + 0*8]= h->direct_table[h->mb2b8_xy[left_xy[0]] + 1 + h->b8_stride*(left_block[0]>>1)]; - else - h->direct_cache[scan8[0] - 1 + 0*8]= 0; - - if(IS_DIRECT(left_type[1])) - h->direct_cache[scan8[0] - 1 + 2*8]= 1; - else if(IS_8X8(left_type[1])) - h->direct_cache[scan8[0] - 1 + 2*8]= h->direct_table[h->mb2b8_xy[left_xy[1]] + 1 + h->b8_stride*(left_block[2]>>1)]; - else - h->direct_cache[scan8[0] - 1 + 2*8]= 0; - } - } - - 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[0])\ - MAP_F2F(scan8[0] - 1 + 1*8, left_type[0])\ - MAP_F2F(scan8[0] - 1 + 2*8, left_type[1])\ - MAP_F2F(scan8[0] - 1 + 3*8, left_type[1]) - 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] /= 2;\ - } - 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 - } - } - } - } -#endif - - h->neighbor_transform_size= !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[0]); -} - -static inline void write_back_intra_pred_mode(H264Context *h){ - const int mb_xy= h->mb_xy; - - h->intra4x4_pred_mode[mb_xy][0]= h->intra4x4_pred_mode_cache[7+8*1]; - h->intra4x4_pred_mode[mb_xy][1]= h->intra4x4_pred_mode_cache[7+8*2]; - h->intra4x4_pred_mode[mb_xy][2]= h->intra4x4_pred_mode_cache[7+8*3]; - h->intra4x4_pred_mode[mb_xy][3]= h->intra4x4_pred_mode_cache[7+8*4]; - h->intra4x4_pred_mode[mb_xy][4]= h->intra4x4_pred_mode_cache[4+8*4]; - h->intra4x4_pred_mode[mb_xy][5]= h->intra4x4_pred_mode_cache[5+8*4]; - h->intra4x4_pred_mode[mb_xy][6]= h->intra4x4_pred_mode_cache[6+8*4]; + AV_COPY32(mode, h->intra4x4_pred_mode_cache + 4 + 8*4); + mode[4]= h->intra4x4_pred_mode_cache[7+8*3]; + mode[5]= h->intra4x4_pred_mode_cache[7+8*2]; + mode[6]= h->intra4x4_pred_mode_cache[7+8*1]; } /** * checks if the top & left blocks are available if needed & changes the dc mode so it only uses the available blocks. */ -static inline int check_intra4x4_pred_mode(H264Context *h){ +int ff_h264_check_intra4x4_pred_mode(H264Context *h){ MpegEncContext * const s = &h->s; static const int8_t top [12]= {-1, 0,LEFT_DC_PRED,-1,-1,-1,-1,-1, 0}; static const int8_t left[12]= { 0,-1, TOP_DC_PRED, 0,-1,-1,-1, 0,-1,DC_128_PRED}; @@ -595,12 +97,12 @@ static inline int check_intra4x4_pred_mode(H264Context *h){ } return 0; -} //FIXME cleanup like next +} //FIXME cleanup like ff_h264_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. */ -static inline int check_intra_pred_mode(H264Context *h, int mode){ +int ff_h264_check_intra_pred_mode(H264Context *h, int mode){ 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}; @@ -632,736 +134,6 @@ static inline int check_intra_pred_mode(H264Context *h, int mode){ return mode; } -/** - * gets the predicted intra4x4 prediction mode. - */ -static inline int pred_intra_mode(H264Context *h, int n){ - const int index8= scan8[n]; - const int left= h->intra4x4_pred_mode_cache[index8 - 1]; - const int top = h->intra4x4_pred_mode_cache[index8 - 8]; - const int min= FFMIN(left, top); - - tprintf(h->s.avctx, "mode:%d %d min:%d\n", left ,top, min); - - if(min<0) return DC_PRED; - else return min; -} - -static inline void write_back_non_zero_count(H264Context *h){ - const int mb_xy= h->mb_xy; - - h->non_zero_count[mb_xy][0]= h->non_zero_count_cache[7+8*1]; - h->non_zero_count[mb_xy][1]= h->non_zero_count_cache[7+8*2]; - h->non_zero_count[mb_xy][2]= h->non_zero_count_cache[7+8*3]; - h->non_zero_count[mb_xy][3]= h->non_zero_count_cache[7+8*4]; - h->non_zero_count[mb_xy][4]= h->non_zero_count_cache[4+8*4]; - h->non_zero_count[mb_xy][5]= h->non_zero_count_cache[5+8*4]; - h->non_zero_count[mb_xy][6]= h->non_zero_count_cache[6+8*4]; - - h->non_zero_count[mb_xy][9]= h->non_zero_count_cache[1+8*2]; - h->non_zero_count[mb_xy][8]= h->non_zero_count_cache[2+8*2]; - h->non_zero_count[mb_xy][7]= h->non_zero_count_cache[2+8*1]; - - h->non_zero_count[mb_xy][12]=h->non_zero_count_cache[1+8*5]; - h->non_zero_count[mb_xy][11]=h->non_zero_count_cache[2+8*5]; - h->non_zero_count[mb_xy][10]=h->non_zero_count_cache[2+8*4]; -} - -/** - * gets the predicted number of non-zero coefficients. - * @param n block index - */ -static inline int pred_non_zero_count(H264Context *h, int n){ - const int index8= scan8[n]; - const int left= h->non_zero_count_cache[index8 - 1]; - const int top = h->non_zero_count_cache[index8 - 8]; - int i= left + top; - - if(i<64) i= (i+1)>>1; - - tprintf(h->s.avctx, "pred_nnz L%X T%X n%d s%d P%X\n", left, top, n, scan8[n], i&31); - - return i&31; -} - -static 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; - - /* there is no consistent mapping of mvs to neighboring locations that will - * make mbaff happy, so we can't move all this logic to fill_caches */ - if(FRAME_MBAFF){ - const uint32_t *mb_types = s->current_picture_ptr->mb_type; - const int16_t *mv; - *(uint32_t*)h->mv_cache[list][scan8[0]-2] = 0; - *C = h->mv_cache[list][scan8[0]-2]; - - if(!MB_FIELD - && (s->mb_y&1) && i < scan8[0]+8 && topright_ref != PART_NOT_AVAILABLE){ - int topright_xy = s->mb_x + (s->mb_y-1)*s->mb_stride + (i == scan8[0]+3); - if(IS_INTERLACED(mb_types[topright_xy])){ -#define SET_DIAG_MV(MV_OP, REF_OP, X4, Y4)\ - const int x4 = X4, y4 = Y4;\ - const int mb_type = mb_types[(x4>>2)+(y4>>2)*s->mb_stride];\ - if(!USES_LIST(mb_type,list))\ - return LIST_NOT_USED;\ - mv = s->current_picture_ptr->motion_val[list][x4 + 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][(x4>>1) + (y4>>1)*h->b8_stride] REF_OP; - - SET_DIAG_MV(*2, >>1, s->mb_x*4+(i&7)-4+part_width, s->mb_y*4-1); - } - } - if(topright_ref == PART_NOT_AVAILABLE - && ((s->mb_y&1) || i >= scan8[0]+8) && (i&7)==4 - && h->ref_cache[list][scan8[0]-1] != PART_NOT_AVAILABLE){ - if(!MB_FIELD - && IS_INTERLACED(mb_types[h->left_mb_xy[0]])){ - SET_DIAG_MV(*2, >>1, s->mb_x*4-1, (s->mb_y|1)*4+(s->mb_y&1)*2+(i>>4)-1); - } - if(MB_FIELD - && !IS_INTERLACED(mb_types[h->left_mb_xy[0]]) - && i >= scan8[0]+8){ - // left shift will turn LIST_NOT_USED into PART_NOT_AVAILABLE, but that's OK. - SET_DIAG_MV(/2, <<1, s->mb_x*4-1, (s->mb_y&~1)*4 - 1 + ((i-scan8[0])>>3)*2); - } - } -#undef SET_DIAG_MV - } - - if(topright_ref != PART_NOT_AVAILABLE){ - *C= h->mv_cache[list][ i - 8 + part_width ]; - return topright_ref; - }else{ - tprintf(s->avctx, "topright MV not available\n"); - - *C= h->mv_cache[list][ i - 8 - 1 ]; - return h->ref_cache[list][ i - 8 - 1 ]; - } -} - -/** - * gets the predicted MV. - * @param n the block index - * @param part_width the width of the partition (4, 8,16) -> (1, 2, 4) - * @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){ - 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 ]; - const int16_t * const A= h->mv_cache[list][ index8 - 1 ]; - const int16_t * const B= h->mv_cache[list][ index8 - 8 ]; - const int16_t * C; - int diagonal_ref, match_count; - - assert(part_width==1 || part_width==2 || part_width==4); - -/* mv_cache - B . . A T T T T - U . . L . . , . - U . . L . . . . - U . . L . . , . - . . . L . . . . -*/ - - diagonal_ref= fetch_diagonal_mv(h, &C, index8, list, part_width); - match_count= (diagonal_ref==ref) + (top_ref==ref) + (left_ref==ref); - tprintf(h->s.avctx, "pred_motion match_count=%d\n", match_count); - if(match_count > 1){ //most common - *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==ref){ - *mx= A[0]; - *my= A[1]; - }else if(top_ref==ref){ - *mx= B[0]; - *my= B[1]; - }else{ - *mx= C[0]; - *my= C[1]; - } - }else{ - if(top_ref == PART_NOT_AVAILABLE && diagonal_ref == PART_NOT_AVAILABLE && left_ref != PART_NOT_AVAILABLE){ - *mx= A[0]; - *my= A[1]; - }else{ - *mx= mid_pred(A[0], B[0], C[0]); - *my= mid_pred(A[1], B[1], C[1]); - } - } - - tprintf(h->s.avctx, "pred_motion (%2d %2d %2d) (%2d %2d %2d) (%2d %2d %2d) -> (%2d %2d %2d) at %2d %2d %d list %d\n", top_ref, B[0], B[1], diagonal_ref, C[0], C[1], left_ref, A[0], A[1], ref, *mx, *my, h->s.mb_x, h->s.mb_y, n, list); -} - -/** - * gets the directionally predicted 16x8 MV. - * @param n the block index - * @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){ - 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 ]; - - tprintf(h->s.avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n", top_ref, B[0], B[1], h->s.mb_x, h->s.mb_y, n, list); - - if(top_ref == ref){ - *mx= B[0]; - *my= B[1]; - return; - } - }else{ - const int left_ref= h->ref_cache[list][ scan8[8] - 1 ]; - const int16_t * const A= h->mv_cache[list][ scan8[8] - 1 ]; - - tprintf(h->s.avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n", left_ref, A[0], A[1], h->s.mb_x, h->s.mb_y, n, list); - - if(left_ref == ref){ - *mx= A[0]; - *my= A[1]; - return; - } - } - - //RARE - pred_motion(h, n, 4, list, ref, mx, my); -} - -/** - * gets the directionally predicted 8x16 MV. - * @param n the block index - * @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){ - 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 ]; - - tprintf(h->s.avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n", left_ref, A[0], A[1], h->s.mb_x, h->s.mb_y, n, list); - - if(left_ref == ref){ - *mx= A[0]; - *my= A[1]; - return; - } - }else{ - const int16_t * C; - int diagonal_ref; - - diagonal_ref= fetch_diagonal_mv(h, &C, scan8[4], list, 2); - - tprintf(h->s.avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n", diagonal_ref, C[0], C[1], h->s.mb_x, h->s.mb_y, n, list); - - if(diagonal_ref == ref){ - *mx= C[0]; - *my= C[1]; - return; - } - } - - //RARE - 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 ]; - - 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(top_ref == PART_NOT_AVAILABLE || left_ref == PART_NOT_AVAILABLE - || !( top_ref | *(uint32_t*)h->mv_cache[0][ scan8[0] - 8 ]) - || !(left_ref | *(uint32_t*)h->mv_cache[0][ scan8[0] - 1 ])){ - - *mx = *my = 0; - return; - } - - pred_motion(h, 0, 4, 0, 0, mx, my); - - return; -} - -static int get_scale_factor(H264Context * const h, int poc, int poc1, int i){ - int poc0 = h->ref_list[0][i].poc; - int td = av_clip(poc1 - poc0, -128, 127); - if(td == 0 || h->ref_list[0][i].long_ref){ - return 256; - }else{ - int tb = av_clip(poc - poc0, -128, 127); - int tx = (16384 + (FFABS(td) >> 1)) / td; - return av_clip((tb*tx + 32) >> 6, -1024, 1023); - } -} - -static inline void direct_dist_scale_factor(H264Context * const h){ - MpegEncContext * const s = &h->s; - const int poc = h->s.current_picture_ptr->field_poc[ s->picture_structure == PICT_BOTTOM_FIELD ]; - const int poc1 = h->ref_list[1][0].poc; - int i, field; - for(field=0; field<2; field++){ - const int poc = h->s.current_picture_ptr->field_poc[field]; - const int poc1 = h->ref_list[1][0].field_poc[field]; - for(i=0; i < 2*h->ref_count[0]; i++) - h->dist_scale_factor_field[field][i^field] = get_scale_factor(h, poc, poc1, i+16); - } - - for(i=0; iref_count[0]; i++){ - h->dist_scale_factor[i] = get_scale_factor(h, poc, poc1, i); - } -} - -static void fill_colmap(H264Context *h, int map[2][16+32], int list, int field, int colfield, int mbafi){ - MpegEncContext * const s = &h->s; - Picture * const ref1 = &h->ref_list[1][0]; - int j, old_ref, rfield; - int start= mbafi ? 16 : 0; - int end = mbafi ? 16+2*h->ref_count[list] : h->ref_count[list]; - int interl= mbafi || s->picture_structure != PICT_FRAME; - - /* bogus; fills in for missing frames */ - memset(map[list], 0, sizeof(map[list])); - - for(rfield=0; rfield<2; rfield++){ - for(old_ref=0; old_refref_count[colfield][list]; old_ref++){ - int poc = ref1->ref_poc[colfield][list][old_ref]; - - if (!interl) - poc |= 3; - else if( interl && (poc&3) == 3) //FIXME store all MBAFF references so this isnt needed - poc= (poc&~3) + rfield + 1; - - for(j=start; jref_list[list][j].frame_num + (h->ref_list[list][j].reference&3) == poc){ - int cur_ref= mbafi ? (j-16)^field : j; - map[list][2*old_ref + (rfield^field) + 16] = cur_ref; - if(rfield == field) - map[list][old_ref] = cur_ref; - break; - } - } - } - } -} - -static inline void direct_ref_list_init(H264Context * const h){ - MpegEncContext * const s = &h->s; - Picture * const ref1 = &h->ref_list[1][0]; - Picture * const cur = s->current_picture_ptr; - int list, j, field; - int sidx= (s->picture_structure&1)^1; - int ref1sidx= (ref1->reference&1)^1; - - for(list=0; list<2; list++){ - cur->ref_count[sidx][list] = h->ref_count[list]; - for(j=0; jref_count[list]; j++) - cur->ref_poc[sidx][list][j] = 4*h->ref_list[list][j].frame_num + (h->ref_list[list][j].reference&3); - } - - if(s->picture_structure == PICT_FRAME){ - memcpy(cur->ref_count[1], cur->ref_count[0], sizeof(cur->ref_count[0])); - memcpy(cur->ref_poc [1], cur->ref_poc [0], sizeof(cur->ref_poc [0])); - } - - cur->mbaff= FRAME_MBAFF; - - if(cur->pict_type != FF_B_TYPE || h->direct_spatial_mv_pred) - return; - - for(list=0; list<2; list++){ - fill_colmap(h, h->map_col_to_list0, list, sidx, ref1sidx, 0); - for(field=0; field<2; field++) - fill_colmap(h, h->map_col_to_list0_field[field], list, field, field, 1); - } -} - -static inline void pred_direct_motion(H264Context * const h, int *mb_type){ - MpegEncContext * const s = &h->s; - int b8_stride = h->b8_stride; - int b4_stride = h->b_stride; - int mb_xy = h->mb_xy; - int mb_type_col[2]; - const int16_t (*l1mv0)[2], (*l1mv1)[2]; - const int8_t *l1ref0, *l1ref1; - const int is_b8x8 = IS_8X8(*mb_type); - unsigned int sub_mb_type; - int i8, i4; - - assert(h->ref_list[1][0].reference&3); - -#define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16|MB_TYPE_INTRA4x4|MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM) - - 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 - int cur_poc = s->current_picture_ptr->poc; - int *col_poc = h->ref_list[1]->field_poc; - int col_parity = FFABS(col_poc[0] - cur_poc) >= FFABS(col_poc[1] - cur_poc); - mb_xy= s->mb_x + ((s->mb_y&~1) + col_parity)*s->mb_stride; - b8_stride = 0; - }else if(!(s->picture_structure & h->ref_list[1][0].reference) && !h->ref_list[1][0].mbaff){// FL -> FL & differ parity - int fieldoff= 2*(h->ref_list[1][0].reference)-3; - mb_xy += s->mb_stride*fieldoff; - } - goto single_col; - }else{ // AFL/AFR/FR/FL -> AFR/FR - if(IS_INTERLACED(*mb_type)){ // AFL /FL -> AFR/FR - 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]; - b8_stride *= 3; - b4_stride *= 6; - //FIXME IS_8X8(mb_type_col[0]) && !h->sps.direct_8x8_inference_flag - if( (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA) - && (mb_type_col[1] & MB_TYPE_16x16_OR_INTRA) - && !is_b8x8){ - sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */ - *mb_type |= MB_TYPE_16x8 |MB_TYPE_L0L1|MB_TYPE_DIRECT2; /* B_16x8 */ - }else{ - sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */ - *mb_type |= MB_TYPE_8x8|MB_TYPE_L0L1; - } - }else{ // AFR/FR -> AFR/FR -single_col: - mb_type_col[0] = - mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy]; - if(IS_8X8(mb_type_col[0]) && !h->sps.direct_8x8_inference_flag){ - /* FIXME save sub mb types from previous frames (or derive from MVs) - * so we know exactly what block size to use */ - sub_mb_type = MB_TYPE_8x8|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_4x4 */ - *mb_type |= MB_TYPE_8x8|MB_TYPE_L0L1; - }else if(!is_b8x8 && (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)){ - sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */ - *mb_type |= MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_16x16 */ - }else{ - sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */ - *mb_type |= MB_TYPE_8x8|MB_TYPE_L0L1; - } - } - } - - 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][h->mb2b8_xy[mb_xy]]; - l1ref1 = &h->ref_list[1][0].ref_index [1][h->mb2b8_xy[mb_xy]]; - if(!b8_stride){ - if(s->mb_y&1){ - l1ref0 += h->b8_stride; - l1ref1 += h->b8_stride; - l1mv0 += 2*b4_stride; - l1mv1 += 2*b4_stride; - } - } - - if(h->direct_spatial_mv_pred){ - int ref[2]; - int mv[2][2]; - int list; - - /* FIXME interlacing + spatial direct uses wrong colocated block positions */ - - /* ref = min(neighbors) */ - for(list=0; list<2; list++){ - int refa = h->ref_cache[list][scan8[0] - 1]; - int refb = h->ref_cache[list][scan8[0] - 8]; - int refc = h->ref_cache[list][scan8[0] - 8 + 4]; - if(refc == PART_NOT_AVAILABLE) - refc = h->ref_cache[list][scan8[0] - 8 - 1]; - ref[list] = FFMIN3((unsigned)refa, (unsigned)refb, (unsigned)refc); - if(ref[list] < 0) - ref[list] = -1; - } - - if(ref[0] < 0 && ref[1] < 0){ - ref[0] = ref[1] = 0; - mv[0][0] = mv[0][1] = - mv[1][0] = mv[1][1] = 0; - }else{ - for(list=0; list<2; list++){ - if(ref[list] >= 0) - pred_motion(h, 0, 4, list, ref[list], &mv[list][0], &mv[list][1]); - else - mv[list][0] = mv[list][1] = 0; - } - } - - if(ref[1] < 0){ - if(!is_b8x8) - *mb_type &= ~MB_TYPE_L1; - sub_mb_type &= ~MB_TYPE_L1; - }else if(ref[0] < 0){ - if(!is_b8x8) - *mb_type &= ~MB_TYPE_L0; - sub_mb_type &= ~MB_TYPE_L0; - } - - if(IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])){ - for(i8=0; i8<4; i8++){ - int x8 = i8&1; - int y8 = i8>>1; - int xy8 = x8+y8*b8_stride; - int xy4 = 3*x8+y8*b4_stride; - int a=0, b=0; - - if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8])) - continue; - h->sub_mb_type[i8] = sub_mb_type; - - fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[0], 1); - fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[1], 1); - if(!IS_INTRA(mb_type_col[y8]) - && ( (l1ref0[xy8] == 0 && FFABS(l1mv0[xy4][0]) <= 1 && FFABS(l1mv0[xy4][1]) <= 1) - || (l1ref0[xy8] < 0 && l1ref1[xy8] == 0 && FFABS(l1mv1[xy4][0]) <= 1 && FFABS(l1mv1[xy4][1]) <= 1))){ - if(ref[0] > 0) - a= pack16to32(mv[0][0],mv[0][1]); - if(ref[1] > 0) - b= pack16to32(mv[1][0],mv[1][1]); - }else{ - a= pack16to32(mv[0][0],mv[0][1]); - b= pack16to32(mv[1][0],mv[1][1]); - } - fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, a, 4); - fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, b, 4); - } - }else if(IS_16X16(*mb_type)){ - int a=0, b=0; - - fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1); - fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1); - if(!IS_INTRA(mb_type_col[0]) - && ( (l1ref0[0] == 0 && FFABS(l1mv0[0][0]) <= 1 && FFABS(l1mv0[0][1]) <= 1) - || (l1ref0[0] < 0 && l1ref1[0] == 0 && FFABS(l1mv1[0][0]) <= 1 && FFABS(l1mv1[0][1]) <= 1 - && (h->x264_build>33 || !h->x264_build)))){ - if(ref[0] > 0) - a= pack16to32(mv[0][0],mv[0][1]); - if(ref[1] > 0) - b= pack16to32(mv[1][0],mv[1][1]); - }else{ - a= pack16to32(mv[0][0],mv[0][1]); - b= pack16to32(mv[1][0],mv[1][1]); - } - fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, a, 4); - fill_rectangle(&h->mv_cache[1][scan8[0]], 4, 4, 8, b, 4); - }else{ - for(i8=0; i8<4; i8++){ - const int x8 = i8&1; - const int y8 = i8>>1; - - if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8])) - continue; - h->sub_mb_type[i8] = sub_mb_type; - - fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, pack16to32(mv[0][0],mv[0][1]), 4); - fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, pack16to32(mv[1][0],mv[1][1]), 4); - fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[0], 1); - fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[1], 1); - - /* col_zero_flag */ - if(!IS_INTRA(mb_type_col[0]) && ( l1ref0[x8 + y8*b8_stride] == 0 - || (l1ref0[x8 + y8*b8_stride] < 0 && l1ref1[x8 + y8*b8_stride] == 0 - && (h->x264_build>33 || !h->x264_build)))){ - const int16_t (*l1mv)[2]= l1ref0[x8 + y8*b8_stride] == 0 ? l1mv0 : l1mv1; - if(IS_SUB_8X8(sub_mb_type)){ - const int16_t *mv_col = l1mv[x8*3 + y8*3*b4_stride]; - if(FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1){ - if(ref[0] == 0) - fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4); - if(ref[1] == 0) - fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4); - } - }else - for(i4=0; i4<4; i4++){ - const int16_t *mv_col = l1mv[x8*2 + (i4&1) + (y8*2 + (i4>>1))*b4_stride]; - if(FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1){ - if(ref[0] == 0) - *(uint32_t*)h->mv_cache[0][scan8[i8*4+i4]] = 0; - if(ref[1] == 0) - *(uint32_t*)h->mv_cache[1][scan8[i8*4+i4]] = 0; - } - } - } - } - } - }else{ /* direct temporal mv pred */ - const int *map_col_to_list0[2] = {h->map_col_to_list0[0], h->map_col_to_list0[1]}; - const int *dist_scale_factor = h->dist_scale_factor; - int ref_offset= 0; - - if(FRAME_MBAFF && IS_INTERLACED(*mb_type)){ - map_col_to_list0[0] = h->map_col_to_list0_field[s->mb_y&1][0]; - map_col_to_list0[1] = h->map_col_to_list0_field[s->mb_y&1][1]; - dist_scale_factor =h->dist_scale_factor_field[s->mb_y&1]; - } - if(h->ref_list[1][0].mbaff && IS_INTERLACED(mb_type_col[0])) - ref_offset += 16; - - if(IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])){ - /* FIXME assumes direct_8x8_inference == 1 */ - int y_shift = 2*!IS_INTERLACED(*mb_type); - - for(i8=0; i8<4; i8++){ - const int x8 = i8&1; - const int y8 = i8>>1; - int ref0, scale; - const int16_t (*l1mv)[2]= l1mv0; - - if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8])) - continue; - h->sub_mb_type[i8] = sub_mb_type; - - fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, 0, 1); - if(IS_INTRA(mb_type_col[y8])){ - fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, 0, 1); - fill_rectangle(&h-> mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4); - fill_rectangle(&h-> mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4); - continue; - } - - ref0 = l1ref0[x8 + y8*b8_stride]; - if(ref0 >= 0) - ref0 = map_col_to_list0[0][ref0 + ref_offset]; - else{ - ref0 = map_col_to_list0[1][l1ref1[x8 + y8*b8_stride] + ref_offset]; - l1mv= l1mv1; - } - scale = dist_scale_factor[ref0]; - fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, ref0, 1); - - { - const int16_t *mv_col = l1mv[x8*3 + y8*b4_stride]; - int my_col = (mv_col[1]<> 8; - int my = (scale * my_col + 128) >> 8; - fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, pack16to32(mx,my), 4); - fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, pack16to32(mx-mv_col[0],my-my_col), 4); - } - } - return; - } - - /* one-to-one mv scaling */ - - if(IS_16X16(*mb_type)){ - int ref, mv0, mv1; - - fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, 0, 1); - if(IS_INTRA(mb_type_col[0])){ - ref=mv0=mv1=0; - }else{ - const int ref0 = l1ref0[0] >= 0 ? map_col_to_list0[0][l1ref0[0] + ref_offset] - : map_col_to_list0[1][l1ref1[0] + ref_offset]; - const int scale = dist_scale_factor[ref0]; - const int16_t *mv_col = l1ref0[0] >= 0 ? l1mv0[0] : l1mv1[0]; - int mv_l0[2]; - mv_l0[0] = (scale * mv_col[0] + 128) >> 8; - mv_l0[1] = (scale * mv_col[1] + 128) >> 8; - ref= ref0; - mv0= pack16to32(mv_l0[0],mv_l0[1]); - mv1= pack16to32(mv_l0[0]-mv_col[0],mv_l0[1]-mv_col[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, mv0, 4); - fill_rectangle(&h-> mv_cache[1][scan8[0]], 4, 4, 8, mv1, 4); - }else{ - for(i8=0; i8<4; i8++){ - const int x8 = i8&1; - const int y8 = i8>>1; - int ref0, scale; - const int16_t (*l1mv)[2]= l1mv0; - - if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8])) - continue; - h->sub_mb_type[i8] = sub_mb_type; - fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, 0, 1); - if(IS_INTRA(mb_type_col[0])){ - fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, 0, 1); - fill_rectangle(&h-> mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4); - fill_rectangle(&h-> mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4); - continue; - } - - ref0 = l1ref0[x8 + y8*b8_stride] + ref_offset; - if(ref0 >= 0) - ref0 = map_col_to_list0[0][ref0]; - else{ - ref0 = map_col_to_list0[1][l1ref1[x8 + y8*b8_stride] + ref_offset]; - l1mv= l1mv1; - } - scale = dist_scale_factor[ref0]; - - fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, ref0, 1); - if(IS_SUB_8X8(sub_mb_type)){ - const int16_t *mv_col = l1mv[x8*3 + y8*3*b4_stride]; - int mx = (scale * mv_col[0] + 128) >> 8; - int my = (scale * mv_col[1] + 128) >> 8; - fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, pack16to32(mx,my), 4); - fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, pack16to32(mx-mv_col[0],my-mv_col[1]), 4); - }else - for(i4=0; i4<4; i4++){ - const int16_t *mv_col = l1mv[x8*2 + (i4&1) + (y8*2 + (i4>>1))*b4_stride]; - int16_t *mv_l0 = h->mv_cache[0][scan8[i8*4+i4]]; - mv_l0[0] = (scale * mv_col[0] + 128) >> 8; - mv_l0[1] = (scale * mv_col[1] + 128) >> 8; - *(uint32_t*)h->mv_cache[1][scan8[i8*4+i4]] = - pack16to32(mv_l0[0]-mv_col[0],mv_l0[1]-mv_col[1]); - } - } - } - } -} - -static inline void write_back_motion(H264Context *h, int mb_type){ - MpegEncContext * const s = &h->s; - const int b_xy = 4*s->mb_x + 4*s->mb_y*h->b_stride; - const int b8_xy= 2*s->mb_x + 2*s->mb_y*h->b8_stride; - int list; - - if(!USES_LIST(mb_type, 0)) - fill_rectangle(&s->current_picture.ref_index[0][b8_xy], 2, 2, h->b8_stride, (uint8_t)LIST_NOT_USED, 1); - - for(list=0; listlist_count; list++){ - int y; - if(!USES_LIST(mb_type, list)) - continue; - - for(y=0; y<4; y++){ - *(uint64_t*)s->current_picture.motion_val[list][b_xy + 0 + y*h->b_stride]= *(uint64_t*)h->mv_cache[list][scan8[0]+0 + 8*y]; - *(uint64_t*)s->current_picture.motion_val[list][b_xy + 2 + y*h->b_stride]= *(uint64_t*)h->mv_cache[list][scan8[0]+2 + 8*y]; - } - if( h->pps.cabac ) { - if(IS_SKIP(mb_type)) - fill_rectangle(h->mvd_table[list][b_xy], 4, 4, h->b_stride, 0, 4); - else - for(y=0; y<4; y++){ - *(uint64_t*)h->mvd_table[list][b_xy + 0 + y*h->b_stride]= *(uint64_t*)h->mvd_cache[list][scan8[0]+0 + 8*y]; - *(uint64_t*)h->mvd_table[list][b_xy + 2 + y*h->b_stride]= *(uint64_t*)h->mvd_cache[list][scan8[0]+2 + 8*y]; - } - } - - { - int8_t *ref_index = &s->current_picture.ref_index[list][b8_xy]; - ref_index[0+0*h->b8_stride]= h->ref_cache[list][scan8[0]]; - ref_index[1+0*h->b8_stride]= h->ref_cache[list][scan8[4]]; - ref_index[0+1*h->b8_stride]= h->ref_cache[list][scan8[8]]; - ref_index[1+1*h->b8_stride]= h->ref_cache[list][scan8[12]]; - } - } - - if(h->slice_type_nos == FF_B_TYPE && h->pps.cabac){ - if(IS_8X8(mb_type)){ - uint8_t *direct_table = &h->direct_table[b8_xy]; - direct_table[1+0*h->b8_stride] = IS_DIRECT(h->sub_mb_type[1]) ? 1 : 0; - direct_table[0+1*h->b8_stride] = IS_DIRECT(h->sub_mb_type[2]) ? 1 : 0; - direct_table[1+1*h->b8_stride] = IS_DIRECT(h->sub_mb_type[3]) ? 1 : 0; - } - } -} - 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; @@ -1381,11 +153,11 @@ const uint8_t *ff_h264_decode_nal(H264Context *h, const uint8_t *src, int *dst_l # if HAVE_FAST_64BIT # define RS 7 for(i=0; i+10 && !src[i]) i--; @@ -1592,13 +364,6 @@ static void chroma_dc_dct_c(DCTELEM *block){ } #endif -/** - * gets the chroma qp. - */ -static inline int get_chroma_qp(H264Context *h, int t, int qscale){ - return h->pps.chroma_qp_table[t][qscale]; -} - 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, @@ -1723,21 +488,21 @@ static inline void mc_part_weighted(H264Context *h, int n, int square, int chrom x_offset, y_offset, qpix_put, chroma_put); if(h->use_weight == 2){ - int weight0 = h->implicit_weight[refn0][refn1]; + 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); }else{ luma_weight_avg(dest_y, tmp_y, h->mb_linesize, h->luma_log2_weight_denom, - h->luma_weight[0][refn0], h->luma_weight[1][refn1], - h->luma_offset[0][refn0] + h->luma_offset[1][refn1]); + 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, - h->chroma_weight[0][refn0][0], h->chroma_weight[1][refn1][0], - h->chroma_offset[0][refn0][0] + h->chroma_offset[1][refn1][0]); + 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, - h->chroma_weight[0][refn0][1], h->chroma_weight[1][refn1][1], - h->chroma_offset[0][refn0][1] + h->chroma_offset[1][refn1][1]); + 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]); } }else{ int list = list1 ? 1 : 0; @@ -1748,12 +513,12 @@ static inline void mc_part_weighted(H264Context *h, int n, int square, int chrom qpix_put, chroma_put); luma_weight_op(dest_y, h->mb_linesize, h->luma_log2_weight_denom, - h->luma_weight[list][refn], h->luma_offset[list][refn]); + 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, - h->chroma_weight[list][refn][0], h->chroma_offset[list][refn][0]); + 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, - h->chroma_weight[list][refn][1], h->chroma_offset[list][refn][1]); + h->chroma_weight[refn][list][1][0], h->chroma_weight[refn][list][1][1]); } } } @@ -1766,7 +531,7 @@ static inline void mc_part(H264Context *h, int n, int square, int chroma_height, h264_weight_func *weight_op, h264_biweight_func *weight_avg, int list0, int list1){ if((h->use_weight==2 && list0 && list1 - && (h->implicit_weight[ h->ref_cache[0][scan8[n]] ][ h->ref_cache[1][scan8[n]] ] != 32)) + && (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, x_offset, y_offset, qpix_put, chroma_put, @@ -1807,7 +572,7 @@ static void hl_motion(H264Context *h, uint8_t *dest_y, uint8_t *dest_cb, uint8_t if(IS_16X16(mb_type)){ mc_part(h, 0, 1, 8, 0, dest_y, dest_cb, dest_cr, 0, 0, qpix_put[0], chroma_put[0], qpix_avg[0], chroma_avg[0], - &weight_op[0], &weight_avg[0], + weight_op, weight_avg, IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1)); }else if(IS_16X8(mb_type)){ mc_part(h, 0, 0, 4, 8, dest_y, dest_cb, dest_cr, 0, 0, @@ -1879,101 +644,6 @@ static void hl_motion(H264Context *h, uint8_t *dest_y, uint8_t *dest_cb, uint8_t prefetch_motion(h, 1); } -static av_cold void init_cavlc_level_tab(void){ - int suffix_length, mask; - unsigned int i; - - for(suffix_length=0; suffix_length<7; suffix_length++){ - for(i=0; i<(1<>(LEVEL_TAB_BITS-prefix-1-suffix_length)) - (1<>1) ^ mask) - mask; - if(prefix + 1 + suffix_length <= LEVEL_TAB_BITS){ - 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){ - cavlc_level_tab[suffix_length][i][0]= prefix+100; - cavlc_level_tab[suffix_length][i][1]= prefix + 1; - }else{ - cavlc_level_tab[suffix_length][i][0]= LEVEL_TAB_BITS+100; - cavlc_level_tab[suffix_length][i][1]= LEVEL_TAB_BITS; - } - } - } -} - -static av_cold void decode_init_vlc(void){ - static int done = 0; - - if (!done) { - int i; - int offset; - done = 1; - - chroma_dc_coeff_token_vlc.table = chroma_dc_coeff_token_vlc_table; - chroma_dc_coeff_token_vlc.table_allocated = chroma_dc_coeff_token_vlc_table_size; - init_vlc(&chroma_dc_coeff_token_vlc, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 4*5, - &chroma_dc_coeff_token_len [0], 1, 1, - &chroma_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; - coeff_token_vlc[i].table_allocated = coeff_token_vlc_tables_size[i]; - init_vlc(&coeff_token_vlc[i], COEFF_TOKEN_VLC_BITS, 4*17, - &coeff_token_len [i][0], 1, 1, - &coeff_token_bits[i][0], 1, 1, - INIT_VLC_USE_NEW_STATIC); - offset += coeff_token_vlc_tables_size[i]; - } - /* - * This is a one time safety check to make sure that - * the packed static coeff_token_vlc table sizes - * were initialized correctly. - */ - assert(offset == FF_ARRAY_ELEMS(coeff_token_vlc_tables)); - - for(i=0; i<3; i++){ - chroma_dc_total_zeros_vlc[i].table = chroma_dc_total_zeros_vlc_tables[i]; - chroma_dc_total_zeros_vlc[i].table_allocated = chroma_dc_total_zeros_vlc_tables_size; - init_vlc(&chroma_dc_total_zeros_vlc[i], - CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 4, - &chroma_dc_total_zeros_len [i][0], 1, 1, - &chroma_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; - init_vlc(&total_zeros_vlc[i], - TOTAL_ZEROS_VLC_BITS, 16, - &total_zeros_len [i][0], 1, 1, - &total_zeros_bits[i][0], 1, 1, - INIT_VLC_USE_NEW_STATIC); - } - - for(i=0; i<6; i++){ - run_vlc[i].table = run_vlc_tables[i]; - run_vlc[i].table_allocated = run_vlc_tables_size; - init_vlc(&run_vlc[i], - RUN_VLC_BITS, 7, - &run_len [i][0], 1, 1, - &run_bits[i][0], 1, 1, - INIT_VLC_USE_NEW_STATIC); - } - run7_vlc.table = run7_vlc_table, - run7_vlc.table_allocated = run7_vlc_table_size; - init_vlc(&run7_vlc, RUN7_VLC_BITS, 16, - &run_len [6][0], 1, 1, - &run_bits[6][0], 1, 1, - INIT_VLC_USE_NEW_STATIC); - - init_cavlc_level_tab(); - } -} static void free_tables(H264Context *h){ int i; @@ -1987,9 +657,10 @@ static void free_tables(H264Context *h){ av_freep(&h->non_zero_count); av_freep(&h->slice_table_base); h->slice_table= NULL; + av_freep(&h->list_counts); av_freep(&h->mb2b_xy); - av_freep(&h->mb2b8_xy); + av_freep(&h->mb2br_xy); for(i = 0; i < MAX_THREADS; i++) { hx = h->thread_context[i]; @@ -1999,13 +670,15 @@ static void free_tables(H264Context *h){ av_freep(&hx->s.obmc_scratchpad); av_freep(&hx->rbsp_buffer[1]); av_freep(&hx->rbsp_buffer[0]); + hx->rbsp_buffer_size[0] = 0; + hx->rbsp_buffer_size[1] = 0; if (i) av_freep(&h->thread_context[i]); } } static void init_dequant8_coeff_table(H264Context *h){ int i,q,x; - const int transpose = (h->s.dsp.h264_idct8_add != ff_h264_idct8_add_c); //FIXME ugly + const int transpose = (h->h264dsp.h264_idct8_add != ff_h264_idct8_add_c); //FIXME ugly h->dequant8_coeff[0] = h->dequant8_buffer[0]; h->dequant8_coeff[1] = h->dequant8_buffer[1]; @@ -2028,7 +701,7 @@ static void init_dequant8_coeff_table(H264Context *h){ static void init_dequant4_coeff_table(H264Context *h){ int i,j,q,x; - const int transpose = (h->s.dsp.h264_idct_add != ff_h264_idct_add_c); //FIXME ugly + const int transpose = (h->h264dsp.h264_idct_add != ff_h264_idct_add_c); //FIXME ugly for(i=0; i<6; i++ ){ h->dequant4_coeff[i] = h->dequant4_buffer[i]; for(j=0; js; const int big_mb_num= s->mb_stride * (s->mb_height+1); + const int row_mb_num= 2*s->mb_stride*s->avctx->thread_count; int x,y; - CHECKED_ALLOCZ(h->intra4x4_pred_mode, big_mb_num * 8 * sizeof(uint8_t)) + FF_ALLOCZ_OR_GOTO(h->s.avctx, h->intra4x4_pred_mode, row_mb_num * 8 * sizeof(uint8_t), fail) - CHECKED_ALLOCZ(h->non_zero_count , big_mb_num * 16 * sizeof(uint8_t)) - CHECKED_ALLOCZ(h->slice_table_base , (big_mb_num+s->mb_stride) * sizeof(*h->slice_table_base)) - CHECKED_ALLOCZ(h->cbp_table, big_mb_num * sizeof(uint16_t)) + FF_ALLOCZ_OR_GOTO(h->s.avctx, h->non_zero_count , big_mb_num * 32 * sizeof(uint8_t), fail) + FF_ALLOCZ_OR_GOTO(h->s.avctx, h->slice_table_base , (big_mb_num+s->mb_stride) * sizeof(*h->slice_table_base), fail) + FF_ALLOCZ_OR_GOTO(h->s.avctx, h->cbp_table, big_mb_num * sizeof(uint16_t), fail) - CHECKED_ALLOCZ(h->chroma_pred_mode_table, big_mb_num * sizeof(uint8_t)) - CHECKED_ALLOCZ(h->mvd_table[0], 32*big_mb_num * sizeof(uint16_t)); - CHECKED_ALLOCZ(h->mvd_table[1], 32*big_mb_num * sizeof(uint16_t)); - CHECKED_ALLOCZ(h->direct_table, 32*big_mb_num * sizeof(uint8_t)); + FF_ALLOCZ_OR_GOTO(h->s.avctx, h->chroma_pred_mode_table, big_mb_num * sizeof(uint8_t), fail) + FF_ALLOCZ_OR_GOTO(h->s.avctx, h->mvd_table[0], 16*row_mb_num * sizeof(uint8_t), fail); + FF_ALLOCZ_OR_GOTO(h->s.avctx, h->mvd_table[1], 16*row_mb_num * sizeof(uint8_t), fail); + FF_ALLOCZ_OR_GOTO(h->s.avctx, h->direct_table, 4*big_mb_num * sizeof(uint8_t) , fail); + FF_ALLOCZ_OR_GOTO(h->s.avctx, h->list_counts, big_mb_num * sizeof(uint8_t), fail) memset(h->slice_table_base, -1, (big_mb_num+s->mb_stride) * sizeof(*h->slice_table_base)); h->slice_table= h->slice_table_base + s->mb_stride*2 + 1; - CHECKED_ALLOCZ(h->mb2b_xy , big_mb_num * sizeof(uint32_t)); - CHECKED_ALLOCZ(h->mb2b8_xy , big_mb_num * sizeof(uint32_t)); + FF_ALLOCZ_OR_GOTO(h->s.avctx, h->mb2b_xy , big_mb_num * sizeof(uint32_t), fail); + FF_ALLOCZ_OR_GOTO(h->s.avctx, h->mb2br_xy , big_mb_num * sizeof(uint32_t), fail); for(y=0; ymb_height; y++){ for(x=0; xmb_width; x++){ const int mb_xy= x + y*s->mb_stride; const int b_xy = 4*x + 4*y*h->b_stride; - const int b8_xy= 2*x + 2*y*h->b8_stride; h->mb2b_xy [mb_xy]= b_xy; - h->mb2b8_xy[mb_xy]= b8_xy; + h->mb2br_xy[mb_xy]= 8*(FMO ? mb_xy : (mb_xy % (2*s->mb_stride))); } } @@ -2118,17 +788,19 @@ fail: /** * Mimic alloc_tables(), but for every context thread. */ -static void clone_tables(H264Context *dst, H264Context *src){ - dst->intra4x4_pred_mode = src->intra4x4_pred_mode; +static void clone_tables(H264Context *dst, H264Context *src, int i){ + MpegEncContext * const s = &src->s; + dst->intra4x4_pred_mode = src->intra4x4_pred_mode + i*8*2*s->mb_stride; dst->non_zero_count = src->non_zero_count; dst->slice_table = src->slice_table; dst->cbp_table = src->cbp_table; dst->mb2b_xy = src->mb2b_xy; - dst->mb2b8_xy = src->mb2b8_xy; + dst->mb2br_xy = src->mb2br_xy; dst->chroma_pred_mode_table = src->chroma_pred_mode_table; - dst->mvd_table[0] = src->mvd_table[0]; - dst->mvd_table[1] = src->mvd_table[1]; + dst->mvd_table[0] = src->mvd_table[0] + i*8*2*s->mb_stride; + dst->mvd_table[1] = src->mvd_table[1] + i*8*2*s->mb_stride; dst->direct_table = src->direct_table; + dst->list_counts = src->list_counts; dst->s.obmc_scratchpad = NULL; ff_h264_pred_init(&dst->hpc, src->s.codec_id); @@ -2139,14 +811,19 @@ static void clone_tables(H264Context *dst, H264Context *src){ * Allocate buffers which are not shared amongst multiple threads. */ static int context_init(H264Context *h){ - CHECKED_ALLOCZ(h->top_borders[0], h->s.mb_width * (16+8+8) * sizeof(uint8_t)) - CHECKED_ALLOCZ(h->top_borders[1], h->s.mb_width * (16+8+8) * sizeof(uint8_t)) + FF_ALLOCZ_OR_GOTO(h->s.avctx, h->top_borders[0], h->s.mb_width * (16+8+8) * sizeof(uint8_t), fail) + FF_ALLOCZ_OR_GOTO(h->s.avctx, h->top_borders[1], h->s.mb_width * (16+8+8) * sizeof(uint8_t), fail) + + h->ref_cache[0][scan8[5 ]+1] = h->ref_cache[0][scan8[7 ]+1] = h->ref_cache[0][scan8[13]+1] = + h->ref_cache[1][scan8[5 ]+1] = h->ref_cache[1][scan8[7 ]+1] = h->ref_cache[1][scan8[13]+1] = PART_NOT_AVAILABLE; return 0; fail: return -1; // free_tables will clean up for us } +static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size); + static av_cold void common_init(H264Context *h){ MpegEncContext * const s = &h->s; @@ -2154,6 +831,7 @@ 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); ff_h264_pred_init(&h->hpc, s->codec_id); h->dequant_coeff_pps= -1; @@ -2166,19 +844,7 @@ static av_cold void common_init(H264Context *h){ memset(h->pps.scaling_matrix8, 16, 2*64*sizeof(uint8_t)); } -/** - * Reset SEI values at the beginning of the frame. - * - * @param h H.264 context. - */ -static void reset_sei(H264Context *h) { - h->sei_recovery_frame_cnt = -1; - h->sei_dpb_output_delay = 0; - h->sei_cpb_removal_delay = -1; - h->sei_buffering_period_present = 0; -} - -static av_cold int decode_init(AVCodecContext *avctx){ +av_cold int ff_h264_decode_init(AVCodecContext *avctx){ H264Context *h= avctx->priv_data; MpegEncContext * const s = &h->s; @@ -2196,37 +862,72 @@ static av_cold int decode_init(AVCodecContext *avctx){ if(!avctx->has_b_frames) s->low_delay= 1; - if(s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU) - avctx->pix_fmt= PIX_FMT_VDPAU_H264; - else - avctx->pix_fmt= avctx->get_format(avctx, avctx->codec->pix_fmts); - avctx->hwaccel = ff_find_hwaccel(avctx->codec->id, avctx->pix_fmt); avctx->chroma_sample_location = AVCHROMA_LOC_LEFT; - decode_init_vlc(); - - if(avctx->extradata_size > 0 && avctx->extradata && - *(char *)avctx->extradata == 1){ - h->is_avc = 1; - h->got_avcC = 0; - } else { - h->is_avc = 0; - } + ff_h264_decode_init_vlc(); h->thread_context[0] = h; h->outputed_poc = INT_MIN; h->prev_poc_msb= 1<<16; - reset_sei(h); + h->x264_build = -1; + ff_h264_reset_sei(h); if(avctx->codec_id == CODEC_ID_H264){ if(avctx->ticks_per_frame == 1){ s->avctx->time_base.den *=2; } avctx->ticks_per_frame = 2; } + + if(avctx->extradata_size > 0 && avctx->extradata && *(char *)avctx->extradata == 1){ + int i, cnt, nalsize; + unsigned char *p = avctx->extradata; + + h->is_avc = 1; + + if(avctx->extradata_size < 7) { + av_log(avctx, AV_LOG_ERROR, "avcC too short\n"); + return -1; + } + /* sps and pps in the avcC always have length coded with 2 bytes, + so put a fake nal_length_size = 2 while parsing them */ + h->nal_length_size = 2; + // Decode sps from avcC + cnt = *(p+5) & 0x1f; // Number of sps + p += 6; + for (i = 0; i < cnt; i++) { + nalsize = AV_RB16(p) + 2; + if(decode_nal_units(h, p, nalsize) < 0) { + av_log(avctx, AV_LOG_ERROR, "Decoding sps %d from avcC failed\n", i); + return -1; + } + p += nalsize; + } + // Decode pps from avcC + cnt = *(p++); // Number of pps + for (i = 0; i < cnt; i++) { + nalsize = AV_RB16(p) + 2; + if(decode_nal_units(h, p, nalsize) != nalsize) { + av_log(avctx, AV_LOG_ERROR, "Decoding pps %d from avcC failed\n", i); + return -1; + } + p += nalsize; + } + // Now store right nal length size, that will be use to parse all other nals + h->nal_length_size = ((*(((char*)(avctx->extradata))+4))&0x03)+1; + } else { + h->is_avc = 0; + if(decode_nal_units(h, s->avctx->extradata, s->avctx->extradata_size) < 0) + return -1; + } + if(h->sps.bitstream_restriction_flag && s->avctx->has_b_frames < h->sps.num_reorder_frames){ + s->avctx->has_b_frames = h->sps.num_reorder_frames; + s->low_delay = 0; + } + return 0; } -static int frame_start(H264Context *h){ +int ff_h264_frame_start(H264Context *h){ MpegEncContext * const s = &h->s; int i; @@ -2261,9 +962,8 @@ static int frame_start(H264Context *h){ if(!h->thread_context[i]->s.obmc_scratchpad) h->thread_context[i]->s.obmc_scratchpad = av_malloc(16*2*s->linesize + 8*2*s->uvlinesize); - /* some macroblocks will be accessed before they're available */ - if(FRAME_MBAFF || s->avctx->thread_count > 1) - memset(h->slice_table, -1, (s->mb_height*s->mb_stride-1) * sizeof(*h->slice_table)); + /* 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; @@ -2285,12 +985,8 @@ static int frame_start(H264Context *h){ 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 simple){ MpegEncContext * const s = &h->s; - int i; - int step = 1; - int offset = 1; - int uvoffset= 1; + uint8_t *top_border; int top_idx = 1; - int skiplast= 0; src_y -= linesize; src_cb -= uvlinesize; @@ -2298,82 +994,51 @@ static inline void backup_mb_border(H264Context *h, uint8_t *src_y, uint8_t *src if(!simple && FRAME_MBAFF){ if(s->mb_y&1){ - offset = MB_MBAFF ? 1 : 17; - uvoffset= MB_MBAFF ? 1 : 9; if(!MB_MBAFF){ - *(uint64_t*)(h->top_borders[0][s->mb_x]+ 0)= *(uint64_t*)(src_y + 15*linesize); - *(uint64_t*)(h->top_borders[0][s->mb_x]+ 8)= *(uint64_t*)(src_y +8+15*linesize); + top_border = h->top_borders[0][s->mb_x]; + AV_COPY128(top_border, src_y + 15*linesize); if(simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ - *(uint64_t*)(h->top_borders[0][s->mb_x]+16)= *(uint64_t*)(src_cb+7*uvlinesize); - *(uint64_t*)(h->top_borders[0][s->mb_x]+24)= *(uint64_t*)(src_cr+7*uvlinesize); + AV_COPY64(top_border+16, src_cb+7*uvlinesize); + AV_COPY64(top_border+24, src_cr+7*uvlinesize); } } - }else{ - if(!MB_MBAFF){ - h->left_border[0]= h->top_borders[0][s->mb_x][15]; - if(simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ - h->left_border[34 ]= h->top_borders[0][s->mb_x][16+7 ]; - h->left_border[34+18]= h->top_borders[0][s->mb_x][16+8+7]; - } - skiplast= 1; - } - offset = - uvoffset= - top_idx = MB_MBAFF ? 0 : 1; - } - step= MB_MBAFF ? 2 : 1; + }else if(MB_MBAFF){ + top_idx = 0; + }else + return; } + top_border = h->top_borders[top_idx][s->mb_x]; // There are two lines saved, the line above the the top macroblock of a pair, // and the line above the bottom macroblock - h->left_border[offset]= h->top_borders[top_idx][s->mb_x][15]; - for(i=1; i<17 - skiplast; i++){ - h->left_border[offset+i*step]= src_y[15+i* linesize]; - } - - *(uint64_t*)(h->top_borders[top_idx][s->mb_x]+0)= *(uint64_t*)(src_y + 16*linesize); - *(uint64_t*)(h->top_borders[top_idx][s->mb_x]+8)= *(uint64_t*)(src_y +8+16*linesize); + AV_COPY128(top_border, src_y + 16*linesize); if(simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ - h->left_border[uvoffset+34 ]= h->top_borders[top_idx][s->mb_x][16+7]; - h->left_border[uvoffset+34+18]= h->top_borders[top_idx][s->mb_x][24+7]; - for(i=1; i<9 - skiplast; i++){ - h->left_border[uvoffset+34 +i*step]= src_cb[7+i*uvlinesize]; - h->left_border[uvoffset+34+18+i*step]= src_cr[7+i*uvlinesize]; - } - *(uint64_t*)(h->top_borders[top_idx][s->mb_x]+16)= *(uint64_t*)(src_cb+8*uvlinesize); - *(uint64_t*)(h->top_borders[top_idx][s->mb_x]+24)= *(uint64_t*)(src_cr+8*uvlinesize); + AV_COPY64(top_border+16, src_cb+8*uvlinesize); + AV_COPY64(top_border+24, src_cr+8*uvlinesize); } } static 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 simple){ MpegEncContext * const s = &h->s; - int temp8, i; - uint64_t temp64; int deblock_left; int deblock_top; - int mb_xy; - int step = 1; - int offset = 1; - int uvoffset= 1; int top_idx = 1; + uint8_t *top_border_m1; + uint8_t *top_border; if(!simple && FRAME_MBAFF){ if(s->mb_y&1){ - offset = MB_MBAFF ? 1 : 17; - uvoffset= MB_MBAFF ? 1 : 9; + if(!MB_MBAFF) + return; }else{ - offset = - uvoffset= top_idx = MB_MBAFF ? 0 : 1; } - step= MB_MBAFF ? 2 : 1; } if(h->deblocking_filter == 2) { - mb_xy = h->mb_xy; - deblock_left = h->slice_table[mb_xy] == h->slice_table[mb_xy - 1]; - deblock_top = h->slice_table[mb_xy] == h->slice_table[h->top_mb_xy]; + deblock_left = h->left_type[0]; + deblock_top = h->top_type; } else { deblock_left = (s->mb_x > 0); deblock_top = (s->mb_y > !!MB_FIELD); @@ -2383,39 +1048,32 @@ static inline void xchg_mb_border(H264Context *h, uint8_t *src_y, uint8_t *src_c src_cb -= uvlinesize + 1; src_cr -= uvlinesize + 1; -#define XCHG(a,b,t,xchg)\ -t= a;\ -if(xchg)\ - a= b;\ -b= t; + top_border_m1 = h->top_borders[top_idx][s->mb_x-1]; + top_border = h->top_borders[top_idx][s->mb_x]; - if(deblock_left){ - for(i = !deblock_top; i<16; i++){ - XCHG(h->left_border[offset+i*step], src_y [i* linesize], temp8, xchg); - } - XCHG(h->left_border[offset+i*step], src_y [i* linesize], temp8, 1); - } +#define XCHG(a,b,xchg)\ +if (xchg) AV_SWAP64(b,a);\ +else AV_COPY64(b,a); if(deblock_top){ - XCHG(*(uint64_t*)(h->top_borders[top_idx][s->mb_x]+0), *(uint64_t*)(src_y +1), temp64, xchg); - XCHG(*(uint64_t*)(h->top_borders[top_idx][s->mb_x]+8), *(uint64_t*)(src_y +9), temp64, 1); + if(deblock_left){ + XCHG(top_border_m1+8, src_y -7, 1); + } + XCHG(top_border+0, src_y +1, xchg); + XCHG(top_border+8, src_y +9, 1); if(s->mb_x+1 < s->mb_width){ - XCHG(*(uint64_t*)(h->top_borders[top_idx][s->mb_x+1]), *(uint64_t*)(src_y +17), temp64, 1); + XCHG(h->top_borders[top_idx][s->mb_x+1], src_y +17, 1); } } if(simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ - if(deblock_left){ - for(i = !deblock_top; i<8; i++){ - XCHG(h->left_border[uvoffset+34 +i*step], src_cb[i*uvlinesize], temp8, xchg); - XCHG(h->left_border[uvoffset+34+18+i*step], src_cr[i*uvlinesize], temp8, xchg); - } - XCHG(h->left_border[uvoffset+34 +i*step], src_cb[i*uvlinesize], temp8, 1); - XCHG(h->left_border[uvoffset+34+18+i*step], src_cr[i*uvlinesize], temp8, 1); - } if(deblock_top){ - XCHG(*(uint64_t*)(h->top_borders[top_idx][s->mb_x]+16), *(uint64_t*)(src_cb+1), temp64, 1); - XCHG(*(uint64_t*)(h->top_borders[top_idx][s->mb_x]+24), *(uint64_t*)(src_cr+1), temp64, 1); + if(deblock_left){ + XCHG(top_border_m1+16, src_cb -7, 1); + XCHG(top_border_m1+24, src_cr -7, 1); + } + XCHG(top_border+16, src_cb+1, 1); + XCHG(top_border+24, src_cr+1, 1); } } } @@ -2443,6 +1101,8 @@ static av_always_inline void hl_decode_mb_internal(H264Context *h, int simple){ s->dsp.prefetch(dest_y + (s->mb_x&3)*4*s->linesize + 64, s->linesize, 4); s->dsp.prefetch(dest_cb + (s->mb_x&7)*s->uvlinesize + 64, dest_cr - dest_cb, 2); + h->list_counts[mb_xy]= h->list_count; + if (!simple && MB_FIELD) { linesize = h->mb_linesize = s->linesize * 2; uvlinesize = h->mb_uvlinesize = s->uvlinesize * 2; @@ -2500,8 +1160,8 @@ static av_always_inline void hl_decode_mb_internal(H264Context *h, int simple){ idct_dc_add = idct_add = s->dsp.add_pixels8; }else{ - idct_dc_add = s->dsp.h264_idct8_dc_add; - idct_add = s->dsp.h264_idct8_add; + idct_dc_add = h->h264dsp.h264_idct8_dc_add; + idct_add = h->h264dsp.h264_idct8_add; } for(i=0; i<16; i+=4){ uint8_t * const ptr= dest_y + block_offset[i]; @@ -2525,8 +1185,8 @@ static av_always_inline void hl_decode_mb_internal(H264Context *h, int simple){ idct_dc_add = idct_add = s->dsp.add_pixels4; }else{ - idct_dc_add = s->dsp.h264_idct_dc_add; - idct_add = s->dsp.h264_idct_add; + idct_dc_add = h->h264dsp.h264_idct_dc_add; + idct_add = h->h264dsp.h264_idct_add; } for(i=0; i<16; i++){ uint8_t * const ptr= dest_y + block_offset[i]; @@ -2557,7 +1217,7 @@ static av_always_inline void hl_decode_mb_internal(H264Context *h, int simple){ else idct_add (ptr, h->mb + i*16, linesize); }else - svq3_add_idct_c(ptr, h->mb + i*16, linesize, s->qscale, 0); + ff_svq3_add_idct_c(ptr, h->mb + i*16, linesize, s->qscale, 0); } } } @@ -2569,7 +1229,7 @@ static av_always_inline void hl_decode_mb_internal(H264Context *h, int simple){ if(!transform_bypass) h264_luma_dc_dequant_idct_c(h->mb, s->qscale, h->dequant4_coeff[0][s->qscale][0]); }else - svq3_luma_dc_dequant_idct_c(h->mb, s->qscale); + ff_svq3_luma_dc_dequant_idct_c(h->mb, s->qscale); } if(h->deblocking_filter) xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 0, simple); @@ -2577,7 +1237,7 @@ static av_always_inline void hl_decode_mb_internal(H264Context *h, int simple){ hl_motion(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, - s->dsp.weight_h264_pixels_tab, s->dsp.biweight_h264_pixels_tab); + h->h264dsp.weight_h264_pixels_tab, h->h264dsp.biweight_h264_pixels_tab); } @@ -2594,7 +1254,7 @@ static av_always_inline void hl_decode_mb_internal(H264Context *h, int simple){ } } }else{ - s->dsp.h264_idct_add16intra(dest_y, block_offset, h->mb, linesize, h->non_zero_count_cache); + h->h264dsp.h264_idct_add16intra(dest_y, block_offset, h->mb, linesize, h->non_zero_count_cache); } }else if(h->cbp&15){ if(transform_bypass){ @@ -2607,9 +1267,9 @@ static av_always_inline void hl_decode_mb_internal(H264Context *h, int simple){ } }else{ if(IS_8x8DCT(mb_type)){ - s->dsp.h264_idct8_add4(dest_y, block_offset, h->mb, linesize, h->non_zero_count_cache); + h->h264dsp.h264_idct8_add4(dest_y, block_offset, h->mb, linesize, h->non_zero_count_cache); }else{ - s->dsp.h264_idct_add16(dest_y, block_offset, h->mb, linesize, h->non_zero_count_cache); + h->h264dsp.h264_idct_add16(dest_y, block_offset, h->mb, linesize, h->non_zero_count_cache); } } } @@ -2617,7 +1277,7 @@ static av_always_inline void hl_decode_mb_internal(H264Context *h, int simple){ for(i=0; i<16; i++){ if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){ //FIXME benchmark weird rule, & below uint8_t * const ptr= dest_y + block_offset[i]; - svq3_add_idct_c(ptr, h->mb + i*16, linesize, s->qscale, IS_INTRA(mb_type) ? 1 : 0); + ff_svq3_add_idct_c(ptr, h->mb + i*16, linesize, s->qscale, IS_INTRA(mb_type) ? 1 : 0); } } } @@ -2640,8 +1300,8 @@ static av_always_inline void hl_decode_mb_internal(H264Context *h, int simple){ chroma_dc_dequant_idct_c(h->mb + 16*16, h->chroma_qp[0], h->dequant4_coeff[IS_INTRA(mb_type) ? 1:4][h->chroma_qp[0]][0]); chroma_dc_dequant_idct_c(h->mb + 16*16+4*16, h->chroma_qp[1], h->dequant4_coeff[IS_INTRA(mb_type) ? 2:5][h->chroma_qp[1]][0]); if(is_h264){ - idct_add = s->dsp.h264_idct_add; - idct_dc_add = s->dsp.h264_idct_dc_add; + idct_add = h->h264dsp.h264_idct_add; + idct_dc_add = h->h264dsp.h264_idct_dc_add; for(i=16; i<16+8; i++){ if(h->non_zero_count_cache[ scan8[i] ]) idct_add (dest[(i&4)>>2] + block_offset[i], h->mb + i*16, uvlinesize); @@ -2652,7 +1312,7 @@ static av_always_inline void hl_decode_mb_internal(H264Context *h, int simple){ for(i=16; i<16+8; i++){ if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){ uint8_t * const ptr= dest[(i&4)>>2] + block_offset[i]; - svq3_add_idct_c(ptr, h->mb + i*16, uvlinesize, chroma_qp[s->qscale + 12] - 12, 2); + ff_svq3_add_idct_c(ptr, h->mb + i*16, uvlinesize, ff_h264_chroma_qp[s->qscale + 12] - 12, 2); } } } @@ -2661,18 +1321,6 @@ static av_always_inline void hl_decode_mb_internal(H264Context *h, int simple){ } if(h->cbp || IS_INTRA(mb_type)) s->dsp.clear_blocks(h->mb); - - if(h->deblocking_filter) { - backup_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, simple); - fill_caches(h, mb_type, 1); //FIXME don't fill stuff which isn't used by filter_mb - 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]); - if (!simple && FRAME_MBAFF) { - filter_mb (h, mb_x, mb_y, dest_y, dest_cb, dest_cr, linesize, uvlinesize); - } else { - filter_mb_fast(h, mb_x, mb_y, dest_y, dest_cb, dest_cr, linesize, uvlinesize); - } - } } /** @@ -2689,7 +1337,7 @@ static void av_noinline hl_decode_mb_complex(H264Context *h){ hl_decode_mb_internal(h, 0); } -static void hl_decode_mb(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]; @@ -2700,305 +1348,6 @@ static void hl_decode_mb(H264Context *h){ else hl_decode_mb_simple(h); } -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->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); - - if (match) { - *dest = *src; - if(parity != PICT_FRAME){ - pic_as_field(dest, parity); - dest->pic_id *= 2; - dest->pic_id += id_add; - } - } - - return match; -} - -static int build_def_list(Picture *def, Picture **in, int len, int is_long, int sel){ - int i[2]={0}; - int index=0; - - while(i[0]reference & sel))) - i[0]++; - while(i[1]reference & (sel^3)))) - i[1]++; - if(i[0] < len){ - in[ i[0] ]->pic_id= is_long ? i[0] : in[ i[0] ]->frame_num; - split_field_copy(&def[index++], in[ i[0]++ ], sel , 1); - } - if(i[1] < len){ - in[ i[1] ]->pic_id= is_long ? i[1] : in[ i[1] ]->frame_num; - split_field_copy(&def[index++], in[ i[1]++ ], sel^3, 0); - } - } - - return index; -} - -static int add_sorted(Picture **sorted, Picture **src, int len, int limit, int dir){ - int i, best_poc; - int out_i= 0; - - for(;;){ - best_poc= dir ? INT_MIN : INT_MAX; - - for(i=0; ipoc; - if(((poc > limit) ^ dir) && ((poc < best_poc) ^ dir)){ - best_poc= poc; - sorted[out_i]= src[i]; - } - } - if(best_poc == (dir ? INT_MIN : INT_MAX)) - break; - limit= sorted[out_i++]->poc - dir; - } - return out_i; -} - -/** - * fills the default_ref_list. - */ -static int fill_default_ref_list(H264Context *h){ - MpegEncContext * const s = &h->s; - int i, len; - - if(h->slice_type_nos==FF_B_TYPE){ - Picture *sorted[32]; - int cur_poc, list; - int lens[2]; - - if(FIELD_PICTURE) - cur_poc= s->current_picture_ptr->field_poc[ s->picture_structure == PICT_BOTTOM_FIELD ]; - else - cur_poc= s->current_picture_ptr->poc; - - for(list= 0; list<2; list++){ - len= add_sorted(sorted , h->short_ref, h->short_ref_count, cur_poc, 1^list); - len+=add_sorted(sorted+len, h->short_ref, h->short_ref_count, cur_poc, 0^list); - assert(len<=32); - len= build_def_list(h->default_ref_list[list] , sorted , len, 0, s->picture_structure); - len+=build_def_list(h->default_ref_list[list]+len, h->long_ref, 16 , 1, s->picture_structure); - assert(len<=32); - - if(len < h->ref_count[list]) - memset(&h->default_ref_list[list][len], 0, sizeof(Picture)*(h->ref_count[list] - len)); - lens[list]= len; - } - - 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] && idefault_ref_list[1][0], h->default_ref_list[1][1]); - } - }else{ - len = build_def_list(h->default_ref_list[0] , h->short_ref, h->short_ref_count, 0, s->picture_structure); - len+= build_def_list(h->default_ref_list[0]+len, h-> long_ref, 16 , 1, s->picture_structure); - assert(len <= 32); - if(len < h->ref_count[0]) - memset(&h->default_ref_list[0][len], 0, sizeof(Picture)*(h->ref_count[0] - len)); - } -#ifdef TRACE - for (i=0; iref_count[0]; i++) { - tprintf(h->s.avctx, "List0: %s fn:%d 0x%p\n", (h->default_ref_list[0][i].long_ref ? "LT" : "ST"), h->default_ref_list[0][i].pic_id, h->default_ref_list[0][i].data[0]); - } - if(h->slice_type_nos==FF_B_TYPE){ - for (i=0; iref_count[1]; i++) { - tprintf(h->s.avctx, "List1: %s fn:%d 0x%p\n", (h->default_ref_list[1][i].long_ref ? "LT" : "ST"), h->default_ref_list[1][i].pic_id, h->default_ref_list[1][i].data[0]); - } - } -#endif - return 0; -} - -static void print_short_term(H264Context *h); -static void print_long_term(H264Context *h); - -/** - * Extract structure information about the picture described by pic_num in - * the current decoding context (frame or field). Note that pic_num is - * picture number without wrapping (so, 0<=pic_nums; - - *structure = s->picture_structure; - if(FIELD_PICTURE){ - if (!(pic_num & 1)) - /* opposite field */ - *structure ^= PICT_FRAME; - pic_num >>= 1; - } - - return pic_num; -} - -static int decode_ref_pic_list_reordering(H264Context *h){ - MpegEncContext * const s = &h->s; - int list, index, pic_structure; - - print_short_term(h); - print_long_term(h); - - for(list=0; listlist_count; list++){ - memcpy(h->ref_list[list], h->default_ref_list[list], sizeof(Picture)*h->ref_count[list]); - - if(get_bits1(&s->gb)){ - int pred= h->curr_pic_num; - - for(index=0; ; index++){ - unsigned int reordering_of_pic_nums_idc= get_ue_golomb_31(&s->gb); - unsigned int pic_id; - int i; - Picture *ref = NULL; - - if(reordering_of_pic_nums_idc==3) - break; - - if(index >= h->ref_count[list]){ - av_log(h->s.avctx, AV_LOG_ERROR, "reference count overflow\n"); - return -1; - } - - if(reordering_of_pic_nums_idc<3){ - if(reordering_of_pic_nums_idc<2){ - const unsigned int abs_diff_pic_num= get_ue_golomb(&s->gb) + 1; - int frame_num; - - if(abs_diff_pic_num > h->max_pic_num){ - av_log(h->s.avctx, AV_LOG_ERROR, "abs_diff_pic_num overflow\n"); - return -1; - } - - if(reordering_of_pic_nums_idc == 0) pred-= abs_diff_pic_num; - else pred+= abs_diff_pic_num; - pred &= h->max_pic_num - 1; - - frame_num = pic_num_extract(h, pred, &pic_structure); - - for(i= h->short_ref_count-1; i>=0; i--){ - ref = h->short_ref[i]; - assert(ref->reference); - assert(!ref->long_ref); - if( - ref->frame_num == frame_num && - (ref->reference & pic_structure) - ) - break; - } - if(i>=0) - ref->pic_id= pred; - }else{ - int long_idx; - pic_id= get_ue_golomb(&s->gb); //long_term_pic_idx - - long_idx= pic_num_extract(h, pic_id, &pic_structure); - - if(long_idx>31){ - av_log(h->s.avctx, AV_LOG_ERROR, "long_term_pic_idx overflow\n"); - return -1; - } - ref = h->long_ref[long_idx]; - assert(!(ref && !ref->reference)); - if(ref && (ref->reference & pic_structure)){ - ref->pic_id= pic_id; - assert(ref->long_ref); - i=0; - }else{ - i=-1; - } - } - - if (i < 0) { - av_log(h->s.avctx, AV_LOG_ERROR, "reference picture missing during reorder\n"); - memset(&h->ref_list[list][index], 0, sizeof(Picture)); //FIXME - } else { - for(i=index; i+1ref_count[list]; i++){ - if(ref->long_ref == h->ref_list[list][i].long_ref && ref->pic_id == h->ref_list[list][i].pic_id) - break; - } - for(; i > index; i--){ - h->ref_list[list][i]= h->ref_list[list][i-1]; - } - h->ref_list[list][index]= *ref; - if (FIELD_PICTURE){ - pic_as_field(&h->ref_list[list][index], pic_structure); - } - } - }else{ - av_log(h->s.avctx, AV_LOG_ERROR, "illegal reordering_of_pic_nums_idc\n"); - return -1; - } - } - } - } - for(list=0; listlist_count; list++){ - for(index= 0; index < h->ref_count[list]; index++){ - if(!h->ref_list[list][index].data[0]){ - av_log(h->s.avctx, AV_LOG_ERROR, "Missing reference picture\n"); - if(h->default_ref_list[list][0].data[0]) - h->ref_list[list][index]= h->default_ref_list[list][0]; - else - return -1; - } - } - } - - return 0; -} - -static void fill_mbaff_ref_list(H264Context *h){ - int list, i, j; - for(list=0; list<2; list++){ //FIXME try list_count - for(i=0; iref_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].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].poc= field[1].field_poc[1]; - - h->luma_weight[list][16+2*i] = h->luma_weight[list][16+2*i+1] = h->luma_weight[list][i]; - h->luma_offset[list][16+2*i] = h->luma_offset[list][16+2*i+1] = h->luma_offset[list][i]; - for(j=0; j<2; j++){ - h->chroma_weight[list][16+2*i][j] = h->chroma_weight[list][16+2*i+1][j] = h->chroma_weight[list][i][j]; - h->chroma_offset[list][16+2*i][j] = h->chroma_offset[list][16+2*i+1][j] = h->chroma_offset[list][i][j]; - } - } - } - for(j=0; jref_count[1]; j++){ - for(i=0; iref_count[0]; i++) - h->implicit_weight[j][16+2*i] = h->implicit_weight[j][16+2*i+1] = h->implicit_weight[j][i]; - memcpy(h->implicit_weight[16+2*j], h->implicit_weight[j], sizeof(*h->implicit_weight)); - memcpy(h->implicit_weight[16+2*j+1], h->implicit_weight[j], sizeof(*h->implicit_weight)); - } -} - static int pred_weight_table(H264Context *h){ MpegEncContext * const s = &h->s; int list, i; @@ -3019,16 +1368,16 @@ static int pred_weight_table(H264Context *h){ luma_weight_flag= get_bits1(&s->gb); if(luma_weight_flag){ - h->luma_weight[list][i]= get_se_golomb(&s->gb); - h->luma_offset[list][i]= get_se_golomb(&s->gb); - if( h->luma_weight[list][i] != luma_def - || h->luma_offset[list][i] != 0) { + h->luma_weight[i][list][0]= get_se_golomb(&s->gb); + h->luma_weight[i][list][1]= get_se_golomb(&s->gb); + if( h->luma_weight[i][list][0] != luma_def + || h->luma_weight[i][list][1] != 0) { h->use_weight= 1; h->luma_weight_flag[list]= 1; } }else{ - h->luma_weight[list][i]= luma_def; - h->luma_offset[list][i]= 0; + h->luma_weight[i][list][0]= luma_def; + h->luma_weight[i][list][1]= 0; } if(CHROMA){ @@ -3036,10 +1385,10 @@ static int pred_weight_table(H264Context *h){ if(chroma_weight_flag){ int j; for(j=0; j<2; j++){ - h->chroma_weight[list][i][j]= get_se_golomb(&s->gb); - h->chroma_offset[list][i][j]= get_se_golomb(&s->gb); - if( h->chroma_weight[list][i][j] != chroma_def - || h->chroma_offset[list][i][j] != 0) { + h->chroma_weight[i][list][j][0]= get_se_golomb(&s->gb); + h->chroma_weight[i][list][j][1]= get_se_golomb(&s->gb); + if( h->chroma_weight[i][list][j][0] != chroma_def + || h->chroma_weight[i][list][j][1] != 0) { h->use_weight_chroma= 1; h->chroma_weight_flag[list]= 1; } @@ -3047,8 +1396,8 @@ static int pred_weight_table(H264Context *h){ }else{ int j; for(j=0; j<2; j++){ - h->chroma_weight[list][i][j]= chroma_def; - h->chroma_offset[list][i][j]= 0; + h->chroma_weight[i][list][j][0]= chroma_def; + h->chroma_weight[i][list][j][1]= 0; } } } @@ -3059,69 +1408,63 @@ static int pred_weight_table(H264Context *h){ return 0; } -static void implicit_weight_table(H264Context *h){ +/** + * Initialize implicit_weight table. + * @param field, 0/1 initialize the weight for interlaced MBAFF + * -1 initializes the rest + */ +static void implicit_weight_table(H264Context *h, int field){ MpegEncContext * const s = &h->s; - int ref0, ref1, i; - int cur_poc = s->current_picture_ptr->poc; + int ref0, ref1, i, cur_poc, ref_start, ref_count0, ref_count1; for (i = 0; i < 2; i++) { h->luma_weight_flag[i] = 0; h->chroma_weight_flag[i] = 0; } - if( h->ref_count[0] == 1 && h->ref_count[1] == 1 + if(field < 0){ + cur_poc = s->current_picture_ptr->poc; + 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; h->use_weight_chroma= 0; return; } + ref_start= 0; + ref_count0= h->ref_count[0]; + ref_count1= h->ref_count[1]; + }else{ + cur_poc = s->current_picture_ptr->field_poc[field]; + ref_start= 16; + ref_count0= 16+2*h->ref_count[0]; + ref_count1= 16+2*h->ref_count[1]; + } h->use_weight= 2; h->use_weight_chroma= 2; h->luma_log2_weight_denom= 5; h->chroma_log2_weight_denom= 5; - for(ref0=0; ref0 < h->ref_count[0]; ref0++){ + for(ref0=ref_start; ref0 < ref_count0; ref0++){ int poc0 = h->ref_list[0][ref0].poc; - for(ref1=0; ref1 < h->ref_count[1]; ref1++){ + 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 = av_clip((tb*tx + 32) >> 6, -1024, 1023) >> 2; - if(dist_scale_factor < -64 || dist_scale_factor > 128) - h->implicit_weight[ref0][ref1] = 32; - else - h->implicit_weight[ref0][ref1] = 64 - dist_scale_factor; - }else - h->implicit_weight[ref0][ref1] = 32; - } - } -} - -/** - * Mark a picture as no longer needed for reference. The refmask - * argument allows unreferencing of individual fields or the whole frame. - * If the picture becomes entirely unreferenced, but is being held for - * display purposes, it is marked as such. - * @param refmask mask of fields to unreference; the mask is bitwise - * anded with the reference marking of pic - * @return non-zero if pic becomes entirely unreferenced (except possibly - * for display purposes) zero if one of the fields remains in - * reference - */ -static inline int unreference_pic(H264Context *h, Picture *pic, int refmask){ - int i; - if (pic->reference &= refmask) { - return 0; - } else { - for(i = 0; h->delayed_pic[i]; i++) - if(pic == h->delayed_pic[i]){ - pic->reference=DELAYED_PIC_REF; - break; + int dist_scale_factor = (tb*tx + 32) >> 8; + if(dist_scale_factor >= -64 && dist_scale_factor <= 128) + w = 64 - dist_scale_factor; } - return 1; + if(field<0){ + h->implicit_weight[ref0][ref1][0]= + h->implicit_weight[ref0][ref1][1]= w; + }else{ + h->implicit_weight[ref0][ref1][field]=w; + } + } } } @@ -3129,18 +1472,7 @@ static inline int unreference_pic(H264Context *h, Picture *pic, int refmask){ * instantaneous decoder refresh. */ static void idr(H264Context *h){ - int i; - - for(i=0; i<16; i++){ - remove_long(h, i, 0); - } - assert(h->long_ref_count==0); - - for(i=0; ishort_ref_count; i++){ - unreference_pic(h, h->short_ref[i], 0); - h->short_ref[i]= NULL; - } - h->short_ref_count=0; + ff_h264_remove_all_refs(h); h->prev_frame_num= 0; h->prev_frame_num_offset= 0; h->prev_poc_msb= @@ -3162,341 +1494,10 @@ static void flush_dpb(AVCodecContext *avctx){ if(h->s.current_picture_ptr) h->s.current_picture_ptr->reference= 0; h->s.first_field= 0; - reset_sei(h); + ff_h264_reset_sei(h); ff_mpeg_flush(avctx); } -/** - * Find a Picture in the short term reference list by frame number. - * @param frame_num frame number to search for - * @param idx the index into h->short_ref where returned picture is found - * undefined if no picture found. - * @return pointer to the found picture, or NULL if no pic with the provided - * frame number is found - */ -static Picture * find_short(H264Context *h, int frame_num, int *idx){ - MpegEncContext * const s = &h->s; - int i; - - for(i=0; ishort_ref_count; i++){ - Picture *pic= h->short_ref[i]; - if(s->avctx->debug&FF_DEBUG_MMCO) - av_log(h->s.avctx, AV_LOG_DEBUG, "%d %d %p\n", i, pic->frame_num, pic); - if(pic->frame_num == frame_num) { - *idx = i; - return pic; - } - } - return NULL; -} - -/** - * Remove a picture from the short term reference list by its index in - * that list. This does no checking on the provided index; it is assumed - * to be valid. Other list entries are shifted down. - * @param i index into h->short_ref of picture to remove. - */ -static void remove_short_at_index(H264Context *h, int i){ - assert(i >= 0 && i < h->short_ref_count); - h->short_ref[i]= NULL; - if (--h->short_ref_count) - memmove(&h->short_ref[i], &h->short_ref[i+1], (h->short_ref_count - i)*sizeof(Picture*)); -} - -/** - * - * @return the removed picture or NULL if an error occurs - */ -static Picture * remove_short(H264Context *h, int frame_num, int ref_mask){ - MpegEncContext * const s = &h->s; - Picture *pic; - int i; - - if(s->avctx->debug&FF_DEBUG_MMCO) - av_log(h->s.avctx, AV_LOG_DEBUG, "remove short %d count %d\n", frame_num, h->short_ref_count); - - pic = find_short(h, frame_num, &i); - if (pic){ - if(unreference_pic(h, pic, ref_mask)) - remove_short_at_index(h, i); - } - - return pic; -} - -/** - * Remove a picture from the long term reference list by its index in - * that list. - * @return the removed picture or NULL if an error occurs - */ -static Picture * remove_long(H264Context *h, int i, int ref_mask){ - Picture *pic; - - pic= h->long_ref[i]; - if (pic){ - if(unreference_pic(h, pic, ref_mask)){ - assert(h->long_ref[i]->long_ref == 1); - h->long_ref[i]->long_ref= 0; - h->long_ref[i]= NULL; - h->long_ref_count--; - } - } - - return pic; -} - -/** - * print short term list - */ -static void print_short_term(H264Context *h) { - uint32_t i; - if(h->s.avctx->debug&FF_DEBUG_MMCO) { - av_log(h->s.avctx, AV_LOG_DEBUG, "short term list:\n"); - for(i=0; ishort_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]); - } - } -} - -/** - * print long term list - */ -static void print_long_term(H264Context *h) { - uint32_t i; - if(h->s.avctx->debug&FF_DEBUG_MMCO) { - av_log(h->s.avctx, AV_LOG_DEBUG, "long term list:\n"); - 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]); - } - } - } -} - -/** - * Executes the reference picture marking (memory management control operations). - */ -static int 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; - Picture *av_uninit(pic); - - if((s->avctx->debug&FF_DEBUG_MMCO) && mmco_count==0) - av_log(h->s.avctx, AV_LOG_DEBUG, "no mmco here\n"); - - for(i=0; iavctx->debug&FF_DEBUG_MMCO) - av_log(h->s.avctx, AV_LOG_DEBUG, "mmco:%d %d %d\n", h->mmco[i].opcode, h->mmco[i].short_pic_num, h->mmco[i].long_arg); - - if( mmco[i].opcode == MMCO_SHORT2UNUSED - || mmco[i].opcode == MMCO_SHORT2LONG){ - frame_num = pic_num_extract(h, mmco[i].short_pic_num, &structure); - 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"); - continue; - } - } - - switch(mmco[i].opcode){ - case MMCO_SHORT2UNUSED: - if(s->avctx->debug&FF_DEBUG_MMCO) - av_log(h->s.avctx, AV_LOG_DEBUG, "mmco: unref short %d count %d\n", h->mmco[i].short_pic_num, h->short_ref_count); - remove_short(h, frame_num, structure ^ PICT_FRAME); - break; - case MMCO_SHORT2LONG: - if (h->long_ref[mmco[i].long_arg] != pic) - remove_long(h, mmco[i].long_arg, 0); - - remove_short_at_index(h, j); - h->long_ref[ mmco[i].long_arg ]= pic; - if (h->long_ref[ mmco[i].long_arg ]){ - h->long_ref[ mmco[i].long_arg ]->long_ref=1; - h->long_ref_count++; - } - break; - case MMCO_LONG2UNUSED: - j = pic_num_extract(h, mmco[i].long_arg, &structure); - pic = h->long_ref[j]; - if (pic) { - remove_long(h, j, structure ^ PICT_FRAME); - } else if(s->avctx->debug&FF_DEBUG_MMCO) - av_log(h->s.avctx, AV_LOG_DEBUG, "mmco: unref long failure\n"); - break; - case MMCO_LONG: - // Comment below left from previous code as it is an interresting note. - /* First field in pair is in short term list or - * at a different long term index. - * This is not allowed; see 7.4.3.3, notes 2 and 3. - * Report the problem and keep the pair where it is, - * and mark this field valid. - */ - - if (h->long_ref[mmco[i].long_arg] != s->current_picture_ptr) { - remove_long(h, mmco[i].long_arg, 0); - - h->long_ref[ mmco[i].long_arg ]= s->current_picture_ptr; - h->long_ref[ mmco[i].long_arg ]->long_ref=1; - h->long_ref_count++; - } - - s->current_picture_ptr->reference |= s->picture_structure; - current_ref_assigned=1; - break; - case MMCO_SET_MAX_LONG: - assert(mmco[i].long_arg <= 16); - // just remove the long term which index is greater than new max - for(j = mmco[i].long_arg; j<16; j++){ - remove_long(h, j, 0); - } - break; - case MMCO_RESET: - while(h->short_ref_count){ - remove_short(h, h->short_ref[0]->frame_num, 0); - } - for(j = 0; j < 16; j++) { - remove_long(h, j, 0); - } - s->current_picture_ptr->poc= - s->current_picture_ptr->field_poc[0]= - s->current_picture_ptr->field_poc[1]= - h->poc_lsb= - h->poc_msb= - h->frame_num= - s->current_picture_ptr->frame_num= 0; - s->current_picture_ptr->mmco_reset=1; - break; - default: assert(0); - } - } - - if (!current_ref_assigned) { - /* Second field of complementary field pair; the first field of - * which is already referenced. If short referenced, it - * should be first entry in short_ref. If not, it must exist - * in long_ref; trying to put it on the short list here is an - * error in the encoded bit stream (ref: 7.4.3.3, NOTE 2 and 3). - */ - 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; - } 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"); - } 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"); - } - - if(h->short_ref_count) - memmove(&h->short_ref[1], &h->short_ref[0], h->short_ref_count*sizeof(Picture*)); - - h->short_ref[0]= s->current_picture_ptr; - h->short_ref_count++; - s->current_picture_ptr->reference |= s->picture_structure; - } - } - - if (h->long_ref_count + h->short_ref_count > h->sps.ref_frame_count){ - - /* We have too many reference frames, probably due to corrupted - * stream. Need to discard one frame. Prevents overrun of the - * short_ref and long_ref buffers. - */ - av_log(h->s.avctx, AV_LOG_ERROR, - "number of reference frames exceeds max (probably " - "corrupt input), discarding one\n"); - - if (h->long_ref_count && !h->short_ref_count) { - for (i = 0; i < 16; ++i) - if (h->long_ref[i]) - break; - - assert(i < 16); - remove_long(h, i, 0); - } else { - pic = h->short_ref[h->short_ref_count - 1]; - remove_short(h, pic->frame_num, 0); - } - } - - print_short_term(h); - print_long_term(h); - return 0; -} - -static int decode_ref_pic_marking(H264Context *h, GetBitContext *gb){ - MpegEncContext * const s = &h->s; - int i; - - h->mmco_index= 0; - if(h->nal_unit_type == NAL_IDR_SLICE){ //FIXME fields - s->broken_link= get_bits1(gb) -1; - if(get_bits1(gb)){ - h->mmco[0].opcode= MMCO_LONG; - h->mmco[0].long_arg= 0; - h->mmco_index= 1; - } - }else{ - if(get_bits1(gb)){ // adaptive_ref_pic_marking_mode_flag - for(i= 0; immco[i].opcode= opcode; - if(opcode==MMCO_SHORT2UNUSED || opcode==MMCO_SHORT2LONG){ - h->mmco[i].short_pic_num= (h->curr_pic_num - get_ue_golomb(gb) - 1) & (h->max_pic_num - 1); -/* if(h->mmco[i].short_pic_num >= h->short_ref_count || h->short_ref[ h->mmco[i].short_pic_num ] == NULL){ - av_log(s->avctx, AV_LOG_ERROR, "illegal short ref in memory management control operation %d\n", mmco); - return -1; - }*/ - } - 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))){ - av_log(h->s.avctx, AV_LOG_ERROR, "illegal long ref in memory management control operation %d\n", opcode); - return -1; - } - h->mmco[i].long_arg= long_arg; - } - - if(opcode > (unsigned)MMCO_LONG){ - av_log(h->s.avctx, AV_LOG_ERROR, "illegal memory management control operation %d\n", opcode); - return -1; - } - if(opcode == MMCO_END) - break; - } - h->mmco_index= i; - }else{ - assert(h->long_ref_count + h->short_ref_count <= h->sps.ref_frame_count); - - 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)) { - 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; - if (FIELD_PICTURE) { - h->mmco[0].short_pic_num *= 2; - h->mmco[1].opcode= MMCO_SHORT2UNUSED; - h->mmco[1].short_pic_num= h->mmco[0].short_pic_num + 1; - h->mmco_index= 2; - } - } - } - } - - return 0; -} - static int init_poc(H264Context *h){ MpegEncContext * const s = &h->s; const int max_frame_num= 1<sps.log2_max_frame_num; @@ -3579,9 +1580,8 @@ static int init_poc(H264Context *h){ * initialize scan tables */ static void init_scan_tables(H264Context *h){ - MpegEncContext * const s = &h->s; int i; - if(s->dsp.h264_idct_add == ff_h264_idct_add_c){ //FIXME little ugly + if(h->h264dsp.h264_idct_add == ff_h264_idct_add_c){ //FIXME little ugly memcpy(h->zigzag_scan, zigzag_scan, 16*sizeof(uint8_t)); memcpy(h-> field_scan, field_scan, 16*sizeof(uint8_t)); }else{ @@ -3592,7 +1592,7 @@ static void init_scan_tables(H264Context *h){ #undef T } } - if(s->dsp.h264_idct8_add == ff_h264_idct8_add_c){ + if(h->h264dsp.h264_idct8_add == ff_h264_idct8_add_c){ memcpy(h->zigzag_scan8x8, ff_zigzag_direct, 64*sizeof(uint8_t)); memcpy(h->zigzag_scan8x8_cavlc, zigzag_scan8x8_cavlc, 64*sizeof(uint8_t)); memcpy(h->field_scan8x8, field_scan8x8, 64*sizeof(uint8_t)); @@ -3636,7 +1636,7 @@ static void field_end(H264Context *h){ ff_vdpau_h264_set_reference_frames(s); if(!s->dropable) { - execute_ref_pic_marking(h, h->mmco, h->mmco_index); + 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; } @@ -3759,11 +1759,6 @@ static int decode_slice_header(H264Context *h, H264Context *h0){ h->slice_type_nos= slice_type & 3; s->pict_type= h->slice_type; // to make a few old functions happy, it's wrong though - if (s->pict_type == FF_B_TYPE && s0->last_picture_ptr == NULL) { - av_log(h->s.avctx, AV_LOG_ERROR, - "B picture before any references, skipping\n"); - return -1; - } pps_id= get_ue_golomb(&s->gb); if(pps_id>=MAX_PPS_COUNT){ @@ -3782,6 +1777,10 @@ static int decode_slice_header(H264Context *h, H264Context *h0){ } h->sps = *h0->sps_buffers[h->pps.sps_id]; + s->avctx->profile = h->sps.profile_idc; + s->avctx->level = h->sps.level_idc; + s->avctx->refs = h->sps.ref_frame_count; + if(h == h0 && h->dequant_coeff_pps != pps_id){ h->dequant_coeff_pps = pps_id; init_dequant_tables(h); @@ -3791,7 +1790,6 @@ static int decode_slice_header(H264Context *h, H264Context *h0){ s->mb_height= h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag); h->b_stride= s->mb_width*4; - h->b8_stride= s->mb_width*2; s->width = 16*s->mb_width - 2*FFMIN(h->sps.crop_right, 7); if(h->sps.frame_mbs_only_flag) @@ -3800,7 +1798,8 @@ static int decode_slice_header(H264Context *h, H264Context *h0){ s->height= 16*s->mb_height - 4*FFMIN(h->sps.crop_bottom, 3); if (s->context_initialized - && ( s->width != s->avctx->width || s->height != s->avctx->height)) { + && ( s->width != s->avctx->width || s->height != s->avctx->height + || av_cmp_q(h->sps.sar, s->avctx->sample_aspect_ratio))) { if(h != h0) return -1; // width / height changed during parallelized decoding free_tables(h); @@ -3810,42 +1809,54 @@ static int decode_slice_header(H264Context *h, H264Context *h0){ if (!s->context_initialized) { if(h != h0) return -1; // we cant (re-)initialize context during parallel decoding + + avcodec_set_dimensions(s->avctx, s->width, s->height); + s->avctx->sample_aspect_ratio= h->sps.sar; + if(!s->avctx->sample_aspect_ratio.den) + s->avctx->sample_aspect_ratio.den = 1; + + if(h->sps.video_signal_type_present_flag){ + s->avctx->color_range = h->sps.full_range ? 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; + s->avctx->colorspace = h->sps.colorspace; + } + } + + if(h->sps.timing_info_present_flag){ + int64_t den= h->sps.time_scale; + if(h->x264_build < 44U) + den *= 2; + av_reduce(&s->avctx->time_base.num, &s->avctx->time_base.den, + h->sps.num_units_in_tick, den, 1<<30); + } + s->avctx->pix_fmt = s->avctx->get_format(s->avctx, s->avctx->codec->pix_fmts); + s->avctx->hwaccel = ff_find_hwaccel(s->avctx->codec->id, s->avctx->pix_fmt); + if (MPV_common_init(s) < 0) return -1; s->first_field = 0; h->prev_interlaced_frame = 1; init_scan_tables(h); - alloc_tables(h); + ff_h264_alloc_tables(h); for(i = 1; i < s->avctx->thread_count; i++) { H264Context *c; c = h->thread_context[i] = av_malloc(sizeof(H264Context)); memcpy(c, h->s.thread_context[i], sizeof(MpegEncContext)); memset(&c->s + 1, 0, sizeof(H264Context) - sizeof(MpegEncContext)); + c->h264dsp = h->h264dsp; c->sps = h->sps; c->pps = h->pps; init_scan_tables(c); - clone_tables(c, h); + clone_tables(c, h, i); } for(i = 0; i < s->avctx->thread_count; i++) if(context_init(h->thread_context[i]) < 0) return -1; - - s->avctx->width = s->width; - s->avctx->height = s->height; - s->avctx->sample_aspect_ratio= h->sps.sar; - if(!s->avctx->sample_aspect_ratio.den) - s->avctx->sample_aspect_ratio.den = 1; - - if(h->sps.timing_info_present_flag){ - s->avctx->time_base= (AVRational){h->sps.num_units_in_tick, h->sps.time_scale}; - if(h->x264_build > 0 && h->x264_build < 44) - s->avctx->time_base.den *= 2; - av_reduce(&s->avctx->time_base.num, &s->avctx->time_base.den, - s->avctx->time_base.num, s->avctx->time_base.den, 1<<30); - } } h->frame_num= get_bits(&s->gb, h->sps.log2_max_frame_num); @@ -3869,12 +1880,12 @@ static int decode_slice_header(H264Context *h, H264Context *h0){ while(h->frame_num != h->prev_frame_num && h->frame_num != (h->prev_frame_num+1)%(1<sps.log2_max_frame_num)){ av_log(NULL, AV_LOG_DEBUG, "Frame num gap %d %d\n", h->frame_num, h->prev_frame_num); - if (frame_start(h) < 0) + if (ff_h264_frame_start(h) < 0) return -1; h->prev_frame_num++; h->prev_frame_num %= 1<sps.log2_max_frame_num; s->current_picture_ptr->frame_num= h->prev_frame_num; - execute_ref_pic_marking(h, NULL, 0); + ff_h264_execute_ref_pic_marking(h, NULL, 0); } /* See if we have a decoded first field looking for a pair... */ @@ -3917,7 +1928,7 @@ static int decode_slice_header(H264Context *h, H264Context *h0){ s0->first_field = FIELD_PICTURE; } - if((!FIELD_PICTURE || s0->first_field) && frame_start(h) < 0) { + if((!FIELD_PICTURE || s0->first_field) && ff_h264_frame_start(h) < 0) { s0->first_field = 0; return -1; } @@ -4001,10 +2012,10 @@ static int decode_slice_header(H264Context *h, H264Context *h0){ h->list_count= 0; if(!default_ref_list_done){ - fill_default_ref_list(h); + ff_h264_fill_default_ref_list(h); } - if(h->slice_type_nos!=FF_I_TYPE && decode_ref_pic_list_reordering(h) < 0) + if(h->slice_type_nos!=FF_I_TYPE && ff_h264_decode_ref_pic_list_reordering(h) < 0) return -1; if(h->slice_type_nos!=FF_I_TYPE){ @@ -4019,9 +2030,9 @@ static int decode_slice_header(H264Context *h, H264Context *h0){ if( (h->pps.weighted_pred && h->slice_type_nos == FF_P_TYPE ) || (h->pps.weighted_bipred_idc==1 && h->slice_type_nos== FF_B_TYPE ) ) pred_weight_table(h); - else if(h->pps.weighted_bipred_idc==2 && h->slice_type_nos== FF_B_TYPE) - implicit_weight_table(h); - else { + else if(h->pps.weighted_bipred_idc==2 && h->slice_type_nos== FF_B_TYPE){ + implicit_weight_table(h, -1); + }else { h->use_weight = 0; for (i = 0; i < 2; i++) { h->luma_weight_flag[i] = 0; @@ -4030,14 +2041,20 @@ static int decode_slice_header(H264Context *h, H264Context *h0){ } if(h->nal_ref_idc) - decode_ref_pic_marking(h0, &s->gb); + ff_h264_decode_ref_pic_marking(h0, &s->gb); - if(FRAME_MBAFF) - fill_mbaff_ref_list(h); + if(FRAME_MBAFF){ + ff_h264_fill_mbaff_ref_list(h); + + if(h->pps.weighted_bipred_idc==2 && h->slice_type_nos== FF_B_TYPE){ + implicit_weight_table(h, 0); + implicit_weight_table(h, 1); + } + } if(h->slice_type_nos==FF_B_TYPE && !h->direct_spatial_mv_pred) - direct_dist_scale_factor(h); - direct_ref_list_init(h); + ff_h264_direct_dist_scale_factor(h); + ff_h264_direct_ref_list_init(h); if( h->slice_type_nos != FF_I_TYPE && h->pps.cabac ){ tmp = get_ue_golomb_31(&s->gb); @@ -4066,8 +2083,8 @@ static int decode_slice_header(H264Context *h, H264Context *h0){ } h->deblocking_filter = 1; - h->slice_alpha_c0_offset = 0; - h->slice_beta_offset = 0; + h->slice_alpha_c0_offset = 52; + h->slice_beta_offset = 52; if( h->pps.deblocking_filter_parameters_present ) { tmp= get_ue_golomb_31(&s->gb); if(tmp > 2){ @@ -4079,8 +2096,13 @@ static int decode_slice_header(H264Context *h, H264Context *h0){ h->deblocking_filter^= 1; // 1<->0 if( h->deblocking_filter ) { - h->slice_alpha_c0_offset = get_se_golomb(&s->gb) << 1; - h->slice_beta_offset = get_se_golomb(&s->gb) << 1; + h->slice_alpha_c0_offset += get_se_golomb(&s->gb) << 1; + h->slice_beta_offset += get_se_golomb(&s->gb) << 1; + if( h->slice_alpha_c0_offset > 104U + || h->slice_beta_offset > 104U){ + av_log(s->avctx, AV_LOG_ERROR, "deblocking filter parameters %d %d out of range\n", h->slice_alpha_c0_offset, h->slice_beta_offset); + return -1; + } } } @@ -4105,6 +2127,7 @@ static int decode_slice_header(H264Context *h, H264Context *h0){ return 1; // deblocking switched inside frame } } + 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]); #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) @@ -4118,24 +2141,41 @@ static int decode_slice_header(H264Context *h, H264Context *h0){ } for(j=0; j<2; j++){ + int id_list[16]; 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]){ + int k; + uint8_t *base= h->ref_list[j][i].base[0]; + for(k=0; kshort_ref_count; k++) + if(h->short_ref[k]->base[0] == base){ + id_list[i]= k; + break; + } + for(k=0; klong_ref_count; k++) + if(h->long_ref[k] && h->long_ref[k]->base[0] == base){ + id_list[i]= h->short_ref_count + k; + break; + } + } + } + ref2frm[0]= ref2frm[1]= -1; for(i=0; i<16; i++) - ref2frm[i+2]= 4*h->ref_list[j][i].frame_num + ref2frm[i+2]= 4*id_list[i] +(h->ref_list[j][i].reference&3); ref2frm[18+0]= ref2frm[18+1]= -1; for(i=16; i<48; i++) - ref2frm[i+4]= 4*h->ref_list[j][i].frame_num + ref2frm[i+4]= 4*id_list[(i-16)>>1] +(h->ref_list[j][i].reference&3); } h->emu_edge_width= (s->flags&CODEC_FLAG_EMU_EDGE) ? 0 : 16; h->emu_edge_height= (FRAME_MBAFF || FIELD_PICTURE) ? 0 : h->emu_edge_width; - s->avctx->refs= h->sps.ref_frame_count; - if(s->avctx->debug&FF_DEBUG_PICT_INFO){ av_log(h->s.avctx, AV_LOG_DEBUG, "slice:%d %s mb:%d %c%s%s pps:%u frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\n", h->slice_num, @@ -4146,7 +2186,7 @@ static int decode_slice_header(H264Context *h, H264Context *h0){ s->current_picture_ptr->field_poc[0], s->current_picture_ptr->field_poc[1], h->ref_count[0], h->ref_count[1], s->qscale, - h->deblocking_filter, h->slice_alpha_c0_offset/2, h->slice_beta_offset/2, + h->deblocking_filter, h->slice_alpha_c0_offset/2-26, h->slice_beta_offset/2-26, h->use_weight, h->use_weight==1 && h->use_weight_chroma ? "c" : "", h->slice_type == FF_B_TYPE ? (h->direct_spatial_mv_pred ? "SPAT" : "TEMP") : "" @@ -4156,2436 +2196,170 @@ static int decode_slice_header(H264Context *h, H264Context *h0){ return 0; } +int ff_h264_get_slice_type(const H264Context *h) +{ + switch (h->slice_type) { + case FF_P_TYPE: return 0; + case FF_B_TYPE: return 1; + case FF_I_TYPE: return 2; + case FF_SP_TYPE: return 3; + case FF_SI_TYPE: return 4; + default: return -1; + } +} + /** * + * @return non zero if the loop filter can be skiped */ -static inline int get_level_prefix(GetBitContext *gb){ - unsigned int buf; - int log; - - OPEN_READER(re, gb); - UPDATE_CACHE(re, gb); - buf=GET_CACHE(re, gb); - - log= 32 - av_log2(buf); -#ifdef TRACE - print_bin(buf>>(32-log), log); - av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d lpr @%5d in %s get_level_prefix\n", buf>>(32-log), log, log-1, get_bits_count(gb), __FILE__); -#endif - - LAST_SKIP_BITS(re, gb, log); - CLOSE_READER(re, gb); - - return log-1; -} - -static inline int get_dct8x8_allowed(H264Context *h){ - if(h->sps.direct_8x8_inference_flag) - return !(*(uint64_t*)h->sub_mb_type & ((MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_8x8 )*0x0001000100010001ULL)); - else - return !(*(uint64_t*)h->sub_mb_type & ((MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_8x8|MB_TYPE_DIRECT2)*0x0001000100010001ULL)); -} - -/** - * decodes a residual block. - * @param n block index - * @param scantable scantable - * @param max_coeff number of coefficients in the block - * @return <0 if an error occurred - */ -static int decode_residual(H264Context *h, GetBitContext *gb, DCTELEM *block, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff){ - MpegEncContext * const s = &h->s; - static const int coeff_token_table_index[17]= {0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3}; - int level[16]; - int zeros_left, coeff_num, coeff_token, total_coeff, i, j, trailing_ones, run_before; - - //FIXME put trailing_onex into the context - - if(n == CHROMA_DC_BLOCK_INDEX){ - coeff_token= get_vlc2(gb, chroma_dc_coeff_token_vlc.table, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 1); - total_coeff= coeff_token>>2; - }else{ - if(n == LUMA_DC_BLOCK_INDEX){ - total_coeff= pred_non_zero_count(h, 0); - coeff_token= get_vlc2(gb, coeff_token_vlc[ coeff_token_table_index[total_coeff] ].table, COEFF_TOKEN_VLC_BITS, 2); - total_coeff= coeff_token>>2; - }else{ - total_coeff= pred_non_zero_count(h, n); - coeff_token= get_vlc2(gb, coeff_token_vlc[ coeff_token_table_index[total_coeff] ].table, COEFF_TOKEN_VLC_BITS, 2); - total_coeff= coeff_token>>2; - h->non_zero_count_cache[ scan8[n] ]= total_coeff; - } - } - - //FIXME set last_non_zero? - - if(total_coeff==0) - return 0; - if(total_coeff > (unsigned)max_coeff) { - av_log(h->s.avctx, AV_LOG_ERROR, "corrupted macroblock %d %d (total_coeff=%d)\n", s->mb_x, s->mb_y, total_coeff); - return -1; - } - - trailing_ones= coeff_token&3; - tprintf(h->s.avctx, "trailing:%d, total:%d\n", trailing_ones, total_coeff); - assert(total_coeff<=16); - - i = show_bits(gb, 3); - skip_bits(gb, trailing_ones); - level[0] = 1-((i&4)>>1); - level[1] = 1-((i&2) ); - level[2] = 1-((i&1)<<1); - - if(trailing_ones 10 && trailing_ones < 3; - int bitsi= show_bits(gb, LEVEL_TAB_BITS); - int level_code= cavlc_level_tab[suffix_length][bitsi][0]; - - skip_bits(gb, cavlc_level_tab[suffix_length][bitsi][1]); - if(level_code >= 100){ - prefix= level_code - 100; - if(prefix == LEVEL_TAB_BITS) - prefix += get_level_prefix(gb); - - //first coefficient has suffix_length equal to 0 or 1 - if(prefix<14){ //FIXME try to build a large unified VLC table for all this - if(suffix_length) - level_code= (prefix<<1) + get_bits1(gb); //part - else - level_code= prefix; //part - }else if(prefix==14){ - if(suffix_length) - level_code= (prefix<<1) + get_bits1(gb); //part - else - level_code= prefix + get_bits(gb, 4); //part - }else{ - level_code= 30 + get_bits(gb, prefix-3); //part - if(prefix>=16) - level_code += (1<<(prefix-3))-4096; - } - - if(trailing_ones < 3) level_code += 2; - - suffix_length = 2; - mask= -(level_code&1); - level[trailing_ones]= (((2+level_code)>>1) ^ mask) - mask; - }else{ - if(trailing_ones < 3) level_code += (level_code>>31)|1; - - suffix_length = 1; - if(level_code + 3U > 6U) - suffix_length++; - level[trailing_ones]= level_code; - } - - //remaining coefficients have suffix_length > 0 - for(i=trailing_ones+1;i= 100){ - prefix= level_code - 100; - if(prefix == LEVEL_TAB_BITS){ - prefix += get_level_prefix(gb); - } - if(prefix<15){ - level_code = (prefix<=16) - level_code += (1<<(prefix-3))-4096; - } - mask= -(level_code&1); - level_code= (((2+level_code)>>1) ^ mask) - mask; - } - level[i]= level_code; - - if(suffix_limit[suffix_length] + level_code > 2U*suffix_limit[suffix_length]) - suffix_length++; - } - } - - if(total_coeff == max_coeff) - zeros_left=0; - else{ - if(n == CHROMA_DC_BLOCK_INDEX) - zeros_left= get_vlc2(gb, chroma_dc_total_zeros_vlc[ total_coeff-1 ].table, CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 1); - else - zeros_left= get_vlc2(gb, total_zeros_vlc[ total_coeff-1 ].table, TOTAL_ZEROS_VLC_BITS, 1); - } - - coeff_num = zeros_left + total_coeff - 1; - j = scantable[coeff_num]; - if(n > 24){ - block[j] = level[0]; - for(i=1;i>6; - for(i=1;i>6; - } - } - - if(zeros_left<0){ - av_log(h->s.avctx, AV_LOG_ERROR, "negative number of zero coeffs at %d %d\n", s->mb_x, s->mb_y); - return -1; - } - - return 0; -} - -static void predict_field_decoding_flag(H264Context *h){ +static int fill_filter_caches(H264Context *h, int mb_type){ MpegEncContext * const s = &h->s; const int mb_xy= h->mb_xy; - int mb_type = (h->slice_table[mb_xy-1] == h->slice_num) - ? s->current_picture.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] - : 0; - h->mb_mbaff = h->mb_field_decoding_flag = IS_INTERLACED(mb_type) ? 1 : 0; -} + int top_xy, left_xy[2]; + int top_type, left_type[2]; -/** - * decodes a P_SKIP or B_SKIP macroblock - */ -static void decode_mb_skip(H264Context *h){ - MpegEncContext * const s = &h->s; - const int mb_xy= h->mb_xy; - int mb_type=0; + top_xy = mb_xy - (s->mb_stride << MB_FIELD); - memset(h->non_zero_count[mb_xy], 0, 16); - memset(h->non_zero_count_cache + 8, 0, 8*5); //FIXME ugly, remove pfui + //FIXME deblocking could skip the intra and nnz parts. - if(MB_FIELD) - mb_type|= MB_TYPE_INTERLACED; + /* Wow, what a mess, why didn't they simplify the interlacing & intra + * stuff, I can't imagine that these complex rules are worth it. */ - if( h->slice_type_nos == FF_B_TYPE ) + left_xy[1] = left_xy[0] = mb_xy-1; + 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[0] -= s->mb_stride; + } + }else{ + if(curr_mb_field_flag){ + top_xy += s->mb_stride & (((s->current_picture.mb_type[top_xy ]>>7)&1)-1); + } + if (left_mb_field_flag != curr_mb_field_flag) { + left_xy[1] += s->mb_stride; + } + } + } + + h->top_mb_xy = top_xy; + h->left_mb_xy[0] = left_xy[0]; + h->left_mb_xy[1] = left_xy[1]; { - // just for fill_caches. pred_direct_motion will set the real mb_type - mb_type|= MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2|MB_TYPE_SKIP; - - fill_caches(h, mb_type, 0); //FIXME check what is needed and what not ... - 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_caches(h, mb_type, 0); //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; -} - -/** - * decodes a macroblock - * @returns 0 if OK, AC_ERROR / DC_ERROR / MV_ERROR if an error is noticed - */ -static int decode_mb_cavlc(H264Context *h){ - MpegEncContext * const s = &h->s; - int mb_xy; - int partition_count; - unsigned int mb_type, cbp; - int dct8x8_allowed= h->pps.transform_8x8_mode; - - mb_xy = h->mb_xy = s->mb_x + s->mb_y*s->mb_stride; - - tprintf(s->avctx, "pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y); - cbp = 0; /* avoid warning. FIXME: find a solution without slowing - down the code */ - if(h->slice_type_nos != FF_I_TYPE){ - if(s->mb_skip_run==-1) - s->mb_skip_run= get_ue_golomb(&s->gb); - - if (s->mb_skip_run--) { - if(FRAME_MBAFF && (s->mb_y&1) == 0){ - if(s->mb_skip_run==0) - h->mb_mbaff = h->mb_field_decoding_flag = get_bits1(&s->gb); - else - predict_field_decoding_flag(h); - } - decode_mb_skip(h); - return 0; - } - } - if(FRAME_MBAFF){ - if( (s->mb_y&1) == 0 ) - h->mb_mbaff = h->mb_field_decoding_flag = get_bits1(&s->gb); - } - - h->prev_mb_skipped= 0; - - mb_type= get_ue_golomb(&s->gb); - if(h->slice_type_nos == FF_B_TYPE){ - if(mb_type < 23){ - partition_count= b_mb_type_info[mb_type].partition_count; - mb_type= b_mb_type_info[mb_type].type; - }else{ - mb_type -= 23; - goto decode_intra_mb; - } - }else if(h->slice_type_nos == FF_P_TYPE){ - if(mb_type < 5){ - partition_count= p_mb_type_info[mb_type].partition_count; - mb_type= p_mb_type_info[mb_type].type; - }else{ - mb_type -= 5; - goto decode_intra_mb; - } - }else{ - assert(h->slice_type_nos == FF_I_TYPE); - if(h->slice_type == FF_SI_TYPE && mb_type) - mb_type--; -decode_intra_mb: - if(mb_type > 25){ - av_log(h->s.avctx, AV_LOG_ERROR, "mb_type %d in %c slice too large at %d %d\n", mb_type, av_get_pict_type_char(h->slice_type), s->mb_x, s->mb_y); - return -1; - } - partition_count=0; - cbp= i_mb_type_info[mb_type].cbp; - h->intra16x16_pred_mode= i_mb_type_info[mb_type].pred_mode; - mb_type= i_mb_type_info[mb_type].type; - } - - if(MB_FIELD) - mb_type |= MB_TYPE_INTERLACED; - - h->slice_table[ mb_xy ]= h->slice_num; - - if(IS_INTRA_PCM(mb_type)){ - unsigned int x; - - // We assume these blocks are very rare so we do not optimize it. - align_get_bits(&s->gb); - - // The pixels are stored in the same order as levels in h->mb array. - for(x=0; x < (CHROMA ? 384 : 256); x++){ - ((uint8_t*)h->mb)[x]= get_bits(&s->gb, 8); - } - - // In deblocking, the quantizer is 0 - s->current_picture.qscale_table[mb_xy]= 0; - // All coeffs are present - memset(h->non_zero_count[mb_xy], 16, 16); - - s->current_picture.mb_type[mb_xy]= mb_type; - return 0; - } - - if(MB_MBAFF){ - h->ref_count[0] <<= 1; - h->ref_count[1] <<= 1; - } - - fill_caches(h, mb_type, 0); - - //mb_pred - if(IS_INTRA(mb_type)){ - int pred_mode; -// init_top_left_availability(h); - if(IS_INTRA4x4(mb_type)){ - int i; - int di = 1; - if(dct8x8_allowed && get_bits1(&s->gb)){ - mb_type |= MB_TYPE_8x8DCT; - di = 4; - } - -// fill_intra4x4_pred_table(h); - for(i=0; i<16; i+=di){ - int mode= pred_intra_mode(h, i); - - if(!get_bits1(&s->gb)){ - const int rem_mode= get_bits(&s->gb, 3); - mode = rem_mode + (rem_mode >= mode); - } - - if(di==4) - fill_rectangle( &h->intra4x4_pred_mode_cache[ scan8[i] ], 2, 2, 8, mode, 1 ); - else - h->intra4x4_pred_mode_cache[ scan8[i] ] = mode; - } - write_back_intra_pred_mode(h); - if( check_intra4x4_pred_mode(h) < 0) - return -1; - }else{ - h->intra16x16_pred_mode= check_intra_pred_mode(h, h->intra16x16_pred_mode); - if(h->intra16x16_pred_mode < 0) - return -1; - } - if(CHROMA){ - pred_mode= check_intra_pred_mode(h, get_ue_golomb_31(&s->gb)); - if(pred_mode < 0) - return -1; - h->chroma_pred_mode= pred_mode; - } - }else if(partition_count==4){ - int i, j, sub_partition_count[4], list, ref[2][4]; - - if(h->slice_type_nos == FF_B_TYPE){ - for(i=0; i<4; i++){ - h->sub_mb_type[i]= get_ue_golomb_31(&s->gb); - if(h->sub_mb_type[i] >=13){ - av_log(h->s.avctx, AV_LOG_ERROR, "B sub_mb_type %u out of range at %d %d\n", h->sub_mb_type[i], s->mb_x, s->mb_y); - return -1; - } - sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; - h->sub_mb_type[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].type; - } - if( IS_DIRECT(h->sub_mb_type[0]) || IS_DIRECT(h->sub_mb_type[1]) - || IS_DIRECT(h->sub_mb_type[2]) || IS_DIRECT(h->sub_mb_type[3])) { - pred_direct_motion(h, &mb_type); - h->ref_cache[0][scan8[4]] = - h->ref_cache[1][scan8[4]] = - h->ref_cache[0][scan8[12]] = - h->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE; - } - }else{ - assert(h->slice_type_nos == FF_P_TYPE); //FIXME SP correct ? - for(i=0; i<4; i++){ - h->sub_mb_type[i]= get_ue_golomb_31(&s->gb); - if(h->sub_mb_type[i] >=4){ - av_log(h->s.avctx, AV_LOG_ERROR, "P sub_mb_type %u out of range at %d %d\n", h->sub_mb_type[i], s->mb_x, s->mb_y); - return -1; - } - sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; - h->sub_mb_type[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].type; - } - } - - for(list=0; listlist_count; list++){ - int ref_count= IS_REF0(mb_type) ? 1 : h->ref_count[list]; - for(i=0; i<4; i++){ - if(IS_DIRECT(h->sub_mb_type[i])) continue; - if(IS_DIR(h->sub_mb_type[i], 0, list)){ - unsigned int tmp; - if(ref_count == 1){ - tmp= 0; - }else if(ref_count == 2){ - tmp= get_bits1(&s->gb)^1; - }else{ - tmp= get_ue_golomb_31(&s->gb); - if(tmp>=ref_count){ - av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", tmp); - return -1; - } - } - ref[list][i]= tmp; - }else{ - //FIXME - ref[list][i] = -1; - } - } - } - - if(dct8x8_allowed) - dct8x8_allowed = get_dct8x8_allowed(h); - - for(list=0; listlist_count; list++){ - for(i=0; i<4; i++){ - if(IS_DIRECT(h->sub_mb_type[i])) { - h->ref_cache[list][ scan8[4*i] ] = h->ref_cache[list][ scan8[4*i]+1 ]; - continue; - } - h->ref_cache[list][ scan8[4*i] ]=h->ref_cache[list][ scan8[4*i]+1 ]= - h->ref_cache[list][ scan8[4*i]+8 ]=h->ref_cache[list][ scan8[4*i]+9 ]= ref[list][i]; - - if(IS_DIR(h->sub_mb_type[i], 0, list)){ - const int sub_mb_type= h->sub_mb_type[i]; - const int block_width= (sub_mb_type & (MB_TYPE_16x16|MB_TYPE_16x8)) ? 2 : 1; - for(j=0; jmv_cache[list][ scan8[index] ]; - pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my); - mx += get_se_golomb(&s->gb); - my += get_se_golomb(&s->gb); - tprintf(s->avctx, "final mv:%d %d\n", mx, my); - - if(IS_SUB_8X8(sub_mb_type)){ - mv_cache[ 1 ][0]= - mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx; - mv_cache[ 1 ][1]= - mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my; - }else if(IS_SUB_8X4(sub_mb_type)){ - mv_cache[ 1 ][0]= mx; - mv_cache[ 1 ][1]= my; - }else if(IS_SUB_4X8(sub_mb_type)){ - mv_cache[ 8 ][0]= mx; - mv_cache[ 8 ][1]= my; - } - mv_cache[ 0 ][0]= mx; - mv_cache[ 0 ][1]= my; - } - }else{ - uint32_t *p= (uint32_t *)&h->mv_cache[list][ scan8[4*i] ][0]; - p[0] = p[1]= - p[8] = p[9]= 0; - } - } - } - }else if(IS_DIRECT(mb_type)){ - pred_direct_motion(h, &mb_type); - dct8x8_allowed &= h->sps.direct_8x8_inference_flag; - }else{ - int list, mx, my, i; - //FIXME we should set ref_idx_l? to 0 if we use that later ... - if(IS_16X16(mb_type)){ - for(list=0; listlist_count; list++){ - unsigned int val; - if(IS_DIR(mb_type, 0, list)){ - if(h->ref_count[list]==1){ - val= 0; - }else if(h->ref_count[list]==2){ - val= get_bits1(&s->gb)^1; - }else{ - val= get_ue_golomb_31(&s->gb); - if(val >= h->ref_count[list]){ - av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", val); - return -1; - } - } - }else - val= LIST_NOT_USED&0xFF; - fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, val, 1); - } - for(list=0; listlist_count; list++){ - unsigned int val; - if(IS_DIR(mb_type, 0, list)){ - pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my); - mx += get_se_golomb(&s->gb); - my += get_se_golomb(&s->gb); - tprintf(s->avctx, "final mv:%d %d\n", mx, my); - - val= pack16to32(mx,my); - }else - val=0; - fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, val, 4); - } - } - else if(IS_16X8(mb_type)){ - for(list=0; listlist_count; list++){ - for(i=0; i<2; i++){ - unsigned int val; - if(IS_DIR(mb_type, i, list)){ - if(h->ref_count[list] == 1){ - val= 0; - }else if(h->ref_count[list] == 2){ - val= get_bits1(&s->gb)^1; - }else{ - val= get_ue_golomb_31(&s->gb); - if(val >= h->ref_count[list]){ - av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", val); - return -1; - } - } - }else - val= LIST_NOT_USED&0xFF; - fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, val, 1); - } - } - for(list=0; listlist_count; list++){ - for(i=0; i<2; i++){ - unsigned int val; - if(IS_DIR(mb_type, i, list)){ - pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my); - mx += get_se_golomb(&s->gb); - my += get_se_golomb(&s->gb); - tprintf(s->avctx, "final mv:%d %d\n", mx, my); - - val= pack16to32(mx,my); - }else - val=0; - fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, val, 4); - } - } - }else{ - assert(IS_8X16(mb_type)); - for(list=0; listlist_count; list++){ - for(i=0; i<2; i++){ - unsigned int val; - if(IS_DIR(mb_type, i, list)){ //FIXME optimize - if(h->ref_count[list]==1){ - val= 0; - }else if(h->ref_count[list]==2){ - val= get_bits1(&s->gb)^1; - }else{ - val= get_ue_golomb_31(&s->gb); - if(val >= h->ref_count[list]){ - av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", val); - return -1; - } - } - }else - val= LIST_NOT_USED&0xFF; - fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, val, 1); - } - } - for(list=0; listlist_count; list++){ - for(i=0; i<2; i++){ - unsigned int val; - if(IS_DIR(mb_type, i, list)){ - pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my); - mx += get_se_golomb(&s->gb); - my += get_se_golomb(&s->gb); - tprintf(s->avctx, "final mv:%d %d\n", mx, my); - - val= pack16to32(mx,my); - }else - val=0; - fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, val, 4); - } - } - } - } - - if(IS_INTER(mb_type)) - write_back_motion(h, mb_type); - - if(!IS_INTRA16x16(mb_type)){ - cbp= get_ue_golomb(&s->gb); - if(cbp > 47){ - av_log(h->s.avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\n", cbp, s->mb_x, s->mb_y); - return -1; - } - - if(CHROMA){ - if(IS_INTRA4x4(mb_type)) cbp= golomb_to_intra4x4_cbp[cbp]; - else cbp= golomb_to_inter_cbp [cbp]; - }else{ - if(IS_INTRA4x4(mb_type)) cbp= golomb_to_intra4x4_cbp_gray[cbp]; - else cbp= golomb_to_inter_cbp_gray[cbp]; - } - } - h->cbp = cbp; - - if(dct8x8_allowed && (cbp&15) && !IS_INTRA(mb_type)){ - if(get_bits1(&s->gb)){ - mb_type |= MB_TYPE_8x8DCT; - h->cbp_table[mb_xy]= cbp; - } - } - s->current_picture.mb_type[mb_xy]= mb_type; - - if(cbp || IS_INTRA16x16(mb_type)){ - int i8x8, i4x4, chroma_idx; - int dquant; - GetBitContext *gb= IS_INTRA(mb_type) ? h->intra_gb_ptr : h->inter_gb_ptr; - const uint8_t *scan, *scan8x8, *dc_scan; - -// fill_non_zero_count_cache(h); - - if(IS_INTERLACED(mb_type)){ - scan8x8= s->qscale ? h->field_scan8x8_cavlc : h->field_scan8x8_cavlc_q0; - scan= s->qscale ? h->field_scan : h->field_scan_q0; - dc_scan= luma_dc_field_scan; - }else{ - scan8x8= s->qscale ? h->zigzag_scan8x8_cavlc : h->zigzag_scan8x8_cavlc_q0; - scan= s->qscale ? h->zigzag_scan : h->zigzag_scan_q0; - dc_scan= luma_dc_zigzag_scan; - } - - dquant= get_se_golomb(&s->gb); - - if( dquant > 25 || dquant < -26 ){ - av_log(h->s.avctx, AV_LOG_ERROR, "dquant out of range (%d) at %d %d\n", dquant, s->mb_x, s->mb_y); - return -1; - } - - s->qscale += dquant; - if(((unsigned)s->qscale) > 51){ - if(s->qscale<0) s->qscale+= 52; - else s->qscale-= 52; - } - - h->chroma_qp[0]= get_chroma_qp(h, 0, s->qscale); - h->chroma_qp[1]= get_chroma_qp(h, 1, s->qscale); - if(IS_INTRA16x16(mb_type)){ - if( decode_residual(h, h->intra_gb_ptr, h->mb, LUMA_DC_BLOCK_INDEX, dc_scan, h->dequant4_coeff[0][s->qscale], 16) < 0){ - return -1; //FIXME continue if partitioned and other return -1 too - } - - assert((cbp&15) == 0 || (cbp&15) == 15); - - if(cbp&15){ - for(i8x8=0; i8x8<4; i8x8++){ - for(i4x4=0; i4x4<4; i4x4++){ - const int index= i4x4 + 4*i8x8; - if( decode_residual(h, h->intra_gb_ptr, h->mb + 16*index, index, scan + 1, h->dequant4_coeff[0][s->qscale], 15) < 0 ){ - return -1; - } - } - } - }else{ - fill_rectangle(&h->non_zero_count_cache[scan8[0]], 4, 4, 8, 0, 1); - } - }else{ - for(i8x8=0; i8x8<4; i8x8++){ - if(cbp & (1<mb[64*i8x8]; - uint8_t *nnz; - for(i4x4=0; i4x4<4; i4x4++){ - if( decode_residual(h, gb, buf, i4x4+4*i8x8, scan8x8+16*i4x4, - h->dequant8_coeff[IS_INTRA( mb_type ) ? 0:1][s->qscale], 16) <0 ) - return -1; - } - nnz= &h->non_zero_count_cache[ scan8[4*i8x8] ]; - nnz[0] += nnz[1] + nnz[8] + nnz[9]; - }else{ - for(i4x4=0; i4x4<4; i4x4++){ - const int index= i4x4 + 4*i8x8; - - if( decode_residual(h, gb, h->mb + 16*index, index, scan, h->dequant4_coeff[IS_INTRA( mb_type ) ? 0:3][s->qscale], 16) <0 ){ - return -1; - } - } - } - }else{ - uint8_t * const nnz= &h->non_zero_count_cache[ scan8[4*i8x8] ]; - nnz[0] = nnz[1] = nnz[8] = nnz[9] = 0; - } - } - } - - if(cbp&0x30){ - for(chroma_idx=0; chroma_idx<2; chroma_idx++) - if( decode_residual(h, gb, h->mb + 256 + 16*4*chroma_idx, CHROMA_DC_BLOCK_INDEX, chroma_dc_scan, NULL, 4) < 0){ - return -1; - } - } - - 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 + 4*chroma_idx + i4x4; - if( decode_residual(h, gb, h->mb + 16*index, index, scan + 1, qmul, 15) < 0){ - return -1; - } - } - } - }else{ - uint8_t * const nnz= &h->non_zero_count_cache[0]; - nnz[ scan8[16]+0 ] = nnz[ scan8[16]+1 ] =nnz[ scan8[16]+8 ] =nnz[ scan8[16]+9 ] = - nnz[ scan8[20]+0 ] = nnz[ scan8[20]+1 ] =nnz[ scan8[20]+8 ] =nnz[ scan8[20]+9 ] = 0; - } - }else{ - uint8_t * const nnz= &h->non_zero_count_cache[0]; - fill_rectangle(&nnz[scan8[0]], 4, 4, 8, 0, 1); - nnz[ scan8[16]+0 ] = nnz[ scan8[16]+1 ] =nnz[ scan8[16]+8 ] =nnz[ scan8[16]+9 ] = - nnz[ scan8[20]+0 ] = nnz[ scan8[20]+1 ] =nnz[ scan8[20]+8 ] =nnz[ scan8[20]+9 ] = 0; - } - s->current_picture.qscale_table[mb_xy]= s->qscale; - write_back_non_zero_count(h); - - if(MB_MBAFF){ - h->ref_count[0] >>= 1; - h->ref_count[1] >>= 1; - } - - return 0; -} - -static int decode_cabac_field_decoding_flag(H264Context *h) { - MpegEncContext * const s = &h->s; - const int mb_x = s->mb_x; - const int mb_y = s->mb_y & ~1; - const int mba_xy = mb_x - 1 + mb_y *s->mb_stride; - const int mbb_xy = mb_x + (mb_y-2)*s->mb_stride; - - unsigned int ctx = 0; - - if( h->slice_table[mba_xy] == h->slice_num && IS_INTERLACED( s->current_picture.mb_type[mba_xy] ) ) { - ctx += 1; - } - if( h->slice_table[mbb_xy] == h->slice_num && IS_INTERLACED( s->current_picture.mb_type[mbb_xy] ) ) { - ctx += 1; - } - - return get_cabac_noinline( &h->cabac, &h->cabac_state[70 + ctx] ); -} - -static int decode_cabac_intra_mb_type(H264Context *h, int ctx_base, int intra_slice) { - uint8_t *state= &h->cabac_state[ctx_base]; - int mb_type; - - if(intra_slice){ - MpegEncContext * const s = &h->s; - const int mba_xy = h->left_mb_xy[0]; - const int mbb_xy = h->top_mb_xy; - int ctx=0; - if( h->slice_table[mba_xy] == h->slice_num && !IS_INTRA4x4( s->current_picture.mb_type[mba_xy] ) ) - ctx++; - if( h->slice_table[mbb_xy] == h->slice_num && !IS_INTRA4x4( s->current_picture.mb_type[mbb_xy] ) ) - ctx++; - if( get_cabac_noinline( &h->cabac, &state[ctx] ) == 0 ) - return 0; /* I4x4 */ - state += 2; - }else{ - if( get_cabac_noinline( &h->cabac, &state[0] ) == 0 ) - return 0; /* I4x4 */ - } - - if( get_cabac_terminate( &h->cabac ) ) - return 25; /* PCM */ - - mb_type = 1; /* I16x16 */ - mb_type += 12 * get_cabac_noinline( &h->cabac, &state[1] ); /* cbp_luma != 0 */ - if( get_cabac_noinline( &h->cabac, &state[2] ) ) /* cbp_chroma */ - mb_type += 4 + 4 * get_cabac_noinline( &h->cabac, &state[2+intra_slice] ); - mb_type += 2 * get_cabac_noinline( &h->cabac, &state[3+intra_slice] ); - mb_type += 1 * get_cabac_noinline( &h->cabac, &state[3+2*intra_slice] ); - return mb_type; -} - -static int decode_cabac_mb_type_b( H264Context *h ) { - MpegEncContext * const s = &h->s; - - const int mba_xy = h->left_mb_xy[0]; - const int mbb_xy = h->top_mb_xy; - int ctx = 0; - int bits; - assert(h->slice_type_nos == FF_B_TYPE); - - if( h->slice_table[mba_xy] == h->slice_num && !IS_DIRECT( s->current_picture.mb_type[mba_xy] ) ) - ctx++; - if( h->slice_table[mbb_xy] == h->slice_num && !IS_DIRECT( s->current_picture.mb_type[mbb_xy] ) ) - ctx++; - - if( !get_cabac_noinline( &h->cabac, &h->cabac_state[27+ctx] ) ) - return 0; /* B_Direct_16x16 */ - - if( !get_cabac_noinline( &h->cabac, &h->cabac_state[27+3] ) ) { - return 1 + get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] ); /* B_L[01]_16x16 */ - } - - bits = get_cabac_noinline( &h->cabac, &h->cabac_state[27+4] ) << 3; - bits|= get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] ) << 2; - bits|= get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] ) << 1; - bits|= get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] ); - if( bits < 8 ) - return bits + 3; /* B_Bi_16x16 through B_L1_L0_16x8 */ - else if( bits == 13 ) { - return decode_cabac_intra_mb_type(h, 32, 0) + 23; - } else if( bits == 14 ) - return 11; /* B_L1_L0_8x16 */ - else if( bits == 15 ) - return 22; /* B_8x8 */ - - bits= ( bits<<1 ) | get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] ); - return bits - 4; /* B_L0_Bi_* through B_Bi_Bi_* */ -} - -static int decode_cabac_mb_skip( H264Context *h, int mb_x, int mb_y ) { - MpegEncContext * const s = &h->s; - int mba_xy, mbb_xy; - int ctx = 0; - - if(FRAME_MBAFF){ //FIXME merge with the stuff in fill_caches? - int mb_xy = mb_x + (mb_y&~1)*s->mb_stride; - 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] ) ) - 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] ) ) - mbb_xy -= s->mb_stride; - }else - mbb_xy = mb_x + (mb_y-1)*s->mb_stride; - }else{ - int mb_xy = h->mb_xy; - mba_xy = mb_xy - 1; - 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] )) - ctx++; - if( h->slice_table[mbb_xy] == h->slice_num && !IS_SKIP( s->current_picture.mb_type[mbb_xy] )) - ctx++; - - if( h->slice_type_nos == FF_B_TYPE ) - ctx += 13; - return get_cabac_noinline( &h->cabac, &h->cabac_state[11+ctx] ); -} - -static int decode_cabac_mb_intra4x4_pred_mode( H264Context *h, int pred_mode ) { - int mode = 0; - - if( get_cabac( &h->cabac, &h->cabac_state[68] ) ) - return pred_mode; - - mode += 1 * get_cabac( &h->cabac, &h->cabac_state[69] ); - mode += 2 * get_cabac( &h->cabac, &h->cabac_state[69] ); - mode += 4 * get_cabac( &h->cabac, &h->cabac_state[69] ); - - if( mode >= pred_mode ) - return mode + 1; - else - return mode; -} - -static int decode_cabac_mb_chroma_pre_mode( H264Context *h) { - const int mba_xy = h->left_mb_xy[0]; - const int mbb_xy = h->top_mb_xy; - - int ctx = 0; - - /* No need to test for IS_INTRA4x4 and IS_INTRA16x16, as we set chroma_pred_mode_table to 0 */ - if( h->slice_table[mba_xy] == h->slice_num && h->chroma_pred_mode_table[mba_xy] != 0 ) - ctx++; - - if( h->slice_table[mbb_xy] == h->slice_num && h->chroma_pred_mode_table[mbb_xy] != 0 ) - ctx++; - - if( get_cabac_noinline( &h->cabac, &h->cabac_state[64+ctx] ) == 0 ) - return 0; - - if( get_cabac_noinline( &h->cabac, &h->cabac_state[64+3] ) == 0 ) - return 1; - if( get_cabac_noinline( &h->cabac, &h->cabac_state[64+3] ) == 0 ) - return 2; - else - return 3; -} - -static int decode_cabac_mb_cbp_luma( H264Context *h) { - int cbp_b, cbp_a, ctx, cbp = 0; - - cbp_a = h->slice_table[h->left_mb_xy[0]] == h->slice_num ? h->left_cbp : -1; - cbp_b = h->slice_table[h->top_mb_xy] == h->slice_num ? h->top_cbp : -1; - - ctx = !(cbp_a & 0x02) + 2 * !(cbp_b & 0x04); - cbp |= get_cabac_noinline(&h->cabac, &h->cabac_state[73 + ctx]); - ctx = !(cbp & 0x01) + 2 * !(cbp_b & 0x08); - cbp |= get_cabac_noinline(&h->cabac, &h->cabac_state[73 + ctx]) << 1; - ctx = !(cbp_a & 0x08) + 2 * !(cbp & 0x01); - cbp |= get_cabac_noinline(&h->cabac, &h->cabac_state[73 + ctx]) << 2; - ctx = !(cbp & 0x04) + 2 * !(cbp & 0x02); - cbp |= get_cabac_noinline(&h->cabac, &h->cabac_state[73 + ctx]) << 3; - return cbp; -} -static int decode_cabac_mb_cbp_chroma( H264Context *h) { - int ctx; - int cbp_a, cbp_b; - - cbp_a = (h->left_cbp>>4)&0x03; - cbp_b = (h-> top_cbp>>4)&0x03; - - ctx = 0; - if( cbp_a > 0 ) ctx++; - if( cbp_b > 0 ) ctx += 2; - if( get_cabac_noinline( &h->cabac, &h->cabac_state[77 + ctx] ) == 0 ) - return 0; - - ctx = 4; - if( cbp_a == 2 ) ctx++; - if( cbp_b == 2 ) ctx += 2; - return 1 + get_cabac_noinline( &h->cabac, &h->cabac_state[77 + ctx] ); -} -static int decode_cabac_mb_dqp( H264Context *h) { - int ctx= h->last_qscale_diff != 0; - int val = 0; - - while( get_cabac_noinline( &h->cabac, &h->cabac_state[60 + ctx] ) ) { - ctx= 2+(ctx>>1); - val++; - if(val > 102) //prevent infinite loop - return INT_MIN; - } - - if( val&0x01 ) - return (val + 1)>>1 ; - else - return -((val + 1)>>1); -} -static int decode_cabac_p_mb_sub_type( H264Context *h ) { - if( get_cabac( &h->cabac, &h->cabac_state[21] ) ) - return 0; /* 8x8 */ - if( !get_cabac( &h->cabac, &h->cabac_state[22] ) ) - return 1; /* 8x4 */ - if( get_cabac( &h->cabac, &h->cabac_state[23] ) ) - return 2; /* 4x8 */ - return 3; /* 4x4 */ -} -static int decode_cabac_b_mb_sub_type( H264Context *h ) { - int type; - if( !get_cabac( &h->cabac, &h->cabac_state[36] ) ) - return 0; /* B_Direct_8x8 */ - if( !get_cabac( &h->cabac, &h->cabac_state[37] ) ) - return 1 + get_cabac( &h->cabac, &h->cabac_state[39] ); /* B_L0_8x8, B_L1_8x8 */ - type = 3; - if( get_cabac( &h->cabac, &h->cabac_state[38] ) ) { - if( get_cabac( &h->cabac, &h->cabac_state[39] ) ) - return 11 + get_cabac( &h->cabac, &h->cabac_state[39] ); /* B_L1_4x4, B_Bi_4x4 */ - type += 4; - } - type += 2*get_cabac( &h->cabac, &h->cabac_state[39] ); - type += get_cabac( &h->cabac, &h->cabac_state[39] ); - return type; -} - -static inline int decode_cabac_mb_transform_size( H264Context *h ) { - return get_cabac_noinline( &h->cabac, &h->cabac_state[399 + h->neighbor_transform_size] ); -} - -static int decode_cabac_mb_ref( H264Context *h, int list, int n ) { - int refa = h->ref_cache[list][scan8[n] - 1]; - int refb = h->ref_cache[list][scan8[n] - 8]; - int ref = 0; - int ctx = 0; - - if( h->slice_type_nos == FF_B_TYPE) { - if( refa > 0 && !h->direct_cache[scan8[n] - 1] ) - ctx++; - if( refb > 0 && !h->direct_cache[scan8[n] - 8] ) - ctx += 2; - } else { - if( refa > 0 ) - ctx++; - if( refb > 0 ) - ctx += 2; - } - - while( get_cabac( &h->cabac, &h->cabac_state[54+ctx] ) ) { - ref++; - ctx = (ctx>>2)+4; - if(ref >= 32 /*h->ref_list[list]*/){ - return -1; - } - } - return ref; -} - -static int decode_cabac_mb_mvd( H264Context *h, int list, int n, int l ) { - int amvd = abs( h->mvd_cache[list][scan8[n] - 1][l] ) + - abs( h->mvd_cache[list][scan8[n] - 8][l] ); - int ctxbase = (l == 0) ? 40 : 47; - int mvd; - int ctx = (amvd>2) + (amvd>32); - - if(!get_cabac(&h->cabac, &h->cabac_state[ctxbase+ctx])) - return 0; - - mvd= 1; - ctx= 3; - while( mvd < 9 && get_cabac( &h->cabac, &h->cabac_state[ctxbase+ctx] ) ) { - mvd++; - if( ctx < 6 ) - ctx++; - } - - if( mvd >= 9 ) { - int k = 3; - while( get_cabac_bypass( &h->cabac ) ) { - mvd += 1 << k; - k++; - if(k>24){ - av_log(h->s.avctx, AV_LOG_ERROR, "overflow in decode_cabac_mb_mvd\n"); - return INT_MIN; - } - } - while( k-- ) { - if( get_cabac_bypass( &h->cabac ) ) - mvd += 1 << k; - } - } - return get_cabac_bypass_sign( &h->cabac, -mvd ); -} - -static av_always_inline int get_cabac_cbf_ctx( H264Context *h, int cat, int idx, int is_dc ) { - int nza, nzb; - int ctx = 0; - - if( is_dc ) { - if( cat == 0 ) { - nza = h->left_cbp&0x100; - nzb = h-> top_cbp&0x100; - } else { - nza = (h->left_cbp>>(6+idx))&0x01; - nzb = (h-> top_cbp>>(6+idx))&0x01; - } - } else { - assert(cat == 1 || cat == 2 || cat == 4); - nza = h->non_zero_count_cache[scan8[idx] - 1]; - nzb = h->non_zero_count_cache[scan8[idx] - 8]; - } - - if( nza > 0 ) - ctx++; - - if( nzb > 0 ) - ctx += 2; - - return ctx + 4 * cat; -} - -DECLARE_ASM_CONST(1, uint8_t, last_coeff_flag_offset_8x8[63]) = { - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, - 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 const int significant_coeff_flag_offset[2][6] = { - { 105+0, 105+15, 105+29, 105+44, 105+47, 402 }, - { 277+0, 277+15, 277+29, 277+44, 277+47, 436 } - }; - static const int last_coeff_flag_offset[2][6] = { - { 166+0, 166+15, 166+29, 166+44, 166+47, 417 }, - { 338+0, 338+15, 338+29, 338+44, 338+47, 451 } - }; - static const int coeff_abs_level_m1_offset[6] = { - 227+0, 227+10, 227+20, 227+30, 227+39, 426 - }; - static const uint8_t significant_coeff_flag_offset_8x8[2][63] = { - { 0, 1, 2, 3, 4, 5, 5, 4, 4, 3, 3, 4, 4, 4, 5, 5, - 4, 4, 4, 4, 3, 3, 6, 7, 7, 7, 8, 9,10, 9, 8, 7, - 7, 6,11,12,13,11, 6, 7, 8, 9,14,10, 9, 8, 6,11, - 12,13,11, 6, 9,14,10, 9,11,12,13,11,14,10,12 }, - { 0, 1, 1, 2, 2, 3, 3, 4, 5, 6, 7, 7, 7, 8, 4, 5, - 6, 9,10,10, 8,11,12,11, 9, 9,10,10, 8,11,12,11, - 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 } - }; - /* 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_level_transition[2][8] = { - /* update node ctx after decoding a level=1 */ - { 1, 2, 3, 3, 4, 5, 6, 7 }, - /* update node ctx after decoding a level>1 */ - { 4, 4, 4, 4, 5, 6, 7, 7 } - }; - - int index[64]; - - int av_unused last; - int coeff_count = 0; - int node_ctx = 0; - - uint8_t *significant_coeff_ctx_base; - uint8_t *last_coeff_ctx_base; - uint8_t *abs_level_m1_ctx_base; - -#if !ARCH_X86 -#define CABAC_ON_STACK -#endif -#ifdef CABAC_ON_STACK -#define CC &cc - CABACContext cc; - cc.range = h->cabac.range; - cc.low = h->cabac.low; - cc.bytestream= h->cabac.bytestream; -#else -#define CC &h->cabac -#endif - - - /* cat: 0-> DC 16x16 n = 0 - * 1-> AC 16x16 n = luma4x4idx - * 2-> Luma4x4 n = luma4x4idx - * 3-> DC Chroma n = iCbCr - * 4-> AC Chroma n = 16 + 4 * iCbCr + chroma4x4idx - * 5-> Luma8x8 n = 4 * luma8x8idx - */ - - /* read coded block flag */ - if( is_dc || cat != 5 ) { - if( get_cabac( CC, &h->cabac_state[85 + get_cabac_cbf_ctx( h, cat, n, is_dc ) ] ) == 0 ) { - if( !is_dc ) - h->non_zero_count_cache[scan8[n]] = 0; - -#ifdef CABAC_ON_STACK - h->cabac.range = cc.range ; - h->cabac.low = cc.low ; - h->cabac.bytestream= cc.bytestream; -#endif - return; - } - } - - significant_coeff_ctx_base = h->cabac_state - + significant_coeff_flag_offset[MB_FIELD][cat]; - last_coeff_ctx_base = h->cabac_state - + last_coeff_flag_offset[MB_FIELD][cat]; - abs_level_m1_ctx_base = h->cabac_state - + coeff_abs_level_m1_offset[cat]; - - if( !is_dc && cat == 5 ) { -#define DECODE_SIGNIFICANCE( coefs, sig_off, last_off ) \ - for(last= 0; last < coefs; last++) { \ - uint8_t *sig_ctx = significant_coeff_ctx_base + sig_off; \ - if( get_cabac( CC, sig_ctx )) { \ - uint8_t *last_ctx = last_coeff_ctx_base + last_off; \ - index[coeff_count++] = last; \ - if( get_cabac( CC, last_ctx ) ) { \ - last= max_coeff; \ - break; \ - } \ - } \ - }\ - if( last == max_coeff -1 ) {\ - index[coeff_count++] = last;\ - } - 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, sig_off); - } else { - coeff_count= decode_significance_x86(CC, max_coeff, significant_coeff_ctx_base, index); -#else - DECODE_SIGNIFICANCE( 63, sig_off[last], last_coeff_flag_offset_8x8[last] ); - } else { - DECODE_SIGNIFICANCE( max_coeff - 1, last, last ); -#endif - } - assert(coeff_count > 0); - - if( is_dc ) { - if( cat == 0 ) - h->cbp_table[h->mb_xy] |= 0x100; - else - h->cbp_table[h->mb_xy] |= 0x40 << n; - } else { - if( cat == 5 ) - fill_rectangle(&h->non_zero_count_cache[scan8[n]], 2, 2, 8, coeff_count, 1); - else { - assert( cat == 1 || cat == 2 || cat == 4 ); - h->non_zero_count_cache[scan8[n]] = coeff_count; - } - } - - do { - uint8_t *ctx = coeff_abs_level1_ctx[node_ctx] + abs_level_m1_ctx_base; - - int j= scantable[index[--coeff_count]]; - - if( get_cabac( CC, ctx ) == 0 ) { - node_ctx = coeff_abs_level_transition[0][node_ctx]; - if( is_dc ) { - block[j] = get_cabac_bypass_sign( CC, -1); - }else{ - block[j] = (get_cabac_bypass_sign( CC, -qmul[j]) + 32) >> 6; - } - } else { - int coeff_abs = 2; - ctx = coeff_abs_levelgt1_ctx[node_ctx] + abs_level_m1_ctx_base; - node_ctx = coeff_abs_level_transition[1][node_ctx]; - - while( coeff_abs < 15 && get_cabac( CC, ctx ) ) { - coeff_abs++; - } - - if( coeff_abs >= 15 ) { - int j = 0; - while( get_cabac_bypass( CC ) ) { - j++; - } - - coeff_abs=1; - while( j-- ) { - coeff_abs += coeff_abs + get_cabac_bypass( CC ); - } - coeff_abs+= 14; - } - - if( is_dc ) { - block[j] = get_cabac_bypass_sign( CC, -coeff_abs ); - }else{ - block[j] = (get_cabac_bypass_sign( CC, -coeff_abs ) * qmul[j] + 32) >> 6; - } - } - } while( coeff_count ); -#ifdef CABAC_ON_STACK - h->cabac.range = cc.range ; - h->cabac.low = cc.low ; - h->cabac.bytestream= cc.bytestream; -#endif - -} - -#if !CONFIG_SMALL -static void decode_cabac_residual_dc( 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, 1); -} - -static void decode_cabac_residual_nondc( 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); -} -#endif - -static void decode_cabac_residual( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff ) { -#if CONFIG_SMALL - decode_cabac_residual_internal(h, block, cat, n, scantable, qmul, max_coeff, cat == 0 || cat == 3); -#else - if( cat == 0 || cat == 3 ) decode_cabac_residual_dc(h, block, cat, n, scantable, qmul, max_coeff); - else decode_cabac_residual_nondc(h, block, cat, n, scantable, qmul, max_coeff); -#endif -} - -static inline void compute_mb_neighbors(H264Context *h) -{ - MpegEncContext * const s = &h->s; - const int mb_xy = h->mb_xy; - h->top_mb_xy = mb_xy - s->mb_stride; - h->left_mb_xy[0] = mb_xy - 1; - if(FRAME_MBAFF){ - const int pair_xy = s->mb_x + (s->mb_y & ~1)*s->mb_stride; - const int top_pair_xy = pair_xy - s->mb_stride; - const int top_mb_field_flag = IS_INTERLACED(s->current_picture.mb_type[top_pair_xy]); - const int left_mb_field_flag = IS_INTERLACED(s->current_picture.mb_type[pair_xy-1]); - const int curr_mb_field_flag = MB_FIELD; - const int bottom = (s->mb_y & 1); - - if (curr_mb_field_flag && (bottom || top_mb_field_flag)){ - h->top_mb_xy -= s->mb_stride; - } - if (!left_mb_field_flag == curr_mb_field_flag) { - h->left_mb_xy[0] = pair_xy - 1; - } - } else if (FIELD_PICTURE) { - h->top_mb_xy -= s->mb_stride; - } - return; -} - -/** - * decodes a macroblock - * @returns 0 if OK, AC_ERROR / DC_ERROR / MV_ERROR if an error is noticed - */ -static int decode_mb_cabac(H264Context *h) { - MpegEncContext * const s = &h->s; - int mb_xy; - int mb_type, partition_count, cbp = 0; - int dct8x8_allowed= h->pps.transform_8x8_mode; - - mb_xy = h->mb_xy = s->mb_x + s->mb_y*s->mb_stride; - - tprintf(s->avctx, "pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y); - if( h->slice_type_nos != FF_I_TYPE ) { - int skip; - /* a skipped mb needs the aff flag from the following mb */ - if( FRAME_MBAFF && s->mb_x==0 && (s->mb_y&1)==0 ) - predict_field_decoding_flag(h); - if( FRAME_MBAFF && (s->mb_y&1)==1 && h->prev_mb_skipped ) - skip = h->next_mb_skipped; - else - skip = decode_cabac_mb_skip( h, s->mb_x, s->mb_y ); - /* read skip flags */ - if( skip ) { - if( FRAME_MBAFF && (s->mb_y&1)==0 ){ - s->current_picture.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); - } - - decode_mb_skip(h); - - h->cbp_table[mb_xy] = 0; - h->chroma_pred_mode_table[mb_xy] = 0; - h->last_qscale_diff = 0; - - return 0; - - } - } - if(FRAME_MBAFF){ - if( (s->mb_y&1) == 0 ) - h->mb_mbaff = - h->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h); - } - - h->prev_mb_skipped = 0; - - compute_mb_neighbors(h); - - if( h->slice_type_nos == FF_B_TYPE ) { - mb_type = decode_cabac_mb_type_b( h ); - if( mb_type < 23 ){ - partition_count= b_mb_type_info[mb_type].partition_count; - mb_type= b_mb_type_info[mb_type].type; - }else{ - mb_type -= 23; - goto decode_intra_mb; - } - } else if( h->slice_type_nos == FF_P_TYPE ) { - if( get_cabac_noinline( &h->cabac, &h->cabac_state[14] ) == 0 ) { - /* P-type */ - if( get_cabac_noinline( &h->cabac, &h->cabac_state[15] ) == 0 ) { - /* P_L0_D16x16, P_8x8 */ - mb_type= 3 * get_cabac_noinline( &h->cabac, &h->cabac_state[16] ); - } else { - /* P_L0_D8x16, P_L0_D16x8 */ - mb_type= 2 - get_cabac_noinline( &h->cabac, &h->cabac_state[17] ); - } - partition_count= p_mb_type_info[mb_type].partition_count; - mb_type= p_mb_type_info[mb_type].type; - } else { - mb_type= decode_cabac_intra_mb_type(h, 17, 0); - goto decode_intra_mb; - } - } else { - mb_type= decode_cabac_intra_mb_type(h, 3, 1); - if(h->slice_type == FF_SI_TYPE && mb_type) - mb_type--; - assert(h->slice_type_nos == FF_I_TYPE); -decode_intra_mb: - partition_count = 0; - cbp= i_mb_type_info[mb_type].cbp; - h->intra16x16_pred_mode= i_mb_type_info[mb_type].pred_mode; - mb_type= i_mb_type_info[mb_type].type; - } - if(MB_FIELD) - mb_type |= MB_TYPE_INTERLACED; - - h->slice_table[ mb_xy ]= h->slice_num; - - if(IS_INTRA_PCM(mb_type)) { - const uint8_t *ptr; - - // We assume these blocks are very rare so we do not optimize it. - // FIXME The two following lines get the bitstream position in the cabac - // decode, I think it should be done by a function in cabac.h (or cabac.c). - ptr= h->cabac.bytestream; - if(h->cabac.low&0x1) ptr--; - if(CABAC_BITS==16){ - if(h->cabac.low&0x1FF) ptr--; - } - - // The pixels are stored in the same order as levels in h->mb array. - memcpy(h->mb, ptr, 256); ptr+=256; - if(CHROMA){ - memcpy(h->mb+128, ptr, 128); ptr+=128; - } - - ff_init_cabac_decoder(&h->cabac, ptr, h->cabac.bytestream_end - ptr); - - // All blocks are present - h->cbp_table[mb_xy] = 0x1ef; - h->chroma_pred_mode_table[mb_xy] = 0; - // In deblocking, the quantizer is 0 - s->current_picture.qscale_table[mb_xy]= 0; - // All coeffs are present - memset(h->non_zero_count[mb_xy], 16, 16); - s->current_picture.mb_type[mb_xy]= mb_type; - h->last_qscale_diff = 0; - return 0; - } - - if(MB_MBAFF){ - h->ref_count[0] <<= 1; - h->ref_count[1] <<= 1; - } - - fill_caches(h, mb_type, 0); - - if( IS_INTRA( mb_type ) ) { - int i, pred_mode; - if( IS_INTRA4x4( mb_type ) ) { - if( dct8x8_allowed && decode_cabac_mb_transform_size( h ) ) { - mb_type |= MB_TYPE_8x8DCT; - for( i = 0; i < 16; i+=4 ) { - int pred = pred_intra_mode( h, i ); - int mode = decode_cabac_mb_intra4x4_pred_mode( h, pred ); - fill_rectangle( &h->intra4x4_pred_mode_cache[ scan8[i] ], 2, 2, 8, mode, 1 ); - } - } else { - for( i = 0; i < 16; i++ ) { - int pred = pred_intra_mode( h, i ); - h->intra4x4_pred_mode_cache[ scan8[i] ] = decode_cabac_mb_intra4x4_pred_mode( h, pred ); - - //av_log( s->avctx, AV_LOG_ERROR, "i4x4 pred=%d mode=%d\n", pred, h->intra4x4_pred_mode_cache[ scan8[i] ] ); - } - } - write_back_intra_pred_mode(h); - if( check_intra4x4_pred_mode(h) < 0 ) return -1; - } else { - h->intra16x16_pred_mode= check_intra_pred_mode( h, h->intra16x16_pred_mode ); - if( h->intra16x16_pred_mode < 0 ) return -1; - } - if(CHROMA){ - h->chroma_pred_mode_table[mb_xy] = - pred_mode = decode_cabac_mb_chroma_pre_mode( h ); - - pred_mode= check_intra_pred_mode( h, pred_mode ); - if( pred_mode < 0 ) return -1; - h->chroma_pred_mode= pred_mode; - } - } else if( partition_count == 4 ) { - int i, j, sub_partition_count[4], list, ref[2][4]; - - if( h->slice_type_nos == FF_B_TYPE ) { - for( i = 0; i < 4; i++ ) { - h->sub_mb_type[i] = decode_cabac_b_mb_sub_type( h ); - sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; - h->sub_mb_type[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].type; - } - if( IS_DIRECT(h->sub_mb_type[0] | h->sub_mb_type[1] | - h->sub_mb_type[2] | h->sub_mb_type[3]) ) { - pred_direct_motion(h, &mb_type); - h->ref_cache[0][scan8[4]] = - h->ref_cache[1][scan8[4]] = - h->ref_cache[0][scan8[12]] = - h->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE; - if( h->ref_count[0] > 1 || h->ref_count[1] > 1 ) { - for( i = 0; i < 4; i++ ) - if( IS_DIRECT(h->sub_mb_type[i]) ) - fill_rectangle( &h->direct_cache[scan8[4*i]], 2, 2, 8, 1, 1 ); - } - } - } else { - for( i = 0; i < 4; i++ ) { - h->sub_mb_type[i] = decode_cabac_p_mb_sub_type( h ); - sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; - h->sub_mb_type[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].type; - } - } - - for( list = 0; list < h->list_count; list++ ) { - for( i = 0; i < 4; i++ ) { - if(IS_DIRECT(h->sub_mb_type[i])) continue; - if(IS_DIR(h->sub_mb_type[i], 0, list)){ - if( h->ref_count[list] > 1 ){ - ref[list][i] = decode_cabac_mb_ref( h, list, 4*i ); - if(ref[list][i] >= (unsigned)h->ref_count[list]){ - av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref[list][i], h->ref_count[list]); - return -1; - } - }else - ref[list][i] = 0; - } else { - ref[list][i] = -1; - } - h->ref_cache[list][ scan8[4*i]+1 ]= - h->ref_cache[list][ scan8[4*i]+8 ]=h->ref_cache[list][ scan8[4*i]+9 ]= ref[list][i]; - } - } - - if(dct8x8_allowed) - dct8x8_allowed = get_dct8x8_allowed(h); - - for(list=0; listlist_count; list++){ - for(i=0; i<4; i++){ - h->ref_cache[list][ scan8[4*i] ]=h->ref_cache[list][ scan8[4*i]+1 ]; - if(IS_DIRECT(h->sub_mb_type[i])){ - fill_rectangle(h->mvd_cache[list][scan8[4*i]], 2, 2, 8, 0, 4); - continue; - } - - if(IS_DIR(h->sub_mb_type[i], 0, list) && !IS_DIRECT(h->sub_mb_type[i])){ - const int sub_mb_type= h->sub_mb_type[i]; - const int block_width= (sub_mb_type & (MB_TYPE_16x16|MB_TYPE_16x8)) ? 2 : 1; - for(j=0; jmv_cache[list][ scan8[index] ]; - int16_t (* mvd_cache)[2]= &h->mvd_cache[list][ scan8[index] ]; - pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mpx, &mpy); - - mx = mpx + decode_cabac_mb_mvd( h, list, index, 0 ); - my = mpy + decode_cabac_mb_mvd( h, list, index, 1 ); - tprintf(s->avctx, "final mv:%d %d\n", mx, my); - - if(IS_SUB_8X8(sub_mb_type)){ - mv_cache[ 1 ][0]= - mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx; - mv_cache[ 1 ][1]= - mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my; - - mvd_cache[ 1 ][0]= - mvd_cache[ 8 ][0]= mvd_cache[ 9 ][0]= mx - mpx; - mvd_cache[ 1 ][1]= - mvd_cache[ 8 ][1]= mvd_cache[ 9 ][1]= my - mpy; - }else if(IS_SUB_8X4(sub_mb_type)){ - mv_cache[ 1 ][0]= mx; - mv_cache[ 1 ][1]= my; - - mvd_cache[ 1 ][0]= mx - mpx; - mvd_cache[ 1 ][1]= my - mpy; - }else if(IS_SUB_4X8(sub_mb_type)){ - mv_cache[ 8 ][0]= mx; - mv_cache[ 8 ][1]= my; - - mvd_cache[ 8 ][0]= mx - mpx; - mvd_cache[ 8 ][1]= my - mpy; - } - mv_cache[ 0 ][0]= mx; - mv_cache[ 0 ][1]= my; - - mvd_cache[ 0 ][0]= mx - mpx; - mvd_cache[ 0 ][1]= my - mpy; - } - }else{ - uint32_t *p= (uint32_t *)&h->mv_cache[list][ scan8[4*i] ][0]; - uint32_t *pd= (uint32_t *)&h->mvd_cache[list][ scan8[4*i] ][0]; - p[0] = p[1] = p[8] = p[9] = 0; - pd[0]= pd[1]= pd[8]= pd[9]= 0; - } - } - } - } else if( IS_DIRECT(mb_type) ) { - pred_direct_motion(h, &mb_type); - fill_rectangle(h->mvd_cache[0][scan8[0]], 4, 4, 8, 0, 4); - fill_rectangle(h->mvd_cache[1][scan8[0]], 4, 4, 8, 0, 4); - dct8x8_allowed &= h->sps.direct_8x8_inference_flag; - } else { - int list, mx, my, i, mpx, mpy; - if(IS_16X16(mb_type)){ - for(list=0; listlist_count; list++){ - if(IS_DIR(mb_type, 0, list)){ - int ref; - if(h->ref_count[list] > 1){ - ref= decode_cabac_mb_ref(h, list, 0); - if(ref >= (unsigned)h->ref_count[list]){ - av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref, h->ref_count[list]); - return -1; - } - }else - ref=0; - fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, ref, 1); - }else - fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, (uint8_t)LIST_NOT_USED, 1); //FIXME factorize and the other fill_rect below too - } - for(list=0; listlist_count; list++){ - if(IS_DIR(mb_type, 0, list)){ - pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mpx, &mpy); - - mx = mpx + decode_cabac_mb_mvd( h, list, 0, 0 ); - my = mpy + decode_cabac_mb_mvd( h, list, 0, 1 ); - tprintf(s->avctx, "final mv:%d %d\n", mx, my); - - fill_rectangle(h->mvd_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx-mpx,my-mpy), 4); - fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4); - }else - fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, 0, 4); - } - } - else if(IS_16X8(mb_type)){ - for(list=0; listlist_count; list++){ - for(i=0; i<2; i++){ - if(IS_DIR(mb_type, i, list)){ - int ref; - if(h->ref_count[list] > 1){ - ref= decode_cabac_mb_ref( h, list, 8*i ); - if(ref >= (unsigned)h->ref_count[list]){ - av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref, h->ref_count[list]); - return -1; - } - }else - ref=0; - fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, ref, 1); - }else - fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, (LIST_NOT_USED&0xFF), 1); - } - } - for(list=0; listlist_count; list++){ - for(i=0; i<2; i++){ - if(IS_DIR(mb_type, i, list)){ - pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mpx, &mpy); - mx = mpx + decode_cabac_mb_mvd( h, list, 8*i, 0 ); - my = mpy + decode_cabac_mb_mvd( h, list, 8*i, 1 ); - tprintf(s->avctx, "final mv:%d %d\n", mx, my); - - fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx-mpx,my-mpy), 4); - fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx,my), 4); - }else{ - fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 4); - fill_rectangle(h-> mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 4); - } - } - } - }else{ - assert(IS_8X16(mb_type)); - for(list=0; listlist_count; list++){ - for(i=0; i<2; i++){ - if(IS_DIR(mb_type, i, list)){ //FIXME optimize - int ref; - if(h->ref_count[list] > 1){ - ref= decode_cabac_mb_ref( h, list, 4*i ); - if(ref >= (unsigned)h->ref_count[list]){ - av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref, h->ref_count[list]); - return -1; - } - }else - ref=0; - fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, ref, 1); - }else - fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, (LIST_NOT_USED&0xFF), 1); - } - } - for(list=0; listlist_count; list++){ - for(i=0; i<2; i++){ - if(IS_DIR(mb_type, i, list)){ - pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mpx, &mpy); - mx = mpx + decode_cabac_mb_mvd( h, list, 4*i, 0 ); - my = mpy + decode_cabac_mb_mvd( h, list, 4*i, 1 ); - - tprintf(s->avctx, "final mv:%d %d\n", mx, my); - fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx-mpx,my-mpy), 4); - fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx,my), 4); - }else{ - fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 4); - fill_rectangle(h-> mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 4); - } - } - } - } - } - - if( IS_INTER( mb_type ) ) { - h->chroma_pred_mode_table[mb_xy] = 0; - write_back_motion( h, mb_type ); - } - - if( !IS_INTRA16x16( mb_type ) ) { - cbp = decode_cabac_mb_cbp_luma( h ); - if(CHROMA) - cbp |= decode_cabac_mb_cbp_chroma( h ) << 4; - } - - h->cbp_table[mb_xy] = h->cbp = cbp; - - if( dct8x8_allowed && (cbp&15) && !IS_INTRA( mb_type ) ) { - if( decode_cabac_mb_transform_size( h ) ) - mb_type |= MB_TYPE_8x8DCT; - } - s->current_picture.mb_type[mb_xy]= mb_type; - - if( cbp || IS_INTRA16x16( mb_type ) ) { - const uint8_t *scan, *scan8x8, *dc_scan; - const uint32_t *qmul; - int dqp; - - if(IS_INTERLACED(mb_type)){ - scan8x8= s->qscale ? h->field_scan8x8 : h->field_scan8x8_q0; - scan= s->qscale ? h->field_scan : h->field_scan_q0; - dc_scan= luma_dc_field_scan; - }else{ - scan8x8= s->qscale ? h->zigzag_scan8x8 : h->zigzag_scan8x8_q0; - scan= s->qscale ? h->zigzag_scan : h->zigzag_scan_q0; - dc_scan= luma_dc_zigzag_scan; - } - - h->last_qscale_diff = dqp = decode_cabac_mb_dqp( h ); - if( dqp == INT_MIN ){ - av_log(h->s.avctx, AV_LOG_ERROR, "cabac decode of qscale diff failed at %d %d\n", s->mb_x, s->mb_y); - return -1; - } - s->qscale += dqp; - if(((unsigned)s->qscale) > 51){ - if(s->qscale<0) s->qscale+= 52; - else s->qscale-= 52; - } - h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale); - h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale); - - if( IS_INTRA16x16( mb_type ) ) { - int i; - //av_log( s->avctx, AV_LOG_ERROR, "INTRA16x16 DC\n" ); - decode_cabac_residual( h, h->mb, 0, 0, dc_scan, NULL, 16); - - if( cbp&15 ) { - qmul = h->dequant4_coeff[0][s->qscale]; - for( i = 0; i < 16; i++ ) { - //av_log( s->avctx, AV_LOG_ERROR, "INTRA16x16 AC:%d\n", i ); - decode_cabac_residual(h, h->mb + 16*i, 1, i, scan + 1, qmul, 15); - } - } else { - fill_rectangle(&h->non_zero_count_cache[scan8[0]], 4, 4, 8, 0, 1); - } - } else { - int i8x8, i4x4; - for( i8x8 = 0; i8x8 < 4; i8x8++ ) { - if( cbp & (1<mb + 64*i8x8, 5, 4*i8x8, - scan8x8, h->dequant8_coeff[IS_INTRA( mb_type ) ? 0:1][s->qscale], 64); - } else { - qmul = h->dequant4_coeff[IS_INTRA( mb_type ) ? 0:3][s->qscale]; - for( i4x4 = 0; i4x4 < 4; i4x4++ ) { - const int index = 4*i8x8 + i4x4; - //av_log( s->avctx, AV_LOG_ERROR, "Luma4x4: %d\n", index ); -//START_TIMER - decode_cabac_residual(h, h->mb + 16*index, 2, index, scan, qmul, 16); -//STOP_TIMER("decode_residual") - } - } - } else { - uint8_t * const nnz= &h->non_zero_count_cache[ scan8[4*i8x8] ]; - nnz[0] = nnz[1] = nnz[8] = nnz[9] = 0; - } - } - } - - 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(h, h->mb + 256 + 16*4*c, 3, c, chroma_dc_scan, NULL, 4); - } - } - - if( cbp&0x20 ) { - int c, i; - for( c = 0; c < 2; c++ ) { - qmul = h->dequant4_coeff[c+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[c]]; - for( i = 0; i < 4; i++ ) { - const int index = 16 + 4 * c + i; - //av_log( s->avctx, AV_LOG_ERROR, "INTRA C%d-AC %d\n",c, index - 16 ); - decode_cabac_residual(h, h->mb + 16*index, 4, index, scan + 1, qmul, 15); - } - } - } else { - uint8_t * const nnz= &h->non_zero_count_cache[0]; - nnz[ scan8[16]+0 ] = nnz[ scan8[16]+1 ] =nnz[ scan8[16]+8 ] =nnz[ scan8[16]+9 ] = - nnz[ scan8[20]+0 ] = nnz[ scan8[20]+1 ] =nnz[ scan8[20]+8 ] =nnz[ scan8[20]+9 ] = 0; - } - } else { - uint8_t * const nnz= &h->non_zero_count_cache[0]; - fill_rectangle(&nnz[scan8[0]], 4, 4, 8, 0, 1); - nnz[ scan8[16]+0 ] = nnz[ scan8[16]+1 ] =nnz[ scan8[16]+8 ] =nnz[ scan8[16]+9 ] = - nnz[ scan8[20]+0 ] = nnz[ scan8[20]+1 ] =nnz[ scan8[20]+8 ] =nnz[ scan8[20]+9 ] = 0; - h->last_qscale_diff = 0; - } - - s->current_picture.qscale_table[mb_xy]= s->qscale; - write_back_non_zero_count(h); - - if(MB_MBAFF){ - h->ref_count[0] >>= 1; - h->ref_count[1] >>= 1; - } - - return 0; -} - - -static void filter_mb_edgev( H264Context *h, uint8_t *pix, int stride, int16_t bS[4], int qp ) { - const int index_a = qp + h->slice_alpha_c0_offset; - const int alpha = (alpha_table+52)[index_a]; - const int beta = (beta_table+52)[qp + h->slice_beta_offset]; - if (alpha ==0 || beta == 0) return; - - if( bS[0] < 4 ) { - int8_t tc[4]; - tc[0] = (tc0_table+52)[index_a][bS[0]]; - tc[1] = (tc0_table+52)[index_a][bS[1]]; - tc[2] = (tc0_table+52)[index_a][bS[2]]; - tc[3] = (tc0_table+52)[index_a][bS[3]]; - h->s.dsp.h264_h_loop_filter_luma(pix, stride, alpha, beta, tc); - } else { - h->s.dsp.h264_h_loop_filter_luma_intra(pix, stride, alpha, beta); - } -} -static void filter_mb_edgecv( H264Context *h, uint8_t *pix, int stride, int16_t bS[4], int qp ) { - const int index_a = qp + h->slice_alpha_c0_offset; - const int alpha = (alpha_table+52)[index_a]; - const int beta = (beta_table+52)[qp + h->slice_beta_offset]; - if (alpha ==0 || beta == 0) return; - - if( bS[0] < 4 ) { - int8_t tc[4]; - tc[0] = (tc0_table+52)[index_a][bS[0]]+1; - tc[1] = (tc0_table+52)[index_a][bS[1]]+1; - tc[2] = (tc0_table+52)[index_a][bS[2]]+1; - tc[3] = (tc0_table+52)[index_a][bS[3]]+1; - h->s.dsp.h264_h_loop_filter_chroma(pix, stride, alpha, beta, tc); - } else { - h->s.dsp.h264_h_loop_filter_chroma_intra(pix, stride, alpha, beta); - } -} - -static void filter_mb_mbaff_edgev( H264Context *h, uint8_t *pix, int stride, int16_t bS[8], int qp[2] ) { - int i; - for( i = 0; i < 16; i++, pix += stride) { - int index_a; - int alpha; - int beta; - - int qp_index; - int bS_index = (i >> 1); - if (!MB_FIELD) { - bS_index &= ~1; - bS_index |= (i & 1); - } - - if( bS[bS_index] == 0 ) { - continue; - } - - qp_index = MB_FIELD ? (i >> 3) : (i & 1); - index_a = qp[qp_index] + h->slice_alpha_c0_offset; - alpha = (alpha_table+52)[index_a]; - beta = (beta_table+52)[qp[qp_index] + h->slice_beta_offset]; - - if( bS[bS_index] < 4 ) { - const int tc0 = (tc0_table+52)[index_a][bS[bS_index]]; - const int p0 = pix[-1]; - const int p1 = pix[-2]; - const int p2 = pix[-3]; - const int q0 = pix[0]; - const int q1 = pix[1]; - const int q2 = pix[2]; - - if( FFABS( p0 - q0 ) < alpha && - FFABS( p1 - p0 ) < beta && - FFABS( q1 - q0 ) < beta ) { - int tc = tc0; - int i_delta; - - if( FFABS( p2 - p0 ) < beta ) { - pix[-2] = p1 + av_clip( ( p2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( p1 << 1 ) ) >> 1, -tc0, tc0 ); - tc++; - } - if( FFABS( q2 - q0 ) < beta ) { - pix[1] = q1 + av_clip( ( q2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( q1 << 1 ) ) >> 1, -tc0, tc0 ); - tc++; - } - - i_delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); - pix[-1] = av_clip_uint8( p0 + i_delta ); /* p0' */ - pix[0] = av_clip_uint8( q0 - i_delta ); /* q0' */ - tprintf(h->s.avctx, "filter_mb_mbaff_edgev i:%d, qp:%d, indexA:%d, alpha:%d, beta:%d, tc:%d\n# bS:%d -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x]\n", i, qp[qp_index], index_a, alpha, beta, tc, bS[bS_index], pix[-3], p1, p0, q0, q1, pix[2], p1, pix[-1], pix[0], q1); - } - }else{ - const int p0 = pix[-1]; - const int p1 = pix[-2]; - const int p2 = pix[-3]; - - const int q0 = pix[0]; - const int q1 = pix[1]; - const int q2 = pix[2]; - - if( FFABS( p0 - q0 ) < alpha && - FFABS( p1 - p0 ) < beta && - FFABS( q1 - q0 ) < beta ) { - - if(FFABS( p0 - q0 ) < (( alpha >> 2 ) + 2 )){ - if( FFABS( p2 - p0 ) < beta) - { - const int p3 = pix[-4]; - /* p0', p1', p2' */ - pix[-1] = ( p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4 ) >> 3; - pix[-2] = ( p2 + p1 + p0 + q0 + 2 ) >> 2; - pix[-3] = ( 2*p3 + 3*p2 + p1 + p0 + q0 + 4 ) >> 3; - } else { - /* p0' */ - pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; - } - if( FFABS( q2 - q0 ) < beta) - { - const int q3 = pix[3]; - /* q0', q1', q2' */ - pix[0] = ( p1 + 2*p0 + 2*q0 + 2*q1 + q2 + 4 ) >> 3; - pix[1] = ( p0 + q0 + q1 + q2 + 2 ) >> 2; - pix[2] = ( 2*q3 + 3*q2 + q1 + q0 + p0 + 4 ) >> 3; - } else { - /* q0' */ - pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; - } - }else{ - /* p0', q0' */ - pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; - pix[ 0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; - } - tprintf(h->s.avctx, "filter_mb_mbaff_edgev i:%d, qp:%d, indexA:%d, alpha:%d, beta:%d\n# bS:4 -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x, %02x, %02x]\n", i, qp[qp_index], index_a, alpha, beta, p2, p1, p0, q0, q1, q2, pix[-3], pix[-2], pix[-1], pix[0], pix[1], pix[2]); - } - } - } -} -static void filter_mb_mbaff_edgecv( H264Context *h, uint8_t *pix, int stride, int16_t bS[8], int qp[2] ) { - int i; - for( i = 0; i < 8; i++, pix += stride) { - int index_a; - int alpha; - int beta; - - int qp_index; - int bS_index = i; - - if( bS[bS_index] == 0 ) { - continue; - } - - qp_index = MB_FIELD ? (i >> 2) : (i & 1); - index_a = qp[qp_index] + h->slice_alpha_c0_offset; - alpha = (alpha_table+52)[index_a]; - beta = (beta_table+52)[qp[qp_index] + h->slice_beta_offset]; - - if( bS[bS_index] < 4 ) { - const int tc = (tc0_table+52)[index_a][bS[bS_index]] + 1; - const int p0 = pix[-1]; - const int p1 = pix[-2]; - const int q0 = pix[0]; - const int q1 = pix[1]; - - if( FFABS( p0 - q0 ) < alpha && - FFABS( p1 - p0 ) < beta && - FFABS( q1 - q0 ) < beta ) { - const int i_delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); - - pix[-1] = av_clip_uint8( p0 + i_delta ); /* p0' */ - pix[0] = av_clip_uint8( q0 - i_delta ); /* q0' */ - tprintf(h->s.avctx, "filter_mb_mbaff_edgecv i:%d, qp:%d, indexA:%d, alpha:%d, beta:%d, tc:%d\n# bS:%d -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x]\n", i, qp[qp_index], index_a, alpha, beta, tc, bS[bS_index], pix[-3], p1, p0, q0, q1, pix[2], p1, pix[-1], pix[0], q1); - } - }else{ - const int p0 = pix[-1]; - const int p1 = pix[-2]; - const int q0 = pix[0]; - const int q1 = pix[1]; - - if( FFABS( p0 - q0 ) < alpha && - FFABS( p1 - p0 ) < beta && - FFABS( q1 - q0 ) < beta ) { - - pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; /* p0' */ - pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; /* q0' */ - tprintf(h->s.avctx, "filter_mb_mbaff_edgecv i:%d\n# bS:4 -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x, %02x, %02x]\n", i, pix[-3], p1, p0, q0, q1, pix[2], pix[-3], pix[-2], pix[-1], pix[0], pix[1], pix[2]); - } - } - } -} - -static void filter_mb_edgeh( H264Context *h, uint8_t *pix, int stride, int16_t bS[4], int qp ) { - const int index_a = qp + h->slice_alpha_c0_offset; - const int alpha = (alpha_table+52)[index_a]; - const int beta = (beta_table+52)[qp + h->slice_beta_offset]; - if (alpha ==0 || beta == 0) return; - - if( bS[0] < 4 ) { - int8_t tc[4]; - tc[0] = (tc0_table+52)[index_a][bS[0]]; - tc[1] = (tc0_table+52)[index_a][bS[1]]; - tc[2] = (tc0_table+52)[index_a][bS[2]]; - tc[3] = (tc0_table+52)[index_a][bS[3]]; - h->s.dsp.h264_v_loop_filter_luma(pix, stride, alpha, beta, tc); - } else { - h->s.dsp.h264_v_loop_filter_luma_intra(pix, stride, alpha, beta); - } -} - -static void filter_mb_edgech( H264Context *h, uint8_t *pix, int stride, int16_t bS[4], int qp ) { - const int index_a = qp + h->slice_alpha_c0_offset; - const int alpha = (alpha_table+52)[index_a]; - const int beta = (beta_table+52)[qp + h->slice_beta_offset]; - if (alpha ==0 || beta == 0) return; - - if( bS[0] < 4 ) { - int8_t tc[4]; - tc[0] = (tc0_table+52)[index_a][bS[0]]+1; - tc[1] = (tc0_table+52)[index_a][bS[1]]+1; - tc[2] = (tc0_table+52)[index_a][bS[2]]+1; - tc[3] = (tc0_table+52)[index_a][bS[3]]+1; - h->s.dsp.h264_v_loop_filter_chroma(pix, stride, alpha, beta, tc); - } else { - h->s.dsp.h264_v_loop_filter_chroma_intra(pix, stride, alpha, beta); - } -} - -static void 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) { - MpegEncContext * const s = &h->s; - int mb_y_firstrow = s->picture_structure == PICT_BOTTOM_FIELD; - int mb_xy, mb_type; - int qp, qp0, qp1, qpc, qpc0, qpc1, qp_thresh; - - mb_xy = h->mb_xy; - - if(mb_x==0 || mb_y==mb_y_firstrow || !s->dsp.h264_loop_filter_strength || h->pps.chroma_qp_diff || - !(s->flags2 & CODEC_FLAG2_FAST) || //FIXME filter_mb_fast is broken, thus hasto be, but should not under CODEC_FLAG2_FAST - (h->deblocking_filter == 2 && (h->slice_table[mb_xy] != h->slice_table[h->top_mb_xy] || - h->slice_table[mb_xy] != h->slice_table[mb_xy - 1]))) { - filter_mb(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize); - return; - } - assert(!FRAME_MBAFF); - - 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 ); - qp0 = (qp + qp0 + 1) >> 1; - qp1 = (qp + qp1 + 1) >> 1; - qpc0 = (qpc + qpc0 + 1) >> 1; - qpc1 = (qpc + qpc1 + 1) >> 1; - qp_thresh = 15 - 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; - if( IS_8x8DCT(mb_type) ) { - filter_mb_edgev( h, &img_y[4*0], linesize, bS4, qp0 ); - filter_mb_edgev( h, &img_y[4*2], linesize, bS3, qp ); - filter_mb_edgeh( h, &img_y[4*0*linesize], linesize, bSH, qp1 ); - filter_mb_edgeh( h, &img_y[4*2*linesize], linesize, bS3, qp ); - } else { - filter_mb_edgev( h, &img_y[4*0], linesize, bS4, qp0 ); - filter_mb_edgev( h, &img_y[4*1], linesize, bS3, qp ); - filter_mb_edgev( h, &img_y[4*2], linesize, bS3, qp ); - filter_mb_edgev( h, &img_y[4*3], linesize, bS3, qp ); - filter_mb_edgeh( h, &img_y[4*0*linesize], linesize, bSH, qp1 ); - filter_mb_edgeh( h, &img_y[4*1*linesize], linesize, bS3, qp ); - filter_mb_edgeh( h, &img_y[4*2*linesize], linesize, bS3, qp ); - filter_mb_edgeh( h, &img_y[4*3*linesize], linesize, bS3, qp ); - } - filter_mb_edgecv( h, &img_cb[2*0], uvlinesize, bS4, qpc0 ); - filter_mb_edgecv( h, &img_cb[2*2], uvlinesize, bS3, qpc ); - filter_mb_edgecv( h, &img_cr[2*0], uvlinesize, bS4, qpc0 ); - filter_mb_edgecv( h, &img_cr[2*2], uvlinesize, bS3, qpc ); - filter_mb_edgech( h, &img_cb[2*0*uvlinesize], uvlinesize, bSH, qpc1 ); - filter_mb_edgech( h, &img_cb[2*2*uvlinesize], uvlinesize, bS3, qpc ); - filter_mb_edgech( h, &img_cr[2*0*uvlinesize], uvlinesize, bSH, qpc1 ); - filter_mb_edgech( h, &img_cr[2*2*uvlinesize], uvlinesize, bS3, qpc ); - return; - } else { - DECLARE_ALIGNED_8(int16_t, bS[2][4][4]); - uint64_t (*bSv)[4] = (uint64_t(*)[4])bS; - int edges; - if( IS_8x8DCT(mb_type) && (h->cbp&7) == 7 ) { - edges = 4; - bSv[0][0] = bSv[0][2] = bSv[1][0] = bSv[1][2] = 0x0002000200020002ULL; - } else { - int mask_edge1 = (mb_type & (MB_TYPE_16x16 | MB_TYPE_8x16)) ? 3 : - (mb_type & MB_TYPE_16x8) ? 1 : 0; - int mask_edge0 = (mb_type & (MB_TYPE_16x16 | MB_TYPE_8x16)) - && (s->current_picture.mb_type[mb_xy-1] & (MB_TYPE_16x16 | MB_TYPE_8x16)) - ? 3 : 0; - int step = IS_8x8DCT(mb_type) ? 2 : 1; - edges = (mb_type & MB_TYPE_16x16) && !(h->cbp & 15) ? 1 : 4; - s->dsp.h264_loop_filter_strength( bS, h->non_zero_count_cache, h->ref_cache, h->mv_cache, - (h->slice_type_nos == FF_B_TYPE), edges, step, mask_edge0, mask_edge1, FIELD_PICTURE); - } - if( IS_INTRA(s->current_picture.mb_type[mb_xy-1]) ) - bSv[0][0] = 0x0004000400040004ULL; - if( IS_INTRA(s->current_picture.mb_type[h->top_mb_xy]) ) - bSv[1][0] = FIELD_PICTURE ? 0x0003000300030003ULL : 0x0004000400040004ULL; - -#define FILTER(hv,dir,edge)\ - if(bSv[dir][edge]) {\ - filter_mb_edge##hv( h, &img_y[4*edge*(dir?linesize:1)], linesize, bS[dir][edge], edge ? qp : qp##dir );\ - if(!(edge&1)) {\ - filter_mb_edgec##hv( h, &img_cb[2*edge*(dir?uvlinesize:1)], uvlinesize, bS[dir][edge], edge ? qpc : qpc##dir );\ - filter_mb_edgec##hv( h, &img_cr[2*edge*(dir?uvlinesize:1)], uvlinesize, bS[dir][edge], edge ? qpc : qpc##dir );\ - }\ - } - if( edges == 1 ) { - FILTER(v,0,0); - FILTER(h,1,0); - } else if( IS_8x8DCT(mb_type) ) { - FILTER(v,0,0); - FILTER(v,0,2); - FILTER(h,1,0); - FILTER(h,1,2); - } else { - FILTER(v,0,0); - FILTER(v,0,1); - FILTER(v,0,2); - FILTER(v,0,3); - FILTER(h,1,0); - FILTER(h,1,1); - FILTER(h,1,2); - FILTER(h,1,3); - } -#undef FILTER - } -} - - -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 dir) { - MpegEncContext * const s = &h->s; - int edge; - const int mbm_xy = dir == 0 ? mb_xy -1 : h->top_mb_xy; - const int mbm_type = s->current_picture.mb_type[mbm_xy]; - int (*ref2frm) [64] = h->ref2frm[ h->slice_num &(MAX_SLICES-1) ][0] + (MB_MBAFF ? 20 : 2); - int (*ref2frmm)[64] = h->ref2frm[ h->slice_table[mbm_xy]&(MAX_SLICES-1) ][0] + (MB_MBAFF ? 20 : 2); - int start = h->slice_table[mbm_xy] == 0xFFFF ? 1 : 0; - - const int edges = (mb_type & (MB_TYPE_16x16|MB_TYPE_SKIP)) - == (MB_TYPE_16x16|MB_TYPE_SKIP) ? 1 : 4; - // how often to recheck mv-based bS when iterating between edges - const int mask_edge = (mb_type & (MB_TYPE_16x16 | (MB_TYPE_16x8 << dir))) ? 3 : - (mb_type & (MB_TYPE_8x16 >> dir)) ? 1 : 0; - // how often to recheck mv-based bS when iterating along each edge - const int mask_par0 = mb_type & (MB_TYPE_16x16 | (MB_TYPE_8x16 >> dir)); - - if (first_vertical_edge_done) { - start = 1; - } - - if (h->deblocking_filter==2 && h->slice_table[mbm_xy] != h->slice_table[mb_xy]) - start = 1; - - if (FRAME_MBAFF && (dir == 1) && ((mb_y&1) == 0) && start == 0 - && !IS_INTERLACED(mb_type) - && IS_INTERLACED(mbm_type) - ) { - // This is a special case in the norm where the filtering must - // be done twice (one each of the field) even if we are in a - // frame macroblock. - // - static const int nnz_idx[4] = {4,5,6,3}; - unsigned int tmp_linesize = 2 * linesize; - unsigned int tmp_uvlinesize = 2 * uvlinesize; - int mbn_xy = mb_xy - 2 * s->mb_stride; - int qp; - int i, j; - int16_t bS[4]; - - for(j=0; j<2; j++, mbn_xy += s->mb_stride){ - if( IS_INTRA(mb_type) || - IS_INTRA(s->current_picture.mb_type[mbn_xy]) ) { - bS[0] = bS[1] = bS[2] = bS[3] = 3; - } else { - const uint8_t *mbn_nnz = h->non_zero_count[mbn_xy]; - for( i = 0; i < 4; i++ ) { - if( h->non_zero_count_cache[scan8[0]+i] != 0 || - mbn_nnz[nnz_idx[i]] != 0 ) - bS[i] = 2; - else - bS[i] = 1; - } - } - // 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; - 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( h, &img_y[j*linesize], tmp_linesize, bS, qp ); - filter_mb_edgech( h, &img_cb[j*uvlinesize], tmp_uvlinesize, bS, - ( h->chroma_qp[0] + get_chroma_qp( h, 0, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1); - filter_mb_edgech( h, &img_cr[j*uvlinesize], tmp_uvlinesize, bS, - ( h->chroma_qp[1] + get_chroma_qp( h, 1, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1); - } - - start = 1; - } - - /* Calculate bS */ - for( edge = start; edge < edges; edge++ ) { - /* mbn_xy: neighbor macroblock */ - const int mbn_xy = edge > 0 ? mb_xy : mbm_xy; - const int mbn_type = s->current_picture.mb_type[mbn_xy]; - int (*ref2frmn)[64] = edge > 0 ? ref2frm : ref2frmm; - int16_t bS[4]; - int qp; - - if( (edge&1) && IS_8x8DCT(mb_type) ) - continue; - - if( IS_INTRA(mb_type) || - IS_INTRA(mbn_type) ) { - int value; - if (edge == 0) { - if ( (!IS_INTERLACED(mb_type) && !IS_INTERLACED(mbm_type)) - || ((FRAME_MBAFF || (s->picture_structure != PICT_FRAME)) && (dir == 0)) - ) { - value = 4; - } else { - value = 3; - } - } else { - value = 3; - } - bS[0] = bS[1] = bS[2] = bS[3] = value; - } else { - int i, l; - int mv_done; - - if( edge & mask_edge ) { - bS[0] = bS[1] = bS[2] = bS[3] = 0; - mv_done = 1; - } - else if( FRAME_MBAFF && IS_INTERLACED(mb_type ^ mbn_type)) { - bS[0] = bS[1] = bS[2] = bS[3] = 1; - mv_done = 1; - } - else if( mask_par0 && (edge || (mbn_type & (MB_TYPE_16x16 | (MB_TYPE_8x16 >> dir)))) ) { - int b_idx= 8 + 4 + edge * (dir ? 8:1); - int bn_idx= b_idx - (dir ? 8:1); - int v = 0; - - for( l = 0; !v && l < 1 + (h->slice_type_nos == FF_B_TYPE); l++ ) { - v |= ref2frm[l][h->ref_cache[l][b_idx]] != ref2frmn[l][h->ref_cache[l][bn_idx]] || - FFABS( h->mv_cache[l][b_idx][0] - h->mv_cache[l][bn_idx][0] ) >= 4 || - FFABS( h->mv_cache[l][b_idx][1] - h->mv_cache[l][bn_idx][1] ) >= mvy_limit; - } - - if(h->slice_type_nos == FF_B_TYPE && v){ - v=0; - for( l = 0; !v && l < 2; l++ ) { - int ln= 1-l; - v |= ref2frm[l][h->ref_cache[l][b_idx]] != ref2frmn[ln][h->ref_cache[ln][bn_idx]] || - FFABS( h->mv_cache[l][b_idx][0] - h->mv_cache[ln][bn_idx][0] ) >= 4 || - FFABS( h->mv_cache[l][b_idx][1] - h->mv_cache[ln][bn_idx][1] ) >= mvy_limit; - } - } - - bS[0] = bS[1] = bS[2] = bS[3] = v; - mv_done = 1; - } - else - mv_done = 0; - - for( i = 0; i < 4; i++ ) { - int x = dir == 0 ? edge : i; - int y = dir == 0 ? i : edge; - int b_idx= 8 + 4 + x + 8*y; - int bn_idx= b_idx - (dir ? 8:1); - - if( h->non_zero_count_cache[b_idx] | - h->non_zero_count_cache[bn_idx] ) { - bS[i] = 2; - } - else if(!mv_done) - { - bS[i] = 0; - for( l = 0; l < 1 + (h->slice_type_nos == FF_B_TYPE); l++ ) { - if( ref2frm[l][h->ref_cache[l][b_idx]] != ref2frmn[l][h->ref_cache[l][bn_idx]] || - FFABS( h->mv_cache[l][b_idx][0] - h->mv_cache[l][bn_idx][0] ) >= 4 || - FFABS( h->mv_cache[l][b_idx][1] - h->mv_cache[l][bn_idx][1] ) >= mvy_limit ) { - bS[i] = 1; - break; - } - } - - if(h->slice_type_nos == FF_B_TYPE && bS[i]){ - bS[i] = 0; - for( l = 0; l < 2; l++ ) { - int ln= 1-l; - if( ref2frm[l][h->ref_cache[l][b_idx]] != ref2frmn[ln][h->ref_cache[ln][bn_idx]] || - FFABS( h->mv_cache[l][b_idx][0] - h->mv_cache[ln][bn_idx][0] ) >= 4 || - FFABS( h->mv_cache[l][b_idx][1] - h->mv_cache[ln][bn_idx][1] ) >= mvy_limit ) { - bS[i] = 1; - break; - } - } - } - } - } - - if(bS[0]+bS[1]+bS[2]+bS[3] == 0) - continue; - } - - /* 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] + s->current_picture.qscale_table[mbn_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, 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( h, &img_y[4*edge], linesize, bS, qp ); - if( (edge&1) == 0 ) { - filter_mb_edgecv( h, &img_cb[2*edge], uvlinesize, bS, - ( h->chroma_qp[0] + get_chroma_qp( h, 0, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1); - filter_mb_edgecv( h, &img_cr[2*edge], uvlinesize, bS, - ( h->chroma_qp[1] + get_chroma_qp( h, 1, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1); - } - } else { - filter_mb_edgeh( h, &img_y[4*edge*linesize], linesize, bS, qp ); - if( (edge&1) == 0 ) { - filter_mb_edgech( h, &img_cb[2*edge*uvlinesize], uvlinesize, bS, - ( h->chroma_qp[0] + get_chroma_qp( h, 0, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1); - filter_mb_edgech( h, &img_cr[2*edge*uvlinesize], uvlinesize, bS, - ( h->chroma_qp[1] + get_chroma_qp( h, 1, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1); - } - } - } -} - -static void 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 mvy_limit = IS_INTERLACED(mb_type) ? 2 : 4; - int first_vertical_edge_done = 0; - av_unused int dir; - - //for sufficiently low qp, filtering wouldn't do anything - //this is a conservative estimate: could also check beta_offset and more accurate chroma_qp - if(!FRAME_MBAFF){ - int qp_thresh = 15 - h->slice_alpha_c0_offset - FFMAX3(0, h->pps.chroma_qp_index_offset[0], h->pps.chroma_qp_index_offset[1]); + //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]; if(qp <= qp_thresh - && (mb_x == 0 || ((qp + s->current_picture.qscale_table[mb_xy-1] + 1)>>1) <= qp_thresh) - && (h->top_mb_xy < 0 || ((qp + s->current_picture.qscale_table[h->top_mb_xy] + 1)>>1) <= qp_thresh)){ - return; + && (left_xy[0]<0 || ((qp + s->current_picture.qscale_table[left_xy[0]] + 1)>>1) <= qp_thresh) + && (top_xy < 0 || ((qp + s->current_picture.qscale_table[top_xy ] + 1)>>1) <= qp_thresh)){ + if(!FRAME_MBAFF) + return 1; + if( (left_xy[0]< 0 || ((qp + s->current_picture.qscale_table[left_xy[1] ] + 1)>>1) <= qp_thresh) + && (top_xy < s->mb_stride || ((qp + s->current_picture.qscale_table[top_xy -s->mb_stride] + 1)>>1) <= qp_thresh)) + return 1; } } + top_type = s->current_picture.mb_type[top_xy] ; + left_type[0] = s->current_picture.mb_type[left_xy[0]]; + left_type[1] = s->current_picture.mb_type[left_xy[1]]; + if(h->deblocking_filter == 2){ + if(h->slice_table[top_xy ] != h->slice_num) top_type= 0; + if(h->slice_table[left_xy[0] ] != h->slice_num) left_type[0]= left_type[1]= 0; + }else{ + if(h->slice_table[top_xy ] == 0xFFFF) top_type= 0; + if(h->slice_table[left_xy[0] ] == 0xFFFF) left_type[0]= left_type[1] =0; + } + h->top_type = top_type ; + h->left_type[0]= left_type[0]; + h->left_type[1]= left_type[1]; + + if(IS_INTRA(mb_type)) + return 0; + + AV_COPY64(&h->non_zero_count_cache[0+8*1], &h->non_zero_count[mb_xy][ 0]); + AV_COPY64(&h->non_zero_count_cache[0+8*2], &h->non_zero_count[mb_xy][ 8]); + AV_COPY32(&h->non_zero_count_cache[0+8*5], &h->non_zero_count[mb_xy][16]); + AV_COPY32(&h->non_zero_count_cache[4+8*3], &h->non_zero_count[mb_xy][20]); + AV_COPY64(&h->non_zero_count_cache[0+8*4], &h->non_zero_count[mb_xy][24]); + + h->cbp= h->cbp_table[mb_xy]; + + { + int list; + for(list=0; listlist_count; list++){ + int8_t *ref; + int y, b_stride; + int16_t (*mv_dst)[2]; + int16_t (*mv_src)[2]; + + if(!USES_LIST(mb_type, list)){ + fill_rectangle( h->mv_cache[list][scan8[0]], 4, 4, 8, pack16to32(0,0), 4); + AV_WN32A(&h->ref_cache[list][scan8[ 0]], ((LIST_NOT_USED)&0xFF)*0x01010101u); + AV_WN32A(&h->ref_cache[list][scan8[ 2]], ((LIST_NOT_USED)&0xFF)*0x01010101u); + AV_WN32A(&h->ref_cache[list][scan8[ 8]], ((LIST_NOT_USED)&0xFF)*0x01010101u); + AV_WN32A(&h->ref_cache[list][scan8[10]], ((LIST_NOT_USED)&0xFF)*0x01010101u); + continue; + } + + ref = &s->current_picture.ref_index[list][4*mb_xy]; + { + int (*ref2frm)[64] = h->ref2frm[ h->slice_num&(MAX_SLICES-1) ][0] + (MB_MBAFF ? 20 : 2); + AV_WN32A(&h->ref_cache[list][scan8[ 0]], (pack16to32(ref2frm[list][ref[0]],ref2frm[list][ref[1]])&0x00FF00FF)*0x0101); + AV_WN32A(&h->ref_cache[list][scan8[ 2]], (pack16to32(ref2frm[list][ref[0]],ref2frm[list][ref[1]])&0x00FF00FF)*0x0101); + ref += 2; + AV_WN32A(&h->ref_cache[list][scan8[ 8]], (pack16to32(ref2frm[list][ref[0]],ref2frm[list][ref[1]])&0x00FF00FF)*0x0101); + AV_WN32A(&h->ref_cache[list][scan8[10]], (pack16to32(ref2frm[list][ref[0]],ref2frm[list][ref[1]])&0x00FF00FF)*0x0101); + } + + b_stride = h->b_stride; + mv_dst = &h->mv_cache[list][scan8[0]]; + mv_src = &s->current_picture.motion_val[list][4*s->mb_x + 4*s->mb_y*b_stride]; + for(y=0; y<4; y++){ + AV_COPY128(mv_dst + 8*y, mv_src + y*b_stride); + } + + } + } + + +/* +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) + if(top_type){ + AV_COPY32(&h->non_zero_count_cache[4+8*0], &h->non_zero_count[top_xy][4+3*8]); + } + + if(left_type[0]){ + h->non_zero_count_cache[3+8*1]= h->non_zero_count[left_xy[0]][7+0*8]; + h->non_zero_count_cache[3+8*2]= h->non_zero_count[left_xy[0]][7+1*8]; + h->non_zero_count_cache[3+8*3]= h->non_zero_count[left_xy[0]][7+2*8]; + h->non_zero_count_cache[3+8*4]= h->non_zero_count[left_xy[0]][7+3*8]; + } + // CAVLC 8x8dct requires NNZ values for residual decoding that differ from what the loop filter needs - if(!h->pps.cabac && h->pps.transform_8x8_mode){ - int top_type, left_type[2]; - top_type = s->current_picture.mb_type[h->top_mb_xy] ; - left_type[0] = s->current_picture.mb_type[h->left_mb_xy[0]]; - left_type[1] = s->current_picture.mb_type[h->left_mb_xy[1]]; - + if(!CABAC && h->pps.transform_8x8_mode){ if(IS_8x8DCT(top_type)){ h->non_zero_count_cache[4+8*0]= - h->non_zero_count_cache[5+8*0]= h->cbp_table[h->top_mb_xy] & 4; + h->non_zero_count_cache[5+8*0]= h->cbp_table[top_xy] & 4; h->non_zero_count_cache[6+8*0]= - h->non_zero_count_cache[7+8*0]= h->cbp_table[h->top_mb_xy] & 8; + h->non_zero_count_cache[7+8*0]= h->cbp_table[top_xy] & 8; } if(IS_8x8DCT(left_type[0])){ h->non_zero_count_cache[3+8*1]= - h->non_zero_count_cache[3+8*2]= h->cbp_table[h->left_mb_xy[0]]&2; //FIXME check MBAFF + h->non_zero_count_cache[3+8*2]= h->cbp_table[left_xy[0]]&2; //FIXME check MBAFF } if(IS_8x8DCT(left_type[1])){ h->non_zero_count_cache[3+8*3]= - h->non_zero_count_cache[3+8*4]= h->cbp_table[h->left_mb_xy[1]]&8; //FIXME check MBAFF + h->non_zero_count_cache[3+8*4]= h->cbp_table[left_xy[1]]&8; //FIXME check MBAFF } if(IS_8x8DCT(mb_type)){ @@ -6603,74 +2377,121 @@ static void filter_mb( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8 } } - if (FRAME_MBAFF - // left mb is in picture - && h->slice_table[mb_xy-1] != 0xFFFF - // and current and left pair do not have the same interlaced type - && (IS_INTERLACED(mb_type) != IS_INTERLACED(s->current_picture.mb_type[mb_xy-1])) - // and left mb is in the same slice if deblocking_filter == 2 - && (h->deblocking_filter!=2 || h->slice_table[mb_xy-1] == h->slice_table[mb_xy])) { - /* First vertical edge is different in MBAFF frames - * There are 8 different bS to compute and 2 different Qp - */ - const int pair_xy = mb_x + (mb_y&~1)*s->mb_stride; - const int left_mb_xy[2] = { pair_xy-1, pair_xy-1+s->mb_stride }; - int16_t bS[8]; - int qp[2]; - int bqp[2]; - int rqp[2]; - int mb_qp, mbn0_qp, mbn1_qp; - int i; - first_vertical_edge_done = 1; + if(IS_INTER(mb_type) || IS_DIRECT(mb_type)){ + int list; + for(list=0; listlist_count; list++){ + if(USES_LIST(top_type, list)){ + const int b_xy= h->mb2b_xy[top_xy] + 3*h->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(h->mv_cache[list][scan8[0] + 0 - 1*8], s->current_picture.motion_val[list][b_xy + 0]); + h->ref_cache[list][scan8[0] + 0 - 1*8]= + h->ref_cache[list][scan8[0] + 1 - 1*8]= ref2frm[list][s->current_picture.ref_index[list][b8_xy + 0]]; + h->ref_cache[list][scan8[0] + 2 - 1*8]= + h->ref_cache[list][scan8[0] + 3 - 1*8]= ref2frm[list][s->current_picture.ref_index[list][b8_xy + 1]]; + }else{ + AV_ZERO128(h->mv_cache[list][scan8[0] + 0 - 1*8]); + AV_WN32A(&h->ref_cache[list][scan8[0] + 0 - 1*8], ((LIST_NOT_USED)&0xFF)*0x01010101u); + } - if( IS_INTRA(mb_type) ) - bS[0] = bS[1] = bS[2] = bS[3] = bS[4] = bS[5] = bS[6] = bS[7] = 4; - else { - for( i = 0; i < 8; i++ ) { - int mbn_xy = MB_FIELD ? left_mb_xy[i>>2] : left_mb_xy[i&1]; - - if( IS_INTRA( s->current_picture.mb_type[mbn_xy] ) ) - bS[i] = 4; - else if( h->non_zero_count_cache[12+8*(i>>1)] != 0 || - ((!h->pps.cabac && IS_8x8DCT(s->current_picture.mb_type[mbn_xy])) ? - (h->cbp_table[mbn_xy] & ((MB_FIELD ? (i&2) : (mb_y&1)) ? 8 : 2)) - : - h->non_zero_count[mbn_xy][MB_FIELD ? i&3 : (i>>2)+(mb_y&1)*2])) - bS[i] = 2; - else - bS[i] = 1; + if(!IS_INTERLACED(mb_type^left_type[0])){ + if(USES_LIST(left_type[0], list)){ + const int b_xy= h->mb2b_xy[left_xy[0]] + 3; + const int b8_xy= 4*left_xy[0] + 1; + int (*ref2frm)[64] = h->ref2frm[ h->slice_table[left_xy[0]]&(MAX_SLICES-1) ][0] + (MB_MBAFF ? 20 : 2); + AV_COPY32(h->mv_cache[list][scan8[0] - 1 + 0 ], s->current_picture.motion_val[list][b_xy + h->b_stride*0]); + AV_COPY32(h->mv_cache[list][scan8[0] - 1 + 8 ], s->current_picture.motion_val[list][b_xy + h->b_stride*1]); + AV_COPY32(h->mv_cache[list][scan8[0] - 1 +16 ], s->current_picture.motion_val[list][b_xy + h->b_stride*2]); + AV_COPY32(h->mv_cache[list][scan8[0] - 1 +24 ], s->current_picture.motion_val[list][b_xy + h->b_stride*3]); + h->ref_cache[list][scan8[0] - 1 + 0 ]= + h->ref_cache[list][scan8[0] - 1 + 8 ]= ref2frm[list][s->current_picture.ref_index[list][b8_xy + 2*0]]; + h->ref_cache[list][scan8[0] - 1 +16 ]= + h->ref_cache[list][scan8[0] - 1 +24 ]= ref2frm[list][s->current_picture.ref_index[list][b8_xy + 2*1]]; + }else{ + AV_ZERO32(h->mv_cache [list][scan8[0] - 1 + 0 ]); + AV_ZERO32(h->mv_cache [list][scan8[0] - 1 + 8 ]); + AV_ZERO32(h->mv_cache [list][scan8[0] - 1 +16 ]); + AV_ZERO32(h->mv_cache [list][scan8[0] - 1 +24 ]); + h->ref_cache[list][scan8[0] - 1 + 0 ]= + h->ref_cache[list][scan8[0] - 1 + 8 ]= + h->ref_cache[list][scan8[0] - 1 + 16 ]= + h->ref_cache[list][scan8[0] - 1 + 24 ]= LIST_NOT_USED; + } } } - - mb_qp = s->current_picture.qscale_table[mb_xy]; - mbn0_qp = s->current_picture.qscale_table[left_mb_xy[0]]; - mbn1_qp = s->current_picture.qscale_table[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; - rqp[0] = ( get_chroma_qp( h, 1, mb_qp ) + - get_chroma_qp( h, 1, mbn0_qp ) + 1 ) >> 1; - qp[1] = ( mb_qp + mbn1_qp + 1 ) >> 1; - bqp[1] = ( get_chroma_qp( h, 0, mb_qp ) + - get_chroma_qp( h, 0, mbn1_qp ) + 1 ) >> 1; - rqp[1] = ( get_chroma_qp( h, 1, mb_qp ) + - get_chroma_qp( h, 1, mbn1_qp ) + 1 ) >> 1; - - /* Filter edge */ - 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"); } - filter_mb_mbaff_edgev ( h, &img_y [0], linesize, bS, qp ); - filter_mb_mbaff_edgecv( h, &img_cb[0], uvlinesize, bS, bqp ); - filter_mb_mbaff_edgecv( h, &img_cr[0], uvlinesize, bS, rqp ); } -#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, 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, 0); - filter_mb_dir(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, 0, 1); -#endif + return 0; +} + +static void loop_filter(H264Context *h){ + MpegEncContext * const s = &h->s; + uint8_t *dest_y, *dest_cb, *dest_cr; + int linesize, uvlinesize, mb_x, mb_y; + const int end_mb_y= s->mb_y + FRAME_MBAFF; + const int old_slice_type= h->slice_type; + + if(h->deblocking_filter) { + for(mb_x= 0; mb_xmb_width; mb_x++){ + for(mb_y=end_mb_y - FRAME_MBAFF; mb_y<= end_mb_y; mb_y++){ + 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]; + h->list_count= h->list_counts[mb_xy]; + + if(FRAME_MBAFF) + h->mb_mbaff = h->mb_field_decoding_flag = !!IS_INTERLACED(mb_type); + + s->mb_x= mb_x; + s->mb_y= mb_y; + dest_y = s->current_picture.data[0] + (mb_x + mb_y * s->linesize ) * 16; + dest_cb = s->current_picture.data[1] + (mb_x + mb_y * s->uvlinesize) * 8; + dest_cr = s->current_picture.data[2] + (mb_x + mb_y * s->uvlinesize) * 8; + //FIXME simplify above + + if (MB_FIELD) { + linesize = h->mb_linesize = s->linesize * 2; + 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*7; + dest_cr-= s->uvlinesize*7; + } + } 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, 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]); + + if (FRAME_MBAFF) { + ff_h264_filter_mb (h, mb_x, mb_y, dest_y, dest_cb, dest_cr, linesize, uvlinesize); + } else { + ff_h264_filter_mb_fast(h, mb_x, mb_y, dest_y, dest_cb, dest_cr, linesize, uvlinesize); + } + } + } + } + h->slice_type= old_slice_type; + s->mb_x= 0; + s->mb_y= end_mb_y - FRAME_MBAFF; + h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale); + h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale); +} + +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] + : (h->slice_table[mb_xy-s->mb_stride] == h->slice_num) + ? s->current_picture.mb_type[mb_xy-s->mb_stride] + : 0; + h->mb_mbaff = h->mb_field_decoding_flag = IS_INTERLACED(mb_type) ? 1 : 0; } static int decode_slice(struct AVCodecContext *avctx, void *arg){ @@ -6684,8 +2505,6 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg){ (CONFIG_GRAY && (s->flags&CODEC_FLAG_GRAY)); if( h->pps.cabac ) { - int i; - /* realign */ align_get_bits( &s->gb ); @@ -6693,39 +2512,32 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg){ ff_init_cabac_states( &h->cabac); ff_init_cabac_decoder( &h->cabac, s->gb.buffer + get_bits_count(&s->gb)/8, - ( s->gb.size_in_bits - get_bits_count(&s->gb) + 7)/8); - /* calculate pre-state */ - for( i= 0; i < 460; i++ ) { - int pre; - if( h->slice_type_nos == FF_I_TYPE ) - pre = av_clip( ((cabac_context_init_I[i][0] * s->qscale) >>4 ) + cabac_context_init_I[i][1], 1, 126 ); - else - pre = av_clip( ((cabac_context_init_PB[h->cabac_init_idc][i][0] * s->qscale) >>4 ) + cabac_context_init_PB[h->cabac_init_idc][i][1], 1, 126 ); + (get_bits_left(&s->gb) + 7)/8); - if( pre <= 63 ) - h->cabac_state[i] = 2 * ( 63 - pre ) + 0; - else - h->cabac_state[i] = 2 * ( pre - 64 ) + 1; - } + ff_h264_init_cabac_states(h); for(;;){ //START_TIMER - int ret = decode_mb_cabac(h); + int ret = ff_h264_decode_mb_cabac(h); int eos; //STOP_TIMER("decode_mb_cabac") - if(ret>=0) hl_decode_mb(h); + if(ret>=0) ff_h264_hl_decode_mb(h); if( ret >= 0 && FRAME_MBAFF ) { //FIXME optimal? or let mb_decode decode 16x32 ? s->mb_y++; - ret = decode_mb_cabac(h); + ret = ff_h264_decode_mb_cabac(h); - if(ret>=0) hl_decode_mb(h); + if(ret>=0) ff_h264_hl_decode_mb(h); s->mb_y--; } eos = get_cabac_terminate( &h->cabac ); + if((s->workaround_bugs & FF_BUG_TRUNCATED) && h->cabac.bytestream > h->cabac.bytestream_end + 2){ + 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; + } if( ret < 0 || h->cabac.bytestream > h->cabac.bytestream_end + 2) { av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d, bytestream (%td)\n", s->mb_x, s->mb_y, h->cabac.bytestream_end - h->cabac.bytestream); 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); @@ -6734,10 +2546,13 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg){ if( ++s->mb_x >= s->mb_width ) { s->mb_x = 0; + loop_filter(h); ff_draw_horiz_band(s, 16*s->mb_y, 16); ++s->mb_y; if(FIELD_OR_MBAFF_PICTURE) { ++s->mb_y; + if(FRAME_MBAFF && s->mb_y < s->mb_height) + predict_field_decoding_flag(h); } } @@ -6750,15 +2565,15 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg){ } else { for(;;){ - int ret = decode_mb_cavlc(h); + int ret = ff_h264_decode_mb_cavlc(h); - if(ret>=0) hl_decode_mb(h); + if(ret>=0) ff_h264_hl_decode_mb(h); if(ret>=0 && FRAME_MBAFF){ //FIXME optimal? or let mb_decode decode 16x32 ? s->mb_y++; - ret = decode_mb_cavlc(h); + ret = ff_h264_decode_mb_cavlc(h); - if(ret>=0) hl_decode_mb(h); + if(ret>=0) ff_h264_hl_decode_mb(h); s->mb_y--; } @@ -6771,10 +2586,13 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg){ if(++s->mb_x >= s->mb_width){ s->mb_x=0; + loop_filter(h); ff_draw_horiz_band(s, 16*s->mb_y, 16); ++s->mb_y; if(FIELD_OR_MBAFF_PICTURE) { ++s->mb_y; + if(FRAME_MBAFF && s->mb_y < s->mb_height) + predict_field_decoding_flag(h); } 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); @@ -6811,7 +2629,7 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg){ for(;s->mb_x < s->mb_width; s->mb_x++){ int ret= decode_mb(h); - hl_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); @@ -6854,583 +2672,6 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg){ return -1; //not reached } -static int decode_picture_timing(H264Context *h){ - MpegEncContext * const s = &h->s; - if(h->sps.nal_hrd_parameters_present_flag || h->sps.vcl_hrd_parameters_present_flag){ - h->sei_cpb_removal_delay = get_bits(&s->gb, h->sps.cpb_removal_delay_length); - h->sei_dpb_output_delay = get_bits(&s->gb, h->sps.dpb_output_delay_length); - } - if(h->sps.pic_struct_present_flag){ - unsigned int i, num_clock_ts; - h->sei_pic_struct = get_bits(&s->gb, 4); - h->sei_ct_type = 0; - - if (h->sei_pic_struct > SEI_PIC_STRUCT_FRAME_TRIPLING) - return -1; - - num_clock_ts = sei_num_clock_ts_table[h->sei_pic_struct]; - - for (i = 0 ; i < num_clock_ts ; i++){ - if(get_bits(&s->gb, 1)){ /* clock_timestamp_flag */ - unsigned int full_timestamp_flag; - h->sei_ct_type |= 1<gb, 2); - skip_bits(&s->gb, 1); /* nuit_field_based_flag */ - skip_bits(&s->gb, 5); /* counting_type */ - full_timestamp_flag = get_bits(&s->gb, 1); - skip_bits(&s->gb, 1); /* discontinuity_flag */ - skip_bits(&s->gb, 1); /* cnt_dropped_flag */ - skip_bits(&s->gb, 8); /* n_frames */ - if(full_timestamp_flag){ - skip_bits(&s->gb, 6); /* seconds_value 0..59 */ - skip_bits(&s->gb, 6); /* minutes_value 0..59 */ - skip_bits(&s->gb, 5); /* hours_value 0..23 */ - }else{ - if(get_bits(&s->gb, 1)){ /* seconds_flag */ - skip_bits(&s->gb, 6); /* seconds_value range 0..59 */ - if(get_bits(&s->gb, 1)){ /* minutes_flag */ - skip_bits(&s->gb, 6); /* minutes_value 0..59 */ - if(get_bits(&s->gb, 1)) /* hours_flag */ - skip_bits(&s->gb, 5); /* hours_value 0..23 */ - } - } - } - if(h->sps.time_offset_length > 0) - skip_bits(&s->gb, h->sps.time_offset_length); /* time_offset */ - } - } - - if(s->avctx->debug & FF_DEBUG_PICT_INFO) - av_log(s->avctx, AV_LOG_DEBUG, "ct_type:%X pic_struct:%d\n", h->sei_ct_type, h->sei_pic_struct); - } - return 0; -} - -static int decode_unregistered_user_data(H264Context *h, int size){ - MpegEncContext * const s = &h->s; - uint8_t user_data[16+256]; - int e, build, i; - - if(size<16) - return -1; - - for(i=0; igb, 8); - } - - user_data[i]= 0; - e= sscanf(user_data+16, "x264 - core %d"/*%s - H.264/MPEG-4 AVC codec - Copyleft 2005 - http://www.videolan.org/x264.html*/, &build); - if(e==1 && build>=0) - h->x264_build= build; - - if(s->avctx->debug & FF_DEBUG_BUGS) - av_log(s->avctx, AV_LOG_DEBUG, "user data:\"%s\"\n", user_data+16); - - for(; igb, 8); - - return 0; -} - -static int decode_recovery_point(H264Context *h){ - MpegEncContext * const s = &h->s; - - h->sei_recovery_frame_cnt = get_ue_golomb(&s->gb); - skip_bits(&s->gb, 4); /* 1b exact_match_flag, 1b broken_link_flag, 2b changing_slice_group_idc */ - - return 0; -} - -static int decode_buffering_period(H264Context *h){ - MpegEncContext * const s = &h->s; - unsigned int sps_id; - int sched_sel_idx; - SPS *sps; - - sps_id = get_ue_golomb_31(&s->gb); - if(sps_id > 31 || !h->sps_buffers[sps_id]) { - av_log(h->s.avctx, AV_LOG_ERROR, "non-existing SPS %d referenced in buffering period\n", sps_id); - return -1; - } - sps = h->sps_buffers[sps_id]; - - // NOTE: This is really so duplicated in the standard... See H.264, D.1.1 - if (sps->nal_hrd_parameters_present_flag) { - for (sched_sel_idx = 0; sched_sel_idx < sps->cpb_cnt; sched_sel_idx++) { - h->initial_cpb_removal_delay[sched_sel_idx] = get_bits(&s->gb, sps->initial_cpb_removal_delay_length); - skip_bits(&s->gb, sps->initial_cpb_removal_delay_length); // initial_cpb_removal_delay_offset - } - } - if (sps->vcl_hrd_parameters_present_flag) { - for (sched_sel_idx = 0; sched_sel_idx < sps->cpb_cnt; sched_sel_idx++) { - h->initial_cpb_removal_delay[sched_sel_idx] = get_bits(&s->gb, sps->initial_cpb_removal_delay_length); - skip_bits(&s->gb, sps->initial_cpb_removal_delay_length); // initial_cpb_removal_delay_offset - } - } - - h->sei_buffering_period_present = 1; - return 0; -} - -int ff_h264_decode_sei(H264Context *h){ - MpegEncContext * const s = &h->s; - - while(get_bits_count(&s->gb) + 16 < s->gb.size_in_bits){ - int size, type; - - type=0; - do{ - type+= show_bits(&s->gb, 8); - }while(get_bits(&s->gb, 8) == 255); - - size=0; - do{ - size+= show_bits(&s->gb, 8); - }while(get_bits(&s->gb, 8) == 255); - - switch(type){ - case SEI_TYPE_PIC_TIMING: // Picture timing SEI - if(decode_picture_timing(h) < 0) - return -1; - break; - case SEI_TYPE_USER_DATA_UNREGISTERED: - if(decode_unregistered_user_data(h, size) < 0) - return -1; - break; - case SEI_TYPE_RECOVERY_POINT: - if(decode_recovery_point(h) < 0) - return -1; - break; - case SEI_BUFFERING_PERIOD: - if(decode_buffering_period(h) < 0) - return -1; - break; - default: - skip_bits(&s->gb, 8*size); - } - - //FIXME check bits here - align_get_bits(&s->gb); - } - - return 0; -} - -static inline int decode_hrd_parameters(H264Context *h, SPS *sps){ - MpegEncContext * const s = &h->s; - int cpb_count, i; - cpb_count = get_ue_golomb_31(&s->gb) + 1; - - if(cpb_count > 32U){ - av_log(h->s.avctx, AV_LOG_ERROR, "cpb_count %d invalid\n", cpb_count); - return -1; - } - - get_bits(&s->gb, 4); /* bit_rate_scale */ - get_bits(&s->gb, 4); /* cpb_size_scale */ - for(i=0; igb); /* bit_rate_value_minus1 */ - get_ue_golomb(&s->gb); /* cpb_size_value_minus1 */ - get_bits1(&s->gb); /* cbr_flag */ - } - sps->initial_cpb_removal_delay_length = get_bits(&s->gb, 5) + 1; - sps->cpb_removal_delay_length = get_bits(&s->gb, 5) + 1; - sps->dpb_output_delay_length = get_bits(&s->gb, 5) + 1; - sps->time_offset_length = get_bits(&s->gb, 5); - sps->cpb_cnt = cpb_count; - return 0; -} - -static inline int decode_vui_parameters(H264Context *h, SPS *sps){ - MpegEncContext * const s = &h->s; - int aspect_ratio_info_present_flag; - unsigned int aspect_ratio_idc; - - aspect_ratio_info_present_flag= get_bits1(&s->gb); - - if( aspect_ratio_info_present_flag ) { - aspect_ratio_idc= get_bits(&s->gb, 8); - if( aspect_ratio_idc == EXTENDED_SAR ) { - sps->sar.num= get_bits(&s->gb, 16); - sps->sar.den= get_bits(&s->gb, 16); - }else if(aspect_ratio_idc < FF_ARRAY_ELEMS(pixel_aspect)){ - sps->sar= pixel_aspect[aspect_ratio_idc]; - }else{ - av_log(h->s.avctx, AV_LOG_ERROR, "illegal aspect ratio\n"); - return -1; - } - }else{ - sps->sar.num= - sps->sar.den= 0; - } -// s->avctx->aspect_ratio= sar_width*s->width / (float)(s->height*sar_height); - - if(get_bits1(&s->gb)){ /* overscan_info_present_flag */ - get_bits1(&s->gb); /* overscan_appropriate_flag */ - } - - if(get_bits1(&s->gb)){ /* video_signal_type_present_flag */ - get_bits(&s->gb, 3); /* video_format */ - get_bits1(&s->gb); /* video_full_range_flag */ - if(get_bits1(&s->gb)){ /* colour_description_present_flag */ - get_bits(&s->gb, 8); /* colour_primaries */ - get_bits(&s->gb, 8); /* transfer_characteristics */ - get_bits(&s->gb, 8); /* matrix_coefficients */ - } - } - - if(get_bits1(&s->gb)){ /* chroma_location_info_present_flag */ - s->avctx->chroma_sample_location = get_ue_golomb(&s->gb)+1; /* chroma_sample_location_type_top_field */ - get_ue_golomb(&s->gb); /* chroma_sample_location_type_bottom_field */ - } - - sps->timing_info_present_flag = get_bits1(&s->gb); - if(sps->timing_info_present_flag){ - sps->num_units_in_tick = get_bits_long(&s->gb, 32); - sps->time_scale = get_bits_long(&s->gb, 32); - sps->fixed_frame_rate_flag = get_bits1(&s->gb); - } - - sps->nal_hrd_parameters_present_flag = get_bits1(&s->gb); - if(sps->nal_hrd_parameters_present_flag) - if(decode_hrd_parameters(h, sps) < 0) - return -1; - sps->vcl_hrd_parameters_present_flag = get_bits1(&s->gb); - if(sps->vcl_hrd_parameters_present_flag) - if(decode_hrd_parameters(h, sps) < 0) - return -1; - if(sps->nal_hrd_parameters_present_flag || sps->vcl_hrd_parameters_present_flag) - get_bits1(&s->gb); /* low_delay_hrd_flag */ - sps->pic_struct_present_flag = get_bits1(&s->gb); - - sps->bitstream_restriction_flag = get_bits1(&s->gb); - if(sps->bitstream_restriction_flag){ - get_bits1(&s->gb); /* motion_vectors_over_pic_boundaries_flag */ - get_ue_golomb(&s->gb); /* max_bytes_per_pic_denom */ - get_ue_golomb(&s->gb); /* max_bits_per_mb_denom */ - get_ue_golomb(&s->gb); /* log2_max_mv_length_horizontal */ - get_ue_golomb(&s->gb); /* log2_max_mv_length_vertical */ - sps->num_reorder_frames= get_ue_golomb(&s->gb); - get_ue_golomb(&s->gb); /*max_dec_frame_buffering*/ - - if(sps->num_reorder_frames > 16U /*max_dec_frame_buffering || max_dec_frame_buffering > 16*/){ - av_log(h->s.avctx, AV_LOG_ERROR, "illegal num_reorder_frames %d\n", sps->num_reorder_frames); - return -1; - } - } - - return 0; -} - -static void decode_scaling_list(H264Context *h, uint8_t *factors, int size, - const uint8_t *jvt_list, const uint8_t *fallback_list){ - MpegEncContext * const s = &h->s; - int i, last = 8, next = 8; - const uint8_t *scan = size == 16 ? zigzag_scan : ff_zigzag_direct; - if(!get_bits1(&s->gb)) /* matrix not written, we use the predicted one */ - memcpy(factors, fallback_list, size*sizeof(uint8_t)); - else - for(i=0;igb)) & 0xff; - if(!i && !next){ /* matrix not written, we use the preset one */ - memcpy(factors, jvt_list, size*sizeof(uint8_t)); - break; - } - last = factors[scan[i]] = next ? next : last; - } -} - -static void decode_scaling_matrices(H264Context *h, SPS *sps, PPS *pps, int is_sps, - uint8_t (*scaling_matrix4)[16], uint8_t (*scaling_matrix8)[64]){ - MpegEncContext * const s = &h->s; - int fallback_sps = !is_sps && sps->scaling_matrix_present; - const uint8_t *fallback[4] = { - fallback_sps ? sps->scaling_matrix4[0] : default_scaling4[0], - fallback_sps ? sps->scaling_matrix4[3] : default_scaling4[1], - fallback_sps ? sps->scaling_matrix8[0] : default_scaling8[0], - fallback_sps ? sps->scaling_matrix8[1] : default_scaling8[1] - }; - if(get_bits1(&s->gb)){ - sps->scaling_matrix_present |= is_sps; - decode_scaling_list(h,scaling_matrix4[0],16,default_scaling4[0],fallback[0]); // Intra, Y - decode_scaling_list(h,scaling_matrix4[1],16,default_scaling4[0],scaling_matrix4[0]); // Intra, Cr - decode_scaling_list(h,scaling_matrix4[2],16,default_scaling4[0],scaling_matrix4[1]); // Intra, Cb - decode_scaling_list(h,scaling_matrix4[3],16,default_scaling4[1],fallback[1]); // Inter, Y - decode_scaling_list(h,scaling_matrix4[4],16,default_scaling4[1],scaling_matrix4[3]); // Inter, Cr - decode_scaling_list(h,scaling_matrix4[5],16,default_scaling4[1],scaling_matrix4[4]); // Inter, Cb - if(is_sps || pps->transform_8x8_mode){ - decode_scaling_list(h,scaling_matrix8[0],64,default_scaling8[0],fallback[2]); // Intra, Y - decode_scaling_list(h,scaling_matrix8[1],64,default_scaling8[1],fallback[3]); // Inter, Y - } - } -} - -int ff_h264_decode_seq_parameter_set(H264Context *h){ - MpegEncContext * const s = &h->s; - int profile_idc, level_idc; - unsigned int sps_id; - int i; - SPS *sps; - - profile_idc= get_bits(&s->gb, 8); - get_bits1(&s->gb); //constraint_set0_flag - get_bits1(&s->gb); //constraint_set1_flag - get_bits1(&s->gb); //constraint_set2_flag - get_bits1(&s->gb); //constraint_set3_flag - get_bits(&s->gb, 4); // reserved - level_idc= get_bits(&s->gb, 8); - sps_id= get_ue_golomb_31(&s->gb); - - if(sps_id >= MAX_SPS_COUNT) { - av_log(h->s.avctx, AV_LOG_ERROR, "sps_id (%d) out of range\n", sps_id); - return -1; - } - sps= av_mallocz(sizeof(SPS)); - if(sps == NULL) - return -1; - - sps->profile_idc= profile_idc; - sps->level_idc= level_idc; - - memset(sps->scaling_matrix4, 16, sizeof(sps->scaling_matrix4)); - memset(sps->scaling_matrix8, 16, sizeof(sps->scaling_matrix8)); - sps->scaling_matrix_present = 0; - - if(sps->profile_idc >= 100){ //high profile - sps->chroma_format_idc= get_ue_golomb_31(&s->gb); - if(sps->chroma_format_idc == 3) - 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; - sps->transform_bypass = get_bits1(&s->gb); - decode_scaling_matrices(h, sps, NULL, 1, sps->scaling_matrix4, sps->scaling_matrix8); - }else{ - sps->chroma_format_idc= 1; - } - - sps->log2_max_frame_num= get_ue_golomb(&s->gb) + 4; - sps->poc_type= get_ue_golomb_31(&s->gb); - - if(sps->poc_type == 0){ //FIXME #define - sps->log2_max_poc_lsb= get_ue_golomb(&s->gb) + 4; - } else if(sps->poc_type == 1){//FIXME #define - sps->delta_pic_order_always_zero_flag= get_bits1(&s->gb); - sps->offset_for_non_ref_pic= get_se_golomb(&s->gb); - sps->offset_for_top_to_bottom_field= get_se_golomb(&s->gb); - sps->poc_cycle_length = get_ue_golomb(&s->gb); - - if((unsigned)sps->poc_cycle_length >= FF_ARRAY_ELEMS(sps->offset_for_ref_frame)){ - av_log(h->s.avctx, AV_LOG_ERROR, "poc_cycle_length overflow %u\n", sps->poc_cycle_length); - goto fail; - } - - for(i=0; ipoc_cycle_length; i++) - sps->offset_for_ref_frame[i]= get_se_golomb(&s->gb); - }else if(sps->poc_type != 2){ - av_log(h->s.avctx, AV_LOG_ERROR, "illegal POC type %d\n", sps->poc_type); - goto fail; - } - - sps->ref_frame_count= get_ue_golomb_31(&s->gb); - if(sps->ref_frame_count > MAX_PICTURE_COUNT-2 || sps->ref_frame_count >= 32U){ - av_log(h->s.avctx, AV_LOG_ERROR, "too many reference frames\n"); - goto fail; - } - sps->gaps_in_frame_num_allowed_flag= get_bits1(&s->gb); - sps->mb_width = get_ue_golomb(&s->gb) + 1; - sps->mb_height= get_ue_golomb(&s->gb) + 1; - if((unsigned)sps->mb_width >= INT_MAX/16 || (unsigned)sps->mb_height >= INT_MAX/16 || - avcodec_check_dimensions(NULL, 16*sps->mb_width, 16*sps->mb_height)){ - av_log(h->s.avctx, AV_LOG_ERROR, "mb_width/height overflow\n"); - goto fail; - } - - sps->frame_mbs_only_flag= get_bits1(&s->gb); - if(!sps->frame_mbs_only_flag) - sps->mb_aff= get_bits1(&s->gb); - else - sps->mb_aff= 0; - - sps->direct_8x8_inference_flag= get_bits1(&s->gb); - -#ifndef ALLOW_INTERLACE - if(sps->mb_aff) - av_log(h->s.avctx, AV_LOG_ERROR, "MBAFF support not included; enable it at compile-time.\n"); -#endif - sps->crop= get_bits1(&s->gb); - if(sps->crop){ - 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"); - } - if(sps->crop_right >= 8 || sps->crop_bottom >= (8>> !sps->frame_mbs_only_flag)){ - av_log(h->s.avctx, AV_LOG_ERROR, "brainfart cropping not supported, this could look slightly wrong ...\n"); - } - }else{ - sps->crop_left = - sps->crop_right = - sps->crop_top = - sps->crop_bottom= 0; - } - - sps->vui_parameters_present_flag= get_bits1(&s->gb); - if( sps->vui_parameters_present_flag ) - if (decode_vui_parameters(h, sps) < 0) - goto fail; - - 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", - sps_id, sps->profile_idc, sps->level_idc, - sps->poc_type, - sps->ref_frame_count, - sps->mb_width, sps->mb_height, - sps->frame_mbs_only_flag ? "FRM" : (sps->mb_aff ? "MB-AFF" : "PIC-AFF"), - sps->direct_8x8_inference_flag ? "8B8" : "", - sps->crop_left, sps->crop_right, - sps->crop_top, sps->crop_bottom, - 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 - ); - } - - av_free(h->sps_buffers[sps_id]); - h->sps_buffers[sps_id]= sps; - h->sps = *sps; - return 0; -fail: - av_free(sps); - return -1; -} - -static void -build_qp_table(PPS *pps, int t, int index) -{ - int i; - for(i = 0; i < 52; i++) - pps->chroma_qp_table[t][i] = chroma_qp[av_clip(i + index, 0, 51)]; -} - -int ff_h264_decode_picture_parameter_set(H264Context *h, int bit_length){ - MpegEncContext * const s = &h->s; - unsigned int pps_id= get_ue_golomb(&s->gb); - PPS *pps; - - if(pps_id >= MAX_PPS_COUNT) { - av_log(h->s.avctx, AV_LOG_ERROR, "pps_id (%d) out of range\n", pps_id); - return -1; - } - - pps= av_mallocz(sizeof(PPS)); - if(pps == NULL) - return -1; - pps->sps_id= get_ue_golomb_31(&s->gb); - if((unsigned)pps->sps_id>=MAX_SPS_COUNT || h->sps_buffers[pps->sps_id] == NULL){ - av_log(h->s.avctx, AV_LOG_ERROR, "sps_id out of range\n"); - goto fail; - } - - pps->cabac= get_bits1(&s->gb); - pps->pic_order_present= get_bits1(&s->gb); - pps->slice_group_count= get_ue_golomb(&s->gb) + 1; - if(pps->slice_group_count > 1 ){ - pps->mb_slice_group_map_type= get_ue_golomb(&s->gb); - av_log(h->s.avctx, AV_LOG_ERROR, "FMO not supported\n"); - switch(pps->mb_slice_group_map_type){ - case 0: -#if 0 -| for( i = 0; i <= num_slice_groups_minus1; i++ ) | | | -| run_length[ i ] |1 |ue(v) | -#endif - break; - case 2: -#if 0 -| for( i = 0; i < num_slice_groups_minus1; i++ ) | | | -|{ | | | -| top_left_mb[ i ] |1 |ue(v) | -| bottom_right_mb[ i ] |1 |ue(v) | -| } | | | -#endif - break; - case 3: - case 4: - case 5: -#if 0 -| slice_group_change_direction_flag |1 |u(1) | -| slice_group_change_rate_minus1 |1 |ue(v) | -#endif - break; - case 6: -#if 0 -| slice_group_id_cnt_minus1 |1 |ue(v) | -| for( i = 0; i <= slice_group_id_cnt_minus1; i++ | | | -|) | | | -| slice_group_id[ i ] |1 |u(v) | -#endif - break; - } - } - pps->ref_count[0]= get_ue_golomb(&s->gb) + 1; - pps->ref_count[1]= get_ue_golomb(&s->gb) + 1; - if(pps->ref_count[0]-1 > 32-1 || pps->ref_count[1]-1 > 32-1){ - av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow (pps)\n"); - goto fail; - } - - pps->weighted_pred= get_bits1(&s->gb); - pps->weighted_bipred_idc= get_bits(&s->gb, 2); - pps->init_qp= get_se_golomb(&s->gb) + 26; - pps->init_qs= get_se_golomb(&s->gb) + 26; - pps->chroma_qp_index_offset[0]= get_se_golomb(&s->gb); - pps->deblocking_filter_parameters_present= get_bits1(&s->gb); - pps->constrained_intra_pred= get_bits1(&s->gb); - pps->redundant_pic_cnt_present = get_bits1(&s->gb); - - pps->transform_8x8_mode= 0; - h->dequant_coeff_pps= -1; //contents of sps/pps can change even if id doesn't, so reinit - 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)); - - 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); - pps->chroma_qp_index_offset[1]= get_se_golomb(&s->gb); //second_chroma_qp_index_offset - } else { - pps->chroma_qp_index_offset[1]= pps->chroma_qp_index_offset[0]; - } - - build_qp_table(pps, 0, pps->chroma_qp_index_offset[0]); - build_qp_table(pps, 1, pps->chroma_qp_index_offset[1]); - if(pps->chroma_qp_index_offset[0] != pps->chroma_qp_index_offset[1]) - h->pps.chroma_qp_diff= 1; - - if(s->avctx->debug&FF_DEBUG_PICT_INFO){ - av_log(h->s.avctx, AV_LOG_DEBUG, "pps:%u sps:%u %s slice_groups:%d ref:%d/%d %s qp:%d/%d/%d/%d %s %s %s %s\n", - pps_id, pps->sps_id, - pps->cabac ? "CABAC" : "CAVLC", - pps->slice_group_count, - pps->ref_count[0], pps->ref_count[1], - pps->weighted_pred ? "weighted" : "", - pps->init_qp, pps->init_qs, pps->chroma_qp_index_offset[0], pps->chroma_qp_index_offset[1], - pps->deblocking_filter_parameters_present ? "LPAR" : "", - pps->constrained_intra_pred ? "CONSTR" : "", - pps->redundant_pic_cnt_present ? "REDU" : "", - pps->transform_8x8_mode ? "8x8DCT" : "" - ); - } - - av_free(h->pps_buffers[pps_id]); - h->pps_buffers[pps_id]= pps; - return 0; -fail: - av_free(pps); - return -1; -} - /** * Call decode_slice() for each context. * @@ -7457,7 +2698,7 @@ static void execute_decode_slices(H264Context *h, int context_count){ } avctx->execute(avctx, (void *)decode_slice, - (void **)h->thread_context, NULL, context_count, sizeof(void*)); + h->thread_context, NULL, context_count, sizeof(void*)); /* pull back stuff from slices to master context */ hx = h->thread_context[context_count - 1]; @@ -7490,7 +2731,7 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){ h->current_slice = 0; if (!s->first_field) s->current_picture_ptr= NULL; - reset_sei(h); + ff_h264_reset_sei(h); } for(;;){ @@ -7518,7 +2759,7 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){ next_avc= buf_index + nalsize; } else { // start code prefix search - for(; buf_index + 3 < buf_size; buf_index++){ + for(; buf_index + 3 < next_avc; buf_index++){ // This should always succeed in the first iteration. if(buf[buf_index] == 0 && buf[buf_index+1] == 0 && buf[buf_index+2] == 1) break; @@ -7527,6 +2768,7 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){ if(buf_index+3 >= buf_size) break; buf_index+=3; + if(buf_index >= next_avc) continue; } hx = h->thread_context[context_count]; @@ -7535,8 +2777,15 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){ if (ptr==NULL || dst_length < 0){ return -1; } + i= buf_index + consumed; + if((s->workaround_bugs & FF_BUG_AUTODETECT) && i+3workaround_bugs |= FF_BUG_TRUNCATED; + + if(!(s->workaround_bugs & FF_BUG_TRUNCATED)){ while(ptr[dst_length - 1] == 0 && dst_length > 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){ @@ -7544,11 +2793,7 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){ } if (h->is_avc && (nalsize != consumed) && nalsize){ - int i, debug_level = AV_LOG_DEBUG; - for (i = consumed; i < nalsize; i++) - if (buf[buf_index+i]) - debug_level = AV_LOG_ERROR; - av_log(h->s.avctx, debug_level, "AVC: Consumed only %d bytes instead of %d\n", consumed, nalsize); + av_log(h->s.avctx, AV_LOG_DEBUG, "AVC: Consumed only %d bytes instead of %d\n", consumed, nalsize); } buf_index += consumed; @@ -7575,9 +2820,11 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){ if((err = decode_slice_header(hx, h))) break; - if (s->avctx->hwaccel && h->current_slice == 1) { - if (s->avctx->hwaccel->start_frame(s->avctx, NULL, 0) < 0) + if (h->current_slice == 1) { + if (s->avctx->hwaccel && s->avctx->hwaccel->start_frame(s->avctx, NULL, 0) < 0) return -1; + if(CONFIG_H264_VDPAU_DECODER && s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU) + ff_vdpau_h264_picture_start(s); } s->current_picture_ptr->key_frame |= @@ -7656,7 +2903,7 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){ case NAL_AUXILIARY_SLICE: break; default: - av_log(avctx, AV_LOG_DEBUG, "Unknown NAL code: %d (%d bits)\n", h->nal_unit_type, bit_length); + av_log(avctx, AV_LOG_DEBUG, "Unknown NAL code: %d (%d bits)\n", hx->nal_unit_type, bit_length); } if(context_count == h->max_contexts) { @@ -7731,53 +2978,6 @@ static int decode_frame(AVCodecContext *avctx, return 0; } - if(h->is_avc && !h->got_avcC) { - int i, cnt, nalsize; - unsigned char *p = avctx->extradata; - if(avctx->extradata_size < 7) { - av_log(avctx, AV_LOG_ERROR, "avcC too short\n"); - return -1; - } - if(*p != 1) { - av_log(avctx, AV_LOG_ERROR, "Unknown avcC version %d\n", *p); - return -1; - } - /* sps and pps in the avcC always have length coded with 2 bytes, - so put a fake nal_length_size = 2 while parsing them */ - h->nal_length_size = 2; - // Decode sps from avcC - cnt = *(p+5) & 0x1f; // Number of sps - p += 6; - for (i = 0; i < cnt; i++) { - nalsize = AV_RB16(p) + 2; - if(decode_nal_units(h, p, nalsize) < 0) { - av_log(avctx, AV_LOG_ERROR, "Decoding sps %d from avcC failed\n", i); - return -1; - } - p += nalsize; - } - // Decode pps from avcC - cnt = *(p++); // Number of pps - for (i = 0; i < cnt; i++) { - nalsize = AV_RB16(p) + 2; - if(decode_nal_units(h, p, nalsize) != nalsize) { - av_log(avctx, AV_LOG_ERROR, "Decoding pps %d from avcC failed\n", i); - return -1; - } - p += nalsize; - } - // Now store right nal length size, that will be use to parse all other nals - h->nal_length_size = ((*(((char*)(avctx->extradata))+4))&0x03)+1; - // Do not reparse avcC - h->got_avcC = 1; - } - - if(!h->got_avcC && !h->is_avc && s->avctx->extradata_size){ - if(decode_nal_units(h, s->avctx->extradata, s->avctx->extradata_size) < 0) - return -1; - h->got_avcC = 1; - } - buf_index=decode_nal_units(h, buf, buf_size); if(buf_index < 0) return -1; @@ -7791,7 +2991,7 @@ static int decode_frame(AVCodecContext *avctx, if(!(s->flags2 & CODEC_FLAG2_CHUNKS) || (s->mb_y >= s->mb_height && s->mb_height)){ Picture *out = s->current_picture_ptr; Picture *cur = s->current_picture_ptr; - int i, pics, cross_idr, out_of_order, out_idx; + int i, pics, out_of_order, out_idx; field_end(h); @@ -7895,15 +3095,15 @@ static int decode_frame(AVCodecContext *avctx, out = h->delayed_pic[i]; out_idx = i; } - cross_idr = !!h->delayed_pic[i] || h->delayed_pic[0]->key_frame || h->delayed_pic[0]->mmco_reset; - - out_of_order = !cross_idr && out->poc < h->outputed_poc; + if(s->avctx->has_b_frames == 0 && (h->delayed_pic[0]->key_frame || h->delayed_pic[0]->mmco_reset)) + h->outputed_poc= INT_MIN; + out_of_order = out->poc < h->outputed_poc; if(h->sps.bitstream_restriction_flag && s->avctx->has_b_frames >= h->sps.num_reorder_frames) { } else if((out_of_order && pics-1 == s->avctx->has_b_frames && s->avctx->has_b_frames < MAX_DELAYED_PIC_COUNT) || (s->low_delay && - ((!cross_idr && out->poc > h->outputed_poc + 2) + ((h->outputed_poc != INT_MIN && out->poc > h->outputed_poc + 2) || cur->pict_type == FF_B_TYPE))) { s->low_delay = 0; @@ -7918,7 +3118,10 @@ static int decode_frame(AVCodecContext *avctx, if(!out_of_order && pics > s->avctx->has_b_frames){ *data_size = sizeof(AVFrame); - h->outputed_poc = out->poc; + if(out_idx==0 && h->delayed_pic[0] && (h->delayed_pic[0]->key_frame || h->delayed_pic[0]->mmco_reset)) { + h->outputed_poc = INT_MIN; + } else + h->outputed_poc = out->poc; *pict= *(AVFrame*)out; }else{ av_log(avctx, AV_LOG_DEBUG, "no picture\n"); @@ -8043,7 +3246,7 @@ int main(void){ } // printf("\n"); - s->dsp.h264_idct_add(ref, block, 4); + h->h264dsp.h264_idct_add(ref, block, 4); /* for(j=0; j<16; j++){ printf("%d ", ref[j]); } @@ -8141,7 +3344,7 @@ av_cold void ff_h264_free_context(H264Context *h) av_freep(h->pps_buffers + i); } -static av_cold int decode_end(AVCodecContext *avctx) +av_cold int ff_h264_decode_end(AVCodecContext *avctx) { H264Context *h = avctx->priv_data; MpegEncContext *s = &h->s; @@ -8158,12 +3361,12 @@ static av_cold int decode_end(AVCodecContext *avctx) AVCodec h264_decoder = { "h264", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_H264, sizeof(H264Context), - decode_init, + ff_h264_decode_init, NULL, - decode_end, + ff_h264_decode_end, decode_frame, /*CODEC_CAP_DRAW_HORIZ_BAND |*/ CODEC_CAP_DR1 | CODEC_CAP_DELAY, .flush= flush_dpb, @@ -8174,19 +3377,16 @@ AVCodec h264_decoder = { #if CONFIG_H264_VDPAU_DECODER AVCodec h264_vdpau_decoder = { "h264_vdpau", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_H264, sizeof(H264Context), - decode_init, + ff_h264_decode_init, NULL, - decode_end, + ff_h264_decode_end, decode_frame, 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}, }; #endif - -#if CONFIG_SVQ3_DECODER -#include "svq3.c" -#endif diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/h264.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264.h index fa348a201f..c6563af35e 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/h264.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264.h @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/h264.h + * @file * H.264 / AVC / MPEG4 part10 codec. * @author Michael Niedermayer */ @@ -28,10 +28,13 @@ #ifndef AVCODEC_H264_H #define AVCODEC_H264_H +#include "libavutil/intreadwrite.h" #include "dsputil.h" #include "cabac.h" #include "mpegvideo.h" +#include "h264dsp.h" #include "h264pred.h" +#include "rectangle.h" #define interlaced_dct interlaced_dct_is_a_bad_name #define mb_intra mb_intra_is_not_initialized_see_mb_type @@ -59,6 +62,8 @@ #define ALLOW_NOCHROMA +#define FMO 0 + /** * The maximum number of slices supported by the decoder. * must be a power of 2 @@ -86,6 +91,10 @@ #define CHROMA 1 #endif +#ifndef CABAC +#define CABAC h->pps.cabac +#endif + #define EXTENDED_SAR 255 #define MB_TYPE_REF0 MB_TYPE_ACPRED //dirty but it fits in 16 bit @@ -93,6 +102,13 @@ #define IS_REF0(a) ((a) & MB_TYPE_REF0) #define IS_8x8DCT(a) ((a) & MB_TYPE_8x8DCT) +/** + * Value of Picture.reference when Picture is not a reference picture, but + * is held for delayed output. + */ +#define DELAYED_PIC_REF 4 + + /* NAL unit types */ enum { NAL_SLICE=1, @@ -166,6 +182,12 @@ typedef struct SPS{ unsigned int crop_bottom; ///< frame_cropping_rect_bottom_offset int vui_parameters_present_flag; AVRational sar; + int video_signal_type_present_flag; + int full_range; + int colour_description_present_flag; + enum AVColorPrimaries color_primaries; + enum AVColorTransferCharacteristic color_trc; + enum AVColorSpace colorspace; int timing_info_present_flag; uint32_t num_units_in_tick; uint32_t time_scale; @@ -241,20 +263,11 @@ typedef struct MMCO{ */ typedef struct H264Context{ MpegEncContext s; - int nal_ref_idc; - int nal_unit_type; - uint8_t *rbsp_buffer[2]; - unsigned int rbsp_buffer_size[2]; - - /** - * Used to parse AVC variant of h264 - */ - int is_avc; ///< this flag is != 0 if codec is avc1 - int got_avcC; ///< flag used to parse avcC data only once - int nal_length_size; ///< Number of bytes used for nal length (1, 2 or 4) - + H264DSPContext h264dsp; int chroma_qp[2]; //QPc + int qp_thresh; ///< QP threshold to skip loopfilter + int prev_mb_skipped; int next_mb_skipped; @@ -262,31 +275,47 @@ typedef struct H264Context{ int chroma_pred_mode; int intra16x16_pred_mode; + int topleft_mb_xy; int top_mb_xy; + int topright_mb_xy; int left_mb_xy[2]; + int topleft_type; + int top_type; + int topright_type; + int left_type[2]; + + const uint8_t * left_block; + int topleft_partition; + int8_t intra4x4_pred_mode_cache[5*8]; - int8_t (*intra4x4_pred_mode)[8]; + int8_t (*intra4x4_pred_mode); H264PredContext hpc; unsigned int topleft_samples_available; unsigned int top_samples_available; unsigned int topright_samples_available; unsigned int left_samples_available; uint8_t (*top_borders[2])[16+2*8]; - uint8_t left_border[2*(17+2*9)]; /** * non zero coeff count cache. * is 64 if not available. */ - DECLARE_ALIGNED_8(uint8_t, non_zero_count_cache[6*8]); - uint8_t (*non_zero_count)[16]; + DECLARE_ALIGNED(8, uint8_t, non_zero_count_cache)[6*8]; + + /* + .UU.YYYY + .UU.YYYY + .vv.YYYY + .VV.YYYY + */ + uint8_t (*non_zero_count)[32]; /** * Motion vector cache. */ - DECLARE_ALIGNED_8(int16_t, mv_cache[2][5*8][2]); - DECLARE_ALIGNED_8(int8_t, ref_cache[2][5*8]); + DECLARE_ALIGNED(16, int16_t, mv_cache)[2][5*8][2]; + DECLARE_ALIGNED(8, int8_t, ref_cache)[2][5*8]; #define LIST_NOT_USED -1 //FIXME rename? #define PART_NOT_AVAILABLE -2 @@ -307,9 +336,8 @@ typedef struct H264Context{ int block_offset[2*(16+8)]; uint32_t *mb2b_xy; //FIXME are these 4 a good idea? - uint32_t *mb2b8_xy; + uint32_t *mb2br_xy; int b_stride; //FIXME use s->b4_stride - int b8_stride; int mb_linesize; ///< may be equal to s->linesize or s->linesize*2, for mbaff int mb_uvlinesize; @@ -317,29 +345,19 @@ typedef struct H264Context{ int emu_edge_width; int emu_edge_height; - int halfpel_flag; - int thirdpel_flag; - - int unknown_svq3_flag; - int next_slice_index; - - SPS *sps_buffers[MAX_SPS_COUNT]; SPS sps; ///< current sps - PPS *pps_buffers[MAX_PPS_COUNT]; /** * current pps */ PPS pps; //FIXME move to Picture perhaps? (->no) do we need that? - uint32_t dequant4_buffer[6][52][16]; + uint32_t dequant4_buffer[6][52][16]; //FIXME should these be moved down? uint32_t dequant8_buffer[2][52][64]; uint32_t (*dequant4_coeff[6])[16]; uint32_t (*dequant8_coeff[2])[64]; - int dequant_coeff_pps; ///< reinit tables when pps changes int slice_num; - uint16_t *slice_table_base; uint16_t *slice_table; ///< slice_table_base + 2*mb_stride + 1 int slice_type; int slice_type_nos; ///< S free slice type (SI/SP are remapped to I/P) @@ -350,7 +368,110 @@ typedef struct H264Context{ int mb_field_decoding_flag; int mb_mbaff; ///< mb_aff_frame && mb_field_decoding_flag - DECLARE_ALIGNED_8(uint16_t, sub_mb_type[4]); + DECLARE_ALIGNED(8, uint16_t, sub_mb_type)[4]; + + //Weighted pred stuff + int use_weight; + int use_weight_chroma; + int luma_log2_weight_denom; + int chroma_log2_weight_denom; + //The following 2 can be changed to int8_t but that causes 10cpu cycles speedloss + int luma_weight[48][2][2]; + int chroma_weight[48][2][2][2]; + int implicit_weight[48][48][2]; + + int direct_spatial_mv_pred; + int col_parity; + int col_fieldoff; + int dist_scale_factor[16]; + int dist_scale_factor_field[2][32]; + int map_col_to_list0[2][16+32]; + int map_col_to_list0_field[2][2][16+32]; + + /** + * num_ref_idx_l0/1_active_minus1 + 1 + */ + 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 */ + int ref2frm[MAX_SLICES][2][64]; ///< reference to frame number lists, used in the loop filter, the first 2 are for -2,-1 + + //data partitioning + GetBitContext intra_gb; + GetBitContext inter_gb; + GetBitContext *intra_gb_ptr; + GetBitContext *inter_gb_ptr; + + DECLARE_ALIGNED(16, DCTELEM, mb)[16*24]; + DCTELEM mb_padding[256]; ///< as mb is addressed by scantable[i] and scantable is uint8_t we can either check that i is not too large or ensure that there is some unused stuff after mb + + /** + * Cabac + */ + CABACContext cabac; + uint8_t cabac_state[460]; + + /* 0x100 -> non null luma_dc, 0x80/0x40 -> non null chroma_dc (cb/cr), 0x?0 -> chroma_cbp(0,1,2), 0x0? luma_cbp */ + uint16_t *cbp_table; + int cbp; + int top_cbp; + int left_cbp; + /* chroma_pred_mode for i4x4 or i16x16, else 0 */ + uint8_t *chroma_pred_mode_table; + int last_qscale_diff; + uint8_t (*mvd_table[2])[2]; + DECLARE_ALIGNED(16, uint8_t, mvd_cache)[2][5*8][2]; + uint8_t *direct_table; + uint8_t direct_cache[5*8]; + + uint8_t zigzag_scan[16]; + uint8_t zigzag_scan8x8[64]; + uint8_t zigzag_scan8x8_cavlc[64]; + uint8_t field_scan[16]; + uint8_t field_scan8x8[64]; + uint8_t field_scan8x8_cavlc[64]; + const uint8_t *zigzag_scan_q0; + const uint8_t *zigzag_scan8x8_q0; + const uint8_t *zigzag_scan8x8_cavlc_q0; + const uint8_t *field_scan_q0; + const uint8_t *field_scan8x8_q0; + const uint8_t *field_scan8x8_cavlc_q0; + + int x264_build; + + int mb_xy; + + int is_complex; + + //deblock + int deblocking_filter; ///< disable_deblocking_filter_idc with 1<->0 + int slice_alpha_c0_offset; + int slice_beta_offset; + +//============================================================= + //Things below are not used in the MB or more inner code + + int nal_ref_idc; + int nal_unit_type; + uint8_t *rbsp_buffer[2]; + unsigned int rbsp_buffer_size[2]; + + /** + * Used to parse AVC variant of h264 + */ + int is_avc; ///< this flag is != 0 if codec is avc1 + int nal_length_size; ///< Number of bytes used for nal length (1, 2 or 4) + + SPS *sps_buffers[MAX_SPS_COUNT]; + PPS *pps_buffers[MAX_PPS_COUNT]; + + int dequant_coeff_pps; ///< reinit tables when pps changes + + uint16_t *slice_table_base; + //POC stuff int poc_lsb; @@ -374,42 +495,11 @@ typedef struct H264Context{ */ int max_pic_num; - //Weighted pred stuff - int use_weight; - int use_weight_chroma; - int luma_log2_weight_denom; - int chroma_log2_weight_denom; - int luma_weight[2][48]; - int luma_offset[2][48]; - int chroma_weight[2][48][2]; - int chroma_offset[2][48][2]; - int implicit_weight[48][48]; - - //deblock - int deblocking_filter; ///< disable_deblocking_filter_idc with 1<->0 - int slice_alpha_c0_offset; - int slice_beta_offset; - int redundant_pic_count; - int direct_spatial_mv_pred; - int dist_scale_factor[16]; - int dist_scale_factor_field[2][32]; - int map_col_to_list0[2][16+32]; - int map_col_to_list0_field[2][2][16+32]; - - /** - * num_ref_idx_l0/1_active_minus1 + 1 - */ - unsigned int ref_count[2]; ///< counts frames or fields, depending on current mb mode - unsigned int list_count; Picture *short_ref[32]; Picture *long_ref[32]; Picture default_ref_list[2][32]; ///< base reference list for all slices of a coded picture - 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 */ - int ref2frm[MAX_SLICES][2][64]; ///< reference to frame number lists, used in the loop filter, the first 2 are for -2,-1 Picture *delayed_pic[MAX_DELAYED_PIC_COUNT+2]; //FIXME size? int outputed_poc; @@ -422,50 +512,8 @@ typedef struct H264Context{ int long_ref_count; ///< number of actual long term references int short_ref_count; ///< number of actual short term references - //data partitioning - GetBitContext intra_gb; - GetBitContext inter_gb; - GetBitContext *intra_gb_ptr; - GetBitContext *inter_gb_ptr; - - DECLARE_ALIGNED_16(DCTELEM, mb[16*24]); - DCTELEM mb_padding[256]; ///< as mb is addressed by scantable[i] and scantable is uint8_t we can either check that i is not too large or ensure that there is some unused stuff after mb - - /** - * Cabac - */ - CABACContext cabac; - uint8_t cabac_state[460]; int cabac_init_idc; - /* 0x100 -> non null luma_dc, 0x80/0x40 -> non null chroma_dc (cb/cr), 0x?0 -> chroma_cbp(0,1,2), 0x0? luma_cbp */ - uint16_t *cbp_table; - int cbp; - int top_cbp; - int left_cbp; - /* chroma_pred_mode for i4x4 or i16x16, else 0 */ - uint8_t *chroma_pred_mode_table; - int last_qscale_diff; - int16_t (*mvd_table[2])[2]; - DECLARE_ALIGNED_8(int16_t, mvd_cache[2][5*8][2]); - uint8_t *direct_table; - uint8_t direct_cache[5*8]; - - uint8_t zigzag_scan[16]; - uint8_t zigzag_scan8x8[64]; - uint8_t zigzag_scan8x8_cavlc[64]; - uint8_t field_scan[16]; - uint8_t field_scan8x8[64]; - uint8_t field_scan8x8_cavlc[64]; - const uint8_t *zigzag_scan_q0; - const uint8_t *zigzag_scan8x8_q0; - const uint8_t *zigzag_scan8x8_cavlc_q0; - const uint8_t *field_scan_q0; - const uint8_t *field_scan8x8_q0; - const uint8_t *field_scan8x8_cavlc_q0; - - int x264_build; - /** * @defgroup multithreading Members for slice based multithreading * @{ @@ -494,10 +542,6 @@ typedef struct H264Context{ int last_slice_type; /** @} */ - int mb_xy; - - uint32_t svq3_watermark_key; - /** * pic_struct in picture timing SEI message */ @@ -537,16 +581,28 @@ typedef struct H264Context{ */ int sei_recovery_frame_cnt; - int is_complex; - 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 // Timestamp stuff int sei_buffering_period_present; ///< Buffering period SEI flag int initial_cpb_removal_delay[32]; ///< Initial timestamps for CPBs + + //SVQ3 specific fields + int halfpel_flag; + int thirdpel_flag; + int unknown_svq3_flag; + int next_slice_index; + uint32_t svq3_watermark_key; }H264Context; + +extern const uint8_t ff_h264_chroma_qp[52]; + +void ff_svq3_luma_dc_dequant_idct_c(DCTELEM *block, int qp); + +void ff_svq3_add_idct_c(uint8_t *dst, DCTELEM *block, int stride, int qp, int dc); + /** * Decode SEI */ @@ -567,7 +623,7 @@ int ff_h264_decode_picture_parameter_set(H264Context *h, int bit_length); * @param consumed is the number of bytes used as input * @param length is the length of the array * @param dst_length is the number of decoded bytes FIXME here or a decode rbsp tailing? - * @returns decoded bytes, might be src+1 if no escapes + * @return decoded bytes, might be src+1 if no escapes */ const uint8_t *ff_h264_decode_nal(H264Context *h, const uint8_t *src, int *dst_length, int *consumed, int length); @@ -582,4 +638,662 @@ int ff_h264_decode_rbsp_trailing(H264Context *h, const uint8_t *src); */ av_cold void ff_h264_free_context(H264Context *h); +/** + * reconstructs bitstream slice_type. + */ +int ff_h264_get_slice_type(const H264Context *h); + +/** + * allocates tables. + * needs width/height + */ +int ff_h264_alloc_tables(H264Context *h); + +/** + * fills the default_ref_list. + */ +int ff_h264_fill_default_ref_list(H264Context *h); + +int ff_h264_decode_ref_pic_list_reordering(H264Context *h); +void ff_h264_fill_mbaff_ref_list(H264Context *h); +void ff_h264_remove_all_refs(H264Context *h); + +/** + * Executes the reference picture marking (memory management control operations). + */ +int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count); + +int ff_h264_decode_ref_pic_marking(H264Context *h, GetBitContext *gb); + + +/** + * 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_intra4x4_pred_mode(H264Context *h); + +/** + * 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); + +void ff_h264_write_back_intra_pred_mode(H264Context *h); +void ff_h264_hl_decode_mb(H264Context *h); +int ff_h264_frame_start(H264Context *h); +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); + +/** + * decodes a macroblock + * @return 0 if OK, AC_ERROR / DC_ERROR / MV_ERROR if an error is noticed + */ +int ff_h264_decode_mb_cavlc(H264Context *h); + +/** + * decodes a CABAC coded macroblock + * @return 0 if OK, AC_ERROR / DC_ERROR / MV_ERROR if an error is noticed + */ +int ff_h264_decode_mb_cabac(H264Context *h); + +void ff_h264_init_cabac_states(H264Context *h); + +void ff_h264_direct_dist_scale_factor(H264Context * const h); +void ff_h264_direct_ref_list_init(H264Context * const h); +void ff_h264_pred_direct_motion(H264Context * const h, int *mb_type); + +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); +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); + +/** + * Reset SEI values at the beginning of the frame. + * + * @param h H.264 context. + */ +void ff_h264_reset_sei(H264Context *h); + + +/* +o-o o-o + / / / +o-o o-o + ,---' +o-o o-o + / / / +o-o o-o +*/ +//This table must be here because scan8[constant] must be known at compiletime +static const uint8_t scan8[16 + 2*4]={ + 4+1*8, 5+1*8, 4+2*8, 5+2*8, + 6+1*8, 7+1*8, 6+2*8, 7+2*8, + 4+3*8, 5+3*8, 4+4*8, 5+4*8, + 6+3*8, 7+3*8, 6+4*8, 7+4*8, + 1+1*8, 2+1*8, + 1+2*8, 2+2*8, + 1+4*8, 2+4*8, + 1+5*8, 2+5*8, +}; + +static av_always_inline uint32_t pack16to32(int a, int b){ +#if HAVE_BIGENDIAN + return (b&0xFFFF) + (a<<16); +#else + return (a&0xFFFF) + (b<<16); +#endif +} + +static av_always_inline uint16_t pack8to16(int a, int b){ +#if HAVE_BIGENDIAN + return (b&0xFF) + (a<<8); +#else + return (a&0xFF) + (b<<8); +#endif +} + +/** + * gets the chroma qp. + */ +static 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[2]; + static const uint8_t left_block_options[4][16]={ + {0,1,2,3,7,10,8,11,7+0*8, 7+1*8, 7+2*8, 7+3*8, 2+0*8, 2+3*8, 2+1*8, 2+2*8}, + {2,2,3,3,8,11,8,11,7+2*8, 7+2*8, 7+3*8, 7+3*8, 2+1*8, 2+2*8, 2+1*8, 2+2*8}, + {0,0,1,1,7,10,7,10,7+0*8, 7+0*8, 7+1*8, 7+1*8, 2+0*8, 2+3*8, 2+0*8, 2+3*8}, + {0,2,0,2,7,10,7,10,7+0*8, 7+2*8, 7+0*8, 7+2*8, 2+0*8, 2+3*8, 2+0*8, 2+3*8} + }; + + 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[1] = left_xy[0] = 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[1] = left_xy[0] = mb_xy - s->mb_stride - 1; + if (curr_mb_field_flag) { + left_xy[1] += 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[1] += 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[0] = left_xy[0]; + h->left_mb_xy[1] = left_xy[1]; + //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[0] = s->current_picture.mb_type[left_xy[0]] ; + h->left_type[1] = s->current_picture.mb_type[left_xy[1]] ; + + 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[0] ] != h->slice_num) h->left_type[0] = h->left_type[1] = 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[0] ] != h->slice_num) h->left_type[0] = h->left_type[1] = 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[2]; + int topleft_type, top_type, topright_type, left_type[2]; + const uint8_t * left_block= h->left_block; + int i; + + topleft_xy = h->topleft_mb_xy ; + top_xy = h->top_mb_xy ; + topright_xy = h->topright_mb_xy; + left_xy[0] = h->left_mb_xy[0] ; + left_xy[1] = h->left_mb_xy[1] ; + topleft_type = h->topleft_type ; + top_type = h->top_type ; + topright_type= h->topright_type ; + left_type[0] = h->left_type[0] ; + left_type[1] = h->left_type[1] ; + + 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[0])){ + if(IS_INTERLACED(mb_type)){ + if(!(left_type[0] & type_mask)){ + h->topleft_samples_available&= 0xDFFF; + h->left_samples_available&= 0x5FFF; + } + if(!(left_type[1] & type_mask)){ + h->topleft_samples_available&= 0xFF5F; + h->left_samples_available&= 0xFF5F; + } + }else{ + int left_typei = s->current_picture.mb_type[left_xy[0] + s->mb_stride]; + + assert(left_xy[0] == left_xy[1]); + if(!((left_typei & type_mask) && (left_type[0] & type_mask))){ + h->topleft_samples_available&= 0xDF5F; + h->left_samples_available&= 0x5F5F; + } + } + }else{ + if(!(left_type[0] & 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[i])){ + int8_t *mode= h->intra4x4_pred_mode + h->mb2br_xy[left_xy[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[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) + if(top_type){ + AV_COPY32(&h->non_zero_count_cache[4+8*0], &h->non_zero_count[top_xy][4+3*8]); + h->non_zero_count_cache[1+8*0]= h->non_zero_count[top_xy][1+1*8]; + h->non_zero_count_cache[2+8*0]= h->non_zero_count[top_xy][2+1*8]; + + h->non_zero_count_cache[1+8*3]= h->non_zero_count[top_xy][1+2*8]; + h->non_zero_count_cache[2+8*3]= h->non_zero_count[top_xy][2+2*8]; + }else { + h->non_zero_count_cache[1+8*0]= + h->non_zero_count_cache[2+8*0]= + + h->non_zero_count_cache[1+8*3]= + h->non_zero_count_cache[2+8*3]= + AV_WN32A(&h->non_zero_count_cache[4+8*0], CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040); + } + + for (i=0; i<2; i++) { + if(left_type[i]){ + h->non_zero_count_cache[3+8*1 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[8+0+2*i]]; + h->non_zero_count_cache[3+8*2 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[8+1+2*i]]; + h->non_zero_count_cache[0+8*1 + 8*i]= h->non_zero_count[left_xy[i]][left_block[8+4+2*i]]; + h->non_zero_count_cache[0+8*4 + 8*i]= h->non_zero_count[left_xy[i]][left_block[8+5+2*i]]; + }else{ + h->non_zero_count_cache[3+8*1 + 2*8*i]= + h->non_zero_count_cache[3+8*2 + 2*8*i]= + h->non_zero_count_cache[0+8*1 + 8*i]= + h->non_zero_count_cache[0+8*4 + 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) ? 0x1CF : 0x00F; + } + // left_cbp + if (left_type[0]) { + h->left_cbp = (h->cbp_table[left_xy[0]] & 0x1f0) + | ((h->cbp_table[left_xy[0]]>>(left_block[0]&(~1)))&2) + | (((h->cbp_table[left_xy[1]]>>(left_block[2]&(~1)))&2) << 2); + } else { + h->left_cbp = IS_INTRA(mb_type) ? 0x1CF : 0x00F; + } + } + } + +#if 1 + if(IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)){ + int list; + for(list=0; listlist_count; list++){ + if(!USES_LIST(mb_type, list)){ + /*if(!h->mv_cache_clean[list]){ + memset(h->mv_cache [list], 0, 8*5*2*sizeof(int16_t)); //FIXME clean only input? clean at all? + memset(h->ref_cache[list], PART_NOT_AVAILABLE, 8*5*sizeof(int8_t)); + h->mv_cache_clean[list]= 1; + }*/ + continue; + } + assert(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred)); + + h->mv_cache_clean[list]= 0; + + if(USES_LIST(top_type, list)){ + const int b_xy= h->mb2b_xy[top_xy] + 3*h->b_stride; + AV_COPY128(h->mv_cache[list][scan8[0] + 0 - 1*8], s->current_picture.motion_val[list][b_xy + 0]); + h->ref_cache[list][scan8[0] + 0 - 1*8]= + h->ref_cache[list][scan8[0] + 1 - 1*8]= s->current_picture.ref_index[list][4*top_xy + 2]; + h->ref_cache[list][scan8[0] + 2 - 1*8]= + h->ref_cache[list][scan8[0] + 3 - 1*8]= s->current_picture.ref_index[list][4*top_xy + 3]; + }else{ + AV_ZERO128(h->mv_cache[list][scan8[0] + 0 - 1*8]); + AV_WN32A(&h->ref_cache[list][scan8[0] + 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 = scan8[0] - 1 + i*2*8; + if(USES_LIST(left_type[i], list)){ + const int b_xy= h->mb2b_xy[left_xy[i]] + 3; + const int b8_xy= 4*left_xy[i] + 1; + AV_COPY32(h->mv_cache[list][cache_idx ], s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[0+i*2]]); + AV_COPY32(h->mv_cache[list][cache_idx+8], s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[1+i*2]]); + h->ref_cache[list][cache_idx ]= s->current_picture.ref_index[list][b8_xy + (left_block[0+i*2]&~1)]; + h->ref_cache[list][cache_idx+8]= s->current_picture.ref_index[list][b8_xy + (left_block[1+i*2]&~1)]; + }else{ + AV_ZERO32(h->mv_cache [list][cache_idx ]); + AV_ZERO32(h->mv_cache [list][cache_idx+8]); + h->ref_cache[list][cache_idx ]= + h->ref_cache[list][cache_idx+8]= (left_type[i]) ? LIST_NOT_USED : PART_NOT_AVAILABLE; + } + } + }else{ + if(USES_LIST(left_type[0], list)){ + const int b_xy= h->mb2b_xy[left_xy[0]] + 3; + const int b8_xy= 4*left_xy[0] + 1; + AV_COPY32(h->mv_cache[list][scan8[0] - 1], s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[0]]); + h->ref_cache[list][scan8[0] - 1]= s->current_picture.ref_index[list][b8_xy + (left_block[0]&~1)]; + }else{ + AV_ZERO32(h->mv_cache [list][scan8[0] - 1]); + h->ref_cache[list][scan8[0] - 1]= left_type[0] ? LIST_NOT_USED : PART_NOT_AVAILABLE; + } + } + + if(USES_LIST(topright_type, list)){ + const int b_xy= h->mb2b_xy[topright_xy] + 3*h->b_stride; + AV_COPY32(h->mv_cache[list][scan8[0] + 4 - 1*8], s->current_picture.motion_val[list][b_xy]); + h->ref_cache[list][scan8[0] + 4 - 1*8]= s->current_picture.ref_index[list][4*topright_xy + 2]; + }else{ + AV_ZERO32(h->mv_cache [list][scan8[0] + 4 - 1*8]); + h->ref_cache[list][scan8[0] + 4 - 1*8]= topright_type ? LIST_NOT_USED : PART_NOT_AVAILABLE; + } + if(h->ref_cache[list][scan8[0] + 4 - 1*8] < 0){ + if(USES_LIST(topleft_type, list)){ + const int b_xy = h->mb2b_xy [topleft_xy] + 3 + h->b_stride + (h->topleft_partition & 2*h->b_stride); + const int b8_xy= 4*topleft_xy + 1 + (h->topleft_partition & 2); + AV_COPY32(h->mv_cache[list][scan8[0] - 1 - 1*8], s->current_picture.motion_val[list][b_xy]); + h->ref_cache[list][scan8[0] - 1 - 1*8]= s->current_picture.ref_index[list][b8_xy]; + }else{ + AV_ZERO32(h->mv_cache[list][scan8[0] - 1 - 1*8]); + h->ref_cache[list][scan8[0] - 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))) { + h->ref_cache[list][scan8[4 ]] = + h->ref_cache[list][scan8[12]] = PART_NOT_AVAILABLE; + AV_ZERO32(h->mv_cache [list][scan8[4 ]]); + AV_ZERO32(h->mv_cache [list][scan8[12]]); + + if( CABAC ) { + /* XXX beurk, Load mvd */ + if(USES_LIST(top_type, list)){ + const int b_xy= h->mb2br_xy[top_xy]; + AV_COPY64(h->mvd_cache[list][scan8[0] + 0 - 1*8], h->mvd_table[list][b_xy + 0]); + }else{ + AV_ZERO64(h->mvd_cache[list][scan8[0] + 0 - 1*8]); + } + if(USES_LIST(left_type[0], list)){ + const int b_xy= h->mb2br_xy[left_xy[0]] + 6; + AV_COPY16(h->mvd_cache[list][scan8[0] - 1 + 0*8], h->mvd_table[list][b_xy - left_block[0]]); + AV_COPY16(h->mvd_cache[list][scan8[0] - 1 + 1*8], h->mvd_table[list][b_xy - left_block[1]]); + }else{ + AV_ZERO16(h->mvd_cache [list][scan8[0] - 1 + 0*8]); + AV_ZERO16(h->mvd_cache [list][scan8[0] - 1 + 1*8]); + } + if(USES_LIST(left_type[1], list)){ + const int b_xy= h->mb2br_xy[left_xy[1]] + 6; + AV_COPY16(h->mvd_cache[list][scan8[0] - 1 + 2*8], h->mvd_table[list][b_xy - left_block[2]]); + AV_COPY16(h->mvd_cache[list][scan8[0] - 1 + 3*8], h->mvd_table[list][b_xy - left_block[3]]); + }else{ + AV_ZERO16(h->mvd_cache [list][scan8[0] - 1 + 2*8]); + AV_ZERO16(h->mvd_cache [list][scan8[0] - 1 + 3*8]); + } + AV_ZERO16(h->mvd_cache [list][scan8[4 ]]); + AV_ZERO16(h->mvd_cache [list][scan8[12]]); + if(h->slice_type_nos == FF_B_TYPE){ + fill_rectangle(&h->direct_cache[scan8[0]], 4, 4, 8, MB_TYPE_16x16>>1, 1); + + if(IS_DIRECT(top_type)){ + AV_WN32A(&h->direct_cache[scan8[0] - 1*8], 0x01010101u*(MB_TYPE_DIRECT2>>1)); + }else if(IS_8X8(top_type)){ + int b8_xy = 4*top_xy; + h->direct_cache[scan8[0] + 0 - 1*8]= h->direct_table[b8_xy + 2]; + h->direct_cache[scan8[0] + 2 - 1*8]= h->direct_table[b8_xy + 3]; + }else{ + AV_WN32A(&h->direct_cache[scan8[0] - 1*8], 0x01010101*(MB_TYPE_16x16>>1)); + } + + if(IS_DIRECT(left_type[0])) + h->direct_cache[scan8[0] - 1 + 0*8]= MB_TYPE_DIRECT2>>1; + else if(IS_8X8(left_type[0])) + h->direct_cache[scan8[0] - 1 + 0*8]= h->direct_table[4*left_xy[0] + 1 + (left_block[0]&~1)]; + else + h->direct_cache[scan8[0] - 1 + 0*8]= MB_TYPE_16x16>>1; + + if(IS_DIRECT(left_type[1])) + h->direct_cache[scan8[0] - 1 + 2*8]= MB_TYPE_DIRECT2>>1; + else if(IS_8X8(left_type[1])) + h->direct_cache[scan8[0] - 1 + 2*8]= h->direct_table[4*left_xy[1] + 1 + (left_block[2]&~1)]; + else + h->direct_cache[scan8[0] - 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[0])\ + MAP_F2F(scan8[0] - 1 + 1*8, left_type[0])\ + MAP_F2F(scan8[0] - 1 + 2*8, left_type[1])\ + MAP_F2F(scan8[0] - 1 + 3*8, left_type[1]) + 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 + } + } + } + } +#endif + + h->neighbor_transform_size= !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[0]); +} + +/** + * gets the predicted intra4x4 prediction mode. + */ +static inline int pred_intra_mode(H264Context *h, int n){ + const int index8= scan8[n]; + const int left= h->intra4x4_pred_mode_cache[index8 - 1]; + const int top = h->intra4x4_pred_mode_cache[index8 - 8]; + const int min= FFMIN(left, top); + + tprintf(h->s.avctx, "mode:%d %d min:%d\n", left ,top, min); + + if(min<0) return DC_PRED; + else return min; +} + +static inline void write_back_non_zero_count(H264Context *h){ + const int mb_xy= h->mb_xy; + + AV_COPY64(&h->non_zero_count[mb_xy][ 0], &h->non_zero_count_cache[0+8*1]); + AV_COPY64(&h->non_zero_count[mb_xy][ 8], &h->non_zero_count_cache[0+8*2]); + AV_COPY32(&h->non_zero_count[mb_xy][16], &h->non_zero_count_cache[0+8*5]); + AV_COPY32(&h->non_zero_count[mb_xy][20], &h->non_zero_count_cache[4+8*3]); + AV_COPY64(&h->non_zero_count[mb_xy][24], &h->non_zero_count_cache[0+8*4]); +} + +static inline void write_back_motion(H264Context *h, int mb_type){ + MpegEncContext * const s = &h->s; + const int b_xy = 4*s->mb_x + 4*s->mb_y*h->b_stride; //try mb2b(8)_xy + const int b8_xy= 4*h->mb_xy; + int list; + + if(!USES_LIST(mb_type, 0)) + fill_rectangle(&s->current_picture.ref_index[0][b8_xy], 2, 2, 2, (uint8_t)LIST_NOT_USED, 1); + + for(list=0; listlist_count; list++){ + int y, b_stride; + int16_t (*mv_dst)[2]; + int16_t (*mv_src)[2]; + + if(!USES_LIST(mb_type, list)) + continue; + + b_stride = h->b_stride; + mv_dst = &s->current_picture.motion_val[list][b_xy]; + mv_src = &h->mv_cache[list][scan8[0]]; + for(y=0; y<4; y++){ + AV_COPY128(mv_dst + y*b_stride, mv_src + 8*y); + } + if( CABAC ) { + uint8_t (*mvd_dst)[2] = &h->mvd_table[list][FMO ? 8*h->mb_xy : h->mb2br_xy[h->mb_xy]]; + uint8_t (*mvd_src)[2] = &h->mvd_cache[list][scan8[0]]; + if(IS_SKIP(mb_type)) + AV_ZERO128(mvd_dst); + else{ + AV_COPY64(mvd_dst, mvd_src + 8*3); + AV_COPY16(mvd_dst + 3 + 3, mvd_src + 3 + 8*0); + AV_COPY16(mvd_dst + 3 + 2, mvd_src + 3 + 8*1); + AV_COPY16(mvd_dst + 3 + 1, mvd_src + 3 + 8*2); + } + } + + { + int8_t *ref_index = &s->current_picture.ref_index[list][b8_xy]; + ref_index[0+0*2]= h->ref_cache[list][scan8[0]]; + ref_index[1+0*2]= h->ref_cache[list][scan8[4]]; + ref_index[0+1*2]= h->ref_cache[list][scan8[8]]; + ref_index[1+1*2]= h->ref_cache[list][scan8[12]]; + } + } + + if(h->slice_type_nos == FF_B_TYPE && CABAC){ + if(IS_8X8(mb_type)){ + uint8_t *direct_table = &h->direct_table[4*h->mb_xy]; + direct_table[1] = h->sub_mb_type[1]>>1; + direct_table[2] = h->sub_mb_type[2]>>1; + direct_table[3] = h->sub_mb_type[3]>>1; + } + } +} + +static inline int get_dct8x8_allowed(H264Context *h){ + if(h->sps.direct_8x8_inference_flag) + return !(AV_RN64A(h->sub_mb_type) & ((MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_8x8 )*0x0001000100010001ULL)); + else + 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 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, 32); + memset(h->non_zero_count_cache + 8, 0, 8*5); //FIXME ugly, remove pfui + + if(MB_FIELD) + mb_type|= MB_TYPE_INTERLACED; + + if( h->slice_type_nos == FF_B_TYPE ) + { + // 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/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_cabac.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_cabac.c new file mode 100644 index 0000000000..485837879d --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_cabac.c @@ -0,0 +1,1720 @@ +/* + * H.26L/H.264/AVC/JVT/14496-10/... cabac decoding + * Copyright (c) 2003 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 + */ + +/** + * @file + * H.264 / AVC / MPEG4 part10 cabac decoding. + * @author Michael Niedermayer + */ + +#define CABAC 1 + +#include "internal.h" +#include "dsputil.h" +#include "avcodec.h" +#include "h264.h" +#include "h264data.h" +#include "h264_mvpred.h" +#include "golomb.h" + +#include "cabac.h" +#if ARCH_X86 +#include "x86/h264_i386.h" +#endif + +//#undef NDEBUG +#include + +/* Cabac pre state table */ + +static const int8_t cabac_context_init_I[460][2] = +{ + /* 0 - 10 */ + { 20, -15 }, { 2, 54 }, { 3, 74 }, { 20, -15 }, + { 2, 54 }, { 3, 74 }, { -28,127 }, { -23, 104 }, + { -6, 53 }, { -1, 54 }, { 7, 51 }, + + /* 11 - 23 unsused for I */ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, + { 0, 0 }, + + /* 24- 39 */ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, + + /* 40 - 53 */ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, + { 0, 0 }, { 0, 0 }, + + /* 54 - 59 */ + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, + { 0, 0 }, { 0, 0 }, + + /* 60 - 69 */ + { 0, 41 }, { 0, 63 }, { 0, 63 }, { 0, 63 }, + { -9, 83 }, { 4, 86 }, { 0, 97 }, { -7, 72 }, + { 13, 41 }, { 3, 62 }, + + /* 70 -> 87 */ + { 0, 11 }, { 1, 55 }, { 0, 69 }, { -17, 127 }, + { -13, 102 },{ 0, 82 }, { -7, 74 }, { -21, 107 }, + { -27, 127 },{ -31, 127 },{ -24, 127 }, { -18, 95 }, + { -27, 127 },{ -21, 114 },{ -30, 127 }, { -17, 123 }, + { -12, 115 },{ -16, 122 }, + + /* 88 -> 104 */ + { -11, 115 },{ -12, 63 }, { -2, 68 }, { -15, 84 }, + { -13, 104 },{ -3, 70 }, { -8, 93 }, { -10, 90 }, + { -30, 127 },{ -1, 74 }, { -6, 97 }, { -7, 91 }, + { -20, 127 },{ -4, 56 }, { -5, 82 }, { -7, 76 }, + { -22, 125 }, + + /* 105 -> 135 */ + { -7, 93 }, { -11, 87 }, { -3, 77 }, { -5, 71 }, + { -4, 63 }, { -4, 68 }, { -12, 84 }, { -7, 62 }, + { -7, 65 }, { 8, 61 }, { 5, 56 }, { -2, 66 }, + { 1, 64 }, { 0, 61 }, { -2, 78 }, { 1, 50 }, + { 7, 52 }, { 10, 35 }, { 0, 44 }, { 11, 38 }, + { 1, 45 }, { 0, 46 }, { 5, 44 }, { 31, 17 }, + { 1, 51 }, { 7, 50 }, { 28, 19 }, { 16, 33 }, + { 14, 62 }, { -13, 108 },{ -15, 100 }, + + /* 136 -> 165 */ + { -13, 101 },{ -13, 91 }, { -12, 94 }, { -10, 88 }, + { -16, 84 }, { -10, 86 }, { -7, 83 }, { -13, 87 }, + { -19, 94 }, { 1, 70 }, { 0, 72 }, { -5, 74 }, + { 18, 59 }, { -8, 102 }, { -15, 100 }, { 0, 95 }, + { -4, 75 }, { 2, 72 }, { -11, 75 }, { -3, 71 }, + { 15, 46 }, { -13, 69 }, { 0, 62 }, { 0, 65 }, + { 21, 37 }, { -15, 72 }, { 9, 57 }, { 16, 54 }, + { 0, 62 }, { 12, 72 }, + + /* 166 -> 196 */ + { 24, 0 }, { 15, 9 }, { 8, 25 }, { 13, 18 }, + { 15, 9 }, { 13, 19 }, { 10, 37 }, { 12, 18 }, + { 6, 29 }, { 20, 33 }, { 15, 30 }, { 4, 45 }, + { 1, 58 }, { 0, 62 }, { 7, 61 }, { 12, 38 }, + { 11, 45 }, { 15, 39 }, { 11, 42 }, { 13, 44 }, + { 16, 45 }, { 12, 41 }, { 10, 49 }, { 30, 34 }, + { 18, 42 }, { 10, 55 }, { 17, 51 }, { 17, 46 }, + { 0, 89 }, { 26, -19 }, { 22, -17 }, + + /* 197 -> 226 */ + { 26, -17 }, { 30, -25 }, { 28, -20 }, { 33, -23 }, + { 37, -27 }, { 33, -23 }, { 40, -28 }, { 38, -17 }, + { 33, -11 }, { 40, -15 }, { 41, -6 }, { 38, 1 }, + { 41, 17 }, { 30, -6 }, { 27, 3 }, { 26, 22 }, + { 37, -16 }, { 35, -4 }, { 38, -8 }, { 38, -3 }, + { 37, 3 }, { 38, 5 }, { 42, 0 }, { 35, 16 }, + { 39, 22 }, { 14, 48 }, { 27, 37 }, { 21, 60 }, + { 12, 68 }, { 2, 97 }, + + /* 227 -> 251 */ + { -3, 71 }, { -6, 42 }, { -5, 50 }, { -3, 54 }, + { -2, 62 }, { 0, 58 }, { 1, 63 }, { -2, 72 }, + { -1, 74 }, { -9, 91 }, { -5, 67 }, { -5, 27 }, + { -3, 39 }, { -2, 44 }, { 0, 46 }, { -16, 64 }, + { -8, 68 }, { -10, 78 }, { -6, 77 }, { -10, 86 }, + { -12, 92 }, { -15, 55 }, { -10, 60 }, { -6, 62 }, + { -4, 65 }, + + /* 252 -> 275 */ + { -12, 73 }, { -8, 76 }, { -7, 80 }, { -9, 88 }, + { -17, 110 },{ -11, 97 }, { -20, 84 }, { -11, 79 }, + { -6, 73 }, { -4, 74 }, { -13, 86 }, { -13, 96 }, + { -11, 97 }, { -19, 117 },{ -8, 78 }, { -5, 33 }, + { -4, 48 }, { -2, 53 }, { -3, 62 }, { -13, 71 }, + { -10, 79 }, { -12, 86 }, { -13, 90 }, { -14, 97 }, + + /* 276 a bit special (not used, bypass is used instead) */ + { 0, 0 }, + + /* 277 -> 307 */ + { -6, 93 }, { -6, 84 }, { -8, 79 }, { 0, 66 }, + { -1, 71 }, { 0, 62 }, { -2, 60 }, { -2, 59 }, + { -5, 75 }, { -3, 62 }, { -4, 58 }, { -9, 66 }, + { -1, 79 }, { 0, 71 }, { 3, 68 }, { 10, 44 }, + { -7, 62 }, { 15, 36 }, { 14, 40 }, { 16, 27 }, + { 12, 29 }, { 1, 44 }, { 20, 36 }, { 18, 32 }, + { 5, 42 }, { 1, 48 }, { 10, 62 }, { 17, 46 }, + { 9, 64 }, { -12, 104 },{ -11, 97 }, + + /* 308 -> 337 */ + { -16, 96 }, { -7, 88 }, { -8, 85 }, { -7, 85 }, + { -9, 85 }, { -13, 88 }, { 4, 66 }, { -3, 77 }, + { -3, 76 }, { -6, 76 }, { 10, 58 }, { -1, 76 }, + { -1, 83 }, { -7, 99 }, { -14, 95 }, { 2, 95 }, + { 0, 76 }, { -5, 74 }, { 0, 70 }, { -11, 75 }, + { 1, 68 }, { 0, 65 }, { -14, 73 }, { 3, 62 }, + { 4, 62 }, { -1, 68 }, { -13, 75 }, { 11, 55 }, + { 5, 64 }, { 12, 70 }, + + /* 338 -> 368 */ + { 15, 6 }, { 6, 19 }, { 7, 16 }, { 12, 14 }, + { 18, 13 }, { 13, 11 }, { 13, 15 }, { 15, 16 }, + { 12, 23 }, { 13, 23 }, { 15, 20 }, { 14, 26 }, + { 14, 44 }, { 17, 40 }, { 17, 47 }, { 24, 17 }, + { 21, 21 }, { 25, 22 }, { 31, 27 }, { 22, 29 }, + { 19, 35 }, { 14, 50 }, { 10, 57 }, { 7, 63 }, + { -2, 77 }, { -4, 82 }, { -3, 94 }, { 9, 69 }, + { -12, 109 },{ 36, -35 }, { 36, -34 }, + + /* 369 -> 398 */ + { 32, -26 }, { 37, -30 }, { 44, -32 }, { 34, -18 }, + { 34, -15 }, { 40, -15 }, { 33, -7 }, { 35, -5 }, + { 33, 0 }, { 38, 2 }, { 33, 13 }, { 23, 35 }, + { 13, 58 }, { 29, -3 }, { 26, 0 }, { 22, 30 }, + { 31, -7 }, { 35, -15 }, { 34, -3 }, { 34, 3 }, + { 36, -1 }, { 34, 5 }, { 32, 11 }, { 35, 5 }, + { 34, 12 }, { 39, 11 }, { 30, 29 }, { 34, 26 }, + { 29, 39 }, { 19, 66 }, + + /* 399 -> 435 */ + { 31, 21 }, { 31, 31 }, { 25, 50 }, + { -17, 120 }, { -20, 112 }, { -18, 114 }, { -11, 85 }, + { -15, 92 }, { -14, 89 }, { -26, 71 }, { -15, 81 }, + { -14, 80 }, { 0, 68 }, { -14, 70 }, { -24, 56 }, + { -23, 68 }, { -24, 50 }, { -11, 74 }, { 23, -13 }, + { 26, -13 }, { 40, -15 }, { 49, -14 }, { 44, 3 }, + { 45, 6 }, { 44, 34 }, { 33, 54 }, { 19, 82 }, + { -3, 75 }, { -1, 23 }, { 1, 34 }, { 1, 43 }, + { 0, 54 }, { -2, 55 }, { 0, 61 }, { 1, 64 }, + { 0, 68 }, { -9, 92 }, + + /* 436 -> 459 */ + { -14, 106 }, { -13, 97 }, { -15, 90 }, { -12, 90 }, + { -18, 88 }, { -10, 73 }, { -9, 79 }, { -14, 86 }, + { -10, 73 }, { -10, 70 }, { -10, 69 }, { -5, 66 }, + { -9, 64 }, { -5, 58 }, { 2, 59 }, { 21, -10 }, + { 24, -11 }, { 28, -8 }, { 28, -1 }, { 29, 3 }, + { 29, 9 }, { 35, 20 }, { 29, 36 }, { 14, 67 } +}; + +static const int8_t cabac_context_init_PB[3][460][2] = +{ + /* i_cabac_init_idc == 0 */ + { + /* 0 - 10 */ + { 20, -15 }, { 2, 54 }, { 3, 74 }, { 20, -15 }, + { 2, 54 }, { 3, 74 }, { -28, 127 }, { -23, 104 }, + { -6, 53 }, { -1, 54 }, { 7, 51 }, + + /* 11 - 23 */ + { 23, 33 }, { 23, 2 }, { 21, 0 }, { 1, 9 }, + { 0, 49 }, { -37, 118 }, { 5, 57 }, { -13, 78 }, + { -11, 65 }, { 1, 62 }, { 12, 49 }, { -4, 73 }, + { 17, 50 }, + + /* 24 - 39 */ + { 18, 64 }, { 9, 43 }, { 29, 0 }, { 26, 67 }, + { 16, 90 }, { 9, 104 }, { -46, 127 }, { -20, 104 }, + { 1, 67 }, { -13, 78 }, { -11, 65 }, { 1, 62 }, + { -6, 86 }, { -17, 95 }, { -6, 61 }, { 9, 45 }, + + /* 40 - 53 */ + { -3, 69 }, { -6, 81 }, { -11, 96 }, { 6, 55 }, + { 7, 67 }, { -5, 86 }, { 2, 88 }, { 0, 58 }, + { -3, 76 }, { -10, 94 }, { 5, 54 }, { 4, 69 }, + { -3, 81 }, { 0, 88 }, + + /* 54 - 59 */ + { -7, 67 }, { -5, 74 }, { -4, 74 }, { -5, 80 }, + { -7, 72 }, { 1, 58 }, + + /* 60 - 69 */ + { 0, 41 }, { 0, 63 }, { 0, 63 }, { 0, 63 }, + { -9, 83 }, { 4, 86 }, { 0, 97 }, { -7, 72 }, + { 13, 41 }, { 3, 62 }, + + /* 70 - 87 */ + { 0, 45 }, { -4, 78 }, { -3, 96 }, { -27, 126 }, + { -28, 98 }, { -25, 101 }, { -23, 67 }, { -28, 82 }, + { -20, 94 }, { -16, 83 }, { -22, 110 }, { -21, 91 }, + { -18, 102 }, { -13, 93 }, { -29, 127 }, { -7, 92 }, + { -5, 89 }, { -7, 96 }, { -13, 108 }, { -3, 46 }, + { -1, 65 }, { -1, 57 }, { -9, 93 }, { -3, 74 }, + { -9, 92 }, { -8, 87 }, { -23, 126 }, { 5, 54 }, + { 6, 60 }, { 6, 59 }, { 6, 69 }, { -1, 48 }, + { 0, 68 }, { -4, 69 }, { -8, 88 }, + + /* 105 -> 165 */ + { -2, 85 }, { -6, 78 }, { -1, 75 }, { -7, 77 }, + { 2, 54 }, { 5, 50 }, { -3, 68 }, { 1, 50 }, + { 6, 42 }, { -4, 81 }, { 1, 63 }, { -4, 70 }, + { 0, 67 }, { 2, 57 }, { -2, 76 }, { 11, 35 }, + { 4, 64 }, { 1, 61 }, { 11, 35 }, { 18, 25 }, + { 12, 24 }, { 13, 29 }, { 13, 36 }, { -10, 93 }, + { -7, 73 }, { -2, 73 }, { 13, 46 }, { 9, 49 }, + { -7, 100 }, { 9, 53 }, { 2, 53 }, { 5, 53 }, + { -2, 61 }, { 0, 56 }, { 0, 56 }, { -13, 63 }, + { -5, 60 }, { -1, 62 }, { 4, 57 }, { -6, 69 }, + { 4, 57 }, { 14, 39 }, { 4, 51 }, { 13, 68 }, + { 3, 64 }, { 1, 61 }, { 9, 63 }, { 7, 50 }, + { 16, 39 }, { 5, 44 }, { 4, 52 }, { 11, 48 }, + { -5, 60 }, { -1, 59 }, { 0, 59 }, { 22, 33 }, + { 5, 44 }, { 14, 43 }, { -1, 78 }, { 0, 60 }, + { 9, 69 }, + + /* 166 - 226 */ + { 11, 28 }, { 2, 40 }, { 3, 44 }, { 0, 49 }, + { 0, 46 }, { 2, 44 }, { 2, 51 }, { 0, 47 }, + { 4, 39 }, { 2, 62 }, { 6, 46 }, { 0, 54 }, + { 3, 54 }, { 2, 58 }, { 4, 63 }, { 6, 51 }, + { 6, 57 }, { 7, 53 }, { 6, 52 }, { 6, 55 }, + { 11, 45 }, { 14, 36 }, { 8, 53 }, { -1, 82 }, + { 7, 55 }, { -3, 78 }, { 15, 46 }, { 22, 31 }, + { -1, 84 }, { 25, 7 }, { 30, -7 }, { 28, 3 }, + { 28, 4 }, { 32, 0 }, { 34, -1 }, { 30, 6 }, + { 30, 6 }, { 32, 9 }, { 31, 19 }, { 26, 27 }, + { 26, 30 }, { 37, 20 }, { 28, 34 }, { 17, 70 }, + { 1, 67 }, { 5, 59 }, { 9, 67 }, { 16, 30 }, + { 18, 32 }, { 18, 35 }, { 22, 29 }, { 24, 31 }, + { 23, 38 }, { 18, 43 }, { 20, 41 }, { 11, 63 }, + { 9, 59 }, { 9, 64 }, { -1, 94 }, { -2, 89 }, + { -9, 108 }, + + /* 227 - 275 */ + { -6, 76 }, { -2, 44 }, { 0, 45 }, { 0, 52 }, + { -3, 64 }, { -2, 59 }, { -4, 70 }, { -4, 75 }, + { -8, 82 }, { -17, 102 }, { -9, 77 }, { 3, 24 }, + { 0, 42 }, { 0, 48 }, { 0, 55 }, { -6, 59 }, + { -7, 71 }, { -12, 83 }, { -11, 87 }, { -30, 119 }, + { 1, 58 }, { -3, 29 }, { -1, 36 }, { 1, 38 }, + { 2, 43 }, { -6, 55 }, { 0, 58 }, { 0, 64 }, + { -3, 74 }, { -10, 90 }, { 0, 70 }, { -4, 29 }, + { 5, 31 }, { 7, 42 }, { 1, 59 }, { -2, 58 }, + { -3, 72 }, { -3, 81 }, { -11, 97 }, { 0, 58 }, + { 8, 5 }, { 10, 14 }, { 14, 18 }, { 13, 27 }, + { 2, 40 }, { 0, 58 }, { -3, 70 }, { -6, 79 }, + { -8, 85 }, + + /* 276 a bit special (not used, bypass is used instead) */ + { 0, 0 }, + + /* 277 - 337 */ + { -13, 106 }, { -16, 106 }, { -10, 87 }, { -21, 114 }, + { -18, 110 }, { -14, 98 }, { -22, 110 }, { -21, 106 }, + { -18, 103 }, { -21, 107 }, { -23, 108 }, { -26, 112 }, + { -10, 96 }, { -12, 95 }, { -5, 91 }, { -9, 93 }, + { -22, 94 }, { -5, 86 }, { 9, 67 }, { -4, 80 }, + { -10, 85 }, { -1, 70 }, { 7, 60 }, { 9, 58 }, + { 5, 61 }, { 12, 50 }, { 15, 50 }, { 18, 49 }, + { 17, 54 }, { 10, 41 }, { 7, 46 }, { -1, 51 }, + { 7, 49 }, { 8, 52 }, { 9, 41 }, { 6, 47 }, + { 2, 55 }, { 13, 41 }, { 10, 44 }, { 6, 50 }, + { 5, 53 }, { 13, 49 }, { 4, 63 }, { 6, 64 }, + { -2, 69 }, { -2, 59 }, { 6, 70 }, { 10, 44 }, + { 9, 31 }, { 12, 43 }, { 3, 53 }, { 14, 34 }, + { 10, 38 }, { -3, 52 }, { 13, 40 }, { 17, 32 }, + { 7, 44 }, { 7, 38 }, { 13, 50 }, { 10, 57 }, + { 26, 43 }, + + /* 338 - 398 */ + { 14, 11 }, { 11, 14 }, { 9, 11 }, { 18, 11 }, + { 21, 9 }, { 23, -2 }, { 32, -15 }, { 32, -15 }, + { 34, -21 }, { 39, -23 }, { 42, -33 }, { 41, -31 }, + { 46, -28 }, { 38, -12 }, { 21, 29 }, { 45, -24 }, + { 53, -45 }, { 48, -26 }, { 65, -43 }, { 43, -19 }, + { 39, -10 }, { 30, 9 }, { 18, 26 }, { 20, 27 }, + { 0, 57 }, { -14, 82 }, { -5, 75 }, { -19, 97 }, + { -35, 125 }, { 27, 0 }, { 28, 0 }, { 31, -4 }, + { 27, 6 }, { 34, 8 }, { 30, 10 }, { 24, 22 }, + { 33, 19 }, { 22, 32 }, { 26, 31 }, { 21, 41 }, + { 26, 44 }, { 23, 47 }, { 16, 65 }, { 14, 71 }, + { 8, 60 }, { 6, 63 }, { 17, 65 }, { 21, 24 }, + { 23, 20 }, { 26, 23 }, { 27, 32 }, { 28, 23 }, + { 28, 24 }, { 23, 40 }, { 24, 32 }, { 28, 29 }, + { 23, 42 }, { 19, 57 }, { 22, 53 }, { 22, 61 }, + { 11, 86 }, + + /* 399 - 435 */ + { 12, 40 }, { 11, 51 }, { 14, 59 }, + { -4, 79 }, { -7, 71 }, { -5, 69 }, { -9, 70 }, + { -8, 66 }, { -10, 68 }, { -19, 73 }, { -12, 69 }, + { -16, 70 }, { -15, 67 }, { -20, 62 }, { -19, 70 }, + { -16, 66 }, { -22, 65 }, { -20, 63 }, { 9, -2 }, + { 26, -9 }, { 33, -9 }, { 39, -7 }, { 41, -2 }, + { 45, 3 }, { 49, 9 }, { 45, 27 }, { 36, 59 }, + { -6, 66 }, { -7, 35 }, { -7, 42 }, { -8, 45 }, + { -5, 48 }, { -12, 56 }, { -6, 60 }, { -5, 62 }, + { -8, 66 }, { -8, 76 }, + + /* 436 - 459 */ + { -5, 85 }, { -6, 81 }, { -10, 77 }, { -7, 81 }, + { -17, 80 }, { -18, 73 }, { -4, 74 }, { -10, 83 }, + { -9, 71 }, { -9, 67 }, { -1, 61 }, { -8, 66 }, + { -14, 66 }, { 0, 59 }, { 2, 59 }, { 21, -13 }, + { 33, -14 }, { 39, -7 }, { 46, -2 }, { 51, 2 }, + { 60, 6 }, { 61, 17 }, { 55, 34 }, { 42, 62 }, + }, + + /* i_cabac_init_idc == 1 */ + { + /* 0 - 10 */ + { 20, -15 }, { 2, 54 }, { 3, 74 }, { 20, -15 }, + { 2, 54 }, { 3, 74 }, { -28, 127 }, { -23, 104 }, + { -6, 53 }, { -1, 54 }, { 7, 51 }, + + /* 11 - 23 */ + { 22, 25 }, { 34, 0 }, { 16, 0 }, { -2, 9 }, + { 4, 41 }, { -29, 118 }, { 2, 65 }, { -6, 71 }, + { -13, 79 }, { 5, 52 }, { 9, 50 }, { -3, 70 }, + { 10, 54 }, + + /* 24 - 39 */ + { 26, 34 }, { 19, 22 }, { 40, 0 }, { 57, 2 }, + { 41, 36 }, { 26, 69 }, { -45, 127 }, { -15, 101 }, + { -4, 76 }, { -6, 71 }, { -13, 79 }, { 5, 52 }, + { 6, 69 }, { -13, 90 }, { 0, 52 }, { 8, 43 }, + + /* 40 - 53 */ + { -2, 69 },{ -5, 82 },{ -10, 96 },{ 2, 59 }, + { 2, 75 },{ -3, 87 },{ -3, 100 },{ 1, 56 }, + { -3, 74 },{ -6, 85 },{ 0, 59 },{ -3, 81 }, + { -7, 86 },{ -5, 95 }, + + /* 54 - 59 */ + { -1, 66 },{ -1, 77 },{ 1, 70 },{ -2, 86 }, + { -5, 72 },{ 0, 61 }, + + /* 60 - 69 */ + { 0, 41 }, { 0, 63 }, { 0, 63 }, { 0, 63 }, + { -9, 83 }, { 4, 86 }, { 0, 97 }, { -7, 72 }, + { 13, 41 }, { 3, 62 }, + + /* 70 - 104 */ + { 13, 15 }, { 7, 51 }, { 2, 80 }, { -39, 127 }, + { -18, 91 }, { -17, 96 }, { -26, 81 }, { -35, 98 }, + { -24, 102 }, { -23, 97 }, { -27, 119 }, { -24, 99 }, + { -21, 110 }, { -18, 102 }, { -36, 127 }, { 0, 80 }, + { -5, 89 }, { -7, 94 }, { -4, 92 }, { 0, 39 }, + { 0, 65 }, { -15, 84 }, { -35, 127 }, { -2, 73 }, + { -12, 104 }, { -9, 91 }, { -31, 127 }, { 3, 55 }, + { 7, 56 }, { 7, 55 }, { 8, 61 }, { -3, 53 }, + { 0, 68 }, { -7, 74 }, { -9, 88 }, + + /* 105 -> 165 */ + { -13, 103 }, { -13, 91 }, { -9, 89 }, { -14, 92 }, + { -8, 76 }, { -12, 87 }, { -23, 110 }, { -24, 105 }, + { -10, 78 }, { -20, 112 }, { -17, 99 }, { -78, 127 }, + { -70, 127 }, { -50, 127 }, { -46, 127 }, { -4, 66 }, + { -5, 78 }, { -4, 71 }, { -8, 72 }, { 2, 59 }, + { -1, 55 }, { -7, 70 }, { -6, 75 }, { -8, 89 }, + { -34, 119 }, { -3, 75 }, { 32, 20 }, { 30, 22 }, + { -44, 127 }, { 0, 54 }, { -5, 61 }, { 0, 58 }, + { -1, 60 }, { -3, 61 }, { -8, 67 }, { -25, 84 }, + { -14, 74 }, { -5, 65 }, { 5, 52 }, { 2, 57 }, + { 0, 61 }, { -9, 69 }, { -11, 70 }, { 18, 55 }, + { -4, 71 }, { 0, 58 }, { 7, 61 }, { 9, 41 }, + { 18, 25 }, { 9, 32 }, { 5, 43 }, { 9, 47 }, + { 0, 44 }, { 0, 51 }, { 2, 46 }, { 19, 38 }, + { -4, 66 }, { 15, 38 }, { 12, 42 }, { 9, 34 }, + { 0, 89 }, + + /* 166 - 226 */ + { 4, 45 }, { 10, 28 }, { 10, 31 }, { 33, -11 }, + { 52, -43 }, { 18, 15 }, { 28, 0 }, { 35, -22 }, + { 38, -25 }, { 34, 0 }, { 39, -18 }, { 32, -12 }, + { 102, -94 }, { 0, 0 }, { 56, -15 }, { 33, -4 }, + { 29, 10 }, { 37, -5 }, { 51, -29 }, { 39, -9 }, + { 52, -34 }, { 69, -58 }, { 67, -63 }, { 44, -5 }, + { 32, 7 }, { 55, -29 }, { 32, 1 }, { 0, 0 }, + { 27, 36 }, { 33, -25 }, { 34, -30 }, { 36, -28 }, + { 38, -28 }, { 38, -27 }, { 34, -18 }, { 35, -16 }, + { 34, -14 }, { 32, -8 }, { 37, -6 }, { 35, 0 }, + { 30, 10 }, { 28, 18 }, { 26, 25 }, { 29, 41 }, + { 0, 75 }, { 2, 72 }, { 8, 77 }, { 14, 35 }, + { 18, 31 }, { 17, 35 }, { 21, 30 }, { 17, 45 }, + { 20, 42 }, { 18, 45 }, { 27, 26 }, { 16, 54 }, + { 7, 66 }, { 16, 56 }, { 11, 73 }, { 10, 67 }, + { -10, 116 }, + + /* 227 - 275 */ + { -23, 112 }, { -15, 71 }, { -7, 61 }, { 0, 53 }, + { -5, 66 }, { -11, 77 }, { -9, 80 }, { -9, 84 }, + { -10, 87 }, { -34, 127 }, { -21, 101 }, { -3, 39 }, + { -5, 53 }, { -7, 61 }, { -11, 75 }, { -15, 77 }, + { -17, 91 }, { -25, 107 }, { -25, 111 }, { -28, 122 }, + { -11, 76 }, { -10, 44 }, { -10, 52 }, { -10, 57 }, + { -9, 58 }, { -16, 72 }, { -7, 69 }, { -4, 69 }, + { -5, 74 }, { -9, 86 }, { 2, 66 }, { -9, 34 }, + { 1, 32 }, { 11, 31 }, { 5, 52 }, { -2, 55 }, + { -2, 67 }, { 0, 73 }, { -8, 89 }, { 3, 52 }, + { 7, 4 }, { 10, 8 }, { 17, 8 }, { 16, 19 }, + { 3, 37 }, { -1, 61 }, { -5, 73 }, { -1, 70 }, + { -4, 78 }, + + /* 276 a bit special (not used, bypass is used instead) */ + { 0, 0 }, + + /* 277 - 337 */ + { -21, 126 }, { -23, 124 }, { -20, 110 }, { -26, 126 }, + { -25, 124 }, { -17, 105 }, { -27, 121 }, { -27, 117 }, + { -17, 102 }, { -26, 117 }, { -27, 116 }, { -33, 122 }, + { -10, 95 }, { -14, 100 }, { -8, 95 }, { -17, 111 }, + { -28, 114 }, { -6, 89 }, { -2, 80 }, { -4, 82 }, + { -9, 85 }, { -8, 81 }, { -1, 72 }, { 5, 64 }, + { 1, 67 }, { 9, 56 }, { 0, 69 }, { 1, 69 }, + { 7, 69 }, { -7, 69 }, { -6, 67 }, { -16, 77 }, + { -2, 64 }, { 2, 61 }, { -6, 67 }, { -3, 64 }, + { 2, 57 }, { -3, 65 }, { -3, 66 }, { 0, 62 }, + { 9, 51 }, { -1, 66 }, { -2, 71 }, { -2, 75 }, + { -1, 70 }, { -9, 72 }, { 14, 60 }, { 16, 37 }, + { 0, 47 }, { 18, 35 }, { 11, 37 }, { 12, 41 }, + { 10, 41 }, { 2, 48 }, { 12, 41 }, { 13, 41 }, + { 0, 59 }, { 3, 50 }, { 19, 40 }, { 3, 66 }, + { 18, 50 }, + + /* 338 - 398 */ + { 19, -6 }, { 18, -6 }, { 14, 0 }, { 26, -12 }, + { 31, -16 }, { 33, -25 }, { 33, -22 }, { 37, -28 }, + { 39, -30 }, { 42, -30 }, { 47, -42 }, { 45, -36 }, + { 49, -34 }, { 41, -17 }, { 32, 9 }, { 69, -71 }, + { 63, -63 }, { 66, -64 }, { 77, -74 }, { 54, -39 }, + { 52, -35 }, { 41, -10 }, { 36, 0 }, { 40, -1 }, + { 30, 14 }, { 28, 26 }, { 23, 37 }, { 12, 55 }, + { 11, 65 }, { 37, -33 }, { 39, -36 }, { 40, -37 }, + { 38, -30 }, { 46, -33 }, { 42, -30 }, { 40, -24 }, + { 49, -29 }, { 38, -12 }, { 40, -10 }, { 38, -3 }, + { 46, -5 }, { 31, 20 }, { 29, 30 }, { 25, 44 }, + { 12, 48 }, { 11, 49 }, { 26, 45 }, { 22, 22 }, + { 23, 22 }, { 27, 21 }, { 33, 20 }, { 26, 28 }, + { 30, 24 }, { 27, 34 }, { 18, 42 }, { 25, 39 }, + { 18, 50 }, { 12, 70 }, { 21, 54 }, { 14, 71 }, + { 11, 83 }, + + /* 399 - 435 */ + { 25, 32 }, { 21, 49 }, { 21, 54 }, + { -5, 85 }, { -6, 81 }, { -10, 77 }, { -7, 81 }, + { -17, 80 }, { -18, 73 }, { -4, 74 }, { -10, 83 }, + { -9, 71 }, { -9, 67 }, { -1, 61 }, { -8, 66 }, + { -14, 66 }, { 0, 59 }, { 2, 59 }, { 17, -10 }, + { 32, -13 }, { 42, -9 }, { 49, -5 }, { 53, 0 }, + { 64, 3 }, { 68, 10 }, { 66, 27 }, { 47, 57 }, + { -5, 71 }, { 0, 24 }, { -1, 36 }, { -2, 42 }, + { -2, 52 }, { -9, 57 }, { -6, 63 }, { -4, 65 }, + { -4, 67 }, { -7, 82 }, + + /* 436 - 459 */ + { -3, 81 }, { -3, 76 }, { -7, 72 }, { -6, 78 }, + { -12, 72 }, { -14, 68 }, { -3, 70 }, { -6, 76 }, + { -5, 66 }, { -5, 62 }, { 0, 57 }, { -4, 61 }, + { -9, 60 }, { 1, 54 }, { 2, 58 }, { 17, -10 }, + { 32, -13 }, { 42, -9 }, { 49, -5 }, { 53, 0 }, + { 64, 3 }, { 68, 10 }, { 66, 27 }, { 47, 57 }, + }, + + /* i_cabac_init_idc == 2 */ + { + /* 0 - 10 */ + { 20, -15 }, { 2, 54 }, { 3, 74 }, { 20, -15 }, + { 2, 54 }, { 3, 74 }, { -28, 127 }, { -23, 104 }, + { -6, 53 }, { -1, 54 }, { 7, 51 }, + + /* 11 - 23 */ + { 29, 16 }, { 25, 0 }, { 14, 0 }, { -10, 51 }, + { -3, 62 }, { -27, 99 }, { 26, 16 }, { -4, 85 }, + { -24, 102 }, { 5, 57 }, { 6, 57 }, { -17, 73 }, + { 14, 57 }, + + /* 24 - 39 */ + { 20, 40 }, { 20, 10 }, { 29, 0 }, { 54, 0 }, + { 37, 42 }, { 12, 97 }, { -32, 127 }, { -22, 117 }, + { -2, 74 }, { -4, 85 }, { -24, 102 }, { 5, 57 }, + { -6, 93 }, { -14, 88 }, { -6, 44 }, { 4, 55 }, + + /* 40 - 53 */ + { -11, 89 },{ -15, 103 },{ -21, 116 },{ 19, 57 }, + { 20, 58 },{ 4, 84 },{ 6, 96 },{ 1, 63 }, + { -5, 85 },{ -13, 106 },{ 5, 63 },{ 6, 75 }, + { -3, 90 },{ -1, 101 }, + + /* 54 - 59 */ + { 3, 55 },{ -4, 79 },{ -2, 75 },{ -12, 97 }, + { -7, 50 },{ 1, 60 }, + + /* 60 - 69 */ + { 0, 41 }, { 0, 63 }, { 0, 63 }, { 0, 63 }, + { -9, 83 }, { 4, 86 }, { 0, 97 }, { -7, 72 }, + { 13, 41 }, { 3, 62 }, + + /* 70 - 104 */ + { 7, 34 }, { -9, 88 }, { -20, 127 }, { -36, 127 }, + { -17, 91 }, { -14, 95 }, { -25, 84 }, { -25, 86 }, + { -12, 89 }, { -17, 91 }, { -31, 127 }, { -14, 76 }, + { -18, 103 }, { -13, 90 }, { -37, 127 }, { 11, 80 }, + { 5, 76 }, { 2, 84 }, { 5, 78 }, { -6, 55 }, + { 4, 61 }, { -14, 83 }, { -37, 127 }, { -5, 79 }, + { -11, 104 }, { -11, 91 }, { -30, 127 }, { 0, 65 }, + { -2, 79 }, { 0, 72 }, { -4, 92 }, { -6, 56 }, + { 3, 68 }, { -8, 71 }, { -13, 98 }, + + /* 105 -> 165 */ + { -4, 86 }, { -12, 88 }, { -5, 82 }, { -3, 72 }, + { -4, 67 }, { -8, 72 }, { -16, 89 }, { -9, 69 }, + { -1, 59 }, { 5, 66 }, { 4, 57 }, { -4, 71 }, + { -2, 71 }, { 2, 58 }, { -1, 74 }, { -4, 44 }, + { -1, 69 }, { 0, 62 }, { -7, 51 }, { -4, 47 }, + { -6, 42 }, { -3, 41 }, { -6, 53 }, { 8, 76 }, + { -9, 78 }, { -11, 83 }, { 9, 52 }, { 0, 67 }, + { -5, 90 }, { 1, 67 }, { -15, 72 }, { -5, 75 }, + { -8, 80 }, { -21, 83 }, { -21, 64 }, { -13, 31 }, + { -25, 64 }, { -29, 94 }, { 9, 75 }, { 17, 63 }, + { -8, 74 }, { -5, 35 }, { -2, 27 }, { 13, 91 }, + { 3, 65 }, { -7, 69 }, { 8, 77 }, { -10, 66 }, + { 3, 62 }, { -3, 68 }, { -20, 81 }, { 0, 30 }, + { 1, 7 }, { -3, 23 }, { -21, 74 }, { 16, 66 }, + { -23, 124 }, { 17, 37 }, { 44, -18 }, { 50, -34 }, + { -22, 127 }, + + /* 166 - 226 */ + { 4, 39 }, { 0, 42 }, { 7, 34 }, { 11, 29 }, + { 8, 31 }, { 6, 37 }, { 7, 42 }, { 3, 40 }, + { 8, 33 }, { 13, 43 }, { 13, 36 }, { 4, 47 }, + { 3, 55 }, { 2, 58 }, { 6, 60 }, { 8, 44 }, + { 11, 44 }, { 14, 42 }, { 7, 48 }, { 4, 56 }, + { 4, 52 }, { 13, 37 }, { 9, 49 }, { 19, 58 }, + { 10, 48 }, { 12, 45 }, { 0, 69 }, { 20, 33 }, + { 8, 63 }, { 35, -18 }, { 33, -25 }, { 28, -3 }, + { 24, 10 }, { 27, 0 }, { 34, -14 }, { 52, -44 }, + { 39, -24 }, { 19, 17 }, { 31, 25 }, { 36, 29 }, + { 24, 33 }, { 34, 15 }, { 30, 20 }, { 22, 73 }, + { 20, 34 }, { 19, 31 }, { 27, 44 }, { 19, 16 }, + { 15, 36 }, { 15, 36 }, { 21, 28 }, { 25, 21 }, + { 30, 20 }, { 31, 12 }, { 27, 16 }, { 24, 42 }, + { 0, 93 }, { 14, 56 }, { 15, 57 }, { 26, 38 }, + { -24, 127 }, + + /* 227 - 275 */ + { -24, 115 }, { -22, 82 }, { -9, 62 }, { 0, 53 }, + { 0, 59 }, { -14, 85 }, { -13, 89 }, { -13, 94 }, + { -11, 92 }, { -29, 127 }, { -21, 100 }, { -14, 57 }, + { -12, 67 }, { -11, 71 }, { -10, 77 }, { -21, 85 }, + { -16, 88 }, { -23, 104 }, { -15, 98 }, { -37, 127 }, + { -10, 82 }, { -8, 48 }, { -8, 61 }, { -8, 66 }, + { -7, 70 }, { -14, 75 }, { -10, 79 }, { -9, 83 }, + { -12, 92 }, { -18, 108 }, { -4, 79 }, { -22, 69 }, + { -16, 75 }, { -2, 58 }, { 1, 58 }, { -13, 78 }, + { -9, 83 }, { -4, 81 }, { -13, 99 }, { -13, 81 }, + { -6, 38 }, { -13, 62 }, { -6, 58 }, { -2, 59 }, + { -16, 73 }, { -10, 76 }, { -13, 86 }, { -9, 83 }, + { -10, 87 }, + + /* 276 a bit special (not used, bypass is used instead) */ + { 0, 0 }, + + /* 277 - 337 */ + { -22, 127 }, { -25, 127 }, { -25, 120 }, { -27, 127 }, + { -19, 114 }, { -23, 117 }, { -25, 118 }, { -26, 117 }, + { -24, 113 }, { -28, 118 }, { -31, 120 }, { -37, 124 }, + { -10, 94 }, { -15, 102 }, { -10, 99 }, { -13, 106 }, + { -50, 127 }, { -5, 92 }, { 17, 57 }, { -5, 86 }, + { -13, 94 }, { -12, 91 }, { -2, 77 }, { 0, 71 }, + { -1, 73 }, { 4, 64 }, { -7, 81 }, { 5, 64 }, + { 15, 57 }, { 1, 67 }, { 0, 68 }, { -10, 67 }, + { 1, 68 }, { 0, 77 }, { 2, 64 }, { 0, 68 }, + { -5, 78 }, { 7, 55 }, { 5, 59 }, { 2, 65 }, + { 14, 54 }, { 15, 44 }, { 5, 60 }, { 2, 70 }, + { -2, 76 }, { -18, 86 }, { 12, 70 }, { 5, 64 }, + { -12, 70 }, { 11, 55 }, { 5, 56 }, { 0, 69 }, + { 2, 65 }, { -6, 74 }, { 5, 54 }, { 7, 54 }, + { -6, 76 }, { -11, 82 }, { -2, 77 }, { -2, 77 }, + { 25, 42 }, + + /* 338 - 398 */ + { 17, -13 }, { 16, -9 }, { 17, -12 }, { 27, -21 }, + { 37, -30 }, { 41, -40 }, { 42, -41 }, { 48, -47 }, + { 39, -32 }, { 46, -40 }, { 52, -51 }, { 46, -41 }, + { 52, -39 }, { 43, -19 }, { 32, 11 }, { 61, -55 }, + { 56, -46 }, { 62, -50 }, { 81, -67 }, { 45, -20 }, + { 35, -2 }, { 28, 15 }, { 34, 1 }, { 39, 1 }, + { 30, 17 }, { 20, 38 }, { 18, 45 }, { 15, 54 }, + { 0, 79 }, { 36, -16 }, { 37, -14 }, { 37, -17 }, + { 32, 1 }, { 34, 15 }, { 29, 15 }, { 24, 25 }, + { 34, 22 }, { 31, 16 }, { 35, 18 }, { 31, 28 }, + { 33, 41 }, { 36, 28 }, { 27, 47 }, { 21, 62 }, + { 18, 31 }, { 19, 26 }, { 36, 24 }, { 24, 23 }, + { 27, 16 }, { 24, 30 }, { 31, 29 }, { 22, 41 }, + { 22, 42 }, { 16, 60 }, { 15, 52 }, { 14, 60 }, + { 3, 78 }, { -16, 123 }, { 21, 53 }, { 22, 56 }, + { 25, 61 }, + + /* 399 - 435 */ + { 21, 33 }, { 19, 50 }, { 17, 61 }, + { -3, 78 }, { -8, 74 }, { -9, 72 }, { -10, 72 }, + { -18, 75 }, { -12, 71 }, { -11, 63 }, { -5, 70 }, + { -17, 75 }, { -14, 72 }, { -16, 67 }, { -8, 53 }, + { -14, 59 }, { -9, 52 }, { -11, 68 }, { 9, -2 }, + { 30, -10 }, { 31, -4 }, { 33, -1 }, { 33, 7 }, + { 31, 12 }, { 37, 23 }, { 31, 38 }, { 20, 64 }, + { -9, 71 }, { -7, 37 }, { -8, 44 }, { -11, 49 }, + { -10, 56 }, { -12, 59 }, { -8, 63 }, { -9, 67 }, + { -6, 68 }, { -10, 79 }, + + /* 436 - 459 */ + { -3, 78 }, { -8, 74 }, { -9, 72 }, { -10, 72 }, + { -18, 75 }, { -12, 71 }, { -11, 63 }, { -5, 70 }, + { -17, 75 }, { -14, 72 }, { -16, 67 }, { -8, 53 }, + { -14, 59 }, { -9, 52 }, { -11, 68 }, { 9, -2 }, + { 30, -10 }, { 31, -4 }, { 33, -1 }, { 33, 7 }, + { 31, 12 }, { 37, 23 }, { 31, 38 }, { 20, 64 }, + } +}; + +void ff_h264_init_cabac_states(H264Context *h) { + MpegEncContext * const s = &h->s; + int i; + const int8_t (*tab)[2]; + + if( h->slice_type_nos == FF_I_TYPE ) tab = cabac_context_init_I; + else tab = cabac_context_init_PB[h->cabac_init_idc]; + + /* calculate pre-state */ + for( i= 0; i < 460; i++ ) { + int pre = 2*(((tab[i][0] * s->qscale) >>4 ) + tab[i][1]) - 127; + + pre^= pre>>31; + if(pre > 124) + pre= 124 + (pre&1); + + h->cabac_state[i] = pre; + } +} + +static int decode_cabac_field_decoding_flag(H264Context *h) { + MpegEncContext * const s = &h->s; + const long mbb_xy = h->mb_xy - 2L*s->mb_stride; + + 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); + + return get_cabac_noinline( &h->cabac, &(h->cabac_state+70)[ctx] ); +} + +static int decode_cabac_intra_mb_type(H264Context *h, int ctx_base, int intra_slice) { + uint8_t *state= &h->cabac_state[ctx_base]; + int mb_type; + + if(intra_slice){ + int ctx=0; + if( h->left_type[0] & (MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM)) + ctx++; + if( h->top_type & (MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM)) + ctx++; + if( get_cabac_noinline( &h->cabac, &state[ctx] ) == 0 ) + return 0; /* I4x4 */ + state += 2; + }else{ + if( get_cabac_noinline( &h->cabac, state ) == 0 ) + return 0; /* I4x4 */ + } + + if( get_cabac_terminate( &h->cabac ) ) + return 25; /* PCM */ + + mb_type = 1; /* I16x16 */ + mb_type += 12 * get_cabac_noinline( &h->cabac, &state[1] ); /* cbp_luma != 0 */ + if( get_cabac_noinline( &h->cabac, &state[2] ) ) /* cbp_chroma */ + mb_type += 4 + 4 * get_cabac_noinline( &h->cabac, &state[2+intra_slice] ); + mb_type += 2 * get_cabac_noinline( &h->cabac, &state[3+intra_slice] ); + mb_type += 1 * get_cabac_noinline( &h->cabac, &state[3+2*intra_slice] ); + return mb_type; +} + +static int decode_cabac_mb_skip( H264Context *h, int mb_x, int mb_y ) { + MpegEncContext * const s = &h->s; + int mba_xy, mbb_xy; + int ctx = 0; + + if(FRAME_MBAFF){ //FIXME merge with the stuff in fill_caches? + int mb_xy = mb_x + (mb_y&~1)*s->mb_stride; + 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] ) ) + 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] ) ) + mbb_xy -= s->mb_stride; + }else + mbb_xy = mb_x + (mb_y-1)*s->mb_stride; + }else{ + int mb_xy = h->mb_xy; + mba_xy = mb_xy - 1; + 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] )) + ctx++; + if( h->slice_table[mbb_xy] == h->slice_num && !IS_SKIP( s->current_picture.mb_type[mbb_xy] )) + ctx++; + + if( h->slice_type_nos == FF_B_TYPE ) + ctx += 13; + return get_cabac_noinline( &h->cabac, &h->cabac_state[11+ctx] ); +} + +static int decode_cabac_mb_intra4x4_pred_mode( H264Context *h, int pred_mode ) { + int mode = 0; + + if( get_cabac( &h->cabac, &h->cabac_state[68] ) ) + return pred_mode; + + mode += 1 * get_cabac( &h->cabac, &h->cabac_state[69] ); + mode += 2 * get_cabac( &h->cabac, &h->cabac_state[69] ); + mode += 4 * get_cabac( &h->cabac, &h->cabac_state[69] ); + + return mode + ( mode >= pred_mode ); +} + +static int decode_cabac_mb_chroma_pre_mode( H264Context *h) { + const int mba_xy = h->left_mb_xy[0]; + const int mbb_xy = h->top_mb_xy; + + int ctx = 0; + + /* No need to test for IS_INTRA4x4 and IS_INTRA16x16, as we set chroma_pred_mode_table to 0 */ + if( h->left_type[0] && h->chroma_pred_mode_table[mba_xy] != 0 ) + ctx++; + + if( h->top_type && h->chroma_pred_mode_table[mbb_xy] != 0 ) + ctx++; + + if( get_cabac_noinline( &h->cabac, &h->cabac_state[64+ctx] ) == 0 ) + return 0; + + if( get_cabac_noinline( &h->cabac, &h->cabac_state[64+3] ) == 0 ) + return 1; + if( get_cabac_noinline( &h->cabac, &h->cabac_state[64+3] ) == 0 ) + return 2; + else + return 3; +} + +static int decode_cabac_mb_cbp_luma( H264Context *h) { + int cbp_b, cbp_a, ctx, cbp = 0; + + cbp_a = h->left_cbp; + cbp_b = h->top_cbp; + + ctx = !(cbp_a & 0x02) + 2 * !(cbp_b & 0x04); + cbp += get_cabac_noinline(&h->cabac, &h->cabac_state[73 + ctx]); + ctx = !(cbp & 0x01) + 2 * !(cbp_b & 0x08); + cbp += get_cabac_noinline(&h->cabac, &h->cabac_state[73 + ctx]) << 1; + ctx = !(cbp_a & 0x08) + 2 * !(cbp & 0x01); + cbp += get_cabac_noinline(&h->cabac, &h->cabac_state[73 + ctx]) << 2; + ctx = !(cbp & 0x04) + 2 * !(cbp & 0x02); + cbp += get_cabac_noinline(&h->cabac, &h->cabac_state[73 + ctx]) << 3; + return cbp; +} +static int decode_cabac_mb_cbp_chroma( H264Context *h) { + int ctx; + int cbp_a, cbp_b; + + cbp_a = (h->left_cbp>>4)&0x03; + cbp_b = (h-> top_cbp>>4)&0x03; + + ctx = 0; + if( cbp_a > 0 ) ctx++; + if( cbp_b > 0 ) ctx += 2; + if( get_cabac_noinline( &h->cabac, &h->cabac_state[77 + ctx] ) == 0 ) + return 0; + + ctx = 4; + if( cbp_a == 2 ) ctx++; + if( cbp_b == 2 ) ctx += 2; + return 1 + get_cabac_noinline( &h->cabac, &h->cabac_state[77 + ctx] ); +} + +static int decode_cabac_p_mb_sub_type( H264Context *h ) { + if( get_cabac( &h->cabac, &h->cabac_state[21] ) ) + return 0; /* 8x8 */ + if( !get_cabac( &h->cabac, &h->cabac_state[22] ) ) + return 1; /* 8x4 */ + if( get_cabac( &h->cabac, &h->cabac_state[23] ) ) + return 2; /* 4x8 */ + return 3; /* 4x4 */ +} +static int decode_cabac_b_mb_sub_type( H264Context *h ) { + int type; + if( !get_cabac( &h->cabac, &h->cabac_state[36] ) ) + return 0; /* B_Direct_8x8 */ + if( !get_cabac( &h->cabac, &h->cabac_state[37] ) ) + return 1 + get_cabac( &h->cabac, &h->cabac_state[39] ); /* B_L0_8x8, B_L1_8x8 */ + type = 3; + if( get_cabac( &h->cabac, &h->cabac_state[38] ) ) { + if( get_cabac( &h->cabac, &h->cabac_state[39] ) ) + return 11 + get_cabac( &h->cabac, &h->cabac_state[39] ); /* B_L1_4x4, B_Bi_4x4 */ + type += 4; + } + type += 2*get_cabac( &h->cabac, &h->cabac_state[39] ); + type += get_cabac( &h->cabac, &h->cabac_state[39] ); + return type; +} + +static int decode_cabac_mb_ref( H264Context *h, int list, int n ) { + int refa = h->ref_cache[list][scan8[n] - 1]; + int refb = h->ref_cache[list][scan8[n] - 8]; + int ref = 0; + int ctx = 0; + + if( h->slice_type_nos == FF_B_TYPE) { + if( refa > 0 && !(h->direct_cache[scan8[n] - 1]&(MB_TYPE_DIRECT2>>1)) ) + ctx++; + if( refb > 0 && !(h->direct_cache[scan8[n] - 8]&(MB_TYPE_DIRECT2>>1)) ) + ctx += 2; + } else { + if( refa > 0 ) + ctx++; + if( refb > 0 ) + ctx += 2; + } + + while( get_cabac( &h->cabac, &h->cabac_state[54+ctx] ) ) { + ref++; + ctx = (ctx>>2)+4; + if(ref >= 32 /*h->ref_list[list]*/){ + return -1; + } + } + return ref; +} + +static int decode_cabac_mb_mvd( H264Context *h, int ctxbase, int amvd, int *mvda) { + int mvd; + + if(!get_cabac(&h->cabac, &h->cabac_state[ctxbase+((amvd-3)>>(INT_BIT-1))+((amvd-33)>>(INT_BIT-1))+2])){ +// if(!get_cabac(&h->cabac, &h->cabac_state[ctxbase+(amvd>2)+(amvd>32)])){ + *mvda= 0; + return 0; + } + + mvd= 1; + ctxbase+= 3; + while( mvd < 9 && get_cabac( &h->cabac, &h->cabac_state[ctxbase] ) ) { + if( mvd < 4 ) + ctxbase++; + mvd++; + } + + if( mvd >= 9 ) { + int k = 3; + while( get_cabac_bypass( &h->cabac ) ) { + mvd += 1 << k; + k++; + if(k>24){ + av_log(h->s.avctx, AV_LOG_ERROR, "overflow in decode_cabac_mb_mvd\n"); + return INT_MIN; + } + } + while( k-- ) { + mvd += get_cabac_bypass( &h->cabac )<cabac, -mvd ); +} + +#define DECODE_CABAC_MB_MVD( h, list, n )\ +{\ + int amvd0 = h->mvd_cache[list][scan8[n] - 1][0] +\ + h->mvd_cache[list][scan8[n] - 8][0];\ + int amvd1 = h->mvd_cache[list][scan8[n] - 1][1] +\ + h->mvd_cache[list][scan8[n] - 8][1];\ +\ + mx += decode_cabac_mb_mvd( h, 40, amvd0, &mpx );\ + my += decode_cabac_mb_mvd( h, 47, amvd1, &mpy );\ +} + +static av_always_inline int get_cabac_cbf_ctx( H264Context *h, int cat, int idx, int is_dc ) { + int nza, nzb; + int ctx = 0; + + if( is_dc ) { + if( cat == 0 ) { + nza = h->left_cbp&0x100; + nzb = h-> top_cbp&0x100; + } else { + nza = (h->left_cbp>>(6+idx))&0x01; + nzb = (h-> top_cbp>>(6+idx))&0x01; + } + } else { + assert(cat == 1 || cat == 2 || cat == 4); + nza = h->non_zero_count_cache[scan8[idx] - 1]; + nzb = h->non_zero_count_cache[scan8[idx] - 8]; + } + + if( nza > 0 ) + ctx++; + + if( nzb > 0 ) + ctx += 2; + + return ctx + 4 * cat; +} + +DECLARE_ASM_CONST(1, uint8_t, last_coeff_flag_offset_8x8)[63] = { + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, + 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 const int significant_coeff_flag_offset[2][6] = { + { 105+0, 105+15, 105+29, 105+44, 105+47, 402 }, + { 277+0, 277+15, 277+29, 277+44, 277+47, 436 } + }; + static const int last_coeff_flag_offset[2][6] = { + { 166+0, 166+15, 166+29, 166+44, 166+47, 417 }, + { 338+0, 338+15, 338+29, 338+44, 338+47, 451 } + }; + static const int coeff_abs_level_m1_offset[6] = { + 227+0, 227+10, 227+20, 227+30, 227+39, 426 + }; + static const uint8_t significant_coeff_flag_offset_8x8[2][63] = { + { 0, 1, 2, 3, 4, 5, 5, 4, 4, 3, 3, 4, 4, 4, 5, 5, + 4, 4, 4, 4, 3, 3, 6, 7, 7, 7, 8, 9,10, 9, 8, 7, + 7, 6,11,12,13,11, 6, 7, 8, 9,14,10, 9, 8, 6,11, + 12,13,11, 6, 9,14,10, 9,11,12,13,11,14,10,12 }, + { 0, 1, 1, 2, 2, 3, 3, 4, 5, 6, 7, 7, 7, 8, 4, 5, + 6, 9,10,10, 8,11,12,11, 9, 9,10,10, 8,11,12,11, + 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 } + }; + /* 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_level_transition[2][8] = { + /* update node ctx after decoding a level=1 */ + { 1, 2, 3, 3, 4, 5, 6, 7 }, + /* update node ctx after decoding a level>1 */ + { 4, 4, 4, 4, 5, 6, 7, 7 } + }; + + int index[64]; + + int av_unused last; + int coeff_count = 0; + int node_ctx = 0; + + uint8_t *significant_coeff_ctx_base; + uint8_t *last_coeff_ctx_base; + uint8_t *abs_level_m1_ctx_base; + +#if !ARCH_X86 +#define CABAC_ON_STACK +#endif +#ifdef CABAC_ON_STACK +#define CC &cc + CABACContext cc; + cc.range = h->cabac.range; + cc.low = h->cabac.low; + cc.bytestream= h->cabac.bytestream; +#else +#define CC &h->cabac +#endif + + + /* cat: 0-> DC 16x16 n = 0 + * 1-> AC 16x16 n = luma4x4idx + * 2-> Luma4x4 n = luma4x4idx + * 3-> DC Chroma n = iCbCr + * 4-> AC Chroma n = 16 + 4 * iCbCr + chroma4x4idx + * 5-> Luma8x8 n = 4 * luma8x8idx + */ + + /* read coded block flag */ + if( is_dc || cat != 5 ) { + if( get_cabac( CC, &h->cabac_state[85 + get_cabac_cbf_ctx( h, cat, n, is_dc ) ] ) == 0 ) { + if( !is_dc ) + h->non_zero_count_cache[scan8[n]] = 0; + +#ifdef CABAC_ON_STACK + h->cabac.range = cc.range ; + h->cabac.low = cc.low ; + h->cabac.bytestream= cc.bytestream; +#endif + return; + } + } + + significant_coeff_ctx_base = h->cabac_state + + significant_coeff_flag_offset[MB_FIELD][cat]; + last_coeff_ctx_base = h->cabac_state + + last_coeff_flag_offset[MB_FIELD][cat]; + abs_level_m1_ctx_base = h->cabac_state + + coeff_abs_level_m1_offset[cat]; + + if( !is_dc && cat == 5 ) { +#define DECODE_SIGNIFICANCE( coefs, sig_off, last_off ) \ + for(last= 0; last < coefs; last++) { \ + uint8_t *sig_ctx = significant_coeff_ctx_base + sig_off; \ + if( get_cabac( CC, sig_ctx )) { \ + uint8_t *last_ctx = last_coeff_ctx_base + last_off; \ + index[coeff_count++] = last; \ + if( get_cabac( CC, last_ctx ) ) { \ + last= max_coeff; \ + break; \ + } \ + } \ + }\ + if( last == max_coeff -1 ) {\ + index[coeff_count++] = last;\ + } + 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, sig_off); + } else { + coeff_count= decode_significance_x86(CC, max_coeff, significant_coeff_ctx_base, index); +#else + DECODE_SIGNIFICANCE( 63, sig_off[last], last_coeff_flag_offset_8x8[last] ); + } else { + DECODE_SIGNIFICANCE( max_coeff - 1, last, last ); +#endif + } + assert(coeff_count > 0); + + if( is_dc ) { + if( cat == 0 ) + h->cbp_table[h->mb_xy] |= 0x100; + else + h->cbp_table[h->mb_xy] |= 0x40 << n; + } else { + if( cat == 5 ) + fill_rectangle(&h->non_zero_count_cache[scan8[n]], 2, 2, 8, coeff_count, 1); + else { + assert( cat == 1 || cat == 2 || cat == 4 ); + h->non_zero_count_cache[scan8[n]] = coeff_count; + } + } + + do { + uint8_t *ctx = coeff_abs_level1_ctx[node_ctx] + abs_level_m1_ctx_base; + + int j= scantable[index[--coeff_count]]; + + if( get_cabac( CC, ctx ) == 0 ) { + node_ctx = coeff_abs_level_transition[0][node_ctx]; + if( is_dc ) { + block[j] = get_cabac_bypass_sign( CC, -1); + }else{ + block[j] = (get_cabac_bypass_sign( CC, -qmul[j]) + 32) >> 6; + } + } else { + int coeff_abs = 2; + ctx = coeff_abs_levelgt1_ctx[node_ctx] + abs_level_m1_ctx_base; + node_ctx = coeff_abs_level_transition[1][node_ctx]; + + while( coeff_abs < 15 && get_cabac( CC, ctx ) ) { + coeff_abs++; + } + + if( coeff_abs >= 15 ) { + int j = 0; + while( get_cabac_bypass( CC ) ) { + j++; + } + + coeff_abs=1; + while( j-- ) { + coeff_abs += coeff_abs + get_cabac_bypass( CC ); + } + coeff_abs+= 14; + } + + if( is_dc ) { + block[j] = get_cabac_bypass_sign( CC, -coeff_abs ); + }else{ + block[j] = (get_cabac_bypass_sign( CC, -coeff_abs ) * qmul[j] + 32) >> 6; + } + } + } while( coeff_count ); +#ifdef CABAC_ON_STACK + h->cabac.range = cc.range ; + h->cabac.low = cc.low ; + h->cabac.bytestream= cc.bytestream; +#endif + +} + +static void decode_cabac_residual_dc( 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); +} + +static void decode_cabac_residual_nondc( 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); +} + +/** + * decodes a macroblock + * @return 0 if OK, AC_ERROR / DC_ERROR / MV_ERROR if an error is noticed + */ +int ff_h264_decode_mb_cabac(H264Context *h) { + MpegEncContext * const s = &h->s; + int mb_xy; + int mb_type, partition_count, cbp = 0; + int dct8x8_allowed= h->pps.transform_8x8_mode; + + mb_xy = h->mb_xy = s->mb_x + s->mb_y*s->mb_stride; + + tprintf(s->avctx, "pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y); + if( h->slice_type_nos != FF_I_TYPE ) { + int skip; + /* a skipped mb needs the aff flag from the following mb */ + if( FRAME_MBAFF && (s->mb_y&1)==1 && h->prev_mb_skipped ) + skip = h->next_mb_skipped; + else + skip = decode_cabac_mb_skip( h, s->mb_x, s->mb_y ); + /* read skip flags */ + if( skip ) { + if( FRAME_MBAFF && (s->mb_y&1)==0 ){ + s->current_picture.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); + } + + decode_mb_skip(h); + + h->cbp_table[mb_xy] = 0; + h->chroma_pred_mode_table[mb_xy] = 0; + h->last_qscale_diff = 0; + + return 0; + + } + } + if(FRAME_MBAFF){ + if( (s->mb_y&1) == 0 ) + h->mb_mbaff = + h->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h); + } + + h->prev_mb_skipped = 0; + + fill_decode_neighbors(h, -(MB_FIELD)); + + if( h->slice_type_nos == FF_B_TYPE ) { + int ctx = 0; + assert(h->slice_type_nos == FF_B_TYPE); + + if( !IS_DIRECT( h->left_type[0]-1 ) ) + ctx++; + if( !IS_DIRECT( h->top_type-1 ) ) + ctx++; + + if( !get_cabac_noinline( &h->cabac, &h->cabac_state[27+ctx] ) ){ + mb_type= 0; /* B_Direct_16x16 */ + }else if( !get_cabac_noinline( &h->cabac, &h->cabac_state[27+3] ) ) { + mb_type= 1 + get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] ); /* B_L[01]_16x16 */ + }else{ + int bits; + bits = get_cabac_noinline( &h->cabac, &h->cabac_state[27+4] ) << 3; + bits+= get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] ) << 2; + bits+= get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] ) << 1; + bits+= get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] ); + if( bits < 8 ){ + mb_type= bits + 3; /* B_Bi_16x16 through B_L1_L0_16x8 */ + }else if( bits == 13 ){ + mb_type= decode_cabac_intra_mb_type(h, 32, 0); + goto decode_intra_mb; + }else if( bits == 14 ){ + mb_type= 11; /* B_L1_L0_8x16 */ + }else if( bits == 15 ){ + mb_type= 22; /* B_8x8 */ + }else{ + bits= ( bits<<1 ) + get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] ); + mb_type= bits - 4; /* B_L0_Bi_* through B_Bi_Bi_* */ + } + } + partition_count= b_mb_type_info[mb_type].partition_count; + mb_type= b_mb_type_info[mb_type].type; + } else if( h->slice_type_nos == FF_P_TYPE ) { + if( get_cabac_noinline( &h->cabac, &h->cabac_state[14] ) == 0 ) { + /* P-type */ + if( get_cabac_noinline( &h->cabac, &h->cabac_state[15] ) == 0 ) { + /* P_L0_D16x16, P_8x8 */ + mb_type= 3 * get_cabac_noinline( &h->cabac, &h->cabac_state[16] ); + } else { + /* P_L0_D8x16, P_L0_D16x8 */ + mb_type= 2 - get_cabac_noinline( &h->cabac, &h->cabac_state[17] ); + } + partition_count= p_mb_type_info[mb_type].partition_count; + mb_type= p_mb_type_info[mb_type].type; + } else { + mb_type= decode_cabac_intra_mb_type(h, 17, 0); + goto decode_intra_mb; + } + } else { + mb_type= decode_cabac_intra_mb_type(h, 3, 1); + if(h->slice_type == FF_SI_TYPE && mb_type) + mb_type--; + assert(h->slice_type_nos == FF_I_TYPE); +decode_intra_mb: + partition_count = 0; + cbp= i_mb_type_info[mb_type].cbp; + h->intra16x16_pred_mode= i_mb_type_info[mb_type].pred_mode; + mb_type= i_mb_type_info[mb_type].type; + } + if(MB_FIELD) + mb_type |= MB_TYPE_INTERLACED; + + h->slice_table[ mb_xy ]= h->slice_num; + + if(IS_INTRA_PCM(mb_type)) { + const uint8_t *ptr; + + // We assume these blocks are very rare so we do not optimize it. + // FIXME The two following lines get the bitstream position in the cabac + // decode, I think it should be done by a function in cabac.h (or cabac.c). + ptr= h->cabac.bytestream; + if(h->cabac.low&0x1) ptr--; + if(CABAC_BITS==16){ + if(h->cabac.low&0x1FF) ptr--; + } + + // The pixels are stored in the same order as levels in h->mb array. + memcpy(h->mb, ptr, 256); ptr+=256; + if(CHROMA){ + memcpy(h->mb+128, ptr, 128); ptr+=128; + } + + ff_init_cabac_decoder(&h->cabac, ptr, h->cabac.bytestream_end - ptr); + + // All blocks are present + h->cbp_table[mb_xy] = 0x1ef; + h->chroma_pred_mode_table[mb_xy] = 0; + // In deblocking, the quantizer is 0 + s->current_picture.qscale_table[mb_xy]= 0; + // All coeffs are present + memset(h->non_zero_count[mb_xy], 16, 32); + s->current_picture.mb_type[mb_xy]= mb_type; + h->last_qscale_diff = 0; + return 0; + } + + if(MB_MBAFF){ + h->ref_count[0] <<= 1; + h->ref_count[1] <<= 1; + } + + fill_decode_caches(h, mb_type); + + if( IS_INTRA( mb_type ) ) { + int i, pred_mode; + if( IS_INTRA4x4( mb_type ) ) { + if( dct8x8_allowed && get_cabac_noinline( &h->cabac, &h->cabac_state[399 + h->neighbor_transform_size] ) ) { + mb_type |= MB_TYPE_8x8DCT; + for( i = 0; i < 16; i+=4 ) { + int pred = pred_intra_mode( h, i ); + int mode = decode_cabac_mb_intra4x4_pred_mode( h, pred ); + fill_rectangle( &h->intra4x4_pred_mode_cache[ scan8[i] ], 2, 2, 8, mode, 1 ); + } + } else { + for( i = 0; i < 16; i++ ) { + int pred = pred_intra_mode( h, i ); + h->intra4x4_pred_mode_cache[ scan8[i] ] = decode_cabac_mb_intra4x4_pred_mode( h, pred ); + + //av_log( s->avctx, AV_LOG_ERROR, "i4x4 pred=%d mode=%d\n", pred, h->intra4x4_pred_mode_cache[ scan8[i] ] ); + } + } + ff_h264_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 ); + if( h->intra16x16_pred_mode < 0 ) return -1; + } + if(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 ); + if( pred_mode < 0 ) return -1; + h->chroma_pred_mode= pred_mode; + } + } else if( partition_count == 4 ) { + int i, j, sub_partition_count[4], list, ref[2][4]; + + if( h->slice_type_nos == FF_B_TYPE ) { + for( i = 0; i < 4; i++ ) { + h->sub_mb_type[i] = decode_cabac_b_mb_sub_type( h ); + sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; + h->sub_mb_type[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].type; + } + if( IS_DIRECT(h->sub_mb_type[0] | h->sub_mb_type[1] | + h->sub_mb_type[2] | h->sub_mb_type[3]) ) { + ff_h264_pred_direct_motion(h, &mb_type); + h->ref_cache[0][scan8[4]] = + h->ref_cache[1][scan8[4]] = + h->ref_cache[0][scan8[12]] = + h->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE; + for( i = 0; i < 4; i++ ) + fill_rectangle( &h->direct_cache[scan8[4*i]], 2, 2, 8, (h->sub_mb_type[i]>>1)&0xFF, 1 ); + } + } else { + for( i = 0; i < 4; i++ ) { + h->sub_mb_type[i] = decode_cabac_p_mb_sub_type( h ); + sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; + h->sub_mb_type[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].type; + } + } + + for( list = 0; list < h->list_count; list++ ) { + for( i = 0; i < 4; i++ ) { + if(IS_DIRECT(h->sub_mb_type[i])) continue; + if(IS_DIR(h->sub_mb_type[i], 0, list)){ + if( h->ref_count[list] > 1 ){ + ref[list][i] = decode_cabac_mb_ref( h, list, 4*i ); + if(ref[list][i] >= (unsigned)h->ref_count[list]){ + av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref[list][i], h->ref_count[list]); + return -1; + } + }else + ref[list][i] = 0; + } else { + ref[list][i] = -1; + } + h->ref_cache[list][ scan8[4*i]+1 ]= + h->ref_cache[list][ scan8[4*i]+8 ]=h->ref_cache[list][ scan8[4*i]+9 ]= ref[list][i]; + } + } + + if(dct8x8_allowed) + dct8x8_allowed = get_dct8x8_allowed(h); + + for(list=0; listlist_count; list++){ + for(i=0; i<4; i++){ + h->ref_cache[list][ scan8[4*i] ]=h->ref_cache[list][ scan8[4*i]+1 ]; + if(IS_DIRECT(h->sub_mb_type[i])){ + fill_rectangle(h->mvd_cache[list][scan8[4*i]], 2, 2, 8, 0, 2); + continue; + } + + if(IS_DIR(h->sub_mb_type[i], 0, list) && !IS_DIRECT(h->sub_mb_type[i])){ + const int sub_mb_type= h->sub_mb_type[i]; + const int block_width= (sub_mb_type & (MB_TYPE_16x16|MB_TYPE_16x8)) ? 2 : 1; + for(j=0; jmv_cache[list][ scan8[index] ]; + uint8_t (* mvd_cache)[2]= &h->mvd_cache[list][ scan8[index] ]; + pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my); + DECODE_CABAC_MB_MVD( h, list, index) + tprintf(s->avctx, "final mv:%d %d\n", mx, my); + + if(IS_SUB_8X8(sub_mb_type)){ + mv_cache[ 1 ][0]= + mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx; + mv_cache[ 1 ][1]= + mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my; + + mvd_cache[ 1 ][0]= + mvd_cache[ 8 ][0]= mvd_cache[ 9 ][0]= mpx; + mvd_cache[ 1 ][1]= + mvd_cache[ 8 ][1]= mvd_cache[ 9 ][1]= mpy; + }else if(IS_SUB_8X4(sub_mb_type)){ + mv_cache[ 1 ][0]= mx; + mv_cache[ 1 ][1]= my; + + mvd_cache[ 1 ][0]= mpx; + mvd_cache[ 1 ][1]= mpy; + }else if(IS_SUB_4X8(sub_mb_type)){ + mv_cache[ 8 ][0]= mx; + mv_cache[ 8 ][1]= my; + + mvd_cache[ 8 ][0]= mpx; + mvd_cache[ 8 ][1]= mpy; + } + mv_cache[ 0 ][0]= mx; + mv_cache[ 0 ][1]= my; + + mvd_cache[ 0 ][0]= mpx; + mvd_cache[ 0 ][1]= mpy; + } + }else{ + fill_rectangle(h->mv_cache [list][ scan8[4*i] ], 2, 2, 8, 0, 4); + fill_rectangle(h->mvd_cache[list][ scan8[4*i] ], 2, 2, 8, 0, 2); + } + } + } + } else if( IS_DIRECT(mb_type) ) { + ff_h264_pred_direct_motion(h, &mb_type); + fill_rectangle(h->mvd_cache[0][scan8[0]], 4, 4, 8, 0, 2); + fill_rectangle(h->mvd_cache[1][scan8[0]], 4, 4, 8, 0, 2); + dct8x8_allowed &= h->sps.direct_8x8_inference_flag; + } else { + int list, i; + if(IS_16X16(mb_type)){ + for(list=0; listlist_count; list++){ + if(IS_DIR(mb_type, 0, list)){ + int ref; + if(h->ref_count[list] > 1){ + ref= decode_cabac_mb_ref(h, list, 0); + if(ref >= (unsigned)h->ref_count[list]){ + av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref, h->ref_count[list]); + return -1; + } + }else + ref=0; + fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, ref, 1); + } + } + for(list=0; listlist_count; list++){ + if(IS_DIR(mb_type, 0, list)){ + int mx,my,mpx,mpy; + pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my); + DECODE_CABAC_MB_MVD( h, list, 0) + tprintf(s->avctx, "final mv:%d %d\n", mx, my); + + fill_rectangle(h->mvd_cache[list][ scan8[0] ], 4, 4, 8, pack8to16(mpx,mpy), 2); + fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4); + } + } + } + else if(IS_16X8(mb_type)){ + for(list=0; listlist_count; list++){ + for(i=0; i<2; i++){ + if(IS_DIR(mb_type, i, list)){ + int ref; + if(h->ref_count[list] > 1){ + ref= decode_cabac_mb_ref( h, list, 8*i ); + if(ref >= (unsigned)h->ref_count[list]){ + av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref, h->ref_count[list]); + return -1; + } + }else + ref=0; + fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, ref, 1); + }else + fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, (LIST_NOT_USED&0xFF), 1); + } + } + for(list=0; listlist_count; list++){ + for(i=0; i<2; i++){ + if(IS_DIR(mb_type, i, list)){ + int mx,my,mpx,mpy; + pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my); + DECODE_CABAC_MB_MVD( h, list, 8*i) + tprintf(s->avctx, "final mv:%d %d\n", mx, my); + + fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack8to16(mpx,mpy), 2); + fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx,my), 4); + }else{ + fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 2); + fill_rectangle(h-> mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 4); + } + } + } + }else{ + assert(IS_8X16(mb_type)); + for(list=0; listlist_count; list++){ + for(i=0; i<2; i++){ + if(IS_DIR(mb_type, i, list)){ //FIXME optimize + int ref; + if(h->ref_count[list] > 1){ + ref= decode_cabac_mb_ref( h, list, 4*i ); + if(ref >= (unsigned)h->ref_count[list]){ + av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\n", ref, h->ref_count[list]); + return -1; + } + }else + ref=0; + fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, ref, 1); + }else + fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, (LIST_NOT_USED&0xFF), 1); + } + } + for(list=0; listlist_count; list++){ + for(i=0; i<2; i++){ + if(IS_DIR(mb_type, i, list)){ + int mx,my,mpx,mpy; + pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my); + DECODE_CABAC_MB_MVD( h, list, 4*i) + + tprintf(s->avctx, "final mv:%d %d\n", mx, my); + fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack8to16(mpx,mpy), 2); + fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx,my), 4); + }else{ + fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 2); + fill_rectangle(h-> mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 4); + } + } + } + } + } + + if( IS_INTER( mb_type ) ) { + h->chroma_pred_mode_table[mb_xy] = 0; + write_back_motion( h, mb_type ); + } + + if( !IS_INTRA16x16( mb_type ) ) { + cbp = decode_cabac_mb_cbp_luma( h ); + if(CHROMA) + cbp |= decode_cabac_mb_cbp_chroma( h ) << 4; + } + + h->cbp_table[mb_xy] = h->cbp = cbp; + + if( dct8x8_allowed && (cbp&15) && !IS_INTRA( mb_type ) ) { + mb_type |= MB_TYPE_8x8DCT * get_cabac_noinline( &h->cabac, &h->cabac_state[399 + h->neighbor_transform_size] ); + } + s->current_picture.mb_type[mb_xy]= mb_type; + + if( cbp || IS_INTRA16x16( mb_type ) ) { + const uint8_t *scan, *scan8x8, *dc_scan; + const uint32_t *qmul; + + if(IS_INTERLACED(mb_type)){ + scan8x8= s->qscale ? h->field_scan8x8 : h->field_scan8x8_q0; + scan= s->qscale ? h->field_scan : h->field_scan_q0; + dc_scan= luma_dc_field_scan; + }else{ + scan8x8= s->qscale ? h->zigzag_scan8x8 : h->zigzag_scan8x8_q0; + scan= s->qscale ? h->zigzag_scan : h->zigzag_scan_q0; + dc_scan= luma_dc_zigzag_scan; + } + + // decode_cabac_mb_dqp + if(get_cabac_noinline( &h->cabac, &h->cabac_state[60 + (h->last_qscale_diff != 0)])){ + int val = 1; + int ctx= 2; + + while( get_cabac_noinline( &h->cabac, &h->cabac_state[60 + ctx] ) ) { + ctx= 3; + val++; + if(val > 102){ //prevent infinite loop + av_log(h->s.avctx, AV_LOG_ERROR, "cabac decode of qscale diff failed at %d %d\n", s->mb_x, s->mb_y); + return -1; + } + } + + if( val&0x01 ) + val= (val + 1)>>1 ; + else + val= -((val + 1)>>1); + h->last_qscale_diff = val; + s->qscale += val; + if(((unsigned)s->qscale) > 51){ + if(s->qscale<0) s->qscale+= 52; + else s->qscale-= 52; + } + h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale); + h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale); + }else + h->last_qscale_diff=0; + + if( IS_INTRA16x16( mb_type ) ) { + int i; + //av_log( s->avctx, AV_LOG_ERROR, "INTRA16x16 DC\n" ); + decode_cabac_residual_dc( h, h->mb, 0, 0, dc_scan, 16); + + if( cbp&15 ) { + qmul = h->dequant4_coeff[0][s->qscale]; + for( i = 0; i < 16; i++ ) { + //av_log( s->avctx, AV_LOG_ERROR, "INTRA16x16 AC:%d\n", i ); + decode_cabac_residual_nondc(h, h->mb + 16*i, 1, i, scan + 1, qmul, 15); + } + } else { + fill_rectangle(&h->non_zero_count_cache[scan8[0]], 4, 4, 8, 0, 1); + } + } else { + int i8x8, i4x4; + for( i8x8 = 0; i8x8 < 4; i8x8++ ) { + if( cbp & (1<mb + 64*i8x8, 5, 4*i8x8, + scan8x8, h->dequant8_coeff[IS_INTRA( mb_type ) ? 0:1][s->qscale], 64); + } else { + qmul = h->dequant4_coeff[IS_INTRA( mb_type ) ? 0:3][s->qscale]; + for( i4x4 = 0; i4x4 < 4; i4x4++ ) { + const int index = 4*i8x8 + i4x4; + //av_log( s->avctx, AV_LOG_ERROR, "Luma4x4: %d\n", index ); +//START_TIMER + decode_cabac_residual_nondc(h, h->mb + 16*index, 2, index, scan, qmul, 16); +//STOP_TIMER("decode_residual") + } + } + } else { + uint8_t * const nnz= &h->non_zero_count_cache[ scan8[4*i8x8] ]; + nnz[0] = nnz[1] = nnz[8] = nnz[9] = 0; + } + } + } + + 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(h, h->mb + 256 + 16*4*c, 3, c, chroma_dc_scan, 4); + } + } + + if( cbp&0x20 ) { + int c, i; + for( c = 0; c < 2; c++ ) { + qmul = h->dequant4_coeff[c+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[c]]; + for( i = 0; i < 4; i++ ) { + const int index = 16 + 4 * c + i; + //av_log( s->avctx, AV_LOG_ERROR, "INTRA C%d-AC %d\n",c, index - 16 ); + decode_cabac_residual_nondc(h, h->mb + 16*index, 4, index, scan + 1, qmul, 15); + } + } + } else { + uint8_t * const nnz= &h->non_zero_count_cache[0]; + nnz[ scan8[16]+0 ] = nnz[ scan8[16]+1 ] =nnz[ scan8[16]+8 ] =nnz[ scan8[16]+9 ] = + nnz[ scan8[20]+0 ] = nnz[ scan8[20]+1 ] =nnz[ scan8[20]+8 ] =nnz[ scan8[20]+9 ] = 0; + } + } else { + uint8_t * const nnz= &h->non_zero_count_cache[0]; + fill_rectangle(&nnz[scan8[0]], 4, 4, 8, 0, 1); + nnz[ scan8[16]+0 ] = nnz[ scan8[16]+1 ] =nnz[ scan8[16]+8 ] =nnz[ scan8[16]+9 ] = + nnz[ scan8[20]+0 ] = nnz[ scan8[20]+1 ] =nnz[ scan8[20]+8 ] =nnz[ scan8[20]+9 ] = 0; + h->last_qscale_diff = 0; + } + + s->current_picture.qscale_table[mb_xy]= s->qscale; + write_back_non_zero_count(h); + + if(MB_MBAFF){ + h->ref_count[0] >>= 1; + h->ref_count[1] >>= 1; + } + + return 0; +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_cavlc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_cavlc.c new file mode 100644 index 0000000000..0475e9454a --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_cavlc.c @@ -0,0 +1,1030 @@ +/* + * H.26L/H.264/AVC/JVT/14496-10/... cavlc bitstream decoding + * Copyright (c) 2003 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 + */ + +/** + * @file + * H.264 / AVC / MPEG4 part10 cavlc bitstream decoding. + * @author Michael Niedermayer + */ + +#define CABAC 0 + +#include "internal.h" +#include "avcodec.h" +#include "mpegvideo.h" +#include "h264.h" +#include "h264data.h" // FIXME FIXME FIXME +#include "h264_mvpred.h" +#include "golomb.h" + +//#undef NDEBUG +#include + +static const uint8_t golomb_to_inter_cbp_gray[16]={ + 0, 1, 2, 4, 8, 3, 5,10,12,15, 7,11,13,14, 6, 9, +}; + +static const uint8_t golomb_to_intra4x4_cbp_gray[16]={ +15, 0, 7,11,13,14, 3, 5,10,12, 1, 2, 4, 8, 6, 9, +}; + +static const uint8_t chroma_dc_coeff_token_len[4*5]={ + 2, 0, 0, 0, + 6, 1, 0, 0, + 6, 6, 3, 0, + 6, 7, 7, 6, + 6, 8, 8, 7, +}; + +static const uint8_t chroma_dc_coeff_token_bits[4*5]={ + 1, 0, 0, 0, + 7, 1, 0, 0, + 4, 6, 1, 0, + 3, 3, 2, 5, + 2, 3, 2, 0, +}; + +static const uint8_t coeff_token_len[4][4*17]={ +{ + 1, 0, 0, 0, + 6, 2, 0, 0, 8, 6, 3, 0, 9, 8, 7, 5, 10, 9, 8, 6, + 11,10, 9, 7, 13,11,10, 8, 13,13,11, 9, 13,13,13,10, + 14,14,13,11, 14,14,14,13, 15,15,14,14, 15,15,15,14, + 16,15,15,15, 16,16,16,15, 16,16,16,16, 16,16,16,16, +}, +{ + 2, 0, 0, 0, + 6, 2, 0, 0, 6, 5, 3, 0, 7, 6, 6, 4, 8, 6, 6, 4, + 8, 7, 7, 5, 9, 8, 8, 6, 11, 9, 9, 6, 11,11,11, 7, + 12,11,11, 9, 12,12,12,11, 12,12,12,11, 13,13,13,12, + 13,13,13,13, 13,14,13,13, 14,14,14,13, 14,14,14,14, +}, +{ + 4, 0, 0, 0, + 6, 4, 0, 0, 6, 5, 4, 0, 6, 5, 5, 4, 7, 5, 5, 4, + 7, 5, 5, 4, 7, 6, 6, 4, 7, 6, 6, 4, 8, 7, 7, 5, + 8, 8, 7, 6, 9, 8, 8, 7, 9, 9, 8, 8, 9, 9, 9, 8, + 10, 9, 9, 9, 10,10,10,10, 10,10,10,10, 10,10,10,10, +}, +{ + 6, 0, 0, 0, + 6, 6, 0, 0, 6, 6, 6, 0, 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, +} +}; + +static const uint8_t coeff_token_bits[4][4*17]={ +{ + 1, 0, 0, 0, + 5, 1, 0, 0, 7, 4, 1, 0, 7, 6, 5, 3, 7, 6, 5, 3, + 7, 6, 5, 4, 15, 6, 5, 4, 11,14, 5, 4, 8,10,13, 4, + 15,14, 9, 4, 11,10,13,12, 15,14, 9,12, 11,10,13, 8, + 15, 1, 9,12, 11,14,13, 8, 7,10, 9,12, 4, 6, 5, 8, +}, +{ + 3, 0, 0, 0, + 11, 2, 0, 0, 7, 7, 3, 0, 7,10, 9, 5, 7, 6, 5, 4, + 4, 6, 5, 6, 7, 6, 5, 8, 15, 6, 5, 4, 11,14,13, 4, + 15,10, 9, 4, 11,14,13,12, 8,10, 9, 8, 15,14,13,12, + 11,10, 9,12, 7,11, 6, 8, 9, 8,10, 1, 7, 6, 5, 4, +}, +{ + 15, 0, 0, 0, + 15,14, 0, 0, 11,15,13, 0, 8,12,14,12, 15,10,11,11, + 11, 8, 9,10, 9,14,13, 9, 8,10, 9, 8, 15,14,13,13, + 11,14,10,12, 15,10,13,12, 11,14, 9,12, 8,10,13, 8, + 13, 7, 9,12, 9,12,11,10, 5, 8, 7, 6, 1, 4, 3, 2, +}, +{ + 3, 0, 0, 0, + 0, 1, 0, 0, 4, 5, 6, 0, 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, +} +}; + +static const uint8_t total_zeros_len[16][16]= { + {1,3,3,4,4,5,5,6,6,7,7,8,8,9,9,9}, + {3,3,3,3,3,4,4,4,4,5,5,6,6,6,6}, + {4,3,3,3,4,4,3,3,4,5,5,6,5,6}, + {5,3,4,4,3,3,3,4,3,4,5,5,5}, + {4,4,4,3,3,3,3,3,4,5,4,5}, + {6,5,3,3,3,3,3,3,4,3,6}, + {6,5,3,3,3,2,3,4,3,6}, + {6,4,5,3,2,2,3,3,6}, + {6,6,4,2,2,3,2,5}, + {5,5,3,2,2,2,4}, + {4,4,3,3,1,3}, + {4,4,2,1,3}, + {3,3,1,2}, + {2,2,1}, + {1,1}, +}; + +static const uint8_t total_zeros_bits[16][16]= { + {1,3,2,3,2,3,2,3,2,3,2,3,2,3,2,1}, + {7,6,5,4,3,5,4,3,2,3,2,3,2,1,0}, + {5,7,6,5,4,3,4,3,2,3,2,1,1,0}, + {3,7,5,4,6,5,4,3,3,2,2,1,0}, + {5,4,3,7,6,5,4,3,2,1,1,0}, + {1,1,7,6,5,4,3,2,1,1,0}, + {1,1,5,4,3,3,2,1,1,0}, + {1,1,1,3,3,2,2,1,0}, + {1,0,1,3,2,1,1,1}, + {1,0,1,3,2,1,1}, + {0,1,1,2,1,3}, + {0,1,1,1,1}, + {0,1,1,1}, + {0,1,1}, + {0,1}, +}; + +static const uint8_t chroma_dc_total_zeros_len[3][4]= { + { 1, 2, 3, 3,}, + { 1, 2, 2, 0,}, + { 1, 1, 0, 0,}, +}; + +static const uint8_t chroma_dc_total_zeros_bits[3][4]= { + { 1, 1, 1, 0,}, + { 1, 1, 0, 0,}, + { 1, 0, 0, 0,}, +}; + +static const uint8_t run_len[7][16]={ + {1,1}, + {1,2,2}, + {2,2,2,2}, + {2,2,2,3,3}, + {2,2,3,3,3,3}, + {2,3,3,3,3,3,3}, + {3,3,3,3,3,3,3,4,5,6,7,8,9,10,11}, +}; + +static const uint8_t run_bits[7][16]={ + {1,0}, + {1,1,0}, + {3,2,1,0}, + {3,2,1,1,0}, + {3,2,3,2,1,0}, + {3,0,1,3,2,5,4}, + {7,6,5,4,3,2,1,1,1,1,1,1,1,1,1}, +}; + +static VLC coeff_token_vlc[4]; +static VLC_TYPE coeff_token_vlc_tables[520+332+280+256][2]; +static const int coeff_token_vlc_tables_size[4]={520,332,280,256}; + +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 total_zeros_vlc[15]; +static VLC_TYPE total_zeros_vlc_tables[15][512][2]; +static const int total_zeros_vlc_tables_size = 512; + +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 run_vlc[6]; +static VLC_TYPE run_vlc_tables[6][8][2]; +static const int run_vlc_tables_size = 8; + +static VLC run7_vlc; +static VLC_TYPE run7_vlc_table[96][2]; +static const int run7_vlc_table_size = 96; + +#define LEVEL_TAB_BITS 8 +static int8_t cavlc_level_tab[7][1<non_zero_count_cache[index8 - 1]; + const int top = h->non_zero_count_cache[index8 - 8]; + int i= left + top; + + if(i<64) i= (i+1)>>1; + + tprintf(h->s.avctx, "pred_nnz L%X T%X n%d s%d P%X\n", left, top, n, scan8[n], i&31); + + return i&31; +} + +static av_cold void init_cavlc_level_tab(void){ + int suffix_length, mask; + unsigned int i; + + for(suffix_length=0; suffix_length<7; suffix_length++){ + for(i=0; i<(1<>(LEVEL_TAB_BITS-prefix-1-suffix_length)) - (1<>1) ^ mask) - mask; + if(prefix + 1 + suffix_length <= LEVEL_TAB_BITS){ + 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){ + cavlc_level_tab[suffix_length][i][0]= prefix+100; + cavlc_level_tab[suffix_length][i][1]= prefix + 1; + }else{ + cavlc_level_tab[suffix_length][i][0]= LEVEL_TAB_BITS+100; + cavlc_level_tab[suffix_length][i][1]= LEVEL_TAB_BITS; + } + } + } +} + +av_cold void ff_h264_decode_init_vlc(void){ + static int done = 0; + + if (!done) { + int i; + int offset; + done = 1; + + chroma_dc_coeff_token_vlc.table = chroma_dc_coeff_token_vlc_table; + chroma_dc_coeff_token_vlc.table_allocated = chroma_dc_coeff_token_vlc_table_size; + init_vlc(&chroma_dc_coeff_token_vlc, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 4*5, + &chroma_dc_coeff_token_len [0], 1, 1, + &chroma_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; + coeff_token_vlc[i].table_allocated = coeff_token_vlc_tables_size[i]; + init_vlc(&coeff_token_vlc[i], COEFF_TOKEN_VLC_BITS, 4*17, + &coeff_token_len [i][0], 1, 1, + &coeff_token_bits[i][0], 1, 1, + INIT_VLC_USE_NEW_STATIC); + offset += coeff_token_vlc_tables_size[i]; + } + /* + * This is a one time safety check to make sure that + * the packed static coeff_token_vlc table sizes + * were initialized correctly. + */ + assert(offset == FF_ARRAY_ELEMS(coeff_token_vlc_tables)); + + for(i=0; i<3; i++){ + chroma_dc_total_zeros_vlc[i].table = chroma_dc_total_zeros_vlc_tables[i]; + chroma_dc_total_zeros_vlc[i].table_allocated = chroma_dc_total_zeros_vlc_tables_size; + init_vlc(&chroma_dc_total_zeros_vlc[i], + CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 4, + &chroma_dc_total_zeros_len [i][0], 1, 1, + &chroma_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; + init_vlc(&total_zeros_vlc[i], + TOTAL_ZEROS_VLC_BITS, 16, + &total_zeros_len [i][0], 1, 1, + &total_zeros_bits[i][0], 1, 1, + INIT_VLC_USE_NEW_STATIC); + } + + for(i=0; i<6; i++){ + run_vlc[i].table = run_vlc_tables[i]; + run_vlc[i].table_allocated = run_vlc_tables_size; + init_vlc(&run_vlc[i], + RUN_VLC_BITS, 7, + &run_len [i][0], 1, 1, + &run_bits[i][0], 1, 1, + INIT_VLC_USE_NEW_STATIC); + } + run7_vlc.table = run7_vlc_table, + run7_vlc.table_allocated = run7_vlc_table_size; + init_vlc(&run7_vlc, RUN7_VLC_BITS, 16, + &run_len [6][0], 1, 1, + &run_bits[6][0], 1, 1, + INIT_VLC_USE_NEW_STATIC); + + init_cavlc_level_tab(); + } +} + +/** + * + */ +static inline int get_level_prefix(GetBitContext *gb){ + unsigned int buf; + int log; + + OPEN_READER(re, gb); + UPDATE_CACHE(re, gb); + buf=GET_CACHE(re, gb); + + log= 32 - av_log2(buf); +#ifdef TRACE + print_bin(buf>>(32-log), log); + av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d lpr @%5d in %s get_level_prefix\n", buf>>(32-log), log, log-1, get_bits_count(gb), __FILE__); +#endif + + LAST_SKIP_BITS(re, gb, log); + CLOSE_READER(re, gb); + + return log-1; +} + +/** + * decodes a residual block. + * @param n block index + * @param scantable scantable + * @param max_coeff number of coefficients in the block + * @return <0 if an error occurred + */ +static int decode_residual(H264Context *h, GetBitContext *gb, DCTELEM *block, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff){ + MpegEncContext * const s = &h->s; + static const int coeff_token_table_index[17]= {0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3}; + int level[16]; + int zeros_left, coeff_num, coeff_token, total_coeff, i, j, trailing_ones, run_before; + + //FIXME put trailing_onex into the context + + if(n == CHROMA_DC_BLOCK_INDEX){ + coeff_token= get_vlc2(gb, chroma_dc_coeff_token_vlc.table, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 1); + total_coeff= coeff_token>>2; + }else{ + if(n == LUMA_DC_BLOCK_INDEX){ + total_coeff= pred_non_zero_count(h, 0); + coeff_token= get_vlc2(gb, coeff_token_vlc[ coeff_token_table_index[total_coeff] ].table, COEFF_TOKEN_VLC_BITS, 2); + total_coeff= coeff_token>>2; + }else{ + total_coeff= pred_non_zero_count(h, n); + coeff_token= get_vlc2(gb, coeff_token_vlc[ coeff_token_table_index[total_coeff] ].table, COEFF_TOKEN_VLC_BITS, 2); + total_coeff= coeff_token>>2; + h->non_zero_count_cache[ scan8[n] ]= total_coeff; + } + } + + //FIXME set last_non_zero? + + if(total_coeff==0) + return 0; + if(total_coeff > (unsigned)max_coeff) { + av_log(h->s.avctx, AV_LOG_ERROR, "corrupted macroblock %d %d (total_coeff=%d)\n", s->mb_x, s->mb_y, total_coeff); + return -1; + } + + trailing_ones= coeff_token&3; + tprintf(h->s.avctx, "trailing:%d, total:%d\n", trailing_ones, total_coeff); + assert(total_coeff<=16); + + i = show_bits(gb, 3); + skip_bits(gb, trailing_ones); + level[0] = 1-((i&4)>>1); + level[1] = 1-((i&2) ); + level[2] = 1-((i&1)<<1); + + if(trailing_ones 10 & trailing_ones < 3; + int bitsi= show_bits(gb, LEVEL_TAB_BITS); + int level_code= cavlc_level_tab[suffix_length][bitsi][0]; + + skip_bits(gb, cavlc_level_tab[suffix_length][bitsi][1]); + if(level_code >= 100){ + prefix= level_code - 100; + if(prefix == LEVEL_TAB_BITS) + prefix += get_level_prefix(gb); + + //first coefficient has suffix_length equal to 0 or 1 + if(prefix<14){ //FIXME try to build a large unified VLC table for all this + if(suffix_length) + level_code= (prefix<<1) + get_bits1(gb); //part + else + level_code= prefix; //part + }else if(prefix==14){ + if(suffix_length) + level_code= (prefix<<1) + get_bits1(gb); //part + else + level_code= prefix + get_bits(gb, 4); //part + }else{ + level_code= 30 + get_bits(gb, prefix-3); //part + if(prefix>=16){ + if(prefix > 25+3){ + av_log(h->s.avctx, AV_LOG_ERROR, "Invalid level prefix\n"); + return -1; + } + level_code += (1<<(prefix-3))-4096; + } + } + + if(trailing_ones < 3) level_code += 2; + + suffix_length = 2; + mask= -(level_code&1); + level[trailing_ones]= (((2+level_code)>>1) ^ mask) - mask; + }else{ + level_code += ((level_code>>31)|1) & -(trailing_ones < 3); + + suffix_length = 1 + (level_code + 3U > 6U); + level[trailing_ones]= level_code; + } + + //remaining coefficients have suffix_length > 0 + for(i=trailing_ones+1;i= 100){ + prefix= level_code - 100; + if(prefix == LEVEL_TAB_BITS){ + prefix += get_level_prefix(gb); + } + if(prefix<15){ + level_code = (prefix<=16) + level_code += (1<<(prefix-3))-4096; + } + mask= -(level_code&1); + level_code= (((2+level_code)>>1) ^ mask) - mask; + } + level[i]= level_code; + suffix_length+= suffix_limit[suffix_length] + level_code > 2U*suffix_limit[suffix_length]; + } + } + + if(total_coeff == max_coeff) + zeros_left=0; + else{ + if(n == CHROMA_DC_BLOCK_INDEX) + 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, (total_zeros_vlc-1)[ total_coeff ].table, TOTAL_ZEROS_VLC_BITS, 1); + } + + coeff_num = zeros_left + total_coeff - 1; + j = scantable[coeff_num]; + if(n > 24){ + block[j] = level[0]; + for(i=1;i>6; + for(i=1;i>6; + } + } + + if(zeros_left<0){ + av_log(h->s.avctx, AV_LOG_ERROR, "negative number of zero coeffs at %d %d\n", s->mb_x, s->mb_y); + return -1; + } + + return 0; +} + +int ff_h264_decode_mb_cavlc(H264Context *h){ + MpegEncContext * const s = &h->s; + int mb_xy; + int partition_count; + unsigned int mb_type, cbp; + int dct8x8_allowed= h->pps.transform_8x8_mode; + + mb_xy = h->mb_xy = s->mb_x + s->mb_y*s->mb_stride; + + tprintf(s->avctx, "pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y); + cbp = 0; /* avoid warning. FIXME: find a solution without slowing + down the code */ + if(h->slice_type_nos != FF_I_TYPE){ + if(s->mb_skip_run==-1) + s->mb_skip_run= get_ue_golomb(&s->gb); + + if (s->mb_skip_run--) { + if(FRAME_MBAFF && (s->mb_y&1) == 0){ + if(s->mb_skip_run==0) + h->mb_mbaff = h->mb_field_decoding_flag = get_bits1(&s->gb); + } + decode_mb_skip(h); + return 0; + } + } + if(FRAME_MBAFF){ + if( (s->mb_y&1) == 0 ) + h->mb_mbaff = h->mb_field_decoding_flag = get_bits1(&s->gb); + } + + h->prev_mb_skipped= 0; + + mb_type= get_ue_golomb(&s->gb); + if(h->slice_type_nos == FF_B_TYPE){ + if(mb_type < 23){ + partition_count= b_mb_type_info[mb_type].partition_count; + mb_type= b_mb_type_info[mb_type].type; + }else{ + mb_type -= 23; + goto decode_intra_mb; + } + }else if(h->slice_type_nos == FF_P_TYPE){ + if(mb_type < 5){ + partition_count= p_mb_type_info[mb_type].partition_count; + mb_type= p_mb_type_info[mb_type].type; + }else{ + mb_type -= 5; + goto decode_intra_mb; + } + }else{ + assert(h->slice_type_nos == FF_I_TYPE); + if(h->slice_type == FF_SI_TYPE && mb_type) + mb_type--; +decode_intra_mb: + if(mb_type > 25){ + av_log(h->s.avctx, AV_LOG_ERROR, "mb_type %d in %c slice too large at %d %d\n", mb_type, av_get_pict_type_char(h->slice_type), s->mb_x, s->mb_y); + return -1; + } + partition_count=0; + cbp= i_mb_type_info[mb_type].cbp; + h->intra16x16_pred_mode= i_mb_type_info[mb_type].pred_mode; + mb_type= i_mb_type_info[mb_type].type; + } + + if(MB_FIELD) + mb_type |= MB_TYPE_INTERLACED; + + h->slice_table[ mb_xy ]= h->slice_num; + + if(IS_INTRA_PCM(mb_type)){ + unsigned int x; + + // We assume these blocks are very rare so we do not optimize it. + align_get_bits(&s->gb); + + // The pixels are stored in the same order as levels in h->mb array. + for(x=0; x < (CHROMA ? 384 : 256); x++){ + ((uint8_t*)h->mb)[x]= get_bits(&s->gb, 8); + } + + // In deblocking, the quantizer is 0 + s->current_picture.qscale_table[mb_xy]= 0; + // All coeffs are present + memset(h->non_zero_count[mb_xy], 16, 32); + + s->current_picture.mb_type[mb_xy]= mb_type; + return 0; + } + + if(MB_MBAFF){ + h->ref_count[0] <<= 1; + h->ref_count[1] <<= 1; + } + + fill_decode_neighbors(h, mb_type); + fill_decode_caches(h, mb_type); + + //mb_pred + if(IS_INTRA(mb_type)){ + int pred_mode; +// init_top_left_availability(h); + if(IS_INTRA4x4(mb_type)){ + int i; + int di = 1; + if(dct8x8_allowed && get_bits1(&s->gb)){ + mb_type |= MB_TYPE_8x8DCT; + di = 4; + } + +// fill_intra4x4_pred_table(h); + for(i=0; i<16; i+=di){ + int mode= pred_intra_mode(h, i); + + if(!get_bits1(&s->gb)){ + const int rem_mode= get_bits(&s->gb, 3); + mode = rem_mode + (rem_mode >= mode); + } + + if(di==4) + fill_rectangle( &h->intra4x4_pred_mode_cache[ scan8[i] ], 2, 2, 8, mode, 1 ); + else + h->intra4x4_pred_mode_cache[ scan8[i] ] = mode; + } + ff_h264_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); + if(h->intra16x16_pred_mode < 0) + return -1; + } + if(CHROMA){ + pred_mode= ff_h264_check_intra_pred_mode(h, get_ue_golomb_31(&s->gb)); + if(pred_mode < 0) + return -1; + h->chroma_pred_mode= pred_mode; + } + }else if(partition_count==4){ + int i, j, sub_partition_count[4], list, ref[2][4]; + + if(h->slice_type_nos == FF_B_TYPE){ + for(i=0; i<4; i++){ + h->sub_mb_type[i]= get_ue_golomb_31(&s->gb); + if(h->sub_mb_type[i] >=13){ + av_log(h->s.avctx, AV_LOG_ERROR, "B sub_mb_type %u out of range at %d %d\n", h->sub_mb_type[i], s->mb_x, s->mb_y); + return -1; + } + sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; + h->sub_mb_type[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].type; + } + if( IS_DIRECT(h->sub_mb_type[0]|h->sub_mb_type[1]|h->sub_mb_type[2]|h->sub_mb_type[3])) { + ff_h264_pred_direct_motion(h, &mb_type); + h->ref_cache[0][scan8[4]] = + h->ref_cache[1][scan8[4]] = + h->ref_cache[0][scan8[12]] = + h->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE; + } + }else{ + assert(h->slice_type_nos == FF_P_TYPE); //FIXME SP correct ? + for(i=0; i<4; i++){ + h->sub_mb_type[i]= get_ue_golomb_31(&s->gb); + if(h->sub_mb_type[i] >=4){ + av_log(h->s.avctx, AV_LOG_ERROR, "P sub_mb_type %u out of range at %d %d\n", h->sub_mb_type[i], s->mb_x, s->mb_y); + return -1; + } + sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; + h->sub_mb_type[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].type; + } + } + + for(list=0; listlist_count; list++){ + int ref_count= IS_REF0(mb_type) ? 1 : h->ref_count[list]; + for(i=0; i<4; i++){ + if(IS_DIRECT(h->sub_mb_type[i])) continue; + if(IS_DIR(h->sub_mb_type[i], 0, list)){ + unsigned int tmp; + if(ref_count == 1){ + tmp= 0; + }else if(ref_count == 2){ + tmp= get_bits1(&s->gb)^1; + }else{ + tmp= get_ue_golomb_31(&s->gb); + if(tmp>=ref_count){ + av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", tmp); + return -1; + } + } + ref[list][i]= tmp; + }else{ + //FIXME + ref[list][i] = -1; + } + } + } + + if(dct8x8_allowed) + dct8x8_allowed = get_dct8x8_allowed(h); + + for(list=0; listlist_count; list++){ + for(i=0; i<4; i++){ + if(IS_DIRECT(h->sub_mb_type[i])) { + h->ref_cache[list][ scan8[4*i] ] = h->ref_cache[list][ scan8[4*i]+1 ]; + continue; + } + h->ref_cache[list][ scan8[4*i] ]=h->ref_cache[list][ scan8[4*i]+1 ]= + h->ref_cache[list][ scan8[4*i]+8 ]=h->ref_cache[list][ scan8[4*i]+9 ]= ref[list][i]; + + if(IS_DIR(h->sub_mb_type[i], 0, list)){ + const int sub_mb_type= h->sub_mb_type[i]; + const int block_width= (sub_mb_type & (MB_TYPE_16x16|MB_TYPE_16x8)) ? 2 : 1; + for(j=0; jmv_cache[list][ scan8[index] ]; + pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my); + mx += get_se_golomb(&s->gb); + my += get_se_golomb(&s->gb); + tprintf(s->avctx, "final mv:%d %d\n", mx, my); + + if(IS_SUB_8X8(sub_mb_type)){ + mv_cache[ 1 ][0]= + mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx; + mv_cache[ 1 ][1]= + mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my; + }else if(IS_SUB_8X4(sub_mb_type)){ + mv_cache[ 1 ][0]= mx; + mv_cache[ 1 ][1]= my; + }else if(IS_SUB_4X8(sub_mb_type)){ + mv_cache[ 8 ][0]= mx; + mv_cache[ 8 ][1]= my; + } + mv_cache[ 0 ][0]= mx; + mv_cache[ 0 ][1]= my; + } + }else{ + uint32_t *p= (uint32_t *)&h->mv_cache[list][ scan8[4*i] ][0]; + p[0] = p[1]= + p[8] = p[9]= 0; + } + } + } + }else if(IS_DIRECT(mb_type)){ + ff_h264_pred_direct_motion(h, &mb_type); + dct8x8_allowed &= h->sps.direct_8x8_inference_flag; + }else{ + int list, mx, my, i; + //FIXME we should set ref_idx_l? to 0 if we use that later ... + if(IS_16X16(mb_type)){ + for(list=0; listlist_count; list++){ + unsigned int val; + if(IS_DIR(mb_type, 0, list)){ + if(h->ref_count[list]==1){ + val= 0; + }else if(h->ref_count[list]==2){ + val= get_bits1(&s->gb)^1; + }else{ + val= get_ue_golomb_31(&s->gb); + if(val >= h->ref_count[list]){ + av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", val); + return -1; + } + } + fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, val, 1); + } + } + for(list=0; listlist_count; list++){ + if(IS_DIR(mb_type, 0, list)){ + pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my); + mx += get_se_golomb(&s->gb); + my += get_se_golomb(&s->gb); + tprintf(s->avctx, "final mv:%d %d\n", mx, my); + + fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4); + } + } + } + else if(IS_16X8(mb_type)){ + for(list=0; listlist_count; list++){ + for(i=0; i<2; i++){ + unsigned int val; + if(IS_DIR(mb_type, i, list)){ + if(h->ref_count[list] == 1){ + val= 0; + }else if(h->ref_count[list] == 2){ + val= get_bits1(&s->gb)^1; + }else{ + val= get_ue_golomb_31(&s->gb); + if(val >= h->ref_count[list]){ + av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", val); + return -1; + } + } + }else + val= LIST_NOT_USED&0xFF; + fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, val, 1); + } + } + for(list=0; listlist_count; list++){ + for(i=0; i<2; i++){ + unsigned int val; + if(IS_DIR(mb_type, i, list)){ + pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my); + mx += get_se_golomb(&s->gb); + my += get_se_golomb(&s->gb); + tprintf(s->avctx, "final mv:%d %d\n", mx, my); + + val= pack16to32(mx,my); + }else + val=0; + fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, val, 4); + } + } + }else{ + assert(IS_8X16(mb_type)); + for(list=0; listlist_count; list++){ + for(i=0; i<2; i++){ + unsigned int val; + if(IS_DIR(mb_type, i, list)){ //FIXME optimize + if(h->ref_count[list]==1){ + val= 0; + }else if(h->ref_count[list]==2){ + val= get_bits1(&s->gb)^1; + }else{ + val= get_ue_golomb_31(&s->gb); + if(val >= h->ref_count[list]){ + av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", val); + return -1; + } + } + }else + val= LIST_NOT_USED&0xFF; + fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, val, 1); + } + } + for(list=0; listlist_count; list++){ + for(i=0; i<2; i++){ + unsigned int val; + if(IS_DIR(mb_type, i, list)){ + pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my); + mx += get_se_golomb(&s->gb); + my += get_se_golomb(&s->gb); + tprintf(s->avctx, "final mv:%d %d\n", mx, my); + + val= pack16to32(mx,my); + }else + val=0; + fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, val, 4); + } + } + } + } + + if(IS_INTER(mb_type)) + write_back_motion(h, mb_type); + + if(!IS_INTRA16x16(mb_type)){ + cbp= get_ue_golomb(&s->gb); + if(cbp > 47){ + av_log(h->s.avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\n", cbp, s->mb_x, s->mb_y); + return -1; + } + + if(CHROMA){ + if(IS_INTRA4x4(mb_type)) cbp= golomb_to_intra4x4_cbp[cbp]; + else cbp= golomb_to_inter_cbp [cbp]; + }else{ + if(IS_INTRA4x4(mb_type)) cbp= golomb_to_intra4x4_cbp_gray[cbp]; + else cbp= golomb_to_inter_cbp_gray[cbp]; + } + } + + if(dct8x8_allowed && (cbp&15) && !IS_INTRA(mb_type)){ + mb_type |= MB_TYPE_8x8DCT*get_bits1(&s->gb); + } + h->cbp= + h->cbp_table[mb_xy]= cbp; + s->current_picture.mb_type[mb_xy]= mb_type; + + if(cbp || IS_INTRA16x16(mb_type)){ + int i8x8, i4x4, chroma_idx; + int dquant; + GetBitContext *gb= IS_INTRA(mb_type) ? h->intra_gb_ptr : h->inter_gb_ptr; + const uint8_t *scan, *scan8x8, *dc_scan; + + if(IS_INTERLACED(mb_type)){ + scan8x8= s->qscale ? h->field_scan8x8_cavlc : h->field_scan8x8_cavlc_q0; + scan= s->qscale ? h->field_scan : h->field_scan_q0; + dc_scan= luma_dc_field_scan; + }else{ + scan8x8= s->qscale ? h->zigzag_scan8x8_cavlc : h->zigzag_scan8x8_cavlc_q0; + scan= s->qscale ? h->zigzag_scan : h->zigzag_scan_q0; + dc_scan= luma_dc_zigzag_scan; + } + + dquant= get_se_golomb(&s->gb); + + s->qscale += dquant; + + if(((unsigned)s->qscale) > 51){ + if(s->qscale<0) s->qscale+= 52; + else s->qscale-= 52; + if(((unsigned)s->qscale) > 51){ + av_log(h->s.avctx, AV_LOG_ERROR, "dquant out of range (%d) at %d %d\n", dquant, s->mb_x, s->mb_y); + return -1; + } + } + + h->chroma_qp[0]= get_chroma_qp(h, 0, s->qscale); + h->chroma_qp[1]= get_chroma_qp(h, 1, s->qscale); + if(IS_INTRA16x16(mb_type)){ + if( decode_residual(h, h->intra_gb_ptr, h->mb, LUMA_DC_BLOCK_INDEX, dc_scan, h->dequant4_coeff[0][s->qscale], 16) < 0){ + return -1; //FIXME continue if partitioned and other return -1 too + } + + assert((cbp&15) == 0 || (cbp&15) == 15); + + if(cbp&15){ + for(i8x8=0; i8x8<4; i8x8++){ + for(i4x4=0; i4x4<4; i4x4++){ + const int index= i4x4 + 4*i8x8; + if( decode_residual(h, h->intra_gb_ptr, h->mb + 16*index, index, scan + 1, h->dequant4_coeff[0][s->qscale], 15) < 0 ){ + return -1; + } + } + } + }else{ + fill_rectangle(&h->non_zero_count_cache[scan8[0]], 4, 4, 8, 0, 1); + } + }else{ + for(i8x8=0; i8x8<4; i8x8++){ + if(cbp & (1<mb[64*i8x8]; + uint8_t *nnz; + for(i4x4=0; i4x4<4; i4x4++){ + if( decode_residual(h, gb, buf, i4x4+4*i8x8, scan8x8+16*i4x4, + h->dequant8_coeff[IS_INTRA( mb_type ) ? 0:1][s->qscale], 16) <0 ) + return -1; + } + nnz= &h->non_zero_count_cache[ scan8[4*i8x8] ]; + nnz[0] += nnz[1] + nnz[8] + nnz[9]; + }else{ + for(i4x4=0; i4x4<4; i4x4++){ + const int index= i4x4 + 4*i8x8; + + if( decode_residual(h, gb, h->mb + 16*index, index, scan, h->dequant4_coeff[IS_INTRA( mb_type ) ? 0:3][s->qscale], 16) <0 ){ + return -1; + } + } + } + }else{ + uint8_t * const nnz= &h->non_zero_count_cache[ scan8[4*i8x8] ]; + nnz[0] = nnz[1] = nnz[8] = nnz[9] = 0; + } + } + } + + if(cbp&0x30){ + for(chroma_idx=0; chroma_idx<2; chroma_idx++) + if( decode_residual(h, gb, h->mb + 256 + 16*4*chroma_idx, CHROMA_DC_BLOCK_INDEX, chroma_dc_scan, NULL, 4) < 0){ + return -1; + } + } + + 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 + 4*chroma_idx + i4x4; + if( decode_residual(h, gb, h->mb + 16*index, index, scan + 1, qmul, 15) < 0){ + return -1; + } + } + } + }else{ + uint8_t * const nnz= &h->non_zero_count_cache[0]; + nnz[ scan8[16]+0 ] = nnz[ scan8[16]+1 ] =nnz[ scan8[16]+8 ] =nnz[ scan8[16]+9 ] = + nnz[ scan8[20]+0 ] = nnz[ scan8[20]+1 ] =nnz[ scan8[20]+8 ] =nnz[ scan8[20]+9 ] = 0; + } + }else{ + uint8_t * const nnz= &h->non_zero_count_cache[0]; + fill_rectangle(&nnz[scan8[0]], 4, 4, 8, 0, 1); + nnz[ scan8[16]+0 ] = nnz[ scan8[16]+1 ] =nnz[ scan8[16]+8 ] =nnz[ scan8[16]+9 ] = + nnz[ scan8[20]+0 ] = nnz[ scan8[20]+1 ] =nnz[ scan8[20]+8 ] =nnz[ scan8[20]+9 ] = 0; + } + s->current_picture.qscale_table[mb_xy]= s->qscale; + write_back_non_zero_count(h); + + if(MB_MBAFF){ + h->ref_count[0] >>= 1; + h->ref_count[1] >>= 1; + } + + return 0; +} + diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_direct.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_direct.c new file mode 100644 index 0000000000..d22780d925 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_direct.c @@ -0,0 +1,590 @@ +/* + * H.26L/H.264/AVC/JVT/14496-10/... direct mb/block decoding + * Copyright (c) 2003 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 + */ + +/** + * @file + * H.264 / AVC / MPEG4 part10 direct mb/block decoding. + * @author Michael Niedermayer + */ + +#include "internal.h" +#include "dsputil.h" +#include "avcodec.h" +#include "mpegvideo.h" +#include "h264.h" +#include "rectangle.h" + +//#undef NDEBUG +#include + + +static int get_scale_factor(H264Context * const h, int poc, int poc1, int i){ + int poc0 = h->ref_list[0][i].poc; + int td = av_clip(poc1 - poc0, -128, 127); + if(td == 0 || h->ref_list[0][i].long_ref){ + return 256; + }else{ + int tb = av_clip(poc - poc0, -128, 127); + int tx = (16384 + (FFABS(td) >> 1)) / td; + return av_clip((tb*tx + 32) >> 6, -1024, 1023); + } +} + +void ff_h264_direct_dist_scale_factor(H264Context * const h){ + MpegEncContext * const s = &h->s; + const int poc = h->s.current_picture_ptr->field_poc[ s->picture_structure == PICT_BOTTOM_FIELD ]; + const int poc1 = h->ref_list[1][0].poc; + int i, field; + for(field=0; field<2; field++){ + const int poc = h->s.current_picture_ptr->field_poc[field]; + const int poc1 = h->ref_list[1][0].field_poc[field]; + for(i=0; i < 2*h->ref_count[0]; i++) + h->dist_scale_factor_field[field][i^field] = get_scale_factor(h, poc, poc1, i+16); + } + + for(i=0; iref_count[0]; i++){ + h->dist_scale_factor[i] = get_scale_factor(h, poc, poc1, i); + } +} + +static void fill_colmap(H264Context *h, int map[2][16+32], int list, int field, int colfield, int mbafi){ + MpegEncContext * const s = &h->s; + Picture * const ref1 = &h->ref_list[1][0]; + int j, old_ref, rfield; + int start= mbafi ? 16 : 0; + int end = mbafi ? 16+2*h->ref_count[0] : h->ref_count[0]; + int interl= mbafi || s->picture_structure != PICT_FRAME; + + /* bogus; fills in for missing frames */ + memset(map[list], 0, sizeof(map[list])); + + for(rfield=0; rfield<2; rfield++){ + for(old_ref=0; old_refref_count[colfield][list]; old_ref++){ + int poc = ref1->ref_poc[colfield][list][old_ref]; + + if (!interl) + poc |= 3; + else if( interl && (poc&3) == 3) //FIXME store all MBAFF references so this isnt needed + poc= (poc&~3) + rfield + 1; + + for(j=start; jref_list[0][j].frame_num + (h->ref_list[0][j].reference&3) == poc){ + int cur_ref= mbafi ? (j-16)^field : j; + map[list][2*old_ref + (rfield^field) + 16] = cur_ref; + if(rfield == field || !interl) + map[list][old_ref] = cur_ref; + break; + } + } + } + } +} + +void ff_h264_direct_ref_list_init(H264Context * const h){ + MpegEncContext * const s = &h->s; + Picture * const ref1 = &h->ref_list[1][0]; + Picture * const cur = s->current_picture_ptr; + int list, j, field; + int sidx= (s->picture_structure&1)^1; + int ref1sidx= (ref1->reference&1)^1; + + for(list=0; list<2; list++){ + cur->ref_count[sidx][list] = h->ref_count[list]; + for(j=0; jref_count[list]; j++) + cur->ref_poc[sidx][list][j] = 4*h->ref_list[list][j].frame_num + (h->ref_list[list][j].reference&3); + } + + if(s->picture_structure == PICT_FRAME){ + memcpy(cur->ref_count[1], cur->ref_count[0], sizeof(cur->ref_count[0])); + memcpy(cur->ref_poc [1], cur->ref_poc [0], sizeof(cur->ref_poc [0])); + } + + cur->mbaff= FRAME_MBAFF; + + h->col_fieldoff= 0; + if(s->picture_structure == PICT_FRAME){ + int cur_poc = s->current_picture_ptr->poc; + 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= s->mb_stride*(2*(h->ref_list[1][0].reference) - 3); + } + + if(cur->pict_type != FF_B_TYPE || h->direct_spatial_mv_pred) + return; + + for(list=0; list<2; list++){ + fill_colmap(h, h->map_col_to_list0, list, sidx, ref1sidx, 0); + if(FRAME_MBAFF) + for(field=0; field<2; field++) + fill_colmap(h, h->map_col_to_list0_field[field], list, field, field, 1); + } +} + +static void pred_spatial_direct_motion(H264Context * const h, int *mb_type){ + MpegEncContext * const s = &h->s; + int b8_stride = 2; + int b4_stride = h->b_stride; + int mb_xy = h->mb_xy; + int mb_type_col[2]; + const int16_t (*l1mv0)[2], (*l1mv1)[2]; + const int8_t *l1ref0, *l1ref1; + const int is_b8x8 = IS_8X8(*mb_type); + unsigned int sub_mb_type= MB_TYPE_L0L1; + int i8, i4; + int ref[2]; + int mv[2]; + int list; + + assert(h->ref_list[1][0].reference&3); + +#define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16|MB_TYPE_INTRA4x4|MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM) + + + /* ref = min(neighbors) */ + for(list=0; list<2; list++){ + int left_ref = h->ref_cache[list][scan8[0] - 1]; + int top_ref = h->ref_cache[list][scan8[0] - 8]; + int refc = h->ref_cache[list][scan8[0] - 8 + 4]; + const int16_t *C= h->mv_cache[list][ scan8[0] - 8 + 4]; + if(refc == PART_NOT_AVAILABLE){ + refc = h->ref_cache[list][scan8[0] - 8 - 1]; + C = h-> mv_cache[list][scan8[0] - 8 - 1]; + } + ref[list] = FFMIN3((unsigned)left_ref, (unsigned)top_ref, (unsigned)refc); + if(ref[list] >= 0){ + //this is just pred_motion() but with the cases removed that cannot happen for direct blocks + const int16_t * const A= h->mv_cache[list][ scan8[0] - 1 ]; + const int16_t * const B= h->mv_cache[list][ scan8[0] - 8 ]; + + int match_count= (left_ref==ref[list]) + (top_ref==ref[list]) + (refc==ref[list]); + if(match_count > 1){ //most common + mv[list]= pack16to32(mid_pred(A[0], B[0], C[0]), + mid_pred(A[1], B[1], C[1]) ); + }else { + assert(match_count==1); + if(left_ref==ref[list]){ + mv[list]= AV_RN32A(A); + }else if(top_ref==ref[list]){ + mv[list]= AV_RN32A(B); + }else{ + mv[list]= AV_RN32A(C); + } + } + }else{ + int mask= ~(MB_TYPE_L0 << (2*list)); + mv[list] = 0; + ref[list] = -1; + if(!is_b8x8) + *mb_type &= mask; + sub_mb_type &= mask; + } + } + if(ref[0] < 0 && ref[1] < 0){ + ref[0] = ref[1] = 0; + if(!is_b8x8) + *mb_type |= MB_TYPE_L0L1; + sub_mb_type |= MB_TYPE_L0L1; + } + + if(!(is_b8x8|mv[0]|mv[1])){ + fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1); + fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1); + fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, 0, 4); + fill_rectangle(&h->mv_cache[1][scan8[0]], 4, 4, 8, 0, 4); + *mb_type= (*mb_type & ~(MB_TYPE_8x8|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_P1L0|MB_TYPE_P1L1))|MB_TYPE_16x16|MB_TYPE_DIRECT2; + 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 + mb_xy= s->mb_x + ((s->mb_y&~1) + h->col_parity)*s->mb_stride; + b8_stride = 0; + }else{ + mb_xy += h->col_fieldoff; // non zero for FL -> FL & differ parity + } + goto single_col; + }else{ // AFL/AFR/FR/FL -> AFR/FR + if(IS_INTERLACED(*mb_type)){ // AFL /FL -> AFR/FR + 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]; + b8_stride = 2+4*s->mb_stride; + b4_stride *= 6; + + sub_mb_type |= MB_TYPE_16x16|MB_TYPE_DIRECT2; /* B_SUB_8x8 */ + if( (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA) + && (mb_type_col[1] & MB_TYPE_16x16_OR_INTRA) + && !is_b8x8){ + *mb_type |= MB_TYPE_16x8 |MB_TYPE_DIRECT2; /* B_16x8 */ + }else{ + *mb_type |= MB_TYPE_8x8; + } + }else{ // AFR/FR -> AFR/FR +single_col: + mb_type_col[0] = + mb_type_col[1] = h->ref_list[1][0].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)){ + *mb_type |= MB_TYPE_16x16|MB_TYPE_DIRECT2; /* B_16x16 */ + }else if(!is_b8x8 && (mb_type_col[0] & (MB_TYPE_16x8|MB_TYPE_8x16))){ + *mb_type |= MB_TYPE_DIRECT2 | (mb_type_col[0] & (MB_TYPE_16x8|MB_TYPE_8x16)); + }else{ + if(!h->sps.direct_8x8_inference_flag){ + /* FIXME save sub mb types from previous frames (or derive from MVs) + * so we know exactly what block size to use */ + sub_mb_type += (MB_TYPE_8x8-MB_TYPE_16x16); /* B_SUB_4x4 */ + } + *mb_type |= MB_TYPE_8x8; + } + } + } + + 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]; + if(!b8_stride){ + if(s->mb_y&1){ + l1ref0 += 2; + l1ref1 += 2; + l1mv0 += 2*b4_stride; + l1mv1 += 2*b4_stride; + } + } + + + if(IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])){ + int n=0; + for(i8=0; i8<4; i8++){ + int x8 = i8&1; + int y8 = i8>>1; + int xy8 = x8+y8*b8_stride; + int xy4 = 3*x8+y8*b4_stride; + int a,b; + + if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8])) + continue; + h->sub_mb_type[i8] = sub_mb_type; + + fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[0], 1); + fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[1], 1); + if(!IS_INTRA(mb_type_col[y8]) && !h->ref_list[1][0].long_ref + && ( (l1ref0[xy8] == 0 && FFABS(l1mv0[xy4][0]) <= 1 && FFABS(l1mv0[xy4][1]) <= 1) + || (l1ref0[xy8] < 0 && l1ref1[xy8] == 0 && FFABS(l1mv1[xy4][0]) <= 1 && FFABS(l1mv1[xy4][1]) <= 1))){ + a=b=0; + if(ref[0] > 0) + a= mv[0]; + if(ref[1] > 0) + b= mv[1]; + n++; + }else{ + a= mv[0]; + b= mv[1]; + } + fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, a, 4); + fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, b, 4); + } + if(!is_b8x8 && !(n&3)) + *mb_type= (*mb_type & ~(MB_TYPE_8x8|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_P1L0|MB_TYPE_P1L1))|MB_TYPE_16x16|MB_TYPE_DIRECT2; + }else if(IS_16X16(*mb_type)){ + int a,b; + + fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1); + fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1); + if(!IS_INTRA(mb_type_col[0]) && !h->ref_list[1][0].long_ref + && ( (l1ref0[0] == 0 && FFABS(l1mv0[0][0]) <= 1 && FFABS(l1mv0[0][1]) <= 1) + || (l1ref0[0] < 0 && l1ref1[0] == 0 && FFABS(l1mv1[0][0]) <= 1 && FFABS(l1mv1[0][1]) <= 1 + && h->x264_build>33U))){ + a=b=0; + if(ref[0] > 0) + a= mv[0]; + if(ref[1] > 0) + b= mv[1]; + }else{ + a= mv[0]; + b= mv[1]; + } + fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, a, 4); + fill_rectangle(&h->mv_cache[1][scan8[0]], 4, 4, 8, b, 4); + }else{ + int n=0; + for(i8=0; i8<4; i8++){ + const int x8 = i8&1; + const int y8 = i8>>1; + + if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8])) + continue; + h->sub_mb_type[i8] = sub_mb_type; + + fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, mv[0], 4); + fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, mv[1], 4); + fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[0], 1); + fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[1], 1); + + assert(b8_stride==2); + /* col_zero_flag */ + if(!IS_INTRA(mb_type_col[0]) && !h->ref_list[1][0].long_ref && ( l1ref0[i8] == 0 + || (l1ref0[i8] < 0 && l1ref1[i8] == 0 + && h->x264_build>33U))){ + const int16_t (*l1mv)[2]= l1ref0[i8] == 0 ? l1mv0 : l1mv1; + if(IS_SUB_8X8(sub_mb_type)){ + const int16_t *mv_col = l1mv[x8*3 + y8*3*b4_stride]; + if(FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1){ + if(ref[0] == 0) + fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4); + if(ref[1] == 0) + fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4); + n+=4; + } + }else{ + int m=0; + for(i4=0; i4<4; i4++){ + const int16_t *mv_col = l1mv[x8*2 + (i4&1) + (y8*2 + (i4>>1))*b4_stride]; + if(FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1){ + if(ref[0] == 0) + AV_ZERO32(h->mv_cache[0][scan8[i8*4+i4]]); + if(ref[1] == 0) + AV_ZERO32(h->mv_cache[1][scan8[i8*4+i4]]); + m++; + } + } + if(!(m&3)) + h->sub_mb_type[i8]+= MB_TYPE_16x16 - MB_TYPE_8x8; + n+=m; + } + } + } + if(!is_b8x8 && !(n&15)) + *mb_type= (*mb_type & ~(MB_TYPE_8x8|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_P1L0|MB_TYPE_P1L1))|MB_TYPE_16x16|MB_TYPE_DIRECT2; + } +} + +static void pred_temp_direct_motion(H264Context * const h, int *mb_type){ + MpegEncContext * const s = &h->s; + int b8_stride = 2; + int b4_stride = h->b_stride; + int mb_xy = h->mb_xy; + int mb_type_col[2]; + const int16_t (*l1mv0)[2], (*l1mv1)[2]; + const int8_t *l1ref0, *l1ref1; + const int is_b8x8 = IS_8X8(*mb_type); + unsigned int sub_mb_type; + int i8, i4; + + assert(h->ref_list[1][0].reference&3); + + 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 + mb_xy= s->mb_x + ((s->mb_y&~1) + h->col_parity)*s->mb_stride; + b8_stride = 0; + }else{ + mb_xy += h->col_fieldoff; // non zero for FL -> FL & differ parity + } + goto single_col; + }else{ // AFL/AFR/FR/FL -> AFR/FR + if(IS_INTERLACED(*mb_type)){ // AFL /FL -> AFR/FR + 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]; + b8_stride = 2+4*s->mb_stride; + b4_stride *= 6; + + sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */ + + if( (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA) + && (mb_type_col[1] & MB_TYPE_16x16_OR_INTRA) + && !is_b8x8){ + *mb_type |= MB_TYPE_16x8 |MB_TYPE_L0L1|MB_TYPE_DIRECT2; /* B_16x8 */ + }else{ + *mb_type |= MB_TYPE_8x8|MB_TYPE_L0L1; + } + }else{ // AFR/FR -> AFR/FR +single_col: + mb_type_col[0] = + mb_type_col[1] = h->ref_list[1][0].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)){ + *mb_type |= MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_16x16 */ + }else if(!is_b8x8 && (mb_type_col[0] & (MB_TYPE_16x8|MB_TYPE_8x16))){ + *mb_type |= MB_TYPE_L0L1|MB_TYPE_DIRECT2 | (mb_type_col[0] & (MB_TYPE_16x8|MB_TYPE_8x16)); + }else{ + if(!h->sps.direct_8x8_inference_flag){ + /* FIXME save sub mb types from previous frames (or derive from MVs) + * so we know exactly what block size to use */ + sub_mb_type = MB_TYPE_8x8|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_4x4 */ + } + *mb_type |= MB_TYPE_8x8|MB_TYPE_L0L1; + } + } + } + + 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]; + if(!b8_stride){ + if(s->mb_y&1){ + l1ref0 += 2; + l1ref1 += 2; + l1mv0 += 2*b4_stride; + l1mv1 += 2*b4_stride; + } + } + + { + const int *map_col_to_list0[2] = {h->map_col_to_list0[0], h->map_col_to_list0[1]}; + const int *dist_scale_factor = h->dist_scale_factor; + int ref_offset; + + if(FRAME_MBAFF && IS_INTERLACED(*mb_type)){ + map_col_to_list0[0] = h->map_col_to_list0_field[s->mb_y&1][0]; + map_col_to_list0[1] = h->map_col_to_list0_field[s->mb_y&1][1]; + dist_scale_factor =h->dist_scale_factor_field[s->mb_y&1]; + } + ref_offset = (h->ref_list[1][0].mbaff<<4) & (mb_type_col[0]>>3); //if(h->ref_list[1][0].mbaff && IS_INTERLACED(mb_type_col[0])) ref_offset=16 else 0 + + if(IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])){ + int y_shift = 2*!IS_INTERLACED(*mb_type); + assert(h->sps.direct_8x8_inference_flag); + + for(i8=0; i8<4; i8++){ + const int x8 = i8&1; + const int y8 = i8>>1; + int ref0, scale; + const int16_t (*l1mv)[2]= l1mv0; + + if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8])) + continue; + h->sub_mb_type[i8] = sub_mb_type; + + fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, 0, 1); + if(IS_INTRA(mb_type_col[y8])){ + fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, 0, 1); + fill_rectangle(&h-> mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4); + fill_rectangle(&h-> mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4); + continue; + } + + ref0 = l1ref0[x8 + y8*b8_stride]; + if(ref0 >= 0) + ref0 = map_col_to_list0[0][ref0 + ref_offset]; + else{ + ref0 = map_col_to_list0[1][l1ref1[x8 + y8*b8_stride] + ref_offset]; + l1mv= l1mv1; + } + scale = dist_scale_factor[ref0]; + fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, ref0, 1); + + { + const int16_t *mv_col = l1mv[x8*3 + y8*b4_stride]; + int my_col = (mv_col[1]<> 8; + int my = (scale * my_col + 128) >> 8; + fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, pack16to32(mx,my), 4); + fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, pack16to32(mx-mv_col[0],my-my_col), 4); + } + } + return; + } + + /* one-to-one mv scaling */ + + if(IS_16X16(*mb_type)){ + int ref, mv0, mv1; + + fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, 0, 1); + if(IS_INTRA(mb_type_col[0])){ + ref=mv0=mv1=0; + }else{ + const int ref0 = l1ref0[0] >= 0 ? map_col_to_list0[0][l1ref0[0] + ref_offset] + : map_col_to_list0[1][l1ref1[0] + ref_offset]; + const int scale = dist_scale_factor[ref0]; + const int16_t *mv_col = l1ref0[0] >= 0 ? l1mv0[0] : l1mv1[0]; + int mv_l0[2]; + mv_l0[0] = (scale * mv_col[0] + 128) >> 8; + mv_l0[1] = (scale * mv_col[1] + 128) >> 8; + ref= ref0; + mv0= pack16to32(mv_l0[0],mv_l0[1]); + mv1= pack16to32(mv_l0[0]-mv_col[0],mv_l0[1]-mv_col[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, mv0, 4); + fill_rectangle(&h-> mv_cache[1][scan8[0]], 4, 4, 8, mv1, 4); + }else{ + for(i8=0; i8<4; i8++){ + const int x8 = i8&1; + const int y8 = i8>>1; + int ref0, scale; + const int16_t (*l1mv)[2]= l1mv0; + + if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8])) + continue; + h->sub_mb_type[i8] = sub_mb_type; + fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, 0, 1); + if(IS_INTRA(mb_type_col[0])){ + fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, 0, 1); + fill_rectangle(&h-> mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4); + fill_rectangle(&h-> mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4); + continue; + } + + assert(b8_stride == 2); + ref0 = l1ref0[i8]; + if(ref0 >= 0) + ref0 = map_col_to_list0[0][ref0 + ref_offset]; + else{ + ref0 = map_col_to_list0[1][l1ref1[i8] + ref_offset]; + l1mv= l1mv1; + } + scale = dist_scale_factor[ref0]; + + fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, ref0, 1); + if(IS_SUB_8X8(sub_mb_type)){ + const int16_t *mv_col = l1mv[x8*3 + y8*3*b4_stride]; + int mx = (scale * mv_col[0] + 128) >> 8; + int my = (scale * mv_col[1] + 128) >> 8; + fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, pack16to32(mx,my), 4); + fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, pack16to32(mx-mv_col[0],my-mv_col[1]), 4); + }else + for(i4=0; i4<4; i4++){ + const int16_t *mv_col = l1mv[x8*2 + (i4&1) + (y8*2 + (i4>>1))*b4_stride]; + int16_t *mv_l0 = h->mv_cache[0][scan8[i8*4+i4]]; + mv_l0[0] = (scale * mv_col[0] + 128) >> 8; + mv_l0[1] = (scale * mv_col[1] + 128) >> 8; + AV_WN32A(h->mv_cache[1][scan8[i8*4+i4]], + pack16to32(mv_l0[0]-mv_col[0],mv_l0[1]-mv_col[1])); + } + } + } + } +} + +void ff_h264_pred_direct_motion(H264Context * const h, int *mb_type){ + if(h->direct_spatial_mv_pred){ + pred_spatial_direct_motion(h, mb_type); + }else{ + pred_temp_direct_motion(h, mb_type); + } +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_loopfilter.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_loopfilter.c new file mode 100644 index 0000000000..710e03706e --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_loopfilter.c @@ -0,0 +1,752 @@ +/* + * H.26L/H.264/AVC/JVT/14496-10/... loop filter + * Copyright (c) 2003 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 + */ + +/** + * @file + * H.264 / AVC / MPEG4 part10 loop filter. + * @author Michael Niedermayer + */ + +#include "libavutil/intreadwrite.h" +#include "internal.h" +#include "dsputil.h" +#include "avcodec.h" +#include "mpegvideo.h" +#include "h264.h" +#include "mathops.h" +#include "rectangle.h" + +//#undef NDEBUG +#include + +/* Deblocking filter (p153) */ +static const uint8_t alpha_table[52*3] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 4, 4, 5, 6, + 7, 8, 9, 10, 12, 13, 15, 17, 20, 22, + 25, 28, 32, 36, 40, 45, 50, 56, 63, 71, + 80, 90,101,113,127,144,162,182,203,226, + 255,255, + 255,255,255,255,255,255,255,255,255,255,255,255,255, + 255,255,255,255,255,255,255,255,255,255,255,255,255, + 255,255,255,255,255,255,255,255,255,255,255,255,255, + 255,255,255,255,255,255,255,255,255,255,255,255,255, +}; +static const uint8_t beta_table[52*3] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 2, 2, 2, 3, + 3, 3, 3, 4, 4, 4, 6, 6, 7, 7, + 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, + 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, + 18, 18, + 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, + 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, + 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, + 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, +}; +static const uint8_t tc0_table[52*3][4] = { + {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, + {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, + {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, + {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, + {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, + {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, + {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, + {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, + {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, + {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, + {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, + {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 1 }, + {-1, 0, 0, 1 }, {-1, 0, 0, 1 }, {-1, 0, 0, 1 }, {-1, 0, 1, 1 }, {-1, 0, 1, 1 }, {-1, 1, 1, 1 }, + {-1, 1, 1, 1 }, {-1, 1, 1, 1 }, {-1, 1, 1, 1 }, {-1, 1, 1, 2 }, {-1, 1, 1, 2 }, {-1, 1, 1, 2 }, + {-1, 1, 1, 2 }, {-1, 1, 2, 3 }, {-1, 1, 2, 3 }, {-1, 2, 2, 3 }, {-1, 2, 2, 4 }, {-1, 2, 3, 4 }, + {-1, 2, 3, 4 }, {-1, 3, 3, 5 }, {-1, 3, 4, 6 }, {-1, 3, 4, 6 }, {-1, 4, 5, 7 }, {-1, 4, 5, 8 }, + {-1, 4, 6, 9 }, {-1, 5, 7,10 }, {-1, 6, 8,11 }, {-1, 6, 8,13 }, {-1, 7,10,14 }, {-1, 8,11,16 }, + {-1, 9,12,18 }, {-1,10,13,20 }, {-1,11,15,23 }, {-1,13,17,25 }, + {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, + {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, + {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, + {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, + {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, + {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, + {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, + {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, + {-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 unsigned int index_a = qp + h->slice_alpha_c0_offset; + const int alpha = alpha_table[index_a]; + const int beta = beta_table[qp + h->slice_beta_offset]; + if (alpha ==0 || beta == 0) return; + + if( bS[0] < 4 ) { + int8_t tc[4]; + tc[0] = tc0_table[index_a][bS[0]]; + tc[1] = tc0_table[index_a][bS[1]]; + tc[2] = tc0_table[index_a][bS[2]]; + tc[3] = tc0_table[index_a][bS[3]]; + h->h264dsp.h264_h_loop_filter_luma(pix, stride, alpha, beta, tc); + } else { + 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 unsigned int index_a = qp + h->slice_alpha_c0_offset; + const int alpha = alpha_table[index_a]; + const int beta = beta_table[qp + h->slice_beta_offset]; + if (alpha ==0 || beta == 0) return; + + if( bS[0] < 4 ) { + int8_t tc[4]; + tc[0] = tc0_table[index_a][bS[0]]+1; + tc[1] = tc0_table[index_a][bS[1]]+1; + tc[2] = tc0_table[index_a][bS[2]]+1; + tc[3] = tc0_table[index_a][bS[3]]+1; + h->h264dsp.h264_h_loop_filter_chroma(pix, stride, alpha, beta, tc); + } else { + h->h264dsp.h264_h_loop_filter_chroma_intra(pix, stride, alpha, beta); + } +} + +static void filter_mb_mbaff_edgev( H264Context *h, uint8_t *pix, int stride, int16_t bS[4], int bsi, int qp ) { + int i; + int index_a = qp + h->slice_alpha_c0_offset; + int alpha = alpha_table[index_a]; + int beta = beta_table[qp + h->slice_beta_offset]; + for( i = 0; i < 8; i++, pix += stride) { + const int bS_index = (i >> 1) * bsi; + + if( bS[bS_index] == 0 ) { + continue; + } + + if( bS[bS_index] < 4 ) { + const int tc0 = tc0_table[index_a][bS[bS_index]]; + const int p0 = pix[-1]; + const int p1 = pix[-2]; + const int p2 = pix[-3]; + const int q0 = pix[0]; + const int q1 = pix[1]; + const int q2 = pix[2]; + + if( FFABS( p0 - q0 ) < alpha && + FFABS( p1 - p0 ) < beta && + FFABS( q1 - q0 ) < beta ) { + int tc = tc0; + int i_delta; + + if( FFABS( p2 - p0 ) < beta ) { + if(tc0) + pix[-2] = p1 + av_clip( ( p2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( p1 << 1 ) ) >> 1, -tc0, tc0 ); + tc++; + } + if( FFABS( q2 - q0 ) < beta ) { + if(tc0) + pix[1] = q1 + av_clip( ( q2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( q1 << 1 ) ) >> 1, -tc0, tc0 ); + tc++; + } + + i_delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); + pix[-1] = av_clip_uint8( p0 + i_delta ); /* p0' */ + pix[0] = av_clip_uint8( q0 - i_delta ); /* q0' */ + tprintf(h->s.avctx, "filter_mb_mbaff_edgev i:%d, qp:%d, indexA:%d, alpha:%d, beta:%d, tc:%d\n# bS:%d -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x]\n", i, qp[qp_index], index_a, alpha, beta, tc, bS[bS_index], pix[-3], p1, p0, q0, q1, pix[2], p1, pix[-1], pix[0], q1); + } + }else{ + const int p0 = pix[-1]; + const int p1 = pix[-2]; + const int p2 = pix[-3]; + + const int q0 = pix[0]; + const int q1 = pix[1]; + const int q2 = pix[2]; + + if( FFABS( p0 - q0 ) < alpha && + FFABS( p1 - p0 ) < beta && + FFABS( q1 - q0 ) < beta ) { + + if(FFABS( p0 - q0 ) < (( alpha >> 2 ) + 2 )){ + if( FFABS( p2 - p0 ) < beta) + { + const int p3 = pix[-4]; + /* p0', p1', p2' */ + pix[-1] = ( p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4 ) >> 3; + pix[-2] = ( p2 + p1 + p0 + q0 + 2 ) >> 2; + pix[-3] = ( 2*p3 + 3*p2 + p1 + p0 + q0 + 4 ) >> 3; + } else { + /* p0' */ + pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; + } + if( FFABS( q2 - q0 ) < beta) + { + const int q3 = pix[3]; + /* q0', q1', q2' */ + pix[0] = ( p1 + 2*p0 + 2*q0 + 2*q1 + q2 + 4 ) >> 3; + pix[1] = ( p0 + q0 + q1 + q2 + 2 ) >> 2; + pix[2] = ( 2*q3 + 3*q2 + q1 + q0 + p0 + 4 ) >> 3; + } else { + /* q0' */ + pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; + } + }else{ + /* p0', q0' */ + pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; + pix[ 0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; + } + tprintf(h->s.avctx, "filter_mb_mbaff_edgev i:%d, qp:%d, indexA:%d, alpha:%d, beta:%d\n# bS:4 -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x, %02x, %02x]\n", i, qp[qp_index], index_a, alpha, beta, p2, p1, p0, q0, q1, q2, pix[-3], pix[-2], pix[-1], pix[0], pix[1], pix[2]); + } + } + } +} +static void filter_mb_mbaff_edgecv( H264Context *h, uint8_t *pix, int stride, int16_t bS[4], int bsi, int qp ) { + int i; + int index_a = qp + h->slice_alpha_c0_offset; + int alpha = alpha_table[index_a]; + int beta = beta_table[qp + h->slice_beta_offset]; + for( i = 0; i < 4; i++, pix += stride) { + const int bS_index = i*bsi; + + if( bS[bS_index] == 0 ) { + continue; + } + + if( bS[bS_index] < 4 ) { + const int tc = tc0_table[index_a][bS[bS_index]] + 1; + const int p0 = pix[-1]; + const int p1 = pix[-2]; + const int q0 = pix[0]; + const int q1 = pix[1]; + + if( FFABS( p0 - q0 ) < alpha && + FFABS( p1 - p0 ) < beta && + FFABS( q1 - q0 ) < beta ) { + const int i_delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); + + pix[-1] = av_clip_uint8( p0 + i_delta ); /* p0' */ + pix[0] = av_clip_uint8( q0 - i_delta ); /* q0' */ + tprintf(h->s.avctx, "filter_mb_mbaff_edgecv i:%d, qp:%d, indexA:%d, alpha:%d, beta:%d, tc:%d\n# bS:%d -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x]\n", i, qp[qp_index], index_a, alpha, beta, tc, bS[bS_index], pix[-3], p1, p0, q0, q1, pix[2], p1, pix[-1], pix[0], q1); + } + }else{ + const int p0 = pix[-1]; + const int p1 = pix[-2]; + const int q0 = pix[0]; + const int q1 = pix[1]; + + if( FFABS( p0 - q0 ) < alpha && + FFABS( p1 - p0 ) < beta && + FFABS( q1 - q0 ) < beta ) { + + pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; /* p0' */ + pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; /* q0' */ + tprintf(h->s.avctx, "filter_mb_mbaff_edgecv i:%d\n# bS:4 -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x, %02x, %02x]\n", i, pix[-3], p1, p0, q0, q1, pix[2], pix[-3], pix[-2], pix[-1], pix[0], pix[1], pix[2]); + } + } + } +} + +static void av_always_inline filter_mb_edgeh( uint8_t *pix, int stride, int16_t bS[4], unsigned int qp, H264Context *h ) { + const unsigned int index_a = qp + h->slice_alpha_c0_offset; + const int alpha = alpha_table[index_a]; + const int beta = beta_table[qp + h->slice_beta_offset]; + if (alpha ==0 || beta == 0) return; + + if( bS[0] < 4 ) { + int8_t tc[4]; + tc[0] = tc0_table[index_a][bS[0]]; + tc[1] = tc0_table[index_a][bS[1]]; + tc[2] = tc0_table[index_a][bS[2]]; + tc[3] = tc0_table[index_a][bS[3]]; + h->h264dsp.h264_v_loop_filter_luma(pix, stride, alpha, beta, tc); + } else { + h->h264dsp.h264_v_loop_filter_luma_intra(pix, stride, alpha, beta); + } +} + +static void av_always_inline filter_mb_edgech( uint8_t *pix, int stride, int16_t bS[4], unsigned int qp, H264Context *h ) { + const unsigned int index_a = qp + h->slice_alpha_c0_offset; + const int alpha = alpha_table[index_a]; + const int beta = beta_table[qp + h->slice_beta_offset]; + if (alpha ==0 || beta == 0) return; + + if( bS[0] < 4 ) { + int8_t tc[4]; + tc[0] = tc0_table[index_a][bS[0]]+1; + tc[1] = tc0_table[index_a][bS[1]]+1; + tc[2] = tc0_table[index_a][bS[2]]+1; + tc[3] = tc0_table[index_a][bS[3]]+1; + h->h264dsp.h264_v_loop_filter_chroma(pix, stride, alpha, beta, tc); + } else { + h->h264dsp.h264_v_loop_filter_chroma_intra(pix, stride, alpha, beta); + } +} + +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) { + MpegEncContext * const s = &h->s; + int mb_xy; + int mb_type, left_type; + int qp, qp0, qp1, qpc, qpc0, qpc1, qp_thresh; + + mb_xy = h->mb_xy; + + if(!h->top_type || !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[0]; + + 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 ); + 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; + if(left_type) + filter_mb_edgev( &img_y[4*0], linesize, bS4, qp0, h); + if( IS_8x8DCT(mb_type) ) { + filter_mb_edgev( &img_y[4*2], linesize, bS3, qp, h); + filter_mb_edgeh( &img_y[4*0*linesize], linesize, bSH, qp1, h); + filter_mb_edgeh( &img_y[4*2*linesize], linesize, bS3, qp, h); + } 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_edgeh( &img_y[4*0*linesize], linesize, bSH, qp1, h); + 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); + } + 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*2], uvlinesize, bS3, qpc, h); + filter_mb_edgecv( &img_cr[2*2], uvlinesize, bS3, qpc, h); + filter_mb_edgech( &img_cb[2*0*uvlinesize], uvlinesize, bSH, qpc1, h); + filter_mb_edgech( &img_cb[2*2*uvlinesize], uvlinesize, bS3, qpc, h); + filter_mb_edgech( &img_cr[2*0*uvlinesize], uvlinesize, bSH, qpc1, h); + filter_mb_edgech( &img_cr[2*2*uvlinesize], uvlinesize, bS3, qpc, h); + return; + } else { + LOCAL_ALIGNED_8(int16_t, bS, [2], [4][4]); + int edges; + if( IS_8x8DCT(mb_type) && (h->cbp&7) == 7 ) { + edges = 4; + AV_WN64A(bS[0][0], 0x0002000200020002ULL); + AV_WN64A(bS[0][2], 0x0002000200020002ULL); + AV_WN64A(bS[1][0], 0x0002000200020002ULL); + AV_WN64A(bS[1][2], 0x0002000200020002ULL); + } else { + int mask_edge1 = (3*(((5*mb_type)>>5)&1)) | (mb_type>>4); //(mb_type & (MB_TYPE_16x16 | MB_TYPE_8x16)) ? 3 : (mb_type & MB_TYPE_16x8) ? 1 : 0; + int mask_edge0 = 3*((mask_edge1>>1) & ((5*left_type)>>5)&1); // (mb_type & (MB_TYPE_16x16 | MB_TYPE_8x16)) && (h->left_type[0] & (MB_TYPE_16x16 | MB_TYPE_8x16)) ? 3 : 0; + int step = 1+(mb_type>>24); //IS_8x8DCT(mb_type) ? 2 : 1; + edges = 4 - 3*((mb_type>>3) & !(h->cbp & 15)); //(mb_type & MB_TYPE_16x16) && !(h->cbp & 15) ? 1 : 4; + h->h264dsp.h264_loop_filter_strength( bS, h->non_zero_count_cache, h->ref_cache, h->mv_cache, + h->list_count==2, edges, step, mask_edge0, mask_edge1, FIELD_PICTURE); + } + if( IS_INTRA(left_type) ) + AV_WN64A(bS[0][0], 0x0004000400040004ULL); + if( IS_INTRA(h->top_type) ) + AV_WN64A(bS[1][0], FIELD_PICTURE ? 0x0003000300030003ULL : 0x0004000400040004ULL); + +#define FILTER(hv,dir,edge)\ + 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 );\ + 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 );\ + }\ + } + if(left_type) + FILTER(v,0,0); + if( edges == 1 ) { + FILTER(h,1,0); + } else if( IS_8x8DCT(mb_type) ) { + FILTER(v,0,2); + FILTER(h,1,0); + FILTER(h,1,2); + } else { + FILTER(v,0,1); + FILTER(v,0,2); + FILTER(v,0,3); + FILTER(h,1,0); + FILTER(h,1,1); + FILTER(h,1,2); + FILTER(h,1,3); + } +#undef FILTER + } +} + +static int check_mv(H264Context *h, long b_idx, long bn_idx, int mvy_limit){ + int v; + + v= h->ref_cache[0][b_idx] != h->ref_cache[0][bn_idx]; + if(!v && h->ref_cache[0][b_idx]!=-1) + v= h->mv_cache[0][b_idx][0] - h->mv_cache[0][bn_idx][0] + 3 >= 7U | + FFABS( h->mv_cache[0][b_idx][1] - h->mv_cache[0][bn_idx][1] ) >= mvy_limit; + + if(h->list_count==2){ + if(!v) + v = h->ref_cache[1][b_idx] != h->ref_cache[1][bn_idx] | + h->mv_cache[1][b_idx][0] - h->mv_cache[1][bn_idx][0] + 3 >= 7U | + FFABS( h->mv_cache[1][b_idx][1] - h->mv_cache[1][bn_idx][1] ) >= mvy_limit; + + if(v){ + if(h->ref_cache[0][b_idx] != h->ref_cache[1][bn_idx] | + h->ref_cache[1][b_idx] != h->ref_cache[0][bn_idx]) + return 1; + return + h->mv_cache[0][b_idx][0] - h->mv_cache[1][bn_idx][0] + 3 >= 7U | + FFABS( h->mv_cache[0][b_idx][1] - h->mv_cache[1][bn_idx][1] ) >= mvy_limit | + h->mv_cache[1][b_idx][0] - h->mv_cache[0][bn_idx][0] + 3 >= 7U | + FFABS( h->mv_cache[1][b_idx][1] - h->mv_cache[0][bn_idx][1] ) >= 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 dir) { + MpegEncContext * const s = &h->s; + int edge; + const int mbm_xy = dir == 0 ? mb_xy -1 : h->top_mb_xy; + const int mbm_type = dir == 0 ? h->left_type[0] : h->top_type; + + // how often to recheck mv-based bS when iterating between edges + static const uint8_t mask_edge_tab[2][8]={{0,3,3,3,1,1,1,1}, + {0,3,1,1,3,3,3,3}}; + const int mask_edge = mask_edge_tab[dir][(mb_type>>3)&7]; + const int edges = mask_edge== 3 && !(h->cbp&15) ? 1 : 4; + + // how often to recheck mv-based bS when iterating along each edge + const int mask_par0 = mb_type & (MB_TYPE_16x16 | (MB_TYPE_8x16 >> dir)); + + if(mbm_type && !first_vertical_edge_done){ + + if (FRAME_MBAFF && (dir == 1) && ((mb_y&1) == 0) + && IS_INTERLACED(mbm_type&~mb_type) + ) { + // This is a special case in the norm where the filtering must + // be done twice (one each of the field) even if we are in a + // frame macroblock. + // + unsigned int tmp_linesize = 2 * linesize; + unsigned int tmp_uvlinesize = 2 * uvlinesize; + int mbn_xy = mb_xy - 2 * s->mb_stride; + int j; + + 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]) ) { + AV_WN64A(bS, 0x0003000300030003ULL); + } else { + if(!CABAC && IS_8x8DCT(s->current_picture.mb_type[mbn_xy])){ + bS[0]= 1+((h->cbp_table[mbn_xy] & 4)||h->non_zero_count_cache[scan8[0]+0]); + bS[1]= 1+((h->cbp_table[mbn_xy] & 4)||h->non_zero_count_cache[scan8[0]+1]); + bS[2]= 1+((h->cbp_table[mbn_xy] & 8)||h->non_zero_count_cache[scan8[0]+2]); + bS[3]= 1+((h->cbp_table[mbn_xy] & 8)||h->non_zero_count_cache[scan8[0]+3]); + }else{ + const uint8_t *mbn_nnz = h->non_zero_count[mbn_xy] + 4+3*8; + int i; + for( i = 0; i < 4; i++ ) { + bS[i] = 1 + !!(h->non_zero_count_cache[scan8[0]+i] | mbn_nnz[i]); + } + } + } + // 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; + 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 ); + filter_mb_edgech( &img_cb[j*uvlinesize], tmp_uvlinesize, bS, + ( h->chroma_qp[0] + get_chroma_qp( h, 0, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1, h); + filter_mb_edgech( &img_cr[j*uvlinesize], tmp_uvlinesize, bS, + ( h->chroma_qp[1] + get_chroma_qp( h, 1, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1, h); + } + }else{ + DECLARE_ALIGNED(8, int16_t, bS)[4]; + int qp; + + if( IS_INTRA(mb_type|mbm_type)) { + AV_WN64A(bS, 0x0003000300030003ULL); + if ( (!IS_INTERLACED(mb_type|mbm_type)) + || ((FRAME_MBAFF || (s->picture_structure != PICT_FRAME)) && (dir == 0)) + ) + AV_WN64A(bS, 0x0004000400040004ULL); + } else { + int i; + int mv_done; + + if( dir && FRAME_MBAFF && IS_INTERLACED(mb_type ^ mbm_type)) { + AV_WN64A(bS, 0x0001000100010001ULL); + mv_done = 1; + } + else if( mask_par0 && ((mbm_type & (MB_TYPE_16x16 | (MB_TYPE_8x16 >> dir)))) ) { + int b_idx= 8 + 4; + int bn_idx= b_idx - (dir ? 8:1); + + bS[0] = bS[1] = bS[2] = bS[3] = check_mv(h, 8 + 4, bn_idx, mvy_limit); + mv_done = 1; + } + else + mv_done = 0; + + for( i = 0; i < 4; i++ ) { + int x = dir == 0 ? 0 : i; + int y = dir == 0 ? i : 0; + int b_idx= 8 + 4 + x + 8*y; + int bn_idx= b_idx - (dir ? 8:1); + + if( h->non_zero_count_cache[b_idx] | + h->non_zero_count_cache[bn_idx] ) { + bS[i] = 2; + } + else if(!mv_done) + { + bS[i] = check_mv(h, b_idx, bn_idx, mvy_limit); + } + } + } + + /* Filter edge */ + // 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; + //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[0], linesize, bS, qp, h ); + { + int qp= ( h->chroma_qp[0] + get_chroma_qp( h, 0, s->current_picture.qscale_table[mbm_xy] ) + 1 ) >> 1; + filter_mb_edgecv( &img_cb[0], uvlinesize, bS, qp, h); + if(h->pps.chroma_qp_diff) + qp= ( h->chroma_qp[1] + get_chroma_qp( h, 1, s->current_picture.qscale_table[mbm_xy] ) + 1 ) >> 1; + filter_mb_edgecv( &img_cr[0], uvlinesize, bS, qp, h); + } + } else { + filter_mb_edgeh( &img_y[0], linesize, bS, qp, h ); + { + int qp= ( h->chroma_qp[0] + get_chroma_qp( h, 0, s->current_picture.qscale_table[mbm_xy] ) + 1 ) >> 1; + filter_mb_edgech( &img_cb[0], uvlinesize, bS, qp, h); + if(h->pps.chroma_qp_diff) + qp= ( h->chroma_qp[1] + get_chroma_qp( h, 1, s->current_picture.qscale_table[mbm_xy] ) + 1 ) >> 1; + filter_mb_edgech( &img_cr[0], uvlinesize, bS, qp, h); + } + } + } + } + } + + /* Calculate bS */ + for( edge = 1; edge < edges; edge++ ) { + DECLARE_ALIGNED(8, int16_t, bS)[4]; + int qp; + + if( IS_8x8DCT(mb_type & (edge<<24)) ) // (edge&1) && IS_8x8DCT(mb_type) + continue; + + if( IS_INTRA(mb_type)) { + AV_WN64A(bS, 0x0003000300030003ULL); + } else { + int i; + int mv_done; + + if( edge & mask_edge ) { + AV_ZERO64(bS); + mv_done = 1; + } + else if( mask_par0 ) { + int b_idx= 8 + 4 + edge * (dir ? 8:1); + int bn_idx= b_idx - (dir ? 8:1); + + bS[0] = bS[1] = bS[2] = bS[3] = check_mv(h, b_idx, bn_idx, mvy_limit); + mv_done = 1; + } + else + mv_done = 0; + + for( i = 0; i < 4; i++ ) { + int x = dir == 0 ? edge : i; + int y = dir == 0 ? i : edge; + int b_idx= 8 + 4 + x + 8*y; + int bn_idx= b_idx - (dir ? 8:1); + + if( h->non_zero_count_cache[b_idx] | + h->non_zero_count_cache[bn_idx] ) { + bS[i] = 2; + } + else if(!mv_done) + { + bS[i] = check_mv(h, b_idx, bn_idx, mvy_limit); + } + } + + if(bS[0]+bS[1]+bS[2]+bS[3] == 0) + continue; + } + + /* 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]; + //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], linesize, bS, qp, h ); + if( (edge&1) == 0 ) { + filter_mb_edgecv( &img_cb[2*edge], uvlinesize, bS, h->chroma_qp[0], h); + filter_mb_edgecv( &img_cr[2*edge], uvlinesize, bS, h->chroma_qp[1], h); + } + } else { + filter_mb_edgeh( &img_y[4*edge*linesize], linesize, bS, qp, h ); + 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); + } + } + } +} + +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 mvy_limit = IS_INTERLACED(mb_type) ? 2 : 4; + int first_vertical_edge_done = 0; + av_unused int dir; + + if (FRAME_MBAFF + // and current and left pair do not have the same interlaced type + && IS_INTERLACED(mb_type^h->left_type[0]) + // and left mb is in available to us + && h->left_type[0]) { + /* First vertical edge is different in MBAFF frames + * There are 8 different bS to compute and 2 different Qp + */ + DECLARE_ALIGNED(8, int16_t, bS)[8]; + int qp[2]; + int bqp[2]; + int rqp[2]; + int mb_qp, mbn0_qp, mbn1_qp; + int i; + first_vertical_edge_done = 1; + + if( IS_INTRA(mb_type) ) { + AV_WN64A(&bS[0], 0x0004000400040004ULL); + AV_WN64A(&bS[4], 0x0004000400040004ULL); + } else { + static const uint8_t offset[2][2][8]={ + { + {7+8*0, 7+8*0, 7+8*0, 7+8*0, 7+8*1, 7+8*1, 7+8*1, 7+8*1}, + {7+8*2, 7+8*2, 7+8*2, 7+8*2, 7+8*3, 7+8*3, 7+8*3, 7+8*3}, + },{ + {7+8*0, 7+8*1, 7+8*2, 7+8*3, 7+8*0, 7+8*1, 7+8*2, 7+8*3}, + {7+8*0, 7+8*1, 7+8*2, 7+8*3, 7+8*0, 7+8*1, 7+8*2, 7+8*3}, + } + }; + const uint8_t *off= offset[MB_FIELD][mb_y&1]; + for( i = 0; i < 8; i++ ) { + int j= MB_FIELD ? i>>2 : i&1; + int mbn_xy = h->left_mb_xy[j]; + int mbn_type= h->left_type[j]; + + if( IS_INTRA( mbn_type ) ) + bS[i] = 4; + else{ + bS[i] = 1 + !!(h->non_zero_count_cache[12+8*(i>>1)] | + ((!h->pps.cabac && IS_8x8DCT(mbn_type)) ? + (h->cbp_table[mbn_xy] & ((MB_FIELD ? (i&2) : (mb_y&1)) ? 8 : 2)) + : + h->non_zero_count[mbn_xy][ off[i] ])); + } + } + } + + 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]]; + 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; + rqp[0] = ( get_chroma_qp( h, 1, mb_qp ) + + get_chroma_qp( h, 1, mbn0_qp ) + 1 ) >> 1; + qp[1] = ( mb_qp + mbn1_qp + 1 ) >> 1; + bqp[1] = ( get_chroma_qp( h, 0, mb_qp ) + + get_chroma_qp( h, 0, mbn1_qp ) + 1 ) >> 1; + rqp[1] = ( get_chroma_qp( h, 1, mb_qp ) + + get_chroma_qp( h, 1, mbn1_qp ) + 1 ) >> 1; + + /* Filter edge */ + 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_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] ); + }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_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] ); + } + } + +#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, 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, 0); + filter_mb_dir(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, 0, 1); +#endif +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_mp4toannexb_bsf.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_mp4toannexb_bsf.c index 936418a8a0..0c92b36f65 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_mp4toannexb_bsf.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_mp4toannexb_bsf.c @@ -55,7 +55,9 @@ static int h264_mp4toannexb_filter(AVBitStreamFilterContext *bsfc, int keyframe) { H264BSFContext *ctx = bsfc->priv_data; uint8_t unit_type; - uint32_t nal_size, cumul_size = 0; + int32_t nal_size; + uint32_t cumul_size = 0; + const uint8_t *buf_end = buf + buf_size; /* nothing to filter */ if (!avctx->extradata || avctx->extradata_size < 6) { @@ -109,6 +111,9 @@ static int h264_mp4toannexb_filter(AVBitStreamFilterContext *bsfc, *poutbuf_size = 0; *poutbuf = NULL; do { + if (buf + ctx->length_size > buf_end) + goto fail; + if (ctx->length_size == 1) nal_size = buf[0]; else if (ctx->length_size == 2) @@ -119,6 +124,9 @@ static int h264_mp4toannexb_filter(AVBitStreamFilterContext *bsfc, buf += ctx->length_size; unit_type = *buf & 0x1f; + if (buf + nal_size > buf_end || nal_size < 0) + goto fail; + /* prepend only to the first type 5 NAL unit of an IDR picture */ if (ctx->first_idr && unit_type == 5) { alloc_and_copy(poutbuf, poutbuf_size, @@ -139,6 +147,11 @@ static int h264_mp4toannexb_filter(AVBitStreamFilterContext *bsfc, } while (cumul_size < buf_size); return 1; + +fail: + av_freep(poutbuf); + *poutbuf_size = 0; + return AVERROR(EINVAL); } static void h264_mp4toannexb_close(AVBitStreamFilterContext *bsfc) diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_mvpred.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_mvpred.h new file mode 100644 index 0000000000..661ef6c381 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_mvpred.h @@ -0,0 +1,236 @@ +/* + * H.26L/H.264/AVC/JVT/14496-10/... motion vector predicion + * Copyright (c) 2003 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 + */ + +/** + * @file + * H.264 / AVC / MPEG4 part10 motion vector predicion. + * @author Michael Niedermayer + */ + +#ifndef AVCODEC_H264_MVPRED_H +#define AVCODEC_H264_MVPRED_H + +#include "internal.h" +#include "avcodec.h" +#include "h264.h" + +//#undef NDEBUG +#include + +static 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; + + /* there is no consistent mapping of mvs to neighboring locations that will + * make mbaff happy, so we can't move all this logic to fill_caches */ + if(FRAME_MBAFF){ + +#define SET_DIAG_MV(MV_OP, REF_OP, XY, Y4)\ + const int xy = XY, y4 = Y4;\ + 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];\ + 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; + + 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 int16_t *mv; + AV_ZERO32(h->mv_cache[list][scan8[0]-2]); + *C = h->mv_cache[list][scan8[0]-2]; + + if(!MB_FIELD + && IS_INTERLACED(h->left_type[0])){ + SET_DIAG_MV(*2, >>1, h->left_mb_xy[0]+s->mb_stride, (s->mb_y&1)*2+(i>>5)); + assert(h->left_mb_xy[0] == h->left_mb_xy[1]); + } + if(MB_FIELD + && !IS_INTERLACED(h->left_type[0])){ + // left shift will turn LIST_NOT_USED into PART_NOT_AVAILABLE, but that's OK. + SET_DIAG_MV(/2, <<1, h->left_mb_xy[i>=36], ((i>>2))&3); + } + } +#undef SET_DIAG_MV + } + + if(topright_ref != PART_NOT_AVAILABLE){ + *C= h->mv_cache[list][ i - 8 + part_width ]; + return topright_ref; + }else{ + tprintf(s->avctx, "topright MV not available\n"); + + *C= h->mv_cache[list][ i - 8 - 1 ]; + return h->ref_cache[list][ i - 8 - 1 ]; + } +} + +/** + * gets the predicted MV. + * @param n the block index + * @param part_width the width of the partition (4, 8,16) -> (1, 2, 4) + * @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){ + 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 ]; + const int16_t * const A= h->mv_cache[list][ index8 - 1 ]; + const int16_t * const B= h->mv_cache[list][ index8 - 8 ]; + const int16_t * C; + int diagonal_ref, match_count; + + assert(part_width==1 || part_width==2 || part_width==4); + +/* mv_cache + B . . A T T T T + U . . L . . , . + U . . L . . . . + U . . L . . , . + . . . L . . . . +*/ + + diagonal_ref= fetch_diagonal_mv(h, &C, index8, list, part_width); + match_count= (diagonal_ref==ref) + (top_ref==ref) + (left_ref==ref); + tprintf(h->s.avctx, "pred_motion match_count=%d\n", match_count); + if(match_count > 1){ //most common + *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==ref){ + *mx= A[0]; + *my= A[1]; + }else if(top_ref==ref){ + *mx= B[0]; + *my= B[1]; + }else{ + *mx= C[0]; + *my= C[1]; + } + }else{ + if(top_ref == PART_NOT_AVAILABLE && diagonal_ref == PART_NOT_AVAILABLE && left_ref != PART_NOT_AVAILABLE){ + *mx= A[0]; + *my= A[1]; + }else{ + *mx= mid_pred(A[0], B[0], C[0]); + *my= mid_pred(A[1], B[1], C[1]); + } + } + + tprintf(h->s.avctx, "pred_motion (%2d %2d %2d) (%2d %2d %2d) (%2d %2d %2d) -> (%2d %2d %2d) at %2d %2d %d list %d\n", top_ref, B[0], B[1], diagonal_ref, C[0], C[1], left_ref, A[0], A[1], ref, *mx, *my, h->s.mb_x, h->s.mb_y, n, list); +} + +/** + * gets the directionally predicted 16x8 MV. + * @param n the block index + * @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){ + 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 ]; + + tprintf(h->s.avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n", top_ref, B[0], B[1], h->s.mb_x, h->s.mb_y, n, list); + + if(top_ref == ref){ + *mx= B[0]; + *my= B[1]; + return; + } + }else{ + const int left_ref= h->ref_cache[list][ scan8[8] - 1 ]; + const int16_t * const A= h->mv_cache[list][ scan8[8] - 1 ]; + + tprintf(h->s.avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n", left_ref, A[0], A[1], h->s.mb_x, h->s.mb_y, n, list); + + if(left_ref == ref){ + *mx= A[0]; + *my= A[1]; + return; + } + } + + //RARE + pred_motion(h, n, 4, list, ref, mx, my); +} + +/** + * gets the directionally predicted 8x16 MV. + * @param n the block index + * @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){ + 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 ]; + + tprintf(h->s.avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n", left_ref, A[0], A[1], h->s.mb_x, h->s.mb_y, n, list); + + if(left_ref == ref){ + *mx= A[0]; + *my= A[1]; + return; + } + }else{ + const int16_t * C; + int diagonal_ref; + + diagonal_ref= fetch_diagonal_mv(h, &C, scan8[4], list, 2); + + tprintf(h->s.avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n", diagonal_ref, C[0], C[1], h->s.mb_x, h->s.mb_y, n, list); + + if(diagonal_ref == ref){ + *mx= C[0]; + *my= C[1]; + return; + } + } + + //RARE + 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 ]; + + 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(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 ]))){ + + *mx = *my = 0; + return; + } + + pred_motion(h, 0, 4, 0, 0, mx, my); + + return; +} + +#endif /* AVCODEC_H264_MVPRED_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_parser.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_parser.c index dabd475f93..6350809834 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_parser.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_parser.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/h264_parser.c + * @file * H.264 / AVC / MPEG4 part10 parser. * @author Michael Niedermayer */ @@ -185,6 +185,9 @@ static inline int parse_nal_units(AVCodecParserContext *s, h->sps = *h->sps_buffers[h->pps.sps_id]; h->frame_num = get_bits(&h->s.gb, h->sps.log2_max_frame_num); + avctx->profile = h->sps.profile_idc; + avctx->level = h->sps.level_idc; + if(h->sps.frame_mbs_only_flag){ h->s.picture_structure= PICT_FRAME; }else{ @@ -300,7 +303,7 @@ static int h264_split(AVCodecContext *avctx, return 0; } -static void close(AVCodecParserContext *s) +static void h264_close(AVCodecParserContext *s) { H264Context *h = s->priv_data; ParseContext *pc = &h->s.parse_context; @@ -309,12 +312,18 @@ static void close(AVCodecParserContext *s) ff_h264_free_context(h); } +static int init(AVCodecParserContext *s) +{ + H264Context *h = s->priv_data; + h->thread_context[0] = h; + return 0; +} AVCodecParser h264_parser = { { CODEC_ID_H264 }, sizeof(H264Context), - NULL, + init, h264_parse, - close, + h264_close, h264_split, }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_parser.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_parser.h index 514f86ee97..149f49a386 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_parser.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_parser.h @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/h264_parser.h + * @file * H.264 / AVC / MPEG4 part10 parser. * @author Michael Niedermayer */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_ps.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_ps.c new file mode 100644 index 0000000000..7648e2c7a6 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_ps.c @@ -0,0 +1,537 @@ +/* + * H.26L/H.264/AVC/JVT/14496-10/... parameter set decoding + * Copyright (c) 2003 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 + */ + +/** + * @file + * H.264 / AVC / MPEG4 part10 parameter set decoding. + * @author Michael Niedermayer + */ + +#include "internal.h" +#include "dsputil.h" +#include "avcodec.h" +#include "h264.h" +#include "h264data.h" //FIXME FIXME FIXME (just for zigzag_scan) +#include "golomb.h" + + +//#undef NDEBUG +#include + +static const AVRational pixel_aspect[17]={ + {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}, + {4, 3}, + {3, 2}, + {2, 1}, +}; + +const uint8_t ff_h264_chroma_qp[52]={ + 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,29,30,31,32,32,33,34,34,35,35,36,36,37,37, + 37,38,38,38,39,39,39,39 +}; + +static const uint8_t default_scaling4[2][16]={ +{ 6,13,20,28, + 13,20,28,32, + 20,28,32,37, + 28,32,37,42 +},{ + 10,14,20,24, + 14,20,24,27, + 20,24,27,30, + 24,27,30,34 +}}; + +static const uint8_t default_scaling8[2][64]={ +{ 6,10,13,16,18,23,25,27, + 10,11,16,18,23,25,27,29, + 13,16,18,23,25,27,29,31, + 16,18,23,25,27,29,31,33, + 18,23,25,27,29,31,33,36, + 23,25,27,29,31,33,36,38, + 25,27,29,31,33,36,38,40, + 27,29,31,33,36,38,40,42 +},{ + 9,13,15,17,19,21,22,24, + 13,13,17,19,21,22,24,25, + 15,17,19,21,22,24,25,27, + 17,19,21,22,24,25,27,28, + 19,21,22,24,25,27,28,30, + 21,22,24,25,27,28,30,32, + 22,24,25,27,28,30,32,33, + 24,25,27,28,30,32,33,35 +}}; + +static inline int decode_hrd_parameters(H264Context *h, SPS *sps){ + MpegEncContext * const s = &h->s; + int cpb_count, i; + cpb_count = get_ue_golomb_31(&s->gb) + 1; + + if(cpb_count > 32U){ + av_log(h->s.avctx, AV_LOG_ERROR, "cpb_count %d invalid\n", cpb_count); + return -1; + } + + get_bits(&s->gb, 4); /* bit_rate_scale */ + get_bits(&s->gb, 4); /* cpb_size_scale */ + for(i=0; igb); /* bit_rate_value_minus1 */ + get_ue_golomb(&s->gb); /* cpb_size_value_minus1 */ + get_bits1(&s->gb); /* cbr_flag */ + } + sps->initial_cpb_removal_delay_length = get_bits(&s->gb, 5) + 1; + sps->cpb_removal_delay_length = get_bits(&s->gb, 5) + 1; + sps->dpb_output_delay_length = get_bits(&s->gb, 5) + 1; + sps->time_offset_length = get_bits(&s->gb, 5); + sps->cpb_cnt = cpb_count; + return 0; +} + +static inline int decode_vui_parameters(H264Context *h, SPS *sps){ + MpegEncContext * const s = &h->s; + int aspect_ratio_info_present_flag; + unsigned int aspect_ratio_idc; + + aspect_ratio_info_present_flag= get_bits1(&s->gb); + + if( aspect_ratio_info_present_flag ) { + aspect_ratio_idc= get_bits(&s->gb, 8); + if( aspect_ratio_idc == EXTENDED_SAR ) { + sps->sar.num= get_bits(&s->gb, 16); + sps->sar.den= get_bits(&s->gb, 16); + }else if(aspect_ratio_idc < FF_ARRAY_ELEMS(pixel_aspect)){ + sps->sar= pixel_aspect[aspect_ratio_idc]; + }else{ + av_log(h->s.avctx, AV_LOG_ERROR, "illegal aspect ratio\n"); + return -1; + } + }else{ + sps->sar.num= + sps->sar.den= 0; + } +// s->avctx->aspect_ratio= sar_width*s->width / (float)(s->height*sar_height); + + if(get_bits1(&s->gb)){ /* overscan_info_present_flag */ + get_bits1(&s->gb); /* overscan_appropriate_flag */ + } + + sps->video_signal_type_present_flag = get_bits1(&s->gb); + if(sps->video_signal_type_present_flag){ + get_bits(&s->gb, 3); /* video_format */ + sps->full_range = get_bits1(&s->gb); /* video_full_range_flag */ + + sps->colour_description_present_flag = get_bits1(&s->gb); + if(sps->colour_description_present_flag){ + sps->color_primaries = get_bits(&s->gb, 8); /* colour_primaries */ + sps->color_trc = get_bits(&s->gb, 8); /* transfer_characteristics */ + sps->colorspace = get_bits(&s->gb, 8); /* matrix_coefficients */ + if (sps->color_primaries >= AVCOL_PRI_NB) + sps->color_primaries = AVCOL_PRI_UNSPECIFIED; + if (sps->color_trc >= AVCOL_TRC_NB) + sps->color_trc = AVCOL_TRC_UNSPECIFIED; + if (sps->colorspace >= AVCOL_SPC_NB) + sps->colorspace = AVCOL_SPC_UNSPECIFIED; + } + } + + if(get_bits1(&s->gb)){ /* chroma_location_info_present_flag */ + s->avctx->chroma_sample_location = get_ue_golomb(&s->gb)+1; /* chroma_sample_location_type_top_field */ + get_ue_golomb(&s->gb); /* chroma_sample_location_type_bottom_field */ + } + + sps->timing_info_present_flag = get_bits1(&s->gb); + if(sps->timing_info_present_flag){ + sps->num_units_in_tick = get_bits_long(&s->gb, 32); + sps->time_scale = get_bits_long(&s->gb, 32); + if(!sps->num_units_in_tick || !sps->time_scale){ + av_log(h->s.avctx, AV_LOG_ERROR, "time_scale/num_units_in_tick invalid or unsupported (%d/%d)\n", sps->time_scale, sps->num_units_in_tick); + return -1; + } + sps->fixed_frame_rate_flag = get_bits1(&s->gb); + } + + sps->nal_hrd_parameters_present_flag = get_bits1(&s->gb); + if(sps->nal_hrd_parameters_present_flag) + if(decode_hrd_parameters(h, sps) < 0) + return -1; + sps->vcl_hrd_parameters_present_flag = get_bits1(&s->gb); + if(sps->vcl_hrd_parameters_present_flag) + if(decode_hrd_parameters(h, sps) < 0) + return -1; + if(sps->nal_hrd_parameters_present_flag || sps->vcl_hrd_parameters_present_flag) + get_bits1(&s->gb); /* low_delay_hrd_flag */ + sps->pic_struct_present_flag = get_bits1(&s->gb); + + sps->bitstream_restriction_flag = get_bits1(&s->gb); + if(sps->bitstream_restriction_flag){ + get_bits1(&s->gb); /* motion_vectors_over_pic_boundaries_flag */ + get_ue_golomb(&s->gb); /* max_bytes_per_pic_denom */ + get_ue_golomb(&s->gb); /* max_bits_per_mb_denom */ + get_ue_golomb(&s->gb); /* log2_max_mv_length_horizontal */ + get_ue_golomb(&s->gb); /* log2_max_mv_length_vertical */ + sps->num_reorder_frames= get_ue_golomb(&s->gb); + 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; + } + + if(sps->num_reorder_frames > 16U /*max_dec_frame_buffering || max_dec_frame_buffering > 16*/){ + av_log(h->s.avctx, AV_LOG_ERROR, "illegal num_reorder_frames %d\n", sps->num_reorder_frames); + return -1; + } + } + + return 0; +} + +static void decode_scaling_list(H264Context *h, uint8_t *factors, int size, + const uint8_t *jvt_list, const uint8_t *fallback_list){ + MpegEncContext * const s = &h->s; + int i, last = 8, next = 8; + const uint8_t *scan = size == 16 ? zigzag_scan : ff_zigzag_direct; + if(!get_bits1(&s->gb)) /* matrix not written, we use the predicted one */ + memcpy(factors, fallback_list, size*sizeof(uint8_t)); + else + for(i=0;igb)) & 0xff; + if(!i && !next){ /* matrix not written, we use the preset one */ + memcpy(factors, jvt_list, size*sizeof(uint8_t)); + break; + } + last = factors[scan[i]] = next ? next : last; + } +} + +static void decode_scaling_matrices(H264Context *h, SPS *sps, PPS *pps, int is_sps, + uint8_t (*scaling_matrix4)[16], uint8_t (*scaling_matrix8)[64]){ + MpegEncContext * const s = &h->s; + int fallback_sps = !is_sps && sps->scaling_matrix_present; + const uint8_t *fallback[4] = { + fallback_sps ? sps->scaling_matrix4[0] : default_scaling4[0], + fallback_sps ? sps->scaling_matrix4[3] : default_scaling4[1], + fallback_sps ? sps->scaling_matrix8[0] : default_scaling8[0], + fallback_sps ? sps->scaling_matrix8[1] : default_scaling8[1] + }; + if(get_bits1(&s->gb)){ + sps->scaling_matrix_present |= is_sps; + decode_scaling_list(h,scaling_matrix4[0],16,default_scaling4[0],fallback[0]); // Intra, Y + decode_scaling_list(h,scaling_matrix4[1],16,default_scaling4[0],scaling_matrix4[0]); // Intra, Cr + decode_scaling_list(h,scaling_matrix4[2],16,default_scaling4[0],scaling_matrix4[1]); // Intra, Cb + decode_scaling_list(h,scaling_matrix4[3],16,default_scaling4[1],fallback[1]); // Inter, Y + decode_scaling_list(h,scaling_matrix4[4],16,default_scaling4[1],scaling_matrix4[3]); // Inter, Cr + decode_scaling_list(h,scaling_matrix4[5],16,default_scaling4[1],scaling_matrix4[4]); // Inter, Cb + if(is_sps || pps->transform_8x8_mode){ + decode_scaling_list(h,scaling_matrix8[0],64,default_scaling8[0],fallback[2]); // Intra, Y + decode_scaling_list(h,scaling_matrix8[1],64,default_scaling8[1],fallback[3]); // Inter, Y + } + } +} + +int ff_h264_decode_seq_parameter_set(H264Context *h){ + MpegEncContext * const s = &h->s; + int profile_idc, level_idc; + unsigned int sps_id; + int i; + SPS *sps; + + profile_idc= get_bits(&s->gb, 8); + get_bits1(&s->gb); //constraint_set0_flag + get_bits1(&s->gb); //constraint_set1_flag + get_bits1(&s->gb); //constraint_set2_flag + get_bits1(&s->gb); //constraint_set3_flag + get_bits(&s->gb, 4); // reserved + level_idc= get_bits(&s->gb, 8); + sps_id= get_ue_golomb_31(&s->gb); + + if(sps_id >= MAX_SPS_COUNT) { + av_log(h->s.avctx, AV_LOG_ERROR, "sps_id (%d) out of range\n", sps_id); + return -1; + } + sps= av_mallocz(sizeof(SPS)); + if(sps == NULL) + return -1; + + sps->profile_idc= profile_idc; + sps->level_idc= level_idc; + + memset(sps->scaling_matrix4, 16, sizeof(sps->scaling_matrix4)); + memset(sps->scaling_matrix8, 16, sizeof(sps->scaling_matrix8)); + sps->scaling_matrix_present = 0; + + if(sps->profile_idc >= 100){ //high profile + sps->chroma_format_idc= get_ue_golomb_31(&s->gb); + if(sps->chroma_format_idc == 3) + 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; + sps->transform_bypass = get_bits1(&s->gb); + decode_scaling_matrices(h, sps, NULL, 1, sps->scaling_matrix4, sps->scaling_matrix8); + }else{ + sps->chroma_format_idc= 1; + sps->bit_depth_luma = 8; + sps->bit_depth_chroma = 8; + } + + sps->log2_max_frame_num= get_ue_golomb(&s->gb) + 4; + sps->poc_type= get_ue_golomb_31(&s->gb); + + if(sps->poc_type == 0){ //FIXME #define + sps->log2_max_poc_lsb= get_ue_golomb(&s->gb) + 4; + } else if(sps->poc_type == 1){//FIXME #define + sps->delta_pic_order_always_zero_flag= get_bits1(&s->gb); + sps->offset_for_non_ref_pic= get_se_golomb(&s->gb); + sps->offset_for_top_to_bottom_field= get_se_golomb(&s->gb); + sps->poc_cycle_length = get_ue_golomb(&s->gb); + + if((unsigned)sps->poc_cycle_length >= FF_ARRAY_ELEMS(sps->offset_for_ref_frame)){ + av_log(h->s.avctx, AV_LOG_ERROR, "poc_cycle_length overflow %u\n", sps->poc_cycle_length); + goto fail; + } + + for(i=0; ipoc_cycle_length; i++) + sps->offset_for_ref_frame[i]= get_se_golomb(&s->gb); + }else if(sps->poc_type != 2){ + av_log(h->s.avctx, AV_LOG_ERROR, "illegal POC type %d\n", sps->poc_type); + goto fail; + } + + sps->ref_frame_count= get_ue_golomb_31(&s->gb); + if(sps->ref_frame_count > MAX_PICTURE_COUNT-2 || sps->ref_frame_count >= 32U){ + av_log(h->s.avctx, AV_LOG_ERROR, "too many reference frames\n"); + goto fail; + } + sps->gaps_in_frame_num_allowed_flag= get_bits1(&s->gb); + sps->mb_width = get_ue_golomb(&s->gb) + 1; + sps->mb_height= get_ue_golomb(&s->gb) + 1; + if((unsigned)sps->mb_width >= INT_MAX/16 || (unsigned)sps->mb_height >= INT_MAX/16 || + avcodec_check_dimensions(NULL, 16*sps->mb_width, 16*sps->mb_height)){ + av_log(h->s.avctx, AV_LOG_ERROR, "mb_width/height overflow\n"); + goto fail; + } + + sps->frame_mbs_only_flag= get_bits1(&s->gb); + if(!sps->frame_mbs_only_flag) + sps->mb_aff= get_bits1(&s->gb); + else + 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) + av_log(h->s.avctx, AV_LOG_ERROR, "MBAFF support not included; enable it at compile-time.\n"); +#endif + sps->crop= get_bits1(&s->gb); + if(sps->crop){ + 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"); + } + if(sps->crop_right >= 8 || sps->crop_bottom >= (8>> !sps->frame_mbs_only_flag)){ + av_log(h->s.avctx, AV_LOG_ERROR, "brainfart cropping not supported, this could look slightly wrong ...\n"); + } + }else{ + sps->crop_left = + sps->crop_right = + sps->crop_top = + sps->crop_bottom= 0; + } + + sps->vui_parameters_present_flag= get_bits1(&s->gb); + if( sps->vui_parameters_present_flag ) + if (decode_vui_parameters(h, sps) < 0) + goto fail; + + 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", + sps_id, sps->profile_idc, sps->level_idc, + sps->poc_type, + sps->ref_frame_count, + sps->mb_width, sps->mb_height, + sps->frame_mbs_only_flag ? "FRM" : (sps->mb_aff ? "MB-AFF" : "PIC-AFF"), + sps->direct_8x8_inference_flag ? "8B8" : "", + sps->crop_left, sps->crop_right, + sps->crop_top, sps->crop_bottom, + 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 + ); + } + + av_free(h->sps_buffers[sps_id]); + h->sps_buffers[sps_id]= sps; + h->sps = *sps; + return 0; +fail: + av_free(sps); + return -1; +} + +static void +build_qp_table(PPS *pps, int t, int index) +{ + int i; + for(i = 0; i < 52; i++) + pps->chroma_qp_table[t][i] = ff_h264_chroma_qp[av_clip(i + index, 0, 51)]; +} + +int ff_h264_decode_picture_parameter_set(H264Context *h, int bit_length){ + MpegEncContext * const s = &h->s; + unsigned int pps_id= get_ue_golomb(&s->gb); + PPS *pps; + + if(pps_id >= MAX_PPS_COUNT) { + av_log(h->s.avctx, AV_LOG_ERROR, "pps_id (%d) out of range\n", pps_id); + return -1; + } + + pps= av_mallocz(sizeof(PPS)); + if(pps == NULL) + return -1; + pps->sps_id= get_ue_golomb_31(&s->gb); + if((unsigned)pps->sps_id>=MAX_SPS_COUNT || h->sps_buffers[pps->sps_id] == NULL){ + av_log(h->s.avctx, AV_LOG_ERROR, "sps_id out of range\n"); + goto fail; + } + + pps->cabac= get_bits1(&s->gb); + pps->pic_order_present= get_bits1(&s->gb); + pps->slice_group_count= get_ue_golomb(&s->gb) + 1; + if(pps->slice_group_count > 1 ){ + pps->mb_slice_group_map_type= get_ue_golomb(&s->gb); + av_log(h->s.avctx, AV_LOG_ERROR, "FMO not supported\n"); + switch(pps->mb_slice_group_map_type){ + case 0: +#if 0 +| for( i = 0; i <= num_slice_groups_minus1; i++ ) | | | +| run_length[ i ] |1 |ue(v) | +#endif + break; + case 2: +#if 0 +| for( i = 0; i < num_slice_groups_minus1; i++ ) | | | +|{ | | | +| top_left_mb[ i ] |1 |ue(v) | +| bottom_right_mb[ i ] |1 |ue(v) | +| } | | | +#endif + break; + case 3: + case 4: + case 5: +#if 0 +| slice_group_change_direction_flag |1 |u(1) | +| slice_group_change_rate_minus1 |1 |ue(v) | +#endif + break; + case 6: +#if 0 +| slice_group_id_cnt_minus1 |1 |ue(v) | +| for( i = 0; i <= slice_group_id_cnt_minus1; i++ | | | +|) | | | +| slice_group_id[ i ] |1 |u(v) | +#endif + break; + } + } + pps->ref_count[0]= get_ue_golomb(&s->gb) + 1; + pps->ref_count[1]= get_ue_golomb(&s->gb) + 1; + if(pps->ref_count[0]-1 > 32-1 || pps->ref_count[1]-1 > 32-1){ + av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow (pps)\n"); + goto fail; + } + + pps->weighted_pred= get_bits1(&s->gb); + pps->weighted_bipred_idc= get_bits(&s->gb, 2); + pps->init_qp= get_se_golomb(&s->gb) + 26; + pps->init_qs= get_se_golomb(&s->gb) + 26; + pps->chroma_qp_index_offset[0]= get_se_golomb(&s->gb); + pps->deblocking_filter_parameters_present= get_bits1(&s->gb); + pps->constrained_intra_pred= get_bits1(&s->gb); + pps->redundant_pic_cnt_present = get_bits1(&s->gb); + + pps->transform_8x8_mode= 0; + h->dequant_coeff_pps= -1; //contents of sps/pps can change even if id doesn't, so reinit + 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)); + + 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); + pps->chroma_qp_index_offset[1]= get_se_golomb(&s->gb); //second_chroma_qp_index_offset + } else { + pps->chroma_qp_index_offset[1]= pps->chroma_qp_index_offset[0]; + } + + build_qp_table(pps, 0, pps->chroma_qp_index_offset[0]); + build_qp_table(pps, 1, pps->chroma_qp_index_offset[1]); + if(pps->chroma_qp_index_offset[0] != pps->chroma_qp_index_offset[1]) + pps->chroma_qp_diff= 1; + + if(s->avctx->debug&FF_DEBUG_PICT_INFO){ + av_log(h->s.avctx, AV_LOG_DEBUG, "pps:%u sps:%u %s slice_groups:%d ref:%d/%d %s qp:%d/%d/%d/%d %s %s %s %s\n", + pps_id, pps->sps_id, + pps->cabac ? "CABAC" : "CAVLC", + pps->slice_group_count, + pps->ref_count[0], pps->ref_count[1], + pps->weighted_pred ? "weighted" : "", + pps->init_qp, pps->init_qs, pps->chroma_qp_index_offset[0], pps->chroma_qp_index_offset[1], + pps->deblocking_filter_parameters_present ? "LPAR" : "", + pps->constrained_intra_pred ? "CONSTR" : "", + pps->redundant_pic_cnt_present ? "REDU" : "", + pps->transform_8x8_mode ? "8x8DCT" : "" + ); + } + + av_free(h->pps_buffers[pps_id]); + h->pps_buffers[pps_id]= pps; + return 0; +fail: + av_free(pps); + return -1; +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_refs.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_refs.c new file mode 100644 index 0000000000..ed715c6b03 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_refs.c @@ -0,0 +1,694 @@ +/* + * H.26L/H.264/AVC/JVT/14496-10/... reference picture handling + * Copyright (c) 2003 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 + */ + +/** + * @file + * H.264 / AVC / MPEG4 part10 reference picture handling. + * @author Michael Niedermayer + */ + +#include "internal.h" +#include "dsputil.h" +#include "avcodec.h" +#include "h264.h" +#include "golomb.h" + +//#undef NDEBUG +#include + + +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->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); + + if (match) { + *dest = *src; + if(parity != PICT_FRAME){ + pic_as_field(dest, parity); + dest->pic_id *= 2; + dest->pic_id += id_add; + } + } + + return match; +} + +static int build_def_list(Picture *def, Picture **in, int len, int is_long, int sel){ + int i[2]={0}; + int index=0; + + while(i[0]reference & sel))) + i[0]++; + while(i[1]reference & (sel^3)))) + i[1]++; + if(i[0] < len){ + in[ i[0] ]->pic_id= is_long ? i[0] : in[ i[0] ]->frame_num; + split_field_copy(&def[index++], in[ i[0]++ ], sel , 1); + } + if(i[1] < len){ + in[ i[1] ]->pic_id= is_long ? i[1] : in[ i[1] ]->frame_num; + split_field_copy(&def[index++], in[ i[1]++ ], sel^3, 0); + } + } + + return index; +} + +static int add_sorted(Picture **sorted, Picture **src, int len, int limit, int dir){ + int i, best_poc; + int out_i= 0; + + for(;;){ + best_poc= dir ? INT_MIN : INT_MAX; + + for(i=0; ipoc; + if(((poc > limit) ^ dir) && ((poc < best_poc) ^ dir)){ + best_poc= poc; + sorted[out_i]= src[i]; + } + } + if(best_poc == (dir ? INT_MIN : INT_MAX)) + break; + limit= sorted[out_i++]->poc - dir; + } + return out_i; +} + +int ff_h264_fill_default_ref_list(H264Context *h){ + MpegEncContext * const s = &h->s; + int i, len; + + if(h->slice_type_nos==FF_B_TYPE){ + Picture *sorted[32]; + int cur_poc, list; + int lens[2]; + + if(FIELD_PICTURE) + cur_poc= s->current_picture_ptr->field_poc[ s->picture_structure == PICT_BOTTOM_FIELD ]; + else + cur_poc= s->current_picture_ptr->poc; + + for(list= 0; list<2; list++){ + len= add_sorted(sorted , h->short_ref, h->short_ref_count, cur_poc, 1^list); + len+=add_sorted(sorted+len, h->short_ref, h->short_ref_count, cur_poc, 0^list); + assert(len<=32); + len= build_def_list(h->default_ref_list[list] , sorted , len, 0, s->picture_structure); + len+=build_def_list(h->default_ref_list[list]+len, h->long_ref, 16 , 1, s->picture_structure); + assert(len<=32); + + if(len < h->ref_count[list]) + memset(&h->default_ref_list[list][len], 0, sizeof(Picture)*(h->ref_count[list] - len)); + lens[list]= len; + } + + 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] && idefault_ref_list[1][0], h->default_ref_list[1][1]); + } + }else{ + len = build_def_list(h->default_ref_list[0] , h->short_ref, h->short_ref_count, 0, s->picture_structure); + len+= build_def_list(h->default_ref_list[0]+len, h-> long_ref, 16 , 1, s->picture_structure); + assert(len <= 32); + if(len < h->ref_count[0]) + memset(&h->default_ref_list[0][len], 0, sizeof(Picture)*(h->ref_count[0] - len)); + } +#ifdef TRACE + for (i=0; iref_count[0]; i++) { + tprintf(h->s.avctx, "List0: %s fn:%d 0x%p\n", (h->default_ref_list[0][i].long_ref ? "LT" : "ST"), h->default_ref_list[0][i].pic_id, h->default_ref_list[0][i].data[0]); + } + if(h->slice_type_nos==FF_B_TYPE){ + for (i=0; iref_count[1]; i++) { + tprintf(h->s.avctx, "List1: %s fn:%d 0x%p\n", (h->default_ref_list[1][i].long_ref ? "LT" : "ST"), h->default_ref_list[1][i].pic_id, h->default_ref_list[1][i].data[0]); + } + } +#endif + return 0; +} + +static void print_short_term(H264Context *h); +static void print_long_term(H264Context *h); + +/** + * Extract structure information about the picture described by pic_num in + * the current decoding context (frame or field). Note that pic_num is + * picture number without wrapping (so, 0<=pic_nums; + + *structure = s->picture_structure; + if(FIELD_PICTURE){ + if (!(pic_num & 1)) + /* opposite field */ + *structure ^= PICT_FRAME; + pic_num >>= 1; + } + + return pic_num; +} + +int ff_h264_decode_ref_pic_list_reordering(H264Context *h){ + MpegEncContext * const s = &h->s; + int list, index, pic_structure; + + print_short_term(h); + print_long_term(h); + + for(list=0; listlist_count; list++){ + memcpy(h->ref_list[list], h->default_ref_list[list], sizeof(Picture)*h->ref_count[list]); + + if(get_bits1(&s->gb)){ + int pred= h->curr_pic_num; + + for(index=0; ; index++){ + unsigned int reordering_of_pic_nums_idc= get_ue_golomb_31(&s->gb); + unsigned int pic_id; + int i; + Picture *ref = NULL; + + if(reordering_of_pic_nums_idc==3) + break; + + if(index >= h->ref_count[list]){ + av_log(h->s.avctx, AV_LOG_ERROR, "reference count overflow\n"); + return -1; + } + + if(reordering_of_pic_nums_idc<3){ + if(reordering_of_pic_nums_idc<2){ + const unsigned int abs_diff_pic_num= get_ue_golomb(&s->gb) + 1; + int frame_num; + + if(abs_diff_pic_num > h->max_pic_num){ + av_log(h->s.avctx, AV_LOG_ERROR, "abs_diff_pic_num overflow\n"); + return -1; + } + + if(reordering_of_pic_nums_idc == 0) pred-= abs_diff_pic_num; + else pred+= abs_diff_pic_num; + pred &= h->max_pic_num - 1; + + frame_num = pic_num_extract(h, pred, &pic_structure); + + for(i= h->short_ref_count-1; i>=0; i--){ + ref = h->short_ref[i]; + assert(ref->reference); + assert(!ref->long_ref); + if( + ref->frame_num == frame_num && + (ref->reference & pic_structure) + ) + break; + } + if(i>=0) + ref->pic_id= pred; + }else{ + int long_idx; + pic_id= get_ue_golomb(&s->gb); //long_term_pic_idx + + long_idx= pic_num_extract(h, pic_id, &pic_structure); + + if(long_idx>31){ + av_log(h->s.avctx, AV_LOG_ERROR, "long_term_pic_idx overflow\n"); + return -1; + } + ref = h->long_ref[long_idx]; + assert(!(ref && !ref->reference)); + if(ref && (ref->reference & pic_structure)){ + ref->pic_id= pic_id; + assert(ref->long_ref); + i=0; + }else{ + i=-1; + } + } + + if (i < 0) { + av_log(h->s.avctx, AV_LOG_ERROR, "reference picture missing during reorder\n"); + memset(&h->ref_list[list][index], 0, sizeof(Picture)); //FIXME + } else { + for(i=index; i+1ref_count[list]; i++){ + if(ref->long_ref == h->ref_list[list][i].long_ref && ref->pic_id == h->ref_list[list][i].pic_id) + break; + } + for(; i > index; i--){ + h->ref_list[list][i]= h->ref_list[list][i-1]; + } + h->ref_list[list][index]= *ref; + if (FIELD_PICTURE){ + pic_as_field(&h->ref_list[list][index], pic_structure); + } + } + }else{ + av_log(h->s.avctx, AV_LOG_ERROR, "illegal reordering_of_pic_nums_idc\n"); + return -1; + } + } + } + } + for(list=0; listlist_count; list++){ + for(index= 0; index < h->ref_count[list]; index++){ + if(!h->ref_list[list][index].data[0]){ + av_log(h->s.avctx, AV_LOG_ERROR, "Missing reference picture\n"); + if(h->default_ref_list[list][0].data[0]) + h->ref_list[list][index]= h->default_ref_list[list][0]; + else + return -1; + } + } + } + + return 0; +} + +void ff_h264_fill_mbaff_ref_list(H264Context *h){ + int list, i, j; + for(list=0; list<2; list++){ //FIXME try list_count + for(i=0; iref_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].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].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]; + h->luma_weight[16+2*i][list][1] = h->luma_weight[16+2*i+1][list][1] = h->luma_weight[i][list][1]; + for(j=0; j<2; j++){ + h->chroma_weight[16+2*i][list][j][0] = h->chroma_weight[16+2*i+1][list][j][0] = h->chroma_weight[i][list][j][0]; + h->chroma_weight[16+2*i][list][j][1] = h->chroma_weight[16+2*i+1][list][j][1] = h->chroma_weight[i][list][j][1]; + } + } + } +} + +/** + * Mark a picture as no longer needed for reference. The refmask + * argument allows unreferencing of individual fields or the whole frame. + * If the picture becomes entirely unreferenced, but is being held for + * display purposes, it is marked as such. + * @param refmask mask of fields to unreference; the mask is bitwise + * anded with the reference marking of pic + * @return non-zero if pic becomes entirely unreferenced (except possibly + * for display purposes) zero if one of the fields remains in + * reference + */ +static inline int unreference_pic(H264Context *h, Picture *pic, int refmask){ + int i; + if (pic->reference &= refmask) { + return 0; + } else { + for(i = 0; h->delayed_pic[i]; i++) + if(pic == h->delayed_pic[i]){ + pic->reference=DELAYED_PIC_REF; + break; + } + return 1; + } +} + +/** + * Find a Picture in the short term reference list by frame number. + * @param frame_num frame number to search for + * @param idx the index into h->short_ref where returned picture is found + * undefined if no picture found. + * @return pointer to the found picture, or NULL if no pic with the provided + * frame number is found + */ +static Picture * find_short(H264Context *h, int frame_num, int *idx){ + MpegEncContext * const s = &h->s; + int i; + + for(i=0; ishort_ref_count; i++){ + Picture *pic= h->short_ref[i]; + if(s->avctx->debug&FF_DEBUG_MMCO) + av_log(h->s.avctx, AV_LOG_DEBUG, "%d %d %p\n", i, pic->frame_num, pic); + if(pic->frame_num == frame_num) { + *idx = i; + return pic; + } + } + return NULL; +} + +/** + * Remove a picture from the short term reference list by its index in + * that list. This does no checking on the provided index; it is assumed + * to be valid. Other list entries are shifted down. + * @param i index into h->short_ref of picture to remove. + */ +static void remove_short_at_index(H264Context *h, int i){ + assert(i >= 0 && i < h->short_ref_count); + h->short_ref[i]= NULL; + if (--h->short_ref_count) + memmove(&h->short_ref[i], &h->short_ref[i+1], (h->short_ref_count - i)*sizeof(Picture*)); +} + +/** + * + * @return the removed picture or NULL if an error occurs + */ +static Picture * remove_short(H264Context *h, int frame_num, int ref_mask){ + MpegEncContext * const s = &h->s; + Picture *pic; + int i; + + if(s->avctx->debug&FF_DEBUG_MMCO) + av_log(h->s.avctx, AV_LOG_DEBUG, "remove short %d count %d\n", frame_num, h->short_ref_count); + + pic = find_short(h, frame_num, &i); + if (pic){ + if(unreference_pic(h, pic, ref_mask)) + remove_short_at_index(h, i); + } + + return pic; +} + +/** + * Remove a picture from the long term reference list by its index in + * that list. + * @return the removed picture or NULL if an error occurs + */ +static Picture * remove_long(H264Context *h, int i, int ref_mask){ + Picture *pic; + + pic= h->long_ref[i]; + if (pic){ + if(unreference_pic(h, pic, ref_mask)){ + assert(h->long_ref[i]->long_ref == 1); + h->long_ref[i]->long_ref= 0; + h->long_ref[i]= NULL; + h->long_ref_count--; + } + } + + return pic; +} + +void ff_h264_remove_all_refs(H264Context *h){ + int i; + + for(i=0; i<16; i++){ + remove_long(h, i, 0); + } + assert(h->long_ref_count==0); + + for(i=0; ishort_ref_count; i++){ + unreference_pic(h, h->short_ref[i], 0); + h->short_ref[i]= NULL; + } + h->short_ref_count=0; +} + +/** + * print short term list + */ +static void print_short_term(H264Context *h) { + uint32_t i; + if(h->s.avctx->debug&FF_DEBUG_MMCO) { + av_log(h->s.avctx, AV_LOG_DEBUG, "short term list:\n"); + for(i=0; ishort_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]); + } + } +} + +/** + * print long term list + */ +static void print_long_term(H264Context *h) { + uint32_t i; + if(h->s.avctx->debug&FF_DEBUG_MMCO) { + av_log(h->s.avctx, AV_LOG_DEBUG, "long term list:\n"); + 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]); + } + } + } +} + +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; + Picture *av_uninit(pic); + + if((s->avctx->debug&FF_DEBUG_MMCO) && mmco_count==0) + av_log(h->s.avctx, AV_LOG_DEBUG, "no mmco here\n"); + + for(i=0; iavctx->debug&FF_DEBUG_MMCO) + av_log(h->s.avctx, AV_LOG_DEBUG, "mmco:%d %d %d\n", h->mmco[i].opcode, h->mmco[i].short_pic_num, h->mmco[i].long_arg); + + if( mmco[i].opcode == MMCO_SHORT2UNUSED + || mmco[i].opcode == MMCO_SHORT2LONG){ + frame_num = pic_num_extract(h, mmco[i].short_pic_num, &structure); + 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"); + continue; + } + } + + switch(mmco[i].opcode){ + case MMCO_SHORT2UNUSED: + if(s->avctx->debug&FF_DEBUG_MMCO) + av_log(h->s.avctx, AV_LOG_DEBUG, "mmco: unref short %d count %d\n", h->mmco[i].short_pic_num, h->short_ref_count); + remove_short(h, frame_num, structure ^ PICT_FRAME); + break; + case MMCO_SHORT2LONG: + if (h->long_ref[mmco[i].long_arg] != pic) + remove_long(h, mmco[i].long_arg, 0); + + remove_short_at_index(h, j); + h->long_ref[ mmco[i].long_arg ]= pic; + if (h->long_ref[ mmco[i].long_arg ]){ + h->long_ref[ mmco[i].long_arg ]->long_ref=1; + h->long_ref_count++; + } + break; + case MMCO_LONG2UNUSED: + j = pic_num_extract(h, mmco[i].long_arg, &structure); + pic = h->long_ref[j]; + if (pic) { + remove_long(h, j, structure ^ PICT_FRAME); + } else if(s->avctx->debug&FF_DEBUG_MMCO) + av_log(h->s.avctx, AV_LOG_DEBUG, "mmco: unref long failure\n"); + break; + case MMCO_LONG: + // Comment below left from previous code as it is an interresting note. + /* First field in pair is in short term list or + * at a different long term index. + * This is not allowed; see 7.4.3.3, notes 2 and 3. + * Report the problem and keep the pair where it is, + * and mark this field valid. + */ + + if (h->long_ref[mmco[i].long_arg] != s->current_picture_ptr) { + remove_long(h, mmco[i].long_arg, 0); + + h->long_ref[ mmco[i].long_arg ]= s->current_picture_ptr; + h->long_ref[ mmco[i].long_arg ]->long_ref=1; + h->long_ref_count++; + } + + s->current_picture_ptr->reference |= s->picture_structure; + current_ref_assigned=1; + break; + case MMCO_SET_MAX_LONG: + assert(mmco[i].long_arg <= 16); + // just remove the long term which index is greater than new max + for(j = mmco[i].long_arg; j<16; j++){ + remove_long(h, j, 0); + } + break; + case MMCO_RESET: + while(h->short_ref_count){ + remove_short(h, h->short_ref[0]->frame_num, 0); + } + for(j = 0; j < 16; j++) { + remove_long(h, j, 0); + } + s->current_picture_ptr->poc= + s->current_picture_ptr->field_poc[0]= + s->current_picture_ptr->field_poc[1]= + h->poc_lsb= + h->poc_msb= + h->frame_num= + s->current_picture_ptr->frame_num= 0; + s->current_picture_ptr->mmco_reset=1; + break; + default: assert(0); + } + } + + if (!current_ref_assigned) { + /* Second field of complementary field pair; the first field of + * which is already referenced. If short referenced, it + * should be first entry in short_ref. If not, it must exist + * in long_ref; trying to put it on the short list here is an + * error in the encoded bit stream (ref: 7.4.3.3, NOTE 2 and 3). + */ + 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; + } 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"); + } 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"); + } + + if(h->short_ref_count) + memmove(&h->short_ref[1], &h->short_ref[0], h->short_ref_count*sizeof(Picture*)); + + h->short_ref[0]= s->current_picture_ptr; + h->short_ref_count++; + s->current_picture_ptr->reference |= s->picture_structure; + } + } + + if (h->long_ref_count + h->short_ref_count > h->sps.ref_frame_count){ + + /* We have too many reference frames, probably due to corrupted + * stream. Need to discard one frame. Prevents overrun of the + * short_ref and long_ref buffers. + */ + av_log(h->s.avctx, AV_LOG_ERROR, + "number of reference frames exceeds max (probably " + "corrupt input), discarding one\n"); + + if (h->long_ref_count && !h->short_ref_count) { + for (i = 0; i < 16; ++i) + if (h->long_ref[i]) + break; + + assert(i < 16); + remove_long(h, i, 0); + } else { + pic = h->short_ref[h->short_ref_count - 1]; + remove_short(h, pic->frame_num, 0); + } + } + + print_short_term(h); + print_long_term(h); + return 0; +} + +int ff_h264_decode_ref_pic_marking(H264Context *h, GetBitContext *gb){ + MpegEncContext * const s = &h->s; + int i; + + h->mmco_index= 0; + if(h->nal_unit_type == NAL_IDR_SLICE){ //FIXME fields + s->broken_link= get_bits1(gb) -1; + if(get_bits1(gb)){ + h->mmco[0].opcode= MMCO_LONG; + h->mmco[0].long_arg= 0; + h->mmco_index= 1; + } + }else{ + if(get_bits1(gb)){ // adaptive_ref_pic_marking_mode_flag + for(i= 0; immco[i].opcode= opcode; + if(opcode==MMCO_SHORT2UNUSED || opcode==MMCO_SHORT2LONG){ + h->mmco[i].short_pic_num= (h->curr_pic_num - get_ue_golomb(gb) - 1) & (h->max_pic_num - 1); +/* if(h->mmco[i].short_pic_num >= h->short_ref_count || h->short_ref[ h->mmco[i].short_pic_num ] == NULL){ + av_log(s->avctx, AV_LOG_ERROR, "illegal short ref in memory management control operation %d\n", mmco); + return -1; + }*/ + } + 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))){ + av_log(h->s.avctx, AV_LOG_ERROR, "illegal long ref in memory management control operation %d\n", opcode); + return -1; + } + h->mmco[i].long_arg= long_arg; + } + + if(opcode > (unsigned)MMCO_LONG){ + av_log(h->s.avctx, AV_LOG_ERROR, "illegal memory management control operation %d\n", opcode); + return -1; + } + if(opcode == MMCO_END) + break; + } + h->mmco_index= i; + }else{ + assert(h->long_ref_count + h->short_ref_count <= h->sps.ref_frame_count); + + 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)) { + 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; + if (FIELD_PICTURE) { + h->mmco[0].short_pic_num *= 2; + h->mmco[1].opcode= MMCO_SHORT2UNUSED; + h->mmco[1].short_pic_num= h->mmco[0].short_pic_num + 1; + h->mmco_index= 2; + } + } + } + } + + return 0; +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_sei.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_sei.c new file mode 100644 index 0000000000..195ea2856f --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264_sei.c @@ -0,0 +1,206 @@ +/* + * H.26L/H.264/AVC/JVT/14496-10/... sei decoding + * Copyright (c) 2003 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 + */ + +/** + * @file + * H.264 / AVC / MPEG4 part10 sei decoding. + * @author Michael Niedermayer + */ + +#include "internal.h" +#include "avcodec.h" +#include "h264.h" +#include "golomb.h" + +//#undef NDEBUG +#include + +static const uint8_t sei_num_clock_ts_table[9]={ + 1, 1, 1, 2, 2, 3, 3, 2, 3 +}; + +void ff_h264_reset_sei(H264Context *h) { + h->sei_recovery_frame_cnt = -1; + h->sei_dpb_output_delay = 0; + h->sei_cpb_removal_delay = -1; + h->sei_buffering_period_present = 0; +} + +static int decode_picture_timing(H264Context *h){ + MpegEncContext * const s = &h->s; + if(h->sps.nal_hrd_parameters_present_flag || h->sps.vcl_hrd_parameters_present_flag){ + h->sei_cpb_removal_delay = get_bits(&s->gb, h->sps.cpb_removal_delay_length); + h->sei_dpb_output_delay = get_bits(&s->gb, h->sps.dpb_output_delay_length); + } + if(h->sps.pic_struct_present_flag){ + unsigned int i, num_clock_ts; + h->sei_pic_struct = get_bits(&s->gb, 4); + h->sei_ct_type = 0; + + if (h->sei_pic_struct > SEI_PIC_STRUCT_FRAME_TRIPLING) + return -1; + + num_clock_ts = sei_num_clock_ts_table[h->sei_pic_struct]; + + for (i = 0 ; i < num_clock_ts ; i++){ + if(get_bits(&s->gb, 1)){ /* clock_timestamp_flag */ + unsigned int full_timestamp_flag; + h->sei_ct_type |= 1<gb, 2); + skip_bits(&s->gb, 1); /* nuit_field_based_flag */ + skip_bits(&s->gb, 5); /* counting_type */ + full_timestamp_flag = get_bits(&s->gb, 1); + skip_bits(&s->gb, 1); /* discontinuity_flag */ + skip_bits(&s->gb, 1); /* cnt_dropped_flag */ + skip_bits(&s->gb, 8); /* n_frames */ + if(full_timestamp_flag){ + skip_bits(&s->gb, 6); /* seconds_value 0..59 */ + skip_bits(&s->gb, 6); /* minutes_value 0..59 */ + skip_bits(&s->gb, 5); /* hours_value 0..23 */ + }else{ + if(get_bits(&s->gb, 1)){ /* seconds_flag */ + skip_bits(&s->gb, 6); /* seconds_value range 0..59 */ + if(get_bits(&s->gb, 1)){ /* minutes_flag */ + skip_bits(&s->gb, 6); /* minutes_value 0..59 */ + if(get_bits(&s->gb, 1)) /* hours_flag */ + skip_bits(&s->gb, 5); /* hours_value 0..23 */ + } + } + } + if(h->sps.time_offset_length > 0) + skip_bits(&s->gb, h->sps.time_offset_length); /* time_offset */ + } + } + + if(s->avctx->debug & FF_DEBUG_PICT_INFO) + av_log(s->avctx, AV_LOG_DEBUG, "ct_type:%X pic_struct:%d\n", h->sei_ct_type, h->sei_pic_struct); + } + return 0; +} + +static int decode_unregistered_user_data(H264Context *h, int size){ + MpegEncContext * const s = &h->s; + uint8_t user_data[16+256]; + int e, build, i; + + if(size<16) + return -1; + + for(i=0; igb, 8); + } + + user_data[i]= 0; + e= sscanf(user_data+16, "x264 - core %d"/*%s - H.264/MPEG-4 AVC codec - Copyleft 2005 - http://www.videolan.org/x264.html*/, &build); + if(e==1 && build>0) + h->x264_build= build; + + if(s->avctx->debug & FF_DEBUG_BUGS) + av_log(s->avctx, AV_LOG_DEBUG, "user data:\"%s\"\n", user_data+16); + + for(; igb, 8); + + return 0; +} + +static int decode_recovery_point(H264Context *h){ + MpegEncContext * const s = &h->s; + + h->sei_recovery_frame_cnt = get_ue_golomb(&s->gb); + skip_bits(&s->gb, 4); /* 1b exact_match_flag, 1b broken_link_flag, 2b changing_slice_group_idc */ + + return 0; +} + +static int decode_buffering_period(H264Context *h){ + MpegEncContext * const s = &h->s; + unsigned int sps_id; + int sched_sel_idx; + SPS *sps; + + sps_id = get_ue_golomb_31(&s->gb); + if(sps_id > 31 || !h->sps_buffers[sps_id]) { + av_log(h->s.avctx, AV_LOG_ERROR, "non-existing SPS %d referenced in buffering period\n", sps_id); + return -1; + } + sps = h->sps_buffers[sps_id]; + + // NOTE: This is really so duplicated in the standard... See H.264, D.1.1 + if (sps->nal_hrd_parameters_present_flag) { + for (sched_sel_idx = 0; sched_sel_idx < sps->cpb_cnt; sched_sel_idx++) { + h->initial_cpb_removal_delay[sched_sel_idx] = get_bits(&s->gb, sps->initial_cpb_removal_delay_length); + skip_bits(&s->gb, sps->initial_cpb_removal_delay_length); // initial_cpb_removal_delay_offset + } + } + if (sps->vcl_hrd_parameters_present_flag) { + for (sched_sel_idx = 0; sched_sel_idx < sps->cpb_cnt; sched_sel_idx++) { + h->initial_cpb_removal_delay[sched_sel_idx] = get_bits(&s->gb, sps->initial_cpb_removal_delay_length); + skip_bits(&s->gb, sps->initial_cpb_removal_delay_length); // initial_cpb_removal_delay_offset + } + } + + h->sei_buffering_period_present = 1; + return 0; +} + +int ff_h264_decode_sei(H264Context *h){ + MpegEncContext * const s = &h->s; + + while(get_bits_count(&s->gb) + 16 < s->gb.size_in_bits){ + int size, type; + + type=0; + do{ + type+= show_bits(&s->gb, 8); + }while(get_bits(&s->gb, 8) == 255); + + size=0; + do{ + size+= show_bits(&s->gb, 8); + }while(get_bits(&s->gb, 8) == 255); + + switch(type){ + case SEI_TYPE_PIC_TIMING: // Picture timing SEI + if(decode_picture_timing(h) < 0) + return -1; + break; + case SEI_TYPE_USER_DATA_UNREGISTERED: + if(decode_unregistered_user_data(h, size) < 0) + return -1; + break; + case SEI_TYPE_RECOVERY_POINT: + if(decode_recovery_point(h) < 0) + return -1; + break; + case SEI_BUFFERING_PERIOD: + if(decode_buffering_period(h) < 0) + return -1; + break; + default: + skip_bits(&s->gb, 8*size); + } + + //FIXME check bits here + align_get_bits(&s->gb); + } + + return 0; +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/h264data.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264data.h index 7d60abbd74..b3631da93b 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/h264data.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264data.h @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/h264data.h + * @file * @brief * H264 / AVC / MPEG4 part10 codec data table * @author Michael Niedermayer @@ -35,37 +35,9 @@ #include "h264.h" -static const AVRational pixel_aspect[17]={ - {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}, - {4, 3}, - {3, 2}, - {2, 1}, -}; - static const uint8_t golomb_to_pict_type[5]= {FF_P_TYPE, FF_B_TYPE, FF_I_TYPE, FF_SP_TYPE, FF_SI_TYPE}; -static const uint8_t chroma_qp[52]={ - 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,29,30,31,32,32,33,34,34,35,35,36,36,37,37, - 37,38,38,38,39,39,39,39 - -}; - static const uint8_t golomb_to_intra4x4_cbp[48]={ 47, 31, 15, 0, 23, 27, 29, 30, 7, 11, 13, 14, 39, 43, 45, 46, 16, 3, 5, 10, 12, 19, 21, 26, 28, 35, 37, 42, 44, 1, 2, 4, @@ -78,181 +50,6 @@ static const uint8_t golomb_to_inter_cbp[48]={ 17, 18, 20, 24, 19, 21, 26, 28, 23, 27, 29, 30, 22, 25, 38, 41 }; -static const uint8_t golomb_to_inter_cbp_gray[16]={ - 0, 1, 2, 4, 8, 3, 5,10,12,15, 7,11,13,14, 6, 9, -}; - -static const uint8_t golomb_to_intra4x4_cbp_gray[16]={ -15, 0, 7,11,13,14, 3, 5,10,12, 1, 2, 4, 8, 6, 9, -}; - -static const uint8_t chroma_dc_coeff_token_len[4*5]={ - 2, 0, 0, 0, - 6, 1, 0, 0, - 6, 6, 3, 0, - 6, 7, 7, 6, - 6, 8, 8, 7, -}; - -static const uint8_t chroma_dc_coeff_token_bits[4*5]={ - 1, 0, 0, 0, - 7, 1, 0, 0, - 4, 6, 1, 0, - 3, 3, 2, 5, - 2, 3, 2, 0, -}; - -static const uint8_t coeff_token_len[4][4*17]={ -{ - 1, 0, 0, 0, - 6, 2, 0, 0, 8, 6, 3, 0, 9, 8, 7, 5, 10, 9, 8, 6, - 11,10, 9, 7, 13,11,10, 8, 13,13,11, 9, 13,13,13,10, - 14,14,13,11, 14,14,14,13, 15,15,14,14, 15,15,15,14, - 16,15,15,15, 16,16,16,15, 16,16,16,16, 16,16,16,16, -}, -{ - 2, 0, 0, 0, - 6, 2, 0, 0, 6, 5, 3, 0, 7, 6, 6, 4, 8, 6, 6, 4, - 8, 7, 7, 5, 9, 8, 8, 6, 11, 9, 9, 6, 11,11,11, 7, - 12,11,11, 9, 12,12,12,11, 12,12,12,11, 13,13,13,12, - 13,13,13,13, 13,14,13,13, 14,14,14,13, 14,14,14,14, -}, -{ - 4, 0, 0, 0, - 6, 4, 0, 0, 6, 5, 4, 0, 6, 5, 5, 4, 7, 5, 5, 4, - 7, 5, 5, 4, 7, 6, 6, 4, 7, 6, 6, 4, 8, 7, 7, 5, - 8, 8, 7, 6, 9, 8, 8, 7, 9, 9, 8, 8, 9, 9, 9, 8, - 10, 9, 9, 9, 10,10,10,10, 10,10,10,10, 10,10,10,10, -}, -{ - 6, 0, 0, 0, - 6, 6, 0, 0, 6, 6, 6, 0, 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, -} -}; - -static const uint8_t coeff_token_bits[4][4*17]={ -{ - 1, 0, 0, 0, - 5, 1, 0, 0, 7, 4, 1, 0, 7, 6, 5, 3, 7, 6, 5, 3, - 7, 6, 5, 4, 15, 6, 5, 4, 11,14, 5, 4, 8,10,13, 4, - 15,14, 9, 4, 11,10,13,12, 15,14, 9,12, 11,10,13, 8, - 15, 1, 9,12, 11,14,13, 8, 7,10, 9,12, 4, 6, 5, 8, -}, -{ - 3, 0, 0, 0, - 11, 2, 0, 0, 7, 7, 3, 0, 7,10, 9, 5, 7, 6, 5, 4, - 4, 6, 5, 6, 7, 6, 5, 8, 15, 6, 5, 4, 11,14,13, 4, - 15,10, 9, 4, 11,14,13,12, 8,10, 9, 8, 15,14,13,12, - 11,10, 9,12, 7,11, 6, 8, 9, 8,10, 1, 7, 6, 5, 4, -}, -{ - 15, 0, 0, 0, - 15,14, 0, 0, 11,15,13, 0, 8,12,14,12, 15,10,11,11, - 11, 8, 9,10, 9,14,13, 9, 8,10, 9, 8, 15,14,13,13, - 11,14,10,12, 15,10,13,12, 11,14, 9,12, 8,10,13, 8, - 13, 7, 9,12, 9,12,11,10, 5, 8, 7, 6, 1, 4, 3, 2, -}, -{ - 3, 0, 0, 0, - 0, 1, 0, 0, 4, 5, 6, 0, 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, -} -}; - -static const uint8_t total_zeros_len[16][16]= { - {1,3,3,4,4,5,5,6,6,7,7,8,8,9,9,9}, - {3,3,3,3,3,4,4,4,4,5,5,6,6,6,6}, - {4,3,3,3,4,4,3,3,4,5,5,6,5,6}, - {5,3,4,4,3,3,3,4,3,4,5,5,5}, - {4,4,4,3,3,3,3,3,4,5,4,5}, - {6,5,3,3,3,3,3,3,4,3,6}, - {6,5,3,3,3,2,3,4,3,6}, - {6,4,5,3,2,2,3,3,6}, - {6,6,4,2,2,3,2,5}, - {5,5,3,2,2,2,4}, - {4,4,3,3,1,3}, - {4,4,2,1,3}, - {3,3,1,2}, - {2,2,1}, - {1,1}, -}; - -static const uint8_t total_zeros_bits[16][16]= { - {1,3,2,3,2,3,2,3,2,3,2,3,2,3,2,1}, - {7,6,5,4,3,5,4,3,2,3,2,3,2,1,0}, - {5,7,6,5,4,3,4,3,2,3,2,1,1,0}, - {3,7,5,4,6,5,4,3,3,2,2,1,0}, - {5,4,3,7,6,5,4,3,2,1,1,0}, - {1,1,7,6,5,4,3,2,1,1,0}, - {1,1,5,4,3,3,2,1,1,0}, - {1,1,1,3,3,2,2,1,0}, - {1,0,1,3,2,1,1,1}, - {1,0,1,3,2,1,1}, - {0,1,1,2,1,3}, - {0,1,1,1,1}, - {0,1,1,1}, - {0,1,1}, - {0,1}, -}; - -static const uint8_t chroma_dc_total_zeros_len[3][4]= { - { 1, 2, 3, 3,}, - { 1, 2, 2, 0,}, - { 1, 1, 0, 0,}, -}; - -static const uint8_t chroma_dc_total_zeros_bits[3][4]= { - { 1, 1, 1, 0,}, - { 1, 1, 0, 0,}, - { 1, 0, 0, 0,}, -}; - -static const uint8_t run_len[7][16]={ - {1,1}, - {1,2,2}, - {2,2,2,2}, - {2,2,2,3,3}, - {2,2,3,3,3,3}, - {2,3,3,3,3,3,3}, - {3,3,3,3,3,3,3,4,5,6,7,8,9,10,11}, -}; - -static const uint8_t run_bits[7][16]={ - {1,0}, - {1,1,0}, - {3,2,1,0}, - {3,2,1,1,0}, - {3,2,3,2,1,0}, - {3,0,1,3,2,5,4}, - {7,6,5,4,3,2,1,1,1,1,1,1,1,1,1}, -}; - -/* -o-o o-o - / / / -o-o o-o - ,---' -o-o o-o - / / / -o-o o-o -*/ - -static const uint8_t scan8[16 + 2*4]={ - 4+1*8, 5+1*8, 4+2*8, 5+2*8, - 6+1*8, 7+1*8, 6+2*8, 7+2*8, - 4+3*8, 5+3*8, 4+4*8, 5+4*8, - 6+3*8, 7+3*8, 6+4*8, 7+4*8, - 1+1*8, 2+1*8, - 1+2*8, 2+2*8, - 1+4*8, 2+4*8, - 1+5*8, 2+5*8, -}; - static const uint8_t zigzag_scan[16]={ 0+0*4, 1+0*4, 0+1*4, 0+2*4, 1+1*4, 2+0*4, 3+0*4, 2+1*4, @@ -400,7 +197,7 @@ static const PMbInfo p_sub_mb_type_info[4]={ }; static const PMbInfo b_mb_type_info[23]={ -{MB_TYPE_DIRECT2 , 1, }, +{MB_TYPE_DIRECT2|MB_TYPE_L0L1 , 1, }, {MB_TYPE_16x16|MB_TYPE_P0L0 , 1, }, {MB_TYPE_16x16 |MB_TYPE_P0L1 , 1, }, {MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1 , 1, }, @@ -441,38 +238,6 @@ static const PMbInfo b_sub_mb_type_info[13]={ {MB_TYPE_8x8 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 4, }, }; -static const uint8_t default_scaling4[2][16]={ -{ 6,13,20,28, - 13,20,28,32, - 20,28,32,37, - 28,32,37,42 -},{ - 10,14,20,24, - 14,20,24,27, - 20,24,27,30, - 24,27,30,34 -}}; - -static const uint8_t default_scaling8[2][64]={ -{ 6,10,13,16,18,23,25,27, - 10,11,16,18,23,25,27,29, - 13,16,18,23,25,27,29,31, - 16,18,23,25,27,29,31,33, - 18,23,25,27,29,31,33,36, - 23,25,27,29,31,33,36,38, - 25,27,29,31,33,36,38,40, - 27,29,31,33,36,38,40,42 -},{ - 9,13,15,17,19,21,22,24, - 13,13,17,19,21,22,24,25, - 15,17,19,21,22,24,25,27, - 17,19,21,22,24,25,27,28, - 19,21,22,24,25,27,28,30, - 21,22,24,25,27,28,30,32, - 22,24,25,27,28,30,32,33, - 24,25,27,28,30,32,33,35 -}}; - static const uint8_t dequant4_coeff_init[6][3]={ {10,13,16}, {11,14,18}, @@ -494,714 +259,4 @@ static const uint8_t dequant8_coeff_init[6][6]={ {36,32,58,34,46,43}, }; - -/* Deblocking filter (p153) */ -static const uint8_t alpha_table[52*3] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 4, 4, 5, 6, - 7, 8, 9, 10, 12, 13, 15, 17, 20, 22, - 25, 28, 32, 36, 40, 45, 50, 56, 63, 71, - 80, 90,101,113,127,144,162,182,203,226, - 255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255, -}; -static const uint8_t beta_table[52*3] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 2, 2, 2, 3, - 3, 3, 3, 4, 4, 4, 6, 6, 7, 7, - 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, - 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, - 18, 18, - 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, - 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, - 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, - 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, -}; -static const uint8_t tc0_table[52*3][4] = { - {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, - {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, - {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, - {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, - {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, - {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, - {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, - {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, - {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, - {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, - {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, - {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 0 }, {-1, 0, 0, 1 }, - {-1, 0, 0, 1 }, {-1, 0, 0, 1 }, {-1, 0, 0, 1 }, {-1, 0, 1, 1 }, {-1, 0, 1, 1 }, {-1, 1, 1, 1 }, - {-1, 1, 1, 1 }, {-1, 1, 1, 1 }, {-1, 1, 1, 1 }, {-1, 1, 1, 2 }, {-1, 1, 1, 2 }, {-1, 1, 1, 2 }, - {-1, 1, 1, 2 }, {-1, 1, 2, 3 }, {-1, 1, 2, 3 }, {-1, 2, 2, 3 }, {-1, 2, 2, 4 }, {-1, 2, 3, 4 }, - {-1, 2, 3, 4 }, {-1, 3, 3, 5 }, {-1, 3, 4, 6 }, {-1, 3, 4, 6 }, {-1, 4, 5, 7 }, {-1, 4, 5, 8 }, - {-1, 4, 6, 9 }, {-1, 5, 7,10 }, {-1, 6, 8,11 }, {-1, 6, 8,13 }, {-1, 7,10,14 }, {-1, 8,11,16 }, - {-1, 9,12,18 }, {-1,10,13,20 }, {-1,11,15,23 }, {-1,13,17,25 }, - {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, - {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, - {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, - {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, - {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, - {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, - {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, - {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, - {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, -}; - -/* Cabac pre state table */ - -static const int8_t cabac_context_init_I[460][2] = -{ - /* 0 - 10 */ - { 20, -15 }, { 2, 54 }, { 3, 74 }, { 20, -15 }, - { 2, 54 }, { 3, 74 }, { -28,127 }, { -23, 104 }, - { -6, 53 }, { -1, 54 }, { 7, 51 }, - - /* 11 - 23 unsused for I */ - { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, - { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, - { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, - { 0, 0 }, - - /* 24- 39 */ - { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, - { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, - { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, - { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, - - /* 40 - 53 */ - { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, - { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, - { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, - { 0, 0 }, { 0, 0 }, - - /* 54 - 59 */ - { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, - { 0, 0 }, { 0, 0 }, - - /* 60 - 69 */ - { 0, 41 }, { 0, 63 }, { 0, 63 }, { 0, 63 }, - { -9, 83 }, { 4, 86 }, { 0, 97 }, { -7, 72 }, - { 13, 41 }, { 3, 62 }, - - /* 70 -> 87 */ - { 0, 11 }, { 1, 55 }, { 0, 69 }, { -17, 127 }, - { -13, 102 },{ 0, 82 }, { -7, 74 }, { -21, 107 }, - { -27, 127 },{ -31, 127 },{ -24, 127 }, { -18, 95 }, - { -27, 127 },{ -21, 114 },{ -30, 127 }, { -17, 123 }, - { -12, 115 },{ -16, 122 }, - - /* 88 -> 104 */ - { -11, 115 },{ -12, 63 }, { -2, 68 }, { -15, 84 }, - { -13, 104 },{ -3, 70 }, { -8, 93 }, { -10, 90 }, - { -30, 127 },{ -1, 74 }, { -6, 97 }, { -7, 91 }, - { -20, 127 },{ -4, 56 }, { -5, 82 }, { -7, 76 }, - { -22, 125 }, - - /* 105 -> 135 */ - { -7, 93 }, { -11, 87 }, { -3, 77 }, { -5, 71 }, - { -4, 63 }, { -4, 68 }, { -12, 84 }, { -7, 62 }, - { -7, 65 }, { 8, 61 }, { 5, 56 }, { -2, 66 }, - { 1, 64 }, { 0, 61 }, { -2, 78 }, { 1, 50 }, - { 7, 52 }, { 10, 35 }, { 0, 44 }, { 11, 38 }, - { 1, 45 }, { 0, 46 }, { 5, 44 }, { 31, 17 }, - { 1, 51 }, { 7, 50 }, { 28, 19 }, { 16, 33 }, - { 14, 62 }, { -13, 108 },{ -15, 100 }, - - /* 136 -> 165 */ - { -13, 101 },{ -13, 91 }, { -12, 94 }, { -10, 88 }, - { -16, 84 }, { -10, 86 }, { -7, 83 }, { -13, 87 }, - { -19, 94 }, { 1, 70 }, { 0, 72 }, { -5, 74 }, - { 18, 59 }, { -8, 102 }, { -15, 100 }, { 0, 95 }, - { -4, 75 }, { 2, 72 }, { -11, 75 }, { -3, 71 }, - { 15, 46 }, { -13, 69 }, { 0, 62 }, { 0, 65 }, - { 21, 37 }, { -15, 72 }, { 9, 57 }, { 16, 54 }, - { 0, 62 }, { 12, 72 }, - - /* 166 -> 196 */ - { 24, 0 }, { 15, 9 }, { 8, 25 }, { 13, 18 }, - { 15, 9 }, { 13, 19 }, { 10, 37 }, { 12, 18 }, - { 6, 29 }, { 20, 33 }, { 15, 30 }, { 4, 45 }, - { 1, 58 }, { 0, 62 }, { 7, 61 }, { 12, 38 }, - { 11, 45 }, { 15, 39 }, { 11, 42 }, { 13, 44 }, - { 16, 45 }, { 12, 41 }, { 10, 49 }, { 30, 34 }, - { 18, 42 }, { 10, 55 }, { 17, 51 }, { 17, 46 }, - { 0, 89 }, { 26, -19 }, { 22, -17 }, - - /* 197 -> 226 */ - { 26, -17 }, { 30, -25 }, { 28, -20 }, { 33, -23 }, - { 37, -27 }, { 33, -23 }, { 40, -28 }, { 38, -17 }, - { 33, -11 }, { 40, -15 }, { 41, -6 }, { 38, 1 }, - { 41, 17 }, { 30, -6 }, { 27, 3 }, { 26, 22 }, - { 37, -16 }, { 35, -4 }, { 38, -8 }, { 38, -3 }, - { 37, 3 }, { 38, 5 }, { 42, 0 }, { 35, 16 }, - { 39, 22 }, { 14, 48 }, { 27, 37 }, { 21, 60 }, - { 12, 68 }, { 2, 97 }, - - /* 227 -> 251 */ - { -3, 71 }, { -6, 42 }, { -5, 50 }, { -3, 54 }, - { -2, 62 }, { 0, 58 }, { 1, 63 }, { -2, 72 }, - { -1, 74 }, { -9, 91 }, { -5, 67 }, { -5, 27 }, - { -3, 39 }, { -2, 44 }, { 0, 46 }, { -16, 64 }, - { -8, 68 }, { -10, 78 }, { -6, 77 }, { -10, 86 }, - { -12, 92 }, { -15, 55 }, { -10, 60 }, { -6, 62 }, - { -4, 65 }, - - /* 252 -> 275 */ - { -12, 73 }, { -8, 76 }, { -7, 80 }, { -9, 88 }, - { -17, 110 },{ -11, 97 }, { -20, 84 }, { -11, 79 }, - { -6, 73 }, { -4, 74 }, { -13, 86 }, { -13, 96 }, - { -11, 97 }, { -19, 117 },{ -8, 78 }, { -5, 33 }, - { -4, 48 }, { -2, 53 }, { -3, 62 }, { -13, 71 }, - { -10, 79 }, { -12, 86 }, { -13, 90 }, { -14, 97 }, - - /* 276 a bit special (not used, bypass is used instead) */ - { 0, 0 }, - - /* 277 -> 307 */ - { -6, 93 }, { -6, 84 }, { -8, 79 }, { 0, 66 }, - { -1, 71 }, { 0, 62 }, { -2, 60 }, { -2, 59 }, - { -5, 75 }, { -3, 62 }, { -4, 58 }, { -9, 66 }, - { -1, 79 }, { 0, 71 }, { 3, 68 }, { 10, 44 }, - { -7, 62 }, { 15, 36 }, { 14, 40 }, { 16, 27 }, - { 12, 29 }, { 1, 44 }, { 20, 36 }, { 18, 32 }, - { 5, 42 }, { 1, 48 }, { 10, 62 }, { 17, 46 }, - { 9, 64 }, { -12, 104 },{ -11, 97 }, - - /* 308 -> 337 */ - { -16, 96 }, { -7, 88 }, { -8, 85 }, { -7, 85 }, - { -9, 85 }, { -13, 88 }, { 4, 66 }, { -3, 77 }, - { -3, 76 }, { -6, 76 }, { 10, 58 }, { -1, 76 }, - { -1, 83 }, { -7, 99 }, { -14, 95 }, { 2, 95 }, - { 0, 76 }, { -5, 74 }, { 0, 70 }, { -11, 75 }, - { 1, 68 }, { 0, 65 }, { -14, 73 }, { 3, 62 }, - { 4, 62 }, { -1, 68 }, { -13, 75 }, { 11, 55 }, - { 5, 64 }, { 12, 70 }, - - /* 338 -> 368 */ - { 15, 6 }, { 6, 19 }, { 7, 16 }, { 12, 14 }, - { 18, 13 }, { 13, 11 }, { 13, 15 }, { 15, 16 }, - { 12, 23 }, { 13, 23 }, { 15, 20 }, { 14, 26 }, - { 14, 44 }, { 17, 40 }, { 17, 47 }, { 24, 17 }, - { 21, 21 }, { 25, 22 }, { 31, 27 }, { 22, 29 }, - { 19, 35 }, { 14, 50 }, { 10, 57 }, { 7, 63 }, - { -2, 77 }, { -4, 82 }, { -3, 94 }, { 9, 69 }, - { -12, 109 },{ 36, -35 }, { 36, -34 }, - - /* 369 -> 398 */ - { 32, -26 }, { 37, -30 }, { 44, -32 }, { 34, -18 }, - { 34, -15 }, { 40, -15 }, { 33, -7 }, { 35, -5 }, - { 33, 0 }, { 38, 2 }, { 33, 13 }, { 23, 35 }, - { 13, 58 }, { 29, -3 }, { 26, 0 }, { 22, 30 }, - { 31, -7 }, { 35, -15 }, { 34, -3 }, { 34, 3 }, - { 36, -1 }, { 34, 5 }, { 32, 11 }, { 35, 5 }, - { 34, 12 }, { 39, 11 }, { 30, 29 }, { 34, 26 }, - { 29, 39 }, { 19, 66 }, - - /* 399 -> 435 */ - { 31, 21 }, { 31, 31 }, { 25, 50 }, - { -17, 120 }, { -20, 112 }, { -18, 114 }, { -11, 85 }, - { -15, 92 }, { -14, 89 }, { -26, 71 }, { -15, 81 }, - { -14, 80 }, { 0, 68 }, { -14, 70 }, { -24, 56 }, - { -23, 68 }, { -24, 50 }, { -11, 74 }, { 23, -13 }, - { 26, -13 }, { 40, -15 }, { 49, -14 }, { 44, 3 }, - { 45, 6 }, { 44, 34 }, { 33, 54 }, { 19, 82 }, - { -3, 75 }, { -1, 23 }, { 1, 34 }, { 1, 43 }, - { 0, 54 }, { -2, 55 }, { 0, 61 }, { 1, 64 }, - { 0, 68 }, { -9, 92 }, - - /* 436 -> 459 */ - { -14, 106 }, { -13, 97 }, { -15, 90 }, { -12, 90 }, - { -18, 88 }, { -10, 73 }, { -9, 79 }, { -14, 86 }, - { -10, 73 }, { -10, 70 }, { -10, 69 }, { -5, 66 }, - { -9, 64 }, { -5, 58 }, { 2, 59 }, { 21, -10 }, - { 24, -11 }, { 28, -8 }, { 28, -1 }, { 29, 3 }, - { 29, 9 }, { 35, 20 }, { 29, 36 }, { 14, 67 } -}; - -static const int8_t cabac_context_init_PB[3][460][2] = -{ - /* i_cabac_init_idc == 0 */ - { - /* 0 - 10 */ - { 20, -15 }, { 2, 54 }, { 3, 74 }, { 20, -15 }, - { 2, 54 }, { 3, 74 }, { -28, 127 }, { -23, 104 }, - { -6, 53 }, { -1, 54 }, { 7, 51 }, - - /* 11 - 23 */ - { 23, 33 }, { 23, 2 }, { 21, 0 }, { 1, 9 }, - { 0, 49 }, { -37, 118 }, { 5, 57 }, { -13, 78 }, - { -11, 65 }, { 1, 62 }, { 12, 49 }, { -4, 73 }, - { 17, 50 }, - - /* 24 - 39 */ - { 18, 64 }, { 9, 43 }, { 29, 0 }, { 26, 67 }, - { 16, 90 }, { 9, 104 }, { -46, 127 }, { -20, 104 }, - { 1, 67 }, { -13, 78 }, { -11, 65 }, { 1, 62 }, - { -6, 86 }, { -17, 95 }, { -6, 61 }, { 9, 45 }, - - /* 40 - 53 */ - { -3, 69 }, { -6, 81 }, { -11, 96 }, { 6, 55 }, - { 7, 67 }, { -5, 86 }, { 2, 88 }, { 0, 58 }, - { -3, 76 }, { -10, 94 }, { 5, 54 }, { 4, 69 }, - { -3, 81 }, { 0, 88 }, - - /* 54 - 59 */ - { -7, 67 }, { -5, 74 }, { -4, 74 }, { -5, 80 }, - { -7, 72 }, { 1, 58 }, - - /* 60 - 69 */ - { 0, 41 }, { 0, 63 }, { 0, 63 }, { 0, 63 }, - { -9, 83 }, { 4, 86 }, { 0, 97 }, { -7, 72 }, - { 13, 41 }, { 3, 62 }, - - /* 70 - 87 */ - { 0, 45 }, { -4, 78 }, { -3, 96 }, { -27, 126 }, - { -28, 98 }, { -25, 101 }, { -23, 67 }, { -28, 82 }, - { -20, 94 }, { -16, 83 }, { -22, 110 }, { -21, 91 }, - { -18, 102 }, { -13, 93 }, { -29, 127 }, { -7, 92 }, - { -5, 89 }, { -7, 96 }, { -13, 108 }, { -3, 46 }, - { -1, 65 }, { -1, 57 }, { -9, 93 }, { -3, 74 }, - { -9, 92 }, { -8, 87 }, { -23, 126 }, { 5, 54 }, - { 6, 60 }, { 6, 59 }, { 6, 69 }, { -1, 48 }, - { 0, 68 }, { -4, 69 }, { -8, 88 }, - - /* 105 -> 165 */ - { -2, 85 }, { -6, 78 }, { -1, 75 }, { -7, 77 }, - { 2, 54 }, { 5, 50 }, { -3, 68 }, { 1, 50 }, - { 6, 42 }, { -4, 81 }, { 1, 63 }, { -4, 70 }, - { 0, 67 }, { 2, 57 }, { -2, 76 }, { 11, 35 }, - { 4, 64 }, { 1, 61 }, { 11, 35 }, { 18, 25 }, - { 12, 24 }, { 13, 29 }, { 13, 36 }, { -10, 93 }, - { -7, 73 }, { -2, 73 }, { 13, 46 }, { 9, 49 }, - { -7, 100 }, { 9, 53 }, { 2, 53 }, { 5, 53 }, - { -2, 61 }, { 0, 56 }, { 0, 56 }, { -13, 63 }, - { -5, 60 }, { -1, 62 }, { 4, 57 }, { -6, 69 }, - { 4, 57 }, { 14, 39 }, { 4, 51 }, { 13, 68 }, - { 3, 64 }, { 1, 61 }, { 9, 63 }, { 7, 50 }, - { 16, 39 }, { 5, 44 }, { 4, 52 }, { 11, 48 }, - { -5, 60 }, { -1, 59 }, { 0, 59 }, { 22, 33 }, - { 5, 44 }, { 14, 43 }, { -1, 78 }, { 0, 60 }, - { 9, 69 }, - - /* 166 - 226 */ - { 11, 28 }, { 2, 40 }, { 3, 44 }, { 0, 49 }, - { 0, 46 }, { 2, 44 }, { 2, 51 }, { 0, 47 }, - { 4, 39 }, { 2, 62 }, { 6, 46 }, { 0, 54 }, - { 3, 54 }, { 2, 58 }, { 4, 63 }, { 6, 51 }, - { 6, 57 }, { 7, 53 }, { 6, 52 }, { 6, 55 }, - { 11, 45 }, { 14, 36 }, { 8, 53 }, { -1, 82 }, - { 7, 55 }, { -3, 78 }, { 15, 46 }, { 22, 31 }, - { -1, 84 }, { 25, 7 }, { 30, -7 }, { 28, 3 }, - { 28, 4 }, { 32, 0 }, { 34, -1 }, { 30, 6 }, - { 30, 6 }, { 32, 9 }, { 31, 19 }, { 26, 27 }, - { 26, 30 }, { 37, 20 }, { 28, 34 }, { 17, 70 }, - { 1, 67 }, { 5, 59 }, { 9, 67 }, { 16, 30 }, - { 18, 32 }, { 18, 35 }, { 22, 29 }, { 24, 31 }, - { 23, 38 }, { 18, 43 }, { 20, 41 }, { 11, 63 }, - { 9, 59 }, { 9, 64 }, { -1, 94 }, { -2, 89 }, - { -9, 108 }, - - /* 227 - 275 */ - { -6, 76 }, { -2, 44 }, { 0, 45 }, { 0, 52 }, - { -3, 64 }, { -2, 59 }, { -4, 70 }, { -4, 75 }, - { -8, 82 }, { -17, 102 }, { -9, 77 }, { 3, 24 }, - { 0, 42 }, { 0, 48 }, { 0, 55 }, { -6, 59 }, - { -7, 71 }, { -12, 83 }, { -11, 87 }, { -30, 119 }, - { 1, 58 }, { -3, 29 }, { -1, 36 }, { 1, 38 }, - { 2, 43 }, { -6, 55 }, { 0, 58 }, { 0, 64 }, - { -3, 74 }, { -10, 90 }, { 0, 70 }, { -4, 29 }, - { 5, 31 }, { 7, 42 }, { 1, 59 }, { -2, 58 }, - { -3, 72 }, { -3, 81 }, { -11, 97 }, { 0, 58 }, - { 8, 5 }, { 10, 14 }, { 14, 18 }, { 13, 27 }, - { 2, 40 }, { 0, 58 }, { -3, 70 }, { -6, 79 }, - { -8, 85 }, - - /* 276 a bit special (not used, bypass is used instead) */ - { 0, 0 }, - - /* 277 - 337 */ - { -13, 106 }, { -16, 106 }, { -10, 87 }, { -21, 114 }, - { -18, 110 }, { -14, 98 }, { -22, 110 }, { -21, 106 }, - { -18, 103 }, { -21, 107 }, { -23, 108 }, { -26, 112 }, - { -10, 96 }, { -12, 95 }, { -5, 91 }, { -9, 93 }, - { -22, 94 }, { -5, 86 }, { 9, 67 }, { -4, 80 }, - { -10, 85 }, { -1, 70 }, { 7, 60 }, { 9, 58 }, - { 5, 61 }, { 12, 50 }, { 15, 50 }, { 18, 49 }, - { 17, 54 }, { 10, 41 }, { 7, 46 }, { -1, 51 }, - { 7, 49 }, { 8, 52 }, { 9, 41 }, { 6, 47 }, - { 2, 55 }, { 13, 41 }, { 10, 44 }, { 6, 50 }, - { 5, 53 }, { 13, 49 }, { 4, 63 }, { 6, 64 }, - { -2, 69 }, { -2, 59 }, { 6, 70 }, { 10, 44 }, - { 9, 31 }, { 12, 43 }, { 3, 53 }, { 14, 34 }, - { 10, 38 }, { -3, 52 }, { 13, 40 }, { 17, 32 }, - { 7, 44 }, { 7, 38 }, { 13, 50 }, { 10, 57 }, - { 26, 43 }, - - /* 338 - 398 */ - { 14, 11 }, { 11, 14 }, { 9, 11 }, { 18, 11 }, - { 21, 9 }, { 23, -2 }, { 32, -15 }, { 32, -15 }, - { 34, -21 }, { 39, -23 }, { 42, -33 }, { 41, -31 }, - { 46, -28 }, { 38, -12 }, { 21, 29 }, { 45, -24 }, - { 53, -45 }, { 48, -26 }, { 65, -43 }, { 43, -19 }, - { 39, -10 }, { 30, 9 }, { 18, 26 }, { 20, 27 }, - { 0, 57 }, { -14, 82 }, { -5, 75 }, { -19, 97 }, - { -35, 125 }, { 27, 0 }, { 28, 0 }, { 31, -4 }, - { 27, 6 }, { 34, 8 }, { 30, 10 }, { 24, 22 }, - { 33, 19 }, { 22, 32 }, { 26, 31 }, { 21, 41 }, - { 26, 44 }, { 23, 47 }, { 16, 65 }, { 14, 71 }, - { 8, 60 }, { 6, 63 }, { 17, 65 }, { 21, 24 }, - { 23, 20 }, { 26, 23 }, { 27, 32 }, { 28, 23 }, - { 28, 24 }, { 23, 40 }, { 24, 32 }, { 28, 29 }, - { 23, 42 }, { 19, 57 }, { 22, 53 }, { 22, 61 }, - { 11, 86 }, - - /* 399 - 435 */ - { 12, 40 }, { 11, 51 }, { 14, 59 }, - { -4, 79 }, { -7, 71 }, { -5, 69 }, { -9, 70 }, - { -8, 66 }, { -10, 68 }, { -19, 73 }, { -12, 69 }, - { -16, 70 }, { -15, 67 }, { -20, 62 }, { -19, 70 }, - { -16, 66 }, { -22, 65 }, { -20, 63 }, { 9, -2 }, - { 26, -9 }, { 33, -9 }, { 39, -7 }, { 41, -2 }, - { 45, 3 }, { 49, 9 }, { 45, 27 }, { 36, 59 }, - { -6, 66 }, { -7, 35 }, { -7, 42 }, { -8, 45 }, - { -5, 48 }, { -12, 56 }, { -6, 60 }, { -5, 62 }, - { -8, 66 }, { -8, 76 }, - - /* 436 - 459 */ - { -5, 85 }, { -6, 81 }, { -10, 77 }, { -7, 81 }, - { -17, 80 }, { -18, 73 }, { -4, 74 }, { -10, 83 }, - { -9, 71 }, { -9, 67 }, { -1, 61 }, { -8, 66 }, - { -14, 66 }, { 0, 59 }, { 2, 59 }, { 21, -13 }, - { 33, -14 }, { 39, -7 }, { 46, -2 }, { 51, 2 }, - { 60, 6 }, { 61, 17 }, { 55, 34 }, { 42, 62 }, - }, - - /* i_cabac_init_idc == 1 */ - { - /* 0 - 10 */ - { 20, -15 }, { 2, 54 }, { 3, 74 }, { 20, -15 }, - { 2, 54 }, { 3, 74 }, { -28, 127 }, { -23, 104 }, - { -6, 53 }, { -1, 54 }, { 7, 51 }, - - /* 11 - 23 */ - { 22, 25 }, { 34, 0 }, { 16, 0 }, { -2, 9 }, - { 4, 41 }, { -29, 118 }, { 2, 65 }, { -6, 71 }, - { -13, 79 }, { 5, 52 }, { 9, 50 }, { -3, 70 }, - { 10, 54 }, - - /* 24 - 39 */ - { 26, 34 }, { 19, 22 }, { 40, 0 }, { 57, 2 }, - { 41, 36 }, { 26, 69 }, { -45, 127 }, { -15, 101 }, - { -4, 76 }, { -6, 71 }, { -13, 79 }, { 5, 52 }, - { 6, 69 }, { -13, 90 }, { 0, 52 }, { 8, 43 }, - - /* 40 - 53 */ - { -2, 69 },{ -5, 82 },{ -10, 96 },{ 2, 59 }, - { 2, 75 },{ -3, 87 },{ -3, 100 },{ 1, 56 }, - { -3, 74 },{ -6, 85 },{ 0, 59 },{ -3, 81 }, - { -7, 86 },{ -5, 95 }, - - /* 54 - 59 */ - { -1, 66 },{ -1, 77 },{ 1, 70 },{ -2, 86 }, - { -5, 72 },{ 0, 61 }, - - /* 60 - 69 */ - { 0, 41 }, { 0, 63 }, { 0, 63 }, { 0, 63 }, - { -9, 83 }, { 4, 86 }, { 0, 97 }, { -7, 72 }, - { 13, 41 }, { 3, 62 }, - - /* 70 - 104 */ - { 13, 15 }, { 7, 51 }, { 2, 80 }, { -39, 127 }, - { -18, 91 }, { -17, 96 }, { -26, 81 }, { -35, 98 }, - { -24, 102 }, { -23, 97 }, { -27, 119 }, { -24, 99 }, - { -21, 110 }, { -18, 102 }, { -36, 127 }, { 0, 80 }, - { -5, 89 }, { -7, 94 }, { -4, 92 }, { 0, 39 }, - { 0, 65 }, { -15, 84 }, { -35, 127 }, { -2, 73 }, - { -12, 104 }, { -9, 91 }, { -31, 127 }, { 3, 55 }, - { 7, 56 }, { 7, 55 }, { 8, 61 }, { -3, 53 }, - { 0, 68 }, { -7, 74 }, { -9, 88 }, - - /* 105 -> 165 */ - { -13, 103 }, { -13, 91 }, { -9, 89 }, { -14, 92 }, - { -8, 76 }, { -12, 87 }, { -23, 110 }, { -24, 105 }, - { -10, 78 }, { -20, 112 }, { -17, 99 }, { -78, 127 }, - { -70, 127 }, { -50, 127 }, { -46, 127 }, { -4, 66 }, - { -5, 78 }, { -4, 71 }, { -8, 72 }, { 2, 59 }, - { -1, 55 }, { -7, 70 }, { -6, 75 }, { -8, 89 }, - { -34, 119 }, { -3, 75 }, { 32, 20 }, { 30, 22 }, - { -44, 127 }, { 0, 54 }, { -5, 61 }, { 0, 58 }, - { -1, 60 }, { -3, 61 }, { -8, 67 }, { -25, 84 }, - { -14, 74 }, { -5, 65 }, { 5, 52 }, { 2, 57 }, - { 0, 61 }, { -9, 69 }, { -11, 70 }, { 18, 55 }, - { -4, 71 }, { 0, 58 }, { 7, 61 }, { 9, 41 }, - { 18, 25 }, { 9, 32 }, { 5, 43 }, { 9, 47 }, - { 0, 44 }, { 0, 51 }, { 2, 46 }, { 19, 38 }, - { -4, 66 }, { 15, 38 }, { 12, 42 }, { 9, 34 }, - { 0, 89 }, - - /* 166 - 226 */ - { 4, 45 }, { 10, 28 }, { 10, 31 }, { 33, -11 }, - { 52, -43 }, { 18, 15 }, { 28, 0 }, { 35, -22 }, - { 38, -25 }, { 34, 0 }, { 39, -18 }, { 32, -12 }, - { 102, -94 }, { 0, 0 }, { 56, -15 }, { 33, -4 }, - { 29, 10 }, { 37, -5 }, { 51, -29 }, { 39, -9 }, - { 52, -34 }, { 69, -58 }, { 67, -63 }, { 44, -5 }, - { 32, 7 }, { 55, -29 }, { 32, 1 }, { 0, 0 }, - { 27, 36 }, { 33, -25 }, { 34, -30 }, { 36, -28 }, - { 38, -28 }, { 38, -27 }, { 34, -18 }, { 35, -16 }, - { 34, -14 }, { 32, -8 }, { 37, -6 }, { 35, 0 }, - { 30, 10 }, { 28, 18 }, { 26, 25 }, { 29, 41 }, - { 0, 75 }, { 2, 72 }, { 8, 77 }, { 14, 35 }, - { 18, 31 }, { 17, 35 }, { 21, 30 }, { 17, 45 }, - { 20, 42 }, { 18, 45 }, { 27, 26 }, { 16, 54 }, - { 7, 66 }, { 16, 56 }, { 11, 73 }, { 10, 67 }, - { -10, 116 }, - - /* 227 - 275 */ - { -23, 112 }, { -15, 71 }, { -7, 61 }, { 0, 53 }, - { -5, 66 }, { -11, 77 }, { -9, 80 }, { -9, 84 }, - { -10, 87 }, { -34, 127 }, { -21, 101 }, { -3, 39 }, - { -5, 53 }, { -7, 61 }, { -11, 75 }, { -15, 77 }, - { -17, 91 }, { -25, 107 }, { -25, 111 }, { -28, 122 }, - { -11, 76 }, { -10, 44 }, { -10, 52 }, { -10, 57 }, - { -9, 58 }, { -16, 72 }, { -7, 69 }, { -4, 69 }, - { -5, 74 }, { -9, 86 }, { 2, 66 }, { -9, 34 }, - { 1, 32 }, { 11, 31 }, { 5, 52 }, { -2, 55 }, - { -2, 67 }, { 0, 73 }, { -8, 89 }, { 3, 52 }, - { 7, 4 }, { 10, 8 }, { 17, 8 }, { 16, 19 }, - { 3, 37 }, { -1, 61 }, { -5, 73 }, { -1, 70 }, - { -4, 78 }, - - /* 276 a bit special (not used, bypass is used instead) */ - { 0, 0 }, - - /* 277 - 337 */ - { -21, 126 }, { -23, 124 }, { -20, 110 }, { -26, 126 }, - { -25, 124 }, { -17, 105 }, { -27, 121 }, { -27, 117 }, - { -17, 102 }, { -26, 117 }, { -27, 116 }, { -33, 122 }, - { -10, 95 }, { -14, 100 }, { -8, 95 }, { -17, 111 }, - { -28, 114 }, { -6, 89 }, { -2, 80 }, { -4, 82 }, - { -9, 85 }, { -8, 81 }, { -1, 72 }, { 5, 64 }, - { 1, 67 }, { 9, 56 }, { 0, 69 }, { 1, 69 }, - { 7, 69 }, { -7, 69 }, { -6, 67 }, { -16, 77 }, - { -2, 64 }, { 2, 61 }, { -6, 67 }, { -3, 64 }, - { 2, 57 }, { -3, 65 }, { -3, 66 }, { 0, 62 }, - { 9, 51 }, { -1, 66 }, { -2, 71 }, { -2, 75 }, - { -1, 70 }, { -9, 72 }, { 14, 60 }, { 16, 37 }, - { 0, 47 }, { 18, 35 }, { 11, 37 }, { 12, 41 }, - { 10, 41 }, { 2, 48 }, { 12, 41 }, { 13, 41 }, - { 0, 59 }, { 3, 50 }, { 19, 40 }, { 3, 66 }, - { 18, 50 }, - - /* 338 - 398 */ - { 19, -6 }, { 18, -6 }, { 14, 0 }, { 26, -12 }, - { 31, -16 }, { 33, -25 }, { 33, -22 }, { 37, -28 }, - { 39, -30 }, { 42, -30 }, { 47, -42 }, { 45, -36 }, - { 49, -34 }, { 41, -17 }, { 32, 9 }, { 69, -71 }, - { 63, -63 }, { 66, -64 }, { 77, -74 }, { 54, -39 }, - { 52, -35 }, { 41, -10 }, { 36, 0 }, { 40, -1 }, - { 30, 14 }, { 28, 26 }, { 23, 37 }, { 12, 55 }, - { 11, 65 }, { 37, -33 }, { 39, -36 }, { 40, -37 }, - { 38, -30 }, { 46, -33 }, { 42, -30 }, { 40, -24 }, - { 49, -29 }, { 38, -12 }, { 40, -10 }, { 38, -3 }, - { 46, -5 }, { 31, 20 }, { 29, 30 }, { 25, 44 }, - { 12, 48 }, { 11, 49 }, { 26, 45 }, { 22, 22 }, - { 23, 22 }, { 27, 21 }, { 33, 20 }, { 26, 28 }, - { 30, 24 }, { 27, 34 }, { 18, 42 }, { 25, 39 }, - { 18, 50 }, { 12, 70 }, { 21, 54 }, { 14, 71 }, - { 11, 83 }, - - /* 399 - 435 */ - { 25, 32 }, { 21, 49 }, { 21, 54 }, - { -5, 85 }, { -6, 81 }, { -10, 77 }, { -7, 81 }, - { -17, 80 }, { -18, 73 }, { -4, 74 }, { -10, 83 }, - { -9, 71 }, { -9, 67 }, { -1, 61 }, { -8, 66 }, - { -14, 66 }, { 0, 59 }, { 2, 59 }, { 17, -10 }, - { 32, -13 }, { 42, -9 }, { 49, -5 }, { 53, 0 }, - { 64, 3 }, { 68, 10 }, { 66, 27 }, { 47, 57 }, - { -5, 71 }, { 0, 24 }, { -1, 36 }, { -2, 42 }, - { -2, 52 }, { -9, 57 }, { -6, 63 }, { -4, 65 }, - { -4, 67 }, { -7, 82 }, - - /* 436 - 459 */ - { -3, 81 }, { -3, 76 }, { -7, 72 }, { -6, 78 }, - { -12, 72 }, { -14, 68 }, { -3, 70 }, { -6, 76 }, - { -5, 66 }, { -5, 62 }, { 0, 57 }, { -4, 61 }, - { -9, 60 }, { 1, 54 }, { 2, 58 }, { 17, -10 }, - { 32, -13 }, { 42, -9 }, { 49, -5 }, { 53, 0 }, - { 64, 3 }, { 68, 10 }, { 66, 27 }, { 47, 57 }, - }, - - /* i_cabac_init_idc == 2 */ - { - /* 0 - 10 */ - { 20, -15 }, { 2, 54 }, { 3, 74 }, { 20, -15 }, - { 2, 54 }, { 3, 74 }, { -28, 127 }, { -23, 104 }, - { -6, 53 }, { -1, 54 }, { 7, 51 }, - - /* 11 - 23 */ - { 29, 16 }, { 25, 0 }, { 14, 0 }, { -10, 51 }, - { -3, 62 }, { -27, 99 }, { 26, 16 }, { -4, 85 }, - { -24, 102 }, { 5, 57 }, { 6, 57 }, { -17, 73 }, - { 14, 57 }, - - /* 24 - 39 */ - { 20, 40 }, { 20, 10 }, { 29, 0 }, { 54, 0 }, - { 37, 42 }, { 12, 97 }, { -32, 127 }, { -22, 117 }, - { -2, 74 }, { -4, 85 }, { -24, 102 }, { 5, 57 }, - { -6, 93 }, { -14, 88 }, { -6, 44 }, { 4, 55 }, - - /* 40 - 53 */ - { -11, 89 },{ -15, 103 },{ -21, 116 },{ 19, 57 }, - { 20, 58 },{ 4, 84 },{ 6, 96 },{ 1, 63 }, - { -5, 85 },{ -13, 106 },{ 5, 63 },{ 6, 75 }, - { -3, 90 },{ -1, 101 }, - - /* 54 - 59 */ - { 3, 55 },{ -4, 79 },{ -2, 75 },{ -12, 97 }, - { -7, 50 },{ 1, 60 }, - - /* 60 - 69 */ - { 0, 41 }, { 0, 63 }, { 0, 63 }, { 0, 63 }, - { -9, 83 }, { 4, 86 }, { 0, 97 }, { -7, 72 }, - { 13, 41 }, { 3, 62 }, - - /* 70 - 104 */ - { 7, 34 }, { -9, 88 }, { -20, 127 }, { -36, 127 }, - { -17, 91 }, { -14, 95 }, { -25, 84 }, { -25, 86 }, - { -12, 89 }, { -17, 91 }, { -31, 127 }, { -14, 76 }, - { -18, 103 }, { -13, 90 }, { -37, 127 }, { 11, 80 }, - { 5, 76 }, { 2, 84 }, { 5, 78 }, { -6, 55 }, - { 4, 61 }, { -14, 83 }, { -37, 127 }, { -5, 79 }, - { -11, 104 }, { -11, 91 }, { -30, 127 }, { 0, 65 }, - { -2, 79 }, { 0, 72 }, { -4, 92 }, { -6, 56 }, - { 3, 68 }, { -8, 71 }, { -13, 98 }, - - /* 105 -> 165 */ - { -4, 86 }, { -12, 88 }, { -5, 82 }, { -3, 72 }, - { -4, 67 }, { -8, 72 }, { -16, 89 }, { -9, 69 }, - { -1, 59 }, { 5, 66 }, { 4, 57 }, { -4, 71 }, - { -2, 71 }, { 2, 58 }, { -1, 74 }, { -4, 44 }, - { -1, 69 }, { 0, 62 }, { -7, 51 }, { -4, 47 }, - { -6, 42 }, { -3, 41 }, { -6, 53 }, { 8, 76 }, - { -9, 78 }, { -11, 83 }, { 9, 52 }, { 0, 67 }, - { -5, 90 }, { 1, 67 }, { -15, 72 }, { -5, 75 }, - { -8, 80 }, { -21, 83 }, { -21, 64 }, { -13, 31 }, - { -25, 64 }, { -29, 94 }, { 9, 75 }, { 17, 63 }, - { -8, 74 }, { -5, 35 }, { -2, 27 }, { 13, 91 }, - { 3, 65 }, { -7, 69 }, { 8, 77 }, { -10, 66 }, - { 3, 62 }, { -3, 68 }, { -20, 81 }, { 0, 30 }, - { 1, 7 }, { -3, 23 }, { -21, 74 }, { 16, 66 }, - { -23, 124 }, { 17, 37 }, { 44, -18 }, { 50, -34 }, - { -22, 127 }, - - /* 166 - 226 */ - { 4, 39 }, { 0, 42 }, { 7, 34 }, { 11, 29 }, - { 8, 31 }, { 6, 37 }, { 7, 42 }, { 3, 40 }, - { 8, 33 }, { 13, 43 }, { 13, 36 }, { 4, 47 }, - { 3, 55 }, { 2, 58 }, { 6, 60 }, { 8, 44 }, - { 11, 44 }, { 14, 42 }, { 7, 48 }, { 4, 56 }, - { 4, 52 }, { 13, 37 }, { 9, 49 }, { 19, 58 }, - { 10, 48 }, { 12, 45 }, { 0, 69 }, { 20, 33 }, - { 8, 63 }, { 35, -18 }, { 33, -25 }, { 28, -3 }, - { 24, 10 }, { 27, 0 }, { 34, -14 }, { 52, -44 }, - { 39, -24 }, { 19, 17 }, { 31, 25 }, { 36, 29 }, - { 24, 33 }, { 34, 15 }, { 30, 20 }, { 22, 73 }, - { 20, 34 }, { 19, 31 }, { 27, 44 }, { 19, 16 }, - { 15, 36 }, { 15, 36 }, { 21, 28 }, { 25, 21 }, - { 30, 20 }, { 31, 12 }, { 27, 16 }, { 24, 42 }, - { 0, 93 }, { 14, 56 }, { 15, 57 }, { 26, 38 }, - { -24, 127 }, - - /* 227 - 275 */ - { -24, 115 }, { -22, 82 }, { -9, 62 }, { 0, 53 }, - { 0, 59 }, { -14, 85 }, { -13, 89 }, { -13, 94 }, - { -11, 92 }, { -29, 127 }, { -21, 100 }, { -14, 57 }, - { -12, 67 }, { -11, 71 }, { -10, 77 }, { -21, 85 }, - { -16, 88 }, { -23, 104 }, { -15, 98 }, { -37, 127 }, - { -10, 82 }, { -8, 48 }, { -8, 61 }, { -8, 66 }, - { -7, 70 }, { -14, 75 }, { -10, 79 }, { -9, 83 }, - { -12, 92 }, { -18, 108 }, { -4, 79 }, { -22, 69 }, - { -16, 75 }, { -2, 58 }, { 1, 58 }, { -13, 78 }, - { -9, 83 }, { -4, 81 }, { -13, 99 }, { -13, 81 }, - { -6, 38 }, { -13, 62 }, { -6, 58 }, { -2, 59 }, - { -16, 73 }, { -10, 76 }, { -13, 86 }, { -9, 83 }, - { -10, 87 }, - - /* 276 a bit special (not used, bypass is used instead) */ - { 0, 0 }, - - /* 277 - 337 */ - { -22, 127 }, { -25, 127 }, { -25, 120 }, { -27, 127 }, - { -19, 114 }, { -23, 117 }, { -25, 118 }, { -26, 117 }, - { -24, 113 }, { -28, 118 }, { -31, 120 }, { -37, 124 }, - { -10, 94 }, { -15, 102 }, { -10, 99 }, { -13, 106 }, - { -50, 127 }, { -5, 92 }, { 17, 57 }, { -5, 86 }, - { -13, 94 }, { -12, 91 }, { -2, 77 }, { 0, 71 }, - { -1, 73 }, { 4, 64 }, { -7, 81 }, { 5, 64 }, - { 15, 57 }, { 1, 67 }, { 0, 68 }, { -10, 67 }, - { 1, 68 }, { 0, 77 }, { 2, 64 }, { 0, 68 }, - { -5, 78 }, { 7, 55 }, { 5, 59 }, { 2, 65 }, - { 14, 54 }, { 15, 44 }, { 5, 60 }, { 2, 70 }, - { -2, 76 }, { -18, 86 }, { 12, 70 }, { 5, 64 }, - { -12, 70 }, { 11, 55 }, { 5, 56 }, { 0, 69 }, - { 2, 65 }, { -6, 74 }, { 5, 54 }, { 7, 54 }, - { -6, 76 }, { -11, 82 }, { -2, 77 }, { -2, 77 }, - { 25, 42 }, - - /* 338 - 398 */ - { 17, -13 }, { 16, -9 }, { 17, -12 }, { 27, -21 }, - { 37, -30 }, { 41, -40 }, { 42, -41 }, { 48, -47 }, - { 39, -32 }, { 46, -40 }, { 52, -51 }, { 46, -41 }, - { 52, -39 }, { 43, -19 }, { 32, 11 }, { 61, -55 }, - { 56, -46 }, { 62, -50 }, { 81, -67 }, { 45, -20 }, - { 35, -2 }, { 28, 15 }, { 34, 1 }, { 39, 1 }, - { 30, 17 }, { 20, 38 }, { 18, 45 }, { 15, 54 }, - { 0, 79 }, { 36, -16 }, { 37, -14 }, { 37, -17 }, - { 32, 1 }, { 34, 15 }, { 29, 15 }, { 24, 25 }, - { 34, 22 }, { 31, 16 }, { 35, 18 }, { 31, 28 }, - { 33, 41 }, { 36, 28 }, { 27, 47 }, { 21, 62 }, - { 18, 31 }, { 19, 26 }, { 36, 24 }, { 24, 23 }, - { 27, 16 }, { 24, 30 }, { 31, 29 }, { 22, 41 }, - { 22, 42 }, { 16, 60 }, { 15, 52 }, { 14, 60 }, - { 3, 78 }, { -16, 123 }, { 21, 53 }, { 22, 56 }, - { 25, 61 }, - - /* 399 - 435 */ - { 21, 33 }, { 19, 50 }, { 17, 61 }, - { -3, 78 }, { -8, 74 }, { -9, 72 }, { -10, 72 }, - { -18, 75 }, { -12, 71 }, { -11, 63 }, { -5, 70 }, - { -17, 75 }, { -14, 72 }, { -16, 67 }, { -8, 53 }, - { -14, 59 }, { -9, 52 }, { -11, 68 }, { 9, -2 }, - { 30, -10 }, { 31, -4 }, { 33, -1 }, { 33, 7 }, - { 31, 12 }, { 37, 23 }, { 31, 38 }, { 20, 64 }, - { -9, 71 }, { -7, 37 }, { -8, 44 }, { -11, 49 }, - { -10, 56 }, { -12, 59 }, { -8, 63 }, { -9, 67 }, - { -6, 68 }, { -10, 79 }, - - /* 436 - 459 */ - { -3, 78 }, { -8, 74 }, { -9, 72 }, { -10, 72 }, - { -18, 75 }, { -12, 71 }, { -11, 63 }, { -5, 70 }, - { -17, 75 }, { -14, 72 }, { -16, 67 }, { -8, 53 }, - { -14, 59 }, { -9, 52 }, { -11, 68 }, { 9, -2 }, - { 30, -10 }, { 31, -4 }, { 33, -1 }, { 33, 7 }, - { 31, 12 }, { 37, 23 }, { 31, 38 }, { 20, 64 }, - } -}; - -static const uint8_t sei_num_clock_ts_table[9]={ - 1, 1, 1, 2, 2, 3, 3, 2, 3 -}; - #endif /* AVCODEC_H264DATA_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/h264dsp.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264dsp.c new file mode 100644 index 0000000000..c01fc77c00 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264dsp.c @@ -0,0 +1,320 @@ +/* + * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder + * Copyright (c) 2003-2010 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 + */ + +/** + * @file + * H.264 / AVC / MPEG4 part10 DSP functions. + * @author Michael Niedermayer + */ + +#include +#include "avcodec.h" +#include "h264dsp.h" + +#define op_scale1(x) block[x] = av_clip_uint8( (block[x]*weight + offset) >> log2_denom ) +#define op_scale2(x) dst[x] = av_clip_uint8( (src[x]*weights + dst[x]*weightd + offset) >> (log2_denom+1)) +#define H264_WEIGHT(W,H) \ +static void weight_h264_pixels ## W ## x ## H ## _c(uint8_t *block, int stride, int log2_denom, int weight, int offset){ \ + int y; \ + offset <<= log2_denom; \ + if(log2_denom) offset += 1<<(log2_denom-1); \ + for(y=0; y> 1 ) ) >> 1) - p1, -tc0[i], tc0[i] ); + tc++; + } + if( FFABS( q2 - q0 ) < beta ) { + if(tc0[i]) + pix[ xstride] = q1 + av_clip( (( q2 + ( ( p0 + q0 + 1 ) >> 1 ) ) >> 1) - q1, -tc0[i], tc0[i] ); + tc++; + } + + i_delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); + pix[-xstride] = av_clip_uint8( p0 + i_delta ); /* p0' */ + pix[0] = av_clip_uint8( q0 - i_delta ); /* q0' */ + } + pix += ystride; + } + } +} +static void h264_v_loop_filter_luma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) +{ + h264_loop_filter_luma_c(pix, stride, 1, alpha, beta, tc0); +} +static void h264_h_loop_filter_luma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) +{ + h264_loop_filter_luma_c(pix, 1, stride, alpha, beta, tc0); +} + +static av_always_inline av_flatten void h264_loop_filter_luma_intra_c(uint8_t *pix, int xstride, int ystride, int alpha, int beta) +{ + int d; + for( d = 0; d < 16; d++ ) { + const int p2 = pix[-3*xstride]; + const int p1 = pix[-2*xstride]; + const int p0 = pix[-1*xstride]; + + const int q0 = pix[ 0*xstride]; + const int q1 = pix[ 1*xstride]; + const int q2 = pix[ 2*xstride]; + + if( FFABS( p0 - q0 ) < alpha && + FFABS( p1 - p0 ) < beta && + FFABS( q1 - q0 ) < beta ) { + + if(FFABS( p0 - q0 ) < (( alpha >> 2 ) + 2 )){ + if( FFABS( p2 - p0 ) < beta) + { + const int p3 = pix[-4*xstride]; + /* p0', p1', p2' */ + pix[-1*xstride] = ( p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4 ) >> 3; + pix[-2*xstride] = ( p2 + p1 + p0 + q0 + 2 ) >> 2; + pix[-3*xstride] = ( 2*p3 + 3*p2 + p1 + p0 + q0 + 4 ) >> 3; + } else { + /* p0' */ + pix[-1*xstride] = ( 2*p1 + p0 + q1 + 2 ) >> 2; + } + if( FFABS( q2 - q0 ) < beta) + { + const int q3 = pix[3*xstride]; + /* q0', q1', q2' */ + pix[0*xstride] = ( p1 + 2*p0 + 2*q0 + 2*q1 + q2 + 4 ) >> 3; + pix[1*xstride] = ( p0 + q0 + q1 + q2 + 2 ) >> 2; + pix[2*xstride] = ( 2*q3 + 3*q2 + q1 + q0 + p0 + 4 ) >> 3; + } else { + /* q0' */ + pix[0*xstride] = ( 2*q1 + q0 + p1 + 2 ) >> 2; + } + }else{ + /* p0', q0' */ + pix[-1*xstride] = ( 2*p1 + p0 + q1 + 2 ) >> 2; + pix[ 0*xstride] = ( 2*q1 + q0 + p1 + 2 ) >> 2; + } + } + pix += ystride; + } +} +static void h264_v_loop_filter_luma_intra_c(uint8_t *pix, int stride, int alpha, int beta) +{ + h264_loop_filter_luma_intra_c(pix, stride, 1, alpha, beta); +} +static void h264_h_loop_filter_luma_intra_c(uint8_t *pix, int stride, int alpha, int beta) +{ + h264_loop_filter_luma_intra_c(pix, 1, stride, alpha, beta); +} + +static av_always_inline av_flatten void h264_loop_filter_chroma_c(uint8_t *pix, int xstride, int ystride, int alpha, int beta, int8_t *tc0) +{ + int i, d; + for( i = 0; i < 4; i++ ) { + const int tc = tc0[i]; + if( tc <= 0 ) { + pix += 2*ystride; + continue; + } + for( d = 0; d < 2; d++ ) { + const int p0 = pix[-1*xstride]; + const int p1 = pix[-2*xstride]; + const int q0 = pix[0]; + const int q1 = pix[1*xstride]; + + if( FFABS( p0 - q0 ) < alpha && + FFABS( p1 - p0 ) < beta && + FFABS( q1 - q0 ) < beta ) { + + int delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); + + pix[-xstride] = av_clip_uint8( p0 + delta ); /* p0' */ + pix[0] = av_clip_uint8( q0 - delta ); /* q0' */ + } + pix += ystride; + } + } +} +static void h264_v_loop_filter_chroma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) +{ + h264_loop_filter_chroma_c(pix, stride, 1, alpha, beta, tc0); +} +static void h264_h_loop_filter_chroma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) +{ + h264_loop_filter_chroma_c(pix, 1, stride, alpha, beta, tc0); +} + +static av_always_inline av_flatten void h264_loop_filter_chroma_intra_c(uint8_t *pix, int xstride, int ystride, int alpha, int beta) +{ + int d; + for( d = 0; d < 8; d++ ) { + const int p0 = pix[-1*xstride]; + const int p1 = pix[-2*xstride]; + const int q0 = pix[0]; + const int q1 = pix[1*xstride]; + + if( FFABS( p0 - q0 ) < alpha && + FFABS( p1 - p0 ) < beta && + FFABS( q1 - q0 ) < beta ) { + + pix[-xstride] = ( 2*p1 + p0 + q1 + 2 ) >> 2; /* p0' */ + pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; /* q0' */ + } + pix += ystride; + } +} +static void h264_v_loop_filter_chroma_intra_c(uint8_t *pix, int stride, int alpha, int beta) +{ + h264_loop_filter_chroma_intra_c(pix, stride, 1, alpha, beta); +} +static void h264_h_loop_filter_chroma_intra_c(uint8_t *pix, int stride, int alpha, int beta) +{ + h264_loop_filter_chroma_intra_c(pix, 1, stride, alpha, beta); +} + +void ff_h264dsp_init(H264DSPContext *c) +{ + c->h264_idct_add= ff_h264_idct_add_c; + c->h264_idct8_add= ff_h264_idct8_add_c; + c->h264_idct_dc_add= ff_h264_idct_dc_add_c; + c->h264_idct8_dc_add= ff_h264_idct8_dc_add_c; + c->h264_idct_add16 = ff_h264_idct_add16_c; + c->h264_idct8_add4 = ff_h264_idct8_add4_c; + c->h264_idct_add8 = ff_h264_idct_add8_c; + c->h264_idct_add16intra= ff_h264_idct_add16intra_c; + + c->weight_h264_pixels_tab[0]= weight_h264_pixels16x16_c; + c->weight_h264_pixels_tab[1]= weight_h264_pixels16x8_c; + c->weight_h264_pixels_tab[2]= weight_h264_pixels8x16_c; + c->weight_h264_pixels_tab[3]= weight_h264_pixels8x8_c; + c->weight_h264_pixels_tab[4]= weight_h264_pixels8x4_c; + c->weight_h264_pixels_tab[5]= weight_h264_pixels4x8_c; + c->weight_h264_pixels_tab[6]= weight_h264_pixels4x4_c; + c->weight_h264_pixels_tab[7]= weight_h264_pixels4x2_c; + c->weight_h264_pixels_tab[8]= weight_h264_pixels2x4_c; + c->weight_h264_pixels_tab[9]= weight_h264_pixels2x2_c; + c->biweight_h264_pixels_tab[0]= biweight_h264_pixels16x16_c; + c->biweight_h264_pixels_tab[1]= biweight_h264_pixels16x8_c; + c->biweight_h264_pixels_tab[2]= biweight_h264_pixels8x16_c; + c->biweight_h264_pixels_tab[3]= biweight_h264_pixels8x8_c; + c->biweight_h264_pixels_tab[4]= biweight_h264_pixels8x4_c; + c->biweight_h264_pixels_tab[5]= biweight_h264_pixels4x8_c; + c->biweight_h264_pixels_tab[6]= biweight_h264_pixels4x4_c; + c->biweight_h264_pixels_tab[7]= biweight_h264_pixels4x2_c; + c->biweight_h264_pixels_tab[8]= biweight_h264_pixels2x4_c; + c->biweight_h264_pixels_tab[9]= biweight_h264_pixels2x2_c; + + c->h264_v_loop_filter_luma= h264_v_loop_filter_luma_c; + c->h264_h_loop_filter_luma= h264_h_loop_filter_luma_c; + c->h264_v_loop_filter_luma_intra= h264_v_loop_filter_luma_intra_c; + c->h264_h_loop_filter_luma_intra= h264_h_loop_filter_luma_intra_c; + c->h264_v_loop_filter_chroma= h264_v_loop_filter_chroma_c; + c->h264_h_loop_filter_chroma= h264_h_loop_filter_chroma_c; + c->h264_v_loop_filter_chroma_intra= h264_v_loop_filter_chroma_intra_c; + c->h264_h_loop_filter_chroma_intra= h264_h_loop_filter_chroma_intra_c; + c->h264_loop_filter_strength= NULL; + + if (ARCH_ARM) ff_h264dsp_init_arm(c); + if (HAVE_ALTIVEC) ff_h264dsp_init_ppc(c); + if (HAVE_MMX) ff_h264dsp_init_x86(c); +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/h264dsp.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264dsp.h new file mode 100644 index 0000000000..3d32a9c18f --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264dsp.h @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2003-2010 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 + */ + +/** + * @file + * H.264 DSP functions. + * @author Michael Niedermayer + */ + +#ifndef AVCODEC_H264DSP_H +#define AVCODEC_H264DSP_H + +#include +#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); + +/** + * 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]; + + /* loop filter */ + void (*h264_v_loop_filter_luma)(uint8_t *pix/*align 16*/, int stride, int alpha, int beta, int8_t *tc0); + void (*h264_h_loop_filter_luma)(uint8_t *pix/*align 4 */, int stride, int alpha, int beta, int8_t *tc0); + /* v/h_loop_filter_luma_intra: align 16 */ + void (*h264_v_loop_filter_luma_intra)(uint8_t *pix, int stride, int alpha, int beta); + void (*h264_h_loop_filter_luma_intra)(uint8_t *pix, int stride, int alpha, int beta); + void (*h264_v_loop_filter_chroma)(uint8_t *pix/*align 8*/, int stride, int alpha, int beta, int8_t *tc0); + void (*h264_h_loop_filter_chroma)(uint8_t *pix/*align 4*/, int stride, int alpha, int beta, int8_t *tc0); + void (*h264_v_loop_filter_chroma_intra)(uint8_t *pix/*align 8*/, int stride, int alpha, int beta); + void (*h264_h_loop_filter_chroma_intra)(uint8_t *pix/*align 8*/, int stride, int alpha, int beta); + // h264_loop_filter_strength: simd only. the C version is inlined in h264.c + void (*h264_loop_filter_strength)(int16_t bS[2][4][4], uint8_t nnz[40], int8_t ref[2][40], int16_t mv[2][40][2], + int bidir, int edges, int step, int mask_mv0, int mask_mv1, int field); + + /* IDCT */ + /* NOTE!!! if you implement any of h264_idct8_add, h264_idct8_add4 then you must implement all of them + NOTE!!! if you implement any of h264_idct_add, h264_idct_add16, h264_idct_add16intra, h264_idct_add8 then you must implement all of them + The reason for above, is that no 2 out of one list may use a different permutation. + */ + void (*h264_idct_add)(uint8_t *dst/*align 4*/, DCTELEM *block/*align 16*/, int stride); + void (*h264_idct8_add)(uint8_t *dst/*align 8*/, DCTELEM *block/*align 16*/, int stride); + void (*h264_idct_dc_add)(uint8_t *dst/*align 4*/, DCTELEM *block/*align 16*/, int stride); + void (*h264_idct8_dc_add)(uint8_t *dst/*align 8*/, DCTELEM *block/*align 16*/, int stride); + void (*h264_dct)(DCTELEM block[4][4]); + void (*h264_idct_add16)(uint8_t *dst/*align 16*/, const int *blockoffset, DCTELEM *block/*align 16*/, int stride, const uint8_t nnzc[6*8]); + void (*h264_idct8_add4)(uint8_t *dst/*align 16*/, const int *blockoffset, DCTELEM *block/*align 16*/, int stride, const uint8_t nnzc[6*8]); + void (*h264_idct_add8)(uint8_t **dst/*align 16*/, const int *blockoffset, DCTELEM *block/*align 16*/, int stride, const uint8_t nnzc[6*8]); + void (*h264_idct_add16intra)(uint8_t *dst/*align 16*/, const int *blockoffset, DCTELEM *block/*align 16*/, int stride, const uint8_t nnzc[6*8]); +}H264DSPContext; + +void ff_h264dsp_init(H264DSPContext *c); +void ff_h264dsp_init_arm(H264DSPContext *c); +void ff_h264dsp_init_ppc(H264DSPContext *c); +void ff_h264dsp_init_x86(H264DSPContext *c); + +#endif /* AVCODEC_H264DSP_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/h264dspenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264dspenc.c index 9dfa01b336..b65a2cc4a2 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/h264dspenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264dspenc.c @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/h264dspenc.c + * @file * H.264 encoder related DSP utils * */ @@ -71,7 +71,7 @@ static void h264_dct_c(DCTELEM block[4][4]) H264_DCT_PART2(3); } -void ff_h264dspenc_init(DSPContext* c, AVCodecContext *avctx) +av_cold void ff_h264dspenc_init(DSPContext* c, AVCodecContext *avctx) { c->h264_dct = h264_dct_c; } diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/h264enc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264enc.c index 5693336b55..ad874f3624 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/h264enc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264enc.c @@ -31,7 +31,7 @@ * @param dest the target buffer, dst+1 == src is allowed as a special case * @param destsize the length of the dst array * @param b2 the data which should be escaped - * @returns pointer to current position in the output buffer or NULL if an error occurred + * @return pointer to current position in the output buffer or NULL if an error occurred */ static uint8_t *h264_write_nal_unit(int nal_ref_idc, int nal_unit_type, uint8_t *dest, int *destsize, PutBitContext *b2) @@ -184,7 +184,7 @@ static inline int quantize_c(DCTELEM *block, uint8_t *scantable, int qscale, int intra, int separate_dc) { int i; - const int * const quant_3Btable = quant_coeff[qscale]; + const int * const quant_table = quant_coeff[qscale]; const int bias = intra ? (1 << QUANT_SHIFT) / 3 : (1 << QUANT_SHIFT) / 6; const unsigned int threshold1 = (1 << QUANT_SHIFT) - bias - 1; const unsigned int threshold2 = (threshold1 << 1); diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/h264idct.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264idct.c index 78fe431eb6..da5c6a5182 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/h264idct.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264idct.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/h264idct.c + * @file * H.264 IDCT. * @author Michael Niedermayer */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/h264pred.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264pred.c index 23db23f09a..9637b45427 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/h264pred.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264pred.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/h264pred.c + * @file * H.264 / AVC / MPEG4 part10 prediction functions. * @author Michael Niedermayer */ @@ -1172,4 +1172,6 @@ void ff_h264_pred_init(H264PredContext *h, int codec_id){ h->pred8x8_add [ HOR_PRED8x8]= pred8x8_horizontal_add_c; h->pred16x16_add[VERT_PRED8x8]= pred16x16_vertical_add_c; h->pred16x16_add[ HOR_PRED8x8]= pred16x16_horizontal_add_c; + + if (ARCH_ARM) ff_h264_pred_init_arm(h, codec_id); } diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/h264pred.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264pred.h index 32e9fb1531..c52aeaa257 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/h264pred.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/h264pred.h @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/h264pred.h + * @file * H.264 / AVC / MPEG4 prediction functions. * @author Michael Niedermayer */ @@ -84,5 +84,6 @@ typedef struct H264PredContext{ }H264PredContext; void ff_h264_pred_init(H264PredContext *h, int codec_id); +void ff_h264_pred_init_arm(H264PredContext *h, int codec_id); #endif /* AVCODEC_H264PRED_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/huffman.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/huffman.c index 10dd2b09d0..853fa64a48 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/huffman.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/huffman.c @@ -1,5 +1,5 @@ /** - * @file libavcodec/huffman.c + * @file * huffman tree builder and VLC generator * Copyright (c) 2006 Konstantin Shishkov * diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/huffman.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/huffman.h index d56c7274b0..3c08e6fb1b 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/huffman.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/huffman.h @@ -1,5 +1,5 @@ /** - * @file libavcodec/huffman.h + * @file * huffman tree builder and VLC generator * Copyright (C) 2007 Aurelien Jacobs * diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/huffyuv.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/huffyuv.c index 53142c074e..7764c35181 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/huffyuv.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/huffyuv.c @@ -24,7 +24,7 @@ */ /** - * @file libavcodec/huffyuv.c + * @file * huffyuv codec for libavcodec. */ @@ -39,10 +39,12 @@ #define B 3 #define G 2 #define R 1 +#define A 0 #else #define B 0 #define G 1 #define R 2 +#define A 3 #endif typedef enum Predictor{ @@ -129,47 +131,6 @@ static const unsigned char classic_add_chroma[256] = { 6, 12, 8, 10, 7, 9, 6, 4, 6, 2, 2, 3, 3, 3, 3, 2, }; -static inline int add_left_prediction(uint8_t *dst, uint8_t *src, int w, int acc){ - int i; - - for(i=0; itemp[i]= av_malloc(s->width + 16); } }else{ - for(i=0; i<2; i++){ - s->temp[i]= av_malloc(4*s->width + 16); - } + s->temp[0]= av_mallocz(4*s->width + 16); } } @@ -493,6 +452,9 @@ s->bgr32=1; if(s->version==2){ int method, interlace; + if (avctx->extradata_size < 4) + return -1; + method= ((uint8_t*)avctx->extradata)[0]; s->decorrelate= method&64 ? 1 : 0; s->predictor= method&63; @@ -503,7 +465,7 @@ s->bgr32=1; s->interlaced= (interlace==1) ? 1 : (interlace==2) ? 0 : s->interlaced; s->context= ((uint8_t*)avctx->extradata)[2] & 0x40 ? 1 : 0; - if(read_huffman_tables(s, ((uint8_t*)avctx->extradata)+4, avctx->extradata_size) < 0) + if(read_huffman_tables(s, ((uint8_t*)avctx->extradata)+4, avctx->extradata_size-4) < 0) return -1; }else{ switch(avctx->bits_per_coded_sample&7){ @@ -567,7 +529,7 @@ s->bgr32=1; #endif /* CONFIG_HUFFYUV_DECODER || CONFIG_FFVHUFF_DECODER */ #if CONFIG_HUFFYUV_ENCODER || CONFIG_FFVHUFF_ENCODER -static int store_table(HYuvContext *s, uint8_t *len, uint8_t *buf){ +static int store_table(HYuvContext *s, const uint8_t *len, uint8_t *buf){ int i; int index= 0; @@ -736,7 +698,7 @@ static void decode_422_bitstream(HYuvContext *s, int count){ count/=2; - if(count >= (s->gb.size_in_bits - get_bits_count(&s->gb))/(31*4)){ + if(count >= (get_bits_left(&s->gb))/(31*4)){ for(i=0; igb) < s->gb.size_in_bits; i++){ READ_2PIX(s->temp[0][2*i ], s->temp[1][i], 1); READ_2PIX(s->temp[0][2*i+1], s->temp[2][i], 2); @@ -754,7 +716,7 @@ static void decode_gray_bitstream(HYuvContext *s, int count){ count/=2; - if(count >= (s->gb.size_in_bits - get_bits_count(&s->gb))/(31*2)){ + if(count >= (get_bits_left(&s->gb))/(31*2)){ for(i=0; igb) < s->gb.size_in_bits; i++){ READ_2PIX(s->temp[0][2*i ], s->temp[0][2*i+1], 0); } @@ -879,7 +841,7 @@ static av_always_inline void decode_bgr_1(HYuvContext *s, int count, int decorre s->temp[0][4*i+R] = get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); } if(alpha) - get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); //?! + s->temp[0][4*i+A] = get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); } } @@ -983,6 +945,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac if (!s->bitstream_buffer) return AVERROR(ENOMEM); + memset(s->bitstream_buffer + buf_size, 0, FF_INPUT_BUFFER_PADDING_SIZE); s->dsp.bswap_buf((uint32_t*)s->bitstream_buffer, (const uint32_t*)buf, buf_size/4); if(p->data[0]) @@ -1035,10 +998,10 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac case LEFT: case PLANE: decode_422_bitstream(s, width-2); - lefty= add_left_prediction(p->data[0] + 2, s->temp[0], width-2, lefty); + lefty= s->dsp.add_hfyu_left_prediction(p->data[0] + 2, s->temp[0], width-2, lefty); if(!(s->flags&CODEC_FLAG_GRAY)){ - leftu= add_left_prediction(p->data[1] + 1, s->temp[1], width2-1, leftu); - leftv= add_left_prediction(p->data[2] + 1, s->temp[2], width2-1, leftv); + leftu= s->dsp.add_hfyu_left_prediction(p->data[1] + 1, s->temp[1], width2-1, leftu); + leftv= s->dsp.add_hfyu_left_prediction(p->data[2] + 1, s->temp[2], width2-1, leftv); } for(cy=y=1; yheight; y++,cy++){ @@ -1049,7 +1012,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac ydst= p->data[0] + p->linesize[0]*y; - lefty= add_left_prediction(ydst, s->temp[0], width, lefty); + lefty= s->dsp.add_hfyu_left_prediction(ydst, s->temp[0], width, lefty); if(s->predictor == PLANE){ if(y>s->interlaced) s->dsp.add_bytes(ydst, ydst - fake_ystride, width); @@ -1065,10 +1028,10 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac vdst= p->data[2] + p->linesize[2]*cy; decode_422_bitstream(s, width); - lefty= add_left_prediction(ydst, s->temp[0], width, lefty); + lefty= s->dsp.add_hfyu_left_prediction(ydst, s->temp[0], width, lefty); if(!(s->flags&CODEC_FLAG_GRAY)){ - leftu= add_left_prediction(udst, s->temp[1], width2, leftu); - leftv= add_left_prediction(vdst, s->temp[2], width2, leftv); + leftu= s->dsp.add_hfyu_left_prediction(udst, s->temp[1], width2, leftu); + leftv= s->dsp.add_hfyu_left_prediction(vdst, s->temp[2], width2, leftv); } if(s->predictor == PLANE){ if(cy>s->interlaced){ @@ -1086,10 +1049,10 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac case MEDIAN: /* first line except first 2 pixels is left predicted */ decode_422_bitstream(s, width-2); - lefty= add_left_prediction(p->data[0] + 2, s->temp[0], width-2, lefty); + lefty= s->dsp.add_hfyu_left_prediction(p->data[0] + 2, s->temp[0], width-2, lefty); if(!(s->flags&CODEC_FLAG_GRAY)){ - leftu= add_left_prediction(p->data[1] + 1, s->temp[1], width2-1, leftu); - leftv= add_left_prediction(p->data[2] + 1, s->temp[2], width2-1, leftv); + leftu= s->dsp.add_hfyu_left_prediction(p->data[1] + 1, s->temp[1], width2-1, leftu); + leftv= s->dsp.add_hfyu_left_prediction(p->data[2] + 1, s->temp[2], width2-1, leftv); } cy=y=1; @@ -1097,20 +1060,20 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac /* second line is left predicted for interlaced case */ if(s->interlaced){ decode_422_bitstream(s, width); - lefty= add_left_prediction(p->data[0] + p->linesize[0], s->temp[0], width, lefty); + lefty= s->dsp.add_hfyu_left_prediction(p->data[0] + p->linesize[0], s->temp[0], width, lefty); if(!(s->flags&CODEC_FLAG_GRAY)){ - leftu= add_left_prediction(p->data[1] + p->linesize[2], s->temp[1], width2, leftu); - leftv= add_left_prediction(p->data[2] + p->linesize[1], s->temp[2], width2, leftv); + leftu= s->dsp.add_hfyu_left_prediction(p->data[1] + p->linesize[2], s->temp[1], width2, leftu); + leftv= s->dsp.add_hfyu_left_prediction(p->data[2] + p->linesize[1], s->temp[2], width2, leftv); } y++; cy++; } /* next 4 pixels are left predicted too */ decode_422_bitstream(s, 4); - lefty= add_left_prediction(p->data[0] + fake_ystride, s->temp[0], 4, lefty); + lefty= s->dsp.add_hfyu_left_prediction(p->data[0] + fake_ystride, s->temp[0], 4, lefty); if(!(s->flags&CODEC_FLAG_GRAY)){ - leftu= add_left_prediction(p->data[1] + fake_ustride, s->temp[1], 2, leftu); - leftv= add_left_prediction(p->data[2] + fake_vstride, s->temp[2], 2, leftv); + leftu= s->dsp.add_hfyu_left_prediction(p->data[1] + fake_ustride, s->temp[1], 2, leftu); + leftv= s->dsp.add_hfyu_left_prediction(p->data[2] + fake_vstride, s->temp[2], 2, leftv); } /* next line except the first 4 pixels is median predicted */ @@ -1158,11 +1121,11 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac } }else{ int y; - int leftr, leftg, leftb; + int leftr, leftg, leftb, lefta; const int last_line= (height-1)*p->linesize[0]; if(s->bitstream_bpp==32){ - skip_bits(&s->gb, 8); + lefta= p->data[0][last_line+A]= get_bits(&s->gb, 8); leftr= p->data[0][last_line+R]= get_bits(&s->gb, 8); leftg= p->data[0][last_line+G]= get_bits(&s->gb, 8); leftb= p->data[0][last_line+B]= get_bits(&s->gb, 8); @@ -1170,6 +1133,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac leftr= p->data[0][last_line+R]= get_bits(&s->gb, 8); leftg= p->data[0][last_line+G]= get_bits(&s->gb, 8); leftb= p->data[0][last_line+B]= get_bits(&s->gb, 8); + lefta= p->data[0][last_line+A]= 255; skip_bits(&s->gb, 8); } @@ -1178,13 +1142,14 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac case LEFT: case PLANE: decode_bgr_bitstream(s, width-1); - add_left_prediction_bgr32(p->data[0] + last_line+4, s->temp[0], width-1, &leftr, &leftg, &leftb); + s->dsp.add_hfyu_left_prediction_bgr32(p->data[0] + last_line+4, s->temp[0], width-1, &leftr, &leftg, &leftb, &lefta); for(y=s->height-2; y>=0; y--){ //Yes it is stored upside down. decode_bgr_bitstream(s, width); - add_left_prediction_bgr32(p->data[0] + p->linesize[0]*y, s->temp[0], width, &leftr, &leftg, &leftb); + s->dsp.add_hfyu_left_prediction_bgr32(p->data[0] + p->linesize[0]*y, s->temp[0], width, &leftr, &leftg, &leftb, &lefta); if(s->predictor == PLANE){ + if(s->bitstream_bpp!=32) lefta=0; if((y&s->interlaced)==0 && yheight-1-s->interlaced){ s->dsp.add_bytes(p->data[0] + p->linesize[0]*y, p->data[0] + p->linesize[0]*y + fake_ystride, fake_ystride); @@ -1226,6 +1191,9 @@ static av_cold int decode_end(AVCodecContext *avctx) HYuvContext *s = avctx->priv_data; int i; + if (s->picture.data[0]) + avctx->release_buffer(avctx, &s->picture); + common_end(s); av_freep(&s->bitstream_buffer); @@ -1449,7 +1417,7 @@ static av_cold int encode_end(AVCodecContext *avctx) #if CONFIG_HUFFYUV_DECODER AVCodec huffyuv_decoder = { "huffyuv", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_HUFFYUV, sizeof(HYuvContext), decode_init, @@ -1465,7 +1433,7 @@ AVCodec huffyuv_decoder = { #if CONFIG_FFVHUFF_DECODER AVCodec ffvhuff_decoder = { "ffvhuff", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_FFVHUFF, sizeof(HYuvContext), decode_init, @@ -1481,13 +1449,13 @@ AVCodec ffvhuff_decoder = { #if CONFIG_HUFFYUV_ENCODER AVCodec huffyuv_encoder = { "huffyuv", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_HUFFYUV, sizeof(HYuvContext), encode_init, encode_frame, encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV422P, PIX_FMT_RGB32, PIX_FMT_NONE}, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV422P, PIX_FMT_RGB32, PIX_FMT_NONE}, .long_name = NULL_IF_CONFIG_SMALL("Huffyuv / HuffYUV"), }; #endif @@ -1495,13 +1463,13 @@ AVCodec huffyuv_encoder = { #if CONFIG_FFVHUFF_ENCODER AVCodec ffvhuff_encoder = { "ffvhuff", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_FFVHUFF, sizeof(HYuvContext), encode_init, encode_frame, encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_RGB32, PIX_FMT_NONE}, + .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"), }; #endif diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/idcinvideo.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/idcinvideo.c index 7ce9c42a39..203812b128 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/idcinvideo.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/idcinvideo.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/idcinvideo.c + * @file * id Quake II Cin Video Decoder by Dr. Tim Ferguson * For more information about the id CIN format, visit: * http://www.csse.monash.edu.au/~timf/ @@ -255,7 +255,7 @@ static av_cold int idcin_decode_end(AVCodecContext *avctx) AVCodec idcin_decoder = { "idcinvideo", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_IDCIN, sizeof(IdcinContext), idcin_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/iff.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/iff.c new file mode 100644 index 0000000000..2989bb0ead --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/iff.c @@ -0,0 +1,290 @@ +/* + * IFF PBM/ILBM bitmap decoder + * Copyright (c) 2010 Peter Ross + * Copyright (c) 2010 Sebastian Vater + * + * 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 + * IFF PBM/ILBM bitmap decoder + */ + +#include "bytestream.h" +#include "avcodec.h" +#include "get_bits.h" +#include "iff.h" + +typedef struct { + AVFrame frame; + int planesize; + uint8_t * planebuf; +} IffContext; + +/** + * Convert CMAP buffer (stored in extradata) to lavc palette format + */ +int ff_cmap_read_palette(AVCodecContext *avctx, uint32_t *pal) +{ + int count, i; + + if (avctx->bits_per_coded_sample > 8) { + av_log(avctx, AV_LOG_ERROR, "bit_per_coded_sample > 8 not supported\n"); + return AVERROR_INVALIDDATA; + } + + count = 1 << avctx->bits_per_coded_sample; + if (avctx->extradata_size < count * 3) { + av_log(avctx, AV_LOG_ERROR, "palette data underflow\n"); + return AVERROR_INVALIDDATA; + } + for (i=0; i < count; i++) { + pal[i] = 0xFF000000 | AV_RB24( avctx->extradata + i*3 ); + } + 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 = PIX_FMT_PAL8; + } else if (avctx->bits_per_coded_sample <= 32) { + avctx->pix_fmt = PIX_FMT_BGR32; + } else { + return AVERROR_INVALIDDATA; + } + + s->planesize = avctx->width >> 3; + s->planebuf = av_malloc(s->planesize + FF_INPUT_BUFFER_PADDING_SIZE); + if (!s->planebuf) + return AVERROR(ENOMEM); + + s->frame.reference = 1; + if ((err = avctx->get_buffer(avctx, &s->frame) < 0)) { + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return err; + } + + return avctx->bits_per_coded_sample <= 8 ? + ff_cmap_read_palette(avctx, (uint32_t*)s->frame.data[1]) : 0; +} + +/** + * Decode interleaved plane buffer up to 8bpp + * @param dst Destination buffer + * @param buf Source buffer + * @param buf_size + * @param bps bits_per_coded_sample (must be <= 8) + * @param plane plane number to decode as + */ +static void decodeplane8(uint8_t *dst, const uint8_t *const buf, int buf_size, int bps, int plane) +{ + GetBitContext gb; + int i; + const int b = (buf_size * 8) + bps - 1; + init_get_bits(&gb, buf, buf_size * 8); + for(i = 0; i < b; i++) { + dst[i] |= get_bits1(&gb) << plane; + } +} + +/** + * Decode interleaved plane buffer up to 24bpp + * @param dst Destination buffer + * @param buf Source buffer + * @param buf_size + * @param bps bits_per_coded_sample + * @param plane plane number to decode as + */ +static void decodeplane32(uint32_t *dst, const uint8_t *const buf, int buf_size, int bps, int plane) +{ + GetBitContext gb; + int i; + const int b = (buf_size * 8) + bps - 1; + init_get_bits(&gb, buf, buf_size * 8); + for(i = 0; i < b; i++) { + dst[i] |= get_bits1(&gb) << plane; + } +} + +static int decode_frame_ilbm(AVCodecContext *avctx, + void *data, int *data_size, + AVPacket *avpkt) +{ + IffContext *s = avctx->priv_data; + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + const uint8_t *buf_end = buf+buf_size; + int y, plane; + + if (avctx->reget_buffer(avctx, &s->frame) < 0){ + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } + + if (avctx->pix_fmt == PIX_FMT_PAL8) { + 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++) { + decodeplane8(row, buf, FFMIN(s->planesize, buf_end - buf), avctx->bits_per_coded_sample, plane); + buf += 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++) { + decodeplane32((uint32_t *) row, buf, FFMIN(s->planesize, buf_end - buf), avctx->bits_per_coded_sample, plane); + buf += s->planesize; + } + } + } + + *data_size = sizeof(AVFrame); + *(AVFrame*)data = s->frame; + return buf_size; +} + +static int decode_frame_byterun1(AVCodecContext *avctx, + void *data, int *data_size, + AVPacket *avpkt) +{ + IffContext *s = avctx->priv_data; + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + const uint8_t *buf_end = buf+buf_size; + int y, plane, x; + + if (avctx->reget_buffer(avctx, &s->frame) < 0){ + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } + + if (avctx->codec_tag == MKTAG('I','L','B','M')) { //interleaved + if (avctx->pix_fmt == PIX_FMT_PAL8) { + 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(x = 0; x < s->planesize && buf < buf_end; ) { + int8_t value = *buf++; + unsigned length; + if (value >= 0) { + length = value + 1; + memcpy(s->planebuf + x, buf, FFMIN3(length, s->planesize - x, buf_end - buf)); + buf += length; + } else if (value > -128) { + length = -value + 1; + memset(s->planebuf + x, *buf++, FFMIN(length, s->planesize - x)); + } else { //noop + continue; + } + x += length; + } + decodeplane8(row, s->planebuf, s->planesize, avctx->bits_per_coded_sample, plane); + } + } + } 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(x = 0; x < s->planesize && buf < buf_end; ) { + int8_t value = *buf++; + unsigned length; + if (value >= 0) { + length = value + 1; + memcpy(s->planebuf + x, buf, FFMIN3(length, s->planesize - x, buf_end - buf)); + buf += length; + } else if (value > -128) { + length = -value + 1; + memset(s->planebuf + x, *buf++, FFMIN(length, s->planesize - x)); + } else { // noop + continue; + } + x += length; + } + decodeplane32((uint32_t *) row, s->planebuf, s->planesize, avctx->bits_per_coded_sample, plane); + } + } + } + } else { + for(y = 0; y < avctx->height ; y++ ) { + uint8_t *row = &s->frame.data[0][y*s->frame.linesize[0]]; + for(x = 0; x < avctx->width && buf < buf_end; ) { + int8_t value = *buf++; + unsigned length; + if (value >= 0) { + length = value + 1; + memcpy(row + x, buf, FFMIN3(length, buf_end - buf, avctx->width - x)); + buf += length; + } else if (value > -128) { + length = -value + 1; + memset(row + x, *buf++, FFMIN(length, avctx->width - x)); + } else { //noop + continue; + } + x += length; + } + } + } + + *data_size = sizeof(AVFrame); + *(AVFrame*)data = s->frame; + return buf_size; +} + +static av_cold int decode_end(AVCodecContext *avctx) +{ + IffContext *s = avctx->priv_data; + if (s->frame.data[0]) + avctx->release_buffer(avctx, &s->frame); + av_freep(&s->planebuf); + return 0; +} + +AVCodec 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, + .long_name = NULL_IF_CONFIG_SMALL("IFF ILBM"), +}; + +AVCodec 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, + .long_name = NULL_IF_CONFIG_SMALL("IFF ByteRun1"), +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/iff.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/iff.h new file mode 100644 index 0000000000..76db10b884 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/iff.h @@ -0,0 +1,30 @@ +/* + * IFF PBM/ILBM bitmap decoder + * Copyright (c) 2010 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 AVCODEC_IFF_H +#define AVCODEC_IFF_H + +#include +#include "avcodec.h" + +int ff_cmap_read_palette(AVCodecContext *avctx, uint32_t *pal); + +#endif /* AVCODEC_IFF_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/iirfilter.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/iirfilter.c index eb6ec90d16..90af43190e 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/iirfilter.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/iirfilter.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/iirfilter.c + * @file * different IIR filters implementation */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/iirfilter.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/iirfilter.h index e6010390cb..f660955403 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/iirfilter.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/iirfilter.h @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/iirfilter.h + * @file * IIR filter interface */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/imc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/imc.c index 93093ebd53..2a420f5bcf 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/imc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/imc.c @@ -22,7 +22,8 @@ */ /** - * @file libavcodec/imc.c IMC - Intel Music Coder + * @file + * IMC - Intel Music Coder * A mdct based codec using a 256 points large transform * divied into 32 bands with some mix of scale factors. * Only mono is supported. @@ -38,6 +39,7 @@ #include "avcodec.h" #include "get_bits.h" #include "dsputil.h" +#include "fft.h" #include "imcdata.h" @@ -84,8 +86,8 @@ typedef struct { DSPContext dsp; FFTContext fft; - DECLARE_ALIGNED_16(FFTComplex, samples[COEFFS/2]); - DECLARE_ALIGNED_16(float, out_samples[COEFFS]); + DECLARE_ALIGNED(16, FFTComplex, samples)[COEFFS/2]; + DECLARE_ALIGNED(16, float, out_samples)[COEFFS]; } IMCContext; static VLC huffman_vlc[4][4]; @@ -822,7 +824,7 @@ static av_cold int imc_decode_close(AVCodecContext * avctx) AVCodec imc_decoder = { .name = "imc", - .type = CODEC_TYPE_AUDIO, + .type = AVMEDIA_TYPE_AUDIO, .id = CODEC_ID_IMC, .priv_data_size = sizeof(IMCContext), .init = imc_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/imgconvert.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/imgconvert.c index fb45c65249..8f789c4ae0 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/imgconvert.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/imgconvert.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/imgconvert.c + * @file * misc image conversion routines */ @@ -33,6 +33,9 @@ #include "avcodec.h" #include "dsputil.h" #include "colorspace.h" +#include "internal.h" +#include "imgconvert.h" +#include "libavutil/pixdesc.h" #if HAVE_MMX #include "x86/mmx.h" @@ -52,14 +55,10 @@ #define FF_PIXEL_PALETTE 2 /**< one components containing indexes for a palette */ typedef struct PixFmtInfo { - const char *name; 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 is_hwaccel : 1; /**< true if this is an HW accelerated format */ - uint8_t x_chroma_shift; /**< X chroma subsampling factor is 2 ^ shift */ - uint8_t y_chroma_shift; /**< Y chroma subsampling factor is 2 ^ shift */ uint8_t depth; /**< bit depth of the color components */ } PixFmtInfo; @@ -67,268 +66,219 @@ typedef struct PixFmtInfo { static const PixFmtInfo pix_fmt_info[PIX_FMT_NB] = { /* YUV formats */ [PIX_FMT_YUV420P] = { - .name = "yuv420p", .nb_channels = 3, .color_type = FF_COLOR_YUV, .pixel_type = FF_PIXEL_PLANAR, .depth = 8, - .x_chroma_shift = 1, .y_chroma_shift = 1, }, [PIX_FMT_YUV422P] = { - .name = "yuv422p", .nb_channels = 3, .color_type = FF_COLOR_YUV, .pixel_type = FF_PIXEL_PLANAR, .depth = 8, - .x_chroma_shift = 1, .y_chroma_shift = 0, }, [PIX_FMT_YUV444P] = { - .name = "yuv444p", .nb_channels = 3, .color_type = FF_COLOR_YUV, .pixel_type = FF_PIXEL_PLANAR, .depth = 8, - .x_chroma_shift = 0, .y_chroma_shift = 0, }, [PIX_FMT_YUYV422] = { - .name = "yuyv422", .nb_channels = 1, .color_type = FF_COLOR_YUV, .pixel_type = FF_PIXEL_PACKED, .depth = 8, - .x_chroma_shift = 1, .y_chroma_shift = 0, }, [PIX_FMT_UYVY422] = { - .name = "uyvy422", .nb_channels = 1, .color_type = FF_COLOR_YUV, .pixel_type = FF_PIXEL_PACKED, .depth = 8, - .x_chroma_shift = 1, .y_chroma_shift = 0, }, [PIX_FMT_YUV410P] = { - .name = "yuv410p", .nb_channels = 3, .color_type = FF_COLOR_YUV, .pixel_type = FF_PIXEL_PLANAR, .depth = 8, - .x_chroma_shift = 2, .y_chroma_shift = 2, }, [PIX_FMT_YUV411P] = { - .name = "yuv411p", .nb_channels = 3, .color_type = FF_COLOR_YUV, .pixel_type = FF_PIXEL_PLANAR, .depth = 8, - .x_chroma_shift = 2, .y_chroma_shift = 0, }, [PIX_FMT_YUV440P] = { - .name = "yuv440p", .nb_channels = 3, .color_type = FF_COLOR_YUV, .pixel_type = FF_PIXEL_PLANAR, .depth = 8, - .x_chroma_shift = 0, .y_chroma_shift = 1, }, - [PIX_FMT_YUV420PLE] = { - .name = "yuv420ple", + [PIX_FMT_YUV420P16LE] = { .nb_channels = 3, .color_type = FF_COLOR_YUV, .pixel_type = FF_PIXEL_PLANAR, .depth = 16, - .x_chroma_shift = 1, .y_chroma_shift = 1, }, - [PIX_FMT_YUV422PLE] = { - .name = "yuv422ple", + [PIX_FMT_YUV422P16LE] = { .nb_channels = 3, .color_type = FF_COLOR_YUV, .pixel_type = FF_PIXEL_PLANAR, .depth = 16, - .x_chroma_shift = 1, .y_chroma_shift = 0, }, - [PIX_FMT_YUV444PLE] = { - .name = "yuv444ple", + [PIX_FMT_YUV444P16LE] = { .nb_channels = 3, .color_type = FF_COLOR_YUV, .pixel_type = FF_PIXEL_PLANAR, .depth = 16, - .x_chroma_shift = 0, .y_chroma_shift = 0, }, - [PIX_FMT_YUV420PBE] = { - .name = "yuv420pbe", + [PIX_FMT_YUV420P16BE] = { .nb_channels = 3, .color_type = FF_COLOR_YUV, .pixel_type = FF_PIXEL_PLANAR, .depth = 16, - .x_chroma_shift = 1, .y_chroma_shift = 1, }, - [PIX_FMT_YUV422PBE] = { - .name = "yuv422pbe", + [PIX_FMT_YUV422P16BE] = { .nb_channels = 3, .color_type = FF_COLOR_YUV, .pixel_type = FF_PIXEL_PLANAR, .depth = 16, - .x_chroma_shift = 1, .y_chroma_shift = 0, }, - [PIX_FMT_YUV444PBE] = { - .name = "yuv444pbe", + [PIX_FMT_YUV444P16BE] = { .nb_channels = 3, .color_type = FF_COLOR_YUV, .pixel_type = FF_PIXEL_PLANAR, .depth = 16, - .x_chroma_shift = 0, .y_chroma_shift = 0, }, /* YUV formats with alpha plane */ [PIX_FMT_YUVA420P] = { - .name = "yuva420p", .nb_channels = 4, .color_type = FF_COLOR_YUV, .pixel_type = FF_PIXEL_PLANAR, .depth = 8, - .x_chroma_shift = 1, .y_chroma_shift = 1, }, /* JPEG YUV */ [PIX_FMT_YUVJ420P] = { - .name = "yuvj420p", .nb_channels = 3, .color_type = FF_COLOR_YUV_JPEG, .pixel_type = FF_PIXEL_PLANAR, .depth = 8, - .x_chroma_shift = 1, .y_chroma_shift = 1, }, [PIX_FMT_YUVJ422P] = { - .name = "yuvj422p", .nb_channels = 3, .color_type = FF_COLOR_YUV_JPEG, .pixel_type = FF_PIXEL_PLANAR, .depth = 8, - .x_chroma_shift = 1, .y_chroma_shift = 0, }, [PIX_FMT_YUVJ444P] = { - .name = "yuvj444p", .nb_channels = 3, .color_type = FF_COLOR_YUV_JPEG, .pixel_type = FF_PIXEL_PLANAR, .depth = 8, - .x_chroma_shift = 0, .y_chroma_shift = 0, }, [PIX_FMT_YUVJ440P] = { - .name = "yuvj440p", .nb_channels = 3, .color_type = FF_COLOR_YUV_JPEG, .pixel_type = FF_PIXEL_PLANAR, .depth = 8, - .x_chroma_shift = 0, .y_chroma_shift = 1, }, /* RGB formats */ [PIX_FMT_RGB24] = { - .name = "rgb24", .nb_channels = 3, .color_type = FF_COLOR_RGB, .pixel_type = FF_PIXEL_PACKED, .depth = 8, - .x_chroma_shift = 0, .y_chroma_shift = 0, }, [PIX_FMT_BGR24] = { - .name = "bgr24", .nb_channels = 3, .color_type = FF_COLOR_RGB, .pixel_type = FF_PIXEL_PACKED, .depth = 8, - .x_chroma_shift = 0, .y_chroma_shift = 0, }, [PIX_FMT_ARGB] = { - .name = "argb", .nb_channels = 4, .is_alpha = 1, .color_type = FF_COLOR_RGB, .pixel_type = FF_PIXEL_PACKED, .depth = 8, - .x_chroma_shift = 0, .y_chroma_shift = 0, }, [PIX_FMT_RGB48BE] = { - .name = "rgb48be", .nb_channels = 3, .color_type = FF_COLOR_RGB, .pixel_type = FF_PIXEL_PACKED, .depth = 16, - .x_chroma_shift = 0, .y_chroma_shift = 0, }, [PIX_FMT_RGB48LE] = { - .name = "rgb48le", .nb_channels = 3, .color_type = FF_COLOR_RGB, .pixel_type = FF_PIXEL_PACKED, .depth = 16, - .x_chroma_shift = 0, .y_chroma_shift = 0, }, [PIX_FMT_RGB565BE] = { - .name = "rgb565be", .nb_channels = 3, .color_type = FF_COLOR_RGB, .pixel_type = FF_PIXEL_PACKED, .depth = 5, - .x_chroma_shift = 0, .y_chroma_shift = 0, }, [PIX_FMT_RGB565LE] = { - .name = "rgb565le", .nb_channels = 3, .color_type = FF_COLOR_RGB, .pixel_type = FF_PIXEL_PACKED, .depth = 5, - .x_chroma_shift = 0, .y_chroma_shift = 0, }, [PIX_FMT_RGB555BE] = { - .name = "rgb555be", .nb_channels = 3, .color_type = FF_COLOR_RGB, .pixel_type = FF_PIXEL_PACKED, .depth = 5, - .x_chroma_shift = 0, .y_chroma_shift = 0, }, [PIX_FMT_RGB555LE] = { - .name = "rgb555le", .nb_channels = 3, .color_type = FF_COLOR_RGB, .pixel_type = FF_PIXEL_PACKED, .depth = 5, - .x_chroma_shift = 0, .y_chroma_shift = 0, + }, + [PIX_FMT_RGB444BE] = { + .nb_channels = 3, + .color_type = FF_COLOR_RGB, + .pixel_type = FF_PIXEL_PACKED, + .depth = 4, + }, + [PIX_FMT_RGB444LE] = { + .nb_channels = 3, + .color_type = FF_COLOR_RGB, + .pixel_type = FF_PIXEL_PACKED, + .depth = 4, }, /* gray / mono formats */ [PIX_FMT_GRAY16BE] = { - .name = "gray16be", .nb_channels = 1, .color_type = FF_COLOR_GRAY, .pixel_type = FF_PIXEL_PLANAR, .depth = 16, }, [PIX_FMT_GRAY16LE] = { - .name = "gray16le", .nb_channels = 1, .color_type = FF_COLOR_GRAY, .pixel_type = FF_PIXEL_PLANAR, .depth = 16, }, [PIX_FMT_GRAY8] = { - .name = "gray", .nb_channels = 1, .color_type = FF_COLOR_GRAY, .pixel_type = FF_PIXEL_PLANAR, .depth = 8, }, [PIX_FMT_MONOWHITE] = { - .name = "monow", .nb_channels = 1, .color_type = FF_COLOR_GRAY, .pixel_type = FF_PIXEL_PLANAR, .depth = 1, }, [PIX_FMT_MONOBLACK] = { - .name = "monob", .nb_channels = 1, .color_type = FF_COLOR_GRAY, .pixel_type = FF_PIXEL_PLANAR, @@ -337,197 +287,126 @@ static const PixFmtInfo pix_fmt_info[PIX_FMT_NB] = { /* paletted formats */ [PIX_FMT_PAL8] = { - .name = "pal8", .nb_channels = 4, .is_alpha = 1, .color_type = FF_COLOR_RGB, .pixel_type = FF_PIXEL_PALETTE, .depth = 8, }, - [PIX_FMT_XVMC_MPEG2_MC] = { - .name = "xvmcmc", - .is_hwaccel = 1, - }, - [PIX_FMT_XVMC_MPEG2_IDCT] = { - .name = "xvmcidct", - .is_hwaccel = 1, - }, - [PIX_FMT_VDPAU_MPEG1] = { - .name = "vdpau_mpeg1", - .is_hwaccel = 1, - .x_chroma_shift = 1, .y_chroma_shift = 1, - }, - [PIX_FMT_VDPAU_MPEG2] = { - .name = "vdpau_mpeg2", - .is_hwaccel = 1, - .x_chroma_shift = 1, .y_chroma_shift = 1, - }, - [PIX_FMT_VDPAU_H264] = { - .name = "vdpau_h264", - .is_hwaccel = 1, - .x_chroma_shift = 1, .y_chroma_shift = 1, - }, - [PIX_FMT_VDPAU_WMV3] = { - .name = "vdpau_wmv3", - .is_hwaccel = 1, - .x_chroma_shift = 1, .y_chroma_shift = 1, - }, - [PIX_FMT_VDPAU_VC1] = { - .name = "vdpau_vc1", - .is_hwaccel = 1, - .x_chroma_shift = 1, .y_chroma_shift = 1, - }, [PIX_FMT_UYYVYY411] = { - .name = "uyyvyy411", .nb_channels = 1, .color_type = FF_COLOR_YUV, .pixel_type = FF_PIXEL_PACKED, .depth = 8, - .x_chroma_shift = 2, .y_chroma_shift = 0, }, [PIX_FMT_ABGR] = { - .name = "abgr", .nb_channels = 4, .is_alpha = 1, .color_type = FF_COLOR_RGB, .pixel_type = FF_PIXEL_PACKED, .depth = 8, - .x_chroma_shift = 0, .y_chroma_shift = 0, }, [PIX_FMT_BGR565BE] = { - .name = "bgr565be", .nb_channels = 3, .color_type = FF_COLOR_RGB, .pixel_type = FF_PIXEL_PACKED, .depth = 5, - .x_chroma_shift = 0, .y_chroma_shift = 0, }, [PIX_FMT_BGR565LE] = { - .name = "bgr565le", .nb_channels = 3, .color_type = FF_COLOR_RGB, .pixel_type = FF_PIXEL_PACKED, .depth = 5, - .x_chroma_shift = 0, .y_chroma_shift = 0, }, [PIX_FMT_BGR555BE] = { - .name = "bgr555be", .nb_channels = 3, .color_type = FF_COLOR_RGB, .pixel_type = FF_PIXEL_PACKED, .depth = 5, - .x_chroma_shift = 0, .y_chroma_shift = 0, }, [PIX_FMT_BGR555LE] = { - .name = "bgr555le", .nb_channels = 3, .color_type = FF_COLOR_RGB, .pixel_type = FF_PIXEL_PACKED, .depth = 5, - .x_chroma_shift = 0, .y_chroma_shift = 0, + }, + [PIX_FMT_BGR444BE] = { + .nb_channels = 3, + .color_type = FF_COLOR_RGB, + .pixel_type = FF_PIXEL_PACKED, + .depth = 4, + }, + [PIX_FMT_BGR444LE] = { + .nb_channels = 3, + .color_type = FF_COLOR_RGB, + .pixel_type = FF_PIXEL_PACKED, + .depth = 4, }, [PIX_FMT_RGB8] = { - .name = "rgb8", .nb_channels = 1, .color_type = FF_COLOR_RGB, .pixel_type = FF_PIXEL_PACKED, .depth = 8, - .x_chroma_shift = 0, .y_chroma_shift = 0, }, [PIX_FMT_RGB4] = { - .name = "rgb4", .nb_channels = 1, .color_type = FF_COLOR_RGB, .pixel_type = FF_PIXEL_PACKED, .depth = 4, - .x_chroma_shift = 0, .y_chroma_shift = 0, }, [PIX_FMT_RGB4_BYTE] = { - .name = "rgb4_byte", .nb_channels = 1, .color_type = FF_COLOR_RGB, .pixel_type = FF_PIXEL_PACKED, .depth = 8, - .x_chroma_shift = 0, .y_chroma_shift = 0, }, [PIX_FMT_BGR8] = { - .name = "bgr8", .nb_channels = 1, .color_type = FF_COLOR_RGB, .pixel_type = FF_PIXEL_PACKED, .depth = 8, - .x_chroma_shift = 0, .y_chroma_shift = 0, }, [PIX_FMT_BGR4] = { - .name = "bgr4", .nb_channels = 1, .color_type = FF_COLOR_RGB, .pixel_type = FF_PIXEL_PACKED, .depth = 4, - .x_chroma_shift = 0, .y_chroma_shift = 0, }, [PIX_FMT_BGR4_BYTE] = { - .name = "bgr4_byte", .nb_channels = 1, .color_type = FF_COLOR_RGB, .pixel_type = FF_PIXEL_PACKED, .depth = 8, - .x_chroma_shift = 0, .y_chroma_shift = 0, }, [PIX_FMT_NV12] = { - .name = "nv12", .nb_channels = 2, .color_type = FF_COLOR_YUV, .pixel_type = FF_PIXEL_PLANAR, .depth = 8, - .x_chroma_shift = 1, .y_chroma_shift = 1, }, [PIX_FMT_NV21] = { - .name = "nv12", .nb_channels = 2, .color_type = FF_COLOR_YUV, .pixel_type = FF_PIXEL_PLANAR, .depth = 8, - .x_chroma_shift = 1, .y_chroma_shift = 1, }, [PIX_FMT_BGRA] = { - .name = "bgra", .nb_channels = 4, .is_alpha = 1, .color_type = FF_COLOR_RGB, .pixel_type = FF_PIXEL_PACKED, .depth = 8, - .x_chroma_shift = 0, .y_chroma_shift = 0, }, [PIX_FMT_RGBA] = { - .name = "rgba", .nb_channels = 4, .is_alpha = 1, .color_type = FF_COLOR_RGB, .pixel_type = FF_PIXEL_PACKED, .depth = 8, - .x_chroma_shift = 0, .y_chroma_shift = 0, - }, - - /* VA API formats */ - [PIX_FMT_VAAPI_MOCO] = { - .name = "vaapi_moco", - .is_hwaccel = 1, - .x_chroma_shift = 1, .y_chroma_shift = 1, - }, - [PIX_FMT_VAAPI_IDCT] = { - .name = "vaapi_idct", - .is_hwaccel = 1, - .x_chroma_shift = 1, .y_chroma_shift = 1, - }, - [PIX_FMT_VAAPI_VLD] = { - .name = "vaapi_vld", - .is_hwaccel = 1, - .x_chroma_shift = 1, .y_chroma_shift = 1, }, }; void avcodec_get_chroma_sub_sample(enum PixelFormat pix_fmt, int *h_shift, int *v_shift) { - *h_shift = pix_fmt_info[pix_fmt].x_chroma_shift; - *v_shift = pix_fmt_info[pix_fmt].y_chroma_shift; + *h_shift = av_pix_fmt_descriptors[pix_fmt].log2_chroma_w; + *v_shift = av_pix_fmt_descriptors[pix_fmt].log2_chroma_h; } const char *avcodec_get_pix_fmt_name(enum PixelFormat pix_fmt) @@ -535,42 +414,15 @@ const char *avcodec_get_pix_fmt_name(enum PixelFormat pix_fmt) if (pix_fmt < 0 || pix_fmt >= PIX_FMT_NB) return NULL; else - return pix_fmt_info[pix_fmt].name; + return av_pix_fmt_descriptors[pix_fmt].name; } -static enum PixelFormat avcodec_get_pix_fmt_internal(const char *name) -{ - int i; - - for (i=0; i < PIX_FMT_NB; i++) - if (pix_fmt_info[i].name && !strcmp(pix_fmt_info[i].name, name)) - return i; - return PIX_FMT_NONE; -} - -#if HAVE_BIGENDIAN -# define X_NE(be, le) be -#else -# define X_NE(be, le) le -#endif - +#if LIBAVCODEC_VERSION_MAJOR < 53 enum PixelFormat avcodec_get_pix_fmt(const char *name) { - enum PixelFormat pix_fmt; - - if (!strcmp(name, "rgb32")) - name = X_NE("argb", "bgra"); - else if (!strcmp(name, "bgr32")) - name = X_NE("abgr", "rgba"); - - pix_fmt = avcodec_get_pix_fmt_internal(name); - if (pix_fmt == PIX_FMT_NONE) { - char name2[32]; - snprintf(name2, sizeof(name2), "%s%s", name, X_NE("be", "le")); - pix_fmt = avcodec_get_pix_fmt_internal(name2); - } - return pix_fmt; + return av_get_pix_fmt(name); } +#endif void avcodec_pix_fmt_string (char *buf, int buf_size, enum PixelFormat pix_fmt) { @@ -585,8 +437,8 @@ void avcodec_pix_fmt_string (char *buf, int buf_size, enum PixelFormat pix_fmt) char is_alpha_char= info.is_alpha ? 'y' : 'n'; snprintf (buf, buf_size, - "%-10s" " %1d " " %2d " " %c ", - info.name, + "%-11s %5d %9d %6c", + av_pix_fmt_descriptors[pix_fmt].name, info.nb_channels, info.depth, is_alpha_char @@ -596,7 +448,7 @@ void avcodec_pix_fmt_string (char *buf, int buf_size, enum PixelFormat pix_fmt) int ff_is_hwaccel_pix_fmt(enum PixelFormat pix_fmt) { - return pix_fmt_info[pix_fmt].is_hwaccel; + return av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_HWACCEL; } int ff_set_systematic_pal(uint32_t pal[256], enum PixelFormat pix_fmt){ @@ -640,104 +492,36 @@ int ff_set_systematic_pal(uint32_t pal[256], enum PixelFormat pix_fmt){ int ff_fill_linesize(AVPicture *picture, enum PixelFormat pix_fmt, int width) { - int w2; - const PixFmtInfo *pinfo; + int i; + const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt]; + int max_plane_step [4]; + int max_plane_step_comp[4]; memset(picture->linesize, 0, sizeof(picture->linesize)); - pinfo = &pix_fmt_info[pix_fmt]; - switch(pix_fmt) { - case PIX_FMT_YUV420P: - case PIX_FMT_YUV422P: - case PIX_FMT_YUV444P: - case PIX_FMT_YUV410P: - case PIX_FMT_YUV411P: - case PIX_FMT_YUV440P: - case PIX_FMT_YUVJ420P: - case PIX_FMT_YUVJ422P: - case PIX_FMT_YUVJ444P: - case PIX_FMT_YUVJ440P: - w2 = (width + (1 << pinfo->x_chroma_shift) - 1) >> pinfo->x_chroma_shift; - picture->linesize[0] = width; - picture->linesize[1] = w2; - picture->linesize[2] = w2; - break; - case PIX_FMT_YUV420PLE: - case PIX_FMT_YUV422PLE: - case PIX_FMT_YUV444PLE: - case PIX_FMT_YUV420PBE: - case PIX_FMT_YUV422PBE: - case PIX_FMT_YUV444PBE: - w2 = (width + (1 << pinfo->x_chroma_shift) - 1) >> pinfo->x_chroma_shift; - picture->linesize[0] = 2*width; - picture->linesize[1] = 2*w2; - picture->linesize[2] = 2*w2; - break; - case PIX_FMT_YUVA420P: - w2 = (width + (1 << pinfo->x_chroma_shift) - 1) >> pinfo->x_chroma_shift; - picture->linesize[0] = width; - picture->linesize[1] = w2; - picture->linesize[2] = w2; - picture->linesize[3] = width; - break; - case PIX_FMT_NV12: - case PIX_FMT_NV21: - w2 = (width + (1 << pinfo->x_chroma_shift) - 1) >> pinfo->x_chroma_shift; - picture->linesize[0] = width; - picture->linesize[1] = w2; - break; - case PIX_FMT_RGB24: - case PIX_FMT_BGR24: - picture->linesize[0] = width * 3; - break; - case PIX_FMT_ARGB: - case PIX_FMT_ABGR: - case PIX_FMT_RGBA: - case PIX_FMT_BGRA: - picture->linesize[0] = width * 4; - break; - case PIX_FMT_RGB48BE: - case PIX_FMT_RGB48LE: - picture->linesize[0] = width * 6; - break; - case PIX_FMT_GRAY16BE: - case PIX_FMT_GRAY16LE: - case PIX_FMT_BGR555BE: - case PIX_FMT_BGR555LE: - case PIX_FMT_BGR565BE: - case PIX_FMT_BGR565LE: - case PIX_FMT_RGB555BE: - case PIX_FMT_RGB555LE: - case PIX_FMT_RGB565BE: - case PIX_FMT_RGB565LE: - case PIX_FMT_YUYV422: - picture->linesize[0] = width * 2; - break; - case PIX_FMT_UYVY422: - picture->linesize[0] = width * 2; - break; - case PIX_FMT_UYYVYY411: - picture->linesize[0] = width + width/2; - break; - case PIX_FMT_RGB4: - case PIX_FMT_BGR4: - picture->linesize[0] = width / 2; - break; - case PIX_FMT_MONOWHITE: - case PIX_FMT_MONOBLACK: - picture->linesize[0] = (width + 7) >> 3; - break; - case PIX_FMT_PAL8: - case PIX_FMT_RGB8: - case PIX_FMT_BGR8: - case PIX_FMT_RGB4_BYTE: - case PIX_FMT_BGR4_BYTE: - case PIX_FMT_GRAY8: - picture->linesize[0] = width; - break; - default: + if (desc->flags & PIX_FMT_HWACCEL) return -1; + + if (desc->flags & PIX_FMT_BITSTREAM) { + picture->linesize[0] = (width * (desc->comp[0].step_minus1+1) + 7) >> 3; + return 0; } + + memset(max_plane_step , 0, sizeof(max_plane_step )); + memset(max_plane_step_comp, 0, sizeof(max_plane_step_comp)); + for (i = 0; i < 4; i++) { + const AVComponentDescriptor *comp = &(desc->comp[i]); + if ((comp->step_minus1+1) > max_plane_step[comp->plane]) { + max_plane_step [comp->plane] = comp->step_minus1+1; + max_plane_step_comp[comp->plane] = i; + } + } + + for (i = 0; i < 4; i++) { + int s = (max_plane_step_comp[i] == 1 || max_plane_step_comp[i] == 2) ? desc->log2_chroma_w : 0; + picture->linesize[i] = max_plane_step[i] * (((width + (1 << s) - 1)) >> s); + } + return 0; } @@ -745,9 +529,8 @@ int ff_fill_pointer(AVPicture *picture, uint8_t *ptr, enum PixelFormat pix_fmt, int height) { int size, h2, size2; - const PixFmtInfo *pinfo; + const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt]; - pinfo = &pix_fmt_info[pix_fmt]; size = picture->linesize[0] * height; switch(pix_fmt) { case PIX_FMT_YUV420P: @@ -760,13 +543,13 @@ int ff_fill_pointer(AVPicture *picture, uint8_t *ptr, enum PixelFormat pix_fmt, case PIX_FMT_YUVJ422P: case PIX_FMT_YUVJ444P: case PIX_FMT_YUVJ440P: - case PIX_FMT_YUV420PLE: - case PIX_FMT_YUV422PLE: - case PIX_FMT_YUV444PLE: - case PIX_FMT_YUV420PBE: - case PIX_FMT_YUV422PBE: - case PIX_FMT_YUV444PBE: - h2 = (height + (1 << pinfo->y_chroma_shift) - 1) >> pinfo->y_chroma_shift; + case PIX_FMT_YUV420P16LE: + case PIX_FMT_YUV422P16LE: + case PIX_FMT_YUV444P16LE: + case PIX_FMT_YUV420P16BE: + case PIX_FMT_YUV422P16BE: + case PIX_FMT_YUV444P16BE: + h2 = (height + (1 << desc->log2_chroma_h) - 1) >> desc->log2_chroma_h; size2 = picture->linesize[1] * h2; picture->data[0] = ptr; picture->data[1] = picture->data[0] + size; @@ -774,7 +557,7 @@ int ff_fill_pointer(AVPicture *picture, uint8_t *ptr, enum PixelFormat pix_fmt, picture->data[3] = NULL; return size + 2 * size2; case PIX_FMT_YUVA420P: - h2 = (height + (1 << pinfo->y_chroma_shift) - 1) >> pinfo->y_chroma_shift; + h2 = (height + (1 << desc->log2_chroma_h) - 1) >> desc->log2_chroma_h; size2 = picture->linesize[1] * h2; picture->data[0] = ptr; picture->data[1] = picture->data[0] + size; @@ -783,13 +566,13 @@ int ff_fill_pointer(AVPicture *picture, uint8_t *ptr, enum PixelFormat pix_fmt, return 2 * size + 2 * size2; case PIX_FMT_NV12: case PIX_FMT_NV21: - h2 = (height + (1 << pinfo->y_chroma_shift) - 1) >> pinfo->y_chroma_shift; - size2 = picture->linesize[1] * h2 * 2; + h2 = (height + (1 << desc->log2_chroma_h) - 1) >> desc->log2_chroma_h; + size2 = picture->linesize[1] * h2; picture->data[0] = ptr; picture->data[1] = picture->data[0] + size; picture->data[2] = NULL; picture->data[3] = NULL; - return size + 2 * size2; + return size + size2; case PIX_FMT_RGB24: case PIX_FMT_BGR24: case PIX_FMT_ARGB: @@ -800,10 +583,14 @@ int ff_fill_pointer(AVPicture *picture, uint8_t *ptr, enum PixelFormat pix_fmt, case PIX_FMT_RGB48LE: case PIX_FMT_GRAY16BE: case PIX_FMT_GRAY16LE: + case PIX_FMT_BGR444BE: + case PIX_FMT_BGR444LE: case PIX_FMT_BGR555BE: case PIX_FMT_BGR555LE: case PIX_FMT_BGR565BE: case PIX_FMT_BGR565LE: + case PIX_FMT_RGB444BE: + case PIX_FMT_RGB444LE: case PIX_FMT_RGB555BE: case PIX_FMT_RGB555LE: case PIX_FMT_RGB565BE: @@ -815,6 +602,7 @@ int ff_fill_pointer(AVPicture *picture, uint8_t *ptr, enum PixelFormat pix_fmt, case PIX_FMT_BGR4: case PIX_FMT_MONOWHITE: case PIX_FMT_MONOBLACK: + case PIX_FMT_Y400A: picture->data[0] = ptr; picture->data[1] = NULL; picture->data[2] = NULL; @@ -858,6 +646,7 @@ int avpicture_layout(const AVPicture* src, enum PixelFormat pix_fmt, int width, unsigned char *dest, int dest_size) { const PixFmtInfo* pf = &pix_fmt_info[pix_fmt]; + const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt]; int i, j, w, ow, h, oh, data_planes; const unsigned char* s; int size = avpicture_get_size(pix_fmt, width, height); @@ -872,17 +661,21 @@ int avpicture_layout(const AVPicture* src, enum PixelFormat pix_fmt, int width, pix_fmt == PIX_FMT_BGR565LE || pix_fmt == PIX_FMT_BGR555BE || pix_fmt == PIX_FMT_BGR555LE || + pix_fmt == PIX_FMT_BGR444BE || + pix_fmt == PIX_FMT_BGR444LE || pix_fmt == PIX_FMT_RGB565BE || pix_fmt == PIX_FMT_RGB565LE || pix_fmt == PIX_FMT_RGB555BE || - pix_fmt == PIX_FMT_RGB555LE) + pix_fmt == PIX_FMT_RGB555LE || + pix_fmt == PIX_FMT_RGB444BE || + pix_fmt == PIX_FMT_RGB444LE) w = width * 2; else if (pix_fmt == PIX_FMT_UYYVYY411) - w = width + width/2; + w = width + width/2; else if (pix_fmt == PIX_FMT_PAL8) - w = width; + w = width; else - w = width * (pf->depth * pf->nb_channels / 8); + w = width * (pf->depth * pf->nb_channels / 8); data_planes = 1; h = height; @@ -896,19 +689,21 @@ int avpicture_layout(const AVPicture* src, enum PixelFormat pix_fmt, int width, oh = h; for (i=0; i> pf->x_chroma_shift; - h = height >> pf->y_chroma_shift; - } else if (i == 3) { - w = ow; - h = oh; - } - s = src->data[i]; - for(j=0; jlinesize[i]; - } + if (i == 1) { + w = (- ((-width) >> desc->log2_chroma_w) * pf->depth + 7) / 8; + h = -((-height) >> desc->log2_chroma_h); + if (pix_fmt == PIX_FMT_NV12 || pix_fmt == PIX_FMT_NV21) + w <<= 1; + } else if (i == 3) { + w = ow; + h = oh; + } + s = src->data[i]; + for(j=0; jlinesize[i]; + } } if (pf->pixel_type == FF_PIXEL_PALETTE) @@ -938,6 +733,8 @@ int avcodec_get_pix_fmt_loss(enum PixelFormat dst_pix_fmt, enum PixelFormat src_ 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; ps = &pix_fmt_info[src_pix_fmt]; @@ -946,11 +743,13 @@ int avcodec_get_pix_fmt_loss(enum PixelFormat dst_pix_fmt, enum PixelFormat src_ 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) && - (src_pix_fmt == PIX_FMT_RGB565BE || src_pix_fmt == PIX_FMT_RGB565LE))) + ((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))) loss |= FF_LOSS_DEPTH; - if (pf->x_chroma_shift > ps->x_chroma_shift || - pf->y_chroma_shift > ps->y_chroma_shift) + 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; switch(pf->color_type) { case FF_COLOR_RGB: @@ -993,6 +792,7 @@ static int avg_bits_per_pixel(enum PixelFormat pix_fmt) { int bits; const PixFmtInfo *pf; + const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt]; pf = &pix_fmt_info[pix_fmt]; switch(pf->pixel_type) { @@ -1004,10 +804,14 @@ static int avg_bits_per_pixel(enum PixelFormat pix_fmt) 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: @@ -1019,11 +823,11 @@ static int avg_bits_per_pixel(enum PixelFormat pix_fmt) } break; case FF_PIXEL_PLANAR: - if (pf->x_chroma_shift == 0 && pf->y_chroma_shift == 0) { + if (desc->log2_chroma_w == 0 && desc->log2_chroma_h == 0) { bits = pf->depth * pf->nb_channels; } else { bits = pf->depth + ((2 * pf->depth) >> - (pf->x_chroma_shift + pf->y_chroma_shift)); + (desc->log2_chroma_w + desc->log2_chroma_h)); } break; case FF_PIXEL_PALETTE: @@ -1045,7 +849,7 @@ static enum PixelFormat avcodec_find_best_pix_fmt1(int64_t pix_fmt_mask, enum PixelFormat dst_pix_fmt; /* find exact color match with smallest size */ - dst_pix_fmt = -1; + dst_pix_fmt = PIX_FMT_NONE; min_dist = 0x7fffffff; for(i = 0;i < PIX_FMT_NB; i++) { if (pix_fmt_mask & (1ULL << i)) { @@ -1088,7 +892,7 @@ enum PixelFormat avcodec_find_best_pix_fmt(int64_t pix_fmt_mask, enum PixelForma if (loss_mask == 0) break; } - return -1; + return PIX_FMT_NONE; found: if (loss_ptr) *loss_ptr = avcodec_get_pix_fmt_loss(dst_pix_fmt, src_pix_fmt, has_alpha); @@ -1112,6 +916,7 @@ int ff_get_plane_bytewidth(enum PixelFormat pix_fmt, int width, int plane) { int bits; const PixFmtInfo *pf = &pix_fmt_info[pix_fmt]; + const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt]; pf = &pix_fmt_info[pix_fmt]; switch(pf->pixel_type) { @@ -1123,10 +928,14 @@ int ff_get_plane_bytewidth(enum PixelFormat pix_fmt, int width, int plane) 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: @@ -1140,7 +949,7 @@ int ff_get_plane_bytewidth(enum PixelFormat pix_fmt, int width, int plane) break; case FF_PIXEL_PLANAR: if (plane == 1 || plane == 2) - width= -((-width)>>pf->x_chroma_shift); + width= -((-width)>>desc->log2_chroma_w); return (width * pf->depth + 7) >> 3; break; @@ -1158,6 +967,7 @@ void av_picture_copy(AVPicture *dst, const AVPicture *src, { int i; const PixFmtInfo *pf = &pix_fmt_info[pix_fmt]; + const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt]; switch(pf->pixel_type) { case FF_PIXEL_PACKED: @@ -1167,7 +977,7 @@ void av_picture_copy(AVPicture *dst, const AVPicture *src, int bwidth = ff_get_plane_bytewidth(pix_fmt, width, i); h = height; if (i == 1 || i == 2) { - h= -((-height)>>pf->y_chroma_shift); + h= -((-height)>>desc->log2_chroma_h); } ff_img_copy_plane(dst->data[i], dst->linesize[i], src->data[i], src->linesize[i], @@ -1179,9 +989,7 @@ void av_picture_copy(AVPicture *dst, const AVPicture *src, src->data[0], src->linesize[0], width, height); /* copy the palette */ - ff_img_copy_plane(dst->data[1], dst->linesize[1], - src->data[1], src->linesize[1], - 4, 256); + memcpy(dst->data[1], src->data[1], 4*256); break; } } @@ -1317,8 +1125,8 @@ int av_picture_crop(AVPicture *dst, const AVPicture *src, if (pix_fmt < 0 || pix_fmt >= PIX_FMT_NB || !is_yuv_planar(&pix_fmt_info[pix_fmt])) return -1; - y_shift = pix_fmt_info[pix_fmt].y_chroma_shift; - x_shift = pix_fmt_info[pix_fmt].x_chroma_shift; + y_shift = av_pix_fmt_descriptors[pix_fmt].log2_chroma_h; + x_shift = av_pix_fmt_descriptors[pix_fmt].log2_chroma_w; 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); @@ -1344,8 +1152,8 @@ int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width, !is_yuv_planar(&pix_fmt_info[pix_fmt])) return -1; for (i = 0; i < 3; i++) { - x_shift = i ? pix_fmt_info[pix_fmt].x_chroma_shift : 0; - y_shift = i ? pix_fmt_info[pix_fmt].y_chroma_shift : 0; + x_shift = i ? av_pix_fmt_descriptors[pix_fmt].log2_chroma_w : 0; + y_shift = i ? av_pix_fmt_descriptors[pix_fmt].log2_chroma_h : 0; if (padtop || padleft) { memset(dst->data[i], color[i], diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/imx_dump_header_bsf.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/imx_dump_header_bsf.c index bf41c8355f..2310185b8e 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/imx_dump_header_bsf.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/imx_dump_header_bsf.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/imx_dump_header_bsf.c + * @file * imx dump header bitstream filter * modifies bitstream to fit in mov and be decoded by final cut pro decoder */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/indeo2.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/indeo2.c index 53624a1078..a3d6c80081 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/indeo2.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/indeo2.c @@ -20,13 +20,14 @@ */ /** - * @file libavcodec/indeo2.c + * @file * Intel Indeo 2 decoder. */ #define ALT_BITSTREAM_READER_LE #include "avcodec.h" #include "get_bits.h" #include "indeo2data.h" +#include "libavutil/common.h" typedef struct Ir2Context{ AVCodecContext *avctx; @@ -160,7 +161,7 @@ static int ir2_decode_frame(AVCodecContext *avctx, /* decide whether frame uses deltas or not */ #ifndef ALT_BITSTREAM_READER_LE for (i = 0; i < buf_size; i++) - buf[i] = ff_reverse[buf[i]]; + buf[i] = av_reverse[buf[i]]; #endif start = 48; /* hardcoded for now */ @@ -213,14 +214,24 @@ static av_cold int ir2_decode_init(AVCodecContext *avctx){ return 0; } +static av_cold int ir2_decode_end(AVCodecContext *avctx){ + Ir2Context * const ic = avctx->priv_data; + AVFrame *pic = &ic->picture; + + if (pic->data[0]) + avctx->release_buffer(avctx, pic); + + return 0; +} + AVCodec indeo2_decoder = { "indeo2", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_INDEO2, sizeof(Ir2Context), ir2_decode_init, NULL, - NULL, + ir2_decode_end, ir2_decode_frame, CODEC_CAP_DR1, .long_name = NULL_IF_CONFIG_SMALL("Intel Indeo 2"), diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/indeo3.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/indeo3.c index 05f79258b3..e5df32c672 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/indeo3.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/indeo3.c @@ -1138,7 +1138,7 @@ static av_cold int indeo3_decode_end(AVCodecContext *avctx) AVCodec indeo3_decoder = { "indeo3", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_INDEO3, sizeof(Indeo3DecodeContext), indeo3_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/indeo5.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/indeo5.c new file mode 100644 index 0000000000..2593e55272 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/indeo5.c @@ -0,0 +1,827 @@ +/* + * Indeo Video Interactive v5 compatible decoder + * Copyright (c) 2009 Maxim Poliakovski + * + * 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 + * Indeo Video Interactive version 5 decoder + * + * Indeo5 data is usually transported within .avi or .mov files. + * Known FOURCCs: 'IV50' + */ + +#define ALT_BITSTREAM_READER_LE +#include "avcodec.h" +#include "get_bits.h" +#include "dsputil.h" +#include "ivi_dsp.h" +#include "ivi_common.h" +#include "indeo5data.h" + +/** + * Indeo5 frame types. + */ +enum { + FRAMETYPE_INTRA = 0, + FRAMETYPE_INTER = 1, ///< non-droppable P-frame + FRAMETYPE_INTER_SCAL = 2, ///< droppable P-frame used in the scalability mode + FRAMETYPE_INTER_NOREF = 3, ///< droppable P-frame + FRAMETYPE_NULL = 4 ///< empty frame with no data +}; + +#define IVI5_PIC_SIZE_ESC 15 + +#define IVI5_IS_PROTECTED 0x20 + +typedef struct { + GetBitContext gb; + AVFrame frame; + RVMapDesc rvmap_tabs[9]; ///< local corrected copy of the static rvmap tables + IVIPlaneDesc planes[3]; ///< color planes + const uint8_t *frame_data; ///< input frame data pointer + int buf_switch; ///< used to switch between three buffers + int inter_scal; ///< signals a sequence of scalable inter frames + int dst_buf; ///< buffer index for the currently decoded frame + int ref_buf; ///< inter frame reference buffer index + int ref2_buf; ///< temporal storage for switching buffers + uint32_t frame_size; ///< frame size in bytes + int frame_type; + int prev_frame_type; ///< frame type of the previous frame + int frame_num; + uint32_t pic_hdr_size; ///< picture header size in bytes + uint8_t frame_flags; + uint16_t checksum; ///< frame checksum + + IVIHuffTab mb_vlc; ///< vlc table for decoding macroblock data + + uint16_t gop_hdr_size; + uint8_t gop_flags; + int is_scalable; + uint32_t lock_word; + IVIPicConfig pic_conf; +} IVI5DecContext; + + +/** + * Decodes Indeo5 GOP (Group of pictures) header. + * This header is present in key frames only. + * It defines parameters for all frames in a GOP. + * + * @param ctx [in,out] ptr to the decoder context + * @param avctx [in] ptr to the AVCodecContext + * @return result code: 0 = OK, -1 = error + */ +static int decode_gop_header(IVI5DecContext *ctx, AVCodecContext *avctx) +{ + int result, i, p, tile_size, pic_size_indx, mb_size, blk_size, blk_size_changed = 0; + IVIBandDesc *band, *band1, *band2; + IVIPicConfig pic_conf; + + ctx->gop_flags = get_bits(&ctx->gb, 8); + + ctx->gop_hdr_size = (ctx->gop_flags & 1) ? get_bits(&ctx->gb, 16) : 0; + + if (ctx->gop_flags & IVI5_IS_PROTECTED) + ctx->lock_word = get_bits_long(&ctx->gb, 32); + + tile_size = (ctx->gop_flags & 0x40) ? 64 << get_bits(&ctx->gb, 2) : 0; + if (tile_size > 256) { + av_log(avctx, AV_LOG_ERROR, "Invalid tile size: %d\n", tile_size); + return -1; + } + + /* decode number of wavelet bands */ + /* num_levels * 3 + 1 */ + pic_conf.luma_bands = get_bits(&ctx->gb, 2) * 3 + 1; + pic_conf.chroma_bands = get_bits1(&ctx->gb) * 3 + 1; + ctx->is_scalable = pic_conf.luma_bands != 1 || pic_conf.chroma_bands != 1; + if (ctx->is_scalable && (pic_conf.luma_bands != 4 || pic_conf.chroma_bands != 1)) { + av_log(avctx, AV_LOG_ERROR, "Scalability: unsupported subdivision! Luma bands: %d, chroma bands: %d\n", + pic_conf.luma_bands, pic_conf.chroma_bands); + return -1; + } + + pic_size_indx = get_bits(&ctx->gb, 4); + if (pic_size_indx == IVI5_PIC_SIZE_ESC) { + pic_conf.pic_height = get_bits(&ctx->gb, 13); + pic_conf.pic_width = get_bits(&ctx->gb, 13); + } else { + pic_conf.pic_height = ivi5_common_pic_sizes[pic_size_indx * 2 + 1] << 2; + pic_conf.pic_width = ivi5_common_pic_sizes[pic_size_indx * 2 ] << 2; + } + + if (ctx->gop_flags & 2) { + av_log(avctx, AV_LOG_ERROR, "YV12 picture format not supported!\n"); + return -1; + } + + pic_conf.chroma_height = (pic_conf.pic_height + 3) >> 2; + pic_conf.chroma_width = (pic_conf.pic_width + 3) >> 2; + + if (!tile_size) { + pic_conf.tile_height = pic_conf.pic_height; + pic_conf.tile_width = pic_conf.pic_width; + } else { + pic_conf.tile_height = pic_conf.tile_width = tile_size; + } + + /* check if picture layout was changed and reallocate buffers */ + if (ivi_pic_config_cmp(&pic_conf, &ctx->pic_conf)) { + result = ff_ivi_init_planes(ctx->planes, &pic_conf); + if (result) { + av_log(avctx, AV_LOG_ERROR, "Couldn't reallocate color planes!\n"); + return -1; + } + ctx->pic_conf = pic_conf; + blk_size_changed = 1; /* force reallocation of the internal structures */ + } + + for (p = 0; p <= 1; p++) { + for (i = 0; i < (!p ? pic_conf.luma_bands : pic_conf.chroma_bands); i++) { + band = &ctx->planes[p].bands[i]; + + band->is_halfpel = get_bits1(&ctx->gb); + + mb_size = get_bits1(&ctx->gb); + blk_size = 8 >> get_bits1(&ctx->gb); + mb_size = blk_size << !mb_size; + + blk_size_changed = mb_size != band->mb_size || blk_size != band->blk_size; + if (blk_size_changed) { + band->mb_size = mb_size; + band->blk_size = blk_size; + } + + if (get_bits1(&ctx->gb)) { + av_log(avctx, AV_LOG_ERROR, "Extended transform info encountered!\n"); + return -1; + } + + /* select transform function and scan pattern according to plane and band number */ + switch ((p << 2) + i) { + case 0: + band->inv_transform = ff_ivi_inverse_slant_8x8; + band->dc_transform = ff_ivi_dc_slant_2d; + band->scan = ff_zigzag_direct; + break; + + case 1: + band->inv_transform = ff_ivi_row_slant8; + band->dc_transform = ff_ivi_dc_row_slant; + band->scan = ivi5_scans8x8[0]; + break; + + case 2: + band->inv_transform = ff_ivi_col_slant8; + band->dc_transform = ff_ivi_dc_col_slant; + band->scan = ivi5_scans8x8[1]; + break; + + case 3: + band->inv_transform = ff_ivi_put_pixels_8x8; + band->dc_transform = ff_ivi_put_dc_pixel_8x8; + band->scan = ivi5_scans8x8[1]; + break; + + case 4: + band->inv_transform = ff_ivi_inverse_slant_4x4; + band->dc_transform = ff_ivi_dc_slant_2d; + band->scan = ivi5_scan4x4; + break; + } + + band->is_2d_trans = band->inv_transform == ff_ivi_inverse_slant_8x8 || + band->inv_transform == ff_ivi_inverse_slant_4x4; + + /* select dequant matrix according to plane and band number */ + if (!p) { + band->quant_mat = (pic_conf.luma_bands > 1) ? i+1 : 0; + } else { + band->quant_mat = 5; + } + + if (get_bits(&ctx->gb, 2)) { + av_log(avctx, AV_LOG_ERROR, "End marker missing!\n"); + return -1; + } + } + } + + /* copy chroma parameters into the 2nd chroma plane */ + for (i = 0; i < pic_conf.chroma_bands; i++) { + band1 = &ctx->planes[1].bands[i]; + band2 = &ctx->planes[2].bands[i]; + + band2->width = band1->width; + band2->height = band1->height; + band2->mb_size = band1->mb_size; + band2->blk_size = band1->blk_size; + band2->is_halfpel = band1->is_halfpel; + band2->quant_mat = band1->quant_mat; + band2->scan = band1->scan; + band2->inv_transform = band1->inv_transform; + band2->dc_transform = band1->dc_transform; + band2->is_2d_trans = band1->is_2d_trans; + } + + /* reallocate internal structures if needed */ + if (blk_size_changed) { + result = ff_ivi_init_tiles(ctx->planes, pic_conf.tile_width, + pic_conf.tile_height); + if (result) { + av_log(avctx, AV_LOG_ERROR, + "Couldn't reallocate internal structures!\n"); + return -1; + } + } + + if (ctx->gop_flags & 8) { + if (get_bits(&ctx->gb, 3)) { + av_log(avctx, AV_LOG_ERROR, "Alignment bits are not zero!\n"); + return -1; + } + + if (get_bits1(&ctx->gb)) + skip_bits_long(&ctx->gb, 24); /* skip transparency fill color */ + } + + align_get_bits(&ctx->gb); + + skip_bits(&ctx->gb, 23); /* FIXME: unknown meaning */ + + /* skip GOP extension if any */ + if (get_bits1(&ctx->gb)) { + do { + i = get_bits(&ctx->gb, 16); + } while (i & 0x8000); + } + + align_get_bits(&ctx->gb); + + return 0; +} + + +/** + * Skips a header extension. + * + * @param gb [in,out] the GetBit context + */ +static inline void skip_hdr_extension(GetBitContext *gb) +{ + int i, len; + + do { + len = get_bits(gb, 8); + for (i = 0; i < len; i++) skip_bits(gb, 8); + } while(len); +} + + +/** + * Decodes Indeo5 picture header. + * + * @param ctx [in,out] ptr to the decoder context + * @param avctx [in] ptr to the AVCodecContext + * @return result code: 0 = OK, -1 = error + */ +static int decode_pic_hdr(IVI5DecContext *ctx, AVCodecContext *avctx) +{ + if (get_bits(&ctx->gb, 5) != 0x1F) { + av_log(avctx, AV_LOG_ERROR, "Invalid picture start code!\n"); + return -1; + } + + ctx->prev_frame_type = ctx->frame_type; + ctx->frame_type = get_bits(&ctx->gb, 3); + if (ctx->frame_type >= 5) { + av_log(avctx, AV_LOG_ERROR, "Invalid frame type: %d \n", ctx->frame_type); + return -1; + } + + ctx->frame_num = get_bits(&ctx->gb, 8); + + if (ctx->frame_type == FRAMETYPE_INTRA) { + if (decode_gop_header(ctx, avctx)) + return -1; + } + + if (ctx->frame_type != FRAMETYPE_NULL) { + ctx->frame_flags = get_bits(&ctx->gb, 8); + + ctx->pic_hdr_size = (ctx->frame_flags & 1) ? get_bits_long(&ctx->gb, 24) : 0; + + ctx->checksum = (ctx->frame_flags & 0x10) ? get_bits(&ctx->gb, 16) : 0; + + /* skip unknown extension if any */ + if (ctx->frame_flags & 0x20) + skip_hdr_extension(&ctx->gb); /* XXX: untested */ + + /* decode macroblock huffman codebook */ + if (ff_ivi_dec_huff_desc(&ctx->gb, ctx->frame_flags & 0x40, IVI_MB_HUFF, &ctx->mb_vlc, avctx)) + return -1; + + skip_bits(&ctx->gb, 3); /* FIXME: unknown meaning! */ + } + + align_get_bits(&ctx->gb); + + return 0; +} + + +/** + * Decodes Indeo5 band header. + * + * @param ctx [in,out] ptr to the decoder context + * @param band [in,out] ptr to the band descriptor + * @param avctx [in] ptr to the AVCodecContext + * @return result code: 0 = OK, -1 = error + */ +static int decode_band_hdr(IVI5DecContext *ctx, IVIBandDesc *band, + AVCodecContext *avctx) +{ + int i; + uint8_t band_flags; + + band_flags = get_bits(&ctx->gb, 8); + + if (band_flags & 1) { + band->is_empty = 1; + return 0; + } + + band->data_size = (ctx->frame_flags & 0x80) ? get_bits_long(&ctx->gb, 24) : 0; + + band->inherit_mv = band_flags & 2; + band->inherit_qdelta = band_flags & 8; + band->qdelta_present = band_flags & 4; + if (!band->qdelta_present) band->inherit_qdelta = 1; + + /* decode rvmap probability corrections if any */ + band->num_corr = 0; /* there are no corrections */ + if (band_flags & 0x10) { + band->num_corr = get_bits(&ctx->gb, 8); /* get number of correction pairs */ + if (band->num_corr > 61) { + av_log(avctx, AV_LOG_ERROR, "Too many corrections: %d\n", + band->num_corr); + return -1; + } + + /* read correction pairs */ + for (i = 0; i < band->num_corr * 2; i++) + band->corr[i] = get_bits(&ctx->gb, 8); + } + + /* select appropriate rvmap table for this band */ + band->rvmap_sel = (band_flags & 0x40) ? get_bits(&ctx->gb, 3) : 8; + + /* decode block huffman codebook */ + if (ff_ivi_dec_huff_desc(&ctx->gb, band_flags & 0x80, IVI_BLK_HUFF, &band->blk_vlc, avctx)) + return -1; + + band->checksum_present = get_bits1(&ctx->gb); + if (band->checksum_present) + band->checksum = get_bits(&ctx->gb, 16); + + band->glob_quant = get_bits(&ctx->gb, 5); + + /* skip unknown extension if any */ + if (band_flags & 0x20) { /* XXX: untested */ + align_get_bits(&ctx->gb); + skip_hdr_extension(&ctx->gb); + } + + align_get_bits(&ctx->gb); + + return 0; +} + + +/** + * Decodes info (block type, cbp, quant delta, motion vector) + * for all macroblocks in the current tile. + * + * @param ctx [in,out] ptr to the decoder context + * @param band [in,out] ptr to the band descriptor + * @param tile [in,out] ptr to the tile descriptor + * @param avctx [in] ptr to the AVCodecContext + * @return result code: 0 = OK, -1 = error + */ +static int decode_mb_info(IVI5DecContext *ctx, IVIBandDesc *band, + IVITile *tile, AVCodecContext *avctx) +{ + int x, y, mv_x, mv_y, mv_delta, offs, mb_offset, + mv_scale, blks_per_mb; + IVIMbInfo *mb, *ref_mb; + int row_offset = band->mb_size * band->pitch; + + mb = tile->mbs; + ref_mb = tile->ref_mbs; + offs = tile->ypos * band->pitch + tile->xpos; + + /* scale factor for motion vectors */ + mv_scale = (ctx->planes[0].bands[0].mb_size >> 3) - (band->mb_size >> 3); + mv_x = mv_y = 0; + + for (y = tile->ypos; y < (tile->ypos + tile->height); y += band->mb_size) { + mb_offset = offs; + + for (x = tile->xpos; x < (tile->xpos + tile->width); x += band->mb_size) { + mb->xpos = x; + mb->ypos = y; + mb->buf_offs = mb_offset; + + if (get_bits1(&ctx->gb)) { + if (ctx->frame_type == FRAMETYPE_INTRA) { + av_log(avctx, AV_LOG_ERROR, "Empty macroblock in an INTRA picture!\n"); + return -1; + } + mb->type = 1; /* empty macroblocks are always INTER */ + mb->cbp = 0; /* all blocks are empty */ + + mb->q_delta = 0; + if (!band->plane && !band->band_num && (ctx->frame_flags & 8)) { + mb->q_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table, + IVI_VLC_BITS, 1); + mb->q_delta = IVI_TOSIGNED(mb->q_delta); + } + + mb->mv_x = mb->mv_y = 0; /* no motion vector coded */ + if (band->inherit_mv){ + /* motion vector inheritance */ + if (mv_scale) { + mb->mv_x = ivi_scale_mv(ref_mb->mv_x, mv_scale); + mb->mv_y = ivi_scale_mv(ref_mb->mv_y, mv_scale); + } else { + mb->mv_x = ref_mb->mv_x; + mb->mv_y = ref_mb->mv_y; + } + } + } else { + if (band->inherit_mv) { + mb->type = ref_mb->type; /* copy mb_type from corresponding reference mb */ + } else if (ctx->frame_type == FRAMETYPE_INTRA) { + mb->type = 0; /* mb_type is always INTRA for intra-frames */ + } else { + mb->type = get_bits1(&ctx->gb); + } + + blks_per_mb = band->mb_size != band->blk_size ? 4 : 1; + mb->cbp = get_bits(&ctx->gb, blks_per_mb); + + mb->q_delta = 0; + if (band->qdelta_present) { + if (band->inherit_qdelta) { + if (ref_mb) mb->q_delta = ref_mb->q_delta; + } else if (mb->cbp || (!band->plane && !band->band_num && + (ctx->frame_flags & 8))) { + mb->q_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table, + IVI_VLC_BITS, 1); + mb->q_delta = IVI_TOSIGNED(mb->q_delta); + } + } + + if (!mb->type) { + mb->mv_x = mb->mv_y = 0; /* there is no motion vector in intra-macroblocks */ + } else { + if (band->inherit_mv){ + /* motion vector inheritance */ + if (mv_scale) { + mb->mv_x = ivi_scale_mv(ref_mb->mv_x, mv_scale); + mb->mv_y = ivi_scale_mv(ref_mb->mv_y, mv_scale); + } else { + mb->mv_x = ref_mb->mv_x; + mb->mv_y = ref_mb->mv_y; + } + } else { + /* decode motion vector deltas */ + mv_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table, + IVI_VLC_BITS, 1); + mv_y += IVI_TOSIGNED(mv_delta); + mv_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table, + IVI_VLC_BITS, 1); + mv_x += IVI_TOSIGNED(mv_delta); + mb->mv_x = mv_x; + mb->mv_y = mv_y; + } + } + } + + mb++; + if (ref_mb) + ref_mb++; + mb_offset += band->mb_size; + } + + offs += row_offset; + } + + align_get_bits(&ctx->gb); + + return 0; +} + + +/** + * Decodes an Indeo5 band. + * + * @param ctx [in,out] ptr to the decoder context + * @param band [in,out] ptr to the band descriptor + * @param avctx [in] ptr to the AVCodecContext + * @return result code: 0 = OK, -1 = error + */ +static int decode_band(IVI5DecContext *ctx, int plane_num, + IVIBandDesc *band, AVCodecContext *avctx) +{ + int result, i, t, idx1, idx2, pos; + IVITile *tile; + + band->buf = band->bufs[ctx->dst_buf]; + band->ref_buf = band->bufs[ctx->ref_buf]; + band->data_ptr = ctx->frame_data + (get_bits_count(&ctx->gb) >> 3); + + result = decode_band_hdr(ctx, band, avctx); + if (result) { + av_log(avctx, AV_LOG_ERROR, "Error while decoding band header: %d\n", + result); + return -1; + } + + if (band->is_empty) { + av_log(avctx, AV_LOG_ERROR, "Empty band encountered!\n"); + return -1; + } + + if (band->blk_size == 8) { + band->intra_base = &ivi5_base_quant_8x8_intra[band->quant_mat][0]; + band->inter_base = &ivi5_base_quant_8x8_inter[band->quant_mat][0]; + band->intra_scale = &ivi5_scale_quant_8x8_intra[band->quant_mat][0]; + band->inter_scale = &ivi5_scale_quant_8x8_inter[band->quant_mat][0]; + } else { + band->intra_base = ivi5_base_quant_4x4_intra; + band->inter_base = ivi5_base_quant_4x4_inter; + band->intra_scale = ivi5_scale_quant_4x4_intra; + band->inter_scale = ivi5_scale_quant_4x4_inter; + } + + band->rv_map = &ctx->rvmap_tabs[band->rvmap_sel]; + + /* apply corrections to the selected rvmap table if present */ + for (i = 0; i < band->num_corr; i++) { + idx1 = band->corr[i*2]; + idx2 = band->corr[i*2+1]; + FFSWAP(uint8_t, band->rv_map->runtab[idx1], band->rv_map->runtab[idx2]); + FFSWAP(int16_t, band->rv_map->valtab[idx1], band->rv_map->valtab[idx2]); + } + + pos = get_bits_count(&ctx->gb); + + for (t = 0; t < band->num_tiles; t++) { + tile = &band->tiles[t]; + + tile->is_empty = get_bits1(&ctx->gb); + if (tile->is_empty) { + ff_ivi_process_empty_tile(avctx, band, tile, + (ctx->planes[0].bands[0].mb_size >> 3) - (band->mb_size >> 3)); + } else { + tile->data_size = ff_ivi_dec_tile_data_size(&ctx->gb); + + result = decode_mb_info(ctx, band, tile, avctx); + if (result < 0) + break; + + result = ff_ivi_decode_blocks(&ctx->gb, band, tile); + if (result < 0 || (get_bits_count(&ctx->gb) - pos) >> 3 != tile->data_size) { + av_log(avctx, AV_LOG_ERROR, "Corrupted tile data encountered!\n"); + break; + } + pos += tile->data_size << 3; // skip to next tile + } + } + + /* restore the selected rvmap table by applying its corrections in reverse order */ + for (i = band->num_corr-1; i >= 0; i--) { + idx1 = band->corr[i*2]; + idx2 = band->corr[i*2+1]; + FFSWAP(uint8_t, band->rv_map->runtab[idx1], band->rv_map->runtab[idx2]); + FFSWAP(int16_t, band->rv_map->valtab[idx1], band->rv_map->valtab[idx2]); + } + +#if IVI_DEBUG + if (band->checksum_present) { + uint16_t chksum = ivi_calc_band_checksum(band); + if (chksum != band->checksum) { + av_log(avctx, AV_LOG_ERROR, + "Band checksum mismatch! Plane %d, band %d, received: %x, calculated: %x\n", + band->plane, band->band_num, band->checksum, chksum); + } + } +#endif + + align_get_bits(&ctx->gb); + + return result; +} + + +/** + * Switches buffers. + * + * @param ctx [in,out] ptr to the decoder context + * @param avctx [in] ptr to the AVCodecContext + */ +static void switch_buffers(IVI5DecContext *ctx, AVCodecContext *avctx) +{ + switch (ctx->prev_frame_type) { + case FRAMETYPE_INTRA: + case FRAMETYPE_INTER: + ctx->buf_switch ^= 1; + ctx->dst_buf = ctx->buf_switch; + ctx->ref_buf = ctx->buf_switch ^ 1; + break; + case FRAMETYPE_INTER_SCAL: + if (!ctx->inter_scal) { + ctx->ref2_buf = 2; + ctx->inter_scal = 1; + } + FFSWAP(int, ctx->dst_buf, ctx->ref2_buf); + ctx->ref_buf = ctx->ref2_buf; + break; + case FRAMETYPE_INTER_NOREF: + break; + } + + switch (ctx->frame_type) { + case FRAMETYPE_INTRA: + ctx->buf_switch = 0; + /* FALLTHROUGH */ + case FRAMETYPE_INTER: + ctx->inter_scal = 0; + ctx->dst_buf = ctx->buf_switch; + ctx->ref_buf = ctx->buf_switch ^ 1; + break; + case FRAMETYPE_INTER_SCAL: + case FRAMETYPE_INTER_NOREF: + case FRAMETYPE_NULL: + break; + } +} + + +/** + * Initializes Indeo5 decoder. + */ +static av_cold int decode_init(AVCodecContext *avctx) +{ + IVI5DecContext *ctx = avctx->priv_data; + int result; + + ff_ivi_init_static_vlc(); + + /* copy rvmap tables in our context so we can apply changes to them */ + memcpy(ctx->rvmap_tabs, ff_ivi_rvmap_tabs, sizeof(ff_ivi_rvmap_tabs)); + + /* set the initial picture layout according to the basic profile: + there is only one band per plane (no scalability), only one tile (no local decoding) + and picture format = YVU9 */ + ctx->pic_conf.pic_width = avctx->width; + ctx->pic_conf.pic_height = avctx->height; + ctx->pic_conf.chroma_width = (avctx->width + 3) >> 2; + ctx->pic_conf.chroma_height = (avctx->height + 3) >> 2; + ctx->pic_conf.tile_width = avctx->width; + ctx->pic_conf.tile_height = avctx->height; + ctx->pic_conf.luma_bands = ctx->pic_conf.chroma_bands = 1; + + result = ff_ivi_init_planes(ctx->planes, &ctx->pic_conf); + if (result) { + av_log(avctx, AV_LOG_ERROR, "Couldn't allocate color planes!\n"); + return -1; + } + + ctx->buf_switch = 0; + ctx->inter_scal = 0; + + avctx->pix_fmt = PIX_FMT_YUV410P; + + return 0; +} + + +/** + * main decoder function + */ +static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, + AVPacket *avpkt) +{ + IVI5DecContext *ctx = avctx->priv_data; + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + int result, p, b; + + init_get_bits(&ctx->gb, buf, buf_size * 8); + ctx->frame_data = buf; + ctx->frame_size = buf_size; + + result = decode_pic_hdr(ctx, avctx); + if (result) { + av_log(avctx, AV_LOG_ERROR, + "Error while decoding picture header: %d\n", result); + return -1; + } + + if (ctx->gop_flags & IVI5_IS_PROTECTED) { + av_log(avctx, AV_LOG_ERROR, "Password-protected clip!\n"); + return -1; + } + + switch_buffers(ctx, avctx); + + //START_TIMER; + + if (ctx->frame_type != FRAMETYPE_NULL) { + for (p = 0; p < 3; p++) { + for (b = 0; b < ctx->planes[p].num_bands; b++) { + result = decode_band(ctx, p, &ctx->planes[p].bands[b], avctx); + if (result) { + av_log(avctx, AV_LOG_ERROR, + "Error while decoding band: %d, plane: %d\n", b, p); + return -1; + } + } + } + } + + //STOP_TIMER("decode_planes"); + + if (ctx->frame.data[0]) + avctx->release_buffer(avctx, &ctx->frame); + + ctx->frame.reference = 0; + if (avctx->get_buffer(avctx, &ctx->frame) < 0) { + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } + + if (ctx->is_scalable) { + ff_ivi_recompose53 (&ctx->planes[0], ctx->frame.data[0], ctx->frame.linesize[0], 4); + } else { + ff_ivi_output_plane(&ctx->planes[0], ctx->frame.data[0], ctx->frame.linesize[0]); + } + + ff_ivi_output_plane(&ctx->planes[2], ctx->frame.data[1], ctx->frame.linesize[1]); + ff_ivi_output_plane(&ctx->planes[1], ctx->frame.data[2], ctx->frame.linesize[2]); + + *data_size = sizeof(AVFrame); + *(AVFrame*)data = ctx->frame; + + return buf_size; +} + + +/** + * Closes Indeo5 decoder and cleans up its context. + */ +static av_cold int decode_close(AVCodecContext *avctx) +{ + IVI5DecContext *ctx = avctx->priv_data; + + ff_ivi_free_buffers(&ctx->planes[0]); + + if (ctx->mb_vlc.cust_tab.table) + free_vlc(&ctx->mb_vlc.cust_tab); + + if (ctx->frame.data[0]) + avctx->release_buffer(avctx, &ctx->frame); + + return 0; +} + + +AVCodec indeo5_decoder = { + .name = "indeo5", + .type = AVMEDIA_TYPE_VIDEO, + .id = CODEC_ID_INDEO5, + .priv_data_size = sizeof(IVI5DecContext), + .init = decode_init, + .close = decode_close, + .decode = decode_frame, + .long_name = NULL_IF_CONFIG_SMALL("Intel Indeo Video Interactive 5"), +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/indeo5data.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/indeo5data.h new file mode 100644 index 0000000000..972e59886b --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/indeo5data.h @@ -0,0 +1,185 @@ +/* + * Indeo Video Interactive 5 compatible decoder + * Copyright (c) 2009 Maxim Poliakovski + * + * 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 + * This file contains data needed for the Indeo5 decoder. + */ + +#ifndef AVCODEC_INDEO5DATA_H +#define AVCODEC_INDEO5DATA_H + +#include + +/** + * standard picture dimensions (width, height divided by 4) + */ +static const uint8_t ivi5_common_pic_sizes[30] = { + 160, 120, 80, 60, 40, 30, 176, 120, 88, 60, 88, 72, 44, 36, 60, 45, 160, 60, + 176, 60, 20, 15, 22, 18, 0, 0, 0, 0, 0, 0 +}; + +/** + * Indeo5 8x8 scan (zigzag) patterns + */ +static const uint8_t ivi5_scans8x8[2][64] = { + {0, 8, 16, 24, 32, 40, 48, 56, 1, 9, 17, 25, 33, 41, 49, 57, + 2, 10, 18, 26, 34, 42, 50, 58, 3, 11, 19, 27, 35, 43, 51, 59, + 4, 12, 20, 28, 36, 44, 52, 60, 5, 13, 21, 29, 37, 45, 53, 61, + 6, 14, 22, 30, 38, 46, 54, 62, 7, 15, 23, 31, 39, 47, 55, 63 + }, + {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, + 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 + } +}; + +/** + * Indeo5 4x4 scan (zigzag) pattern + */ +static const uint8_t ivi5_scan4x4[16] = { + 0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 10, 7, 11, 14, 15 +}; + + +/** + * Indeo5 dequantization matrixes consist of two tables: base table + * and scale table. The base table defines the dequantization matrix + * itself and the scale table tells how this matrix should be scaled + * for a particular quant level (0...24). + * + * ivi5_base_quant_bbb_ttt - base tables for block size 'bbb' of type 'ttt' + * ivi5_scale_quant_bbb_ttt - scale tables for block size 'bbb' of type 'ttt' + */ +static const uint8_t ivi5_base_quant_8x8_inter[5][64] = { + {0x13, 0x1d, 0x1f, 0x23, 0x25, 0x27, 0x29, 0x2d, 0x1d, 0x1f, 0x21, 0x23, 0x25, 0x27, 0x2b, 0x2f, + 0x1f, 0x21, 0x23, 0x24, 0x26, 0x29, 0x2d, 0x31, 0x23, 0x23, 0x24, 0x25, 0x27, 0x2b, 0x2f, 0x33, + 0x25, 0x25, 0x26, 0x27, 0x29, 0x2d, 0x31, 0x35, 0x27, 0x27, 0x29, 0x2b, 0x2d, 0x2f, 0x33, 0x37, + 0x29, 0x2b, 0x2d, 0x2f, 0x31, 0x33, 0x35, 0x39, 0x2d, 0x2f, 0x31, 0x33, 0x35, 0x37, 0x39, 0x3b + }, + {0x13, 0x1d, 0x1f, 0x23, 0x25, 0x27, 0x29, 0x2d, 0x1d, 0x1f, 0x21, 0x23, 0x25, 0x27, 0x2b, 0x2f, + 0x1f, 0x21, 0x23, 0x24, 0x26, 0x29, 0x2d, 0x31, 0x23, 0x23, 0x24, 0x25, 0x27, 0x2b, 0x2f, 0x33, + 0x25, 0x25, 0x26, 0x27, 0x29, 0x2d, 0x31, 0x35, 0x27, 0x27, 0x29, 0x2b, 0x2d, 0x2f, 0x33, 0x37, + 0x29, 0x2b, 0x2d, 0x2f, 0x31, 0x33, 0x35, 0x39, 0x2d, 0x2f, 0x31, 0x33, 0x35, 0x37, 0x39, 0x3b + }, + {0x27, 0x55, 0x79, 0x6a, 0x6f, 0x61, 0x6b, 0x61, 0x27, 0x55, 0x79, 0x6a, 0x6f, 0x61, 0x6b, 0x61, + 0x27, 0x55, 0x79, 0x6a, 0x6f, 0x61, 0x6b, 0x61, 0x27, 0x55, 0x79, 0x6a, 0x6f, 0x61, 0x6b, 0x61, + 0x27, 0x55, 0x79, 0x6a, 0x6f, 0x61, 0x6b, 0x61, 0x27, 0x55, 0x79, 0x6a, 0x6f, 0x61, 0x6b, 0x61, + 0x27, 0x55, 0x79, 0x6a, 0x6f, 0x61, 0x6b, 0x61, 0x27, 0x55, 0x79, 0x6a, 0x6f, 0x61, 0x6b, 0x61 + }, + {0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, + 0x79, 0x79, 0x79, 0x79, 0x79, 0x79, 0x79, 0x79, 0x6a, 0x6a, 0x6a, 0x6a, 0x6a, 0x6a, 0x6a, 0x6a, + 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, + 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61 + }, + {0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, + 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, + 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, + 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f + } +}; + +static const uint8_t ivi5_base_quant_8x8_intra[5][64] = { + {0x0d, 0x17, 0x1b, 0x21, 0x23, 0x25, 0x27, 0x2d, 0x17, 0x19, 0x1f, 0x21, 0x23, 0x27, 0x2b, 0x35, + 0x1b, 0x1f, 0x1f, 0x22, 0x25, 0x2a, 0x33, 0x39, 0x21, 0x21, 0x22, 0x25, 0x29, 0x31, 0x36, 0x3d, + 0x23, 0x23, 0x25, 0x29, 0x2f, 0x33, 0x39, 0x47, 0x25, 0x27, 0x2a, 0x31, 0x33, 0x37, 0x43, 0x53, + 0x27, 0x2b, 0x33, 0x36, 0x39, 0x43, 0x4d, 0x65, 0x2d, 0x35, 0x39, 0x3d, 0x47, 0x53, 0x65, 0x7f + }, + {0x13, 0x1d, 0x1f, 0x23, 0x25, 0x27, 0x29, 0x2d, 0x1d, 0x1f, 0x21, 0x23, 0x25, 0x27, 0x2b, 0x2f, + 0x1f, 0x21, 0x23, 0x24, 0x26, 0x29, 0x2d, 0x31, 0x23, 0x23, 0x24, 0x25, 0x27, 0x2b, 0x2f, 0x33, + 0x25, 0x25, 0x26, 0x27, 0x29, 0x2d, 0x31, 0x35, 0x27, 0x27, 0x29, 0x2b, 0x2d, 0x2f, 0x33, 0x37, + 0x29, 0x2b, 0x2d, 0x2f, 0x31, 0x33, 0x35, 0x39, 0x2d, 0x2f, 0x31, 0x33, 0x35, 0x37, 0x39, 0x3b + }, + {0x27, 0x55, 0x79, 0x6a, 0x6f, 0x61, 0x6b, 0x61, 0x27, 0x55, 0x79, 0x6a, 0x6f, 0x61, 0x6b, 0x61, + 0x27, 0x55, 0x79, 0x6a, 0x6f, 0x61, 0x6b, 0x61, 0x27, 0x55, 0x79, 0x6a, 0x6f, 0x61, 0x6b, 0x61, + 0x27, 0x55, 0x79, 0x6a, 0x6f, 0x61, 0x6b, 0x61, 0x27, 0x55, 0x79, 0x6a, 0x6f, 0x61, 0x6b, 0x61, + 0x27, 0x55, 0x79, 0x6a, 0x6f, 0x61, 0x6b, 0x61, 0x27, 0x55, 0x79, 0x6a, 0x6f, 0x61, 0x6b, 0x61 + }, + {0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x27, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, + 0x79, 0x79, 0x79, 0x79, 0x79, 0x79, 0x79, 0x79, 0x6a, 0x6a, 0x6a, 0x6a, 0x6a, 0x6a, 0x6a, 0x6a, + 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x6f, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, + 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x6b, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61 + }, + {0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, + 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, + 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, + 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f, 0x2f + } +}; + +static const uint8_t ivi5_base_quant_4x4_inter[16] = { + 0x0f, 0x1f, 0x25, 0x29, 0x1f, 0x25, 0x29, 0x2b, 0x25, 0x29, 0x2b, 0x2f, 0x29, 0x2b, 0x2f, 0x33 +}; + +static const uint8_t ivi5_base_quant_4x4_intra[16] = { + 0x0f, 0x1f, 0x25, 0x29, 0x1f, 0x25, 0x29, 0x2f, 0x25, 0x29, 0x2f, 0x3d, 0x29, 0x2f, 0x3d, 0x49 +}; + + +static const uint8_t ivi5_scale_quant_8x8_inter[5][24] = { + {0x0b, 0x11, 0x13, 0x14, 0x15, 0x16, 0x18, 0x1a, 0x1b, 0x1d, 0x20, 0x22, + 0x23, 0x25, 0x28, 0x2a, 0x2e, 0x32, 0x35, 0x39, 0x3d, 0x41, 0x44, 0x4a, + }, + {0x07, 0x14, 0x16, 0x18, 0x1b, 0x1e, 0x22, 0x25, 0x29, 0x2d, 0x31, 0x35, + 0x3a, 0x3f, 0x44, 0x4a, 0x50, 0x56, 0x5c, 0x63, 0x6a, 0x71, 0x78, 0x7e, + }, + {0x15, 0x25, 0x28, 0x2d, 0x30, 0x34, 0x3a, 0x3d, 0x42, 0x48, 0x4c, 0x51, + 0x56, 0x5b, 0x60, 0x65, 0x6b, 0x70, 0x76, 0x7c, 0x82, 0x88, 0x8f, 0x97, + }, + {0x13, 0x1f, 0x20, 0x22, 0x25, 0x28, 0x2b, 0x2d, 0x30, 0x33, 0x36, 0x39, + 0x3c, 0x3f, 0x42, 0x45, 0x48, 0x4b, 0x4e, 0x52, 0x56, 0x5a, 0x5e, 0x62, + }, + {0x3c, 0x52, 0x58, 0x5d, 0x63, 0x68, 0x68, 0x6d, 0x73, 0x78, 0x7c, 0x80, + 0x84, 0x89, 0x8e, 0x93, 0x98, 0x9d, 0xa3, 0xa9, 0xad, 0xb1, 0xb5, 0xba, + }, +}; + +static const uint8_t ivi5_scale_quant_8x8_intra[5][24] = { + {0x0b, 0x0e, 0x10, 0x12, 0x14, 0x16, 0x17, 0x18, 0x1a, 0x1c, 0x1e, 0x20, + 0x22, 0x24, 0x27, 0x28, 0x2a, 0x2d, 0x2f, 0x31, 0x34, 0x37, 0x39, 0x3c, + }, + {0x01, 0x10, 0x12, 0x14, 0x16, 0x18, 0x1b, 0x1e, 0x22, 0x25, 0x28, 0x2c, + 0x30, 0x34, 0x38, 0x3d, 0x42, 0x47, 0x4c, 0x52, 0x58, 0x5e, 0x65, 0x6c, + }, + {0x13, 0x22, 0x27, 0x2a, 0x2d, 0x33, 0x36, 0x3c, 0x41, 0x45, 0x49, 0x4e, + 0x53, 0x58, 0x5d, 0x63, 0x69, 0x6f, 0x75, 0x7c, 0x82, 0x88, 0x8e, 0x95, + }, + {0x13, 0x1f, 0x21, 0x24, 0x27, 0x29, 0x2d, 0x2f, 0x34, 0x37, 0x3a, 0x3d, + 0x40, 0x44, 0x48, 0x4c, 0x4f, 0x52, 0x56, 0x5a, 0x5e, 0x62, 0x66, 0x6b, + }, + {0x31, 0x42, 0x47, 0x47, 0x4d, 0x52, 0x58, 0x58, 0x5d, 0x63, 0x67, 0x6b, + 0x6f, 0x73, 0x78, 0x7c, 0x80, 0x84, 0x89, 0x8e, 0x93, 0x98, 0x9d, 0xa4, + } +}; + +static const uint8_t ivi5_scale_quant_4x4_inter[24] = { + 0x0b, 0x0d, 0x0d, 0x0e, 0x11, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, +}; + +static const uint8_t ivi5_scale_quant_4x4_intra[24] = { + 0x01, 0x0b, 0x0b, 0x0d, 0x0d, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x13, 0x14, + 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20 +}; + + +#endif /* AVCODEC_INDEO5DATA_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/intelh263dec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/intelh263dec.c new file mode 100644 index 0000000000..5e451294da --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/intelh263dec.c @@ -0,0 +1,131 @@ +/* + * H.263i decoder + * + * 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 "mpegvideo.h" +#include "h263.h" + +/* don't understand why they choose a different header ! */ +int ff_intel_h263_decode_picture_header(MpegEncContext *s) +{ + int format; + + /* picture header */ + if (get_bits_long(&s->gb, 22) != 0x20) { + av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n"); + return -1; + } + s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */ + + if (get_bits1(&s->gb) != 1) { + av_log(s->avctx, AV_LOG_ERROR, "Bad marker\n"); + return -1; /* marker */ + } + if (get_bits1(&s->gb) != 0) { + av_log(s->avctx, AV_LOG_ERROR, "Bad H263 id\n"); + return -1; /* h263 id */ + } + skip_bits1(&s->gb); /* split screen off */ + skip_bits1(&s->gb); /* camera off */ + skip_bits1(&s->gb); /* freeze picture release off */ + + format = get_bits(&s->gb, 3); + if (format != 7) { + av_log(s->avctx, AV_LOG_ERROR, "Intel H263 free format not supported\n"); + return -1; + } + s->h263_plus = 0; + + s->pict_type = FF_I_TYPE + get_bits1(&s->gb); + + s->unrestricted_mv = get_bits1(&s->gb); + s->h263_long_vectors = s->unrestricted_mv; + + if (get_bits1(&s->gb) != 0) { + av_log(s->avctx, AV_LOG_ERROR, "SAC not supported\n"); + return -1; /* SAC: off */ + } + s->obmc= get_bits1(&s->gb); + s->pb_frame = get_bits1(&s->gb); + + if(format == 7){ + format = get_bits(&s->gb, 3); + if(format == 0 || format == 7){ + av_log(s->avctx, AV_LOG_ERROR, "Wrong Intel H263 format\n"); + return -1; + } + if(get_bits(&s->gb, 2)) + av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n"); + s->loop_filter = get_bits1(&s->gb); + if(get_bits1(&s->gb)) + av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n"); + if(get_bits1(&s->gb)) + s->pb_frame = 2; + if(get_bits(&s->gb, 5)) + av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n"); + if(get_bits(&s->gb, 5) != 1) + av_log(s->avctx, AV_LOG_ERROR, "Invalid marker\n"); + } + if(format == 6){ + int ar = get_bits(&s->gb, 4); + skip_bits(&s->gb, 9); // display width + skip_bits1(&s->gb); + skip_bits(&s->gb, 9); // display height + if(ar == 15){ + skip_bits(&s->gb, 8); // aspect ratio - width + skip_bits(&s->gb, 8); // aspect ratio - height + } + } + + s->chroma_qscale= s->qscale = get_bits(&s->gb, 5); + skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */ + + if(s->pb_frame){ + skip_bits(&s->gb, 3); //temporal reference for B-frame + skip_bits(&s->gb, 2); //dbquant + } + + /* PEI */ + while (get_bits1(&s->gb) != 0) { + skip_bits(&s->gb, 8); + } + s->f_code = 1; + + s->y_dc_scale_table= + s->c_dc_scale_table= ff_mpeg1_dc_scale_table; + + ff_h263_show_pict_info(s); + + return 0; +} + +AVCodec 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, + .long_name = NULL_IF_CONFIG_SMALL("Intel H.263"), + .pix_fmts= ff_pixfmt_list_420, +}; + diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/internal.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/internal.h index ce8dad057d..97c0dcb3a6 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/internal.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/internal.h @@ -17,7 +17,7 @@ */ /** - * @file libavcodec/internal.h + * @file * common internal api header. */ @@ -42,4 +42,10 @@ int ff_is_hwaccel_pix_fmt(enum PixelFormat pix_fmt); */ AVHWAccel *ff_find_hwaccel(enum CodecID codec_id, enum PixelFormat pix_fmt); +/** + * Return the index into tab at which {a,b} match elements {[0],[1]} of tab. + * If there is no such matching pair then size is returned. + */ +int ff_match_2uint16(const uint16_t (*tab)[2], int size, int a, int b); + #endif /* AVCODEC_INTERNAL_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/interplayvideo.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/interplayvideo.c index d5b73a1163..b98386f77c 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/interplayvideo.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/interplayvideo.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/interplayvideo.c + * @file * Interplay MVE Video Decoder by Mike Melanson (melanson@pcisys.net) * For more information about the Interplay MVE format, visit: * http://www.pcisys.net/~melanson/codecs/interplay-mve.txt @@ -67,8 +67,11 @@ typedef struct IpvideoContext { const unsigned char *buf; int size; + int is_16bpp; const unsigned char *stream_ptr; const unsigned char *stream_end; + const uint8_t *mv_ptr; + const uint8_t *mv_end; unsigned char *pixel_ptr; int line_inc; int stride; @@ -76,17 +79,18 @@ typedef struct IpvideoContext { } IpvideoContext; -#define CHECK_STREAM_PTR(n) \ - if (s->stream_end - s->stream_ptr < n) { \ - av_log(s->avctx, AV_LOG_ERROR, "Interplay video warning: stream_ptr out of bounds (%p >= %p)\n", \ - s->stream_ptr + n, s->stream_end); \ - return -1; \ - } +#define CHECK_STREAM_PTR(stream_ptr, stream_end, n) \ + if (stream_end - stream_ptr < n) { \ + av_log(s->avctx, AV_LOG_ERROR, "Interplay video warning: stream_ptr out of bounds (%p >= %p)\n", \ + stream_ptr + n, stream_end); \ + return -1; \ + } static int copy_from(IpvideoContext *s, AVFrame *src, int delta_x, int delta_y) { int current_offset = s->pixel_ptr - s->current_frame.data[0]; - int motion_offset = current_offset + delta_y * s->stride + delta_x; + int motion_offset = current_offset + delta_y * s->current_frame.linesize[0] + + delta_x * (1 + s->is_16bpp); if (motion_offset < 0) { av_log(s->avctx, AV_LOG_ERROR, " Interplay video: motion offset < 0 (%d)\n", motion_offset); return -1; @@ -95,7 +99,8 @@ static int copy_from(IpvideoContext *s, AVFrame *src, int delta_x, int delta_y) motion_offset, s->upper_motion_limit_offset); return -1; } - s->dsp.put_pixels_tab[1][0](s->pixel_ptr, src->data[0] + motion_offset, s->stride, 8); + s->dsp.put_pixels_tab[!s->is_16bpp][0](s->pixel_ptr, src->data[0] + motion_offset, + s->current_frame.linesize[0], 8); return 0; } @@ -115,8 +120,13 @@ static int ipvideo_decode_block_opcode_0x2(IpvideoContext *s) int x, y; /* copy block from 2 frames ago using a motion vector; need 1 more byte */ - CHECK_STREAM_PTR(1); - B = *s->stream_ptr++; + if (!s->is_16bpp) { + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 1); + B = *s->stream_ptr++; + } else { + CHECK_STREAM_PTR(s->mv_ptr, s->mv_end, 1); + B = *s->mv_ptr++; + } if (B < 56) { x = 8 + (B % 7); @@ -138,8 +148,13 @@ static int ipvideo_decode_block_opcode_0x3(IpvideoContext *s) /* copy 8x8 block from current frame from an up/left block */ /* need 1 more byte for motion */ - CHECK_STREAM_PTR(1); - B = *s->stream_ptr++; + if (!s->is_16bpp) { + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 1); + B = *s->stream_ptr++; + } else { + CHECK_STREAM_PTR(s->mv_ptr, s->mv_end, 1); + B = *s->mv_ptr++; + } if (B < 56) { x = -(8 + (B % 7)); @@ -159,9 +174,14 @@ static int ipvideo_decode_block_opcode_0x4(IpvideoContext *s) unsigned char B, BL, BH; /* copy a block from the previous frame; need 1 more byte */ - CHECK_STREAM_PTR(1); + if (!s->is_16bpp) { + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 1); + B = *s->stream_ptr++; + } else { + CHECK_STREAM_PTR(s->mv_ptr, s->mv_end, 1); + B = *s->mv_ptr++; + } - B = *s->stream_ptr++; BL = B & 0x0F; BH = (B >> 4) & 0x0F; x = -8 + BL; @@ -177,7 +197,7 @@ static int ipvideo_decode_block_opcode_0x5(IpvideoContext *s) /* copy a block from the previous frame using an expanded range; * need 2 more bytes */ - CHECK_STREAM_PTR(2); + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 2); x = *s->stream_ptr++; y = *s->stream_ptr++; @@ -202,7 +222,7 @@ static int ipvideo_decode_block_opcode_0x7(IpvideoContext *s) unsigned int flags; /* 2-color encoding */ - CHECK_STREAM_PTR(2); + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 2); P[0] = *s->stream_ptr++; P[1] = *s->stream_ptr++; @@ -210,7 +230,7 @@ static int ipvideo_decode_block_opcode_0x7(IpvideoContext *s) if (P[0] <= P[1]) { /* need 8 more bytes from the stream */ - CHECK_STREAM_PTR(8); + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 8); for (y = 0; y < 8; y++) { flags = *s->stream_ptr++ | 0x100; @@ -222,7 +242,7 @@ static int ipvideo_decode_block_opcode_0x7(IpvideoContext *s) } else { /* need 2 more bytes from the stream */ - CHECK_STREAM_PTR(2); + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 2); flags = bytestream_get_le16(&s->stream_ptr); for (y = 0; y < 8; y += 2) { @@ -248,14 +268,14 @@ static int ipvideo_decode_block_opcode_0x8(IpvideoContext *s) /* 2-color encoding for each 4x4 quadrant, or 2-color encoding on * either top and bottom or left and right halves */ - CHECK_STREAM_PTR(2); + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 2); P[0] = *s->stream_ptr++; P[1] = *s->stream_ptr++; if (P[0] <= P[1]) { - CHECK_STREAM_PTR(14); + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 14); s->stream_ptr -= 2; for (y = 0; y < 16; y++) { @@ -275,7 +295,7 @@ static int ipvideo_decode_block_opcode_0x8(IpvideoContext *s) } else { /* need 10 more bytes */ - CHECK_STREAM_PTR(10); + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 10); if (s->stream_ptr[4] <= s->stream_ptr[5]) { @@ -323,7 +343,7 @@ static int ipvideo_decode_block_opcode_0x9(IpvideoContext *s) unsigned char P[4]; /* 4-color encoding */ - CHECK_STREAM_PTR(4); + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 4); memcpy(P, s->stream_ptr, 4); s->stream_ptr += 4; @@ -332,7 +352,7 @@ static int ipvideo_decode_block_opcode_0x9(IpvideoContext *s) if (P[2] <= P[3]) { /* 1 of 4 colors for each pixel, need 16 more bytes */ - CHECK_STREAM_PTR(16); + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 16); for (y = 0; y < 8; y++) { /* get the next set of 8 2-bit flags */ @@ -346,7 +366,7 @@ static int ipvideo_decode_block_opcode_0x9(IpvideoContext *s) uint32_t flags; /* 1 of 4 colors for each 2x2 block, need 4 more bytes */ - CHECK_STREAM_PTR(4); + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 4); flags = bytestream_get_le32(&s->stream_ptr); @@ -365,7 +385,7 @@ static int ipvideo_decode_block_opcode_0x9(IpvideoContext *s) uint64_t flags; /* 1 of 4 colors for each 2x1 or 1x2 block, need 8 more bytes */ - CHECK_STREAM_PTR(8); + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 8); flags = bytestream_get_le64(&s->stream_ptr); if (P[2] <= P[3]) { @@ -399,12 +419,12 @@ static int ipvideo_decode_block_opcode_0xA(IpvideoContext *s) /* 4-color encoding for each 4x4 quadrant, or 4-color encoding on * either top and bottom or left and right halves */ - CHECK_STREAM_PTR(24); + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 24); if (s->stream_ptr[0] <= s->stream_ptr[1]) { /* 4-color encoding for each quadrant; need 32 bytes */ - CHECK_STREAM_PTR(32); + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 32); for (y = 0; y < 16; y++) { // new values for each 4x4 block @@ -458,7 +478,7 @@ static int ipvideo_decode_block_opcode_0xB(IpvideoContext *s) int y; /* 64-color encoding (each pixel in block is a different color) */ - CHECK_STREAM_PTR(64); + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 64); for (y = 0; y < 8; y++) { memcpy(s->pixel_ptr, s->stream_ptr, 8); @@ -475,7 +495,7 @@ static int ipvideo_decode_block_opcode_0xC(IpvideoContext *s) int x, y; /* 16-color block encoding: each 2x2 block is a different color */ - CHECK_STREAM_PTR(16); + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 16); for (y = 0; y < 8; y += 2) { for (x = 0; x < 8; x += 2) { @@ -497,7 +517,7 @@ static int ipvideo_decode_block_opcode_0xD(IpvideoContext *s) unsigned char P[2]; /* 4-color block encoding: each 4x4 block is a different color */ - CHECK_STREAM_PTR(4); + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 4); for (y = 0; y < 8; y++) { if (!(y & 3)) { @@ -519,7 +539,7 @@ static int ipvideo_decode_block_opcode_0xE(IpvideoContext *s) unsigned char pix; /* 1-color encoding: the whole block is 1 solid color */ - CHECK_STREAM_PTR(1); + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 1); pix = *s->stream_ptr++; for (y = 0; y < 8; y++) { @@ -537,7 +557,7 @@ static int ipvideo_decode_block_opcode_0xF(IpvideoContext *s) unsigned char sample[2]; /* dithered encoding */ - CHECK_STREAM_PTR(2); + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 2); sample[0] = *s->stream_ptr++; sample[1] = *s->stream_ptr++; @@ -553,6 +573,363 @@ static int ipvideo_decode_block_opcode_0xF(IpvideoContext *s) return 0; } +static int ipvideo_decode_block_opcode_0x6_16(IpvideoContext *s) +{ + signed char x, y; + + /* copy a block from the second last frame using an expanded range */ + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 2); + + x = *s->stream_ptr++; + y = *s->stream_ptr++; + + debug_interplay (" motion bytes = %d, %d\n", x, y); + return copy_from(s, &s->second_last_frame, x, y); +} + +static int ipvideo_decode_block_opcode_0x7_16(IpvideoContext *s) +{ + int x, y; + uint16_t P[2]; + unsigned int flags; + uint16_t *pixel_ptr = (uint16_t*)s->pixel_ptr; + + /* 2-color encoding */ + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 4); + + P[0] = bytestream_get_le16(&s->stream_ptr); + P[1] = bytestream_get_le16(&s->stream_ptr); + + if (!(P[0] & 0x8000)) { + + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 8); + + for (y = 0; y < 8; y++) { + flags = *s->stream_ptr++ | 0x100; + for (; flags != 1; flags >>= 1) + *pixel_ptr++ = P[flags & 1]; + pixel_ptr += s->line_inc; + } + + } else { + + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 2); + + flags = bytestream_get_le16(&s->stream_ptr); + for (y = 0; y < 8; y += 2) { + for (x = 0; x < 8; x += 2, flags >>= 1) { + pixel_ptr[x ] = + pixel_ptr[x + 1 ] = + pixel_ptr[x + s->stride] = + pixel_ptr[x + 1 + s->stride] = P[flags & 1]; + } + pixel_ptr += s->stride * 2; + } + } + + return 0; +} + +static int ipvideo_decode_block_opcode_0x8_16(IpvideoContext *s) +{ + int x, y; + uint16_t P[2]; + unsigned int flags = 0; + uint16_t *pixel_ptr = (uint16_t*)s->pixel_ptr; + + /* 2-color encoding for each 4x4 quadrant, or 2-color encoding on + * either top and bottom or left and right halves */ + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 4); + + P[0] = bytestream_get_le16(&s->stream_ptr); + P[1] = bytestream_get_le16(&s->stream_ptr); + + if (!(P[0] & 0x8000)) { + + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 24); + s->stream_ptr -= 4; + + for (y = 0; y < 16; y++) { + // new values for each 4x4 block + if (!(y & 3)) { + P[0] = bytestream_get_le16(&s->stream_ptr); + P[1] = bytestream_get_le16(&s->stream_ptr); + flags = bytestream_get_le16(&s->stream_ptr); + } + + for (x = 0; x < 4; x++, flags >>= 1) + *pixel_ptr++ = P[flags & 1]; + pixel_ptr += s->stride - 4; + // switch to right half + if (y == 7) pixel_ptr -= 8 * s->stride - 4; + } + + } else { + + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 12); + + if (!(AV_RL16(s->stream_ptr + 4) & 0x8000)) { + + flags = bytestream_get_le32(&s->stream_ptr); + + /* vertical split; left & right halves are 2-color encoded */ + + for (y = 0; y < 16; y++) { + for (x = 0; x < 4; x++, flags >>= 1) + *pixel_ptr++ = P[flags & 1]; + pixel_ptr += s->stride - 4; + // switch to right half + if (y == 7) { + pixel_ptr -= 8 * s->stride - 4; + P[0] = bytestream_get_le16(&s->stream_ptr); + P[1] = bytestream_get_le16(&s->stream_ptr); + flags = bytestream_get_le32(&s->stream_ptr); + } + } + + } else { + + /* horizontal split; top & bottom halves are 2-color encoded */ + + for (y = 0; y < 8; y++) { + if (y == 4) { + P[0] = bytestream_get_le16(&s->stream_ptr); + P[1] = bytestream_get_le16(&s->stream_ptr); + } + flags = *s->stream_ptr++ | 0x100; + + for (; flags != 1; flags >>= 1) + *pixel_ptr++ = P[flags & 1]; + pixel_ptr += s->line_inc; + } + } + } + + /* report success */ + return 0; +} + +static int ipvideo_decode_block_opcode_0x9_16(IpvideoContext *s) +{ + int x, y; + uint16_t P[4]; + uint16_t *pixel_ptr = (uint16_t*)s->pixel_ptr; + + /* 4-color encoding */ + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 8); + + for (x = 0; x < 4; x++) + P[x] = bytestream_get_le16(&s->stream_ptr); + + if (!(P[0] & 0x8000)) { + if (!(P[2] & 0x8000)) { + + /* 1 of 4 colors for each pixel */ + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 16); + + for (y = 0; y < 8; y++) { + /* get the next set of 8 2-bit flags */ + int flags = bytestream_get_le16(&s->stream_ptr); + for (x = 0; x < 8; x++, flags >>= 2) + *pixel_ptr++ = P[flags & 0x03]; + pixel_ptr += s->line_inc; + } + + } else { + uint32_t flags; + + /* 1 of 4 colors for each 2x2 block */ + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 4); + + flags = bytestream_get_le32(&s->stream_ptr); + + for (y = 0; y < 8; y += 2) { + for (x = 0; x < 8; x += 2, flags >>= 2) { + pixel_ptr[x ] = + pixel_ptr[x + 1 ] = + pixel_ptr[x + s->stride] = + pixel_ptr[x + 1 + s->stride] = P[flags & 0x03]; + } + pixel_ptr += s->stride * 2; + } + + } + } else { + uint64_t flags; + + /* 1 of 4 colors for each 2x1 or 1x2 block */ + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 8); + + flags = bytestream_get_le64(&s->stream_ptr); + if (!(P[2] & 0x8000)) { + for (y = 0; y < 8; y++) { + for (x = 0; x < 8; x += 2, flags >>= 2) { + pixel_ptr[x ] = + pixel_ptr[x + 1] = P[flags & 0x03]; + } + pixel_ptr += s->stride; + } + } else { + for (y = 0; y < 8; y += 2) { + for (x = 0; x < 8; x++, flags >>= 2) { + pixel_ptr[x ] = + pixel_ptr[x + s->stride] = P[flags & 0x03]; + } + pixel_ptr += s->stride * 2; + } + } + } + + /* report success */ + return 0; +} + +static int ipvideo_decode_block_opcode_0xA_16(IpvideoContext *s) +{ + int x, y; + uint16_t P[4]; + int flags = 0; + uint16_t *pixel_ptr = (uint16_t*)s->pixel_ptr; + + /* 4-color encoding for each 4x4 quadrant, or 4-color encoding on + * either top and bottom or left and right halves */ + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 24); + + if (!(AV_RL16(s->stream_ptr) & 0x8000)) { + + /* 4-color encoding for each quadrant */ + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 48); + + for (y = 0; y < 16; y++) { + // new values for each 4x4 block + if (!(y & 3)) { + for (x = 0; x < 4; x++) + P[x] = bytestream_get_le16(&s->stream_ptr); + flags = bytestream_get_le32(&s->stream_ptr); + } + + for (x = 0; x < 4; x++, flags >>= 2) + *pixel_ptr++ = P[flags & 0x03]; + + pixel_ptr += s->stride - 4; + // switch to right half + if (y == 7) pixel_ptr -= 8 * s->stride - 4; + } + + } else { + // vertical split? + int vert = !(AV_RL16(s->stream_ptr + 16) & 0x8000); + uint64_t flags = 0; + + /* 4-color encoding for either left and right or top and bottom + * halves */ + + for (y = 0; y < 16; y++) { + // load values for each half + if (!(y & 7)) { + for (x = 0; x < 4; x++) + P[x] = bytestream_get_le16(&s->stream_ptr); + flags = bytestream_get_le64(&s->stream_ptr); + } + + for (x = 0; x < 4; x++, flags >>= 2) + *pixel_ptr++ = P[flags & 0x03]; + + if (vert) { + pixel_ptr += s->stride - 4; + // switch to right half + if (y == 7) pixel_ptr -= 8 * s->stride - 4; + } else if (y & 1) pixel_ptr += s->line_inc; + } + } + + /* report success */ + return 0; +} + +static int ipvideo_decode_block_opcode_0xB_16(IpvideoContext *s) +{ + int x, y; + uint16_t *pixel_ptr = (uint16_t*)s->pixel_ptr; + + /* 64-color encoding (each pixel in block is a different color) */ + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 128); + + for (y = 0; y < 8; y++) { + for (x = 0; x < 8; x++) + pixel_ptr[x] = bytestream_get_le16(&s->stream_ptr); + pixel_ptr += s->stride; + } + + /* report success */ + return 0; +} + +static int ipvideo_decode_block_opcode_0xC_16(IpvideoContext *s) +{ + int x, y; + uint16_t *pixel_ptr = (uint16_t*)s->pixel_ptr; + + /* 16-color block encoding: each 2x2 block is a different color */ + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 32); + + for (y = 0; y < 8; y += 2) { + for (x = 0; x < 8; x += 2) { + pixel_ptr[x ] = + pixel_ptr[x + 1 ] = + pixel_ptr[x + s->stride] = + pixel_ptr[x + 1 + s->stride] = bytestream_get_le16(&s->stream_ptr); + } + pixel_ptr += s->stride * 2; + } + + /* report success */ + return 0; +} + +static int ipvideo_decode_block_opcode_0xD_16(IpvideoContext *s) +{ + int x, y; + uint16_t P[2]; + uint16_t *pixel_ptr = (uint16_t*)s->pixel_ptr; + + /* 4-color block encoding: each 4x4 block is a different color */ + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 8); + + for (y = 0; y < 8; y++) { + if (!(y & 3)) { + P[0] = bytestream_get_le16(&s->stream_ptr); + P[1] = bytestream_get_le16(&s->stream_ptr); + } + for (x = 0; x < 8; x++) + pixel_ptr[x] = P[x >> 2]; + pixel_ptr += s->stride; + } + + /* report success */ + return 0; +} + +static int ipvideo_decode_block_opcode_0xE_16(IpvideoContext *s) +{ + int x, y; + uint16_t pix; + uint16_t *pixel_ptr = (uint16_t*)s->pixel_ptr; + + /* 1-color encoding: the whole block is 1 solid color */ + CHECK_STREAM_PTR(s->stream_ptr, s->stream_end, 2); + pix = bytestream_get_le16(&s->stream_ptr); + + for (y = 0; y < 8; y++) { + for (x = 0; x < 8; x++) + pixel_ptr[x] = pix; + pixel_ptr += s->stride; + } + + /* report success */ + return 0; +} + static int (* const ipvideo_decode_block[])(IpvideoContext *s) = { ipvideo_decode_block_opcode_0x0, ipvideo_decode_block_opcode_0x1, ipvideo_decode_block_opcode_0x2, ipvideo_decode_block_opcode_0x3, @@ -564,6 +941,17 @@ static int (* const ipvideo_decode_block[])(IpvideoContext *s) = { ipvideo_decode_block_opcode_0xE, ipvideo_decode_block_opcode_0xF, }; +static int (* const ipvideo_decode_block16[])(IpvideoContext *s) = { + ipvideo_decode_block_opcode_0x0, ipvideo_decode_block_opcode_0x1, + ipvideo_decode_block_opcode_0x2, ipvideo_decode_block_opcode_0x3, + ipvideo_decode_block_opcode_0x4, ipvideo_decode_block_opcode_0x5, + ipvideo_decode_block_opcode_0x6_16, ipvideo_decode_block_opcode_0x7_16, + ipvideo_decode_block_opcode_0x8_16, ipvideo_decode_block_opcode_0x9_16, + ipvideo_decode_block_opcode_0xA_16, ipvideo_decode_block_opcode_0xB_16, + ipvideo_decode_block_opcode_0xC_16, ipvideo_decode_block_opcode_0xD_16, + ipvideo_decode_block_opcode_0xE_16, ipvideo_decode_block_opcode_0x1, +}; + static void ipvideo_decode_opcodes(IpvideoContext *s) { int x, y; @@ -575,36 +963,51 @@ static void ipvideo_decode_opcodes(IpvideoContext *s) debug_interplay("------------------ frame %d\n", frame); frame++; - /* this is PAL8, so make the palette available */ - memcpy(s->current_frame.data[1], s->avctx->palctrl->palette, PALETTE_COUNT * 4); + if (!s->is_16bpp) { + /* this is PAL8, so make the palette available */ + memcpy(s->current_frame.data[1], s->avctx->palctrl->palette, PALETTE_COUNT * 4); - s->stride = s->current_frame.linesize[0]; - s->stream_ptr = s->buf + 14; /* data starts 14 bytes in */ - s->stream_end = s->buf + s->size; + s->stride = s->current_frame.linesize[0]; + s->stream_ptr = s->buf + 14; /* data starts 14 bytes in */ + s->stream_end = s->buf + s->size; + } else { + s->stride = s->current_frame.linesize[0] >> 1; + s->stream_ptr = s->buf + 16; + s->stream_end = + s->mv_ptr = s->buf + 14 + AV_RL16(s->buf+14); + s->mv_end = s->buf + s->size; + } s->line_inc = s->stride - 8; - s->upper_motion_limit_offset = (s->avctx->height - 8) * s->stride - + s->avctx->width - 8; + s->upper_motion_limit_offset = (s->avctx->height - 8) * s->current_frame.linesize[0] + + (s->avctx->width - 8) * (1 + s->is_16bpp); init_get_bits(&gb, s->decoding_map, s->decoding_map_size * 8); - for (y = 0; y < (s->stride * s->avctx->height); y += s->stride * 8) { - for (x = y; x < y + s->avctx->width; x += 8) { + for (y = 0; y < s->avctx->height; y += 8) { + for (x = 0; x < s->avctx->width; x += 8) { opcode = get_bits(&gb, 4); debug_interplay(" block @ (%3d, %3d): encoding 0x%X, data ptr @ %p\n", - x - y, y / s->stride, opcode, s->stream_ptr); + x, y, opcode, s->stream_ptr); - s->pixel_ptr = s->current_frame.data[0] + x; - ret = ipvideo_decode_block[opcode](s); + if (!s->is_16bpp) { + s->pixel_ptr = s->current_frame.data[0] + x + + y*s->current_frame.linesize[0]; + ret = ipvideo_decode_block[opcode](s); + } else { + s->pixel_ptr = s->current_frame.data[0] + x*2 + + y*s->current_frame.linesize[0]; + ret = ipvideo_decode_block16[opcode](s); + } if (ret != 0) { av_log(s->avctx, AV_LOG_ERROR, " Interplay video: decode problem on frame %d, @ block (%d, %d)\n", - frame, x - y, y / s->stride); + frame, x, y); return; } } } if (s->stream_end - s->stream_ptr > 1) { av_log(s->avctx, AV_LOG_ERROR, " Interplay video: decode finished with %td bytes left over\n", - s->stream_end - s->stream_ptr); + s->stream_end - s->stream_ptr); } } @@ -614,12 +1017,13 @@ static av_cold int ipvideo_decode_init(AVCodecContext *avctx) s->avctx = avctx; - if (s->avctx->palctrl == NULL) { + s->is_16bpp = avctx->bits_per_coded_sample == 16; + avctx->pix_fmt = s->is_16bpp ? PIX_FMT_RGB555 : PIX_FMT_PAL8; + if (!s->is_16bpp && s->avctx->palctrl == NULL) { av_log(avctx, AV_LOG_ERROR, " Interplay video: palette expected.\n"); return -1; } - avctx->pix_fmt = PIX_FMT_PAL8; dsputil_init(&s->dsp, avctx); /* decoding map contains 4 bits of information per 8x8 block */ @@ -657,7 +1061,7 @@ static int ipvideo_decode_frame(AVCodecContext *avctx, ipvideo_decode_opcodes(s); - if (palette_control->palette_changed) { + if (!s->is_16bpp && palette_control->palette_changed) { palette_control->palette_changed = 0; s->current_frame.palette_has_changed = 1; } @@ -691,7 +1095,7 @@ static av_cold int ipvideo_decode_end(AVCodecContext *avctx) AVCodec interplay_video_decoder = { "interplayvideo", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_INTERPLAY_VIDEO, sizeof(IpvideoContext), ipvideo_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/intrax8.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/intrax8.c index 9971e6479b..75166e8ffd 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/intrax8.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/intrax8.c @@ -17,7 +17,7 @@ */ /** - * @file libavcodec/intrax8.c + * @file * @brief IntraX8 (J-Frame) subdecoder, used by WMV2 and VC-1 */ @@ -44,13 +44,30 @@ static VLC j_orient_vlc[2][4]; //[quant], [select] static av_cold void x8_vlc_init(void){ int i; + int offset = 0; + int sizeidx = 0; + static const uint16_t sizes[8*4 + 8*2 + 2 + 4] = { + 576, 548, 582, 618, 546, 616, 560, 642, + 584, 582, 704, 664, 512, 544, 656, 640, + 512, 648, 582, 566, 532, 614, 596, 648, + 586, 552, 584, 590, 544, 578, 584, 624, + + 528, 528, 526, 528, 536, 528, 526, 544, + 544, 512, 512, 528, 528, 544, 512, 544, + + 128, 128, 128, 128, 128, 128}; + + static VLC_TYPE table[28150][2]; #define init_ac_vlc(dst,src) \ + dst.table = &table[offset]; \ + dst.table_allocated = sizes[sizeidx]; \ + offset += sizes[sizeidx++]; \ init_vlc(&dst, \ AC_VLC_BITS,77, \ &src[1],4,2, \ &src[0],4,2, \ - INIT_VLC_USE_STATIC) + INIT_VLC_USE_NEW_STATIC) //set ac tables for(i=0;i<8;i++){ init_ac_vlc( j_ac_vlc[0][0][i], x8_ac0_highquant_table[i][0] ); @@ -62,11 +79,14 @@ static av_cold void x8_vlc_init(void){ //set dc tables #define init_dc_vlc(dst,src) \ + dst.table = &table[offset]; \ + dst.table_allocated = sizes[sizeidx]; \ + offset += sizes[sizeidx++]; \ init_vlc(&dst, \ DC_VLC_BITS,34, \ &src[1],4,2, \ &src[0],4,2, \ - INIT_VLC_USE_STATIC); + INIT_VLC_USE_NEW_STATIC); for(i=0;i<8;i++){ init_dc_vlc( j_dc_vlc[0][i], x8_dc_highquant_table[i][0]); init_dc_vlc( j_dc_vlc[1][i], x8_dc_lowquant_table [i][0]); @@ -75,17 +95,22 @@ static av_cold void x8_vlc_init(void){ //set orient tables #define init_or_vlc(dst,src) \ + dst.table = &table[offset]; \ + dst.table_allocated = sizes[sizeidx]; \ + offset += sizes[sizeidx++]; \ init_vlc(&dst, \ OR_VLC_BITS,12, \ &src[1],4,2, \ &src[0],4,2, \ - INIT_VLC_USE_STATIC); + INIT_VLC_USE_NEW_STATIC); for(i=0;i<2;i++){ init_or_vlc( j_orient_vlc[0][i], x8_orient_highquant_table[i][0]); } for(i=0;i<4;i++){ init_or_vlc( j_orient_vlc[1][i], x8_orient_lowquant_table [i][0]) } + if (offset != sizeof(table)/sizeof(VLC_TYPE)/2) + av_log(NULL, AV_LOG_ERROR, "table size %i does not match needed %i\n", (int)(sizeof(table)/sizeof(VLC_TYPE)/2), offset); } #undef init_or_vlc diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/intrax8dsp.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/intrax8dsp.c index 0ed2e39d02..692e1b102f 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/intrax8dsp.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/intrax8dsp.c @@ -17,7 +17,7 @@ */ /** -* @file libavcodec/intrax8dsp.c +* @file *@brief IntraX8 frame subdecoder image manipulation routines */ @@ -413,7 +413,7 @@ static void x8_v_loop_filter(uint8_t *src, int stride, int qscale){ x8_loop_filter(src, 1, stride, qscale); } -void ff_intrax8dsp_init(DSPContext* dsp, AVCodecContext *avctx) { +av_cold void ff_intrax8dsp_init(DSPContext* dsp, AVCodecContext *avctx) { dsp->x8_h_loop_filter=x8_h_loop_filter; dsp->x8_v_loop_filter=x8_v_loop_filter; dsp->x8_setup_spatial_compensation=x8_setup_spatial_compensation; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ituh263dec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/ituh263dec.c new file mode 100644 index 0000000000..8b5d9391b2 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ituh263dec.c @@ -0,0 +1,1131 @@ +/* + * ITU H263 bitstream decoder + * Copyright (c) 2000,2001 Fabrice Bellard + * H263+ support. + * Copyright (c) 2001 Juan J. Sierralta P + * Copyright (c) 2002-2004 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 + */ + +/** + * @file + * h263 decoder. + */ + +//#define DEBUG +#include + +#include "dsputil.h" +#include "avcodec.h" +#include "mpegvideo.h" +#include "h263.h" +#include "mathops.h" +#include "unary.h" +#include "flv.h" +#include "mpeg4video.h" + +//#undef NDEBUG +//#include + +// The defines below define the number of bits that are read at once for +// reading vlc values. Changing these may improve speed and data cache needs +// be aware though that decreasing them may need the number of stages that is +// passed to get_vlc* to be increased. +#define MV_VLC_BITS 9 +#define H263_MBTYPE_B_VLC_BITS 6 +#define CBPC_B_VLC_BITS 3 + +static const int h263_mb_type_b_map[15]= { + MB_TYPE_DIRECT2 | MB_TYPE_L0L1, + MB_TYPE_DIRECT2 | MB_TYPE_L0L1 | MB_TYPE_CBP, + MB_TYPE_DIRECT2 | MB_TYPE_L0L1 | MB_TYPE_CBP | MB_TYPE_QUANT, + MB_TYPE_L0 | MB_TYPE_16x16, + MB_TYPE_L0 | MB_TYPE_CBP | MB_TYPE_16x16, + MB_TYPE_L0 | MB_TYPE_CBP | MB_TYPE_QUANT | MB_TYPE_16x16, + MB_TYPE_L1 | MB_TYPE_16x16, + MB_TYPE_L1 | MB_TYPE_CBP | MB_TYPE_16x16, + MB_TYPE_L1 | MB_TYPE_CBP | MB_TYPE_QUANT | MB_TYPE_16x16, + MB_TYPE_L0L1 | MB_TYPE_16x16, + MB_TYPE_L0L1 | MB_TYPE_CBP | MB_TYPE_16x16, + MB_TYPE_L0L1 | MB_TYPE_CBP | MB_TYPE_QUANT | MB_TYPE_16x16, + 0, //stuffing + MB_TYPE_INTRA4x4 | MB_TYPE_CBP, + MB_TYPE_INTRA4x4 | MB_TYPE_CBP | MB_TYPE_QUANT, +}; + +void ff_h263_show_pict_info(MpegEncContext *s){ + if(s->avctx->debug&FF_DEBUG_PICT_INFO){ + av_log(s->avctx, AV_LOG_DEBUG, "qp:%d %c size:%d rnd:%d%s%s%s%s%s%s%s%s%s %d/%d\n", + s->qscale, av_get_pict_type_char(s->pict_type), + s->gb.size_in_bits, 1-s->no_rounding, + s->obmc ? " AP" : "", + s->umvplus ? " UMV" : "", + s->h263_long_vectors ? " LONG" : "", + s->h263_plus ? " +" : "", + s->h263_aic ? " AIC" : "", + s->alt_inter_vlc ? " AIV" : "", + s->modified_quant ? " MQ" : "", + s->loop_filter ? " LOOP" : "", + s->h263_slice_structured ? " SS" : "", + s->avctx->time_base.den, s->avctx->time_base.num + ); + } +} + +/***********************************************/ +/* decoding */ + +VLC ff_h263_intra_MCBPC_vlc; +VLC ff_h263_inter_MCBPC_vlc; +VLC ff_h263_cbpy_vlc; +static VLC mv_vlc; +static VLC h263_mbtype_b_vlc; +static VLC cbpc_b_vlc; + +/* init vlcs */ + +/* XXX: find a better solution to handle static init */ +void h263_decode_init_vlc(MpegEncContext *s) +{ + static int done = 0; + + if (!done) { + done = 1; + + INIT_VLC_STATIC(&ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 9, + ff_h263_intra_MCBPC_bits, 1, 1, + ff_h263_intra_MCBPC_code, 1, 1, 72); + INIT_VLC_STATIC(&ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 28, + ff_h263_inter_MCBPC_bits, 1, 1, + ff_h263_inter_MCBPC_code, 1, 1, 198); + INIT_VLC_STATIC(&ff_h263_cbpy_vlc, CBPY_VLC_BITS, 16, + &ff_h263_cbpy_tab[0][1], 2, 1, + &ff_h263_cbpy_tab[0][0], 2, 1, 64); + INIT_VLC_STATIC(&mv_vlc, MV_VLC_BITS, 33, + &mvtab[0][1], 2, 1, + &mvtab[0][0], 2, 1, 538); + init_rl(&ff_h263_rl_inter, ff_h263_static_rl_table_store[0]); + init_rl(&rl_intra_aic, ff_h263_static_rl_table_store[1]); + INIT_VLC_RL(ff_h263_rl_inter, 554); + INIT_VLC_RL(rl_intra_aic, 554); + INIT_VLC_STATIC(&h263_mbtype_b_vlc, H263_MBTYPE_B_VLC_BITS, 15, + &h263_mbtype_b_tab[0][1], 2, 1, + &h263_mbtype_b_tab[0][0], 2, 1, 80); + INIT_VLC_STATIC(&cbpc_b_vlc, CBPC_B_VLC_BITS, 4, + &cbpc_b_tab[0][1], 2, 1, + &cbpc_b_tab[0][0], 2, 1, 8); + } +} + +int ff_h263_decode_mba(MpegEncContext *s) +{ + int i, mb_pos; + + for(i=0; i<6; i++){ + if(s->mb_num-1 <= ff_mba_max[i]) break; + } + mb_pos= get_bits(&s->gb, ff_mba_length[i]); + s->mb_x= mb_pos % s->mb_width; + s->mb_y= mb_pos / s->mb_width; + + return mb_pos; +} + +/** + * decodes the group of blocks header or slice header. + * @return <0 if an error occurred + */ +static int h263_decode_gob_header(MpegEncContext *s) +{ + unsigned int val, gfid, gob_number; + int left; + + /* Check for GOB Start Code */ + val = show_bits(&s->gb, 16); + if(val) + return -1; + + /* We have a GBSC probably with GSTUFF */ + skip_bits(&s->gb, 16); /* Drop the zeros */ + left= get_bits_left(&s->gb); + //MN: we must check the bits left or we might end in a infinite loop (or segfault) + for(;left>13; left--){ + if(get_bits1(&s->gb)) break; /* Seek the '1' bit */ + } + if(left<=13) + return -1; + + if(s->h263_slice_structured){ + if(get_bits1(&s->gb)==0) + return -1; + + ff_h263_decode_mba(s); + + if(s->mb_num > 1583) + if(get_bits1(&s->gb)==0) + return -1; + + s->qscale = get_bits(&s->gb, 5); /* SQUANT */ + if(get_bits1(&s->gb)==0) + return -1; + gfid = get_bits(&s->gb, 2); /* GFID */ + }else{ + gob_number = get_bits(&s->gb, 5); /* GN */ + s->mb_x= 0; + s->mb_y= s->gob_index* gob_number; + gfid = get_bits(&s->gb, 2); /* GFID */ + s->qscale = get_bits(&s->gb, 5); /* GQUANT */ + } + + if(s->mb_y >= s->mb_height) + return -1; + + if(s->qscale==0) + return -1; + + return 0; +} + +/** + * finds the next resync_marker + * @param p pointer to buffer to scan + * @param end pointer to the end of the buffer + * @return pointer to the next resync_marker, or end if none was found + */ +const uint8_t *ff_h263_find_resync_marker(const uint8_t *restrict p, const uint8_t * restrict end) +{ + assert(p < end); + + end-=2; + p++; + for(;pcodec_id==CODEC_ID_MPEG4){ + skip_bits1(&s->gb); + align_get_bits(&s->gb); + } + + if(show_bits(&s->gb, 16)==0){ + pos= get_bits_count(&s->gb); + if(CONFIG_MPEG4_DECODER && s->codec_id==CODEC_ID_MPEG4) + ret= mpeg4_decode_video_packet_header(s); + else + ret= h263_decode_gob_header(s); + if(ret>=0) + return pos; + } + //OK, it's not where it is supposed to be ... + s->gb= s->last_resync_gb; + align_get_bits(&s->gb); + left= get_bits_left(&s->gb); + + for(;left>16+1+5+5; left-=8){ + if(show_bits(&s->gb, 16)==0){ + GetBitContext bak= s->gb; + + pos= get_bits_count(&s->gb); + if(CONFIG_MPEG4_DECODER && s->codec_id==CODEC_ID_MPEG4) + ret= mpeg4_decode_video_packet_header(s); + else + ret= h263_decode_gob_header(s); + if(ret>=0) + return pos; + + s->gb= bak; + } + skip_bits(&s->gb, 8); + } + + return -1; +} + +int h263_decode_motion(MpegEncContext * s, int pred, int f_code) +{ + int code, val, sign, shift, l; + code = get_vlc2(&s->gb, mv_vlc.table, MV_VLC_BITS, 2); + + if (code == 0) + return pred; + if (code < 0) + return 0xffff; + + sign = get_bits1(&s->gb); + shift = f_code - 1; + val = code; + if (shift) { + val = (val - 1) << shift; + val |= get_bits(&s->gb, shift); + val++; + } + if (sign) + val = -val; + val += pred; + + /* modulo decoding */ + if (!s->h263_long_vectors) { + l = INT_BIT - 5 - f_code; + val = (val<>l; + } else { + /* horrible h263 long vector mode */ + if (pred < -31 && val < -63) + val += 64; + if (pred > 32 && val > 63) + val -= 64; + + } + return val; +} + + +/* Decodes RVLC of H.263+ UMV */ +static int h263p_decode_umotion(MpegEncContext * s, int pred) +{ + int code = 0, sign; + + if (get_bits1(&s->gb)) /* Motion difference = 0 */ + return pred; + + code = 2 + get_bits1(&s->gb); + + while (get_bits1(&s->gb)) + { + code <<= 1; + code += get_bits1(&s->gb); + } + sign = code & 1; + code >>= 1; + + code = (sign) ? (pred - code) : (pred + code); + dprintf(s->avctx,"H.263+ UMV Motion = %d\n", code); + return code; + +} + +/** + * read the next MVs for OBMC. yes this is a ugly hack, feel free to send a patch :) + */ +static void preview_obmc(MpegEncContext *s){ + GetBitContext gb= s->gb; + + int cbpc, i, pred_x, pred_y, mx, my; + int16_t *mot_val; + const int xy= s->mb_x + 1 + s->mb_y * s->mb_stride; + const int stride= s->b8_stride*2; + + for(i=0; i<4; i++) + s->block_index[i]+= 2; + for(i=4; i<6; i++) + s->block_index[i]+= 1; + s->mb_x++; + + assert(s->pict_type == FF_P_TYPE); + + do{ + if (get_bits1(&s->gb)) { + /* skip mb */ + mot_val = s->current_picture.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; + 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; + }else{ + get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1); + if (cbpc & 8) { + if(s->modified_quant){ + if(get_bits1(&s->gb)) skip_bits(&s->gb, 1); + else skip_bits(&s->gb, 5); + }else + skip_bits(&s->gb, 2); + } + + if ((cbpc & 16) == 0) { + s->current_picture.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) + mx = h263p_decode_umotion(s, pred_x); + else + mx = h263_decode_motion(s, pred_x, 1); + + if (s->umvplus) + my = h263p_decode_umotion(s, pred_y); + else + my = h263_decode_motion(s, pred_y, 1); + + mot_val[0 ]= mot_val[2 ]= + mot_val[0+stride]= mot_val[2+stride]= mx; + 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; + for(i=0;i<4;i++) { + mot_val = h263_pred_motion(s, i, 0, &pred_x, &pred_y); + if (s->umvplus) + mx = h263p_decode_umotion(s, pred_x); + else + mx = h263_decode_motion(s, pred_x, 1); + + if (s->umvplus) + my = h263p_decode_umotion(s, pred_y); + else + my = h263_decode_motion(s, pred_y, 1); + if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) + skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ + mot_val[0] = mx; + mot_val[1] = my; + } + } + } +end: + + for(i=0; i<4; i++) + s->block_index[i]-= 2; + for(i=4; i<6; i++) + s->block_index[i]-= 1; + s->mb_x--; + + s->gb= gb; +} + +static void h263_decode_dquant(MpegEncContext *s){ + static const int8_t quant_tab[4] = { -1, -2, 1, 2 }; + + if(s->modified_quant){ + if(get_bits1(&s->gb)) + s->qscale= modified_quant_tab[get_bits1(&s->gb)][ s->qscale ]; + else + s->qscale= get_bits(&s->gb, 5); + }else + s->qscale += quant_tab[get_bits(&s->gb, 2)]; + ff_set_qscale(s, s->qscale); +} + +static int h263_decode_block(MpegEncContext * s, DCTELEM * block, + int n, int coded) +{ + int code, level, i, j, last, run; + RLTable *rl = &ff_h263_rl_inter; + const uint8_t *scan_table; + GetBitContext gb= s->gb; + + scan_table = s->intra_scantable.permutated; + if (s->h263_aic && s->mb_intra) { + rl = &rl_intra_aic; + i = 0; + if (s->ac_pred) { + if (s->h263_aic_dir) + scan_table = s->intra_v_scantable.permutated; /* left */ + else + scan_table = s->intra_h_scantable.permutated; /* top */ + } + } else if (s->mb_intra) { + /* DC coef */ + if(s->codec_id == CODEC_ID_RV10){ +#if CONFIG_RV10_DECODER + if (s->rv10_version == 3 && s->pict_type == FF_I_TYPE) { + int component, diff; + component = (n <= 3 ? 0 : n - 4 + 1); + level = s->last_dc[component]; + if (s->rv10_first_dc_coded[component]) { + diff = rv_decode_dc(s, n); + if (diff == 0xffff) + return -1; + level += diff; + level = level & 0xff; /* handle wrap round */ + s->last_dc[component] = level; + } else { + s->rv10_first_dc_coded[component] = 1; + } + } else { + level = get_bits(&s->gb, 8); + if (level == 255) + level = 128; + } +#endif + }else{ + level = get_bits(&s->gb, 8); + if((level&0x7F) == 0){ + av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n", level, s->mb_x, s->mb_y); + if(s->error_recognition >= FF_ER_COMPLIANT) + return -1; + } + if (level == 255) + level = 128; + } + block[0] = level; + i = 1; + } else { + i = 0; + } + if (!coded) { + if (s->mb_intra && s->h263_aic) + goto not_coded; + s->block_last_index[n] = i - 1; + return 0; + } +retry: + for(;;) { + code = get_vlc2(&s->gb, rl->vlc.table, TEX_VLC_BITS, 2); + if (code < 0){ + av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n", s->mb_x, s->mb_y); + return -1; + } + if (code == rl->n) { + /* escape */ + if (CONFIG_FLV_DECODER && s->h263_flv > 1) { + ff_flv2_decode_ac_esc(&s->gb, &level, &run, &last); + } else { + last = get_bits1(&s->gb); + run = get_bits(&s->gb, 6); + level = (int8_t)get_bits(&s->gb, 8); + if(level == -128){ + if (s->codec_id == CODEC_ID_RV10) { + /* XXX: should patch encoder too */ + level = get_sbits(&s->gb, 12); + }else{ + level = get_bits(&s->gb, 5); + level |= get_sbits(&s->gb, 6)<<5; + } + } + } + } else { + run = rl->table_run[code]; + level = rl->table_level[code]; + last = code >= rl->last; + if (get_bits1(&s->gb)) + level = -level; + } + i += run; + if (i >= 64){ + if(s->alt_inter_vlc && rl == &ff_h263_rl_inter && !s->mb_intra){ + //Looks like a hack but no, it's the way it is supposed to work ... + rl = &rl_intra_aic; + i = 0; + s->gb= gb; + s->dsp.clear_block(block); + goto retry; + } + av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d i:%d\n", s->mb_x, s->mb_y, s->mb_intra); + return -1; + } + j = scan_table[i]; + block[j] = level; + if (last) + break; + i++; + } +not_coded: + if (s->mb_intra && s->h263_aic) { + h263_pred_acdc(s, block, n); + i = 63; + } + s->block_last_index[n] = i; + return 0; +} + +static int h263_skip_b_part(MpegEncContext *s, int cbp) +{ + LOCAL_ALIGNED_16(DCTELEM, dblock, [64]); + int i, mbi; + + /* we have to set s->mb_intra to zero to decode B-part of PB-frame correctly + * but real value should be restored in order to be used later (in OBMC condition) + */ + mbi = s->mb_intra; + s->mb_intra = 0; + for (i = 0; i < 6; i++) { + if (h263_decode_block(s, dblock, i, cbp&32) < 0) + return -1; + cbp+=cbp; + } + s->mb_intra = mbi; + return 0; +} + +static int h263_get_modb(GetBitContext *gb, int pb_frame, int *cbpb) +{ + int c, mv = 1; + + if (pb_frame < 3) { // h.263 Annex G and i263 PB-frame + c = get_bits1(gb); + if (pb_frame == 2 && c) + mv = !get_bits1(gb); + } else { // h.263 Annex M improved PB-frame + mv = get_unary(gb, 0, 4) + 1; + c = mv & 1; + mv = !!(mv & 2); + } + if(c) + *cbpb = get_bits(gb, 6); + return mv; +} + +int ff_h263_decode_mb(MpegEncContext *s, + DCTELEM block[6][64]) +{ + int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant; + int16_t *mot_val; + const int xy= s->mb_x + s->mb_y * s->mb_stride; + int cbpb = 0, pb_mv_count = 0; + + assert(!s->h263_pred); + + if (s->pict_type == FF_P_TYPE) { + do{ + if (get_bits1(&s->gb)) { + /* skip mb */ + s->mb_intra = 0; + for(i=0;i<6;i++) + 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->mv[0][0][0] = 0; + s->mv[0][0][1] = 0; + s->mb_skipped = !(s->obmc | s->loop_filter); + goto end; + } + cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2); + if (cbpc < 0){ + av_log(s->avctx, AV_LOG_ERROR, "cbpc damaged at %d %d\n", s->mb_x, s->mb_y); + return -1; + } + }while(cbpc == 20); + + s->dsp.clear_blocks(s->block[0]); + + dquant = cbpc & 8; + s->mb_intra = ((cbpc & 4) != 0); + if (s->mb_intra) goto intra; + + if(s->pb_frame && get_bits1(&s->gb)) + pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb); + cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1); + + if(s->alt_inter_vlc==0 || (cbpc & 3)!=3) + cbpy ^= 0xF; + + cbp = (cbpc & 3) | (cbpy << 2); + if (dquant) { + h263_decode_dquant(s); + } + + s->mv_dir = MV_DIR_FORWARD; + if ((cbpc & 16) == 0) { + s->current_picture.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); + if (s->umvplus) + mx = h263p_decode_umotion(s, pred_x); + else + mx = h263_decode_motion(s, pred_x, 1); + + if (mx >= 0xffff) + return -1; + + if (s->umvplus) + my = h263p_decode_umotion(s, pred_y); + else + my = h263_decode_motion(s, pred_y, 1); + + if (my >= 0xffff) + return -1; + s->mv[0][0][0] = mx; + s->mv[0][0][1] = my; + + 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->mv_type = MV_TYPE_8X8; + for(i=0;i<4;i++) { + mot_val = h263_pred_motion(s, i, 0, &pred_x, &pred_y); + if (s->umvplus) + mx = h263p_decode_umotion(s, pred_x); + else + mx = h263_decode_motion(s, pred_x, 1); + if (mx >= 0xffff) + return -1; + + if (s->umvplus) + my = h263p_decode_umotion(s, pred_y); + else + my = h263_decode_motion(s, pred_y, 1); + if (my >= 0xffff) + return -1; + s->mv[0][i][0] = mx; + s->mv[0][i][1] = my; + if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) + skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ + mot_val[0] = mx; + mot_val[1] = my; + } + } + } else if(s->pict_type==FF_B_TYPE) { + 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) ]; +// const int mv_xy= s->mb_x + 1 + s->mb_y * s->mb_stride; + + //FIXME ugly + mot_val0[0 ]= mot_val0[2 ]= mot_val0[0+2*stride]= mot_val0[2+2*stride]= + mot_val0[1 ]= mot_val0[3 ]= mot_val0[1+2*stride]= mot_val0[3+2*stride]= + mot_val1[0 ]= mot_val1[2 ]= mot_val1[0+2*stride]= mot_val1[2+2*stride]= + mot_val1[1 ]= mot_val1[3 ]= mot_val1[1+2*stride]= mot_val1[3+2*stride]= 0; + + do{ + mb_type= get_vlc2(&s->gb, h263_mbtype_b_vlc.table, H263_MBTYPE_B_VLC_BITS, 2); + if (mb_type < 0){ + av_log(s->avctx, AV_LOG_ERROR, "b mb_type damaged at %d %d\n", s->mb_x, s->mb_y); + return -1; + } + + mb_type= h263_mb_type_b_map[ mb_type ]; + }while(!mb_type); + + s->mb_intra = IS_INTRA(mb_type); + if(HAS_CBP(mb_type)){ + s->dsp.clear_blocks(s->block[0]); + cbpc = get_vlc2(&s->gb, cbpc_b_vlc.table, CBPC_B_VLC_BITS, 1); + if(s->mb_intra){ + dquant = IS_QUANT(mb_type); + goto intra; + } + + cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1); + + if (cbpy < 0){ + av_log(s->avctx, AV_LOG_ERROR, "b cbpy damaged at %d %d\n", s->mb_x, s->mb_y); + return -1; + } + + if(s->alt_inter_vlc==0 || (cbpc & 3)!=3) + cbpy ^= 0xF; + + cbp = (cbpc & 3) | (cbpy << 2); + }else + cbp=0; + + assert(!s->mb_intra); + + if(IS_QUANT(mb_type)){ + h263_decode_dquant(s); + } + + if(IS_DIRECT(mb_type)){ + s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; + mb_type |= ff_mpeg4_set_direct_mv(s, 0, 0); + }else{ + s->mv_dir = 0; + s->mv_type= MV_TYPE_16X16; +//FIXME UMV + + if(USES_LIST(mb_type, 0)){ + int16_t *mot_val= h263_pred_motion(s, 0, 0, &mx, &my); + s->mv_dir = MV_DIR_FORWARD; + + mx = h263_decode_motion(s, mx, 1); + my = h263_decode_motion(s, my, 1); + + s->mv[0][0][0] = mx; + s->mv[0][0][1] = my; + mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx; + mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my; + } + + if(USES_LIST(mb_type, 1)){ + int16_t *mot_val= h263_pred_motion(s, 0, 1, &mx, &my); + s->mv_dir |= MV_DIR_BACKWARD; + + mx = h263_decode_motion(s, mx, 1); + my = h263_decode_motion(s, my, 1); + + s->mv[1][0][0] = mx; + s->mv[1][0][1] = my; + mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx; + mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my; + } + } + + s->current_picture.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); + if (cbpc < 0){ + av_log(s->avctx, AV_LOG_ERROR, "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y); + return -1; + } + }while(cbpc == 8); + + s->dsp.clear_blocks(s->block[0]); + + dquant = cbpc & 4; + s->mb_intra = 1; +intra: + s->current_picture.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->h263_aic_dir = get_bits1(&s->gb); + } + }else + s->ac_pred = 0; + + if(s->pb_frame && get_bits1(&s->gb)) + pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb); + cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1); + if(cbpy<0){ + av_log(s->avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y); + return -1; + } + cbp = (cbpc & 3) | (cbpy << 2); + if (dquant) { + h263_decode_dquant(s); + } + + pb_mv_count += !!s->pb_frame; + } + + while(pb_mv_count--){ + h263_decode_motion(s, 0, 1); + h263_decode_motion(s, 0, 1); + } + + /* decode each block */ + for (i = 0; i < 6; i++) { + if (h263_decode_block(s, block[i], i, cbp&32) < 0) + return -1; + cbp+=cbp; + } + + if(s->pb_frame && h263_skip_b_part(s, cbpb) < 0) + return -1; + if(s->obmc && !s->mb_intra){ + if(s->pict_type == FF_P_TYPE && s->mb_x+1mb_width && s->mb_num_left != 1) + preview_obmc(s); + } +end: + + /* per-MB end of slice check */ + { + int v= show_bits(&s->gb, 16); + + if(get_bits_count(&s->gb) + 16 > s->gb.size_in_bits){ + v>>= get_bits_count(&s->gb) + 16 - s->gb.size_in_bits; + } + + if(v==0) + return SLICE_END; + } + + return SLICE_OK; +} + +/* most is hardcoded. should extend to handle all h263 streams */ +int h263_decode_picture_header(MpegEncContext *s) +{ + int format, width, height, i; + uint32_t startcode; + + align_get_bits(&s->gb); + + startcode= get_bits(&s->gb, 22-8); + + for(i= get_bits_left(&s->gb); i>24; i-=8) { + startcode = ((startcode << 8) | get_bits(&s->gb, 8)) & 0x003FFFFF; + + if(startcode == 0x20) + break; + } + + if (startcode != 0x20) { + av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n"); + return -1; + } + /* temporal reference */ + 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->picture_number= (s->picture_number&~0xFF) + i; + + /* PTYPE starts here */ + if (get_bits1(&s->gb) != 1) { + /* marker */ + av_log(s->avctx, AV_LOG_ERROR, "Bad marker\n"); + return -1; + } + if (get_bits1(&s->gb) != 0) { + av_log(s->avctx, AV_LOG_ERROR, "Bad H263 id\n"); + return -1; /* h263 id */ + } + skip_bits1(&s->gb); /* split screen off */ + skip_bits1(&s->gb); /* camera off */ + skip_bits1(&s->gb); /* freeze picture release off */ + + format = get_bits(&s->gb, 3); + /* + 0 forbidden + 1 sub-QCIF + 10 QCIF + 7 extended PTYPE (PLUSPTYPE) + */ + + if (format != 7 && format != 6) { + s->h263_plus = 0; + /* H.263v1 */ + width = h263_format[format][0]; + height = h263_format[format][1]; + if (!width) + return -1; + + s->pict_type = FF_I_TYPE + get_bits1(&s->gb); + + s->h263_long_vectors = get_bits1(&s->gb); + + if (get_bits1(&s->gb) != 0) { + av_log(s->avctx, AV_LOG_ERROR, "H263 SAC not supported\n"); + return -1; /* SAC: off */ + } + s->obmc= get_bits1(&s->gb); /* Advanced prediction mode */ + s->unrestricted_mv = s->h263_long_vectors || s->obmc; + + s->pb_frame = get_bits1(&s->gb); + s->chroma_qscale= s->qscale = get_bits(&s->gb, 5); + skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */ + + s->width = width; + s->height = height; + s->avctx->sample_aspect_ratio= (AVRational){12,11}; + s->avctx->time_base= (AVRational){1001, 30000}; + } else { + int ufep; + + /* H.263v2 */ + s->h263_plus = 1; + ufep = get_bits(&s->gb, 3); /* Update Full Extended PTYPE */ + + /* ufep other than 0 and 1 are reserved */ + if (ufep == 1) { + /* OPPTYPE */ + format = get_bits(&s->gb, 3); + dprintf(s->avctx, "ufep=1, format: %d\n", format); + s->custom_pcf= get_bits1(&s->gb); + s->umvplus = get_bits1(&s->gb); /* Unrestricted Motion Vector */ + if (get_bits1(&s->gb) != 0) { + av_log(s->avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n"); + } + s->obmc= get_bits1(&s->gb); /* Advanced prediction mode */ + s->h263_aic = get_bits1(&s->gb); /* Advanced Intra Coding (AIC) */ + s->loop_filter= get_bits1(&s->gb); + s->unrestricted_mv = s->umvplus || s->obmc || s->loop_filter; + + s->h263_slice_structured= get_bits1(&s->gb); + if (get_bits1(&s->gb) != 0) { + av_log(s->avctx, AV_LOG_ERROR, "Reference Picture Selection not supported\n"); + } + if (get_bits1(&s->gb) != 0) { + av_log(s->avctx, AV_LOG_ERROR, "Independent Segment Decoding not supported\n"); + } + s->alt_inter_vlc= get_bits1(&s->gb); + s->modified_quant= get_bits1(&s->gb); + if(s->modified_quant) + s->chroma_qscale_table= ff_h263_chroma_qscale_table; + + skip_bits(&s->gb, 1); /* Prevent start code emulation */ + + skip_bits(&s->gb, 3); /* Reserved */ + } else if (ufep != 0) { + av_log(s->avctx, AV_LOG_ERROR, "Bad UFEP type (%d)\n", ufep); + return -1; + } + + /* MPPTYPE */ + s->pict_type = get_bits(&s->gb, 3); + switch(s->pict_type){ + case 0: s->pict_type= FF_I_TYPE;break; + case 1: s->pict_type= FF_P_TYPE;break; + case 2: s->pict_type= FF_P_TYPE;s->pb_frame = 3;break; + case 3: s->pict_type= FF_B_TYPE;break; + case 7: s->pict_type= FF_I_TYPE;break; //ZYGO + default: + return -1; + } + skip_bits(&s->gb, 2); + s->no_rounding = get_bits1(&s->gb); + skip_bits(&s->gb, 4); + + /* Get the picture dimensions */ + if (ufep) { + if (format == 6) { + /* Custom Picture Format (CPFMT) */ + s->aspect_ratio_info = get_bits(&s->gb, 4); + dprintf(s->avctx, "aspect: %d\n", s->aspect_ratio_info); + /* aspect ratios: + 0 - forbidden + 1 - 1:1 + 2 - 12:11 (CIF 4:3) + 3 - 10:11 (525-type 4:3) + 4 - 16:11 (CIF 16:9) + 5 - 40:33 (525-type 16:9) + 6-14 - reserved + */ + width = (get_bits(&s->gb, 9) + 1) * 4; + skip_bits1(&s->gb); + height = get_bits(&s->gb, 9) * 4; + dprintf(s->avctx, "\nH.263+ Custom picture: %dx%d\n",width,height); + if (s->aspect_ratio_info == FF_ASPECT_EXTENDED) { + /* aspected dimensions */ + s->avctx->sample_aspect_ratio.num= get_bits(&s->gb, 8); + s->avctx->sample_aspect_ratio.den= get_bits(&s->gb, 8); + }else{ + s->avctx->sample_aspect_ratio= ff_h263_pixel_aspect[s->aspect_ratio_info]; + } + } else { + width = h263_format[format][0]; + height = h263_format[format][1]; + s->avctx->sample_aspect_ratio= (AVRational){12,11}; + } + if ((width == 0) || (height == 0)) + return -1; + s->width = width; + s->height = height; + + if(s->custom_pcf){ + int gcd; + s->avctx->time_base.den= 1800000; + s->avctx->time_base.num= 1000 + get_bits1(&s->gb); + s->avctx->time_base.num*= get_bits(&s->gb, 7); + if(s->avctx->time_base.num == 0){ + av_log(s, AV_LOG_ERROR, "zero framerate\n"); + return -1; + } + gcd= av_gcd(s->avctx->time_base.den, s->avctx->time_base.num); + s->avctx->time_base.den /= gcd; + s->avctx->time_base.num /= gcd; + }else{ + s->avctx->time_base= (AVRational){1001, 30000}; + } + } + + if(s->custom_pcf){ + skip_bits(&s->gb, 2); //extended Temporal reference + } + + if (ufep) { + if (s->umvplus) { + if(get_bits1(&s->gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ + skip_bits1(&s->gb); + } + if(s->h263_slice_structured){ + if (get_bits1(&s->gb) != 0) { + av_log(s->avctx, AV_LOG_ERROR, "rectangular slices not supported\n"); + } + if (get_bits1(&s->gb) != 0) { + av_log(s->avctx, AV_LOG_ERROR, "unordered slices not supported\n"); + } + } + } + + s->qscale = get_bits(&s->gb, 5); + } + + s->mb_width = (s->width + 15) / 16; + s->mb_height = (s->height + 15) / 16; + s->mb_num = s->mb_width * s->mb_height; + + if (s->pb_frame) { + skip_bits(&s->gb, 3); /* Temporal reference for B-pictures */ + if (s->custom_pcf) + skip_bits(&s->gb, 2); //extended Temporal reference + skip_bits(&s->gb, 2); /* Quantization information for B-pictures */ + } + + /* PEI */ + while (get_bits1(&s->gb) != 0) { + skip_bits(&s->gb, 8); + } + + if(s->h263_slice_structured){ + if (get_bits1(&s->gb) != 1) { + av_log(s->avctx, AV_LOG_ERROR, "SEPB1 marker missing\n"); + return -1; + } + + ff_h263_decode_mba(s); + + if (get_bits1(&s->gb) != 1) { + av_log(s->avctx, AV_LOG_ERROR, "SEPB2 marker missing\n"); + return -1; + } + } + s->f_code = 1; + + if(s->h263_aic){ + s->y_dc_scale_table= + s->c_dc_scale_table= ff_aic_dc_scale_table; + }else{ + s->y_dc_scale_table= + s->c_dc_scale_table= ff_mpeg1_dc_scale_table; + } + + ff_h263_show_pict_info(s); + if (s->pict_type == FF_I_TYPE && s->codec_tag == AV_RL32("ZYGO")){ + int i,j; + for(i=0; i<85; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb)); + av_log(s->avctx, AV_LOG_DEBUG, "\n"); + for(i=0; i<13; i++){ + for(j=0; j<3; j++){ + int v= get_bits(&s->gb, 8); + v |= get_sbits(&s->gb, 8)<<8; + av_log(s->avctx, AV_LOG_DEBUG, " %5d", v); + } + av_log(s->avctx, AV_LOG_DEBUG, "\n"); + } + for(i=0; i<50; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb)); + } + + return 0; +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ituh263enc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/ituh263enc.c new file mode 100644 index 0000000000..f736d7c66a --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ituh263enc.c @@ -0,0 +1,842 @@ +/* + * ITU H263 bitstream encoder + * Copyright (c) 2000,2001 Fabrice Bellard + * H263+ support. + * Copyright (c) 2001 Juan J. Sierralta P + * Copyright (c) 2002-2004 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 + */ + +/** + * @file + * h263 bitstream encoder. + */ + +//#define DEBUG +#include + +#include "dsputil.h" +#include "avcodec.h" +#include "mpegvideo.h" +#include "h263.h" +#include "mathops.h" +#include "unary.h" +#include "flv.h" +#include "mpeg4video.h" +#include "internal.h" + +//#undef NDEBUG +//#include + +/** + * Table of number of bits a motion vector component needs. + */ +static uint8_t mv_penalty[MAX_FCODE+1][MAX_MV*2+1]; + +/** + * Minimal fcode that a motion vector component would need. + */ +static uint8_t fcode_tab[MAX_MV*2+1]; + +/** + * Minimal fcode that a motion vector component would need in umv. + * All entries in this table are 1. + */ +static uint8_t umv_fcode_tab[MAX_MV*2+1]; + +//unified encoding tables for run length encoding of coefficients +//unified in the sense that the specification specifies the encoding in several steps. +static uint8_t uni_h263_intra_aic_rl_len [64*64*2*2]; +static uint8_t uni_h263_inter_rl_len [64*64*2*2]; +//#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128 + (run)*256 + (level)) +//#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128*64 + (run) + (level)*64) +#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128*64 + (run)*128 + (level)) + +static const uint8_t wrong_run[102] = { + 1, 2, 3, 5, 4, 10, 9, 8, +11, 15, 17, 16, 23, 22, 21, 20, +19, 18, 25, 24, 27, 26, 11, 7, + 6, 1, 2, 13, 2, 2, 2, 2, + 6, 12, 3, 9, 1, 3, 4, 3, + 7, 4, 1, 1, 5, 5, 14, 6, + 1, 7, 1, 8, 1, 1, 1, 1, +10, 1, 1, 5, 9, 17, 25, 24, +29, 33, 32, 41, 2, 23, 28, 31, + 3, 22, 30, 4, 27, 40, 8, 26, + 6, 39, 7, 38, 16, 37, 15, 10, +11, 12, 13, 14, 1, 21, 20, 18, +19, 2, 1, 34, 35, 36 +}; + +/** + * Returns the 4 bit value that specifies the given aspect ratio. + * This may be one of the standard aspect ratios or it specifies + * that the aspect will be stored explicitly later. + */ +av_const int ff_h263_aspect_to_info(AVRational aspect){ + int i; + + if(aspect.num==0) aspect= (AVRational){1,1}; + + for(i=1; i<6; i++){ + if(av_cmp_q(ff_h263_pixel_aspect[i], aspect) == 0){ + return i; + } + } + + return FF_ASPECT_EXTENDED; +} + +void h263_encode_picture_header(MpegEncContext * s, int picture_number) +{ + int format, coded_frame_rate, coded_frame_rate_base, i, temp_ref; + int best_clock_code=1; + int best_divisor=60; + int best_error= INT_MAX; + + if(s->h263_plus){ + for(i=0; i<2; i++){ + int div, error; + div= (s->avctx->time_base.num*1800000LL + 500LL*s->avctx->time_base.den) / ((1000LL+i)*s->avctx->time_base.den); + div= av_clip(div, 1, 127); + error= FFABS(s->avctx->time_base.num*1800000LL - (1000LL+i)*s->avctx->time_base.den*div); + if(error < best_error){ + best_error= error; + best_divisor= div; + best_clock_code= i; + } + } + } + s->custom_pcf= best_clock_code!=1 || best_divisor!=60; + coded_frame_rate= 1800000; + coded_frame_rate_base= (1000+best_clock_code)*best_divisor; + + align_put_bits(&s->pb); + + /* Update the pointer to last GOB */ + s->ptr_lastgob = put_bits_ptr(&s->pb); + put_bits(&s->pb, 22, 0x20); /* PSC */ + temp_ref= s->picture_number * (int64_t)coded_frame_rate * s->avctx->time_base.num / //FIXME use timestamp + (coded_frame_rate_base * (int64_t)s->avctx->time_base.den); + put_sbits(&s->pb, 8, temp_ref); /* TemporalReference */ + + put_bits(&s->pb, 1, 1); /* marker */ + put_bits(&s->pb, 1, 0); /* h263 id */ + put_bits(&s->pb, 1, 0); /* split screen off */ + put_bits(&s->pb, 1, 0); /* camera off */ + put_bits(&s->pb, 1, 0); /* freeze picture release off */ + + format = ff_match_2uint16(h263_format, FF_ARRAY_ELEMS(h263_format), s->width, s->height); + if (!s->h263_plus) { + /* H.263v1 */ + put_bits(&s->pb, 3, format); + put_bits(&s->pb, 1, (s->pict_type == FF_P_TYPE)); + /* By now UMV IS DISABLED ON H.263v1, since the restrictions + of H.263v1 UMV implies to check the predicted MV after + calculation of the current MB to see if we're on the limits */ + put_bits(&s->pb, 1, 0); /* Unrestricted Motion Vector: off */ + put_bits(&s->pb, 1, 0); /* SAC: off */ + put_bits(&s->pb, 1, s->obmc); /* Advanced Prediction */ + put_bits(&s->pb, 1, 0); /* only I/P frames, no PB frame */ + put_bits(&s->pb, 5, s->qscale); + put_bits(&s->pb, 1, 0); /* Continuous Presence Multipoint mode: off */ + } else { + int ufep=1; + /* H.263v2 */ + /* H.263 Plus PTYPE */ + + put_bits(&s->pb, 3, 7); + put_bits(&s->pb,3,ufep); /* Update Full Extended PTYPE */ + if (format == 7) + put_bits(&s->pb,3,6); /* Custom Source Format */ + else + put_bits(&s->pb, 3, format); + + put_bits(&s->pb,1, s->custom_pcf); + put_bits(&s->pb,1, s->umvplus); /* Unrestricted Motion Vector */ + put_bits(&s->pb,1,0); /* SAC: off */ + put_bits(&s->pb,1,s->obmc); /* Advanced Prediction Mode */ + put_bits(&s->pb,1,s->h263_aic); /* Advanced Intra Coding */ + put_bits(&s->pb,1,s->loop_filter); /* Deblocking Filter */ + put_bits(&s->pb,1,s->h263_slice_structured); /* Slice Structured */ + put_bits(&s->pb,1,0); /* Reference Picture Selection: off */ + put_bits(&s->pb,1,0); /* Independent Segment Decoding: off */ + put_bits(&s->pb,1,s->alt_inter_vlc); /* Alternative Inter VLC */ + put_bits(&s->pb,1,s->modified_quant); /* Modified Quantization: */ + put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */ + put_bits(&s->pb,3,0); /* Reserved */ + + put_bits(&s->pb, 3, s->pict_type == FF_P_TYPE); + + put_bits(&s->pb,1,0); /* Reference Picture Resampling: off */ + put_bits(&s->pb,1,0); /* Reduced-Resolution Update: off */ + put_bits(&s->pb,1,s->no_rounding); /* Rounding Type */ + put_bits(&s->pb,2,0); /* Reserved */ + put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */ + + /* This should be here if PLUSPTYPE */ + put_bits(&s->pb, 1, 0); /* Continuous Presence Multipoint mode: off */ + + if (format == 7) { + /* Custom Picture Format (CPFMT) */ + s->aspect_ratio_info= ff_h263_aspect_to_info(s->avctx->sample_aspect_ratio); + + put_bits(&s->pb,4,s->aspect_ratio_info); + put_bits(&s->pb,9,(s->width >> 2) - 1); + put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */ + put_bits(&s->pb,9,(s->height >> 2)); + if (s->aspect_ratio_info == FF_ASPECT_EXTENDED){ + put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.num); + put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.den); + } + } + if(s->custom_pcf){ + if(ufep){ + put_bits(&s->pb, 1, best_clock_code); + put_bits(&s->pb, 7, best_divisor); + } + put_sbits(&s->pb, 2, temp_ref>>8); + } + + /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ + if (s->umvplus) +// put_bits(&s->pb,1,1); /* Limited according tables of Annex D */ +//FIXME check actual requested range + put_bits(&s->pb,2,1); /* unlimited */ + if(s->h263_slice_structured) + put_bits(&s->pb,2,0); /* no weird submodes */ + + put_bits(&s->pb, 5, s->qscale); + } + + put_bits(&s->pb, 1, 0); /* no PEI */ + + if(s->h263_slice_structured){ + put_bits(&s->pb, 1, 1); + + assert(s->mb_x == 0 && s->mb_y == 0); + ff_h263_encode_mba(s); + + put_bits(&s->pb, 1, 1); + } + + if(s->h263_aic){ + s->y_dc_scale_table= + s->c_dc_scale_table= ff_aic_dc_scale_table; + }else{ + s->y_dc_scale_table= + s->c_dc_scale_table= ff_mpeg1_dc_scale_table; + } +} + +/** + * Encodes a group of blocks header. + */ +void h263_encode_gob_header(MpegEncContext * s, int mb_line) +{ + put_bits(&s->pb, 17, 1); /* GBSC */ + + if(s->h263_slice_structured){ + put_bits(&s->pb, 1, 1); + + ff_h263_encode_mba(s); + + if(s->mb_num > 1583) + put_bits(&s->pb, 1, 1); + put_bits(&s->pb, 5, s->qscale); /* GQUANT */ + put_bits(&s->pb, 1, 1); + put_bits(&s->pb, 2, s->pict_type == FF_I_TYPE); /* GFID */ + }else{ + int gob_number= mb_line / s->gob_index; + + put_bits(&s->pb, 5, gob_number); /* GN */ + put_bits(&s->pb, 2, s->pict_type == FF_I_TYPE); /* GFID */ + put_bits(&s->pb, 5, s->qscale); /* GQUANT */ + } +} + +/** + * modify qscale so that encoding is acually possible in h263 (limit difference to -2..2) + */ +void ff_clean_h263_qscales(MpegEncContext *s){ + int i; + int8_t * const qscale_table= s->current_picture.qscale_table; + + ff_init_qscale_tab(s); + + for(i=1; imb_num; i++){ + if(qscale_table[ s->mb_index2xy[i] ] - qscale_table[ s->mb_index2xy[i-1] ] >2) + qscale_table[ s->mb_index2xy[i] ]= qscale_table[ s->mb_index2xy[i-1] ]+2; + } + for(i=s->mb_num-2; i>=0; i--){ + if(qscale_table[ s->mb_index2xy[i] ] - qscale_table[ s->mb_index2xy[i+1] ] >2) + qscale_table[ s->mb_index2xy[i] ]= qscale_table[ s->mb_index2xy[i+1] ]+2; + } + + if(s->codec_id != CODEC_ID_H263P){ + for(i=1; imb_num; i++){ + int mb_xy= s->mb_index2xy[i]; + + if(qscale_table[mb_xy] != qscale_table[s->mb_index2xy[i-1]] && (s->mb_type[mb_xy]&CANDIDATE_MB_TYPE_INTER4V)){ + s->mb_type[mb_xy]|= CANDIDATE_MB_TYPE_INTER; + } + } + } +} + +static const int dquant_code[5]= {1,0,9,2,3}; + +/** + * encodes a 8x8 block. + * @param block the 8x8 block + * @param n block index (0-3 are luma, 4-5 are chroma) + */ +static void h263_encode_block(MpegEncContext * s, DCTELEM * block, int n) +{ + int level, run, last, i, j, last_index, last_non_zero, sign, slevel, code; + RLTable *rl; + + rl = &ff_h263_rl_inter; + if (s->mb_intra && !s->h263_aic) { + /* DC coef */ + level = block[0]; + /* 255 cannot be represented, so we clamp */ + if (level > 254) { + level = 254; + block[0] = 254; + } + /* 0 cannot be represented also */ + else if (level < 1) { + level = 1; + block[0] = 1; + } + if (level == 128) //FIXME check rv10 + put_bits(&s->pb, 8, 0xff); + else + put_bits(&s->pb, 8, level); + i = 1; + } else { + i = 0; + if (s->h263_aic && s->mb_intra) + rl = &rl_intra_aic; + + if(s->alt_inter_vlc && !s->mb_intra){ + int aic_vlc_bits=0; + int inter_vlc_bits=0; + int wrong_pos=-1; + int aic_code; + + last_index = s->block_last_index[n]; + last_non_zero = i - 1; + for (; i <= last_index; i++) { + j = s->intra_scantable.permutated[i]; + level = block[j]; + if (level) { + run = i - last_non_zero - 1; + last = (i == last_index); + + if(level<0) level= -level; + + code = get_rl_index(rl, last, run, level); + aic_code = get_rl_index(&rl_intra_aic, last, run, level); + inter_vlc_bits += rl->table_vlc[code][1]+1; + aic_vlc_bits += rl_intra_aic.table_vlc[aic_code][1]+1; + + if (code == rl->n) { + inter_vlc_bits += 1+6+8-1; + } + if (aic_code == rl_intra_aic.n) { + aic_vlc_bits += 1+6+8-1; + wrong_pos += run + 1; + }else + wrong_pos += wrong_run[aic_code]; + last_non_zero = i; + } + } + i = 0; + if(aic_vlc_bits < inter_vlc_bits && wrong_pos > 63) + rl = &rl_intra_aic; + } + } + + /* AC coefs */ + last_index = s->block_last_index[n]; + last_non_zero = i - 1; + for (; i <= last_index; i++) { + j = s->intra_scantable.permutated[i]; + level = block[j]; + if (level) { + run = i - last_non_zero - 1; + last = (i == last_index); + sign = 0; + slevel = level; + if (level < 0) { + sign = 1; + level = -level; + } + code = get_rl_index(rl, last, run, level); + put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); + if (code == rl->n) { + if(!CONFIG_FLV_ENCODER || s->h263_flv <= 1){ + put_bits(&s->pb, 1, last); + put_bits(&s->pb, 6, run); + + assert(slevel != 0); + + if(level < 128) + put_sbits(&s->pb, 8, slevel); + else{ + put_bits(&s->pb, 8, 128); + put_sbits(&s->pb, 5, slevel); + put_sbits(&s->pb, 6, slevel>>5); + } + }else{ + ff_flv2_encode_ac_esc(&s->pb, slevel, level, run, last); + } + } else { + put_bits(&s->pb, 1, sign); + } + last_non_zero = i; + } + } +} + +/* Encode MV differences on H.263+ with Unrestricted MV mode */ +static void h263p_encode_umotion(MpegEncContext * s, int val) +{ + short sval = 0; + short i = 0; + short n_bits = 0; + short temp_val; + int code = 0; + int tcode; + + if ( val == 0) + put_bits(&s->pb, 1, 1); + else if (val == 1) + put_bits(&s->pb, 3, 0); + else if (val == -1) + put_bits(&s->pb, 3, 2); + else { + + sval = ((val < 0) ? (short)(-val):(short)val); + temp_val = sval; + + while (temp_val != 0) { + temp_val = temp_val >> 1; + n_bits++; + } + + i = n_bits - 1; + while (i > 0) { + tcode = (sval & (1 << (i-1))) >> (i-1); + tcode = (tcode << 1) | 1; + code = (code << 2) | tcode; + i--; + } + code = ((code << 1) | (val < 0)) << 1; + put_bits(&s->pb, (2*n_bits)+1, code); + } +} + +void h263_encode_mb(MpegEncContext * s, + DCTELEM block[6][64], + int motion_x, int motion_y) +{ + int cbpc, cbpy, i, cbp, pred_x, pred_y; + int16_t pred_dc; + int16_t rec_intradc[6]; + int16_t *dc_ptr[6]; + const int interleaved_stats= (s->flags&CODEC_FLAG_PASS1); + + if (!s->mb_intra) { + /* compute cbp */ + cbp= get_p_cbp(s, block, motion_x, motion_y); + + if ((cbp | motion_x | motion_y | s->dquant | (s->mv_type - MV_TYPE_16X16)) == 0) { + /* skip macroblock */ + put_bits(&s->pb, 1, 1); + if(interleaved_stats){ + s->misc_bits++; + s->last_bits++; + } + s->skip_count++; + + return; + } + put_bits(&s->pb, 1, 0); /* mb coded */ + + cbpc = cbp & 3; + cbpy = cbp >> 2; + if(s->alt_inter_vlc==0 || cbpc!=3) + cbpy ^= 0xF; + if(s->dquant) cbpc+= 8; + if(s->mv_type==MV_TYPE_16X16){ + put_bits(&s->pb, + ff_h263_inter_MCBPC_bits[cbpc], + ff_h263_inter_MCBPC_code[cbpc]); + + put_bits(&s->pb, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]); + if(s->dquant) + put_bits(&s->pb, 2, dquant_code[s->dquant+2]); + + if(interleaved_stats){ + s->misc_bits+= get_bits_diff(s); + } + + /* motion vectors: 16x16 mode */ + h263_pred_motion(s, 0, 0, &pred_x, &pred_y); + + if (!s->umvplus) { + ff_h263_encode_motion_vector(s, motion_x - pred_x, + motion_y - pred_y, 1); + } + else { + h263p_encode_umotion(s, motion_x - pred_x); + h263p_encode_umotion(s, motion_y - pred_y); + if (((motion_x - pred_x) == 1) && ((motion_y - pred_y) == 1)) + /* To prevent Start Code emulation */ + put_bits(&s->pb,1,1); + } + }else{ + put_bits(&s->pb, + ff_h263_inter_MCBPC_bits[cbpc+16], + ff_h263_inter_MCBPC_code[cbpc+16]); + put_bits(&s->pb, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]); + if(s->dquant) + put_bits(&s->pb, 2, dquant_code[s->dquant+2]); + + if(interleaved_stats){ + s->misc_bits+= get_bits_diff(s); + } + + for(i=0; i<4; i++){ + /* 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]; + if (!s->umvplus) { + ff_h263_encode_motion_vector(s, motion_x - pred_x, + motion_y - pred_y, 1); + } + else { + h263p_encode_umotion(s, motion_x - pred_x); + h263p_encode_umotion(s, motion_y - pred_y); + if (((motion_x - pred_x) == 1) && ((motion_y - pred_y) == 1)) + /* To prevent Start Code emulation */ + put_bits(&s->pb,1,1); + } + } + } + + if(interleaved_stats){ + s->mv_bits+= get_bits_diff(s); + } + } else { + assert(s->mb_intra); + + cbp = 0; + if (s->h263_aic) { + /* Predict DC */ + for(i=0; i<6; i++) { + int16_t level = block[i][0]; + int scale; + + if(i<4) scale= s->y_dc_scale; + else scale= s->c_dc_scale; + + pred_dc = h263_pred_dc(s, i, &dc_ptr[i]); + level -= pred_dc; + /* Quant */ + if (level >= 0) + level = (level + (scale>>1))/scale; + else + level = (level - (scale>>1))/scale; + + /* AIC can change CBP */ + if (level == 0 && s->block_last_index[i] == 0) + s->block_last_index[i] = -1; + + if(!s->modified_quant){ + if (level < -127) + level = -127; + else if (level > 127) + level = 127; + } + + block[i][0] = level; + /* Reconstruction */ + rec_intradc[i] = scale*level + pred_dc; + /* Oddify */ + rec_intradc[i] |= 1; + //if ((rec_intradc[i] % 2) == 0) + // rec_intradc[i]++; + /* Clipping */ + if (rec_intradc[i] < 0) + rec_intradc[i] = 0; + else if (rec_intradc[i] > 2047) + rec_intradc[i] = 2047; + + /* Update AC/DC tables */ + *dc_ptr[i] = rec_intradc[i]; + if (s->block_last_index[i] >= 0) + cbp |= 1 << (5 - i); + } + }else{ + for(i=0; i<6; i++) { + /* compute cbp */ + if (s->block_last_index[i] >= 1) + cbp |= 1 << (5 - i); + } + } + + cbpc = cbp & 3; + if (s->pict_type == FF_I_TYPE) { + if(s->dquant) cbpc+=4; + put_bits(&s->pb, + ff_h263_intra_MCBPC_bits[cbpc], + ff_h263_intra_MCBPC_code[cbpc]); + } else { + if(s->dquant) cbpc+=8; + put_bits(&s->pb, 1, 0); /* mb coded */ + put_bits(&s->pb, + ff_h263_inter_MCBPC_bits[cbpc + 4], + ff_h263_inter_MCBPC_code[cbpc + 4]); + } + if (s->h263_aic) { + /* XXX: currently, we do not try to use ac prediction */ + put_bits(&s->pb, 1, 0); /* no AC prediction */ + } + cbpy = cbp >> 2; + put_bits(&s->pb, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]); + if(s->dquant) + put_bits(&s->pb, 2, dquant_code[s->dquant+2]); + + if(interleaved_stats){ + s->misc_bits+= get_bits_diff(s); + } + } + + for(i=0; i<6; i++) { + /* encode each block */ + h263_encode_block(s, block[i], i); + + /* Update INTRADC for decoding */ + if (s->h263_aic && s->mb_intra) { + block[i][0] = rec_intradc[i]; + + } + } + + if(interleaved_stats){ + if (!s->mb_intra) { + s->p_tex_bits+= get_bits_diff(s); + s->f_count++; + }else{ + s->i_tex_bits+= get_bits_diff(s); + s->i_count++; + } + } +} + +void ff_h263_encode_motion(MpegEncContext * s, int val, int f_code) +{ + int range, l, bit_size, sign, code, bits; + + if (val == 0) { + /* zero vector */ + code = 0; + put_bits(&s->pb, mvtab[code][1], mvtab[code][0]); + } else { + bit_size = f_code - 1; + range = 1 << bit_size; + /* modulo encoding */ + l= INT_BIT - 6 - bit_size; + val = (val<>l; + sign = val>>31; + val= (val^sign)-sign; + sign&=1; + + val--; + code = (val >> bit_size) + 1; + bits = val & (range - 1); + + put_bits(&s->pb, mvtab[code][1] + 1, (mvtab[code][0] << 1) | sign); + if (bit_size > 0) { + put_bits(&s->pb, bit_size, bits); + } + } +} + +static void init_mv_penalty_and_fcode(MpegEncContext *s) +{ + int f_code; + int mv; + + for(f_code=1; f_code<=MAX_FCODE; f_code++){ + for(mv=-MAX_MV; mv<=MAX_MV; mv++){ + int len; + + if(mv==0) len= mvtab[0][1]; + else{ + int val, bit_size, code; + + bit_size = f_code - 1; + + val=mv; + if (val < 0) + val = -val; + val--; + code = (val >> bit_size) + 1; + if(code<33){ + len= mvtab[code][1] + 1 + bit_size; + }else{ + len= mvtab[32][1] + av_log2(code>>5) + 2 + bit_size; + } + } + + mv_penalty[f_code][mv+MAX_MV]= len; + } + } + + for(f_code=MAX_FCODE; f_code>0; f_code--){ + for(mv=-(16<= 64); + assert(MAX_RUN >= 63); + + for(slevel=-64; slevel<64; slevel++){ + if(slevel==0) continue; + for(run=0; run<64; run++){ + for(last=0; last<=1; last++){ + const int index= UNI_MPEG4_ENC_INDEX(last, run, slevel+64); + int level= slevel < 0 ? -slevel : slevel; + int sign= slevel < 0 ? 1 : 0; + int bits, len, code; + + len_tab[index]= 100; + + /* ESC0 */ + code= get_rl_index(rl, last, run, level); + bits= rl->table_vlc[code][0]; + len= rl->table_vlc[code][1]; + bits=bits*2+sign; len++; + + if(code!=rl->n && len < len_tab[index]){ + if(bits_tab) bits_tab[index]= bits; + len_tab [index]= len; + } + /* ESC */ + bits= rl->table_vlc[rl->n][0]; + len = rl->table_vlc[rl->n][1]; + bits=bits*2+last; len++; + bits=bits*64+run; len+=6; + bits=bits*256+(level&0xff); len+=8; + + if(len < len_tab[index]){ + if(bits_tab) bits_tab[index]= bits; + len_tab [index]= len; + } + } + } + } +} + +void h263_encode_init(MpegEncContext *s) +{ + static int done = 0; + + if (!done) { + done = 1; + + init_rl(&ff_h263_rl_inter, ff_h263_static_rl_table_store[0]); + init_rl(&rl_intra_aic, ff_h263_static_rl_table_store[1]); + + init_uni_h263_rl_tab(&rl_intra_aic, NULL, uni_h263_intra_aic_rl_len); + init_uni_h263_rl_tab(&ff_h263_rl_inter , NULL, uni_h263_inter_rl_len); + + init_mv_penalty_and_fcode(s); + } + s->me.mv_penalty= mv_penalty; //FIXME exact table for msmpeg4 & h263p + + s->intra_ac_vlc_length =s->inter_ac_vlc_length = uni_h263_inter_rl_len; + s->intra_ac_vlc_last_length=s->inter_ac_vlc_last_length= uni_h263_inter_rl_len + 128*64; + if(s->h263_aic){ + s->intra_ac_vlc_length = uni_h263_intra_aic_rl_len; + s->intra_ac_vlc_last_length= uni_h263_intra_aic_rl_len + 128*64; + } + s->ac_esc_length= 7+1+6+8; + + // use fcodes >1 only for mpeg4 & h263 & h263p FIXME + switch(s->codec_id){ + case CODEC_ID_MPEG4: + s->fcode_tab= fcode_tab; + break; + case CODEC_ID_H263P: + if(s->umvplus) + s->fcode_tab= umv_fcode_tab; + if(s->modified_quant){ + s->min_qcoeff= -2047; + s->max_qcoeff= 2047; + }else{ + s->min_qcoeff= -127; + s->max_qcoeff= 127; + } + break; + //Note for mpeg4 & h263 the dc-scale table will be set per frame as needed later + case CODEC_ID_FLV1: + if (s->h263_flv > 1) { + s->min_qcoeff= -1023; + s->max_qcoeff= 1023; + } else { + s->min_qcoeff= -127; + s->max_qcoeff= 127; + } + s->y_dc_scale_table= + s->c_dc_scale_table= ff_mpeg1_dc_scale_table; + break; + default: //nothing needed - default table already set in mpegvideo.c + s->min_qcoeff= -127; + s->max_qcoeff= 127; + s->y_dc_scale_table= + s->c_dc_scale_table= ff_mpeg1_dc_scale_table; + } +} + +void ff_h263_encode_mba(MpegEncContext *s) +{ + int i, mb_pos; + + for(i=0; i<6; i++){ + if(s->mb_num-1 <= ff_mba_max[i]) break; + } + mb_pos= s->mb_x + s->mb_width*s->mb_y; + put_bits(&s->pb, ff_mba_length[i], mb_pos); +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ivi_common.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/ivi_common.c new file mode 100644 index 0000000000..a0596f67af --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ivi_common.c @@ -0,0 +1,1000 @@ +/* + * common functions for Indeo Video Interactive codecs (Indeo4 and Indeo5) + * + * Copyright (c) 2009 Maxim Poliakovski + * + * 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 + * This file contains functions and data shared by both Indeo4 and + * Indeo5 decoders. + */ + +#define ALT_BITSTREAM_READER_LE +#include "avcodec.h" +#include "get_bits.h" +#include "ivi_common.h" +#include "libavutil/common.h" +#include "ivi_dsp.h" + +extern const IVIHuffDesc ff_ivi_mb_huff_desc[8]; ///< static macroblock huffman tables +extern const IVIHuffDesc ff_ivi_blk_huff_desc[8]; ///< static block huffman tables + +VLC ff_ivi_mb_vlc_tabs [8]; +VLC ff_ivi_blk_vlc_tabs[8]; + +/** + * Reverses "nbits" bits of the value "val" and returns the result + * in the least significant bits. + */ +static uint16_t inv_bits(uint16_t val, int nbits) +{ + uint16_t res; + + if (nbits <= 8) { + res = av_reverse[val] >> (8-nbits); + } else + res = ((av_reverse[val & 0xFF] << 8) + (av_reverse[val >> 8])) >> (16-nbits); + + return res; +} + +int ff_ivi_create_huff_from_desc(const IVIHuffDesc *cb, VLC *vlc, int flag) +{ + int pos, i, j, codes_per_row, prefix, not_last_row; + uint16_t codewords[256]; /* FIXME: move this temporal storage out? */ + uint8_t bits[256]; + + pos = 0; /* current position = 0 */ + + for (i = 0; i < cb->num_rows; i++) { + codes_per_row = 1 << cb->xbits[i]; + not_last_row = (i != cb->num_rows - 1); + prefix = ((1 << i) - 1) << (cb->xbits[i] + not_last_row); + + for (j = 0; j < codes_per_row; j++) { + if (pos >= 256) /* Some Indeo5 codebooks can have more than 256 */ + break; /* elements, but only 256 codes are allowed! */ + + bits[pos] = i + cb->xbits[i] + not_last_row; + if (bits[pos] > IVI_VLC_BITS) + return -1; /* invalid descriptor */ + + codewords[pos] = inv_bits((prefix | j), bits[pos]); + if (!bits[pos]) + bits[pos] = 1; + + pos++; + }//for j + }//for i + + /* number of codewords = pos */ + return init_vlc(vlc, IVI_VLC_BITS, pos, bits, 1, 1, codewords, 2, 2, + (flag ? INIT_VLC_USE_NEW_STATIC : 0) | INIT_VLC_LE); +} + +void ff_ivi_init_static_vlc(void) +{ + int i; + static VLC_TYPE table_data[8192 * 16][2]; + static int initialized_vlcs = 0; + + if (initialized_vlcs) + return; + for (i = 0; i < 8; i++) { + ff_ivi_mb_vlc_tabs[i].table = table_data + i * 2 * 8192; + ff_ivi_mb_vlc_tabs[i].table_allocated = 8192; + ff_ivi_create_huff_from_desc(&ff_ivi_mb_huff_desc[i], &ff_ivi_mb_vlc_tabs[i], 1); + ff_ivi_blk_vlc_tabs[i].table = table_data + (i * 2 + 1) * 8192; + ff_ivi_blk_vlc_tabs[i].table_allocated = 8192; + ff_ivi_create_huff_from_desc(&ff_ivi_blk_huff_desc[i], &ff_ivi_blk_vlc_tabs[i], 1); + } + initialized_vlcs = 1; +} + +int ff_ivi_dec_huff_desc(GetBitContext *gb, int desc_coded, int which_tab, + IVIHuffTab *huff_tab, AVCodecContext *avctx) +{ + int i, result; + IVIHuffDesc new_huff; + + if (!desc_coded) { + /* select default table */ + huff_tab->tab = (which_tab) ? &ff_ivi_blk_vlc_tabs[7] + : &ff_ivi_mb_vlc_tabs [7]; + } else { + huff_tab->tab_sel = get_bits(gb, 3); + if (huff_tab->tab_sel == 7) { + /* custom huffman table (explicitly encoded) */ + new_huff.num_rows = get_bits(gb, 4); + + for (i = 0; i < new_huff.num_rows; i++) + new_huff.xbits[i] = get_bits(gb, 4); + + /* Have we got the same custom table? Rebuild if not. */ + if (ff_ivi_huff_desc_cmp(&new_huff, &huff_tab->cust_desc)) { + ff_ivi_huff_desc_copy(&huff_tab->cust_desc, &new_huff); + + if (huff_tab->cust_tab.table) + free_vlc(&huff_tab->cust_tab); + result = ff_ivi_create_huff_from_desc(&huff_tab->cust_desc, + &huff_tab->cust_tab, 0); + if (result) { + av_log(avctx, AV_LOG_ERROR, + "Error while initializing custom vlc table!\n"); + return -1; + } + } + huff_tab->tab = &huff_tab->cust_tab; + } else { + /* select one of predefined tables */ + huff_tab->tab = (which_tab) ? &ff_ivi_blk_vlc_tabs[huff_tab->tab_sel] + : &ff_ivi_mb_vlc_tabs [huff_tab->tab_sel]; + } + } + + return 0; +} + +int ff_ivi_huff_desc_cmp(const IVIHuffDesc *desc1, const IVIHuffDesc *desc2) +{ + return desc1->num_rows != desc2->num_rows + || memcmp(desc1->xbits, desc2->xbits, desc1->num_rows); +} + +void ff_ivi_huff_desc_copy(IVIHuffDesc *dst, const IVIHuffDesc *src) +{ + dst->num_rows = src->num_rows; + memcpy(dst->xbits, src->xbits, src->num_rows); +} + +int av_cold ff_ivi_init_planes(IVIPlaneDesc *planes, const IVIPicConfig *cfg) +{ + int p, b; + uint32_t b_width, b_height, align_fac, width_aligned, height_aligned, buf_size; + IVIBandDesc *band; + + ff_ivi_free_buffers(planes); + + /* fill in the descriptor of the luminance plane */ + planes[0].width = cfg->pic_width; + planes[0].height = cfg->pic_height; + planes[0].num_bands = cfg->luma_bands; + + /* fill in the descriptors of the chrominance planes */ + planes[1].width = planes[2].width = (cfg->pic_width + 3) >> 2; + planes[1].height = planes[2].height = (cfg->pic_height + 3) >> 2; + planes[1].num_bands = planes[2].num_bands = cfg->chroma_bands; + + for (p = 0; p < 3; p++) { + planes[p].bands = av_mallocz(planes[p].num_bands * sizeof(IVIBandDesc)); + if (!planes[p].bands) + return AVERROR(ENOMEM); + + /* select band dimensions: if there is only one band then it + * has the full size, if there are several bands each of them + * has only half size */ + b_width = planes[p].num_bands == 1 ? planes[p].width : (planes[p].width + 1) >> 1; + b_height = planes[p].num_bands == 1 ? planes[p].height : (planes[p].height + 1) >> 1; + + /* luma band buffers will be aligned on 16x16 (max macroblock size) */ + /* chroma band buffers will be aligned on 8x8 (max macroblock size) */ + align_fac = p ? 8 : 16; + width_aligned = FFALIGN(b_width , align_fac); + height_aligned = FFALIGN(b_height, align_fac); + buf_size = width_aligned * height_aligned * sizeof(int16_t); + + for (b = 0; b < planes[p].num_bands; b++) { + band = &planes[p].bands[b]; /* select appropriate plane/band */ + band->plane = p; + band->band_num = b; + band->width = b_width; + band->height = b_height; + band->pitch = width_aligned; + band->bufs[0] = av_malloc(buf_size); + band->bufs[1] = av_malloc(buf_size); + if (!band->bufs[0] || !band->bufs[1]) + return AVERROR(ENOMEM); + + /* allocate the 3rd band buffer for scalability mode */ + if (cfg->luma_bands > 1) { + band->bufs[2] = av_malloc(buf_size); + if (!band->bufs[2]) + return AVERROR(ENOMEM); + } + + planes[p].bands[0].blk_vlc.cust_desc.num_rows = 0; /* reset custom vlc */ + } + } + + return 0; +} + +void av_cold ff_ivi_free_buffers(IVIPlaneDesc *planes) +{ + int p, b, t; + + for (p = 0; p < 3; p++) { + for (b = 0; b < planes[p].num_bands; b++) { + av_freep(&planes[p].bands[b].bufs[0]); + av_freep(&planes[p].bands[b].bufs[1]); + av_freep(&planes[p].bands[b].bufs[2]); + + if (planes[p].bands[b].blk_vlc.cust_tab.table) + free_vlc(&planes[p].bands[b].blk_vlc.cust_tab); + for (t = 0; t < planes[p].bands[b].num_tiles; t++) + av_freep(&planes[p].bands[b].tiles[t].mbs); + av_freep(&planes[p].bands[b].tiles); + } + av_freep(&planes[p].bands); + } +} + +int av_cold ff_ivi_init_tiles(IVIPlaneDesc *planes, int tile_width, int tile_height) +{ + int p, b, x, y, x_tiles, y_tiles, t_width, t_height; + IVIBandDesc *band; + IVITile *tile, *ref_tile; + + for (p = 0; p < 3; p++) { + t_width = !p ? tile_width : (tile_width + 3) >> 2; + t_height = !p ? tile_height : (tile_height + 3) >> 2; + + if (!p && planes[0].num_bands == 4) { + t_width >>= 1; + t_height >>= 1; + } + + for (b = 0; b < planes[p].num_bands; b++) { + band = &planes[p].bands[b]; + x_tiles = IVI_NUM_TILES(band->width, t_width); + y_tiles = IVI_NUM_TILES(band->height, t_height); + band->num_tiles = x_tiles * y_tiles; + + av_freep(&band->tiles); + band->tiles = av_mallocz(band->num_tiles * sizeof(IVITile)); + if (!band->tiles) + return AVERROR(ENOMEM); + + tile = band->tiles; + + /* use the first luma band as reference for motion vectors + * and quant */ + ref_tile = planes[0].bands[0].tiles; + + for (y = 0; y < band->height; y += t_height) { + for (x = 0; x < band->width; x += t_width) { + tile->xpos = x; + tile->ypos = y; + tile->width = FFMIN(band->width - x, t_width); + tile->height = FFMIN(band->height - y, t_height); + tile->is_empty = tile->data_size = 0; + /* calculate number of macroblocks */ + tile->num_MBs = IVI_MBs_PER_TILE(tile->width, tile->height, + band->mb_size); + + av_freep(&tile->mbs); + tile->mbs = av_malloc(tile->num_MBs * sizeof(IVIMbInfo)); + if (!tile->mbs) + return AVERROR(ENOMEM); + + tile->ref_mbs = 0; + if (p || b) { + tile->ref_mbs = ref_tile->mbs; + ref_tile++; + } + + tile++; + } + } + + }// for b + }// for p + + return 0; +} + +int ff_ivi_dec_tile_data_size(GetBitContext *gb) +{ + int len; + + len = 0; + if (get_bits1(gb)) { + len = get_bits(gb, 8); + if (len == 255) + len = get_bits_long(gb, 24); + } + + /* align the bitstream reader on the byte boundary */ + align_get_bits(gb); + + return len; +} + +int ff_ivi_decode_blocks(GetBitContext *gb, IVIBandDesc *band, IVITile *tile) +{ + int mbn, blk, num_blocks, num_coeffs, blk_size, scan_pos, run, val, + pos, is_intra, mc_type, mv_x, mv_y, col_mask; + uint8_t col_flags[8]; + int32_t prev_dc, trvec[64]; + uint32_t cbp, sym, lo, hi, quant, buf_offs, q; + IVIMbInfo *mb; + RVMapDesc *rvmap = band->rv_map; + void (*mc_with_delta_func)(int16_t *buf, const int16_t *ref_buf, uint32_t pitch, int mc_type); + void (*mc_no_delta_func) (int16_t *buf, const int16_t *ref_buf, uint32_t pitch, int mc_type); + const uint8_t *base_tab, *scale_tab; + + prev_dc = 0; /* init intra prediction for the DC coefficient */ + + blk_size = band->blk_size; + col_mask = blk_size - 1; /* column mask for tracking non-zero coeffs */ + num_blocks = (band->mb_size != blk_size) ? 4 : 1; /* number of blocks per mb */ + num_coeffs = blk_size * blk_size; + if (blk_size == 8) { + mc_with_delta_func = ff_ivi_mc_8x8_delta; + mc_no_delta_func = ff_ivi_mc_8x8_no_delta; + } else { + mc_with_delta_func = ff_ivi_mc_4x4_delta; + mc_no_delta_func = ff_ivi_mc_4x4_no_delta; + } + + for (mbn = 0, mb = tile->mbs; mbn < tile->num_MBs; mb++, mbn++) { + is_intra = !mb->type; + cbp = mb->cbp; + buf_offs = mb->buf_offs; + + quant = av_clip(band->glob_quant + mb->q_delta, 0, 23); + + base_tab = is_intra ? band->intra_base : band->inter_base; + scale_tab = is_intra ? band->intra_scale : band->inter_scale; + + if (!is_intra) { + mv_x = mb->mv_x; + mv_y = mb->mv_y; + if (!band->is_halfpel) { + mc_type = 0; /* we have only fullpel vectors */ + } else { + mc_type = ((mv_y & 1) << 1) | (mv_x & 1); + mv_x >>= 1; + mv_y >>= 1; /* convert halfpel vectors into fullpel ones */ + } + } + + for (blk = 0; blk < num_blocks; blk++) { + /* adjust block position in the buffer according to its number */ + if (blk & 1) { + buf_offs += blk_size; + } else if (blk == 2) { + buf_offs -= blk_size; + buf_offs += blk_size * band->pitch; + } + + if (cbp & 1) { /* block coded ? */ + scan_pos = -1; + memset(trvec, 0, num_coeffs*sizeof(trvec[0])); /* zero transform vector */ + memset(col_flags, 0, sizeof(col_flags)); /* zero column flags */ + + while (scan_pos <= num_coeffs) { + sym = get_vlc2(gb, band->blk_vlc.tab->table, IVI_VLC_BITS, 1); + if (sym == rvmap->eob_sym) + break; /* End of block */ + + if (sym == rvmap->esc_sym) { /* Escape - run/val explicitly coded using 3 vlc codes */ + run = get_vlc2(gb, band->blk_vlc.tab->table, IVI_VLC_BITS, 1) + 1; + lo = get_vlc2(gb, band->blk_vlc.tab->table, IVI_VLC_BITS, 1); + hi = get_vlc2(gb, band->blk_vlc.tab->table, IVI_VLC_BITS, 1); + val = IVI_TOSIGNED((hi << 6) | lo); /* merge them and convert into signed val */ + } else { + run = rvmap->runtab[sym]; + val = rvmap->valtab[sym]; + } + + /* de-zigzag and dequantize */ + scan_pos += run; + if (scan_pos >= num_coeffs) + break; + pos = band->scan[scan_pos]; + + if (IVI_DEBUG && !val) + av_log(NULL, AV_LOG_ERROR, "Val = 0 encountered!\n"); + + q = (base_tab[pos] * scale_tab[quant]) >> 8; + if (q > 1) + val = val * q + FFSIGN(val) * ((q >> 1) - (q & 1)); + trvec[pos] = val; + col_flags[pos & col_mask] |= !!val; /* track columns containing non-zero coeffs */ + }// while + + if (scan_pos >= num_coeffs && sym != rvmap->eob_sym) + return -1; /* corrupt block data */ + + /* undoing DC coeff prediction for intra-blocks */ + if (is_intra && band->is_2d_trans) { + prev_dc += trvec[0]; + trvec[0] = prev_dc; + col_flags[0] |= !!prev_dc; + } + + /* apply inverse transform */ + band->inv_transform(trvec, band->buf + buf_offs, + band->pitch, col_flags); + + /* apply motion compensation */ + if (!is_intra) + mc_with_delta_func(band->buf + buf_offs, + band->ref_buf + buf_offs + mv_y * band->pitch + mv_x, + band->pitch, mc_type); + } else { + /* block not coded */ + /* for intra blocks apply the dc slant transform */ + /* for inter - perform the motion compensation without delta */ + if (is_intra && band->dc_transform) { + band->dc_transform(&prev_dc, band->buf + buf_offs, + band->pitch, blk_size); + } else + mc_no_delta_func(band->buf + buf_offs, + band->ref_buf + buf_offs + mv_y * band->pitch + mv_x, + band->pitch, mc_type); + } + + cbp >>= 1; + }// for blk + }// for mbn + + align_get_bits(gb); + + return 0; +} + +void ff_ivi_process_empty_tile(AVCodecContext *avctx, IVIBandDesc *band, + IVITile *tile, int32_t mv_scale) +{ + int x, y, need_mc, mbn, blk, num_blocks, mv_x, mv_y, mc_type; + int offs, mb_offset, row_offset; + IVIMbInfo *mb, *ref_mb; + const int16_t *src; + int16_t *dst; + void (*mc_no_delta_func)(int16_t *buf, const int16_t *ref_buf, uint32_t pitch, + int mc_type); + + offs = tile->ypos * band->pitch + tile->xpos; + mb = tile->mbs; + ref_mb = tile->ref_mbs; + row_offset = band->mb_size * band->pitch; + need_mc = 0; /* reset the mc tracking flag */ + + for (y = tile->ypos; y < (tile->ypos + tile->height); y += band->mb_size) { + mb_offset = offs; + + for (x = tile->xpos; x < (tile->xpos + tile->width); x += band->mb_size) { + mb->xpos = x; + mb->ypos = y; + mb->buf_offs = mb_offset; + + mb->type = 1; /* set the macroblocks type = INTER */ + mb->cbp = 0; /* all blocks are empty */ + + if (!band->qdelta_present && !band->plane && !band->band_num) { + mb->q_delta = band->glob_quant; + mb->mv_x = 0; + mb->mv_y = 0; + } + + if (band->inherit_qdelta && ref_mb) + mb->q_delta = ref_mb->q_delta; + + if (band->inherit_mv) { + /* motion vector inheritance */ + if (mv_scale) { + mb->mv_x = ivi_scale_mv(ref_mb->mv_x, mv_scale); + mb->mv_y = ivi_scale_mv(ref_mb->mv_y, mv_scale); + } else { + mb->mv_x = ref_mb->mv_x; + mb->mv_y = ref_mb->mv_y; + } + need_mc |= mb->mv_x || mb->mv_y; /* tracking non-zero motion vectors */ + } + + mb++; + if (ref_mb) + ref_mb++; + mb_offset += band->mb_size; + } // for x + offs += row_offset; + } // for y + + if (band->inherit_mv && need_mc) { /* apply motion compensation if there is at least one non-zero motion vector */ + num_blocks = (band->mb_size != band->blk_size) ? 4 : 1; /* number of blocks per mb */ + mc_no_delta_func = (band->blk_size == 8) ? ff_ivi_mc_8x8_no_delta + : ff_ivi_mc_4x4_no_delta; + + for (mbn = 0, mb = tile->mbs; mbn < tile->num_MBs; mb++, mbn++) { + mv_x = mb->mv_x; + mv_y = mb->mv_y; + if (!band->is_halfpel) { + mc_type = 0; /* we have only fullpel vectors */ + } else { + mc_type = ((mv_y & 1) << 1) | (mv_x & 1); + mv_x >>= 1; + mv_y >>= 1; /* convert halfpel vectors into fullpel ones */ + } + + for (blk = 0; blk < num_blocks; blk++) { + /* adjust block position in the buffer according with its number */ + offs = mb->buf_offs + band->blk_size * ((blk & 1) + !!(blk & 2) * band->pitch); + mc_no_delta_func(band->buf + offs, + band->ref_buf + offs + mv_y * band->pitch + mv_x, + band->pitch, mc_type); + } + } + } else { + /* copy data from the reference tile into the current one */ + src = band->ref_buf + tile->ypos * band->pitch + tile->xpos; + dst = band->buf + tile->ypos * band->pitch + tile->xpos; + for (y = 0; y < tile->height; y++) { + memcpy(dst, src, tile->width*sizeof(band->buf[0])); + src += band->pitch; + dst += band->pitch; + } + } +} + + +#if IVI_DEBUG +uint16_t ivi_calc_band_checksum (IVIBandDesc *band) +{ + int x, y; + int16_t *src, checksum; + + src = band->buf; + checksum = 0; + + for (y = 0; y < band->height; src += band->pitch, y++) + for (x = 0; x < band->width; x++) + checksum += src[x]; + + return checksum; +} + +int ivi_check_band (IVIBandDesc *band, const uint8_t *ref, int pitch) +{ + int x, y, result; + uint8_t t1, t2; + int16_t *src; + + src = band->buf; + result = 0; + + for (y = 0; y < band->height; src += band->pitch, y++) { + for (x = 0; x < band->width; x++) { + t1 = av_clip(src[x] + 128, 0, 255); + t2 = ref[x]; + if (t1 != t2) { + av_log(NULL, AV_LOG_ERROR, "Data mismatch: row %d, column %d\n", + y / band->blk_size, x / band->blk_size); + result = -1; + } + } + ref += pitch; + } + + return result; +} +#endif + +void ff_ivi_output_plane(IVIPlaneDesc *plane, uint8_t *dst, int dst_pitch) +{ + int x, y; + const int16_t *src = plane->bands[0].buf; + uint32_t pitch = plane->bands[0].pitch; + + for (y = 0; y < plane->height; y++) { + for (x = 0; x < plane->width; x++) + dst[x] = av_clip_uint8(src[x] + 128); + src += pitch; + dst += dst_pitch; + } +} + + +/** + * These are 2x8 predefined Huffman codebooks for coding macroblock/block + * signals. They are specified using "huffman descriptors" in order to + * avoid huge static tables. The decoding tables will be generated at + * startup from these descriptors. + */ +const IVIHuffDesc ff_ivi_mb_huff_desc[8] = { + {8, {0, 4, 5, 4, 4, 4, 6, 6}}, + {12, {0, 2, 2, 3, 3, 3, 3, 5, 3, 2, 2, 2}}, + {12, {0, 2, 3, 4, 3, 3, 3, 3, 4, 3, 2, 2}}, + {12, {0, 3, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2}}, + {13, {0, 4, 4, 3, 3, 3, 3, 2, 3, 3, 2, 1, 1}}, + {9, {0, 4, 4, 4, 4, 3, 3, 3, 2}}, + {10, {0, 4, 4, 4, 4, 3, 3, 2, 2, 2}}, + {12, {0, 4, 4, 4, 3, 3, 2, 3, 2, 2, 2, 2}} +}; + +const IVIHuffDesc ff_ivi_blk_huff_desc[8] = { + {10, {1, 2, 3, 4, 4, 7, 5, 5, 4, 1}}, + {11, {2, 3, 4, 4, 4, 7, 5, 4, 3, 3, 2}}, + {12, {2, 4, 5, 5, 5, 5, 6, 4, 4, 3, 1, 1}}, + {13, {3, 3, 4, 4, 5, 6, 6, 4, 4, 3, 2, 1, 1}}, + {11, {3, 4, 4, 5, 5, 5, 6, 5, 4, 2, 2}}, + {13, {3, 4, 5, 5, 5, 5, 6, 4, 3, 3, 2, 1, 1}}, + {13, {3, 4, 5, 5, 5, 6, 5, 4, 3, 3, 2, 1, 1}}, + {9, {3, 4, 4, 5, 5, 5, 6, 5, 5}} +}; + + +/** + * Run-value (RLE) tables. + */ +const RVMapDesc ff_ivi_rvmap_tabs[9] = { +{ /* MapTab0 */ + 5, /* eob_sym */ + 2, /* esc_sym */ + /* run table */ + {1, 1, 0, 1, 1, 0, 1, 1, 2, 2, 1, 1, 1, 1, 3, 3, + 1, 1, 2, 2, 1, 1, 4, 4, 1, 1, 1, 1, 2, 2, 5, 5, + 1, 1, 3, 3, 1, 1, 6, 6, 1, 2, 1, 2, 7, 7, 1, 1, + 8, 8, 1, 1, 4, 2, 1, 4, 2, 1, 3, 3, 1, 1, 1, 9, + 9, 1, 2, 1, 2, 1, 5, 5, 1, 1, 10, 10, 1, 1, 3, 3, + 2, 2, 1, 1, 11, 11, 6, 4, 4, 1, 6, 1, 2, 1, 2, 12, + 8, 1, 12, 7, 8, 7, 1, 16, 1, 16, 1, 3, 3, 13, 1, 13, + 2, 2, 1, 15, 1, 5, 14, 15, 1, 5, 14, 1, 17, 8, 17, 8, + 1, 4, 4, 2, 2, 1, 25, 25, 24, 24, 1, 3, 1, 3, 1, 8, + 6, 7, 6, 1, 18, 8, 18, 1, 7, 23, 2, 2, 23, 1, 1, 21, + 22, 9, 9, 22, 19, 1, 21, 5, 19, 5, 1, 33, 20, 33, 20, 8, + 4, 4, 1, 32, 2, 2, 8, 3, 32, 26, 3, 1, 7, 7, 26, 6, + 1, 6, 1, 1, 16, 1, 10, 1, 10, 2, 16, 29, 28, 2, 29, 28, + 1, 27, 5, 8, 5, 27, 1, 8, 3, 7, 3, 31, 41, 31, 1, 41, + 6, 1, 6, 7, 4, 4, 1, 1, 2, 1, 2, 11, 34, 30, 11, 1, + 30, 15, 15, 34, 36, 40, 36, 40, 35, 35, 37, 37, 39, 39, 38, 38}, + + /* value table */ + { 1, -1, 0, 2, -2, 0, 3, -3, 1, -1, 4, -4, 5, -5, 1, -1, + 6, -6, 2, -2, 7, -7, 1, -1, 8, -8, 9, -9, 3, -3, 1, -1, + 10, -10, 2, -2, 11, -11, 1, -1, 12, 4, -12, -4, 1, -1, 13, -13, + 1, -1, 14, -14, 2, 5, 15, -2, -5, -15, -3, 3, 16, -16, 17, 1, + -1, -17, 6, 18, -6, -18, 2, -2, 19, -19, 1, -1, 20, -20, 4, -4, + 7, -7, 21, -21, 1, -1, 2, 3, -3, 22, -2, -22, 8, 23, -8, 1, + 2, -23, -1, 2, -2, -2, 24, 1, -24, -1, 25, 5, -5, 1, -25, -1, + 9, -9, 26, 1, -26, 3, 1, -1, 27, -3, -1, -27, 1, 3, -1, -3, + 28, -4, 4, 10, -10, -28, 1, -1, 1, -1, 29, 6, -29, -6, 30, -4, + 3, 3, -3, -30, 1, 4, -1, 31, -3, 1, 11, -11, -1, -31, 32, -1, + -1, 2, -2, 1, 1, -32, 1, 4, -1, -4, 33, -1, 1, 1, -1, 5, + 5, -5, -33, -1, -12, 12, -5, -7, 1, 1, 7, 34, 4, -4, -1, 4, + -34, -4, 35, 36, -2, -35, -2, -36, 2, 13, 2, -1, 1, -13, 1, -1, + 37, 1, -5, 6, 5, -1, 38, -6, -8, 5, 8, -1, 1, 1, -37, -1, + 5, 39, -5, -5, 6, -6, -38, -39, -14, 40, 14, 2, 1, 1, -2, -40, + -1, -2, 2, -1, -1, -1, 1, 1, 1, -1, 1, -1, 1, -1, 1, -1} +},{ + /* MapTab1 */ + 0, /* eob_sym */ + 38, /* esc_sym */ + /* run table */ + {0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 8, 6, 8, 7, + 7, 9, 9, 10, 10, 11, 11, 1, 12, 1, 12, 13, 13, 16, 14, 16, + 14, 15, 15, 17, 17, 18, 0, 18, 19, 20, 21, 19, 22, 21, 20, 22, + 25, 24, 2, 25, 24, 23, 23, 2, 26, 28, 26, 28, 29, 27, 29, 27, + 33, 33, 1, 32, 1, 3, 32, 30, 36, 3, 36, 30, 31, 31, 35, 34, + 37, 41, 34, 35, 37, 4, 41, 4, 49, 8, 8, 49, 40, 38, 5, 38, + 40, 39, 5, 39, 42, 43, 42, 7, 57, 6, 43, 44, 6, 50, 7, 44, + 57, 48, 50, 48, 45, 45, 46, 47, 51, 46, 47, 58, 1, 51, 58, 1, + 52, 59, 53, 9, 52, 55, 55, 59, 53, 56, 54, 56, 54, 9, 64, 64, + 60, 63, 60, 63, 61, 62, 61, 62, 2, 10, 2, 10, 11, 1, 11, 13, + 12, 1, 12, 13, 16, 16, 8, 8, 14, 3, 3, 15, 14, 15, 4, 4, + 1, 17, 17, 5, 1, 7, 7, 5, 6, 1, 2, 2, 6, 22, 1, 25, + 21, 22, 8, 24, 1, 21, 25, 24, 8, 18, 18, 23, 9, 20, 23, 33, + 29, 33, 20, 1, 19, 1, 29, 36, 9, 36, 19, 41, 28, 57, 32, 3, + 28, 3, 1, 27, 49, 49, 1, 32, 26, 26, 2, 4, 4, 7, 57, 41, + 2, 7, 10, 5, 37, 16, 10, 27, 8, 8, 13, 16, 37, 13, 1, 5}, + + /* value table */ + {0, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 1, -1, -1, 1, + -1, 1, -1, 1, -1, 1, -1, 2, 1, -2, -1, 1, -1, 1, 1, -1, + -1, 1, -1, 1, -1, 1, 0, -1, 1, 1, 1, -1, 1, -1, -1, -1, + 1, 1, 2, -1, -1, 1, -1, -2, 1, 1, -1, -1, 1, 1, -1, -1, + 1, -1, 3, 1, -3, 2, -1, 1, 1, -2, -1, -1, -1, 1, 1, 1, + 1, 1, -1, -1, -1, 2, -1, -2, 1, 2, -2, -1, 1, 1, 2, -1, + -1, 1, -2, -1, 1, 1, -1, 2, 1, 2, -1, 1, -2, -1, -2, -1, + -1, 1, 1, -1, 1, -1, 1, 1, 1, -1, -1, 1, 4, -1, -1, -4, + 1, 1, 1, 2, -1, -1, 1, -1, -1, 1, -1, -1, 1, -2, 1, -1, + 1, 1, -1, -1, 1, 1, -1, -1, 3, 2, -3, -2, 2, 5, -2, 2, + 2, -5, -2, -2, -2, 2, -3, 3, 2, 3, -3, 2, -2, -2, 3, -3, + 6, 2, -2, 3, -6, 3, -3, -3, 3, 7, -4, 4, -3, 2, -7, 2, + 2, -2, -4, 2, 8, -2, -2, -2, 4, 2, -2, 2, 3, 2, -2, -2, + 2, 2, -2, -8, -2, 9, -2, 2, -3, -2, 2, -2, 2, 2, 2, 4, + -2, -4, 10, 2, 2, -2, -9, -2, 2, -2, 5, 4, -4, 4, -2, 2, + -5, -4, -3, 4, 2, -3, 3, -2, -5, 5, 3, 3, -2, -3, -10, -4} +},{ + /* MapTab2 */ + 2, /* eob_sym */ + 11, /* esc_sym */ + /* run table */ + {1, 1, 0, 2, 2, 1, 1, 3, 3, 4, 4, 0, 1, 1, 5, 5, + 2, 2, 6, 6, 7, 7, 1, 8, 1, 8, 3, 3, 9, 9, 1, 2, + 2, 1, 4, 10, 4, 10, 11, 11, 1, 5, 12, 12, 1, 5, 13, 13, + 3, 3, 6, 6, 2, 2, 14, 14, 16, 16, 15, 7, 15, 8, 8, 7, + 1, 1, 17, 17, 4, 4, 1, 1, 18, 18, 2, 2, 5, 5, 25, 3, + 9, 3, 25, 9, 19, 24, 19, 24, 1, 21, 20, 1, 21, 22, 20, 22, + 23, 23, 8, 6, 33, 6, 8, 33, 7, 7, 26, 26, 1, 32, 1, 32, + 28, 4, 28, 10, 29, 27, 27, 10, 41, 4, 29, 2, 2, 41, 36, 31, + 49, 31, 34, 30, 34, 36, 30, 35, 1, 49, 11, 5, 35, 11, 1, 3, + 3, 5, 37, 37, 8, 40, 8, 40, 12, 12, 42, 42, 1, 38, 16, 57, + 1, 6, 16, 39, 38, 6, 7, 7, 13, 13, 39, 43, 2, 43, 57, 2, + 50, 9, 44, 9, 50, 4, 15, 48, 44, 4, 1, 15, 48, 14, 14, 1, + 45, 45, 8, 3, 5, 8, 51, 47, 3, 46, 46, 47, 5, 51, 1, 17, + 17, 58, 1, 58, 2, 52, 52, 2, 53, 7, 59, 6, 6, 56, 53, 55, + 7, 55, 1, 54, 59, 56, 54, 10, 1, 10, 4, 60, 1, 60, 8, 4, + 8, 64, 64, 61, 1, 63, 3, 63, 62, 61, 5, 11, 5, 3, 11, 62}, + + /* value table */ + { 1, -1, 0, 1, -1, 2, -2, 1, -1, 1, -1, 0, 3, -3, 1, -1, + 2, -2, 1, -1, 1, -1, 4, 1, -4, -1, 2, -2, 1, -1, 5, 3, + -3, -5, 2, 1, -2, -1, 1, -1, 6, 2, 1, -1, -6, -2, 1, -1, + 3, -3, 2, -2, 4, -4, 1, -1, 1, -1, 1, 2, -1, 2, -2, -2, + 7, -7, 1, -1, 3, -3, 8, -8, 1, -1, 5, -5, 3, -3, 1, 4, + 2, -4, -1, -2, 1, 1, -1, -1, 9, 1, 1, -9, -1, 1, -1, -1, + 1, -1, 3, -3, 1, 3, -3, -1, 3, -3, 1, -1, 10, 1, -10, -1, + 1, 4, -1, 2, 1, -1, 1, -2, 1, -4, -1, 6, -6, -1, 1, 1, + 1, -1, 1, 1, -1, -1, -1, 1, 11, -1, -2, 4, -1, 2, -11, 5, + -5, -4, -1, 1, 4, 1, -4, -1, -2, 2, 1, -1, 12, 1, -2, 1, + -12, 4, 2, 1, -1, -4, 4, -4, 2, -2, -1, 1, 7, -1, -1, -7, + -1, -3, 1, 3, 1, 5, 2, 1, -1, -5, 13, -2, -1, 2, -2, -13, + 1, -1, 5, 6, 5, -5, 1, 1, -6, 1, -1, -1, -5, -1, 14, 2, + -2, 1, -14, -1, 8, 1, -1, -8, 1, 5, 1, 5, -5, 1, -1, 1, + -5, -1, 15, 1, -1, -1, -1, 3, -15, -3, 6, 1, 16, -1, 6, -6, + -6, 1, -1, 1, -16, 1, 7, -1, 1, -1, -6, -3, 6, -7, 3, -1} +},{ + /* MapTab3 */ + 0, /* eob_sym */ + 35, /* esc_sym */ + /* run table */ + {0, 1, 1, 2, 2, 3, 3, 4, 4, 1, 1, 5, 5, 6, 6, 7, + 7, 8, 8, 9, 9, 2, 2, 10, 10, 1, 1, 11, 11, 12, 12, 3, + 3, 13, 13, 0, 14, 14, 16, 15, 16, 15, 4, 4, 17, 1, 17, 1, + 5, 5, 18, 18, 2, 2, 6, 6, 8, 19, 7, 8, 7, 19, 20, 20, + 21, 21, 22, 24, 22, 24, 23, 23, 1, 1, 25, 25, 3, 3, 26, 26, + 9, 9, 27, 27, 28, 28, 33, 29, 4, 33, 29, 1, 4, 1, 32, 32, + 2, 2, 31, 10, 30, 10, 30, 31, 34, 34, 5, 5, 36, 36, 35, 41, + 35, 11, 41, 11, 37, 1, 8, 8, 37, 6, 1, 6, 40, 7, 7, 40, + 12, 38, 12, 39, 39, 38, 49, 13, 49, 13, 3, 42, 3, 42, 16, 16, + 43, 43, 14, 14, 1, 1, 44, 15, 44, 15, 2, 2, 57, 48, 50, 48, + 57, 50, 4, 45, 45, 4, 46, 47, 47, 46, 1, 51, 1, 17, 17, 51, + 8, 9, 9, 5, 58, 8, 58, 5, 52, 52, 55, 56, 53, 56, 55, 59, + 59, 53, 54, 1, 6, 54, 7, 7, 6, 1, 2, 3, 2, 3, 64, 60, + 60, 10, 10, 64, 61, 62, 61, 63, 1, 63, 62, 1, 18, 24, 18, 4, + 25, 4, 8, 21, 21, 1, 24, 22, 25, 22, 8, 11, 19, 11, 23, 1, + 20, 23, 19, 20, 5, 12, 5, 1, 16, 2, 12, 13, 2, 13, 1, 16}, + + /* value table */ + { 0, 1, -1, 1, -1, 1, -1, 1, -1, 2, -2, 1, -1, 1, -1, 1, + -1, 1, -1, 1, -1, 2, -2, 1, -1, 3, -3, 1, -1, 1, -1, 2, + -2, 1, -1, 0, 1, -1, 1, 1, -1, -1, 2, -2, 1, 4, -1, -4, + 2, -2, 1, -1, -3, 3, 2, -2, 2, 1, 2, -2, -2, -1, 1, -1, + 1, -1, 1, 1, -1, -1, 1, -1, 5, -5, 1, -1, 3, -3, 1, -1, + 2, -2, 1, -1, 1, -1, 1, 1, 3, -1, -1, 6, -3, -6, -1, 1, + 4, -4, 1, 2, 1, -2, -1, -1, 1, -1, 3, -3, 1, -1, 1, 1, + -1, 2, -1, -2, 1, 7, -3, 3, -1, 3, -7, -3, 1, -3, 3, -1, + 2, 1, -2, 1, -1, -1, 1, 2, -1, -2, -4, -1, 4, 1, 2, -2, + 1, -1, -2, 2, 8, -8, -1, 2, 1, -2, -5, 5, 1, -1, -1, 1, + -1, 1, 4, -1, 1, -4, -1, -1, 1, 1, 9, 1, -9, 2, -2, -1, + -4, 3, -3, -4, -1, 4, 1, 4, 1, -1, 1, -1, 1, 1, -1, 1, + -1, -1, -1, 10, 4, 1, 4, -4, -4, -10, 6, 5, -6, -5, 1, -1, + 1, 3, -3, -1, 1, -1, -1, -1, 11, 1, 1, -11, -2, -2, 2, 5, + -2, -5, -5, 2, -2, 12, 2, -2, 2, 2, 5, -3, -2, 3, -2, -12, + -2, 2, 2, 2, -5, 3, 5, 13, -3, 7, -3, -3, -7, 3, -13, 3} +},{ + /* MapTab4 */ + 0, /* eob_sym */ + 34, /* esc_sym */ + /* run table */ + {0, 1, 1, 1, 2, 2, 1, 3, 3, 1, 1, 1, 4, 4, 1, 5, + 2, 1, 5, 2, 1, 1, 6, 6, 1, 1, 1, 1, 1, 7, 3, 1, + 2, 3, 0, 1, 2, 7, 1, 1, 1, 8, 1, 1, 8, 1, 1, 1, + 9, 1, 9, 1, 2, 1, 1, 2, 1, 1, 10, 4, 1, 10, 1, 4, + 1, 1, 1, 1, 1, 3, 1, 1, 1, 3, 2, 1, 5, 1, 1, 1, + 2, 5, 1, 11, 1, 11, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 2, 1, 6, 1, 6, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 12, + 3, 1, 12, 1, 1, 1, 2, 1, 1, 3, 1, 1, 1, 1, 1, 1, + 4, 1, 1, 1, 2, 1, 1, 4, 1, 1, 1, 1, 1, 1, 2, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 2, 1, 1, 5, + 1, 1, 1, 1, 1, 7, 1, 7, 1, 1, 2, 3, 1, 1, 1, 1, + 5, 1, 1, 1, 1, 1, 1, 2, 13, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 13, 2, 1, 1, 4, 1, 1, 1, + 3, 1, 6, 1, 1, 1, 14, 1, 1, 1, 1, 1, 14, 6, 1, 1, + 1, 1, 15, 2, 4, 1, 2, 3, 15, 1, 1, 1, 8, 1, 1, 8, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1}, + + /* value table */ + { 0, 1, -1, 2, 1, -1, -2, 1, -1, 3, -3, 4, 1, -1, -4, 1, + 2, 5, -1, -2, -5, 6, 1, -1, -6, 7, -7, 8, -8, 1, 2, 9, + 3, -2, 0, -9, -3, -1, 10, -10, 11, 1, -11, 12, -1, -12, 13, -13, + 1, 14, -1, -14, 4, 15, -15, -4, 16, -16, 1, 2, 17, -1, -17, -2, + 18, -18, 19, -19, 20, 3, -20, 21, -21, -3, 5, 22, 2, -22, -23, 23, + -5, -2, 24, 1, -24, -1, 25, -25, 26, -26, -27, 27, 28, 29, -28, -29, + 6, 30, 2, -31, -2, -30, 31, -6, -32, 32, 33, -33, 34, -35, -34, 1, + 4, -36, -1, 35, 37, 36, 7, -37, 38, -4, -38, 39, 41, 40, -40, -39, + 3, 42, -43, -41, -7, -42, 43, -3, 44, -44, 45, -45, 46, 47, 8, -47, + -48, -46, 50, -50, 48, 49, 51, -49, 52, -52, 5, -51, -8, -53, 53, 3, + -56, 56, 55, 54, -54, 2, 60, -2, -55, 58, 9, -5, 59, 57, -57, -63, + -3, -58, -60, -61, 61, -59, -62, -9, 1, 64, 62, 69, -64, 63, 65, -67, + -68, 66, -65, 68, -66, -69, 67, -70, -1, 10, 71, -71, 4, 73, 72, 70, + 6, -76, -3, 74, -78, -74, 1, 78, 80, -72, -75, 76, -1, 3, -73, 79, + 75, 77, 1, 11, -4, -79, -10, -6, -1, -77, -83, -80, 2, 81, -84, -2, + 83, -81, 82, -82, 84, -87, -86, 85, -11, -85, 86, -89, 87, -88, 88, 89} +},{ + /* MapTab5 */ + 2, /* eob_sym */ + 33, /* esc_sym */ + /* run table */ + {1, 1, 0, 2, 1, 2, 1, 3, 3, 1, 1, 4, 4, 2, 2, 1, + 1, 5, 5, 6, 1, 6, 1, 7, 7, 3, 3, 2, 8, 2, 8, 1, + 1, 0, 9, 9, 1, 1, 10, 4, 10, 4, 11, 11, 2, 1, 2, 1, + 12, 12, 3, 3, 1, 1, 13, 5, 5, 13, 14, 1, 1, 14, 2, 2, + 6, 6, 15, 1, 1, 15, 16, 4, 7, 16, 4, 7, 1, 1, 3, 3, + 8, 8, 2, 2, 1, 1, 17, 17, 1, 1, 18, 18, 5, 5, 2, 2, + 1, 1, 9, 19, 9, 19, 20, 3, 3, 20, 1, 10, 21, 1, 10, 4, + 4, 21, 22, 6, 6, 22, 1, 1, 23, 24, 2, 2, 23, 24, 11, 1, + 1, 11, 7, 25, 7, 1, 1, 25, 8, 8, 3, 26, 3, 1, 12, 2, + 2, 26, 1, 12, 5, 5, 27, 4, 1, 4, 1, 27, 28, 1, 28, 13, + 1, 13, 2, 29, 2, 1, 32, 6, 1, 30, 14, 29, 14, 6, 3, 31, + 3, 1, 30, 1, 32, 31, 33, 9, 33, 1, 1, 7, 9, 7, 2, 2, + 1, 1, 4, 36, 34, 4, 5, 10, 10, 5, 34, 1, 1, 35, 8, 8, + 36, 3, 35, 1, 15, 3, 2, 1, 16, 15, 16, 2, 37, 1, 37, 1, + 1, 1, 6, 6, 38, 1, 38, 11, 1, 39, 39, 40, 11, 2, 41, 4, + 40, 1, 2, 4, 1, 1, 1, 41, 3, 1, 3, 1, 5, 7, 5, 7}, + + /* value table */ + { 1, -1, 0, 1, 2, -1, -2, 1, -1, 3, -3, 1, -1, 2, -2, 4, + -4, 1, -1, 1, 5, -1, -5, 1, -1, 2, -2, 3, 1, -3, -1, 6, + -6, 0, 1, -1, 7, -7, 1, 2, -1, -2, 1, -1, 4, 8, -4, -8, + 1, -1, 3, -3, 9, -9, 1, 2, -2, -1, 1, 10, -10, -1, 5, -5, + 2, -2, 1, 11, -11, -1, 1, 3, 2, -1, -3, -2, 12, -12, 4, -4, + 2, -2, -6, 6, 13, -13, 1, -1, 14, -14, 1, -1, 3, -3, 7, -7, + 15, -15, 2, 1, -2, -1, 1, 5, -5, -1, -16, 2, 1, 16, -2, 4, + -4, -1, 1, 3, -3, -1, 17, -17, 1, 1, -8, 8, -1, -1, 2, 18, + -18, -2, 3, 1, -3, 19, -19, -1, 3, -3, 6, 1, -6, 20, 2, 9, + -9, -1, -20, -2, 4, -4, 1, -5, 21, 5, -21, -1, 1, -22, -1, 2, + 22, -2, 10, 1, -10, 23, 1, 4, -23, 1, 2, -1, -2, -4, -7, 1, + 7, -24, -1, 24, -1, -1, 1, 3, -1, -25, 25, 4, -3, -4, 11, -11, + 26, -26, 6, 1, 1, -6, -5, -3, 3, 5, -1, -27, 27, 1, 4, -4, + -1, -8, -1, 28, 2, 8, -12, -28, -2, -2, 2, 12, -1, 29, 1, -29, + 30, -30, 5, -5, 1, -31, -1, 3, 31, -1, 1, 1, -3, -13, 1, -7, + -1, -32, 13, 7, 32, 33, -33, -1, -9, -34, 9, 34, -6, 5, 6, -5} +},{ + /* MapTab6 */ + 2, /* eob_sym */ + 13, /* esc_sym */ + /* run table */ + {1, 1, 0, 1, 1, 2, 2, 1, 1, 3, 3, 1, 1, 0, 2, 2, + 4, 1, 4, 1, 1, 1, 5, 5, 1, 1, 6, 6, 2, 2, 1, 1, + 3, 3, 7, 7, 1, 1, 8, 8, 1, 1, 2, 2, 1, 9, 1, 9, + 4, 4, 10, 1, 1, 10, 1, 1, 11, 11, 3, 3, 1, 2, 1, 2, + 1, 1, 12, 12, 5, 5, 1, 1, 13, 1, 1, 13, 2, 2, 1, 1, + 6, 6, 1, 1, 4, 14, 4, 14, 3, 1, 3, 1, 1, 1, 15, 7, + 15, 2, 2, 7, 1, 1, 1, 8, 1, 8, 16, 16, 1, 1, 1, 1, + 2, 1, 1, 2, 1, 1, 3, 5, 5, 3, 4, 1, 1, 4, 1, 1, + 17, 17, 9, 1, 1, 9, 2, 2, 1, 1, 10, 10, 1, 6, 1, 1, + 6, 18, 1, 1, 18, 1, 1, 1, 2, 2, 3, 1, 3, 1, 1, 1, + 4, 1, 19, 1, 19, 7, 1, 1, 20, 1, 4, 20, 1, 7, 11, 2, + 1, 11, 21, 2, 8, 5, 1, 8, 1, 5, 21, 1, 1, 1, 22, 1, + 1, 22, 1, 1, 3, 3, 1, 23, 2, 12, 24, 1, 1, 2, 1, 1, + 12, 23, 1, 1, 24, 1, 1, 1, 4, 1, 1, 1, 2, 1, 6, 6, + 4, 2, 1, 1, 1, 1, 1, 1, 1, 14, 13, 3, 1, 25, 9, 25, + 14, 1, 9, 3, 13, 1, 1, 1, 1, 1, 10, 1, 1, 2, 10, 2}, + + /* value table */ + {-20, -1, 0, 2, -2, 1, -1, 3, -3, 1, -1, 4, -4, 0, 2, -2, + 1, 5, -1, -5, 6, -6, 1, -1, 7, -7, 1, -1, 3, -3, 8, -8, + 2, -2, 1, -1, 9, -9, 1, -1, 10, -10, 4, -4, 11, 1, -11, -1, + 2, -2, 1, 12, -12, -1, 13, -13, 1, -1, 3, -3, 14, 5, -14, -5, + -15, 15, -1, 1, 2, -2, 16, -16, 1, 17, -17, -1, 6, -6, 18, -18, + 2, -2, -19, 19, -3, 1, 3, -1, 4, 20, -4, 1, -21, 21, 1, 2, + -1, -7, 7, -2, 22, -22, 23, 2, -23, -2, 1, -1, -24, 24, -25, 25, + -8, -26, 26, 8, -27, 27, 5, 3, -3, -5, -4, 28, -28, 4, 29, -29, + 1, -1, -2, -30, 30, 2, 9, -9, -31, 31, 2, -2, -32, 3, 32, -33, + -3, 1, 33, -34, -1, 34, -35, 35, -10, 10, -6, 36, 6, -36, 37, -37, + -5, 38, 1, -38, -1, 3, 39, -39, -1, 40, 5, 1, -40, -3, 2, -11, + -41, -2, 1, 11, -3, -4, 41, 3, 42, 4, -1, -43, -42, 43, 1, -44, + 45, -1, 44, -45, -7, 7, -46, 1, -12, 2, 1, -47, 46, 12, 47, 48, + -2, -1, -48, 49, -1, -50, -49, 50, -6, -51, 51, 52, -13, 53, -4, 4, + 6, 13, -53, -52, -54, 55, 54, -55, -56, -2, 2, -8, 56, 1, -3, -1, + 2, 58, 3, 8, -2, 57, -58, -60, -59, -57, -3, 60, 59, -14, 3, 14} +},{ + /* MapTab7 */ + 2, /* eob_sym */ + 38, /* esc_sym */ + /* run table */ + {1, 1, 0, 2, 2, 1, 1, 3, 3, 4, 4, 5, 5, 1, 1, 6, + 6, 2, 2, 7, 7, 8, 8, 1, 1, 3, 3, 9, 9, 10, 10, 1, + 1, 2, 2, 4, 4, 11, 0, 11, 12, 12, 13, 13, 1, 1, 5, 5, + 14, 14, 15, 16, 15, 16, 3, 3, 1, 6, 1, 6, 2, 2, 7, 7, + 8, 8, 17, 17, 1, 1, 4, 4, 18, 18, 2, 2, 1, 19, 1, 20, + 19, 20, 21, 21, 3, 3, 22, 22, 5, 5, 24, 1, 1, 23, 9, 23, + 24, 9, 2, 2, 10, 1, 1, 10, 6, 6, 25, 4, 4, 25, 7, 7, + 26, 8, 1, 8, 3, 1, 26, 3, 11, 11, 27, 27, 2, 28, 1, 2, + 28, 1, 12, 12, 5, 5, 29, 13, 13, 29, 32, 1, 1, 33, 31, 30, + 32, 4, 30, 33, 4, 31, 3, 14, 1, 1, 3, 34, 34, 2, 2, 14, + 6, 6, 35, 36, 35, 36, 1, 15, 1, 16, 16, 15, 7, 9, 7, 9, + 37, 8, 8, 37, 1, 1, 39, 2, 38, 39, 2, 40, 5, 38, 40, 5, + 3, 3, 4, 4, 10, 10, 1, 1, 1, 1, 41, 2, 41, 2, 6, 6, + 1, 1, 11, 42, 11, 43, 3, 42, 3, 17, 4, 43, 1, 17, 7, 1, + 8, 44, 4, 7, 44, 5, 8, 2, 5, 1, 2, 48, 45, 1, 12, 45, + 12, 48, 13, 13, 1, 9, 9, 46, 1, 46, 47, 47, 49, 18, 18, 49}, + + /* value table */ + { 1, -1, 0, 1, -1, 2, -2, 1, -1, 1, -1, 1, -1, 3, -3, 1, + -1, -2, 2, 1, -1, 1, -1, 4, -4, -2, 2, 1, -1, 1, -1, 5, + -5, -3, 3, 2, -2, 1, 0, -1, 1, -1, 1, -1, 6, -6, 2, -2, + 1, -1, 1, 1, -1, -1, -3, 3, 7, 2, -7, -2, -4, 4, 2, -2, + 2, -2, 1, -1, 8, -8, 3, -3, 1, -1, -5, 5, 9, 1, -9, 1, + -1, -1, 1, -1, -4, 4, 1, -1, 3, -3, 1, -10, 10, 1, 2, -1, + -1, -2, 6, -6, 2, 11, -11, -2, 3, -3, 1, -4, 4, -1, 3, -3, + 1, 3, 12, -3, -5, -12, -1, 5, 2, -2, 1, -1, -7, 1, 13, 7, + -1, -13, 2, -2, 4, -4, 1, 2, -2, -1, 1, 14, -14, 1, 1, 1, + -1, -5, -1, -1, 5, -1, -6, 2, -15, 15, 6, 1, -1, -8, 8, -2, + -4, 4, 1, 1, -1, -1, 16, 2, -16, -2, 2, -2, 4, 3, -4, -3, + -1, -4, 4, 1, -17, 17, -1, -9, 1, 1, 9, 1, -5, -1, -1, 5, + -7, 7, 6, -6, 3, -3, 18, -18, 19, -19, 1, -10, -1, 10, -5, 5, + 20, -20, -3, 1, 3, 1, 8, -1, -8, 2, 7, -1, -21, -2, 5, 21, + 5, -1, -7, -5, 1, -6, -5, -11, 6, 22, 11, 1, 1, -22, -3, -1, + 3, -1, 3, -3, -23, 4, -4, 1, 23, -1, 1, -1, 1, -2, 2, -1} +},{ + /* MapTab8 */ + 4, /* eob_sym */ + 11, /* esc_sym */ + /* run table */ + {1, 1, 1, 1, 0, 2, 2, 1, 1, 3, 3, 0, 1, 1, 2, 2, + 4, 4, 1, 1, 5, 5, 1, 1, 2, 2, 3, 3, 6, 6, 1, 1, + 7, 7, 8, 1, 8, 2, 2, 1, 4, 4, 1, 3, 1, 3, 9, 9, + 2, 2, 1, 5, 1, 5, 10, 10, 1, 1, 11, 11, 3, 6, 3, 4, + 4, 6, 2, 2, 1, 12, 1, 12, 7, 13, 7, 13, 1, 1, 8, 8, + 2, 2, 14, 14, 16, 15, 16, 5, 5, 1, 3, 15, 1, 3, 4, 4, + 1, 1, 17, 17, 2, 2, 6, 6, 1, 18, 1, 18, 22, 21, 22, 21, + 25, 24, 25, 19, 9, 20, 9, 23, 19, 24, 20, 3, 23, 7, 3, 1, + 1, 7, 28, 26, 29, 5, 28, 26, 5, 8, 29, 4, 8, 27, 2, 2, + 4, 27, 1, 1, 10, 36, 10, 33, 33, 36, 30, 1, 32, 32, 1, 30, + 6, 31, 31, 35, 3, 6, 11, 11, 3, 2, 35, 2, 34, 1, 34, 1, + 37, 37, 12, 7, 12, 5, 41, 5, 4, 7, 1, 8, 13, 4, 1, 41, + 13, 38, 8, 38, 9, 1, 40, 40, 9, 1, 39, 2, 2, 49, 39, 42, + 3, 3, 14, 16, 49, 14, 16, 42, 43, 43, 6, 6, 15, 1, 1, 15, + 44, 44, 1, 1, 50, 48, 4, 5, 4, 7, 5, 2, 10, 10, 48, 7, + 50, 45, 2, 1, 45, 8, 8, 1, 46, 46, 3, 47, 47, 3, 1, 1}, + + /* value table */ + { 1, -1, 2, -2, 0, 1, -1, 3, -3, 1, -1, 0, 4, -4, 2, -2, + 1, -1, 5, -5, 1, -1, 6, -6, 3, -3, 2, -2, 1, -1, 7, -7, + 1, -1, 1, 8, -1, 4, -4, -8, 2, -2, 9, 3, -9, -3, 1, -1, + 5, -5, 10, 2, -10, -2, 1, -1, 11, -11, 1, -1, -4, 2, 4, 3, + -3, -2, 6, -6, 12, 1, -12, -1, 2, 1, -2, -1, 13, -13, 2, -2, + 7, -7, 1, -1, 1, 1, -1, 3, -3, 14, 5, -1, -14, -5, 4, -4, + 15, -15, 1, -1, 8, -8, -3, 3, 16, 1, -16, -1, 1, 1, -1, -1, + 1, 1, -1, 1, 2, 1, -2, 1, -1, -1, -1, 6, -1, 3, -6, 17, + -17, -3, 1, 1, 1, 4, -1, -1, -4, 3, -1, 5, -3, -1, -9, 9, + -5, 1, 18, -18, 2, 1, -2, 1, -1, -1, 1, 19, -1, 1, -19, -1, + 4, 1, -1, 1, 7, -4, -2, 2, -7, 10, -1, -10, 1, 20, -1, -20, + 1, -1, 2, 4, -2, 5, 1, -5, 6, -4, 21, 4, 2, -6, -21, -1, + -2, 1, -4, -1, -3, 22, -1, 1, 3, -22, -1, 11, -11, 1, 1, 1, + 8, -8, 2, 2, -1, -2, -2, -1, 1, -1, -5, 5, 2, 23, -23, -2, + 1, -1, 24, -24, -1, -1, 7, 6, -7, 5, -6, 12, -3, 3, 1, -5, + 1, 1, -12, 25, -1, -5, 5, -25, -1, 1, 9, 1, -1, -9, 26, -26} +} +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ivi_common.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/ivi_common.h new file mode 100644 index 0000000000..64793e479e --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ivi_common.h @@ -0,0 +1,342 @@ +/* + * common functions for Indeo Video Interactive codecs (Indeo4 and Indeo5) + * + * Copyright (c) 2009 Maxim Poliakovski + * + * 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 + * This file contains structures and macros shared by both Indeo4 and + * Indeo5 decoders. + */ + +#ifndef AVCODEC_IVI_COMMON_H +#define AVCODEC_IVI_COMMON_H + +#include "avcodec.h" +#include "get_bits.h" +#include + +#define IVI_DEBUG 0 + +#define IVI_VLC_BITS 13 ///< max number of bits of the ivi's huffman codes + +/** + * huffman codebook descriptor + */ +typedef struct { + int32_t num_rows; + uint8_t xbits[16]; +} IVIHuffDesc; + +/** + * macroblock/block huffman table descriptor + */ +typedef struct { + int32_t tab_sel; /// index of one of the predefined tables + /// or "7" for custom one + VLC *tab; /// pointer to the table associated with tab_sel + + //! the following are used only when tab_sel == 7 + IVIHuffDesc cust_desc; /// custom Huffman codebook descriptor + VLC cust_tab; /// vlc table for custom codebook +} IVIHuffTab; + +enum { + IVI_MB_HUFF = 0, /// Huffman table is used for coding macroblocks + IVI_BLK_HUFF = 1 /// Huffman table is used for coding blocks +}; + +extern VLC ff_ivi_mb_vlc_tabs [8]; ///< static macroblock Huffman tables +extern VLC ff_ivi_blk_vlc_tabs[8]; ///< static block Huffman tables + + +/** + * run-value (RLE) table descriptor + */ +typedef struct { + uint8_t eob_sym; ///< end of block symbol + uint8_t esc_sym; ///< escape symbol + uint8_t runtab[256]; + int8_t valtab[256]; +} RVMapDesc; + +extern const RVMapDesc ff_ivi_rvmap_tabs[9]; + + +/** + * information for Indeo macroblock (16x16, 8x8 or 4x4) + */ +typedef struct { + int16_t xpos; + int16_t ypos; + uint32_t buf_offs; ///< address in the output buffer for this mb + uint8_t type; ///< macroblock type: 0 - INTRA, 1 - INTER + uint8_t cbp; ///< coded block pattern + int8_t q_delta; ///< quant delta + int8_t mv_x; ///< motion vector (x component) + int8_t mv_y; ///< motion vector (y component) +} IVIMbInfo; + + +/** + * information for Indeo tile + */ +typedef struct { + int xpos; + int ypos; + int width; + int height; + int is_empty; ///< = 1 if this tile doesn't contain any data + int data_size; ///< size of the data in bytes + int num_MBs; ///< number of macroblocks in this tile + IVIMbInfo *mbs; ///< array of macroblock descriptors + IVIMbInfo *ref_mbs; ///< ptr to the macroblock descriptors of the reference tile +} IVITile; + + +/** + * information for Indeo wavelet band + */ +typedef struct { + int plane; ///< plane number this band belongs to + int band_num; ///< band number + int width; + int height; + const uint8_t *data_ptr; ///< ptr to the first byte of the band data + int data_size; ///< size of the band data + int16_t *buf; ///< pointer to the output buffer for this band + int16_t *ref_buf; ///< pointer to the reference frame buffer (for motion compensation) + int16_t *bufs[3]; ///< array of pointers to the band buffers + int pitch; ///< pitch associated with the buffers above + int is_empty; ///< = 1 if this band doesn't contain any data + int mb_size; ///< macroblock size + int blk_size; ///< block size + int is_halfpel; ///< precision of the motion compensation: 0 - fullpel, 1 - halfpel + int inherit_mv; ///< tells if motion vector is inherited from reference macroblock + int inherit_qdelta; ///< tells if quantiser delta is inherited from reference macroblock + int qdelta_present; ///< tells if Qdelta signal is present in the bitstream (Indeo5 only) + int quant_mat; ///< dequant matrix index + int glob_quant; ///< quant base for this band + const uint8_t *scan; ///< ptr to the scan pattern + + IVIHuffTab blk_vlc; ///< vlc table for decoding block data + + uint16_t *dequant_intra; ///< ptr to dequant tables for intra blocks + uint16_t *dequant_inter; ///< ptr dequant tables for inter blocks + int num_corr; ///< number of correction entries + uint8_t corr[61*2]; ///< rvmap correction pairs + int rvmap_sel; ///< rvmap table selector + RVMapDesc *rv_map; ///< ptr to the RLE table for this band + int num_tiles; ///< number of tiles in this band + IVITile *tiles; ///< array of tile descriptors + void (*inv_transform)(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags); ///< inverse transform function pointer + void (*dc_transform) (const int32_t *in, int16_t *out, uint32_t pitch, int blk_size); ///< dc transform function pointer, it may be NULL + int is_2d_trans; ///< 1 indicates that the two-dimensional inverse transform is used + int32_t checksum; ///< for debug purposes + int checksum_present; + int bufsize; ///< band buffer size in bytes + const uint8_t *intra_base; ///< quantization matrix for intra blocks + const uint8_t *inter_base; ///< quantization matrix for inter blocks + const uint8_t *intra_scale; ///< quantization coefficient for intra blocks + const uint8_t *inter_scale; ///< quantization coefficient for inter blocks +} IVIBandDesc; + + +/** + * color plane (luma or chroma) information + */ +typedef struct { + uint16_t width; + uint16_t height; + uint8_t num_bands; ///< number of bands this plane subdivided into + IVIBandDesc *bands; ///< array of band descriptors +} IVIPlaneDesc; + + +typedef struct { + uint16_t pic_width; + uint16_t pic_height; + uint16_t chroma_width; + uint16_t chroma_height; + uint16_t tile_width; + uint16_t tile_height; + uint8_t luma_bands; + uint8_t chroma_bands; +} IVIPicConfig; + +/** compares some properties of two pictures */ +static inline int ivi_pic_config_cmp(IVIPicConfig *str1, IVIPicConfig *str2) +{ + return (str1->pic_width != str2->pic_width || str1->pic_height != str2->pic_height || + str1->chroma_width != str2->chroma_width || str1->chroma_height != str2->chroma_height || + str1->tile_width != str2->tile_width || str1->tile_height != str2->tile_height || + str1->luma_bands != str2->luma_bands || str1->chroma_bands != str2->chroma_bands); +} + +/** calculate number of tiles in a stride */ +#define IVI_NUM_TILES(stride, tile_size) (((stride) + (tile_size) - 1) / (tile_size)) + +/** calculate number of macroblocks in a tile */ +#define IVI_MBs_PER_TILE(tile_width, tile_height, mb_size) \ + ((((tile_width) + (mb_size) - 1) / (mb_size)) * (((tile_height) + (mb_size) - 1) / (mb_size))) + +/** convert unsigned values into signed ones (the sign is in the LSB) */ +#define IVI_TOSIGNED(val) (-(((val) >> 1) ^ -((val) & 1))) + +/** scales motion vector */ +static inline int ivi_scale_mv(int mv, int mv_scale) +{ + return (mv + (mv > 0) + (mv_scale - 1)) >> mv_scale; +} + +/** + * Generates a huffman codebook from the given descriptor + * and converts it into the FFmpeg VLC table. + * + * @param cb [in] pointer to codebook descriptor + * @param vlc [out] where to place the generated VLC table + * @param flag [in] flag: 1 - for static or 0 for dynamic tables + * @return result code: 0 - OK, -1 = error (invalid codebook descriptor) + */ +int ff_ivi_create_huff_from_desc(const IVIHuffDesc *cb, VLC *vlc, int flag); + +/** + * Initializes static codes used for macroblock and block decoding. + */ +void ff_ivi_init_static_vlc(void); + +/** + * Decodes a huffman codebook descriptor from the bitstream + * and selects specified huffman table. + * + * @param gb [in,out] the GetBit context + * @param desc_coded [in] flag signalling if table descriptor was coded + * @param which_tab [in] codebook purpose (IVI_MB_HUFF or IVI_BLK_HUFF) + * @param huff_tab [out] pointer to the descriptor of the selected table + * @param avctx [in] AVCodecContext pointer + * @return zero on success, negative value otherwise + */ +int ff_ivi_dec_huff_desc(GetBitContext *gb, int desc_coded, int which_tab, + IVIHuffTab *huff_tab, AVCodecContext *avctx); + +/** + * Compares two huffman codebook descriptors. + * + * @param desc1 [in] ptr to the 1st descriptor to compare + * @param desc2 [in] ptr to the 2nd descriptor to compare + * @return comparison result: 0 - equal, 1 - not equal + */ +int ff_ivi_huff_desc_cmp(const IVIHuffDesc *desc1, const IVIHuffDesc *desc2); + +/** + * Copies huffman codebook descriptors. + * + * @param dst [out] ptr to the destination descriptor + * @param src [in] ptr to the source descriptor + */ +void ff_ivi_huff_desc_copy(IVIHuffDesc *dst, const IVIHuffDesc *src); + +/** + * Initializes planes (prepares descriptors, allocates buffers etc). + * + * @param planes [in,out] pointer to the array of the plane descriptors + * @param cfg [in] pointer to the ivi_pic_config structure describing picture layout + * @return result code: 0 - OK + */ +int ff_ivi_init_planes(IVIPlaneDesc *planes, const IVIPicConfig *cfg); + +/** + * Frees planes, bands and macroblocks buffers. + * + * @param planes [in] pointer to the array of the plane descriptors + */ +void ff_ivi_free_buffers(IVIPlaneDesc *planes); + +/** + * Initializes tile and macroblock descriptors. + * + * @param planes [in,out] pointer to the array of the plane descriptors + * @param tile_width [in] tile width + * @param tile_height [in] tile height + * @return result code: 0 - OK + */ +int ff_ivi_init_tiles(IVIPlaneDesc *planes, int tile_width, int tile_height); + +/** + * Decodes size of the tile data. + * The size is stored as a variable-length field having the following format: + * if (tile_data_size < 255) than this field is only one byte long + * if (tile_data_size >= 255) than this field four is byte long: 0xFF X1 X2 X3 + * where X1-X3 is size of the tile data + * + * @param gb [in,out] the GetBit context + * @return size of the tile data in bytes + */ +int ff_ivi_dec_tile_data_size(GetBitContext *gb); + +/** + * Decodes block data: + * extracts huffman-coded transform coefficients from the bitstream, + * dequantizes them, applies inverse transform and motion compensation + * in order to reconstruct the picture. + * + * @param gb [in,out] the GetBit context + * @param band [in] pointer to the band descriptor + * @param tile [in] pointer to the tile descriptor + * @return result code: 0 - OK, -1 = error (corrupted blocks data) + */ +int ff_ivi_decode_blocks(GetBitContext *gb, IVIBandDesc *band, IVITile *tile); + +/** + * Handles empty tiles by performing data copying and motion + * compensation respectively. + * + * @param avctx [in] ptr to the AVCodecContext + * @param band [in] pointer to the band descriptor + * @param tile [in] pointer to the tile descriptor + * @param mv_scale [in] scaling factor for motion vectors + */ +void ff_ivi_process_empty_tile(AVCodecContext *avctx, IVIBandDesc *band, + IVITile *tile, int32_t mv_scale); + +/** + * Converts and outputs the current plane. + * This conversion is done by adding back the bias value of 128 + * (subtracted in the encoder) and clipping the result. + * + * @param plane [in] pointer to the descriptor of the plane being processed + * @param dst [out] pointer to the buffer receiving converted pixels + * @param dst_pitch [in] pitch for moving to the next y line + */ +void ff_ivi_output_plane(IVIPlaneDesc *plane, uint8_t *dst, int dst_pitch); + +#if IVI_DEBUG +/** + * Calculates band checksum from band data. + */ +uint16_t ivi_calc_band_checksum (IVIBandDesc *band); + +/** + * Verifies that band data lies in range. + */ +int ivi_check_band (IVIBandDesc *band, const uint8_t *ref, int pitch); +#endif + +#endif /* AVCODEC_IVI_COMMON_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ivi_dsp.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/ivi_dsp.c new file mode 100644 index 0000000000..ccaffd45ce --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ivi_dsp.c @@ -0,0 +1,467 @@ +/* + * DSP functions for Indeo Video Interactive codecs (Indeo4 and Indeo5) + * + * Copyright (c) 2009 Maxim Poliakovski + * + * 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 + * DSP functions (inverse transforms, motion compensation, wavelet recompostions) + * for Indeo Video Interactive codecs. + */ + +#include "avcodec.h" +#include "dsputil.h" +#include "dwt.h" +#include "ivi_common.h" +#include "ivi_dsp.h" + +void ff_ivi_recompose53(const IVIPlaneDesc *plane, uint8_t *dst, + const int dst_pitch, const int num_bands) +{ + int x, y, indx; + int32_t p0, p1, p2, p3, tmp0, tmp1, tmp2; + int32_t b0_1, b0_2, b1_1, b1_2, b1_3, b2_1, b2_2, b2_3, b2_4, b2_5, b2_6; + int32_t b3_1, b3_2, b3_3, b3_4, b3_5, b3_6, b3_7, b3_8, b3_9; + int32_t pitch, back_pitch; + const IDWTELEM *b0_ptr, *b1_ptr, *b2_ptr, *b3_ptr; + + /* all bands should have the same pitch */ + pitch = plane->bands[0].pitch; + + /* pixels at the position "y-1" will be set to pixels at the "y" for the 1st iteration */ + back_pitch = 0; + + /* get pointers to the wavelet bands */ + b0_ptr = plane->bands[0].buf; + b1_ptr = plane->bands[1].buf; + b2_ptr = plane->bands[2].buf; + b3_ptr = plane->bands[3].buf; + + for (y = 0; y < plane->height; y += 2) { + /* load storage variables with values */ + if (num_bands > 0) { + b0_1 = b0_ptr[0]; + b0_2 = b0_ptr[pitch]; + } + + if (num_bands > 1) { + b1_1 = b1_ptr[back_pitch]; + b1_2 = b1_ptr[0]; + b1_3 = b1_1 - b1_2*6 + b1_ptr[pitch]; + } + + if (num_bands > 2) { + b2_2 = b2_ptr[0]; // b2[x, y ] + b2_3 = b2_2; // b2[x+1,y ] = b2[x,y] + b2_5 = b2_ptr[pitch]; // b2[x ,y+1] + b2_6 = b2_5; // b2[x+1,y+1] = b2[x,y+1] + } + + if (num_bands > 3) { + b3_2 = b3_ptr[back_pitch]; // b3[x ,y-1] + b3_3 = b3_2; // b3[x+1,y-1] = b3[x ,y-1] + b3_5 = b3_ptr[0]; // b3[x ,y ] + b3_6 = b3_5; // b3[x+1,y ] = b3[x ,y ] + b3_8 = b3_2 - b3_5*6 + b3_ptr[pitch]; + b3_9 = b3_8; + } + + for (x = 0, indx = 0; x < plane->width; x+=2, indx++) { + /* some values calculated in the previous iterations can */ + /* be reused in the next ones, so do appropriate copying */ + b2_1 = b2_2; // b2[x-1,y ] = b2[x, y ] + b2_2 = b2_3; // b2[x ,y ] = b2[x+1,y ] + b2_4 = b2_5; // b2[x-1,y+1] = b2[x ,y+1] + b2_5 = b2_6; // b2[x ,y+1] = b2[x+1,y+1] + b3_1 = b3_2; // b3[x-1,y-1] = b3[x ,y-1] + b3_2 = b3_3; // b3[x ,y-1] = b3[x+1,y-1] + b3_4 = b3_5; // b3[x-1,y ] = b3[x ,y ] + b3_5 = b3_6; // b3[x ,y ] = b3[x+1,y ] + b3_7 = b3_8; // vert_HPF(x-1) + b3_8 = b3_9; // vert_HPF(x ) + + p0 = p1 = p2 = p3 = 0; + + /* process the LL-band by applying LPF both vertically and horizontally */ + if (num_bands > 0) { + tmp0 = b0_1; + tmp2 = b0_2; + b0_1 = b0_ptr[indx+1]; + b0_2 = b0_ptr[pitch+indx+1]; + tmp1 = tmp0 + b0_1; + + p0 = tmp0 << 4; + p1 = tmp1 << 3; + p2 = (tmp0 + tmp2) << 3; + p3 = (tmp1 + tmp2 + b0_2) << 2; + } + + /* process the HL-band by applying HPF vertically and LPF horizontally */ + if (num_bands > 1) { + tmp0 = b1_2; + tmp1 = b1_1; + b1_2 = b1_ptr[indx+1]; + b1_1 = b1_ptr[back_pitch+indx+1]; + + tmp2 = tmp1 - tmp0*6 + b1_3; + b1_3 = b1_1 - b1_2*6 + b1_ptr[pitch+indx+1]; + + p0 += (tmp0 + tmp1) << 3; + p1 += (tmp0 + tmp1 + b1_1 + b1_2) << 2; + p2 += tmp2 << 2; + p3 += (tmp2 + b1_3) << 1; + } + + /* process the LH-band by applying LPF vertically and HPF horizontally */ + if (num_bands > 2) { + b2_3 = b2_ptr[indx+1]; + b2_6 = b2_ptr[pitch+indx+1]; + + tmp0 = b2_1 + b2_2; + tmp1 = b2_1 - b2_2*6 + b2_3; + + p0 += tmp0 << 3; + p1 += tmp1 << 2; + p2 += (tmp0 + b2_4 + b2_5) << 2; + p3 += (tmp1 + b2_4 - b2_5*6 + b2_6) << 1; + } + + /* process the HH-band by applying HPF both vertically and horizontally */ + if (num_bands > 3) { + b3_6 = b3_ptr[indx+1]; // b3[x+1,y ] + b3_3 = b3_ptr[back_pitch+indx+1]; // b3[x+1,y-1] + + tmp0 = b3_1 + b3_4; + tmp1 = b3_2 + b3_5; + tmp2 = b3_3 + b3_6; + + b3_9 = b3_3 - b3_6*6 + b3_ptr[pitch+indx+1]; + + p0 += (tmp0 + tmp1) << 2; + p1 += (tmp0 - tmp1*6 + tmp2) << 1; + p2 += (b3_7 + b3_8) << 1; + p3 += b3_7 - b3_8*6 + b3_9; + } + + /* output four pixels */ + dst[x] = av_clip_uint8((p0 >> 6) + 128); + dst[x+1] = av_clip_uint8((p1 >> 6) + 128); + dst[dst_pitch+x] = av_clip_uint8((p2 >> 6) + 128); + dst[dst_pitch+x+1] = av_clip_uint8((p3 >> 6) + 128); + }// for x + + dst += dst_pitch << 1; + + back_pitch = -pitch; + + b0_ptr += pitch; + b1_ptr += pitch; + b2_ptr += pitch; + b3_ptr += pitch; + } +} + +/** butterfly operation for the inverse slant transform */ +#define IVI_SLANT_BFLY(s1, s2, o1, o2, t) \ + t = s1 - s2;\ + o1 = s1 + s2;\ + o2 = t;\ + +/** This is a reflection a,b = 1/2, 5/4 for the inverse slant transform */ +#define IVI_IREFLECT(s1, s2, o1, o2, t) \ + t = ((s1 + s2*2 + 2) >> 2) + s1;\ + o2 = ((s1*2 - s2 + 2) >> 2) - s2;\ + o1 = t;\ + +/** This is a reflection a,b = 1/2, 7/8 for the inverse slant transform */ +#define IVI_SLANT_PART4(s1, s2, o1, o2, t) \ + t = s2 + ((s1*4 - s2 + 4) >> 3);\ + o2 = s1 + ((-s1 - s2*4 + 4) >> 3);\ + o1 = t;\ + +/** inverse slant8 transform */ +#define IVI_INV_SLANT8(s1, s4, s8, s5, s2, s6, s3, s7,\ + d1, d2, d3, d4, d5, d6, d7, d8,\ + t0, t1, t2, t3, t4, t5, t6, t7, t8) {\ + IVI_SLANT_PART4(s4, s5, t4, t5, t0);\ +\ + IVI_SLANT_BFLY(s1, t5, t1, t5, t0); IVI_SLANT_BFLY(s2, s6, t2, t6, t0);\ + IVI_SLANT_BFLY(s7, s3, t7, t3, t0); IVI_SLANT_BFLY(t4, s8, t4, t8, t0);\ +\ + IVI_SLANT_BFLY(t1, t2, t1, t2, t0); IVI_IREFLECT (t4, t3, t4, t3, t0);\ + IVI_SLANT_BFLY(t5, t6, t5, t6, t0); IVI_IREFLECT (t8, t7, t8, t7, t0);\ + IVI_SLANT_BFLY(t1, t4, t1, t4, t0); IVI_SLANT_BFLY(t2, t3, t2, t3, t0);\ + IVI_SLANT_BFLY(t5, t8, t5, t8, t0); IVI_SLANT_BFLY(t6, t7, t6, t7, t0);\ + d1 = COMPENSATE(t1);\ + d2 = COMPENSATE(t2);\ + d3 = COMPENSATE(t3);\ + d4 = COMPENSATE(t4);\ + d5 = COMPENSATE(t5);\ + d6 = COMPENSATE(t6);\ + d7 = COMPENSATE(t7);\ + d8 = COMPENSATE(t8);} + +/** inverse slant4 transform */ +#define IVI_INV_SLANT4(s1, s4, s2, s3, d1, d2, d3, d4, t0, t1, t2, t3, t4) {\ + IVI_SLANT_BFLY(s1, s2, t1, t2, t0); IVI_IREFLECT (s4, s3, t4, t3, t0);\ +\ + IVI_SLANT_BFLY(t1, t4, t1, t4, t0); IVI_SLANT_BFLY(t2, t3, t2, t3, t0);\ + d1 = COMPENSATE(t1);\ + d2 = COMPENSATE(t2);\ + d3 = COMPENSATE(t3);\ + d4 = COMPENSATE(t4);} + +void ff_ivi_inverse_slant_8x8(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags) +{ + int i; + const int32_t *src; + int32_t *dst; + int tmp[64]; + int t0, t1, t2, t3, t4, t5, t6, t7, t8; + +#define COMPENSATE(x) (x) + src = in; + dst = tmp; + for (i = 0; i < 8; i++) { + if (flags[i]) { + IVI_INV_SLANT8(src[0], src[8], src[16], src[24], src[32], src[40], src[48], src[56], + dst[0], dst[8], dst[16], dst[24], dst[32], dst[40], dst[48], dst[56], + t0, t1, t2, t3, t4, t5, t6, t7, t8); + } else + dst[0] = dst[8] = dst[16] = dst[24] = dst[32] = dst[40] = dst[48] = dst[56] = 0; + + src++; + dst++; + } +#undef COMPENSATE + +#define COMPENSATE(x) ((x + 1)>>1) + src = tmp; + for (i = 0; i < 8; i++) { + if (!src[0] && !src[1] && !src[2] && !src[3] && !src[4] && !src[5] && !src[6] && !src[7]) { + memset(out, 0, 8*sizeof(out[0])); + } else { + IVI_INV_SLANT8(src[0], src[1], src[2], src[3], src[4], src[5], src[6], src[7], + out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7], + t0, t1, t2, t3, t4, t5, t6, t7, t8); + } + src += 8; + out += pitch; + } +#undef COMPENSATE +} + +void ff_ivi_inverse_slant_4x4(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags) +{ + int i; + const int32_t *src; + int32_t *dst; + int tmp[16]; + int t0, t1, t2, t3, t4; + +#define COMPENSATE(x) (x) + src = in; + dst = tmp; + for (i = 0; i < 4; i++) { + if (flags[i]) { + IVI_INV_SLANT4(src[0], src[4], src[8], src[12], + dst[0], dst[4], dst[8], dst[12], + t0, t1, t2, t3, t4); + } else + dst[0] = dst[4] = dst[8] = dst[12] = 0; + + src++; + dst++; + } +#undef COMPENSATE + +#define COMPENSATE(x) ((x + 1)>>1) + src = tmp; + for (i = 0; i < 4; i++) { + if (!src[0] && !src[1] && !src[2] && !src[3]) { + out[0] = out[1] = out[2] = out[3] = 0; + } else { + IVI_INV_SLANT4(src[0], src[1], src[2], src[3], + out[0], out[1], out[2], out[3], + t0, t1, t2, t3, t4); + } + src += 4; + out += pitch; + } +#undef COMPENSATE +} + +void ff_ivi_dc_slant_2d(const int32_t *in, int16_t *out, uint32_t pitch, int blk_size) +{ + int x, y; + int16_t dc_coeff; + + dc_coeff = (*in + 1) >> 1; + + for (y = 0; y < blk_size; out += pitch, y++) { + for (x = 0; x < blk_size; x++) + out[x] = dc_coeff; + } +} + +void ff_ivi_row_slant8(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags) +{ + int i; + int t0, t1, t2, t3, t4, t5, t6, t7, t8; + +#define COMPENSATE(x) ((x + 1)>>1) + for (i = 0; i < 8; i++) { + if (!in[0] && !in[1] && !in[2] && !in[3] && !in[4] && !in[5] && !in[6] && !in[7]) { + memset(out, 0, 8*sizeof(out[0])); + } else { + IVI_INV_SLANT8( in[0], in[1], in[2], in[3], in[4], in[5], in[6], in[7], + out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7], + t0, t1, t2, t3, t4, t5, t6, t7, t8); + } + in += 8; + out += pitch; + } +#undef COMPENSATE +} + +void ff_ivi_dc_row_slant(const int32_t *in, int16_t *out, uint32_t pitch, int blk_size) +{ + int x, y; + int16_t dc_coeff; + + dc_coeff = (*in + 1) >> 1; + + for (x = 0; x < blk_size; x++) + out[x] = dc_coeff; + + out += pitch; + + for (y = 1; y < blk_size; out += pitch, y++) { + for (x = 0; x < blk_size; x++) + out[x] = 0; + } +} + +void ff_ivi_col_slant8(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags) +{ + int i, row2, row4, row8; + int t0, t1, t2, t3, t4, t5, t6, t7, t8; + + row2 = pitch << 1; + row4 = pitch << 2; + row8 = pitch << 3; + +#define COMPENSATE(x) ((x + 1)>>1) + for (i = 0; i < 8; i++) { + if (flags[i]) { + IVI_INV_SLANT8(in[0], in[8], in[16], in[24], in[32], in[40], in[48], in[56], + out[0], out[pitch], out[row2], out[row2 + pitch], out[row4], + out[row4 + pitch], out[row4 + row2], out[row8 - pitch], + t0, t1, t2, t3, t4, t5, t6, t7, t8); + } else { + out[0] = out[pitch] = out[row2] = out[row2 + pitch] = out[row4] = + out[row4 + pitch] = out[row4 + row2] = out[row8 - pitch] = 0; + } + + in++; + out++; + } +#undef COMPENSATE +} + +void ff_ivi_dc_col_slant(const int32_t *in, int16_t *out, uint32_t pitch, int blk_size) +{ + int x, y; + int16_t dc_coeff; + + dc_coeff = (*in + 1) >> 1; + + for (y = 0; y < blk_size; out += pitch, y++) { + out[0] = dc_coeff; + for (x = 1; x < blk_size; x++) + out[x] = 0; + } +} + +void ff_ivi_put_pixels_8x8(const int32_t *in, int16_t *out, uint32_t pitch, + const uint8_t *flags) +{ + int x, y; + + for (y = 0; y < 8; out += pitch, in += 8, y++) + for (x = 0; x < 8; x++) + out[x] = in[x]; +} + +void ff_ivi_put_dc_pixel_8x8(const int32_t *in, int16_t *out, uint32_t pitch, + int blk_size) +{ + int y; + + out[0] = in[0]; + memset(out + 1, 0, 7*sizeof(out[0])); + out += pitch; + + for (y = 1; y < 8; out += pitch, y++) + memset(out, 0, 8*sizeof(out[0])); +} + +#define IVI_MC_TEMPLATE(size, suffix, OP) \ +void ff_ivi_mc_ ## size ##x## size ## suffix (int16_t *buf, const int16_t *ref_buf, \ + uint32_t pitch, int mc_type) \ +{ \ + int i, j; \ + const int16_t *wptr; \ +\ + switch (mc_type) { \ + case 0: /* fullpel (no interpolation) */ \ + for (i = 0; i < size; i++, buf += pitch, ref_buf += pitch) { \ + for (j = 0; j < size; j++) {\ + OP(buf[j], ref_buf[j]); \ + } \ + } \ + break; \ + case 1: /* horizontal halfpel interpolation */ \ + for (i = 0; i < size; i++, buf += pitch, ref_buf += pitch) \ + for (j = 0; j < size; j++) \ + OP(buf[j], (ref_buf[j] + ref_buf[j+1]) >> 1); \ + break; \ + case 2: /* vertical halfpel interpolation */ \ + wptr = ref_buf + pitch; \ + for (i = 0; i < size; i++, buf += pitch, wptr += pitch, ref_buf += pitch) \ + for (j = 0; j < size; j++) \ + OP(buf[j], (ref_buf[j] + wptr[j]) >> 1); \ + break; \ + case 3: /* vertical and horizontal halfpel interpolation */ \ + wptr = ref_buf + pitch; \ + for (i = 0; i < size; i++, buf += pitch, wptr += pitch, ref_buf += pitch) \ + for (j = 0; j < size; j++) \ + OP(buf[j], (ref_buf[j] + ref_buf[j+1] + wptr[j] + wptr[j+1]) >> 2); \ + break; \ + } \ +} \ + +#define OP_PUT(a, b) (a) = (b) +#define OP_ADD(a, b) (a) += (b) + +IVI_MC_TEMPLATE(8, _no_delta, OP_PUT); +IVI_MC_TEMPLATE(8, _delta, OP_ADD); +IVI_MC_TEMPLATE(4, _no_delta, OP_PUT); +IVI_MC_TEMPLATE(4, _delta, OP_ADD); diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ivi_dsp.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/ivi_dsp.h new file mode 100644 index 0000000000..bdd9654c79 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ivi_dsp.h @@ -0,0 +1,170 @@ +/* + * DSP functions for Indeo Video Interactive codecs (Indeo4 and Indeo5) + * + * Copyright (c) 2009 Maxim Poliakovski + * + * 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 + * DSP functions (inverse transforms, motion compensations, wavelet recompostion) + * for Indeo Video Interactive codecs. + */ + +#ifndef AVCODEC_IVI_DSP_H +#define AVCODEC_IVI_DSP_H + +#include "avcodec.h" +#include "ivi_common.h" + +/** + * 5/3 wavelet recomposition filter for Indeo5 + * + * @param plane [in] pointer to the descriptor of the plane being processed + * @param dst [out] pointer to the destination buffer + * @param dst_pitch [in] pitch of the destination buffer + * @param num_bands [in] number of wavelet bands to be processed + */ +void ff_ivi_recompose53(const IVIPlaneDesc *plane, uint8_t *dst, + const int dst_pitch, const int num_bands); + +/** + * two-dimensional inverse slant 8x8 transform + * + * @param in [in] pointer to the vector of transform coefficients + * @param out [out] pointer to the output buffer (frame) + * @param pitch [in] pitch to move to the next y line + * @param flags [in] pointer to the array of column flags: + * != 0 - non_empty column, 0 - empty one + * (this array must be filled by caller) + */ +void ff_ivi_inverse_slant_8x8(const int32_t *in, int16_t *out, uint32_t pitch, + const uint8_t *flags); + +/** + * two-dimensional inverse slant 4x4 transform + * + * @param in [in] pointer to the vector of transform coefficients + * @param out [out] pointer to the output buffer (frame) + * @param pitch [in] pitch to move to the next y line + * @param flags [in] pointer to the array of column flags: + * != 0 - non_empty column, 0 - empty one + * (this array must be filled by caller) + */ +void ff_ivi_inverse_slant_4x4(const int32_t *in, int16_t *out, uint32_t pitch, + const uint8_t *flags); + +/** + * DC-only two-dimensional inverse slant transform. + * Performing the inverse slant transform in this case is equivalent to + * spreading (DC_coeff + 1)/2 over the whole block. + * It works much faster than performing the slant transform on a vector of zeroes. + * + * @param in [in] pointer to the dc coefficient + * @param out [out] pointer to the output buffer (frame) + * @param pitch [in] pitch to move to the next y line + * @param blk_size [in] transform block size + */ +void ff_ivi_dc_slant_2d(const int32_t *in, int16_t *out, uint32_t pitch, int blk_size); + +/** + * inverse 1D row slant transform + * + * @param in [in] pointer to the vector of transform coefficients + * @param out [out] pointer to the output buffer (frame) + * @param pitch [in] pitch to move to the next y line + * @param flags [in] pointer to the array of column flags (unused here) + */ +void ff_ivi_row_slant8(const int32_t *in, int16_t *out, uint32_t pitch, + const uint8_t *flags); + +/** + * inverse 1D column slant transform + * + * @param in [in] pointer to the vector of transform coefficients + * @param out [out] pointer to the output buffer (frame) + * @param pitch [in] pitch to move to the next y line + * @param flags [in] pointer to the array of column flags: + * != 0 - non_empty column, 0 - empty one + * (this array must be filled by caller) + */ +void ff_ivi_col_slant8(const int32_t *in, int16_t *out, uint32_t pitch, + const uint8_t *flags); + +/** + * DC-only inverse row slant transform + */ +void ff_ivi_dc_row_slant(const int32_t *in, int16_t *out, uint32_t pitch, int blk_size); + +/** + * DC-only inverse column slant transform + */ +void ff_ivi_dc_col_slant(const int32_t *in, int16_t *out, uint32_t pitch, int blk_size); + +/** + * Copies the pixels into the frame buffer. + */ +void ff_ivi_put_pixels_8x8(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags); + +/** + * Copies the DC coefficient into the first pixel of the block and + * zeroes all others. + */ +void ff_ivi_put_dc_pixel_8x8(const int32_t *in, int16_t *out, uint32_t pitch, int blk_size); + +/** + * 8x8 block motion compensation with adding delta + * + * @param buf [in,out] pointer to the block in the current frame buffer containing delta + * @param ref_buf [in] pointer to the corresponding block in the reference frame + * @param pitch [in] pitch for moving to the next y line + * @param mc_type [in] interpolation type + */ +void ff_ivi_mc_8x8_delta(int16_t *buf, const int16_t *ref_buf, uint32_t pitch, int mc_type); + +/** + * 4x4 block motion compensation with adding delta + * + * @param buf [in,out] pointer to the block in the current frame buffer containing delta + * @param ref_buf [in] pointer to the corresponding block in the reference frame + * @param pitch [in] pitch for moving to the next y line + * @param mc_type [in] interpolation type + */ +void ff_ivi_mc_4x4_delta(int16_t *buf, const int16_t *ref_buf, uint32_t pitch, int mc_type); + +/** + * motion compensation without adding delta + * + * @param buf [in,out] pointer to the block in the current frame receiving the result + * @param ref_buf [in] pointer to the corresponding block in the reference frame + * @param pitch [in] pitch for moving to the next y line + * @param mc_type [in] interpolation type + */ +void ff_ivi_mc_8x8_no_delta(int16_t *buf, const int16_t *ref_buf, uint32_t pitch, int mc_type); + +/** + * 4x4 block motion compensation without adding delta + * + * @param buf [in,out] pointer to the block in the current frame receiving the result + * @param ref_buf [in] pointer to the corresponding block in the reference frame + * @param pitch [in] pitch for moving to the next y line + * @param mc_type [in] interpolation type + */ +void ff_ivi_mc_4x4_no_delta(int16_t *buf, const int16_t *ref_buf, uint32_t pitch, int mc_type); + +#endif /* AVCODEC_IVI_DSP_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/jfdctfst.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/jfdctfst.c index dcbe19e69d..b911909ec3 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/jfdctfst.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/jfdctfst.c @@ -64,7 +64,7 @@ */ /** - * @file libavcodec/jfdctfst.c + * @file * Independent JPEG Group's fast AAN dct. */ @@ -76,7 +76,6 @@ #define DCTSIZE 8 #define GLOBAL(x) x #define RIGHT_SHIFT(x, n) ((x) >> (n)) -#define SHIFT_TEMPS /* * This module is specialized to the case DCTSIZE = 8. @@ -151,7 +150,6 @@ static av_always_inline void row_fdct(DCTELEM * data){ int_fast16_t z1, z2, z3, z4, z5, z11, z13; DCTELEM *dataptr; int ctr; - SHIFT_TEMPS /* Pass 1: process rows. */ @@ -216,7 +214,6 @@ fdct_ifast (DCTELEM * data) int_fast16_t z1, z2, z3, z4, z5, z11, z13; DCTELEM *dataptr; int ctr; - SHIFT_TEMPS row_fdct(data); @@ -283,7 +280,6 @@ fdct_ifast248 (DCTELEM * data) int_fast16_t z1; DCTELEM *dataptr; int ctr; - SHIFT_TEMPS row_fdct(data); diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/jfdctint.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/jfdctint.c index b27657b0df..f6e8c4e939 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/jfdctint.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/jfdctint.c @@ -57,7 +57,7 @@ */ /** - * @file libavcodec/jfdctint.c + * @file * Independent JPEG Group's slow & accurate dct. */ @@ -66,7 +66,6 @@ #include "libavutil/common.h" #include "dsputil.h" -#define SHIFT_TEMPS #define DCTSIZE 8 #define BITS_IN_JSAMPLE 8 #define GLOBAL(x) x @@ -187,7 +186,6 @@ static av_always_inline void row_fdct(DCTELEM * data){ int_fast32_t z1, z2, z3, z4, z5; DCTELEM *dataptr; int ctr; - SHIFT_TEMPS /* Pass 1: process rows. */ /* Note results are scaled up by sqrt(8) compared to a true DCT; */ @@ -266,7 +264,6 @@ ff_jpeg_fdct_islow (DCTELEM * data) int_fast32_t z1, z2, z3, z4, z5; DCTELEM *dataptr; int ctr; - SHIFT_TEMPS row_fdct(data); @@ -353,7 +350,6 @@ ff_fdct248_islow (DCTELEM * data) int_fast32_t z1; DCTELEM *dataptr; int ctr; - SHIFT_TEMPS row_fdct(data); diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/jpegls.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/jpegls.c index ff429e5afe..c40b929e95 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/jpegls.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/jpegls.c @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/jpegls.c + * @file * JPEG-LS common code. */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/jpegls.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/jpegls.h index 6ce1b92ddf..28c75248be 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/jpegls.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/jpegls.h @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/jpegls.h + * @file * JPEG-LS common code. */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/jpeglsdec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/jpeglsdec.c index bc80d13d68..6b7dd94647 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/jpeglsdec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/jpeglsdec.c @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/jpeglsdec.c + * @file * JPEG-LS decoder. */ @@ -365,7 +365,7 @@ int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near, int point_transfor AVCodec jpegls_decoder = { "jpegls", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_JPEGLS, sizeof(MJpegDecodeContext), ff_mjpeg_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/jpeglsdec.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/jpeglsdec.h index 080aa3d12d..5204ecb205 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/jpeglsdec.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/jpeglsdec.h @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/jpeglsdec.h + * @file * JPEG-LS decoder. */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/jpeglsenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/jpeglsenc.c index 4224a24633..08ef71f716 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/jpeglsenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/jpeglsenc.c @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/jpeglsenc.c + * @file * JPEG-LS encoder. */ @@ -384,12 +384,12 @@ static av_cold int encode_init_ls(AVCodecContext *ctx) { AVCodec jpegls_encoder = { //FIXME avoid MPV_* lossless JPEG should not need them "jpegls", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_JPEGLS, sizeof(JpeglsContext), encode_init_ls, encode_picture_ls, NULL, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_BGR24, PIX_FMT_RGB24, PIX_FMT_GRAY8, PIX_FMT_GRAY16, PIX_FMT_NONE}, + .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/src/add-ons/media/plugins/ffmpeg/libavcodec/jrevdct.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/jrevdct.c index 3096b0b2eb..9e28daeae6 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/jrevdct.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/jrevdct.c @@ -60,7 +60,7 @@ */ /** - * @file libavcodec/jrevdct.c + * @file * Independent JPEG Group's LLM idct. */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/kgv1dec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/kgv1dec.c new file mode 100644 index 0000000000..5af6b3b2bb --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/kgv1dec.c @@ -0,0 +1,176 @@ +/* + * Kega Game Video (KGV1) decoder + * Copyright (c) 2010 Daniel Verkamp + * + * 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 + * Kega Game Video decoder + */ + +#include "libavutil/intreadwrite.h" +#include "avcodec.h" + +typedef struct { + AVCodecContext *avctx; + AVFrame pic; + uint16_t *prev, *cur; +} KgvContext; + +static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) +{ + const uint8_t *buf = avpkt->data; + const uint8_t *buf_end = buf + avpkt->size; + KgvContext * const c = avctx->priv_data; + int offsets[7]; + uint16_t *out, *prev; + int outcnt = 0, maxcnt; + int w, h, i; + + if (avpkt->size < 2) + return -1; + + w = (buf[0] + 1) * 8; + h = (buf[1] + 1) * 8; + buf += 2; + + if (avcodec_check_dimensions(avctx, w, h)) + return -1; + + if (w != avctx->width || h != avctx->height) + avcodec_set_dimensions(avctx, w, h); + + maxcnt = w * h; + + out = av_realloc(c->cur, w * h * 2); + if (!out) + return -1; + c->cur = out; + + prev = av_realloc(c->prev, w * h * 2); + if (!prev) + return -1; + c->prev = prev; + + for (i = 0; i < 7; i++) + offsets[i] = -1; + + while (outcnt < maxcnt && buf_end - 2 > buf) { + int code = AV_RL16(buf); + buf += 2; + + if (!(code & 0x8000)) { + out[outcnt++] = code; // rgb555 pixel coded directly + } else { + int count; + uint16_t *inp; + + if ((code & 0x6000) == 0x6000) { + // copy from previous frame + int oidx = (code >> 10) & 7; + int start; + + count = (code & 0x3FF) + 3; + + if (offsets[oidx] < 0) { + if (buf_end - 3 < buf) + break; + offsets[oidx] = AV_RL24(buf); + buf += 3; + } + + start = (outcnt + offsets[oidx]) % maxcnt; + + if (maxcnt - start < count) + break; + + inp = prev + start; + } else { + // copy from earlier in this frame + int offset = (code & 0x1FFF) + 1; + + if (!(code & 0x6000)) { + count = 2; + } else if ((code & 0x6000) == 0x2000) { + count = 3; + } else { + if (buf_end - 1 < buf) + break; + count = 4 + *buf++; + } + + if (outcnt < offset) + break; + + inp = out + outcnt - offset; + } + + if (maxcnt - outcnt < count) + break; + + for (i = 0; i < count; i++) + out[outcnt++] = inp[i]; + } + } + + if (outcnt - maxcnt) + av_log(avctx, AV_LOG_DEBUG, "frame finished with %d diff\n", outcnt - maxcnt); + + c->pic.data[0] = (uint8_t *)c->cur; + c->pic.linesize[0] = w * 2; + + *data_size = sizeof(AVFrame); + *(AVFrame*)data = c->pic; + + FFSWAP(uint16_t *, c->cur, c->prev); + + return avpkt->size; +} + +static av_cold int decode_init(AVCodecContext *avctx) +{ + KgvContext * const c = avctx->priv_data; + + c->avctx = avctx; + avctx->pix_fmt = PIX_FMT_RGB555; + + return 0; +} + +static av_cold int decode_end(AVCodecContext *avctx) +{ + KgvContext * const c = avctx->priv_data; + + av_freep(&c->cur); + av_freep(&c->prev); + + return 0; +} + +AVCodec kgv1_decoder = { + "kgv1", + AVMEDIA_TYPE_VIDEO, + CODEC_ID_KGV1, + sizeof(KgvContext), + decode_init, + NULL, + decode_end, + decode_frame, + .long_name = NULL_IF_CONFIG_SMALL("Kega Game Video"), +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/kmvc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/kmvc.c index f4b54a138f..3e8dccd363 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/kmvc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/kmvc.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/kmvc.c + * @file * Karl Morton's Video Codec decoder */ @@ -403,7 +403,7 @@ static av_cold int decode_end(AVCodecContext * avctx) AVCodec kmvc_decoder = { "kmvc", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_KMVC, sizeof(KmvcContext), decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/lcldec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/lcldec.c index 15c686e0a9..2bf448a775 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/lcldec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/lcldec.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/lcldec.c + * @file * LCL (LossLess Codec Library) Video Codec * Decoder for MSZH and ZLIB codecs * Experimental encoder for ZLIB RGB24 @@ -458,10 +458,6 @@ static av_cold int decode_init(AVCodecContext *avctx) return 1; } - if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) { - return 1; - } - /* Check codec type */ if ((avctx->codec_id == CODEC_ID_MSZH && avctx->extradata[7] != CODEC_MSZH) || (avctx->codec_id == CODEC_ID_ZLIB && avctx->extradata[7] != CODEC_ZLIB)) { @@ -615,7 +611,7 @@ static av_cold int decode_end(AVCodecContext *avctx) #if CONFIG_MSZH_DECODER AVCodec mszh_decoder = { "mszh", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_MSZH, sizeof(LclDecContext), decode_init, @@ -630,7 +626,7 @@ AVCodec mszh_decoder = { #if CONFIG_ZLIB_DECODER AVCodec zlib_decoder = { "zlib", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_ZLIB, sizeof(LclDecContext), decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/lclenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/lclenc.c index 4c43916fd1..8d7c5bf4e6 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/lclenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/lclenc.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/lclenc.c + * @file * LCL (LossLess Codec Library) Video Codec * Decoder for MSZH and ZLIB codecs * Experimental encoder for ZLIB RGB24 @@ -180,7 +180,7 @@ static av_cold int encode_end(AVCodecContext *avctx) AVCodec zlib_encoder = { "zlib", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_ZLIB, sizeof(LclEncContext), encode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/libdirac.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/libdirac.h index 93e75d2dc6..0dc19ca338 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/libdirac.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/libdirac.h @@ -19,7 +19,7 @@ */ /** -* @file libavcodec/libdirac.h +* @file * data structures common to libdiracenc.c and libdiracdec.c */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/libdirac_libschro.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/libdirac_libschro.c index 115cc49965..aee185885e 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/libdirac_libschro.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/libdirac_libschro.c @@ -19,7 +19,7 @@ */ /** -* @file libavcodec/libdirac_libschro.c +* @file * functions common to libdirac and libschroedinger */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/libdirac_libschro.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/libdirac_libschro.h index 2d47a0c406..3d63f977cf 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/libdirac_libschro.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/libdirac_libschro.h @@ -19,7 +19,7 @@ */ /** -* @file libavcodec/libdirac_libschro.h +* @file * data structures common to libdirac and libschroedinger */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/libdiracdec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/libdiracdec.c index b403094198..d24d3baf99 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/libdiracdec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/libdiracdec.c @@ -21,7 +21,7 @@ */ /** -* @file libavcodec/libdiracdec.c +* @file * Dirac decoder support via libdirac library; more details about the Dirac * project can be found at http://dirac.sourceforge.net/. * The libdirac_decoder library implements Dirac specification version 2.2 @@ -195,7 +195,7 @@ static void libdirac_flush(AVCodecContext *avccontext) AVCodec libdirac_decoder = { "libdirac", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_DIRAC, sizeof(FfmpegDiracDecoderParams), libdirac_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/libdiracenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/libdiracenc.c index 3fd3ed2cb9..d390aa8a7b 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/libdiracenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/libdiracenc.c @@ -21,7 +21,7 @@ */ /** -* @file libavcodec/libdiracenc.c +* @file * Dirac encoding support via libdirac library; more details about the * Dirac project can be found at http://dirac.sourceforge.net/. * The libdirac_encoder library implements Dirac specification version 2.2 @@ -393,13 +393,13 @@ static av_cold int libdirac_encode_close(AVCodecContext *avccontext) AVCodec libdirac_encoder = { "libdirac", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_DIRAC, sizeof(FfmpegDiracEncoderParams), libdirac_encode_init, libdirac_encode_frame, libdirac_encode_close, .capabilities = CODEC_CAP_DELAY, - .pix_fmts = (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_YUV444P, PIX_FMT_NONE}, + .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/src/add-ons/media/plugins/ffmpeg/libavcodec/libfaac.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/libfaac.c index cd4d38f5eb..82fd05bafd 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/libfaac.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/libfaac.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/libfaac.c + * @file * Interface to libfaac for aac encoding. */ @@ -147,12 +147,12 @@ static av_cold int Faac_encode_close(AVCodecContext *avctx) AVCodec libfaac_encoder = { "libfaac", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_AAC, sizeof(FaacAudioContext), Faac_encode_init, Faac_encode_frame, Faac_encode_close, - .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, + .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, .long_name = NULL_IF_CONFIG_SMALL("libfaac AAC (Advanced Audio Codec)"), }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/libfaad.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/libfaad.c index 953c2a1ed2..679729ad2c 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/libfaad.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/libfaad.c @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/libfaad.c + * @file * AAC decoder. * * still a bit unfinished - but it plays something @@ -183,7 +183,7 @@ static int faac_decode_frame(AVCodecContext *avctx, unsigned char channels; int r = s->faacDecInit(s->faac_handle, buf, buf_size, &srate, &channels); if(r < 0){ - av_log(avctx, AV_LOG_ERROR, "faac: codec init failed.\n"); + av_log(avctx, AV_LOG_ERROR, "libfaad: codec init failed.\n"); return -1; } avctx->sample_rate = srate; @@ -195,7 +195,7 @@ static int faac_decode_frame(AVCodecContext *avctx, out = s->faacDecDecode(s->faac_handle, &frame_info, (unsigned char*)buf, (unsigned long)buf_size); if (frame_info.error > 0) { - av_log(avctx, AV_LOG_ERROR, "faac: frame decoding failed: %s\n", + av_log(avctx, AV_LOG_ERROR, "libfaad: frame decoding failed: %s\n", s->faacDecGetErrorMessage(frame_info.error)); return -1; } @@ -322,7 +322,7 @@ static av_cold int faac_decode_init(AVCodecContext *avctx) AVCodec libfaad_decoder = { "libfaad", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_AAC, sizeof(FAACContext), faac_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/libgsm.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/libgsm.c index 7dc2af8405..1062099a7a 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/libgsm.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/libgsm.c @@ -21,14 +21,14 @@ */ /** - * @file libavcodec/libgsm.c + * @file * Interface to libgsm for gsm encoding/decoding */ // The idiosyncrasies of GSM-in-WAV are explained at http://kbs.cs.tu-berlin.de/~jutta/toast.html #include "avcodec.h" -#include +#include // gsm.h misses some essential constants #define GSM_BLOCK_SIZE 33 @@ -114,25 +114,25 @@ static int libgsm_encode_frame(AVCodecContext *avctx, AVCodec libgsm_encoder = { "libgsm", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_GSM, 0, libgsm_init, libgsm_encode_frame, libgsm_close, - .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, + .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, .long_name = NULL_IF_CONFIG_SMALL("libgsm GSM"), }; AVCodec libgsm_ms_encoder = { "libgsm_ms", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_GSM_MS, 0, libgsm_init, libgsm_encode_frame, libgsm_close, - .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, + .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, .long_name = NULL_IF_CONFIG_SMALL("libgsm GSM Microsoft variant"), }; @@ -158,7 +158,7 @@ static int libgsm_decode_frame(AVCodecContext *avctx, AVCodec libgsm_decoder = { "libgsm", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_GSM, 0, libgsm_init, @@ -170,7 +170,7 @@ AVCodec libgsm_decoder = { AVCodec libgsm_ms_decoder = { "libgsm_ms", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_GSM_MS, 0, libgsm_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/libmp3lame.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/libmp3lame.c index c7d529163d..1d74d6d59d 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/libmp3lame.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/libmp3lame.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/libmp3lame.c + * @file * Interface to libmp3lame for mp3 encoding. */ @@ -81,8 +81,8 @@ err: return -1; } -static const int sSampleRates[3] = { - 44100, 48000, 32000 +static const int sSampleRates[] = { + 44100, 48000, 32000, 22050, 24000, 16000, 11025, 12000, 8000, 0 }; static const int sBitRates[2][3][15] = { @@ -216,13 +216,14 @@ static av_cold int MP3lame_encode_close(AVCodecContext *avctx) AVCodec libmp3lame_encoder = { "libmp3lame", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_MP3, sizeof(Mp3AudioContext), MP3lame_encode_init, MP3lame_encode_frame, MP3lame_encode_close, .capabilities= CODEC_CAP_DELAY, - .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, + .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, + .supported_samplerates= sSampleRates, .long_name= NULL_IF_CONFIG_SMALL("libmp3lame MP3 (MPEG audio layer 3)"), }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/libopencore-amr.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/libopencore-amr.c index 1544db7bed..266164514f 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/libopencore-amr.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/libopencore-amr.c @@ -141,7 +141,7 @@ static int amr_nb_decode_frame(AVCodecContext *avctx, void *data, AVCodec libopencore_amrnb_decoder = { "libopencore_amrnb", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_AMR_NB, sizeof(AMRContext), amr_nb_decode_init, @@ -215,14 +215,14 @@ static int amr_nb_encode_frame(AVCodecContext *avctx, AVCodec libopencore_amrnb_encoder = { "libopencore_amrnb", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_AMR_NB, sizeof(AMRContext), amr_nb_encode_init, amr_nb_encode_frame, amr_nb_encode_close, NULL, - .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, + .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, .long_name = NULL_IF_CONFIG_SMALL("OpenCORE Adaptive Multi-Rate (AMR) Narrow-Band"), }; @@ -312,7 +312,7 @@ static int amr_wb_decode_close(AVCodecContext *avctx) AVCodec libopencore_amrwb_decoder = { "libopencore_amrwb", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_AMR_WB, sizeof(AMRWBContext), amr_wb_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/libopenjpeg.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/libopenjpeg.c index 8717f67048..0956da9c36 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/libopenjpeg.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/libopenjpeg.c @@ -20,7 +20,7 @@ */ /** -* @file libavcodec/libopenjpeg.c +* @file * JPEG 2000 decoder using libopenjpeg */ @@ -39,12 +39,12 @@ typedef struct { static int check_image_attributes(opj_image_t *image) { - return(image->comps[0].dx == image->comps[1].dx && + return image->comps[0].dx == image->comps[1].dx && image->comps[1].dx == image->comps[2].dx && image->comps[0].dy == image->comps[1].dy && image->comps[1].dy == image->comps[2].dy && image->comps[0].prec == image->comps[1].prec && - image->comps[1].prec == image->comps[2].prec); + image->comps[1].prec == image->comps[2].prec; } static av_cold int libopenjpeg_decode_init(AVCodecContext *avctx) @@ -78,9 +78,13 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx, if((AV_RB32(buf) == 12) && (AV_RB32(buf + 4) == JP2_SIG_TYPE) && (AV_RB32(buf + 8) == JP2_SIG_VALUE)) { - dec = opj_create_decompress(CODEC_JP2); + dec = opj_create_decompress(CODEC_JP2); } else { - dec = opj_create_decompress(CODEC_J2K); + // If the AVPacket contains a jp2c box, then skip to + // the starting byte of the codestream. + if (AV_RB32(buf + 4) == AV_RB32("jp2c")) + buf += 8; + dec = opj_create_decompress(CODEC_J2K); } if(!dec) { @@ -127,7 +131,7 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx, } break; case 4: has_alpha = 1; - avctx->pix_fmt = PIX_FMT_RGB32; + avctx->pix_fmt = PIX_FMT_RGBA; break; default: av_log(avctx, AV_LOG_ERROR, "%d components unsupported.\n", image->numcomps); goto done; @@ -181,7 +185,7 @@ static av_cold int libopenjpeg_decode_close(AVCodecContext *avctx) AVCodec libopenjpeg_decoder = { "libopenjpeg", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_JPEG2000, sizeof(LibOpenJPEGContext), libopenjpeg_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/libschroedinger.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/libschroedinger.c index 242d354be3..04c15a2a01 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/libschroedinger.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/libschroedinger.c @@ -19,7 +19,7 @@ */ /** -* @file libavcodec/libschroedinger.c +* @file * function definitions common to libschroedingerdec.c and libschroedingerenc.c */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/libschroedinger.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/libschroedinger.h index cfc2087b47..65a41e642a 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/libschroedinger.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/libschroedinger.h @@ -19,7 +19,7 @@ */ /** -* @file libavcodec/libschroedinger.h +* @file * data structures common to libschroedingerdec.c and libschroedingerenc.c */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/libschroedingerdec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/libschroedingerdec.c index 53ded57ba4..ef20f20f33 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/libschroedingerdec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/libschroedingerdec.c @@ -20,7 +20,7 @@ */ /** -* @file libavcodec/libschroedingerdec.c +* @file * Dirac decoder support via libschroedinger-1.0 libraries. More details about * the Schroedinger project can be found at http://www.diracvideo.org/. * The library implements Dirac Specification Version 2.2. @@ -347,7 +347,7 @@ static void libschroedinger_flush(AVCodecContext *avccontext) AVCodec libschroedinger_decoder = { "libschroedinger", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_DIRAC, sizeof(FfmpegSchroDecoderParams), libschroedinger_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/libschroedingerenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/libschroedingerenc.c index 9f8d95cc3e..c375c73c0b 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/libschroedingerenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/libschroedingerenc.c @@ -20,7 +20,7 @@ */ /** -* @file libavcodec/libschroedingerenc.c +* @file * Dirac encoder support via libschroedinger-1.0 libraries. More details about * the Schroedinger project can be found at http://www.diracvideo.org/. * The library implements Dirac Specification Version 2.2 @@ -407,13 +407,13 @@ static int libschroedinger_encode_close(AVCodecContext *avccontext) AVCodec libschroedinger_encoder = { "libschroedinger", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_DIRAC, sizeof(FfmpegSchroEncoderParams), libschroedinger_encode_init, libschroedinger_encode_frame, libschroedinger_encode_close, .capabilities = CODEC_CAP_DELAY, - .pix_fmts = (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_YUV444P, PIX_FMT_NONE}, + .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/src/add-ons/media/plugins/ffmpeg/libavcodec/libspeexdec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/libspeexdec.c index 8c3dc293df..c5cfbd5108 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/libspeexdec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/libspeexdec.c @@ -29,6 +29,7 @@ typedef struct { SpeexStereoState stereo; void *dec_state; SpeexHeader *header; + int frame_size; } LibSpeexContext; @@ -52,7 +53,9 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx) if (s->header) { avctx->sample_rate = s->header->rate; avctx->channels = s->header->nb_channels; - avctx->frame_size = s->header->frame_size; + avctx->frame_size = s->frame_size = s->header->frame_size; + if (s->header->frames_per_packet) + avctx->frame_size *= s->header->frames_per_packet; mode = speex_lib_get_mode(s->header->mode); if (!mode) { @@ -74,8 +77,9 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx) return -1; } - if (!s->header) - speex_decoder_ctl(s->dec_state, SPEEX_GET_FRAME_SIZE, &avctx->frame_size); + if (!s->header) { + speex_decoder_ctl(s->dec_state, SPEEX_GET_FRAME_SIZE, &s->frame_size); + } if (avctx->channels == 2) { SpeexCallback callback; @@ -98,8 +102,8 @@ static int libspeex_decode_frame(AVCodecContext *avctx, int16_t *output = data, *end; int i, num_samples; - num_samples = avctx->frame_size * avctx->channels; - end = output + *data_size/2; + num_samples = s->frame_size * avctx->channels; + end = output + *data_size / sizeof(*output); speex_bits_read_from(&s->bits, buf, buf_size); @@ -113,12 +117,13 @@ static int libspeex_decode_frame(AVCodecContext *avctx, break; if (avctx->channels == 2) - speex_decode_stereo_int(output, avctx->frame_size, &s->stereo); + speex_decode_stereo_int(output, s->frame_size, &s->stereo); output += num_samples; } - *data_size = i * avctx->channels * avctx->frame_size * 2; + avctx->frame_size = s->frame_size * i; + *data_size = avctx->channels * avctx->frame_size * sizeof(*output); return buf_size; } @@ -135,7 +140,7 @@ static av_cold int libspeex_decode_close(AVCodecContext *avctx) AVCodec libspeex_decoder = { "libspeex", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_SPEEX, sizeof(LibSpeexContext), libspeex_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/libtheoraenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/libtheoraenc.c index 9da0d19944..2dc45a92cb 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/libtheoraenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/libtheoraenc.c @@ -18,10 +18,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/*! - * \file libtheoraenc.c - * \brief Theora encoder using libtheora. - * \author Paul Richards +/** + * @file + * @brief Theora encoder using libtheora. + * @author Paul Richards * * A lot of this is copy / paste from other output codecs in * libavcodec or pure guesswork (or both). @@ -33,22 +33,29 @@ /* FFmpeg includes */ #include "libavutil/intreadwrite.h" #include "libavutil/log.h" +#include "libavutil/base64.h" #include "avcodec.h" /* libtheora includes */ -#include +#include -typedef struct TheoraContext{ - theora_state t_state; +typedef struct TheoraContext { + th_enc_ctx *t_state; + uint8_t *stats; + int stats_size; + int stats_offset; + int uv_hshift; + int uv_vshift; + int keyframe_mask; } TheoraContext; -/*! - Concatenates an ogg_packet into the extradata. -*/ -static int concatenate_packet(unsigned int* offset, AVCodecContext* avc_context, const ogg_packet* packet) +/** Concatenates an ogg_packet into the extradata. */ +static int concatenate_packet(unsigned int* offset, + AVCodecContext* avc_context, + const ogg_packet* packet) { const char* message = NULL; - uint8_t* newdata = NULL; + uint8_t* newdata = NULL; int newsize = avc_context->extradata_size + 2 + packet->bytes; if (packet->bytes < 0) { @@ -59,75 +66,175 @@ static int concatenate_packet(unsigned int* offset, AVCodecContext* avc_context, message = "extradata_size would overflow"; } else { newdata = av_realloc(avc_context->extradata, newsize); - if (newdata == NULL) { + if (!newdata) message = "av_realloc failed"; - } } - if (message != NULL) { + if (message) { av_log(avc_context, AV_LOG_ERROR, "concatenate_packet failed: %s\n", message); return -1; } - avc_context->extradata = newdata; + avc_context->extradata = newdata; avc_context->extradata_size = newsize; AV_WB16(avc_context->extradata + (*offset), packet->bytes); *offset += 2; - memcpy( avc_context->extradata + (*offset), packet->packet, packet->bytes ); + memcpy(avc_context->extradata + (*offset), packet->packet, packet->bytes); (*offset) += packet->bytes; return 0; } +static int get_stats(AVCodecContext *avctx, int eos) +{ +#ifdef TH_ENCCTL_2PASS_OUT + TheoraContext *h = avctx->priv_data; + uint8_t *buf; + int bytes; + + bytes = th_encode_ctl(h->t_state, TH_ENCCTL_2PASS_OUT, &buf, sizeof(buf)); + if (bytes < 0) { + av_log(avctx, AV_LOG_ERROR, "Error getting first pass stats\n"); + return -1; + } + if (!eos) { + h->stats = av_fast_realloc(h->stats, &h->stats_size, + h->stats_offset + bytes); + memcpy(h->stats + h->stats_offset, buf, bytes); + h->stats_offset += bytes; + } else { + int b64_size = ((h->stats_offset + 2) / 3) * 4 + 1; + // libtheora generates a summary header at the end + memcpy(h->stats, buf, bytes); + avctx->stats_out = av_malloc(b64_size); + av_base64_encode(avctx->stats_out, b64_size, h->stats, h->stats_offset); + } + return 0; +#else + av_log(avctx, AV_LOG_ERROR, "libtheora too old to support 2pass\n"); + return -1; +#endif +} + +// libtheora won't read the entire buffer we give it at once, so we have to +// repeatedly submit it... +static int submit_stats(AVCodecContext *avctx) +{ +#ifdef TH_ENCCTL_2PASS_IN + TheoraContext *h = avctx->priv_data; + int bytes; + if (!h->stats) { + if (!avctx->stats_in) { + av_log(avctx, AV_LOG_ERROR, "No statsfile for second pass\n"); + return -1; + } + h->stats_size = strlen(avctx->stats_in) * 3/4; + h->stats = av_malloc(h->stats_size); + h->stats_size = av_base64_decode(h->stats, avctx->stats_in, h->stats_size); + } + while (h->stats_size - h->stats_offset > 0) { + bytes = th_encode_ctl(h->t_state, TH_ENCCTL_2PASS_IN, + h->stats + h->stats_offset, + h->stats_size - h->stats_offset); + if (bytes < 0) { + av_log(avctx, AV_LOG_ERROR, "Error submitting stats\n"); + return -1; + } + if (!bytes) + return 0; + h->stats_offset += bytes; + } + return 0; +#else + av_log(avctx, AV_LOG_ERROR, "libtheora too old to support 2pass\n"); + return -1; +#endif +} + static av_cold int encode_init(AVCodecContext* avc_context) { - theora_info t_info; - theora_comment t_comment; + th_info t_info; + th_comment t_comment; ogg_packet o_packet; unsigned int offset; TheoraContext *h = avc_context->priv_data; + uint32_t gop_size = avc_context->gop_size; /* Set up the theora_info struct */ - theora_info_init( &t_info ); - t_info.width = FFALIGN(avc_context->width, 16); - t_info.height = FFALIGN(avc_context->height, 16); - t_info.frame_width = avc_context->width; - t_info.frame_height = avc_context->height; - t_info.offset_x = 0; - t_info.offset_y = avc_context->height & 0xf; + th_info_init(&t_info); + t_info.frame_width = FFALIGN(avc_context->width, 16); + t_info.frame_height = FFALIGN(avc_context->height, 16); + t_info.pic_width = avc_context->width; + t_info.pic_height = avc_context->height; + t_info.pic_x = 0; + t_info.pic_y = 0; /* Swap numerator and denominator as time_base in AVCodecContext gives the * time period between frames, but theora_info needs the framerate. */ - t_info.fps_numerator = avc_context->time_base.den; + t_info.fps_numerator = avc_context->time_base.den; t_info.fps_denominator = avc_context->time_base.num; - if (avc_context->sample_aspect_ratio.num != 0) { - t_info.aspect_numerator = avc_context->sample_aspect_ratio.num; + if (avc_context->sample_aspect_ratio.num) { + t_info.aspect_numerator = avc_context->sample_aspect_ratio.num; t_info.aspect_denominator = avc_context->sample_aspect_ratio.den; } else { - t_info.aspect_numerator = 1; + t_info.aspect_numerator = 1; t_info.aspect_denominator = 1; } - t_info.colorspace = OC_CS_UNSPECIFIED; - t_info.pixelformat = OC_PF_420; - t_info.target_bitrate = avc_context->bit_rate; - t_info.keyframe_frequency = avc_context->gop_size; - t_info.keyframe_frequency_force = avc_context->gop_size; - t_info.keyframe_mindistance = avc_context->keyint_min; - t_info.quality = 0; - t_info.quick_p = 1; - t_info.dropframes_p = 0; - t_info.keyframe_auto_p = 1; - t_info.keyframe_data_target_bitrate = t_info.target_bitrate * 1.5; - t_info.keyframe_auto_threshold = 80; - t_info.noise_sensitivity = 1; - t_info.sharpness = 0; + if (avc_context->color_primaries == AVCOL_PRI_BT470M) + t_info.colorspace = TH_CS_ITU_REC_470M; + else if (avc_context->color_primaries == AVCOL_PRI_BT470BG) + t_info.colorspace = TH_CS_ITU_REC_470BG; + else + t_info.colorspace = TH_CS_UNSPECIFIED; + + if (avc_context->pix_fmt == PIX_FMT_YUV420P) + t_info.pixel_fmt = TH_PF_420; + else if (avc_context->pix_fmt == PIX_FMT_YUV422P) + t_info.pixel_fmt = TH_PF_422; + else if (avc_context->pix_fmt == PIX_FMT_YUV444P) + t_info.pixel_fmt = TH_PF_444; + else { + av_log(avc_context, AV_LOG_ERROR, "Unsupported pix_fmt\n"); + return -1; + } + avcodec_get_chroma_sub_sample(avc_context->pix_fmt, &h->uv_hshift, &h->uv_vshift); + + if (avc_context->flags & CODEC_FLAG_QSCALE) { + /* to be constant with the libvorbis implementation, clip global_quality to 0 - 10 + Theora accepts a quality parameter p, which is: + * 0 <= p <=63 + * an int value + */ + t_info.quality = av_clip(avc_context->global_quality / (float)FF_QP2LAMBDA, 0, 10) * 6.3; + t_info.target_bitrate = 0; + } else { + t_info.target_bitrate = avc_context->bit_rate; + t_info.quality = 0; + } /* Now initialise libtheora */ - if (theora_encode_init( &(h->t_state), &t_info ) != 0) { + h->t_state = th_encode_alloc(&t_info); + if (!h->t_state) { av_log(avc_context, AV_LOG_ERROR, "theora_encode_init failed\n"); return -1; } + h->keyframe_mask = (1 << t_info.keyframe_granule_shift) - 1; /* Clear up theora_info struct */ - theora_info_clear( &t_info ); + th_info_clear(&t_info); + + if (th_encode_ctl(h->t_state, TH_ENCCTL_SET_KEYFRAME_FREQUENCY_FORCE, + &gop_size, sizeof(gop_size))) { + av_log(avc_context, AV_LOG_ERROR, "Error setting GOP size\n"); + return -1; + } + + // need to enable 2 pass (via TH_ENCCTL_2PASS_) before encoding headers + if (avc_context->flags & CODEC_FLAG_PASS1) { + if (get_stats(avc_context, 0)) + return -1; + } else if (avc_context->flags & CODEC_FLAG_PASS2) { + if (submit_stats(avc_context)) + return -1; + } /* Output first header packet consisting of theora @@ -138,29 +245,14 @@ static av_cold int encode_init(AVCodecContext* avc_context) */ offset = 0; - /* Header */ - theora_encode_header( &(h->t_state), &o_packet ); - if (concatenate_packet( &offset, avc_context, &o_packet ) != 0) { - return -1; - } + /* Headers */ + th_comment_init(&t_comment); - /* Comment */ - theora_comment_init( &t_comment ); - theora_encode_comment( &t_comment, &o_packet ); - if (concatenate_packet( &offset, avc_context, &o_packet ) != 0) { - return -1; - } - /* Clear up theora_comment struct before we reset the packet */ - theora_comment_clear( &t_comment ); - /* And despite documentation to the contrary, theora_comment_clear - * does not release the packet */ - ogg_packet_clear(&o_packet); + while (th_encode_flushheader(h->t_state, &t_comment, &o_packet)) + if (concatenate_packet(&offset, avc_context, &o_packet)) + return -1; - /* Tables */ - theora_encode_tables( &(h->t_state), &o_packet ); - if (concatenate_packet( &offset, avc_context, &o_packet ) != 0) { - return -1; - } + th_comment_clear(&t_comment); /* Set up the output AVFrame */ avc_context->coded_frame= avcodec_alloc_frame(); @@ -168,68 +260,71 @@ static av_cold int encode_init(AVCodecContext* avc_context) return 0; } -static int encode_frame( - AVCodecContext* avc_context, - uint8_t *outbuf, - int buf_size, - void *data) +static int encode_frame(AVCodecContext* avc_context, uint8_t *outbuf, + int buf_size, void *data) { - yuv_buffer t_yuv_buffer; + th_ycbcr_buffer t_yuv_buffer; TheoraContext *h = avc_context->priv_data; AVFrame *frame = data; ogg_packet o_packet; - int result; + int result, i; - assert(avc_context->pix_fmt == PIX_FMT_YUV420P); - - /* Copy planes to the theora yuv_buffer */ - if (frame->linesize[1] != frame->linesize[2]) { - av_log(avc_context, AV_LOG_ERROR, "U and V stride differ\n"); - return -1; + // EOS, finish and get 1st pass stats if applicable + if (!frame) { + th_encode_packetout(h->t_state, 1, &o_packet); + if (avc_context->flags & CODEC_FLAG_PASS1) + if (get_stats(avc_context, 1)) + return -1; + return 0; } - t_yuv_buffer.y_width = FFALIGN(avc_context->width, 16); - t_yuv_buffer.y_height = FFALIGN(avc_context->height, 16); - t_yuv_buffer.y_stride = frame->linesize[0]; - t_yuv_buffer.uv_width = t_yuv_buffer.y_width / 2; - t_yuv_buffer.uv_height = t_yuv_buffer.y_height / 2; - t_yuv_buffer.uv_stride = frame->linesize[1]; + /* Copy planes to the theora yuv_buffer */ + for (i = 0; i < 3; i++) { + t_yuv_buffer[i].width = FFALIGN(avc_context->width, 16) >> (i && h->uv_hshift); + t_yuv_buffer[i].height = FFALIGN(avc_context->height, 16) >> (i && h->uv_vshift); + t_yuv_buffer[i].stride = frame->linesize[i]; + t_yuv_buffer[i].data = frame->data[i]; + } - t_yuv_buffer.y = frame->data[0]; - t_yuv_buffer.u = frame->data[1]; - t_yuv_buffer.v = frame->data[2]; + if (avc_context->flags & CODEC_FLAG_PASS2) + if (submit_stats(avc_context)) + return -1; /* Now call into theora_encode_YUVin */ - result = theora_encode_YUVin( &(h->t_state), &t_yuv_buffer ); - if (result != 0) { + result = th_encode_ycbcr_in(h->t_state, t_yuv_buffer); + if (result) { const char* message; switch (result) { - case -1: - message = "differing frame sizes"; - break; - case OC_EINVAL: - message = "encoder is not ready or is finished"; - break; - default: - message = "unknown reason"; - break; + case -1: + message = "differing frame sizes"; + break; + case TH_EINVAL: + message = "encoder is not ready or is finished"; + break; + default: + message = "unknown reason"; + break; } av_log(avc_context, AV_LOG_ERROR, "theora_encode_YUVin failed (%s) [%d]\n", message, result); return -1; } - /* Pick up returned ogg_packet */ - result = theora_encode_packetout( &(h->t_state), 0, &o_packet ); - switch (result) { - case 0: - /* No packet is ready */ - return 0; - case 1: - /* Success, we have a packet */ - break; - default: - av_log(avc_context, AV_LOG_ERROR, "theora_encode_packetout failed [%d]\n", result); + if (avc_context->flags & CODEC_FLAG_PASS1) + if (get_stats(avc_context, 0)) return -1; + + /* Pick up returned ogg_packet */ + result = th_encode_packetout(h->t_state, 0, &o_packet); + switch (result) { + case 0: + /* No packet is ready */ + return 0; + case 1: + /* Success, we have a packet */ + break; + default: + av_log(avc_context, AV_LOG_ERROR, "theora_encode_packetout failed [%d]\n", result); + return -1; } /* Copy ogg_packet content out to buffer */ @@ -239,50 +334,38 @@ static int encode_frame( } memcpy(outbuf, o_packet.packet, o_packet.bytes); + // HACK: assumes no encoder delay, this is true until libtheora becomes + // multithreaded (which will be disabled unless explictly requested) + avc_context->coded_frame->pts = frame->pts; + avc_context->coded_frame->key_frame = !(o_packet.granulepos & h->keyframe_mask); + return o_packet.bytes; } static av_cold int encode_close(AVCodecContext* avc_context) { - ogg_packet o_packet; TheoraContext *h = avc_context->priv_data; - int result; - const char* message; - result = theora_encode_packetout( &(h->t_state), 1, &o_packet ); - theora_clear( &(h->t_state) ); + th_encode_free(h->t_state); + av_freep(&h->stats); av_freep(&avc_context->coded_frame); + av_freep(&avc_context->stats_out); av_freep(&avc_context->extradata); avc_context->extradata_size = 0; - switch (result) { - case 0:/* No packet is ready */ - case -1:/* Encoding finished */ - return 0; - case 1: - /* We have a packet */ - message = "gave us a packet"; - break; - default: - message = "unknown reason"; - break; - } - av_log(avc_context, AV_LOG_ERROR, "theora_encode_packetout failed (%s) [%d]\n", message, result); - return -1; + return 0; } -static const enum PixelFormat supported_pixel_formats[] = { PIX_FMT_YUV420P, PIX_FMT_NONE }; - -/*! AVCodec struct exposed to libavcodec */ -AVCodec libtheora_encoder = -{ +/** AVCodec struct exposed to libavcodec */ +AVCodec libtheora_encoder = { .name = "libtheora", - .type = CODEC_TYPE_VIDEO, + .type = AVMEDIA_TYPE_VIDEO, .id = CODEC_ID_THEORA, .priv_data_size = sizeof(TheoraContext), .init = encode_init, .close = encode_close, .encode = encode_frame, - .pix_fmts = supported_pixel_formats, + .capabilities = CODEC_CAP_DELAY, // needed to get the statsfile summary + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_YUV444P, PIX_FMT_NONE}, .long_name = NULL_IF_CONFIG_SMALL("libtheora Theora"), }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/libvorbis.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/libvorbis.c index 11d9a28636..81d328af4e 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/libvorbis.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/libvorbis.c @@ -19,7 +19,7 @@ */ /** - * @file libavcodec/libvorbis.c + * @file * Ogg Vorbis codec support via libvorbisenc. * @author Mark Hills */ @@ -217,13 +217,13 @@ static av_cold int oggvorbis_encode_close(AVCodecContext *avccontext) { AVCodec libvorbis_encoder = { "libvorbis", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_VORBIS, sizeof(OggVorbisContext), oggvorbis_encode_init, oggvorbis_encode_frame, oggvorbis_encode_close, .capabilities= CODEC_CAP_DELAY, - .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, + .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, .long_name= NULL_IF_CONFIG_SMALL("libvorbis Vorbis"), } ; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/libvpxdec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/libvpxdec.c new file mode 100644 index 0000000000..0464d12e71 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/libvpxdec.c @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2010, Google, Inc. + * + * 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 + * VP8 decoder support via libvpx + */ + +#define VPX_CODEC_DISABLE_COMPAT 1 +#include +#include + +#include "avcodec.h" + +typedef struct VP8DecoderContext { + struct vpx_codec_ctx decoder; +} VP8Context; + +static av_cold int vp8_init(AVCodecContext *avctx) +{ + VP8Context *ctx = avctx->priv_data; + const struct vpx_codec_iface *iface = &vpx_codec_vp8_dx_algo; + struct vpx_codec_dec_cfg deccfg = { + /* token partitions+1 would be a decent choice */ + .threads = FFMIN(avctx->thread_count, 16) + }; + + av_log(avctx, AV_LOG_INFO, "%s\n", vpx_codec_version_str()); + av_log(avctx, AV_LOG_VERBOSE, "%s\n", vpx_codec_build_config()); + + if (vpx_codec_dec_init(&ctx->decoder, iface, &deccfg, 0) != VPX_CODEC_OK) { + const char *error = vpx_codec_error(&ctx->decoder); + av_log(avctx, AV_LOG_ERROR, "Failed to initialize decoder: %s\n", + error); + return AVERROR(EINVAL); + } + + avctx->pix_fmt = PIX_FMT_YUV420P; + return 0; +} + +static int vp8_decode(AVCodecContext *avctx, + void *data, int *data_size, AVPacket *avpkt) +{ + VP8Context *ctx = avctx->priv_data; + AVFrame *picture = data; + const void *iter = NULL; + struct vpx_image *img; + + if (vpx_codec_decode(&ctx->decoder, avpkt->data, avpkt->size, NULL, 0) != + VPX_CODEC_OK) { + const char *error = vpx_codec_error(&ctx->decoder); + const char *detail = vpx_codec_error_detail(&ctx->decoder); + + av_log(avctx, AV_LOG_ERROR, "Failed to decode frame: %s\n", error); + if (detail) + av_log(avctx, AV_LOG_ERROR, " Additional information: %s\n", + detail); + return AVERROR_INVALIDDATA; + } + + if ((img = vpx_codec_get_frame(&ctx->decoder, &iter))) { + if (img->fmt != VPX_IMG_FMT_I420) { + av_log(avctx, AV_LOG_ERROR, "Unsupported output colorspace (%d)\n", + img->fmt); + return AVERROR_INVALIDDATA; + } + + if ((int) img->d_w != avctx->width || (int) img->d_h != avctx->height) { + av_log(avctx, AV_LOG_INFO, "dimension change! %dx%d -> %dx%d\n", + avctx->width, avctx->height, img->d_w, img->d_h); + if (avcodec_check_dimensions(avctx, img->d_w, img->d_h)) + return AVERROR_INVALIDDATA; + avcodec_set_dimensions(avctx, img->d_w, img->d_h); + } + picture->data[0] = img->planes[0]; + picture->data[1] = img->planes[1]; + picture->data[2] = img->planes[2]; + picture->data[3] = NULL; + picture->linesize[0] = img->stride[0]; + picture->linesize[1] = img->stride[1]; + picture->linesize[2] = img->stride[2]; + picture->linesize[3] = 0; + *data_size = sizeof(AVPicture); + } + return avpkt->size; +} + +static av_cold int vp8_free(AVCodecContext *avctx) +{ + VP8Context *ctx = avctx->priv_data; + vpx_codec_destroy(&ctx->decoder); + return 0; +} + +AVCodec libvpx_decoder = { + "libvpx", + AVMEDIA_TYPE_VIDEO, + CODEC_ID_VP8, + sizeof(VP8Context), + vp8_init, + NULL, /* encode */ + vp8_free, + vp8_decode, + 0, /* capabilities */ + .long_name = NULL_IF_CONFIG_SMALL("libvpx VP8"), +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/libvpxenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/libvpxenc.c new file mode 100644 index 0000000000..fa393b8f42 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/libvpxenc.c @@ -0,0 +1,489 @@ +/* + * Copyright (c) 2010, Google, Inc. + * + * 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 + * VP8 encoder support via libvpx + */ + +#define VPX_DISABLE_CTRL_TYPECHECKS 1 +#define VPX_CODEC_DISABLE_COMPAT 1 +#include +#include + +#include "avcodec.h" +#include "libavutil/base64.h" + +/** + * Portion of struct vpx_codec_cx_pkt from vpx_encoder.h. + * One encoded frame returned from the library. + */ +struct FrameListData { + void *buf; /**≤ compressed data buffer */ + size_t sz; /**≤ length of compressed data */ + int64_t pts; /**≤ time stamp to show frame + (in timebase units) */ + unsigned long duration; /**≤ duration to show frame + (in timebase units) */ + uint32_t flags; /**≤ flags for this frame */ + struct FrameListData *next; +}; + +typedef struct VP8EncoderContext { + struct vpx_codec_ctx encoder; + struct vpx_image rawimg; + struct vpx_fixed_buf twopass_stats; + unsigned long deadline; //i.e., RT/GOOD/BEST + struct FrameListData *coded_frame_list; +} VP8Context; + +/** String mappings for enum vp8e_enc_control_id */ +static const char *ctlidstr[] = { + [VP8E_UPD_ENTROPY] = "VP8E_UPD_ENTROPY", + [VP8E_UPD_REFERENCE] = "VP8E_UPD_REFERENCE", + [VP8E_USE_REFERENCE] = "VP8E_USE_REFERENCE", + [VP8E_SET_ROI_MAP] = "VP8E_SET_ROI_MAP", + [VP8E_SET_ACTIVEMAP] = "VP8E_SET_ACTIVEMAP", + [VP8E_SET_SCALEMODE] = "VP8E_SET_SCALEMODE", + [VP8E_SET_CPUUSED] = "VP8E_SET_CPUUSED", + [VP8E_SET_ENABLEAUTOALTREF] = "VP8E_SET_ENABLEAUTOALTREF", + [VP8E_SET_NOISE_SENSITIVITY] = "VP8E_SET_NOISE_SENSITIVITY", + [VP8E_SET_SHARPNESS] = "VP8E_SET_SHARPNESS", + [VP8E_SET_STATIC_THRESHOLD] = "VP8E_SET_STATIC_THRESHOLD", + [VP8E_SET_TOKEN_PARTITIONS] = "VP8E_SET_TOKEN_PARTITIONS", + [VP8E_GET_LAST_QUANTIZER] = "VP8E_GET_LAST_QUANTIZER", + [VP8E_SET_ARNR_MAXFRAMES] = "VP8E_SET_ARNR_MAXFRAMES", + [VP8E_SET_ARNR_STRENGTH] = "VP8E_SET_ARNR_STRENGTH", + [VP8E_SET_ARNR_TYPE] = "VP8E_SET_ARNR_TYPE", +}; + +static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc) +{ + VP8Context *ctx = avctx->priv_data; + const char *error = vpx_codec_error(&ctx->encoder); + const char *detail = vpx_codec_error_detail(&ctx->encoder); + + av_log(avctx, AV_LOG_ERROR, "%s: %s\n", desc, error); + if (detail) + av_log(avctx, AV_LOG_ERROR, " Additional information: %s\n", detail); +} + +static av_cold void dump_enc_cfg(AVCodecContext *avctx, + const struct vpx_codec_enc_cfg *cfg) +{ + int width = -30; + int level = AV_LOG_DEBUG; + + av_log(avctx, level, "vpx_codec_enc_cfg\n"); + av_log(avctx, level, "generic settings\n" + " %*s%u\n %*s%u\n %*s%u\n %*s%u\n %*s%u\n" + " %*s{%u/%u}\n %*s%u\n %*s%d\n %*s%u\n", + width, "g_usage:", cfg->g_usage, + width, "g_threads:", cfg->g_threads, + width, "g_profile:", cfg->g_profile, + width, "g_w:", cfg->g_w, + width, "g_h:", cfg->g_h, + width, "g_timebase:", cfg->g_timebase.num, cfg->g_timebase.den, + width, "g_error_resilient:", cfg->g_error_resilient, + width, "g_pass:", cfg->g_pass, + width, "g_lag_in_frames:", cfg->g_lag_in_frames); + av_log(avctx, level, "rate control settings\n" + " %*s%u\n %*s%u\n %*s%u\n %*s%u\n" + " %*s%d\n %*s%p(%zu)\n %*s%u\n", + width, "rc_dropframe_thresh:", cfg->rc_dropframe_thresh, + width, "rc_resize_allowed:", cfg->rc_resize_allowed, + width, "rc_resize_up_thresh:", cfg->rc_resize_up_thresh, + width, "rc_resize_down_thresh:", cfg->rc_resize_down_thresh, + width, "rc_end_usage:", cfg->rc_end_usage, + width, "rc_twopass_stats_in:", cfg->rc_twopass_stats_in.buf, cfg->rc_twopass_stats_in.sz, + width, "rc_target_bitrate:", cfg->rc_target_bitrate); + av_log(avctx, level, "quantizer settings\n" + " %*s%u\n %*s%u\n", + width, "rc_min_quantizer:", cfg->rc_min_quantizer, + width, "rc_max_quantizer:", cfg->rc_max_quantizer); + av_log(avctx, level, "bitrate tolerance\n" + " %*s%u\n %*s%u\n", + width, "rc_undershoot_pct:", cfg->rc_undershoot_pct, + width, "rc_overshoot_pct:", cfg->rc_overshoot_pct); + av_log(avctx, level, "decoder buffer model\n" + " %*s%u\n %*s%u\n %*s%u\n", + width, "rc_buf_sz:", cfg->rc_buf_sz, + width, "rc_buf_initial_sz:", cfg->rc_buf_initial_sz, + width, "rc_buf_optimal_sz:", cfg->rc_buf_optimal_sz); + av_log(avctx, level, "2 pass rate control settings\n" + " %*s%u\n %*s%u\n %*s%u\n", + width, "rc_2pass_vbr_bias_pct:", cfg->rc_2pass_vbr_bias_pct, + width, "rc_2pass_vbr_minsection_pct:", cfg->rc_2pass_vbr_minsection_pct, + width, "rc_2pass_vbr_maxsection_pct:", cfg->rc_2pass_vbr_maxsection_pct); + av_log(avctx, level, "keyframing settings\n" + " %*s%d\n %*s%u\n %*s%u\n", + width, "kf_mode:", cfg->kf_mode, + width, "kf_min_dist:", cfg->kf_min_dist, + width, "kf_max_dist:", cfg->kf_max_dist); + av_log(avctx, level, "\n"); +} + +static void coded_frame_add(void *list, struct FrameListData *cx_frame) +{ + struct FrameListData **p = list; + + while (*p != NULL) + p = &(*p)->next; + *p = cx_frame; + cx_frame->next = NULL; +} + +static av_cold void free_coded_frame(struct FrameListData *cx_frame) +{ + av_freep(&cx_frame->buf); + av_freep(&cx_frame); +} + +static av_cold void free_frame_list(struct FrameListData *list) +{ + struct FrameListData *p = list; + + while (p) { + list = list->next; + free_coded_frame(p); + p = list; + } +} + +static av_cold int codecctl_int(AVCodecContext *avctx, + enum vp8e_enc_control_id id, int val) +{ + VP8Context *ctx = avctx->priv_data; + char buf[80]; + int width = -30; + int res; + + snprintf(buf, sizeof(buf), "%s:", ctlidstr[id]); + av_log(avctx, AV_LOG_DEBUG, " %*s%d\n", width, buf, val); + + res = vpx_codec_control(&ctx->encoder, id, val); + if (res != VPX_CODEC_OK) { + snprintf(buf, sizeof(buf), "Failed to set %s codec control", + ctlidstr[id]); + log_encoder_error(avctx, buf); + } + + return res == VPX_CODEC_OK ? 0 : AVERROR(EINVAL); +} + +static av_cold int vp8_free(AVCodecContext *avctx) +{ + VP8Context *ctx = avctx->priv_data; + + vpx_codec_destroy(&ctx->encoder); + av_freep(&ctx->twopass_stats.buf); + av_freep(&avctx->coded_frame); + av_freep(&avctx->stats_out); + free_frame_list(ctx->coded_frame_list); + return 0; +} + +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; + + av_log(avctx, AV_LOG_INFO, "%s\n", vpx_codec_version_str()); + av_log(avctx, AV_LOG_VERBOSE, "%s\n", vpx_codec_build_config()); + + if ((res = vpx_codec_enc_config_default(iface, &enccfg, 0)) != VPX_CODEC_OK) { + av_log(avctx, AV_LOG_ERROR, "Failed to get config: %s\n", + vpx_codec_err_to_string(res)); + return AVERROR(EINVAL); + } + dump_enc_cfg(avctx, &enccfg); + + enccfg.g_w = avctx->width; + enccfg.g_h = avctx->height; + enccfg.g_timebase.num = avctx->time_base.num; + enccfg.g_timebase.den = avctx->time_base.den; + enccfg.g_threads = avctx->thread_count; + + if (avctx->flags & CODEC_FLAG_PASS1) + enccfg.g_pass = VPX_RC_FIRST_PASS; + else if (avctx->flags & CODEC_FLAG_PASS2) + enccfg.g_pass = VPX_RC_LAST_PASS; + else + enccfg.g_pass = VPX_RC_ONE_PASS; + + if (avctx->rc_min_rate == avctx->rc_max_rate && + avctx->rc_min_rate == avctx->bit_rate) + enccfg.rc_end_usage = VPX_CBR; + enccfg.rc_target_bitrate = av_rescale_rnd(avctx->bit_rate, 1, 1000, + AV_ROUND_NEAR_INF); + + //convert [1,51] -> [0,63] + enccfg.rc_min_quantizer = ((avctx->qmin * 5 + 1) >> 2) - 1; + enccfg.rc_max_quantizer = ((avctx->qmax * 5 + 1) >> 2) - 1; + + if (avctx->keyint_min == avctx->gop_size) + enccfg.kf_mode = VPX_KF_FIXED; + //_enc_init() will balk if kf_min_dist is set in this case + if (enccfg.kf_mode != VPX_KF_AUTO) + enccfg.kf_min_dist = avctx->keyint_min; + enccfg.kf_max_dist = avctx->gop_size; + + if (enccfg.g_pass == VPX_RC_FIRST_PASS) + enccfg.g_lag_in_frames = 0; + else if (enccfg.g_pass == VPX_RC_LAST_PASS) { + int decode_size; + + if (!avctx->stats_in) { + av_log(avctx, AV_LOG_ERROR, "No stats file for second pass\n"); + return AVERROR_INVALIDDATA; + } + + ctx->twopass_stats.sz = strlen(avctx->stats_in) * 3 / 4; + ctx->twopass_stats.buf = av_malloc(ctx->twopass_stats.sz); + if (!ctx->twopass_stats.buf) { + av_log(avctx, AV_LOG_ERROR, + "Stat buffer alloc (%zu bytes) failed\n", + ctx->twopass_stats.sz); + return AVERROR(ENOMEM); + } + decode_size = av_base64_decode(ctx->twopass_stats.buf, avctx->stats_in, + ctx->twopass_stats.sz); + if (decode_size < 0) { + av_log(avctx, AV_LOG_ERROR, "Stat buffer decode failed\n"); + return AVERROR_INVALIDDATA; + } + + ctx->twopass_stats.sz = decode_size; + enccfg.rc_twopass_stats_in = ctx->twopass_stats; + } + + ctx->deadline = VPX_DL_GOOD_QUALITY; + + dump_enc_cfg(avctx, &enccfg); + /* Construct Encoder Context */ + res = vpx_codec_enc_init(&ctx->encoder, iface, &enccfg, 0); + if (res != VPX_CODEC_OK) { + log_encoder_error(avctx, "Failed to initialize encoder"); + return AVERROR(EINVAL); + } + + //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); + codecctl_int(avctx, VP8E_SET_NOISE_SENSITIVITY, avctx->noise_reduction); + + //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, + (unsigned char*)1); + + avctx->coded_frame = avcodec_alloc_frame(); + if (!avctx->coded_frame) { + av_log(avctx, AV_LOG_ERROR, "Error allocating coded frame\n"); + vp8_free(avctx); + return AVERROR(ENOMEM); + } + return 0; +} + +static inline void cx_pktcpy(struct FrameListData *dst, + const struct vpx_codec_cx_pkt *src) +{ + dst->pts = src->data.frame.pts; + dst->duration = src->data.frame.duration; + dst->flags = src->data.frame.flags; + dst->sz = src->data.frame.sz; + dst->buf = src->data.frame.buf; +} + +/** + * Store coded frame information in format suitable for return from encode(). + * + * Write buffer information from @a cx_frame to @a buf & @a buf_size. + * Timing/frame details to @a coded_frame. + * @return Frame size written to @a buf on success + * @return AVERROR(EINVAL) on error + */ +static int storeframe(AVCodecContext *avctx, struct FrameListData *cx_frame, + uint8_t *buf, int buf_size, AVFrame *coded_frame) +{ + if ((int) cx_frame->sz <= buf_size) { + buf_size = cx_frame->sz; + memcpy(buf, cx_frame->buf, buf_size); + coded_frame->pts = cx_frame->pts; + coded_frame->key_frame = !!(cx_frame->flags & VPX_FRAME_IS_KEY); + + if (coded_frame->key_frame) + coded_frame->pict_type = FF_I_TYPE; + else + coded_frame->pict_type = FF_P_TYPE; + } else { + av_log(avctx, AV_LOG_ERROR, + "Compressed frame larger than storage provided! (%zu/%d)\n", + cx_frame->sz, buf_size); + return AVERROR(EINVAL); + } + return buf_size; +} + +/** + * Queue multiple output frames from the encoder, returning the front-most. + * In cases where vpx_codec_get_cx_data() returns more than 1 frame append + * the frame queue. Return the head frame if available. + * @return Stored frame size + * @return AVERROR(EINVAL) on output size error + * @return AVERROR(ENOMEM) on coded frame queue data allocation error + */ +static int queue_frames(AVCodecContext *avctx, uint8_t *buf, int buf_size, + AVFrame *coded_frame) +{ + VP8Context *ctx = avctx->priv_data; + const struct vpx_codec_cx_pkt *pkt; + const void *iter = NULL; + int size = 0; + + if (ctx->coded_frame_list) { + struct FrameListData *cx_frame = ctx->coded_frame_list; + /* return the leading frame if we've already begun queueing */ + size = storeframe(avctx, cx_frame, buf, buf_size, coded_frame); + if (size < 0) + return AVERROR(EINVAL); + ctx->coded_frame_list = cx_frame->next; + free_coded_frame(cx_frame); + } + + /* consume all available output from the encoder before returning. buffers + are only good through the next vpx_codec call */ + while ((pkt = vpx_codec_get_cx_data(&ctx->encoder, &iter))) { + switch (pkt->kind) { + case VPX_CODEC_CX_FRAME_PKT: + if (!size) { + struct FrameListData cx_frame; + + /* avoid storing the frame when the list is empty and we haven't yet + provided a frame for output */ + assert(!ctx->coded_frame_list); + cx_pktcpy(&cx_frame, pkt); + size = storeframe(avctx, &cx_frame, buf, buf_size, coded_frame); + if (size < 0) + return AVERROR(EINVAL); + } else { + struct FrameListData *cx_frame = + av_malloc(sizeof(struct FrameListData)); + + if (!cx_frame) { + av_log(avctx, AV_LOG_ERROR, + "Frame queue element alloc failed\n"); + return AVERROR(ENOMEM); + } + cx_pktcpy(cx_frame, pkt); + cx_frame->buf = av_malloc(cx_frame->sz); + + if (!cx_frame->buf) { + av_log(avctx, AV_LOG_ERROR, + "Data buffer alloc (%zu bytes) failed\n", + cx_frame->sz); + return AVERROR(ENOMEM); + } + memcpy(cx_frame->buf, pkt->data.frame.buf, pkt->data.frame.sz); + coded_frame_add(&ctx->coded_frame_list, cx_frame); + } + 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); + if (!stats->buf) { + av_log(avctx, AV_LOG_ERROR, "Stat buffer realloc failed\n"); + return AVERROR(ENOMEM); + } + memcpy((uint8_t*)stats->buf + stats->sz, + pkt->data.twopass_stats.buf, pkt->data.twopass_stats.sz); + stats->sz += pkt->data.twopass_stats.sz; + break; + } + case VPX_CODEC_PSNR_PKT: //FIXME add support for CODEC_FLAG_PSNR + case VPX_CODEC_CUSTOM_PKT: + //ignore unsupported/unrecognized packet types + break; + } + } + + return size; +} + +static int vp8_encode(AVCodecContext *avctx, uint8_t *buf, int buf_size, + void *data) +{ + VP8Context *ctx = avctx->priv_data; + AVFrame *frame = data; + struct vpx_image *rawimg = NULL; + int64_t timestamp = 0; + int res, coded_size; + + if (frame) { + rawimg = &ctx->rawimg; + rawimg->planes[VPX_PLANE_Y] = frame->data[0]; + rawimg->planes[VPX_PLANE_U] = frame->data[1]; + rawimg->planes[VPX_PLANE_V] = frame->data[2]; + rawimg->stride[VPX_PLANE_Y] = frame->linesize[0]; + rawimg->stride[VPX_PLANE_U] = frame->linesize[1]; + rawimg->stride[VPX_PLANE_V] = frame->linesize[2]; + timestamp = frame->pts; + } + + res = vpx_codec_encode(&ctx->encoder, rawimg, timestamp, + avctx->ticks_per_frame, 0, ctx->deadline); + if (res != VPX_CODEC_OK) { + log_encoder_error(avctx, "Error encoding frame"); + return AVERROR_INVALIDDATA; + } + coded_size = queue_frames(avctx, buf, buf_size, avctx->coded_frame); + + if (!frame && avctx->flags & CODEC_FLAG_PASS1) { + unsigned int b64_size = ((ctx->twopass_stats.sz + 2) / 3) * 4 + 1; + + avctx->stats_out = av_malloc(b64_size); + if (!avctx->stats_out) { + av_log(avctx, AV_LOG_ERROR, "Stat buffer alloc (%d bytes) failed\n", + b64_size); + return AVERROR(ENOMEM); + } + av_base64_encode(avctx->stats_out, b64_size, ctx->twopass_stats.buf, + ctx->twopass_stats.sz); + } + return coded_size; +} + +AVCodec libvpx_encoder = { + "libvpx", + AVMEDIA_TYPE_VIDEO, + CODEC_ID_VP8, + sizeof(VP8Context), + vp8_init, + vp8_encode, + vp8_free, + NULL, + CODEC_CAP_DELAY, + .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("libvpx VP8"), +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/libx264.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/libx264.c index 21334c9460..df7b2e806b 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/libx264.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/libx264.c @@ -27,16 +27,15 @@ #include typedef struct X264Context { - x264_param_t params; - x264_t *enc; - x264_picture_t pic; - uint8_t *sei; - int sei_size; - AVFrame out_pic; + x264_param_t params; + x264_t *enc; + x264_picture_t pic; + uint8_t *sei; + int sei_size; + AVFrame out_pic; } X264Context; -static void -X264_log(void *p, int level, const char *fmt, va_list args) +static void X264_log(void *p, int level, const char *fmt, va_list args) { static const int level_map[] = { [X264_LOG_ERROR] = AV_LOG_ERROR, @@ -45,48 +44,44 @@ X264_log(void *p, int level, const char *fmt, va_list args) [X264_LOG_DEBUG] = AV_LOG_DEBUG }; - if(level < 0 || level > X264_LOG_DEBUG) + if (level < 0 || level > X264_LOG_DEBUG) return; av_vlog(p, level_map[level], fmt, args); } -static int -encode_nals(AVCodecContext *ctx, uint8_t *buf, int size, x264_nal_t *nals, int nnal, int skip_sei) +static int encode_nals(AVCodecContext *ctx, uint8_t *buf, int size, + x264_nal_t *nals, int nnal, int skip_sei) { X264Context *x4 = ctx->priv_data; uint8_t *p = buf; - int i, s; + int i; /* Write the SEI as part of the first frame. */ - if(x4->sei_size > 0 && nnal > 0) - { + if (x4->sei_size > 0 && nnal > 0) { memcpy(p, x4->sei, x4->sei_size); p += x4->sei_size; x4->sei_size = 0; } - for(i = 0; i < nnal; i++){ + for (i = 0; i < nnal; i++){ /* Don't put the SEI in extradata. */ - if(skip_sei && nals[i].i_type == NAL_SEI) - { - x4->sei = av_malloc( 5 + nals[i].i_payload * 4 / 3 ); - if(x264_nal_encode(x4->sei, &x4->sei_size, 1, nals + i) < 0) - return -1; + if (skip_sei && nals[i].i_type == NAL_SEI) { + x4->sei_size = nals[i].i_payload; + x4->sei = av_malloc(x4->sei_size); + memcpy(x4->sei, nals[i].p_payload, nals[i].i_payload); continue; } - s = x264_nal_encode(p, &size, 1, nals + i); - if(s < 0) - return -1; - p += s; + memcpy(p, nals[i].p_payload, nals[i].i_payload); + p += nals[i].i_payload; } return p - buf; } -static int -X264_frame(AVCodecContext *ctx, uint8_t *buf, int bufsize, void *data) +static int X264_frame(AVCodecContext *ctx, uint8_t *buf, + int bufsize, void *data) { X264Context *x4 = ctx->priv_data; AVFrame *frame = data; @@ -94,31 +89,30 @@ X264_frame(AVCodecContext *ctx, uint8_t *buf, int bufsize, void *data) int nnal, i; x264_picture_t pic_out; - x4->pic.img.i_csp = X264_CSP_I420; + x4->pic.img.i_csp = X264_CSP_I420; x4->pic.img.i_plane = 3; if (frame) { - for(i = 0; i < 3; i++){ - x4->pic.img.plane[i] = frame->data[i]; + for (i = 0; i < 3; i++) { + x4->pic.img.plane[i] = frame->data[i]; x4->pic.img.i_stride[i] = frame->linesize[i]; } - x4->pic.i_pts = frame->pts; + x4->pic.i_pts = frame->pts; x4->pic.i_type = X264_TYPE_AUTO; } - if(x264_encoder_encode(x4->enc, &nal, &nnal, frame? &x4->pic: NULL, - &pic_out)) + if (x264_encoder_encode(x4->enc, &nal, &nnal, frame? &x4->pic: NULL, &pic_out) < 0) return -1; bufsize = encode_nals(ctx, buf, bufsize, nal, nnal, 0); - if(bufsize < 0) + if (bufsize < 0) return -1; - /* FIXME: dts */ + /* FIXME: libx264 now provides DTS, but AVFrame doesn't have a field for it. */ x4->out_pic.pts = pic_out.i_pts; - switch(pic_out.i_type){ + switch (pic_out.i_type) { case X264_TYPE_IDR: case X264_TYPE_I: x4->out_pic.pict_type = FF_I_TYPE; @@ -132,179 +126,189 @@ X264_frame(AVCodecContext *ctx, uint8_t *buf, int bufsize, void *data) break; } - x4->out_pic.key_frame = pic_out.i_type == X264_TYPE_IDR; - x4->out_pic.quality = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA; + x4->out_pic.key_frame = pic_out.b_keyframe; + x4->out_pic.quality = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA; return bufsize; } -static av_cold int -X264_close(AVCodecContext *avctx) +static av_cold int X264_close(AVCodecContext *avctx) { X264Context *x4 = avctx->priv_data; av_freep(&avctx->extradata); av_free(x4->sei); - if(x4->enc) + if (x4->enc) x264_encoder_close(x4->enc); return 0; } -static av_cold int -X264_init(AVCodecContext *avctx) +static av_cold int X264_init(AVCodecContext *avctx) { X264Context *x4 = avctx->priv_data; x4->sei_size = 0; x264_param_default(&x4->params); - x4->params.pf_log = X264_log; - x4->params.p_log_private = avctx; + x4->params.pf_log = X264_log; + x4->params.p_log_private = avctx; - x4->params.i_keyint_max = avctx->gop_size; - x4->params.rc.i_bitrate = avctx->bit_rate / 1000; + x4->params.i_keyint_max = avctx->gop_size; + x4->params.rc.i_bitrate = avctx->bit_rate / 1000; 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(avctx->crf){ - x4->params.rc.i_rc_method = X264_RC_CRF; + 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 (avctx->crf) { + x4->params.rc.i_rc_method = X264_RC_CRF; x4->params.rc.f_rf_constant = avctx->crf; - }else if(avctx->cqp > -1){ - x4->params.rc.i_rc_method = X264_RC_CQP; + } else if (avctx->cqp > -1) { + 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; + 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 = 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.b_bframe_pyramid = avctx->flags2 & CODEC_FLAG2_BPYRAMID; - avctx->has_b_frames= avctx->flags2 & CODEC_FLAG2_BPYRAMID ? 2 : !!avctx->max_b_frames; + 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; x4->params.i_keyint_min = avctx->keyint_min; - if(x4->params.i_keyint_min > x4->params.i_keyint_max) + 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; + x4->params.i_scenecut_threshold = avctx->scenechange_threshold; - x4->params.b_deblocking_filter = avctx->flags & CODEC_FLAG_LOOP_FILTER; + 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.i_deblocking_filter_beta = avctx->deblockbeta; - 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; + 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; - 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_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; + x4->params.i_frame_reference = avctx->refs; - 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 = avctx->time_base.den; - x4->params.i_fps_den = avctx->time_base.num; + 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.inter = 0; - if(avctx->partitions){ - if(avctx->partitions & X264_PART_I4X4) + x4->params.analyse.inter = 0; + if (avctx->partitions) { + if (avctx->partitions & X264_PART_I4X4) x4->params.analyse.inter |= X264_ANALYSE_I4x4; - if(avctx->partitions & X264_PART_I8X8) + if (avctx->partitions & X264_PART_I8X8) x4->params.analyse.inter |= X264_ANALYSE_I8x8; - if(avctx->partitions & X264_PART_P8X8) + if (avctx->partitions & X264_PART_P8X8) x4->params.analyse.inter |= X264_ANALYSE_PSUB16x16; - if(avctx->partitions & X264_PART_P4X4) + if (avctx->partitions & X264_PART_P4X4) x4->params.analyse.inter |= X264_ANALYSE_PSUB8x8; - if(avctx->partitions & X264_PART_B8X8) + 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.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->me_method == ME_EPZS) + if (avctx->me_method == ME_EPZS) x4->params.analyse.i_me_method = X264_ME_DIA; - else if(avctx->me_method == ME_HEX) + else if (avctx->me_method == ME_HEX) x4->params.analyse.i_me_method = X264_ME_HEX; - else if(avctx->me_method == ME_UMH) + else if (avctx->me_method == ME_UMH) x4->params.analyse.i_me_method = X264_ME_UMH; - else if(avctx->me_method == ME_FULL) + else if (avctx->me_method == ME_FULL) x4->params.analyse.i_me_method = X264_ME_ESA; - else if(avctx->me_method == ME_TESA) + 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.analyse.i_me_range = avctx->me_range; - x4->params.analyse.i_subpel_refine = avctx->me_subpel_quality; + 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_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.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_trellis = avctx->trellis; - x4->params.analyse.i_noise_reduction = avctx->noise_reduction; + x4->params.analyse.i_me_range = avctx->me_range; + x4->params.analyse.i_subpel_refine = avctx->me_subpel_quality; - if(avctx->level > 0) x4->params.i_level_idc = avctx->level; + 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; x4->params.rc.f_rate_tolerance = (float)avctx->bit_rate_tolerance/avctx->bit_rate; - if((avctx->rc_buffer_size != 0) && - (avctx->rc_initial_buffer_occupancy <= avctx->rc_buffer_size)){ + if ((avctx->rc_buffer_size != 0) && + (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; - } - else x4->params.rc.f_vbv_buffer_init = 0.9; + (float)avctx->rc_initial_buffer_occupancy / avctx->rc_buffer_size; + } else + x4->params.rc.f_vbv_buffer_init = 0.9; - x4->params.rc.f_ip_factor = 1/fabs(avctx->i_quant_factor); - x4->params.rc.f_pb_factor = avctx->b_quant_factor; + 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 = X264_LOG_DEBUG; + 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.b_aud = avctx->flags2 & CODEC_FLAG2_AUD; - x4->params.i_threads = avctx->thread_count; + x4->params.i_threads = avctx->thread_count; - x4->params.b_interlaced = avctx->flags & CODEC_FLAG_INTERLACED_DCT; + x4->params.b_interlaced = avctx->flags & CODEC_FLAG_INTERLACED_DCT; - if(avctx->flags & CODEC_FLAG_GLOBAL_HEADER){ + if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) x4->params.b_repeat_headers = 0; - } x4->enc = x264_encoder_open(&x4->params); - if(!x4->enc) + if (!x4->enc) return -1; avctx->coded_frame = &x4->out_pic; - if(avctx->flags & CODEC_FLAG_GLOBAL_HEADER){ + if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) { x264_nal_t *nal; - int nnal, i, s = 0; + int nnal, s, i; - x264_encoder_headers(x4->enc, &nal, &nnal); + s = x264_encoder_headers(x4->enc, &nal, &nnal); - /* 5 bytes NAL header + worst case escaping */ - for(i = 0; i < nnal; i++) - s += 5 + nal[i].i_payload * 4 / 3; + for (i = 0; i < nnal; i++) + if (nal[i].i_type == NAL_SEI) + av_log(avctx, AV_LOG_INFO, "%s\n", nal[i].p_payload+25); - avctx->extradata = av_malloc(s); + avctx->extradata = av_malloc(s); avctx->extradata_size = encode_nals(avctx, avctx->extradata, s, nal, nnal, 1); } @@ -312,14 +316,14 @@ X264_init(AVCodecContext *avctx) } AVCodec libx264_encoder = { - .name = "libx264", - .type = CODEC_TYPE_VIDEO, - .id = CODEC_ID_H264, + .name = "libx264", + .type = AVMEDIA_TYPE_VIDEO, + .id = CODEC_ID_H264, .priv_data_size = sizeof(X264Context), - .init = X264_init, - .encode = X264_frame, - .close = X264_close, - .capabilities = CODEC_CAP_DELAY, - .pix_fmts = (enum PixelFormat[]) { PIX_FMT_YUV420P, PIX_FMT_NONE }, - .long_name = NULL_IF_CONFIG_SMALL("libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"), + .init = X264_init, + .encode = X264_frame, + .close = X264_close, + .capabilities = CODEC_CAP_DELAY, + .pix_fmts = (const enum PixelFormat[]) { PIX_FMT_YUV420P, PIX_FMT_NONE }, + .long_name = NULL_IF_CONFIG_SMALL("libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"), }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/libxvid_internal.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/libxvid_internal.h index 11a1a2e736..ffa5cf8d2c 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/libxvid_internal.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/libxvid_internal.h @@ -22,7 +22,7 @@ #define AVCODEC_LIBXVID_INTERNAL_H /** - * @file libavcodec/libxvid_internal.h + * @file * common functions for use with the Xvid wrappers */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/libxvidff.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/libxvidff.c index bdf70a09df..2a404cd5f9 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/libxvidff.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/libxvidff.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/libxvidff.c + * @file * Interface to xvidcore for MPEG-4 compliant encoding. * @author Adam Thayer (krevnik@comcast.net) */ @@ -82,7 +82,7 @@ void xvid_correct_framerate(AVCodecContext *avctx); * @param avctx AVCodecContext pointer to context * @return Returns 0 on success, -1 on failure */ -av_cold int ff_xvid_encode_init(AVCodecContext *avctx) { +static av_cold int xvid_encode_init(AVCodecContext *avctx) { int xerr, i; int xvid_flags = avctx->flags; struct xvid_context *x = avctx->priv_data; @@ -367,7 +367,7 @@ av_cold int ff_xvid_encode_init(AVCodecContext *avctx) { * @param data Pointer to AVFrame of unencoded frame * @return Returns 0 on success, -1 on failure */ -int ff_xvid_encode_frame(AVCodecContext *avctx, +static int xvid_encode_frame(AVCodecContext *avctx, unsigned char *frame, int buf_size, void *data) { int xerr, i; char *tmp; @@ -475,13 +475,13 @@ int ff_xvid_encode_frame(AVCodecContext *avctx, * @param avctx AVCodecContext pointer to context * @return Returns 0, success guaranteed */ -av_cold int ff_xvid_encode_close(AVCodecContext *avctx) { +static av_cold int xvid_encode_close(AVCodecContext *avctx) { struct xvid_context *x = avctx->priv_data; xvid_encore(x->encoder_handle, XVID_ENC_DESTROY, NULL, NULL); if( avctx->extradata != NULL ) - av_free(avctx->extradata); + av_freep(&avctx->extradata); if( x->twopassbuffer != NULL ) { av_free(x->twopassbuffer); av_free(x->old_twopassbuffer); @@ -769,12 +769,12 @@ int xvid_ff_2pass(void *ref, int cmd, void *p1, void *p2) { */ AVCodec libxvid_encoder = { "libxvid", - CODEC_TYPE_VIDEO, - CODEC_ID_XVID, + AVMEDIA_TYPE_VIDEO, + CODEC_ID_MPEG4, sizeof(struct xvid_context), - ff_xvid_encode_init, - ff_xvid_encode_frame, - ff_xvid_encode_close, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, + xvid_encode_init, + xvid_encode_frame, + 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/src/add-ons/media/plugins/ffmpeg/libavcodec/ljpegenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/ljpegenc.c index 6c9f058dce..2ef07c3a32 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/ljpegenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ljpegenc.c @@ -26,7 +26,7 @@ */ /** - * @file libavcodec/ljpegenc.c + * @file * lossless JPEG encoder. */ @@ -56,7 +56,7 @@ static int encode_picture_lossless(AVCodecContext *avctx, unsigned char *buf, in s->header_bits= put_bits_count(&s->pb); - if(avctx->pix_fmt == PIX_FMT_RGB32){ + if(avctx->pix_fmt == PIX_FMT_BGRA){ int x, y, i; const int linesize= p->linesize[0]; uint16_t (*buffer)[4]= (void *) s->rd_scratchpad; @@ -188,7 +188,7 @@ static int encode_picture_lossless(AVCodecContext *avctx, unsigned char *buf, in AVCodec ljpeg_encoder = { //FIXME avoid MPV_* lossless JPEG should not need them "ljpeg", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_LJPEG, sizeof(MpegEncContext), MPV_encode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/loco.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/loco.c index 4fd64f4bda..d19a80cf34 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/loco.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/loco.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/loco.c + * @file * LOCO codec. */ @@ -275,14 +275,24 @@ static av_cold int decode_init(AVCodecContext *avctx){ return 0; } +static av_cold int decode_end(AVCodecContext *avctx){ + LOCOContext * const l = avctx->priv_data; + AVFrame *pic = &l->pic; + + if (pic->data[0]) + avctx->release_buffer(avctx, pic); + + return 0; +} + AVCodec loco_decoder = { "loco", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_LOCO, sizeof(LOCOContext), decode_init, NULL, - NULL, + decode_end, decode_frame, CODEC_CAP_DR1, .long_name = NULL_IF_CONFIG_SMALL("LOCO"), diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/lpc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/lpc.c index 896db51759..49e41d8c34 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/lpc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/lpc.c @@ -26,6 +26,68 @@ #include "lpc.h" +/** + * Apply Welch window function to audio block + */ +static void apply_welch_window(const int32_t *data, int len, double *w_data) +{ + int i, n2; + double w; + double c; + + assert(!(len&1)); //the optimization in r11881 does not support odd len + //if someone wants odd len extend the change in r11881 + + n2 = (len >> 1); + c = 2.0 / (len - 1.0); + + w_data+=n2; + data+=n2; + for(i=0; i= MIN_LPC_ORDER && max_order <= MAX_LPC_ORDER && use_lpc > 0); if(use_lpc == 1){ - s->flac_compute_autocorr(samples, blocksize, max_order, autoc); + s->lpc_compute_autocorr(samples, blocksize, max_order, autoc); compute_lpc_coefs(autoc, max_order, &lpc[0][0], MAX_LPC_ORDER, 0, 1); diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/lpc.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/lpc.h index 05a1deea67..d3754f04d2 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/lpc.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/lpc.h @@ -45,6 +45,9 @@ int ff_lpc_calc_coefs(DSPContext *s, int32_t coefs[][MAX_LPC_ORDER], int *shift, int use_lpc, int omethod, int max_shift, int zero_shift); +void ff_lpc_compute_autocorr(const int32_t *data, int len, int lag, + double *autoc); + #ifdef LPC_USE_DOUBLE #define LPC_TYPE double #else diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/lsp.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/lsp.c index 5b5fc1c50e..003ffbc634 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/lsp.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/lsp.c @@ -47,6 +47,14 @@ void ff_acelp_reorder_lsf(int16_t* lsfq, int lsfq_min_distance, int lsfq_min, in lsfq[lp_order-1] = FFMIN(lsfq[lp_order-1], lsfq_max);//Is warning required ? } +void ff_set_min_dist_lsf(float *lsf, double min_spacing, int size) +{ + int i; + float prev = 0.0; + for (i = 0; i < size; i++) + prev = lsf[i] = FFMAX(lsf[i], prev + min_spacing); +} + void ff_acelp_lsf2lsp(int16_t *lsp, const int16_t *lsf, int lp_order) { int i; @@ -120,17 +128,7 @@ void ff_acelp_lp_decode(int16_t* lp_1st, int16_t* lp_2nd, const int16_t* lsp_2nd ff_acelp_lsp2lpc(lp_2nd, lsp_2nd, lp_order >> 1); } -/** - * Computes the Pa / (1 + z(-1)) or Qa / (1 - z(-1)) coefficients - * needed for LSP to LPC conversion. - * We only need to calculate the 6 first elements of the polynomial. - * - * @param lsp line spectral pairs in cosine domain - * @param f [out] polynomial input/output as a vector - * - * TIA/EIA/IS-733 2.4.3.3.5-1/2 - */ -static void lsp2polyf(const double *lsp, double *f, int lp_half_order) +void ff_lsp2polyf(const double *lsp, double *f, int lp_half_order) { int i, j; @@ -147,20 +145,30 @@ static void lsp2polyf(const double *lsp, double *f, int lp_half_order) } } -void ff_acelp_lspd2lpc(const double *lsp, float *lpc) +void ff_acelp_lspd2lpc(const double *lsp, float *lpc, int lp_half_order) { - double pa[6], qa[6]; - int i; + double pa[MAX_LP_HALF_ORDER+1], qa[MAX_LP_HALF_ORDER+1]; + float *lpc2 = lpc + (lp_half_order << 1) - 1; - lsp2polyf(lsp, pa, 5); - lsp2polyf(lsp + 1, qa, 5); + assert(lp_half_order <= MAX_LP_HALF_ORDER); - for (i=4; i>=0; i--) - { - double paf = pa[i+1] + pa[i]; - double qaf = qa[i+1] - qa[i]; + ff_lsp2polyf(lsp, pa, lp_half_order); + ff_lsp2polyf(lsp + 1, qa, lp_half_order); - lpc[i ] = 0.5*(paf+qaf); - lpc[9-i] = 0.5*(paf-qaf); + while (lp_half_order--) { + double paf = pa[lp_half_order+1] + pa[lp_half_order]; + double qaf = qa[lp_half_order+1] - qa[lp_half_order]; + + lpc [ lp_half_order] = 0.5*(paf+qaf); + lpc2[-lp_half_order] = 0.5*(paf-qaf); } } + +void ff_sort_nearly_sorted_floats(float *vals, int len) +{ + int i,j; + + for (i = 0; i < len - 1; i++) + for (j = i; j >= 0 && vals[j] > vals[j+1]; j--) + FFSWAP(float, vals[j], vals[j+1]); +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/lsp.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/lsp.h index 0fa585016a..c3aee7b7dc 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/lsp.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/lsp.h @@ -39,6 +39,19 @@ */ void ff_acelp_reorder_lsf(int16_t* lsfq, int lsfq_min_distance, int lsfq_min, int lsfq_max, int lp_order); +/** + * Adjust the quantized LSFs so they are increasing and not too close. + * + * This step is not mentioned in the AMR spec but is in the reference C decoder. + * Omitting this step creates audible distortion on the sinusoidal sweep + * test vectors in 3GPP TS 26.074. + * + * @param[in,out] lsf LSFs in Hertz + * @param min_spacing minimum distance between two consecutive lsf values + * @param size size of the lsf vector + */ +void ff_set_min_dist_lsf(float *lsf, double min_spacing, int order); + /** * \brief Convert LSF to LSP * \param lsp [out] LSP coefficients (-0x8000 <= (0.15) < 0x8000) @@ -67,14 +80,40 @@ void ff_acelp_lsp2lpc(int16_t* lp, const int16_t* lsp, int lp_half_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 + /** * Reconstructs LPC coefficients from the line spectral pair frequencies. * * @param lsp line spectral pairs in cosine domain * @param lpc linear predictive coding coefficients + * @param lp_half_order half the number of the amount of LPCs to be + * reconstructed, need to be smaller or equal to MAX_LP_HALF_ORDER + * + * @note buffers should have a minimux size of 2*lp_half_order elements. * * TIA/EIA/IS-733 2.4.3.3.5 */ -void ff_acelp_lspd2lpc(const double *lsp, float *lpc); +void ff_acelp_lspd2lpc(const double *lsp, float *lpc, int lp_half_order); + +/** + * Sort values in ascending order. + * + * @note O(n) if data already sorted, O(n^2) - otherwise + */ +void ff_sort_nearly_sorted_floats(float *vals, int len); + +/** + * Computes the Pa / (1 + z(-1)) or Qa / (1 - z(-1)) coefficients + * needed for LSP to LPC conversion. + * We only need to calculate the 6 first elements of the polynomial. + * + * @param lsp line spectral pairs in cosine domain + * @param f [out] polynomial input/output as a vector + * + * TIA/EIA/IS-733 2.4.3.3.5-1/2 + */ +void ff_lsp2polyf(const double *lsp, double *f, int lp_half_order); #endif /* AVCODEC_LSP_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/lzw.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/lzw.c index 0447225834..8043789d56 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/lzw.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/lzw.c @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/lzw.c + * @file * @brief LZW decoding routines * @author Fabrice Bellard * Modified for use in TIFF by Konstantin Shishkov diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/lzw.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/lzw.h index 601d01fd67..76a5b6752e 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/lzw.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/lzw.h @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/lzw.h + * @file * @brief LZW decoding routines * @author Fabrice Bellard * Modified for use in TIFF by Konstantin Shishkov @@ -30,7 +30,9 @@ #ifndef AVCODEC_LZW_H #define AVCODEC_LZW_H -#include "get_bits.h" +#include + +struct PutBitContext; enum FF_LZW_MODES{ FF_LZW_GIF, @@ -52,8 +54,11 @@ void ff_lzw_decode_tail(LZWState *lzw); struct LZWEncodeState; extern const int ff_lzw_encode_state_size; -void ff_lzw_encode_init(struct LZWEncodeState * s, uint8_t * outbuf, int outsize, int maxbits); +void ff_lzw_encode_init(struct LZWEncodeState *s, uint8_t *outbuf, int outsize, + int maxbits, enum FF_LZW_MODES mode, + void (*lzw_put_bits)(struct PutBitContext *, int, unsigned int)); int ff_lzw_encode(struct LZWEncodeState * s, const uint8_t * inbuf, int insize); -int ff_lzw_encode_flush(struct LZWEncodeState * s); +int ff_lzw_encode_flush(struct LZWEncodeState *s, + void (*lzw_flush_put_bits)(struct PutBitContext *)); #endif /* AVCODEC_LZW_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/lzwenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/lzwenc.c index f3f66833a1..23248a6034 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/lzwenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/lzwenc.c @@ -21,7 +21,7 @@ /** * LZW encoder - * @file libavcodec/lzwenc.c + * @file * @author Bartlomiej Wolowiec */ @@ -58,6 +58,8 @@ typedef struct LZWEncodeState { int maxcode; ///< Max value of code int output_bytes; ///< Number of written bytes int last_code; ///< Value of last output code or LZW_PREFIX_EMPTY + enum FF_LZW_MODES mode; ///< TIFF or GIF + void (*put_bits)(PutBitContext *, int, unsigned); ///< GIF is LE while TIFF is BE }LZWEncodeState; @@ -110,7 +112,7 @@ static inline int hashOffset(const int head) static inline void writeCode(LZWEncodeState * s, int c) { assert(0 <= c && c < 1 << s->bits); - put_bits(&s->pb, s->bits, c); + s->put_bits(&s->pb, s->bits, c); } @@ -151,7 +153,7 @@ static inline void addCode(LZWEncodeState * s, uint8_t c, int hash_prefix, int h s->tabsize++; - if (s->tabsize >= 1 << s->bits) + if (s->tabsize >= (1 << s->bits) + (s->mode == FF_LZW_GIF)) s->bits++; } @@ -196,7 +198,9 @@ static int writtenBytes(LZWEncodeState *s){ * @param outsize Size of output buffer * @param maxbits Maximum length of code */ -void ff_lzw_encode_init(LZWEncodeState * s, uint8_t * outbuf, int outsize, int maxbits) +void ff_lzw_encode_init(LZWEncodeState *s, uint8_t *outbuf, int outsize, + int maxbits, enum FF_LZW_MODES mode, + void (*lzw_put_bits)(PutBitContext *, int, unsigned)) { s->clear_code = 256; s->end_code = 257; @@ -208,6 +212,8 @@ void ff_lzw_encode_init(LZWEncodeState * s, uint8_t * outbuf, int outsize, int m s->output_bytes = 0; s->last_code = LZW_PREFIX_EMPTY; s->bits = 9; + s->mode = mode; + s->put_bits = lzw_put_bits; } /** @@ -250,12 +256,13 @@ int ff_lzw_encode(LZWEncodeState * s, const uint8_t * inbuf, int insize) * @param s LZW state * @return Number of bytes written or -1 on error */ -int ff_lzw_encode_flush(LZWEncodeState * s) +int ff_lzw_encode_flush(LZWEncodeState *s, + void (*lzw_flush_put_bits)(PutBitContext *)) { if (s->last_code != -1) writeCode(s, s->last_code); writeCode(s, s->end_code); - flush_put_bits(&s->pb); + lzw_flush_put_bits(&s->pb); s->last_code = -1; return writtenBytes(s); diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mace.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mace.c index ae7b4dc833..3c71320d54 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mace.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mace.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/mace.c + * @file * MACE decoder. */ @@ -281,7 +281,7 @@ static int mace_decode_frame(AVCodecContext *avctx, AVCodec mace3_decoder = { "mace3", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_MACE3, sizeof(MACEContext), mace_decode_init, @@ -293,7 +293,7 @@ AVCodec mace3_decoder = { AVCodec mace6_decoder = { "mace6", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_MACE6, sizeof(MACEContext), mace_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mathops.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/mathops.h index 4e24350ef2..149910bb1d 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mathops.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mathops.h @@ -53,6 +53,12 @@ static av_always_inline int MULH(int a, int b){ } #endif +#ifndef UMULH +static av_always_inline unsigned UMULH(unsigned a, unsigned b){ + return ((uint64_t)(a) * (uint64_t)(b))>>32; +} +#endif + #ifndef MUL64 # define MUL64(a,b) ((int64_t)(a) * (int64_t)(b)) #endif @@ -116,5 +122,29 @@ static inline av_const int sign_extend(int val, unsigned bits) } #endif +#ifndef zero_extend +static inline av_const unsigned zero_extend(unsigned val, unsigned bits) +{ + return (val << (INT_BIT - bits)) >> (INT_BIT - bits); +} +#endif + +#ifndef COPY3_IF_LT +#define COPY3_IF_LT(x, y, a, b, c, d)\ +if ((y) < (x)) {\ + (x) = (y);\ + (a) = (b);\ + (c) = (d);\ +} +#endif + +#ifndef NEG_SSR32 +# define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s))) +#endif + +#ifndef NEG_USR32 +# define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s))) +#endif + #endif /* AVCODEC_MATHOPS_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mdct.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mdct.c index 8a42adb4f3..69e1bbff22 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mdct.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mdct.c @@ -18,10 +18,15 @@ * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "dsputil.h" + +#include +#include +#include "libavutil/common.h" +#include "libavutil/mathematics.h" +#include "fft.h" /** - * @file libavcodec/mdct.c + * @file * MDCT/IMDCT transforms. */ @@ -48,56 +53,54 @@ av_cold void ff_kbd_window_init(float *window, float alpha, int n) window[i] = sqrt(local_window[i] / sum); } -DECLARE_ALIGNED(16, float, ff_sine_128 [ 128]); -DECLARE_ALIGNED(16, float, ff_sine_256 [ 256]); -DECLARE_ALIGNED(16, float, ff_sine_512 [ 512]); -DECLARE_ALIGNED(16, float, ff_sine_1024[1024]); -DECLARE_ALIGNED(16, float, ff_sine_2048[2048]); -DECLARE_ALIGNED(16, float, ff_sine_4096[4096]); -float *ff_sine_windows[6] = { - ff_sine_128, ff_sine_256, ff_sine_512, ff_sine_1024, ff_sine_2048, ff_sine_4096 -}; - -// Generate a sine window. -av_cold void ff_sine_window_init(float *window, int n) { - int i; - for(i = 0; i < n; i++) - window[i] = sinf((i + 0.5) * (M_PI / (2.0 * n))); -} +#include "mdct_tablegen.h" /** * init MDCT or IMDCT computation. */ -av_cold int ff_mdct_init(MDCTContext *s, int nbits, int inverse, double scale) +av_cold int ff_mdct_init(FFTContext *s, int nbits, int inverse, double scale) { int n, n4, i; double alpha, theta; + int tstep; memset(s, 0, sizeof(*s)); n = 1 << nbits; - s->nbits = nbits; - s->n = n; + s->mdct_bits = nbits; + s->mdct_size = n; n4 = n >> 2; - s->tcos = av_malloc(n4 * sizeof(FFTSample)); + s->permutation = FF_MDCT_PERM_NONE; + + if (ff_fft_init(s, s->mdct_bits - 2, inverse) < 0) + goto fail; + + s->tcos = av_malloc(n/2 * sizeof(FFTSample)); if (!s->tcos) goto fail; - s->tsin = av_malloc(n4 * sizeof(FFTSample)); - if (!s->tsin) + + switch (s->permutation) { + case FF_MDCT_PERM_NONE: + s->tsin = s->tcos + n4; + tstep = 1; + break; + case FF_MDCT_PERM_INTERLEAVE: + s->tsin = s->tcos + 1; + tstep = 2; + break; + default: goto fail; + } theta = 1.0 / 8.0 + (scale < 0 ? n4 : 0); scale = sqrt(fabs(scale)); for(i=0;itcos[i] = -cos(alpha) * scale; - s->tsin[i] = -sin(alpha) * scale; + s->tcos[i*tstep] = -cos(alpha) * scale; + s->tsin[i*tstep] = -sin(alpha) * scale; } - if (ff_fft_init(&s->fft, s->nbits - 2, inverse) < 0) - goto fail; return 0; fail: - av_freep(&s->tcos); - av_freep(&s->tsin); + ff_mdct_end(s); return -1; } @@ -118,16 +121,16 @@ av_cold int ff_mdct_init(MDCTContext *s, int nbits, int inverse, double scale) * @param output N/2 samples * @param input N/2 samples */ -void ff_imdct_half_c(MDCTContext *s, FFTSample *output, const FFTSample *input) +void ff_imdct_half_c(FFTContext *s, FFTSample *output, const FFTSample *input) { int k, n8, n4, n2, n, j; - const uint16_t *revtab = s->fft.revtab; + const uint16_t *revtab = s->revtab; const FFTSample *tcos = s->tcos; const FFTSample *tsin = s->tsin; const FFTSample *in1, *in2; FFTComplex *z = (FFTComplex *)output; - n = 1 << s->nbits; + n = 1 << s->mdct_bits; n2 = n >> 1; n4 = n >> 2; n8 = n >> 3; @@ -141,7 +144,7 @@ void ff_imdct_half_c(MDCTContext *s, FFTSample *output, const FFTSample *input) in1 += 2; in2 -= 2; } - ff_fft_calc(&s->fft, z); + ff_fft_calc(s, z); /* post rotation + reordering */ for(k = 0; k < n8; k++) { @@ -160,10 +163,10 @@ void ff_imdct_half_c(MDCTContext *s, FFTSample *output, const FFTSample *input) * @param output N samples * @param input N/2 samples */ -void ff_imdct_calc_c(MDCTContext *s, FFTSample *output, const FFTSample *input) +void ff_imdct_calc_c(FFTContext *s, FFTSample *output, const FFTSample *input) { int k; - int n = 1 << s->nbits; + int n = 1 << s->mdct_bits; int n2 = n >> 1; int n4 = n >> 2; @@ -180,16 +183,16 @@ void ff_imdct_calc_c(MDCTContext *s, FFTSample *output, const FFTSample *input) * @param input N samples * @param out N/2 samples */ -void ff_mdct_calc(MDCTContext *s, FFTSample *out, const FFTSample *input) +void ff_mdct_calc_c(FFTContext *s, FFTSample *out, const FFTSample *input) { int i, j, n, n8, n4, n2, n3; FFTSample re, im; - const uint16_t *revtab = s->fft.revtab; + const uint16_t *revtab = s->revtab; const FFTSample *tcos = s->tcos; const FFTSample *tsin = s->tsin; FFTComplex *x = (FFTComplex *)out; - n = 1 << s->nbits; + n = 1 << s->mdct_bits; n2 = n >> 1; n4 = n >> 2; n8 = n >> 3; @@ -208,7 +211,7 @@ void ff_mdct_calc(MDCTContext *s, FFTSample *out, const FFTSample *input) CMUL(x[j].re, x[j].im, re, im, -tcos[n8 + i], tsin[n8 + i]); } - ff_fft_calc(&s->fft, x); + ff_fft_calc(s, x); /* post rotation */ for(i=0;itcos); - av_freep(&s->tsin); - ff_fft_end(&s->fft); + ff_fft_end(s); } diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mdct_tablegen.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mdct_tablegen.c new file mode 100644 index 0000000000..6205f06e3c --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mdct_tablegen.c @@ -0,0 +1,49 @@ +/* + * Generate a header file for hardcoded MDCT tables + * + * Copyright (c) 2009 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 +#define CONFIG_HARDCODED_TABLES 0 +#define SINETABLE_CONST +#define SINETABLE(size) \ + float ff_sine_##size[size] +#define FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0])) +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif +#include "mdct_tablegen.h" +#include "tableprint.h" + +int main(void) +{ + int i; + + write_fileheader(); + + for (i = 5; i <= 12; i++) { + ff_init_ff_sine_windows(i); + printf("SINETABLE(%4i) = {\n", 1 << i); + write_float_array(ff_sine_windows[i], 1 << i); + printf("};\n"); + } + + return 0; +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mdct_tablegen.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/mdct_tablegen.h new file mode 100644 index 0000000000..1722c3b4d0 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mdct_tablegen.h @@ -0,0 +1,60 @@ +/* + * Header file for hardcoded MDCT tables + * + * Copyright (c) 2009 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 +// do not use libavutil/mathematics.h since this is compiled both +// for the host and the target and config.h is only valid for the target +#include +#include "../libavutil/attributes.h" + +#if !CONFIG_HARDCODED_TABLES +SINETABLE( 32); +SINETABLE( 64); +SINETABLE( 128); +SINETABLE( 256); +SINETABLE( 512); +SINETABLE(1024); +SINETABLE(2048); +SINETABLE(4096); +#else +#include "libavcodec/mdct_tables.h" +#endif + +SINETABLE_CONST float * const ff_sine_windows[] = { + NULL, NULL, NULL, NULL, NULL, // unused + ff_sine_32 , ff_sine_64 , + ff_sine_128, ff_sine_256, ff_sine_512, ff_sine_1024, ff_sine_2048, ff_sine_4096 +}; + +// Generate a sine window. +av_cold void ff_sine_window_init(float *window, int n) { + int i; + for(i = 0; i < n; i++) + window[i] = sinf((i + 0.5) * (M_PI / (2.0 * n))); +} + +av_cold void ff_init_ff_sine_windows(int index) { + assert(index >= 0 && index < FF_ARRAY_ELEMS(ff_sine_windows)); +#if !CONFIG_HARDCODED_TABLES + ff_sine_window_init(ff_sine_windows[index], 1 << index); +#endif +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mdec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mdec.c index e0281ef16a..606a749695 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mdec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mdec.c @@ -22,7 +22,7 @@ */ /** - * @file libavcodec/mdec.c + * @file * Sony PlayStation MDEC (Motion DECoder) * This is very similar to intra-only MPEG-1. */ @@ -44,9 +44,7 @@ typedef struct MDECContext{ int mb_width; int mb_height; int mb_x, mb_y; - DECLARE_ALIGNED_16(DCTELEM, block[6][64]); - DECLARE_ALIGNED_8(uint16_t, intra_matrix[64]); - DECLARE_ALIGNED_8(int, q_intra_matrix[64]); + DECLARE_ALIGNED(16, DCTELEM, block)[6][64]; uint8_t *bitstream_buffer; unsigned int bitstream_buffer_size; int block_last_index[6]; @@ -203,7 +201,7 @@ static int decode_frame(AVCodecContext *avctx, } p->quality= a->qscale * FF_QP2LAMBDA; - memset(p->qscale_table, a->qscale, p->qstride*a->mb_height); + memset(p->qscale_table, a->qscale, a->mb_width); *picture = a->picture; *data_size = sizeof(AVPicture); @@ -231,8 +229,8 @@ static av_cold int decode_init(AVCodecContext *avctx){ ff_mpeg12_init_vlcs(); ff_init_scantable(a->dsp.idct_permutation, &a->scantable, ff_zigzag_direct); - p->qstride= a->mb_width; - p->qscale_table= av_mallocz( p->qstride * a->mb_height); + p->qstride= 0; + p->qscale_table= av_mallocz(a->mb_width); avctx->pix_fmt= PIX_FMT_YUV420P; return 0; @@ -241,6 +239,8 @@ static av_cold int decode_init(AVCodecContext *avctx){ static av_cold int decode_end(AVCodecContext *avctx){ MDECContext * const a = avctx->priv_data; + if(a->picture.data[0]) + avctx->release_buffer(avctx, &a->picture); av_freep(&a->bitstream_buffer); av_freep(&a->picture.qscale_table); a->bitstream_buffer_size=0; @@ -250,7 +250,7 @@ static av_cold int decode_end(AVCodecContext *avctx){ AVCodec mdec_decoder = { "mdec", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_MDEC, sizeof(MDECContext), decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mimic.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mimic.c index a0af430c76..e5f7123e94 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mimic.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mimic.c @@ -45,7 +45,7 @@ typedef struct { AVFrame buf_ptrs [16]; AVPicture flipped_ptrs[16]; - DECLARE_ALIGNED_16(DCTELEM, dct_block[64]); + DECLARE_ALIGNED(16, DCTELEM, dct_block)[64]; GetBitContext gb; ScanTable scantable; @@ -380,7 +380,7 @@ static av_cold int mimic_decode_end(AVCodecContext *avctx) AVCodec mimic_decoder = { "mimic", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_MIMIC, sizeof(MimicContext), mimic_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpeg.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpeg.c index 196beaa7dc..6eba27da0b 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpeg.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpeg.c @@ -26,7 +26,7 @@ */ /** - * @file libavcodec/mjpeg.c + * @file * MJPEG encoder and decoder. */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpeg.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpeg.h index c556cb2366..3c88471bab 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpeg.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpeg.h @@ -26,7 +26,7 @@ */ /** - * @file libavcodec/mjpeg.h + * @file * MJPEG encoder and decoder. */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpeg_parser.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpeg_parser.c index ce824a6871..b1848fac51 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpeg_parser.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpeg_parser.c @@ -22,7 +22,7 @@ */ /** - * @file libavcodec/mjpeg_parser.c + * @file * MJPEG parser. */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpega_dump_header_bsf.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpega_dump_header_bsf.c index 9215450802..bb7858e498 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpega_dump_header_bsf.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpega_dump_header_bsf.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/mjpega_dump_header_bsf.c + * @file * MJPEG A dump header bitstream filter * modifies bitstream to be decoded by quicktime */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpegbdec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpegbdec.c index 185e7bb55c..b418f5734c 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpegbdec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpegbdec.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/mjpegbdec.c + * @file * Apple MJPEG-B decoder. */ @@ -147,7 +147,7 @@ read_header: AVCodec mjpegb_decoder = { "mjpegb", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_MJPEGB, sizeof(MJpegDecodeContext), ff_mjpeg_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpegdec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpegdec.c index ad4187b121..7f57af905c 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpegdec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpegdec.c @@ -26,7 +26,7 @@ */ /** - * @file libavcodec/mjpegdec.c + * @file * MJPEG decoder. */ @@ -105,6 +105,8 @@ av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx) av_log(avctx, AV_LOG_DEBUG, "mjpeg bottom field first\n"); } } + if (avctx->codec->id == CODEC_ID_AMV) + s->flipped = 1; return 0; } @@ -290,15 +292,16 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) (s->h_count[2] << 12) | (s->v_count[2] << 8) | (s->h_count[3] << 4) | s->v_count[3]; av_log(s->avctx, AV_LOG_DEBUG, "pix fmt id %x\n", pix_fmt_id); - if(!(pix_fmt_id & 0x10101010)) + //NOTE we do not allocate pictures large enough for the possible padding of h/v_count being 4 + if(!(pix_fmt_id & 0xD0D0D0D0)) pix_fmt_id-= (pix_fmt_id & 0xF0F0F0F0)>>1; - if(!(pix_fmt_id & 0x01010101)) + if(!(pix_fmt_id & 0x0D0D0D0D)) pix_fmt_id-= (pix_fmt_id & 0x0F0F0F0F)>>1; switch(pix_fmt_id){ case 0x11111100: if(s->rgb){ - s->avctx->pix_fmt = PIX_FMT_RGB32; + s->avctx->pix_fmt = PIX_FMT_BGRA; }else s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV444P : PIX_FMT_YUVJ444P; assert(s->nb_components==3); @@ -614,13 +617,13 @@ static int decode_block_refinement(MJpegDecodeContext *s, DCTELEM *block, uint8_ static int ljpeg_decode_rgb_scan(MJpegDecodeContext *s, int predictor, int point_transform){ int i, mb_x, mb_y; - uint16_t buffer[32768][4]; + uint16_t (*buffer)[4]; int left[3], top[3], topleft[3]; const int linesize= s->linesize[0]; const int mask= (1<bits)-1; - if((unsigned)s->mb_width > 32768) //dynamic alloc - return -1; + av_fast_malloc(&s->ljpeg_buffer, &s->ljpeg_buffer_size, (unsigned)s->mb_width * 4 * sizeof(s->ljpeg_buffer[0][0])); + buffer= s->ljpeg_buffer; for(i=0; i<3; i++){ buffer[0][i]= 1 << (s->bits + point_transform - 1); @@ -671,9 +674,9 @@ static int ljpeg_decode_rgb_scan(MJpegDecodeContext *s, int predictor, int point } }else{ for(mb_x = 0; mb_x < s->mb_width; mb_x++) { - ptr[4*mb_x+0] = buffer[mb_x][0]; + ptr[4*mb_x+0] = buffer[mb_x][2]; ptr[4*mb_x+1] = buffer[mb_x][1]; - ptr[4*mb_x+2] = buffer[mb_x][2]; + ptr[4*mb_x+2] = buffer[mb_x][0]; } } } @@ -768,14 +771,17 @@ static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int Ah, i uint8_t* data[MAX_COMPONENTS]; int linesize[MAX_COMPONENTS]; + if(s->flipped && s->avctx->flags & CODEC_FLAG_EMU_EDGE) { + av_log(s->avctx, AV_LOG_ERROR, "Can not flip image with CODEC_FLAG_EMU_EDGE set!\n"); + s->flipped = 0; + } for(i=0; i < nb_components; i++) { int c = s->comp_index[i]; data[c] = s->picture.data[c]; linesize[c]=s->linesize[c]; s->coefs_finished[c] |= 1; - if(s->avctx->codec->id==CODEC_ID_AMV) { + if(s->flipped) { //picture should be flipped upside-down for this codec - assert(!(s->avctx->flags & CODEC_FLAG_EMU_EDGE)); data[c] += (linesize[c] * (s->v_scount[i] * (8 * s->mb_height -((s->height/s->v_max)&7)) - 1 )); linesize[c] *= -1; } @@ -893,6 +899,10 @@ int ff_mjpeg_decode_sos(MJpegDecodeContext *s) /* XXX: verify len field validity */ len = get_bits(&s->gb, 16); nb_components = get_bits(&s->gb, 8); + if (nb_components == 0 || nb_components > MAX_COMPONENTS){ + av_log(s->avctx, AV_LOG_ERROR, "decode_sos: nb_components (%d) unsupported\n", nb_components); + return -1; + } if (len != 6+2*nb_components) { av_log(s->avctx, AV_LOG_ERROR, "decode_sos: invalid len (%d)\n", len); @@ -910,6 +920,10 @@ int ff_mjpeg_decode_sos(MJpegDecodeContext *s) av_log(s->avctx, AV_LOG_ERROR, "decode_sos: index(%d) out of components\n", index); return -1; } + /* Metasoft MJPEG codec has Cb and Cr swapped */ + if (s->avctx->codec_tag == MKTAG('M', 'T', 'S', 'J') + && nb_components == 3 && s->nb_components == 3 && i) + index = 3 - i; s->comp_index[i] = index; @@ -950,7 +964,7 @@ 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" : "sequencial DCT", s->rgb ? "RGB" : "", + 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" : "")); @@ -1176,6 +1190,10 @@ static int mjpeg_decode_com(MJpegDecodeContext *s) else if(!strcmp(cbuf, "CS=ITU601")){ s->cs_itu601= 1; } + else if((len > 20 && !strncmp(cbuf, "Intel(R) JPEG Library", 21)) || + (len > 19 && !strncmp(cbuf, "Metasoft MJPEG Codec", 20))){ + s->flipped = 1; + } av_free(cbuf); } @@ -1374,6 +1392,7 @@ int ff_mjpeg_decode_frame(AVCodecContext *avctx, } break; case SOF0: + case SOF1: s->lossless=0; s->ls=0; s->progressive=0; @@ -1451,7 +1470,6 @@ eoi_parser: case DRI: mjpeg_decode_dri(s); break; - case SOF1: case SOF5: case SOF6: case SOF7: @@ -1494,8 +1512,13 @@ av_cold int ff_mjpeg_decode_end(AVCodecContext *avctx) MJpegDecodeContext *s = avctx->priv_data; int i, j; + if (s->picture.data[0]) + avctx->release_buffer(avctx, &s->picture); + av_free(s->buffer); av_free(s->qscale_table); + av_freep(&s->ljpeg_buffer); + s->ljpeg_buffer_size=0; for(i=0;i<2;i++) { for(j=0;j<4;j++) @@ -1510,7 +1533,7 @@ av_cold int ff_mjpeg_decode_end(AVCodecContext *avctx) AVCodec mjpeg_decoder = { "mjpeg", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_MJPEG, sizeof(MJpegDecodeContext), ff_mjpeg_decode_init, @@ -1524,7 +1547,7 @@ AVCodec mjpeg_decoder = { AVCodec thp_decoder = { "thp", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_THP, sizeof(MJpegDecodeContext), ff_mjpeg_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpegdec.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpegdec.h index 9ef8987db3..bbf734b56f 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpegdec.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpegdec.h @@ -22,7 +22,7 @@ */ /** - * @file libavcodec/mjpegdec.h + * @file * MJPEG decoder. */ @@ -84,7 +84,7 @@ typedef struct MJpegDecodeContext { int got_picture; ///< we found a SOF and picture is valid, too. int linesize[MAX_COMPONENTS]; ///< linesize << interlaced int8_t *qscale_table; - DECLARE_ALIGNED_16(DCTELEM, block[64]); + DECLARE_ALIGNED(16, DCTELEM, block)[64]; DCTELEM (*blocks[MAX_COMPONENTS])[64]; ///< intermediate sums (progressive mode) uint8_t *last_nnz[MAX_COMPONENTS]; uint64_t coefs_finished[MAX_COMPONENTS]; ///< bitmask of which coefs have been completely decoded (progressive mode) @@ -101,6 +101,10 @@ typedef struct MJpegDecodeContext { int mjpb_skiptosod; int cur_scan; /* current scan, used by JPEG-LS */ + int flipped; /* true if picture is flipped */ + + uint16_t (*ljpeg_buffer)[4]; + unsigned int ljpeg_buffer_size; } MJpegDecodeContext; int ff_mjpeg_decode_init(AVCodecContext *avctx); diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpegenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpegenc.c index 8369e9c946..ec819c800a 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpegenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpegenc.c @@ -26,7 +26,7 @@ */ /** - * @file libavcodec/mjpegenc.c + * @file * MJPEG encoder. */ @@ -211,7 +211,7 @@ void ff_mjpeg_encode_picture_header(MpegEncContext *s) } put_bits(&s->pb, 16, 17); - if(lossless && s->avctx->pix_fmt == PIX_FMT_RGB32) + if(lossless && s->avctx->pix_fmt == PIX_FMT_BGRA) put_bits(&s->pb, 8, 9); /* 9 bits/component RCT */ else put_bits(&s->pb, 8, 8); /* 8 bits/component */ @@ -313,11 +313,8 @@ static void escape_FF(MpegEncContext *s, int start) if(ff_count==0) return; - /* skip put bits */ - for(i=0; ipb, 32, 0); - put_bits(&s->pb, (ff_count-i)*8, 0); flush_put_bits(&s->pb); + skip_put_bytes(&s->pb, ff_count); for(i=size-1; ff_count; i--){ int v= buf[i]; @@ -448,12 +445,12 @@ void ff_mjpeg_encode_mb(MpegEncContext *s, DCTELEM block[6][64]) AVCodec mjpeg_encoder = { "mjpeg", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_MJPEG, sizeof(MpegEncContext), MPV_encode_init, MPV_encode_picture, MPV_encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUVJ420P, PIX_FMT_YUVJ422P, PIX_FMT_NONE}, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUVJ420P, PIX_FMT_YUVJ422P, PIX_FMT_NONE}, .long_name= NULL_IF_CONFIG_SMALL("MJPEG (Motion JPEG)"), }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpegenc.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpegenc.h index 7a861b84c4..49627a3d55 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpegenc.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mjpegenc.h @@ -26,7 +26,7 @@ */ /** - * @file libavcodec/mjpegenc.h + * @file * MJPEG encoder. */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mlp.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mlp.c index a290e465e5..87f7c77139 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mlp.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mlp.c @@ -42,9 +42,14 @@ const uint8_t ff_mlp_huffman_tables[3][18][2] = { }; static int crc_init = 0; -static AVCRC crc_63[1024]; -static AVCRC crc_1D[1024]; -static AVCRC crc_2D[1024]; +#if CONFIG_SMALL +#define CRC_TABLE_SIZE 257 +#else +#define CRC_TABLE_SIZE 1024 +#endif +static AVCRC crc_63[CRC_TABLE_SIZE]; +static AVCRC crc_1D[CRC_TABLE_SIZE]; +static AVCRC crc_2D[CRC_TABLE_SIZE]; av_cold void ff_mlp_init_crc(void) { diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mlp.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/mlp.h index b83881653c..628b58d318 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mlp.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mlp.h @@ -47,13 +47,15 @@ */ #define MAX_SUBSTREAMS 3 +/** which multiple of 48000 the maximum sample rate is */ +#define MAX_RATEFACTOR 4 /** maximum sample frequency seen in files */ -#define MAX_SAMPLERATE 192000 +#define MAX_SAMPLERATE (MAX_RATEFACTOR * 48000) /** maximum number of audio samples within one access unit */ -#define MAX_BLOCKSIZE (40 * (MAX_SAMPLERATE / 48000)) +#define MAX_BLOCKSIZE (40 * MAX_RATEFACTOR) /** next power of two greater than MAX_BLOCKSIZE */ -#define MAX_BLOCKSIZE_POW2 (64 * (MAX_SAMPLERATE / 48000)) +#define MAX_BLOCKSIZE_POW2 (64 * MAX_RATEFACTOR) /** number of allowed filters */ #define NUM_FILTERS 2 diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mlp_parser.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mlp_parser.c index 42295cc352..90bf9391e9 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mlp_parser.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mlp_parser.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/mlp_parser.c + * @file * MLP parser */ @@ -176,7 +176,9 @@ static int mlp_parse(AVCodecParserContext *s, for (i = 0; i < buf_size; i++) { mp->pc.state = (mp->pc.state << 8) | buf[i]; - if ((mp->pc.state & 0xfffffffe) == 0xf8726fba) { + if ((mp->pc.state & 0xfffffffe) == 0xf8726fba && + // ignore if we do not have the data for the start of header + mp->pc.index + i >= 7) { mp->in_sync = 1; mp->bytes_left = 0; break; @@ -291,5 +293,5 @@ AVCodecParser mlp_parser = { sizeof(MLPParseContext), mlp_init, mlp_parse, - NULL, + ff_parse_close, }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mlp_parser.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/mlp_parser.h index 5e8861b94f..d7ce2b8311 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mlp_parser.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mlp_parser.h @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/mlp_parser.h + * @file * MLP parser prototypes */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mlpdec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mlpdec.c index 88803959bf..80fbbdb07e 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mlpdec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mlpdec.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/mlpdec.c + * @file * MLP decoder */ @@ -62,6 +62,9 @@ typedef struct SubStream { //! For each channel output by the matrix, the output channel to map it to uint8_t ch_assign[MAX_CHANNELS]; + //! Channel coding parameters for channels in the substream + ChannelParams channel_params[MAX_CHANNELS]; + //! The left shift applied to random noise in 0x31ea substreams. uint8_t noise_shift; //! The current seed value for the pseudorandom noise generator(s). @@ -137,8 +140,6 @@ typedef struct MLPDecodeContext { SubStream substream[MAX_SUBSTREAMS]; - ChannelParams channel_params[MAX_CHANNELS]; - int matrix_changed; int filter_changed[MAX_CHANNELS][NUM_FILTERS]; @@ -155,15 +156,17 @@ static VLC huff_vlc[3]; static av_cold void init_static(void) { - INIT_VLC_STATIC(&huff_vlc[0], VLC_BITS, 18, - &ff_mlp_huffman_tables[0][0][1], 2, 1, - &ff_mlp_huffman_tables[0][0][0], 2, 1, 512); - INIT_VLC_STATIC(&huff_vlc[1], VLC_BITS, 16, - &ff_mlp_huffman_tables[1][0][1], 2, 1, - &ff_mlp_huffman_tables[1][0][0], 2, 1, 512); - INIT_VLC_STATIC(&huff_vlc[2], VLC_BITS, 15, - &ff_mlp_huffman_tables[2][0][1], 2, 1, - &ff_mlp_huffman_tables[2][0][0], 2, 1, 512); + if (!huff_vlc[0].bits) { + INIT_VLC_STATIC(&huff_vlc[0], VLC_BITS, 18, + &ff_mlp_huffman_tables[0][0][1], 2, 1, + &ff_mlp_huffman_tables[0][0][0], 2, 1, 512); + INIT_VLC_STATIC(&huff_vlc[1], VLC_BITS, 16, + &ff_mlp_huffman_tables[1][0][1], 2, 1, + &ff_mlp_huffman_tables[1][0][0], 2, 1, 512); + INIT_VLC_STATIC(&huff_vlc[2], VLC_BITS, 15, + &ff_mlp_huffman_tables[2][0][1], 2, 1, + &ff_mlp_huffman_tables[2][0][0], 2, 1, 512); + } ff_mlp_init_crc(); } @@ -171,8 +174,8 @@ static av_cold void init_static(void) static inline int32_t calculate_sign_huff(MLPDecodeContext *m, unsigned int substr, unsigned int ch) { - ChannelParams *cp = &m->channel_params[ch]; SubStream *s = &m->substream[substr]; + ChannelParams *cp = &s->channel_params[ch]; int lsb_bits = cp->huff_lsbs - s->quant_step_size[ch]; int sign_shift = lsb_bits + (cp->codebook ? 2 - cp->codebook : -1); int32_t sign_huff_offset = cp->huff_offset; @@ -200,7 +203,7 @@ static inline int read_huff_channels(MLPDecodeContext *m, GetBitContext *gbp, m->bypassed_lsbs[pos + s->blockpos][mat] = get_bits1(gbp); for (channel = s->min_channel; channel <= s->max_channel; channel++) { - ChannelParams *cp = &m->channel_params[channel]; + ChannelParams *cp = &s->channel_params[channel]; int codebook = cp->codebook; int quant_step_size = s->quant_step_size[channel]; int lsb_bits = cp->huff_lsbs - quant_step_size; @@ -395,7 +398,7 @@ static int read_restart_header(MLPDecodeContext *m, GetBitContext *gbp, if (m->avctx->request_channels > 0 && s->max_channel + 1 >= m->avctx->request_channels && substr < m->max_decoded_substream) { - av_log(m->avctx, AV_LOG_INFO, + av_log(m->avctx, AV_LOG_DEBUG, "Extracting %d channel downmix from substream %d. " "Further substreams will be skipped.\n", s->max_channel + 1, substr); @@ -448,7 +451,7 @@ static int read_restart_header(MLPDecodeContext *m, GetBitContext *gbp, memset(s->quant_step_size, 0, sizeof(s->quant_step_size)); for (ch = s->min_channel; ch <= s->max_channel; ch++) { - ChannelParams *cp = &m->channel_params[ch]; + ChannelParams *cp = &s->channel_params[ch]; cp->filter_params[FIR].order = 0; cp->filter_params[IIR].order = 0; cp->filter_params[FIR].shift = 0; @@ -470,9 +473,11 @@ static int read_restart_header(MLPDecodeContext *m, GetBitContext *gbp, /** Read parameters for one of the prediction filters. */ static int read_filter_params(MLPDecodeContext *m, GetBitContext *gbp, - unsigned int channel, unsigned int filter) + unsigned int substr, unsigned int channel, + unsigned int filter) { - FilterParams *fp = &m->channel_params[channel].filter_params[filter]; + SubStream *s = &m->substream[substr]; + FilterParams *fp = &s->channel_params[channel].filter_params[filter]; const int max_order = filter ? MAX_IIR_ORDER : MAX_FIR_ORDER; const char fchar = filter ? 'I' : 'F'; int i, order; @@ -495,7 +500,7 @@ static int read_filter_params(MLPDecodeContext *m, GetBitContext *gbp, fp->order = order; if (order > 0) { - int32_t *fcoeff = m->channel_params[channel].coeff[filter]; + int32_t *fcoeff = s->channel_params[channel].coeff[filter]; int coeff_bits, coeff_shift; fp->shift = get_bits(gbp, 4); @@ -608,19 +613,19 @@ static int read_matrix_params(MLPDecodeContext *m, unsigned int substr, GetBitCo static int read_channel_params(MLPDecodeContext *m, unsigned int substr, GetBitContext *gbp, unsigned int ch) { - ChannelParams *cp = &m->channel_params[ch]; + SubStream *s = &m->substream[substr]; + ChannelParams *cp = &s->channel_params[ch]; FilterParams *fir = &cp->filter_params[FIR]; FilterParams *iir = &cp->filter_params[IIR]; - SubStream *s = &m->substream[substr]; if (s->param_presence_flags & PARAM_FIR) if (get_bits1(gbp)) - if (read_filter_params(m, gbp, ch, FIR) < 0) + if (read_filter_params(m, gbp, substr, ch, FIR) < 0) return -1; if (s->param_presence_flags & PARAM_IIR) if (get_bits1(gbp)) - if (read_filter_params(m, gbp, ch, IIR) < 0) + if (read_filter_params(m, gbp, substr, ch, IIR) < 0) return -1; if (fir->order + iir->order > 8) { @@ -695,7 +700,7 @@ static int read_decoding_params(MLPDecodeContext *m, GetBitContext *gbp, if (s->param_presence_flags & PARAM_QUANTSTEP) if (get_bits1(gbp)) for (ch = 0; ch <= s->max_channel; ch++) { - ChannelParams *cp = &m->channel_params[ch]; + ChannelParams *cp = &s->channel_params[ch]; s->quant_step_size[ch] = get_bits(gbp, 4); @@ -719,12 +724,12 @@ static void filter_channel(MLPDecodeContext *m, unsigned int substr, unsigned int channel) { SubStream *s = &m->substream[substr]; - const int32_t *fircoeff = m->channel_params[channel].coeff[FIR]; + const int32_t *fircoeff = s->channel_params[channel].coeff[FIR]; int32_t state_buffer[NUM_FILTERS][MAX_BLOCKSIZE + MAX_FIR_ORDER]; int32_t *firbuf = state_buffer[FIR] + MAX_BLOCKSIZE; int32_t *iirbuf = state_buffer[IIR] + MAX_BLOCKSIZE; - FilterParams *fir = &m->channel_params[channel].filter_params[FIR]; - FilterParams *iir = &m->channel_params[channel].filter_params[IIR]; + FilterParams *fir = &s->channel_params[channel].filter_params[FIR]; + FilterParams *iir = &s->channel_params[channel].filter_params[IIR]; unsigned int filter_shift = fir->shift; int32_t mask = MSB_MASK(s->quant_step_size[channel]); @@ -957,7 +962,7 @@ static int read_access_unit(AVCodecContext *avctx, void* data, int *data_size, length = (AV_RB16(buf) & 0xfff) * 2; - if (length > buf_size) + if (length < 4 || length > buf_size) return -1; init_get_bits(&gb, (buf + 4), (length - 4) * 8); @@ -1132,10 +1137,9 @@ error: return -1; } -#if CONFIG_MLP_DECODER AVCodec mlp_decoder = { "mlp", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_MLP, sizeof(MLPDecodeContext), mlp_decode_init, @@ -1144,12 +1148,11 @@ AVCodec mlp_decoder = { read_access_unit, .long_name = NULL_IF_CONFIG_SMALL("MLP (Meridian Lossless Packing)"), }; -#endif /* CONFIG_MLP_DECODER */ #if CONFIG_TRUEHD_DECODER AVCodec truehd_decoder = { "truehd", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_TRUEHD, sizeof(MLPDecodeContext), mlp_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mlpdsp.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mlpdsp.c index 79059d925a..a0647eee69 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mlpdsp.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mlpdsp.c @@ -55,8 +55,6 @@ static void ff_mlp_filter_channel(int32_t *state, const int32_t *coeff, } } -void ff_mlp_init_x86(DSPContext* c, AVCodecContext *avctx); - void ff_mlp_init(DSPContext* c, AVCodecContext *avctx) { c->mlp_filter_channel = ff_mlp_filter_channel; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mmvideo.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mmvideo.c index 6dc95589c6..6dbc0c4494 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mmvideo.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mmvideo.c @@ -20,9 +20,9 @@ */ /** - * @file libavcodec/mmvideo.c + * @file * American Laser Games MM Video Decoder - * by Peter Ross (suxen_drol at hotmail dot com) + * by Peter Ross (pross@xvid.org) * * The MM format was used by IBM-PC ports of ALG's "arcade shooter" games, * including Mad Dog McCree and Crime Patrol. @@ -58,12 +58,9 @@ static av_cold int mm_decode_init(AVCodecContext *avctx) avctx->pix_fmt = PIX_FMT_PAL8; - if (avcodec_check_dimensions(avctx, avctx->width, avctx->height)) - return -1; - s->frame.reference = 1; if (avctx->get_buffer(avctx, &s->frame)) { - av_log(s->avctx, AV_LOG_ERROR, "mmvideo: get_buffer() failed\n"); + av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return -1; } @@ -203,7 +200,7 @@ static av_cold int mm_decode_end(AVCodecContext *avctx) AVCodec mmvideo_decoder = { "mmvideo", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_MMVIDEO, sizeof(MmContext), mm_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/motion-test.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/motion-test.c index 5fa06ad41a..37f55a6f42 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/motion-test.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/motion-test.c @@ -19,7 +19,7 @@ */ /** - * @file libavcodec/motion-test.c + * @file * motion test. */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/motion_est.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/motion_est.c index 047fbd6697..82a36d0032 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/motion_est.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/motion_est.c @@ -23,13 +23,14 @@ */ /** - * @file libavcodec/motion_est.c + * @file * Motion estimation. */ #include #include #include +#include "libavutil/intmath.h" #include "avcodec.h" #include "dsputil.h" #include "mathops.h" @@ -103,25 +104,17 @@ static int get_flags(MotionEstContext *c, int direct, int chroma){ + (chroma ? FLAG_CHROMA : 0); } -/*! \brief compares a block (either a full macroblock or a partition thereof) - against a proposed motion-compensated prediction of that block - */ -static av_always_inline int cmp(MpegEncContext *s, const int x, const int y, const int subx, const int suby, +static av_always_inline int cmp_direct_inline(MpegEncContext *s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, - me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags){ + me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, int qpel){ MotionEstContext * const c= &s->me; const int stride= c->stride; - const int uvstride= c->uvstride; - const int qpel= flags&FLAG_QPEL; - const int chroma= flags&FLAG_CHROMA; - const int dxy= subx + (suby<<(1+qpel)); //FIXME log2_subpel? const int hx= subx + (x<<(1+qpel)); const int hy= suby + (y<<(1+qpel)); uint8_t * const * const ref= c->ref[ref_index]; uint8_t * const * const src= c->src[src_index]; int d; //FIXME check chroma 4mv, (no crashes ...) - if(flags&FLAG_DIRECT){ assert(x >= c->xmin && hx <= c->xmax<<(qpel+1) && y >= c->ymin && hy <= c->ymax<<(qpel+1)); if(x >= c->xmin && hx <= c->xmax<<(qpel+1) && y >= c->ymin && hy <= c->ymax<<(qpel+1)){ const int time_pp= s->pp_time; @@ -180,7 +173,22 @@ static av_always_inline int cmp(MpegEncContext *s, const int x, const int y, con d = cmp_func(s, c->temp, src[0], stride, 16); }else d= 256*256*256*32; - }else{ + return d; +} + +static av_always_inline int cmp_inline(MpegEncContext *s, const int x, const int y, const int subx, const int suby, + const int size, const int h, int ref_index, int src_index, + me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, int qpel, int chroma){ + MotionEstContext * const c= &s->me; + const int stride= c->stride; + const int uvstride= c->uvstride; + const int dxy= subx + (suby<<(1+qpel)); //FIXME log2_subpel? + const int hx= subx + (x<<(1+qpel)); + const int hy= suby + (y<<(1+qpel)); + uint8_t * const * const ref= c->ref[ref_index]; + uint8_t * const * const src= c->src[src_index]; + int d; + //FIXME check chroma 4mv, (no crashes ...) int uvdxy; /* no, it might not be used uninitialized */ if(dxy){ if(qpel){ @@ -211,18 +219,73 @@ static av_always_inline int cmp(MpegEncContext *s, const int x, const int y, con d += chroma_cmp_func(s, uvtemp , src[1], uvstride, h>>1); d += chroma_cmp_func(s, uvtemp+8, src[2], uvstride, h>>1); } - } -#if 0 - if(full_pel){ - const int index= (((y)<mv_penalty[hx - c->pred_x] + c->mv_penalty[hy - c->pred_y])*c->penalty_factor; -#endif return d; } +static int cmp_simple(MpegEncContext *s, const int x, const int y, + int ref_index, int src_index, + me_cmp_func cmp_func, me_cmp_func chroma_cmp_func){ + return cmp_inline(s,x,y,0,0,0,16,ref_index,src_index, cmp_func, chroma_cmp_func, 0, 0); +} + +static int cmp_fpel_internal(MpegEncContext *s, const int x, const int y, + const int size, const int h, int ref_index, int src_index, + me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags){ + if(flags&FLAG_DIRECT){ + return cmp_direct_inline(s,x,y,0,0,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, flags&FLAG_QPEL); + }else{ + return cmp_inline(s,x,y,0,0,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, 0, flags&FLAG_CHROMA); + } +} + +static int cmp_internal(MpegEncContext *s, const int x, const int y, const int subx, const int suby, + const int size, const int h, int ref_index, int src_index, + me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags){ + if(flags&FLAG_DIRECT){ + return cmp_direct_inline(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, flags&FLAG_QPEL); + }else{ + return cmp_inline(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, flags&FLAG_QPEL, flags&FLAG_CHROMA); + } +} + +/*! \brief compares a block (either a full macroblock or a partition thereof) + against a proposed motion-compensated prediction of that block + */ +static av_always_inline int cmp(MpegEncContext *s, const int x, const int y, const int subx, const int suby, + const int size, const int h, int ref_index, int src_index, + me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags){ + if(av_builtin_constant_p(flags) && av_builtin_constant_p(h) && av_builtin_constant_p(size) + && av_builtin_constant_p(subx) && av_builtin_constant_p(suby) + && flags==0 && h==16 && size==0 && subx==0 && suby==0){ + return cmp_simple(s,x,y,ref_index,src_index, cmp_func, chroma_cmp_func); + }else if(av_builtin_constant_p(subx) && av_builtin_constant_p(suby) + && subx==0 && suby==0){ + return cmp_fpel_internal(s,x,y,size,h,ref_index,src_index, cmp_func, chroma_cmp_func,flags); + }else{ + return cmp_internal(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, flags); + } +} + +static int cmp_hpel(MpegEncContext *s, const int x, const int y, const int subx, const int suby, + const int size, const int h, int ref_index, int src_index, + me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags){ + if(flags&FLAG_DIRECT){ + return cmp_direct_inline(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, 0); + }else{ + return cmp_inline(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, 0, flags&FLAG_CHROMA); + } +} + +static int cmp_qpel(MpegEncContext *s, const int x, const int y, const int subx, const int suby, + const int size, const int h, int ref_index, int src_index, + me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags){ + if(flags&FLAG_DIRECT){ + return cmp_direct_inline(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, 1); + }else{ + return cmp_inline(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, 1, flags&FLAG_CHROMA); + } +} + #include "motion_est_template.c" static int zero_cmp(void *s, uint8_t *a, uint8_t *b, int stride, int h){ @@ -849,8 +912,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][xy ]; - int field_select1= p->ref_index[0][xy2]; + int field_select0= p->ref_index[0][4*mb_xy ]; + int field_select1= p->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); @@ -877,8 +940,8 @@ static inline int check_input_motion(MpegEncContext * s, int mb_x, int mb_y, int 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][xy ]; - int field_select1= p->ref_index[1][xy2]; + int field_select0= p->ref_index[1][4*mb_xy ]; + int field_select1= p->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); @@ -1412,12 +1475,12 @@ static inline int bidir_refine(MpegEncContext * s, int mb_x, int mb_y) const int ymin= c->ymin<xmax<ymax<avctx->bidir_refine){ - int score, end; + int end; + static const uint8_t limittab[5]={0,8,32,64,80}; + const int limit= limittab[s->avctx->bidir_refine]; + static const int8_t vect[][4]={ +{ 0, 0, 0, 1}, { 0, 0, 0,-1}, { 0, 0, 1, 0}, { 0, 0,-1, 0}, { 0, 1, 0, 0}, { 0,-1, 0, 0}, { 1, 0, 0, 0}, {-1, 0, 0, 0}, + +{ 0, 0, 1, 1}, { 0, 0,-1,-1}, { 0, 1, 1, 0}, { 0,-1,-1, 0}, { 1, 1, 0, 0}, {-1,-1, 0, 0}, { 1, 0, 0, 1}, {-1, 0, 0,-1}, +{ 0, 1, 0, 1}, { 0,-1, 0,-1}, { 1, 0, 1, 0}, {-1, 0,-1, 0}, +{ 0, 0,-1, 1}, { 0, 0, 1,-1}, { 0,-1, 1, 0}, { 0, 1,-1, 0}, {-1, 1, 0, 0}, { 1,-1, 0, 0}, { 1, 0, 0,-1}, {-1, 0, 0, 1}, +{ 0,-1, 0, 1}, { 0, 1, 0,-1}, {-1, 0, 1, 0}, { 1, 0,-1, 0}, + +{ 0, 1, 1, 1}, { 0,-1,-1,-1}, { 1, 1, 1, 0}, {-1,-1,-1, 0}, { 1, 1, 0, 1}, {-1,-1, 0,-1}, { 1, 0, 1, 1}, {-1, 0,-1,-1}, +{ 0,-1, 1, 1}, { 0, 1,-1,-1}, {-1, 1, 1, 0}, { 1,-1,-1, 0}, { 1, 1, 0,-1}, {-1,-1, 0, 1}, { 1, 0,-1, 1}, {-1, 0, 1,-1}, +{ 0, 1,-1, 1}, { 0,-1, 1,-1}, { 1,-1, 1, 0}, {-1, 1,-1, 0}, {-1, 1, 0, 1}, { 1,-1, 0,-1}, { 1, 0, 1,-1}, {-1, 0,-1, 1}, +{ 0, 1, 1,-1}, { 0,-1,-1, 1}, { 1, 1,-1, 0}, {-1,-1, 1, 0}, { 1,-1, 0, 1}, {-1, 1, 0,-1}, {-1, 0, 1, 1}, { 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}, {-1, 1,-1,-1}, {-1, 1, 1, 1}, { 1,-1,-1,-1}, +{ 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 hash[]={ +HASH( 0, 0, 0, 1), HASH( 0, 0, 0,-1), HASH( 0, 0, 1, 0), HASH( 0, 0,-1, 0), HASH( 0, 1, 0, 0), HASH( 0,-1, 0, 0), HASH( 1, 0, 0, 0), HASH(-1, 0, 0, 0), + +HASH( 0, 0, 1, 1), HASH( 0, 0,-1,-1), HASH( 0, 1, 1, 0), HASH( 0,-1,-1, 0), HASH( 1, 1, 0, 0), HASH(-1,-1, 0, 0), HASH( 1, 0, 0, 1), HASH(-1, 0, 0,-1), +HASH( 0, 1, 0, 1), HASH( 0,-1, 0,-1), HASH( 1, 0, 1, 0), HASH(-1, 0,-1, 0), +HASH( 0, 0,-1, 1), HASH( 0, 0, 1,-1), HASH( 0,-1, 1, 0), HASH( 0, 1,-1, 0), HASH(-1, 1, 0, 0), HASH( 1,-1, 0, 0), HASH( 1, 0, 0,-1), HASH(-1, 0, 0, 1), +HASH( 0,-1, 0, 1), HASH( 0, 1, 0,-1), HASH(-1, 0, 1, 0), HASH( 1, 0,-1, 0), + +HASH( 0, 1, 1, 1), HASH( 0,-1,-1,-1), HASH( 1, 1, 1, 0), HASH(-1,-1,-1, 0), HASH( 1, 1, 0, 1), HASH(-1,-1, 0,-1), HASH( 1, 0, 1, 1), HASH(-1, 0,-1,-1), +HASH( 0,-1, 1, 1), HASH( 0, 1,-1,-1), HASH(-1, 1, 1, 0), HASH( 1,-1,-1, 0), HASH( 1, 1, 0,-1), HASH(-1,-1, 0, 1), HASH( 1, 0,-1, 1), HASH(-1, 0, 1,-1), +HASH( 0, 1,-1, 1), HASH( 0,-1, 1,-1), HASH( 1,-1, 1, 0), HASH(-1, 1,-1, 0), HASH(-1, 1, 0, 1), HASH( 1,-1, 0,-1), HASH( 1, 0, 1,-1), HASH(-1, 0,-1, 1), +HASH( 0, 1, 1,-1), HASH( 0,-1,-1, 1), HASH( 1, 1,-1, 0), HASH(-1,-1, 1, 0), HASH( 1,-1, 0, 1), HASH(-1, 1, 0,-1), HASH(-1, 0, 1, 1), HASH( 1, 0,-1,-1), + +HASH( 1, 1, 1, 1), HASH(-1,-1,-1,-1), +HASH( 1, 1, 1,-1), HASH(-1,-1,-1, 1), HASH( 1, 1,-1, 1), HASH(-1,-1, 1,-1), HASH( 1,-1, 1, 1), HASH(-1, 1,-1,-1), HASH(-1, 1, 1, 1), HASH( 1,-1,-1,-1), +HASH( 1, 1,-1,-1), HASH(-1,-1, 1, 1), HASH( 1,-1,-1, 1), HASH(-1, 1, 1,-1), HASH( 1,-1, 1,-1), HASH(-1, 1,-1, 1), +}; + #define CHECK_BIDIR(fx,fy,bx,by)\ - if( !BIDIR_MAP(fx,fy,bx,by)\ + if( !map[(hashidx+HASH(fx,fy,bx,by))&255]\ &&(fx<=0 || motion_fx+fx<=xmax) && (fy<=0 || motion_fy+fy<=ymax) && (bx<=0 || motion_bx+bx<=xmax) && (by<=0 || motion_by+by<=ymax)\ &&(fx>=0 || motion_fx+fx>=xmin) && (fy>=0 || motion_fy+fy>=ymin) && (bx>=0 || motion_bx+bx>=xmin) && (by>=0 || motion_by+by>=ymin)){\ - BIDIR_MAP(fx,fy,bx,by) = 1;\ + int score;\ + map[(hashidx+HASH(fx,fy,bx,by))&255] = 1;\ score= check_bidir_mv(s, motion_fx+fx, motion_fy+fy, motion_bx+bx, motion_by+by, pred_fx, pred_fy, pred_bx, pred_by, 0, 16);\ if(score < fbmin){\ + hashidx += HASH(fx,fy,bx,by);\ fbmin= score;\ motion_fx+=fx;\ motion_fy+=fy;\ @@ -1446,34 +1548,45 @@ static inline int bidir_refine(MpegEncContext * s, int mb_x, int mb_y) CHECK_BIDIR(a,b,c,d)\ CHECK_BIDIR(-(a),-(b),-(c),-(d)) -#define CHECK_BIDIRR(a,b,c,d)\ -CHECK_BIDIR2(a,b,c,d)\ -CHECK_BIDIR2(b,c,d,a)\ -CHECK_BIDIR2(c,d,a,b)\ -CHECK_BIDIR2(d,a,b,c) - do{ + int i; + int borderdist=0; end=1; - CHECK_BIDIRR( 0, 0, 0, 1) - if(s->avctx->bidir_refine > 1){ - CHECK_BIDIRR( 0, 0, 1, 1) - CHECK_BIDIR2( 0, 1, 0, 1) - CHECK_BIDIR2( 1, 0, 1, 0) - CHECK_BIDIRR( 0, 0,-1, 1) - CHECK_BIDIR2( 0,-1, 0, 1) - CHECK_BIDIR2(-1, 0, 1, 0) - if(s->avctx->bidir_refine > 2){ - CHECK_BIDIRR( 0, 1, 1, 1) - CHECK_BIDIRR( 0,-1, 1, 1) - CHECK_BIDIRR( 0, 1,-1, 1) - CHECK_BIDIRR( 0, 1, 1,-1) - if(s->avctx->bidir_refine > 3){ - CHECK_BIDIR2( 1, 1, 1, 1) - CHECK_BIDIRR( 1, 1, 1,-1) - CHECK_BIDIR2( 1, 1,-1,-1) - CHECK_BIDIR2( 1,-1,-1, 1) - CHECK_BIDIR2( 1,-1, 1,-1) + CHECK_BIDIR2(0,0,0,1) + CHECK_BIDIR2(0,0,1,0) + CHECK_BIDIR2(0,1,0,0) + CHECK_BIDIR2(1,0,0,0) + + for(i=8; i> 3); - if ((unsigned)r < 32 && (unsigned)g < 32 && (unsigned)b < 32) - return (r << 10) | (g << 5) | b; - return 1 << 15; -} - -static void mp_set_zero_yuv(YuvPixel *p) -{ - int i, j; - - for (i = 0; i < 31; ++i) { - for (j = 31; j > i; --j) - if (!(p[j].u | p[j].v | p[j].y)) - p[j] = p[j - 1]; - for (j = 0; j < 31 - i; ++j) - if (!(p[j].u | p[j].v | p[j].y)) - p[j] = p[j + 1]; - } -} - -static void mp_build_rgb_yuv_table(YuvPixel *p) -{ - int y, v, u, i; - - for (y = 0; y <= 31; ++y) - for (v = -31; v <= 31; ++v) - for (u = -31; u <= 31; ++u) { - i = mp_yuv_to_rgb(y, v, u, 0); - if (i < (1 << 15) && !(p[i].u | p[i].v | p[i].y)) { - p[i].y = y; - p[i].v = v; - p[i].u = u; - } - } - for (i = 0; i < 1024; ++i) - mp_set_zero_yuv(p + i * 32); -} - static av_cold int mp_decode_init(AVCodecContext *avctx) { MotionPixelsContext *mp = avctx->priv_data; - if (!mp_rgb_yuv_table[0].u) { - mp_build_rgb_yuv_table(mp_rgb_yuv_table); - } + motionpixels_tableinit(); mp->avctx = avctx; dsputil_init(&mp->dsp, avctx); mp->changes_map = av_mallocz(avctx->width * avctx->height); 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)); + avctx->pix_fmt = PIX_FMT_RGB555; return 0; } @@ -355,7 +304,7 @@ static av_cold int mp_decode_end(AVCodecContext *avctx) AVCodec motionpixels_decoder = { "motionpixels", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_MOTIONPIXELS, sizeof(MotionPixelsContext), mp_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/motionpixels_tablegen.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/motionpixels_tablegen.c new file mode 100644 index 0000000000..5f1220aff5 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/motionpixels_tablegen.c @@ -0,0 +1,41 @@ +/* + * Generate a header file for hardcoded motionpixels RGB to YUV table + * + * Copyright (c) 2009 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 +#define CONFIG_HARDCODED_TABLES 0 +#define MAX_NEG_CROP 0 +#define ff_cropTbl ((uint8_t *)NULL) +#include "motionpixels_tablegen.h" +#include "tableprint.h" + +int main(void) +{ + motionpixels_tableinit(); + + write_fileheader(); + + printf("static const YuvPixel mp_rgb_yuv_table[1 << 15] = {\n"); + write_int8_2d_array(mp_rgb_yuv_table, 1 << 15, 3); + printf("};\n"); + + return 0; +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/motionpixels_tablegen.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/motionpixels_tablegen.h new file mode 100644 index 0000000000..5d6df52af1 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/motionpixels_tablegen.h @@ -0,0 +1,91 @@ +/* + * Header file for hardcoded motionpixels RGB to YUV table + * + * Copyright (c) 2009 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 + */ + +#ifndef MOTIONPIXELS_TABLEGEN_H +#define MOTIONPIXELS_TABLEGEN_H + +#include + +typedef struct YuvPixel { + int8_t y, v, u; +} 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; + int r, g, b; + + r = (1000 * y + 701 * v) / 1000; + g = (1000 * y - 357 * v - 172 * u) / 1000; + b = (1000 * y + 886 * u) / 1000; + if (clip_rgb) + return ((cm[r * 8] & 0xF8) << 7) | ((cm[g * 8] & 0xF8) << 2) | (cm[b * 8] >> 3); + if ((unsigned)r < 32 && (unsigned)g < 32 && (unsigned)b < 32) + return (r << 10) | (g << 5) | b; + return 1 << 15; +} + +#if CONFIG_HARDCODED_TABLES +#define motionpixels_tableinit() +#include "libavcodec/motionpixels_tables.h" +#else +static YuvPixel mp_rgb_yuv_table[1 << 15]; + +static void mp_set_zero_yuv(YuvPixel *p) +{ + int i, j; + + for (i = 0; i < 31; ++i) { + for (j = 31; j > i; --j) + if (!(p[j].u | p[j].v | p[j].y)) + p[j] = p[j - 1]; + for (j = 0; j < 31 - i; ++j) + if (!(p[j].u | p[j].v | p[j].y)) + p[j] = p[j + 1]; + } +} + +static void mp_build_rgb_yuv_table(YuvPixel *p) +{ + int y, v, u, i; + + for (y = 0; y <= 31; ++y) + for (v = -31; v <= 31; ++v) + for (u = -31; u <= 31; ++u) { + i = mp_yuv_to_rgb(y, v, u, 0); + if (i < (1 << 15) && !(p[i].u | p[i].v | p[i].y)) { + p[i].y = y; + p[i].v = v; + p[i].u = u; + } + } + for (i = 0; i < 1024; ++i) + mp_set_zero_yuv(p + i * 32); +} + +static void motionpixels_tableinit(void) +{ + if (!mp_rgb_yuv_table[0].u) + mp_build_rgb_yuv_table(mp_rgb_yuv_table); +} +#endif /* CONFIG_HARDCODED_TABLES */ + +#endif /* MOTIONPIXELS_TABLEGEN_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpc.c index f8fe4c4bc3..30ae591a0f 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpc.c @@ -20,7 +20,8 @@ */ /** - * @file libavcodec/mpc.c Musepack decoder core + * @file + * Musepack decoder core * MPEG Audio Layer 1/2 -like codec with frames of 1152 samples * divided into 32 subbands. */ @@ -33,11 +34,9 @@ #include "mpc.h" #include "mpcdata.h" -static DECLARE_ALIGNED_16(MPA_INT, mpa_window[512]); - void ff_mpc_init(void) { - ff_mpa_synth_init(mpa_window); + ff_mpa_synth_init(ff_mpa_synth_window); } /** @@ -53,7 +52,7 @@ static void mpc_synth(MPCContext *c, int16_t *out) samples_ptr = samples + ch; for(i = 0; i < SAMPLES_PER_BAND; i++) { ff_mpa_synth_filter(c->synth_buf[ch], &(c->synth_buf_offset[ch]), - mpa_window, &dither_state, + ff_mpa_synth_window, &dither_state, samples_ptr, 2, c->sb_samples[ch][i]); samples_ptr += 64; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpc.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpc.h index 738aede6c5..25d1d2ce04 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpc.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpc.h @@ -20,7 +20,8 @@ */ /** - * @file libavcodec/mpc.h Musepack decoder + * @file + * Musepack decoder * MPEG Audio Layer 1/2 -like codec with frames of 1152 samples * divided into 32 subbands. */ @@ -65,9 +66,9 @@ typedef struct { AVLFG rnd; int frames_to_skip; /* for synthesis */ - DECLARE_ALIGNED_16(MPA_INT, synth_buf[MPA_MAX_CHANNELS][512*2]); + DECLARE_ALIGNED(16, MPA_INT, synth_buf)[MPA_MAX_CHANNELS][512*2]; int synth_buf_offset[MPA_MAX_CHANNELS]; - DECLARE_ALIGNED_16(int32_t, sb_samples[MPA_MAX_CHANNELS][36][SBLIMIT]); + DECLARE_ALIGNED(16, int32_t, sb_samples)[MPA_MAX_CHANNELS][36][SBLIMIT]; } MPCContext; void ff_mpc_init(void); diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpc7.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpc7.c index 614a418684..42de27e7b9 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpc7.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpc7.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/mpc7.c Musepack SV7 decoder + * @file * MPEG Audio Layer 1/2 -like codec with frames of 1152 samples * divided into 32 subbands. */ @@ -85,6 +85,9 @@ static av_cold int mpc7_decode_init(AVCodecContext * avctx) c->IS, c->MSS, c->gapless, c->lastframelen, c->maxbands); c->frames_to_skip = 0; + avctx->sample_fmt = SAMPLE_FMT_S16; + avctx->channel_layout = (avctx->channels==2) ? CH_LAYOUT_STEREO : CH_LAYOUT_MONO; + if(vlc_initialized) return 0; av_log(avctx, AV_LOG_DEBUG, "Initing VLC\n"); scfi_vlc.table = scfi_table; @@ -124,8 +127,6 @@ static av_cold int mpc7_decode_init(AVCodecContext * avctx) } } vlc_initialized = 1; - avctx->sample_fmt = SAMPLE_FMT_S16; - avctx->channel_layout = (avctx->channels==2) ? CH_LAYOUT_STEREO : CH_LAYOUT_MONO; return 0; } @@ -174,6 +175,14 @@ static inline void idx_to_quant(MPCContext *c, GetBitContext *gb, int idx, int * } } +static int get_scale_idx(GetBitContext *gb, int ref) +{ + int t = get_vlc2(gb, dscf_vlc.table, MPC7_DSCF_BITS, 1) - 7; + if (t == 8) + return get_bits(gb, 6); + return ref + t; +} + static int mpc7_decode_frame(AVCodecContext * avctx, void *data, int *data_size, AVPacket *avpkt) @@ -183,7 +192,7 @@ static int mpc7_decode_frame(AVCodecContext * avctx, MPCContext *c = avctx->priv_data; GetBitContext gb; uint8_t *bits; - int i, ch, t; + int i, ch; int mb = -1; Band *bands = c->bands; int off; @@ -202,8 +211,9 @@ static int mpc7_decode_frame(AVCodecContext * avctx, /* read subband indexes */ for(i = 0; i <= c->maxbands; i++){ for(ch = 0; ch < 2; ch++){ + int t = 4; if(i) t = get_vlc2(&gb, hdr_vlc.table, MPC7_HDR_BITS, 1) - 5; - if(!i || (t == 4)) bands[i].res[ch] = get_bits(&gb, 4); + if(t == 4) bands[i].res[ch] = get_bits(&gb, 4); else bands[i].res[ch] = bands[i-1].res[ch] + t; } @@ -221,24 +231,19 @@ static int mpc7_decode_frame(AVCodecContext * avctx, for(ch = 0; ch < 2; ch++){ if(bands[i].res[ch]){ bands[i].scf_idx[ch][2] = c->oldDSCF[ch][i]; - t = get_vlc2(&gb, dscf_vlc.table, MPC7_DSCF_BITS, 1) - 7; - bands[i].scf_idx[ch][0] = (t == 8) ? get_bits(&gb, 6) : (bands[i].scf_idx[ch][2] + t); + bands[i].scf_idx[ch][0] = get_scale_idx(&gb, bands[i].scf_idx[ch][2]); switch(bands[i].scfi[ch]){ case 0: - t = get_vlc2(&gb, dscf_vlc.table, MPC7_DSCF_BITS, 1) - 7; - bands[i].scf_idx[ch][1] = (t == 8) ? get_bits(&gb, 6) : (bands[i].scf_idx[ch][0] + t); - t = get_vlc2(&gb, dscf_vlc.table, MPC7_DSCF_BITS, 1) - 7; - bands[i].scf_idx[ch][2] = (t == 8) ? get_bits(&gb, 6) : (bands[i].scf_idx[ch][1] + t); + bands[i].scf_idx[ch][1] = get_scale_idx(&gb, bands[i].scf_idx[ch][0]); + bands[i].scf_idx[ch][2] = get_scale_idx(&gb, bands[i].scf_idx[ch][1]); break; case 1: - t = get_vlc2(&gb, dscf_vlc.table, MPC7_DSCF_BITS, 1) - 7; - bands[i].scf_idx[ch][1] = (t == 8) ? get_bits(&gb, 6) : (bands[i].scf_idx[ch][0] + t); + bands[i].scf_idx[ch][1] = get_scale_idx(&gb, bands[i].scf_idx[ch][0]); bands[i].scf_idx[ch][2] = bands[i].scf_idx[ch][1]; break; case 2: bands[i].scf_idx[ch][1] = bands[i].scf_idx[ch][0]; - t = get_vlc2(&gb, dscf_vlc.table, MPC7_DSCF_BITS, 1) - 7; - bands[i].scf_idx[ch][2] = (t == 8) ? get_bits(&gb, 6) : (bands[i].scf_idx[ch][1] + t); + bands[i].scf_idx[ch][2] = get_scale_idx(&gb, bands[i].scf_idx[ch][1]); break; case 3: bands[i].scf_idx[ch][2] = bands[i].scf_idx[ch][1] = bands[i].scf_idx[ch][0]; @@ -285,7 +290,7 @@ static void mpc7_decode_flush(AVCodecContext *avctx) AVCodec mpc7_decoder = { "mpc7", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_MUSEPACK7, sizeof(MPCContext), mpc7_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpc8.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpc8.c index e1b3866b0b..376274608f 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpc8.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpc8.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/mpc8.c Musepack SV8 decoder + * @file * MPEG Audio Layer 1/2 -like codec with frames of 1152 samples * divided into 32 subbands. */ @@ -129,6 +129,9 @@ static av_cold int mpc8_decode_init(AVCodecContext * avctx) c->MSS = get_bits1(&gb); c->frames = 1 << (get_bits(&gb, 3) * 2); + avctx->sample_fmt = SAMPLE_FMT_S16; + avctx->channel_layout = (avctx->channels==2) ? CH_LAYOUT_STEREO : CH_LAYOUT_MONO; + if(vlc_initialized) return 0; av_log(avctx, AV_LOG_DEBUG, "Initing VLC\n"); @@ -219,8 +222,6 @@ static av_cold int mpc8_decode_init(AVCodecContext * avctx) &mpc8_q8_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC); } vlc_initialized = 1; - avctx->sample_fmt = SAMPLE_FMT_S16; - avctx->channel_layout = (avctx->channels==2) ? CH_LAYOUT_STEREO : CH_LAYOUT_MONO; return 0; } @@ -400,7 +401,7 @@ static int mpc8_decode_frame(AVCodecContext * avctx, AVCodec mpc8_decoder = { "mpc8", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_MUSEPACK8, sizeof(MPCContext), mpc8_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg12.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg12.c index 477e99c444..bc9ddcc4cb 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg12.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg12.c @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/mpeg12.c + * @file * MPEG-1/2 decoder */ @@ -122,7 +122,7 @@ void ff_mpeg12_common_init(MpegEncContext *s) { s->y_dc_scale_table= - s->c_dc_scale_table= mpeg2_dc_scale_table[s->intra_dc_precision]; + s->c_dc_scale_table= ff_mpeg2_dc_scale_table[s->intra_dc_precision]; } @@ -448,18 +448,20 @@ static int mpeg_decode_mb(MpegEncContext *s, 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] >> 1); + s->last_mv[i][0][1] >> my_shift); dmy = get_dmv(s); - s->last_mv[i][0][1] = my<<1; - s->last_mv[i][1][1] = my<<1; + s->last_mv[i][0][1] = my<last_mv[i][1][1] = my<mv[i][0][0] = mx; s->mv[i][0][1] = my; @@ -1172,7 +1174,7 @@ typedef struct Mpeg1Context { int save_aspect_info; 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? } Mpeg1Context; static av_cold int mpeg_decode_init(AVCodecContext *avctx) @@ -1352,9 +1354,6 @@ static int mpeg1_decode_picture(AVCodecContext *avctx, MpegEncContext *s = &s1->mpeg_enc_ctx; int ref, f_code, vbv_delay; - if(mpeg_decode_postinit(s->avctx) < 0) - return -2; - init_get_bits(&s->gb, buf, buf_size*8); ref = get_bits(&s->gb, 10); /* temporal ref */ @@ -1387,7 +1386,6 @@ static int mpeg1_decode_picture(AVCodecContext *avctx, s->y_dc_scale = 8; s->c_dc_scale = 8; - s->first_slice = 1; return 0; } @@ -1536,7 +1534,6 @@ static void mpeg_decode_picture_coding_extension(Mpeg1Context *s1) s->pict_type= FF_B_TYPE; s->current_picture.pict_type= s->pict_type; s->current_picture.key_frame= s->pict_type == FF_I_TYPE; - s->first_slice= 1; } s->intra_dc_precision = get_bits(&s->gb, 2); s->picture_structure = get_bits(&s->gb, 2); @@ -1550,6 +1547,21 @@ static void mpeg_decode_picture_coding_extension(Mpeg1Context *s1) 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)){ + av_log(s->avctx, AV_LOG_ERROR, "picture_structure %d invalid, ignoring\n", s->picture_structure); + s->picture_structure= PICT_FRAME; + } + + 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; @@ -1579,35 +1591,6 @@ static void mpeg_decode_picture_coding_extension(Mpeg1Context *s1) dprintf(s->avctx, "progressive_frame=%d\n", s->progressive_frame); } -static void mpeg_decode_extension(AVCodecContext *avctx, - const uint8_t *buf, int buf_size) -{ - Mpeg1Context *s1 = avctx->priv_data; - MpegEncContext *s = &s1->mpeg_enc_ctx; - int ext_type; - - init_get_bits(&s->gb, buf, buf_size*8); - - ext_type = get_bits(&s->gb, 4); - switch(ext_type) { - case 0x1: - mpeg_decode_sequence_extension(s1); - break; - case 0x2: - mpeg_decode_sequence_display_extension(s1); - break; - case 0x3: - mpeg_decode_quant_matrix_extension(s); - break; - case 0x7: - mpeg_decode_picture_display_extension(s1); - break; - case 0x8: - mpeg_decode_picture_coding_extension(s1); - break; - } -} - static void exchange_uv(MpegEncContext *s){ DCTELEM (*tmp)[64]; @@ -1690,10 +1673,7 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y, s->resync_mb_x= s->resync_mb_y= -1; - if (mb_y<= s->mb_height){ - av_log(s->avctx, AV_LOG_ERROR, "slice below image (%d >= %d)\n", mb_y, s->mb_height); - return -1; - } + assert(mb_y < s->mb_height); init_get_bits(&s->gb, *buf, buf_size*8); @@ -1714,6 +1694,32 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y, s->mb_x=0; + if(mb_y==0 && s->codec_tag == AV_RL32("SLIF")){ + skip_bits1(&s->gb); + }else{ + for(;;) { + int code = get_vlc2(&s->gb, mbincr_vlc.table, MBINCR_VLC_BITS, 2); + if (code < 0){ + av_log(s->avctx, AV_LOG_ERROR, "first mb_incr damaged\n"); + return -1; + } + if (code >= 33) { + if (code == 33) { + s->mb_x += 33; + } + /* otherwise, stuffing, nothing to do */ + } else { + s->mb_x += code; + break; + } + } + } + + if(s->mb_x >= (unsigned)s->mb_width){ + av_log(s->avctx, AV_LOG_ERROR, "initial skip overflow\n"); + return -1; + } + if (avctx->hwaccel) { const uint8_t *buf_end, *buf_start = *buf - 4; /* include start_code */ int start_code = -1; @@ -1727,27 +1733,6 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y, return DECODE_SLICE_OK; } - for(;;) { - int code = get_vlc2(&s->gb, mbincr_vlc.table, MBINCR_VLC_BITS, 2); - if (code < 0){ - av_log(s->avctx, AV_LOG_ERROR, "first mb_incr damaged\n"); - return -1; - } - if (code >= 33) { - if (code == 33) { - s->mb_x += 33; - } - /* otherwise, stuffing, nothing to do */ - } else { - s->mb_x += code; - break; - } - } - if(s->mb_x >= (unsigned)s->mb_width){ - av_log(s->avctx, AV_LOG_ERROR, "initial skip overflow\n"); - return -1; - } - s->resync_mb_x= s->mb_x; s->resync_mb_y= s->mb_y= mb_y; s->mb_skip_run= 0; @@ -1773,11 +1758,10 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y, return -1; if(s->current_picture.motion_val[0] && !s->encoding){ //note motion_val is normally NULL unless we want to extract the MVs - const int wrap = field_pic ? 2*s->b8_stride : s->b8_stride; + 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 motion_x, motion_y, dir, i; - if(field_pic && !s->first_field) - xy += wrap/2; for(i=0; i<2; i++){ for(dir=0; dir<2; dir++){ @@ -1795,11 +1779,12 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y, 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][xy ]= - s->current_picture.ref_index [dir][xy + 1]= s->field_select[dir][i]; + 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); } xy += wrap; + b8_xy +=2; } } @@ -1812,13 +1797,13 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y, if (++s->mb_x >= s->mb_width) { const int mb_size= 16>>s->avctx->lowres; - ff_draw_horiz_band(s, mb_size*s->mb_y, mb_size); + ff_draw_horiz_band(s, mb_size*(s->mb_y>>field_pic), mb_size); s->mb_x = 0; - s->mb_y++; + s->mb_y += 1<mb_y<= s->mb_height){ - int left= s->gb.size_in_bits - get_bits_count(&s->gb); + if(s->mb_y >= s->mb_height){ + int left= get_bits_left(&s->gb); int is_d10= s->chroma_format==2 && s->pict_type==FF_I_TYPE && 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*/; @@ -1881,7 +1866,7 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y, 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; + 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]; @@ -1902,8 +1887,9 @@ 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; + s->error_count= (3*(s->end_mb_y - s->start_mb_y)*s->mb_width) >> field_pic; for(;;){ uint32_t start_code; @@ -2108,33 +2094,29 @@ static int vcr2_init_sequence(AVCodecContext *avctx) 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; return 0; } static void mpeg_decode_user_data(AVCodecContext *avctx, - const uint8_t *buf, int buf_size) + const uint8_t *p, int buf_size) { - const uint8_t *p; - int len, flags; - p = buf; - len = buf_size; + const uint8_t *buf_end = p+buf_size; /* we parse the DTG active format information */ - if (len >= 5 && + if (buf_end - p >= 5 && p[0] == 'D' && p[1] == 'T' && p[2] == 'G' && p[3] == '1') { - flags = p[4]; + int flags = p[4]; p += 5; - len -= 5; if (flags & 0x80) { /* skip event id */ - if (len < 2) - return; p += 2; - len -= 2; } if (flags & 0x40) { - if (len < 1) + if (buf_end - p < 1) return; avctx->dtg_active_format = p[0] & 0x0f; } @@ -2224,7 +2206,7 @@ int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size, return i-3; } } - if(s && state == PICTURE_START_CODE){ + if(pc->frame_start_found == 0 && s && state == PICTURE_START_CODE){ ff_fetch_timestamp(s, i-3, 1); } } @@ -2299,6 +2281,7 @@ static int decode_chunks(AVCodecContext *avctx, const uint8_t *buf_ptr = buf; const uint8_t *buf_end = buf + buf_size; int ret, input_size; + int last_code= 0; for(;;) { /* find next start code */ @@ -2309,7 +2292,7 @@ static int decode_chunks(AVCodecContext *avctx, if(avctx->thread_count > 1){ int i; - avctx->execute(avctx, slice_decode_thread, (void**)&(s2->thread_context[0]), NULL, s->slice_count, sizeof(void*)); + avctx->execute(avctx, slice_decode_thread, &s2->thread_context[0], NULL, s->slice_count, sizeof(void*)); for(i=0; islice_count; i++) s2->error_count += s2->thread_context[i]->error_count; } @@ -2335,50 +2318,102 @@ static int decode_chunks(AVCodecContext *avctx, /* prepare data for next 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{ + av_log(avctx, AV_LOG_ERROR, "ignoring SEQ_START_CODE after %X\n", last_code); + } break; case PICTURE_START_CODE: + 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; + } + /* 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{ + av_log(avctx, AV_LOG_ERROR, "ignoring pic after %X\n", last_code); + } break; case EXT_START_CODE: - mpeg_decode_extension(avctx, - buf_ptr, input_size); + init_get_bits(&s2->gb, buf_ptr, input_size*8); + + switch(get_bits(&s2->gb, 4)) { + case 0x1: + if(last_code == 0){ + mpeg_decode_sequence_extension(s); + }else{ + av_log(avctx, AV_LOG_ERROR, "ignoring seq ext after %X\n", last_code); + } + break; + case 0x2: + mpeg_decode_sequence_display_extension(s); + break; + case 0x3: + mpeg_decode_quant_matrix_extension(s2); + break; + case 0x7: + mpeg_decode_picture_display_extension(s); + break; + case 0x8: + 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); + } + break; + } break; case USER_START_CODE: 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); + s->sync=1; + }else{ + av_log(avctx, AV_LOG_ERROR, "ignoring GOP_START_CODE after %X\n", last_code); + } break; default: if (start_code >= SLICE_MIN_START_CODE && - start_code <= SLICE_MAX_START_CODE) { - int mb_y= 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; + + if(s2->picture_structure == PICT_BOTTOM_FIELD) + mb_y++; + + 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){ /* Skip B-frames if we do not have reference frames and gop is not closed */ if(s2->pict_type==FF_B_TYPE){ - int i; if(!s2->closed_gop) break; - /* Allocate a dummy frame */ - i= ff_find_unused_picture(s2, 0); - s2->last_picture_ptr= &s2->picture[i]; - if(ff_alloc_picture(s2, s2->last_picture_ptr, 0) < 0) - return -1; } } + if(s2->pict_type==FF_I_TYPE) + s->sync=1; 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==FF_P_TYPE && (s2->first_field || s2->picture_structure==PICT_FRAME)) break; + if(s2->pict_type==FF_P_TYPE && !s->sync) break; } /* Skip B-frames if we are in a hurry. */ if(avctx->hurry_up && s2->pict_type==FF_B_TYPE) break; @@ -2448,6 +2483,14 @@ static int decode_chunks(AVCodecContext *avctx, } } +static void flush(AVCodecContext *avctx){ + Mpeg1Context *s = avctx->priv_data; + + s->sync=0; + + ff_mpeg_flush(avctx); +} + static int mpeg_decode_end(AVCodecContext *avctx) { Mpeg1Context *s = avctx->priv_data; @@ -2459,7 +2502,7 @@ static int mpeg_decode_end(AVCodecContext *avctx) AVCodec mpeg1video_decoder = { "mpeg1video", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_MPEG1VIDEO, sizeof(Mpeg1Context), mpeg_decode_init, @@ -2467,13 +2510,13 @@ AVCodec mpeg1video_decoder = { mpeg_decode_end, mpeg_decode_frame, CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY, - .flush= ff_mpeg_flush, + .flush= flush, .long_name= NULL_IF_CONFIG_SMALL("MPEG-1 video"), }; AVCodec mpeg2video_decoder = { "mpeg2video", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_MPEG2VIDEO, sizeof(Mpeg1Context), mpeg_decode_init, @@ -2481,14 +2524,14 @@ AVCodec mpeg2video_decoder = { mpeg_decode_end, mpeg_decode_frame, CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY, - .flush= ff_mpeg_flush, + .flush= flush, .long_name= NULL_IF_CONFIG_SMALL("MPEG-2 video"), }; //legacy decoder AVCodec mpegvideo_decoder = { "mpegvideo", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_MPEG2VIDEO, sizeof(Mpeg1Context), mpeg_decode_init, @@ -2496,7 +2539,7 @@ AVCodec mpegvideo_decoder = { mpeg_decode_end, mpeg_decode_frame, CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY, - .flush= ff_mpeg_flush, + .flush= flush, .long_name= NULL_IF_CONFIG_SMALL("MPEG-1 video"), }; @@ -2519,7 +2562,7 @@ static av_cold int mpeg_mc_decode_init(AVCodecContext *avctx){ AVCodec mpeg_xvmc_decoder = { "mpegvideo_xvmc", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_MPEG2VIDEO_XVMC, sizeof(Mpeg1Context), mpeg_mc_decode_init, @@ -2527,7 +2570,7 @@ AVCodec mpeg_xvmc_decoder = { mpeg_decode_end, mpeg_decode_frame, CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED| CODEC_CAP_HWACCEL | CODEC_CAP_DELAY, - .flush= ff_mpeg_flush, + .flush= flush, .long_name = NULL_IF_CONFIG_SMALL("MPEG-1/2 video XvMC (X-Video Motion Compensation)"), }; @@ -2536,7 +2579,7 @@ AVCodec mpeg_xvmc_decoder = { #if CONFIG_MPEG_VDPAU_DECODER AVCodec mpeg_vdpau_decoder = { "mpegvideo_vdpau", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_MPEG2VIDEO, sizeof(Mpeg1Context), mpeg_decode_init, @@ -2544,7 +2587,7 @@ AVCodec mpeg_vdpau_decoder = { mpeg_decode_end, mpeg_decode_frame, CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_HWACCEL_VDPAU | CODEC_CAP_DELAY, - .flush= ff_mpeg_flush, + .flush= flush, .long_name = NULL_IF_CONFIG_SMALL("MPEG-1/2 video (VDPAU acceleration)"), }; #endif @@ -2552,7 +2595,7 @@ AVCodec mpeg_vdpau_decoder = { #if CONFIG_MPEG1_VDPAU_DECODER AVCodec mpeg1_vdpau_decoder = { "mpeg1video_vdpau", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_MPEG1VIDEO, sizeof(Mpeg1Context), mpeg_decode_init, @@ -2560,7 +2603,7 @@ AVCodec mpeg1_vdpau_decoder = { mpeg_decode_end, mpeg_decode_frame, CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_HWACCEL_VDPAU | CODEC_CAP_DELAY, - .flush= ff_mpeg_flush, + .flush= flush, .long_name = NULL_IF_CONFIG_SMALL("MPEG-1 video (VDPAU acceleration)"), }; #endif diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg12data.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg12data.c index 7d90f65a32..8b1f563bf4 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg12data.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg12data.c @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/mpeg12data.c + * @file * MPEG1/2 tables. */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg12data.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg12data.h index 47973e19b4..9695e9d41e 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg12data.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg12data.h @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/mpeg12data.h + * @file * MPEG1/2 tables. */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg12decdata.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg12decdata.h index 0799521639..66ca5c4971 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg12decdata.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg12decdata.h @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/mpeg12decdata.h + * @file * MPEG1/2 decoder tables. */ @@ -90,35 +90,4 @@ static const uint8_t non_linear_qscale[32] = { 56,64,72,80,88,96,104,112, }; -static const uint8_t mpeg2_dc_scale_table1[128]={ -// 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 - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, -}; - -static const uint8_t mpeg2_dc_scale_table2[128]={ -// 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 - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -}; - -static const uint8_t mpeg2_dc_scale_table3[128]={ -// 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 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 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 * const mpeg2_dc_scale_table[4]={ - ff_mpeg1_dc_scale_table, - mpeg2_dc_scale_table1, - mpeg2_dc_scale_table2, - mpeg2_dc_scale_table3, -}; - #endif /* AVCODEC_MPEG12DECDATA_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg12enc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg12enc.c index 1b5632dbcb..bf36129029 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg12enc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg12enc.c @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/mpeg12enc.c + * @file * MPEG1/2 encoder */ @@ -327,7 +327,12 @@ static av_always_inline void put_qscale(MpegEncContext *s) } void ff_mpeg1_encode_slice_header(MpegEncContext *s){ - put_header(s, SLICE_MIN_START_CODE + s->mb_y); + if (s->height > 2800) { + put_header(s, SLICE_MIN_START_CODE + (s->mb_y & 127)); + put_bits(&s->pb, 3, s->mb_y >> 7); /* slice_vertical_position_extension */ + } else { + put_header(s, SLICE_MIN_START_CODE + s->mb_y); + } put_qscale(s); put_bits(&s->pb, 1, 0); /* slice extra information */ } @@ -927,28 +932,28 @@ static void mpeg1_encode_block(MpegEncContext *s, AVCodec mpeg1video_encoder = { "mpeg1video", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_MPEG1VIDEO, sizeof(MpegEncContext), encode_init, MPV_encode_picture, MPV_encode_end, .supported_framerates= ff_frame_rate_tab+1, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, .capabilities= CODEC_CAP_DELAY, .long_name= NULL_IF_CONFIG_SMALL("MPEG-1 video"), }; AVCodec mpeg2video_encoder = { "mpeg2video", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_MPEG2VIDEO, sizeof(MpegEncContext), encode_init, MPV_encode_picture, MPV_encode_end, .supported_framerates= ff_frame_rate_tab+1, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_NONE}, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_NONE}, .capabilities= CODEC_CAP_DELAY, .long_name= NULL_IF_CONFIG_SMALL("MPEG-2 video"), }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg4audio.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg4audio.c index 6c0bc7d76a..7507212c76 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg4audio.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg4audio.c @@ -24,6 +24,34 @@ #include "put_bits.h" #include "mpeg4audio.h" +/** + * Parse MPEG-4 audio configuration for ALS object type. + * @param[in] gb bit reader context + * @param[in] c MPEG4AudioConfig structure to fill + * @return on success 0 is returned, otherwise a value < 0 + */ +static int parse_config_ALS(GetBitContext *gb, MPEG4AudioConfig *c) +{ + if (get_bits_left(gb) < 112) + return -1; + + if (get_bits_long(gb, 32) != MKBETAG('A','L','S','\0')) + return -1; + + // override AudioSpecificConfig channel configuration and sample rate + // which are buggy in old ALS conformance files + c->sample_rate = get_bits_long(gb, 32); + + // skip number of samples + skip_bits_long(gb, 32); + + // read number of channels + c->chan_config = 0; + c->channels = get_bits(gb, 16) + 1; + + return 0; +} + const int ff_mpeg4audio_sample_rates[16] = { 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350 @@ -57,9 +85,16 @@ int ff_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, int buf_si c->object_type = get_object_type(&gb); c->sample_rate = get_sample_rate(&gb, &c->sampling_index); c->chan_config = get_bits(&gb, 4); + if (c->chan_config < FF_ARRAY_ELEMS(ff_mpeg4audio_channels)) + c->channels = ff_mpeg4audio_channels[c->chan_config]; c->sbr = -1; - if (c->object_type == AOT_SBR) { - c->ext_object_type = c->object_type; + c->ps = -1; + if (c->object_type == AOT_SBR || (c->object_type == AOT_PS && + // check for W6132 Annex YYYY draft MP3onMP4 + !(show_bits(&gb, 3) & 0x03 && !(show_bits(&gb, 9) & 0x3F)))) { + if (c->object_type == AOT_PS) + c->ps = 1; + c->ext_object_type = AOT_SBR; c->sbr = 1; c->ext_sample_rate = get_sample_rate(&gb, &c->ext_sampling_index); c->object_type = get_object_type(&gb); @@ -71,14 +106,26 @@ int ff_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, int buf_si } specific_config_bitindex = get_bits_count(&gb); + if (c->object_type == AOT_ALS) { + skip_bits(&gb, 5); + if (show_bits_long(&gb, 24) != MKBETAG('\0','A','L','S')) + skip_bits_long(&gb, 24); + + specific_config_bitindex = get_bits_count(&gb); + + if (parse_config_ALS(&gb, c)) + return -1; + } + if (c->ext_object_type != AOT_SBR) { - int bits_left = buf_size*8 - specific_config_bitindex; - for (; bits_left > 15; bits_left--) { + while (get_bits_left(&gb) > 15) { if (show_bits(&gb, 11) == 0x2b7) { // sync extension get_bits(&gb, 11); c->ext_object_type = get_object_type(&gb); if (c->ext_object_type == AOT_SBR && (c->sbr = get_bits1(&gb)) == 1) c->ext_sample_rate = get_sample_rate(&gb, &c->ext_sampling_index); + if (get_bits_left(&gb) > 11 && get_bits(&gb, 11) == 0x548) + c->ps = get_bits1(&gb); break; } else get_bits1(&gb); // skip 1 bit diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg4audio.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg4audio.h index 98cddad2b1..b94185079d 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg4audio.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg4audio.h @@ -36,6 +36,8 @@ typedef struct { int ext_sampling_index; int ext_sample_rate; int ext_chan_config; + int channels; + int ps; //< -1 implicit, 1 presence } MPEG4AudioConfig; extern const int ff_mpeg4audio_sample_rates[16]; @@ -56,7 +58,7 @@ enum AudioObjectType { AOT_AAC_LC, ///< Y Low Complexity AOT_AAC_SSR, ///< N (code in SoC repo) Scalable Sample Rate AOT_AAC_LTP, ///< N (code in SoC repo) Long Term Prediction - AOT_SBR, ///< N (in progress) Spectral Band Replication + AOT_SBR, ///< Y Spectral Band Replication AOT_AAC_SCALABLE, ///< N Scalable AOT_TWINVQ, ///< N Twin Vector Quantizer AOT_CELP, ///< N Code Excited Linear Prediction @@ -84,7 +86,7 @@ enum AudioObjectType { AOT_L2, ///< Y Layer 2 AOT_L3, ///< Y Layer 3 AOT_DST, ///< N Direct Stream Transfer - AOT_ALS, ///< N Audio LosslesS + AOT_ALS, ///< Y Audio LosslesS AOT_SLS, ///< N Scalable LosslesS AOT_SLS_NON_CORE, ///< N Scalable LosslesS (non core) AOT_ER_AAC_ELD, ///< N Error Resilient Enhanced Low Delay @@ -92,7 +94,8 @@ enum AudioObjectType { AOT_SMR_MAIN, ///< N Symbolic Music Representation Main AOT_USAC_NOSBR, ///< N Unified Speech and Audio Coding (no SBR) AOT_SAOC, ///< N Spatial Audio Object Coding - AOT_USAC = 45, ///< N Unified Speech and Audio Coding + AOT_LD_SURROUND, ///< N Low Delay MPEG Surround + AOT_USAC, ///< N Unified Speech and Audio Coding }; #define MAX_PCE_SIZE 304 /// #include "mpegvideo.h" -// shapes -#define RECT_SHAPE 0 -#define BIN_SHAPE 1 -#define BIN_ONLY_SHAPE 2 -#define GRAY_SHAPE 3 - -#define SIMPLE_VO_TYPE 1 -#define CORE_VO_TYPE 3 -#define MAIN_VO_TYPE 4 -#define NBIT_VO_TYPE 5 -#define ARTS_VO_TYPE 10 -#define ACE_VO_TYPE 12 -#define ADV_SIMPLE_VO_TYPE 17 - -// aspect_ratio_info -#define EXTENDED_PAR 15 - -//vol_sprite_usage / sprite_enable -#define STATIC_SPRITE 1 -#define GMC_SPRITE 2 - -#define MOTION_MARKER 0x1F001 -#define DC_MARKER 0x6B001 - -static const int mb_type_b_map[4]= { - MB_TYPE_DIRECT2 | MB_TYPE_L0L1, - MB_TYPE_L0L1 | MB_TYPE_16x16, - MB_TYPE_L1 | MB_TYPE_16x16, - MB_TYPE_L0 | MB_TYPE_16x16, -}; - -#define VOS_STARTCODE 0x1B0 -#define USER_DATA_STARTCODE 0x1B2 -#define GOP_STARTCODE 0x1B3 -#define VISUAL_OBJ_STARTCODE 0x1B5 -#define VOP_STARTCODE 0x1B6 - /* dc encoding for mpeg4 */ -const uint8_t DCtab_lum[13][2] = +const uint8_t ff_mpeg4_DCtab_lum[13][2] = { {3,3}, {3,2}, {2,2}, {2,3}, {1,3}, {1,4}, {1,5}, {1,6}, {1,7}, {1,8}, {1,9}, {1,10}, {1,11}, }; -const uint8_t DCtab_chrom[13][2] = +const uint8_t ff_mpeg4_DCtab_chrom[13][2] = { {3,2}, {2,2}, {1,2}, {1,3}, {1,4}, {1,5}, {1,6}, {1,7}, {1,8}, {1,9}, {1,10}, {1,11}, {1,12}, }; -const uint16_t intra_vlc[103][2] = { +const uint16_t ff_mpeg4_intra_vlc[103][2] = { { 0x2, 2 }, { 0x6, 3 },{ 0xf, 4 },{ 0xd, 5 },{ 0xc, 5 }, { 0x15, 6 },{ 0x13, 6 },{ 0x12, 6 },{ 0x17, 7 }, @@ -111,7 +74,7 @@ const uint16_t intra_vlc[103][2] = { { 0x5f, 12 },{ 0x3, 7 }, }; -const int8_t intra_level[102] = { +const int8_t ff_mpeg4_intra_level[102] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, @@ -127,7 +90,7 @@ const int8_t intra_level[102] = { 1, 1, 1, 1, 1, 1, }; -const int8_t intra_run[102] = { +const int8_t ff_mpeg4_intra_run[102] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -143,16 +106,16 @@ const int8_t intra_run[102] = { 15, 16, 17, 18, 19, 20, }; -static RLTable rl_intra = { +RLTable ff_mpeg4_rl_intra = { 102, 67, - intra_vlc, - intra_run, - intra_level, + ff_mpeg4_intra_vlc, + ff_mpeg4_intra_run, + ff_mpeg4_intra_level, }; /* Note this is identical to the intra rvlc except that it is reordered. */ -static const uint16_t inter_rvlc[170][2]={ +const uint16_t inter_rvlc[170][2]={ {0x0006, 3},{0x0001, 4},{0x0004, 5},{0x001C, 7}, {0x003C, 8},{0x003D, 8},{0x007C, 9},{0x00FC, 10}, {0x00FD, 10},{0x01FC, 11},{0x01FD, 11},{0x03FC, 12}, @@ -248,7 +211,7 @@ static const int8_t inter_rvlc_level[169]={ 1, 1, }; -static RLTable rvlc_rl_inter = { +RLTable rvlc_rl_inter = { 169, 103, inter_rvlc, @@ -256,7 +219,7 @@ static RLTable rvlc_rl_inter = { inter_rvlc_level, }; -static const uint16_t intra_rvlc[170][2]={ +const uint16_t intra_rvlc[170][2]={ {0x0006, 3},{0x0007, 3},{0x000A, 4},{0x0009, 5}, {0x0014, 6},{0x0015, 6},{0x0034, 7},{0x0074, 8}, {0x0075, 8},{0x00DD, 9},{0x00EC, 9},{0x01EC, 10}, @@ -352,7 +315,7 @@ static const int8_t intra_rvlc_level[169]={ 1, 1, }; -static RLTable rvlc_rl_intra = { +RLTable rvlc_rl_intra = { 169, 103, intra_rvlc, @@ -360,35 +323,16 @@ static RLTable rvlc_rl_intra = { intra_rvlc_level, }; -static const uint16_t sprite_trajectory_tab[15][2] = { +const uint16_t sprite_trajectory_tab[15][2] = { {0x00, 2}, {0x02, 3}, {0x03, 3}, {0x04, 3}, {0x05, 3}, {0x06, 3}, {0x0E, 4}, {0x1E, 5}, {0x3E, 6}, {0x7E, 7}, {0xFE, 8}, {0x1FE, 9},{0x3FE, 10},{0x7FE, 11},{0xFFE, 12}, }; -static const uint8_t mb_type_b_tab[4][2] = { +const uint8_t mb_type_b_tab[4][2] = { {1, 1}, {1, 2}, {1, 3}, {1, 4}, }; -static const AVRational pixel_aspect[16]={ - {0, 1}, - {1, 1}, - {12, 11}, - {10, 11}, - {16, 11}, - {40, 33}, - {0, 1}, - {0, 1}, - {0, 1}, - {0, 1}, - {0, 1}, - {0, 1}, - {0, 1}, - {0, 1}, - {0, 1}, - {0, 1}, -}; - /* these matrixes will be permuted for the idct */ const int16_t ff_mpeg4_default_intra_matrix[64] = { 8, 17, 18, 19, 21, 23, 25, 27, @@ -425,7 +369,7 @@ const uint16_t ff_mpeg4_resync_prefix[8]={ 0x7F00, 0x7E00, 0x7C00, 0x7800, 0x7000, 0x6000, 0x4000, 0x0000 }; -static const uint8_t mpeg4_dc_threshold[8]={ +const uint8_t mpeg4_dc_threshold[8]={ 99, 13, 15, 17, 19, 21, 23, 0 }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg4video.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg4video.c new file mode 100644 index 0000000000..dd4dd8ad95 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg4video.c @@ -0,0 +1,171 @@ +/* + * MPEG4 decoder / encoder common code. + * Copyright (c) 2000,2001 Fabrice Bellard + * Copyright (c) 2002-2010 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 + */ + +#include "mpegvideo.h" +#include "mpeg4video.h" +#include "mpeg4data.h" + +uint8_t ff_mpeg4_static_rl_table_store[3][2][2*MAX_RUN + MAX_LEVEL + 3]; + +int ff_mpeg4_get_video_packet_prefix_length(MpegEncContext *s){ + switch(s->pict_type){ + case FF_I_TYPE: + return 16; + case FF_P_TYPE: + case FF_S_TYPE: + return s->f_code+15; + case FF_B_TYPE: + return FFMAX3(s->f_code, s->b_code, 2) + 15; + default: + return -1; + } +} + +void ff_mpeg4_clean_buffers(MpegEncContext *s) +{ + int c_wrap, c_xy, l_wrap, l_xy; + + l_wrap= s->b8_stride; + l_xy= (2*s->mb_y-1)*l_wrap + s->mb_x*2 - 1; + c_wrap= s->mb_stride; + c_xy= (s->mb_y-1)*c_wrap + s->mb_x - 1; + +#if 0 + /* clean DC */ + memsetw(s->dc_val[0] + l_xy, 1024, l_wrap*2+1); + memsetw(s->dc_val[1] + c_xy, 1024, c_wrap+1); + memsetw(s->dc_val[2] + c_xy, 1024, c_wrap+1); +#endif + + /* clean AC */ + memset(s->ac_val[0] + l_xy, 0, (l_wrap*2+1)*16*sizeof(int16_t)); + memset(s->ac_val[1] + c_xy, 0, (c_wrap +1)*16*sizeof(int16_t)); + memset(s->ac_val[2] + c_xy, 0, (c_wrap +1)*16*sizeof(int16_t)); + + /* clean MV */ + // we can't clear the MVs as they might be needed by a b frame +// memset(s->motion_val + l_xy, 0, (l_wrap*2+1)*2*sizeof(int16_t)); +// memset(s->motion_val, 0, 2*sizeof(int16_t)*(2 + s->mb_width*2)*(2 + s->mb_height*2)); + s->last_mv[0][0][0]= + s->last_mv[0][0][1]= + s->last_mv[1][0][0]= + s->last_mv[1][0][1]= 0; +} + +#define tab_size ((signed)FF_ARRAY_ELEMS(s->direct_scale_mv[0])) +#define tab_bias (tab_size/2) + +//used by mpeg4 and rv10 decoder +void ff_mpeg4_init_direct_mv(MpegEncContext *s){ + int i; + for(i=0; idirect_scale_mv[0][i] = (i-tab_bias)*s->pb_time/s->pp_time; + s->direct_scale_mv[1][i] = (i-tab_bias)*(s->pb_time-s->pp_time)/s->pp_time; + } +} + +static inline void ff_mpeg4_set_one_direct_mv(MpegEncContext *s, int mx, int my, int i){ + int xy= s->block_index[i]; + uint16_t time_pp= s->pp_time; + uint16_t time_pb= s->pb_time; + int p_mx, p_my; + + p_mx= s->next_picture.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 + : s->direct_scale_mv[1][p_mx + tab_bias]; + }else{ + s->mv[0][i][0] = p_mx*time_pb/time_pp + mx; + 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]; + 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 + : s->direct_scale_mv[1][p_my + tab_bias]; + }else{ + s->mv[0][i][1] = p_my*time_pb/time_pp + my; + s->mv[1][i][1] = my ? s->mv[0][i][1] - p_my + : p_my*(time_pb - time_pp)/time_pp; + } +} + +#undef tab_size +#undef tab_bias + +/** + * + * @return the mb_type + */ +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]; + uint16_t time_pp; + uint16_t time_pb; + int i; + + //FIXME avoid divides + // try special case with shifts for 1 and 3 B-frames? + + if(IS_8X8(colocated_mb_type)){ + s->mv_type = MV_TYPE_8X8; + for(i=0; i<4; i++){ + ff_mpeg4_set_one_direct_mv(s, mx, my, i); + } + return MB_TYPE_DIRECT2 | MB_TYPE_8x8 | MB_TYPE_L0L1; + } 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]; + s->field_select[0][i]= field_select; + s->field_select[1][i]= i; + if(s->top_field_first){ + time_pp= s->pp_field_time - field_select + i; + time_pb= s->pb_field_time - field_select + i; + }else{ + time_pp= s->pp_field_time + field_select - i; + time_pb= s->pb_field_time + field_select - i; + } + s->mv[0][i][0] = s->p_field_mv_table[i][0][mb_index][0]*time_pb/time_pp + mx; + s->mv[0][i][1] = s->p_field_mv_table[i][0][mb_index][1]*time_pb/time_pp + my; + s->mv[1][i][0] = mx ? s->mv[0][i][0] - s->p_field_mv_table[i][0][mb_index][0] + : s->p_field_mv_table[i][0][mb_index][0]*(time_pb - time_pp)/time_pp; + s->mv[1][i][1] = my ? s->mv[0][i][1] - s->p_field_mv_table[i][0][mb_index][1] + : s->p_field_mv_table[i][0][mb_index][1]*(time_pb - time_pp)/time_pp; + } + return MB_TYPE_DIRECT2 | MB_TYPE_16x8 | MB_TYPE_L0L1 | MB_TYPE_INTERLACED; + }else{ + ff_mpeg4_set_one_direct_mv(s, mx, my, 0); + s->mv[0][1][0] = s->mv[0][2][0] = s->mv[0][3][0] = s->mv[0][0][0]; + s->mv[0][1][1] = s->mv[0][2][1] = s->mv[0][3][1] = s->mv[0][0][1]; + s->mv[1][1][0] = s->mv[1][2][0] = s->mv[1][3][0] = s->mv[1][0][0]; + s->mv[1][1][1] = s->mv[1][2][1] = s->mv[1][3][1] = s->mv[1][0][1]; + if((s->avctx->workaround_bugs & FF_BUG_DIRECT_BLOCKSIZE) || !s->quarter_sample) + s->mv_type= MV_TYPE_16X16; + else + s->mv_type= MV_TYPE_8X8; + return MB_TYPE_DIRECT2 | MB_TYPE_16x16 | MB_TYPE_L0L1; //Note see prev line + } +} + diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg4video.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg4video.h new file mode 100644 index 0000000000..aab32364e5 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg4video.h @@ -0,0 +1,202 @@ +/* + * MPEG4 encoder/decoder internal header. + * Copyright (c) 2000,2001 Fabrice Bellard + * Copyright (c) 2002-2010 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 + */ + +#ifndef AVCODEC_MPEG4VIDEO_H +#define AVCODEC_MPEG4VIDEO_H + +#include +#include "get_bits.h" +#include "mpegvideo.h" +#include "rl.h" + +// shapes +#define RECT_SHAPE 0 +#define BIN_SHAPE 1 +#define BIN_ONLY_SHAPE 2 +#define GRAY_SHAPE 3 + +#define SIMPLE_VO_TYPE 1 +#define CORE_VO_TYPE 3 +#define MAIN_VO_TYPE 4 +#define NBIT_VO_TYPE 5 +#define ARTS_VO_TYPE 10 +#define ACE_VO_TYPE 12 +#define ADV_SIMPLE_VO_TYPE 17 + +// aspect_ratio_info +#define EXTENDED_PAR 15 + +//vol_sprite_usage / sprite_enable +#define STATIC_SPRITE 1 +#define GMC_SPRITE 2 + +#define MOTION_MARKER 0x1F001 +#define DC_MARKER 0x6B001 + +#define VOS_STARTCODE 0x1B0 +#define USER_DATA_STARTCODE 0x1B2 +#define GOP_STARTCODE 0x1B3 +#define VISUAL_OBJ_STARTCODE 0x1B5 +#define VOP_STARTCODE 0x1B6 + +/* dc encoding for mpeg4 */ +extern const uint8_t ff_mpeg4_DCtab_lum[13][2]; +extern const uint8_t ff_mpeg4_DCtab_chrom[13][2]; + +extern const uint16_t ff_mpeg4_intra_vlc[103][2]; +extern RLTable ff_mpeg4_rl_intra; + +/* Note this is identical to the intra rvlc except that it is reordered. */ +extern const uint16_t inter_rvlc[170][2]; +extern RLTable rvlc_rl_inter; + +extern const uint16_t intra_rvlc[170][2]; +extern RLTable rvlc_rl_intra; + +extern const uint16_t sprite_trajectory_tab[15][2]; +extern const uint8_t mb_type_b_tab[4][2]; + +/* these matrixes will be permuted for the idct */ +extern const int16_t ff_mpeg4_default_intra_matrix[64]; +extern const int16_t ff_mpeg4_default_non_intra_matrix[64]; + +extern const uint8_t ff_mpeg4_y_dc_scale_table[32]; +extern const uint8_t ff_mpeg4_c_dc_scale_table[32]; +extern const uint16_t ff_mpeg4_resync_prefix[8]; + +extern const uint8_t mpeg4_dc_threshold[8]; + +void mpeg4_encode_mb(MpegEncContext *s, + DCTELEM block[6][64], + int motion_x, int motion_y); +void mpeg4_pred_ac(MpegEncContext * s, DCTELEM *block, int n, + int dir); +void ff_set_mpeg4_time(MpegEncContext * s); +void mpeg4_encode_picture_header(MpegEncContext *s, int picture_number); + +int ff_mpeg4_decode_picture_header(MpegEncContext * s, GetBitContext *gb); +void ff_mpeg4_encode_video_packet_header(MpegEncContext *s); +void ff_mpeg4_clean_buffers(MpegEncContext *s); +void ff_mpeg4_stuffing(PutBitContext * pbc); +void ff_mpeg4_init_partitions(MpegEncContext *s); +void ff_mpeg4_merge_partitions(MpegEncContext *s); +void ff_clean_mpeg4_qscales(MpegEncContext *s); +int ff_mpeg4_decode_partitions(MpegEncContext *s); +int ff_mpeg4_get_video_packet_prefix_length(MpegEncContext *s); +int mpeg4_decode_video_packet_header(MpegEncContext *s); +void ff_mpeg4_init_direct_mv(MpegEncContext *s); + +/** + * + * @return the mb_type + */ +int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my); + +extern uint8_t ff_mpeg4_static_rl_table_store[3][2][2*MAX_RUN + MAX_LEVEL + 3]; + + +#if 0 //3IV1 is quite rare and it slows things down a tiny bit +#define IS_3IV1 s->codec_tag == AV_RL32("3IV1") +#else +#define IS_3IV1 0 +#endif + + +/** + * predicts the dc. + * encoding quantized level -> quantized diff + * decoding quantized diff -> quantized level + * @param n block index (0-3 are luma, 4-5 are chroma) + * @param dir_ptr pointer to an integer where the prediction direction will be stored + */ +static inline int ff_mpeg4_pred_dc(MpegEncContext * s, int n, int level, int *dir_ptr, int encoding) +{ + int a, b, c, wrap, pred, scale, ret; + int16_t *dc_val; + + /* find prediction */ + if (n < 4) { + scale = s->y_dc_scale; + } else { + scale = s->c_dc_scale; + } + if(IS_3IV1) + scale= 8; + + wrap= s->block_wrap[n]; + dc_val = s->dc_val[0] + s->block_index[n]; + + /* B C + * A X + */ + a = dc_val[ - 1]; + b = dc_val[ - 1 - wrap]; + c = dc_val[ - wrap]; + + /* outside slice handling (we can't do that by memset as we need the dc for error resilience) */ + if(s->first_slice_line && n!=3){ + if(n!=2) b=c= 1024; + if(n!=1 && s->mb_x == s->resync_mb_x) b=a= 1024; + } + if(s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y+1){ + if(n==0 || n==4 || n==5) + b=1024; + } + + if (abs(a - b) < abs(b - c)) { + pred = c; + *dir_ptr = 1; /* top */ + } else { + pred = a; + *dir_ptr = 0; /* left */ + } + /* we assume pred is positive */ + pred = FASTDIV((pred + (scale >> 1)), scale); + + if(encoding){ + ret = level - pred; + }else{ + level += pred; + ret= level; + if(s->error_recognition>=3){ + if(level<0){ + av_log(s->avctx, AV_LOG_ERROR, "dc<0 at %dx%d\n", s->mb_x, s->mb_y); + return -1; + } + if(level*scale > 2048 + scale){ + av_log(s->avctx, AV_LOG_ERROR, "dc overflow at %dx%d\n", s->mb_x, s->mb_y); + return -1; + } + } + } + level *=scale; + if(level&(~2047)){ + if(level<0) + level=0; + else if(!(s->workaround_bugs&FF_BUG_DC_CLIP)) + level=2047; + } + dc_val[0]= level; + + return ret; +} +#endif diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg4video_parser.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg4video_parser.c index 06094c6f54..5dbda8ba80 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg4video_parser.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg4video_parser.c @@ -22,6 +22,7 @@ #include "parser.h" #include "mpegvideo.h" +#include "mpeg4video.h" #include "mpeg4video_parser.h" @@ -82,7 +83,7 @@ static int av_mpeg4_decode_header(AVCodecParserContext *s1, init_get_bits(gb, buf, 8 * buf_size); ret = ff_mpeg4_decode_picture_header(s, gb); - if (s->width) { + if (s->width && (!avctx->width || !avctx->height || !avctx->coded_width || !avctx->coded_height)) { avcodec_set_dimensions(avctx, s->width, s->height); } s1->pict_type= s->pict_type; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg4videodec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg4videodec.c new file mode 100644 index 0000000000..fa69c9ef87 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg4videodec.c @@ -0,0 +1,2267 @@ +/* + * MPEG4 decoder. + * Copyright (c) 2000,2001 Fabrice Bellard + * Copyright (c) 2002-2010 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 + */ + +#include "mpegvideo.h" +#include "mpeg4video.h" +#include "h263.h" + +// The defines below define the number of bits that are read at once for +// reading vlc values. Changing these may improve speed and data cache needs +// be aware though that decreasing them may need the number of stages that is +// passed to get_vlc* to be increased. +#define SPRITE_TRAJ_VLC_BITS 6 +#define DC_VLC_BITS 9 +#define MB_TYPE_B_VLC_BITS 4 + + +static VLC dc_lum, dc_chrom; +static VLC sprite_trajectory; +static VLC mb_type_b_vlc; + +static const int mb_type_b_map[4]= { + MB_TYPE_DIRECT2 | MB_TYPE_L0L1, + MB_TYPE_L0L1 | MB_TYPE_16x16, + MB_TYPE_L1 | MB_TYPE_16x16, + MB_TYPE_L0 | MB_TYPE_16x16, +}; + +/** + * predicts the ac. + * @param n block index (0-3 are luma, 4-5 are chroma) + * @param dir the ac prediction direction + */ +void mpeg4_pred_ac(MpegEncContext * s, DCTELEM *block, int n, + int dir) +{ + int i; + int16_t *ac_val, *ac_val1; + int8_t * const qscale_table= s->current_picture.qscale_table; + + /* find prediction */ + ac_val = s->ac_val[0][0] + s->block_index[n] * 16; + ac_val1 = ac_val; + if (s->ac_pred) { + if (dir == 0) { + const int xy= s->mb_x-1 + s->mb_y*s->mb_stride; + /* left prediction */ + ac_val -= 16; + + if(s->mb_x==0 || s->qscale == qscale_table[xy] || n==1 || n==3){ + /* same qscale */ + for(i=1;i<8;i++) { + block[s->dsp.idct_permutation[i<<3]] += ac_val[i]; + } + }else{ + /* different qscale, we must rescale */ + for(i=1;i<8;i++) { + block[s->dsp.idct_permutation[i<<3]] += ROUNDED_DIV(ac_val[i]*qscale_table[xy], s->qscale); + } + } + } else { + const int xy= s->mb_x + s->mb_y*s->mb_stride - s->mb_stride; + /* top prediction */ + ac_val -= 16 * s->block_wrap[n]; + + if(s->mb_y==0 || s->qscale == qscale_table[xy] || n==2 || n==3){ + /* same qscale */ + for(i=1;i<8;i++) { + block[s->dsp.idct_permutation[i]] += ac_val[i + 8]; + } + }else{ + /* different qscale, we must rescale */ + for(i=1;i<8;i++) { + block[s->dsp.idct_permutation[i]] += ROUNDED_DIV(ac_val[i + 8]*qscale_table[xy], s->qscale); + } + } + } + } + /* left copy */ + for(i=1;i<8;i++) + ac_val1[i ] = block[s->dsp.idct_permutation[i<<3]]; + + /* top copy */ + for(i=1;i<8;i++) + ac_val1[8 + i] = block[s->dsp.idct_permutation[i ]]; + +} + +/** + * check if the next stuff is a resync marker or the end. + * @return 0 if not + */ +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){ + return 0; + } + + while(v<=0xFF){ + if(s->pict_type==FF_B_TYPE || (v>>(8-s->pict_type)!=1) || s->partitioned_frame) + break; + skip_bits(&s->gb, 8+s->pict_type); + bits_count+= 8+s->pict_type; + v= show_bits(&s->gb, 16); + } + + if(bits_count + 8 >= s->gb.size_in_bits){ + v>>=8; + v|= 0x7F >> (7-(bits_count&7)); + + if(v==0x7F) + return 1; + }else{ + if(v == ff_mpeg4_resync_prefix[bits_count&7]){ + int len; + GetBitContext gb= s->gb; + + skip_bits(&s->gb, 1); + align_get_bits(&s->gb); + + for(len=0; len<32; len++){ + if(get_bits1(&s->gb)) break; + } + + s->gb= gb; + + if(len>=ff_mpeg4_get_video_packet_prefix_length(s)) + return 1; + } + } + return 0; +} + +static void mpeg4_decode_sprite_trajectory(MpegEncContext * s, GetBitContext *gb) +{ + int i; + int a= 2<sprite_warping_accuracy; + int rho= 3-s->sprite_warping_accuracy; + int r=16/a; + const int vop_ref[4][2]= {{0,0}, {s->width,0}, {0, s->height}, {s->width, s->height}}; // only true for rectangle shapes + int d[4][2]={{0,0}, {0,0}, {0,0}, {0,0}}; + int sprite_ref[4][2]; + int virtual_ref[2][2]; + int w2, h2, w3, h3; + int alpha=0, beta=0; + int w= s->width; + int h= s->height; + int min_ab; + + for(i=0; inum_sprite_warping_points; i++){ + int length; + int x=0, y=0; + + length= get_vlc2(gb, sprite_trajectory.table, SPRITE_TRAJ_VLC_BITS, 3); + if(length){ + x= get_xbits(gb, length); + } + if(!(s->divx_version==500 && s->divx_build==413)) skip_bits1(gb); /* marker bit */ + + length= get_vlc2(gb, sprite_trajectory.table, SPRITE_TRAJ_VLC_BITS, 3); + if(length){ + y=get_xbits(gb, length); + } + skip_bits1(gb); /* marker bit */ + s->sprite_traj[i][0]= d[i][0]= x; + s->sprite_traj[i][1]= d[i][1]= y; + } + for(; i<4; i++) + s->sprite_traj[i][0]= s->sprite_traj[i][1]= 0; + + while((1<divx_version==500 && s->divx_build==413){ + sprite_ref[0][0]= a*vop_ref[0][0] + d[0][0]; + sprite_ref[0][1]= a*vop_ref[0][1] + d[0][1]; + sprite_ref[1][0]= a*vop_ref[1][0] + d[0][0] + d[1][0]; + sprite_ref[1][1]= a*vop_ref[1][1] + d[0][1] + d[1][1]; + sprite_ref[2][0]= a*vop_ref[2][0] + d[0][0] + d[2][0]; + sprite_ref[2][1]= a*vop_ref[2][1] + d[0][1] + d[2][1]; + } else { + sprite_ref[0][0]= (a>>1)*(2*vop_ref[0][0] + d[0][0]); + sprite_ref[0][1]= (a>>1)*(2*vop_ref[0][1] + d[0][1]); + sprite_ref[1][0]= (a>>1)*(2*vop_ref[1][0] + d[0][0] + d[1][0]); + sprite_ref[1][1]= (a>>1)*(2*vop_ref[1][1] + d[0][1] + d[1][1]); + sprite_ref[2][0]= (a>>1)*(2*vop_ref[2][0] + d[0][0] + d[2][0]); + sprite_ref[2][1]= (a>>1)*(2*vop_ref[2][1] + d[0][1] + d[2][1]); + } +/* sprite_ref[3][0]= (a>>1)*(2*vop_ref[3][0] + d[0][0] + d[1][0] + d[2][0] + d[3][0]); + sprite_ref[3][1]= (a>>1)*(2*vop_ref[3][1] + d[0][1] + d[1][1] + d[2][1] + d[3][1]); */ + +// this is mostly identical to the mpeg4 std (and is totally unreadable because of that ...) +// perhaps it should be reordered to be more readable ... +// the idea behind this virtual_ref mess is to be able to use shifts later per pixel instead of divides +// so the distance between points is converted from w&h based to w2&h2 based which are of the 2^x form + virtual_ref[0][0]= 16*(vop_ref[0][0] + w2) + + ROUNDED_DIV(((w - w2)*(r*sprite_ref[0][0] - 16*vop_ref[0][0]) + w2*(r*sprite_ref[1][0] - 16*vop_ref[1][0])),w); + virtual_ref[0][1]= 16*vop_ref[0][1] + + ROUNDED_DIV(((w - w2)*(r*sprite_ref[0][1] - 16*vop_ref[0][1]) + w2*(r*sprite_ref[1][1] - 16*vop_ref[1][1])),w); + virtual_ref[1][0]= 16*vop_ref[0][0] + + ROUNDED_DIV(((h - h2)*(r*sprite_ref[0][0] - 16*vop_ref[0][0]) + h2*(r*sprite_ref[2][0] - 16*vop_ref[2][0])),h); + virtual_ref[1][1]= 16*(vop_ref[0][1] + h2) + + ROUNDED_DIV(((h - h2)*(r*sprite_ref[0][1] - 16*vop_ref[0][1]) + h2*(r*sprite_ref[2][1] - 16*vop_ref[2][1])),h); + + switch(s->num_sprite_warping_points) + { + case 0: + s->sprite_offset[0][0]= 0; + s->sprite_offset[0][1]= 0; + s->sprite_offset[1][0]= 0; + s->sprite_offset[1][1]= 0; + s->sprite_delta[0][0]= a; + s->sprite_delta[0][1]= 0; + s->sprite_delta[1][0]= 0; + s->sprite_delta[1][1]= a; + s->sprite_shift[0]= 0; + s->sprite_shift[1]= 0; + break; + case 1: //GMC only + s->sprite_offset[0][0]= sprite_ref[0][0] - a*vop_ref[0][0]; + s->sprite_offset[0][1]= sprite_ref[0][1] - a*vop_ref[0][1]; + s->sprite_offset[1][0]= ((sprite_ref[0][0]>>1)|(sprite_ref[0][0]&1)) - a*(vop_ref[0][0]/2); + s->sprite_offset[1][1]= ((sprite_ref[0][1]>>1)|(sprite_ref[0][1]&1)) - a*(vop_ref[0][1]/2); + s->sprite_delta[0][0]= a; + s->sprite_delta[0][1]= 0; + s->sprite_delta[1][0]= 0; + s->sprite_delta[1][1]= a; + s->sprite_shift[0]= 0; + s->sprite_shift[1]= 0; + break; + case 2: + s->sprite_offset[0][0]= (sprite_ref[0][0]<<(alpha+rho)) + + (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-vop_ref[0][0]) + + ( r*sprite_ref[0][1] - virtual_ref[0][1])*(-vop_ref[0][1]) + + (1<<(alpha+rho-1)); + s->sprite_offset[0][1]= (sprite_ref[0][1]<<(alpha+rho)) + + (-r*sprite_ref[0][1] + virtual_ref[0][1])*(-vop_ref[0][0]) + + (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-vop_ref[0][1]) + + (1<<(alpha+rho-1)); + s->sprite_offset[1][0]= ( (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-2*vop_ref[0][0] + 1) + +( r*sprite_ref[0][1] - virtual_ref[0][1])*(-2*vop_ref[0][1] + 1) + +2*w2*r*sprite_ref[0][0] + - 16*w2 + + (1<<(alpha+rho+1))); + s->sprite_offset[1][1]= ( (-r*sprite_ref[0][1] + virtual_ref[0][1])*(-2*vop_ref[0][0] + 1) + +(-r*sprite_ref[0][0] + virtual_ref[0][0])*(-2*vop_ref[0][1] + 1) + +2*w2*r*sprite_ref[0][1] + - 16*w2 + + (1<<(alpha+rho+1))); + s->sprite_delta[0][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0]); + s->sprite_delta[0][1]= (+r*sprite_ref[0][1] - virtual_ref[0][1]); + s->sprite_delta[1][0]= (-r*sprite_ref[0][1] + virtual_ref[0][1]); + s->sprite_delta[1][1]= (-r*sprite_ref[0][0] + virtual_ref[0][0]); + + s->sprite_shift[0]= alpha+rho; + s->sprite_shift[1]= alpha+rho+2; + break; + case 3: + min_ab= FFMIN(alpha, beta); + w3= w2>>min_ab; + h3= h2>>min_ab; + s->sprite_offset[0][0]= (sprite_ref[0][0]<<(alpha+beta+rho-min_ab)) + + (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3*(-vop_ref[0][0]) + + (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3*(-vop_ref[0][1]) + + (1<<(alpha+beta+rho-min_ab-1)); + s->sprite_offset[0][1]= (sprite_ref[0][1]<<(alpha+beta+rho-min_ab)) + + (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3*(-vop_ref[0][0]) + + (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3*(-vop_ref[0][1]) + + (1<<(alpha+beta+rho-min_ab-1)); + s->sprite_offset[1][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3*(-2*vop_ref[0][0] + 1) + + (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3*(-2*vop_ref[0][1] + 1) + + 2*w2*h3*r*sprite_ref[0][0] + - 16*w2*h3 + + (1<<(alpha+beta+rho-min_ab+1)); + s->sprite_offset[1][1]= (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3*(-2*vop_ref[0][0] + 1) + + (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3*(-2*vop_ref[0][1] + 1) + + 2*w2*h3*r*sprite_ref[0][1] + - 16*w2*h3 + + (1<<(alpha+beta+rho-min_ab+1)); + s->sprite_delta[0][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3; + s->sprite_delta[0][1]= (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3; + s->sprite_delta[1][0]= (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3; + s->sprite_delta[1][1]= (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3; + + s->sprite_shift[0]= alpha + beta + rho - min_ab; + s->sprite_shift[1]= alpha + beta + rho - min_ab + 2; + break; + } + /* try to simplify the situation */ + if( s->sprite_delta[0][0] == a<sprite_shift[0] + && s->sprite_delta[0][1] == 0 + && s->sprite_delta[1][0] == 0 + && s->sprite_delta[1][1] == a<sprite_shift[0]) + { + s->sprite_offset[0][0]>>=s->sprite_shift[0]; + s->sprite_offset[0][1]>>=s->sprite_shift[0]; + s->sprite_offset[1][0]>>=s->sprite_shift[1]; + s->sprite_offset[1][1]>>=s->sprite_shift[1]; + s->sprite_delta[0][0]= a; + s->sprite_delta[0][1]= 0; + s->sprite_delta[1][0]= 0; + s->sprite_delta[1][1]= a; + s->sprite_shift[0]= 0; + s->sprite_shift[1]= 0; + s->real_sprite_warping_points=1; + } + else{ + int shift_y= 16 - s->sprite_shift[0]; + int shift_c= 16 - s->sprite_shift[1]; + for(i=0; i<2; i++){ + s->sprite_offset[0][i]<<= shift_y; + s->sprite_offset[1][i]<<= shift_c; + s->sprite_delta[0][i]<<= shift_y; + s->sprite_delta[1][i]<<= shift_y; + s->sprite_shift[i]= 16; + } + s->real_sprite_warping_points= s->num_sprite_warping_points; + } +} + +/** + * decodes the next video packet. + * @return <0 if something went wrong + */ +int mpeg4_decode_video_packet_header(MpegEncContext *s) +{ + int mb_num_bits= av_log2(s->mb_num - 1) + 1; + int header_extension=0, mb_num, len; + + /* is there enough space left for a video packet + header */ + if( get_bits_count(&s->gb) > s->gb.size_in_bits-20) return -1; + + for(len=0; len<32; len++){ + if(get_bits1(&s->gb)) break; + } + + if(len!=ff_mpeg4_get_video_packet_prefix_length(s)){ + av_log(s->avctx, AV_LOG_ERROR, "marker does not match f_code\n"); + return -1; + } + + if(s->shape != RECT_SHAPE){ + header_extension= get_bits1(&s->gb); + //FIXME more stuff here + } + + mb_num= get_bits(&s->gb, mb_num_bits); + if(mb_num>=s->mb_num){ + 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 == FF_B_TYPE){ + while(s->next_picture.mbskip_table[ s->mb_index2xy[ mb_num ] ]) mb_num++; + 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; + + if(s->shape != BIN_ONLY_SHAPE){ + int qscale= get_bits(&s->gb, s->quant_precision); + if(qscale) + s->chroma_qscale=s->qscale= qscale; + } + + if(s->shape == RECT_SHAPE){ + header_extension= get_bits1(&s->gb); + } + if(header_extension){ + int time_increment; + int time_incr=0; + + while (get_bits1(&s->gb) != 0) + time_incr++; + + check_marker(&s->gb, "before time_increment in video packed header"); + time_increment= get_bits(&s->gb, s->time_increment_bits); + check_marker(&s->gb, "before vop_coding_type in video packed header"); + + skip_bits(&s->gb, 2); /* vop coding type */ + //FIXME not rect stuff here + + if(s->shape != BIN_ONLY_SHAPE){ + skip_bits(&s->gb, 3); /* intra dc vlc threshold */ +//FIXME don't just ignore everything + if(s->pict_type == FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE){ + mpeg4_decode_sprite_trajectory(s, &s->gb); + av_log(s->avctx, AV_LOG_ERROR, "untested\n"); + } + + //FIXME reduced res stuff here + + if (s->pict_type != FF_I_TYPE) { + int f_code = get_bits(&s->gb, 3); /* fcode_for */ + if(f_code==0){ + av_log(s->avctx, AV_LOG_ERROR, "Error, video packet header damaged (f_code=0)\n"); + } + } + if (s->pict_type == FF_B_TYPE) { + int b_code = get_bits(&s->gb, 3); + if(b_code==0){ + av_log(s->avctx, AV_LOG_ERROR, "Error, video packet header damaged (b_code=0)\n"); + } + } + } + } + //FIXME new-pred stuff + + return 0; +} + +/** + * gets the average motion vector for a GMC MB. + * @param n either 0 for the x component or 1 for y + * @return the average MV for a GMC MB + */ +static inline int get_amv(MpegEncContext *s, int n){ + int x, y, mb_v, sum, dx, dy, shift; + int len = 1 << (s->f_code + 4); + const int a= s->sprite_warping_accuracy; + + if(s->workaround_bugs & FF_BUG_AMV) + len >>= s->quarter_sample; + + if(s->real_sprite_warping_points==1){ + if(s->divx_version==500 && s->divx_build==413) + sum= s->sprite_offset[0][n] / (1<<(a - s->quarter_sample)); + else + sum= RSHIFT(s->sprite_offset[0][n]<quarter_sample, a); + }else{ + dx= s->sprite_delta[n][0]; + dy= s->sprite_delta[n][1]; + shift= s->sprite_shift[0]; + if(n) dy -= 1<<(shift + a + 1); + else dx -= 1<<(shift + a + 1); + mb_v= s->sprite_offset[0][n] + dx*s->mb_x*16 + dy*s->mb_y*16; + + sum=0; + for(y=0; y<16; y++){ + int v; + + v= mb_v + dy*y; + //XXX FIXME optimize + for(x=0; x<16; x++){ + sum+= v>>shift; + v+= dx; + } + } + sum= RSHIFT(sum, a+8-s->quarter_sample); + } + + if (sum < -len) sum= -len; + else if (sum >= len) sum= len-1; + + return sum; +} + +/** + * decodes the dc value. + * @param n block index (0-3 are luma, 4-5 are chroma) + * @param dir_ptr the prediction direction will be stored here + * @return the quantized dc + */ +static inline int mpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr) +{ + int level, code; + + if (n < 4) + code = get_vlc2(&s->gb, dc_lum.table, DC_VLC_BITS, 1); + else + code = get_vlc2(&s->gb, dc_chrom.table, DC_VLC_BITS, 1); + if (code < 0 || code > 9 /* && s->nbit<9 */){ + av_log(s->avctx, AV_LOG_ERROR, "illegal dc vlc\n"); + return -1; + } + if (code == 0) { + level = 0; + } else { + if(IS_3IV1){ + if(code==1) + level= 2*get_bits1(&s->gb)-1; + else{ + if(get_bits1(&s->gb)) + level = get_bits(&s->gb, code-1) + (1<<(code-1)); + else + level = -get_bits(&s->gb, code-1) - (1<<(code-1)); + } + }else{ + level = get_xbits(&s->gb, code); + } + + if (code > 8){ + if(get_bits1(&s->gb)==0){ /* marker */ + if(s->error_recognition>=2){ + av_log(s->avctx, AV_LOG_ERROR, "dc marker bit missing\n"); + return -1; + } + } + } + } + + return ff_mpeg4_pred_dc(s, n, level, dir_ptr, 0); +} + +/** + * decodes first partition. + * @return number of MBs decoded or <0 if an error occurred + */ +static int mpeg4_decode_partition_a(MpegEncContext *s){ + int mb_num; + static const int8_t quant_tab[4] = { -1, -2, 1, 2 }; + + /* decode first partition */ + mb_num=0; + s->first_slice_line=1; + for(; s->mb_ymb_height; s->mb_y++){ + ff_init_block_index(s); + for(; s->mb_xmb_width; s->mb_x++){ + const int xy= s->mb_x + s->mb_y*s->mb_stride; + int cbpc; + int dir=0; + + mb_num++; + ff_update_block_index(s); + if(s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y+1) + s->first_slice_line=0; + + if(s->pict_type==FF_I_TYPE){ + int i; + + do{ + if(show_bits_long(&s->gb, 19)==DC_MARKER){ + return mb_num-1; + } + + cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2); + if (cbpc < 0){ + av_log(s->avctx, AV_LOG_ERROR, "cbpc corrupted at %d %d\n", s->mb_x, s->mb_y); + return -1; + } + }while(cbpc == 8); + + s->cbp_table[xy]= cbpc & 3; + s->current_picture.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->mbintra_table[xy]= 1; + for(i=0; i<6; i++){ + int dc_pred_dir; + int dc= mpeg4_decode_dc(s, i, &dc_pred_dir); + if(dc < 0){ + av_log(s->avctx, AV_LOG_ERROR, "DC corrupted at %d %d\n", s->mb_x, s->mb_y); + return -1; + } + dir<<=1; + if(dc_pred_dir) dir|=1; + } + 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]]; + const int stride= s->b8_stride*2; + +try_again: + bits= show_bits(&s->gb, 17); + if(bits==MOTION_MARKER){ + return mb_num-1; + } + skip_bits1(&s->gb); + if(bits&0x10000){ + /* skip mb */ + if(s->pict_type==FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE){ + s->current_picture.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; + mx=my=0; + } + mot_val[0 ]= mot_val[2 ]= + mot_val[0+stride]= mot_val[2+stride]= mx; + mot_val[1 ]= mot_val[3 ]= + mot_val[1+stride]= mot_val[3+stride]= my; + + if(s->mbintra_table[xy]) + ff_clean_intra_table_entries(s); + continue; + } + + cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2); + if (cbpc < 0){ + av_log(s->avctx, AV_LOG_ERROR, "cbpc corrupted at %d %d\n", s->mb_x, s->mb_y); + return -1; + } + if(cbpc == 20) + goto try_again; + + s->cbp_table[xy]= cbpc&(8+3); //8 is dquant + + s->mb_intra = ((cbpc & 4) != 0); + + if(s->mb_intra){ + s->current_picture.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; + mot_val[1 ]= mot_val[3 ]= + mot_val[1+stride]= mot_val[3+stride]= 0; + }else{ + if(s->mbintra_table[xy]) + ff_clean_intra_table_entries(s); + + if(s->pict_type==FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE && (cbpc & 16) == 0) + s->mcsel= get_bits1(&s->gb); + else s->mcsel= 0; + + if ((cbpc & 16) == 0) { + /* 16x16 motion prediction */ + + h263_pred_motion(s, 0, 0, &pred_x, &pred_y); + if(!s->mcsel){ + mx = h263_decode_motion(s, pred_x, s->f_code); + if (mx >= 0xffff) + return -1; + + 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; + } 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; + } + + mot_val[0 ]= mot_val[2 ] = + mot_val[0+stride]= mot_val[2+stride]= mx; + mot_val[1 ]= mot_val[3 ]= + mot_val[1+stride]= mot_val[3+stride]= my; + } else { + int i; + s->current_picture.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); + if (mx >= 0xffff) + return -1; + + my = h263_decode_motion(s, pred_y, s->f_code); + if (my >= 0xffff) + return -1; + mot_val[0] = mx; + mot_val[1] = my; + } + } + } + } + } + s->mb_x= 0; + } + + return mb_num; +} + +/** + * decode second partition. + * @return <0 if an error occurred + */ +static int mpeg4_decode_partition_b(MpegEncContext *s, int mb_count){ + int mb_num=0; + static const int8_t quant_tab[4] = { -1, -2, 1, 2 }; + + s->mb_x= s->resync_mb_x; + s->first_slice_line=1; + for(s->mb_y= s->resync_mb_y; mb_num < mb_count; s->mb_y++){ + ff_init_block_index(s); + for(; mb_num < mb_count && s->mb_xmb_width; s->mb_x++){ + const int xy= s->mb_x + s->mb_y*s->mb_stride; + + mb_num++; + ff_update_block_index(s); + if(s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y+1) + s->first_slice_line=0; + + if(s->pict_type==FF_I_TYPE){ + int ac_pred= get_bits1(&s->gb); + int cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1); + if(cbpy<0){ + av_log(s->avctx, AV_LOG_ERROR, "cbpy corrupted at %d %d\n", s->mb_x, s->mb_y); + return -1; + } + + s->cbp_table[xy]|= cbpy<<2; + s->current_picture.mb_type[xy] |= ac_pred*MB_TYPE_ACPRED; + }else{ /* P || S_TYPE */ + if(IS_INTRA(s->current_picture.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); + + if(cbpy<0){ + av_log(s->avctx, AV_LOG_ERROR, "I cbpy corrupted at %d %d\n", s->mb_x, s->mb_y); + return -1; + } + + 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; + + for(i=0; i<6; i++){ + int dc_pred_dir; + int dc= mpeg4_decode_dc(s, i, &dc_pred_dir); + if(dc < 0){ + av_log(s->avctx, AV_LOG_ERROR, "DC corrupted at %d %d\n", s->mb_x, s->mb_y); + return -1; + } + dir<<=1; + if(dc_pred_dir) dir|=1; + } + 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->pred_dir_table[xy]= dir; + }else if(IS_SKIP(s->current_picture.mb_type[xy])){ + s->current_picture.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); + + if(cbpy<0){ + av_log(s->avctx, AV_LOG_ERROR, "P cbpy corrupted at %d %d\n", s->mb_x, s->mb_y); + return -1; + } + + 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->cbp_table[xy]&= 3; //remove dquant + s->cbp_table[xy]|= (cbpy^0xf)<<2; + } + } + } + if(mb_num >= mb_count) return 0; + s->mb_x= 0; + } + return 0; +} + +/** + * decodes the first & second partition + * @return <0 if error (and sets error type in the error_status_table) + */ +int ff_mpeg4_decode_partitions(MpegEncContext *s) +{ + int mb_num; + const int part_a_error= s->pict_type==FF_I_TYPE ? (DC_ERROR|MV_ERROR) : MV_ERROR; + const int part_a_end = s->pict_type==FF_I_TYPE ? (DC_END |MV_END) : MV_END; + + mb_num= mpeg4_decode_partition_a(s); + if(mb_num<0){ + ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, part_a_error); + return -1; + } + + if(s->resync_mb_x + s->resync_mb_y*s->mb_width + mb_num > s->mb_num){ + av_log(s->avctx, AV_LOG_ERROR, "slice below monitor ...\n"); + ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, part_a_error); + return -1; + } + + s->mb_num_left= mb_num; + + if(s->pict_type==FF_I_TYPE){ + while(show_bits(&s->gb, 9) == 1) + skip_bits(&s->gb, 9); + if(get_bits_long(&s->gb, 19)!=DC_MARKER){ + av_log(s->avctx, AV_LOG_ERROR, "marker missing after first I partition at %d %d\n", s->mb_x, s->mb_y); + return -1; + } + }else{ + while(show_bits(&s->gb, 10) == 1) + skip_bits(&s->gb, 10); + if(get_bits(&s->gb, 17)!=MOTION_MARKER){ + av_log(s->avctx, AV_LOG_ERROR, "marker missing after first P partition at %d %d\n", s->mb_x, s->mb_y); + return -1; + } + } + ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, part_a_end); + + if( mpeg4_decode_partition_b(s, mb_num) < 0){ + if(s->pict_type==FF_P_TYPE) + ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, DC_ERROR); + return -1; + }else{ + if(s->pict_type==FF_P_TYPE) + ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, DC_END); + } + + return 0; +} + +/** + * decodes a block. + * @return <0 if an error occurred + */ +static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block, + int n, int coded, int intra, int rvlc) +{ + int level, i, last, run; + int dc_pred_dir; + RLTable * rl; + RL_VLC_ELEM * rl_vlc; + const uint8_t * scan_table; + int qmul, qadd; + + //Note intra & rvlc should be optimized away if this is inlined + + if(intra) { + if(s->use_intra_dc_vlc){ + /* DC coef */ + if(s->partitioned_frame){ + level = s->dc_val[0][ s->block_index[n] ]; + if(n<4) level= FASTDIV((level + (s->y_dc_scale>>1)), s->y_dc_scale); + else level= FASTDIV((level + (s->c_dc_scale>>1)), s->c_dc_scale); + dc_pred_dir= (s->pred_dir_table[s->mb_x + s->mb_y*s->mb_stride]<ac_pred) { + if (dc_pred_dir == 0) + scan_table = s->intra_v_scantable.permutated; /* left */ + else + scan_table = s->intra_h_scantable.permutated; /* top */ + } else { + scan_table = s->intra_scantable.permutated; + } + qmul=1; + qadd=0; + } else { + i = -1; + if (!coded) { + s->block_last_index[n] = i; + return 0; + } + if(rvlc) rl = &rvlc_rl_inter; + else rl = &ff_h263_rl_inter; + + scan_table = s->intra_scantable.permutated; + + if(s->mpeg_quant){ + qmul=1; + qadd=0; + if(rvlc){ + rl_vlc = rvlc_rl_inter.rl_vlc[0]; + }else{ + rl_vlc = ff_h263_rl_inter.rl_vlc[0]; + } + }else{ + qmul = s->qscale << 1; + qadd = (s->qscale - 1) | 1; + if(rvlc){ + rl_vlc = rvlc_rl_inter.rl_vlc[s->qscale]; + }else{ + rl_vlc = ff_h263_rl_inter.rl_vlc[s->qscale]; + } + } + } + { + OPEN_READER(re, &s->gb); + for(;;) { + UPDATE_CACHE(re, &s->gb); + GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 0); + if (level==0) { + /* escape */ + if(rvlc){ + if(SHOW_UBITS(re, &s->gb, 1)==0){ + av_log(s->avctx, AV_LOG_ERROR, "1. marker bit missing in rvlc esc\n"); + return -1; + }; SKIP_CACHE(re, &s->gb, 1); + + last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1); + run= SHOW_UBITS(re, &s->gb, 6); LAST_SKIP_CACHE(re, &s->gb, 6); + SKIP_COUNTER(re, &s->gb, 1+1+6); + UPDATE_CACHE(re, &s->gb); + + if(SHOW_UBITS(re, &s->gb, 1)==0){ + av_log(s->avctx, AV_LOG_ERROR, "2. marker bit missing in rvlc esc\n"); + return -1; + }; SKIP_CACHE(re, &s->gb, 1); + + level= SHOW_UBITS(re, &s->gb, 11); SKIP_CACHE(re, &s->gb, 11); + + if(SHOW_UBITS(re, &s->gb, 5)!=0x10){ + av_log(s->avctx, AV_LOG_ERROR, "reverse esc missing\n"); + return -1; + }; SKIP_CACHE(re, &s->gb, 5); + + level= level * qmul + qadd; + level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); LAST_SKIP_CACHE(re, &s->gb, 1); + SKIP_COUNTER(re, &s->gb, 1+11+5+1); + + i+= run + 1; + if(last) i+=192; + }else{ + int cache; + cache= GET_CACHE(re, &s->gb); + + if(IS_3IV1) + cache ^= 0xC0000000; + + if (cache&0x80000000) { + if (cache&0x40000000) { + /* third escape */ + SKIP_CACHE(re, &s->gb, 2); + last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1); + run= SHOW_UBITS(re, &s->gb, 6); LAST_SKIP_CACHE(re, &s->gb, 6); + SKIP_COUNTER(re, &s->gb, 2+1+6); + UPDATE_CACHE(re, &s->gb); + + if(IS_3IV1){ + level= SHOW_SBITS(re, &s->gb, 12); LAST_SKIP_BITS(re, &s->gb, 12); + }else{ + if(SHOW_UBITS(re, &s->gb, 1)==0){ + av_log(s->avctx, AV_LOG_ERROR, "1. marker bit missing in 3. esc\n"); + return -1; + }; SKIP_CACHE(re, &s->gb, 1); + + level= SHOW_SBITS(re, &s->gb, 12); SKIP_CACHE(re, &s->gb, 12); + + if(SHOW_UBITS(re, &s->gb, 1)==0){ + av_log(s->avctx, AV_LOG_ERROR, "2. marker bit missing in 3. esc\n"); + return -1; + }; LAST_SKIP_CACHE(re, &s->gb, 1); + + SKIP_COUNTER(re, &s->gb, 1+12+1); + } + +#if 0 + if(s->error_recognition >= FF_ER_COMPLIANT){ + const int abs_level= FFABS(level); + if(abs_level<=MAX_LEVEL && run<=MAX_RUN){ + const int run1= run - rl->max_run[last][abs_level] - 1; + if(abs_level <= rl->max_level[last][run]){ + av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, vlc encoding possible\n"); + return -1; + } + if(s->error_recognition > FF_ER_COMPLIANT){ + if(abs_level <= rl->max_level[last][run]*2){ + av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 1 encoding possible\n"); + return -1; + } + if(run1 >= 0 && abs_level <= rl->max_level[last][run1]){ + av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 2 encoding possible\n"); + return -1; + } + } + } + } +#endif + if (level>0) level= level * qmul + qadd; + else level= level * qmul - qadd; + + if((unsigned)(level + 2048) > 4095){ + if(s->error_recognition > FF_ER_COMPLIANT){ + if(level > 2560 || level<-2560){ + av_log(s->avctx, AV_LOG_ERROR, "|level| overflow in 3. esc, qp=%d\n", s->qscale); + return -1; + } + } + level= level<0 ? -2048 : 2047; + } + + i+= run + 1; + if(last) i+=192; + } else { + /* second escape */ +#if MIN_CACHE_BITS < 20 + LAST_SKIP_BITS(re, &s->gb, 2); + UPDATE_CACHE(re, &s->gb); +#else + SKIP_BITS(re, &s->gb, 2); +#endif + GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1); + i+= run + rl->max_run[run>>7][level/qmul] +1; //FIXME opt indexing + level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); + LAST_SKIP_BITS(re, &s->gb, 1); + } + } else { + /* first escape */ +#if MIN_CACHE_BITS < 19 + LAST_SKIP_BITS(re, &s->gb, 1); + UPDATE_CACHE(re, &s->gb); +#else + SKIP_BITS(re, &s->gb, 1); +#endif + GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1); + i+= run; + level = level + rl->max_level[run>>7][(run-1)&63] * qmul;//FIXME opt indexing + level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); + LAST_SKIP_BITS(re, &s->gb, 1); + } + } + } else { + i+= run; + level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); + LAST_SKIP_BITS(re, &s->gb, 1); + } + if (i > 62){ + i-= 192; + 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[scan_table[i]] = level; + break; + } + + block[scan_table[i]] = level; + } + CLOSE_READER(re, &s->gb); + } + not_coded: + if (intra) { + if(!s->use_intra_dc_vlc){ + block[0] = ff_mpeg4_pred_dc(s, n, block[0], &dc_pred_dir, 0); + + i -= i>>31; //if(i == -1) i=0; + } + + mpeg4_pred_ac(s, block, n, dc_pred_dir); + if (s->ac_pred) { + i = 63; /* XXX: not optimal */ + } + } + s->block_last_index[n] = i; + return 0; +} + +/** + * decode partition C of one MB. + * @return <0 if an error occurred + */ +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]; + 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->pict_type == FF_P_TYPE || s->pict_type==FF_S_TYPE) { + 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->mb_intra = IS_INTRA(mb_type); + + if (IS_SKIP(mb_type)) { + /* skip mb */ + for(i=0;i<6;i++) + s->block_last_index[i] = -1; + s->mv_dir = MV_DIR_FORWARD; + s->mv_type = MV_TYPE_16X16; + if(s->pict_type==FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE){ + s->mcsel=1; + s->mb_skipped = 0; + }else{ + s->mcsel=0; + s->mb_skipped = 1; + } + }else if(s->mb_intra){ + s->ac_pred = IS_ACPRED(s->current_picture.mb_type[xy]); + }else if(!s->mb_intra){ +// s->mcsel= 0; //FIXME do we need to init that + + s->mv_dir = MV_DIR_FORWARD; + if (IS_8X8(mb_type)) { + s->mv_type = MV_TYPE_8X8; + } else { + s->mv_type = MV_TYPE_16X16; + } + } + } else { /* I-Frame */ + s->mb_intra = 1; + s->ac_pred = IS_ACPRED(s->current_picture.mb_type[xy]); + } + + if (!IS_SKIP(mb_type)) { + int i; + s->dsp.clear_blocks(s->block[0]); + /* decode each block */ + for (i = 0; i < 6; i++) { + if(mpeg4_decode_block(s, block[i], i, cbp&32, s->mb_intra, s->rvlc) < 0){ + av_log(s->avctx, AV_LOG_ERROR, "texture corrupted at %d %d %d\n", s->mb_x, s->mb_y, s->mb_intra); + return -1; + } + cbp+=cbp; + } + } + + /* per-MB end of slice check */ + + if(--s->mb_num_left <= 0){ + if(mpeg4_is_resync(s)) + return SLICE_END; + else + return SLICE_NOEND; + }else{ + if(mpeg4_is_resync(s)){ + const int delta= s->mb_x + 1 == s->mb_width ? 2 : 1; + if(s->cbp_table[xy+delta]) + return SLICE_END; + } + return SLICE_OK; + } +} + +static int mpeg4_decode_mb(MpegEncContext *s, + DCTELEM block[6][64]) +{ + int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant; + int16_t *mot_val; + static int8_t quant_tab[4] = { -1, -2, 1, 2 }; + const int xy= s->mb_x + s->mb_y * s->mb_stride; + + assert(s->h263_pred); + + if (s->pict_type == FF_P_TYPE || s->pict_type==FF_S_TYPE) { + do{ + if (get_bits1(&s->gb)) { + /* skip mb */ + s->mb_intra = 0; + for(i=0;i<6;i++) + s->block_last_index[i] = -1; + s->mv_dir = MV_DIR_FORWARD; + s->mv_type = MV_TYPE_16X16; + if(s->pict_type==FF_S_TYPE && 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->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->mcsel=0; + s->mv[0][0][0] = 0; + s->mv[0][0][1] = 0; + s->mb_skipped = 1; + } + goto end; + } + cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2); + if (cbpc < 0){ + av_log(s->avctx, AV_LOG_ERROR, "cbpc damaged at %d %d\n", s->mb_x, s->mb_y); + return -1; + } + }while(cbpc == 20); + + s->dsp.clear_blocks(s->block[0]); + dquant = cbpc & 8; + s->mb_intra = ((cbpc & 4) != 0); + if (s->mb_intra) goto intra; + + if(s->pict_type==FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE && (cbpc & 16) == 0) + s->mcsel= get_bits1(&s->gb); + else s->mcsel= 0; + cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1) ^ 0x0F; + + cbp = (cbpc & 3) | (cbpy << 2); + if (dquant) { + ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]); + } + if((!s->progressive_sequence) && (cbp || (s->workaround_bugs&FF_BUG_XVID_ILACE))) + s->interlaced_dct= get_bits1(&s->gb); + + 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; + /* 16x16 global motion prediction */ + s->mv_type = MV_TYPE_16X16; + mx= get_amv(s, 0); + my= get_amv(s, 1); + 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; + /* 16x8 field motion prediction */ + s->mv_type= MV_TYPE_FIELD; + + s->field_select[0][0]= get_bits1(&s->gb); + s->field_select[0][1]= get_bits1(&s->gb); + + h263_pred_motion(s, 0, 0, &pred_x, &pred_y); + + for(i=0; i<2; i++){ + mx = h263_decode_motion(s, pred_x, s->f_code); + if (mx >= 0xffff) + return -1; + + my = h263_decode_motion(s, pred_y/2, s->f_code); + if (my >= 0xffff) + return -1; + + s->mv[0][i][0] = mx; + s->mv[0][i][1] = my; + } + }else{ + s->current_picture.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); + mx = h263_decode_motion(s, pred_x, s->f_code); + + if (mx >= 0xffff) + return -1; + + my = h263_decode_motion(s, pred_y, s->f_code); + + if (my >= 0xffff) + return -1; + s->mv[0][0][0] = mx; + s->mv[0][0][1] = my; + } + } else { + s->current_picture.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); + mx = h263_decode_motion(s, pred_x, s->f_code); + if (mx >= 0xffff) + return -1; + + my = h263_decode_motion(s, pred_y, s->f_code); + if (my >= 0xffff) + return -1; + s->mv[0][i][0] = mx; + s->mv[0][i][1] = my; + mot_val[0] = mx; + mot_val[1] = my; + } + } + } else if(s->pict_type==FF_B_TYPE) { + int modb1; // first bit of modb + int modb2; // second bit of modb + int mb_type; + + s->mb_intra = 0; //B-frames never contain intra blocks + s->mcsel=0; // ... true gmc blocks + + if(s->mb_x==0){ + for(i=0; i<2; i++){ + s->last_mv[i][0][0]= + s->last_mv[i][0][1]= + s->last_mv[i][1][0]= + s->last_mv[i][1][1]= 0; + } + } + + /* 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 + + if(s->mb_skipped){ + /* skip mb */ + for(i=0;i<6;i++) + s->block_last_index[i] = -1; + + s->mv_dir = MV_DIR_FORWARD; + s->mv_type = MV_TYPE_16X16; + s->mv[0][0][0] = 0; + 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; + goto end; + } + + modb1= get_bits1(&s->gb); + if(modb1){ + mb_type= MB_TYPE_DIRECT2 | MB_TYPE_SKIP | MB_TYPE_L0L1; //like MB_TYPE_B_DIRECT but no vectors coded + cbp=0; + }else{ + modb2= get_bits1(&s->gb); + mb_type= get_vlc2(&s->gb, mb_type_b_vlc.table, MB_TYPE_B_VLC_BITS, 1); + if(mb_type<0){ + av_log(s->avctx, AV_LOG_ERROR, "illegal MB_type\n"); + return -1; + } + mb_type= mb_type_b_map[ mb_type ]; + if(modb2) cbp= 0; + else{ + s->dsp.clear_blocks(s->block[0]); + cbp= get_bits(&s->gb, 6); + } + + if ((!IS_DIRECT(mb_type)) && cbp) { + if(get_bits1(&s->gb)){ + ff_set_qscale(s, s->qscale + get_bits1(&s->gb)*4 - 2); + } + } + + if(!s->progressive_sequence){ + if(cbp) + s->interlaced_dct= get_bits1(&s->gb); + + if(!IS_DIRECT(mb_type) && get_bits1(&s->gb)){ + mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED; + mb_type &= ~MB_TYPE_16x16; + + if(USES_LIST(mb_type, 0)){ + s->field_select[0][0]= get_bits1(&s->gb); + s->field_select[0][1]= get_bits1(&s->gb); + } + if(USES_LIST(mb_type, 1)){ + s->field_select[1][0]= get_bits1(&s->gb); + s->field_select[1][1]= get_bits1(&s->gb); + } + } + } + + s->mv_dir = 0; + if((mb_type & (MB_TYPE_DIRECT2|MB_TYPE_INTERLACED)) == 0){ + s->mv_type= MV_TYPE_16X16; + + if(USES_LIST(mb_type, 0)){ + s->mv_dir = MV_DIR_FORWARD; + + mx = h263_decode_motion(s, s->last_mv[0][0][0], s->f_code); + my = h263_decode_motion(s, s->last_mv[0][0][1], s->f_code); + s->last_mv[0][1][0]= s->last_mv[0][0][0]= s->mv[0][0][0] = mx; + s->last_mv[0][1][1]= s->last_mv[0][0][1]= s->mv[0][0][1] = my; + } + + if(USES_LIST(mb_type, 1)){ + s->mv_dir |= MV_DIR_BACKWARD; + + mx = h263_decode_motion(s, s->last_mv[1][0][0], s->b_code); + my = h263_decode_motion(s, s->last_mv[1][0][1], s->b_code); + s->last_mv[1][1][0]= s->last_mv[1][0][0]= s->mv[1][0][0] = mx; + s->last_mv[1][1][1]= s->last_mv[1][0][1]= s->mv[1][0][1] = my; + } + }else if(!IS_DIRECT(mb_type)){ + s->mv_type= MV_TYPE_FIELD; + + if(USES_LIST(mb_type, 0)){ + s->mv_dir = MV_DIR_FORWARD; + + for(i=0; i<2; i++){ + mx = h263_decode_motion(s, s->last_mv[0][i][0] , s->f_code); + my = h263_decode_motion(s, s->last_mv[0][i][1]/2, s->f_code); + s->last_mv[0][i][0]= s->mv[0][i][0] = mx; + s->last_mv[0][i][1]= (s->mv[0][i][1] = my)*2; + } + } + + if(USES_LIST(mb_type, 1)){ + s->mv_dir |= MV_DIR_BACKWARD; + + for(i=0; i<2; i++){ + mx = h263_decode_motion(s, s->last_mv[1][i][0] , s->b_code); + my = h263_decode_motion(s, s->last_mv[1][i][1]/2, s->b_code); + s->last_mv[1][i][0]= s->mv[1][i][0] = mx; + s->last_mv[1][i][1]= (s->mv[1][i][1] = my)*2; + } + } + } + } + + if(IS_DIRECT(mb_type)){ + if(IS_SKIP(mb_type)) + mx=my=0; + else{ + mx = h263_decode_motion(s, 0, 1); + my = h263_decode_motion(s, 0, 1); + } + + 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; + } else { /* I-Frame */ + do{ + cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2); + if (cbpc < 0){ + av_log(s->avctx, AV_LOG_ERROR, "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y); + return -1; + } + }while(cbpc == 8); + + dquant = cbpc & 4; + s->mb_intra = 1; +intra: + s->ac_pred = get_bits1(&s->gb); + if(s->ac_pred) + s->current_picture.mb_type[xy]= MB_TYPE_INTRA | MB_TYPE_ACPRED; + else + s->current_picture.mb_type[xy]= MB_TYPE_INTRA; + + cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1); + if(cbpy<0){ + av_log(s->avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y); + return -1; + } + cbp = (cbpc & 3) | (cbpy << 2); + + s->use_intra_dc_vlc= s->qscale < s->intra_dc_threshold; + + if (dquant) { + ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]); + } + + if(!s->progressive_sequence) + s->interlaced_dct= get_bits1(&s->gb); + + s->dsp.clear_blocks(s->block[0]); + /* decode each block */ + for (i = 0; i < 6; i++) { + if (mpeg4_decode_block(s, block[i], i, cbp&32, 1, 0) < 0) + return -1; + cbp+=cbp; + } + goto end; + } + + /* decode each block */ + for (i = 0; i < 6; i++) { + if (mpeg4_decode_block(s, block[i], i, cbp&32, 0, 0) < 0) + return -1; + cbp+=cbp; + } +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; + if(s->pict_type==FF_B_TYPE && s->next_picture.mbskip_table[xy + delta]) + return SLICE_OK; + return SLICE_END; + } + } + + return SLICE_OK; +} + + +static int mpeg4_decode_gop_header(MpegEncContext * s, GetBitContext *gb){ + int hours, minutes, seconds; + + 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 decode_vol_header(MpegEncContext *s, GetBitContext *gb){ + int width, height, vo_ver_id; + + /* vol header */ + skip_bits(gb, 1); /* random access */ + s->vo_type= get_bits(gb, 8); + if (get_bits1(gb) != 0) { /* is_ol_id */ + vo_ver_id = get_bits(gb, 4); /* vo_ver_id */ + skip_bits(gb, 3); /* vo_priority */ + } else { + vo_ver_id = 1; + } + s->aspect_ratio_info= get_bits(gb, 4); + if(s->aspect_ratio_info == FF_ASPECT_EXTENDED){ + s->avctx->sample_aspect_ratio.num= get_bits(gb, 8); // par_width + s->avctx->sample_aspect_ratio.den= get_bits(gb, 8); // par_height + }else{ + s->avctx->sample_aspect_ratio= ff_h263_pixel_aspect[s->aspect_ratio_info]; + } + + if ((s->vol_control_parameters=get_bits1(gb))) { /* vol control parameter */ + int chroma_format= get_bits(gb, 2); + if(chroma_format!=CHROMA_420){ + av_log(s->avctx, AV_LOG_ERROR, "illegal chroma format\n"); + } + s->low_delay= get_bits1(gb); + if(get_bits1(gb)){ /* vbv parameters */ + get_bits(gb, 15); /* first_half_bitrate */ + skip_bits1(gb); /* marker */ + get_bits(gb, 15); /* latter_half_bitrate */ + skip_bits1(gb); /* marker */ + get_bits(gb, 15); /* first_half_vbv_buffer_size */ + skip_bits1(gb); /* marker */ + get_bits(gb, 3); /* latter_half_vbv_buffer_size */ + get_bits(gb, 11); /* first_half_vbv_occupancy */ + skip_bits1(gb); /* marker */ + get_bits(gb, 15); /* latter_half_vbv_occupancy */ + skip_bits1(gb); /* marker */ + } + }else{ + // set low delay flag only once the smartest? low delay detection won't be overriden + if(s->picture_number==0) + s->low_delay=0; + } + + s->shape = get_bits(gb, 2); /* vol shape */ + if(s->shape != RECT_SHAPE) av_log(s->avctx, AV_LOG_ERROR, "only rectangular vol supported\n"); + if(s->shape == GRAY_SHAPE && vo_ver_id != 1){ + av_log(s->avctx, AV_LOG_ERROR, "Gray shape not supported\n"); + skip_bits(gb, 4); //video_object_layer_shape_extension + } + + check_marker(gb, "before time_increment_resolution"); + + s->avctx->time_base.den = get_bits(gb, 16); + if(!s->avctx->time_base.den){ + av_log(s->avctx, AV_LOG_ERROR, "time_base.den==0\n"); + return -1; + } + + s->time_increment_bits = av_log2(s->avctx->time_base.den - 1) + 1; + if (s->time_increment_bits < 1) + s->time_increment_bits = 1; + + check_marker(gb, "before fixed_vop_rate"); + + if (get_bits1(gb) != 0) { /* fixed_vop_rate */ + s->avctx->time_base.num = get_bits(gb, s->time_increment_bits); + }else + s->avctx->time_base.num = 1; + + s->t_frame=0; + + if (s->shape != BIN_ONLY_SHAPE) { + if (s->shape == RECT_SHAPE) { + skip_bits1(gb); /* marker */ + width = get_bits(gb, 13); + skip_bits1(gb); /* marker */ + height = get_bits(gb, 13); + skip_bits1(gb); /* marker */ + if(width && height && !(s->width && s->codec_tag == AV_RL32("MP4S"))){ /* they should be non zero but who knows ... */ + s->width = width; + s->height = height; + } + } + + s->progressive_sequence= + s->progressive_frame= get_bits1(gb)^1; + s->interlaced_dct=0; + if(!get_bits1(gb) && (s->avctx->debug & FF_DEBUG_PICT_INFO)) + av_log(s->avctx, AV_LOG_INFO, "MPEG4 OBMC not supported (very likely buggy encoder)\n"); /* OBMC Disable */ + if (vo_ver_id == 1) { + s->vol_sprite_usage = get_bits1(gb); /* vol_sprite_usage */ + } else { + s->vol_sprite_usage = get_bits(gb, 2); /* vol_sprite_usage */ + } + if(s->vol_sprite_usage==STATIC_SPRITE) av_log(s->avctx, AV_LOG_ERROR, "Static Sprites not supported\n"); + if(s->vol_sprite_usage==STATIC_SPRITE || s->vol_sprite_usage==GMC_SPRITE){ + if(s->vol_sprite_usage==STATIC_SPRITE){ + s->sprite_width = get_bits(gb, 13); + skip_bits1(gb); /* marker */ + s->sprite_height= get_bits(gb, 13); + skip_bits1(gb); /* marker */ + s->sprite_left = get_bits(gb, 13); + skip_bits1(gb); /* marker */ + s->sprite_top = get_bits(gb, 13); + skip_bits1(gb); /* marker */ + } + s->num_sprite_warping_points= get_bits(gb, 6); + if(s->num_sprite_warping_points > 3){ + av_log(s->avctx, AV_LOG_ERROR, "%d sprite_warping_points\n", s->num_sprite_warping_points); + s->num_sprite_warping_points= 0; + return -1; + } + s->sprite_warping_accuracy = get_bits(gb, 2); + s->sprite_brightness_change= get_bits1(gb); + if(s->vol_sprite_usage==STATIC_SPRITE) + s->low_latency_sprite= get_bits1(gb); + } + // FIXME sadct disable bit if verid!=1 && shape not rect + + if (get_bits1(gb) == 1) { /* not_8_bit */ + s->quant_precision = get_bits(gb, 4); /* quant_precision */ + if(get_bits(gb, 4)!=8) av_log(s->avctx, AV_LOG_ERROR, "N-bit not supported\n"); /* bits_per_pixel */ + if(s->quant_precision!=5) av_log(s->avctx, AV_LOG_ERROR, "quant precision %d\n", s->quant_precision); + } else { + s->quant_precision = 5; + } + + // FIXME a bunch of grayscale shape things + + if((s->mpeg_quant=get_bits1(gb))){ /* vol_quant_type */ + int i, v; + + /* load default matrixes */ + for(i=0; i<64; i++){ + int j= s->dsp.idct_permutation[i]; + v= ff_mpeg4_default_intra_matrix[i]; + s->intra_matrix[j]= v; + s->chroma_intra_matrix[j]= v; + + v= ff_mpeg4_default_non_intra_matrix[i]; + s->inter_matrix[j]= v; + s->chroma_inter_matrix[j]= v; + } + + /* load custom intra matrix */ + if(get_bits1(gb)){ + int last=0; + for(i=0; i<64; i++){ + int j; + v= get_bits(gb, 8); + if(v==0) break; + + last= v; + j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ]; + s->intra_matrix[j]= v; + s->chroma_intra_matrix[j]= v; + } + + /* replicate last value */ + for(; i<64; i++){ + int j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ]; + s->intra_matrix[j]= last; + s->chroma_intra_matrix[j]= last; + } + } + + /* load custom non intra matrix */ + if(get_bits1(gb)){ + int last=0; + for(i=0; i<64; i++){ + int j; + v= get_bits(gb, 8); + if(v==0) break; + + last= v; + j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ]; + s->inter_matrix[j]= v; + s->chroma_inter_matrix[j]= v; + } + + /* replicate last value */ + for(; i<64; i++){ + int j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ]; + s->inter_matrix[j]= last; + s->chroma_inter_matrix[j]= last; + } + } + + // FIXME a bunch of grayscale shape things + } + + if(vo_ver_id != 1) + s->quarter_sample= get_bits1(gb); + else s->quarter_sample=0; + + if(!get_bits1(gb)){ + int pos= get_bits_count(gb); + int estimation_method= get_bits(gb, 2); + if(estimation_method<2){ + if(!get_bits1(gb)){ + s->cplx_estimation_trash_i += 8*get_bits1(gb); //opaque + s->cplx_estimation_trash_i += 8*get_bits1(gb); //transparent + s->cplx_estimation_trash_i += 8*get_bits1(gb); //intra_cae + s->cplx_estimation_trash_i += 8*get_bits1(gb); //inter_cae + s->cplx_estimation_trash_i += 8*get_bits1(gb); //no_update + s->cplx_estimation_trash_i += 8*get_bits1(gb); //upampling + } + if(!get_bits1(gb)){ + s->cplx_estimation_trash_i += 8*get_bits1(gb); //intra_blocks + s->cplx_estimation_trash_p += 8*get_bits1(gb); //inter_blocks + s->cplx_estimation_trash_p += 8*get_bits1(gb); //inter4v_blocks + s->cplx_estimation_trash_i += 8*get_bits1(gb); //not coded blocks + } + if(!check_marker(gb, "in complexity estimation part 1")){ + skip_bits_long(gb, pos - get_bits_count(gb)); + goto no_cplx_est; + } + if(!get_bits1(gb)){ + s->cplx_estimation_trash_i += 8*get_bits1(gb); //dct_coeffs + s->cplx_estimation_trash_i += 8*get_bits1(gb); //dct_lines + s->cplx_estimation_trash_i += 8*get_bits1(gb); //vlc_syms + s->cplx_estimation_trash_i += 4*get_bits1(gb); //vlc_bits + } + if(!get_bits1(gb)){ + s->cplx_estimation_trash_p += 8*get_bits1(gb); //apm + s->cplx_estimation_trash_p += 8*get_bits1(gb); //npm + s->cplx_estimation_trash_b += 8*get_bits1(gb); //interpolate_mc_q + s->cplx_estimation_trash_p += 8*get_bits1(gb); //forwback_mc_q + s->cplx_estimation_trash_p += 8*get_bits1(gb); //halfpel2 + s->cplx_estimation_trash_p += 8*get_bits1(gb); //halfpel4 + } + if(!check_marker(gb, "in complexity estimation part 2")){ + skip_bits_long(gb, pos - get_bits_count(gb)); + goto no_cplx_est; + } + if(estimation_method==1){ + s->cplx_estimation_trash_i += 8*get_bits1(gb); //sadct + s->cplx_estimation_trash_p += 8*get_bits1(gb); //qpel + } + }else + av_log(s->avctx, AV_LOG_ERROR, "Invalid Complexity estimation method %d\n", estimation_method); + }else{ +no_cplx_est: + s->cplx_estimation_trash_i= + s->cplx_estimation_trash_p= + s->cplx_estimation_trash_b= 0; + } + + s->resync_marker= !get_bits1(gb); /* resync_marker_disabled */ + + s->data_partitioning= get_bits1(gb); + if(s->data_partitioning){ + s->rvlc= get_bits1(gb); + } + + if(vo_ver_id != 1) { + s->new_pred= get_bits1(gb); + if(s->new_pred){ + av_log(s->avctx, AV_LOG_ERROR, "new pred not supported\n"); + skip_bits(gb, 2); /* requested upstream message type */ + skip_bits1(gb); /* newpred segment type */ + } + s->reduced_res_vop= get_bits1(gb); + if(s->reduced_res_vop) av_log(s->avctx, AV_LOG_ERROR, "reduced resolution VOP not supported\n"); + } + else{ + s->new_pred=0; + s->reduced_res_vop= 0; + } + + s->scalability= get_bits1(gb); + + if (s->scalability) { + GetBitContext bak= *gb; + int ref_layer_id; + int ref_layer_sampling_dir; + int h_sampling_factor_n; + int h_sampling_factor_m; + int v_sampling_factor_n; + int v_sampling_factor_m; + + s->hierachy_type= get_bits1(gb); + ref_layer_id= get_bits(gb, 4); + ref_layer_sampling_dir= get_bits1(gb); + h_sampling_factor_n= get_bits(gb, 5); + h_sampling_factor_m= get_bits(gb, 5); + v_sampling_factor_n= get_bits(gb, 5); + v_sampling_factor_m= get_bits(gb, 5); + s->enhancement_type= get_bits1(gb); + + if( h_sampling_factor_n==0 || h_sampling_factor_m==0 + || v_sampling_factor_n==0 || v_sampling_factor_m==0){ + /* illegal scalability header (VERY broken encoder), + * trying to workaround */ + s->scalability=0; + *gb= bak; + }else + av_log(s->avctx, AV_LOG_ERROR, "scalability not supported\n"); + + // bin shape stuff FIXME + } + } + return 0; +} + +/** + * decodes the user data stuff in the header. + * Also initializes divx/xvid/lavc_version/build. + */ +static int decode_user_data(MpegEncContext *s, GetBitContext *gb){ + char buf[256]; + int i; + int e; + int ver = 0, build = 0, ver2 = 0, ver3 = 0; + char last; + + for(i=0; i<255 && get_bits_count(gb) < gb->size_in_bits; i++){ + if(show_bits(gb, 23) == 0) break; + buf[i]= get_bits(gb, 8); + } + buf[i]=0; + + /* divx detection */ + e=sscanf(buf, "DivX%dBuild%d%c", &ver, &build, &last); + if(e<2) + e=sscanf(buf, "DivX%db%d%c", &ver, &build, &last); + if(e>=2){ + s->divx_version= ver; + s->divx_build= build; + s->divx_packed= e==3 && last=='p'; + if(s->divx_packed && !s->showed_packed_warning) { + av_log(s->avctx, AV_LOG_WARNING, "Invalid and inefficient vfw-avi packed B frames detected\n"); + s->showed_packed_warning=1; + } + } + + /* ffmpeg detection */ + e=sscanf(buf, "FFmpe%*[^b]b%d", &build)+3; + if(e!=4) + e=sscanf(buf, "FFmpeg v%d.%d.%d / libavcodec build: %d", &ver, &ver2, &ver3, &build); + if(e!=4){ + e=sscanf(buf, "Lavc%d.%d.%d", &ver, &ver2, &ver3)+1; + if (e>1) + build= (ver<<16) + (ver2<<8) + ver3; + } + if(e!=4){ + if(strcmp(buf, "ffmpeg")==0){ + s->lavc_build= 4600; + } + } + if(e==4){ + s->lavc_build= build; + } + + /* Xvid detection */ + e=sscanf(buf, "XviD%d", &build); + if(e==1){ + s->xvid_build= build; + } + + return 0; +} + +static int decode_vop_header(MpegEncContext *s, GetBitContext *gb){ + int time_incr, time_increment; + + s->pict_type = get_bits(gb, 2) + FF_I_TYPE; /* pict type: I = 0 , P = 1 */ + if(s->pict_type==FF_B_TYPE && s->low_delay && s->vol_control_parameters==0 && !(s->flags & CODEC_FLAG_LOW_DELAY)){ + av_log(s->avctx, AV_LOG_ERROR, "low_delay flag incorrectly, clearing it\n"); + s->low_delay=0; + } + + s->partitioned_frame= s->data_partitioning && s->pict_type!=FF_B_TYPE; + if(s->partitioned_frame) + s->decode_mb= mpeg4_decode_partitioned_mb; + else + s->decode_mb= mpeg4_decode_mb; + + time_incr=0; + while (get_bits1(gb) != 0) + time_incr++; + + check_marker(gb, "before time_increment"); + + if(s->time_increment_bits==0 || !(show_bits(gb, s->time_increment_bits+1)&1)){ + av_log(s->avctx, AV_LOG_ERROR, "hmm, seems the headers are not complete, trying to guess time_increment_bits\n"); + + for(s->time_increment_bits=1 ;s->time_increment_bits<16; s->time_increment_bits++){ + if ( s->pict_type == FF_P_TYPE + || (s->pict_type == FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE)) { + if((show_bits(gb, s->time_increment_bits+6)&0x37) == 0x30) break; + }else + if((show_bits(gb, s->time_increment_bits+5)&0x1F) == 0x18) break; + } + + av_log(s->avctx, AV_LOG_ERROR, "my guess is %d bits ;)\n",s->time_increment_bits); + } + + if(IS_3IV1) time_increment= get_bits1(gb); //FIXME investigate further + else time_increment= get_bits(gb, s->time_increment_bits); + + if(s->pict_type!=FF_B_TYPE){ + s->last_time_base= s->time_base; + s->time_base+= time_incr; + s->time= s->time_base*s->avctx->time_base.den + time_increment; + if(s->workaround_bugs&FF_BUG_UMP4){ + if(s->time < s->last_non_b_time){ + /* header is not mpeg-4-compatible, broken encoder, + * trying to workaround */ + s->time_base++; + s->time+= s->avctx->time_base.den; + } + } + s->pp_time= s->time - s->last_non_b_time; + s->last_non_b_time= s->time; + }else{ + s->time= (s->last_time_base + time_incr)*s->avctx->time_base.den + time_increment; + s->pb_time= s->pp_time - (s->last_non_b_time - s->time); + if(s->pp_time <=s->pb_time || s->pp_time <= s->pp_time - s->pb_time || s->pp_time<=0){ + /* messed up order, maybe after seeking? skipping current b-frame */ + return FRAME_SKIPPED; + } + ff_mpeg4_init_direct_mv(s); + + if(s->t_frame==0) s->t_frame= s->pb_time; + if(s->t_frame==0) s->t_frame=1; // 1/0 protection + s->pp_field_time= ( ROUNDED_DIV(s->last_non_b_time, s->t_frame) + - ROUNDED_DIV(s->last_non_b_time - s->pp_time, s->t_frame))*2; + s->pb_field_time= ( ROUNDED_DIV(s->time, s->t_frame) + - ROUNDED_DIV(s->last_non_b_time - s->pp_time, s->t_frame))*2; + if(!s->progressive_sequence){ + if(s->pp_field_time <= s->pb_field_time || s->pb_field_time <= 1) + return FRAME_SKIPPED; + } + } + + if(s->avctx->time_base.num) + s->current_picture_ptr->pts= (s->time + s->avctx->time_base.num/2) / s->avctx->time_base.num; + else + s->current_picture_ptr->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); + + check_marker(gb, "before vop_coded"); + + /* vop coded */ + if (get_bits1(gb) != 1){ + if(s->avctx->debug&FF_DEBUG_PICT_INFO) + av_log(s->avctx, AV_LOG_ERROR, "vop not coded\n"); + return FRAME_SKIPPED; + } + if (s->shape != BIN_ONLY_SHAPE && ( s->pict_type == FF_P_TYPE + || (s->pict_type == FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE))) { + /* rounding type for motion estimation */ + s->no_rounding = get_bits1(gb); + } else { + s->no_rounding = 0; + } +//FIXME reduced res stuff + + if (s->shape != RECT_SHAPE) { + if (s->vol_sprite_usage != 1 || s->pict_type != FF_I_TYPE) { + int width, height, hor_spat_ref, ver_spat_ref; + + width = get_bits(gb, 13); + skip_bits1(gb); /* marker */ + height = get_bits(gb, 13); + skip_bits1(gb); /* marker */ + hor_spat_ref = get_bits(gb, 13); /* hor_spat_ref */ + skip_bits1(gb); /* marker */ + ver_spat_ref = get_bits(gb, 13); /* ver_spat_ref */ + } + skip_bits1(gb); /* change_CR_disable */ + + if (get_bits1(gb) != 0) { + skip_bits(gb, 8); /* constant_alpha_value */ + } + } +//FIXME complexity estimation stuff + + if (s->shape != BIN_ONLY_SHAPE) { + skip_bits_long(gb, s->cplx_estimation_trash_i); + if(s->pict_type != FF_I_TYPE) + skip_bits_long(gb, s->cplx_estimation_trash_p); + if(s->pict_type == FF_B_TYPE) + skip_bits_long(gb, s->cplx_estimation_trash_b); + + s->intra_dc_threshold= mpeg4_dc_threshold[ get_bits(gb, 3) ]; + if(!s->progressive_sequence){ + s->top_field_first= get_bits1(gb); + s->alternate_scan= get_bits1(gb); + }else + s->alternate_scan= 0; + } + + 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); + ff_init_scantable(s->dsp.idct_permutation, &s->intra_h_scantable, ff_alternate_vertical_scan); + ff_init_scantable(s->dsp.idct_permutation, &s->intra_v_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); + ff_init_scantable(s->dsp.idct_permutation, &s->intra_h_scantable, ff_alternate_horizontal_scan); + ff_init_scantable(s->dsp.idct_permutation, &s->intra_v_scantable, ff_alternate_vertical_scan); + } + + if(s->pict_type == FF_S_TYPE && (s->vol_sprite_usage==STATIC_SPRITE || s->vol_sprite_usage==GMC_SPRITE)){ + mpeg4_decode_sprite_trajectory(s, gb); + if(s->sprite_brightness_change) av_log(s->avctx, AV_LOG_ERROR, "sprite_brightness_change not supported\n"); + if(s->vol_sprite_usage==STATIC_SPRITE) av_log(s->avctx, AV_LOG_ERROR, "static sprite not supported\n"); + } + + if (s->shape != BIN_ONLY_SHAPE) { + s->chroma_qscale= s->qscale = get_bits(gb, s->quant_precision); + if(s->qscale==0){ + av_log(s->avctx, AV_LOG_ERROR, "Error, header damaged or not MPEG4 header (qscale=0)\n"); + return -1; // makes no sense to continue, as there is nothing left from the image then + } + + if (s->pict_type != FF_I_TYPE) { + s->f_code = get_bits(gb, 3); /* fcode_for */ + if(s->f_code==0){ + av_log(s->avctx, AV_LOG_ERROR, "Error, header damaged or not MPEG4 header (f_code=0)\n"); + return -1; // makes no sense to continue, as the MV decoding will break very quickly + } + }else + s->f_code=1; + + if (s->pict_type == FF_B_TYPE) { + s->b_code = get_bits(gb, 3); + }else + s->b_code=1; + + if(s->avctx->debug&FF_DEBUG_PICT_INFO){ + av_log(s->avctx, AV_LOG_DEBUG, "qp:%d fc:%d,%d %s size:%d pro:%d alt:%d top:%d %spel part:%d resync:%d w:%d a:%d rnd:%d vot:%d%s dc:%d ce:%d/%d/%d\n", + s->qscale, s->f_code, s->b_code, + s->pict_type == FF_I_TYPE ? "I" : (s->pict_type == FF_P_TYPE ? "P" : (s->pict_type == FF_B_TYPE ? "B" : "S")), + gb->size_in_bits,s->progressive_sequence, s->alternate_scan, s->top_field_first, + s->quarter_sample ? "q" : "h", s->data_partitioning, s->resync_marker, s->num_sprite_warping_points, + s->sprite_warping_accuracy, 1-s->no_rounding, s->vo_type, s->vol_control_parameters ? " VOLC" : " ", s->intra_dc_threshold, s->cplx_estimation_trash_i, s->cplx_estimation_trash_p, s->cplx_estimation_trash_b); + } + + if(!s->scalability){ + if (s->shape!=RECT_SHAPE && s->pict_type!=FF_I_TYPE) { + skip_bits1(gb); // vop shape coding type + } + }else{ + if(s->enhancement_type){ + int load_backward_shape= get_bits1(gb); + if(load_backward_shape){ + av_log(s->avctx, AV_LOG_ERROR, "load backward shape isn't supported\n"); + } + } + skip_bits(gb, 2); //ref_select_code + } + } + /* detect buggy encoders which don't set the low_delay flag (divx4/xvid/opendivx)*/ + // note we cannot detect divx5 without b-frames easily (although it's buggy too) + if(s->vo_type==0 && s->vol_control_parameters==0 && s->divx_version==-1 && s->picture_number==0){ + av_log(s->avctx, AV_LOG_ERROR, "looks like this file was encoded with (divx4/(old)xvid/opendivx) -> forcing low_delay flag\n"); + s->low_delay=1; + } + + s->picture_number++; // better than pic number==0 always ;) + + s->y_dc_scale_table= ff_mpeg4_y_dc_scale_table; //FIXME add short header support + s->c_dc_scale_table= ff_mpeg4_c_dc_scale_table; + + if(s->workaround_bugs&FF_BUG_EDGE){ + s->h_edge_pos= s->width; + s->v_edge_pos= s->height; + } + return 0; +} + +/** + * decode mpeg4 headers + * @return <0 if no VOP found (or a damaged one) + * FRAME_SKIPPED if a not coded VOP is found + * 0 if a VOP is found + */ +int ff_mpeg4_decode_picture_header(MpegEncContext * s, GetBitContext *gb) +{ + int startcode, v; + + /* search next start code */ + align_get_bits(gb); + + if(s->codec_tag == AV_RL32("WV1F") && show_bits(gb, 24) == 0x575630){ + skip_bits(gb, 24); + if(get_bits(gb, 8) == 0xF0) + goto end; + } + + startcode = 0xff; + for(;;) { + if(get_bits_count(gb) >= gb->size_in_bits){ + if(gb->size_in_bits==8 && (s->divx_version>=0 || s->xvid_build>=0)){ + av_log(s->avctx, AV_LOG_ERROR, "frame skip %d\n", gb->size_in_bits); + return FRAME_SKIPPED; //divx bug + }else + return -1; //end of stream + } + + /* use the bits after the test */ + v = get_bits(gb, 8); + startcode = ((startcode << 8) | v) & 0xffffffff; + + if((startcode&0xFFFFFF00) != 0x100) + continue; //no startcode + + if(s->avctx->debug&FF_DEBUG_STARTCODE){ + av_log(s->avctx, AV_LOG_DEBUG, "startcode: %3X ", startcode); + if (startcode<=0x11F) av_log(s->avctx, AV_LOG_DEBUG, "Video Object Start"); + else if(startcode<=0x12F) av_log(s->avctx, AV_LOG_DEBUG, "Video Object Layer Start"); + else if(startcode<=0x13F) av_log(s->avctx, AV_LOG_DEBUG, "Reserved"); + else if(startcode<=0x15F) av_log(s->avctx, AV_LOG_DEBUG, "FGS bp start"); + else if(startcode<=0x1AF) av_log(s->avctx, AV_LOG_DEBUG, "Reserved"); + else if(startcode==0x1B0) av_log(s->avctx, AV_LOG_DEBUG, "Visual Object Seq Start"); + else if(startcode==0x1B1) av_log(s->avctx, AV_LOG_DEBUG, "Visual Object Seq End"); + else if(startcode==0x1B2) av_log(s->avctx, AV_LOG_DEBUG, "User Data"); + else if(startcode==0x1B3) av_log(s->avctx, AV_LOG_DEBUG, "Group of VOP start"); + else if(startcode==0x1B4) av_log(s->avctx, AV_LOG_DEBUG, "Video Session Error"); + else if(startcode==0x1B5) av_log(s->avctx, AV_LOG_DEBUG, "Visual Object Start"); + else if(startcode==0x1B6) av_log(s->avctx, AV_LOG_DEBUG, "Video Object Plane start"); + else if(startcode==0x1B7) av_log(s->avctx, AV_LOG_DEBUG, "slice start"); + else if(startcode==0x1B8) av_log(s->avctx, AV_LOG_DEBUG, "extension start"); + else if(startcode==0x1B9) av_log(s->avctx, AV_LOG_DEBUG, "fgs start"); + else if(startcode==0x1BA) av_log(s->avctx, AV_LOG_DEBUG, "FBA Object start"); + else if(startcode==0x1BB) av_log(s->avctx, AV_LOG_DEBUG, "FBA Object Plane start"); + else if(startcode==0x1BC) av_log(s->avctx, AV_LOG_DEBUG, "Mesh Object start"); + else if(startcode==0x1BD) av_log(s->avctx, AV_LOG_DEBUG, "Mesh Object Plane start"); + else if(startcode==0x1BE) av_log(s->avctx, AV_LOG_DEBUG, "Still Texture Object start"); + else if(startcode==0x1BF) av_log(s->avctx, AV_LOG_DEBUG, "Texture Spatial Layer start"); + else if(startcode==0x1C0) av_log(s->avctx, AV_LOG_DEBUG, "Texture SNR Layer start"); + else if(startcode==0x1C1) av_log(s->avctx, AV_LOG_DEBUG, "Texture Tile start"); + else if(startcode==0x1C2) av_log(s->avctx, AV_LOG_DEBUG, "Texture Shape Layer start"); + else if(startcode==0x1C3) av_log(s->avctx, AV_LOG_DEBUG, "stuffing start"); + else if(startcode<=0x1C5) av_log(s->avctx, AV_LOG_DEBUG, "reserved"); + else if(startcode<=0x1FF) av_log(s->avctx, AV_LOG_DEBUG, "System start"); + av_log(s->avctx, AV_LOG_DEBUG, " at %d\n", get_bits_count(gb)); + } + + if(startcode >= 0x120 && startcode <= 0x12F){ + if(decode_vol_header(s, gb) < 0) + return -1; + } + else if(startcode == USER_DATA_STARTCODE){ + decode_user_data(s, gb); + } + else if(startcode == GOP_STARTCODE){ + mpeg4_decode_gop_header(s, gb); + } + else if(startcode == VOP_STARTCODE){ + break; + } + + align_get_bits(gb); + startcode = 0xff; + } +end: + if(s->flags& CODEC_FLAG_LOW_DELAY) + s->low_delay=1; + s->avctx->has_b_frames= !s->low_delay; + return decode_vop_header(s, gb); +} + +static av_cold int decode_init(AVCodecContext *avctx) +{ + MpegEncContext *s = avctx->priv_data; + int ret; + static int done = 0; + + s->divx_version= + s->divx_build= + s->xvid_build= + s->lavc_build= -1; + + if((ret=ff_h263_decode_init(avctx)) < 0) + return ret; + + if (!done) { + done = 1; + + init_rl(&ff_mpeg4_rl_intra, ff_mpeg4_static_rl_table_store[0]); + init_rl(&rvlc_rl_inter, ff_mpeg4_static_rl_table_store[1]); + init_rl(&rvlc_rl_intra, ff_mpeg4_static_rl_table_store[2]); + INIT_VLC_RL(ff_mpeg4_rl_intra, 554); + INIT_VLC_RL(rvlc_rl_inter, 1072); + INIT_VLC_RL(rvlc_rl_intra, 1072); + INIT_VLC_STATIC(&dc_lum, DC_VLC_BITS, 10 /* 13 */, + &ff_mpeg4_DCtab_lum[0][1], 2, 1, + &ff_mpeg4_DCtab_lum[0][0], 2, 1, 512); + INIT_VLC_STATIC(&dc_chrom, DC_VLC_BITS, 10 /* 13 */, + &ff_mpeg4_DCtab_chrom[0][1], 2, 1, + &ff_mpeg4_DCtab_chrom[0][0], 2, 1, 512); + INIT_VLC_STATIC(&sprite_trajectory, SPRITE_TRAJ_VLC_BITS, 15, + &sprite_trajectory_tab[0][1], 4, 2, + &sprite_trajectory_tab[0][0], 4, 2, 128); + INIT_VLC_STATIC(&mb_type_b_vlc, MB_TYPE_B_VLC_BITS, 4, + &mb_type_b_tab[0][1], 2, 1, + &mb_type_b_tab[0][0], 2, 1, 16); + } + + s->h263_pred = 1; + s->low_delay = 0; //default, might be overriden in the vol header during header parsing + s->decode_mb= mpeg4_decode_mb; + s->time_increment_bits = 4; /* default value for broken headers */ + avctx->chroma_sample_location = AVCHROMA_LOC_LEFT; + + return 0; +} + +AVCodec 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, + .flush= ff_mpeg_flush, + .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2"), + .pix_fmts= ff_hwaccel_pixfmt_list_420, +}; + + +#if CONFIG_MPEG4_VDPAU_DECODER +AVCodec 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, + .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 (VDPAU)"), + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_VDPAU_MPEG4, PIX_FMT_NONE}, +}; +#endif diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg4videoenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg4videoenc.c new file mode 100644 index 0000000000..79190f0a6f --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpeg4videoenc.c @@ -0,0 +1,1352 @@ +/* + * MPEG4 encoder. + * Copyright (c) 2000,2001 Fabrice Bellard + * Copyright (c) 2002-2010 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 + */ + +#include "mpegvideo.h" +#include "h263.h" +#include "mpeg4video.h" + +//The uni_DCtab_* tables below contain unified bits+length tables to encode DC +//differences in mpeg4. Unified in the sense that the specification specifies +//this encoding in several steps. +static uint8_t uni_DCtab_lum_len[512]; +static uint8_t uni_DCtab_chrom_len[512]; +static uint16_t uni_DCtab_lum_bits[512]; +static uint16_t uni_DCtab_chrom_bits[512]; + +//unified encoding tables for run length encoding of coefficients +//unified in the sense that the specification specifies the encoding in several steps. +static uint32_t uni_mpeg4_intra_rl_bits[64*64*2*2]; +static uint8_t uni_mpeg4_intra_rl_len [64*64*2*2]; +static uint32_t uni_mpeg4_inter_rl_bits[64*64*2*2]; +static uint8_t uni_mpeg4_inter_rl_len [64*64*2*2]; +//#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128 + (run)*256 + (level)) +//#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128*64 + (run) + (level)*64) +#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128*64 + (run)*128 + (level)) + +/* mpeg4 +inter +max level: 24/6 +max run: 53/63 + +intra +max level: 53/16 +max run: 29/41 +*/ + + +/** + * Returns the number of bits that encoding the 8x8 block in block would need. + * @param[in] block_last_index last index in scantable order that refers to a non zero element in block. + */ +static inline int get_block_rate(MpegEncContext * s, DCTELEM block[64], int block_last_index, uint8_t scantable[64]){ + int last=0; + int j; + int rate=0; + + for(j=1; j<=block_last_index; j++){ + const int index= scantable[j]; + int level= block[index]; + if(level){ + level+= 64; + if((level&(~127)) == 0){ + if(jintra_ac_vlc_length [UNI_AC_ENC_INDEX(j-last-1, level)]; + else rate+= s->intra_ac_vlc_last_length[UNI_AC_ENC_INDEX(j-last-1, level)]; + }else + rate += s->ac_esc_length; + + last= j; + } + } + + return rate; +} + + +/** + * Restores the ac coefficients in block that have been changed by decide_ac_pred(). + * This function also restores s->block_last_index. + * @param[in,out] block MB coefficients, these will be restored + * @param[in] dir ac prediction direction for each 8x8 block + * @param[out] st scantable for each 8x8 block + * @param[in] zigzag_last_index index refering to the last non zero coefficient in zigzag order + */ +static inline void restore_ac_coeffs(MpegEncContext * s, DCTELEM block[6][64], const int dir[6], uint8_t *st[6], const int zigzag_last_index[6]) +{ + int i, n; + memcpy(s->block_last_index, zigzag_last_index, sizeof(int)*6); + + for(n=0; n<6; n++){ + int16_t *ac_val = s->ac_val[0][0] + s->block_index[n] * 16; + + st[n]= s->intra_scantable.permutated; + if(dir[n]){ + /* top prediction */ + for(i=1; i<8; i++){ + block[n][s->dsp.idct_permutation[i ]] = ac_val[i+8]; + } + }else{ + /* left prediction */ + for(i=1; i<8; i++){ + block[n][s->dsp.idct_permutation[i<<3]]= ac_val[i ]; + } + } + } +} + +/** + * Returns the optimal value (0 or 1) for the ac_pred element for the given MB in mpeg4. + * This function will also update s->block_last_index and s->ac_val. + * @param[in,out] block MB coefficients, these will be updated if 1 is returned + * @param[in] dir ac prediction direction for each 8x8 block + * @param[out] st scantable for each 8x8 block + * @param[out] zigzag_last_index index refering to the last non zero coefficient in zigzag order + */ +static inline int decide_ac_pred(MpegEncContext * s, DCTELEM block[6][64], const int dir[6], uint8_t *st[6], int zigzag_last_index[6]) +{ + int score= 0; + int i, n; + int8_t * const qscale_table= s->current_picture.qscale_table; + + memcpy(zigzag_last_index, s->block_last_index, sizeof(int)*6); + + for(n=0; n<6; n++){ + int16_t *ac_val, *ac_val1; + + score -= get_block_rate(s, block[n], s->block_last_index[n], s->intra_scantable.permutated); + + ac_val = s->ac_val[0][0] + s->block_index[n] * 16; + ac_val1= ac_val; + if(dir[n]){ + const int xy= s->mb_x + s->mb_y*s->mb_stride - s->mb_stride; + /* top prediction */ + ac_val-= s->block_wrap[n]*16; + if(s->mb_y==0 || s->qscale == qscale_table[xy] || n==2 || n==3){ + /* same qscale */ + for(i=1; i<8; i++){ + const int level= block[n][s->dsp.idct_permutation[i ]]; + block[n][s->dsp.idct_permutation[i ]] = level - ac_val[i+8]; + ac_val1[i ]= block[n][s->dsp.idct_permutation[i<<3]]; + ac_val1[i+8]= level; + } + }else{ + /* different qscale, we must rescale */ + for(i=1; i<8; i++){ + const int level= block[n][s->dsp.idct_permutation[i ]]; + block[n][s->dsp.idct_permutation[i ]] = level - ROUNDED_DIV(ac_val[i + 8]*qscale_table[xy], s->qscale); + ac_val1[i ]= block[n][s->dsp.idct_permutation[i<<3]]; + ac_val1[i+8]= level; + } + } + st[n]= s->intra_h_scantable.permutated; + }else{ + const int xy= s->mb_x-1 + s->mb_y*s->mb_stride; + /* left prediction */ + ac_val-= 16; + if(s->mb_x==0 || s->qscale == qscale_table[xy] || n==1 || n==3){ + /* same qscale */ + for(i=1; i<8; i++){ + const int level= block[n][s->dsp.idct_permutation[i<<3]]; + block[n][s->dsp.idct_permutation[i<<3]]= level - ac_val[i]; + ac_val1[i ]= level; + ac_val1[i+8]= block[n][s->dsp.idct_permutation[i ]]; + } + }else{ + /* different qscale, we must rescale */ + for(i=1; i<8; i++){ + const int level= block[n][s->dsp.idct_permutation[i<<3]]; + block[n][s->dsp.idct_permutation[i<<3]]= level - ROUNDED_DIV(ac_val[i]*qscale_table[xy], s->qscale); + ac_val1[i ]= level; + ac_val1[i+8]= block[n][s->dsp.idct_permutation[i ]]; + } + } + st[n]= s->intra_v_scantable.permutated; + } + + for(i=63; i>0; i--) //FIXME optimize + if(block[n][ st[n][i] ]) break; + s->block_last_index[n]= i; + + score += get_block_rate(s, block[n], s->block_last_index[n], st[n]); + } + + if(score < 0){ + return 1; + }else{ + restore_ac_coeffs(s, block, dir, st, zigzag_last_index); + return 0; + } +} + +/** + * modify mb_type & qscale so that encoding is acually possible in mpeg4 + */ +void ff_clean_mpeg4_qscales(MpegEncContext *s){ + int i; + int8_t * const qscale_table= s->current_picture.qscale_table; + + ff_clean_h263_qscales(s); + + if(s->pict_type== FF_B_TYPE){ + int odd=0; + /* ok, come on, this isn't funny anymore, there's more code for handling this mpeg4 mess than for the actual adaptive quantization */ + + for(i=0; imb_num; i++){ + int mb_xy= s->mb_index2xy[i]; + odd += qscale_table[mb_xy]&1; + } + + if(2*odd > s->mb_num) odd=1; + else odd=0; + + for(i=0; imb_num; i++){ + int mb_xy= s->mb_index2xy[i]; + if((qscale_table[mb_xy]&1) != odd) + qscale_table[mb_xy]++; + if(qscale_table[mb_xy] > 31) + qscale_table[mb_xy]= 31; + } + + for(i=1; imb_num; i++){ + int mb_xy= s->mb_index2xy[i]; + if(qscale_table[mb_xy] != qscale_table[s->mb_index2xy[i-1]] && (s->mb_type[mb_xy]&CANDIDATE_MB_TYPE_DIRECT)){ + s->mb_type[mb_xy]|= CANDIDATE_MB_TYPE_BIDIR; + } + } + } +} + + +/** + * encodes the dc value. + * @param n block index (0-3 are luma, 4-5 are chroma) + */ +static inline void mpeg4_encode_dc(PutBitContext * s, int level, int n) +{ +#if 1 + /* DC will overflow if level is outside the [-255,255] range. */ + level+=256; + if (n < 4) { + /* luminance */ + put_bits(s, uni_DCtab_lum_len[level], uni_DCtab_lum_bits[level]); + } else { + /* chrominance */ + put_bits(s, uni_DCtab_chrom_len[level], uni_DCtab_chrom_bits[level]); + } +#else + int size, v; + /* find number of bits */ + size = 0; + v = abs(level); + while (v) { + v >>= 1; + size++; + } + + if (n < 4) { + /* luminance */ + put_bits(&s->pb, ff_mpeg4_DCtab_lum[size][1], ff_mpeg4_DCtab_lum[size][0]); + } else { + /* chrominance */ + put_bits(&s->pb, ff_mpeg4_DCtab_chrom[size][1], ff_mpeg4_DCtab_chrom[size][0]); + } + + /* encode remaining bits */ + if (size > 0) { + if (level < 0) + level = (-level) ^ ((1 << size) - 1); + put_bits(&s->pb, size, level); + if (size > 8) + put_bits(&s->pb, 1, 1); + } +#endif +} + +static inline int mpeg4_get_dc_length(int level, int n){ + if (n < 4) { + return uni_DCtab_lum_len[level + 256]; + } else { + return uni_DCtab_chrom_len[level + 256]; + } +} + +/** + * encodes a 8x8 block + * @param n block index (0-3 are luma, 4-5 are chroma) + */ +static inline void mpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n, int intra_dc, + uint8_t *scan_table, PutBitContext *dc_pb, PutBitContext *ac_pb) +{ + int i, last_non_zero; +#if 0 //variables for the outcommented version + int code, sign, last; +#endif + const RLTable *rl; + uint32_t *bits_tab; + uint8_t *len_tab; + const int last_index = s->block_last_index[n]; + + if (s->mb_intra) { //Note gcc (3.2.1 at least) will optimize this away + /* mpeg4 based DC predictor */ + mpeg4_encode_dc(dc_pb, intra_dc, n); + if(last_index<1) return; + i = 1; + rl = &ff_mpeg4_rl_intra; + bits_tab= uni_mpeg4_intra_rl_bits; + len_tab = uni_mpeg4_intra_rl_len; + } else { + if(last_index<0) return; + i = 0; + rl = &ff_h263_rl_inter; + bits_tab= uni_mpeg4_inter_rl_bits; + len_tab = uni_mpeg4_inter_rl_len; + } + + /* AC coefs */ + last_non_zero = i - 1; +#if 1 + for (; i < last_index; i++) { + int level = block[ scan_table[i] ]; + if (level) { + int run = i - last_non_zero - 1; + level+=64; + if((level&(~127)) == 0){ + const int index= UNI_MPEG4_ENC_INDEX(0, run, level); + put_bits(ac_pb, len_tab[index], bits_tab[index]); + }else{ //ESC3 + put_bits(ac_pb, 7+2+1+6+1+12+1, (3<<23)+(3<<21)+(0<<20)+(run<<14)+(1<<13)+(((level-64)&0xfff)<<1)+1); + } + last_non_zero = i; + } + } + /*if(i<=last_index)*/{ + int level = block[ scan_table[i] ]; + int run = i - last_non_zero - 1; + level+=64; + if((level&(~127)) == 0){ + const int index= UNI_MPEG4_ENC_INDEX(1, run, level); + put_bits(ac_pb, len_tab[index], bits_tab[index]); + }else{ //ESC3 + put_bits(ac_pb, 7+2+1+6+1+12+1, (3<<23)+(3<<21)+(1<<20)+(run<<14)+(1<<13)+(((level-64)&0xfff)<<1)+1); + } + } +#else + for (; i <= last_index; i++) { + const int slevel = block[ scan_table[i] ]; + if (slevel) { + int level; + int run = i - last_non_zero - 1; + last = (i == last_index); + sign = 0; + level = slevel; + if (level < 0) { + sign = 1; + level = -level; + } + code = get_rl_index(rl, last, run, level); + put_bits(ac_pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); + if (code == rl->n) { + int level1, run1; + level1 = level - rl->max_level[last][run]; + if (level1 < 1) + goto esc2; + code = get_rl_index(rl, last, run, level1); + if (code == rl->n) { + esc2: + put_bits(ac_pb, 1, 1); + if (level > MAX_LEVEL) + goto esc3; + run1 = run - rl->max_run[last][level] - 1; + if (run1 < 0) + goto esc3; + code = get_rl_index(rl, last, run1, level); + if (code == rl->n) { + esc3: + /* third escape */ + put_bits(ac_pb, 1, 1); + put_bits(ac_pb, 1, last); + put_bits(ac_pb, 6, run); + put_bits(ac_pb, 1, 1); + put_sbits(ac_pb, 12, slevel); + put_bits(ac_pb, 1, 1); + } else { + /* second escape */ + put_bits(ac_pb, 1, 0); + put_bits(ac_pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); + put_bits(ac_pb, 1, sign); + } + } else { + /* first escape */ + put_bits(ac_pb, 1, 0); + put_bits(ac_pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); + put_bits(ac_pb, 1, sign); + } + } else { + put_bits(ac_pb, 1, sign); + } + last_non_zero = i; + } + } +#endif +} + +static int mpeg4_get_block_length(MpegEncContext * s, DCTELEM * block, int n, int intra_dc, + uint8_t *scan_table) +{ + int i, last_non_zero; + uint8_t *len_tab; + const int last_index = s->block_last_index[n]; + int len=0; + + if (s->mb_intra) { //Note gcc (3.2.1 at least) will optimize this away + /* mpeg4 based DC predictor */ + len += mpeg4_get_dc_length(intra_dc, n); + if(last_index<1) return len; + i = 1; + len_tab = uni_mpeg4_intra_rl_len; + } else { + if(last_index<0) return 0; + i = 0; + len_tab = uni_mpeg4_inter_rl_len; + } + + /* AC coefs */ + last_non_zero = i - 1; + for (; i < last_index; i++) { + int level = block[ scan_table[i] ]; + if (level) { + int run = i - last_non_zero - 1; + level+=64; + if((level&(~127)) == 0){ + const int index= UNI_MPEG4_ENC_INDEX(0, run, level); + len += len_tab[index]; + }else{ //ESC3 + len += 7+2+1+6+1+12+1; + } + last_non_zero = i; + } + } + /*if(i<=last_index)*/{ + int level = block[ scan_table[i] ]; + int run = i - last_non_zero - 1; + level+=64; + if((level&(~127)) == 0){ + const int index= UNI_MPEG4_ENC_INDEX(1, run, level); + len += len_tab[index]; + }else{ //ESC3 + len += 7+2+1+6+1+12+1; + } + } + + return len; +} + +static inline void mpeg4_encode_blocks(MpegEncContext * s, DCTELEM block[6][64], int intra_dc[6], + uint8_t **scan_table, PutBitContext *dc_pb, PutBitContext *ac_pb){ + int i; + + if(scan_table){ + if(s->flags2 & CODEC_FLAG2_NO_OUTPUT){ + for (i = 0; i < 6; i++) { + skip_put_bits(&s->pb, mpeg4_get_block_length(s, block[i], i, intra_dc[i], scan_table[i])); + } + }else{ + /* encode each block */ + for (i = 0; i < 6; i++) { + mpeg4_encode_block(s, block[i], i, intra_dc[i], scan_table[i], dc_pb, ac_pb); + } + } + }else{ + if(s->flags2 & CODEC_FLAG2_NO_OUTPUT){ + for (i = 0; i < 6; i++) { + skip_put_bits(&s->pb, mpeg4_get_block_length(s, block[i], i, 0, s->intra_scantable.permutated)); + } + }else{ + /* encode each block */ + for (i = 0; i < 6; i++) { + mpeg4_encode_block(s, block[i], i, 0, s->intra_scantable.permutated, dc_pb, ac_pb); + } + } + } +} + +//FIXME this is duplicated to h263.c +static const int dquant_code[5]= {1,0,9,2,3}; + +void mpeg4_encode_mb(MpegEncContext * s, + DCTELEM block[6][64], + int motion_x, int motion_y) +{ + int cbpc, cbpy, pred_x, pred_y; + PutBitContext * const pb2 = s->data_partitioning ? &s->pb2 : &s->pb; + PutBitContext * const tex_pb = s->data_partitioning && s->pict_type!=FF_B_TYPE ? &s->tex_pb : &s->pb; + PutBitContext * const dc_pb = s->data_partitioning && s->pict_type!=FF_I_TYPE ? &s->pb2 : &s->pb; + const int interleaved_stats= (s->flags&CODEC_FLAG_PASS1) && !s->data_partitioning ? 1 : 0; + + if (!s->mb_intra) { + int i, cbp; + + if(s->pict_type==FF_B_TYPE){ + static const int mb_type_table[8]= {-1, 3, 2, 1,-1,-1,-1, 0}; /* convert from mv_dir to type */ + int mb_type= mb_type_table[s->mv_dir]; + + if(s->mb_x==0){ + for(i=0; i<2; i++){ + s->last_mv[i][0][0]= + s->last_mv[i][0][1]= + s->last_mv[i][1][0]= + s->last_mv[i][1][1]= 0; + } + } + + assert(s->dquant>=-2 && s->dquant<=2); + assert((s->dquant&1)==0); + 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 & ... + s->skip_count++; + s->mv[0][0][0]= + s->mv[0][0][1]= + s->mv[1][0][0]= + s->mv[1][0][1]= 0; + s->mv_dir= MV_DIR_FORWARD; //doesn't matter + s->qscale -= s->dquant; +// s->mb_skipped=1; + + return; + } + + cbp= get_b_cbp(s, block, motion_x, motion_y, mb_type); + + if ((cbp | motion_x | motion_y | mb_type) ==0) { + /* direct MB with MV={0,0} */ + assert(s->dquant==0); + + put_bits(&s->pb, 1, 1); /* mb not coded modb1=1 */ + + if(interleaved_stats){ + s->misc_bits++; + s->last_bits++; + } + s->skip_count++; + return; + } + + put_bits(&s->pb, 1, 0); /* mb coded modb1=0 */ + put_bits(&s->pb, 1, cbp ? 0 : 1); /* modb2 */ //FIXME merge + put_bits(&s->pb, mb_type+1, 1); // this table is so simple that we don't need it :) + if(cbp) put_bits(&s->pb, 6, cbp); + + if(cbp && mb_type){ + if(s->dquant) + put_bits(&s->pb, 2, (s->dquant>>2)+3); + else + put_bits(&s->pb, 1, 0); + }else + s->qscale -= s->dquant; + + if(!s->progressive_sequence){ + if(cbp) + put_bits(&s->pb, 1, s->interlaced_dct); + if(mb_type) // not direct mode + put_bits(&s->pb, 1, s->mv_type == MV_TYPE_FIELD); + } + + if(interleaved_stats){ + s->misc_bits+= get_bits_diff(s); + } + + if(mb_type == 0){ + assert(s->mv_dir & MV_DIRECT); + ff_h263_encode_motion_vector(s, motion_x, motion_y, 1); + s->b_count++; + s->f_count++; + }else{ + assert(mb_type > 0 && mb_type < 4); + if(s->mv_type != MV_TYPE_FIELD){ + if(s->mv_dir & MV_DIR_FORWARD){ + ff_h263_encode_motion_vector(s, s->mv[0][0][0] - s->last_mv[0][0][0], + s->mv[0][0][1] - s->last_mv[0][0][1], s->f_code); + s->last_mv[0][0][0]= s->last_mv[0][1][0]= s->mv[0][0][0]; + s->last_mv[0][0][1]= s->last_mv[0][1][1]= s->mv[0][0][1]; + s->f_count++; + } + if(s->mv_dir & MV_DIR_BACKWARD){ + ff_h263_encode_motion_vector(s, s->mv[1][0][0] - s->last_mv[1][0][0], + s->mv[1][0][1] - s->last_mv[1][0][1], s->b_code); + s->last_mv[1][0][0]= s->last_mv[1][1][0]= s->mv[1][0][0]; + s->last_mv[1][0][1]= s->last_mv[1][1][1]= s->mv[1][0][1]; + s->b_count++; + } + }else{ + if(s->mv_dir & MV_DIR_FORWARD){ + put_bits(&s->pb, 1, s->field_select[0][0]); + put_bits(&s->pb, 1, s->field_select[0][1]); + } + if(s->mv_dir & MV_DIR_BACKWARD){ + put_bits(&s->pb, 1, s->field_select[1][0]); + put_bits(&s->pb, 1, s->field_select[1][1]); + } + if(s->mv_dir & MV_DIR_FORWARD){ + for(i=0; i<2; i++){ + ff_h263_encode_motion_vector(s, s->mv[0][i][0] - s->last_mv[0][i][0] , + s->mv[0][i][1] - s->last_mv[0][i][1]/2, s->f_code); + s->last_mv[0][i][0]= s->mv[0][i][0]; + s->last_mv[0][i][1]= s->mv[0][i][1]*2; + } + s->f_count++; + } + if(s->mv_dir & MV_DIR_BACKWARD){ + for(i=0; i<2; i++){ + ff_h263_encode_motion_vector(s, s->mv[1][i][0] - s->last_mv[1][i][0] , + s->mv[1][i][1] - s->last_mv[1][i][1]/2, s->b_code); + s->last_mv[1][i][0]= s->mv[1][i][0]; + s->last_mv[1][i][1]= s->mv[1][i][1]*2; + } + s->b_count++; + } + } + } + + if(interleaved_stats){ + s->mv_bits+= get_bits_diff(s); + } + + mpeg4_encode_blocks(s, block, NULL, NULL, NULL, &s->pb); + + if(interleaved_stats){ + s->p_tex_bits+= get_bits_diff(s); + } + + }else{ /* s->pict_type==FF_B_TYPE */ + cbp= get_p_cbp(s, block, motion_x, motion_y); + + if ((cbp | motion_x | motion_y | s->dquant) == 0 && s->mv_type==MV_TYPE_16X16) { + /* check if the B frames can skip it too, as we must skip it if we skip here + why didn't they just compress the skip-mb bits instead of reusing them ?! */ + if(s->max_b_frames>0){ + int i; + int x,y, offset; + uint8_t *p_pic; + + 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; + + s->mb_skipped=1; + for(i=0; imax_b_frames; i++){ + uint8_t *b_pic; + int diff; + Picture *pic= s->reordered_input_picture[i+1]; + + if(pic==NULL || pic->pict_type!=FF_B_TYPE) break; + + b_pic= pic->data[0] + offset; + if(pic->type != FF_BUFFER_TYPE_SHARED) + b_pic+= INPLACE_OFFSET; + 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; + } + } + }else + s->mb_skipped=1; + + if(s->mb_skipped==1){ + /* skip macroblock */ + put_bits(&s->pb, 1, 1); + + if(interleaved_stats){ + s->misc_bits++; + s->last_bits++; + } + s->skip_count++; + + return; + } + } + + put_bits(&s->pb, 1, 0); /* mb coded */ + cbpc = cbp & 3; + cbpy = cbp >> 2; + cbpy ^= 0xf; + if(s->mv_type==MV_TYPE_16X16){ + if(s->dquant) cbpc+= 8; + put_bits(&s->pb, + ff_h263_inter_MCBPC_bits[cbpc], + ff_h263_inter_MCBPC_code[cbpc]); + + put_bits(pb2, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]); + if(s->dquant) + put_bits(pb2, 2, dquant_code[s->dquant+2]); + + if(!s->progressive_sequence){ + if(cbp) + put_bits(pb2, 1, s->interlaced_dct); + put_bits(pb2, 1, 0); + } + + if(interleaved_stats){ + s->misc_bits+= get_bits_diff(s); + } + + /* motion vectors: 16x16 mode */ + h263_pred_motion(s, 0, 0, &pred_x, &pred_y); + + ff_h263_encode_motion_vector(s, motion_x - pred_x, + motion_y - pred_y, s->f_code); + }else if(s->mv_type==MV_TYPE_FIELD){ + if(s->dquant) cbpc+= 8; + put_bits(&s->pb, + ff_h263_inter_MCBPC_bits[cbpc], + ff_h263_inter_MCBPC_code[cbpc]); + + put_bits(pb2, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]); + if(s->dquant) + put_bits(pb2, 2, dquant_code[s->dquant+2]); + + assert(!s->progressive_sequence); + if(cbp) + put_bits(pb2, 1, s->interlaced_dct); + put_bits(pb2, 1, 1); + + if(interleaved_stats){ + s->misc_bits+= get_bits_diff(s); + } + + /* motion vectors: 16x8 interlaced mode */ + h263_pred_motion(s, 0, 0, &pred_x, &pred_y); + pred_y /=2; + + put_bits(&s->pb, 1, s->field_select[0][0]); + put_bits(&s->pb, 1, s->field_select[0][1]); + + ff_h263_encode_motion_vector(s, s->mv[0][0][0] - pred_x, + s->mv[0][0][1] - pred_y, s->f_code); + ff_h263_encode_motion_vector(s, s->mv[0][1][0] - pred_x, + s->mv[0][1][1] - pred_y, s->f_code); + }else{ + assert(s->mv_type==MV_TYPE_8X8); + put_bits(&s->pb, + ff_h263_inter_MCBPC_bits[cbpc+16], + ff_h263_inter_MCBPC_code[cbpc+16]); + put_bits(pb2, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]); + + if(!s->progressive_sequence){ + if(cbp) + put_bits(pb2, 1, s->interlaced_dct); + } + + if(interleaved_stats){ + s->misc_bits+= get_bits_diff(s); + } + + for(i=0; i<4; i++){ + /* 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); + } + } + + if(interleaved_stats){ + s->mv_bits+= get_bits_diff(s); + } + + mpeg4_encode_blocks(s, block, NULL, NULL, NULL, tex_pb); + + if(interleaved_stats){ + s->p_tex_bits+= get_bits_diff(s); + } + s->f_count++; + } + } else { + int cbp; + int dc_diff[6]; //dc values with the dc prediction subtracted + int dir[6]; //prediction direction + int zigzag_last_index[6]; + uint8_t *scan_table[6]; + int i; + + for(i=0; i<6; i++){ + dc_diff[i]= ff_mpeg4_pred_dc(s, i, block[i][0], &dir[i], 1); + } + + if(s->flags & CODEC_FLAG_AC_PRED){ + s->ac_pred= decide_ac_pred(s, block, dir, scan_table, zigzag_last_index); + }else{ + for(i=0; i<6; i++) + scan_table[i]= s->intra_scantable.permutated; + } + + /* compute cbp */ + cbp = 0; + for (i = 0; i < 6; i++) { + if (s->block_last_index[i] >= 1) + cbp |= 1 << (5 - i); + } + + cbpc = cbp & 3; + if (s->pict_type == FF_I_TYPE) { + if(s->dquant) cbpc+=4; + put_bits(&s->pb, + ff_h263_intra_MCBPC_bits[cbpc], + ff_h263_intra_MCBPC_code[cbpc]); + } else { + if(s->dquant) cbpc+=8; + put_bits(&s->pb, 1, 0); /* mb coded */ + put_bits(&s->pb, + ff_h263_inter_MCBPC_bits[cbpc + 4], + ff_h263_inter_MCBPC_code[cbpc + 4]); + } + put_bits(pb2, 1, s->ac_pred); + cbpy = cbp >> 2; + put_bits(pb2, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]); + if(s->dquant) + put_bits(dc_pb, 2, dquant_code[s->dquant+2]); + + if(!s->progressive_sequence){ + put_bits(dc_pb, 1, s->interlaced_dct); + } + + if(interleaved_stats){ + s->misc_bits+= get_bits_diff(s); + } + + mpeg4_encode_blocks(s, block, dc_diff, scan_table, dc_pb, tex_pb); + + if(interleaved_stats){ + s->i_tex_bits+= get_bits_diff(s); + } + s->i_count++; + + /* restore ac coeffs & last_index stuff if we messed them up with the prediction */ + if(s->ac_pred) + restore_ac_coeffs(s, block, dir, scan_table, zigzag_last_index); + } +} + +/** + * add mpeg4 stuffing bits (01...1) + */ +void ff_mpeg4_stuffing(PutBitContext * pbc) +{ + int length; + put_bits(pbc, 1, 0); + length= (-put_bits_count(pbc))&7; + if(length) put_bits(pbc, length, (1<pict_type==FF_B_TYPE){ + ff_mpeg4_init_direct_mv(s); + }else{ + s->last_time_base= s->time_base; + s->time_base= s->time/s->avctx->time_base.den; + } +} + +static void mpeg4_encode_gop_header(MpegEncContext * s){ + int hours, minutes, seconds; + int64_t time; + + put_bits(&s->pb, 16, 0); + put_bits(&s->pb, 16, GOP_STARTCODE); + + time= s->current_picture_ptr->pts; + if(s->reordered_input_picture[1]) + time= FFMIN(time, s->reordered_input_picture[1]->pts); + time= time*s->avctx->time_base.num; + + seconds= time/s->avctx->time_base.den; + minutes= seconds/60; seconds %= 60; + hours= minutes/60; minutes %= 60; + hours%=24; + + put_bits(&s->pb, 5, hours); + put_bits(&s->pb, 6, minutes); + put_bits(&s->pb, 1, 1); + put_bits(&s->pb, 6, seconds); + + 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); +} + +static void mpeg4_encode_visual_object_header(MpegEncContext * s){ + int profile_and_level_indication; + int vo_ver_id; + + if(s->avctx->profile != FF_PROFILE_UNKNOWN){ + profile_and_level_indication = s->avctx->profile << 4; + }else if(s->max_b_frames || s->quarter_sample){ + profile_and_level_indication= 0xF0; // adv simple + }else{ + profile_and_level_indication= 0x00; // simple + } + + if(s->avctx->level != FF_LEVEL_UNKNOWN){ + profile_and_level_indication |= s->avctx->level; + }else{ + profile_and_level_indication |= 1; //level 1 + } + + if(profile_and_level_indication>>4 == 0xF){ + vo_ver_id= 5; + }else{ + vo_ver_id= 1; + } + + //FIXME levels + + put_bits(&s->pb, 16, 0); + put_bits(&s->pb, 16, VOS_STARTCODE); + + put_bits(&s->pb, 8, profile_and_level_indication); + + put_bits(&s->pb, 16, 0); + put_bits(&s->pb, 16, VISUAL_OBJ_STARTCODE); + + put_bits(&s->pb, 1, 1); + put_bits(&s->pb, 4, vo_ver_id); + put_bits(&s->pb, 3, 1); //priority + + put_bits(&s->pb, 4, 1); //visual obj type== video obj + + put_bits(&s->pb, 1, 0); //video signal type == no clue //FIXME + + ff_mpeg4_stuffing(&s->pb); +} + +static void mpeg4_encode_vol_header(MpegEncContext * s, int vo_number, int vol_number) +{ + int vo_ver_id; + + if (!CONFIG_MPEG4_ENCODER) return; + + if(s->max_b_frames || s->quarter_sample){ + vo_ver_id= 5; + s->vo_type= ADV_SIMPLE_VO_TYPE; + }else{ + vo_ver_id= 1; + s->vo_type= SIMPLE_VO_TYPE; + } + + put_bits(&s->pb, 16, 0); + put_bits(&s->pb, 16, 0x100 + vo_number); /* video obj */ + put_bits(&s->pb, 16, 0); + put_bits(&s->pb, 16, 0x120 + vol_number); /* video obj layer */ + + put_bits(&s->pb, 1, 0); /* random access vol */ + put_bits(&s->pb, 8, s->vo_type); /* video obj type indication */ + if(s->workaround_bugs & FF_BUG_MS) { + put_bits(&s->pb, 1, 0); /* is obj layer id= no */ + } else { + put_bits(&s->pb, 1, 1); /* is obj layer id= yes */ + put_bits(&s->pb, 4, vo_ver_id); /* is obj layer ver id */ + put_bits(&s->pb, 3, 1); /* is obj layer priority */ + } + + s->aspect_ratio_info= ff_h263_aspect_to_info(s->avctx->sample_aspect_ratio); + + put_bits(&s->pb, 4, s->aspect_ratio_info);/* aspect ratio info */ + if (s->aspect_ratio_info == FF_ASPECT_EXTENDED){ + put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.num); + put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.den); + } + + if(s->workaround_bugs & FF_BUG_MS) { // + put_bits(&s->pb, 1, 0); /* vol control parameters= no @@@ */ + } else { + put_bits(&s->pb, 1, 1); /* vol control parameters= yes */ + put_bits(&s->pb, 2, 1); /* chroma format YUV 420/YV12 */ + put_bits(&s->pb, 1, s->low_delay); + put_bits(&s->pb, 1, 0); /* vbv parameters= no */ + } + + put_bits(&s->pb, 2, RECT_SHAPE); /* vol shape= rectangle */ + put_bits(&s->pb, 1, 1); /* marker bit */ + + put_bits(&s->pb, 16, s->avctx->time_base.den); + if (s->time_increment_bits < 1) + s->time_increment_bits = 1; + put_bits(&s->pb, 1, 1); /* marker bit */ + put_bits(&s->pb, 1, 0); /* fixed vop rate=no */ + put_bits(&s->pb, 1, 1); /* marker bit */ + put_bits(&s->pb, 13, s->width); /* vol width */ + put_bits(&s->pb, 1, 1); /* marker bit */ + put_bits(&s->pb, 13, s->height); /* vol height */ + put_bits(&s->pb, 1, 1); /* marker bit */ + put_bits(&s->pb, 1, s->progressive_sequence ? 0 : 1); + put_bits(&s->pb, 1, 1); /* obmc disable */ + if (vo_ver_id == 1) { + put_bits(&s->pb, 1, s->vol_sprite_usage); /* sprite enable */ + }else{ + put_bits(&s->pb, 2, s->vol_sprite_usage); /* sprite enable */ + } + + put_bits(&s->pb, 1, 0); /* not 8 bit == false */ + put_bits(&s->pb, 1, s->mpeg_quant); /* quant type= (0=h263 style)*/ + + if(s->mpeg_quant){ + ff_write_quant_matrix(&s->pb, s->avctx->intra_matrix); + ff_write_quant_matrix(&s->pb, s->avctx->inter_matrix); + } + + if (vo_ver_id != 1) + put_bits(&s->pb, 1, s->quarter_sample); + put_bits(&s->pb, 1, 1); /* complexity estimation disable */ + s->resync_marker= s->rtp_mode; + put_bits(&s->pb, 1, s->resync_marker ? 0 : 1);/* resync marker disable */ + put_bits(&s->pb, 1, s->data_partitioning ? 1 : 0); + if(s->data_partitioning){ + put_bits(&s->pb, 1, 0); /* no rvlc */ + } + + if (vo_ver_id != 1){ + put_bits(&s->pb, 1, 0); /* newpred */ + put_bits(&s->pb, 1, 0); /* reduced res vop */ + } + put_bits(&s->pb, 1, 0); /* scalability */ + + ff_mpeg4_stuffing(&s->pb); + + /* user data */ + if(!(s->flags & CODEC_FLAG_BITEXACT)){ + put_bits(&s->pb, 16, 0); + put_bits(&s->pb, 16, 0x1B2); /* user_data */ + ff_put_string(&s->pb, LIBAVCODEC_IDENT, 0); + } +} + +/* write mpeg4 VOP header */ +void mpeg4_encode_picture_header(MpegEncContext * s, int picture_number) +{ + int time_incr; + int time_div, time_mod; + + if(s->pict_type==FF_I_TYPE){ + if(!(s->flags&CODEC_FLAG_GLOBAL_HEADER)){ + if(s->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT) //HACK, the reference sw is buggy + mpeg4_encode_visual_object_header(s); + if(s->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT || picture_number==0) //HACK, the reference sw is buggy + mpeg4_encode_vol_header(s, 0, 0); + } + if(!(s->workaround_bugs & FF_BUG_MS)) + mpeg4_encode_gop_header(s); + } + + s->partitioned_frame= s->data_partitioning && s->pict_type!=FF_B_TYPE; + + put_bits(&s->pb, 16, 0); /* vop header */ + 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_incr= time_div - s->last_time_base; + assert(time_incr >= 0); + while(time_incr--) + put_bits(&s->pb, 1, 1); + + put_bits(&s->pb, 1, 0); + + put_bits(&s->pb, 1, 1); /* marker */ + put_bits(&s->pb, s->time_increment_bits, time_mod); /* time increment */ + put_bits(&s->pb, 1, 1); /* marker */ + put_bits(&s->pb, 1, 1); /* vop coded */ + if ( s->pict_type == FF_P_TYPE + || (s->pict_type == FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE)) { + put_bits(&s->pb, 1, s->no_rounding); /* rounding type */ + } + 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->alternate_scan); + } + //FIXME sprite stuff + + put_bits(&s->pb, 5, s->qscale); + + if (s->pict_type != FF_I_TYPE) + put_bits(&s->pb, 3, s->f_code); /* fcode_for */ + if (s->pict_type == FF_B_TYPE) + put_bits(&s->pb, 3, s->b_code); /* fcode_back */ +} + + +static void init_uni_dc_tab(void) +{ + int level, uni_code, uni_len; + + for(level=-256; level<256; level++){ + int size, v, l; + /* find number of bits */ + size = 0; + v = abs(level); + while (v) { + v >>= 1; + size++; + } + + if (level < 0) + l= (-level) ^ ((1 << size) - 1); + else + l= level; + + /* luminance */ + uni_code= ff_mpeg4_DCtab_lum[size][0]; + uni_len = ff_mpeg4_DCtab_lum[size][1]; + + if (size > 0) { + uni_code<<=size; uni_code|=l; + uni_len+=size; + if (size > 8){ + uni_code<<=1; uni_code|=1; + uni_len++; + } + } + uni_DCtab_lum_bits[level+256]= uni_code; + uni_DCtab_lum_len [level+256]= uni_len; + + /* chrominance */ + uni_code= ff_mpeg4_DCtab_chrom[size][0]; + uni_len = ff_mpeg4_DCtab_chrom[size][1]; + + if (size > 0) { + uni_code<<=size; uni_code|=l; + uni_len+=size; + if (size > 8){ + uni_code<<=1; uni_code|=1; + uni_len++; + } + } + uni_DCtab_chrom_bits[level+256]= uni_code; + uni_DCtab_chrom_len [level+256]= uni_len; + + } +} + +static void init_uni_mpeg4_rl_tab(RLTable *rl, uint32_t *bits_tab, uint8_t *len_tab){ + int slevel, run, last; + + assert(MAX_LEVEL >= 64); + assert(MAX_RUN >= 63); + + for(slevel=-64; slevel<64; slevel++){ + if(slevel==0) continue; + for(run=0; run<64; run++){ + for(last=0; last<=1; last++){ + const int index= UNI_MPEG4_ENC_INDEX(last, run, slevel+64); + int level= slevel < 0 ? -slevel : slevel; + int sign= slevel < 0 ? 1 : 0; + int bits, len, code; + int level1, run1; + + len_tab[index]= 100; + + /* ESC0 */ + code= get_rl_index(rl, last, run, level); + bits= rl->table_vlc[code][0]; + len= rl->table_vlc[code][1]; + bits=bits*2+sign; len++; + + if(code!=rl->n && len < len_tab[index]){ + bits_tab[index]= bits; + len_tab [index]= len; + } + /* ESC1 */ + bits= rl->table_vlc[rl->n][0]; + len= rl->table_vlc[rl->n][1]; + bits=bits*2; len++; //esc1 + level1= level - rl->max_level[last][run]; + if(level1>0){ + code= get_rl_index(rl, last, run, level1); + bits<<= rl->table_vlc[code][1]; + len += rl->table_vlc[code][1]; + bits += rl->table_vlc[code][0]; + bits=bits*2+sign; len++; + + if(code!=rl->n && len < len_tab[index]){ + bits_tab[index]= bits; + len_tab [index]= len; + } + } + /* ESC2 */ + bits= rl->table_vlc[rl->n][0]; + len= rl->table_vlc[rl->n][1]; + bits=bits*4+2; len+=2; //esc2 + run1 = run - rl->max_run[last][level] - 1; + if(run1>=0){ + code= get_rl_index(rl, last, run1, level); + bits<<= rl->table_vlc[code][1]; + len += rl->table_vlc[code][1]; + bits += rl->table_vlc[code][0]; + bits=bits*2+sign; len++; + + if(code!=rl->n && len < len_tab[index]){ + bits_tab[index]= bits; + len_tab [index]= len; + } + } + /* ESC3 */ + bits= rl->table_vlc[rl->n][0]; + len = rl->table_vlc[rl->n][1]; + bits=bits*4+3; len+=2; //esc3 + bits=bits*2+last; len++; + bits=bits*64+run; len+=6; + bits=bits*2+1; len++; //marker + bits=bits*4096+(slevel&0xfff); len+=12; + bits=bits*2+1; len++; //marker + + if(len < len_tab[index]){ + bits_tab[index]= bits; + len_tab [index]= len; + } + } + } + } +} + +static av_cold int encode_init(AVCodecContext *avctx) +{ + MpegEncContext *s = avctx->priv_data; + int ret; + static int done = 0; + + if((ret=MPV_encode_init(avctx)) < 0) + return ret; + + if (!done) { + done = 1; + + init_uni_dc_tab(); + + init_rl(&ff_mpeg4_rl_intra, ff_mpeg4_static_rl_table_store[0]); + + init_uni_mpeg4_rl_tab(&ff_mpeg4_rl_intra, uni_mpeg4_intra_rl_bits, uni_mpeg4_intra_rl_len); + init_uni_mpeg4_rl_tab(&ff_h263_rl_inter, uni_mpeg4_inter_rl_bits, uni_mpeg4_inter_rl_len); + } + + s->min_qcoeff= -2048; + s->max_qcoeff= 2047; + s->intra_ac_vlc_length = uni_mpeg4_intra_rl_len; + s->intra_ac_vlc_last_length= uni_mpeg4_intra_rl_len + 128*64; + s->inter_ac_vlc_length = uni_mpeg4_inter_rl_len; + s->inter_ac_vlc_last_length= uni_mpeg4_inter_rl_len + 128*64; + s->luma_dc_vlc_length= uni_DCtab_lum_len; + s->chroma_dc_vlc_length= uni_DCtab_chrom_len; + s->ac_esc_length= 7+2+1+6+1+12+1; + s->y_dc_scale_table= ff_mpeg4_y_dc_scale_table; + s->c_dc_scale_table= ff_mpeg4_c_dc_scale_table; + + if(s->flags & CODEC_FLAG_GLOBAL_HEADER){ + + s->avctx->extradata= av_malloc(1024); + init_put_bits(&s->pb, s->avctx->extradata, 1024); + + if(!(s->workaround_bugs & FF_BUG_MS)) + mpeg4_encode_visual_object_header(s); + mpeg4_encode_vol_header(s, 0, 0); + +// ff_mpeg4_stuffing(&s->pb); ? + flush_put_bits(&s->pb); + s->avctx->extradata_size= (put_bits_count(&s->pb)+7)>>3; + } + return 0; +} + +void ff_mpeg4_init_partitions(MpegEncContext *s) +{ + uint8_t *start= put_bits_ptr(&s->pb); + uint8_t *end= s->pb.buf_end; + int size= end - start; + int pb_size = (((intptr_t)start + size/3)&(~3)) - (intptr_t)start; + int tex_size= (size - 2*pb_size)&(~3); + + set_put_bits_buffer_size(&s->pb, pb_size); + init_put_bits(&s->tex_pb, start + pb_size , tex_size); + init_put_bits(&s->pb2 , start + pb_size + tex_size, pb_size); +} + +void ff_mpeg4_merge_partitions(MpegEncContext *s) +{ + const int pb2_len = put_bits_count(&s->pb2 ); + const int tex_pb_len= put_bits_count(&s->tex_pb); + const int bits= put_bits_count(&s->pb); + + if(s->pict_type==FF_I_TYPE){ + put_bits(&s->pb, 19, DC_MARKER); + s->misc_bits+=19 + pb2_len + bits - s->last_bits; + s->i_tex_bits+= tex_pb_len; + }else{ + put_bits(&s->pb, 17, MOTION_MARKER); + s->misc_bits+=17 + pb2_len; + s->mv_bits+= bits - s->last_bits; + s->p_tex_bits+= tex_pb_len; + } + + flush_put_bits(&s->pb2); + 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); + s->last_bits= put_bits_count(&s->pb); +} + + +void ff_mpeg4_encode_video_packet_header(MpegEncContext *s) +{ + int mb_num_bits= av_log2(s->mb_num - 1) + 1; + + put_bits(&s->pb, ff_mpeg4_get_video_packet_prefix_length(s), 0); + put_bits(&s->pb, 1, 1); + + put_bits(&s->pb, mb_num_bits, s->mb_x + s->mb_y*s->mb_width); + put_bits(&s->pb, s->quant_precision, s->qscale); + put_bits(&s->pb, 1, 0); /* no HEC */ +} + +AVCodec mpeg4_encoder = { + "mpeg4", + AVMEDIA_TYPE_VIDEO, + CODEC_ID_MPEG4, + sizeof(MpegEncContext), + encode_init, + MPV_encode_picture, + MPV_encode_end, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, + .capabilities= CODEC_CAP_DELAY, + .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2"), +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudio.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudio.c index 45cb0e4157..cba52992ef 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudio.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudio.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/mpegaudio.c + * @file * MPEG Audio common code. */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudio.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudio.h index 65a2283fba..26ec2bebc1 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudio.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudio.h @@ -19,7 +19,7 @@ */ /** - * @file libavcodec/mpegaudio.h + * @file * mpeg audio declarations for both encoder and decoder. */ @@ -88,7 +88,25 @@ typedef int32_t MPA_INT; #define BACKSTEP_SIZE 512 #define EXTRABYTES 24 -struct GranuleDef; +/* layer 3 "granule" */ +typedef struct GranuleDef { + uint8_t scfsi; + int part2_3_length; + int big_values; + int global_gain; + int scalefac_compress; + uint8_t block_type; + uint8_t switch_point; + int table_select[3]; + int subblock_gain[3]; + uint8_t scalefac_scale; + uint8_t count1table_select; + int region_size[3]; /* number of huffman codes in each region */ + int preflag; + int short_start, long_end; /* long/short band indexes */ + uint8_t scale_factors[40]; + int32_t sb_hybrid[SBLIMIT * 18]; /* 576 samples */ +} GranuleDef; #define MPA_DECODE_HEADER \ int frame_size; \ @@ -108,16 +126,17 @@ typedef struct MPADecodeHeader { typedef struct MPADecodeContext { MPA_DECODE_HEADER - DECLARE_ALIGNED_8(uint8_t, last_buf[2*BACKSTEP_SIZE + EXTRABYTES]); + uint8_t last_buf[2*BACKSTEP_SIZE + EXTRABYTES]; int last_buf_size; /* next header (used in free format parsing) */ uint32_t free_format_next_header; GetBitContext gb; GetBitContext in_gb; - DECLARE_ALIGNED_16(MPA_INT, synth_buf[MPA_MAX_CHANNELS][512 * 2]); + DECLARE_ALIGNED(16, MPA_INT, synth_buf)[MPA_MAX_CHANNELS][512 * 2]; int synth_buf_offset[MPA_MAX_CHANNELS]; - DECLARE_ALIGNED_16(int32_t, sb_samples[MPA_MAX_CHANNELS][36][SBLIMIT]); + DECLARE_ALIGNED(16, int32_t, sb_samples)[MPA_MAX_CHANNELS][36][SBLIMIT]; int32_t mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18]; /* previous samples, for layer 3 MDCT */ + GranuleDef granules[2][2]; /* Used in Layer 3 */ #ifdef DEBUG int frame_count; #endif @@ -137,6 +156,7 @@ typedef struct HuffTable { int ff_mpa_l2_select_table(int bitrate, int nb_channels, int freq, int lsf); int ff_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bitrate); +extern MPA_INT ff_mpa_synth_window[]; void ff_mpa_synth_init(MPA_INT *window); void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset, MPA_INT *window, int *dither_state, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudio3.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudio3.h new file mode 100644 index 0000000000..c374a59a76 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudio3.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2007 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 + */ + +/* layer 3 "granule" */ +typedef struct GranuleDef { + uint8_t scfsi; + int part2_3_length; + int big_values; + int global_gain; + int scalefac_compress; + uint8_t block_type; + uint8_t switch_point; + int table_select[3]; + int subblock_gain[3]; + uint8_t scalefac_scale; + uint8_t count1table_select; + int region_size[3]; /* number of huffman codes in each region */ + int preflag; + int short_start, long_end; /* long/short band indexes */ + uint8_t scale_factors[40]; + int32_t sb_hybrid[SBLIMIT * 18]; /* 576 samples */ +} GranuleDef; + +void ff_mp3_init(void); + +/** + * Compute huffman coded region sizes. + */ +void ff_init_short_region(MPADecodeContext *s, GranuleDef *g); + +/** + * Compute huffman coded region sizes. + */ +void ff_init_long_region(MPADecodeContext *s, GranuleDef *g, int ra1, int ra2); + +void ff_compute_band_indexes(MPADecodeContext *s, GranuleDef *g); diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudio_tablegen.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudio_tablegen.c new file mode 100644 index 0000000000..70d145b205 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudio_tablegen.c @@ -0,0 +1,51 @@ +/* + * Generate a header file for hardcoded mpegaudiodec tables + * + * Copyright (c) 2009 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 +#define CONFIG_HARDCODED_TABLES 0 +#include "mpegaudio_tablegen.h" +#include "tableprint.h" + +int main(void) +{ + mpegaudio_tableinit(); + + write_fileheader(); + + printf("static const int8_t table_4_3_exp[TABLE_4_3_SIZE] = {\n"); + write_int8_array(table_4_3_exp, TABLE_4_3_SIZE); + printf("};\n"); + + printf("static const uint32_t table_4_3_value[TABLE_4_3_SIZE] = {\n"); + write_uint32_array(table_4_3_value, TABLE_4_3_SIZE); + printf("};\n"); + + printf("static const uint32_t exp_table[512] = {\n"); + write_uint32_array(exp_table, 512); + printf("};\n"); + + printf("static const uint32_t expval_table[512][16] = {\n"); + write_uint32_2d_array(expval_table, 512, 16); + printf("};\n"); + + return 0; +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudio_tablegen.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudio_tablegen.h new file mode 100644 index 0000000000..9d056cb253 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudio_tablegen.h @@ -0,0 +1,67 @@ +/* + * Header file for hardcoded mpegaudiodec tables + * + * Copyright (c) 2009 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 + */ + +#ifndef MPEGAUDIO_TABLEGEN_H +#define MPEGAUDIO_TABLEGEN_H + +#include +// do not use libavutil/mathematics.h since this is compiled both +// for the host and the target and config.h is only valid for the target +#include + +#define TABLE_4_3_SIZE (8191 + 16)*4 +#if CONFIG_HARDCODED_TABLES +#define mpegaudio_tableinit() +#include "libavcodec/mpegaudio_tables.h" +#else +static int8_t table_4_3_exp[TABLE_4_3_SIZE]; +static uint32_t table_4_3_value[TABLE_4_3_SIZE]; +static uint32_t exp_table[512]; +static uint32_t expval_table[512][16]; + +static void mpegaudio_tableinit(void) +{ + int i, value, exponent; + for (i = 1; i < TABLE_4_3_SIZE; i++) { + double value = i / 4; + double f, fm; + int e, m; + f = value * cbrtf(value) * pow(2, (i & 3) * 0.25); + fm = frexp(f, &e); + m = (uint32_t)(fm * (1LL << 31) + 0.5); + e += FRAC_BITS - 31 + 5 - 100; + + /* normalized to FRAC_BITS */ + table_4_3_value[i] = m; + table_4_3_exp[i] = -e; + } + for (exponent = 0; exponent < 512; exponent++) { + for (value = 0; value < 16; value++) { + double f = (double)value * cbrtf(value) * pow(2, (exponent - 400) * 0.25 + FRAC_BITS + 5); + expval_table[exponent][value] = llrint(f); + } + exp_table[exponent] = expval_table[exponent][1]; + } +} +#endif /* CONFIG_HARDCODED_TABLES */ + +#endif /* MPEGAUDIO_TABLEGEN_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudiodata.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudiodata.c index 7e811a91d2..c9dabf3185 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudiodata.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudiodata.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/mpegaudiodata.c + * @file * mpeg audio layer common tables. */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudiodata.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudiodata.h index e45a9d00ec..5626e3df50 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudiodata.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudiodata.h @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/mpegaudiodata.h + * @file * mpeg audio layer common tables. */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudiodec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudiodec.c index 221941abcc..25fad80284 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudiodec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudiodec.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/mpegaudiodec.c + * @file * MPEG Audio decoder. */ @@ -49,26 +49,6 @@ #define HEADER_SIZE 4 -/* layer 3 "granule" */ -typedef struct GranuleDef { - uint8_t scfsi; - int part2_3_length; - int big_values; - int global_gain; - int scalefac_compress; - uint8_t block_type; - uint8_t switch_point; - int table_select[3]; - int subblock_gain[3]; - uint8_t scalefac_scale; - uint8_t count1table_select; - int region_size[3]; /* number of huffman codes in each region */ - int preflag; - int short_start, long_end; /* long/short band indexes */ - uint8_t scale_factors[40]; - int32_t sb_hybrid[SBLIMIT * 18]; /* 576 samples */ -} GranuleDef; - #include "mpegaudiodata.h" #include "mpegaudiodectab.h" @@ -92,12 +72,7 @@ static const int huff_quad_vlc_tables_sizes[2] = { }; /* computed from band_size_long */ static uint16_t band_index_long[9][23]; -/* XXX: free when all decoders are closed */ -#define TABLE_4_3_SIZE (8191 + 16)*4 -static int8_t table_4_3_exp[TABLE_4_3_SIZE]; -static uint32_t table_4_3_value[TABLE_4_3_SIZE]; -static uint32_t exp_table[512]; -static uint32_t expval_table[512][16]; +#include "mpegaudio_tablegen.h" /* intensity stereo coef table */ static int32_t is_table[2][16]; static int32_t is_table_lsf[2][2][16]; @@ -120,13 +95,13 @@ static const int32_t scale_factor_mult2[3][3] = { SCALE_GEN(4.0 / 9.0), /* 9 steps */ }; -static DECLARE_ALIGNED_16(MPA_INT, window[512]); +DECLARE_ALIGNED(16, MPA_INT, ff_mpa_synth_window)[512]; /** * Convert region offsets to region sizes and truncate * size to big_values. */ -void ff_region_offset2size(GranuleDef *g){ +static void ff_region_offset2size(GranuleDef *g){ int i, k, j=0; g->region_size[2] = (576 / 2); for(i=0;i<3;i++) { @@ -136,7 +111,7 @@ void ff_region_offset2size(GranuleDef *g){ } } -void ff_init_short_region(MPADecodeContext *s, GranuleDef *g){ +static void ff_init_short_region(MPADecodeContext *s, GranuleDef *g){ if (g->block_type == 2) g->region_size[0] = (36 / 2); else { @@ -150,7 +125,7 @@ void ff_init_short_region(MPADecodeContext *s, GranuleDef *g){ g->region_size[1] = (576 / 2); } -void ff_init_long_region(MPADecodeContext *s, GranuleDef *g, int ra1, int ra2){ +static void ff_init_long_region(MPADecodeContext *s, GranuleDef *g, int ra1, int ra2){ int l; g->region_size[0] = band_index_long[s->sample_rate_index][ra1 + 1] >> 1; @@ -160,7 +135,7 @@ void ff_init_long_region(MPADecodeContext *s, GranuleDef *g, int ra1, int ra2){ band_index_long[s->sample_rate_index][l] >> 1; } -void ff_compute_band_indexes(MPADecodeContext *s, GranuleDef *g){ +static void ff_compute_band_indexes(MPADecodeContext *s, GranuleDef *g){ if (g->block_type == 2) { if (g->switch_point) { /* if switched mode, we handle the 36 first samples as @@ -351,7 +326,7 @@ static av_cold int decode_init(AVCodecContext * avctx) scale_factor_mult[i][2]); } - ff_mpa_synth_init(window); + ff_mpa_synth_init(ff_mpa_synth_window); /* huffman decode tables */ offset = 0; @@ -407,25 +382,7 @@ static av_cold int decode_init(AVCodecContext * avctx) /* compute n ^ (4/3) and store it in mantissa/exp format */ int_pow_init(); - for(i=1;i>4); - double f= pow(i&15, 4.0 / 3.0) * pow(2, (exponent-400)*0.25 + FRAC_BITS + 5); - expval_table[exponent][i&15]= llrint(f); - if((i&15)==1) - exp_table[exponent]= llrint(f); - } + mpegaudio_tableinit(); for(i=0;i<7;i++) { float f; @@ -1358,23 +1315,32 @@ static int mp_decode_layer2(MPADecodeContext *s) return 3 * 12; } -static inline void lsf_sf_expand(int *slen, +#define SPLIT(dst,sf,n)\ + if(n==3){\ + int m= (sf*171)>>9;\ + dst= sf - 3*m;\ + sf=m;\ + }else if(n==4){\ + dst= sf&3;\ + sf>>=2;\ + }else if(n==5){\ + int m= (sf*205)>>10;\ + dst= sf - 5*m;\ + sf=m;\ + }else if(n==6){\ + int m= (sf*171)>>10;\ + dst= sf - 6*m;\ + sf=m;\ + }else{\ + dst=0;\ + } + +static av_always_inline void lsf_sf_expand(int *slen, int sf, int n1, int n2, int n3) { - if (n3) { - slen[3] = sf % n3; - sf /= n3; - } else { - slen[3] = 0; - } - if (n2) { - slen[2] = sf % n2; - sf /= n2; - } else { - slen[2] = 0; - } - slen[1] = sf % n1; - sf /= n1; + SPLIT(slen[3], sf, n3) + SPLIT(slen[2], sf, n2) + SPLIT(slen[1], sf, n1) slen[0] = sf; } @@ -1935,7 +1901,7 @@ static int mp_decode_layer3(MPADecodeContext *s) { int nb_granules, main_data_begin, private_bits; int gr, ch, blocksplit_flag, i, j, k, n, bits_pos; - GranuleDef granules[2][2], *g; + GranuleDef *g; int16_t exponents[576]; /* read side info */ @@ -1951,15 +1917,15 @@ static int mp_decode_layer3(MPADecodeContext *s) private_bits = get_bits(&s->gb, 5); nb_granules = 2; for(ch=0;chnb_channels;ch++) { - granules[ch][0].scfsi = 0; /* all scale factors are transmitted */ - granules[ch][1].scfsi = get_bits(&s->gb, 4); + s->granules[ch][0].scfsi = 0;/* all scale factors are transmitted */ + s->granules[ch][1].scfsi = get_bits(&s->gb, 4); } } for(gr=0;grnb_channels;ch++) { dprintf(s->avctx, "gr=%d ch=%d: side_info\n", gr, ch); - g = &granules[ch][gr]; + g = &s->granules[ch][gr]; g->part2_3_length = get_bits(&s->gb, 12); g->big_values = get_bits(&s->gb, 9); if(g->big_values > 288){ @@ -2031,9 +1997,9 @@ static int mp_decode_layer3(MPADecodeContext *s) for(gr=0;grnb_channels;ch++) { - g = &granules[ch][gr]; + g = &s->granules[ch][gr]; if(get_bits_count(&s->gb)<0){ - av_log(s->avctx, AV_LOG_ERROR, "mdb:%d, lastbuf:%d skipping granule %d\n", + av_log(s->avctx, AV_LOG_DEBUG, "mdb:%d, lastbuf:%d skipping granule %d\n", main_data_begin, s->last_buf_size, gr); skip_bits_long(&s->gb, g->part2_3_length); memset(g->sb_hybrid, 0, sizeof(g->sb_hybrid)); @@ -2075,7 +2041,7 @@ static int mp_decode_layer3(MPADecodeContext *s) g->scale_factors[j++] = 0; } } else { - sc = granules[ch][0].scale_factors; + sc = s->granules[ch][0].scale_factors; j = 0; for(k=0;k<4;k++) { n = (k == 0 ? 6 : 5); @@ -2160,10 +2126,10 @@ static int mp_decode_layer3(MPADecodeContext *s) } /* ch */ if (s->nb_channels == 2) - compute_stereo(s, &granules[0][gr], &granules[1][gr]); + compute_stereo(s, &s->granules[0][gr], &s->granules[1][gr]); for(ch=0;chnb_channels;ch++) { - g = &granules[ch][gr]; + g = &s->granules[ch][gr]; reorder_block(s, g); s->compute_antialias(s, g); @@ -2205,7 +2171,7 @@ static int mp_decode_frame(MPADecodeContext *s, s->last_buf_size=0; if(s->in_gb.buffer){ align_get_bits(&s->gb); - i= (s->gb.size_in_bits - get_bits_count(&s->gb))>>3; + i= get_bits_left(&s->gb)>>3; if(i >= 0 && i <= BACKSTEP_SIZE){ memmove(s->last_buf, s->gb.buffer + (get_bits_count(&s->gb)>>3), i); s->last_buf_size=i; @@ -2217,7 +2183,7 @@ static int mp_decode_frame(MPADecodeContext *s, align_get_bits(&s->gb); assert((get_bits_count(&s->gb) & 7) == 0); - i= (s->gb.size_in_bits - get_bits_count(&s->gb))>>3; + i= get_bits_left(&s->gb)>>3; if(i<0 || i > BACKSTEP_SIZE || nb_frames<0){ if(i<0) @@ -2236,7 +2202,7 @@ static int mp_decode_frame(MPADecodeContext *s, samples_ptr = samples + ch; for(i=0;isynth_buf[ch], &(s->synth_buf_offset[ch]), - window, &s->dither_state, + ff_mpa_synth_window, &s->dither_state, samples_ptr, s->nb_channels, s->sb_samples[ch][i]); samples_ptr += 32 * s->nb_channels; @@ -2276,6 +2242,10 @@ static int decode_frame(AVCodecContext * avctx, avctx->bit_rate = s->bit_rate; avctx->sub_id = s->layer; + if(*data_size < 1152*avctx->channels*sizeof(OUT_INT)) + return -1; + *data_size = 0; + if(s->frame_size<=0 || s->frame_size > buf_size){ av_log(avctx, AV_LOG_ERROR, "incomplete frame\n"); return -1; @@ -2463,6 +2433,9 @@ static int decode_frame_mp3on4(AVCodecContext * avctx, OUT_INT *outptr, *bp; int fr, j, n; + if(*data_size < MPA_FRAME_SIZE * MPA_MAX_CHANNELS * s->frames * sizeof(OUT_INT)) + return -1; + *data_size = 0; // Discard too short frames if (buf_size < HEADER_SIZE) @@ -2521,7 +2494,7 @@ static int decode_frame_mp3on4(AVCodecContext * avctx, AVCodec mp1_decoder = { "mp1", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_MP1, sizeof(MPADecodeContext), decode_init, @@ -2537,7 +2510,7 @@ AVCodec mp1_decoder = AVCodec mp2_decoder = { "mp2", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_MP2, sizeof(MPADecodeContext), decode_init, @@ -2553,7 +2526,7 @@ AVCodec mp2_decoder = AVCodec mp3_decoder = { "mp3", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_MP3, sizeof(MPADecodeContext), decode_init, @@ -2569,7 +2542,7 @@ AVCodec mp3_decoder = AVCodec mp3adu_decoder = { "mp3adu", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_MP3ADU, sizeof(MPADecodeContext), decode_init, @@ -2585,7 +2558,7 @@ AVCodec mp3adu_decoder = AVCodec mp3on4_decoder = { "mp3on4", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_MP3ON4, sizeof(MP3On4DecodeContext), decode_init_mp3on4, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudiodecheader.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudiodecheader.c index df1785e060..67f882f566 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudiodecheader.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudiodecheader.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/mpegaudiodecheader.c + * @file * MPEG Audio header decoder. */ @@ -28,6 +28,7 @@ #include "avcodec.h" #include "mpegaudio.h" #include "mpegaudiodata.h" +#include "mpegaudiodecheader.h" int ff_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header) diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudiodecheader.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudiodecheader.h index 2db8a9cb8f..5578618288 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudiodecheader.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudiodecheader.h @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/mpegaudiodecheader.c + * @file * MPEG Audio header decoder. */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudiodectab.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudiodectab.h index f96a90f7cc..234a70e474 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudiodectab.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudiodectab.h @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/mpegaudiodectab.h + * @file * mpeg audio layer decoder tables. */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudioenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudioenc.c index f48d4c8ba6..264175ecc5 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudioenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudioenc.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/mpegaudio.c + * @file * The simplest mpeg audio layer 2 encoder. */ @@ -59,7 +59,7 @@ typedef struct MpegAudioContext { } MpegAudioContext; /* define it to use floats in quantization (I don't like floats !) */ -//#define USE_FLOATS +#define USE_FLOATS #include "mpegaudiodata.h" #include "mpegaudiotab.h" @@ -790,14 +790,15 @@ static av_cold int MPA_encode_close(AVCodecContext *avctx) AVCodec mp2_encoder = { "mp2", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_MP2, sizeof(MpegAudioContext), MPA_encode_init, MPA_encode_frame, MPA_encode_close, NULL, - .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, + .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,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)"), }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudiotab.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudiotab.h index bebee76d4e..35129e646c 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudiotab.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegaudiotab.h @@ -22,7 +22,7 @@ */ /** - * @file libavcodec/mpegaudiotab.h + * @file * mpeg audio layer 2 tables. * Most of them come from the mpeg audio specification. */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegvideo.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegvideo.c index 35cde71f6f..e11fee8ffc 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegvideo.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegvideo.c @@ -23,10 +23,11 @@ */ /** - * @file libavcodec/mpegvideo.c + * @file * The simplest mpeg encoder (well, it was the simplest!). */ +#include "libavutil/intmath.h" #include "avcodec.h" #include "dsputil.h" #include "mpegvideo.h" @@ -75,12 +76,44 @@ const uint8_t ff_mpeg1_dc_scale_table[128]={ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, }; +static const uint8_t mpeg2_dc_scale_table1[128]={ +// 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 + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, +}; + +static const uint8_t mpeg2_dc_scale_table2[128]={ +// 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 + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, +}; + +static const uint8_t mpeg2_dc_scale_table3[128]={ +// 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 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 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 uint8_t * const ff_mpeg2_dc_scale_table[4]={ + ff_mpeg1_dc_scale_table, + mpeg2_dc_scale_table1, + mpeg2_dc_scale_table2, + mpeg2_dc_scale_table3, +}; + const enum PixelFormat ff_pixfmt_list_420[] = { PIX_FMT_YUV420P, PIX_FMT_NONE }; const enum PixelFormat ff_hwaccel_pixfmt_list_420[] = { + PIX_FMT_DXVA2_VLD, PIX_FMT_VAAPI_VLD, PIX_FMT_YUV420P, PIX_FMT_NONE @@ -243,35 +276,35 @@ int ff_alloc_picture(MpegEncContext *s, Picture *pic, int shared){ if(pic->qscale_table==NULL){ if (s->encoding) { - CHECKED_ALLOCZ(pic->mb_var , mb_array_size * sizeof(int16_t)) - CHECKED_ALLOCZ(pic->mc_mb_var, mb_array_size * sizeof(int16_t)) - CHECKED_ALLOCZ(pic->mb_mean , mb_array_size * sizeof(int8_t)) + 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) } - CHECKED_ALLOCZ(pic->mbskip_table , mb_array_size * sizeof(uint8_t)+2) //the +2 is for the slice end check - CHECKED_ALLOCZ(pic->qscale_table , mb_array_size * sizeof(uint8_t)) - CHECKED_ALLOCZ(pic->mb_type_base , (big_mb_num + s->mb_stride) * sizeof(uint32_t)) + 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->qscale_table , mb_array_size * 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; if(s->out_format == FMT_H264){ for(i=0; i<2; i++){ - CHECKED_ALLOCZ(pic->motion_val_base[i], 2 * (b4_array_size+4) * sizeof(int16_t)) + 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; - CHECKED_ALLOCZ(pic->ref_index[i], b8_array_size * sizeof(uint8_t)) + FF_ALLOCZ_OR_GOTO(s->avctx, pic->ref_index[i], 4*mb_array_size * sizeof(uint8_t), fail) } pic->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++){ - CHECKED_ALLOCZ(pic->motion_val_base[i], 2 * (b8_array_size+4) * sizeof(int16_t)) + 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; - CHECKED_ALLOCZ(pic->ref_index[i], b8_array_size * sizeof(uint8_t)) + FF_ALLOCZ_OR_GOTO(s->avctx, pic->ref_index[i], 4*mb_array_size * sizeof(uint8_t), fail) } pic->motion_subsample_log2= 3; } if(s->avctx->debug&FF_DEBUG_DCT_COEFF) { - CHECKED_ALLOCZ(pic->dct_coeff, 64 * mb_array_size * sizeof(DCTELEM)*6) + FF_ALLOCZ_OR_GOTO(s->avctx, pic->dct_coeff, 64 * mb_array_size * sizeof(DCTELEM)*6, fail) } pic->qstride= s->mb_stride; - CHECKED_ALLOCZ(pic->pan_scan , 1 * sizeof(AVPanScan)) + FF_ALLOCZ_OR_GOTO(s->avctx, pic->pan_scan , 1 * sizeof(AVPanScan), fail) } /* It might be nicer if the application would keep track of these @@ -282,7 +315,7 @@ int ff_alloc_picture(MpegEncContext *s, Picture *pic, int shared){ 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. return 0; -fail: //for the CHECKED_ALLOCZ macro +fail: //for the FF_ALLOCZ_OR_GOTO macro if(r>=0) free_frame_buffer(s, pic); return -1; @@ -325,23 +358,23 @@ static int init_duplicate_context(MpegEncContext *s, MpegEncContext *base){ int i; // edge emu needs blocksize + filter length - 1 (=17x17 for halfpel / 21x21 for h264) - CHECKED_ALLOCZ(s->allocated_edge_emu_buffer, (s->width+64)*2*21*2); //(width + edge + align)*interlaced*MBsize*tolerance + 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; //FIXME should be linesize instead of s->width*2 but that is not known before get_buffer() - CHECKED_ALLOCZ(s->me.scratchpad, (s->width+64)*4*16*2*sizeof(uint8_t)) + FF_ALLOCZ_OR_GOTO(s->avctx, s->me.scratchpad, (s->width+64)*4*16*2*sizeof(uint8_t), fail) s->me.temp= s->me.scratchpad; s->rd_scratchpad= s->me.scratchpad; s->b_scratchpad= s->me.scratchpad; s->obmc_scratchpad= s->me.scratchpad + 16; if (s->encoding) { - CHECKED_ALLOCZ(s->me.map , ME_MAP_SIZE*sizeof(uint32_t)) - CHECKED_ALLOCZ(s->me.score_map, ME_MAP_SIZE*sizeof(uint32_t)) + FF_ALLOCZ_OR_GOTO(s->avctx, s->me.map , ME_MAP_SIZE*sizeof(uint32_t), fail) + FF_ALLOCZ_OR_GOTO(s->avctx, s->me.score_map, ME_MAP_SIZE*sizeof(uint32_t), fail) if(s->avctx->noise_reduction){ - CHECKED_ALLOCZ(s->dct_error_sum, 2 * 64 * sizeof(int)) + FF_ALLOCZ_OR_GOTO(s->avctx, s->dct_error_sum, 2 * 64 * sizeof(int), fail) } } - CHECKED_ALLOCZ(s->blocks, 64*12*2 * sizeof(DCTELEM)) + FF_ALLOCZ_OR_GOTO(s->avctx, s->blocks, 64*12*2 * sizeof(DCTELEM), fail) s->block= s->blocks[0]; for(i=0;i<12;i++){ @@ -509,7 +542,7 @@ av_cold int MPV_common_init(MpegEncContext *s) s->avctx->coded_frame= (AVFrame*)&s->current_picture; - CHECKED_ALLOCZ(s->mb_index2xy, (s->mb_num+1)*sizeof(int)) //error ressilience code looks cleaner with this + 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; ymb_height; y++){ for(x=0; xmb_width; x++){ s->mb_index2xy[ x + y*s->mb_width ] = x + y*s->mb_stride; @@ -519,12 +552,12 @@ av_cold int MPV_common_init(MpegEncContext *s) if (s->encoding) { /* Allocate MV tables */ - CHECKED_ALLOCZ(s->p_mv_table_base , mv_table_size * 2 * sizeof(int16_t)) - CHECKED_ALLOCZ(s->b_forw_mv_table_base , mv_table_size * 2 * sizeof(int16_t)) - CHECKED_ALLOCZ(s->b_back_mv_table_base , mv_table_size * 2 * sizeof(int16_t)) - CHECKED_ALLOCZ(s->b_bidir_forw_mv_table_base , mv_table_size * 2 * sizeof(int16_t)) - CHECKED_ALLOCZ(s->b_bidir_back_mv_table_base , mv_table_size * 2 * sizeof(int16_t)) - CHECKED_ALLOCZ(s->b_direct_mv_table_base , mv_table_size * 2 * sizeof(int16_t)) + 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; @@ -533,32 +566,32 @@ av_cold int MPV_common_init(MpegEncContext *s) s->b_direct_mv_table = s->b_direct_mv_table_base + s->mb_stride + 1; if(s->msmpeg4_version){ - CHECKED_ALLOCZ(s->ac_stats, 2*2*(MAX_LEVEL+1)*(MAX_RUN+1)*2*sizeof(int)); + FF_ALLOCZ_OR_GOTO(s->avctx, s->ac_stats, 2*2*(MAX_LEVEL+1)*(MAX_RUN+1)*2*sizeof(int), fail); } - CHECKED_ALLOCZ(s->avctx->stats_out, 256); + FF_ALLOCZ_OR_GOTO(s->avctx, s->avctx->stats_out, 256, fail); /* Allocate MB type table */ - CHECKED_ALLOCZ(s->mb_type , mb_array_size * sizeof(uint16_t)) //needed for encoding + FF_ALLOCZ_OR_GOTO(s->avctx, s->mb_type , mb_array_size * sizeof(uint16_t), fail) //needed for encoding - CHECKED_ALLOCZ(s->lambda_table, mb_array_size * sizeof(int)) + FF_ALLOCZ_OR_GOTO(s->avctx, s->lambda_table, mb_array_size * sizeof(int), fail) - CHECKED_ALLOCZ(s->q_intra_matrix, 64*32 * sizeof(int)) - CHECKED_ALLOCZ(s->q_inter_matrix, 64*32 * sizeof(int)) - CHECKED_ALLOCZ(s->q_intra_matrix16, 64*32*2 * sizeof(uint16_t)) - CHECKED_ALLOCZ(s->q_inter_matrix16, 64*32*2 * sizeof(uint16_t)) - CHECKED_ALLOCZ(s->input_picture, MAX_PICTURE_COUNT * sizeof(Picture*)) - CHECKED_ALLOCZ(s->reordered_input_picture, MAX_PICTURE_COUNT * sizeof(Picture*)) + 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->avctx->noise_reduction){ - CHECKED_ALLOCZ(s->dct_offset, 2 * 64 * sizeof(uint16_t)) + FF_ALLOCZ_OR_GOTO(s->avctx, s->dct_offset, 2 * 64 * sizeof(uint16_t), fail) } } - CHECKED_ALLOCZ(s->picture, MAX_PICTURE_COUNT * sizeof(Picture)) + FF_ALLOCZ_OR_GOTO(s->avctx, s->picture, MAX_PICTURE_COUNT * sizeof(Picture), fail) for(i = 0; i < MAX_PICTURE_COUNT; i++) { avcodec_get_frame_defaults((AVFrame *)&s->picture[i]); } - CHECKED_ALLOCZ(s->error_status_table, mb_array_size*sizeof(uint8_t)) + 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 */ @@ -566,36 +599,36 @@ av_cold int MPV_common_init(MpegEncContext *s) int j, k; for(j=0; j<2; j++){ for(k=0; k<2; k++){ - CHECKED_ALLOCZ(s->b_field_mv_table_base[i][j][k] , mv_table_size * 2 * sizeof(int16_t)) - s->b_field_mv_table[i][j][k] = s->b_field_mv_table_base[i][j][k] + s->mb_stride + 1; + FF_ALLOCZ_OR_GOTO(s->avctx, s->b_field_mv_table_base[i][j][k], mv_table_size * 2 * sizeof(int16_t), fail) + s->b_field_mv_table[i][j][k] = s->b_field_mv_table_base[i][j][k] + s->mb_stride + 1; } - CHECKED_ALLOCZ(s->b_field_select_table[i][j] , mb_array_size * 2 * sizeof(uint8_t)) - CHECKED_ALLOCZ(s->p_field_mv_table_base[i][j] , mv_table_size * 2 * sizeof(int16_t)) - s->p_field_mv_table[i][j] = s->p_field_mv_table_base[i][j] + s->mb_stride + 1; + FF_ALLOCZ_OR_GOTO(s->avctx, s->b_field_select_table [i][j], mb_array_size * 2 * sizeof(uint8_t), fail) + FF_ALLOCZ_OR_GOTO(s->avctx, s->p_field_mv_table_base[i][j], mv_table_size * 2 * sizeof(int16_t), fail) + s->p_field_mv_table[i][j] = s->p_field_mv_table_base[i][j]+ s->mb_stride + 1; } - CHECKED_ALLOCZ(s->p_field_select_table[i] , mb_array_size * 2 * sizeof(uint8_t)) + 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) { /* ac values */ - CHECKED_ALLOCZ(s->ac_val_base, yc_size * sizeof(int16_t) * 16); + FF_ALLOCZ_OR_GOTO(s->avctx, s->ac_val_base, yc_size * sizeof(int16_t) * 16, fail); s->ac_val[0] = s->ac_val_base + s->b8_stride + 1; s->ac_val[1] = s->ac_val_base + y_size + s->mb_stride + 1; s->ac_val[2] = s->ac_val[1] + c_size; /* cbp values */ - CHECKED_ALLOCZ(s->coded_block_base, y_size); + 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 */ - CHECKED_ALLOCZ(s->cbp_table , mb_array_size * sizeof(uint8_t)) - CHECKED_ALLOCZ(s->pred_dir_table, mb_array_size * sizeof(uint8_t)) + 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->h263_pred || s->h263_plus || !s->encoding) { /* dc values */ //MN: we need these for error resilience of intra-frames - CHECKED_ALLOCZ(s->dc_val_base, yc_size * sizeof(int16_t)); + 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; @@ -604,13 +637,13 @@ av_cold int MPV_common_init(MpegEncContext *s) } /* which mb is a intra block */ - CHECKED_ALLOCZ(s->mbintra_table, mb_array_size); + FF_ALLOCZ_OR_GOTO(s->avctx, s->mbintra_table, mb_array_size, fail); memset(s->mbintra_table, 1, mb_array_size); /* init macroblock skip table */ - CHECKED_ALLOCZ(s->mbskip_table, mb_array_size+2); + 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 - CHECKED_ALLOCZ(s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE); + 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)){ @@ -894,7 +927,7 @@ int MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx) } } } -alloc: + if(!s->encoding){ /* release non reference frames */ for(i=0; icurrent_picture_ptr ? s->current_picture_ptr->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) && s->pict_type!=FF_I_TYPE){ + av_log(avctx, AV_LOG_ERROR, "warning: first frame is no keyframe\n"); + /* Allocate a dummy frame */ + i= ff_find_unused_picture(s, 0); + s->last_picture_ptr= &s->picture[i]; + if(ff_alloc_picture(s, s->last_picture_ptr, 0) < 0) + return -1; + } + if((s->next_picture_ptr==NULL || s->next_picture_ptr->data[0]==NULL) && s->pict_type==FF_B_TYPE){ + /* Allocate a dummy frame */ + i= ff_find_unused_picture(s, 0); + s->next_picture_ptr= &s->picture[i]; + if(ff_alloc_picture(s, s->next_picture_ptr, 0) < 0) + return -1; + } + } + 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); - if(s->pict_type != FF_I_TYPE && (s->last_picture_ptr==NULL || s->last_picture_ptr->data[0]==NULL) && !s->dropable && s->codec_id != CODEC_ID_H264){ - av_log(avctx, AV_LOG_ERROR, "warning: first frame is no keyframe\n"); - assert(s->pict_type != FF_B_TYPE); //these should have been dropped if we don't have a reference - goto alloc; - } - assert(s->pict_type == FF_I_TYPE || (s->last_picture_ptr && s->last_picture_ptr->data[0])); if(s->picture_structure!=PICT_FRAME && s->out_format != FMT_H264){ @@ -1404,6 +1449,7 @@ static inline int hpel_motion_lowres(MpegEncContext *s, int motion_x, int motion_y) { const int lowres= s->avctx->lowres; + const int op_index= FFMIN(lowres, 2); const int s_mask= (2<> lowres; + sy= (sy << 2) >> lowres; if(field_select) src += s->linesize; - pix_op[lowres](dest, src, stride, h, sx, sy); + pix_op[op_index](dest, src, stride, h, sx, sy); return emu; } @@ -1441,11 +1487,12 @@ static av_always_inline void mpeg_motion_lowres(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, int field_based, int bottom_field, int field_select, uint8_t **ref_picture, h264_chroma_mc_func *pix_op, - int motion_x, int motion_y, int h) + int motion_x, int motion_y, int h, int mb_y) { 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 block_s= 8>>lowres; const int s_mask= (2<h_edge_pos >> lowres; @@ -1465,7 +1512,7 @@ static av_always_inline void mpeg_motion_lowres(MpegEncContext *s, sx= motion_x & s_mask; sy= motion_y & s_mask; src_x = s->mb_x*2*block_s + (motion_x >> (lowres+1)); - src_y =(s->mb_y*2*block_s>>field_based) + (motion_y >> (lowres+1)); + src_y =( mb_y*2*block_s>>field_based) + (motion_y >> (lowres+1)); if (s->out_format == FMT_H263) { uvsx = ((motion_x>>1) & s_mask) | (sx&1); @@ -1478,14 +1525,14 @@ static av_always_inline void mpeg_motion_lowres(MpegEncContext *s, uvsx = (2*mx) & s_mask; uvsy = (2*my) & s_mask; uvsrc_x = s->mb_x*block_s + (mx >> lowres); - uvsrc_y = s->mb_y*block_s + (my >> 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 =(s->mb_y*block_s>>field_based) + (my >> (lowres+1)); + uvsrc_y =( mb_y*block_s>>field_based) + (my >> (lowres+1)); } ptr_y = ref_picture[0] + src_y * linesize + src_x; @@ -1520,15 +1567,15 @@ static av_always_inline void mpeg_motion_lowres(MpegEncContext *s, ptr_cr+= s->uvlinesize; } - sx <<= 2 - lowres; - sy <<= 2 - lowres; + sx= (sx << 2) >> lowres; + sy= (sy << 2) >> lowres; pix_op[lowres-1](dest_y, ptr_y, linesize, h, sx, sy); if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ - uvsx <<= 2 - lowres; - uvsy <<= 2 - lowres; - pix_op[lowres](dest_cb, ptr_cb, uvlinesize, h >> s->chroma_y_shift, uvsx, uvsy); - pix_op[lowres](dest_cr, ptr_cr, uvlinesize, h >> s->chroma_y_shift, uvsx, uvsy); + 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); } //FIXME h261 lowres loop filter } @@ -1539,6 +1586,7 @@ static inline void chroma_4mv_motion_lowres(MpegEncContext *s, h264_chroma_mc_func *pix_op, int mx, int my){ const int lowres= s->avctx->lowres; + const int op_index= FFMIN(lowres, 2); const int block_s= 8>>lowres; const int s_mask= (2<h_edge_pos >> (lowres+1); @@ -1571,16 +1619,16 @@ static inline void chroma_4mv_motion_lowres(MpegEncContext *s, emu=1; } } - sx <<= 2 - lowres; - sy <<= 2 - lowres; - pix_op[lowres](dest_cb, ptr, s->uvlinesize, block_s, sx, sy); + sx= (sx << 2) >> lowres; + sy= (sy << 2) >> lowres; + pix_op[op_index](dest_cb, ptr, s->uvlinesize, block_s, sx, sy); ptr = ref_picture[2] + offset; if(emu){ ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, h_edge_pos, v_edge_pos); ptr= s->edge_emu_buffer; } - pix_op[lowres](dest_cr, ptr, s->uvlinesize, block_s, sx, sy); + pix_op[op_index](dest_cr, ptr, s->uvlinesize, block_s, sx, sy); } /** @@ -1612,7 +1660,7 @@ static inline void MPV_motion_lowres(MpegEncContext *s, mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, 0, 0, 0, ref_picture, pix_op, - s->mv[dir][0][0], s->mv[dir][0][1], 2*block_s); + s->mv[dir][0][0], s->mv[dir][0][1], 2*block_s, mb_y); break; case MV_TYPE_8X8: mx = 0; @@ -1639,12 +1687,12 @@ static inline void MPV_motion_lowres(MpegEncContext *s, mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, 1, 0, s->field_select[dir][0], ref_picture, pix_op, - s->mv[dir][0][0], s->mv[dir][0][1], block_s); + s->mv[dir][0][0], s->mv[dir][0][1], block_s, mb_y); /* bottom field */ mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, 1, 1, s->field_select[dir][1], ref_picture, pix_op, - s->mv[dir][1][0], s->mv[dir][1][1], block_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 != FF_B_TYPE && !s->first_field){ ref_picture= s->current_picture_ptr->data; @@ -1653,7 +1701,7 @@ static inline void MPV_motion_lowres(MpegEncContext *s, mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, 0, 0, s->field_select[dir][0], ref_picture, pix_op, - s->mv[dir][0][0], s->mv[dir][0][1], 2*block_s); + s->mv[dir][0][0], s->mv[dir][0][1], 2*block_s, mb_y>>1); } break; case MV_TYPE_16X8: @@ -1669,7 +1717,7 @@ static inline void MPV_motion_lowres(MpegEncContext *s, mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, 0, 0, s->field_select[dir][i], ref2picture, pix_op, - s->mv[dir][i][0], s->mv[dir][i][1] + 2*block_s*i, block_s); + s->mv[dir][i][0], s->mv[dir][i][1] + 2*block_s*i, block_s, mb_y>>1); dest_y += 2*block_s*s->linesize; dest_cb+= (2*block_s>>s->chroma_y_shift)*s->uvlinesize; @@ -1684,7 +1732,7 @@ static inline void MPV_motion_lowres(MpegEncContext *s, mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, 1, j, j^i, ref_picture, pix_op, - s->mv[dir][2*i + j][0], s->mv[dir][2*i + j][1], block_s); + s->mv[dir][2*i + j][0], s->mv[dir][2*i + j][1], block_s, mb_y); } pix_op = s->dsp.avg_h264_chroma_pixels_tab; } @@ -1693,7 +1741,7 @@ static inline void MPV_motion_lowres(MpegEncContext *s, mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, 0, 0, s->picture_structure != i+1, ref_picture, pix_op, - s->mv[dir][2*i][0],s->mv[dir][2*i][1],2*block_s); + s->mv[dir][2*i][0],s->mv[dir][2*i][1],2*block_s, mb_y>>1); // after put we make avg of the same block pix_op = s->dsp.avg_h264_chroma_pixels_tab; @@ -1954,7 +2002,7 @@ void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64], } }//fi gray } - else if (CONFIG_WMV2) { + else if (CONFIG_WMV2_DECODER || CONFIG_WMV2_ENCODER) { ff_wmv2_add_mb(s, block, dest_y, dest_cb, dest_cr); } } else { @@ -2034,16 +2082,17 @@ void MPV_decode_mb(MpegEncContext *s, DCTELEM block[12][64]){ void ff_draw_horiz_band(MpegEncContext *s, int y, int h){ if (s->avctx->draw_horiz_band) { AVFrame *src; + const int field_pic= s->picture_structure != PICT_FRAME; int offset[4]; - if(s->picture_structure != PICT_FRAME){ + h= FFMIN(h, (s->avctx->height>>field_pic) - y); + + if(field_pic && !(s->avctx->slice_flags&SLICE_FLAG_ALLOW_FIELD)){ h <<= 1; y <<= 1; - if(s->first_field && !(s->avctx->slice_flags&SLICE_FLAG_ALLOW_FIELD)) return; + if(s->first_field) return; } - h= FFMIN(h, s->avctx->height - y); - if(s->pict_type==FF_B_TYPE || s->low_delay || (s->avctx->slice_flags&SLICE_FLAG_CODED_ORDER)) src= (AVFrame*)s->current_picture_ptr; else if(s->last_picture_ptr) @@ -2089,9 +2138,16 @@ void ff_init_block_index(MpegEncContext *s){ //FIXME maybe rename if(!(s->pict_type==FF_B_TYPE && s->avctx->draw_horiz_band && s->picture_structure==PICT_FRAME)) { + if(s->picture_structure==PICT_FRAME){ s->dest[0] += s->mb_y * linesize << mb_size; s->dest[1] += s->mb_y * uvlinesize << (mb_size - s->chroma_y_shift); s->dest[2] += s->mb_y * uvlinesize << (mb_size - s->chroma_y_shift); + }else{ + s->dest[0] += (s->mb_y>>1) * linesize << mb_size; + s->dest[1] += (s->mb_y>>1) * uvlinesize << (mb_size - s->chroma_y_shift); + s->dest[2] += (s->mb_y>>1) * uvlinesize << (mb_size - s->chroma_y_shift); + assert((s->mb_y&1) == (s->picture_structure == PICT_BOTTOM_FIELD)); + } } } diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegvideo.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegvideo.h index 181a9cdea6..8cd20b7036 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegvideo.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegvideo.h @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/mpegvideo.h + * @file * mpegvideo header. */ @@ -54,7 +54,7 @@ enum OutputFormat { #define MAX_FCODE 7 #define MAX_MV 2048 -#define MAX_THREADS 8 +#define MAX_THREADS 16 #define MAX_PICTURE_COUNT 32 @@ -436,7 +436,7 @@ typedef struct MpegEncContext { uint16_t (*q_inter_matrix16)[2][64]; int block_last_index[12]; ///< last non zero coefficient in block /* scantables */ - DECLARE_ALIGNED_8(ScanTable, intra_scantable); + ScanTable intra_scantable; ScanTable intra_h_scantable; ScanTable intra_v_scantable; ScanTable inter_scantable; ///< if inter == intra then intra should be used to reduce tha cache usage @@ -571,6 +571,7 @@ typedef struct MpegEncContext { /* RV10 specific */ int rv10_version; ///< RV10 version: 0 or 3 int rv10_first_dc_coded[3]; + int orig_width, orig_height; /* MJPEG specific */ struct MJpegContext *mjpeg_ctx; @@ -691,6 +692,7 @@ void MPV_common_init_mlib(MpegEncContext *s); void MPV_common_init_mmi(MpegEncContext *s); void MPV_common_init_arm(MpegEncContext *s); void MPV_common_init_altivec(MpegEncContext *s); +void MPV_common_init_bfin(MpegEncContext *s); void ff_clean_intra_table_entries(MpegEncContext *s); void ff_draw_horiz_band(MpegEncContext *s, int y, int h); void ff_mpeg_flush(AVCodecContext *avctx); @@ -700,6 +702,7 @@ int ff_find_unused_picture(MpegEncContext *s, int shared); void ff_denoise_dct(MpegEncContext *s, DCTELEM *block); void ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src); const uint8_t *ff_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); void ff_er_frame_end(MpegEncContext *s); @@ -771,6 +774,7 @@ int ff_get_mb_score(MpegEncContext * s, int mx, int my, int src_index, /* mpeg12.c */ extern const uint8_t ff_mpeg1_dc_scale_table[128]; +extern const uint8_t * const ff_mpeg2_dc_scale_table[4]; void mpeg1_encode_picture_header(MpegEncContext *s, int picture_number); void mpeg1_encode_mb(MpegEncContext *s, @@ -781,11 +785,7 @@ void ff_mpeg1_encode_slice_header(MpegEncContext *s); void ff_mpeg1_clean_buffers(MpegEncContext *s); int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size, AVCodecParserContext *s); -extern const uint8_t ff_mpeg4_y_dc_scale_table[32]; -extern const uint8_t ff_mpeg4_c_dc_scale_table[32]; extern const uint8_t ff_aic_dc_scale_table[32]; -extern const int16_t ff_mpeg4_default_intra_matrix[64]; -extern const int16_t ff_mpeg4_default_non_intra_matrix[64]; extern const uint8_t ff_h263_chroma_qscale_table[32]; extern const uint8_t ff_h263_loop_filter_strength[32]; @@ -800,62 +800,6 @@ void ff_h261_encode_init(MpegEncContext *s); int ff_h261_get_picture_format(int width, int height); -/* h263.c, h263dec.c */ -int ff_h263_decode_init(AVCodecContext *avctx); -int ff_h263_decode_frame(AVCodecContext *avctx, - void *data, int *data_size, - AVPacket *avpkt); -int ff_h263_decode_end(AVCodecContext *avctx); -void h263_encode_mb(MpegEncContext *s, - DCTELEM block[6][64], - int motion_x, int motion_y); -void mpeg4_encode_mb(MpegEncContext *s, - DCTELEM block[6][64], - int motion_x, int motion_y); -void h263_encode_picture_header(MpegEncContext *s, int picture_number); -void ff_flv_encode_picture_header(MpegEncContext *s, int picture_number); -void h263_encode_gob_header(MpegEncContext * s, int mb_line); -int16_t *h263_pred_motion(MpegEncContext * s, int block, int dir, - int *px, int *py); -void mpeg4_pred_ac(MpegEncContext * s, DCTELEM *block, int n, - int dir); -void ff_set_mpeg4_time(MpegEncContext * s); -void mpeg4_encode_picture_header(MpegEncContext *s, int picture_number); -void h263_encode_init(MpegEncContext *s); -void h263_decode_init_vlc(MpegEncContext *s); -int h263_decode_picture_header(MpegEncContext *s); -int ff_h263_decode_gob_header(MpegEncContext *s); -int ff_mpeg4_decode_picture_header(MpegEncContext * s, GetBitContext *gb); -void ff_h263_update_motion_val(MpegEncContext * s); -void ff_h263_loop_filter(MpegEncContext * s); -void ff_set_qscale(MpegEncContext * s, int qscale); -int ff_h263_decode_mba(MpegEncContext *s); -void ff_h263_encode_mba(MpegEncContext *s); - -int intel_h263_decode_picture_header(MpegEncContext *s); -int flv_h263_decode_picture_header(MpegEncContext *s); -int ff_h263_decode_mb(MpegEncContext *s, - DCTELEM block[6][64]); -int ff_mpeg4_decode_mb(MpegEncContext *s, - DCTELEM block[6][64]); -int h263_get_picture_format(int width, int height); -void ff_mpeg4_encode_video_packet_header(MpegEncContext *s); -void ff_mpeg4_clean_buffers(MpegEncContext *s); -void ff_mpeg4_stuffing(PutBitContext * pbc); -void ff_mpeg4_init_partitions(MpegEncContext *s); -void ff_mpeg4_merge_partitions(MpegEncContext *s); -void ff_clean_mpeg4_qscales(MpegEncContext *s); -void ff_clean_h263_qscales(MpegEncContext *s); -int ff_mpeg4_decode_partitions(MpegEncContext *s); -int ff_mpeg4_get_video_packet_prefix_length(MpegEncContext *s); -int ff_h263_resync(MpegEncContext *s); -const uint8_t *ff_h263_find_resync_marker(const uint8_t *p, const uint8_t *end); -int ff_h263_get_gob_height(MpegEncContext *s); -void ff_mpeg4_init_direct_mv(MpegEncContext *s); -int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my); -void ff_h263_encode_motion(MpegEncContext * s, int val, int f_code); - - /* rv10.c */ void rv10_encode_picture_header(MpegEncContext *s, int picture_number); int rv_decode_dc(MpegEncContext *s, int n); @@ -870,7 +814,7 @@ void msmpeg4_encode_mb(MpegEncContext * s, int motion_x, int motion_y); int msmpeg4_decode_picture_header(MpegEncContext * s); int msmpeg4_decode_ext_header(MpegEncContext * s, int buf_size); -int ff_msmpeg4_decode_init(MpegEncContext *s); +int ff_msmpeg4_decode_init(AVCodecContext *avctx); void ff_msmpeg4_encode_init(MpegEncContext *s); int ff_wmv2_decode_picture_header(MpegEncContext * s); int ff_wmv2_decode_secondary_picture_header(MpegEncContext * s); diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegvideo_common.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegvideo_common.h index 5ce60dc64c..73106664f9 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegvideo_common.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegvideo_common.h @@ -23,7 +23,7 @@ */ /** - * @file libavcodec/mpegvideo_common.h + * @file * The simplest mpeg encoder (well, it was the simplest!). */ @@ -242,7 +242,7 @@ void mpeg_motion_internal(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, int field_based, int bottom_field, int field_select, uint8_t **ref_picture, op_pixels_func (*pix_op)[4], - int motion_x, int motion_y, int h, int is_mpeg12) + int motion_x, int motion_y, int h, int is_mpeg12, int mb_y) { uint8_t *ptr_y, *ptr_cb, *ptr_cr; int dxy, uvdxy, mx, my, src_x, src_y, @@ -262,7 +262,7 @@ if(s->quarter_sample) dxy = ((motion_y & 1) << 1) | (motion_x & 1); src_x = s->mb_x* 16 + (motion_x >> 1); - src_y =(s->mb_y<<(4-field_based)) + (motion_y >> 1); + src_y =( mb_y<<(4-field_based)) + (motion_y >> 1); if (!is_mpeg12 && s->out_format == FMT_H263) { if((s->workaround_bugs & FF_BUG_HPEL_CHROMA) && field_based){ @@ -270,7 +270,7 @@ if(s->quarter_sample) my = motion_y >>1; uvdxy = ((my & 1) << 1) | (mx & 1); uvsrc_x = s->mb_x* 8 + (mx >> 1); - uvsrc_y = (s->mb_y<<(3-field_based)) + (my >> 1); + uvsrc_y =( mb_y<<(3-field_based))+ (my >> 1); }else{ uvdxy = dxy | (motion_y & 2) | ((motion_x & 2) >> 1); uvsrc_x = src_x>>1; @@ -281,14 +281,14 @@ if(s->quarter_sample) my = motion_y / 4; uvdxy = 0; uvsrc_x = s->mb_x*8 + mx; - uvsrc_y = s->mb_y*8 + my; + uvsrc_y = mb_y*8 + my; } else { if(s->chroma_y_shift){ mx = motion_x / 2; my = motion_y / 2; uvdxy = ((my & 1) << 1) | (mx & 1); uvsrc_x = s->mb_x* 8 + (mx >> 1); - uvsrc_y = (s->mb_y<<(3-field_based)) + (my >> 1); + uvsrc_y =( mb_y<<(3-field_based))+ (my >> 1); } else { if(s->chroma_x_shift){ //Chroma422 @@ -314,7 +314,7 @@ if(s->quarter_sample) if(is_mpeg12 || s->codec_id == CODEC_ID_MPEG2VIDEO || s->codec_id == CODEC_ID_MPEG1VIDEO){ av_log(s->avctx,AV_LOG_DEBUG, - "MPEG motion vector out of boundary\n"); + "MPEG motion vector out of boundary (%d %d)\n", src_x, src_y); return; } ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, @@ -370,18 +370,18 @@ void mpeg_motion(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, int field_based, int bottom_field, int field_select, uint8_t **ref_picture, op_pixels_func (*pix_op)[4], - int motion_x, int motion_y, int h) + int motion_x, int motion_y, int h, int mb_y) { #if !CONFIG_SMALL if(s->out_format == FMT_MPEG1) mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, field_based, bottom_field, field_select, ref_picture, pix_op, - motion_x, motion_y, h, 1); + motion_x, motion_y, h, 1, mb_y); else #endif mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, field_based, bottom_field, field_select, ref_picture, pix_op, - motion_x, motion_y, h, 0); + motion_x, motion_y, h, 0, mb_y); } //FIXME move to dsputil, avg variant, 16x16 version @@ -727,7 +727,7 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s, 0, 0, 0, ref_picture, pix_op, qpix_op, s->mv[dir][0][0], s->mv[dir][0][1], 16); - }else if(!is_mpeg12 && CONFIG_WMV2 && s->mspel){ + }else if(!is_mpeg12 && (CONFIG_WMV2_DECODER || CONFIG_WMV2_ENCODER) && s->mspel){ ff_mspel_motion(s, dest_y, dest_cb, dest_cr, ref_picture, pix_op, s->mv[dir][0][0], s->mv[dir][0][1], 16); @@ -736,7 +736,7 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s, mpeg_motion(s, dest_y, dest_cb, dest_cr, 0, 0, 0, ref_picture, pix_op, - s->mv[dir][0][0], s->mv[dir][0][1], 16); + s->mv[dir][0][0], s->mv[dir][0][1], 16, mb_y); } break; case MV_TYPE_8X8: @@ -810,12 +810,12 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s, mpeg_motion(s, dest_y, dest_cb, dest_cr, 1, 0, s->field_select[dir][0], ref_picture, pix_op, - s->mv[dir][0][0], s->mv[dir][0][1], 8); + s->mv[dir][0][0], s->mv[dir][0][1], 8, mb_y); /* bottom field */ mpeg_motion(s, dest_y, dest_cb, dest_cr, 1, 1, s->field_select[dir][1], ref_picture, pix_op, - s->mv[dir][1][0], s->mv[dir][1][1], 8); + s->mv[dir][1][0], s->mv[dir][1][1], 8, mb_y); } } else { if(s->picture_structure != s->field_select[dir][0] + 1 && s->pict_type != FF_B_TYPE && !s->first_field){ @@ -825,7 +825,7 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s, mpeg_motion(s, dest_y, dest_cb, dest_cr, 0, 0, s->field_select[dir][0], ref_picture, pix_op, - s->mv[dir][0][0], s->mv[dir][0][1], 16); + s->mv[dir][0][0], s->mv[dir][0][1], 16, mb_y>>1); } break; case MV_TYPE_16X8: @@ -842,7 +842,7 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s, mpeg_motion(s, dest_y, dest_cb, dest_cr, 0, 0, s->field_select[dir][i], ref2picture, pix_op, - s->mv[dir][i][0], s->mv[dir][i][1] + 16*i, 8); + s->mv[dir][i][0], s->mv[dir][i][1] + 16*i, 8, mb_y>>1); dest_y += 16*s->linesize; dest_cb+= (16>>s->chroma_y_shift)*s->uvlinesize; @@ -857,7 +857,7 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s, mpeg_motion(s, dest_y, dest_cb, dest_cr, 1, j, j^i, ref_picture, pix_op, - s->mv[dir][2*i + j][0], s->mv[dir][2*i + j][1], 8); + s->mv[dir][2*i + j][0], s->mv[dir][2*i + j][1], 8, mb_y); } pix_op = s->dsp.avg_pixels_tab; } @@ -866,7 +866,7 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s, mpeg_motion(s, dest_y, dest_cb, dest_cr, 0, 0, s->picture_structure != i+1, ref_picture, pix_op, - s->mv[dir][2*i][0],s->mv[dir][2*i][1],16); + s->mv[dir][2*i][0],s->mv[dir][2*i][1],16, mb_y>>1); // after put we make avg of the same block pix_op=s->dsp.avg_pixels_tab; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegvideo_enc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegvideo_enc.c index 6159078077..a8616d0ae8 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegvideo_enc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegvideo_enc.c @@ -23,19 +23,23 @@ */ /** - * @file libavcodec/mpegvideo_enc.c + * @file * The simplest mpeg encoder (well, it was the simplest!). */ +#include "libavutil/intmath.h" #include "avcodec.h" #include "dsputil.h" #include "mpegvideo.h" #include "mpegvideo_common.h" +#include "h263.h" #include "mjpegenc.h" #include "msmpeg4.h" -#include "h263.h" #include "faandct.h" #include "aandcttab.h" +#include "flv.h" +#include "mpeg4video.h" +#include "internal.h" #include //#undef NDEBUG @@ -146,6 +150,20 @@ void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix){ put_bits(pb, 1, 0); } +/** + * 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; + int i; + + for(i=0; imb_num; i++){ + unsigned int lam= s->lambda_table[ s->mb_index2xy[i] ]; + int qp= (lam*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7); + qscale_table[ s->mb_index2xy[i] ]= av_clip(qp, s->avctx->qmin, s->avctx->qmax); + } +} + static void copy_picture_attributes(MpegEncContext *s, AVFrame *dst, AVFrame *src){ int i; @@ -179,7 +197,7 @@ static void copy_picture_attributes(MpegEncContext *s, AVFrame *dst, AVFrame *sr memcpy(dst->motion_val[i], src->motion_val[i], 2*stride*height*sizeof(int16_t)); } if(src->ref_index[i] && src->ref_index[i] != dst->ref_index[i]){ - memcpy(dst->ref_index[i], src->ref_index[i], s->b8_stride*2*s->mb_height*sizeof(int8_t)); + memcpy(dst->ref_index[i], src->ref_index[i], s->mb_stride*4*s->mb_height*sizeof(int8_t)); } } } @@ -381,6 +399,14 @@ av_cold int MPV_encode_init(AVCodecContext *avctx) return -1; } + 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", + avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den); + return -1; + } + if((s->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME|CODEC_FLAG_ALT_SCAN)) && s->codec_id != CODEC_ID_MPEG4 && s->codec_id != CODEC_ID_MPEG2VIDEO){ av_log(avctx, AV_LOG_ERROR, "interlacing not supported by codec\n"); @@ -441,6 +467,11 @@ av_cold int MPV_encode_init(AVCodecContext *avctx) return -1; } + if(s->avctx->thread_count < 1){ + av_log(avctx, AV_LOG_ERROR, "automatic thread number detection not supported by codec, patch welcome\n"); + return -1; + } + if(s->avctx->thread_count > 1) s->rtp_mode= 1; @@ -472,10 +503,7 @@ av_cold int MPV_encode_init(AVCodecContext *avctx) // return -1; } - if(s->codec_id==CODEC_ID_MJPEG){ - s->intra_quant_bias= 1<<(QUANT_BIAS_SHIFT-1); //(a + x/2)/x - s->inter_quant_bias= 0; - }else if(s->mpeg_quant || s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO){ + if(s->mpeg_quant || s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO || s->codec_id==CODEC_ID_MJPEG){ s->intra_quant_bias= 3<<(QUANT_BIAS_SHIFT-3); //(a + x*3/8)/x s->inter_quant_bias= 0; }else{ @@ -512,12 +540,18 @@ av_cold int MPV_encode_init(AVCodecContext *avctx) case CODEC_ID_MJPEG: s->out_format = FMT_MJPEG; s->intra_only = 1; /* force intra only for jpeg */ - s->mjpeg_vsample[0] = 2; - s->mjpeg_vsample[1] = 2>>chroma_v_shift; - s->mjpeg_vsample[2] = 2>>chroma_v_shift; - s->mjpeg_hsample[0] = 2; - s->mjpeg_hsample[1] = 2>>chroma_h_shift; - s->mjpeg_hsample[2] = 2>>chroma_h_shift; + if(avctx->codec->id == CODEC_ID_LJPEG && avctx->pix_fmt == PIX_FMT_BGRA){ + s->mjpeg_vsample[0] = s->mjpeg_hsample[0] = + s->mjpeg_vsample[1] = s->mjpeg_hsample[1] = + s->mjpeg_vsample[2] = s->mjpeg_hsample[2] = 1; + }else{ + s->mjpeg_vsample[0] = 2; + s->mjpeg_vsample[1] = 2>>chroma_v_shift; + s->mjpeg_vsample[2] = 2>>chroma_v_shift; + s->mjpeg_hsample[0] = 2; + s->mjpeg_hsample[1] = 2>>chroma_h_shift; + s->mjpeg_hsample[2] = 2>>chroma_h_shift; + } if (!(CONFIG_MJPEG_ENCODER || CONFIG_LJPEG_ENCODER) || ff_mjpeg_encode_init(s) < 0) return -1; @@ -536,7 +570,7 @@ av_cold int MPV_encode_init(AVCodecContext *avctx) break; case CODEC_ID_H263: if (!CONFIG_H263_ENCODER) return -1; - if (h263_get_picture_format(s->width, s->height) == 7) { + if (ff_match_2uint16(h263_format, FF_ARRAY_ELEMS(h263_format), s->width, s->height) == 7) { 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); return -1; } @@ -674,7 +708,7 @@ av_cold int MPV_encode_init(AVCodecContext *avctx) if (CONFIG_H261_ENCODER && s->out_format == FMT_H261) ff_h261_encode_init(s); - if (CONFIG_ANY_H263_ENCODER && s->out_format == FMT_H263) + if (CONFIG_H263_ENCODER && s->out_format == FMT_H263) h263_encode_init(s); if (CONFIG_MSMPEG4_ENCODER && s->msmpeg4_version) ff_msmpeg4_encode_init(s); @@ -817,14 +851,18 @@ static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg){ pic->data[i]= pic_arg->data[i]; pic->linesize[i]= pic_arg->linesize[i]; } - ff_alloc_picture(s, (Picture*)pic, 1); + if(ff_alloc_picture(s, (Picture*)pic, 1) < 0){ + return -1; + } }else{ i= ff_find_unused_picture(s, 0); pic= (AVFrame*)&s->picture[i]; pic->reference= 3; - ff_alloc_picture(s, (Picture*)pic, 0); + if(ff_alloc_picture(s, (Picture*)pic, 0) < 0){ + return -1; + } if( pic->data[0] + INPLACE_OFFSET == pic_arg->data[0] && pic->data[1] + INPLACE_OFFSET == pic_arg->data[1] @@ -1014,7 +1052,7 @@ static int estimate_best_b_count(MpegEncContext *s){ return best_b_count; } -static void select_input_picture(MpegEncContext *s){ +static int select_input_picture(MpegEncContext *s){ int i; for(i=1; ipicture[i]; pic->reference = s->reordered_input_picture[0]->reference; - ff_alloc_picture(s, pic, 0); + 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) @@ -1180,6 +1220,7 @@ no_output_pic: }else{ memset(&s->new_picture, 0, sizeof(Picture)); } + return 0; } int MPV_encode_picture(AVCodecContext *avctx, @@ -1204,7 +1245,9 @@ int MPV_encode_picture(AVCodecContext *avctx, if(load_input_picture(s, pic_arg) < 0) return -1; - select_input_picture(s); + if(select_input_picture(s) < 0){ + return -1; + } /* output? */ if(s->new_picture.data[0]){ @@ -2439,7 +2482,7 @@ static int encode_thread(AVCodecContext *c, void *arg){ } s->last_bits= put_bits_count(&s->pb); - if (CONFIG_ANY_H263_ENCODER && + if (CONFIG_H263_ENCODER && s->out_format == FMT_H263 && s->pict_type!=FF_B_TYPE) ff_h263_update_motion_val(s); @@ -2566,7 +2609,7 @@ static int encode_thread(AVCodecContext *c, void *arg){ // RAL: Update last macroblock type s->last_mv_dir = s->mv_dir; - if (CONFIG_ANY_H263_ENCODER && + if (CONFIG_H263_ENCODER && s->out_format == FMT_H263 && s->pict_type!=FF_B_TYPE) ff_h263_update_motion_val(s); @@ -2597,7 +2640,7 @@ static int encode_thread(AVCodecContext *c, void *arg){ s->dest[2], w>>1, h>>s->chroma_y_shift, s->uvlinesize); } if(s->loop_filter){ - if(CONFIG_ANY_H263_ENCODER && s->out_format == FMT_H263) + if(CONFIG_H263_ENCODER && s->out_format == FMT_H263) ff_h263_loop_filter(s); } //printf("MB %d %d bits\n", s->mb_x+s->mb_y*s->mb_stride, put_bits_count(&s->pb)); @@ -2685,6 +2728,8 @@ static int estimate_qp(MpegEncContext *s, int dry_run){ if (CONFIG_H263_ENCODER) ff_clean_h263_qscales(s); break; + default: + ff_init_qscale_tab(s); } s->lambda= s->lambda_table[0]; @@ -2767,11 +2812,11 @@ static int encode_picture(MpegEncContext *s, int picture_number) s->lambda2= (s->lambda2* (int64_t)s->avctx->me_penalty_compensation + 128)>>8; if(s->pict_type != FF_B_TYPE && s->avctx->me_threshold==0){ if((s->avctx->pre_me && s->last_non_b_pict_type==FF_I_TYPE) || s->avctx->pre_me==2){ - s->avctx->execute(s->avctx, pre_estimate_motion_thread, (void**)&(s->thread_context[0]), NULL, s->avctx->thread_count, sizeof(void*)); + s->avctx->execute(s->avctx, pre_estimate_motion_thread, &s->thread_context[0], NULL, s->avctx->thread_count, sizeof(void*)); } } - s->avctx->execute(s->avctx, estimate_motion_thread, (void**)&(s->thread_context[0]), NULL, s->avctx->thread_count, sizeof(void*)); + s->avctx->execute(s->avctx, estimate_motion_thread, &s->thread_context[0], NULL, s->avctx->thread_count, sizeof(void*)); }else /* if(s->pict_type == FF_I_TYPE) */{ /* I-Frame */ for(i=0; imb_stride*s->mb_height; i++) @@ -2779,7 +2824,7 @@ static int encode_picture(MpegEncContext *s, int picture_number) if(!s->fixed_qscale){ /* finding spatial complexity for I-frame rate control */ - s->avctx->execute(s->avctx, mb_var_thread, (void**)&(s->thread_context[0]), NULL, s->avctx->thread_count, sizeof(void*)); + s->avctx->execute(s->avctx, mb_var_thread, &s->thread_context[0], NULL, s->avctx->thread_count, sizeof(void*)); } } for(i=1; iavctx->thread_count; i++){ @@ -2858,12 +2903,14 @@ static int encode_picture(MpegEncContext *s, int picture_number) if (s->out_format == FMT_MJPEG) { /* for mjpeg, we do include qscale in the matrix */ - s->intra_matrix[0] = ff_mpeg1_default_intra_matrix[0]; for(i=1;i<64;i++){ int j= s->dsp.idct_permutation[i]; s->intra_matrix[j] = av_clip_uint8((ff_mpeg1_default_intra_matrix[i] * s->qscale) >> 3); } + s->y_dc_scale_table= + s->c_dc_scale_table= ff_mpeg2_dc_scale_table[s->intra_dc_precision]; + s->intra_matrix[0] = ff_mpeg2_dc_scale_table[s->intra_dc_precision][8]; ff_convert_matrix(&s->dsp, s->q_intra_matrix, s->q_intra_matrix16, s->intra_matrix, s->intra_quant_bias, 8, 8, 1); s->qscale= 8; @@ -2901,7 +2948,7 @@ static int encode_picture(MpegEncContext *s, int picture_number) rv20_encode_picture_header(s, picture_number); else if (CONFIG_FLV_ENCODER && s->codec_id == CODEC_ID_FLV1) ff_flv_encode_picture_header(s, picture_number); - else if (CONFIG_ANY_H263_ENCODER) + else if (CONFIG_H263_ENCODER) h263_encode_picture_header(s, picture_number); break; case FMT_MPEG1: @@ -2919,7 +2966,7 @@ static int encode_picture(MpegEncContext *s, int picture_number) for(i=1; iavctx->thread_count; i++){ update_duplicate_context_after_me(s->thread_context[i], s); } - s->avctx->execute(s->avctx, encode_thread, (void**)&(s->thread_context[0]), NULL, s->avctx->thread_count, sizeof(void*)); + s->avctx->execute(s->avctx, encode_thread, &s->thread_context[0], NULL, s->avctx->thread_count, sizeof(void*)); for(i=1; iavctx->thread_count; i++){ merge_context_after_encode(s, s->thread_context[i]); } @@ -3273,7 +3320,7 @@ static int dct_quantize_refine(MpegEncContext *s, //FIXME breaks denoise? DCTELEM *block, int16_t *weight, DCTELEM *orig, int n, int qscale){ int16_t rem[64]; - DECLARE_ALIGNED_16(DCTELEM, d1[64]); + LOCAL_ALIGNED_16(DCTELEM, d1, [64]); const uint8_t *scantable= s->intra_scantable.scantable; const uint8_t *perm_scantable= s->intra_scantable.permutated; // unsigned int threshold1, threshold2; @@ -3724,97 +3771,72 @@ int dct_quantize_c(MpegEncContext *s, AVCodec h263_encoder = { "h263", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_H263, sizeof(MpegEncContext), MPV_encode_init, MPV_encode_picture, MPV_encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, .long_name= NULL_IF_CONFIG_SMALL("H.263 / H.263-1996"), }; AVCodec h263p_encoder = { "h263p", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_H263P, sizeof(MpegEncContext), MPV_encode_init, MPV_encode_picture, MPV_encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, + .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"), }; -AVCodec flv_encoder = { - "flv", - CODEC_TYPE_VIDEO, - CODEC_ID_FLV1, - sizeof(MpegEncContext), - MPV_encode_init, - MPV_encode_picture, - MPV_encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, - .long_name= NULL_IF_CONFIG_SMALL("Flash Video (FLV)"), -}; - -AVCodec mpeg4_encoder = { - "mpeg4", - CODEC_TYPE_VIDEO, - CODEC_ID_MPEG4, - sizeof(MpegEncContext), - MPV_encode_init, - MPV_encode_picture, - MPV_encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, - .capabilities= CODEC_CAP_DELAY, - .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2"), -}; - AVCodec msmpeg4v1_encoder = { "msmpeg4v1", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_MSMPEG4V1, sizeof(MpegEncContext), MPV_encode_init, MPV_encode_picture, MPV_encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 1"), }; AVCodec msmpeg4v2_encoder = { "msmpeg4v2", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_MSMPEG4V2, sizeof(MpegEncContext), MPV_encode_init, MPV_encode_picture, MPV_encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, + .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 msmpeg4v3_encoder = { "msmpeg4", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_MSMPEG4V3, sizeof(MpegEncContext), MPV_encode_init, MPV_encode_picture, MPV_encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, + .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 wmv1_encoder = { "wmv1", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_WMV1, sizeof(MpegEncContext), MPV_encode_init, MPV_encode_picture, MPV_encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, .long_name= NULL_IF_CONFIG_SMALL("Windows Media Video 7"), }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegvideo_parser.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegvideo_parser.c index 215c86c400..546c3bdad7 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegvideo_parser.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegvideo_parser.c @@ -28,15 +28,16 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s, const uint8_t *buf, int buf_size) { ParseContext1 *pc = s->priv_data; - const uint8_t *buf_end; + const uint8_t *buf_end = buf + buf_size; uint32_t start_code; int frame_rate_index, ext_type, bytes_left; int frame_rate_ext_n, frame_rate_ext_d; int picture_structure, top_field_first, repeat_first_field, progressive_frame; int horiz_size_ext, vert_size_ext, bit_rate_ext; + int did_set_size=0; //FIXME replace the crap with get_bits() s->repeat_pict = 0; - buf_end = buf + buf_size; + while (buf < buf_end) { start_code= -1; buf= ff_find_start_code(buf, buf_end, &start_code); @@ -51,7 +52,10 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s, if (bytes_left >= 7) { pc->width = (buf[0] << 4) | (buf[1] >> 4); pc->height = ((buf[1] & 0x0f) << 8) | buf[2]; - avcodec_set_dimensions(avctx, pc->width, pc->height); + if(!avctx->width || !avctx->height || !avctx->coded_width || !avctx->coded_height){ + avcodec_set_dimensions(avctx, pc->width, pc->height); + 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; @@ -77,7 +81,8 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s, pc->width |=(horiz_size_ext << 12); pc->height |=( vert_size_ext << 12); avctx->bit_rate += (bit_rate_ext << 18) * 400; - avcodec_set_dimensions(avctx, pc->width, pc->height); + if(did_set_size) + avcodec_set_dimensions(avctx, pc->width, pc->height); avctx->time_base.den = pc->frame_rate.den * (frame_rate_ext_n + 1) * 2; avctx->time_base.num = pc->frame_rate.num * (frame_rate_ext_d + 1); avctx->codec_id = CODEC_ID_MPEG2VIDEO; @@ -177,4 +182,5 @@ AVCodecParser mpegvideo_parser = { NULL, mpegvideo_parse, ff_parse1_close, + mpegvideo_split, }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegvideo_xvmc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegvideo_xvmc.c index b73a399b9e..df81e5da68 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegvideo_xvmc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/mpegvideo_xvmc.c @@ -48,7 +48,7 @@ void ff_xvmc_init_block(MpegEncContext *s) } /** - * Fill individual block pointers, so there are no gaps in the data_block array + * Fills individual block pointers, so there are no gaps in the data_block array * in case not all blocks in the macroblock are coded. */ void ff_xvmc_pack_pblocks(MpegEncContext *s, int cbp) @@ -67,7 +67,7 @@ void ff_xvmc_pack_pblocks(MpegEncContext *s, int cbp) } /** - * Find and store the surfaces that are used as reference frames. + * Finds and stores the surfaces that are used as reference frames. * This function should be called for every new field and/or frame. * It should be safe to call the function a few times for the same field. */ @@ -134,7 +134,7 @@ return -1; } /** - * Complete frame/field rendering by passing any remaining blocks. + * Completes frame/field rendering by passing any remaining blocks. * Normally ff_draw_horiz_band() is called for each slice, however, * some leftover blocks, for example from error_resilience(), may remain. * It should be safe to call the function a few times for the same field. @@ -149,8 +149,8 @@ void ff_xvmc_field_end(MpegEncContext *s) } /** - * Synthesize the data needed by XvMC to render one macroblock of data. - * Fill all relevant fields, if necessary do IDCT. + * Synthesizes the data needed by XvMC to render one macroblock of data. + * Fills all relevant fields, if necessary do IDCT. */ void ff_xvmc_decode_mb(MpegEncContext *s) { diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/msmpeg4.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/msmpeg4.c index 8c0da0ae10..84658fe84d 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/msmpeg4.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/msmpeg4.c @@ -23,7 +23,7 @@ */ /** - * @file libavcodec/msmpeg4.c + * @file * MSMPEG4 backend for ffmpeg encoder and decoder. */ @@ -32,6 +32,8 @@ #include "mpegvideo.h" #include "msmpeg4.h" #include "libavutil/x86_cpu.h" +#include "h263.h" +#include "mpeg4video.h" /* * You can also call this codec : MPEG4 with a twist ! @@ -43,9 +45,6 @@ //#define DEBUG #define DC_VLC_BITS 9 -#define CBPY_VLC_BITS 6 -#define V1_INTRA_CBPC_VLC_BITS 6 -#define V1_INTER_CBPC_VLC_BITS 6 #define V2_INTRA_CBPC_VLC_BITS 3 #define V2_MB_TYPE_VLC_BITS 7 #define MV_VLC_BITS 9 @@ -60,16 +59,6 @@ static uint32_t v2_dc_lum_table[512][2]; static uint32_t v2_dc_chroma_table[512][2]; -static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr); -static void init_h263_dc_for_msmpeg4(void); -static inline void msmpeg4_memsetw(short *tab, int val, int n); -#if CONFIG_ENCODERS -static void msmpeg4v2_encode_motion(MpegEncContext * s, int val); -static int get_size_of_code(MpegEncContext * s, RLTable *rl, int last, int run, int level, int intra); -#endif //CONFIG_ENCODERS -static int msmpeg4v12_decode_mb(MpegEncContext *s, DCTELEM block[6][64]); -static int msmpeg4v34_decode_mb(MpegEncContext *s, DCTELEM block[6][64]); - /* vc1 externs */ extern const uint8_t wmv3_dc_scale_table[32]; @@ -85,6 +74,62 @@ static uint8_t rl_length[NB_RL_TABLES][MAX_LEVEL+1][MAX_RUN+1][2]; static uint8_t static_rl_table_store[NB_RL_TABLES][2][2*MAX_RUN + MAX_LEVEL + 3]; +/* This table is practically identical to the one from h263 + * except that it is inverted. */ +static av_cold void init_h263_dc_for_msmpeg4(void) +{ + int level, uni_code, uni_len; + + for(level=-256; level<256; level++){ + int size, v, l; + /* find number of bits */ + size = 0; + v = abs(level); + while (v) { + v >>= 1; + size++; + } + + if (level < 0) + l= (-level) ^ ((1 << size) - 1); + else + l= level; + + /* luminance h263 */ + uni_code= ff_mpeg4_DCtab_lum[size][0]; + uni_len = ff_mpeg4_DCtab_lum[size][1]; + uni_code ^= (1< 0) { + uni_code<<=size; uni_code|=l; + uni_len+=size; + if (size > 8){ + uni_code<<=1; uni_code|=1; + uni_len++; + } + } + v2_dc_lum_table[level+256][0]= uni_code; + v2_dc_lum_table[level+256][1]= uni_len; + + /* chrominance h263 */ + uni_code= ff_mpeg4_DCtab_chrom[size][0]; + uni_len = ff_mpeg4_DCtab_chrom[size][1]; + uni_code ^= (1< 0) { + uni_code<<=size; uni_code|=l; + uni_len+=size; + if (size > 8){ + uni_code<<=1; uni_code|=1; + uni_len++; + } + } + v2_dc_chroma_table[level+256][0]= uni_code; + v2_dc_chroma_table[level+256][1]= uni_len; + + } +} + static av_cold void common_init(MpegEncContext * s) { static int initialized=0; @@ -163,40 +208,6 @@ void ff_msmpeg4_code012(PutBitContext *pb, int n) } } -av_cold void ff_msmpeg4_encode_init(MpegEncContext *s) -{ - static int init_done=0; - int i; - - common_init(s); - if(s->msmpeg4_version>=4){ - s->min_qcoeff= -255; - s->max_qcoeff= 255; - } - - if (!init_done) { - /* init various encoding tables */ - init_done = 1; - init_mv_table(&mv_tables[0]); - init_mv_table(&mv_tables[1]); - for(i=0;imsmpeg4_version>=4){ + s->min_qcoeff= -255; + s->max_qcoeff= 255; + } + + if (!init_done) { + /* init various encoding tables */ + init_done = 1; + init_mv_table(&mv_tables[0]); + init_mv_table(&mv_tables[1]); + for(i=0;ipb, mvtab[code][1], mvtab[code][0]); + } else { + bit_size = s->f_code - 1; + range = 1 << bit_size; + if (val <= -64) + val += 64; + else if (val >= 64) + val -= 64; + + if (val >= 0) { + sign = 0; + } else { + val = -val; + sign = 1; + } + val--; + code = (val >> bit_size) + 1; + bits = val & (range - 1); + + put_bits(&s->pb, mvtab[code][1] + 1, (mvtab[code][0] << 1) | sign); + if (bit_size > 0) { + put_bits(&s->pb, bit_size, bits); + } + } +} + void msmpeg4_encode_mb(MpegEncContext * s, DCTELEM block[6][64], int motion_x, int motion_y) @@ -496,8 +574,8 @@ void msmpeg4_encode_mb(MpegEncContext * s, else coded_cbp= cbp; put_bits(&s->pb, - cbpy_tab[coded_cbp>>2][1], - cbpy_tab[coded_cbp>>2][0]); + ff_h263_cbpy_tab[coded_cbp>>2][1], + ff_h263_cbpy_tab[coded_cbp>>2][0]); s->misc_bits += get_bits_diff(s); @@ -557,8 +635,8 @@ void msmpeg4_encode_mb(MpegEncContext * s, } put_bits(&s->pb, 1, 0); /* no AC prediction yet */ put_bits(&s->pb, - cbpy_tab[cbp>>2][1], - cbpy_tab[cbp>>2][0]); + ff_h263_cbpy_tab[cbp>>2][1], + ff_h263_cbpy_tab[cbp>>2][0]); }else{ if (s->pict_type == FF_I_TYPE) { put_bits(&s->pb, @@ -980,77 +1058,229 @@ else VLC ff_mb_non_intra_vlc[4]; static VLC v2_dc_lum_vlc; static VLC v2_dc_chroma_vlc; -static VLC cbpy_vlc; static VLC v2_intra_cbpc_vlc; static VLC v2_mb_type_vlc; static VLC v2_mv_vlc; -static VLC v1_intra_cbpc_vlc; -static VLC v1_inter_cbpc_vlc; VLC ff_inter_intra_vlc; -/* This table is practically identical to the one from h263 - * except that it is inverted. */ -static av_cold void init_h263_dc_for_msmpeg4(void) +/* This is identical to h263 except that its range is multiplied by 2. */ +static int msmpeg4v2_decode_motion(MpegEncContext * s, int pred, int f_code) { - int level, uni_code, uni_len; + int code, val, sign, shift; - for(level=-256; level<256; level++){ - int size, v, l; - /* find number of bits */ - size = 0; - v = abs(level); - while (v) { - v >>= 1; - size++; + code = get_vlc2(&s->gb, v2_mv_vlc.table, V2_MV_VLC_BITS, 2); +// printf("MV code %d at %d %d pred: %d\n", code, s->mb_x,s->mb_y, pred); + if (code < 0) + return 0xffff; + + if (code == 0) + return pred; + sign = get_bits1(&s->gb); + shift = f_code - 1; + val = code; + if (shift) { + val = (val - 1) << shift; + val |= get_bits(&s->gb, shift); + val++; + } + if (sign) + val = -val; + + val += pred; + if (val <= -64) + val += 64; + else if (val >= 64) + val -= 64; + + return val; +} + +static int msmpeg4v12_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) +{ + int cbp, code, i; + + if (s->pict_type == FF_P_TYPE) { + if (s->use_skip_mb_code) { + if (get_bits1(&s->gb)) { + /* skip mb */ + s->mb_intra = 0; + for(i=0;i<6;i++) + s->block_last_index[i] = -1; + s->mv_dir = MV_DIR_FORWARD; + s->mv_type = MV_TYPE_16X16; + s->mv[0][0][0] = 0; + s->mv[0][0][1] = 0; + s->mb_skipped = 1; + return 0; } - - if (level < 0) - l= (-level) ^ ((1 << size) - 1); - else - l= level; - - /* luminance h263 */ - uni_code= DCtab_lum[size][0]; - uni_len = DCtab_lum[size][1]; - uni_code ^= (1< 0) { - uni_code<<=size; uni_code|=l; - uni_len+=size; - if (size > 8){ - uni_code<<=1; uni_code|=1; - uni_len++; - } - } - v2_dc_lum_table[level+256][0]= uni_code; - v2_dc_lum_table[level+256][1]= uni_len; - - /* chrominance h263 */ - uni_code= DCtab_chrom[size][0]; - uni_len = DCtab_chrom[size][1]; - uni_code ^= (1< 0) { - uni_code<<=size; uni_code|=l; - uni_len+=size; - if (size > 8){ - uni_code<<=1; uni_code|=1; - uni_len++; - } - } - v2_dc_chroma_table[level+256][0]= uni_code; - v2_dc_chroma_table[level+256][1]= uni_len; - } + + if(s->msmpeg4_version==2) + code = get_vlc2(&s->gb, v2_mb_type_vlc.table, V2_MB_TYPE_VLC_BITS, 1); + else + code = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2); + if(code<0 || code>7){ + av_log(s->avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n", code, s->mb_x, s->mb_y); + return -1; + } + + s->mb_intra = code >>2; + + cbp = code & 0x3; + } else { + s->mb_intra = 1; + if(s->msmpeg4_version==2) + cbp= get_vlc2(&s->gb, v2_intra_cbpc_vlc.table, V2_INTRA_CBPC_VLC_BITS, 1); + else + cbp= get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 1); + if(cbp<0 || cbp>3){ + av_log(s->avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n", cbp, s->mb_x, s->mb_y); + return -1; + } + } + + if (!s->mb_intra) { + int mx, my, cbpy; + + cbpy= get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1); + if(cbpy<0){ + av_log(s->avctx, AV_LOG_ERROR, "cbpy %d invalid at %d %d\n", cbp, s->mb_x, s->mb_y); + return -1; + } + + cbp|= cbpy<<2; + if(s->msmpeg4_version==1 || (cbp&3) != 3) cbp^= 0x3C; + + h263_pred_motion(s, 0, 0, &mx, &my); + mx= msmpeg4v2_decode_motion(s, mx, 1); + my= msmpeg4v2_decode_motion(s, my, 1); + + s->mv_dir = MV_DIR_FORWARD; + s->mv_type = MV_TYPE_16X16; + s->mv[0][0][0] = mx; + s->mv[0][0][1] = my; + } else { + if(s->msmpeg4_version==2){ + s->ac_pred = get_bits1(&s->gb); + cbp|= get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1)<<2; //FIXME check errors + } else{ + s->ac_pred = 0; + cbp|= get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1)<<2; //FIXME check errors + if(s->pict_type==FF_P_TYPE) cbp^=0x3C; + } + } + + s->dsp.clear_blocks(s->block[0]); + for (i = 0; i < 6; i++) { + if (ff_msmpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0) + { + av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n", s->mb_x, s->mb_y, i); + return -1; + } + } + return 0; +} + +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 ]; + + if (s->pict_type == FF_P_TYPE) { + if (s->use_skip_mb_code) { + if (get_bits1(&s->gb)) { + /* skip mb */ + s->mb_intra = 0; + for(i=0;i<6;i++) + s->block_last_index[i] = -1; + s->mv_dir = MV_DIR_FORWARD; + s->mv_type = MV_TYPE_16X16; + s->mv[0][0][0] = 0; + s->mv[0][0][1] = 0; + s->mb_skipped = 1; + *mb_type_ptr = MB_TYPE_SKIP | MB_TYPE_L0 | MB_TYPE_16x16; + + return 0; + } + } + + code = get_vlc2(&s->gb, ff_mb_non_intra_vlc[DEFAULT_INTER_INDEX].table, MB_NON_INTRA_VLC_BITS, 3); + if (code < 0) + return -1; + //s->mb_intra = (code & 0x40) ? 0 : 1; + s->mb_intra = (~code & 0x40) >> 6; + + cbp = code & 0x3f; + } else { + s->mb_intra = 1; + code = get_vlc2(&s->gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2); + if (code < 0) + return -1; + /* predict coded block pattern */ + cbp = 0; + for(i=0;i<6;i++) { + int val = ((code >> (5 - i)) & 1); + if (i < 4) { + int pred = ff_msmpeg4_coded_block_pred(s, i, &coded_val); + val = val ^ pred; + *coded_val = val; + } + cbp |= val << (5 - i); + } + } + + if (!s->mb_intra) { + int mx, my; +//printf("P at %d %d\n", s->mb_x, s->mb_y); + if(s->per_mb_rl_table && cbp){ + s->rl_table_index = decode012(&s->gb); + s->rl_chroma_table_index = s->rl_table_index; + } + h263_pred_motion(s, 0, 0, &mx, &my); + if (ff_msmpeg4_decode_motion(s, &mx, &my) < 0) + return -1; + s->mv_dir = MV_DIR_FORWARD; + s->mv_type = MV_TYPE_16X16; + s->mv[0][0][0] = mx; + s->mv[0][0][1] = my; + *mb_type_ptr = MB_TYPE_L0 | MB_TYPE_16x16; + } else { +//printf("I at %d %d %d %06X\n", s->mb_x, s->mb_y, ((cbp&3)? 1 : 0) +((cbp&0x3C)? 2 : 0), show_bits(&s->gb, 24)); + s->ac_pred = get_bits1(&s->gb); + *mb_type_ptr = MB_TYPE_INTRA; + if(s->inter_intra_pred){ + s->h263_aic_dir= get_vlc2(&s->gb, ff_inter_intra_vlc.table, INTER_INTRA_VLC_BITS, 1); +// printf("%d%d %d %d/", s->ac_pred, s->h263_aic_dir, s->mb_x, s->mb_y); + } + if(s->per_mb_rl_table && cbp){ + s->rl_table_index = decode012(&s->gb); + s->rl_chroma_table_index = s->rl_table_index; + } + } + + s->dsp.clear_blocks(s->block[0]); + for (i = 0; i < 6; i++) { + if (ff_msmpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0) + { + av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n", s->mb_x, s->mb_y, i); + return -1; + } + } + + return 0; } /* init all vlc decoding tables */ -av_cold int ff_msmpeg4_decode_init(MpegEncContext *s) +av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx) { + MpegEncContext *s = avctx->priv_data; static int done = 0; int i; MVTable *mv; + ff_h263_decode_init(avctx); + common_init(s); if (!done) { @@ -1095,9 +1325,6 @@ av_cold int ff_msmpeg4_decode_init(MpegEncContext *s) &v2_dc_chroma_table[0][1], 8, 4, &v2_dc_chroma_table[0][0], 8, 4, 1506); - INIT_VLC_STATIC(&cbpy_vlc, CBPY_VLC_BITS, 16, - &cbpy_tab[0][1], 2, 1, - &cbpy_tab[0][0], 2, 1, 64); INIT_VLC_STATIC(&v2_intra_cbpc_vlc, V2_INTRA_CBPC_VLC_BITS, 4, &v2_intra_cbpc[0][1], 2, 1, &v2_intra_cbpc[0][0], 2, 1, 8); @@ -1125,13 +1352,6 @@ av_cold int ff_msmpeg4_decode_init(MpegEncContext *s) &ff_msmp4_mb_i_table[0][1], 4, 2, &ff_msmp4_mb_i_table[0][0], 4, 2, 536); - INIT_VLC_STATIC(&v1_intra_cbpc_vlc, V1_INTRA_CBPC_VLC_BITS, 8, - intra_MCBPC_bits, 1, 1, - intra_MCBPC_code, 1, 1, 64); - INIT_VLC_STATIC(&v1_inter_cbpc_vlc, V1_INTER_CBPC_VLC_BITS, 25, - inter_MCBPC_bits, 1, 1, - inter_MCBPC_code, 1, 1, 104); - INIT_VLC_STATIC(&ff_inter_intra_vlc, INTER_INTRA_VLC_BITS, 4, &table_inter_intra[0][1], 2, 1, &table_inter_intra[0][0], 2, 1, 8); @@ -1357,255 +1577,63 @@ int msmpeg4_decode_ext_header(MpegEncContext * s, int buf_size) return 0; } -static inline void msmpeg4_memsetw(short *tab, int val, int n) +static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr) { - int i; - for(i=0;ipb, mvtab[code][1], mvtab[code][0]); - } else { - bit_size = s->f_code - 1; - range = 1 << bit_size; - if (val <= -64) - val += 64; - else if (val >= 64) - val -= 64; - - if (val >= 0) { - sign = 0; + if(s->msmpeg4_version<=2){ + if (n < 4) { + level = get_vlc2(&s->gb, v2_dc_lum_vlc.table, DC_VLC_BITS, 3); } else { - val = -val; - sign = 1; + level = get_vlc2(&s->gb, v2_dc_chroma_vlc.table, DC_VLC_BITS, 3); + } + if (level < 0) + return -1; + level-=256; + }else{ //FIXME optimize use unified tables & index + if (n < 4) { + level = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3); + } else { + level = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3); + } + if (level < 0){ + av_log(s->avctx, AV_LOG_ERROR, "illegal dc vlc\n"); + return -1; } - val--; - code = (val >> bit_size) + 1; - bits = val & (range - 1); - put_bits(&s->pb, mvtab[code][1] + 1, (mvtab[code][0] << 1) | sign); - if (bit_size > 0) { - put_bits(&s->pb, bit_size, bits); + if (level == DC_MAX) { + level = get_bits(&s->gb, 8); + if (get_bits1(&s->gb)) + level = -level; + } else if (level != 0) { + if (get_bits1(&s->gb)) + level = -level; } } -} -#endif -/* This is identical to h263 except that its range is multiplied by 2. */ -static int msmpeg4v2_decode_motion(MpegEncContext * s, int pred, int f_code) -{ - int code, val, sign, shift; + if(s->msmpeg4_version==1){ + int32_t *dc_val; + pred = msmpeg4v1_pred_dc(s, n, &dc_val); + level += pred; - code = get_vlc2(&s->gb, v2_mv_vlc.table, V2_MV_VLC_BITS, 2); -// printf("MV code %d at %d %d pred: %d\n", code, s->mb_x,s->mb_y, pred); - if (code < 0) - return 0xffff; + /* update predictor */ + *dc_val= level; + }else{ + int16_t *dc_val; + pred = msmpeg4_pred_dc(s, n, &dc_val, dir_ptr); + level += pred; - if (code == 0) - return pred; - sign = get_bits1(&s->gb); - shift = f_code - 1; - val = code; - if (shift) { - val = (val - 1) << shift; - val |= get_bits(&s->gb, shift); - val++; + /* update predictor */ + if (n < 4) { + *dc_val = level * s->y_dc_scale; + } else { + *dc_val = level * s->c_dc_scale; + } } - if (sign) - val = -val; - val += pred; - if (val <= -64) - val += 64; - else if (val >= 64) - val -= 64; - - return val; + return level; } -static int msmpeg4v12_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) -{ - int cbp, code, i; - - if (s->pict_type == FF_P_TYPE) { - if (s->use_skip_mb_code) { - if (get_bits1(&s->gb)) { - /* skip mb */ - s->mb_intra = 0; - for(i=0;i<6;i++) - s->block_last_index[i] = -1; - s->mv_dir = MV_DIR_FORWARD; - s->mv_type = MV_TYPE_16X16; - s->mv[0][0][0] = 0; - s->mv[0][0][1] = 0; - s->mb_skipped = 1; - return 0; - } - } - - if(s->msmpeg4_version==2) - code = get_vlc2(&s->gb, v2_mb_type_vlc.table, V2_MB_TYPE_VLC_BITS, 1); - else - code = get_vlc2(&s->gb, v1_inter_cbpc_vlc.table, V1_INTER_CBPC_VLC_BITS, 3); - if(code<0 || code>7){ - av_log(s->avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n", code, s->mb_x, s->mb_y); - return -1; - } - - s->mb_intra = code >>2; - - cbp = code & 0x3; - } else { - s->mb_intra = 1; - if(s->msmpeg4_version==2) - cbp= get_vlc2(&s->gb, v2_intra_cbpc_vlc.table, V2_INTRA_CBPC_VLC_BITS, 1); - else - cbp= get_vlc2(&s->gb, v1_intra_cbpc_vlc.table, V1_INTRA_CBPC_VLC_BITS, 1); - if(cbp<0 || cbp>3){ - av_log(s->avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n", cbp, s->mb_x, s->mb_y); - return -1; - } - } - - if (!s->mb_intra) { - int mx, my, cbpy; - - cbpy= get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); - if(cbpy<0){ - av_log(s->avctx, AV_LOG_ERROR, "cbpy %d invalid at %d %d\n", cbp, s->mb_x, s->mb_y); - return -1; - } - - cbp|= cbpy<<2; - if(s->msmpeg4_version==1 || (cbp&3) != 3) cbp^= 0x3C; - - h263_pred_motion(s, 0, 0, &mx, &my); - mx= msmpeg4v2_decode_motion(s, mx, 1); - my= msmpeg4v2_decode_motion(s, my, 1); - - s->mv_dir = MV_DIR_FORWARD; - s->mv_type = MV_TYPE_16X16; - s->mv[0][0][0] = mx; - s->mv[0][0][1] = my; - } else { - if(s->msmpeg4_version==2){ - s->ac_pred = get_bits1(&s->gb); - cbp|= get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1)<<2; //FIXME check errors - } else{ - s->ac_pred = 0; - cbp|= get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1)<<2; //FIXME check errors - if(s->pict_type==FF_P_TYPE) cbp^=0x3C; - } - } - - s->dsp.clear_blocks(s->block[0]); - for (i = 0; i < 6; i++) { - if (ff_msmpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0) - { - av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n", s->mb_x, s->mb_y, i); - return -1; - } - } - return 0; -} - -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 ]; - - if (s->pict_type == FF_P_TYPE) { - if (s->use_skip_mb_code) { - if (get_bits1(&s->gb)) { - /* skip mb */ - s->mb_intra = 0; - for(i=0;i<6;i++) - s->block_last_index[i] = -1; - s->mv_dir = MV_DIR_FORWARD; - s->mv_type = MV_TYPE_16X16; - s->mv[0][0][0] = 0; - s->mv[0][0][1] = 0; - s->mb_skipped = 1; - *mb_type_ptr = MB_TYPE_SKIP | MB_TYPE_L0 | MB_TYPE_16x16; - - return 0; - } - } - - code = get_vlc2(&s->gb, ff_mb_non_intra_vlc[DEFAULT_INTER_INDEX].table, MB_NON_INTRA_VLC_BITS, 3); - if (code < 0) - return -1; - //s->mb_intra = (code & 0x40) ? 0 : 1; - s->mb_intra = (~code & 0x40) >> 6; - - cbp = code & 0x3f; - } else { - s->mb_intra = 1; - code = get_vlc2(&s->gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2); - if (code < 0) - return -1; - /* predict coded block pattern */ - cbp = 0; - for(i=0;i<6;i++) { - int val = ((code >> (5 - i)) & 1); - if (i < 4) { - int pred = ff_msmpeg4_coded_block_pred(s, i, &coded_val); - val = val ^ pred; - *coded_val = val; - } - cbp |= val << (5 - i); - } - } - - if (!s->mb_intra) { - int mx, my; -//printf("P at %d %d\n", s->mb_x, s->mb_y); - if(s->per_mb_rl_table && cbp){ - s->rl_table_index = decode012(&s->gb); - s->rl_chroma_table_index = s->rl_table_index; - } - h263_pred_motion(s, 0, 0, &mx, &my); - if (ff_msmpeg4_decode_motion(s, &mx, &my) < 0) - return -1; - s->mv_dir = MV_DIR_FORWARD; - s->mv_type = MV_TYPE_16X16; - s->mv[0][0][0] = mx; - s->mv[0][0][1] = my; - *mb_type_ptr = MB_TYPE_L0 | MB_TYPE_16x16; - } else { -//printf("I at %d %d %d %06X\n", s->mb_x, s->mb_y, ((cbp&3)? 1 : 0) +((cbp&0x3C)? 2 : 0), show_bits(&s->gb, 24)); - s->ac_pred = get_bits1(&s->gb); - *mb_type_ptr = MB_TYPE_INTRA; - if(s->inter_intra_pred){ - s->h263_aic_dir= get_vlc2(&s->gb, ff_inter_intra_vlc.table, INTER_INTRA_VLC_BITS, 1); -// printf("%d%d %d %d/", s->ac_pred, s->h263_aic_dir, s->mb_x, s->mb_y); - } - if(s->per_mb_rl_table && cbp){ - s->rl_table_index = decode012(&s->gb); - s->rl_chroma_table_index = s->rl_table_index; - } - } - - s->dsp.clear_blocks(s->block[0]); - for (i = 0; i < 6; i++) { - if (ff_msmpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0) - { - av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n", s->mb_x, s->mb_y, i); - return -1; - } - } - - return 0; -} //#define ERROR_DETAILS int ff_msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block, int n, int coded, const uint8_t *scan_table) @@ -1704,9 +1732,7 @@ int ff_msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block, if(s->qscale<8){ ll= SHOW_UBITS(re, &s->gb, 3); SKIP_BITS(re, &s->gb, 3); if(ll==0){ - if(SHOW_UBITS(re, &s->gb, 1)) av_log(s->avctx, AV_LOG_ERROR, "cool a new vlc code ,contact the ffmpeg developers and upload the file\n"); - SKIP_BITS(re, &s->gb, 1); - ll=8; + ll= 8+SHOW_UBITS(re, &s->gb, 1); SKIP_BITS(re, &s->gb, 1); } }else{ ll=2; @@ -1823,7 +1849,7 @@ int ff_msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block, if (i > 62){ i-= 192; if(i&(~63)){ - const int left= s->gb.size_in_bits - get_bits_count(&s->gb); + const int left= get_bits_left(&s->gb); if(((i+192 == 64 && level/qmul==-1) || s->error_recognition<=1) && left>=0){ av_log(s->avctx, AV_LOG_ERROR, "ignoring overflow at %d %d\n", s->mb_x, s->mb_y); break; @@ -1854,63 +1880,6 @@ int ff_msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block, return 0; } -static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr) -{ - int level, pred; - - if(s->msmpeg4_version<=2){ - if (n < 4) { - level = get_vlc2(&s->gb, v2_dc_lum_vlc.table, DC_VLC_BITS, 3); - } else { - level = get_vlc2(&s->gb, v2_dc_chroma_vlc.table, DC_VLC_BITS, 3); - } - if (level < 0) - return -1; - level-=256; - }else{ //FIXME optimize use unified tables & index - if (n < 4) { - level = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3); - } else { - level = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3); - } - if (level < 0){ - av_log(s->avctx, AV_LOG_ERROR, "illegal dc vlc\n"); - return -1; - } - - if (level == DC_MAX) { - level = get_bits(&s->gb, 8); - if (get_bits1(&s->gb)) - level = -level; - } else if (level != 0) { - if (get_bits1(&s->gb)) - level = -level; - } - } - - if(s->msmpeg4_version==1){ - int32_t *dc_val; - pred = msmpeg4v1_pred_dc(s, n, &dc_val); - level += pred; - - /* update predictor */ - *dc_val= level; - }else{ - int16_t *dc_val; - pred = msmpeg4_pred_dc(s, n, &dc_val, dir_ptr); - level += pred; - - /* update predictor */ - if (n < 4) { - *dc_val = level * s->y_dc_scale; - } else { - *dc_val = level * s->c_dc_scale; - } - } - - return level; -} - int ff_msmpeg4_decode_motion(MpegEncContext * s, int *mx_ptr, int *my_ptr) { @@ -1949,3 +1918,59 @@ int ff_msmpeg4_decode_motion(MpegEncContext * s, *my_ptr = my; return 0; } + +AVCodec 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, + .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 1"), + .pix_fmts= ff_pixfmt_list_420, +}; + +AVCodec 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, + .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 2"), + .pix_fmts= ff_pixfmt_list_420, +}; + +AVCodec 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, + .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 3"), + .pix_fmts= ff_pixfmt_list_420, +}; + +AVCodec 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, + .long_name= NULL_IF_CONFIG_SMALL("Windows Media Video 7"), + .pix_fmts= ff_pixfmt_list_420, +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/msmpeg4.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/msmpeg4.h index 278ed15ee1..28372a0bc8 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/msmpeg4.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/msmpeg4.h @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/msmpeg4.h + * @file */ #ifndef AVCODEC_MSMPEG4_H @@ -58,9 +58,5 @@ int ff_wmv2_decode_mb(MpegEncContext *s, DCTELEM block[6][64]); CONFIG_MSMPEG4V2_ENCODER || \ CONFIG_MSMPEG4V3_ENCODER || \ CONFIG_WMV2_ENCODER) -#define CONFIG_MSMPEG4 (CONFIG_MSMPEG4_DECODER || CONFIG_MSMPEG4_ENCODER) -#define CONFIG_WMV2 (CONFIG_WMV2_DECODER || CONFIG_WMV2_ENCODER) -#define CONFIG_WMV_DECODER (CONFIG_WMV1_DECODER || CONFIG_WMV2_DECODER) -#define CONFIG_WMV_ENCODER (CONFIG_WMV1_ENCODER || CONFIG_WMV2_ENCODER) #endif /* AVCODEC_MSMPEG4_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/msmpeg4data.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/msmpeg4data.c index 003e3a60ee..f72715dea0 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/msmpeg4data.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/msmpeg4data.c @@ -23,7 +23,7 @@ */ /** - * @file libavcodec/msmpeg4data.c + * @file * MSMPEG4 data tables. */ @@ -596,9 +596,9 @@ extern const uint16_t inter_vlc[103][2]; extern const int8_t inter_level[102]; extern const int8_t inter_run[102]; -extern const uint16_t intra_vlc[103][2]; -extern const int8_t intra_level[102]; -extern const int8_t intra_run[102]; +extern const uint16_t ff_mpeg4_intra_vlc[103][2]; +extern const int8_t ff_mpeg4_intra_level[102]; +extern const int8_t ff_mpeg4_intra_run[102]; RLTable rl_table[NB_RL_TABLES] = { /* intra luminance tables */ @@ -622,9 +622,9 @@ RLTable rl_table[NB_RL_TABLES] = { { 102, 67, - intra_vlc, - intra_run, - intra_level, + ff_mpeg4_intra_vlc, + ff_mpeg4_intra_run, + ff_mpeg4_intra_level, }, /* intra chrominance / non intra tables */ /* low motion inter */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/msmpeg4data.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/msmpeg4data.h index 69d542fe6f..623d9570a7 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/msmpeg4data.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/msmpeg4data.h @@ -23,7 +23,7 @@ */ /** - * @file libavcodec/msmpeg4data.h + * @file * MSMPEG4 data tables. */ @@ -52,19 +52,6 @@ extern VLC ff_msmp4_dc_chroma_vlc[2]; /* intra picture macroblock coded block pattern */ extern const uint16_t ff_msmp4_mb_i_table[64][2]; -extern const uint8_t cbpy_tab[16][2]; - -extern const uint8_t DCtab_lum[13][2]; -extern const uint8_t DCtab_chrom[13][2]; - -extern const uint8_t mvtab[33][2]; - -extern const uint8_t intra_MCBPC_code[9]; -extern const uint8_t intra_MCBPC_bits[9]; - -extern const uint8_t inter_MCBPC_code[28]; -extern const uint8_t inter_MCBPC_bits[28]; - #define WMV1_SCANTABLE_COUNT 4 extern const uint8_t wmv1_scantable[WMV1_SCANTABLE_COUNT][64]; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/msrle.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/msrle.c index 3ab73a3957..28eb5d33f1 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/msrle.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/msrle.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/msrle.c + * @file * MS RLE Video Decoder by Mike Melanson (melanson@pcisys.net) * For more information about the MS RLE format, visit: * http://www.pcisys.net/~melanson/codecs/ @@ -145,7 +145,7 @@ static av_cold int msrle_decode_end(AVCodecContext *avctx) AVCodec msrle_decoder = { "msrle", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_MSRLE, sizeof(MsrleContext), msrle_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/msrledec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/msrledec.c index 7f9adcdce6..6e16d535b3 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/msrledec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/msrledec.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/msrledec.c + * @file * MS RLE decoder based on decoder by Mike Melanson and my own for TSCC * For more information about the MS RLE format, visit: * http://www.multimedia.cx/msrle.txt @@ -28,6 +28,7 @@ #include "libavutil/intreadwrite.h" #include "avcodec.h" +#include "msrledec.h" #define FETCH_NEXT_STREAM_BYTE() \ if (stream_ptr >= data_size) \ @@ -167,7 +168,8 @@ static int msrle_decode_8_16_24_32(AVCodecContext *avctx, AVPicture *pic, int de continue; } // Copy data - if (output + p2 * (depth >> 3) > output_end) { + if ((pic->linesize[0] > 0 && output + p2 * (depth >> 3) > output_end) + ||(pic->linesize[0] < 0 && output + p2 * (depth >> 3) < output_end)) { src += p2 * (depth >> 3); continue; } @@ -211,7 +213,8 @@ static int msrle_decode_8_16_24_32(AVCodecContext *avctx, AVPicture *pic, int de src += 4; break; } - if (output + p1 * (depth >> 3) > output_end) + if ((pic->linesize[0] > 0 && output + p1 * (depth >> 3) > output_end) + ||(pic->linesize[0] < 0 && output + p1 * (depth >> 3) < output_end)) continue; for(i = 0; i < p1; i++) { switch(depth){ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/msvideo1.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/msvideo1.c index a9d94f8f57..30aca3954e 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/msvideo1.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/msvideo1.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/msvideo1.c + * @file * Microsoft Video-1 Decoder by Mike Melanson (melanson@pcisys.net) * For more information about the MS Video-1 format, visit: * http://www.pcisys.net/~melanson/codecs/ @@ -333,7 +333,7 @@ static av_cold int msvideo1_decode_end(AVCodecContext *avctx) AVCodec msvideo1_decoder = { "msvideo1", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_MSVIDEO1, sizeof(Msvideo1Context), msvideo1_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/nellymoser.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/nellymoser.c index 08559e68c7..0716c25a20 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/nellymoser.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/nellymoser.c @@ -26,7 +26,7 @@ */ /** - * @file libavcodec/nellymoser.c + * @file * The 3 alphanumeric copyright notices are md5summed they are from the original * implementors. The original code is available from http://code.google.com/p/nelly2pcm/ */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/nellymoser.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/nellymoser.h index aa16b55e07..88d9aa6245 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/nellymoser.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/nellymoser.h @@ -26,7 +26,7 @@ */ /** - * @file libavcodec/nellymoser.h + * @file * The 3 alphanumeric copyright notices are md5summed they are from the original * implementors. The original code is available from http://code.google.com/p/nelly2pcm/ */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/nellymoserdec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/nellymoserdec.c index a1f55266bf..82a3f07950 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/nellymoserdec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/nellymoserdec.c @@ -26,7 +26,7 @@ */ /** - * @file libavcodec/nellymoserdec.c + * @file * The 3 alphanumeric copyright notices are md5summed they are from the original * implementors. The original code is available from http://code.google.com/p/nelly2pcm/ */ @@ -36,6 +36,7 @@ #include "libavutil/random_seed.h" #include "avcodec.h" #include "dsputil.h" +#include "fft.h" #define ALT_BITSTREAM_READER_LE #include "get_bits.h" @@ -43,15 +44,15 @@ typedef struct NellyMoserDecodeContext { AVCodecContext* avctx; - DECLARE_ALIGNED_16(float,float_buf[NELLY_SAMPLES]); + DECLARE_ALIGNED(16, float,float_buf)[NELLY_SAMPLES]; float state[128]; AVLFG random_state; GetBitContext gb; int add_bias; float scale_bias; DSPContext dsp; - MDCTContext imdct_ctx; - DECLARE_ALIGNED_16(float,imdct_out[NELLY_BUF_LEN * 2]); + FFTContext imdct_ctx; + DECLARE_ALIGNED(16, float,imdct_out)[NELLY_BUF_LEN * 2]; } NellyMoserDecodeContext; static void overlap_and_window(NellyMoserDecodeContext *s, float *state, float *audio, float *a_in) @@ -129,7 +130,7 @@ static av_cold int decode_init(AVCodecContext * avctx) { NellyMoserDecodeContext *s = avctx->priv_data; s->avctx = avctx; - av_lfg_init(&s->random_state, ff_random_get_seed()); + av_lfg_init(&s->random_state, 0); ff_mdct_init(&s->imdct_ctx, 8, 1, 1.0); dsputil_init(&s->dsp, avctx); @@ -144,7 +145,7 @@ static av_cold int decode_init(AVCodecContext * avctx) { /* Generate overlap window */ if (!ff_sine_128[127]) - ff_sine_window_init(ff_sine_128, 128); + ff_init_ff_sine_windows(7); avctx->sample_fmt = SAMPLE_FMT_S16; avctx->channel_layout = CH_LAYOUT_MONO; @@ -199,7 +200,7 @@ static av_cold int decode_end(AVCodecContext * avctx) { AVCodec nellymoser_decoder = { "nellymoser", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_NELLYMOSER, sizeof(NellyMoserDecodeContext), decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/nellymoserenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/nellymoserenc.c index c9f93dbcb8..dd9a2719e2 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/nellymoserenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/nellymoserenc.c @@ -22,7 +22,7 @@ */ /** - * @file libavcodec/nellymoserenc.c + * @file * Nellymoser encoder * by Bartlomiej Wolowiec * @@ -38,6 +38,7 @@ #include "nellymoser.h" #include "avcodec.h" #include "dsputil.h" +#include "fft.h" #define BITSTREAM_WRITER_LE #include "put_bits.h" @@ -52,10 +53,10 @@ typedef struct NellyMoserEncodeContext { int bufsel; int have_saved; DSPContext dsp; - MDCTContext mdct_ctx; - DECLARE_ALIGNED_16(float, mdct_out[NELLY_SAMPLES]); - DECLARE_ALIGNED_16(float, in_buff[NELLY_SAMPLES]); - DECLARE_ALIGNED_16(float, buf[2][3 * NELLY_BUF_LEN]); ///< sample buffer + FFTContext mdct_ctx; + DECLARE_ALIGNED(16, float, mdct_out)[NELLY_SAMPLES]; + DECLARE_ALIGNED(16, float, in_buff)[NELLY_SAMPLES]; + DECLARE_ALIGNED(16, float, buf)[2][3 * NELLY_BUF_LEN]; ///< sample buffer float (*opt )[NELLY_BANDS]; uint8_t (*path)[NELLY_BANDS]; } NellyMoserEncodeContext; @@ -110,7 +111,7 @@ static const float quant_lut_mul[7] = { 0.0, 0.0, 2.0, 2.0, 5.0, 12.0, 36.6 static const float quant_lut_add[7] = { 0.0, 0.0, 2.0, 7.0, 21.0, 56.0, 157.0 }; static const uint8_t quant_lut_offset[8] = { 0, 0, 1, 4, 11, 32, 81, 230 }; -void apply_mdct(NellyMoserEncodeContext *s) +static void apply_mdct(NellyMoserEncodeContext *s) { memcpy(s->in_buff, s->buf[s->bufsel], NELLY_BUF_LEN * sizeof(float)); s->dsp.vector_fmul(s->in_buff, ff_sine_128, NELLY_BUF_LEN); @@ -383,7 +384,7 @@ static int encode_frame(AVCodecContext *avctx, uint8_t *frame, int buf_size, voi AVCodec nellymoser_encoder = { .name = "nellymoser", - .type = CODEC_TYPE_AUDIO, + .type = AVMEDIA_TYPE_AUDIO, .id = CODEC_ID_NELLYMOSER, .priv_data_size = sizeof(NellyMoserEncodeContext), .init = encode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/nuv.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/nuv.c index 4f049baf90..791f450913 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/nuv.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/nuv.c @@ -202,7 +202,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, c->pic.reference = 3; c->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_READABLE | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; - result = keyframe ? avctx->get_buffer(avctx, &c->pic) : avctx->reget_buffer(avctx, &c->pic); + result = avctx->reget_buffer(avctx, &c->pic); if (result < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return -1; @@ -274,7 +274,7 @@ static av_cold int decode_end(AVCodecContext *avctx) { AVCodec nuv_decoder = { "nuv", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_NUV, sizeof(NuvContext), decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/opt.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/opt.c index c7218296f6..f9cba05759 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/opt.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/opt.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/opt.c + * @file * AVOptions * @author Michael Niedermayer */ @@ -112,10 +112,8 @@ int av_set_string3(void *obj, const char *name, const char *val, int alloc, cons const AVOption *o= av_find_opt(obj, name, NULL, 0, 0); if (o_out) *o_out = o; - if(!o) { - av_log(obj, AV_LOG_ERROR, "Unknown option '%s'\n", name); + if(!o) return AVERROR(ENOENT); - } if(!val || o->offset<=0) return AVERROR(EINVAL); @@ -158,7 +156,7 @@ int av_set_string3(void *obj, const char *name, const char *val, int alloc, cons buf[i]= val[i]; buf[i]=0; - d = ff_eval2(buf, const_values, const_names, NULL, NULL, NULL, NULL, NULL, &error); + d = ff_parse_and_eval_expr(buf, const_values, const_names, NULL, NULL, NULL, NULL, NULL, &error); if(isnan(d)) { const AVOption *o_named= av_find_opt(obj, buf, o->unit, 0, 0); if(o_named && o_named->type == FF_OPT_TYPE_CONST) @@ -426,7 +424,7 @@ void av_opt_set_defaults2(void *s, int mask, int flags) break; case FF_OPT_TYPE_INT64: if((double)(opt->default_val+0.6) == opt->default_val) - av_log(s, AV_LOG_DEBUG, "loss of precission in default of %s\n", opt->name); + 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); break; case FF_OPT_TYPE_FLOAT: { diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/opt.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/opt.h index 84511e0c06..55ca4ea63e 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/opt.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/opt.h @@ -23,7 +23,7 @@ #define AVCODEC_OPT_H /** - * @file libavcodec/opt.h + * @file * AVOptions */ @@ -85,6 +85,58 @@ typedef struct AVOption { const char *unit; } AVOption; +/** + * AVOption2. + * THIS IS NOT PART OF THE API/ABI YET! + * This is identical to AVOption except that default_val was replaced by + * an union, it should be compatible with AVOption on normal platforms. + */ +typedef struct AVOption2 { + const char *name; + + /** + * short English help text + * @todo What about other languages? + */ + const char *help; + + /** + * The offset relative to the context structure where the option + * value is stored. It should be 0 for named constants. + */ + int offset; + enum AVOptionType type; + + /** + * the default value for scalar options + */ + union { + double dbl; + const char *str; + } default_val; + + double min; ///< minimum valid value for the option + double max; ///< maximum valid value for the option + + int flags; +/* +#define AV_OPT_FLAG_ENCODING_PARAM 1 ///< a generic parameter which can be set by the user for muxing or encoding +#define AV_OPT_FLAG_DECODING_PARAM 2 ///< a generic parameter which can be set by the user for demuxing or decoding +#define AV_OPT_FLAG_METADATA 4 ///< some data extracted or inserted into the file like title, comment, ... +#define AV_OPT_FLAG_AUDIO_PARAM 8 +#define AV_OPT_FLAG_VIDEO_PARAM 16 +#define AV_OPT_FLAG_SUBTITLE_PARAM 32 +*/ +//FIXME think about enc-audio, ... style flags + + /** + * The logical unit to which the option belongs. Non-constant + * options and corresponding named constants share the same + * unit. May be NULL. + */ + const char *unit; +} AVOption2; + /** * Looks for an option in obj. Looks only for the options which diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/options.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/options.c index d3a4916fc6..6835352c30 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/options.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/options.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/options.c + * @file * Options definition for AVCodecContext. */ @@ -124,6 +124,7 @@ static const AVOption options[]={ {"b_qfactor", "qp factor between p and b frames", OFFSET(b_quant_factor), FF_OPT_TYPE_FLOAT, 1.25, -FLT_MAX, FLT_MAX, V|E}, {"rc_strategy", "ratecontrol method", OFFSET(rc_strategy), FF_OPT_TYPE_INT, 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, 0, INT_MIN, INT_MAX, V|E}, +{"wpredp", "weighted prediction analysis method", OFFSET(weighted_p_pred), FF_OPT_TYPE_INT, 0, INT_MIN, INT_MAX, V|E}, {"hurry_up", NULL, OFFSET(hurry_up), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D}, {"ps", "rtp payload size in bytes", OFFSET(rtp_payload_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, {"mv_bits", NULL, OFFSET(mv_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, @@ -152,13 +153,14 @@ static const AVOption options[]={ {"hpel_chroma", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_HPEL_CHROMA, INT_MIN, INT_MAX, V|D, "bug"}, {"dc_clip", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_DC_CLIP, INT_MIN, INT_MAX, V|D, "bug"}, {"ms", "workaround various bugs in microsofts broken decoders", 0, FF_OPT_TYPE_CONST, FF_BUG_MS, INT_MIN, INT_MAX, V|D, "bug"}, +{"trunc", "trancated frames", 0, FF_OPT_TYPE_CONST,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, 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, DEFAULT, INT_MIN, INT_MAX, V|E}, {"strict", "how strictly to follow the standards", OFFSET(strict_std_compliance), FF_OPT_TYPE_INT, 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, 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, FF_COMPLIANCE_STRICT, INT_MIN, INT_MAX, V|D|E, "strict"}, {"normal", NULL, 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_NORMAL, INT_MIN, INT_MAX, V|D|E, "strict"}, -{"inofficial", "allow inofficial extensions", 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_INOFFICIAL, INT_MIN, INT_MAX, V|D|E, "strict"}, +{"inofficial", "allow unofficial extensions", 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_INOFFICIAL, INT_MIN, INT_MAX, V|D|E, "strict"}, {"experimental", "allow non standardized experimental things", 0, FF_OPT_TYPE_CONST, 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, 1.25, -FLT_MAX, FLT_MAX, V|E}, {"er", "set error detection aggressivity", OFFSET(error_recognition), FF_OPT_TYPE_INT, FF_ER_CAREFUL, INT_MIN, INT_MAX, A|V|D, "er"}, @@ -305,7 +307,7 @@ static const AVOption options[]={ {"nr", "noise reduction", OFFSET(noise_reduction), FF_OPT_TYPE_INT, 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, DEFAULT, INT_MIN, INT_MAX, V|E}, {"inter_threshold", NULL, OFFSET(inter_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, -{"flags2", NULL, OFFSET(flags2), FF_OPT_TYPE_FLAGS, CODEC_FLAG2_FASTPSKIP|CODEC_FLAG2_BIT_RESERVOIR, 0, UINT_MAX, V|A|E|D, "flags2"}, +{"flags2", NULL, OFFSET(flags2), FF_OPT_TYPE_FLAGS, 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, DEFAULT, INT_MIN, INT_MAX, V|E}, {"antialias", "MP3 antialias algorithm", OFFSET(antialias_algo), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D, "aa"}, {"auto", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_AUTO, INT_MIN, INT_MAX, V|D, "aa"}, @@ -346,7 +348,7 @@ static const AVOption options[]={ {"bidir" , NULL, 0, FF_OPT_TYPE_CONST, AVDISCARD_BIDIR , INT_MIN, INT_MAX, V|D, "avdiscard"}, {"nokey" , NULL, 0, FF_OPT_TYPE_CONST, AVDISCARD_NONKEY , INT_MIN, INT_MAX, V|D, "avdiscard"}, {"all" , NULL, 0, FF_OPT_TYPE_CONST, 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, DEFAULT, 0, 4, V|E}, +{"bidir_refine", "refine the two motion vectors used in bidirectional macroblocks", OFFSET(bidir_refine), FF_OPT_TYPE_INT, 1, 0, 4, V|E}, {"brd_scale", "downscales frames for dynamic B-frame decision", OFFSET(brd_scale), FF_OPT_TYPE_INT, DEFAULT, 0, 10, V|E}, {"crf", "enables constant quality mode, and selects the quality (x264)", OFFSET(crf), FF_OPT_TYPE_FLOAT, DEFAULT, 0, 51, V|E}, {"cqp", "constant quantization parameter rate control method", OFFSET(cqp), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, V|E}, @@ -390,6 +392,7 @@ static const AVOption options[]={ {"request_channels", "set desired number of audio channels", OFFSET(request_channels), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, A|D}, {"drc_scale", "percentage of dynamic range compression to apply", OFFSET(drc_scale), FF_OPT_TYPE_FLOAT, 1.0, 0.0, 1.0, A|D}, {"reservoir", "use bit reservoir", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_BIT_RESERVOIR, INT_MIN, INT_MAX, A|E, "flags2"}, +{"mbtree", "use macroblock tree ratecontrol (x264 only)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_MBTREE, INT_MIN, INT_MAX, V|E, "flags2"}, {"bits_per_raw_sample", NULL, OFFSET(bits_per_raw_sample), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, {"channel_layout", NULL, OFFSET(channel_layout), FF_OPT_TYPE_INT64, DEFAULT, 0, INT64_MAX, A|E|D, "channel_layout"}, {"request_channel_layout", NULL, OFFSET(request_channel_layout), FF_OPT_TYPE_INT64, DEFAULT, 0, INT64_MAX, A|D, "request_channel_layout"}, @@ -401,6 +404,13 @@ static const AVOption options[]={ {"colorspace", NULL, OFFSET(colorspace), FF_OPT_TYPE_INT, AVCOL_SPC_UNSPECIFIED, 1, AVCOL_SPC_NB-1, V|E|D}, {"color_range", NULL, OFFSET(color_range), FF_OPT_TYPE_INT, AVCOL_RANGE_UNSPECIFIED, 0, AVCOL_RANGE_NB-1, V|E|D}, {"chroma_sample_location", NULL, OFFSET(chroma_sample_location), FF_OPT_TYPE_INT, AVCHROMA_LOC_UNSPECIFIED, 0, AVCHROMA_LOC_NB-1, V|E|D}, +{"psy", "use psycho visual optimization", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_PSY, INT_MIN, INT_MAX, V|E, "flags2"}, +{"psy_rd", "specify psycho visual strength", OFFSET(psy_rd), FF_OPT_TYPE_FLOAT, 1.0, 0, FLT_MAX, V|E}, +{"psy_trellis", "specify psycho visual trellis", OFFSET(psy_trellis), FF_OPT_TYPE_FLOAT, 0, 0, FLT_MAX, V|E}, +{"aq_mode", "specify aq method", OFFSET(aq_mode), FF_OPT_TYPE_INT, 1, 0, INT_MAX, V|E}, +{"aq_strength", "specify aq strength", OFFSET(aq_strength), FF_OPT_TYPE_FLOAT, 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, 40, 0, INT_MAX, V|E}, +{"ssim", "ssim will be calculated during encoding", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_SSIM, INT_MIN, INT_MAX, V|E, "flags2"}, {NULL}, }; @@ -411,20 +421,20 @@ static const AVOption options[]={ #undef D #undef DEFAULT -static const AVClass av_codec_context_class = { "AVCodecContext", context_to_name, options }; +static const AVClass av_codec_context_class = { "AVCodecContext", context_to_name, options, LIBAVUTIL_VERSION_INT }; -void avcodec_get_context_defaults2(AVCodecContext *s, enum CodecType codec_type){ +void avcodec_get_context_defaults2(AVCodecContext *s, enum AVMediaType codec_type){ int flags=0; memset(s, 0, sizeof(AVCodecContext)); s->av_class= &av_codec_context_class; s->codec_type = codec_type; - if(codec_type == CODEC_TYPE_AUDIO) + if(codec_type == AVMEDIA_TYPE_AUDIO) flags= AV_OPT_FLAG_AUDIO_PARAM; - else if(codec_type == CODEC_TYPE_VIDEO) + else if(codec_type == AVMEDIA_TYPE_VIDEO) flags= AV_OPT_FLAG_VIDEO_PARAM; - else if(codec_type == CODEC_TYPE_SUBTITLE) + else if(codec_type == AVMEDIA_TYPE_SUBTITLE) flags= AV_OPT_FLAG_SUBTITLE_PARAM; av_opt_set_defaults2(s, flags, flags); @@ -433,15 +443,17 @@ void avcodec_get_context_defaults2(AVCodecContext *s, enum CodecType codec_type) 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= SAMPLE_FMT_S16; // FIXME: set to NONE + s->sample_fmt= SAMPLE_FMT_NONE; s->palctrl = NULL; s->reget_buffer= avcodec_default_reget_buffer; + s->reordered_opaque= AV_NOPTS_VALUE; } -AVCodecContext *avcodec_alloc_context2(enum CodecType codec_type){ +AVCodecContext *avcodec_alloc_context2(enum AVMediaType codec_type){ AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext)); if(avctx==NULL) return NULL; @@ -452,10 +464,70 @@ AVCodecContext *avcodec_alloc_context2(enum CodecType codec_type){ } void avcodec_get_context_defaults(AVCodecContext *s){ - avcodec_get_context_defaults2(s, CODEC_TYPE_UNKNOWN); + avcodec_get_context_defaults2(s, AVMEDIA_TYPE_UNKNOWN); } AVCodecContext *avcodec_alloc_context(void){ - return avcodec_alloc_context2(CODEC_TYPE_UNKNOWN); + return avcodec_alloc_context2(AVMEDIA_TYPE_UNKNOWN); } +int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src) +{ + if (dest->codec) { // check that the dest context is uninitialized + av_log(dest, AV_LOG_ERROR, + "Tried to copy AVCodecContext %p into already-initialized %p\n", + src, dest); + return AVERROR(EINVAL); + } + memcpy(dest, src, sizeof(*dest)); + + /* 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; + dest->execute = NULL; + dest->execute2 = NULL; + dest->reget_buffer = NULL; + dest->thread_opaque = NULL; + + /* reallocate values that should be allocated separately */ + dest->rc_eq = NULL; + dest->extradata = NULL; + dest->intra_matrix = NULL; + dest->inter_matrix = NULL; + dest->rc_override = NULL; + if (src->rc_eq) { + dest->rc_eq = av_strdup(src->rc_eq); + if (!dest->rc_eq) + return AVERROR(ENOMEM); + } + +#define alloc_and_copy_or_fail(obj, size, pad) \ + if (src->obj && size > 0) { \ + dest->obj = av_malloc(size + pad); \ + if (!dest->obj) \ + goto fail; \ + memcpy(dest->obj, src->obj, size); \ + if (pad) \ + memset(((uint8_t *) dest->obj) + size, 0, pad); \ + } + alloc_and_copy_or_fail(extradata, src->extradata_size, + FF_INPUT_BUFFER_PADDING_SIZE); + alloc_and_copy_or_fail(intra_matrix, 64 * sizeof(int16_t), 0); + alloc_and_copy_or_fail(inter_matrix, 64 * sizeof(int16_t), 0); + alloc_and_copy_or_fail(rc_override, src->rc_override_count * sizeof(*src->rc_override), 0); +#undef alloc_and_copy_or_fail + + return 0; + +fail: + av_freep(&dest->rc_override); + av_freep(&dest->intra_matrix); + av_freep(&dest->inter_matrix); + av_freep(&dest->extradata); + av_freep(&dest->rc_eq); + return AVERROR(ENOMEM); +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/os2thread.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/os2thread.c index edebc9a6c8..3d1367c8f4 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/os2thread.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/os2thread.c @@ -39,7 +39,7 @@ typedef struct ThreadContext{ }ThreadContext; -void attribute_align_arg thread_func(void *v){ +static void attribute_align_arg thread_func(void *v){ ThreadContext *c= v; for(;;){ @@ -81,7 +81,7 @@ void avcodec_thread_free(AVCodecContext *s){ av_freep(&s->thread_opaque); } -int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size){ +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; @@ -116,6 +116,9 @@ int avcodec_thread_init(AVCodecContext *s, int thread_count){ s->thread_count= thread_count; + if (thread_count <= 1) + return 0; + assert(!s->thread_opaque); c= av_mallocz(sizeof(ThreadContext)*thread_count); s->thread_opaque= c; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/pamenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/pamenc.c new file mode 100644 index 0000000000..ae0ea3a102 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/pamenc.c @@ -0,0 +1,120 @@ +/* + * PAM image format + * Copyright (c) 2002, 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 "avcodec.h" +#include "bytestream.h" +#include "pnm.h" + + +static int pam_encode_frame(AVCodecContext *avctx, unsigned char *outbuf, + int buf_size, void *data) +{ + PNMContext *s = avctx->priv_data; + AVFrame *pict = data; + AVFrame * const p = (AVFrame*)&s->picture; + int i, h, w, n, linesize, depth, maxval; + const char *tuple_type; + uint8_t *ptr; + + if (buf_size < avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height) + 200) { + av_log(avctx, AV_LOG_ERROR, "encoded frame too large\n"); + return -1; + } + + *p = *pict; + p->pict_type = FF_I_TYPE; + p->key_frame = 1; + + s->bytestream_start = + s->bytestream = outbuf; + s->bytestream_end = outbuf+buf_size; + + h = avctx->height; + w = avctx->width; + switch (avctx->pix_fmt) { + case PIX_FMT_MONOWHITE: + n = (w + 7) >> 3; + depth = 1; + maxval = 1; + tuple_type = "BLACKANDWHITE"; + break; + case PIX_FMT_GRAY8: + n = w; + depth = 1; + maxval = 255; + tuple_type = "GRAYSCALE"; + break; + case PIX_FMT_RGB24: + n = w * 3; + depth = 3; + maxval = 255; + tuple_type = "RGB"; + break; + case PIX_FMT_RGB32: + n = w * 4; + depth = 4; + maxval = 255; + tuple_type = "RGB_ALPHA"; + break; + default: + return -1; + } + snprintf(s->bytestream, s->bytestream_end - s->bytestream, + "P7\nWIDTH %d\nHEIGHT %d\nDEPTH %d\nMAXVAL %d\nTUPLETYPE %s\nENDHDR\n", + w, h, depth, maxval, tuple_type); + s->bytestream += strlen(s->bytestream); + + ptr = p->data[0]; + linesize = p->linesize[0]; + + if (avctx->pix_fmt == PIX_FMT_RGB32) { + int j; + unsigned int v; + + for (i = 0; i < h; i++) { + for (j = 0; j < w; j++) { + v = ((uint32_t *)ptr)[j]; + bytestream_put_be24(&s->bytestream, v); + *s->bytestream++ = v >> 24; + } + ptr += linesize; + } + } else { + for (i = 0; i < h; i++) { + memcpy(s->bytestream, ptr, n); + s->bytestream += n; + ptr += linesize; + } + } + return s->bytestream - s->bytestream_start; +} + + +AVCodec pam_encoder = { + "pam", + AVMEDIA_TYPE_VIDEO, + CODEC_ID_PAM, + sizeof(PNMContext), + ff_pnm_init, + 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/src/add-ons/media/plugins/ffmpeg/libavcodec/parser.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/parser.c index 0b007e9ee4..864b5f2d2a 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/parser.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/parser.c @@ -91,7 +91,7 @@ void ff_fetch_timestamp(AVCodecParserContext *s, int off, int remove){ if ( s->cur_offset + off >= s->cur_frame_offset[i] && (s->frame_offset < s->cur_frame_offset[i] || (!s->frame_offset && !s->next_frame_offset)) // first field/frame - //check is disabled becausue mpeg-ts doesnt send complete PES packets + //check is disabled because mpeg-ts doesnt send complete PES packets && /*s->next_frame_offset + off <*/ s->cur_frame_end[i]){ s->dts= s->cur_frame_dts[i]; s->pts= s->cur_frame_pts[i]; @@ -244,7 +244,7 @@ void av_parser_close(AVCodecParserContext *s) /** * combines the (truncated) bitstream to a complete frame - * @returns -1 if no complete frame could be created, AVERROR(ENOMEM) if there was a memory allocation error + * @return -1 if no complete frame could be created, AVERROR(ENOMEM) if there was a memory allocation error */ int ff_combine_frame(ParseContext *pc, int next, const uint8_t **buf, int *buf_size) { diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/pcm-mpeg.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/pcm-mpeg.c new file mode 100644 index 0000000000..c2343a69b0 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/pcm-mpeg.c @@ -0,0 +1,310 @@ +/* + * LPCM codecs for PCM formats found in MPEG streams + * Copyright (c) 2009 Christian Schmidt + * + * 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 + * PCM codecs for encodings found in MPEG streams (DVD/Blu-ray) + */ + +#include "avcodec.h" +#include "bytestream.h" + +/* + * Channel Mapping according to + * Blu-ray Disc Read-Only Format Version 1 + * Part 3: Audio Visual Basic Specifications + * mono M1 X + * stereo L R + * 3/0 L R C X + * 2/1 L R S X + * 3/1 L R C S + * 2/2 L R LS RS + * 3/2 L R C LS RS X + * 3/2+lfe L R C LS RS lfe + * 3/4 L R C LS Rls Rrs RS X + * 3/4+lfe L R C LS Rls Rrs RS lfe + */ + +/** + * Parse the header of a LPCM frame read from a MPEG-TS stream + * @param avctx the codec context + * @param header pointer to the first four bytes of the data packet + */ +static int pcm_bluray_parse_header(AVCodecContext *avctx, + const uint8_t *header) +{ + static const uint8_t bits_per_samples[4] = { 0, 16, 20, 24 }; + static const uint32_t channel_layouts[16] = { + 0, CH_LAYOUT_MONO, 0, CH_LAYOUT_STEREO, CH_LAYOUT_SURROUND, + CH_LAYOUT_2_1, CH_LAYOUT_4POINT0, CH_LAYOUT_2_2, CH_LAYOUT_5POINT0, + CH_LAYOUT_5POINT1, CH_LAYOUT_7POINT0, CH_LAYOUT_7POINT1, 0, 0, 0, 0 + }; + static const uint8_t channels[16] = { + 0, 1, 0, 2, 3, 3, 4, 4, 5, 6, 7, 8, 0, 0, 0, 0 + }; + uint8_t channel_layout = header[2] >> 4; + + if (avctx->debug & FF_DEBUG_PICT_INFO) + dprintf(avctx, "pcm_bluray_parse_header: header = %02x%02x%02x%02x\n", + header[0], header[1], header[2], header[3]); + + /* get the sample depth and derive the sample format from it */ + avctx->bits_per_coded_sample = bits_per_samples[header[3] >> 6]; + if (!avctx->bits_per_coded_sample) { + av_log(avctx, AV_LOG_ERROR, "unsupported sample depth (0)\n"); + return -1; + } + avctx->sample_fmt = avctx->bits_per_coded_sample == 16 ? SAMPLE_FMT_S16 : + SAMPLE_FMT_S32; + + /* get the sample rate. Not all values are known or exist. */ + switch (header[2] & 0x0f) { + case 1: + avctx->sample_rate = 48000; + break; + case 4: + avctx->sample_rate = 96000; + break; + case 5: + avctx->sample_rate = 192000; + break; + default: + avctx->sample_rate = 0; + av_log(avctx, AV_LOG_ERROR, "unsupported sample rate (%d)\n", + header[2] & 0x0f); + return -1; + } + + /* + * get the channel number (and mapping). Not all values are known or exist. + * It must be noted that the number of channels in the MPEG stream can + * differ from the actual meaningful number, e.g. mono audio still has two + * channels, one being empty. + */ + avctx->channel_layout = channel_layouts[channel_layout]; + avctx->channels = channels[channel_layout]; + if (!avctx->channels) { + av_log(avctx, AV_LOG_ERROR, "unsupported channel configuration (%d)\n", + channel_layout); + return -1; + } + + avctx->bit_rate = avctx->channels * avctx->sample_rate * + avctx->bits_per_coded_sample; + + if (avctx->debug & FF_DEBUG_PICT_INFO) + dprintf(avctx, + "pcm_bluray_parse_header: %d channels, %d bits per sample, %d kHz, %d kbit\n", + avctx->channels, avctx->bits_per_coded_sample, + avctx->sample_rate, avctx->bit_rate); + return 0; +} + +static int pcm_bluray_decode_frame(AVCodecContext *avctx, + void *data, + int *data_size, + AVPacket *avpkt) +{ + const uint8_t *src = avpkt->data; + int buf_size = avpkt->size; + int num_source_channels, channel, retval; + int sample_size, samples, output_size; + int16_t *dst16 = data; + int32_t *dst32 = data; + + if (buf_size < 4) { + av_log(avctx, AV_LOG_ERROR, "PCM packet too small\n"); + return -1; + } + + if (pcm_bluray_parse_header(avctx, src)) + return -1; + src += 4; + buf_size -= 4; + + /* There's always an even number of channels in the source */ + num_source_channels = FFALIGN(avctx->channels, 2); + sample_size = (num_source_channels * avctx->bits_per_coded_sample) >> 3; + samples = buf_size / sample_size; + + output_size = samples * avctx->channels * + (avctx->sample_fmt == SAMPLE_FMT_S32 ? 4 : 2); + if (output_size > *data_size) { + av_log(avctx, AV_LOG_ERROR, + "Insufficient output buffer space (%d bytes, needed %d bytes)\n", + *data_size, output_size); + return -1; + } + *data_size = output_size; + + if (samples) { + switch (avctx->channel_layout) { + /* cases with same number of source and coded channels */ + case CH_LAYOUT_STEREO: + case CH_LAYOUT_4POINT0: + case CH_LAYOUT_2_2: + samples *= num_source_channels; + if (SAMPLE_FMT_S16 == avctx->sample_fmt) { +#if HAVE_BIGENDIAN + memcpy(dst16, src, output_size); +#else + do { + *dst16++ = bytestream_get_be16(&src); + } while (--samples); +#endif + } else { + do { + *dst32++ = bytestream_get_be24(&src) << 8; + } while (--samples); + } + break; + /* cases where number of source channels = coded channels + 1 */ + case CH_LAYOUT_MONO: + case CH_LAYOUT_SURROUND: + case CH_LAYOUT_2_1: + case CH_LAYOUT_5POINT0: + if (SAMPLE_FMT_S16 == avctx->sample_fmt) { + do { +#if HAVE_BIGENDIAN + memcpy(dst16, src, avctx->channels * 2); + dst16 += avctx->channels; + src += sample_size; +#else + channel = avctx->channels; + do { + *dst16++ = bytestream_get_be16(&src); + } while (--channel); + src += 2; +#endif + } while (--samples); + } else { + do { + channel = avctx->channels; + do { + *dst32++ = bytestream_get_be24(&src) << 8; + } while (--channel); + src += 3; + } while (--samples); + } + break; + /* remapping: L, R, C, LBack, RBack, LF */ + case CH_LAYOUT_5POINT1: + if (SAMPLE_FMT_S16 == avctx->sample_fmt) { + do { + dst16[0] = bytestream_get_be16(&src); + dst16[1] = bytestream_get_be16(&src); + dst16[2] = bytestream_get_be16(&src); + dst16[4] = bytestream_get_be16(&src); + dst16[5] = bytestream_get_be16(&src); + dst16[3] = bytestream_get_be16(&src); + dst16 += 6; + } while (--samples); + } else { + do { + dst32[0] = bytestream_get_be24(&src) << 8; + dst32[1] = bytestream_get_be24(&src) << 8; + dst32[2] = bytestream_get_be24(&src) << 8; + dst32[4] = bytestream_get_be24(&src) << 8; + dst32[5] = bytestream_get_be24(&src) << 8; + dst32[3] = bytestream_get_be24(&src) << 8; + dst32 += 6; + } while (--samples); + } + break; + /* remapping: L, R, C, LSide, LBack, RBack, RSide, */ + case CH_LAYOUT_7POINT0: + if (SAMPLE_FMT_S16 == avctx->sample_fmt) { + do { + dst16[0] = bytestream_get_be16(&src); + dst16[1] = bytestream_get_be16(&src); + dst16[2] = bytestream_get_be16(&src); + dst16[5] = bytestream_get_be16(&src); + dst16[3] = bytestream_get_be16(&src); + dst16[4] = bytestream_get_be16(&src); + dst16[6] = bytestream_get_be16(&src); + dst16 += 7; + src += 2; + } while (--samples); + } else { + do { + dst32[0] = bytestream_get_be24(&src) << 8; + dst32[1] = bytestream_get_be24(&src) << 8; + dst32[2] = bytestream_get_be24(&src) << 8; + dst32[5] = bytestream_get_be24(&src) << 8; + dst32[3] = bytestream_get_be24(&src) << 8; + dst32[4] = bytestream_get_be24(&src) << 8; + dst32[6] = bytestream_get_be24(&src) << 8; + dst32 += 7; + src += 3; + } while (--samples); + } + break; + /* remapping: L, R, C, LSide, LBack, RBack, RSide, LF */ + case CH_LAYOUT_7POINT1: + if (SAMPLE_FMT_S16 == avctx->sample_fmt) { + do { + dst16[0] = bytestream_get_be16(&src); + dst16[1] = bytestream_get_be16(&src); + dst16[2] = bytestream_get_be16(&src); + dst16[6] = bytestream_get_be16(&src); + dst16[4] = bytestream_get_be16(&src); + dst16[5] = bytestream_get_be16(&src); + dst16[7] = bytestream_get_be16(&src); + dst16[3] = bytestream_get_be16(&src); + dst16 += 8; + } while (--samples); + } else { + do { + dst32[0] = bytestream_get_be24(&src) << 8; + dst32[1] = bytestream_get_be24(&src) << 8; + dst32[2] = bytestream_get_be24(&src) << 8; + dst32[6] = bytestream_get_be24(&src) << 8; + dst32[4] = bytestream_get_be24(&src) << 8; + dst32[5] = bytestream_get_be24(&src) << 8; + dst32[7] = bytestream_get_be24(&src) << 8; + dst32[3] = bytestream_get_be24(&src) << 8; + dst32 += 8; + } while (--samples); + } + break; + } + } + + retval = src - avpkt->data; + if (avctx->debug & FF_DEBUG_BITSTREAM) + dprintf(avctx, "pcm_bluray_decode_frame: decoded %d -> %d bytes\n", + retval, *data_size); + return retval; +} + +AVCodec pcm_bluray_decoder = { + "pcm_bluray", + AVMEDIA_TYPE_AUDIO, + CODEC_ID_PCM_BLURAY, + 0, + NULL, + NULL, + NULL, + pcm_bluray_decode_frame, + .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16, SAMPLE_FMT_S32, + SAMPLE_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("PCM signed 16|20|24-bit big-endian for Blu-ray media"), +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/pcm.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/pcm.c index 8530cd689a..746a520256 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/pcm.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/pcm.c @@ -20,99 +20,26 @@ */ /** - * @file libavcodec/pcm.c + * @file * PCM codecs */ #include "avcodec.h" -#include "get_bits.h" // for ff_reverse +#include "libavutil/common.h" /* for av_reverse */ #include "bytestream.h" +#include "pcm_tablegen.h" #define MAX_CHANNELS 64 -/* from g711.c by SUN microsystems (unrestricted use) */ - -#define SIGN_BIT (0x80) /* Sign bit for a A-law byte. */ -#define QUANT_MASK (0xf) /* Quantization field mask. */ -#define NSEGS (8) /* Number of A-law segments. */ -#define SEG_SHIFT (4) /* Left shift for segment number. */ -#define SEG_MASK (0x70) /* Segment field mask. */ - -#define BIAS (0x84) /* Bias for linear code. */ - -/* - * alaw2linear() - Convert an A-law value to 16-bit linear PCM - * - */ -static av_cold int alaw2linear(unsigned char a_val) -{ - int t; - int seg; - - a_val ^= 0x55; - - t = a_val & QUANT_MASK; - seg = ((unsigned)a_val & SEG_MASK) >> SEG_SHIFT; - if(seg) t= (t + t + 1 + 32) << (seg + 2); - else t= (t + t + 1 ) << 3; - - return (a_val & SIGN_BIT) ? t : -t; -} - -static av_cold int ulaw2linear(unsigned char u_val) -{ - int t; - - /* Complement to obtain normal u-law value. */ - u_val = ~u_val; - - /* - * Extract and bias the quantization bits. Then - * shift up by the segment number and subtract out the bias. - */ - t = ((u_val & QUANT_MASK) << 3) + BIAS; - t <<= ((unsigned)u_val & SEG_MASK) >> SEG_SHIFT; - - return (u_val & SIGN_BIT) ? (BIAS - t) : (t - BIAS); -} - -/* 16384 entries per table */ -static uint8_t linear_to_alaw[16384]; -static uint8_t linear_to_ulaw[16384]; - -static av_cold void build_xlaw_table(uint8_t *linear_to_xlaw, - int (*xlaw2linear)(unsigned char), - int mask) -{ - int i, j, v, v1, v2; - - j = 0; - for(i=0;i<128;i++) { - if (i != 127) { - v1 = xlaw2linear(i ^ mask); - v2 = xlaw2linear((i + 1) ^ mask); - v = (v1 + v2 + 4) >> 3; - } else { - v = 8192; - } - for(;j 0) - linear_to_xlaw[8192 - j] = (i ^ (mask ^ 0x80)); - } - } - linear_to_xlaw[0] = linear_to_xlaw[1]; -} - static av_cold int pcm_encode_init(AVCodecContext *avctx) { avctx->frame_size = 1; switch(avctx->codec->id) { case CODEC_ID_PCM_ALAW: - build_xlaw_table(linear_to_alaw, alaw2linear, 0xd5); + pcm_alaw_tableinit(); break; case CODEC_ID_PCM_MULAW: - build_xlaw_table(linear_to_ulaw, ulaw2linear, 0xff); + pcm_ulaw_tableinit(); break; default: break; @@ -194,8 +121,8 @@ static int pcm_encode_frame(AVCodecContext *avctx, break; case CODEC_ID_PCM_S24DAUD: for(;n>0;n--) { - uint32_t tmp = ff_reverse[(*samples >> 8) & 0xff] + - (ff_reverse[*samples & 0xff] << 8); + uint32_t tmp = av_reverse[(*samples >> 8) & 0xff] + + (av_reverse[*samples & 0xff] << 8); tmp <<= 4; // sync flags would go here bytestream_put_be24(&dst, tmp); samples++; @@ -396,8 +323,8 @@ static int pcm_decode_frame(AVCodecContext *avctx, for(;n>0;n--) { uint32_t v = bytestream_get_be24(&src); v >>= 4; // sync flags are here - *samples++ = ff_reverse[(v >> 8) & 0xff] + - (ff_reverse[v & 0xff] << 8); + *samples++ = av_reverse[(v >> 8) & 0xff] + + (av_reverse[v & 0xff] << 8); } break; case CODEC_ID_PCM_S16LE_PLANAR: @@ -516,14 +443,14 @@ static int pcm_decode_frame(AVCodecContext *avctx, #define PCM_ENCODER(id,sample_fmt_,name,long_name_) \ AVCodec name ## _encoder = { \ #name, \ - CODEC_TYPE_AUDIO, \ + AVMEDIA_TYPE_AUDIO, \ id, \ 0, \ pcm_encode_init, \ pcm_encode_frame, \ pcm_encode_close, \ NULL, \ - .sample_fmts = (enum SampleFormat[]){sample_fmt_,SAMPLE_FMT_NONE}, \ + .sample_fmts = (const enum SampleFormat[]){sample_fmt_,SAMPLE_FMT_NONE}, \ .long_name = NULL_IF_CONFIG_SMALL(long_name_), \ }; #else @@ -534,14 +461,14 @@ AVCodec name ## _encoder = { \ #define PCM_DECODER(id,sample_fmt_,name,long_name_) \ AVCodec name ## _decoder = { \ #name, \ - CODEC_TYPE_AUDIO, \ + AVMEDIA_TYPE_AUDIO, \ id, \ sizeof(PCMDecode), \ pcm_decode_init, \ NULL, \ NULL, \ pcm_decode_frame, \ - .sample_fmts = (enum SampleFormat[]){sample_fmt_,SAMPLE_FMT_NONE}, \ + .sample_fmts = (const enum SampleFormat[]){sample_fmt_,SAMPLE_FMT_NONE}, \ .long_name = NULL_IF_CONFIG_SMALL(long_name_), \ }; #else diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/pcm_tablegen.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/pcm_tablegen.c new file mode 100644 index 0000000000..57ecb43dc6 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/pcm_tablegen.c @@ -0,0 +1,45 @@ +/* + * Generate a header file for hardcoded PCM tables + * + * Copyright (c) 2010 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 +#define CONFIG_HARDCODED_TABLES 0 +#include "pcm_tablegen.h" +#include "tableprint.h" + +int main(void) +{ + pcm_alaw_tableinit(); + pcm_ulaw_tableinit(); + + write_fileheader(); + + printf("static const uint8_t linear_to_alaw[1 << 14] = {\n"); + write_uint8_array(linear_to_alaw, 1 << 14); + printf("};\n"); + + printf("static const uint8_t linear_to_ulaw[1 << 14] = {\n"); + write_uint8_array(linear_to_ulaw, 1 << 14); + printf("};\n"); + + return 0; +} + diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/pcm_tablegen.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/pcm_tablegen.h new file mode 100644 index 0000000000..8921baaba2 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/pcm_tablegen.h @@ -0,0 +1,119 @@ +/* + * Header file for hardcoded PCM tables + * + * Copyright (c) 2010 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 + */ + +#ifndef PCM_TABLEGEN_H +#define PCM_TABLEGEN_H + +#include +#include "../libavutil/attributes.h" + +/* from g711.c by SUN microsystems (unrestricted use) */ + +#define SIGN_BIT (0x80) /* Sign bit for a A-law byte. */ +#define QUANT_MASK (0xf) /* Quantization field mask. */ +#define NSEGS (8) /* Number of A-law segments. */ +#define SEG_SHIFT (4) /* Left shift for segment number. */ +#define SEG_MASK (0x70) /* Segment field mask. */ + +#define BIAS (0x84) /* Bias for linear code. */ + +/* + * alaw2linear() - Convert an A-law value to 16-bit linear PCM + * + */ +static av_cold int alaw2linear(unsigned char a_val) +{ + int t; + int seg; + + a_val ^= 0x55; + + t = a_val & QUANT_MASK; + seg = ((unsigned)a_val & SEG_MASK) >> SEG_SHIFT; + if(seg) t= (t + t + 1 + 32) << (seg + 2); + else t= (t + t + 1 ) << 3; + + return (a_val & SIGN_BIT) ? t : -t; +} + +static av_cold int ulaw2linear(unsigned char u_val) +{ + int t; + + /* Complement to obtain normal u-law value. */ + u_val = ~u_val; + + /* + * Extract and bias the quantization bits. Then + * shift up by the segment number and subtract out the bias. + */ + t = ((u_val & QUANT_MASK) << 3) + BIAS; + t <<= ((unsigned)u_val & SEG_MASK) >> SEG_SHIFT; + + return (u_val & SIGN_BIT) ? (BIAS - t) : (t - BIAS); +} + +#if CONFIG_HARDCODED_TABLES +#define pcm_alaw_tableinit() +#define pcm_ulaw_tableinit() +#include "libavcodec/pcm_tables.h" +#else +/* 16384 entries per table */ +static uint8_t linear_to_alaw[16384]; +static uint8_t linear_to_ulaw[16384]; + +static av_cold void build_xlaw_table(uint8_t *linear_to_xlaw, + int (*xlaw2linear)(unsigned char), + int mask) +{ + int i, j, v, v1, v2; + + j = 0; + for(i=0;i<128;i++) { + if (i != 127) { + v1 = xlaw2linear(i ^ mask); + v2 = xlaw2linear((i + 1) ^ mask); + v = (v1 + v2 + 4) >> 3; + } else { + v = 8192; + } + for(;j 0) + linear_to_xlaw[8192 - j] = (i ^ (mask ^ 0x80)); + } + } + linear_to_xlaw[0] = linear_to_xlaw[1]; +} + +static void pcm_alaw_tableinit(void) +{ + build_xlaw_table(linear_to_alaw, alaw2linear, 0xd5); +} + +static void pcm_ulaw_tableinit(void) +{ + build_xlaw_table(linear_to_ulaw, ulaw2linear, 0xff); +} +#endif /* CONFIG_HARDCODED_TABLES */ + +#endif /* PCM_TABLEGEN_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/pcx.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/pcx.c index 43d7a5a028..2174184bce 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/pcx.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/pcx.c @@ -43,19 +43,24 @@ static av_cold int pcx_init(AVCodecContext *avctx) { * @return advanced src pointer */ static const uint8_t *pcx_rle_decode(const uint8_t *src, uint8_t *dst, - unsigned int bytes_per_scanline) { + unsigned int bytes_per_scanline, int compressed) { unsigned int i = 0; unsigned char run, value; - while (i= 0xc0) { - run = value & 0x3f; + if (compressed) { + while (i= 0xc0) { + run = value & 0x3f; + value = *src++; + } + while (ipriv_data; AVFrame *picture = data; AVFrame * const p = &s->picture; - int xmin, ymin, xmax, ymax; + int compressed, xmin, ymin, xmax, ymax; unsigned int w, h, bits_per_pixel, bytes_per_line, nplanes, stride, y, x, bytes_per_scanline; uint8_t *ptr; uint8_t const *bufstart = buf; - if (buf[0] != 0x0a || buf[1] > 5 || buf[1] == 1 || buf[2] != 1) { + if (buf[0] != 0x0a || buf[1] > 5) { av_log(avctx, AV_LOG_ERROR, "this is not PCX encoded data\n"); return -1; } + compressed = buf[2]; xmin = AV_RL16(buf+ 4); ymin = AV_RL16(buf+ 6); xmax = AV_RL16(buf+ 8); @@ -151,7 +158,7 @@ static int pcx_decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t scanline[bytes_per_scanline]; for (y=0; y> (x&7), v = 0; @@ -237,7 +244,7 @@ static av_cold int pcx_end(AVCodecContext *avctx) { AVCodec pcx_decoder = { "pcx", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_PCX, sizeof(PCXContext), pcx_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/pcxenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/pcxenc.c index 36f7d1d84c..a3ce284b5b 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/pcxenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/pcxenc.c @@ -21,7 +21,7 @@ /** * PCX image encoder - * @file libavcodec/pcxenc.c + * @file * @author Daniel Verkamp * @sa http://www.qzx.com/pc-gpe/pcx.txt */ @@ -191,13 +191,13 @@ static int pcx_encode_frame(AVCodecContext *avctx, AVCodec pcx_encoder = { "pcx", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_PCX, sizeof(PCXContext), pcx_encode_init, pcx_encode_frame, NULL, - .pix_fmts = (enum PixelFormat[]){ + .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, PIX_FMT_MONOBLACK, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/pgssubdec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/pgssubdec.c new file mode 100644 index 0000000000..5512006845 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/pgssubdec.c @@ -0,0 +1,465 @@ +/* + * PGS subtitle decoder + * Copyright (c) 2009 Stephen Backway + * + * 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 + * PGS subtitle decoder + */ + +#include "avcodec.h" +#include "dsputil.h" +#include "colorspace.h" +#include "bytestream.h" + +//#define DEBUG_PACKET_CONTENTS + +#define RGBA(r,g,b,a) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b)) + +enum SegmentType { + PALETTE_SEGMENT = 0x14, + PICTURE_SEGMENT = 0x15, + PRESENTATION_SEGMENT = 0x16, + WINDOW_SEGMENT = 0x17, + DISPLAY_SEGMENT = 0x80, +}; + +typedef struct PGSSubPresentation { + int x; + int y; + int video_w; + int video_h; + int id_number; +} PGSSubPresentation; + +typedef struct PGSSubPicture { + int w; + int h; + uint8_t *rle; + unsigned int rle_buffer_size, rle_data_len; +} PGSSubPicture; + +typedef struct PGSSubContext { + PGSSubPresentation presentation; + uint32_t clut[256]; + PGSSubPicture picture; +} PGSSubContext; + +static av_cold int init_decoder(AVCodecContext *avctx) +{ + avctx->pix_fmt = PIX_FMT_RGB32; + + return 0; +} + +static av_cold int close_decoder(AVCodecContext *avctx) +{ + PGSSubContext *ctx = avctx->priv_data; + + av_freep(&ctx->picture.rle); + ctx->picture.rle_buffer_size = 0; + + return 0; +} + +/** + * Decodes the RLE data. + * + * The subtitle is stored as an Run Length Encoded image. + * + * @param avctx contains the current codec context + * @param sub pointer to the processed subtitle data + * @param buf pointer to the RLE data to process + * @param buf_size size of the RLE data to process + */ +static int decode_rle(AVCodecContext *avctx, AVSubtitle *sub, + const uint8_t *buf, unsigned int buf_size) +{ + const uint8_t *rle_bitmap_end; + int pixel_count, line_count; + + rle_bitmap_end = buf + buf_size; + + sub->rects[0]->pict.data[0] = av_malloc(sub->rects[0]->w * sub->rects[0]->h); + + if (!sub->rects[0]->pict.data[0]) + return -1; + + pixel_count = 0; + line_count = 0; + + while (buf < rle_bitmap_end && line_count < sub->rects[0]->h) { + uint8_t flags, color; + int run; + + color = bytestream_get_byte(&buf); + run = 1; + + if (color == 0x00) { + flags = bytestream_get_byte(&buf); + run = flags & 0x3f; + if (flags & 0x40) + run = (run << 8) + bytestream_get_byte(&buf); + color = flags & 0x80 ? bytestream_get_byte(&buf) : 0; + } + + if (run > 0 && pixel_count + run <= sub->rects[0]->w * sub->rects[0]->h) { + memset(sub->rects[0]->pict.data[0] + pixel_count, color, run); + pixel_count += run; + } else if (!run) { + /* + * New Line. Check if correct pixels decoded, if not display warning + * and adjust bitmap pointer to correct new line position. + */ + if (pixel_count % sub->rects[0]->w > 0) + av_log(avctx, AV_LOG_ERROR, "Decoded %d pixels, when line should be %d pixels\n", + pixel_count % sub->rects[0]->w, sub->rects[0]->w); + line_count++; + } + } + + dprintf(avctx, "Pixel Count = %d, Area = %d\n", pixel_count, sub->rects[0]->w * sub->rects[0]->h); + + return 0; +} + +/** + * Parses the picture segment packet. + * + * The picture segment contains details on the sequence id, + * width, height and Run Length Encoded (RLE) bitmap data. + * + * @param avctx contains the current codec context + * @param buf pointer to the packet to process + * @param buf_size size of packet to process + * @todo TODO: Enable support for RLE data over multiple packets + */ +static int parse_picture_segment(AVCodecContext *avctx, + const uint8_t *buf, int buf_size) +{ + PGSSubContext *ctx = avctx->priv_data; + + uint8_t sequence_desc; + unsigned int rle_bitmap_len, width, height; + + /* skip 3 unknown bytes: Object ID (2 bytes), Version Number */ + buf += 3; + + /* Read the Sequence Description to determine if start of RLE data or appended to previous RLE */ + sequence_desc = bytestream_get_byte(&buf); + + if (!(sequence_desc & 0x80)) { + av_log(avctx, AV_LOG_ERROR, "Decoder does not support object data over multiple packets.\n"); + return -1; + } + + /* Decode rle bitmap length */ + rle_bitmap_len = bytestream_get_be24(&buf); + + /* Check to ensure we have enough data for rle_bitmap_length if just a single packet */ + if (rle_bitmap_len > buf_size - 7) { + av_log(avctx, AV_LOG_ERROR, "Not enough RLE data for specified length of %d.\n", rle_bitmap_len); + return -1; + } + + ctx->picture.rle_data_len = rle_bitmap_len; + + /* Get bitmap dimensions from data */ + width = bytestream_get_be16(&buf); + height = bytestream_get_be16(&buf); + + /* Make sure the bitmap is not too large */ + if (ctx->presentation.video_w < width || ctx->presentation.video_h < height) { + av_log(avctx, AV_LOG_ERROR, "Bitmap dimensions larger then video.\n"); + return -1; + } + + ctx->picture.w = width; + ctx->picture.h = height; + + av_fast_malloc(&ctx->picture.rle, &ctx->picture.rle_buffer_size, rle_bitmap_len); + + if (!ctx->picture.rle) + return -1; + + memcpy(ctx->picture.rle, buf, rle_bitmap_len); + + return 0; +} + +/** + * Parses the palette segment packet. + * + * The palette segment contains details of the palette, + * a maximum of 256 colors can be defined. + * + * @param avctx contains the current codec context + * @param buf pointer to the packet to process + * @param buf_size size of packet to process + */ +static void parse_palette_segment(AVCodecContext *avctx, + const uint8_t *buf, int buf_size) +{ + PGSSubContext *ctx = avctx->priv_data; + + const uint8_t *buf_end = buf + buf_size; + const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; + int color_id; + int y, cb, cr, alpha; + int r, g, b, r_add, g_add, b_add; + + /* Skip two null bytes */ + buf += 2; + + while (buf < buf_end) { + color_id = bytestream_get_byte(&buf); + y = bytestream_get_byte(&buf); + cb = bytestream_get_byte(&buf); + cr = bytestream_get_byte(&buf); + alpha = bytestream_get_byte(&buf); + + YUV_TO_RGB1(cb, cr); + YUV_TO_RGB2(r, g, b, y); + + dprintf(avctx, "Color %d := (%d,%d,%d,%d)\n", color_id, r, g, b, alpha); + + /* Store color in palette */ + ctx->clut[color_id] = RGBA(r,g,b,alpha); + } +} + +/** + * Parses the presentation segment packet. + * + * The presentation segment contains details on the video + * width, video height, x & y subtitle position. + * + * @param avctx contains the current codec context + * @param buf pointer to the packet to process + * @param buf_size size of packet to process + * @todo TODO: Implement cropping + * @todo TODO: Implement forcing of subtitles + * @todo TODO: Blanking of subtitle + */ +static void parse_presentation_segment(AVCodecContext *avctx, + const uint8_t *buf, int buf_size) +{ + PGSSubContext *ctx = avctx->priv_data; + + int x, y; + uint8_t block; + + ctx->presentation.video_w = bytestream_get_be16(&buf); + ctx->presentation.video_h = bytestream_get_be16(&buf); + + dprintf(avctx, "Video Dimensions %dx%d\n", + ctx->presentation.video_w, ctx->presentation.video_h); + + /* Skip 1 bytes of unknown, frame rate? */ + buf++; + + ctx->presentation.id_number = bytestream_get_be16(&buf); + + /* Next byte is the state. */ + block = bytestream_get_byte(&buf);; + if (block == 0x80) { + /* + * Skip 7 bytes of unknown: + * palette_update_flag (0x80), + * palette_id_to_use, + * Object Number (if > 0 determines if more data to process), + * object_id_ref (2 bytes), + * window_id_ref, + * composition_flag (0x80 - object cropped, 0x40 - object forced) + */ + buf += 7; + + x = bytestream_get_be16(&buf); + y = bytestream_get_be16(&buf); + + /* TODO If cropping, cropping_x, cropping_y, cropping_width, cropping_height (all 2 bytes).*/ + + dprintf(avctx, "Subtitle Placement x=%d, y=%d\n", x, y); + + if (x > ctx->presentation.video_w || y > ctx->presentation.video_h) { + av_log(avctx, AV_LOG_ERROR, "Subtitle out of video bounds. x = %d, y = %d, video width = %d, video height = %d.\n", + x, y, ctx->presentation.video_w, ctx->presentation.video_h); + x = 0; y = 0; + } + + /* Fill in dimensions */ + ctx->presentation.x = x; + ctx->presentation.y = y; + } else if (block == 0x00) { + /* TODO: Blank context as subtitle should not be displayed. + * If the subtitle is blanked now the subtitle is not + * on screen long enough to read, due to a delay in + * initial display timing. + */ + } +} + +/** + * Parses the display segment packet. + * + * The display segment controls the updating of the display. + * + * @param avctx contains the current codec context + * @param data pointer to the data pertaining the subtitle to display + * @param buf pointer to the packet to process + * @param buf_size size of packet to process + * @todo TODO: Fix start time, relies on correct PTS, currently too late + * + * @todo TODO: Fix end time, normally cleared by a second display + * @todo segment, which is currently ignored as it clears + * @todo the subtitle too early. + */ +static int display_end_segment(AVCodecContext *avctx, void *data, + const uint8_t *buf, int buf_size) +{ + AVSubtitle *sub = data; + PGSSubContext *ctx = avctx->priv_data; + + /* + * The end display time is a timeout value and is only reached + * if the next subtitle is later then timeout or subtitle has + * not been cleared by a subsequent empty display command. + */ + + memset(sub, 0, sizeof(*sub)); + sub->start_display_time = 0; + sub->end_display_time = 20000; + sub->format = 0; + + sub->rects = av_mallocz(sizeof(*sub->rects)); + sub->rects[0] = av_mallocz(sizeof(*sub->rects[0])); + sub->num_rects = 1; + + sub->rects[0]->x = ctx->presentation.x; + sub->rects[0]->y = ctx->presentation.y; + sub->rects[0]->w = ctx->picture.w; + sub->rects[0]->h = ctx->picture.h; + sub->rects[0]->type = SUBTITLE_BITMAP; + + /* Process bitmap */ + sub->rects[0]->pict.linesize[0] = ctx->picture.w; + + if (ctx->picture.rle) + if(decode_rle(avctx, sub, ctx->picture.rle, ctx->picture.rle_data_len) < 0) + return 0; + + /* Allocate memory for colors */ + sub->rects[0]->nb_colors = 256; + sub->rects[0]->pict.data[1] = av_mallocz(AVPALETTE_SIZE); + + memcpy(sub->rects[0]->pict.data[1], ctx->clut, sub->rects[0]->nb_colors * sizeof(uint32_t)); + + return 1; +} + +static int decode(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; + uint8_t segment_type; + int segment_length; + +#ifdef DEBUG_PACKET_CONTENTS + int i; + + av_log(avctx, AV_LOG_INFO, "PGS sub packet:\n"); + + for (i = 0; i < buf_size; i++) { + av_log(avctx, AV_LOG_INFO, "%02x ", buf[i]); + if (i % 16 == 15) + av_log(avctx, AV_LOG_INFO, "\n"); + } + + if (i & 15) + av_log(avctx, AV_LOG_INFO, "\n"); +#endif + + *data_size = 0; + + /* Ensure that we have received at a least a segment code and segment length */ + if (buf_size < 3) + return -1; + + buf_end = buf + buf_size; + + /* Step through buffer to identify segments */ + while (buf < buf_end) { + segment_type = bytestream_get_byte(&buf); + segment_length = bytestream_get_be16(&buf); + + dprintf(avctx, "Segment Length %d, Segment Type %x\n", segment_length, segment_type); + + if (segment_type != DISPLAY_SEGMENT && segment_length > buf_end - buf) + break; + + switch (segment_type) { + case PALETTE_SEGMENT: + parse_palette_segment(avctx, buf, segment_length); + break; + case PICTURE_SEGMENT: + parse_picture_segment(avctx, buf, segment_length); + break; + case PRESENTATION_SEGMENT: + parse_presentation_segment(avctx, buf, segment_length); + break; + case WINDOW_SEGMENT: + /* + * Window Segment Structure (No new information provided): + * 2 bytes: Unkown, + * 2 bytes: X position of subtitle, + * 2 bytes: Y position of subtitle, + * 2 bytes: Width of subtitle, + * 2 bytes: Height of subtitle. + */ + break; + case DISPLAY_SEGMENT: + *data_size = display_end_segment(avctx, data, buf, segment_length); + break; + default: + av_log(avctx, AV_LOG_ERROR, "Unknown subtitle segment type 0x%x, length %d\n", + segment_type, segment_length); + break; + } + + buf += segment_length; + } + + return buf_size; +} + +AVCodec pgssub_decoder = { + "pgssub", + AVMEDIA_TYPE_SUBTITLE, + CODEC_ID_HDMV_PGS_SUBTITLE, + sizeof(PGSSubContext), + init_decoder, + NULL, + close_decoder, + decode, + .long_name = NULL_IF_CONFIG_SMALL("HDMV Presentation Graphic Stream subtitles"), +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/png.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/png.h index 97e81f5628..7c0ab9f6c6 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/png.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/png.h @@ -73,4 +73,6 @@ int ff_png_get_nb_channels(int color_type); /* compute the row size of an interleaved pass */ 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); + #endif /* AVCODEC_PNG_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/pngdec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/pngdec.c index 29644f5095..03859a9913 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/pngdec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/pngdec.c @@ -489,6 +489,8 @@ static int decode_frame(AVCodecContext *avctx, 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; } else { goto fail; } @@ -599,7 +601,7 @@ static int decode_frame(AVCodecContext *avctx, exit_loop: /* handle p-frames only if a predecessor frame is available */ if(s->last_picture->data[0] != NULL) { - if(!(avpkt->flags & PKT_FLAG_KEY)) { + if(!(avpkt->flags & AV_PKT_FLAG_KEY)) { int i, j; uint8_t *pd = s->current_picture->data[0]; uint8_t *pd_last = s->last_picture->data[0]; @@ -642,14 +644,26 @@ static av_cold int png_dec_init(AVCodecContext *avctx){ return 0; } +static av_cold int png_dec_end(AVCodecContext *avctx) +{ + PNGDecContext *s = avctx->priv_data; + + if (s->picture1.data[0]) + avctx->release_buffer(avctx, &s->picture1); + if (s->picture2.data[0]) + avctx->release_buffer(avctx, &s->picture2); + + return 0; +} + AVCodec png_decoder = { "png", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_PNG, sizeof(PNGDecContext), png_dec_init, NULL, - NULL, //decode_end, + png_dec_end, decode_frame, CODEC_CAP_DR1 /*| CODEC_CAP_DRAW_HORIZ_BAND*/, NULL, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/pngenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/pngenc.c index 40dadc863b..615bcc44cc 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/pngenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/pngenc.c @@ -438,12 +438,12 @@ static av_cold int png_enc_init(AVCodecContext *avctx){ AVCodec png_encoder = { "png", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_PNG, sizeof(PNGEncContext), png_enc_init, encode_frame, NULL, //encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB32, PIX_FMT_PAL8, PIX_FMT_GRAY8, PIX_FMT_MONOBLACK, PIX_FMT_NONE}, + .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/src/add-ons/media/plugins/ffmpeg/libavcodec/pnm.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/pnm.c index 134e9f6065..cb6a7139f2 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/pnm.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/pnm.c @@ -18,6 +18,7 @@ * 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 "pnm.h" @@ -32,10 +33,10 @@ static void pnm_get(PNMContext *sc, char *str, int buf_size) int c; /* skip spaces and comments */ - for(;;) { + for (;;) { c = *sc->bytestream++; if (c == '#') { - do { + do { c = *sc->bytestream++; } while (c != '\n' && sc->bytestream < sc->bytestream_end); } else if (!pnm_space(c)) { @@ -52,27 +53,32 @@ static void pnm_get(PNMContext *sc, char *str, int buf_size) *s = '\0'; } -int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s){ +int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) +{ char buf1[32], tuple_type[32]; int h, w, depth, maxval; pnm_get(s, buf1, sizeof(buf1)); - if (!strcmp(buf1, "P4")) { + s->type= buf1[1]-'0'; + if(buf1[0] != 'P') + return -1; + + if (s->type==1 || s->type==4) { avctx->pix_fmt = PIX_FMT_MONOWHITE; - } else if (!strcmp(buf1, "P5")) { + } else if (s->type==2 || s->type==5) { if (avctx->codec_id == CODEC_ID_PGMYUV) avctx->pix_fmt = PIX_FMT_YUV420P; else avctx->pix_fmt = PIX_FMT_GRAY8; - } else if (!strcmp(buf1, "P6")) { + } else if (s->type==3 || s->type==6) { avctx->pix_fmt = PIX_FMT_RGB24; - } else if (!strcmp(buf1, "P7")) { - w = -1; - h = -1; + } else if (s->type==7) { + w = -1; + h = -1; maxval = -1; - depth = -1; + depth = -1; tuple_type[0] = '\0'; - for(;;) { + for (;;) { pnm_get(s, buf1, sizeof(buf1)); if (!strcmp(buf1, "WIDTH")) { pnm_get(s, buf1, sizeof(buf1)); @@ -98,7 +104,7 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s){ if (w <= 0 || h <= 0 || maxval <= 0 || depth <= 0 || tuple_type[0] == '\0' || avcodec_check_dimensions(avctx, w, h)) return -1; - avctx->width = w; + avctx->width = w; avctx->height = h; if (depth == 1) { if (maxval == 1) @@ -147,7 +153,8 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s){ return -1; } } - } + }else + s->maxval=1; /* more check if YUV420 */ if (avctx->pix_fmt == PIX_FMT_YUV420P) { if ((avctx->width & 1) != 0) @@ -160,3 +167,23 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s){ } return 0; } + +av_cold int ff_pnm_end(AVCodecContext *avctx) +{ + PNMContext *s = avctx->priv_data; + + if (s->picture.data[0]) + avctx->release_buffer(avctx, &s->picture); + + return 0; +} + +av_cold int ff_pnm_init(AVCodecContext *avctx) +{ + PNMContext *s = avctx->priv_data; + + avcodec_get_frame_defaults((AVFrame*)&s->picture); + avctx->coded_frame = (AVFrame*)&s->picture; + + return 0; +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/pnm.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/pnm.h index ef0cd8676e..ac4b1084fb 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/pnm.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/pnm.h @@ -30,8 +30,11 @@ typedef struct PNMContext { uint8_t *bytestream_end; AVFrame picture; int maxval; ///< maximum value of a pixel + int type; } PNMContext; int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s); +av_cold int ff_pnm_end(AVCodecContext *avctx); +av_cold int ff_pnm_init(AVCodecContext *avctx); #endif /* AVCODEC_PNM_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/pnm_parser.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/pnm_parser.c index 687f0ca6de..b8ba1a836c 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/pnm_parser.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/pnm_parser.c @@ -23,63 +23,62 @@ #include "pnm.h" -static int pnm_parse(AVCodecParserContext *s, - AVCodecContext *avctx, - const uint8_t **poutbuf, int *poutbuf_size, - const uint8_t *buf, int buf_size) +static int pnm_parse(AVCodecParserContext *s, AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) { ParseContext *pc = s->priv_data; PNMContext pnmctx; int next; - for(; pc->overread>0; pc->overread--){ + for (; pc->overread > 0; pc->overread--) { pc->buffer[pc->index++]= pc->buffer[pc->overread_index++]; } retry: - if(pc->index){ - pnmctx.bytestream_start= - pnmctx.bytestream= pc->buffer; - pnmctx.bytestream_end= pc->buffer + pc->index; - }else{ - pnmctx.bytestream_start= - pnmctx.bytestream= (uint8_t *) buf; /* casts avoid warnings */ - pnmctx.bytestream_end= (uint8_t *) buf + buf_size; + if (pc->index) { + pnmctx.bytestream_start = + pnmctx.bytestream = pc->buffer; + pnmctx.bytestream_end = pc->buffer + pc->index; + } else { + pnmctx.bytestream_start = + pnmctx.bytestream = (uint8_t *) buf; /* casts avoid warnings */ + pnmctx.bytestream_end = (uint8_t *) buf + buf_size; } - if(ff_pnm_decode_header(avctx, &pnmctx) < 0){ - if(pnmctx.bytestream < pnmctx.bytestream_end){ - if(pc->index){ - pc->index=0; - }else{ + if (ff_pnm_decode_header(avctx, &pnmctx) < 0) { + if (pnmctx.bytestream < pnmctx.bytestream_end) { + if (pc->index) { + pc->index = 0; + } else { buf++; buf_size--; } goto retry; } #if 0 - if(pc->index && pc->index*2 + FF_INPUT_BUFFER_PADDING_SIZE < pc->buffer_size && buf_size > pc->index){ + if (pc->index && pc->index * 2 + FF_INPUT_BUFFER_PADDING_SIZE < pc->buffer_size && buf_size > pc->index) { memcpy(pc->buffer + pc->index, buf, pc->index); pc->index += pc->index; - buf += pc->index; - buf_size -= pc->index; + buf += pc->index; + buf_size -= pc->index; goto retry; } #endif - next= END_NOT_FOUND; - }else{ - next= pnmctx.bytestream - pnmctx.bytestream_start - + avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height); - if(pnmctx.bytestream_start!=buf) - next-= pc->index; - if(next > buf_size) - next= END_NOT_FOUND; + next = END_NOT_FOUND; + } else { + next = pnmctx.bytestream - pnmctx.bytestream_start + + avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height); + if (pnmctx.bytestream_start != buf) + next -= pc->index; + if (next > buf_size) + next = END_NOT_FOUND; } - if(ff_combine_frame(pc, next, &buf, &buf_size)<0){ - *poutbuf = NULL; + if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { + *poutbuf = NULL; *poutbuf_size = 0; return buf_size; } - *poutbuf = buf; + *poutbuf = buf; *poutbuf_size = buf_size; return next; } diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/pnmdec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/pnmdec.c new file mode 100644 index 0000000000..66033c1f4e --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/pnmdec.c @@ -0,0 +1,268 @@ +/* + * PNM image format + * Copyright (c) 2002, 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 "avcodec.h" +#include "bytestream.h" +#include "put_bits.h" +#include "pnm.h" + + +static int pnm_decode_frame(AVCodecContext *avctx, void *data, + int *data_size, AVPacket *avpkt) +{ + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + PNMContext * const s = avctx->priv_data; + AVFrame *picture = data; + AVFrame * const p = (AVFrame*)&s->picture; + int i, j, n, linesize, h, upgrade = 0; + unsigned char *ptr; + int components, sample_len; + + s->bytestream_start = + s->bytestream = buf; + s->bytestream_end = buf + buf_size; + + if (ff_pnm_decode_header(avctx, s) < 0) + return -1; + + if (p->data[0]) + avctx->release_buffer(avctx, p); + + p->reference = 0; + if (avctx->get_buffer(avctx, p) < 0) { + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } + p->pict_type = FF_I_TYPE; + p->key_frame = 1; + + switch (avctx->pix_fmt) { + default: + return -1; + case PIX_FMT_RGB48BE: + n = avctx->width * 6; + components=3; + sample_len=16; + goto do_read; + case PIX_FMT_RGB24: + n = avctx->width * 3; + components=3; + sample_len=8; + goto do_read; + case PIX_FMT_GRAY8: + n = avctx->width; + components=1; + sample_len=8; + if (s->maxval < 255) + upgrade = 1; + goto do_read; + case PIX_FMT_GRAY16BE: + case PIX_FMT_GRAY16LE: + n = avctx->width * 2; + components=1; + sample_len=16; + if (s->maxval < 65535) + upgrade = 2; + goto do_read; + case PIX_FMT_MONOWHITE: + case PIX_FMT_MONOBLACK: + n = (avctx->width + 7) >> 3; + components=1; + sample_len=1; + do_read: + ptr = p->data[0]; + linesize = p->linesize[0]; + if (s->bytestream + n * avctx->height > s->bytestream_end) + return -1; + if(s->type < 4){ + for (i=0; iheight; i++) { + PutBitContext pb; + init_put_bits(&pb, ptr, linesize); + for(j=0; jwidth * components; j++){ + unsigned int c=0; + int v=0; + while(s->bytestream < s->bytestream_end && (*s->bytestream < '0' || *s->bytestream > '9' )) + s->bytestream++; + if(s->bytestream >= s->bytestream_end) + return -1; + do{ + v= 10*v + c; + c= (*s->bytestream++) - '0'; + }while(c <= 9); + put_bits(&pb, sample_len, (((1<maxval>>1))/s->maxval); + } + flush_put_bits(&pb); + ptr+= linesize; + } + }else{ + for (i = 0; i < avctx->height; i++) { + if (!upgrade) + memcpy(ptr, s->bytestream, n); + else if (upgrade == 1) { + unsigned int j, f = (255 * 128 + s->maxval / 2) / s->maxval; + for (j = 0; j < n; j++) + ptr[j] = (s->bytestream[j] * f + 64) >> 7; + } else if (upgrade == 2) { + unsigned int j, v, f = (65535 * 32768 + s->maxval / 2) / s->maxval; + for (j = 0; j < n / 2; j++) { + v = be2me_16(((uint16_t *)s->bytestream)[j]); + ((uint16_t *)ptr)[j] = (v * f + 16384) >> 15; + } + } + s->bytestream += n; + ptr += linesize; + } + } + break; + case PIX_FMT_YUV420P: + { + unsigned char *ptr1, *ptr2; + + n = avctx->width; + ptr = p->data[0]; + linesize = p->linesize[0]; + if (s->bytestream + n * avctx->height * 3 / 2 > s->bytestream_end) + return -1; + for (i = 0; i < avctx->height; i++) { + memcpy(ptr, s->bytestream, n); + s->bytestream += n; + ptr += linesize; + } + ptr1 = p->data[1]; + ptr2 = p->data[2]; + n >>= 1; + h = avctx->height >> 1; + for (i = 0; i < h; i++) { + memcpy(ptr1, s->bytestream, n); + s->bytestream += n; + memcpy(ptr2, s->bytestream, n); + s->bytestream += n; + ptr1 += p->linesize[1]; + ptr2 += p->linesize[2]; + } + } + break; + case PIX_FMT_RGB32: + ptr = p->data[0]; + linesize = p->linesize[0]; + if (s->bytestream + avctx->width * avctx->height * 4 > s->bytestream_end) + return -1; + for (i = 0; i < avctx->height; i++) { + int j, r, g, b, a; + + for (j = 0; j < avctx->width; j++) { + r = *s->bytestream++; + g = *s->bytestream++; + b = *s->bytestream++; + a = *s->bytestream++; + ((uint32_t *)ptr)[j] = (a << 24) | (r << 16) | (g << 8) | b; + } + ptr += linesize; + } + break; + } + *picture = *(AVFrame*)&s->picture; + *data_size = sizeof(AVPicture); + + return s->bytestream - s->bytestream_start; +} + + +#if CONFIG_PGM_DECODER +AVCodec pgm_decoder = { + "pgm", + AVMEDIA_TYPE_VIDEO, + CODEC_ID_PGM, + sizeof(PNMContext), + ff_pnm_init, + NULL, + ff_pnm_end, + pnm_decode_frame, + CODEC_CAP_DR1, + .pix_fmts = (const enum PixelFormat[]){PIX_FMT_GRAY8, PIX_FMT_GRAY16BE, PIX_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("PGM (Portable GrayMap) image"), +}; +#endif + +#if CONFIG_PGMYUV_DECODER +AVCodec pgmyuv_decoder = { + "pgmyuv", + AVMEDIA_TYPE_VIDEO, + CODEC_ID_PGMYUV, + sizeof(PNMContext), + ff_pnm_init, + NULL, + ff_pnm_end, + pnm_decode_frame, + CODEC_CAP_DR1, + .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("PGMYUV (Portable GrayMap YUV) image"), +}; +#endif + +#if CONFIG_PPM_DECODER +AVCodec ppm_decoder = { + "ppm", + AVMEDIA_TYPE_VIDEO, + CODEC_ID_PPM, + sizeof(PNMContext), + ff_pnm_init, + NULL, + ff_pnm_end, + pnm_decode_frame, + CODEC_CAP_DR1, + .pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB48BE, PIX_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("PPM (Portable PixelMap) image"), +}; +#endif + +#if CONFIG_PBM_DECODER +AVCodec pbm_decoder = { + "pbm", + AVMEDIA_TYPE_VIDEO, + CODEC_ID_PBM, + sizeof(PNMContext), + ff_pnm_init, + NULL, + ff_pnm_end, + pnm_decode_frame, + CODEC_CAP_DR1, + .pix_fmts = (const enum PixelFormat[]){PIX_FMT_MONOWHITE, PIX_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("PBM (Portable BitMap) image"), +}; +#endif + +#if CONFIG_PAM_DECODER +AVCodec pam_decoder = { + "pam", + AVMEDIA_TYPE_VIDEO, + CODEC_ID_PAM, + sizeof(PNMContext), + ff_pnm_init, + NULL, + ff_pnm_end, + pnm_decode_frame, + CODEC_CAP_DR1, + .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"), +}; +#endif diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/pnmenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/pnmenc.c index c60e4da2c0..1fbf665883 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/pnmenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/pnmenc.c @@ -18,203 +18,67 @@ * 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 "bytestream.h" #include "pnm.h" -static av_cold int common_init(AVCodecContext *avctx){ - PNMContext *s = avctx->priv_data; - - avcodec_get_frame_defaults((AVFrame*)&s->picture); - avctx->coded_frame= (AVFrame*)&s->picture; - - return 0; -} - -static int pnm_decode_frame(AVCodecContext *avctx, - void *data, int *data_size, - AVPacket *avpkt) +static int pnm_encode_frame(AVCodecContext *avctx, unsigned char *outbuf, + int buf_size, void *data) { - const uint8_t *buf = avpkt->data; - int buf_size = avpkt->size; - PNMContext * const s = avctx->priv_data; - AVFrame *picture = data; - AVFrame * const p= (AVFrame*)&s->picture; - int i, n, linesize, h, upgrade = 0; - unsigned char *ptr; - - s->bytestream_start= - s->bytestream= buf; - s->bytestream_end= buf + buf_size; - - if(ff_pnm_decode_header(avctx, s) < 0) - return -1; - - if(p->data[0]) - avctx->release_buffer(avctx, p); - - p->reference= 0; - if(avctx->get_buffer(avctx, p) < 0){ - av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; - } - p->pict_type= FF_I_TYPE; - p->key_frame= 1; - - switch(avctx->pix_fmt) { - default: - return -1; - case PIX_FMT_RGB48BE: - n = avctx->width * 6; - goto do_read; - case PIX_FMT_RGB24: - n = avctx->width * 3; - goto do_read; - case PIX_FMT_GRAY8: - n = avctx->width; - if (s->maxval < 255) - upgrade = 1; - goto do_read; - case PIX_FMT_GRAY16BE: - case PIX_FMT_GRAY16LE: - n = avctx->width * 2; - if (s->maxval < 65535) - upgrade = 2; - goto do_read; - case PIX_FMT_MONOWHITE: - case PIX_FMT_MONOBLACK: - n = (avctx->width + 7) >> 3; - do_read: - ptr = p->data[0]; - linesize = p->linesize[0]; - if(s->bytestream + n*avctx->height > s->bytestream_end) - return -1; - for(i = 0; i < avctx->height; i++) { - if (!upgrade) - memcpy(ptr, s->bytestream, n); - else if (upgrade == 1) { - unsigned int j, f = (255*128 + s->maxval/2) / s->maxval; - for (j=0; jbytestream[j] * f + 64) >> 7; - } else if (upgrade == 2) { - unsigned int j, v, f = (65535*32768 + s->maxval/2) / s->maxval; - for (j=0; jbytestream)[j]); - ((uint16_t *)ptr)[j] = (v * f + 16384) >> 15; - } - } - s->bytestream += n; - ptr += linesize; - } - break; - case PIX_FMT_YUV420P: - { - unsigned char *ptr1, *ptr2; - - n = avctx->width; - ptr = p->data[0]; - linesize = p->linesize[0]; - if(s->bytestream + n*avctx->height*3/2 > s->bytestream_end) - return -1; - for(i = 0; i < avctx->height; i++) { - memcpy(ptr, s->bytestream, n); - s->bytestream += n; - ptr += linesize; - } - ptr1 = p->data[1]; - ptr2 = p->data[2]; - n >>= 1; - h = avctx->height >> 1; - for(i = 0; i < h; i++) { - memcpy(ptr1, s->bytestream, n); - s->bytestream += n; - memcpy(ptr2, s->bytestream, n); - s->bytestream += n; - ptr1 += p->linesize[1]; - ptr2 += p->linesize[2]; - } - } - break; - case PIX_FMT_RGB32: - ptr = p->data[0]; - linesize = p->linesize[0]; - if(s->bytestream + avctx->width*avctx->height*4 > s->bytestream_end) - return -1; - for(i = 0; i < avctx->height; i++) { - int j, r, g, b, a; - - for(j = 0;j < avctx->width; j++) { - r = *s->bytestream++; - g = *s->bytestream++; - b = *s->bytestream++; - a = *s->bytestream++; - ((uint32_t *)ptr)[j] = (a << 24) | (r << 16) | (g << 8) | b; - } - ptr += linesize; - } - break; - } - *picture= *(AVFrame*)&s->picture; - *data_size = sizeof(AVPicture); - - return s->bytestream - s->bytestream_start; -} - -static int pnm_encode_frame(AVCodecContext *avctx, unsigned char *outbuf, int buf_size, void *data){ - PNMContext *s = avctx->priv_data; - AVFrame *pict = data; - AVFrame * const p= (AVFrame*)&s->picture; + PNMContext *s = avctx->priv_data; + AVFrame *pict = data; + AVFrame * const p = (AVFrame*)&s->picture; int i, h, h1, c, n, linesize; uint8_t *ptr, *ptr1, *ptr2; - if(buf_size < avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height) + 200){ + if (buf_size < avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height) + 200) { av_log(avctx, AV_LOG_ERROR, "encoded frame too large\n"); return -1; } - *p = *pict; - p->pict_type= FF_I_TYPE; - p->key_frame= 1; + *p = *pict; + p->pict_type = FF_I_TYPE; + p->key_frame = 1; - s->bytestream_start= - s->bytestream= outbuf; - s->bytestream_end= outbuf+buf_size; + s->bytestream_start = + s->bytestream = outbuf; + s->bytestream_end = outbuf + buf_size; - h = avctx->height; + h = avctx->height; h1 = h; - switch(avctx->pix_fmt) { + switch (avctx->pix_fmt) { case PIX_FMT_MONOWHITE: - c = '4'; - n = (avctx->width + 7) >> 3; + c = '4'; + n = (avctx->width + 7) >> 3; break; case PIX_FMT_GRAY8: - c = '5'; - n = avctx->width; + c = '5'; + n = avctx->width; break; case PIX_FMT_GRAY16BE: - c = '5'; - n = avctx->width * 2; + c = '5'; + n = avctx->width * 2; break; case PIX_FMT_RGB24: - c = '6'; - n = avctx->width * 3; + c = '6'; + n = avctx->width * 3; break; case PIX_FMT_RGB48BE: - c = '6'; - n = avctx->width * 6; + c = '6'; + n = avctx->width * 6; break; case PIX_FMT_YUV420P: - c = '5'; - n = avctx->width; + c = '5'; + n = avctx->width; h1 = (h * 3) / 2; break; default: return -1; } snprintf(s->bytestream, s->bytestream_end - s->bytestream, - "P%c\n%d %d\n", - c, avctx->width, h1); + "P%c\n%d %d\n", c, avctx->width, h1); s->bytestream += strlen(s->bytestream); if (avctx->pix_fmt != PIX_FMT_MONOWHITE) { snprintf(s->bytestream, s->bytestream_end - s->bytestream, @@ -222,12 +86,12 @@ static int pnm_encode_frame(AVCodecContext *avctx, unsigned char *outbuf, int bu s->bytestream += strlen(s->bytestream); } - ptr = p->data[0]; + ptr = p->data[0]; linesize = p->linesize[0]; - for(i=0;ibytestream, ptr, n); s->bytestream += n; - ptr += linesize; + ptr += linesize; } if (avctx->pix_fmt == PIX_FMT_YUV420P) { @@ -235,7 +99,7 @@ static int pnm_encode_frame(AVCodecContext *avctx, unsigned char *outbuf, int bu n >>= 1; ptr1 = p->data[1]; ptr2 = p->data[2]; - for(i=0;ibytestream, ptr1, n); s->bytestream += n; memcpy(s->bytestream, ptr2, n); @@ -247,263 +111,55 @@ static int pnm_encode_frame(AVCodecContext *avctx, unsigned char *outbuf, int bu return s->bytestream - s->bytestream_start; } -static int pam_encode_frame(AVCodecContext *avctx, unsigned char *outbuf, int buf_size, void *data){ - PNMContext *s = avctx->priv_data; - AVFrame *pict = data; - AVFrame * const p= (AVFrame*)&s->picture; - int i, h, w, n, linesize, depth, maxval; - const char *tuple_type; - uint8_t *ptr; - - if(buf_size < avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height) + 200){ - av_log(avctx, AV_LOG_ERROR, "encoded frame too large\n"); - return -1; - } - - *p = *pict; - p->pict_type= FF_I_TYPE; - p->key_frame= 1; - - s->bytestream_start= - s->bytestream= outbuf; - s->bytestream_end= outbuf+buf_size; - - h = avctx->height; - w = avctx->width; - switch(avctx->pix_fmt) { - case PIX_FMT_MONOWHITE: - n = (w + 7) >> 3; - depth = 1; - maxval = 1; - tuple_type = "BLACKANDWHITE"; - break; - case PIX_FMT_GRAY8: - n = w; - depth = 1; - maxval = 255; - tuple_type = "GRAYSCALE"; - break; - case PIX_FMT_RGB24: - n = w * 3; - depth = 3; - maxval = 255; - tuple_type = "RGB"; - break; - case PIX_FMT_RGB32: - n = w * 4; - depth = 4; - maxval = 255; - tuple_type = "RGB_ALPHA"; - break; - default: - return -1; - } - snprintf(s->bytestream, s->bytestream_end - s->bytestream, - "P7\nWIDTH %d\nHEIGHT %d\nDEPTH %d\nMAXVAL %d\nTUPLETYPE %s\nENDHDR\n", - w, h, depth, maxval, tuple_type); - s->bytestream += strlen(s->bytestream); - - ptr = p->data[0]; - linesize = p->linesize[0]; - - if (avctx->pix_fmt == PIX_FMT_RGB32) { - int j; - unsigned int v; - - for(i=0;ibytestream, v); - *s->bytestream++ = v >> 24; - } - ptr += linesize; - } - } else { - for(i=0;ibytestream, ptr, n); - s->bytestream += n; - ptr += linesize; - } - } - return s->bytestream - s->bytestream_start; -} - -#if 0 -static int pnm_probe(AVProbeData *pd) -{ - const char *p = pd->buf; - if (pd->buf_size >= 8 && - p[0] == 'P' && - p[1] >= '4' && p[1] <= '6' && - pnm_space(p[2]) ) - return AVPROBE_SCORE_MAX - 1; /* to permit pgmyuv probe */ - else - return 0; -} - -static int pgmyuv_probe(AVProbeData *pd) -{ - if (match_ext(pd->filename, "pgmyuv")) - return AVPROBE_SCORE_MAX; - else - return 0; -} - -static int pam_probe(AVProbeData *pd) -{ - const char *p = pd->buf; - if (pd->buf_size >= 8 && - p[0] == 'P' && - p[1] == '7' && - p[2] == '\n') - return AVPROBE_SCORE_MAX; - else - return 0; -} -#endif - - -#if CONFIG_PGM_DECODER -AVCodec pgm_decoder = { - "pgm", - CODEC_TYPE_VIDEO, - CODEC_ID_PGM, - sizeof(PNMContext), - common_init, - NULL, - NULL, - pnm_decode_frame, - CODEC_CAP_DR1, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_GRAY8, PIX_FMT_GRAY16BE, PIX_FMT_NONE}, - .long_name= NULL_IF_CONFIG_SMALL("PGM (Portable GrayMap) image"), -}; -#endif #if CONFIG_PGM_ENCODER AVCodec pgm_encoder = { "pgm", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_PGM, sizeof(PNMContext), - common_init, + ff_pnm_init, pnm_encode_frame, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_GRAY8, PIX_FMT_GRAY16BE, PIX_FMT_NONE}, - .long_name= NULL_IF_CONFIG_SMALL("PGM (Portable GrayMap) image"), -}; -#endif // CONFIG_PGM_ENCODER - -#if CONFIG_PGMYUV_DECODER -AVCodec pgmyuv_decoder = { - "pgmyuv", - CODEC_TYPE_VIDEO, - CODEC_ID_PGMYUV, - sizeof(PNMContext), - common_init, - NULL, - NULL, - pnm_decode_frame, - CODEC_CAP_DR1, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, - .long_name= NULL_IF_CONFIG_SMALL("PGMYUV (Portable GrayMap YUV) image"), + .pix_fmts = (const enum PixelFormat[]){PIX_FMT_GRAY8, PIX_FMT_GRAY16BE, PIX_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("PGM (Portable GrayMap) image"), }; #endif #if CONFIG_PGMYUV_ENCODER AVCodec pgmyuv_encoder = { "pgmyuv", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_PGMYUV, sizeof(PNMContext), - common_init, + ff_pnm_init, pnm_encode_frame, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, - .long_name= NULL_IF_CONFIG_SMALL("PGMYUV (Portable GrayMap YUV) image"), -}; -#endif // CONFIG_PGMYUV_ENCODER - -#if CONFIG_PPM_DECODER -AVCodec ppm_decoder = { - "ppm", - CODEC_TYPE_VIDEO, - CODEC_ID_PPM, - sizeof(PNMContext), - common_init, - NULL, - NULL, - pnm_decode_frame, - CODEC_CAP_DR1, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB48BE, PIX_FMT_NONE}, - .long_name= NULL_IF_CONFIG_SMALL("PPM (Portable PixelMap) image"), + .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("PGMYUV (Portable GrayMap YUV) image"), }; #endif #if CONFIG_PPM_ENCODER AVCodec ppm_encoder = { "ppm", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_PPM, sizeof(PNMContext), - common_init, + ff_pnm_init, pnm_encode_frame, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB48BE, PIX_FMT_NONE}, - .long_name= NULL_IF_CONFIG_SMALL("PPM (Portable PixelMap) image"), -}; -#endif // CONFIG_PPM_ENCODER - -#if CONFIG_PBM_DECODER -AVCodec pbm_decoder = { - "pbm", - CODEC_TYPE_VIDEO, - CODEC_ID_PBM, - sizeof(PNMContext), - common_init, - NULL, - NULL, - pnm_decode_frame, - CODEC_CAP_DR1, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_MONOWHITE, PIX_FMT_NONE}, - .long_name= NULL_IF_CONFIG_SMALL("PBM (Portable BitMap) image"), + .pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB48BE, PIX_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("PPM (Portable PixelMap) image"), }; #endif #if CONFIG_PBM_ENCODER AVCodec pbm_encoder = { "pbm", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_PBM, sizeof(PNMContext), - common_init, + ff_pnm_init, pnm_encode_frame, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_MONOWHITE, PIX_FMT_NONE}, - .long_name= NULL_IF_CONFIG_SMALL("PBM (Portable BitMap) image"), -}; -#endif // CONFIG_PBM_ENCODER - -#if CONFIG_PAM_DECODER -AVCodec pam_decoder = { - "pam", - CODEC_TYPE_VIDEO, - CODEC_ID_PAM, - sizeof(PNMContext), - common_init, - NULL, - NULL, - pnm_decode_frame, - CODEC_CAP_DR1, - .pix_fmts= (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"), + .pix_fmts = (const enum PixelFormat[]){PIX_FMT_MONOWHITE, PIX_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("PBM (Portable BitMap) image"), }; #endif - -#if CONFIG_PAM_ENCODER -AVCodec pam_encoder = { - "pam", - CODEC_TYPE_VIDEO, - CODEC_ID_PAM, - sizeof(PNMContext), - common_init, - pam_encode_frame, - .pix_fmts= (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"), -}; -#endif // CONFIG_PAM_ENCODER diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/check_altivec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/check_altivec.c index 7f5143341b..c8bc6edcf3 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/check_altivec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/check_altivec.c @@ -18,12 +18,10 @@ /** - * @file libavcodec/ppc/check_altivec.c + * @file * Checks for AltiVec presence. */ -#include "config.h" - #ifdef __APPLE__ #undef _POSIX_C_SOURCE #include @@ -37,6 +35,9 @@ #include #endif /* __APPLE__ */ +#include "config.h" +#include "dsputil_altivec.h" + /** * This function MAY rely on signal() or fork() in order to make sure AltiVec * is present. diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/dsputil_altivec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/dsputil_altivec.c index fcce9aed09..925b6c83b7 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/dsputil_altivec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/dsputil_altivec.c @@ -28,11 +28,12 @@ #include "dsputil_ppc.h" #include "util_altivec.h" #include "types_altivec.h" +#include "dsputil_altivec.h" -int sad16_x2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) +static int sad16_x2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) { int i; - DECLARE_ALIGNED_16(int, s); + int s; const vector unsigned char zero = (const vector unsigned char)vec_splat_u8(0); vector unsigned char *tv; vector unsigned char pix1v, pix2v, pix2iv, avgv, t5; @@ -74,10 +75,10 @@ int sad16_x2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h return s; } -int sad16_y2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) +static int sad16_y2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) { int i; - DECLARE_ALIGNED_16(int, s); + int s; const vector unsigned char zero = (const vector unsigned char)vec_splat_u8(0); vector unsigned char *tv; vector unsigned char pix1v, pix2v, pix3v, avgv, t5; @@ -130,10 +131,10 @@ int sad16_y2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h return s; } -int sad16_xy2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) +static int sad16_xy2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) { int i; - DECLARE_ALIGNED_16(int, s); + int s; uint8_t *pix3 = pix2 + line_size; const vector unsigned char zero = (const vector unsigned char)vec_splat_u8(0); const vector unsigned short two = (const vector unsigned short)vec_splat_u16(2); @@ -225,10 +226,10 @@ int sad16_xy2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int return s; } -int sad16_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) +static int sad16_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) { int i; - DECLARE_ALIGNED_16(int, s); + int s; const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0); vector unsigned char perm1, perm2, *pix1v, *pix2v; vector unsigned char t1, t2, t3,t4, t5; @@ -267,10 +268,10 @@ int sad16_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) return s; } -int sad8_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) +static int sad8_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) { int i; - DECLARE_ALIGNED_16(int, s); + int s; const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0); vector unsigned char perm1, perm2, permclear, *pix1v, *pix2v; vector unsigned char t1, t2, t3,t4, t5; @@ -312,10 +313,10 @@ int sad8_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) return s; } -int pix_norm1_altivec(uint8_t *pix, int line_size) +static int pix_norm1_altivec(uint8_t *pix, int line_size) { int i; - DECLARE_ALIGNED_16(int, s); + int s; const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0); vector unsigned char *tv; vector unsigned char pixv; @@ -348,10 +349,10 @@ int pix_norm1_altivec(uint8_t *pix, int line_size) * AltiVec-enhanced. * It's the sad8_altivec code above w/ squaring added. */ -int sse8_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) +static int sse8_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) { int i; - DECLARE_ALIGNED_16(int, s); + int s; const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0); vector unsigned char perm1, perm2, permclear, *pix1v, *pix2v; vector unsigned char t1, t2, t3,t4, t5; @@ -402,10 +403,10 @@ int sse8_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) * AltiVec-enhanced. * It's the sad16_altivec code above w/ squaring added. */ -int sse16_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) +static int sse16_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) { int i; - DECLARE_ALIGNED_16(int, s); + int s; const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0); vector unsigned char perm1, perm2, *pix1v, *pix2v; vector unsigned char t1, t2, t3,t4, t5; @@ -446,7 +447,7 @@ int sse16_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) return s; } -int pix_sum_altivec(uint8_t * pix, int line_size) +static int pix_sum_altivec(uint8_t * pix, int line_size) { const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0); vector unsigned char perm, *pixv; @@ -455,7 +456,7 @@ int pix_sum_altivec(uint8_t * pix, int line_size) vector signed int sumdiffs; int i; - DECLARE_ALIGNED_16(int, s); + int s; sad = (vector unsigned int)vec_splat_u32(0); @@ -479,7 +480,7 @@ int pix_sum_altivec(uint8_t * pix, int line_size) return s; } -void get_pixels_altivec(DCTELEM *restrict block, const uint8_t *pixels, int line_size) +static void get_pixels_altivec(DCTELEM *restrict block, const uint8_t *pixels, int line_size) { int i; vector unsigned char perm, bytes, *pixv; @@ -504,7 +505,7 @@ void get_pixels_altivec(DCTELEM *restrict block, const uint8_t *pixels, int line } } -void diff_pixels_altivec(DCTELEM *restrict block, const uint8_t *s1, +static void diff_pixels_altivec(DCTELEM *restrict block, const uint8_t *s1, const uint8_t *s2, int stride) { int i; @@ -589,7 +590,7 @@ static void clear_block_altivec(DCTELEM *block) { } -void add_bytes_altivec(uint8_t *dst, uint8_t *src, int w) { +static void add_bytes_altivec(uint8_t *dst, uint8_t *src, int w) { register int i; register vector unsigned char vdst, vsrc; @@ -687,7 +688,7 @@ POWERPC_PERF_STOP_COUNT(altivec_avg_pixels16_num, 1); } /* next one assumes that ((line_size % 8) == 0) */ -void avg_pixels8_altivec(uint8_t * block, const uint8_t * pixels, int line_size, int h) +static void avg_pixels8_altivec(uint8_t * block, const uint8_t * pixels, int line_size, int h) { POWERPC_PERF_DECLARE(altivec_avg_pixels8_num, 1); register vector unsigned char pixelsv1, pixelsv2, pixelsv, blockv; @@ -723,7 +724,7 @@ POWERPC_PERF_STOP_COUNT(altivec_avg_pixels8_num, 1); } /* next one assumes that ((line_size % 8) == 0) */ -void put_pixels8_xy2_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h) +static void put_pixels8_xy2_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h) { POWERPC_PERF_DECLARE(altivec_put_pixels8_xy2_num, 1); register int i; @@ -786,7 +787,7 @@ POWERPC_PERF_STOP_COUNT(altivec_put_pixels8_xy2_num, 1); } /* next one assumes that ((line_size % 8) == 0) */ -void put_no_rnd_pixels8_xy2_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h) +static void put_no_rnd_pixels8_xy2_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h) { POWERPC_PERF_DECLARE(altivec_put_no_rnd_pixels8_xy2_num, 1); register int i; @@ -850,7 +851,7 @@ POWERPC_PERF_STOP_COUNT(altivec_put_no_rnd_pixels8_xy2_num, 1); } /* next one assumes that ((line_size % 16) == 0) */ -void put_pixels16_xy2_altivec(uint8_t * block, const uint8_t * pixels, int line_size, int h) +static void put_pixels16_xy2_altivec(uint8_t * block, const uint8_t * pixels, int line_size, int h) { POWERPC_PERF_DECLARE(altivec_put_pixels16_xy2_num, 1); register int i; @@ -923,7 +924,7 @@ POWERPC_PERF_STOP_COUNT(altivec_put_pixels16_xy2_num, 1); } /* next one assumes that ((line_size % 16) == 0) */ -void put_no_rnd_pixels16_xy2_altivec(uint8_t * block, const uint8_t * pixels, int line_size, int h) +static void put_no_rnd_pixels16_xy2_altivec(uint8_t * block, const uint8_t * pixels, int line_size, int h) { POWERPC_PERF_DECLARE(altivec_put_no_rnd_pixels16_xy2_num, 1); register int i; @@ -996,7 +997,7 @@ POWERPC_PERF_START_COUNT(altivec_put_no_rnd_pixels16_xy2_num, 1); POWERPC_PERF_STOP_COUNT(altivec_put_no_rnd_pixels16_xy2_num, 1); } -int hadamard8_diff8x8_altivec(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h){ +static int hadamard8_diff8x8_altivec(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h){ POWERPC_PERF_DECLARE(altivec_hadamard8_diff8x8_num, 1); int sum; register const vector unsigned char vzero = @@ -1317,7 +1318,7 @@ static int hadamard8_diff16x8_altivec(/*MpegEncContext*/ void *s, uint8_t *dst, return sum; } -int hadamard8_diff16_altivec(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h){ +static int hadamard8_diff16_altivec(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h){ POWERPC_PERF_DECLARE(altivec_hadamard8_diff16_num, 1); int score; POWERPC_PERF_START_COUNT(altivec_hadamard8_diff16_num, 1); @@ -1355,7 +1356,7 @@ static void vorbis_inverse_coupling_altivec(float *mag, float *ang, } /* next one assumes that ((line_size % 8) == 0) */ -void avg_pixels8_xy2_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h) +static void avg_pixels8_xy2_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h) { POWERPC_PERF_DECLARE(altivec_avg_pixels8_xy2_num, 1); register int i; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/dsputil_altivec.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/dsputil_altivec.h index 03ff0b9fc8..18f8dd8710 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/dsputil_altivec.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/dsputil_altivec.h @@ -24,11 +24,29 @@ #define AVCODEC_PPC_DSPUTIL_ALTIVEC_H #include - -int has_altivec(void); +#include "libavcodec/dsputil.h" void put_pixels16_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h); void avg_pixels16_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h); +int has_altivec(void); + +void fdct_altivec(int16_t *block); +void gmc1_altivec(uint8_t *dst, uint8_t *src, int stride, int h, + int x16, int y16, int rounder); +void idct_put_altivec(uint8_t *dest, int line_size, int16_t *block); +void idct_add_altivec(uint8_t *dest, int line_size, int16_t *block); + +void ff_vp3_idct_altivec(DCTELEM *block); +void ff_vp3_idct_put_altivec(uint8_t *dest, int line_size, DCTELEM *block); +void ff_vp3_idct_add_altivec(uint8_t *dest, int line_size, DCTELEM *block); + +void dsputil_h264_init_ppc(DSPContext* c, AVCodecContext *avctx); + +void dsputil_init_altivec(DSPContext* c, AVCodecContext *avctx); +void vc1dsp_init_altivec(DSPContext* c, AVCodecContext *avctx); +void float_init_altivec(DSPContext* c, AVCodecContext *avctx); +void int_init_altivec(DSPContext* c, AVCodecContext *avctx); + #endif /* AVCODEC_PPC_DSPUTIL_ALTIVEC_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/dsputil_ppc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/dsputil_ppc.c index 63103f8bd1..cf0ac39de3 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/dsputil_ppc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/dsputil_ppc.c @@ -26,23 +26,6 @@ #include "dsputil_altivec.h" -void fdct_altivec(int16_t *block); -void gmc1_altivec(uint8_t *dst, uint8_t *src, int stride, int h, - int x16, int y16, int rounder); -void idct_put_altivec(uint8_t *dest, int line_size, int16_t *block); -void idct_add_altivec(uint8_t *dest, int line_size, int16_t *block); - -void ff_vp3_idct_altivec(DCTELEM *block); -void ff_vp3_idct_put_altivec(uint8_t *dest, int line_size, DCTELEM *block); -void ff_vp3_idct_add_altivec(uint8_t *dest, int line_size, DCTELEM *block); - -void dsputil_h264_init_ppc(DSPContext* c, AVCodecContext *avctx); - -void dsputil_init_altivec(DSPContext* c, AVCodecContext *avctx); -void vc1dsp_init_altivec(DSPContext* c, AVCodecContext *avctx); -void float_init_altivec(DSPContext* c, AVCodecContext *avctx); -void int_init_altivec(DSPContext* c, AVCodecContext *avctx); - int mm_flags = 0; int mm_support(void) @@ -133,7 +116,7 @@ distinguish, and use dcbz (32 bytes) or dcbzl (one cache line) as required. see and */ -void clear_blocks_dcbz32_ppc(DCTELEM *blocks) +static void clear_blocks_dcbz32_ppc(DCTELEM *blocks) { POWERPC_PERF_DECLARE(powerpc_clear_blocks_dcbz32, 1); register int misal = ((unsigned long)blocks & 0x00000010); @@ -166,7 +149,7 @@ POWERPC_PERF_STOP_COUNT(powerpc_clear_blocks_dcbz32, 1); /* same as above, when dcbzl clear a whole 128B cache line i.e. the PPC970 aka G5 */ #if HAVE_DCBZL -void clear_blocks_dcbz128_ppc(DCTELEM *blocks) +static void clear_blocks_dcbz128_ppc(DCTELEM *blocks) { POWERPC_PERF_DECLARE(powerpc_clear_blocks_dcbz128, 1); register int misal = ((unsigned long)blocks & 0x0000007f); @@ -189,7 +172,7 @@ POWERPC_PERF_START_COUNT(powerpc_clear_blocks_dcbz128, 1); POWERPC_PERF_STOP_COUNT(powerpc_clear_blocks_dcbz128, 1); } #else -void clear_blocks_dcbz128_ppc(DCTELEM *blocks) +static void clear_blocks_dcbz128_ppc(DCTELEM *blocks) { memset(blocks, 0, sizeof(DCTELEM)*6*64); } @@ -201,7 +184,7 @@ void clear_blocks_dcbz128_ppc(DCTELEM *blocks) the intended effect (Apple "fixed" dcbz) unfortunately this cannot be used unless the assembler knows about dcbzl ... */ -long check_dcbzl_effect(void) +static long check_dcbzl_effect(void) { register char *fakedata = av_malloc(1024); register char *fakedata_middle; @@ -231,7 +214,7 @@ long check_dcbzl_effect(void) return count; } #else -long check_dcbzl_effect(void) +static long check_dcbzl_effect(void) { return 0; } diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/fdct_altivec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/fdct_altivec.c index 3dfd59ca29..8f3bc26947 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/fdct_altivec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/fdct_altivec.c @@ -25,7 +25,7 @@ #include "libavutil/common.h" #include "libavcodec/dsputil.h" #include "dsputil_ppc.h" - +#include "dsputil_altivec.h" #define vs16(v) ((vector signed short)(v)) #define vs32(v) ((vector signed int)(v)) diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/fft_altivec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/fft_altivec.c index 7391131a73..ce35ab602c 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/fft_altivec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/fft_altivec.c @@ -20,9 +20,11 @@ * 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" +#include "libavcodec/fft.h" #include "dsputil_ppc.h" #include "util_altivec.h" +#include "dsputil_altivec.h" + /** * Do a complex FFT with the parameters defined in ff_fft_init(). The * input data must be permuted before with s->revtab table. No @@ -34,7 +36,7 @@ * that successive MUL + ADD/SUB have been merged into * fused multiply-add ('vec_madd' in altivec) */ -void ff_fft_calc_altivec(FFTContext *s, FFTComplex *z) +static void ff_fft_calc_altivec(FFTContext *s, FFTComplex *z) { POWERPC_PERF_DECLARE(altivec_fft_num, s->nbits >= 6); register const vector float vczero = (const vector float)vec_splat_u32(0.); @@ -133,3 +135,9 @@ POWERPC_PERF_START_COUNT(altivec_fft_num, s->nbits >= 6); POWERPC_PERF_STOP_COUNT(altivec_fft_num, s->nbits >= 6); } + +av_cold void ff_fft_init_altivec(FFTContext *s) +{ + s->fft_calc = ff_fft_calc_altivec; + s->split_radix = 0; +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/float_altivec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/float_altivec.c index 096f75f8b9..d1f9f1ade3 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/float_altivec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/float_altivec.c @@ -66,86 +66,28 @@ static void vector_fmul_reverse_altivec(float *dst, const float *src0, } } -static void vector_fmul_add_add_altivec(float *dst, const float *src0, - const float *src1, const float *src2, - int src3, int len, int step) +static void vector_fmul_add_altivec(float *dst, const float *src0, + const float *src1, const float *src2, + int len) { int i; vector float d, s0, s1, s2, t0, t1, edges; vector unsigned char align = vec_lvsr(0,dst), mask = vec_lvsl(0, dst); -#if 0 //FIXME: there is still something wrong - if (step == 2) { - int y; - vector float d0, d1, s3, t2; - vector unsigned int sel = - vec_mergeh(vec_splat_u32(-1), vec_splat_u32(0)); - t1 = vec_ld(16, dst); - for (i=0,y=0; ivector_fmul = vector_fmul_altivec; c->vector_fmul_reverse = vector_fmul_reverse_altivec; - c->vector_fmul_add_add = vector_fmul_add_add_altivec; + c->vector_fmul_add = vector_fmul_add_altivec; c->int32_to_float_fmul_scalar = int32_to_float_fmul_scalar_altivec; if(!(avctx->flags & CODEC_FLAG_BITEXACT)) { c->vector_fmul_window = vector_fmul_window_altivec; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/gmc_altivec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/gmc_altivec.c index c77c7162b3..fa71047b72 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/gmc_altivec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/gmc_altivec.c @@ -23,6 +23,8 @@ #include "libavcodec/dsputil.h" #include "dsputil_ppc.h" #include "util_altivec.h" +#include "types_altivec.h" +#include "dsputil_altivec.h" /* altivec-enhanced gmc1. ATM this code assume stride is a multiple of 8, @@ -32,10 +34,8 @@ void gmc1_altivec(uint8_t *dst /* align 8 */, uint8_t *src /* align1 */, int stride, int h, int x16, int y16, int rounder) { POWERPC_PERF_DECLARE(altivec_gmc1_num, GMC1_PERF_COND); - const DECLARE_ALIGNED_16(unsigned short, rounder_a[8]) = - {rounder, rounder, rounder, rounder, - rounder, rounder, rounder, rounder}; - const DECLARE_ALIGNED_16(unsigned short, ABCD[8]) = + const DECLARE_ALIGNED(16, unsigned short, rounder_a) = rounder; + const DECLARE_ALIGNED(16, unsigned short, ABCD)[8] = { (16-x16)*(16-y16), /* A */ ( x16)*(16-y16), /* B */ @@ -60,7 +60,7 @@ POWERPC_PERF_START_COUNT(altivec_gmc1_num, GMC1_PERF_COND); Cv = vec_splat(tempA, 2); Dv = vec_splat(tempA, 3); - rounderV = vec_ld(0, (unsigned short*)rounder_a); + rounderV = vec_splat((vec_u16)vec_lde(0, &rounder_a), 0); // we'll be able to pick-up our 9 char elements // at src from those 32 bytes diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/h264_altivec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/h264_altivec.c index 29a9c7315a..47e416b82b 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/h264_altivec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/h264_altivec.c @@ -20,6 +20,7 @@ #include "libavcodec/dsputil.h" #include "libavcodec/h264data.h" +#include "libavcodec/h264dsp.h" #include "dsputil_ppc.h" #include "dsputil_altivec.h" @@ -79,7 +80,7 @@ static void OPNAME ## h264_qpel ## SIZE ## _mc00_ ## CODETYPE (uint8_t *dst, uin }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc10_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){ \ - DECLARE_ALIGNED_16(uint8_t, half[SIZE*SIZE]);\ + DECLARE_ALIGNED(16, uint8_t, half)[SIZE*SIZE];\ put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(half, src, SIZE, stride);\ OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, src, half, stride, stride, SIZE);\ }\ @@ -89,13 +90,13 @@ static void OPNAME ## h264_qpel ## SIZE ## _mc20_ ## CODETYPE(uint8_t *dst, uint }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc30_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED_16(uint8_t, half[SIZE*SIZE]);\ + DECLARE_ALIGNED(16, uint8_t, half)[SIZE*SIZE];\ put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(half, src, SIZE, stride);\ OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, src+1, half, stride, stride, SIZE);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc01_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED_16(uint8_t, half[SIZE*SIZE]);\ + DECLARE_ALIGNED(16, uint8_t, half)[SIZE*SIZE];\ put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(half, src, SIZE, stride);\ OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, src, half, stride, stride, SIZE);\ }\ @@ -105,79 +106,79 @@ static void OPNAME ## h264_qpel ## SIZE ## _mc02_ ## CODETYPE(uint8_t *dst, uint }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc03_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED_16(uint8_t, half[SIZE*SIZE]);\ + DECLARE_ALIGNED(16, uint8_t, half)[SIZE*SIZE];\ put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(half, src, SIZE, stride);\ OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, src+stride, half, stride, stride, SIZE);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc11_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED_16(uint8_t, halfH[SIZE*SIZE]);\ - DECLARE_ALIGNED_16(uint8_t, halfV[SIZE*SIZE]);\ + DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\ + DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\ put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src, SIZE, stride);\ put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src, SIZE, stride);\ OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfV, stride, SIZE, SIZE);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc31_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED_16(uint8_t, halfH[SIZE*SIZE]);\ - DECLARE_ALIGNED_16(uint8_t, halfV[SIZE*SIZE]);\ + DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\ + DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\ put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src, SIZE, stride);\ put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src+1, SIZE, stride);\ OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfV, stride, SIZE, SIZE);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc13_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED_16(uint8_t, halfH[SIZE*SIZE]);\ - DECLARE_ALIGNED_16(uint8_t, halfV[SIZE*SIZE]);\ + DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\ + DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\ put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src + stride, SIZE, stride);\ put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src, SIZE, stride);\ OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfV, stride, SIZE, SIZE);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc33_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED_16(uint8_t, halfH[SIZE*SIZE]);\ - DECLARE_ALIGNED_16(uint8_t, halfV[SIZE*SIZE]);\ + DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\ + DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\ put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src + stride, SIZE, stride);\ put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src+1, SIZE, stride);\ OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfV, stride, SIZE, SIZE);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc22_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED_16(int16_t, tmp[SIZE*(SIZE+8)]);\ + DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\ OPNAME ## h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(dst, tmp, src, stride, SIZE, stride);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc21_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED_16(uint8_t, halfH[SIZE*SIZE]);\ - DECLARE_ALIGNED_16(uint8_t, halfHV[SIZE*SIZE]);\ - DECLARE_ALIGNED_16(int16_t, tmp[SIZE*(SIZE+8)]);\ + DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\ + DECLARE_ALIGNED(16, uint8_t, halfHV)[SIZE*SIZE];\ + DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\ put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src, SIZE, stride);\ put_h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(halfHV, tmp, src, SIZE, SIZE, stride);\ OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfHV, stride, SIZE, SIZE);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc23_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED_16(uint8_t, halfH[SIZE*SIZE]);\ - DECLARE_ALIGNED_16(uint8_t, halfHV[SIZE*SIZE]);\ - DECLARE_ALIGNED_16(int16_t, tmp[SIZE*(SIZE+8)]);\ + DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\ + DECLARE_ALIGNED(16, uint8_t, halfHV)[SIZE*SIZE];\ + DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\ put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src + stride, SIZE, stride);\ put_h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(halfHV, tmp, src, SIZE, SIZE, stride);\ OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfHV, stride, SIZE, SIZE);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc12_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED_16(uint8_t, halfV[SIZE*SIZE]);\ - DECLARE_ALIGNED_16(uint8_t, halfHV[SIZE*SIZE]);\ - DECLARE_ALIGNED_16(int16_t, tmp[SIZE*(SIZE+8)]);\ + DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\ + DECLARE_ALIGNED(16, uint8_t, halfHV)[SIZE*SIZE];\ + DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\ put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src, SIZE, stride);\ put_h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(halfHV, tmp, src, SIZE, SIZE, stride);\ OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfV, halfHV, stride, SIZE, SIZE);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc32_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED_16(uint8_t, halfV[SIZE*SIZE]);\ - DECLARE_ALIGNED_16(uint8_t, halfHV[SIZE*SIZE]);\ - DECLARE_ALIGNED_16(int16_t, tmp[SIZE*(SIZE+8)]);\ + DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\ + DECLARE_ALIGNED(16, uint8_t, halfHV)[SIZE*SIZE];\ + DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\ put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src+1, SIZE, stride);\ put_h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(halfHV, tmp, src, SIZE, SIZE, stride);\ OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfV, halfHV, stride, SIZE, SIZE);\ @@ -431,7 +432,7 @@ static void ff_h264_idct_add_altivec(uint8_t *dst, DCTELEM *block, int stride) vec_st( hv, 0, dest ); \ } -void ff_h264_idct8_add_altivec( uint8_t *dst, DCTELEM *dct, int stride ) { +static void ff_h264_idct8_add_altivec( uint8_t *dst, DCTELEM *dct, int stride ) { vec_s16 s0, s1, s2, s3, s4, s5, s6, s7; vec_s16 d0, d1, d2, d3, d4, d5, d6, d7; vec_s16 idct0, idct1, idct2, idct3, idct4, idct5, idct6, idct7; @@ -480,7 +481,7 @@ static av_always_inline void h264_idct_dc_add_internal(uint8_t *dst, DCTELEM *bl vec_s16 dc16; vec_u8 dcplus, dcminus, v0, v1, v2, v3, aligner; LOAD_ZERO; - DECLARE_ALIGNED_16(int, dc); + DECLARE_ALIGNED(16, int, dc); int i; dc = (block[0] + 32) >> 6; @@ -590,7 +591,7 @@ static void ff_h264_idct_add8_altivec(uint8_t **dest, const int *block_offset, D static inline void write16x4(uint8_t *dst, int dst_stride, register vec_u8 r0, register vec_u8 r1, register vec_u8 r2, register vec_u8 r3) { - DECLARE_ALIGNED_16(unsigned char, result[64]); + DECLARE_ALIGNED(16, unsigned char, result)[64]; uint32_t *src_int = (uint32_t *)result, *dst_int = (uint32_t *)dst; int int_dst_stride = dst_stride/4; @@ -770,7 +771,7 @@ static inline vec_u8 h264_deblock_q1(register vec_u8 p0, } #define h264_loop_filter_luma_altivec(p2, p1, p0, q0, q1, q2, alpha, beta, tc0) { \ - DECLARE_ALIGNED_16(unsigned char, temp[16]); \ + DECLARE_ALIGNED(16, unsigned char, temp)[16]; \ register vec_u8 alphavec; \ register vec_u8 betavec; \ register vec_u8 mask; \ @@ -850,7 +851,7 @@ void weight_h264_WxH_altivec(uint8_t *block, int stride, int log2_denom, int wei vec_u8 vblock; vec_s16 vtemp, vweight, voffset, v0, v1; vec_u16 vlog2_denom; - DECLARE_ALIGNED_16(int32_t, temp[4]); + DECLARE_ALIGNED(16, int32_t, temp)[4]; LOAD_ZERO; offset <<= log2_denom; @@ -896,7 +897,7 @@ void biweight_h264_WxH_altivec(uint8_t *dst, uint8_t *src, int stride, int log2_ vec_u8 vsrc, vdst; vec_s16 vtemp, vweights, vweightd, voffset, v0, v1, v2, v3; vec_u16 vlog2_denom; - DECLARE_ALIGNED_16(int32_t, temp[4]); + DECLARE_ALIGNED(16, int32_t, temp)[4]; LOAD_ZERO; offset = ((offset + 1) | 1) << log2_denom; @@ -974,16 +975,6 @@ void dsputil_h264_init_ppc(DSPContext* c, AVCodecContext *avctx) { c->avg_h264_chroma_pixels_tab[0] = avg_h264_chroma_mc8_altivec; c->put_no_rnd_vc1_chroma_pixels_tab[0] = put_no_rnd_vc1_chroma_mc8_altivec; c->avg_no_rnd_vc1_chroma_pixels_tab[0] = avg_no_rnd_vc1_chroma_mc8_altivec; - c->h264_idct_add = ff_h264_idct_add_altivec; - 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; - c->h264_idct8_dc_add = ff_h264_idct8_dc_add_altivec; - c->h264_idct8_add = ff_h264_idct8_add_altivec; - c->h264_idct8_add4 = ff_h264_idct8_add4_altivec; - c->h264_v_loop_filter_luma= h264_v_loop_filter_luma_altivec; - c->h264_h_loop_filter_luma= h264_h_loop_filter_luma_altivec; #define dspfunc(PFX, IDX, NUM) \ c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_altivec; \ @@ -1006,6 +997,22 @@ void dsputil_h264_init_ppc(DSPContext* c, AVCodecContext *avctx) { dspfunc(put_h264_qpel, 0, 16); dspfunc(avg_h264_qpel, 0, 16); #undef dspfunc + } +} + +void ff_h264dsp_init_ppc(H264DSPContext *c) +{ + if (has_altivec()) { + c->h264_idct_add = ff_h264_idct_add_altivec; + 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; + c->h264_idct8_dc_add = ff_h264_idct8_dc_add_altivec; + c->h264_idct8_add = ff_h264_idct8_add_altivec; + c->h264_idct8_add4 = ff_h264_idct8_add4_altivec; + 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; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/h264_template_altivec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/h264_template_altivec.c index 954fd16bd9..c0a4eb7a60 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/h264_template_altivec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/h264_template_altivec.c @@ -75,10 +75,10 @@ #define noop(a) a #define add28(a) vec_add(v28ss, a) -void PREFIX_h264_chroma_mc8_altivec(uint8_t * dst, uint8_t * src, +static void PREFIX_h264_chroma_mc8_altivec(uint8_t * dst, uint8_t * src, int stride, int h, int x, int y) { POWERPC_PERF_DECLARE(PREFIX_h264_chroma_mc8_num, 1); - DECLARE_ALIGNED_16(signed int, ABCD[4]) = + DECLARE_ALIGNED(16, signed int, ABCD)[4] = {((8 - x) * (8 - y)), (( x) * (8 - y)), ((8 - x) * ( y)), @@ -207,8 +207,8 @@ void PREFIX_h264_chroma_mc8_altivec(uint8_t * dst, uint8_t * src, } /* this code assume that stride % 16 == 0 */ -void PREFIX_no_rnd_vc1_chroma_mc8_altivec(uint8_t * dst, uint8_t * src, int stride, int h, int x, int y) { - DECLARE_ALIGNED_16(signed int, ABCD[4]) = +static void PREFIX_no_rnd_vc1_chroma_mc8_altivec(uint8_t * dst, uint8_t * src, int stride, int h, int x, int y) { + DECLARE_ALIGNED(16, signed int, ABCD)[4] = {((8 - x) * (8 - y)), (( x) * (8 - y)), ((8 - x) * ( y)), diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/idct_altivec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/idct_altivec.c index 6043a172bf..7c6b79e9c0 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/idct_altivec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/idct_altivec.c @@ -44,6 +44,7 @@ #include "libavcodec/dsputil.h" #include "types_altivec.h" #include "dsputil_ppc.h" +#include "dsputil_altivec.h" #define IDCT_HALF \ /* 1st stage */ \ @@ -158,9 +159,10 @@ static const vec_s16 constants[5] = { {19266, 26722, 25172, 22654, 19266, 22654, 25172, 26722} }; -void idct_put_altivec(uint8_t* dest, int stride, vec_s16* block) +void idct_put_altivec(uint8_t* dest, int stride, int16_t *blk) { POWERPC_PERF_DECLARE(altivec_idct_put_num, 1); + vec_s16 *block = (vec_s16*)blk; vec_u8 tmp; #if CONFIG_POWERPC_PERF @@ -185,9 +187,10 @@ POWERPC_PERF_START_COUNT(altivec_idct_put_num, 1); POWERPC_PERF_STOP_COUNT(altivec_idct_put_num, 1); } -void idct_add_altivec(uint8_t* dest, int stride, vec_s16* block) +void idct_add_altivec(uint8_t* dest, int stride, int16_t *blk) { POWERPC_PERF_DECLARE(altivec_idct_add_num, 1); + vec_s16 *block = (vec_s16*)blk; vec_u8 tmp; vec_s16 tmp2, tmp3; vec_u8 perm0; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/int_altivec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/int_altivec.c index 6cfcc08f93..7fb11ddd9b 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/int_altivec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/int_altivec.c @@ -19,7 +19,7 @@ */ /** - ** @file libavcodec/ppc/int_altivec.c + ** @file ** integer misc ops. **/ @@ -79,34 +79,6 @@ static int ssd_int8_vs_int16_altivec(const int8_t *pix1, const int16_t *pix2, return u.score[3]; } -static void add_int16_altivec(int16_t * v1, int16_t * v2, int order) -{ - int i; - register vec_s16 vec, *pv; - - for(i = 0; i < order; i += 8){ - pv = (vec_s16*)v2; - vec = vec_perm(pv[0], pv[1], vec_lvsl(0, v2)); - vec_st(vec_add(vec_ld(0, v1), vec), 0, v1); - v1 += 8; - v2 += 8; - } -} - -static void sub_int16_altivec(int16_t * v1, int16_t * v2, int order) -{ - int i; - register vec_s16 vec, *pv; - - for(i = 0; i < order; i += 8){ - pv = (vec_s16*)v2; - vec = vec_perm(pv[0], pv[1], vec_lvsl(0, v2)); - vec_st(vec_sub(vec_ld(0, v1), vec), 0, v1); - v1 += 8; - v2 += 8; - } -} - static int32_t scalarproduct_int16_altivec(int16_t * v1, int16_t * v2, int order, const int shift) { int i; @@ -114,7 +86,7 @@ static int32_t scalarproduct_int16_altivec(int16_t * v1, int16_t * v2, int order register vec_s16 vec1, *pv; register vec_s32 res = vec_splat_s32(0), t; register vec_u32 shifts; - DECLARE_ALIGNED_16(int32_t, ires); + int32_t ires; shifts = zero_u32v; if(shift & 0x10) shifts = vec_add(shifts, vec_sl(vec_splat_u32(0x08), vec_splat_u32(0x1))); @@ -137,10 +109,44 @@ static int32_t scalarproduct_int16_altivec(int16_t * v1, int16_t * v2, int order return ires; } +static int32_t scalarproduct_and_madd_int16_altivec(int16_t *v1, int16_t *v2, int16_t *v3, int order, int mul) +{ + LOAD_ZERO; + vec_s16 *pv1 = (vec_s16*)v1; + vec_s16 *pv2 = (vec_s16*)v2; + vec_s16 *pv3 = (vec_s16*)v3; + register vec_s16 muls = {mul,mul,mul,mul,mul,mul,mul,mul}; + register vec_s16 t0, t1, i0, i1; + register vec_s16 i2 = pv2[0], i3 = pv3[0]; + register vec_s32 res = zero_s32v; + register vec_u8 align = vec_lvsl(0, v2); + int32_t ires; + order >>= 4; + do { + t0 = vec_perm(i2, pv2[1], align); + i2 = pv2[2]; + t1 = vec_perm(pv2[1], i2, align); + i0 = pv1[0]; + i1 = pv1[1]; + res = vec_msum(t0, i0, res); + res = vec_msum(t1, i1, res); + t0 = vec_perm(i3, pv3[1], align); + i3 = pv3[2]; + t1 = vec_perm(pv3[1], i3, align); + pv1[0] = vec_mladd(t0, muls, i0); + pv1[1] = vec_mladd(t1, muls, i1); + pv1 += 2; + pv2 += 2; + pv3 += 2; + } while(--order); + res = vec_splat(vec_sums(res, zero_s32v), 3); + vec_ste(res, 0, &ires); + return ires; +} + void int_init_altivec(DSPContext* c, AVCodecContext *avctx) { c->ssd_int8_vs_int16 = ssd_int8_vs_int16_altivec; - c->add_int16 = add_int16_altivec; - c->sub_int16 = sub_int16_altivec; c->scalarproduct_int16 = scalarproduct_int16_altivec; + c->scalarproduct_and_madd_int16 = scalarproduct_and_madd_int16_altivec; } diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/mathops.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/mathops.h index 1dcc09aebd..dbd714fcd4 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/mathops.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/mathops.h @@ -23,7 +23,9 @@ #ifndef AVCODEC_PPC_MATHOPS_H #define AVCODEC_PPC_MATHOPS_H +#include #include "config.h" +#include "libavutil/common.h" #if HAVE_PPC4XX /* signed 16x16 -> 32 multiply add accumulate */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/mpegvideo_altivec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/mpegvideo_altivec.c index 74775f05fd..07e63be47a 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/mpegvideo_altivec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/mpegvideo_altivec.c @@ -28,6 +28,9 @@ #include "dsputil_ppc.h" #include "util_altivec.h" +#include "types_altivec.h" +#include "dsputil_altivec.h" + // Swaps two variables (used for altivec registers) #define SWAP(a,b) \ do { \ @@ -66,7 +69,7 @@ do { \ #define FOUROF(a) {a,a,a,a} -int dct_quantize_altivec(MpegEncContext* s, +static int dct_quantize_altivec(MpegEncContext* s, DCTELEM* data, int n, int qscale, int* overflow) { @@ -473,7 +476,7 @@ int dct_quantize_altivec(MpegEncContext* s, /* AltiVec version of dct_unquantize_h263 this code assumes `block' is 16 bytes-aligned */ -void dct_unquantize_h263_altivec(MpegEncContext *s, +static void dct_unquantize_h263_altivec(MpegEncContext *s, DCTELEM *block, int n, int qscale) { POWERPC_PERF_DECLARE(altivec_dct_unquantize_h263_num, 1); @@ -504,29 +507,16 @@ POWERPC_PERF_START_COUNT(altivec_dct_unquantize_h263_num, 1); { register const vector signed short vczero = (const vector signed short)vec_splat_s16(0); - DECLARE_ALIGNED_16(short, qmul8[]) = - { - qmul, qmul, qmul, qmul, - qmul, qmul, qmul, qmul - }; - DECLARE_ALIGNED_16(short, qadd8[]) = - { - qadd, qadd, qadd, qadd, - qadd, qadd, qadd, qadd - }; - DECLARE_ALIGNED_16(short, nqadd8[]) = - { - -qadd, -qadd, -qadd, -qadd, - -qadd, -qadd, -qadd, -qadd - }; + DECLARE_ALIGNED(16, short, qmul8) = qmul; + DECLARE_ALIGNED(16, short, qadd8) = qadd; register vector signed short blockv, qmulv, qaddv, nqaddv, temp1; register vector bool short blockv_null, blockv_neg; register short backup_0 = block[0]; register int j = 0; - qmulv = vec_ld(0, qmul8); - qaddv = vec_ld(0, qadd8); - nqaddv = vec_ld(0, nqadd8); + qmulv = vec_splat((vec_s16)vec_lde(0, &qmul8), 0); + 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 @@ -583,9 +573,6 @@ POWERPC_PERF_STOP_COUNT(altivec_dct_unquantize_h263_num, nCoeffs == 63); } -void idct_put_altivec(uint8_t *dest, int line_size, int16_t *block); -void idct_add_altivec(uint8_t *dest, int line_size, int16_t *block); - void MPV_common_init_altivec(MpegEncContext *s) { if ((mm_flags & FF_MM_ALTIVEC) == 0) return; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/util_altivec.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/util_altivec.h index 9bf7e390ac..62f228a275 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/util_altivec.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/util_altivec.h @@ -17,7 +17,7 @@ */ /** - * @file libavcodec/ppc/util_altivec.h + * @file * Contains misc utility macros and inline functions */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/vc1dsp_altivec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/vc1dsp_altivec.c index d0b77969f9..a2f55f2db0 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/vc1dsp_altivec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/vc1dsp_altivec.c @@ -22,6 +22,7 @@ #include "libavcodec/dsputil.h" #include "util_altivec.h" +#include "dsputil_altivec.h" // main steps of 8x8 transform #define STEP8(s0, s1, s2, s3, s4, s5, s6, s7, vec_rnd) \ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/vp3dsp_altivec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/vp3dsp_altivec.c index d766c6a3ee..b0509d8b64 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/vp3dsp_altivec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ppc/vp3dsp_altivec.c @@ -21,6 +21,7 @@ #include "libavcodec/dsputil.h" #include "util_altivec.h" #include "types_altivec.h" +#include "dsputil_altivec.h" static const vec_s16 constants = {0, 64277, 60547, 54491, 46341, 36410, 25080, 12785}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/psymodel.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/psymodel.c index b337bfd509..f87dbcf277 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/psymodel.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/psymodel.c @@ -80,17 +80,14 @@ av_cold struct FFPsyPreprocessContext* ff_psy_preprocess_init(AVCodecContext *av { FFPsyPreprocessContext *ctx; int i; - float cutoff_coeff; + float cutoff_coeff = 0; ctx = av_mallocz(sizeof(FFPsyPreprocessContext)); ctx->avctx = avctx; if (avctx->cutoff > 0) cutoff_coeff = 2.0 * avctx->cutoff / avctx->sample_rate; - else if (avctx->flags & CODEC_FLAG_QSCALE) - cutoff_coeff = 1.0f / av_clip(1 + avctx->global_quality / FF_QUALITY_SCALE, 1, 8); - else - cutoff_coeff = avctx->bit_rate / (4.0f * avctx->sample_rate * avctx->channels); + if (cutoff_coeff) ctx->fcoeffs = ff_iir_filter_init_coeffs(FF_FILTER_TYPE_BUTTERWORTH, FF_FILTER_MODE_LOWPASS, FILT_ORDER, cutoff_coeff, 0.0, 0.0); if (ctx->fcoeffs) { diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/pthread.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/pthread.c index 82eba38786..1628b21a1f 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/pthread.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/pthread.c @@ -26,10 +26,12 @@ #include "avcodec.h" typedef int (action_func)(AVCodecContext *c, void *arg); +typedef int (action_func2)(AVCodecContext *c, void *arg, int jobnr, int threadnr); typedef struct ThreadContext { pthread_t *workers; action_func *func; + action_func2 *func2; void *args; int *rets; int rets_count; @@ -68,7 +70,8 @@ static void* attribute_align_arg worker(void *v) } pthread_mutex_unlock(&c->current_job_lock); - c->rets[our_job%c->rets_count] = c->func(avctx, (char*)c->args + our_job*c->job_size); + c->rets[our_job%c->rets_count] = c->func ? c->func(avctx, (char*)c->args + our_job*c->job_size): + c->func2(avctx, c->args, our_job, self_id); pthread_mutex_lock(&c->current_job_lock); our_job = c->current_job++; @@ -101,7 +104,7 @@ void avcodec_thread_free(AVCodecContext *avctx) av_freep(&avctx->thread_opaque); } -int avcodec_thread_execute(AVCodecContext *avctx, action_func* func, void *arg, int *ret, int job_count, int job_size) +static int avcodec_thread_execute(AVCodecContext *avctx, action_func* func, void *arg, int *ret, int job_count, int job_size) { ThreadContext *c= avctx->thread_opaque; int dummy_ret; @@ -130,11 +133,23 @@ int avcodec_thread_execute(AVCodecContext *avctx, action_func* func, void *arg, return 0; } +static int avcodec_thread_execute2(AVCodecContext *avctx, action_func2* func2, void *arg, int *ret, int job_count) +{ + ThreadContext *c= avctx->thread_opaque; + c->func2 = func2; + return avcodec_thread_execute(avctx, NULL, arg, ret, job_count, 0); +} + int avcodec_thread_init(AVCodecContext *avctx, int thread_count) { int i; ThreadContext *c; + avctx->thread_count = thread_count; + + if (thread_count <= 1) + return 0; + c = av_mallocz(sizeof(ThreadContext)); if (!c) return -1; @@ -146,7 +161,6 @@ int avcodec_thread_init(AVCodecContext *avctx, int thread_count) } avctx->thread_opaque = c; - avctx->thread_count = thread_count; c->current_job = 0; c->job_count = 0; c->job_size = 0; @@ -167,5 +181,6 @@ int avcodec_thread_init(AVCodecContext *avctx, int thread_count) avcodec_thread_park_workers(c, thread_count); avctx->execute = avcodec_thread_execute; + avctx->execute2 = avcodec_thread_execute2; return 0; } diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ptx.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/ptx.c index f5aa601cde..d8798f2e9c 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/ptx.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ptx.c @@ -107,7 +107,7 @@ static av_cold int ptx_end(AVCodecContext *avctx) { AVCodec ptx_decoder = { "ptx", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_PTX, sizeof(PTXContext), ptx_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/put_bits.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/put_bits.h index 4b4b3a873a..80a514df89 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/put_bits.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/put_bits.h @@ -19,7 +19,7 @@ */ /** - * @file libavcodec/put_bits.h + * @file * bitstream writer API */ @@ -117,17 +117,22 @@ static inline void flush_put_bits(PutBitContext *s) #endif } +#if defined(ALT_BITSTREAM_WRITER) || defined(BITSTREAM_WRITER_LE) +#define 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 +#else /** * Pads the bitstream with zeros up to the next byte boundary. */ void align_put_bits(PutBitContext *s); /** - * Puts the string s in the bitstream. + * Puts the string string in the bitstream. * * @param terminate_string 0-terminates the written string if value is 1 */ -void ff_put_string(PutBitContext * pbc, const char *s, int terminate_string); +void ff_put_string(PutBitContext *pb, const char *string, int terminate_string); /** * Copies the content of src to the bitstream. @@ -135,7 +140,12 @@ void ff_put_string(PutBitContext * pbc, const char *s, 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); +#endif +/** + * Writes up to 31 bits into a bitstream. + * Use put_bits32 to write 32 bits. + */ static inline void put_bits(PutBitContext *s, int n, unsigned int value) #ifndef ALT_BITSTREAM_WRITER { @@ -143,7 +153,7 @@ static inline void put_bits(PutBitContext *s, int n, unsigned int value) int bit_left; // printf("put_bits=%d %x\n", n, value); - assert(n == 32 || value < (1U << n)); + assert(n <= 31 && value < (1U << n)); bit_buf = s->bit_buf; bit_left = s->bit_left; @@ -252,11 +262,27 @@ static inline void put_bits(PutBitContext *s, int n, unsigned int value) } #endif -static inline void put_sbits(PutBitContext *pb, int bits, int32_t val) +static inline void put_sbits(PutBitContext *pb, int n, int32_t value) { - assert(bits >= 0 && bits <= 31); + assert(n >= 0 && n <= 31); - put_bits(pb, bits, val & ((1<> 16; +#ifdef BITSTREAM_WRITER_LE + put_bits(s, 16, lo); + put_bits(s, 16, hi); +#else + put_bits(s, 16, hi); + put_bits(s, 16, lo); +#endif } /** @@ -276,7 +302,8 @@ static inline uint8_t* put_bits_ptr(PutBitContext *s) * Skips the given number of bytes. * PutBitContext must be flushed & aligned to a byte boundary before calling this. */ -static inline void skip_put_bytes(PutBitContext *s, int n){ +static inline void skip_put_bytes(PutBitContext *s, int n) +{ assert((put_bits_count(s)&7)==0); #ifdef ALT_BITSTREAM_WRITER FIXME may need some cleaning of the buffer @@ -292,7 +319,8 @@ static inline void skip_put_bytes(PutBitContext *s, int n){ * Must only be used if the actual values in the bitstream do not matter. * If n is 0 the behavior is undefined. */ -static inline void skip_put_bits(PutBitContext *s, int n){ +static inline void skip_put_bits(PutBitContext *s, int n) +{ #ifdef ALT_BITSTREAM_WRITER s->index += n; #else @@ -307,7 +335,8 @@ static inline void skip_put_bits(PutBitContext *s, int n){ * * @param size the new size in bytes of the buffer where to put bits */ -static inline void set_put_bits_buffer_size(PutBitContext *s, int size){ +static inline void set_put_bits_buffer_size(PutBitContext *s, int size) +{ s->buf_end= s->buf + size; } diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/qcelpdata.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/qcelpdata.h index 6ca80dd8ef..d79cea9f6c 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/qcelpdata.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/qcelpdata.h @@ -23,7 +23,7 @@ #define AVCODEC_QCELPDATA_H /** - * @file libavcodec/qcelpdata.h + * @file * Data tables for the QCELP decoder * @author Reynaldo H. Verdejo Pinochet * @remark FFmpeg merging spearheaded by Kenan Gillet @@ -424,16 +424,6 @@ static const qcelp_vector * const qcelp_lspvq[5] = { */ #define QCELP_SCALE 8192. -/** - * the upper boundary of the clipping, depends on QCELP_SCALE - */ -#define QCELP_CLIP_UPPER_BOUND (8191.75/8192.) - -/** - * the lower boundary of the clipping, depends on QCELP_SCALE - */ -#define QCELP_CLIP_LOWER_BOUND -1. - /** * table for computing Ga (decoded linear codebook gain magnitude) * diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/qcelpdec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/qcelpdec.c index 0df30daf34..97785adb96 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/qcelpdec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/qcelpdec.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/qcelpdec.c + * @file * QCELP decoder * @author Reynaldo H. Verdejo Pinochet * @remark FFmpeg merging spearheaded by Kenan Gillet @@ -37,6 +37,7 @@ #include "celp_math.h" #include "celp_filters.h" +#include "acelp_filters.h" #include "acelp_vectors.h" #include "lsp.h" @@ -74,6 +75,11 @@ typedef struct uint8_t pitch_lag[4]; uint16_t first16bits; uint8_t warned_buf_mismatch_bitrate; + + /* postfilter */ + float postfilter_synth_mem[10]; + float postfilter_agc_mem; + float postfilter_tilt_mem; } QCELPContext; /** @@ -405,31 +411,6 @@ static void compute_svector(QCELPContext *q, const float *gain, } } -/** - * Compute the gain control - * - * @param v_in gain-controlled vector - * @param v_ref vector to control gain of - * - * @return gain control - * - * FIXME: If v_ref is a zero vector, it energy is zero - * and the behavior of the gain control is - * undefined in the specs. - * - * TIA/EIA/IS-733 2.4.8.3-2/3/4/5, 2.4.8.6 - */ -static float compute_gain_ctrl(const float *v_ref, const float *v_in, const int len) -{ - float scalefactor = ff_dot_productf(v_in, v_in, len); - - if(scalefactor) - scalefactor = sqrt(ff_dot_productf(v_ref, v_ref, len) / scalefactor); - else - av_log_missing_feature(NULL, "Zero energy for gain control", 1); - return scalefactor; -} - /** * Apply generic gain control. * @@ -442,15 +423,13 @@ static float compute_gain_ctrl(const float *v_ref, const float *v_in, const int static void apply_gain_ctrl(float *v_out, const float *v_ref, const float *v_in) { - int i, j, len; - float scalefactor; + int i; - for(i=0, j=0; i<4; i++) - { - scalefactor = compute_gain_ctrl(v_ref + j, v_in + j, 40); - for(len=j+40; jformant_mem + 10, 160, 10); + memcpy(pole_out, q->postfilter_synth_mem, sizeof(float) * 10); + ff_celp_lp_synthesis_filterf(pole_out + 10, lpc_p, zero_out, 160, 10); + memcpy(q->postfilter_synth_mem, pole_out + 160, sizeof(float) * 10); + + ff_tilt_compensation(&q->postfilter_tilt_mem, 0.3, pole_out + 10, 160); + + ff_adaptive_gain_control(samples, pole_out + 10, + ff_dot_productf(q->formant_mem + 10, q->formant_mem + 10, 160), + 160, 0.9375, &q->postfilter_agc_mem); +} + static int qcelp_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) { @@ -819,16 +828,12 @@ erasure: 10); formant_mem += 40; } + + // postfilter, as per TIA/EIA/IS-733 2.4.8.6 + postfilter(q, outbuffer, lpc); + memcpy(q->formant_mem, q->formant_mem + 160, 10 * sizeof(float)); - // FIXME: postfilter and final gain control should be here. - // TIA/EIA/IS-733 2.4.8.6 - - formant_mem = q->formant_mem + 10; - for(i=0; i<160; i++) - *outbuffer++ = av_clipf(*formant_mem++, QCELP_CLIP_LOWER_BOUND, - QCELP_CLIP_UPPER_BOUND); - memcpy(q->prev_lspf, quantized_lspf, sizeof(q->prev_lspf)); q->prev_bitrate = q->bitrate; @@ -840,7 +845,7 @@ erasure: AVCodec qcelp_decoder = { .name = "qcelp", - .type = CODEC_TYPE_AUDIO, + .type = AVMEDIA_TYPE_AUDIO, .id = CODEC_ID_QCELP, .init = qcelp_decode_init, .decode = qcelp_decode_frame, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/qdm2.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/qdm2.c index df1479c25e..6451fbe91f 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/qdm2.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/qdm2.c @@ -23,7 +23,7 @@ */ /** - * @file libavcodec/qdm2.c + * @file * QDM2 decoder * @author Ewald Snel, Benjamin Larsson, Alex Beregszaszi, Roberto Togni * The decoder is not perfect yet, there are still some distortions @@ -38,18 +38,16 @@ #include "avcodec.h" #include "get_bits.h" #include "dsputil.h" +#include "fft.h" #include "mpegaudio.h" #include "qdm2data.h" +#include "qdm2_tablegen.h" #undef NDEBUG #include -#define SOFTCLIP_THRESHOLD 27600 -#define HARDCLIP_THRESHOLD 35716 - - #define QDM2_LIST_ADD(list, size, packet) \ do { \ if (size > 0) { \ @@ -122,7 +120,7 @@ typedef struct { } FFTCoefficient; typedef struct { - DECLARE_ALIGNED_16(QDM2Complex, complex[MPA_MAX_CHANNELS][256]); + DECLARE_ALIGNED(16, QDM2Complex, complex)[MPA_MAX_CHANNELS][256]; } QDM2FFT; /** @@ -172,9 +170,9 @@ typedef struct { float output_buffer[1024]; /// Synthesis filter - DECLARE_ALIGNED_16(MPA_INT, synth_buf[MPA_MAX_CHANNELS][512*2]); + DECLARE_ALIGNED(16, MPA_INT, synth_buf)[MPA_MAX_CHANNELS][512*2]; int synth_buf_offset[MPA_MAX_CHANNELS]; - DECLARE_ALIGNED_16(int32_t, sb_samples[MPA_MAX_CHANNELS][128][SBLIMIT]); + DECLARE_ALIGNED(16, int32_t, sb_samples)[MPA_MAX_CHANNELS][128][SBLIMIT]; /// Mixed temporary data used in decoding float tone_level[MPA_MAX_CHANNELS][30][64]; @@ -213,71 +211,6 @@ static VLC vlc_tab_type30; static VLC vlc_tab_type34; static VLC vlc_tab_fft_tone_offset[5]; -static uint16_t softclip_table[HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1]; -static float noise_table[4096]; -static uint8_t random_dequant_index[256][5]; -static uint8_t random_dequant_type24[128][3]; -static float noise_samples[128]; - -static DECLARE_ALIGNED_16(MPA_INT, mpa_window[512]); - - -static av_cold void softclip_table_init(void) { - int i; - double dfl = SOFTCLIP_THRESHOLD - 32767; - float delta = 1.0 / -dfl; - for (i = 0; i < HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1; i++) - softclip_table[i] = SOFTCLIP_THRESHOLD - ((int)(sin((float)i * delta) * dfl) & 0x0000FFFF); -} - - -// random generated table -static av_cold void rnd_table_init(void) { - int i,j; - uint32_t ldw,hdw; - uint64_t tmp64_1; - uint64_t random_seed = 0; - float delta = 1.0 / 16384.0; - for(i = 0; i < 4096 ;i++) { - random_seed = random_seed * 214013 + 2531011; - noise_table[i] = (delta * (float)(((int32_t)random_seed >> 16) & 0x00007FFF)- 1.0) * 1.3; - } - - for (i = 0; i < 256 ;i++) { - random_seed = 81; - ldw = i; - for (j = 0; j < 5 ;j++) { - random_dequant_index[i][j] = (uint8_t)((ldw / random_seed) & 0xFF); - ldw = (uint32_t)ldw % (uint32_t)random_seed; - tmp64_1 = (random_seed * 0x55555556); - hdw = (uint32_t)(tmp64_1 >> 32); - random_seed = (uint64_t)(hdw + (ldw >> 31)); - } - } - for (i = 0; i < 128 ;i++) { - random_seed = 25; - ldw = i; - for (j = 0; j < 3 ;j++) { - random_dequant_type24[i][j] = (uint8_t)((ldw / random_seed) & 0xFF); - ldw = (uint32_t)ldw % (uint32_t)random_seed; - tmp64_1 = (random_seed * 0x66666667); - hdw = (uint32_t)(tmp64_1 >> 33); - random_seed = hdw + (ldw >> 31); - } - } -} - - -static av_cold void init_noise_samples(void) { - int i; - int random_seed = 0; - float delta = 1.0 / 16384.0; - for (i = 0; i < 128;i++) { - random_seed = random_seed * 214013 + 2531011; - noise_samples[i] = (delta * (float)((random_seed >> 16) & 0x00007fff) - 1.0); - } -} - static const uint16_t qdm2_vlc_offs[] = { 0,260,566,598,894,1166,1230,1294,1678,1950,2214,2278,2310,2570,2834,3124,3448,3838, }; @@ -1684,7 +1617,7 @@ static void qdm2_synthesis_filter (QDM2Context *q, int index) for (i = 0; i < 8; i++) { ff_mpa_synth_filter(q->synth_buf[ch], &(q->synth_buf_offset[ch]), - mpa_window, &dither_state, + ff_mpa_synth_window, &dither_state, samples_ptr, q->nb_channels, q->sb_samples[ch][(8 * index) + i]); samples_ptr += 32 * q->nb_channels; @@ -1713,7 +1646,7 @@ static av_cold void qdm2_init(QDM2Context *q) { initialized = 1; qdm2_init_vlc(); - ff_mpa_synth_init(mpa_window); + ff_mpa_synth_init(ff_mpa_synth_window); softclip_table_init(); rnd_table_init(); init_noise_samples(); @@ -1929,7 +1862,7 @@ static av_cold int qdm2_decode_init(AVCodecContext *avctx) return -1; } - ff_rdft_init(&s->rdft_ctx, s->fft_order, IRDFT); + ff_rdft_init(&s->rdft_ctx, s->fft_order, IDFT_C2R); qdm2_init(s); @@ -2041,7 +1974,7 @@ static int qdm2_decode_frame(AVCodecContext *avctx, AVCodec qdm2_decoder = { .name = "qdm2", - .type = CODEC_TYPE_AUDIO, + .type = AVMEDIA_TYPE_AUDIO, .id = CODEC_ID_QDM2, .priv_data_size = sizeof(QDM2Context), .init = qdm2_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/qdm2_tablegen.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/qdm2_tablegen.c new file mode 100644 index 0000000000..c225bc4391 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/qdm2_tablegen.c @@ -0,0 +1,57 @@ +/* + * Generate a header file for hardcoded QDM2 tables + * + * Copyright (c) 2010 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 +#define CONFIG_HARDCODED_TABLES 0 +#include "qdm2_tablegen.h" +#include "tableprint.h" + +int main(void) +{ + softclip_table_init(); + rnd_table_init(); + init_noise_samples(); + + write_fileheader(); + + printf("static const uint16_t softclip_table[HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1] = {\n"); + write_uint16_array(softclip_table, HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1); + printf("};\n"); + + printf("static const float noise_table[4096] = {\n"); + write_float_array(noise_table, 4096); + printf("};\n"); + + printf("static const uint8_t random_dequant_index[256][5] = {\n"); + write_uint8_2d_array(random_dequant_index, 256, 5); + printf("};\n"); + + printf("static const uint8_t random_dequant_type24[128][3] = {\n"); + write_uint8_2d_array(random_dequant_type24, 128, 3); + printf("};\n"); + + printf("static const float noise_samples[128] = {\n"); + write_float_array(noise_samples, 128); + printf("};\n"); + + return 0; +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/qdm2_tablegen.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/qdm2_tablegen.h new file mode 100644 index 0000000000..de9ff0c902 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/qdm2_tablegen.h @@ -0,0 +1,102 @@ +/* + * Header file for hardcoded QDM2 tables + * + * Copyright (c) 2010 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 + */ + +#ifndef QDM2_TABLEGEN_H +#define QDM2_TABLEGEN_H + +#include +#include +#include "../libavutil/attributes.h" + +#define SOFTCLIP_THRESHOLD 27600 +#define HARDCLIP_THRESHOLD 35716 + +#if CONFIG_HARDCODED_TABLES +#define softclip_table_init() +#define rnd_table_init() +#define init_noise_samples() +#include "libavcodec/qdm2_tables.h" +#else +static uint16_t softclip_table[HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1]; +static float noise_table[4096]; +static uint8_t random_dequant_index[256][5]; +static uint8_t random_dequant_type24[128][3]; +static float noise_samples[128]; + +static av_cold void softclip_table_init(void) { + int i; + double dfl = SOFTCLIP_THRESHOLD - 32767; + float delta = 1.0 / -dfl; + for (i = 0; i < HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1; i++) + softclip_table[i] = SOFTCLIP_THRESHOLD - ((int)(sin((float)i * delta) * dfl) & 0x0000FFFF); +} + + +// random generated table +static av_cold void rnd_table_init(void) { + int i,j; + uint32_t ldw,hdw; + uint64_t tmp64_1; + uint64_t random_seed = 0; + float delta = 1.0 / 16384.0; + for(i = 0; i < 4096 ;i++) { + random_seed = random_seed * 214013 + 2531011; + noise_table[i] = (delta * (float)(((int32_t)random_seed >> 16) & 0x00007FFF)- 1.0) * 1.3; + } + + for (i = 0; i < 256 ;i++) { + random_seed = 81; + ldw = i; + for (j = 0; j < 5 ;j++) { + random_dequant_index[i][j] = (uint8_t)((ldw / random_seed) & 0xFF); + ldw = (uint32_t)ldw % (uint32_t)random_seed; + tmp64_1 = (random_seed * 0x55555556); + hdw = (uint32_t)(tmp64_1 >> 32); + random_seed = (uint64_t)(hdw + (ldw >> 31)); + } + } + for (i = 0; i < 128 ;i++) { + random_seed = 25; + ldw = i; + for (j = 0; j < 3 ;j++) { + random_dequant_type24[i][j] = (uint8_t)((ldw / random_seed) & 0xFF); + ldw = (uint32_t)ldw % (uint32_t)random_seed; + tmp64_1 = (random_seed * 0x66666667); + hdw = (uint32_t)(tmp64_1 >> 33); + random_seed = hdw + (ldw >> 31); + } + } +} + + +static av_cold void init_noise_samples(void) { + int i; + int random_seed = 0; + float delta = 1.0 / 16384.0; + for (i = 0; i < 128;i++) { + random_seed = random_seed * 214013 + 2531011; + noise_samples[i] = (delta * (float)((random_seed >> 16) & 0x00007fff) - 1.0); + } +} +#endif /* CONFIG_HARDCODED_TABLES */ + +#endif /* QDM2_TABLEGEN_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/qdm2data.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/qdm2data.h index 981db5488c..355d61387b 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/qdm2data.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/qdm2data.h @@ -23,7 +23,7 @@ */ /** - * @file libavcodec/qdm2data.h + * @file * Various QDM2 tables. */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/qdrw.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/qdrw.c index 0f9609159c..57500580e2 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/qdrw.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/qdrw.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/qdrw.c + * @file * Apple QuickDraw codec. */ @@ -135,23 +135,29 @@ static int decode_frame(AVCodecContext *avctx, static av_cold int decode_init(AVCodecContext *avctx){ // QdrawContext * const a = avctx->priv_data; - if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) { - return 1; - } - avctx->pix_fmt= PIX_FMT_PAL8; return 0; } +static av_cold int decode_end(AVCodecContext *avctx){ + QdrawContext * const a = avctx->priv_data; + AVFrame *pic = &a->pic; + + if (pic->data[0]) + avctx->release_buffer(avctx, pic); + + return 0; +} + AVCodec qdraw_decoder = { "qdraw", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_QDRAW, sizeof(QdrawContext), decode_init, NULL, - NULL, + decode_end, decode_frame, CODEC_CAP_DR1, .long_name = NULL_IF_CONFIG_SMALL("Apple QuickDraw"), diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/qpeg.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/qpeg.c index 6b5d8732d9..e6a0b30aef 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/qpeg.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/qpeg.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/qpeg.c + * @file * QPEG codec. */ @@ -313,7 +313,7 @@ static av_cold int decode_end(AVCodecContext *avctx){ AVCodec qpeg_decoder = { "qpeg", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_QPEG, sizeof(QpegContext), decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/qtrle.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/qtrle.c index dcb76ecfe5..1fd9a803e4 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/qtrle.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/qtrle.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/qtrle.c + * @file * QT RLE Video Decoder by Mike Melanson (melanson@pcisys.net) * For more information about the QT RLE format, visit: * http://www.pcisys.net/~melanson/codecs/ @@ -539,7 +539,7 @@ static av_cold int qtrle_decode_end(AVCodecContext *avctx) AVCodec qtrle_decoder = { "qtrle", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_QTRLE, sizeof(QtrleContext), qtrle_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/qtrleenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/qtrleenc.c index 945111a931..7f95c7f5a4 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/qtrleenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/qtrleenc.c @@ -68,9 +68,9 @@ static av_cold int qtrle_encode_init(AVCodecContext *avctx) s->avctx=avctx; switch (avctx->pix_fmt) { -/* case PIX_FMT_RGB555: + case PIX_FMT_RGB555BE: s->pixel_size = 2; - break;*/ + break; case PIX_FMT_RGB24: s->pixel_size = 3; break; @@ -322,12 +322,12 @@ static av_cold int qtrle_encode_end(AVCodecContext *avctx) AVCodec qtrle_encoder = { "qtrle", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_QTRLE, sizeof(QtrleEncContext), qtrle_encode_init, qtrle_encode_frame, qtrle_encode_end, - .pix_fmts = (enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_ARGB, PIX_FMT_NONE}, + .pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB555BE, PIX_FMT_ARGB, PIX_FMT_NONE}, .long_name = NULL_IF_CONFIG_SMALL("QuickTime Animation (RLE) video"), }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/r210dec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/r210dec.c new file mode 100644 index 0000000000..416f76498c --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/r210dec.c @@ -0,0 +1,104 @@ +/* + * R210 decoder + * + * Copyright (c) 2009 Reimar Doeffinger + * + * 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 "libavutil/bswap.h" + +static av_cold int decode_init(AVCodecContext *avctx) +{ + avctx->pix_fmt = PIX_FMT_RGB48; + avctx->bits_per_raw_sample = 10; + + avctx->coded_frame = avcodec_alloc_frame(); + + return 0; +} + +static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, + AVPacket *avpkt) +{ + int h, w; + AVFrame *pic = avctx->coded_frame; + const uint32_t *src = (const uint32_t *)avpkt->data; + int aligned_width = FFALIGN(avctx->width, 64); + uint8_t *dst_line; + + if (pic->data[0]) + avctx->release_buffer(avctx, pic); + + if (avpkt->size < 4 * aligned_width * avctx->height) { + av_log(avctx, AV_LOG_ERROR, "packet too small\n"); + return -1; + } + + pic->reference = 0; + if (avctx->get_buffer(avctx, pic) < 0) + return -1; + + pic->pict_type = FF_I_TYPE; + pic->key_frame = 1; + dst_line = pic->data[0]; + + for (h = 0; h < avctx->height; h++) { + uint16_t *dst = (uint16_t *)dst_line; + for (w = 0; w < avctx->width; w++) { + uint32_t pixel = be2me_32(*src++); + uint16_t r, g, b; + b = pixel << 6; + g = (pixel >> 4) & 0xffc0; + r = (pixel >> 14) & 0xffc0; + *dst++ = r | (r >> 10); + *dst++ = g | (g >> 10); + *dst++ = b | (b >> 10); + } + src += aligned_width - avctx->width; + dst_line += pic->linesize[0]; + } + + *data_size = sizeof(AVFrame); + *(AVFrame*)data = *avctx->coded_frame; + + return avpkt->size; +} + +static av_cold int decode_close(AVCodecContext *avctx) +{ + AVFrame *pic = avctx->coded_frame; + if (pic->data[0]) + avctx->release_buffer(avctx, pic); + av_freep(&avctx->coded_frame); + + return 0; +} + +AVCodec r210_decoder = { + "r210", + AVMEDIA_TYPE_VIDEO, + CODEC_ID_R210, + 0, + decode_init, + NULL, + decode_close, + decode_frame, + CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Uncompressed RGB 10-bit"), +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ra144.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/ra144.c index 81a29086ca..efa62c4913 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/ra144.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ra144.c @@ -22,6 +22,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/intmath.h" #include "avcodec.h" #include "get_bits.h" #include "ra144.h" @@ -33,6 +34,8 @@ typedef struct { + AVCodecContext *avctx; + unsigned int old_energy; ///< previous frame energy unsigned int lpc_tables[2][10]; @@ -55,6 +58,8 @@ static av_cold int ra144_decode_init(AVCodecContext * avctx) { RA144Context *ractx = avctx->priv_data; + ractx->avctx = avctx; + ractx->lpc_coef[0] = ractx->lpc_tables[0]; ractx->lpc_coef[1] = ractx->lpc_tables[1]; @@ -215,7 +220,7 @@ static void int_to_int16(int16_t *out, const int *inp) { int i; - for (i=0; i < 30; i++) + for (i=0; i < 10; i++) *out++ = *inp++; } @@ -226,7 +231,7 @@ static void int_to_int16(int16_t *out, const int *inp) * @return 1 if one of the reflection coefficients is greater than * 4095, 0 if not. */ -static int eval_refl(int *refl, const int16_t *coefs, RA144Context *ractx) +static int eval_refl(int *refl, const int16_t *coefs, AVCodecContext *avctx) { int b, i, j; int buffer1[10]; @@ -240,7 +245,7 @@ static int eval_refl(int *refl, const int16_t *coefs, RA144Context *ractx) refl[9] = bp2[9]; if ((unsigned) bp2[9] + 0x1000 > 0x1fff) { - av_log(ractx, AV_LOG_ERROR, "Overflow. Broken sample?\n"); + av_log(avctx, AV_LOG_ERROR, "Overflow. Broken sample?\n"); return 1; } @@ -272,10 +277,10 @@ static int interp(RA144Context *ractx, int16_t *out, int a, // Interpolate block coefficients from the this frame's forth block and // last frame's forth block. - for (i=0; i<30; i++) + for (i=0; i<10; i++) out[i] = (a * ractx->lpc_coef[0][i] + b * ractx->lpc_coef[1][i])>> 2; - if (eval_refl(work, out, ractx)) { + if (eval_refl(work, out, ractx->avctx)) { // The interpolated coefficients are unstable, copy either new or old // coefficients. int_to_int16(out, ractx->lpc_coef[copyold]); @@ -293,7 +298,7 @@ static int ra144_decode_frame(AVCodecContext * avctx, void *vdata, 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][30]; // LPC coefficients of each sub-block + uint16_t block_coefs[4][10]; // LPC coefficients of each sub-block unsigned int lpc_refl[10]; // LPC reflection coefficients of the frame int i, j; int16_t *data = vdata; @@ -348,7 +353,7 @@ static int ra144_decode_frame(AVCodecContext * avctx, void *vdata, AVCodec ra_144_decoder = { "real_144", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_RA_144, sizeof(RA144Context), ra144_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ra288.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/ra288.c index abc7df51bd..20a21f5dc7 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/ra288.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ra288.c @@ -102,10 +102,6 @@ static void decode(RA288Context *ractx, float gain, int cb_coef) gain_block[9] = 10 * log10(sum) - 32; ff_celp_lp_synthesis_filterf(block, ractx->sp_lpc, buffer, 5, 36); - - /* output */ - for (i=0; i < 5; i++) - block[i] = av_clipf(block[i], -4095./4096., 4095./4096.); } /** @@ -206,7 +202,7 @@ static int ra288_decode_frame(AVCodecContext * avctx, void *data, AVCodec ra_288_decoder = { "real_288", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_RA_288, sizeof(RA288Context), ra288_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/rangecoder.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/rangecoder.c index d750e65453..04c2738523 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/rangecoder.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/rangecoder.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/rangecoder.c + * @file * Range coder. * based upon * "Range encoding: an algorithm for removing redundancy from a digitised diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/rangecoder.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/rangecoder.h index 281c0fde33..47c0362ba3 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/rangecoder.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/rangecoder.h @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/rangecoder.h + * @file * Range coder. */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ratecontrol.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/ratecontrol.c index 442dc72b5d..e52ef1a295 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/ratecontrol.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ratecontrol.c @@ -21,10 +21,11 @@ */ /** - * @file libavcodec/ratecontrol.c + * @file * Rate control for video encoders. */ +#include "libavutil/intmath.h" #include "avcodec.h" #include "dsputil.h" #include "ratecontrol.h" @@ -106,7 +107,7 @@ int ff_rate_control_init(MpegEncContext *s) }; emms_c(); - rcc->rc_eq_eval = ff_parse(s->avctx->rc_eq ? s->avctx->rc_eq : "tex^qComp", const_names, func1, func1_names, NULL, NULL, &error); + rcc->rc_eq_eval = ff_parse_expr(s->avctx->rc_eq ? s->avctx->rc_eq : "tex^qComp", const_names, func1, func1_names, NULL, NULL, &error); if (!rcc->rc_eq_eval) { av_log(s->avctx, AV_LOG_ERROR, "Error parsing rc_eq \"%s\": %s\n", s->avctx->rc_eq, error? error : ""); return -1; @@ -254,7 +255,7 @@ void ff_rate_control_uninit(MpegEncContext *s) RateControlContext *rcc= &s->rc_context; emms_c(); - ff_eval_free(rcc->rc_eq_eval); + ff_free_expr(rcc->rc_eq_eval); av_freep(&rcc->entry); #if CONFIG_LIBXVID @@ -338,7 +339,7 @@ static double get_qscale(MpegEncContext *s, RateControlEntry *rce, double rate_f 0 }; - bits= ff_parse_eval(rcc->rc_eq_eval, const_values, rce); + bits= ff_eval_expr(rcc->rc_eq_eval, const_values, rce); if (isnan(bits)) { av_log(s->avctx, AV_LOG_ERROR, "Error evaluating rc_eq \"%s\"\n", s->avctx->rc_eq); return -1; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ratecontrol.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/ratecontrol.h index 5673750e83..d5fe2bc81d 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/ratecontrol.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ratecontrol.h @@ -24,7 +24,7 @@ #define AVCODEC_RATECONTROL_H /** - * @file libavcodec/ratecontrol.h + * @file * ratecontrol header. */ @@ -84,7 +84,7 @@ typedef struct RateControlContext{ void *non_lavc_opaque; ///< context for non lavc rc code (for example xvid) float dry_run_qscale; ///< for xvid rc int last_picture_number; ///< for xvid rc - AVEvalExpr * rc_eq_eval; + AVExpr * rc_eq_eval; }RateControlContext; struct MpegEncContext; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/raw.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/raw.c index 1f60477aef..c2ce3bc9dc 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/raw.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/raw.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/raw.c + * @file * Raw Video Codec */ @@ -35,25 +35,39 @@ const PixelFormatTag ff_raw_pixelFormatTags[] = { { PIX_FMT_YUV410P, MKTAG('Y', 'V', 'U', '9') }, { 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_GRAY8, MKTAG('Y', '8', '0', '0') }, { PIX_FMT_GRAY8, MKTAG(' ', ' ', 'Y', '8') }, { PIX_FMT_YUYV422, MKTAG('Y', 'U', 'Y', '2') }, /* Packed formats */ { PIX_FMT_YUYV422, MKTAG('Y', '4', '2', '2') }, + { PIX_FMT_YUYV422, MKTAG('V', '4', '2', '2') }, + { PIX_FMT_YUYV422, MKTAG('V', 'Y', 'U', 'Y') }, + { PIX_FMT_YUYV422, MKTAG('Y', 'U', 'N', 'V') }, { PIX_FMT_UYVY422, MKTAG('U', 'Y', 'V', 'Y') }, { PIX_FMT_UYVY422, MKTAG('H', 'D', 'Y', 'C') }, + { PIX_FMT_UYVY422, MKTAG('U', 'Y', 'N', 'V') }, + { PIX_FMT_UYVY422, MKTAG('U', 'Y', 'N', 'Y') }, + { PIX_FMT_UYVY422, MKTAG('u', 'y', 'v', '1') }, + { PIX_FMT_UYVY422, MKTAG('2', 'V', 'u', '1') }, + { PIX_FMT_UYVY422, MKTAG('A', 'V', 'R', 'n') }, /* Avid AVI Codec 1:1 */ + { PIX_FMT_UYVY422, MKTAG('A', 'V', '1', 'x') }, /* Avid 1:1x */ + { PIX_FMT_UYVY422, MKTAG('A', 'V', 'u', 'p') }, + { PIX_FMT_UYVY422, MKTAG('V', 'D', 'T', 'Z') }, /* SoftLab-NSK VideoTizer */ { PIX_FMT_GRAY8, MKTAG('G', 'R', 'E', 'Y') }, - { PIX_FMT_RGB555, MKTAG('R', 'G', 'B', 15) }, - { PIX_FMT_BGR555, MKTAG('B', 'G', 'R', 15) }, - { PIX_FMT_RGB565, MKTAG('R', 'G', 'B', 16) }, - { PIX_FMT_BGR565, MKTAG('B', 'G', 'R', 16) }, - { PIX_FMT_RGB565, MKTAG( 3 , 0 , 0 , 0 ) }, + { PIX_FMT_RGB555LE, MKTAG('R', 'G', 'B', 15) }, + { PIX_FMT_BGR555LE, MKTAG('B', 'G', 'R', 15) }, + { PIX_FMT_RGB565LE, MKTAG('R', 'G', 'B', 16) }, + { PIX_FMT_BGR565LE, MKTAG('B', 'G', 'R', 16) }, + { PIX_FMT_RGB565LE, MKTAG( 3 , 0 , 0 , 0) }, /* quicktime */ { PIX_FMT_UYVY422, MKTAG('2', 'v', 'u', 'y') }, + { PIX_FMT_UYVY422, MKTAG('2', 'V', 'u', 'y') }, { PIX_FMT_UYVY422, MKTAG('A', 'V', 'U', 'I') }, /* FIXME merge both fields */ { PIX_FMT_YUYV422, MKTAG('y', 'u', 'v', '2') }, + { PIX_FMT_YUYV422, MKTAG('y', 'u', 'v', 's') }, { PIX_FMT_PAL8, MKTAG('W', 'R', 'A', 'W') }, { PIX_FMT_NONE, 0 }, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/raw.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/raw.h index 824b8c719a..e74006ac3c 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/raw.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/raw.h @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/raw.h + * @file * Raw Video Codec */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/rawdec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/rawdec.c index 2f29271c9a..8b398d2dc9 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/rawdec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/rawdec.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/rawdec.c + * @file * Raw Video Decoder */ @@ -46,13 +46,15 @@ static const PixelFormatTag pixelFormatBpsAVI[] = { }; static const PixelFormatTag pixelFormatBpsMOV[] = { + { PIX_FMT_MONOWHITE, 1 }, + { PIX_FMT_PAL8, 2 }, { PIX_FMT_PAL8, 4 }, { PIX_FMT_PAL8, 8 }, // FIXME swscale does not support 16 bit in .mov, sample 16bit.mov // http://developer.apple.com/documentation/QuickTime/QTFF/QTFFChap3/qtff3.html - { PIX_FMT_BGR555, 16 }, + { PIX_FMT_RGB555BE, 16 }, { PIX_FMT_RGB24, 24 }, - { PIX_FMT_BGR32_1, 32 }, + { PIX_FMT_ARGB, 32 }, { PIX_FMT_NONE, 0 }, }; @@ -113,18 +115,32 @@ static int raw_decode(AVCodecContext *avctx, frame->interlaced_frame = avctx->coded_frame->interlaced_frame; frame->top_field_first = avctx->coded_frame->top_field_first; - //4bpp raw in avi and mov (yes this is ugly ...) - if(avctx->bits_per_coded_sample == 4 && avctx->pix_fmt==PIX_FMT_PAL8 && + //2bpp and 4bpp raw in avi and mov (yes this is ugly ...) + 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',' '))){ int i; - for(i=256*2; i+1 < context->length>>1; i++){ - context->buffer[2*i+0]= buf[i-256*2]>>4; - context->buffer[2*i+1]= buf[i-256*2]&15; - } - buf= context->buffer + 256*4; - buf_size= context->length - 256*4; + uint8_t *dst = context->buffer + 256*4; + buf_size = context->length - 256*4; + if (avctx->bits_per_coded_sample == 4){ + for(i=0; 2*i+1 < buf_size; i++){ + dst[2*i+0]= buf[i]>>4; + dst[2*i+1]= buf[i]&15; + } + } else + for(i=0; 4*i+3 < buf_size; i++){ + dst[4*i+0]= buf[i]>>6; + dst[4*i+1]= buf[i]>>4&3; + dst[4*i+2]= buf[i]>>2&3; + dst[4*i+3]= buf[i] &3; + } + buf= dst; } + if(avctx->codec_tag == MKTAG('A', 'V', '1', 'x') || + avctx->codec_tag == MKTAG('A', 'V', 'u', 'p')) + buf += buf_size - context->length; + if(buf_size < context->length - (avctx->pix_fmt==PIX_FMT_PAL8 ? 256*4 : 0)) return -1; @@ -136,18 +152,15 @@ static int raw_decode(AVCodecContext *avctx, memcpy(frame->data[1], avctx->palctrl->palette, AVPALETTE_SIZE); avctx->palctrl->palette_changed = 0; } + if(avctx->pix_fmt==PIX_FMT_BGR24 && ((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', 'U', '9')) - { - // swap fields - unsigned char *tmp = picture->data[1]; - picture->data[1] = picture->data[2]; - picture->data[2] = tmp; - } + FFSWAP(uint8_t *, picture->data[1], picture->data[2]); if(avctx->codec_tag == AV_RL32("yuv2") && avctx->pix_fmt == PIX_FMT_YUYV422) { @@ -174,7 +187,7 @@ static av_cold int raw_close_decoder(AVCodecContext *avctx) AVCodec rawvideo_decoder = { "rawvideo", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_RAWVIDEO, sizeof(RawVideoContext), raw_init_decoder, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/rawenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/rawenc.c index 82a543ad46..419970486b 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/rawenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/rawenc.c @@ -20,12 +20,13 @@ */ /** - * @file libavcodec/rawenc.c + * @file * Raw Video Encoder */ #include "avcodec.h" #include "raw.h" +#include "libavutil/pixdesc.h" #include "libavutil/intreadwrite.h" static av_cold int raw_init_encoder(AVCodecContext *avctx) @@ -33,6 +34,7 @@ static av_cold int raw_init_encoder(AVCodecContext *avctx) avctx->coded_frame = (AVFrame *)avctx->priv_data; avctx->coded_frame->pict_type = FF_I_TYPE; avctx->coded_frame->key_frame = 1; + avctx->bits_per_coded_sample = av_get_bits_per_pixel(&av_pix_fmt_descriptors[avctx->pix_fmt]); if(!avctx->codec_tag) avctx->codec_tag = avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt); return 0; @@ -55,7 +57,7 @@ static int raw_encode(AVCodecContext *avctx, AVCodec rawvideo_encoder = { "rawvideo", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_RAWVIDEO, sizeof(AVFrame), raw_init_encoder, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/rdft.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/rdft.c index a5cf4f9753..f37263b7c2 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/rdft.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/rdft.c @@ -18,63 +18,43 @@ * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include #include -#include "dsputil.h" +#include "libavutil/mathematics.h" +#include "fft.h" /** - * @file libavcodec/rdft.c + * @file * (Inverse) Real Discrete Fourier Transforms. */ /* sin(2*pi*x/n) for 0<=xnbits = nbits; - s->inverse = trans == IRDFT || trans == IRIDFT; - s->sign_convention = trans == RIDFT || trans == IRIDFT ? 1 : -1; - - if (nbits < 4 || nbits > 16) - return -1; - - if (ff_fft_init(&s->fft, nbits-1, trans == IRDFT || trans == RIDFT) < 0) - return -1; - - s->tcos = ff_cos_tabs[nbits-4]; - s->tsin = ff_sin_tabs[nbits-4]+(trans == RDFT || trans == IRIDFT)*(n>>2); - for (i = 0; i < (n>>2); i++) { - s->tcos[i] = cos(i*theta); - s->tsin[i] = sin(i*theta); - } - return 0; -} - /** Map one real FFT into two parallel real even and odd FFTs. Then interleave * the two real FFTs into one complex FFT. Unmangle the results. * ref: http://www.engineeringproductivitytools.com/stuff/T0001/PT10.HTM */ -void ff_rdft_calc_c(RDFTContext* s, FFTSample* data) +static void ff_rdft_calc_c(RDFTContext* s, FFTSample* data) { int i, i1, i2; FFTComplex ev, od; @@ -116,9 +96,35 @@ void ff_rdft_calc_c(RDFTContext* s, FFTSample* data) } } -void ff_rdft_calc(RDFTContext *s, FFTSample *data) +av_cold int ff_rdft_init(RDFTContext *s, int nbits, enum RDFTransformType trans) { - ff_rdft_calc_c(s, data); + int n = 1 << nbits; + int i; + const double theta = (trans == DFT_R2C || trans == DFT_C2R ? -1 : 1)*2*M_PI/n; + + s->nbits = nbits; + s->inverse = trans == IDFT_C2R || trans == DFT_C2R; + s->sign_convention = trans == IDFT_R2C || trans == DFT_C2R ? 1 : -1; + + if (nbits < 4 || nbits > 16) + return -1; + + if (ff_fft_init(&s->fft, nbits-1, trans == IDFT_C2R || trans == IDFT_R2C) < 0) + return -1; + + ff_init_ff_cos_tabs(nbits); + s->tcos = ff_cos_tabs[nbits]; + s->tsin = ff_sin_tabs[nbits]+(trans == DFT_R2C || trans == DFT_C2R)*(n>>2); +#if !CONFIG_HARDCODED_TABLES + for (i = 0; i < (n>>2); i++) { + s->tsin[i] = sin(i*theta); + } +#endif + s->rdft_calc = ff_rdft_calc_c; + + if (ARCH_ARM) ff_rdft_init_arm(s); + + return 0; } av_cold void ff_rdft_end(RDFTContext *s) diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/rectangle.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/rectangle.h index cfd0f0696d..cf4a9ccec3 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/rectangle.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/rectangle.h @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/rectangle.h + * @file * useful rectangle filling function * @author Michael Niedermayer */ @@ -37,11 +37,11 @@ * fill a rectangle. * @param h height of the rectangle, should be a constant * @param w width of the rectangle, should be a constant - * @param size the size of val (1 or 4), should be a constant + * @param size the size of val (1, 2 or 4), should be a constant */ static av_always_inline void fill_rectangle(void *vp, int w, int h, int stride, uint32_t val, int size){ uint8_t *p= (uint8_t*)vp; - assert(size==1 || size==4); + assert(size==1 || size==2 || size==4); assert(w<=4); w *= size; @@ -58,7 +58,7 @@ static av_always_inline void fill_rectangle(void *vp, int w, int h, int stride, *(uint16_t*)(p + 2*stride)= v; *(uint16_t*)(p + 3*stride)= v; }else if(w==4){ - const uint32_t v= size==4 ? val : val*0x01010101; + const uint32_t v= size==4 ? val : size==2 ? val*0x00010001 : val*0x01010101; *(uint32_t*)(p + 0*stride)= v; if(h==1) return; *(uint32_t*)(p + 1*stride)= v; @@ -68,7 +68,7 @@ static av_always_inline void fill_rectangle(void *vp, int w, int h, int stride, }else if(w==8){ //gcc can't optimize 64bit math on x86_32 #if HAVE_FAST_64BIT - const uint64_t v= val*0x0100000001ULL; + const uint64_t v= size==2 ? val*0x0001000100010001ULL : val*0x0100000001ULL; *(uint64_t*)(p + 0*stride)= v; if(h==1) return; *(uint64_t*)(p + 1*stride)= v; @@ -87,16 +87,17 @@ static av_always_inline void fill_rectangle(void *vp, int w, int h, int stride, *(uint64_t*)(p + 0+3*stride)= v; *(uint64_t*)(p + 8+3*stride)= v; #else - *(uint32_t*)(p + 0+0*stride)= val; - *(uint32_t*)(p + 4+0*stride)= val; + const uint32_t v= size==2 ? val*0x00010001 : val; + *(uint32_t*)(p + 0+0*stride)= v; + *(uint32_t*)(p + 4+0*stride)= v; if(h==1) return; - *(uint32_t*)(p + 0+1*stride)= val; - *(uint32_t*)(p + 4+1*stride)= val; + *(uint32_t*)(p + 0+1*stride)= v; + *(uint32_t*)(p + 4+1*stride)= v; if(h==2) return; - *(uint32_t*)(p + 0+2*stride)= val; - *(uint32_t*)(p + 4+2*stride)= val; - *(uint32_t*)(p + 0+3*stride)= val; - *(uint32_t*)(p + 4+3*stride)= val; + *(uint32_t*)(p + 0+2*stride)= v; + *(uint32_t*)(p + 4+2*stride)= v; + *(uint32_t*)(p + 0+3*stride)= v; + *(uint32_t*)(p + 4+3*stride)= v; }else if(w==16){ *(uint32_t*)(p + 0+0*stride)= val; *(uint32_t*)(p + 4+0*stride)= val; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/resample.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/resample.c index e1d29f7e92..b008180fe5 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/resample.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/resample.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/resample.c + * @file * samplerate conversion for both audio and video */ @@ -36,7 +36,7 @@ static const char *context_to_name(void *ptr) } static const AVOption options[] = {{NULL}}; -static const AVClass audioresample_context_class = { "ReSampleContext", context_to_name, options }; +static const AVClass audioresample_context_class = { "ReSampleContext", context_to_name, options, LIBAVUTIL_VERSION_INT }; struct ReSampleContext { struct AVResampleContext *resample_context; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/resample2.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/resample2.c index 31d2be7ded..45f41a144c 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/resample2.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/resample2.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/resample2.c + * @file * audio resampling * @author Michael Niedermayer */ @@ -76,11 +76,13 @@ typedef struct AVResampleContext{ */ static double bessel(double x){ double v=1; + double lastv=0; double t=1; int i; x= x*x/4; - for(i=1; i<50; i++){ + for(i=1; v != lastv; i++){ + lastv=v; t *= x/(i*i); v += t; } @@ -93,7 +95,7 @@ static double bessel(double x){ * @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 */ -void av_build_filter(FELEM *filter, double factor, int tap_count, int phase_count, int scale, int type){ +static void build_filter(FELEM *filter, double factor, int tap_count, int phase_count, int scale, int type){ int ph, i; double x, y, w, tab[tap_count]; const int center= (tap_count-1)/2; @@ -187,7 +189,7 @@ AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_size, c->filter_length= FFMAX((int)ceil(filter_size/factor), 1); c->filter_bank= av_mallocz(c->filter_length*(phase_count+1)*sizeof(FELEM)); - av_build_filter(c->filter_bank, factor, c->filter_length, phase_count, 1<filter_bank, factor, c->filter_length, phase_count, 1<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]; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/rl.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/rl.h index 64cbeddfaa..b2445890e6 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/rl.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/rl.h @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/rl.h + * @file * rl header. */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/rl2.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/rl2.c index 721e5706ac..30f5e839cc 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/rl2.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/rl2.c @@ -21,7 +21,7 @@ /** * RL2 Video Decoder - * @file libavcodec/rl2.c + * @file * @author Sascha Sommer (saschasommer@freenet.de) * For more information about the RL2 format, visit: * http://wiki.multimedia.cx/index.php?title=RL2 @@ -230,7 +230,7 @@ static av_cold int rl2_decode_end(AVCodecContext *avctx) AVCodec rl2_decoder = { "rl2", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_RL2, sizeof(Rl2Context), rl2_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/roqaudioenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/roqaudioenc.c index 5e5dde73fe..11fd6f06cb 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/roqaudioenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/roqaudioenc.c @@ -21,6 +21,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/intmath.h" #include "avcodec.h" #include "bytestream.h" @@ -29,7 +30,6 @@ #define MAX_DPCM (127*127) -static unsigned char dpcmValues[MAX_DPCM]; typedef struct @@ -37,18 +37,6 @@ typedef struct short lastSample[2]; } ROQDPCMContext; -static av_cold void roq_dpcm_table_init(void) -{ - int i; - - /* Create a table of quick DPCM values */ - for (i=0; imid); - } -} - static av_cold int roq_dpcm_encode_init(AVCodecContext *avctx) { ROQDPCMContext *context = avctx->priv_data; @@ -66,8 +54,6 @@ static av_cold int roq_dpcm_encode_init(AVCodecContext *avctx) return -1; } - roq_dpcm_table_init(); - avctx->frame_size = ROQ_FIRST_FRAME_SIZE; context->lastSample[0] = context->lastSample[1] = 0; @@ -92,8 +78,10 @@ static unsigned char dpcm_predict(short *previous, short current) if (diff >= MAX_DPCM) result = 127; - else - result = dpcmValues[diff]; + else { + result = ff_sqrt(diff); + result += diff > result*result+result; + } /* See if this overflows */ retry: @@ -167,13 +155,13 @@ static av_cold int roq_dpcm_encode_close(AVCodecContext *avctx) AVCodec roq_dpcm_encoder = { "roq_dpcm", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_ROQ_DPCM, sizeof(ROQDPCMContext), roq_dpcm_encode_init, roq_dpcm_encode_frame, roq_dpcm_encode_close, NULL, - .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, + .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, .long_name = NULL_IF_CONFIG_SMALL("id RoQ DPCM"), }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/roqvideo.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/roqvideo.c index d97c4361ce..830eb7b329 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/roqvideo.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/roqvideo.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/roqvideo.c + * @file * id RoQ Video common functions based on work by Dr. Tim Ferguson */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/roqvideodec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/roqvideodec.c index 8e3bdb0dc3..7c6f5ff6fb 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/roqvideodec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/roqvideodec.c @@ -19,7 +19,7 @@ */ /** - * @file libavcodec/roqvideodec.c + * @file * id RoQ Video Decoder by Dr. Tim Ferguson * For more information about the id RoQ format, visit: * http://www.csse.monash.edu.au/~timf/ @@ -212,7 +212,7 @@ static av_cold int roq_decode_end(AVCodecContext *avctx) AVCodec roq_decoder = { "roqvideo", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_ROQ, sizeof(RoqContext), roq_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/roqvideoenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/roqvideoenc.c index e7cfcb7036..f9fbb64bd8 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/roqvideoenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/roqvideoenc.c @@ -23,7 +23,7 @@ */ /** - * @file libavcodec/roqvideoenc.c + * @file * id RoQ encoder by Vitor. Based on the Switchblade3 library and the * Switchblade3 FFmpeg glue by Eric Lasota. */ @@ -939,12 +939,6 @@ static int roq_encode_init(AVCodecContext *avctx) if (((avctx->width)&(avctx->width-1))||((avctx->height)&(avctx->height-1))) av_log(avctx, AV_LOG_ERROR, "Warning: dimensions not power of two\n"); - if (avcodec_check_dimensions(avctx, avctx->width, avctx->height)) { - av_log(avctx, AV_LOG_ERROR, "Invalid dimensions (%dx%d)\n", - avctx->width, avctx->height); - return -1; - } - enc->width = avctx->width; enc->height = avctx->height; @@ -1063,13 +1057,13 @@ static int roq_encode_end(AVCodecContext *avctx) AVCodec roq_encoder = { "roqvideo", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_ROQ, sizeof(RoqContext), roq_encode_init, roq_encode_frame, roq_encode_end, - .supported_framerates = (AVRational[]){{30,1}, {0,0}}, - .pix_fmts = (enum PixelFormat[]){PIX_FMT_YUV444P, PIX_FMT_NONE}, + .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"), }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/rpza.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/rpza.c index e24508df49..e103f525d2 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/rpza.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/rpza.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/rpza.c + * @file * QT RPZA Video Decoder by Roberto Togni * For more information about the RPZA format, visit: * http://www.pcisys.net/~melanson/codecs/ @@ -277,7 +277,7 @@ static av_cold int rpza_decode_end(AVCodecContext *avctx) AVCodec rpza_decoder = { "rpza", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_RPZA, sizeof(RpzaContext), rpza_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/rtjpeg.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/rtjpeg.h index d2745f824b..4bcb9f70ca 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/rtjpeg.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/rtjpeg.h @@ -31,7 +31,7 @@ typedef struct { uint8_t scan[64]; uint32_t lquant[64]; uint32_t cquant[64]; - DECLARE_ALIGNED_16(DCTELEM, block[64]); + DECLARE_ALIGNED(16, DCTELEM, block)[64]; } RTJpegContext; void rtjpeg_decode_init(RTJpegContext *c, DSPContext *dsp, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/rv10.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/rv10.c index d552bf9501..b6ca031dfa 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/rv10.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/rv10.c @@ -21,13 +21,15 @@ */ /** - * @file libavcodec/rv10.c + * @file * RV10/RV20 decoder */ #include "avcodec.h" #include "dsputil.h" #include "mpegvideo.h" +#include "mpeg4video.h" +#include "h263.h" //#define DEBUG @@ -362,16 +364,17 @@ static int rv20_decode_picture_header(MpegEncContext *s) new_w= 4*((uint8_t*)s->avctx->extradata)[6+2*f]; new_h= 4*((uint8_t*)s->avctx->extradata)[7+2*f]; }else{ - new_w= s->width; //FIXME wrong we of course must save the original in the context - new_h= s->height; + new_w= s->orig_width ; + new_h= s->orig_height; } if(new_w != s->width || new_h != s->height){ av_log(s->avctx, AV_LOG_DEBUG, "attempting to change resolution to %dx%d\n", new_w, new_h); - if (avcodec_check_dimensions(s->avctx, new_h, new_w) < 0) + if (avcodec_check_dimensions(s->avctx, new_w, new_h) < 0) return -1; MPV_common_end(s); - s->width = s->avctx->width = new_w; - s->height = s->avctx->height= new_h; + avcodec_set_dimensions(s->avctx, new_w, new_h); + s->width = new_w; + s->height = new_h; if (MPV_common_init(s) < 0) return -1; } @@ -452,8 +455,8 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx) s->out_format = FMT_H263; s->codec_id= avctx->codec_id; - s->width = avctx->coded_width; - s->height = avctx->coded_height; + s->orig_width = s->width = avctx->coded_width; + s->orig_height= s->height = avctx->coded_height; s->h263_long_vectors= ((uint8_t*)avctx->extradata)[3] & 1; avctx->sub_id= AV_RB32((uint8_t*)avctx->extradata + 4); @@ -519,7 +522,7 @@ static av_cold int rv10_decode_end(AVCodecContext *avctx) } static int rv10_decode_packet(AVCodecContext *avctx, - const uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size, int buf_size2) { MpegEncContext *s = avctx->priv_data; int mb_count, mb_pos, left, start_mb_x; @@ -602,6 +605,12 @@ static int rv10_decode_packet(AVCodecContext *avctx, s->mv_type = MV_TYPE_16X16; ret=ff_h263_decode_mb(s, s->block); + if (ret != SLICE_ERROR && s->gb.size_in_bits < get_bits_count(&s->gb) && 8*buf_size2 >= get_bits_count(&s->gb)){ + av_log(avctx, AV_LOG_DEBUG, "update size from %d to %d\n", s->gb.size_in_bits, 8*buf_size2); + s->gb.size_in_bits= 8*buf_size2; + ret= SLICE_OK; + } + if (ret == SLICE_ERROR || s->gb.size_in_bits < get_bits_count(&s->gb)) { av_log(s->avctx, AV_LOG_ERROR, "ERROR at MB %d %d\n", s->mb_x, s->mb_y); return -1; @@ -624,7 +633,7 @@ static int rv10_decode_packet(AVCodecContext *avctx, ff_er_add_slice(s, start_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, AC_END|DC_END|MV_END); - return buf_size; + return s->gb.size_in_bits; } static int get_slice_offset(AVCodecContext *avctx, const uint8_t *buf, int n) @@ -661,14 +670,20 @@ static int rv10_decode_frame(AVCodecContext *avctx, for(i=0; i= slice_count) + size2= buf_size - offset; + else + size2= get_slice_offset(avctx, slices_hdr, i+2) - offset; + + if(rv10_decode_packet(avctx, buf+offset, size, size2) > 8*size) + i++; } if(s->current_picture_ptr != NULL && s->mb_y>=s->mb_height){ @@ -693,7 +708,7 @@ static int rv10_decode_frame(AVCodecContext *avctx, AVCodec rv10_decoder = { "rv10", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_RV10, sizeof(MpegEncContext), rv10_decode_init, @@ -707,7 +722,7 @@ AVCodec rv10_decoder = { AVCodec rv20_decoder = { "rv20", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_RV20, sizeof(MpegEncContext), rv10_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/rv10enc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/rv10enc.c index 41ccbcafba..51ca69118a 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/rv10enc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/rv10enc.c @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/rv10enc.c + * @file * RV10 encoder */ @@ -58,12 +58,12 @@ void rv10_encode_picture_header(MpegEncContext *s, int picture_number) AVCodec rv10_encoder = { "rv10", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_RV10, sizeof(MpegEncContext), MPV_encode_init, MPV_encode_picture, MPV_encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, .long_name= NULL_IF_CONFIG_SMALL("RealVideo 1.0"), }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/rv20enc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/rv20enc.c index 3af504d836..5ab0b9a039 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/rv20enc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/rv20enc.c @@ -21,11 +21,12 @@ */ /** - * @file libavcodec/rv20enc.c + * @file * RV20 encoder */ #include "mpegvideo.h" +#include "h263.h" #include "put_bits.h" void rv20_encode_picture_header(MpegEncContext *s, int picture_number){ @@ -58,12 +59,12 @@ void rv20_encode_picture_header(MpegEncContext *s, int picture_number){ AVCodec rv20_encoder = { "rv20", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_RV20, sizeof(MpegEncContext), MPV_encode_init, MPV_encode_picture, MPV_encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, .long_name= NULL_IF_CONFIG_SMALL("RealVideo 2.0"), }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/rv30.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/rv30.c index 4cb2c3d900..22a5dd5b64 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/rv30.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/rv30.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/rv30.c + * @file * RV30 decoder */ @@ -268,7 +268,7 @@ static av_cold int rv30_decode_init(AVCodecContext *avctx) AVCodec rv30_decoder = { "rv30", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_RV30, sizeof(RV34DecContext), rv30_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/rv30data.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/rv30data.h index 2a8f3ad991..9cc48a6a31 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/rv30data.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/rv30data.h @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/rv30data.h + * @file * miscellaneous RV30 tables */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/rv30dsp.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/rv30dsp.c index c0509ea650..4700e7868c 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/rv30dsp.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/rv30dsp.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/rv30dsp.c + * @file * RV30 decoder motion compensation functions */ @@ -251,7 +251,7 @@ RV30_MC(put_, 16) RV30_MC(avg_, 8) RV30_MC(avg_, 16) -void ff_rv30dsp_init(DSPContext* c, AVCodecContext *avctx) { +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; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/rv34.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/rv34.c index f3e571a29c..88652f9fe1 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/rv34.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/rv34.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/rv34.c + * @file * RV30/40 decoder common data */ @@ -37,6 +37,12 @@ //#define DEBUG +static inline void ZERO8x2(void* dst, int stride) +{ + fill_rectangle(dst, 1, 2, stride, 0, 4); + fill_rectangle(((uint8_t*)(dst))+4, 1, 2, stride, 0, 4); +} + /** translation of RV30/40 macroblock types to lavc ones */ static const int rv34_mb_type_to_lavc[12] = { MB_TYPE_INTRA, @@ -440,7 +446,7 @@ static const uint8_t part_sizes_w[RV34_MB_TYPES] = { 2, 2, 2, 1, 2, 2, 2, 2, 2, static const uint8_t part_sizes_h[RV34_MB_TYPES] = { 2, 2, 2, 1, 2, 2, 2, 2, 1, 2, 2, 2 }; /** availability index for subblocks */ -static const uint8_t avail_indexes[4] = { 5, 6, 9, 10 }; +static const uint8_t avail_indexes[4] = { 6, 7, 10, 11 }; /** * motion vector prediction @@ -553,21 +559,21 @@ static void rv34_pred_mv_b(RV34DecContext *r, int block_type, int dir) memset(A, 0, sizeof(A)); memset(B, 0, sizeof(B)); memset(C, 0, sizeof(C)); - if((r->avail_cache[5-1] & type) & mask){ + 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]; has_A = 1; } - if((r->avail_cache[5-4] & type) & mask){ + 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]; has_B = 1; } - if(r->avail_cache[5-4] && (r->avail_cache[5-2] & type) & mask){ + 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]; has_C = 1; - }else if((s->mb_x+1) == s->mb_width && (r->avail_cache[5-5] & type) & mask){ + }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]; has_C = 1; @@ -584,8 +590,9 @@ static void rv34_pred_mv_b(RV34DecContext *r, int block_type, int dir) cur_pic->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) - fill_rectangle(cur_pic->motion_val[!dir][mv_pos], 2, 2, s->b8_stride, 0, 4); + if(block_type == RV34_MB_B_BACKWARD || block_type == RV34_MB_B_FORWARD){ + ZERO8x2(cur_pic->motion_val[!dir][mv_pos], s->b8_stride); + } } /** @@ -806,11 +813,11 @@ static int rv34_decode_mv(RV34DecContext *r, int block_type) switch(block_type){ case RV34_MB_TYPE_INTRA: case RV34_MB_TYPE_INTRA16x16: - fill_rectangle(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], 2, 2, s->b8_stride, 0, 4); + ZERO8x2(s->current_picture_ptr->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 == FF_P_TYPE){ - fill_rectangle(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], 2, 2, s->b8_stride, 0, 4); + ZERO8x2(s->current_picture_ptr->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; } @@ -818,8 +825,8 @@ static int rv34_decode_mv(RV34DecContext *r, int block_type) //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]; if(IS_INTRA(next_bt) || IS_SKIP(next_bt)){ - fill_rectangle(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], 2, 2, s->b8_stride, 0, 4); - fill_rectangle(s->current_picture_ptr->motion_val[1][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], 2, 2, s->b8_stride, 0, 4); + 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); }else for(j = 0; j < 2; j++) for(i = 0; i < 2; i++) @@ -830,7 +837,7 @@ static int rv34_decode_mv(RV34DecContext *r, int block_type) rv34_mc_2mv(r, block_type); else rv34_mc_2mv_skip(r); - fill_rectangle(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], 2, 2, s->b8_stride, 0, 4); + ZERO8x2(s->current_picture_ptr->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: @@ -958,17 +965,17 @@ static void rv34_output_macroblock(RV34DecContext *r, int8_t *intra_types, int c int idx; // Set neighbour information. - if(r->avail_cache[0]) - avail[0] = 1; if(r->avail_cache[1]) - avail[1] = avail[2] = 1; + avail[0] = 1; if(r->avail_cache[2]) - avail[3] = avail[4] = 1; + avail[1] = avail[2] = 1; if(r->avail_cache[3]) - avail[5] = 1; + avail[3] = avail[4] = 1; if(r->avail_cache[4]) + avail[5] = 1; + if(r->avail_cache[5]) avail[8] = avail[16] = 1; - if(r->avail_cache[8]) + if(r->avail_cache[9]) avail[24] = avail[32] = 1; Y = s->dest[0]; @@ -987,9 +994,9 @@ static void rv34_output_macroblock(RV34DecContext *r, int8_t *intra_types, int c intra_types += r->intra_types_stride; } intra_types -= r->intra_types_stride * 4; - fill_rectangle(r->avail_cache + 5, 2, 2, 4, 0, 4); + fill_rectangle(r->avail_cache + 6, 2, 2, 4, 0, 4); for(j = 0; j < 2; j++){ - idx = 5 + j*4; + idx = 6 + j*4; for(i = 0; i < 2; i++, cbp >>= 1, idx++){ rv34_pred_4x4_block(r, U + i*4 + j*4*s->uvlinesize, s->uvlinesize, ittrans[intra_types[i*2+j*2*r->intra_types_stride]], r->avail_cache[idx-4], r->avail_cache[idx-1], !i && !j, r->avail_cache[idx-3]); rv34_pred_4x4_block(r, V + i*4 + j*4*s->uvlinesize, s->uvlinesize, ittrans[intra_types[i*2+j*2*r->intra_types_stride]], r->avail_cache[idx-4], r->avail_cache[idx-1], !i && !j, r->avail_cache[idx-3]); @@ -1002,7 +1009,7 @@ static void rv34_output_macroblock(RV34DecContext *r, int8_t *intra_types, int c } }else{ itype = ittrans16[intra_types[0]]; - itype = adjust_pred16(itype, r->avail_cache[5-4], r->avail_cache[5-1]); + itype = adjust_pred16(itype, r->avail_cache[6-4], r->avail_cache[6-1]); r->h.pred16x16[itype](Y, s->linesize); dsp->add_pixels_clamped(s->block[0], Y, s->linesize); dsp->add_pixels_clamped(s->block[1], Y + 8, s->linesize); @@ -1012,7 +1019,7 @@ static void rv34_output_macroblock(RV34DecContext *r, int8_t *intra_types, int c itype = ittrans16[intra_types[0]]; if(itype == PLANE_PRED8x8) itype = DC_PRED8x8; - itype = adjust_pred16(itype, r->avail_cache[5-4], r->avail_cache[5-1]); + itype = adjust_pred16(itype, r->avail_cache[6-4], r->avail_cache[6-1]); r->h.pred8x8[itype](U, s->uvlinesize); dsp->add_pixels_clamped(s->block[4], U, s->uvlinesize); r->h.pred8x8[itype](V, s->uvlinesize); @@ -1173,18 +1180,18 @@ static int rv34_decode_macroblock(RV34DecContext *r, int8_t *intra_types) // Calculate which neighbours are available. Maybe it's worth optimizing too. memset(r->avail_cache, 0, sizeof(r->avail_cache)); - fill_rectangle(r->avail_cache + 5, 2, 2, 4, 1, 4); + fill_rectangle(r->avail_cache + 6, 2, 2, 4, 1, 4); 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[4] = - r->avail_cache[8] = s->current_picture_ptr->mb_type[mb_pos - 1]; + r->avail_cache[5] = + r->avail_cache[9] = s->current_picture_ptr->mb_type[mb_pos - 1]; if(dist >= s->mb_width) - r->avail_cache[1] = - r->avail_cache[2] = s->current_picture_ptr->mb_type[mb_pos - s->mb_stride]; + r->avail_cache[2] = + r->avail_cache[3] = s->current_picture_ptr->mb_type[mb_pos - s->mb_stride]; if(((s->mb_x+1) < s->mb_width) && dist >= s->mb_width - 1) - r->avail_cache[3] = s->current_picture_ptr->mb_type[mb_pos - s->mb_stride + 1]; + r->avail_cache[4] = s->current_picture_ptr->mb_type[mb_pos - s->mb_stride + 1]; if(s->mb_x && dist > s->mb_width) - r->avail_cache[0] = s->current_picture_ptr->mb_type[mb_pos - s->mb_stride - 1]; + r->avail_cache[1] = s->current_picture_ptr->mb_type[mb_pos - s->mb_stride - 1]; s->qscale = r->si.quant; cbp = cbp2 = rv34_decode_mb_header(r, intra_types); @@ -1280,6 +1287,7 @@ static int rv34_decode_slice(RV34DecContext *r, int end, const uint8_t* buf, int MPV_common_end(s); s->width = r->si.width; s->height = r->si.height; + avcodec_set_dimensions(s->avctx, s->width, s->height); if(MPV_common_init(s) < 0) return -1; r->intra_types_stride = s->mb_width*4 + 4; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/rv34.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/rv34.h index 0da348b6ab..24a27ce482 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/rv34.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/rv34.h @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/rv34.h + * @file * RV30 and RV40 decoder common data declarations */ @@ -111,7 +111,7 @@ typedef struct RV34DecContext{ int *deblock_coefs; ///< deblock coefficients for each macroblock /** 8x8 block available flags (for MV prediction) */ - DECLARE_ALIGNED_8(uint32_t, avail_cache[3*4]); + DECLARE_ALIGNED(8, uint32_t, avail_cache)[3*4]; int (*parse_slice_header)(struct RV34DecContext *r, GetBitContext *gb, SliceInfo *si); int (*decode_mb_info)(struct RV34DecContext *r); diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/rv34data.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/rv34data.h index 87dbee26e4..2155084d09 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/rv34data.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/rv34data.h @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/rv34data.h + * @file * miscellaneous RV30/40 tables */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/rv34vlc.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/rv34vlc.h index cfd37bf884..2b89e4cb46 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/rv34vlc.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/rv34vlc.h @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/rv34vlc.h + * @file * RV30/40 VLC tables */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/rv40.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/rv40.c index c20a85ecda..abdeeffb79 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/rv40.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/rv40.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/rv40.c + * @file * RV40 decoder */ @@ -235,13 +235,13 @@ static int rv40_decode_mb_info(RV34DecContext *r) if(--r->s.mb_skip_run) return RV34_MB_SKIP; - if(r->avail_cache[5-1]) + if(r->avail_cache[6-1]) blocks[r->mb_type[mb_pos - 1]]++; - if(r->avail_cache[5-4]){ + if(r->avail_cache[6-4]){ blocks[r->mb_type[mb_pos - s->mb_stride]]++; - if(r->avail_cache[5-2]) + if(r->avail_cache[6-2]) blocks[r->mb_type[mb_pos - s->mb_stride + 1]]++; - if(r->avail_cache[5-5]) + if(r->avail_cache[6-5]) blocks[r->mb_type[mb_pos - s->mb_stride - 1]]++; } @@ -668,7 +668,7 @@ static av_cold int rv40_decode_init(AVCodecContext *avctx) AVCodec rv40_decoder = { "rv40", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_RV40, sizeof(RV34DecContext), rv40_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/rv40data.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/rv40data.h index 648f095c77..5566569201 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/rv40data.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/rv40data.h @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/rv40data.h + * @file * miscellaneous RV40 tables */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/rv40dsp.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/rv40dsp.c index 9226225a19..27bc79eec0 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/rv40dsp.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/rv40dsp.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/rv40dsp.c + * @file * RV40 decoder motion compensation functions */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/rv40vlc2.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/rv40vlc2.h index ef24c25305..15119a145b 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/rv40vlc2.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/rv40vlc2.h @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/rv40vlc2.h + * @file * RV40 VLC tables used for macroblock information decoding */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/sbr.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/sbr.h new file mode 100644 index 0000000000..2d9f4a519d --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/sbr.h @@ -0,0 +1,183 @@ +/* + * Spectral Band Replication definitions and structures + * Copyright (c) 2008-2009 Robert Swain ( rob opendot cl ) + * Copyright (c) 2010 Alex Converse + * + * 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 + * Spectral Band Replication definitions and structures + * @author Robert Swain ( rob opendot cl ) + */ + +#ifndef AVCODEC_SBR_H +#define AVCODEC_SBR_H + +#include +#include "fft.h" + +/** + * Spectral Band Replication header - spectrum parameters that invoke a reset if they differ from the previous header. + */ +typedef struct { + uint8_t bs_start_freq; + uint8_t bs_stop_freq; + uint8_t bs_xover_band; + + /** + * @defgroup bs_header_extra_1 Variables associated with bs_header_extra_1 + * @{ + */ + uint8_t bs_freq_scale; + uint8_t bs_alter_scale; + uint8_t bs_noise_bands; + /** @} */ +} SpectrumParameters; + +#define SBR_SYNTHESIS_BUF_SIZE ((1280-128)*2) + +/** + * Spectral Band Replication per channel data + */ +typedef struct { + /** + * @defgroup bitstream Main bitstream data variables + * @{ + */ + unsigned bs_frame_class; + unsigned bs_add_harmonic_flag; + unsigned bs_num_env; + uint8_t bs_freq_res[7]; + unsigned bs_num_noise; + uint8_t bs_df_env[5]; + uint8_t bs_df_noise[2]; + uint8_t bs_invf_mode[2][5]; + uint8_t bs_add_harmonic[48]; + unsigned bs_amp_res; + /** @} */ + + /** + * @defgroup state State variables + * @{ + */ + DECLARE_ALIGNED(16, float, synthesis_filterbank_samples)[SBR_SYNTHESIS_BUF_SIZE]; + DECLARE_ALIGNED(16, float, analysis_filterbank_samples) [1312]; + int synthesis_filterbank_samples_offset; + ///l_APrev and l_A + int e_a[2]; + ///Chirp factors + float bw_array[5]; + ///QMF values of the original signal + float W[2][32][32][2]; + ///QMF output of the HF adjustor + float Y[2][38][64][2]; + float g_temp[42][48]; + float q_temp[42][48]; + uint8_t s_indexmapped[8][48]; + ///Envelope scalefactors + float env_facs[6][48]; + ///Noise scalefactors + float noise_facs[3][5]; + ///Envelope time borders + uint8_t t_env[8]; + ///Envelope time border of the last envelope of the previous frame + uint8_t t_env_num_env_old; + ///Noise time borders + uint8_t t_q[3]; + unsigned f_indexnoise; + unsigned f_indexsine; + /** @} */ +} SBRData; + +/** + * Spectral Band Replication + */ +typedef struct { + int sample_rate; + int start; + int reset; + SpectrumParameters spectrum_params; + int bs_amp_res_header; + /** + * @defgroup bs_header_extra_2 variables associated with bs_header_extra_2 + * @{ + */ + unsigned bs_limiter_bands; + unsigned bs_limiter_gains; + unsigned bs_interpol_freq; + unsigned bs_smoothing_mode; + /** @} */ + unsigned bs_coupling; + unsigned k[5]; ///< k0, k1, k2 + ///kx', and kx respectively, kx is the first QMF subband where SBR is used. + ///kx' is its value from the previous frame + unsigned kx[2]; + ///M' and M respectively, M is the number of QMF subbands that use SBR. + unsigned m[2]; + ///The number of frequency bands in f_master + unsigned n_master; + SBRData data[2]; + ///N_Low and N_High respectively, the number of frequency bands for low and high resolution + unsigned n[2]; + ///Number of noise floor bands + unsigned n_q; + ///Number of limiter bands + unsigned n_lim; + ///The master QMF frequency grouping + uint16_t f_master[49]; + ///Frequency borders for low resolution SBR + uint16_t f_tablelow[25]; + ///Frequency borders for high resolution SBR + uint16_t f_tablehigh[49]; + ///Frequency borders for noise floors + uint16_t f_tablenoise[6]; + ///Frequency borders for the limiter + uint16_t f_tablelim[29]; + unsigned num_patches; + uint8_t patch_num_subbands[6]; + uint8_t patch_start_subband[6]; + ///QMF low frequency input to the HF generator + float X_low[32][40][2]; + ///QMF output of the HF generator + float X_high[64][40][2]; + ///QMF values of the reconstructed signal + DECLARE_ALIGNED(16, float, X)[2][2][32][64]; + ///Zeroth coefficient used to filter the subband signals + float alpha0[64][2]; + ///First coefficient used to filter the subband signals + float alpha1[64][2]; + ///Dequantized envelope scalefactors, remapped + float e_origmapped[7][48]; + ///Dequantized noise scalefactors, remapped + float q_mapped[7][48]; + ///Sinusoidal presence, remapped + uint8_t s_mapped[7][48]; + ///Estimated envelope + float e_curr[7][48]; + ///Amplitude adjusted noise scalefactors + float q_m[7][48]; + ///Sinusoidal levels + float s_m[7][48]; + float gain[7][48]; + DECLARE_ALIGNED(16, float, qmf_filter_scratch)[5][64]; + RDFTContext rdft; + FFTContext mdct; +} SpectralBandReplication; + +#endif /* AVCODEC_SBR_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/sgidec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/sgidec.c index dadbc19d22..bbfd94bdf0 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/sgidec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/sgidec.c @@ -28,6 +28,7 @@ typedef struct SgiState { unsigned int width; unsigned int height; unsigned int depth; + unsigned int bytes_per_channel; int linesize; } SgiState; @@ -125,7 +126,7 @@ static int read_uncompressed_sgi(unsigned char* out_buf, uint8_t* out_end, { int x, y, z; const uint8_t *ptr; - unsigned int offset = s->height * s->width; + unsigned int offset = s->height * s->width * s->bytes_per_channel; /* Test buffer size. */ if (offset * s->depth > in_end - in_buf) { @@ -135,9 +136,10 @@ static int read_uncompressed_sgi(unsigned char* out_buf, uint8_t* out_end, for (y = s->height - 1; y >= 0; y--) { out_end = out_buf + (y * s->linesize); for (x = s->width; x > 0; x--) { - ptr = in_buf++; + ptr = in_buf += s->bytes_per_channel; for(z = 0; z < s->depth; z ++) { - bytestream_put_byte(&out_end, *ptr); + memcpy(out_end, ptr, s->bytes_per_channel); + out_end += s->bytes_per_channel; ptr += offset; } } @@ -155,7 +157,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *picture = data; AVFrame *p = &s->picture; const uint8_t *in_end = in_buf + buf_size; - unsigned int dimension, bytes_per_channel, rle; + unsigned int dimension, rle; int ret = 0; uint8_t *out_buf, *out_end; @@ -171,13 +173,13 @@ static int decode_frame(AVCodecContext *avctx, } rle = bytestream_get_byte(&in_buf); - bytes_per_channel = bytestream_get_byte(&in_buf); + s->bytes_per_channel = bytestream_get_byte(&in_buf); dimension = bytestream_get_be16(&in_buf); s->width = bytestream_get_be16(&in_buf); s->height = bytestream_get_be16(&in_buf); s->depth = bytestream_get_be16(&in_buf); - if (bytes_per_channel != 1) { + if (s->bytes_per_channel != 1 && (s->bytes_per_channel != 2 || rle)) { av_log(avctx, AV_LOG_ERROR, "wrong channel number\n"); return -1; } @@ -189,10 +191,10 @@ static int decode_frame(AVCodecContext *avctx, } if (s->depth == SGI_GRAYSCALE) { - avctx->pix_fmt = PIX_FMT_GRAY8; + avctx->pix_fmt = s->bytes_per_channel == 2 ? PIX_FMT_GRAY16BE : PIX_FMT_GRAY8; } else if (s->depth == SGI_RGB) { - avctx->pix_fmt = PIX_FMT_RGB24; - } else if (s->depth == SGI_RGBA) { + avctx->pix_fmt = s->bytes_per_channel == 2 ? PIX_FMT_RGB48BE : PIX_FMT_RGB24; + } else if (s->depth == SGI_RGBA && s->bytes_per_channel == 1) { avctx->pix_fmt = PIX_FMT_RGBA; } else { av_log(avctx, AV_LOG_ERROR, "wrong picture format\n"); @@ -258,7 +260,7 @@ static av_cold int sgi_end(AVCodecContext *avctx) AVCodec sgi_decoder = { "sgi", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_SGI, sizeof(SgiState), sgi_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/sgienc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/sgienc.c index b2fd145e20..f9f3709788 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/sgienc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/sgienc.c @@ -31,7 +31,8 @@ typedef struct SgiContext { AVFrame picture; } SgiContext; -static av_cold int encode_init(AVCodecContext *avctx){ +static av_cold int encode_init(AVCodecContext *avctx) +{ SgiContext *s = avctx->priv_data; avcodec_get_frame_defaults(&s->picture); @@ -41,7 +42,8 @@ static av_cold int encode_init(AVCodecContext *avctx){ } static int encode_frame(AVCodecContext *avctx, unsigned char *buf, - int buf_size, void *data) { + int buf_size, void *data) +{ SgiContext *s = avctx->priv_data; AVFrame * const p = &s->picture; uint8_t *offsettab, *lengthtab, *in_buf, *encode_buf; @@ -53,24 +55,24 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, p->pict_type = FF_I_TYPE; p->key_frame = 1; - width = avctx->width; + width = avctx->width; height = avctx->height; switch (avctx->pix_fmt) { - case PIX_FMT_GRAY8: - dimension = SGI_SINGLE_CHAN; - depth = SGI_GRAYSCALE; - break; - case PIX_FMT_RGB24: - dimension = SGI_MULTI_CHAN; - depth = SGI_RGB; - break; - case PIX_FMT_RGBA: - dimension = SGI_MULTI_CHAN; - depth = SGI_RGBA; - break; - default: - return AVERROR_INVALIDDATA; + case PIX_FMT_GRAY8: + dimension = SGI_SINGLE_CHAN; + depth = SGI_GRAYSCALE; + break; + case PIX_FMT_RGB24: + dimension = SGI_MULTI_CHAN; + depth = SGI_RGB; + break; + case PIX_FMT_RGBA: + dimension = SGI_MULTI_CHAN; + depth = SGI_RGBA; + break; + default: + return AVERROR_INVALIDDATA; } tablesize = depth * height * 4; @@ -83,7 +85,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, /* Encode header. */ bytestream_put_be16(&buf, SGI_MAGIC); - bytestream_put_byte(&buf, 1); /* RLE */ + bytestream_put_byte(&buf, avctx->coder_type != FF_CODER_TYPE_RAW); /* RLE 1 - VERBATIM 0*/ bytestream_put_byte(&buf, 1); /* bytes_per_channel */ bytestream_put_be16(&buf, dimension); bytestream_put_be16(&buf, width); @@ -106,52 +108,65 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, buf += 404; offsettab = buf; - /* Skip RLE offset table. */ - buf += tablesize; - lengthtab = buf; + if (avctx->coder_type != FF_CODER_TYPE_RAW) { + /* Skip RLE offset table. */ + buf += tablesize; + lengthtab = buf; - /* Skip RLE length table. */ - buf += tablesize; + /* Skip RLE length table. */ + buf += tablesize; - /* Make an intermediate consecutive buffer. */ - if ((encode_buf = av_malloc(width)) == NULL) - return -1; + /* Make an intermediate consecutive buffer. */ + if (!(encode_buf = av_malloc(width))) + return -1; - for (z = 0; z < depth; z++) { - in_buf = p->data[0] + p->linesize[0] * (height - 1) + z; + for (z = 0; z < depth; z++) { + in_buf = p->data[0] + p->linesize[0] * (height - 1) + z; - for (y = 0; y < height; y++) { - bytestream_put_be32(&offsettab, buf - orig_buf); + for (y = 0; y < height; y++) { + bytestream_put_be32(&offsettab, buf - orig_buf); - for (x = 0; x < width; x++) - encode_buf[x] = in_buf[depth * x]; + for (x = 0; x < width; x++) + encode_buf[x] = in_buf[depth * x]; - if((length = ff_rle_encode(buf, end_buf - buf - 1, encode_buf, 1, width, 0, 0, 0x80, 0)) < 1) { - av_free(encode_buf); - return -1; + if ((length = ff_rle_encode(buf, end_buf - buf - 1, encode_buf, 1, width, 0, 0, 0x80, 0)) < 1) { + av_free(encode_buf); + return -1; + } + + buf += length; + bytestream_put_byte(&buf, 0); + bytestream_put_be32(&lengthtab, length + 1); + in_buf -= p->linesize[0]; } + } - buf += length; - bytestream_put_byte(&buf, 0); - bytestream_put_be32(&lengthtab, length + 1); - in_buf -= p->linesize[0]; + av_free(encode_buf); + } else { + for (z = 0; z < depth; z++) { + in_buf = p->data[0] + p->linesize[0] * (height - 1) + z; + + for (y = 0; y < height; y++) { + for (x = 0; x < width * depth; x += depth) + bytestream_put_byte(&buf, in_buf[x]); + + in_buf -= p->linesize[0]; + } } } - av_free(encode_buf); /* total length */ return buf - orig_buf; } AVCodec sgi_encoder = { "sgi", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_SGI, sizeof(SgiContext), encode_init, encode_frame, NULL, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGBA, PIX_FMT_GRAY8, PIX_FMT_NONE}, + .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/src/add-ons/media/plugins/ffmpeg/libavcodec/shorten.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/shorten.c index 328aaccd29..7e17f18e17 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/shorten.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/shorten.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/shorten.c + * @file * Shorten decoder * @author Jeff Muizelaar * @@ -527,7 +527,7 @@ static void shorten_flush(AVCodecContext *avctx){ AVCodec shorten_decoder = { "shorten", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_SHORTEN, sizeof(ShortenContext), shorten_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/simple_idct.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/simple_idct.c index 6670740bf3..475be6d2d4 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/simple_idct.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/simple_idct.c @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/simple_idct.c + * @file * simpleidct in C. */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/simple_idct.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/simple_idct.h index 44db29ec13..24f6a6d5db 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/simple_idct.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/simple_idct.h @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/simple_idct.h + * @file * simple idct header. */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/sipr.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/sipr.c new file mode 100644 index 0000000000..b76e89100f --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/sipr.c @@ -0,0 +1,588 @@ +/* + * SIPR / ACELP.NET decoder + * + * Copyright (c) 2008 Vladimir Voroshilov + * Copyright (c) 2009 Vitor Sessak + * + * 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 +#include + +#include "libavutil/mathematics.h" +#include "avcodec.h" +#define ALT_BITSTREAM_READER_LE +#include "get_bits.h" +#include "dsputil.h" + +#include "lsp.h" +#include "celp_math.h" +#include "acelp_vectors.h" +#include "acelp_pitch_delay.h" +#include "acelp_filters.h" +#include "celp_filters.h" + +#define MAX_SUBFRAME_COUNT 5 + +#include "sipr.h" +#include "siprdata.h" + +typedef struct { + const char *mode_name; + uint16_t bits_per_frame; + uint8_t subframe_count; + uint8_t frames_per_packet; + float pitch_sharp_factor; + + /* bitstream parameters */ + uint8_t number_of_fc_indexes; + uint8_t ma_predictor_bits; ///< size in bits of the switched MA predictor + + /** size in bits of the i-th stage vector of quantizer */ + uint8_t vq_indexes_bits[5]; + + /** size in bits of the adaptive-codebook index for every subframe */ + uint8_t pitch_delay_bits[5]; + + uint8_t gp_index_bits; + uint8_t fc_index_bits[10]; ///< size in bits of the fixed codebook indexes + uint8_t gc_index_bits; ///< size in bits of the gain codebook indexes +} SiprModeParam; + +static const SiprModeParam modes[MODE_COUNT] = { + [MODE_16k] = { + .mode_name = "16k", + .bits_per_frame = 160, + .subframe_count = SUBFRAME_COUNT_16k, + .frames_per_packet = 1, + .pitch_sharp_factor = 0.00, + + .number_of_fc_indexes = 10, + .ma_predictor_bits = 1, + .vq_indexes_bits = {7, 8, 7, 7, 7}, + .pitch_delay_bits = {9, 6}, + .gp_index_bits = 4, + .fc_index_bits = {4, 5, 4, 5, 4, 5, 4, 5, 4, 5}, + .gc_index_bits = 5 + }, + + [MODE_8k5] = { + .mode_name = "8k5", + .bits_per_frame = 152, + .subframe_count = 3, + .frames_per_packet = 1, + .pitch_sharp_factor = 0.8, + + .number_of_fc_indexes = 3, + .ma_predictor_bits = 0, + .vq_indexes_bits = {6, 7, 7, 7, 5}, + .pitch_delay_bits = {8, 5, 5}, + .gp_index_bits = 0, + .fc_index_bits = {9, 9, 9}, + .gc_index_bits = 7 + }, + + [MODE_6k5] = { + .mode_name = "6k5", + .bits_per_frame = 232, + .subframe_count = 3, + .frames_per_packet = 2, + .pitch_sharp_factor = 0.8, + + .number_of_fc_indexes = 3, + .ma_predictor_bits = 0, + .vq_indexes_bits = {6, 7, 7, 7, 5}, + .pitch_delay_bits = {8, 5, 5}, + .gp_index_bits = 0, + .fc_index_bits = {5, 5, 5}, + .gc_index_bits = 7 + }, + + [MODE_5k0] = { + .mode_name = "5k0", + .bits_per_frame = 296, + .subframe_count = 5, + .frames_per_packet = 2, + .pitch_sharp_factor = 0.85, + + .number_of_fc_indexes = 1, + .ma_predictor_bits = 0, + .vq_indexes_bits = {6, 7, 7, 7, 5}, + .pitch_delay_bits = {8, 5, 8, 5, 5}, + .gp_index_bits = 0, + .fc_index_bits = {10}, + .gc_index_bits = 7 + } +}; + +const float ff_pow_0_5[] = { + 1.0/(1 << 1), 1.0/(1 << 2), 1.0/(1 << 3), 1.0/(1 << 4), + 1.0/(1 << 5), 1.0/(1 << 6), 1.0/(1 << 7), 1.0/(1 << 8), + 1.0/(1 << 9), 1.0/(1 << 10), 1.0/(1 << 11), 1.0/(1 << 12), + 1.0/(1 << 13), 1.0/(1 << 14), 1.0/(1 << 15), 1.0/(1 << 16) +}; + +static void dequant(float *out, const int *idx, const float *cbs[]) +{ + int i; + int stride = 2; + int num_vec = 5; + + for (i = 0; i < num_vec; i++) + memcpy(out + stride*i, cbs[i] + stride*idx[i], stride*sizeof(float)); + +} + +static void lsf_decode_fp(float *lsfnew, float *lsf_history, + const SiprParameters *parm) +{ + int i; + float lsf_tmp[LP_FILTER_ORDER]; + + dequant(lsf_tmp, parm->vq_indexes, lsf_codebooks); + + for (i = 0; i < LP_FILTER_ORDER; i++) + lsfnew[i] = lsf_history[i] * 0.33 + lsf_tmp[i] + mean_lsf[i]; + + ff_sort_nearly_sorted_floats(lsfnew, LP_FILTER_ORDER - 1); + + /* Note that a minimum distance is not enforced between the last value and + the previous one, contrary to what is done in ff_acelp_reorder_lsf() */ + ff_set_min_dist_lsf(lsfnew, LSFQ_DIFF_MIN, LP_FILTER_ORDER - 1); + lsfnew[9] = FFMIN(lsfnew[LP_FILTER_ORDER - 1], 1.3 * M_PI); + + memcpy(lsf_history, lsf_tmp, LP_FILTER_ORDER * sizeof(*lsf_history)); + + for (i = 0; i < LP_FILTER_ORDER - 1; i++) + lsfnew[i] = cos(lsfnew[i]); + lsfnew[LP_FILTER_ORDER - 1] *= 6.153848 / M_PI; +} + +/** Apply pitch lag to the fixed vector (AMR section 6.1.2). */ +static void pitch_sharpening(int pitch_lag_int, float beta, + float *fixed_vector) +{ + int i; + + for (i = pitch_lag_int; i < SUBFR_SIZE; i++) + fixed_vector[i] += beta * fixed_vector[i - pitch_lag_int]; +} + +/** + * Extracts decoding parameters from the input bitstream. + * @param parms parameters structure + * @param pgb pointer to initialized GetBitContext structure + */ +static void decode_parameters(SiprParameters* parms, GetBitContext *pgb, + const SiprModeParam *p) +{ + int i, j; + + 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); + + for (j = 0; j < p->number_of_fc_indexes; j++) + parms->fc_indexes[i][j] = get_bits(pgb, p->fc_index_bits[j]); + + parms->gc_index[i] = get_bits(pgb, p->gc_index_bits); + } +} + +static void lsp2lpc_sipr(const double *lsp, float *Az) +{ + int lp_half_order = LP_FILTER_ORDER >> 1; + double buf[(LP_FILTER_ORDER >> 1) + 1]; + double pa[(LP_FILTER_ORDER >> 1) + 1]; + double *qa = buf + 1; + int i,j; + + qa[-1] = 0.0; + + ff_lsp2polyf(lsp , pa, lp_half_order ); + ff_lsp2polyf(lsp + 1, qa, lp_half_order - 1); + + for (i = 1, j = LP_FILTER_ORDER - 1; i < lp_half_order; i++, j--) { + double paf = pa[i] * (1 + lsp[LP_FILTER_ORDER - 1]); + double qaf = (qa[i] - qa[i-2]) * (1 - lsp[LP_FILTER_ORDER - 1]); + Az[i-1] = (paf + qaf) * 0.5; + Az[j-1] = (paf - qaf) * 0.5; + } + + Az[lp_half_order - 1] = (1.0 + lsp[LP_FILTER_ORDER - 1]) * + pa[lp_half_order] * 0.5; + + Az[LP_FILTER_ORDER - 1] = lsp[LP_FILTER_ORDER - 1]; +} + +static void sipr_decode_lp(float *lsfnew, const float *lsfold, float *Az, + int num_subfr) +{ + double lsfint[LP_FILTER_ORDER]; + int i,j; + float t, t0 = 1.0 / num_subfr; + + t = t0 * 0.5; + for (i = 0; i < num_subfr; i++) { + for (j = 0; j < LP_FILTER_ORDER; j++) + lsfint[j] = lsfold[j] * (1 - t) + t * lsfnew[j]; + + lsp2lpc_sipr(lsfint, Az); + Az += LP_FILTER_ORDER; + t += t0; + } +} + +/** + * Evaluates the adaptive impulse response. + */ +static void eval_ir(const float *Az, int pitch_lag, float *freq, + float pitch_sharp_factor) +{ + float tmp1[SUBFR_SIZE+1], tmp2[LP_FILTER_ORDER+1]; + int i; + + tmp1[0] = 1.; + for (i = 0; i < LP_FILTER_ORDER; i++) { + tmp1[i+1] = Az[i] * ff_pow_0_55[i]; + tmp2[i ] = Az[i] * ff_pow_0_7 [i]; + } + memset(tmp1 + 11, 0, 37 * sizeof(float)); + + ff_celp_lp_synthesis_filterf(freq, tmp2, tmp1, SUBFR_SIZE, + LP_FILTER_ORDER); + + pitch_sharpening(pitch_lag, pitch_sharp_factor, freq); +} + +/** + * Evaluates the convolution of a vector with a sparse vector. + */ +static void convolute_with_sparse(float *out, const AMRFixed *pulses, + const float *shape, int length) +{ + int i, j; + + memset(out, 0, length*sizeof(float)); + for (i = 0; i < pulses->n; i++) + for (j = pulses->x[i]; j < length; j++) + out[j] += pulses->y[i] * shape[j - pulses->x[i]]; +} + +/** + * Apply postfilter, very similar to AMR one. + */ +static void postfilter_5k0(SiprContext *ctx, const float *lpc, float *samples) +{ + float buf[SUBFR_SIZE + LP_FILTER_ORDER]; + float *pole_out = buf + LP_FILTER_ORDER; + float lpc_n[LP_FILTER_ORDER]; + float lpc_d[LP_FILTER_ORDER]; + int i; + + for (i = 0; i < LP_FILTER_ORDER; i++) { + lpc_d[i] = lpc[i] * ff_pow_0_75[i]; + lpc_n[i] = lpc[i] * ff_pow_0_5 [i]; + }; + + memcpy(pole_out - LP_FILTER_ORDER, ctx->postfilter_mem, + LP_FILTER_ORDER*sizeof(float)); + + ff_celp_lp_synthesis_filterf(pole_out, lpc_d, samples, SUBFR_SIZE, + LP_FILTER_ORDER); + + memcpy(ctx->postfilter_mem, pole_out + SUBFR_SIZE - LP_FILTER_ORDER, + LP_FILTER_ORDER*sizeof(float)); + + ff_tilt_compensation(&ctx->tilt_mem, 0.4, pole_out, SUBFR_SIZE); + + memcpy(pole_out - LP_FILTER_ORDER, ctx->postfilter_mem5k0, + LP_FILTER_ORDER*sizeof(*pole_out)); + + memcpy(ctx->postfilter_mem5k0, pole_out + SUBFR_SIZE - LP_FILTER_ORDER, + LP_FILTER_ORDER*sizeof(*pole_out)); + + ff_celp_lp_zero_synthesis_filterf(samples, lpc_n, pole_out, SUBFR_SIZE, + LP_FILTER_ORDER); + +} + +static void decode_fixed_sparse(AMRFixed *fixed_sparse, const int16_t *pulses, + SiprMode mode, int low_gain) +{ + int i; + + switch (mode) { + case MODE_6k5: + for (i = 0; i < 3; i++) { + fixed_sparse->x[i] = 3 * (pulses[i] & 0xf) + i; + fixed_sparse->y[i] = pulses[i] & 0x10 ? -1 : 1; + } + fixed_sparse->n = 3; + break; + case MODE_8k5: + for (i = 0; i < 3; i++) { + fixed_sparse->x[2*i ] = 3 * ((pulses[i] >> 4) & 0xf) + i; + fixed_sparse->x[2*i + 1] = 3 * ( pulses[i] & 0xf) + i; + + fixed_sparse->y[2*i ] = (pulses[i] & 0x100) ? -1.0: 1.0; + + fixed_sparse->y[2*i + 1] = + (fixed_sparse->x[2*i + 1] < fixed_sparse->x[2*i]) ? + -fixed_sparse->y[2*i ] : fixed_sparse->y[2*i]; + } + + fixed_sparse->n = 6; + break; + case MODE_5k0: + default: + if (low_gain) { + int offset = (pulses[0] & 0x200) ? 2 : 0; + int val = pulses[0]; + + for (i = 0; i < 3; i++) { + int index = (val & 0x7) * 6 + 4 - i*2; + + fixed_sparse->y[i] = (offset + index) & 0x3 ? -1 : 1; + fixed_sparse->x[i] = index; + + val >>= 3; + } + fixed_sparse->n = 3; + } else { + int pulse_subset = (pulses[0] >> 8) & 1; + + fixed_sparse->x[0] = ((pulses[0] >> 4) & 15) * 3 + pulse_subset; + fixed_sparse->x[1] = ( pulses[0] & 15) * 3 + pulse_subset + 1; + + fixed_sparse->y[0] = pulses[0] & 0x200 ? -1 : 1; + fixed_sparse->y[1] = -fixed_sparse->y[0]; + fixed_sparse->n = 2; + } + break; + } +} + +static void decode_frame(SiprContext *ctx, SiprParameters *params, + float *out_data) +{ + int i, j; + int subframe_count = modes[ctx->mode].subframe_count; + int frame_size = subframe_count * SUBFR_SIZE; + float Az[LP_FILTER_ORDER * MAX_SUBFRAME_COUNT]; + float *excitation; + float ir_buf[SUBFR_SIZE + LP_FILTER_ORDER]; + float lsf_new[LP_FILTER_ORDER]; + float *impulse_response = ir_buf + LP_FILTER_ORDER; + float *synth = ctx->synth_buf + 16; // 16 instead of LP_FILTER_ORDER for + // memory alignment + int t0_first = 0; + AMRFixed fixed_cb; + + memset(ir_buf, 0, LP_FILTER_ORDER * sizeof(float)); + lsf_decode_fp(lsf_new, ctx->lsf_history, params); + + sipr_decode_lp(lsf_new, ctx->lsp_history, Az, subframe_count); + + memcpy(ctx->lsp_history, lsf_new, LP_FILTER_ORDER * sizeof(float)); + + excitation = ctx->excitation + PITCH_DELAY_MAX + L_INTERPOL; + + for (i = 0; i < subframe_count; i++) { + float *pAz = Az + i*LP_FILTER_ORDER; + float fixed_vector[SUBFR_SIZE]; + int T0,T0_frac; + float pitch_gain, gain_code, avg_energy; + + ff_decode_pitch_lag(&T0, &T0_frac, params->pitch_delay[i], t0_first, i, + ctx->mode == MODE_5k0, 6); + + if (i == 0 || (i == 2 && ctx->mode == MODE_5k0)) + t0_first = T0; + + ff_acelp_interpolatef(excitation, excitation - T0 + (T0_frac <= 0), + ff_b60_sinc, 6, + 2 * ((2 + T0_frac)%3 + 1), LP_FILTER_ORDER, + SUBFR_SIZE); + + decode_fixed_sparse(&fixed_cb, params->fc_indexes[i], ctx->mode, + ctx->past_pitch_gain < 0.8); + + eval_ir(pAz, T0, impulse_response, modes[ctx->mode].pitch_sharp_factor); + + convolute_with_sparse(fixed_vector, &fixed_cb, impulse_response, + SUBFR_SIZE); + + avg_energy = + (0.01 + ff_dot_productf(fixed_vector, fixed_vector, SUBFR_SIZE))/ + SUBFR_SIZE; + + ctx->past_pitch_gain = pitch_gain = gain_cb[params->gc_index[i]][0]; + + gain_code = ff_amr_set_fixed_gain(gain_cb[params->gc_index[i]][1], + avg_energy, ctx->energy_history, + 34 - 15.0/(0.05*M_LN10/M_LN2), + pred); + + ff_weighted_vector_sumf(excitation, excitation, fixed_vector, + pitch_gain, gain_code, SUBFR_SIZE); + + pitch_gain *= 0.5 * pitch_gain; + pitch_gain = FFMIN(pitch_gain, 0.4); + + ctx->gain_mem = 0.7 * ctx->gain_mem + 0.3 * pitch_gain; + ctx->gain_mem = FFMIN(ctx->gain_mem, pitch_gain); + gain_code *= ctx->gain_mem; + + for (j = 0; j < SUBFR_SIZE; j++) + fixed_vector[j] = excitation[j] - gain_code * fixed_vector[j]; + + if (ctx->mode == MODE_5k0) { + postfilter_5k0(ctx, pAz, fixed_vector); + + ff_celp_lp_synthesis_filterf(ctx->postfilter_syn5k0 + LP_FILTER_ORDER + i*SUBFR_SIZE, + pAz, excitation, SUBFR_SIZE, + LP_FILTER_ORDER); + } + + ff_celp_lp_synthesis_filterf(synth + i*SUBFR_SIZE, pAz, fixed_vector, + SUBFR_SIZE, LP_FILTER_ORDER); + + excitation += SUBFR_SIZE; + } + + memcpy(synth - LP_FILTER_ORDER, synth + frame_size - LP_FILTER_ORDER, + LP_FILTER_ORDER * sizeof(float)); + + if (ctx->mode == MODE_5k0) { + for (i = 0; i < subframe_count; i++) { + float energy = ff_dot_productf(ctx->postfilter_syn5k0 + LP_FILTER_ORDER + i*SUBFR_SIZE, + ctx->postfilter_syn5k0 + LP_FILTER_ORDER + i*SUBFR_SIZE, + SUBFR_SIZE); + ff_adaptive_gain_control(&synth[i * SUBFR_SIZE], + &synth[i * SUBFR_SIZE], energy, + SUBFR_SIZE, 0.9, &ctx->postfilter_agc); + } + + memcpy(ctx->postfilter_syn5k0, ctx->postfilter_syn5k0 + frame_size, + LP_FILTER_ORDER*sizeof(float)); + } + memcpy(ctx->excitation, excitation - PITCH_DELAY_MAX - L_INTERPOL, + (PITCH_DELAY_MAX + L_INTERPOL) * sizeof(float)); + + ff_acelp_apply_order_2_transfer_function(out_data, synth, + (const float[2]) {-1.99997 , 1.000000000}, + (const float[2]) {-1.93307352, 0.935891986}, + 0.939805806, + ctx->highpass_filt_mem, + frame_size); +} + +static av_cold int sipr_decoder_init(AVCodecContext * avctx) +{ + SiprContext *ctx = avctx->priv_data; + int i; + + if (avctx->bit_rate > 12200) ctx->mode = MODE_16k; + else if (avctx->bit_rate > 7500 ) ctx->mode = MODE_8k5; + else if (avctx->bit_rate > 5750 ) ctx->mode = MODE_6k5; + else ctx->mode = MODE_5k0; + + av_log(avctx, AV_LOG_DEBUG, "Mode: %s\n", modes[ctx->mode].mode_name); + + if (ctx->mode == MODE_16k) + ff_sipr_init_16k(ctx); + + for (i = 0; i < LP_FILTER_ORDER; i++) + ctx->lsp_history[i] = cos((i+1) * M_PI / (LP_FILTER_ORDER + 1)); + + for (i = 0; i < 4; i++) + ctx->energy_history[i] = -14; + + avctx->sample_fmt = SAMPLE_FMT_FLT; + + dsputil_init(&ctx->dsp, avctx); + + return 0; +} + +static int sipr_decode_frame(AVCodecContext *avctx, void *datap, + int *data_size, AVPacket *avpkt) +{ + SiprContext *ctx = avctx->priv_data; + const uint8_t *buf=avpkt->data; + SiprParameters parm; + const SiprModeParam *mode_par = &modes[ctx->mode]; + GetBitContext gb; + float *data = datap; + int subframe_size = ctx->mode == MODE_16k ? L_SUBFR_16k : SUBFR_SIZE; + int i; + + ctx->avctx = avctx; + if (avpkt->size < (mode_par->bits_per_frame >> 3)) { + av_log(avctx, AV_LOG_ERROR, + "Error processing packet: packet size (%d) too small\n", + avpkt->size); + + *data_size = 0; + return -1; + } + if (*data_size < subframe_size * mode_par->subframe_count * sizeof(float)) { + av_log(avctx, AV_LOG_ERROR, + "Error processing packet: output buffer (%d) too small\n", + *data_size); + + *data_size = 0; + return -1; + } + + init_get_bits(&gb, buf, mode_par->bits_per_frame); + + for (i = 0; i < mode_par->frames_per_packet; i++) { + decode_parameters(&parm, &gb, mode_par); + + if (ctx->mode == MODE_16k) + ff_sipr_decode_frame_16k(ctx, &parm, data); + else + decode_frame(ctx, &parm, data); + + data += subframe_size * mode_par->subframe_count; + } + + *data_size = mode_par->frames_per_packet * subframe_size * + mode_par->subframe_count * sizeof(float); + + return mode_par->bits_per_frame >> 3; +}; + +AVCodec sipr_decoder = { + "sipr", + AVMEDIA_TYPE_AUDIO, + CODEC_ID_SIPR, + sizeof(SiprContext), + sipr_decoder_init, + NULL, + NULL, + sipr_decode_frame, + .long_name = NULL_IF_CONFIG_SMALL("RealAudio SIPR / ACELP.NET"), +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/sipr.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/sipr.h new file mode 100644 index 0000000000..66e7696466 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/sipr.h @@ -0,0 +1,107 @@ +/* + * SIPR / ACELP.NET decoder + * + * Copyright (c) 2008 Vladimir Voroshilov + * Copyright (c) 2009 Vitor Sessak + * + * 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_SIPR_H +#define AVCODEC_SIPR_H + +#include "avcodec.h" +#include "dsputil.h" +#include "acelp_pitch_delay.h" + +#define LP_FILTER_ORDER_16k 16 +#define L_SUBFR_16k 80 +#define PITCH_MIN 30 +#define PITCH_MAX 281 + +#define LSFQ_DIFF_MIN (0.0125 * M_PI) + +#define LP_FILTER_ORDER 10 + +/** Number of past samples needed for excitation interpolation */ +#define L_INTERPOL (LP_FILTER_ORDER + 1) + +/** Subframe size for all modes except 16k */ +#define SUBFR_SIZE 48 + +#define SUBFRAME_COUNT_16k 2 + +typedef enum { + MODE_16k, + MODE_8k5, + MODE_6k5, + MODE_5k0, + MODE_COUNT +} SiprMode; + +typedef struct { + AVCodecContext *avctx; + DSPContext dsp; + + SiprMode mode; + + float past_pitch_gain; + float lsf_history[LP_FILTER_ORDER_16k]; + + float excitation[L_INTERPOL + PITCH_MAX + 2 * L_SUBFR_16k]; + + DECLARE_ALIGNED(16, float, synth_buf)[LP_FILTER_ORDER + 5*SUBFR_SIZE + 6]; + + float lsp_history[LP_FILTER_ORDER]; + float gain_mem; + float energy_history[4]; + float highpass_filt_mem[2]; + float postfilter_mem[PITCH_DELAY_MAX + LP_FILTER_ORDER]; + + /* 5k0 */ + float tilt_mem; + float postfilter_agc; + float postfilter_mem5k0[PITCH_DELAY_MAX + LP_FILTER_ORDER]; + float postfilter_syn5k0[LP_FILTER_ORDER + SUBFR_SIZE*5]; + + /* 16k */ + int pitch_lag_prev; + float iir_mem[LP_FILTER_ORDER_16k+1]; + float filt_buf[2][LP_FILTER_ORDER_16k+1]; + float *filt_mem[2]; + float mem_preemph[LP_FILTER_ORDER_16k]; + float synth[LP_FILTER_ORDER_16k]; + double lsp_history_16k[16]; +} SiprContext; + +typedef struct { + int ma_pred_switch; ///< switched moving average predictor + int vq_indexes[5]; + int pitch_delay[5]; ///< pitch delay + int gp_index[5]; ///< adaptive-codebook gain indexes + int16_t fc_indexes[5][10]; ///< fixed-codebook indexes + int gc_index[5]; ///< fixed-codebook gain indexes +} SiprParameters; + +extern const float ff_pow_0_5[16]; + +void ff_sipr_init_16k(SiprContext *ctx); + +void ff_sipr_decode_frame_16k(SiprContext *ctx, SiprParameters *params, + float *out_data); + +#endif /* AVCODEC_SIPR_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/sipr16k.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/sipr16k.c new file mode 100644 index 0000000000..7fb9252927 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/sipr16k.c @@ -0,0 +1,280 @@ +/* + * SIPR decoder for the 16k mode + * + * Copyright (c) 2008 Vladimir Voroshilov + * Copyright (c) 2009 Vitor Sessak + * + * 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 + +#include "sipr.h" +#include "libavutil/mathematics.h" +#include "lsp.h" +#include "celp_math.h" +#include "acelp_vectors.h" +#include "acelp_pitch_delay.h" +#include "acelp_filters.h" +#include "celp_filters.h" + +#include "sipr16kdata.h" + +/** + * Convert an lsf vector into an lsp vector. + * + * @param lsf input lsf vector + * @param lsp output lsp vector + */ +static void lsf2lsp(const float *lsf, double *lsp) +{ + int i; + + for (i = 0; i < LP_FILTER_ORDER_16k; i++) + lsp[i] = cosf(lsf[i]); +} + +static void dequant(float *out, const int *idx, const float *cbs[]) +{ + int i; + + for (i = 0; i < 4; i++) + memcpy(out + 3*i, cbs[i] + 3*idx[i], 3*sizeof(float)); + + memcpy(out + 12, cbs[4] + 4*idx[4], 4*sizeof(float)); +} + +static void lsf_decode_fp_16k(float* lsf_history, float* isp_new, + const int* parm, int ma_pred) +{ + int i; + float isp_q[LP_FILTER_ORDER_16k]; + + dequant(isp_q, parm, lsf_codebooks_16k); + + for (i = 0; i < LP_FILTER_ORDER_16k; i++) { + isp_new[i] = (1 - qu[ma_pred]) * isp_q[i] + + qu[ma_pred] * lsf_history[i] + + mean_lsf_16k[i]; + } + + memcpy(lsf_history, isp_q, LP_FILTER_ORDER_16k * sizeof(float)); +} + +static int dec_delay3_1st(int index) +{ + if (index < 390) { + return index + 88; + } else + return 3 * index - 690; +} + +static int dec_delay3_2nd(int index, int pit_min, int pit_max, + int pitch_lag_prev) +{ + if (index < 62) { + int pitch_delay_min = av_clip(pitch_lag_prev - 10, + pit_min, pit_max - 19); + return 3 * pitch_delay_min + index - 2; + } else + return 3 * pitch_lag_prev; +} + +static void postfilter(float *out_data, float* synth, float* iir_mem, + float* filt_mem[2], float* mem_preemph) +{ + float buf[30 + LP_FILTER_ORDER_16k]; + float *tmpbuf = buf + LP_FILTER_ORDER_16k; + float s; + int i; + + for (i = 0; i < LP_FILTER_ORDER_16k; i++) + filt_mem[0][i] = iir_mem[i] * ff_pow_0_5[i]; + + memcpy(tmpbuf - LP_FILTER_ORDER_16k, mem_preemph, + LP_FILTER_ORDER_16k*sizeof(*buf)); + + ff_celp_lp_synthesis_filterf(tmpbuf, filt_mem[1], synth, 30, + LP_FILTER_ORDER_16k); + + memcpy(synth - LP_FILTER_ORDER_16k, mem_preemph, + LP_FILTER_ORDER_16k * sizeof(*synth)); + + ff_celp_lp_synthesis_filterf(synth, filt_mem[0], synth, 30, + LP_FILTER_ORDER_16k); + + memcpy(out_data + 30 - LP_FILTER_ORDER_16k, + synth + 30 - LP_FILTER_ORDER_16k, + LP_FILTER_ORDER_16k * sizeof(*synth)); + + ff_celp_lp_synthesis_filterf(out_data + 30, filt_mem[0], + synth + 30, 2 * L_SUBFR_16k - 30, + LP_FILTER_ORDER_16k); + + + memcpy(mem_preemph, out_data + 2*L_SUBFR_16k - LP_FILTER_ORDER_16k, + LP_FILTER_ORDER_16k * sizeof(*synth)); + + FFSWAP(float *, filt_mem[0], filt_mem[1]); + for (i = 0, s = 0; i < 30; i++, s += 1.0/30) + out_data[i] = tmpbuf[i] + s * (synth[i] - tmpbuf[i]); +} + +/** + * Floating point version of ff_acelp_lp_decode(). + */ +static void acelp_lp_decodef(float *lp_1st, float *lp_2nd, + const double *lsp_2nd, const double *lsp_prev) +{ + double lsp_1st[LP_FILTER_ORDER_16k]; + int i; + + /* LSP values for first subframe (3.2.5 of G.729, Equation 24) */ + for (i = 0; i < LP_FILTER_ORDER_16k; i++) + lsp_1st[i] = (lsp_2nd[i] + lsp_prev[i]) * 0.5; + + ff_acelp_lspd2lpc(lsp_1st, lp_1st, LP_FILTER_ORDER_16k >> 1); + + /* LSP values for second subframe (3.2.5 of G.729) */ + ff_acelp_lspd2lpc(lsp_2nd, lp_2nd, LP_FILTER_ORDER_16k >> 1); +} + +/** + * Floating point version of ff_acelp_decode_gain_code(). + */ +static float acelp_decode_gain_codef(float gain_corr_factor, const float *fc_v, + float mr_energy, const float *quant_energy, + const float *ma_prediction_coeff, + int subframe_size, int ma_pred_order) +{ + mr_energy += + ff_dot_productf(quant_energy, ma_prediction_coeff, ma_pred_order); + + mr_energy = gain_corr_factor * exp(M_LN10 / 20. * mr_energy) / + sqrt((0.01 + ff_dot_productf(fc_v, fc_v, subframe_size))); + return mr_energy; +} + +#define DIVIDE_BY_3(x) ((x) * 10923 >> 15) + +void ff_sipr_decode_frame_16k(SiprContext *ctx, SiprParameters *params, + float *out_data) +{ + int frame_size = SUBFRAME_COUNT_16k * L_SUBFR_16k; + float *synth = ctx->synth_buf + LP_FILTER_ORDER_16k; + float lsf_new[LP_FILTER_ORDER_16k]; + double lsp_new[LP_FILTER_ORDER_16k]; + float Az[2][LP_FILTER_ORDER_16k]; + float fixed_vector[L_SUBFR_16k]; + float pitch_fac, gain_code; + + int i; + int pitch_delay_3x; + + float *excitation = ctx->excitation + 292; + + lsf_decode_fp_16k(ctx->lsf_history, lsf_new, params->vq_indexes, + params->ma_pred_switch); + + ff_set_min_dist_lsf(lsf_new, LSFQ_DIFF_MIN / 2, LP_FILTER_ORDER_16k); + + lsf2lsp(lsf_new, lsp_new); + + acelp_lp_decodef(Az[0], Az[1], lsp_new, ctx->lsp_history_16k); + + memcpy(ctx->lsp_history_16k, lsp_new, LP_FILTER_ORDER_16k * sizeof(double)); + + memcpy(synth - LP_FILTER_ORDER_16k, ctx->synth, + LP_FILTER_ORDER_16k * sizeof(*synth)); + + for (i = 0; i < SUBFRAME_COUNT_16k; i++) { + int i_subfr = i * L_SUBFR_16k; + AMRFixed f; + float gain_corr_factor; + int pitch_delay_int; + int pitch_delay_frac; + + if (!i) { + pitch_delay_3x = dec_delay3_1st(params->pitch_delay[i]); + } else + pitch_delay_3x = dec_delay3_2nd(params->pitch_delay[i], + PITCH_MIN, PITCH_MAX, + ctx->pitch_lag_prev); + + pitch_fac = gain_pitch_cb_16k[params->gp_index[i]]; + f.pitch_fac = FFMIN(pitch_fac, 1.0); + f.pitch_lag = DIVIDE_BY_3(pitch_delay_3x+1); + ctx->pitch_lag_prev = f.pitch_lag; + + pitch_delay_int = DIVIDE_BY_3(pitch_delay_3x + 2); + pitch_delay_frac = pitch_delay_3x + 2 - 3*pitch_delay_int; + + ff_acelp_interpolatef(&excitation[i_subfr], + &excitation[i_subfr] - pitch_delay_int + 1, + sinc_win, 3, pitch_delay_frac + 1, + LP_FILTER_ORDER, L_SUBFR_16k); + + + memset(fixed_vector, 0, sizeof(fixed_vector)); + + ff_decode_10_pulses_35bits(params->fc_indexes[i], &f, + ff_fc_4pulses_8bits_tracks_13, 5, 4); + + ff_set_fixed_vector(fixed_vector, &f, 1.0, L_SUBFR_16k); + + gain_corr_factor = gain_cb_16k[params->gc_index[i]]; + gain_code = gain_corr_factor * + acelp_decode_gain_codef(sqrt(L_SUBFR_16k), fixed_vector, + 19.0 - 15.0/(0.05*M_LN10/M_LN2), + pred_16k, ctx->energy_history, + L_SUBFR_16k, 2); + + ctx->energy_history[1] = ctx->energy_history[0]; + ctx->energy_history[0] = 20.0 * log10f(gain_corr_factor); + + ff_weighted_vector_sumf(&excitation[i_subfr], &excitation[i_subfr], + fixed_vector, pitch_fac, + gain_code, L_SUBFR_16k); + + ff_celp_lp_synthesis_filterf(synth + i_subfr, Az[i], + &excitation[i_subfr], L_SUBFR_16k, + LP_FILTER_ORDER_16k); + + } + memcpy(ctx->synth, synth + frame_size - LP_FILTER_ORDER_16k, + LP_FILTER_ORDER_16k * sizeof(*synth)); + + memmove(ctx->excitation, ctx->excitation + 2 * L_SUBFR_16k, + (L_INTERPOL+PITCH_MAX) * sizeof(float)); + + postfilter(out_data, synth, ctx->iir_mem, ctx->filt_mem, ctx->mem_preemph); + + memcpy(ctx->iir_mem, Az[1], LP_FILTER_ORDER_16k * sizeof(float)); +} + +void ff_sipr_init_16k(SiprContext *ctx) +{ + int i; + + for (i = 0; i < LP_FILTER_ORDER_16k; i++) + ctx->lsp_history_16k[i] = cos((i + 1) * M_PI/(LP_FILTER_ORDER_16k + 1)); + + ctx->filt_mem[0] = ctx->filt_buf[0]; + ctx->filt_mem[1] = ctx->filt_buf[1]; + + ctx->pitch_lag_prev = 180; +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/sipr16kdata.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/sipr16kdata.h new file mode 100644 index 0000000000..96bf0e96c8 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/sipr16kdata.h @@ -0,0 +1,533 @@ +/* + * SIPR decoder for the 16k mode + * + * Copyright (c) 2008 Vladimir Voroshilov + * Copyright (c) 2009 Vitor Sessak + * + * 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_SIPR16KDATA_H +#define AVCODEC_SIPR16KDATA_H + +static const float pred_16k[2] = {0.8, 0.6}; +static const float qu[2] = { 0.12, 0.5}; + +static const float gain_cb_16k[32] = { + 0.07499, 0.10593, 0.14125, 0.18836, + 0.23714, 0.28184, 0.32734, 0.37584, + 0.42170, 0.47315, 0.53088, 0.59566, + 0.66834, 0.74989, 0.84140, 0.94406, + 1.05925, 1.18850, 1.33352, 1.49624, + 1.67880, 1.88365, 2.11349, 2.37137, + 2.66073, 3.05492, 3.54813, 4.21697, + 5.30884, 7.07946, 9.44061, 13.33521, +}; + +static const float gain_pitch_cb_16k[16] = { + 0.00, 0.2, 0.40, 0.5, 0.60, 0.7, 0.75, 0.8, + 0.85, 0.9, 0.95, 1.0, 1.05, 1.1, 1.15, 1.2, +}; + + +static const float mean_lsf_16k[16] = { + 0.131554, 0.246615, 0.435896, 0.644419, + 0.827810, 1.017876, 1.198910, 1.379159, + 1.562157, 1.736908, 1.940719, 2.131963, + 2.347162, 2.521521, 2.717870, 2.847068 +}; + +/** + * Hamming windowed sinc function, like in AMR + */ +static const float sinc_win[40] = { + 0.874475, 0.755101, 0.455962, 0.118807, -0.114223, -0.176778, + -0.101923, 0.015553, 0.086555, 0.078193, 0.018660, -0.037513, + -0.052733, -0.027459, 0.009967, 0.030278, 0.024050, 0.003055, + -0.013862, -0.016162, -0.006725, 0.004212, 0.008634, 0.005721, + -0.000000, -0.003710, -0.003690, -0.001228, 0.001409, 0.002610, +}; + +static const float lsf_cb1_16k[128][3] = { + {-0.089990, -0.172485, -0.203391}, {-0.094710, -0.178687, -0.134483}, + {-0.056398, -0.131952, -0.154500}, {-0.051362, -0.128138, -0.198549}, + {-0.061700, -0.142830, -0.251623}, {-0.041512, -0.115637, -0.229420}, + {-0.036544, -0.107512, -0.173125}, {-0.024158, -0.088450, -0.204144}, + {-0.038690, -0.103368, -0.132674}, {-0.056954, -0.128472, -0.104669}, + {-0.020963, -0.076785, -0.163199}, {-0.012952, -0.077249, -0.128385}, + {-0.032787, -0.097044, -0.093967}, {-0.035214, -0.053838, -0.111940}, + {-0.013850, -0.036926, -0.139328}, {-0.004956, -0.065092, -0.087709}, + {-0.065354, -0.065595, -0.079064}, {-0.023627, -0.081457, -0.054195}, + {-0.027335, -0.035244, -0.068034}, { 0.016555, -0.047075, -0.128286}, + { 0.021066, -0.037252, -0.092041}, { 0.014681, -0.043044, -0.057739}, + {-0.008493, -0.008143, -0.102486}, {-0.002303, -0.061540, -0.022952}, + {-0.006061, -0.014278, -0.033652}, {-0.005276, 0.011246, -0.062762}, + { 0.043411, -0.006303, -0.063730}, { 0.035885, -0.010052, -0.115290}, + { 0.030628, -0.031538, -0.017807}, { 0.022345, 0.028210, -0.032335}, + { 0.026535, 0.027536, -0.091150}, {-0.003365, -0.008077, 0.015687}, + {-0.026013, 0.017493, -0.010355}, { 0.059069, 0.010634, -0.007530}, + { 0.044038, -0.019424, 0.030453}, {-0.036065, -0.034215, -0.007758}, + { 0.022486, 0.042543, 0.027870}, {-0.049985, -0.016085, 0.021768}, + {-0.021715, 0.021168, 0.052076}, {-0.004243, -0.061228, 0.027640}, + {-0.033950, -0.017287, 0.064656}, { 0.016151, 0.000727, 0.062757}, + {-0.063456, -0.043152, 0.056707}, {-0.067715, 0.006126, 0.058178}, + {-0.038931, 0.051673, 0.030636}, {-0.073017, -0.074716, 0.026387}, + {-0.039893, -0.104629, 0.039616}, {-0.073179, -0.074601, 0.082069}, + {-0.066154, -0.027180, 0.099439}, {-0.075167, -0.121149, 0.071938}, + {-0.030382, -0.092582, 0.091067}, {-0.084519, -0.137542, 0.023626}, + {-0.060956, -0.121259, -0.015264}, {-0.030069, -0.093823, -0.008692}, + {-0.063564, -0.065225, -0.025820}, {-0.052074, -0.117595, -0.059689}, + {-0.091652, -0.165173, -0.045573}, {-0.070167, -0.121342, 0.131707}, + {-0.061024, -0.005833, -0.051035}, { 0.007837, -0.051816, 0.074575}, + {-0.070643, -0.053927, 0.149498}, {-0.014358, -0.066681, 0.139708}, + {-0.058186, 0.029576, 0.092923}, {-0.023371, 0.007058, 0.112484}, + {-0.057969, 0.022786, 0.148420}, { 0.029439, -0.017673, 0.121423}, + {-0.015811, 0.056785, 0.091594}, { 0.004347, 0.056680, 0.137848}, + {-0.004464, 0.002342, 0.184013}, { 0.029660, 0.046870, 0.082654}, + { 0.059408, 0.001016, 0.086063}, { 0.055263, 0.027574, 0.155037}, + { 0.062166, 0.064323, 0.117371}, { 0.022967, 0.100050, 0.077227}, + { 0.041795, 0.096343, 0.170421}, { 0.053189, 0.122931, 0.118549}, + { 0.094247, 0.094448, 0.078395}, { 0.082407, 0.033408, 0.041085}, + { 0.096820, 0.115960, 0.149433}, { 0.067804, 0.121849, 0.025336}, + {-0.008421, 0.104316, 0.032314}, { 0.031013, 0.073218, -0.004899}, + { 0.085079, 0.060323, -0.009687}, { 0.028174, 0.092766, -0.055590}, + { 0.070133, 0.039160, -0.061035}, {-0.039211, 0.072517, -0.028756}, + { 0.129686, 0.100233, -0.046998}, { 0.154189, 0.107616, 0.022791}, + {-0.049331, 0.094184, 0.087984}, {-0.013179, 0.126552, 0.125099}, + {-0.058716, 0.098524, 0.150886}, {-0.022753, 0.080011, 0.191127}, + { 0.013451, 0.164593, 0.153768}, { 0.074818, 0.181214, 0.108211}, + { 0.091323, 0.169249, 0.168460}, { 0.033885, 0.155516, 0.213745}, + {-0.032128, 0.227238, 0.135815}, {-0.059176, 0.168980, 0.229110}, + { 0.033917, 0.229753, 0.222264}, { 0.082702, 0.116370, 0.224697}, + { 0.127737, 0.186658, 0.212783}, { 0.047528, 0.063920, 0.216856}, + {-0.002446, 0.114174, 0.263289}, {-0.077783, 0.082523, 0.249697}, + { 0.010023, 0.024267, 0.256874}, { 0.053190, 0.111422, 0.310407}, + {-0.078804, 0.004444, 0.224078}, {-0.055253, -0.059180, 0.217892}, + {-0.065371, 0.008124, 0.333405}, {-0.076188, -0.098767, 0.286983}, + {-0.071911, -0.115804, 0.198031}, {-0.062473, 0.183639, 0.370162}, + {-0.042666, 0.255210, 0.262720}, { 0.011999, 0.217530, 0.318291}, + {-0.042144, 0.322087, 0.326387}, { 0.090663, 0.205835, 0.294784}, + { 0.058218, 0.293649, 0.277927}, { 0.157506, 0.282870, 0.294610}, + { 0.118248, 0.261007, 0.148614}, { 0.065261, 0.332362, 0.411912}, + { 0.141269, 0.451850, 0.315726}, { 0.001706, 0.456301, 0.357590}, + {-0.052947, 0.356559, 0.456944}, { 0.247707, 0.263837, 0.152591}, + { 0.306847, 0.417373, 0.258553}, { 0.166347, 0.149222, 0.118973}, + { 0.379709, 0.292172, 0.139875}, { 0.010171, -0.055170, -0.174523} +}; + +static const float lsf_cb2_16k[256][3] = { + {-0.213011, -0.293385, -0.330597}, {-0.212582, -0.240992, -0.338239}, + {-0.223373, -0.306214, -0.277192}, {-0.231138, -0.287729, -0.229412}, + {-0.238466, -0.228571, -0.260954}, {-0.140931, -0.247018, -0.258566}, + {-0.136239, -0.249669, -0.350143}, {-0.149738, -0.192970, -0.281475}, + {-0.167058, -0.261052, -0.196301}, {-0.177049, -0.201324, -0.207897}, + {-0.116915, -0.200629, -0.212526}, {-0.162247, -0.143805, -0.245093}, + {-0.082042, -0.191842, -0.266338}, {-0.098846, -0.208511, -0.320481}, + {-0.113510, -0.152470, -0.222474}, {-0.066197, -0.179112, -0.207813}, + {-0.129490, -0.169320, -0.155238}, {-0.078843, -0.190292, -0.155172}, + {-0.087790, -0.147729, -0.169351}, {-0.141037, -0.127207, -0.177910}, + {-0.126525, -0.223961, -0.153639}, {-0.101464, -0.189953, -0.114559}, + {-0.102450, -0.106303, -0.151171}, {-0.103208, -0.144457, -0.105378}, + {-0.170794, -0.140525, -0.136428}, {-0.168641, -0.203064, -0.135368}, + {-0.138193, -0.116042, -0.111905}, {-0.145085, -0.168581, -0.092613}, + {-0.126379, -0.220431, -0.091327}, {-0.212934, -0.184797, -0.101632}, + {-0.193711, -0.140556, -0.078304}, {-0.173674, -0.197276, -0.060140}, + {-0.197897, -0.241907, -0.091997}, {-0.156037, -0.258519, -0.111628}, + {-0.241964, -0.191124, -0.063140}, {-0.261340, -0.240847, -0.103132}, + {-0.221621, -0.242972, -0.041255}, {-0.224166, -0.232742, -0.161568}, + {-0.203591, -0.294470, -0.126035}, {-0.209540, -0.303149, -0.053170}, + {-0.253859, -0.295066, -0.156050}, {-0.278143, -0.331105, -0.085237}, + {-0.300273, -0.198750, -0.094834}, {-0.260477, -0.169713, -0.132476}, + {-0.211889, -0.172454, -0.164281}, {-0.228370, -0.122149, -0.124178}, + {-0.254629, -0.135668, -0.081692}, {-0.263813, -0.154928, -0.213596}, + {-0.308224, -0.106877, -0.084404}, {-0.242644, -0.082862, -0.085835}, + {-0.252084, -0.064888, -0.146498}, {-0.198162, -0.105721, -0.188887}, + {-0.189238, -0.088028, -0.109736}, {-0.197598, -0.099831, -0.044030}, + {-0.269017, -0.105991, -0.021513}, {-0.231349, -0.058825, -0.041407}, + {-0.225589, -0.027501, -0.087160}, {-0.160347, -0.058341, -0.079789}, + {-0.158729, -0.108951, -0.067262}, {-0.170483, -0.053023, -0.017561}, + {-0.175207, -0.013649, -0.049513}, {-0.156004, -0.108378, -0.004052}, + {-0.219958, -0.082362, 0.014950}, {-0.217785, -0.012981, -0.009410}, + {-0.123290, -0.040849, -0.040910}, {-0.119861, -0.095078, -0.060246}, + {-0.117537, -0.065479, 0.002968}, {-0.103231, -0.113298, -0.023282}, + {-0.136365, -0.149524, -0.051387}, {-0.119332, -0.164400, -0.009103}, + {-0.104522, -0.060948, -0.083056}, {-0.071461, -0.070787, -0.037347}, + {-0.081116, -0.149015, -0.056740}, {-0.069561, -0.108099, -0.069167}, + {-0.055624, -0.117369, -0.025091}, {-0.091941, -0.190091, -0.060020}, + {-0.072003, -0.168433, -0.006540}, {-0.033305, -0.154427, -0.054608}, + {-0.062988, -0.127093, -0.108307}, {-0.056690, -0.170813, -0.102834}, + {-0.018273, -0.127863, -0.094998}, {-0.056239, -0.123678, -0.146262}, + {-0.023442, -0.154617, -0.137417}, {-0.051903, -0.078379, -0.093395}, + {-0.014599, -0.104412, -0.135959}, {-0.051582, -0.081280, -0.140643}, + {-0.092727, -0.091930, -0.107816}, {-0.024814, -0.140993, -0.183243}, + {-0.064307, -0.113024, -0.194788}, {-0.000118, -0.098858, -0.195336}, + {-0.028090, -0.048258, -0.164101}, {-0.093414, -0.055969, -0.172743}, + {-0.114445, -0.104336, -0.215204}, {-0.048518, -0.132063, -0.242991}, + {-0.159620, -0.060240, -0.178592}, {-0.135728, -0.067473, -0.131876}, + {-0.078464, -0.038040, -0.125105}, {-0.011061, -0.064011, -0.102496}, + {-0.033887, -0.026485, -0.109493}, {-0.129128, -0.014216, -0.111329}, + {-0.190687, -0.030660, -0.135825}, {-0.082037, 0.010997, -0.100167}, + {-0.183403, 0.001651, -0.098962}, {-0.074775, -0.030335, -0.062217}, + {-0.031759, -0.050551, -0.059420}, {-0.051439, 0.010827, -0.052148}, + {-0.126744, 0.008689, -0.047785}, {-0.145916, 0.042019, -0.077431}, + {-0.093552, 0.054143, -0.060473}, {-0.090660, 0.012868, -0.018195}, + {-0.079783, -0.033071, 0.001482}, {-0.033010, -0.022331, -0.014506}, + {-0.004798, -0.017339, -0.060120}, {-0.025021, 0.026390, -0.003263}, + {-0.001437, 0.025994, -0.040892}, {-0.074821, 0.019005, 0.027549}, + {-0.030811, -0.012114, 0.034284}, { 0.006785, 0.004618, 0.018717}, + { 0.013392, -0.032597, -0.023731}, { 0.035994, 0.005963, -0.011757}, + { 0.008071, -0.045750, 0.024889}, { 0.013055, 0.017040, 0.054121}, + {-0.012989, 0.044864, 0.036327}, { 0.025054, 0.047137, 0.009974}, + { 0.053801, 0.024178, 0.031774}, { 0.056442, -0.030647, 0.021291}, + { 0.032247, 0.052680, 0.049886}, { 0.035369, 0.090207, 0.031394}, + { 0.064720, 0.070390, 0.040938}, { 0.022112, 0.054834, 0.091059}, + { 0.041765, 0.086248, 0.070196}, { 0.070645, 0.060852, 0.078825}, + { 0.058506, 0.016920, 0.081612}, { 0.000009, 0.086500, 0.059849}, + { 0.071253, 0.107392, 0.059046}, { 0.094702, 0.096160, 0.090982}, + { 0.047639, 0.110877, 0.111227}, { 0.122444, 0.090909, 0.057396}, + { 0.101916, 0.052299, 0.029909}, { 0.076560, 0.086094, -0.007252}, + { 0.123411, 0.030769, 0.082749}, { 0.135579, 0.103022, 0.009540}, + { 0.120576, 0.065284, -0.024095}, { 0.077483, 0.028526, -0.012369}, + { 0.128747, 0.017901, -0.003874}, { 0.158254, 0.046962, 0.029577}, + { 0.102287, -0.002211, 0.037329}, { 0.089654, -0.021372, -0.006857}, + { 0.137917, 0.027228, -0.053223}, { 0.098728, -0.012192, -0.048518}, + { 0.083974, 0.036153, -0.062266}, { 0.048230, -0.010241, -0.052293}, + { 0.110135, 0.007715, -0.095233}, { 0.068294, -0.014317, -0.104029}, + { 0.063909, -0.056416, -0.063023}, { 0.059133, -0.044675, -0.023780}, + { 0.030748, 0.021845, -0.086332}, { 0.023994, -0.045574, -0.076232}, + { 0.052147, -0.059825, -0.109667}, { 0.013087, -0.020420, -0.121945}, + { 0.018163, -0.096765, -0.088758}, { 0.020196, -0.076470, -0.048112}, + { 0.020282, -0.084204, -0.135535}, { 0.040076, -0.053464, -0.161949}, + {-0.017796, -0.103070, -0.059559}, {-0.016484, -0.070138, -0.016866}, + { 0.004849, -0.112481, -0.017731}, { 0.040160, -0.073873, -0.005327}, + { 0.002202, -0.094723, 0.045366}, {-0.056918, -0.081578, 0.017875}, + {-0.031099, -0.141708, 0.009186}, {-0.102802, -0.122675, 0.030060}, + {-0.061717, -0.145116, 0.076680}, {-0.073607, -0.050464, 0.072853}, + {-0.117403, -0.194921, 0.040101}, {-0.185236, -0.133620, 0.045939}, + {-0.160174, -0.057226, 0.056641}, {-0.178489, -0.173435, -0.007806}, + {-0.199916, -0.204866, 0.047342}, {-0.152337, -0.249651, 0.034656}, + {-0.185637, -0.230942, -0.002072}, {-0.122548, -0.215209, -0.024552}, + {-0.249578, -0.209714, 0.009470}, {-0.160108, -0.257702, -0.040992}, + {-0.216694, -0.289353, 0.027182}, {-0.226390, -0.147844, -0.022742}, + {-0.288737, -0.272150, -0.013948}, {-0.262554, -0.237035, 0.072473}, + {-0.306267, -0.188335, -0.032894}, {-0.259666, -0.345816, 0.024138}, + {-0.271093, -0.137143, 0.040404}, {-0.201317, -0.286782, 0.107615}, + {-0.235725, -0.163396, 0.113844}, {-0.159988, -0.209788, 0.112140}, + {-0.262985, -0.056741, 0.093506}, {-0.277226, -0.037306, 0.016008}, + {-0.293486, -0.040422, -0.062018}, {-0.214921, 0.022900, 0.055295}, + {-0.253889, 0.058575, -0.000151}, {-0.246689, 0.024242, -0.058488}, + {-0.143790, 0.006767, 0.014061}, {-0.187077, 0.048882, -0.035625}, + {-0.196369, 0.112085, 0.031546}, {-0.124264, 0.086197, -0.020800}, + {-0.126249, 0.016960, 0.095741}, {-0.079816, 0.080398, 0.051038}, + {-0.056269, 0.075380, -0.028262}, {-0.120493, 0.148495, 0.028430}, + {-0.161750, 0.101290, 0.117806}, {-0.003247, 0.083393, -0.017061}, + {-0.034007, 0.142542, 0.007402}, {-0.037618, 0.025871, 0.089496}, + {-0.082819, 0.184435, 0.073224}, { 0.006448, 0.167015, 0.080548}, + { 0.035315, 0.144022, 0.003218}, {-0.023459, 0.088147, 0.152604}, + { 0.006247, -0.024099, 0.077792}, { 0.039894, 0.057586, -0.042455}, + {-0.020417, 0.035400, -0.093971}, { 0.075465, 0.052063, 0.145582}, + { 0.078027, 0.184720, 0.092096}, { 0.107295, 0.148380, 0.022264}, + { 0.066928, -0.052831, 0.065108}, { 0.093295, 0.118157, 0.149815}, + { 0.119373, 0.137114, 0.099536}, { 0.138653, 0.075509, 0.121545}, + { 0.174025, 0.077531, 0.077169}, { 0.165839, 0.150080, 0.133423}, + { 0.173276, 0.155887, 0.048150}, { 0.162910, 0.095898, 0.171896}, + { 0.214577, 0.112888, 0.115579}, { 0.204755, 0.106392, 0.032337}, + { 0.178853, 0.205034, 0.114760}, { 0.177401, 0.070504, -0.013778}, + { 0.241624, 0.166921, 0.066087}, { 0.219595, 0.183553, 0.172332}, + { 0.123671, 0.170842, 0.167216}, { 0.177104, 0.240197, 0.186359}, + { 0.272003, 0.220214, 0.126073}, { 0.093748, 0.235843, 0.160998}, + { 0.141510, 0.190012, 0.240416}, { 0.046878, 0.168984, 0.190412}, + { 0.094898, 0.107038, 0.235003}, { 0.108592, 0.269536, 0.262528}, + {-0.027754, 0.234355, 0.134544}, { 0.265127, 0.267540, 0.199041}, + { 0.199523, 0.291507, 0.265171}, { 0.266177, 0.209339, 0.350369}, + { 0.322159, 0.344794, 0.270823}, { 0.399957, 0.264065, 0.110387}, + { 0.277817, 0.127407, -0.035625}, {-0.177038, 0.208155, 0.119077}, + { 0.049075, -0.076294, 0.145711}, { 0.187246, 0.042865, -0.127097}, + { 0.117885, -0.023489, -0.138658}, {-0.284256, 0.068153, 0.124259} +}; + +static const float lsf_cb3_16k[128][3] = { + {-0.223412, -0.236300, -0.188067}, {-0.202286, -0.218711, -0.102947}, + {-0.251652, -0.161020, -0.125280}, {-0.169223, -0.138155, -0.140430}, + {-0.176427, -0.146628, -0.222632}, {-0.120584, -0.187276, -0.180164}, + {-0.195559, -0.074225, -0.169109}, {-0.144551, -0.142774, -0.073340}, + {-0.111001, -0.111310, -0.130696}, {-0.095221, -0.174684, -0.111841}, + {-0.112158, -0.103049, -0.195130}, {-0.059989, -0.142170, -0.157850}, + {-0.127598, -0.051759, -0.153109}, {-0.063753, -0.067898, -0.164117}, + {-0.141753, -0.068274, -0.091999}, {-0.060482, -0.101054, -0.099475}, + {-0.104699, -0.104456, -0.066496}, {-0.073649, -0.052614, -0.091612}, + {-0.088268, -0.019072, -0.129956}, {-0.018837, -0.104115, -0.127837}, + {-0.021630, -0.033055, -0.129868}, {-0.083768, -0.047549, -0.041407}, + {-0.055892, -0.108526, -0.043200}, {-0.027816, -0.062499, -0.048190}, + {-0.002248, -0.110428, -0.062868}, { 0.001270, -0.033245, -0.072404}, + {-0.042747, -0.013835, -0.033829}, {-0.037615, -0.147833, -0.083912}, + {-0.045023, 0.006011, -0.092182}, {-0.050411, -0.081832, 0.005787}, + { 0.000357, -0.104282, -0.009428}, {-0.003893, -0.047892, -0.001506}, + {-0.040077, -0.147110, -0.009065}, {-0.060858, -0.030972, 0.012999}, + {-0.014674, 0.001370, 0.005554}, {-0.101362, -0.126061, -0.001898}, + {-0.102519, -0.000390, -0.015721}, {-0.132687, -0.069608, -0.019928}, + {-0.102227, -0.076131, 0.043306}, {-0.055193, 0.027001, 0.011857}, + {-0.156427, -0.016629, 0.017480}, {-0.078736, 0.002809, 0.057979}, + {-0.157789, -0.016693, -0.055073}, {-0.179397, -0.095520, 0.022065}, + {-0.110219, 0.010408, -0.081927}, {-0.125392, 0.049111, 0.044595}, + {-0.112528, 0.063173, -0.024954}, {-0.185525, 0.053093, -0.032102}, + {-0.176887, -0.019379, -0.115125}, {-0.249706, -0.017664, -0.059188}, + {-0.200243, -0.103311, -0.066846}, {-0.055404, 0.045106, -0.046991}, + {-0.000544, 0.022690, -0.044831}, { 0.022298, -0.016367, -0.022509}, + { 0.028278, 0.017585, -0.100612}, { 0.061781, -0.020826, -0.068190}, + { 0.029157, -0.074477, -0.098898}, { 0.043073, -0.067234, -0.032293}, + { 0.060157, 0.034636, -0.034885}, { 0.071153, -0.013881, -0.009036}, + { 0.054196, -0.029989, -0.131139}, { 0.030193, 0.024976, 0.009861}, + { 0.055943, -0.045304, 0.031927}, { 0.033217, -0.002418, 0.038165}, + { 0.063814, 0.045625, 0.025309}, { 0.033689, 0.038819, 0.049700}, + { 0.073582, 0.028527, 0.060200}, {-0.007957, 0.022531, 0.043687}, + {-0.000984, 0.054518, 0.018742}, { 0.057004, 0.060916, 0.060573}, + { 0.009883, 0.015238, 0.080211}, { 0.022742, 0.070832, 0.068855}, + { 0.053001, 0.029790, 0.091446}, {-0.042447, 0.060379, 0.061462}, + { 0.076826, 0.062468, 0.089653}, { 0.039065, 0.069768, 0.119128}, + { 0.064145, 0.095353, 0.071621}, { 0.094411, 0.069527, 0.054197}, + { 0.042812, 0.093060, 0.027980}, { 0.094791, 0.099189, 0.101112}, + { 0.117611, 0.048601, 0.093111}, { 0.119951, 0.122758, 0.051546}, + { 0.103558, 0.085245, -0.010700}, { 0.150126, 0.059766, 0.020280}, + { 0.108066, 0.017170, 0.008606}, { 0.108422, 0.023253, -0.063942}, + { 0.019652, 0.072284, -0.030331}, { 0.192719, 0.075624, 0.071156}, + { 0.221140, 0.069191, -0.035085}, { 0.188367, 0.126200, 0.035225}, + { 0.185760, 0.043537, -0.101714}, {-0.042518, 0.099646, 0.003244}, + {-0.015308, -0.027521, 0.046006}, { 0.034086, -0.045777, 0.095989}, + { 0.007174, -0.093358, 0.046459}, {-0.051248, -0.062095, 0.083161}, + {-0.045626, -0.133301, 0.052997}, {-0.037840, 0.024042, 0.131097}, + {-0.020217, -0.115942, 0.126170}, {-0.134550, -0.036291, 0.111322}, + {-0.110576, -0.160024, 0.091841}, {-0.093308, -0.184958, 0.013939}, + {-0.082735, -0.167417, -0.051725}, {-0.169934, -0.173003, -0.007155}, + {-0.128244, -0.213123, -0.053337}, {-0.079852, -0.154116, -0.246546}, + {-0.032242, -0.108756, -0.204133}, {-0.140117, -0.199495, -0.284505}, + { 0.010842, -0.074979, -0.166333}, {-0.093313, 0.145006, 0.034110}, + {-0.039236, 0.113213, 0.111053}, { 0.040613, -0.031783, 0.174058}, + {-0.164232, 0.131421, 0.149842}, { 0.026893, 0.107281, 0.179297}, + { 0.047086, 0.158606, 0.103267}, {-0.070567, 0.210459, 0.134734}, + { 0.094392, 0.137050, 0.166892}, { 0.086039, 0.063657, 0.168825}, + { 0.159371, 0.120897, 0.154357}, { 0.147101, 0.160684, 0.114882}, + { 0.120158, 0.199650, 0.180948}, { 0.191417, 0.174500, 0.170734}, + { 0.159153, 0.142165, 0.233347}, { 0.232002, 0.150181, 0.102736}, + { 0.188299, 0.221738, 0.228748}, { 0.256786, 0.209685, 0.161534}, + { 0.257861, 0.247793, 0.250516}, {-0.164461, -0.000143, 0.232461} +}; + +static const float lsf_cb4_16k[128][3] = { + {-0.193369, -0.304643, -0.253777}, {-0.164125, -0.277786, -0.153116}, + {-0.135681, -0.209120, -0.211724}, {-0.121822, -0.215734, -0.292207}, + {-0.198781, -0.161674, -0.242538}, {-0.164147, -0.180570, -0.138070}, + {-0.095915, -0.198695, -0.154309}, {-0.248386, -0.234462, -0.136984}, + {-0.164968, -0.108318, -0.175635}, {-0.124171, -0.111809, -0.224402}, + {-0.067398, -0.157017, -0.195759}, {-0.090132, -0.119174, -0.165253}, + {-0.099460, -0.146895, -0.106799}, {-0.141493, -0.108103, -0.108880}, + {-0.085088, -0.098340, -0.109953}, {-0.105526, -0.054463, -0.154315}, + {-0.040480, -0.144285, -0.124042}, {-0.040969, -0.084039, -0.142880}, + {-0.049082, -0.118553, -0.066686}, {-0.096336, -0.087515, -0.055741}, + {-0.058605, -0.059327, -0.089275}, {-0.121842, -0.058681, -0.086949}, + {-0.053792, -0.022025, -0.124451}, {-0.036744, -0.068891, -0.045865}, + { 0.003900, -0.098237, -0.091158}, {-0.001664, -0.045089, -0.081353}, + {-0.072829, -0.034087, -0.038416}, {-0.100822, -0.007330, -0.088715}, + {-0.035911, -0.005864, -0.062577}, {-0.020205, -0.026547, -0.019634}, + { 0.004291, -0.041290, -0.138181}, { 0.023404, -0.010932, -0.044904}, + { 0.013557, 0.014823, -0.092943}, { 0.059673, -0.031024, -0.095739}, + { 0.021130, -0.080607, -0.034594}, { 0.024655, -0.035564, 0.003243}, + { 0.017106, 0.006952, -0.000308}, { 0.075208, -0.030910, -0.031181}, + { 0.024965, 0.048632, -0.039448}, { 0.057028, 0.021547, -0.009418}, + {-0.018577, 0.023697, -0.009759}, { 0.024077, 0.033053, 0.024324}, + { 0.037052, -0.003436, 0.044530}, {-0.012871, -0.007179, 0.031795}, + { 0.077877, 0.021547, 0.023131}, { 0.053365, 0.052078, 0.029433}, + { 0.011429, 0.070426, 0.028734}, {-0.001827, 0.033115, 0.061505}, + {-0.044870, 0.038568, 0.026239}, { 0.061633, 0.034799, 0.059784}, + { 0.034261, 0.060342, 0.065185}, { 0.058981, 0.082481, 0.047252}, + { 0.090008, 0.065942, 0.044470}, { 0.066961, 0.073728, -0.000428}, + { 0.074763, 0.060293, 0.085632}, { 0.066366, 0.103375, 0.079642}, + { 0.122297, 0.036558, 0.058745}, { 0.111042, 0.092093, 0.085412}, + { 0.099243, 0.115476, 0.039254}, { 0.019973, 0.122844, 0.050255}, + { 0.159571, 0.098965, 0.051740}, { 0.137624, 0.072405, -0.006922}, + { 0.130240, 0.146091, 0.089698}, { 0.138335, 0.092968, 0.136193}, + { 0.066031, 0.149304, 0.125476}, { 0.202749, 0.145751, 0.077122}, + { 0.002224, 0.082811, 0.131200}, { 0.124476, 0.178073, 0.162336}, + { 0.174722, 0.190298, 0.127106}, { 0.202193, 0.153569, 0.163840}, + { 0.242604, 0.197796, 0.136929}, { 0.185809, 0.229348, 0.193353}, + {-0.058814, 0.195178, 0.141821}, { 0.253646, 0.247175, 0.205766}, + { 0.061433, -0.025542, 0.119311}, {-0.057816, 0.082445, 0.073243}, + {-0.069239, 0.148678, 0.031146}, {-0.030217, -0.008503, 0.106194}, + {-0.026708, 0.087469, -0.009589}, {-0.090418, 0.000265, 0.056807}, + {-0.050607, -0.019383, 0.010494}, {-0.079397, 0.008233, -0.011469}, + {-0.072634, -0.061165, 0.046917}, {-0.075741, -0.072343, -0.007557}, + {-0.025162, -0.073363, 0.005173}, {-0.123371, -0.041257, -0.008375}, + {-0.139904, 0.018285, 0.009920}, {-0.143421, -0.104238, 0.033457}, + {-0.100923, -0.134400, -0.023257}, {-0.157791, -0.095042, -0.036959}, + {-0.219890, -0.078637, 0.001815}, {-0.183607, -0.023053, -0.043678}, + {-0.145303, -0.158923, -0.059045}, {-0.197615, -0.165199, 0.028099}, + {-0.225131, -0.167756, -0.056401}, {-0.216572, -0.104751, -0.102964}, + {-0.171336, -0.241967, -0.063404}, {-0.134035, -0.205614, 0.011831}, + {-0.297116, -0.211173, -0.015352}, {-0.086464, -0.200592, -0.070454}, + {-0.217777, -0.278403, 0.030398}, {-0.236248, -0.323694, -0.087588}, + {-0.222074, -0.210785, 0.106210}, {-0.283400, -0.097077, 0.041303}, + {-0.078417, -0.154464, 0.062956}, {-0.214417, -0.100695, 0.121909}, + {-0.178576, -0.028847, 0.061042}, {-0.037999, -0.144233, -0.010546}, + {-0.086695, -0.070996, 0.125282}, { 0.010788, -0.085006, 0.058527}, + {-0.154015, 0.066560, 0.071038}, {-0.143503, 0.033260, 0.154393}, + {-0.134069, 0.032420, -0.056293}, {-0.110851, 0.086908, 0.003920}, + {-0.057254, 0.047674, -0.055571}, {-0.214206, 0.068784, -0.004735}, + {-0.257264, 0.050468, 0.081702}, {-0.291834, 0.004120, -0.022366}, + {-0.173309, -0.029081, -0.115901}, {-0.207622, 0.168664, 0.136030}, + { 0.090541, 0.032754, -0.057330}, { 0.140219, -0.000735, -0.015633}, + { 0.136697, -0.017163, -0.100909}, { 0.029838, -0.089515, -0.147130}, + {-0.055367, -0.072683, -0.214015}, { 0.048680, -0.057633, -0.212429}, + {-0.013134, -0.113898, -0.196403}, {-0.071702, -0.159408, -0.254895} +}; + +static const float lsf_cb5_16k[128][4] = { + {-0.201277, -0.278679, -0.173262, -0.198580}, + {-0.214667, -0.151922, -0.117551, -0.192713}, + {-0.160962, -0.207728, -0.124750, -0.129749}, + {-0.131043, -0.137818, -0.155281, -0.166308}, + {-0.179134, -0.169602, -0.165223, -0.066293}, + {-0.136474, -0.177035, -0.250127, -0.134370}, + {-0.066970, -0.146274, -0.170638, -0.134436}, + {-0.083288, -0.165860, -0.103437, -0.140361}, + {-0.130474, -0.119317, -0.124393, -0.086408}, + {-0.127609, -0.134415, -0.073592, -0.116103}, + {-0.113027, -0.091756, -0.107786, -0.131935}, + {-0.125530, -0.182152, -0.093796, -0.045088}, + {-0.077122, -0.138052, -0.166271, -0.038886}, + {-0.073027, -0.106845, -0.067073, -0.113910}, + {-0.049146, -0.107019, -0.112531, -0.063388}, + {-0.101539, -0.119586, -0.050297, -0.040670}, + {-0.107784, -0.066913, -0.080993, -0.052352}, + {-0.152155, -0.103010, -0.090461, -0.015526}, + {-0.153087, -0.087656, -0.029889, -0.037367}, + {-0.215281, -0.138062, -0.089162, -0.050839}, + {-0.053350, -0.060169, -0.063459, -0.024499}, + {-0.051674, -0.076355, -0.033733, -0.077211}, + {-0.045047, -0.107006, -0.020880, -0.024525}, + {-0.083003, -0.063672, -0.013243, -0.028324}, + {-0.104104, -0.075450, -0.032746, 0.024480}, + {-0.085695, -0.019502, -0.045121, -0.025016}, + {-0.123120, -0.030844, -0.003533, -0.016224}, + {-0.025568, -0.049172, -0.003911, -0.027522}, + {-0.039029, -0.019857, -0.043211, -0.058087}, + {-0.040122, -0.023067, -0.001356, 0.008607}, + {-0.063351, -0.001776, 0.016015, -0.027088}, + {-0.068110, -0.038838, 0.042525, 0.001076}, + {-0.043623, -0.020736, -0.047862, 0.037710}, + {-0.041052, 0.021954, -0.025660, 0.000758}, + {-0.013035, 0.002583, -0.008233, -0.037300}, + {-0.005523, -0.014670, 0.019651, -0.012667}, + {-0.004409, -0.014437, -0.059412, -0.019701}, + { 0.024946, -0.011663, -0.014351, -0.028762}, + { 0.012660, 0.018489, -0.010205, 0.012695}, + {-0.004423, 0.017827, 0.040544, 0.003629}, + { 0.020684, 0.026743, 0.007752, -0.025595}, + { 0.032071, 0.000043, 0.026188, -0.006444}, + { 0.058793, 0.015820, -0.001119, -0.017415}, + { 0.020156, -0.047590, 0.004227, 0.008670}, + { 0.054770, 0.032135, 0.029770, -0.009767}, + { 0.030884, 0.047757, 0.033068, 0.006866}, + { 0.062039, 0.011646, 0.056037, 0.016859}, + { 0.013798, -0.028196, 0.060710, 0.014299}, + { 0.100043, 0.041445, 0.023379, -0.014889}, + { 0.062728, -0.042821, 0.002180, -0.055380}, + { 0.061663, 0.018767, -0.015571, -0.074095}, + { 0.062980, 0.080497, 0.011808, -0.031787}, + { 0.084964, 0.043100, -0.025877, 0.020309}, + { 0.014707, 0.035421, -0.041440, -0.053373}, + { 0.081268, 0.005791, -0.066290, -0.039825}, + { 0.017691, -0.020401, -0.040513, -0.083960}, + { 0.120874, 0.055753, -0.025988, -0.059552}, + { 0.079912, 0.007894, -0.085380, -0.114587}, + { 0.036856, -0.039331, -0.104237, -0.069116}, + { 0.008526, -0.064273, -0.048312, -0.038595}, + { 0.033461, -0.028956, -0.066505, 0.038722}, + {-0.042064, -0.043989, -0.100653, -0.071550}, + {-0.015342, -0.064850, -0.065675, -0.122769}, + {-0.006581, -0.004919, -0.113564, -0.145753}, + { 0.008273, -0.070702, -0.164998, -0.095541}, + {-0.001698, -0.063744, -0.129971, -0.011162}, + {-0.048471, -0.087500, -0.111006, -0.161823}, + {-0.032193, -0.091955, -0.080642, 0.012288}, + {-0.095873, -0.015986, -0.072722, -0.101745}, + {-0.079477, -0.082060, -0.203008, -0.100297}, + {-0.023883, -0.064022, -0.168341, -0.211739}, + {-0.070530, -0.103547, -0.123858, 0.055049}, + {-0.033503, -0.076812, -0.016287, 0.044159}, + {-0.088427, -0.161682, -0.058579, 0.013873}, + {-0.083068, -0.168222, -0.016773, -0.080209}, + {-0.080548, -0.139090, 0.030544, 0.007171}, + {-0.117482, -0.083718, 0.027074, -0.003674}, + {-0.163085, -0.156856, -0.012618, -0.022329}, + {-0.176540, -0.113042, -0.020148, 0.051770}, + {-0.153891, -0.199293, -0.043244, 0.028331}, + {-0.107822, -0.150615, 0.016430, 0.092919}, + {-0.137676, -0.183224, 0.066026, 0.029343}, + {-0.191106, -0.099250, 0.045370, 0.004084}, + {-0.237042, -0.130815, -0.022543, -0.029428}, + {-0.201014, -0.053591, -0.007305, -0.033547}, + {-0.249286, -0.228408, 0.005002, 0.007146}, + {-0.206509, -0.211998, -0.061352, -0.047233}, + {-0.255702, -0.135114, 0.076375, 0.036630}, + {-0.296271, -0.073946, -0.007273, -0.019601}, + {-0.302917, -0.175111, -0.070024, -0.043905}, + {-0.239275, -0.043962, -0.084982, -0.067446}, + {-0.254583, -0.294720, -0.088762, -0.070451}, + {-0.205583, -0.238996, -0.124753, 0.033076}, + {-0.205583, -0.215882, -0.028472, 0.118679}, + {-0.153640, -0.204464, -0.039654, -0.134441}, + {-0.145929, -0.191970, -0.175308, 0.021366}, + {-0.149348, -0.212569, -0.118324, 0.103812}, + {-0.166397, -0.220581, -0.265260, -0.029113}, + {-0.164171, -0.231262, -0.258828, 0.061427}, + {-0.200198, -0.263453, -0.212016, 0.115359}, + {-0.130088, -0.212168, -0.202368, 0.118563}, + {-0.206387, -0.078075, -0.227856, -0.111165}, + {-0.129605, -0.176848, -0.241584, -0.259900}, + {-0.176826, -0.045901, -0.141712, -0.209345}, + {-0.351173, -0.031097, -0.133935, -0.182412}, + {-0.164232, 0.027006, -0.014039, -0.053567}, + {-0.171037, -0.025924, 0.030972, 0.017329}, + {-0.080862, -0.021577, 0.007652, 0.063968}, + {-0.061788, 0.042024, -0.018783, -0.057979}, + {-0.110311, 0.054760, 0.031446, -0.006710}, + {-0.136637, 0.022171, 0.084991, 0.028039}, + {-0.254471, -0.004376, 0.078034, 0.033649}, + {-0.234464, 0.088157, 0.040999, 0.002639}, + {-0.037095, 0.059443, 0.072180, 0.015027}, + {-0.046841, -0.004813, 0.088266, 0.038786}, + {-0.086782, 0.120100, 0.082655, 0.020271}, + {-0.118361, -0.069242, 0.094867, 0.039200}, + {-0.023342, -0.084303, 0.052684, 0.017093}, + {-0.014194, 0.001012, 0.011946, 0.074125}, + {-0.015342, 0.076396, 0.022365, -0.028001}, + { 0.027706, 0.037047, 0.107573, 0.060815}, + { 0.030615, 0.040664, 0.010467, 0.074289}, + { 0.038646, 0.115584, 0.069627, 0.007642}, + { 0.096463, 0.069818, 0.062494, 0.015413}, + { 0.054834, 0.065232, 0.054286, 0.110088}, + { 0.152312, 0.092371, 0.026420, -0.013184}, + { 0.144264, 0.123438, 0.080131, 0.023233}, + { 0.124405, 0.009943, -0.148477, -0.205184} +}; + +static const float *lsf_codebooks_16k[] = { + lsf_cb1_16k[0], lsf_cb2_16k[0], lsf_cb3_16k[0], lsf_cb4_16k[0], + lsf_cb5_16k[0] +}; + +#endif /* AVCODEC_SIPR16KDATA_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/siprdata.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/siprdata.h new file mode 100644 index 0000000000..ed804ee87c --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/siprdata.h @@ -0,0 +1,263 @@ +/* + * SIPR / ACELP.NET decoder + * + * Copyright (c) 2008 Vladimir Voroshilov + * Copyright (c) 2009 Vitor Sessak + * + * 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_SIPRDATA_H +#define AVCODEC_SIPRDATA_H + +static const float mean_lsf[10] = { + 0.297151, 0.452308, 0.765443, 1.134803, 1.421125, + 1.773822, 2.049173, 2.375914, 2.585097, 0.075756 +}; + +static const float lsf_cb1[64][2] = { + { 0.007587, -0.005843}, { 0.042163, -0.028048}, {-0.017147, -0.060705}, + { 0.013773, -0.038108}, {-0.041563, -0.078571}, {-0.076928, -0.119343}, + { 0.012654, 0.176005}, { 0.059737, 0.156869}, { 0.171767, 0.231837}, + { 0.114030, 0.242047}, { 0.168977, 0.283101}, { 0.146210, 0.397961}, + { 0.249446, 0.268421}, { 0.137074, 0.186724}, {-0.057736, -0.135638}, + {-0.109664, -0.124611}, {-0.021234, -0.031174}, {-0.013990, -0.091819}, + {-0.040046, -0.111426}, {-0.016830, 0.055361}, { 0.057815, 0.071606}, + { 0.060670, 0.114436}, { 0.106695, 0.140838}, { 0.093601, 0.092793}, + { 0.039593, 0.006142}, {-0.066589, -0.092463}, {-0.102589, -0.171380}, + {-0.059621, -0.050671}, { 0.166131, 0.139773}, { 0.213069, 0.190761}, + { 0.061820, 0.037661}, { 0.136471, 0.090823}, {-0.019789, 0.013515}, + { 0.022280, 0.079473}, { 0.215281, 0.461959}, { 0.206497, 0.340077}, + { 0.012249, -0.065596}, { 0.091345, 0.190871}, { 0.019506, 0.037266}, + {-0.050702, -0.013223}, {-0.057334, 0.028943}, { 0.291512, 0.371415}, + {-0.053467, 0.084160}, { 0.025372, 0.375310}, { 0.269995, 0.566520}, + {-0.095259, -0.012353}, { 0.050479, 0.212893}, { 0.101219, 0.049320}, + { 0.072426, 0.283362}, {-0.084116, -0.150542}, {-0.031485, 0.144922}, + { 0.012714, 0.256910}, {-0.009528, 0.102768}, {-0.039572, 0.204967}, + {-0.098800, 0.055038}, { 0.020719, 0.128387}, {-0.045559, -0.178373}, + {-0.082338, 0.136933}, {-0.058270, 0.292806}, { 0.084242, 0.505112}, + { 0.121825, 0.326386}, {-0.102658, -0.069341}, { 0.071675, 0.004744}, + {-0.117763, -0.202608} +}; + +static const float lsf_cb2[128][2] = { + { 0.025412, 0.006095}, {-0.069803, 0.010650}, {-0.175957, -0.185800}, + {-0.139298, -0.048013}, {-0.156150, -0.129688}, {-0.160523, 0.068022}, + { 0.199683, 0.259982}, { 0.258038, 0.236147}, { 0.367089, 0.304716}, + { 0.251764, 0.305853}, { 0.394314, 0.382153}, { 0.448579, 0.337438}, + { 0.323286, 0.425563}, { 0.015369, 0.123820}, {-0.026770, 0.083881}, + {-0.112161, -0.097993}, {-0.221847, -0.161311}, {-0.050014, -0.092862}, + {-0.214960, -0.398498}, {-0.114062, -0.241381}, { 0.137950, 0.138852}, + { 0.031529, 0.065719}, { 0.208734, 0.084760}, { 0.157862, 0.057535}, + { 0.124750, 0.011922}, {-0.035227, -0.154397}, {-0.105523, -0.291427}, + {-0.073488, -0.201948}, {-0.224184, -0.273290}, {-0.168019, -0.240297}, + {-0.271591, -0.384682}, {-0.124784, 0.014253}, { 0.004210, -0.110418}, + { 0.074270, -0.014272}, { 0.053058, -0.068672}, {-0.090098, -0.145019}, + { 0.303214, 0.210323}, { 0.413443, 0.272002}, { 0.356904, 0.230646}, + {-0.035186, -0.028579}, {-0.117558, 0.115105}, {-0.159225, 0.218385}, + {-0.230178, 0.172901}, {-0.216148, -0.110195}, { 0.309444, 0.101508}, + { 0.250489, 0.118338}, { 0.293324, 0.151205}, {-0.023634, 0.033084}, + { 0.076708, 0.114024}, { 0.123119, 0.087704}, {-0.060265, 0.126543}, + {-0.223766, -0.021903}, {-0.241987, -0.328089}, { 0.205598, 0.147925}, + {-0.087010, 0.064601}, {-0.287892, -0.286099}, {-0.179451, -0.350781}, + {-0.219572, 0.043816}, {-0.217263, 0.245550}, {-0.286743, -0.180981}, + { 0.172659, 0.112620}, {-0.105422, 0.176856}, { 0.006176, -0.051491}, + { 0.099802, 0.176322}, {-0.186620, -0.068980}, { 0.164689, 0.185018}, + { 0.519877, 0.376111}, { 0.521941, 0.533731}, { 0.473375, 0.439534}, + { 0.214235, 0.202476}, { 0.579215, 0.466969}, { 0.310414, 0.271057}, + { 0.257450, 0.058939}, { 0.023936, -0.169464}, {-0.268817, -0.064531}, + {-0.174182, -0.000198}, {-0.268405, -0.234529}, {-0.296522, 0.247140}, + { 0.115950, -0.072194}, {-0.303666, 0.149084}, {-0.347762, -0.011002}, + {-0.223829, -0.214137}, {-0.278958, -0.457975}, { 0.135500, 0.238466}, + { 0.312730, 0.342760}, { 0.071754, -0.125912}, { 0.485938, 0.260429}, + { 0.037536, 0.179771}, { 0.391493, 0.156938}, { 0.397320, 0.484446}, + {-0.308630, -0.342418}, {-0.269599, -0.128453}, {-0.086683, -0.043863}, + { 0.421115, 0.213521}, { 0.082417, 0.049006}, {-0.087873, 0.238126}, + { 0.338899, 0.166131}, {-0.166988, 0.147105}, {-0.167214, -0.294075}, + { 0.588706, 0.328303}, { 0.207270, 0.017671}, {-0.141658, 0.291147}, + {-0.140850, 0.374321}, { 0.028180, 0.322510}, {-0.229858, 0.328036}, + {-0.060743, -0.260916}, {-0.011131, 0.246442}, {-0.058151, 0.310760}, + {-0.127536, -0.186432}, {-0.128523, -0.334884}, {-0.283899, 0.077729}, + {-0.031595, 0.181015}, {-0.329330, -0.108630}, {-0.215739, 0.107458}, + { 0.175734, 0.327134}, { 0.255801, 0.176077}, { 0.228265, 0.396859}, + {-0.370909, -0.185081}, {-0.355138, -0.300405}, { 0.061669, 0.242616}, + { 0.104489, 0.307995}, {-0.320021, -0.234002}, { 0.077349, 0.416286}, + {-0.339471, -0.407609}, {-0.019384, -0.215111}, { 0.168229, -0.032453}, + {-0.040140, 0.399658}, {-0.275141, 0.008218} +}; + +static const float lsf_cb3[128][2] = { + { 0.024608, 0.006198}, {-0.216616, -0.398169}, {-0.089601, -0.201370}, + {-0.121878, -0.305281}, { 0.037913, 0.059320}, { 0.245126, 0.244089}, + { 0.266853, 0.182476}, { 0.319362, 0.203481}, { 0.349945, 0.252644}, + { 0.393849, 0.279272}, { 0.445707, 0.258063}, { 0.387321, 0.200855}, + {-0.038818, 0.129603}, {-0.009510, 0.076441}, {-0.023892, -0.028199}, + {-0.117134, -0.145990}, {-0.186585, -0.052886}, {-0.034250, -0.084547}, + {-0.087443, -0.095426}, {-0.453322, -0.174493}, {-0.363975, -0.148186}, + {-0.334413, -0.202479}, {-0.221313, -0.181320}, {-0.131146, -0.050611}, + {-0.104706, 0.115139}, { 0.192765, 0.275417}, { 0.014184, 0.194251}, + { 0.154215, 0.226949}, { 0.084031, 0.221759}, { 0.189438, 0.164566}, + { 0.130737, 0.170962}, {-0.066815, 0.062954}, {-0.177176, -0.145167}, + {-0.247608, -0.129767}, {-0.187886, -0.293720}, {-0.244036, -0.344655}, + {-0.203063, -0.234947}, {-0.292715, -0.158421}, { 0.064990, -0.028164}, + { 0.147664, 0.085995}, { 0.107977, 0.002253}, { 0.071286, 0.027533}, + { 0.021017, -0.049807}, {-0.272056, -0.217857}, {-0.065596, 0.008375}, + {-0.150818, -0.195514}, {-0.012767, -0.150787}, { 0.238541, 0.136606}, + { 0.291741, 0.114024}, { 0.202677, 0.103701}, { 0.140985, 0.037759}, + {-0.257347, -0.442383}, {-0.320666, -0.319742}, {-0.488725, -0.603660}, + {-0.319170, -0.469806}, { 0.014970, -0.101074}, { 0.102209, 0.066790}, + {-0.076202, -0.044884}, { 0.073868, 0.152565}, { 0.070755, -0.091358}, + {-0.016751, 0.027216}, { 0.071201, 0.096981}, {-0.060975, -0.145638}, + { 0.114156, 0.117587}, {-0.284757, -0.029101}, {-0.253005, -0.073645}, + {-0.204028, -0.098492}, {-0.114508, 0.001219}, {-0.225284, -0.011998}, + {-0.235670, 0.084330}, { 0.161921, 0.128334}, { 0.025717, 0.119456}, + {-0.255292, -0.281471}, {-0.392803, -0.095809}, { 0.039229, -0.152110}, + {-0.310905, -0.099233}, {-0.268773, 0.032308}, {-0.340150, 0.013129}, + {-0.344890, -0.045157}, {-0.188423, 0.265603}, {-0.168235, -0.000936}, + { 0.000462, 0.297000}, { 0.263674, 0.371214}, {-0.146797, -0.098225}, + {-0.386557, -0.282426}, {-0.070940, -0.255550}, { 0.293258, 0.252785}, + { 0.408332, 0.387751}, {-0.381914, -0.358918}, {-0.463621, -0.315560}, + {-0.323681, -0.258465}, { 0.250055, 0.071195}, {-0.405256, -0.429754}, + {-0.135748, -0.251274}, { 0.186827, 0.060177}, { 0.116742, -0.053526}, + {-0.403321, -0.220339}, {-0.414144, -0.021108}, {-0.416877, 0.050184}, + {-0.470083, -0.079564}, {-0.315554, 0.219217}, {-0.273183, 0.138437}, + { 0.253231, 0.306374}, { 0.177802, 0.346298}, { 0.210358, 0.207697}, + {-0.323480, 0.077519}, {-0.193136, 0.048170}, { 0.114492, 0.292778}, + {-0.130766, 0.056677}, {-0.171572, -0.349267}, {-0.370076, -0.536392}, + {-0.311109, -0.389953}, { 0.334928, 0.367664}, { 0.351246, 0.438664}, + { 0.518803, 0.331253}, { 0.437061, 0.327257}, { 0.318906, 0.307389}, + {-0.025972, -0.206758}, { 0.373278, 0.325438}, { 0.473488, 0.389441}, + { 0.478553, 0.477990}, { 0.332783, 0.153825}, { 0.212098, 0.452336}, + { 0.161522, -0.011212}, { 0.209368, 0.020687}, {-0.086262, 0.204493}, + {-0.388643, 0.133640}, {-0.177016, 0.134404} +}; + +static const float lsf_cb4[128][2] = { + {-0.003594, -0.022447}, { 0.070651, 0.028334}, {-0.290374, -0.018347}, + {-0.224495, -0.370312}, {-0.269555, -0.131227}, {-0.122714, -0.267733}, + { 0.173325, 0.138698}, { 0.161946, 0.020687}, { 0.111706, 0.022510}, + { 0.097638, 0.056049}, { 0.139754, 0.059920}, { 0.056549, -0.050586}, + { 0.036301, 0.021501}, {-0.066347, 0.012324}, {-0.066972, 0.096136}, + {-0.120062, -0.084201}, { 0.011225, 0.047425}, {-0.012846, -0.067390}, + {-0.116201, 0.122874}, {-0.027819, 0.035453}, {-0.024743, 0.072835}, + {-0.034061, -0.001310}, { 0.077469, 0.081609}, { 0.128347, 0.139584}, + { 0.183416, 0.086563}, {-0.155839, -0.053775}, {-0.190403, -0.018639}, + {-0.202548, -0.062841}, {-0.373733, -0.275094}, {-0.394260, -0.186513}, + {-0.465700, -0.220031}, { 0.064400, -0.095825}, {-0.262053, -0.199837}, + {-0.167233, -0.094402}, { 0.048600, 0.057567}, {-0.007122, 0.168506}, + { 0.050938, 0.156451}, {-0.060828, 0.147083}, {-0.171889, 0.195822}, + {-0.218934, 0.138431}, {-0.270532, 0.195775}, {-0.405818, 0.075643}, + {-0.440187, 0.193387}, {-0.484968, 0.157607}, {-0.480560, 0.067230}, + {-0.436757, -0.111847}, {-0.040731, -0.040363}, {-0.202319, -0.170457}, + {-0.158515, -0.134551}, {-0.356709, -0.378549}, {-0.268820, -0.289831}, + {-0.188486, -0.289306}, {-0.148139, -0.177616}, {-0.071591, -0.191128}, + {-0.052270, -0.150589}, {-0.020543, -0.116220}, { 0.039584, -0.012592}, + {-0.268226, 0.042704}, {-0.209755, 0.069423}, {-0.168964, 0.124504}, + {-0.363240, 0.188266}, {-0.524935, -0.025010}, {-0.105894, -0.002699}, + {-0.251830, -0.062018}, {-0.310480, -0.082325}, { 0.014652, 0.083127}, + {-0.136512, 0.033116}, {-0.073755, -0.025236}, { 0.110766, 0.095954}, + { 0.002878, 0.011838}, {-0.074977, -0.244586}, {-0.047023, -0.081339}, + {-0.183249, 0.029525}, { 0.263435, 0.206934}, {-0.156721, -0.229993}, + {-0.112224, -0.208941}, {-0.116534, -0.123191}, {-0.073988, -0.111668}, + { 0.029484, -0.137573}, {-0.009802, -0.161685}, {-0.023273, 0.114043}, + {-0.332651, 0.049072}, {-0.394009, 0.018608}, {-0.433543, -0.035318}, + {-0.368459, -0.108024}, {-0.350215, -0.037617}, {-0.321140, -0.178537}, + { 0.020307, -0.048487}, {-0.210512, -0.232274}, {-0.082140, -0.065443}, + { 0.081961, -0.009340}, { 0.146794, 0.101973}, { 0.213999, 0.124687}, + { 0.100217, -0.054095}, {-0.114411, -0.041403}, {-0.097631, 0.037061}, + {-0.099651, -0.157978}, {-0.215790, -0.116550}, {-0.107100, 0.076300}, + { 0.084653, 0.126088}, { 0.246439, 0.091442}, { 0.160077, 0.188536}, + { 0.273900, 0.279190}, { 0.320417, 0.232550}, { 0.132710, -0.018988}, + { 0.018950, -0.091681}, {-0.032073, -0.202906}, { 0.212789, 0.178188}, + { 0.208580, 0.239726}, { 0.049420, 0.099840}, {-0.145695, -0.010619}, + {-0.132525, -0.322660}, { 0.019666, 0.126603}, { 0.260809, 0.147727}, + {-0.232795, -0.001090}, {-0.049826, 0.225987}, {-0.154774, 0.076614}, + { 0.045032, 0.221397}, { 0.321014, 0.161632}, {-0.062379, 0.053586}, + { 0.132252, 0.246675}, { 0.392627, 0.271905}, {-0.264585, 0.102344}, + {-0.327200, 0.121624}, {-0.399642, 0.124445}, {-0.108335, 0.179171}, + { 0.100374, 0.182731}, { 0.203852, 0.049505} +}; + +static const float lsf_cb5[32][2] = { + {-0.047705, 0.008002}, { 0.011332, 0.065028}, {-0.021796, -0.034777}, + {-0.147394, -0.001241}, {-0.001577, 0.020599}, {-0.083827, -0.028975}, + {-0.177707, 0.066046}, {-0.043241, -0.165144}, { 0.053322, 0.096519}, + {-0.097688, 0.106484}, {-0.023392, 0.111234}, {-0.146747, -0.159360}, + { 0.027241, -0.011806}, {-0.043156, 0.057667}, { 0.019516, -0.062116}, + { 0.025990, 0.162533}, { 0.091888, 0.009720}, {-0.098511, 0.036414}, + { 0.013722, -0.116512}, { 0.054833, -0.180975}, { 0.119497, 0.128774}, + { 0.118378, -0.125997}, { 0.065882, -0.030932}, { 0.120581, -0.039964}, + {-0.050561, -0.088577}, { 0.050134, 0.033194}, {-0.129654, -0.075112}, + {-0.225334, -0.040234}, { 0.070629, -0.084455}, { 0.095508, 0.063548}, + { 0.150514, 0.034366}, { 0.186092, -0.069272} +}; + +static const float *lsf_codebooks[] = { + lsf_cb1[0], lsf_cb2[0], lsf_cb3[0], lsf_cb4[0], lsf_cb5[0] +}; + +static const float gain_cb[128][2] = { + {0.035230, 0.161540}, {0.049223, 0.448359}, {0.057443, 0.809043}, + {0.072434, 1.760306}, {0.111491, 0.566418}, {0.112820, 1.098524}, + {0.143493, 0.726856}, {0.144840, 0.347800}, {0.180341, 1.050010}, + {0.188171, 2.197256}, {0.189771, 0.256947}, {0.198260, 0.484678}, + {0.210622, 0.755825}, {0.220694, 0.590788}, {0.237062, 1.322214}, + {0.255175, 0.338710}, {0.298980, 0.919051}, {0.314627, 0.520961}, + {0.337106, 1.469863}, {0.341422, 2.804546}, {0.363257, 0.736222}, + {0.363881, 0.367640}, {0.369850, 1.937934}, {0.370136, 1.075201}, + {0.397152, 0.549410}, {0.426557, 0.876015}, {0.450686, 0.215588}, + {0.468116, 0.671848}, {0.470495, 1.242034}, {0.474180, 1.739845}, + {0.484875, 0.490564}, {0.498917, 0.971238}, {0.530996, 0.785765}, + {0.539768, 2.130689}, {0.546021, 0.589544}, {0.546632, 3.050846}, + {0.552336, 0.389775}, {0.556302, 1.400103}, {0.559688, 1.105421}, + {0.574140, 0.667513}, {0.595547, 0.828943}, {0.597771, 0.496929}, + {0.617079, 1.863075}, {0.619657, 1.221713}, {0.621172, 0.950275}, + {0.628426, 0.630766}, {0.628689, 4.242164}, {0.640899, 1.529846}, + {0.645813, 0.331127}, {0.653056, 0.748168}, {0.662909, 1.077438}, + {0.669505, 2.631114}, {0.681570, 1.839298}, {0.687844, 0.903400}, + {0.688660, 1.270830}, {0.695070, 0.578227}, {0.697926, 0.428440}, + {0.715454, 0.812355}, {0.729981, 1.539357}, {0.737434, 1.106765}, + {0.740241, 2.033374}, {0.740871, 0.568460}, {0.752689, 0.698461}, + {0.756587, 0.893078}, {0.767797, 0.499246}, {0.768516, 3.712434}, + {0.773153, 1.332360}, {0.786125, 1.042996}, {0.788792, 0.238388}, + {0.790861, 2.273229}, {0.795338, 1.582767}, {0.809621, 0.595501}, + {0.821032, 0.756460}, {0.824590, 0.922925}, {0.826019, 1.186793}, + {0.827426, 1.885076}, {0.830080, 6.088666}, {0.837028, 2.819993}, + {0.845561, 1.490623}, {0.848323, 0.410436}, {0.856522, 0.729725}, + {0.862636, 0.966880}, {0.874561, 1.681660}, {0.874751, 1.177630}, + {0.879289, 2.301300}, {0.886671, 0.613068}, {0.896729, 0.781097}, + {0.904777, 3.484111}, {0.906098, 1.330892}, {0.919182, 1.877203}, + {0.919901, 0.569511}, {0.921772, 1.034126}, {0.922439, 0.376000}, + {0.934221, 1.485214}, {0.938842, 0.869135}, {0.939166, 2.378294}, + {0.958933, 1.122722}, {0.959042, 0.694098}, {0.960995, 1.743430}, + {0.970763, 2.884897}, {0.982881, 0.814506}, {0.990141, 1.330022}, + {0.996447, 1.823381}, {1.000013, 0.967498}, {1.000743, 0.480597}, + {1.008020, 5.095226}, {1.013883, 2.105435}, {1.026438, 0.691312}, + {1.027361, 1.558169}, {1.030123, 3.586526}, {1.033916, 1.118036}, + {1.039315, 2.543360}, {1.068596, 0.836380}, {1.081023, 1.318768}, + {1.093150, 2.267843}, {1.095607, 1.712383}, {1.102816, 1.037334}, + {1.103231, 3.536292}, {1.107320, 0.508615}, {1.150000, 7.999000}, + {1.156731, 1.236772}, {1.168428, 2.268084}, {1.184130, 0.775839}, + {1.210609, 1.511840}, {1.220663, 4.365683}, {1.224016, 0.983179}, + {1.252236, 2.778535}, {1.301176, 1.923126} +}; + +static const float pred[4] = { + 0.200, 0.334, 0.504, 0.691 +}; + +#endif /* AVCODEC_SIPRDATA_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/smacker.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/smacker.c index 0d39027b0b..1d85f68907 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/smacker.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/smacker.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/smacker.c + * @file * Smacker decoder */ @@ -514,10 +514,6 @@ static av_cold int decode_init(AVCodecContext *avctx) c->avctx = avctx; - if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) { - return 1; - } - avctx->pix_fmt = PIX_FMT_PAL8; @@ -559,6 +555,7 @@ static av_cold int decode_end(AVCodecContext *avctx) static av_cold int smka_decode_init(AVCodecContext *avctx) { avctx->channel_layout = (avctx->channels==2) ? CH_LAYOUT_STEREO : CH_LAYOUT_MONO; + avctx->sample_fmt = avctx->bits_per_coded_sample == 8 ? SAMPLE_FMT_U8 : SAMPLE_FMT_S16; return 0; } @@ -694,7 +691,7 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVCodec smacker_decoder = { "smackvid", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_SMACKVIDEO, sizeof(SmackVContext), decode_init, @@ -707,7 +704,7 @@ AVCodec smacker_decoder = { AVCodec smackaud_decoder = { "smackaud", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_SMACKAUDIO, 0, smka_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/smc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/smc.c index 0153f0c71b..2e2dffdc86 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/smc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/smc.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/smc.c + * @file * QT SMC Video Decoder by Mike Melanson (melanson@pcisys.net) * For more information about the SMC format, visit: * http://www.pcisys.net/~melanson/codecs/ @@ -366,16 +366,11 @@ static void smc_decode_stream(SmcContext *s) flags_a = xx012456, flags_b = xx89A37B */ /* build the color flags */ - color_flags_a = color_flags_b = 0; color_flags_a = - (s->buf[stream_ptr + 0] << 16) | - ((s->buf[stream_ptr + 1] & 0xF0) << 8) | - ((s->buf[stream_ptr + 2] & 0xF0) << 4) | - ((s->buf[stream_ptr + 2] & 0x0F) << 4) | - ((s->buf[stream_ptr + 3] & 0xF0) >> 4); + ((AV_RB16(s->buf + stream_ptr ) & 0xFFF0) << 8) | + (AV_RB16(s->buf + stream_ptr + 2) >> 4); color_flags_b = - (s->buf[stream_ptr + 4] << 16) | - ((s->buf[stream_ptr + 5] & 0xF0) << 8) | + ((AV_RB16(s->buf + stream_ptr + 4) & 0xFFF0) << 8) | ((s->buf[stream_ptr + 1] & 0x0F) << 8) | ((s->buf[stream_ptr + 3] & 0x0F) << 4) | (s->buf[stream_ptr + 5] & 0x0F); @@ -478,7 +473,7 @@ static av_cold int smc_decode_end(AVCodecContext *avctx) AVCodec smc_decoder = { "smc", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_SMC, sizeof(SmcContext), smc_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/snow.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/snow.c index 7dab31cf30..5ef9e5e811 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/snow.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/snow.c @@ -18,14 +18,17 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/intmath.h" #include "avcodec.h" #include "dsputil.h" +#include "dwt.h" #include "snow.h" #include "rangecoder.h" #include "mathops.h" #include "mpegvideo.h" +#include "h263.h" #undef NDEBUG #include @@ -434,11 +437,11 @@ typedef struct Plane{ }Plane; typedef struct SnowContext{ -// 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) AVCodecContext *avctx; RangeCoder c; DSPContext dsp; + DWTContext dwt; AVFrame new_picture; AVFrame input_picture; ///< new_picture with the internal linesizes AVFrame current_picture; @@ -493,87 +496,6 @@ typedef struct SnowContext{ uint8_t *scratchbuf; }SnowContext; -typedef struct { - IDWTELEM *b0; - IDWTELEM *b1; - IDWTELEM *b2; - IDWTELEM *b3; - int y; -} DWTCompose; - -#define slice_buffer_get_line(slice_buf, line_num) ((slice_buf)->line[line_num] ? (slice_buf)->line[line_num] : slice_buffer_load_line((slice_buf), (line_num))) -//#define slice_buffer_get_line(slice_buf, line_num) (slice_buffer_load_line((slice_buf), (line_num))) - -static void iterative_me(SnowContext *s); - -static void slice_buffer_init(slice_buffer * buf, int line_count, int max_allocated_lines, int line_width, IDWTELEM * base_buffer) -{ - int i; - - buf->base_buffer = base_buffer; - buf->line_count = line_count; - buf->line_width = line_width; - buf->data_count = max_allocated_lines; - buf->line = av_mallocz (sizeof(IDWTELEM *) * line_count); - buf->data_stack = av_malloc (sizeof(IDWTELEM *) * max_allocated_lines); - - for(i = 0; i < max_allocated_lines; i++){ - buf->data_stack[i] = av_malloc (sizeof(IDWTELEM) * line_width); - } - - buf->data_stack_top = max_allocated_lines - 1; -} - -static IDWTELEM * slice_buffer_load_line(slice_buffer * buf, int line) -{ - IDWTELEM * buffer; - - assert(buf->data_stack_top >= 0); -// assert(!buf->line[line]); - if (buf->line[line]) - return buf->line[line]; - - buffer = buf->data_stack[buf->data_stack_top]; - buf->data_stack_top--; - buf->line[line] = buffer; - - return buffer; -} - -static void slice_buffer_release(slice_buffer * buf, int line) -{ - IDWTELEM * buffer; - - assert(line >= 0 && line < buf->line_count); - assert(buf->line[line]); - - buffer = buf->line[line]; - buf->data_stack_top++; - buf->data_stack[buf->data_stack_top] = buffer; - buf->line[line] = NULL; -} - -static void slice_buffer_flush(slice_buffer * buf) -{ - int i; - for(i = 0; i < buf->line_count; i++){ - if (buf->line[i]) - slice_buffer_release(buf, i); - } -} - -static void slice_buffer_destroy(slice_buffer * buf) -{ - int i; - slice_buffer_flush(buf); - - for(i = buf->data_count - 1; i >= 0; i--){ - av_freep(&buf->data_stack[i]); - } - av_freep(&buf->data_stack); - av_freep(&buf->line); -} - #ifdef __sgi // Avoid a name clash on SGI IRIX #undef qexp @@ -581,14 +503,6 @@ static void slice_buffer_destroy(slice_buffer * buf) #define QEXPSHIFT (7-FRAC_BITS+8) //FIXME try to change this to 0 static uint8_t qexp[QROOT]; -static inline int mirror(int v, int m){ - while((unsigned)v > (unsigned)m){ - v=-v; - if(v<0) v+= 2*m; - } - return v; -} - static inline void put_symbol(RangeCoder *c, uint8_t *state, int v, int is_signed){ int i; @@ -710,852 +624,102 @@ static inline int get_symbol2(RangeCoder *c, uint8_t *state, int log2){ return v; } -static av_always_inline void -lift(DWTELEM *dst, DWTELEM *src, DWTELEM *ref, - int dst_step, int src_step, int ref_step, - int width, int mul, int add, int shift, - int highpass, int inverse){ - const int mirror_left= !highpass; - const int mirror_right= (width&1) ^ highpass; - const int w= (width>>1) - 1 + (highpass & width); - int i; - -#define LIFT(src, ref, inv) ((src) + ((inv) ? - (ref) : + (ref))) - if(mirror_left){ - dst[0] = LIFT(src[0], ((mul*2*ref[0]+add)>>shift), inverse); - dst += dst_step; - src += src_step; - } - - for(i=0; i>shift), - inverse); - } - - if(mirror_right){ - dst[w*dst_step] = - LIFT(src[w*src_step], - ((mul*2*ref[w*ref_step]+add)>>shift), - inverse); - } -} - -static av_always_inline void -inv_lift(IDWTELEM *dst, IDWTELEM *src, IDWTELEM *ref, - int dst_step, int src_step, int ref_step, - int width, int mul, int add, int shift, - int highpass, int inverse){ - const int mirror_left= !highpass; - const int mirror_right= (width&1) ^ highpass; - const int w= (width>>1) - 1 + (highpass & width); - int i; - -#define LIFT(src, ref, inv) ((src) + ((inv) ? - (ref) : + (ref))) - if(mirror_left){ - dst[0] = LIFT(src[0], ((mul*2*ref[0]+add)>>shift), inverse); - dst += dst_step; - src += src_step; - } - - for(i=0; i>shift), - inverse); - } - - if(mirror_right){ - dst[w*dst_step] = - LIFT(src[w*src_step], - ((mul*2*ref[w*ref_step]+add)>>shift), - inverse); - } -} - -#ifndef liftS -static av_always_inline void -liftS(DWTELEM *dst, DWTELEM *src, DWTELEM *ref, - int dst_step, int src_step, int ref_step, - int width, int mul, int add, int shift, - int highpass, int inverse){ - const int mirror_left= !highpass; - const int mirror_right= (width&1) ^ highpass; - const int w= (width>>1) - 1 + (highpass & width); - int i; - - assert(shift == 4); -#define LIFTS(src, ref, inv) \ - ((inv) ? \ - (src) + (((ref) + 4*(src))>>shift): \ - -((-16*(src) + (ref) + add/4 + 1 + (5<<25))/(5*4) - (1<<23))) - if(mirror_left){ - dst[0] = LIFTS(src[0], mul*2*ref[0]+add, inverse); - dst += dst_step; - src += src_step; - } - - for(i=0; i>1) - 1 + (highpass & width); - int i; - - assert(shift == 4); -#define LIFTS(src, ref, inv) \ - ((inv) ? \ - (src) + (((ref) + 4*(src))>>shift): \ - -((-16*(src) + (ref) + add/4 + 1 + (5<<25))/(5*4) - (1<<23))) - if(mirror_left){ - dst[0] = LIFTS(src[0], mul*2*ref[0]+add, inverse); - dst += dst_step; - src += src_step; - } - - for(i=0; i>1; - int x; - const int w2= (width+1)>>1; - - for(x=0; x>1; - A4 += (A1 + 1)>>1; - b[0+width2] = A1; - b[0 ] = A4; - for(x=1; x+1>1; - A2 += (A1 + A3 + 2)>>2; - b[x+width2] = A3; - b[x ] = A2; - - A1= temp[x+1+width2]; - A2= temp[x+2 ]; - A1 -= (A2 + A4)>>1; - A4 += (A1 + A3 + 2)>>2; - b[x+1+width2] = A1; - b[x+1 ] = A4; - } - A3= temp[width-1]; - A3 -= A2; - A2 += (A1 + A3 + 2)>>2; - b[width -1] = A3; - b[width2-1] = A2; - } -#else - lift(b+w2, temp+w2, temp, 1, 1, 1, width, -1, 0, 1, 1, 0); - lift(b , temp , b+w2, 1, 1, 1, width, 1, 2, 2, 0, 0); -#endif /* 0 */ -} - -static void vertical_decompose53iH0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){ - int i; - - for(i=0; i>1; - } -} - -static void vertical_decompose53iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){ - int i; - - for(i=0; i>2; - } -} - -static void spatial_decompose53i(DWTELEM *buffer, int width, int height, int stride){ - int y; - DWTELEM *b0= buffer + mirror(-2-1, height-1)*stride; - DWTELEM *b1= buffer + mirror(-2 , height-1)*stride; - - for(y=-2; y>1; - - lift (temp+w2, b +1, b , 1, 2, 2, width, W_AM, W_AO, W_AS, 1, 1); - liftS(temp , b , temp+w2, 1, 2, 1, width, W_BM, W_BO, W_BS, 0, 0); - lift (b +w2, temp+w2, temp , 1, 1, 1, width, W_CM, W_CO, W_CS, 1, 0); - lift (b , temp , b +w2, 1, 1, 1, width, W_DM, W_DO, W_DS, 0, 0); -} - - -static void vertical_decompose97iH0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){ - int i; - - for(i=0; i>W_AS; - } -} - -static void vertical_decompose97iH1(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){ - int i; - - for(i=0; i>W_CS; - } -} - -static void vertical_decompose97iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){ - int i; - - for(i=0; i>W_BS; -#else - b1[i] = (16*4*b1[i] - 4*(b0[i] + b2[i]) + W_BO*5 + (5<<27)) / (5*16) - (1<<23); -#endif - } -} - -static void vertical_decompose97iL1(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){ - int i; - - for(i=0; i>W_DS; - } -} - -static void spatial_decompose97i(DWTELEM *buffer, int width, int height, int stride){ - int y; - DWTELEM *b0= buffer + mirror(-4-1, height-1)*stride; - DWTELEM *b1= buffer + mirror(-4 , height-1)*stride; - DWTELEM *b2= buffer + mirror(-4+1, height-1)*stride; - DWTELEM *b3= buffer + mirror(-4+2, height-1)*stride; - - for(y=-4; y>level, height>>level, stride<>level, height>>level, stride<>1; - const int w2= (width+1)>>1; - int x; - -#if 0 - int A1,A2,A3,A4; - A2= temp[1 ]; - A4= temp[0 ]; - A1= temp[0+width2]; - A1 -= (A2 + A4)>>1; - A4 += (A1 + 1)>>1; - b[0+width2] = A1; - b[0 ] = A4; - for(x=1; x+1>1; - A2 += (A1 + A3 + 2)>>2; - b[x+width2] = A3; - b[x ] = A2; - - A1= temp[x+1+width2]; - A2= temp[x+2 ]; - A1 -= (A2 + A4)>>1; - A4 += (A1 + A3 + 2)>>2; - b[x+1+width2] = A1; - b[x+1 ] = A4; - } - A3= temp[width-1]; - A3 -= A2; - A2 += (A1 + A3 + 2)>>2; - b[width -1] = A3; - b[width2-1] = A2; -#else - inv_lift(temp , b , b+w2, 1, 1, 1, width, 1, 2, 2, 0, 1); - inv_lift(temp+w2, b+w2, temp, 1, 1, 1, width, -1, 0, 1, 1, 1); -#endif /* 0 */ - for(x=0; x>1; - } -} - -static void vertical_compose53iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width){ - int i; - - for(i=0; i>2; - } -} - -static void spatial_compose53i_buffered_init(DWTCompose *cs, slice_buffer * sb, int height, int stride_line){ - cs->b0 = slice_buffer_get_line(sb, mirror(-1-1, height-1) * stride_line); - cs->b1 = slice_buffer_get_line(sb, mirror(-1 , height-1) * stride_line); - cs->y = -1; -} - -static void spatial_compose53i_init(DWTCompose *cs, IDWTELEM *buffer, int height, int stride){ - cs->b0 = buffer + mirror(-1-1, height-1)*stride; - cs->b1 = buffer + mirror(-1 , height-1)*stride; - cs->y = -1; -} - -static void spatial_compose53i_dy_buffered(DWTCompose *cs, slice_buffer * sb, int width, int height, int stride_line){ - int y= cs->y; - - IDWTELEM *b0= cs->b0; - IDWTELEM *b1= cs->b1; - IDWTELEM *b2= slice_buffer_get_line(sb, mirror(y+1, height-1) * stride_line); - IDWTELEM *b3= slice_buffer_get_line(sb, mirror(y+2, height-1) * stride_line); - - if(y+1<(unsigned)height) vertical_compose53iL0(b1, b2, b3, width); - if(y+0<(unsigned)height) vertical_compose53iH0(b0, b1, b2, width); - - if(y-1<(unsigned)height) horizontal_compose53i(b0, width); - if(y+0<(unsigned)height) horizontal_compose53i(b1, width); - - cs->b0 = b2; - cs->b1 = b3; - cs->y += 2; -} - -static void spatial_compose53i_dy(DWTCompose *cs, IDWTELEM *buffer, int width, int height, int stride){ - int y= cs->y; - IDWTELEM *b0= cs->b0; - IDWTELEM *b1= cs->b1; - IDWTELEM *b2= buffer + mirror(y+1, height-1)*stride; - IDWTELEM *b3= buffer + mirror(y+2, height-1)*stride; - - if(y+1<(unsigned)height) vertical_compose53iL0(b1, b2, b3, width); - if(y+0<(unsigned)height) vertical_compose53iH0(b0, b1, b2, width); - - if(y-1<(unsigned)height) horizontal_compose53i(b0, width); - if(y+0<(unsigned)height) horizontal_compose53i(b1, width); - - cs->b0 = b2; - cs->b1 = b3; - cs->y += 2; -} - -static void av_unused spatial_compose53i(IDWTELEM *buffer, int width, int height, int stride){ - DWTCompose cs; - spatial_compose53i_init(&cs, buffer, height, stride); - while(cs.y <= height) - spatial_compose53i_dy(&cs, buffer, width, height, stride); -} - - -void ff_snow_horizontal_compose97i(IDWTELEM *b, int width){ - IDWTELEM temp[width]; - const int w2= (width+1)>>1; - - inv_lift (temp , b , b +w2, 1, 1, 1, width, W_DM, W_DO, W_DS, 0, 1); - inv_lift (temp+w2, b +w2, temp , 1, 1, 1, width, W_CM, W_CO, W_CS, 1, 1); - inv_liftS(b , temp , temp+w2, 2, 1, 1, width, W_BM, W_BO, W_BS, 0, 1); - inv_lift (b+1 , temp+w2, b , 2, 1, 2, width, W_AM, W_AO, W_AS, 1, 0); -} - -static void vertical_compose97iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width){ - int i; - - for(i=0; i>W_AS; - } -} - -static void vertical_compose97iH1(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width){ - int i; - - for(i=0; i>W_CS; - } -} - -static void vertical_compose97iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width){ - int i; - - for(i=0; i>W_BS; -#else - b1[i] += (W_BM*(b0[i] + b2[i])+4*b1[i]+W_BO)>>W_BS; -#endif - } -} - -static void vertical_compose97iL1(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width){ - int i; - - for(i=0; i>W_DS; - } -} - -void ff_snow_vertical_compose97i(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width){ - int i; - - for(i=0; i>W_DS; - b3[i] -= (W_CM*(b2[i] + b4[i])+W_CO)>>W_CS; -#ifdef liftS - b2[i] += (W_BM*(b1[i] + b3[i])+W_BO)>>W_BS; -#else - b2[i] += (W_BM*(b1[i] + b3[i])+4*b2[i]+W_BO)>>W_BS; -#endif - b1[i] += (W_AM*(b0[i] + b2[i])+W_AO)>>W_AS; - } -} - -static void spatial_compose97i_buffered_init(DWTCompose *cs, slice_buffer * sb, int height, int stride_line){ - cs->b0 = slice_buffer_get_line(sb, mirror(-3-1, height-1) * stride_line); - cs->b1 = slice_buffer_get_line(sb, mirror(-3 , height-1) * stride_line); - cs->b2 = slice_buffer_get_line(sb, mirror(-3+1, height-1) * stride_line); - cs->b3 = slice_buffer_get_line(sb, mirror(-3+2, height-1) * stride_line); - cs->y = -3; -} - -static void spatial_compose97i_init(DWTCompose *cs, IDWTELEM *buffer, int height, int stride){ - cs->b0 = buffer + mirror(-3-1, height-1)*stride; - cs->b1 = buffer + mirror(-3 , height-1)*stride; - cs->b2 = buffer + mirror(-3+1, height-1)*stride; - cs->b3 = buffer + mirror(-3+2, height-1)*stride; - cs->y = -3; -} - -static void spatial_compose97i_dy_buffered(DSPContext *dsp, DWTCompose *cs, slice_buffer * sb, int width, int height, int stride_line){ - int y = cs->y; - - IDWTELEM *b0= cs->b0; - IDWTELEM *b1= cs->b1; - IDWTELEM *b2= cs->b2; - IDWTELEM *b3= cs->b3; - IDWTELEM *b4= slice_buffer_get_line(sb, mirror(y + 3, height - 1) * stride_line); - IDWTELEM *b5= slice_buffer_get_line(sb, mirror(y + 4, height - 1) * stride_line); - - if(y>0 && y+4vertical_compose97i(b0, b1, b2, b3, b4, b5, width); - }else{ - if(y+3<(unsigned)height) vertical_compose97iL1(b3, b4, b5, width); - if(y+2<(unsigned)height) vertical_compose97iH1(b2, b3, b4, width); - if(y+1<(unsigned)height) vertical_compose97iL0(b1, b2, b3, width); - if(y+0<(unsigned)height) vertical_compose97iH0(b0, b1, b2, width); - } - - if(y-1<(unsigned)height) dsp->horizontal_compose97i(b0, width); - if(y+0<(unsigned)height) dsp->horizontal_compose97i(b1, width); - - cs->b0=b2; - cs->b1=b3; - cs->b2=b4; - cs->b3=b5; - cs->y += 2; -} - -static void spatial_compose97i_dy(DWTCompose *cs, IDWTELEM *buffer, int width, int height, int stride){ - int y = cs->y; - IDWTELEM *b0= cs->b0; - IDWTELEM *b1= cs->b1; - IDWTELEM *b2= cs->b2; - IDWTELEM *b3= cs->b3; - IDWTELEM *b4= buffer + mirror(y+3, height-1)*stride; - IDWTELEM *b5= buffer + mirror(y+4, height-1)*stride; - - if(y+3<(unsigned)height) vertical_compose97iL1(b3, b4, b5, width); - if(y+2<(unsigned)height) vertical_compose97iH1(b2, b3, b4, width); - if(y+1<(unsigned)height) vertical_compose97iL0(b1, b2, b3, width); - if(y+0<(unsigned)height) vertical_compose97iH0(b0, b1, b2, width); - - if(y-1<(unsigned)height) ff_snow_horizontal_compose97i(b0, width); - if(y+0<(unsigned)height) ff_snow_horizontal_compose97i(b1, width); - - cs->b0=b2; - cs->b1=b3; - cs->b2=b4; - cs->b3=b5; - cs->y += 2; -} - -static void av_unused spatial_compose97i(IDWTELEM *buffer, int width, int height, int stride){ - DWTCompose cs; - spatial_compose97i_init(&cs, buffer, height, stride); - while(cs.y <= height) - spatial_compose97i_dy(&cs, buffer, width, height, stride); -} - -static void ff_spatial_idwt_buffered_init(DWTCompose *cs, slice_buffer * sb, int width, int height, int stride_line, int type, int decomposition_count){ - int level; - for(level=decomposition_count-1; level>=0; level--){ - switch(type){ - case DWT_97: spatial_compose97i_buffered_init(cs+level, sb, height>>level, stride_line<>level, stride_line<=0; level--){ - switch(type){ - case DWT_97: spatial_compose97i_init(cs+level, buffer, height>>level, stride<>level, stride<=0; level--){ - while(cs[level].y <= FFMIN((y>>level)+support, height>>level)){ - switch(type){ - case DWT_97: spatial_compose97i_dy(cs+level, buffer, width>>level, height>>level, stride<>level, height>>level, stride<=0; level--){ - while(cs[level].y <= FFMIN((y>>level)+support, height>>level)){ - switch(type){ - case DWT_97: spatial_compose97i_dy_buffered(dsp, cs+level, slice_buf, width>>level, height>>level, stride_line<>level, height>>level, stride_line<width; - const int h= b->height; - int x, y; - - if(1){ - int run=0; - int runs[w*h]; - int run_index=0; - int max_index; - - for(y=0; y 1){ - if(orientation==1) ll= src[y + (x-2)*stride]; - else ll= src[x - 2 + y*stride]; - }*/ - } - if(parent){ - int px= x>>1; - int py= y>>1; - if(pxparent->width && pyparent->height) - p= parent[px + py*2*stride]; - } - if(!(/*ll|*/l|lt|t|rt|p)){ - if(v){ - runs[run_index++]= run; - run=0; - }else{ - run++; - } - } - } - } - max_index= run_index; - runs[run_index++]= run; - run_index=0; - run= runs[run_index++]; - - put_symbol2(&s->c, b->state[30], max_index, 0); - if(run_index <= max_index) - put_symbol2(&s->c, b->state[1], run, 3); - - for(y=0; yc.bytestream_end - s->c.bytestream < w*40){ - av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); - return -1; - } - for(x=0; x 1){ - if(orientation==1) ll= src[y + (x-2)*stride]; - else ll= src[x - 2 + y*stride]; - }*/ - } - if(parent){ - int px= x>>1; - int py= y>>1; - if(pxparent->width && pyparent->height) - p= parent[px + py*2*stride]; - } - if(/*ll|*/l|lt|t|rt|p){ - int context= av_log2(/*FFABS(ll) + */3*FFABS(l) + FFABS(lt) + 2*FFABS(t) + FFABS(rt) + FFABS(p)); - - put_rac(&s->c, &b->state[0][context], !!v); - }else{ - if(!run){ - run= runs[run_index++]; - - if(run_index <= max_index) - put_symbol2(&s->c, b->state[1], run, 3); - assert(v); - }else{ - run--; - assert(!v); - } - } - if(v){ - int context= av_log2(/*FFABS(ll) + */3*FFABS(l) + FFABS(lt) + 2*FFABS(t) + FFABS(rt) + FFABS(p)); - int l2= 2*FFABS(l) + (l<0); - int t2= 2*FFABS(t) + (t<0); - - put_symbol2(&s->c, b->state[context + 2], FFABS(v)-1, context-4); - put_rac(&s->c, &b->state[0][16 + 1 + 3 + quant3bA[l2&0xFF] + 3*quant3bA[t2&0xFF]], v<0); - } - } - } - } - return 0; -} - -static int encode_subband(SnowContext *s, SubBand *b, IDWTELEM *src, IDWTELEM *parent, int stride, int orientation){ -// encode_subband_qtree(s, b, src, parent, stride, orientation); -// encode_subband_z0run(s, b, src, parent, stride, orientation); - return encode_subband_c0run(s, b, src, parent, stride, orientation); -// encode_subband_dzr(s, b, src, parent, stride, orientation); -} - static inline void unpack_coeffs(SnowContext *s, SubBand *b, SubBand * parent, int orientation){ const int w= b->width; const int h= b->height; int x,y; - if(1){ - int run, runs; - x_and_coeff *xc= b->x_coeff; - x_and_coeff *prev_xc= NULL; - x_and_coeff *prev2_xc= xc; - x_and_coeff *parent_xc= parent ? parent->x_coeff : NULL; - x_and_coeff *prev_parent_xc= parent_xc; + int run, runs; + x_and_coeff *xc= b->x_coeff; + x_and_coeff *prev_xc= NULL; + x_and_coeff *prev2_xc= xc; + x_and_coeff *parent_xc= parent ? parent->x_coeff : NULL; + x_and_coeff *prev_parent_xc= parent_xc; - runs= get_symbol2(&s->c, b->state[30], 0); - if(runs-- > 0) run= get_symbol2(&s->c, b->state[1], 3); - else run= INT_MAX; + runs= get_symbol2(&s->c, b->state[30], 0); + if(runs-- > 0) run= get_symbol2(&s->c, b->state[1], 3); + else run= INT_MAX; - for(y=0; yx == 0){ - rt= prev_xc->coeff; + if(y && prev_xc->x == 0){ + rt= prev_xc->coeff; + } + for(x=0; xx <= x) + prev_xc++; + if(prev_xc->x == x + 1) + rt= prev_xc->coeff; + else + rt=0; } - for(x=0; xx <= x) - prev_xc++; - if(prev_xc->x == x + 1) - rt= prev_xc->coeff; - else - rt=0; - } - if(parent_xc){ - if(x>>1 > parent_xc->x){ - parent_xc++; - } - if(x>>1 == parent_xc->x){ - p= parent_xc->coeff; - } - } - if(/*ll|*/l|lt|t|rt|p){ - int context= av_log2(/*FFABS(ll) + */3*(l>>1) + (lt>>1) + (t&~1) + (rt>>1) + (p>>1)); - - v=get_rac(&s->c, &b->state[0][context]); - if(v){ - v= 2*(get_symbol2(&s->c, b->state[context + 2], context-4) + 1); - v+=get_rac(&s->c, &b->state[0][16 + 1 + 3 + quant3bA[l&0xFF] + 3*quant3bA[t&0xFF]]); - - xc->x=x; - (xc++)->coeff= v; - } - }else{ - if(!run){ - if(runs-- > 0) run= get_symbol2(&s->c, b->state[1], 3); - else run= INT_MAX; - v= 2*(get_symbol2(&s->c, b->state[0 + 2], 0-4) + 1); - v+=get_rac(&s->c, &b->state[0][16 + 1 + 3]); - - xc->x=x; - (xc++)->coeff= v; - }else{ - int max_run; - run--; - v=0; - - if(y) max_run= FFMIN(run, prev_xc->x - x - 2); - else max_run= FFMIN(run, w-x-1); - if(parent_xc) - max_run= FFMIN(max_run, 2*parent_xc->x - x - 1); - x+= max_run; - run-= max_run; - } - } - } - (xc++)->x= w+1; //end marker - prev_xc= prev2_xc; - prev2_xc= xc; - if(parent_xc){ - if(y&1){ - while(parent_xc->x != parent->width+1) - parent_xc++; + if(x>>1 > parent_xc->x){ parent_xc++; - prev_parent_xc= parent_xc; + } + if(x>>1 == parent_xc->x){ + p= parent_xc->coeff; + } + } + if(/*ll|*/l|lt|t|rt|p){ + int context= av_log2(/*FFABS(ll) + */3*(l>>1) + (lt>>1) + (t&~1) + (rt>>1) + (p>>1)); + + v=get_rac(&s->c, &b->state[0][context]); + if(v){ + v= 2*(get_symbol2(&s->c, b->state[context + 2], context-4) + 1); + v+=get_rac(&s->c, &b->state[0][16 + 1 + 3 + quant3bA[l&0xFF] + 3*quant3bA[t&0xFF]]); + + xc->x=x; + (xc++)->coeff= v; + } + }else{ + if(!run){ + if(runs-- > 0) run= get_symbol2(&s->c, b->state[1], 3); + else run= INT_MAX; + v= 2*(get_symbol2(&s->c, b->state[0 + 2], 0-4) + 1); + v+=get_rac(&s->c, &b->state[0][16 + 1 + 3]); + + xc->x=x; + (xc++)->coeff= v; }else{ - parent_xc= prev_parent_xc; + int max_run; + run--; + v=0; + + if(y) max_run= FFMIN(run, prev_xc->x - x - 2); + else max_run= FFMIN(run, w-x-1); + if(parent_xc) + max_run= FFMIN(max_run, 2*parent_xc->x - x - 1); + x+= max_run; + run-= max_run; } } } - (xc++)->x= w+1; //end marker + prev_xc= prev2_xc; + prev2_xc= xc; + + if(parent_xc){ + if(y&1){ + while(parent_xc->x != parent->width+1) + parent_xc++; + parent_xc++; + prev_parent_xc= parent_xc; + }else{ + parent_xc= prev_parent_xc; + } + } } + + (xc++)->x= w+1; //end marker } static inline void decode_subband_slice_buffered(SnowContext *s, SubBand *b, slice_buffer * sb, int start_y, int h, int save_state[1]){ @@ -1633,39 +797,6 @@ static inline void copy_rac_state(RangeCoder *d, RangeCoder *s){ d->bytestream_start= bytestream_start; } -//near copy & paste from dsputil, FIXME -static int pix_sum(uint8_t * pix, int line_size, int w) -{ - int s, i, j; - - s = 0; - for (i = 0; i < w; i++) { - for (j = 0; j < w; j++) { - s += pix[0]; - pix ++; - } - pix += line_size - w; - } - return s; -} - -//near copy & paste from dsputil, FIXME -static int pix_norm1(uint8_t * pix, int line_size, int w) -{ - int s, i, j; - uint32_t *sq = ff_squareTbl + 256; - - s = 0; - for (i = 0; i < w; i++) { - for (j = 0; j < w; j ++) { - s += sq[pix[0]]; - pix ++; - } - pix += line_size - w; - } - return s; -} - static inline void set_blocks(SnowContext *s, int level, int x, int y, int l, int cb, int cr, int mx, int my, int ref, int type){ const int w= s->b_width << s->block_max_depth; const int rem_depth= s->block_max_depth - level; @@ -1720,238 +851,6 @@ static inline void pred_mv(SnowContext *s, int *mx, int *my, int ref, } } -//FIXME copy&paste -#define P_LEFT P[1] -#define P_TOP P[2] -#define P_TOPRIGHT P[3] -#define P_MEDIAN P[4] -#define P_MV1 P[9] -#define FLAG_QPEL 1 //must be 1 - -static int encode_q_branch(SnowContext *s, int level, int x, int y){ - uint8_t p_buffer[1024]; - uint8_t i_buffer[1024]; - uint8_t p_state[sizeof(s->block_state)]; - uint8_t i_state[sizeof(s->block_state)]; - RangeCoder pc, ic; - uint8_t *pbbak= s->c.bytestream; - uint8_t *pbbak_start= s->c.bytestream_start; - int score, score2, iscore, i_len, p_len, block_s, sum, base_bits; - const int w= s->b_width << s->block_max_depth; - const int h= s->b_height << s->block_max_depth; - const int rem_depth= s->block_max_depth - level; - const int index= (x + y*w) << rem_depth; - const int block_w= 1<<(LOG2_MB_SIZE - level); - int trx= (x+1)<block[index-1] : &null_block; - const BlockNode *top = y ? &s->block[index-w] : &null_block; - const BlockNode *right = trxblock[index+1] : &null_block; - const BlockNode *bottom= tryblock[index+w] : &null_block; - const BlockNode *tl = y && x ? &s->block[index-w-1] : left; - const BlockNode *tr = y && trxblock[index-w+(1<color[0]; - int pcb= left->color[1]; - int pcr= left->color[2]; - int pmx, pmy; - int mx=0, my=0; - int l,cr,cb; - const int stride= s->current_picture.linesize[0]; - const int uvstride= s->current_picture.linesize[1]; - uint8_t *current_data[3]= { s->input_picture.data[0] + (x + y* stride)*block_w, - s->input_picture.data[1] + (x + y*uvstride)*block_w/2, - s->input_picture.data[2] + (x + y*uvstride)*block_w/2}; - int P[10][2]; - int16_t last_mv[3][2]; - int qpel= !!(s->avctx->flags & CODEC_FLAG_QPEL); //unused - const int shift= 1+qpel; - MotionEstContext *c= &s->m.me; - int ref_context= av_log2(2*left->ref) + av_log2(2*top->ref); - int mx_context= av_log2(2*FFABS(left->mx - top->mx)); - int my_context= av_log2(2*FFABS(left->my - top->my)); - int s_context= 2*left->level + 2*top->level + tl->level + tr->level; - int ref, best_ref, ref_score, ref_mx, ref_my; - - assert(sizeof(s->block_state) >= 256); - if(s->keyframe){ - set_blocks(s, level, x, y, pl, pcb, pcr, 0, 0, 0, BLOCK_INTRA); - return 0; - } - -// clip predictors / edge ? - - P_LEFT[0]= left->mx; - P_LEFT[1]= left->my; - P_TOP [0]= top->mx; - P_TOP [1]= top->my; - P_TOPRIGHT[0]= tr->mx; - P_TOPRIGHT[1]= tr->my; - - last_mv[0][0]= s->block[index].mx; - last_mv[0][1]= s->block[index].my; - last_mv[1][0]= right->mx; - last_mv[1][1]= right->my; - last_mv[2][0]= bottom->mx; - last_mv[2][1]= bottom->my; - - s->m.mb_stride=2; - s->m.mb_x= - s->m.mb_y= 0; - c->skip= 0; - - assert(c-> stride == stride); - assert(c->uvstride == uvstride); - - c->penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_cmp); - c->sub_penalty_factor= get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_sub_cmp); - c->mb_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->mb_cmp); - c->current_mv_penalty= c->mv_penalty[s->m.f_code=1] + MAX_MV; - - c->xmin = - x*block_w - 16+3; - c->ymin = - y*block_w - 16+3; - c->xmax = - (x+1)*block_w + (w<<(LOG2_MB_SIZE - s->block_max_depth)) + 16-3; - c->ymax = - (y+1)*block_w + (h<<(LOG2_MB_SIZE - s->block_max_depth)) + 16-3; - - if(P_LEFT[0] > (c->xmax<xmax< (c->ymax<ymax< (c->xmax<xmax< (c->ymax<ymax<xmin<xmin< (c->xmax<xmax< (c->ymax<ymax<pred_x= P_LEFT[0]; - c->pred_y= P_LEFT[1]; - } else { - c->pred_x = P_MEDIAN[0]; - c->pred_y = P_MEDIAN[1]; - } - - score= INT_MAX; - best_ref= 0; - for(ref=0; refref_frames; ref++){ - init_ref(c, current_data, s->last_picture[ref].data, NULL, block_w*x, block_w*y, 0); - - ref_score= ff_epzs_motion_search(&s->m, &ref_mx, &ref_my, P, 0, /*ref_index*/ 0, last_mv, - (1<<16)>>shift, level-LOG2_MB_SIZE+4, block_w); - - assert(ref_mx >= c->xmin); - assert(ref_mx <= c->xmax); - assert(ref_my >= c->ymin); - assert(ref_my <= c->ymax); - - ref_score= c->sub_motion_search(&s->m, &ref_mx, &ref_my, ref_score, 0, 0, level-LOG2_MB_SIZE+4, block_w); - ref_score= ff_get_mb_score(&s->m, ref_mx, ref_my, 0, 0, level-LOG2_MB_SIZE+4, block_w, 0); - ref_score+= 2*av_log2(2*ref)*c->penalty_factor; - if(s->ref_mvs[ref]){ - s->ref_mvs[ref][index][0]= ref_mx; - s->ref_mvs[ref][index][1]= ref_my; - s->ref_scores[ref][index]= ref_score; - } - if(score > ref_score){ - score= ref_score; - best_ref= ref; - mx= ref_mx; - my= ref_my; - } - } - //FIXME if mb_cmp != SSE then intra cannot be compared currently and mb_penalty vs. lambda2 - - // subpel search - base_bits= get_rac_count(&s->c) - 8*(s->c.bytestream - s->c.bytestream_start); - pc= s->c; - pc.bytestream_start= - pc.bytestream= p_buffer; //FIXME end/start? and at the other stoo - memcpy(p_state, s->block_state, sizeof(s->block_state)); - - if(level!=s->block_max_depth) - put_rac(&pc, &p_state[4 + s_context], 1); - put_rac(&pc, &p_state[1 + left->type + top->type], 0); - if(s->ref_frames > 1) - put_symbol(&pc, &p_state[128 + 1024 + 32*ref_context], best_ref, 0); - pred_mv(s, &pmx, &pmy, best_ref, left, top, tr); - put_symbol(&pc, &p_state[128 + 32*(mx_context + 16*!!best_ref)], mx - pmx, 1); - put_symbol(&pc, &p_state[128 + 32*(my_context + 16*!!best_ref)], my - pmy, 1); - p_len= pc.bytestream - pc.bytestream_start; - score += (s->lambda2*(get_rac_count(&pc)-base_bits))>>FF_LAMBDA_SHIFT; - - block_s= block_w*block_w; - sum = pix_sum(current_data[0], stride, block_w); - l= (sum + block_s/2)/block_s; - iscore = pix_norm1(current_data[0], stride, block_w) - 2*l*sum + l*l*block_s; - - block_s= block_w*block_w>>2; - sum = pix_sum(current_data[1], uvstride, block_w>>1); - cb= (sum + block_s/2)/block_s; -// iscore += pix_norm1(¤t_mb[1][0], uvstride, block_w>>1) - 2*cb*sum + cb*cb*block_s; - sum = pix_sum(current_data[2], uvstride, block_w>>1); - cr= (sum + block_s/2)/block_s; -// iscore += pix_norm1(¤t_mb[2][0], uvstride, block_w>>1) - 2*cr*sum + cr*cr*block_s; - - ic= s->c; - ic.bytestream_start= - ic.bytestream= i_buffer; //FIXME end/start? and at the other stoo - memcpy(i_state, s->block_state, sizeof(s->block_state)); - if(level!=s->block_max_depth) - put_rac(&ic, &i_state[4 + s_context], 1); - put_rac(&ic, &i_state[1 + left->type + top->type], 1); - put_symbol(&ic, &i_state[32], l-pl , 1); - put_symbol(&ic, &i_state[64], cb-pcb, 1); - put_symbol(&ic, &i_state[96], cr-pcr, 1); - i_len= ic.bytestream - ic.bytestream_start; - iscore += (s->lambda2*(get_rac_count(&ic)-base_bits))>>FF_LAMBDA_SHIFT; - -// assert(score==256*256*256*64-1); - assert(iscore < 255*255*256 + s->lambda2*10); - assert(iscore >= 0); - assert(l>=0 && l<=255); - assert(pl>=0 && pl<=255); - - if(level==0){ - int varc= iscore >> 8; - int vard= score >> 8; - if (vard <= 64 || vard < varc) - c->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc); - else - c->scene_change_score+= s->m.qscale; - } - - if(level!=s->block_max_depth){ - put_rac(&s->c, &s->block_state[4 + s_context], 0); - score2 = encode_q_branch(s, level+1, 2*x+0, 2*y+0); - score2+= encode_q_branch(s, level+1, 2*x+1, 2*y+0); - score2+= encode_q_branch(s, level+1, 2*x+0, 2*y+1); - score2+= encode_q_branch(s, level+1, 2*x+1, 2*y+1); - score2+= s->lambda2>>FF_LAMBDA_SHIFT; //FIXME exact split overhead - - if(score2 < score && score2 < iscore) - return score2; - } - - if(iscore < score){ - pred_mv(s, &pmx, &pmy, 0, left, top, tr); - memcpy(pbbak, i_buffer, i_len); - s->c= ic; - s->c.bytestream_start= pbbak_start; - s->c.bytestream= pbbak + i_len; - set_blocks(s, level, x, y, l, cb, cr, pmx, pmy, 0, BLOCK_INTRA); - memcpy(s->block_state, i_state, sizeof(s->block_state)); - return iscore; - }else{ - memcpy(pbbak, p_buffer, p_len); - s->c= pc; - s->c.bytestream_start= pbbak_start; - s->c.bytestream= pbbak + p_len; - set_blocks(s, level, x, y, pl, pcb, pcr, mx, my, best_ref, 0); - memcpy(s->block_state, p_state, sizeof(s->block_state)); - return score; - } -} - static av_always_inline int same_block(BlockNode *a, BlockNode *b){ if((a->type&BLOCK_INTRA) && (b->type&BLOCK_INTRA)){ return !((a->color[0] - b->color[0]) | (a->color[1] - b->color[1]) | (a->color[2] - b->color[2])); @@ -1960,60 +859,6 @@ static av_always_inline int same_block(BlockNode *a, BlockNode *b){ } } -static void encode_q_branch2(SnowContext *s, int level, int x, int y){ - const int w= s->b_width << s->block_max_depth; - const int rem_depth= s->block_max_depth - level; - const int index= (x + y*w) << rem_depth; - int trx= (x+1)<block[index]; - const BlockNode *left = x ? &s->block[index-1] : &null_block; - const BlockNode *top = y ? &s->block[index-w] : &null_block; - const BlockNode *tl = y && x ? &s->block[index-w-1] : left; - const BlockNode *tr = y && trxblock[index-w+(1<color[0]; - int pcb= left->color[1]; - int pcr= left->color[2]; - int pmx, pmy; - int ref_context= av_log2(2*left->ref) + av_log2(2*top->ref); - int mx_context= av_log2(2*FFABS(left->mx - top->mx)) + 16*!!b->ref; - int my_context= av_log2(2*FFABS(left->my - top->my)) + 16*!!b->ref; - int s_context= 2*left->level + 2*top->level + tl->level + tr->level; - - if(s->keyframe){ - set_blocks(s, level, x, y, pl, pcb, pcr, 0, 0, 0, BLOCK_INTRA); - return; - } - - if(level!=s->block_max_depth){ - if(same_block(b,b+1) && same_block(b,b+w) && same_block(b,b+w+1)){ - put_rac(&s->c, &s->block_state[4 + s_context], 1); - }else{ - put_rac(&s->c, &s->block_state[4 + s_context], 0); - encode_q_branch2(s, level+1, 2*x+0, 2*y+0); - encode_q_branch2(s, level+1, 2*x+1, 2*y+0); - encode_q_branch2(s, level+1, 2*x+0, 2*y+1); - encode_q_branch2(s, level+1, 2*x+1, 2*y+1); - return; - } - } - if(b->type & BLOCK_INTRA){ - pred_mv(s, &pmx, &pmy, 0, left, top, tr); - put_rac(&s->c, &s->block_state[1 + (left->type&1) + (top->type&1)], 1); - put_symbol(&s->c, &s->block_state[32], b->color[0]-pl , 1); - put_symbol(&s->c, &s->block_state[64], b->color[1]-pcb, 1); - put_symbol(&s->c, &s->block_state[96], b->color[2]-pcr, 1); - set_blocks(s, level, x, y, b->color[0], b->color[1], b->color[2], pmx, pmy, 0, BLOCK_INTRA); - }else{ - pred_mv(s, &pmx, &pmy, b->ref, left, top, tr); - put_rac(&s->c, &s->block_state[1 + (left->type&1) + (top->type&1)], 0); - if(s->ref_frames > 1) - put_symbol(&s->c, &s->block_state[128 + 1024 + 32*ref_context], b->ref, 0); - put_symbol(&s->c, &s->block_state[128 + 32*mx_context], b->mx - pmx, 1); - put_symbol(&s->c, &s->block_state[128 + 32*my_context], b->my - pmy, 1); - set_blocks(s, level, x, y, pl, pcb, pcr, b->mx, b->my, b->ref, 0); - } -} - static void decode_q_branch(SnowContext *s, int level, int x, int y){ const int w= s->b_width << s->block_max_depth; const int rem_depth= s->block_max_depth - level; @@ -2063,28 +908,6 @@ static void decode_q_branch(SnowContext *s, int level, int x, int y){ } } -static void encode_blocks(SnowContext *s, int search){ - int x, y; - int w= s->b_width; - int h= s->b_height; - - if(s->avctx->me_method == ME_ITER && !s->keyframe && search) - iterative_me(s); - - for(y=0; yc.bytestream_end - s->c.bytestream < w*MB_SIZE*MB_SIZE*3){ //FIXME nicer limit - av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); - return; - } - for(x=0; xavctx->me_method == ME_ITER || !search) - encode_q_branch2(s, 0, x, y); - else - encode_q_branch (s, 0, x, y); - } - } -} - static void decode_blocks(SnowContext *s){ int x, y; int w= s->b_width; @@ -2536,7 +1359,7 @@ static av_always_inline void add_yblock(SnowContext *s, int sliced, slice_buffer } #else if(sliced){ - s->dsp.inner_add_yblock(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8); + s->dwt.inner_add_yblock(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8); }else{ for(y=0; ywidth; + const int qlog= av_clip(s->qlog + b->qlog, 0, QROOT*16); + const int qmul= qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT); + const int qadd= (s->qbias*qmul)>>QBIAS_SHIFT; + int x,y; + + if(s->qlog == LOSSLESS_QLOG) return; + + for(y=start_y; ystride_line) + b->buf_y_offset) + b->buf_x_offset; + for(x=0; x>(QEXPSHIFT)); //FIXME try different bias + }else if(i>0){ + line[x]= (( i*qmul + qadd)>>(QEXPSHIFT)); + } + } + } +} + +static void correlate_slice_buffered(SnowContext *s, slice_buffer * sb, SubBand *b, IDWTELEM *src, int stride, int inverse, int use_median, int start_y, int end_y){ + const int w= b->width; + int x,y; + + IDWTELEM * line=0; // silence silly "could be used without having been initialized" warning + IDWTELEM * prev; + + if (start_y != 0) + line = slice_buffer_get_line(sb, ((start_y - 1) * b->stride_line) + b->buf_y_offset) + b->buf_x_offset; + + for(y=start_y; ystride_line) + b->buf_y_offset) + b->buf_x_offset; + for(x=0; xspatial_decomposition_count; level++){ + for(orientation=level ? 1:0; orientation<4; orientation++){ + int q; + if (plane_index==2) q= s->plane[1].band[level][orientation].qlog; + else if(orientation==2) q= s->plane[plane_index].band[level][1].qlog; + else q= get_symbol(&s->c, s->header_state, 1); + s->plane[plane_index].band[level][orientation].qlog= q; + } + } + } +} + +#define GET_S(dst, check) \ + tmp= get_symbol(&s->c, s->header_state, 0);\ + if(!(check)){\ + av_log(s->avctx, AV_LOG_ERROR, "Error " #dst " is %d\n", tmp);\ + return -1;\ + }\ + dst= tmp; + +static int decode_header(SnowContext *s){ + int plane_index, tmp; + uint8_t kstate[32]; + + memset(kstate, MID_STATE, sizeof(kstate)); + + s->keyframe= get_rac(&s->c, kstate); + if(s->keyframe || s->always_reset){ + reset_contexts(s); + s->spatial_decomposition_type= + s->qlog= + s->qbias= + s->mv_scale= + s->block_max_depth= 0; + } + if(s->keyframe){ + GET_S(s->version, tmp <= 0U) + s->always_reset= get_rac(&s->c, s->header_state); + s->temporal_decomposition_type= get_symbol(&s->c, s->header_state, 0); + s->temporal_decomposition_count= get_symbol(&s->c, s->header_state, 0); + GET_S(s->spatial_decomposition_count, 0 < tmp && tmp <= MAX_DECOMPOSITIONS) + s->colorspace_type= get_symbol(&s->c, s->header_state, 0); + s->chroma_h_shift= get_symbol(&s->c, s->header_state, 0); + s->chroma_v_shift= get_symbol(&s->c, s->header_state, 0); + s->spatial_scalability= get_rac(&s->c, s->header_state); +// s->rate_scalability= get_rac(&s->c, s->header_state); + GET_S(s->max_ref_frames, tmp < (unsigned)MAX_REF_FRAMES) + s->max_ref_frames++; + + decode_qlogs(s); + } + + if(!s->keyframe){ + if(get_rac(&s->c, s->header_state)){ + for(plane_index=0; plane_index<2; plane_index++){ + int htaps, i, sum=0; + Plane *p= &s->plane[plane_index]; + p->diag_mc= get_rac(&s->c, s->header_state); + htaps= get_symbol(&s->c, s->header_state, 0)*2 + 2; + if((unsigned)htaps > HTAPS_MAX || htaps==0) + return -1; + p->htaps= htaps; + for(i= htaps/2; i; i--){ + p->hcoeff[i]= get_symbol(&s->c, s->header_state, 0) * (1-2*(i&1)); + sum += p->hcoeff[i]; + } + p->hcoeff[0]= 32-sum; + } + s->plane[2].diag_mc= s->plane[1].diag_mc; + s->plane[2].htaps = s->plane[1].htaps; + memcpy(s->plane[2].hcoeff, s->plane[1].hcoeff, sizeof(s->plane[1].hcoeff)); + } + if(get_rac(&s->c, s->header_state)){ + GET_S(s->spatial_decomposition_count, 0 < tmp && tmp <= MAX_DECOMPOSITIONS) + decode_qlogs(s); + } + } + + s->spatial_decomposition_type+= get_symbol(&s->c, s->header_state, 1); + if(s->spatial_decomposition_type > 1U){ + av_log(s->avctx, AV_LOG_ERROR, "spatial_decomposition_type %d not supported", s->spatial_decomposition_type); + return -1; + } + if(FFMIN(s->avctx-> width>>s->chroma_h_shift, + s->avctx->height>>s->chroma_v_shift) >> (s->spatial_decomposition_count-1) <= 0){ + av_log(s->avctx, AV_LOG_ERROR, "spatial_decomposition_count %d too large for size", s->spatial_decomposition_count); + return -1; + } + + s->qlog += get_symbol(&s->c, s->header_state, 1); + s->mv_scale += get_symbol(&s->c, s->header_state, 1); + s->qbias += get_symbol(&s->c, s->header_state, 1); + s->block_max_depth+= get_symbol(&s->c, s->header_state, 1); + if(s->block_max_depth > 1 || s->block_max_depth < 0){ + av_log(s->avctx, AV_LOG_ERROR, "block_max_depth= %d is too large", s->block_max_depth); + s->block_max_depth= 0; + return -1; + } + + return 0; +} + +static void init_qexp(void){ + int i; + double v=128; + + for(i=0; ipriv_data; + int width, height; + int i, j; + + s->avctx= avctx; + s->max_ref_frames=1; //just make sure its not an invalid value in case of no initial keyframe + + dsputil_init(&s->dsp, avctx); + ff_dwt_init(&s->dwt); + +#define mcf(dx,dy)\ + s->dsp.put_qpel_pixels_tab [0][dy+dx/4]=\ + s->dsp.put_no_rnd_qpel_pixels_tab[0][dy+dx/4]=\ + s->dsp.put_h264_qpel_pixels_tab[0][dy+dx/4];\ + s->dsp.put_qpel_pixels_tab [1][dy+dx/4]=\ + s->dsp.put_no_rnd_qpel_pixels_tab[1][dy+dx/4]=\ + s->dsp.put_h264_qpel_pixels_tab[1][dy+dx/4]; + + mcf( 0, 0) + mcf( 4, 0) + mcf( 8, 0) + mcf(12, 0) + mcf( 0, 4) + mcf( 4, 4) + mcf( 8, 4) + mcf(12, 4) + mcf( 0, 8) + mcf( 4, 8) + mcf( 8, 8) + mcf(12, 8) + mcf( 0,12) + mcf( 4,12) + mcf( 8,12) + mcf(12,12) + +#define mcfh(dx,dy)\ + s->dsp.put_pixels_tab [0][dy/4+dx/8]=\ + s->dsp.put_no_rnd_pixels_tab[0][dy/4+dx/8]=\ + mc_block_hpel ## dx ## dy ## 16;\ + s->dsp.put_pixels_tab [1][dy/4+dx/8]=\ + s->dsp.put_no_rnd_pixels_tab[1][dy/4+dx/8]=\ + mc_block_hpel ## dx ## dy ## 8; + + mcfh(0, 0) + mcfh(8, 0) + mcfh(0, 8) + mcfh(8, 8) + + if(!qexp[0]) + init_qexp(); + +// dec += FFMAX(s->chroma_h_shift, s->chroma_v_shift); + + width= s->avctx->width; + height= s->avctx->height; + + s->spatial_idwt_buffer= av_mallocz(width*height*sizeof(IDWTELEM)); + s->spatial_dwt_buffer= av_mallocz(width*height*sizeof(DWTELEM)); //FIXME this does not belong here + + for(i=0; iavctx->get_buffer(s->avctx, &s->mconly_picture); + s->scratchbuf = av_malloc(s->mconly_picture.linesize[0]*7*MB_SIZE); + + return 0; +} + +static int common_init_after_header(AVCodecContext *avctx){ + SnowContext *s = avctx->priv_data; + int plane_index, level, orientation; + + for(plane_index=0; plane_index<3; plane_index++){ + int w= s->avctx->width; + int h= s->avctx->height; + + if(plane_index){ + w>>= s->chroma_h_shift; + h>>= s->chroma_v_shift; + } + s->plane[plane_index].width = w; + s->plane[plane_index].height= h; + + for(level=s->spatial_decomposition_count-1; level>=0; level--){ + for(orientation=level ? 1 : 0; orientation<4; orientation++){ + SubBand *b= &s->plane[plane_index].band[level][orientation]; + + b->buf= s->spatial_dwt_buffer; + b->level= level; + b->stride= s->plane[plane_index].width << (s->spatial_decomposition_count - level); + b->width = (w + !(orientation&1))>>1; + b->height= (h + !(orientation>1))>>1; + + b->stride_line = 1 << (s->spatial_decomposition_count - level); + b->buf_x_offset = 0; + b->buf_y_offset = 0; + + if(orientation&1){ + b->buf += (w+1)>>1; + b->buf_x_offset = (w+1)>>1; + } + if(orientation>1){ + b->buf += b->stride>>1; + b->buf_y_offset = b->stride_line >> 1; + } + b->ibuf= s->spatial_idwt_buffer + (b->buf - s->spatial_dwt_buffer); + + if(level) + b->parent= &s->plane[plane_index].band[level-1][orientation]; + //FIXME avoid this realloc + av_freep(&b->x_coeff); + b->x_coeff=av_mallocz(((b->width+1) * b->height+1)*sizeof(x_and_coeff)); + } + w= (w+1)>>1; + h= (h+1)>>1; + } + } + + return 0; +} + +#define QUANTIZE2 0 + +#if QUANTIZE2==1 +#define Q2_STEP 8 + +static void find_sse(SnowContext *s, Plane *p, int *score, int score_stride, IDWTELEM *r0, IDWTELEM *r1, int level, int orientation){ + SubBand *b= &p->band[level][orientation]; + int x, y; + int xo=0; + int yo=0; + int step= 1 << (s->spatial_decomposition_count - level); + + if(orientation&1) + xo= step>>1; + if(orientation&2) + yo= step>>1; + + //FIXME bias for nonzero ? + //FIXME optimize + memset(score, 0, sizeof(*score)*score_stride*((p->height + Q2_STEP-1)/Q2_STEP)); + for(y=0; yheight; y++){ + for(x=0; xwidth; x++){ + int sx= (x-xo + step/2) / step / Q2_STEP; + int sy= (y-yo + step/2) / step / Q2_STEP; + int v= r0[x + y*p->width] - r1[x + y*p->width]; + assert(sx>=0 && sy>=0 && sx < score_stride); + v= ((v+8)>>4)<<4; + score[sx + sy*score_stride] += v*v; + assert(score[sx + sy*score_stride] >= 0); + } + } +} + +static void dequantize_all(SnowContext *s, Plane *p, IDWTELEM *buffer, int width, int height){ + int level, orientation; + + for(level=0; levelspatial_decomposition_count; level++){ + for(orientation=level ? 1 : 0; orientation<4; orientation++){ + SubBand *b= &p->band[level][orientation]; + IDWTELEM *dst= buffer + (b->ibuf - s->spatial_idwt_buffer); + + dequantize(s, b, dst, b->stride); + } + } +} + +static void dwt_quantize(SnowContext *s, Plane *p, DWTELEM *buffer, int width, int height, int stride, int type){ + int level, orientation, ys, xs, x, y, pass; + IDWTELEM best_dequant[height * stride]; + IDWTELEM idwt2_buffer[height * stride]; + const int score_stride= (width + 10)/Q2_STEP; + int best_score[(width + 10)/Q2_STEP * (height + 10)/Q2_STEP]; //FIXME size + int score[(width + 10)/Q2_STEP * (height + 10)/Q2_STEP]; //FIXME size + int threshold= (s->m.lambda * s->m.lambda) >> 6; + + //FIXME pass the copy cleanly ? + +// memcpy(dwt_buffer, buffer, height * stride * sizeof(DWTELEM)); + ff_spatial_dwt(buffer, width, height, stride, type, s->spatial_decomposition_count); + + for(level=0; levelspatial_decomposition_count; level++){ + for(orientation=level ? 1 : 0; orientation<4; orientation++){ + SubBand *b= &p->band[level][orientation]; + IDWTELEM *dst= best_dequant + (b->ibuf - s->spatial_idwt_buffer); + DWTELEM *src= buffer + (b-> buf - s->spatial_dwt_buffer); + assert(src == b->buf); // code does not depend on this but it is true currently + + quantize(s, b, dst, src, b->stride, s->qbias); + } + } + for(pass=0; pass<1; pass++){ + if(s->qbias == 0) //keyframe + continue; + for(level=0; levelspatial_decomposition_count; level++){ + for(orientation=level ? 1 : 0; orientation<4; orientation++){ + SubBand *b= &p->band[level][orientation]; + IDWTELEM *dst= idwt2_buffer + (b->ibuf - s->spatial_idwt_buffer); + IDWTELEM *best_dst= best_dequant + (b->ibuf - s->spatial_idwt_buffer); + + for(ys= 0; ysspatial_decomposition_count); + find_sse(s, p, best_score, score_stride, idwt2_buffer, s->spatial_idwt_buffer, level, orientation); + memcpy(idwt2_buffer, best_dequant, height * stride * sizeof(IDWTELEM)); + for(y=ys; yheight; y+= Q2_STEP){ + for(x=xs; xwidth; x+= Q2_STEP){ + if(dst[x + y*b->stride]<0) dst[x + y*b->stride]++; + if(dst[x + y*b->stride]>0) dst[x + y*b->stride]--; + //FIXME try more than just -- + } + } + dequantize_all(s, p, idwt2_buffer, width, height); + ff_spatial_idwt(idwt2_buffer, width, height, stride, type, s->spatial_decomposition_count); + find_sse(s, p, score, score_stride, idwt2_buffer, s->spatial_idwt_buffer, level, orientation); + for(y=ys; yheight; y+= Q2_STEP){ + for(x=xs; xwidth; x+= Q2_STEP){ + int score_idx= x/Q2_STEP + (y/Q2_STEP)*score_stride; + if(score[score_idx] <= best_score[score_idx] + threshold){ + best_score[score_idx]= score[score_idx]; + if(best_dst[x + y*b->stride]<0) best_dst[x + y*b->stride]++; + if(best_dst[x + y*b->stride]>0) best_dst[x + y*b->stride]--; + //FIXME copy instead + } + } + } + } + } + } + } + } + memcpy(s->spatial_idwt_buffer, best_dequant, height * stride * sizeof(IDWTELEM)); //FIXME work with that directly instead of copy at the end +} + +#endif /* QUANTIZE2==1 */ + +#define USE_HALFPEL_PLANE 0 + +static void halfpel_interpol(SnowContext *s, uint8_t *halfpel[4][4], AVFrame *frame){ + int p,x,y; + + assert(!(s->avctx->flags & CODEC_FLAG_EMU_EDGE)); + + for(p=0; p<3; p++){ + int is_chroma= !!p; + int w= s->avctx->width >>is_chroma; + int h= s->avctx->height >>is_chroma; + int ls= frame->linesize[p]; + uint8_t *src= frame->data[p]; + + halfpel[1][p]= (uint8_t*)av_malloc(ls * (h+2*EDGE_WIDTH)) + EDGE_WIDTH*(1+ls); + halfpel[2][p]= (uint8_t*)av_malloc(ls * (h+2*EDGE_WIDTH)) + EDGE_WIDTH*(1+ls); + halfpel[3][p]= (uint8_t*)av_malloc(ls * (h+2*EDGE_WIDTH)) + EDGE_WIDTH*(1+ls); + + halfpel[0][p]= src; + for(y=0; y>5; + } + } + for(y=0; y>5; + } + } + src= halfpel[1][p]; + for(y=0; y>5; + } + } + +//FIXME border! + } +} + +static void release_buffer(AVCodecContext *avctx){ + SnowContext *s = avctx->priv_data; + int i; + + if(s->last_picture[s->max_ref_frames-1].data[0]){ + avctx->release_buffer(avctx, &s->last_picture[s->max_ref_frames-1]); + for(i=0; i<9; i++) + if(s->halfpel_plane[s->max_ref_frames-1][1+i/3][i%3]) + av_free(s->halfpel_plane[s->max_ref_frames-1][1+i/3][i%3] - EDGE_WIDTH*(1+s->current_picture.linesize[i%3])); + } +} + +static int frame_start(SnowContext *s){ + AVFrame tmp; + int w= s->avctx->width; //FIXME round up to x16 ? + int h= s->avctx->height; + + if(s->current_picture.data[0]){ + s->dsp.draw_edges(s->current_picture.data[0], s->current_picture.linesize[0], w , h , EDGE_WIDTH ); + s->dsp.draw_edges(s->current_picture.data[1], s->current_picture.linesize[1], w>>1, h>>1, EDGE_WIDTH/2); + s->dsp.draw_edges(s->current_picture.data[2], s->current_picture.linesize[2], w>>1, h>>1, EDGE_WIDTH/2); + } + + release_buffer(s->avctx); + + tmp= s->last_picture[s->max_ref_frames-1]; + memmove(s->last_picture+1, s->last_picture, (s->max_ref_frames-1)*sizeof(AVFrame)); + memmove(s->halfpel_plane+1, s->halfpel_plane, (s->max_ref_frames-1)*sizeof(void*)*4*4); + if(USE_HALFPEL_PLANE && s->current_picture.data[0]) + halfpel_interpol(s, s->halfpel_plane[0], &s->current_picture); + s->last_picture[0]= s->current_picture; + s->current_picture= tmp; + + if(s->keyframe){ + s->ref_frames= 0; + }else{ + int i; + for(i=0; imax_ref_frames && s->last_picture[i].data[0]; i++) + if(i && s->last_picture[i-1].key_frame) + break; + s->ref_frames= i; + if(s->ref_frames==0){ + av_log(s->avctx,AV_LOG_ERROR, "No reference frames\n"); + return -1; + } + } + + s->current_picture.reference= 1; + if(s->avctx->get_buffer(s->avctx, &s->current_picture) < 0){ + av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } + + s->current_picture.key_frame= s->keyframe; + + return 0; +} + +static av_cold void common_end(SnowContext *s){ + int plane_index, level, orientation, i; + + av_freep(&s->spatial_dwt_buffer); + av_freep(&s->spatial_idwt_buffer); + + s->m.me.temp= NULL; + av_freep(&s->m.me.scratchpad); + av_freep(&s->m.me.map); + av_freep(&s->m.me.score_map); + av_freep(&s->m.obmc_scratchpad); + + av_freep(&s->block); + av_freep(&s->scratchbuf); + + for(i=0; iref_mvs[i]); + av_freep(&s->ref_scores[i]); + if(s->last_picture[i].data[0]) + s->avctx->release_buffer(s->avctx, &s->last_picture[i]); + } + + for(plane_index=0; plane_index<3; plane_index++){ + for(level=s->spatial_decomposition_count-1; level>=0; level--){ + for(orientation=level ? 1 : 0; orientation<4; orientation++){ + SubBand *b= &s->plane[plane_index].band[level][orientation]; + + av_freep(&b->x_coeff); + } + } + } + if (s->mconly_picture.data[0]) + s->avctx->release_buffer(s->avctx, &s->mconly_picture); + if (s->current_picture.data[0]) + s->avctx->release_buffer(s->avctx, &s->current_picture); +} + +static av_cold int decode_init(AVCodecContext *avctx) +{ + avctx->pix_fmt= PIX_FMT_YUV420P; + + common_init(avctx); + + return 0; +} + +static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt){ + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + SnowContext *s = avctx->priv_data; + RangeCoder * const c= &s->c; + int bytes_read; + AVFrame *picture = data; + int level, orientation, plane_index; + + ff_init_range_decoder(c, buf, buf_size); + ff_build_rac_states(c, 0.05*(1LL<<32), 256-8); + + s->current_picture.pict_type= FF_I_TYPE; //FIXME I vs. P + if(decode_header(s)<0) + return -1; + common_init_after_header(avctx); + + // realloc slice buffer for the case that spatial_decomposition_count changed + ff_slice_buffer_destroy(&s->sb); + ff_slice_buffer_init(&s->sb, s->plane[0].height, (MB_SIZE >> s->block_max_depth) + s->spatial_decomposition_count * 8 + 1, s->plane[0].width, s->spatial_idwt_buffer); + + for(plane_index=0; plane_index<3; plane_index++){ + Plane *p= &s->plane[plane_index]; + p->fast_mc= p->diag_mc && p->htaps==6 && p->hcoeff[0]==40 + && p->hcoeff[1]==-10 + && p->hcoeff[2]==2; + } + + alloc_blocks(s); + + if(frame_start(s) < 0) + return -1; + //keyframe flag duplication mess FIXME + if(avctx->debug&FF_DEBUG_PICT_INFO) + av_log(avctx, AV_LOG_ERROR, "keyframe:%d qlog:%d\n", s->keyframe, s->qlog); + + decode_blocks(s); + + for(plane_index=0; plane_index<3; plane_index++){ + Plane *p= &s->plane[plane_index]; + int w= p->width; + int h= p->height; + int x, y; + int decode_state[MAX_DECOMPOSITIONS][4][1]; /* Stored state info for unpack_coeffs. 1 variable per instance. */ + + if(s->avctx->debug&2048){ + memset(s->spatial_dwt_buffer, 0, sizeof(DWTELEM)*w*h); + predict_plane(s, s->spatial_idwt_buffer, plane_index, 1); + + for(y=0; ycurrent_picture.data[plane_index][y*s->current_picture.linesize[plane_index] + x]; + s->mconly_picture.data[plane_index][y*s->mconly_picture.linesize[plane_index] + x]= v; + } + } + } + + { + for(level=0; levelspatial_decomposition_count; level++){ + for(orientation=level ? 1 : 0; orientation<4; orientation++){ + SubBand *b= &p->band[level][orientation]; + unpack_coeffs(s, b, b->parent, orientation); + } + } + } + + { + const int mb_h= s->b_height << s->block_max_depth; + const int block_size = MB_SIZE >> s->block_max_depth; + const int block_w = plane_index ? block_size/2 : block_size; + int mb_y; + DWTCompose cs[MAX_DECOMPOSITIONS]; + int yd=0, yq=0; + int y; + int end_y; + + ff_spatial_idwt_buffered_init(cs, &s->sb, w, h, 1, s->spatial_decomposition_type, s->spatial_decomposition_count); + for(mb_y=0; mb_y<=mb_h; mb_y++){ + + int slice_starty = block_w*mb_y; + int slice_h = block_w*(mb_y+1); + if (!(s->keyframe || s->avctx->debug&512)){ + slice_starty = FFMAX(0, slice_starty - (block_w >> 1)); + slice_h -= (block_w >> 1); + } + + for(level=0; levelspatial_decomposition_count; level++){ + for(orientation=level ? 1 : 0; orientation<4; orientation++){ + SubBand *b= &p->band[level][orientation]; + int start_y; + int end_y; + int our_mb_start = mb_y; + int our_mb_end = (mb_y + 1); + const int extra= 3; + start_y = (mb_y ? ((block_w * our_mb_start) >> (s->spatial_decomposition_count - level)) + s->spatial_decomposition_count - level + extra: 0); + end_y = (((block_w * our_mb_end) >> (s->spatial_decomposition_count - level)) + s->spatial_decomposition_count - level + extra); + if (!(s->keyframe || s->avctx->debug&512)){ + start_y = FFMAX(0, start_y - (block_w >> (1+s->spatial_decomposition_count - level))); + end_y = FFMAX(0, end_y - (block_w >> (1+s->spatial_decomposition_count - level))); + } + start_y = FFMIN(b->height, start_y); + end_y = FFMIN(b->height, end_y); + + if (start_y != end_y){ + if (orientation == 0){ + SubBand * correlate_band = &p->band[0][0]; + int correlate_end_y = FFMIN(b->height, end_y + 1); + int correlate_start_y = FFMIN(b->height, (start_y ? start_y + 1 : 0)); + decode_subband_slice_buffered(s, correlate_band, &s->sb, correlate_start_y, correlate_end_y, decode_state[0][0]); + correlate_slice_buffered(s, &s->sb, correlate_band, correlate_band->ibuf, correlate_band->stride, 1, 0, correlate_start_y, correlate_end_y); + dequantize_slice_buffered(s, &s->sb, correlate_band, correlate_band->ibuf, correlate_band->stride, start_y, end_y); + } + else + decode_subband_slice_buffered(s, b, &s->sb, start_y, end_y, decode_state[level][orientation]); + } + } + } + + for(; yddwt, cs, &s->sb, w, h, 1, s->spatial_decomposition_type, s->spatial_decomposition_count, yd); + } + + if(s->qlog == LOSSLESS_QLOG){ + for(; yqsb, yq); + for(x=0; xsb, s->spatial_idwt_buffer, plane_index, 1, mb_y); + + y = FFMIN(p->height, slice_starty); + end_y = FFMIN(p->height, slice_h); + while(y < end_y) + ff_slice_buffer_release(&s->sb, y++); + } + + ff_slice_buffer_flush(&s->sb); + } + + } + + emms_c(); + + release_buffer(avctx); + + if(!(s->avctx->debug&2048)) + *picture= s->current_picture; + else + *picture= s->mconly_picture; + + *data_size = sizeof(AVFrame); + + bytes_read= c->bytestream - c->bytestream_start; + if(bytes_read ==0) av_log(s->avctx, AV_LOG_ERROR, "error at end of frame\n"); //FIXME + + return bytes_read; +} + +static av_cold int decode_end(AVCodecContext *avctx) +{ + SnowContext *s = avctx->priv_data; + + ff_slice_buffer_destroy(&s->sb); + + common_end(s); + + return 0; +} + +AVCodec 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, + .long_name = NULL_IF_CONFIG_SMALL("Snow"), +}; + +#if CONFIG_SNOW_ENCODER +static av_cold int encode_init(AVCodecContext *avctx) +{ + SnowContext *s = avctx->priv_data; + int plane_index; + + if(avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){ + av_log(avctx, AV_LOG_ERROR, "This codec is under development, files encoded with it may not be decodable with future versions!!!\n" + "Use vstrict=-2 / -strict -2 to use it anyway.\n"); + return -1; + } + + if(avctx->prediction_method == DWT_97 + && (avctx->flags & CODEC_FLAG_QSCALE) + && avctx->global_quality == 0){ + av_log(avctx, AV_LOG_ERROR, "The 9/7 wavelet is incompatible with lossless mode.\n"); + return -1; + } + + s->spatial_decomposition_type= avctx->prediction_method; //FIXME add decorrelator type r transform_type + + s->mv_scale = (avctx->flags & CODEC_FLAG_QPEL) ? 2 : 4; + s->block_max_depth= (avctx->flags & CODEC_FLAG_4MV ) ? 1 : 0; + + for(plane_index=0; plane_index<3; plane_index++){ + s->plane[plane_index].diag_mc= 1; + s->plane[plane_index].htaps= 6; + s->plane[plane_index].hcoeff[0]= 40; + s->plane[plane_index].hcoeff[1]= -10; + s->plane[plane_index].hcoeff[2]= 2; + s->plane[plane_index].fast_mc= 1; + } + + common_init(avctx); + alloc_blocks(s); + + s->version=0; + + s->m.avctx = avctx; + s->m.flags = avctx->flags; + s->m.bit_rate= avctx->bit_rate; + + s->m.me.temp = + s->m.me.scratchpad= av_mallocz((avctx->width+64)*2*16*2*sizeof(uint8_t)); + s->m.me.map = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t)); + s->m.me.score_map = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t)); + s->m.obmc_scratchpad= av_mallocz(MB_SIZE*MB_SIZE*12*sizeof(uint32_t)); + h263_encode_init(&s->m); //mv_penalty + + s->max_ref_frames = FFMAX(FFMIN(avctx->refs, MAX_REF_FRAMES), 1); + + if(avctx->flags&CODEC_FLAG_PASS1){ + if(!avctx->stats_out) + avctx->stats_out = av_mallocz(256); + } + if((avctx->flags&CODEC_FLAG_PASS2) || !(avctx->flags&CODEC_FLAG_QSCALE)){ + if(ff_rate_control_init(&s->m) < 0) + return -1; + } + s->pass1_rc= !(avctx->flags & (CODEC_FLAG_QSCALE|CODEC_FLAG_PASS2)); + + avctx->coded_frame= &s->current_picture; + switch(avctx->pix_fmt){ +// case PIX_FMT_YUV444P: +// case PIX_FMT_YUV422P: + case PIX_FMT_YUV420P: + case PIX_FMT_GRAY8: +// case PIX_FMT_YUV411P: +// case PIX_FMT_YUV410P: + s->colorspace_type= 0; + break; +/* case PIX_FMT_RGB32: + s->colorspace= 1; + break;*/ + default: + av_log(avctx, AV_LOG_ERROR, "pixel format not supported\n"); + return -1; + } +// avcodec_get_chroma_sub_sample(avctx->pix_fmt, &s->chroma_h_shift, &s->chroma_v_shift); + s->chroma_h_shift= 1; + s->chroma_v_shift= 1; + + ff_set_cmp(&s->dsp, s->dsp.me_cmp, s->avctx->me_cmp); + ff_set_cmp(&s->dsp, s->dsp.me_sub_cmp, s->avctx->me_sub_cmp); + + s->avctx->get_buffer(s->avctx, &s->input_picture); + + if(s->avctx->me_method == ME_ITER){ + int i; + int size= s->b_width * s->b_height << 2*s->block_max_depth; + for(i=0; imax_ref_frames; i++){ + s->ref_mvs[i]= av_mallocz(size*sizeof(int16_t[2])); + s->ref_scores[i]= av_mallocz(size*sizeof(uint32_t)); + } + } + + return 0; +} + +//near copy & paste from dsputil, FIXME +static int pix_sum(uint8_t * pix, int line_size, int w) +{ + int s, i, j; + + s = 0; + for (i = 0; i < w; i++) { + for (j = 0; j < w; j++) { + s += pix[0]; + pix ++; + } + pix += line_size - w; + } + return s; +} + +//near copy & paste from dsputil, FIXME +static int pix_norm1(uint8_t * pix, int line_size, int w) +{ + int s, i, j; + uint32_t *sq = ff_squareTbl + 256; + + s = 0; + for (i = 0; i < w; i++) { + for (j = 0; j < w; j ++) { + s += sq[pix[0]]; + pix ++; + } + pix += line_size - w; + } + return s; +} + +//FIXME copy&paste +#define P_LEFT P[1] +#define P_TOP P[2] +#define P_TOPRIGHT P[3] +#define P_MEDIAN P[4] +#define P_MV1 P[9] +#define FLAG_QPEL 1 //must be 1 + +static int encode_q_branch(SnowContext *s, int level, int x, int y){ + uint8_t p_buffer[1024]; + uint8_t i_buffer[1024]; + uint8_t p_state[sizeof(s->block_state)]; + uint8_t i_state[sizeof(s->block_state)]; + RangeCoder pc, ic; + uint8_t *pbbak= s->c.bytestream; + uint8_t *pbbak_start= s->c.bytestream_start; + int score, score2, iscore, i_len, p_len, block_s, sum, base_bits; + const int w= s->b_width << s->block_max_depth; + const int h= s->b_height << s->block_max_depth; + const int rem_depth= s->block_max_depth - level; + const int index= (x + y*w) << rem_depth; + const int block_w= 1<<(LOG2_MB_SIZE - level); + int trx= (x+1)<block[index-1] : &null_block; + const BlockNode *top = y ? &s->block[index-w] : &null_block; + const BlockNode *right = trxblock[index+1] : &null_block; + const BlockNode *bottom= tryblock[index+w] : &null_block; + const BlockNode *tl = y && x ? &s->block[index-w-1] : left; + const BlockNode *tr = y && trxblock[index-w+(1<color[0]; + int pcb= left->color[1]; + int pcr= left->color[2]; + int pmx, pmy; + int mx=0, my=0; + int l,cr,cb; + const int stride= s->current_picture.linesize[0]; + const int uvstride= s->current_picture.linesize[1]; + uint8_t *current_data[3]= { s->input_picture.data[0] + (x + y* stride)*block_w, + s->input_picture.data[1] + (x + y*uvstride)*block_w/2, + s->input_picture.data[2] + (x + y*uvstride)*block_w/2}; + int P[10][2]; + int16_t last_mv[3][2]; + int qpel= !!(s->avctx->flags & CODEC_FLAG_QPEL); //unused + const int shift= 1+qpel; + MotionEstContext *c= &s->m.me; + int ref_context= av_log2(2*left->ref) + av_log2(2*top->ref); + int mx_context= av_log2(2*FFABS(left->mx - top->mx)); + int my_context= av_log2(2*FFABS(left->my - top->my)); + int s_context= 2*left->level + 2*top->level + tl->level + tr->level; + int ref, best_ref, ref_score, ref_mx, ref_my; + + assert(sizeof(s->block_state) >= 256); + if(s->keyframe){ + set_blocks(s, level, x, y, pl, pcb, pcr, 0, 0, 0, BLOCK_INTRA); + return 0; + } + +// clip predictors / edge ? + + P_LEFT[0]= left->mx; + P_LEFT[1]= left->my; + P_TOP [0]= top->mx; + P_TOP [1]= top->my; + P_TOPRIGHT[0]= tr->mx; + P_TOPRIGHT[1]= tr->my; + + last_mv[0][0]= s->block[index].mx; + last_mv[0][1]= s->block[index].my; + last_mv[1][0]= right->mx; + last_mv[1][1]= right->my; + last_mv[2][0]= bottom->mx; + last_mv[2][1]= bottom->my; + + s->m.mb_stride=2; + s->m.mb_x= + s->m.mb_y= 0; + c->skip= 0; + + assert(c-> stride == stride); + assert(c->uvstride == uvstride); + + c->penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_cmp); + c->sub_penalty_factor= get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_sub_cmp); + c->mb_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->mb_cmp); + c->current_mv_penalty= c->mv_penalty[s->m.f_code=1] + MAX_MV; + + c->xmin = - x*block_w - 16+3; + c->ymin = - y*block_w - 16+3; + c->xmax = - (x+1)*block_w + (w<<(LOG2_MB_SIZE - s->block_max_depth)) + 16-3; + c->ymax = - (y+1)*block_w + (h<<(LOG2_MB_SIZE - s->block_max_depth)) + 16-3; + + if(P_LEFT[0] > (c->xmax<xmax< (c->ymax<ymax< (c->xmax<xmax< (c->ymax<ymax<xmin<xmin< (c->xmax<xmax< (c->ymax<ymax<pred_x= P_LEFT[0]; + c->pred_y= P_LEFT[1]; + } else { + c->pred_x = P_MEDIAN[0]; + c->pred_y = P_MEDIAN[1]; + } + + score= INT_MAX; + best_ref= 0; + for(ref=0; refref_frames; ref++){ + init_ref(c, current_data, s->last_picture[ref].data, NULL, block_w*x, block_w*y, 0); + + ref_score= ff_epzs_motion_search(&s->m, &ref_mx, &ref_my, P, 0, /*ref_index*/ 0, last_mv, + (1<<16)>>shift, level-LOG2_MB_SIZE+4, block_w); + + assert(ref_mx >= c->xmin); + assert(ref_mx <= c->xmax); + assert(ref_my >= c->ymin); + assert(ref_my <= c->ymax); + + ref_score= c->sub_motion_search(&s->m, &ref_mx, &ref_my, ref_score, 0, 0, level-LOG2_MB_SIZE+4, block_w); + ref_score= ff_get_mb_score(&s->m, ref_mx, ref_my, 0, 0, level-LOG2_MB_SIZE+4, block_w, 0); + ref_score+= 2*av_log2(2*ref)*c->penalty_factor; + if(s->ref_mvs[ref]){ + s->ref_mvs[ref][index][0]= ref_mx; + s->ref_mvs[ref][index][1]= ref_my; + s->ref_scores[ref][index]= ref_score; + } + if(score > ref_score){ + score= ref_score; + best_ref= ref; + mx= ref_mx; + my= ref_my; + } + } + //FIXME if mb_cmp != SSE then intra cannot be compared currently and mb_penalty vs. lambda2 + + // subpel search + base_bits= get_rac_count(&s->c) - 8*(s->c.bytestream - s->c.bytestream_start); + pc= s->c; + pc.bytestream_start= + pc.bytestream= p_buffer; //FIXME end/start? and at the other stoo + memcpy(p_state, s->block_state, sizeof(s->block_state)); + + if(level!=s->block_max_depth) + put_rac(&pc, &p_state[4 + s_context], 1); + put_rac(&pc, &p_state[1 + left->type + top->type], 0); + if(s->ref_frames > 1) + put_symbol(&pc, &p_state[128 + 1024 + 32*ref_context], best_ref, 0); + pred_mv(s, &pmx, &pmy, best_ref, left, top, tr); + put_symbol(&pc, &p_state[128 + 32*(mx_context + 16*!!best_ref)], mx - pmx, 1); + put_symbol(&pc, &p_state[128 + 32*(my_context + 16*!!best_ref)], my - pmy, 1); + p_len= pc.bytestream - pc.bytestream_start; + score += (s->lambda2*(get_rac_count(&pc)-base_bits))>>FF_LAMBDA_SHIFT; + + block_s= block_w*block_w; + sum = pix_sum(current_data[0], stride, block_w); + l= (sum + block_s/2)/block_s; + iscore = pix_norm1(current_data[0], stride, block_w) - 2*l*sum + l*l*block_s; + + block_s= block_w*block_w>>2; + sum = pix_sum(current_data[1], uvstride, block_w>>1); + cb= (sum + block_s/2)/block_s; +// iscore += pix_norm1(¤t_mb[1][0], uvstride, block_w>>1) - 2*cb*sum + cb*cb*block_s; + sum = pix_sum(current_data[2], uvstride, block_w>>1); + cr= (sum + block_s/2)/block_s; +// iscore += pix_norm1(¤t_mb[2][0], uvstride, block_w>>1) - 2*cr*sum + cr*cr*block_s; + + ic= s->c; + ic.bytestream_start= + ic.bytestream= i_buffer; //FIXME end/start? and at the other stoo + memcpy(i_state, s->block_state, sizeof(s->block_state)); + if(level!=s->block_max_depth) + put_rac(&ic, &i_state[4 + s_context], 1); + put_rac(&ic, &i_state[1 + left->type + top->type], 1); + put_symbol(&ic, &i_state[32], l-pl , 1); + put_symbol(&ic, &i_state[64], cb-pcb, 1); + put_symbol(&ic, &i_state[96], cr-pcr, 1); + i_len= ic.bytestream - ic.bytestream_start; + iscore += (s->lambda2*(get_rac_count(&ic)-base_bits))>>FF_LAMBDA_SHIFT; + +// assert(score==256*256*256*64-1); + assert(iscore < 255*255*256 + s->lambda2*10); + assert(iscore >= 0); + assert(l>=0 && l<=255); + assert(pl>=0 && pl<=255); + + if(level==0){ + int varc= iscore >> 8; + int vard= score >> 8; + if (vard <= 64 || vard < varc) + c->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc); + else + c->scene_change_score+= s->m.qscale; + } + + if(level!=s->block_max_depth){ + put_rac(&s->c, &s->block_state[4 + s_context], 0); + score2 = encode_q_branch(s, level+1, 2*x+0, 2*y+0); + score2+= encode_q_branch(s, level+1, 2*x+1, 2*y+0); + score2+= encode_q_branch(s, level+1, 2*x+0, 2*y+1); + score2+= encode_q_branch(s, level+1, 2*x+1, 2*y+1); + score2+= s->lambda2>>FF_LAMBDA_SHIFT; //FIXME exact split overhead + + if(score2 < score && score2 < iscore) + return score2; + } + + if(iscore < score){ + pred_mv(s, &pmx, &pmy, 0, left, top, tr); + memcpy(pbbak, i_buffer, i_len); + s->c= ic; + s->c.bytestream_start= pbbak_start; + s->c.bytestream= pbbak + i_len; + set_blocks(s, level, x, y, l, cb, cr, pmx, pmy, 0, BLOCK_INTRA); + memcpy(s->block_state, i_state, sizeof(s->block_state)); + return iscore; + }else{ + memcpy(pbbak, p_buffer, p_len); + s->c= pc; + s->c.bytestream_start= pbbak_start; + s->c.bytestream= pbbak + p_len; + set_blocks(s, level, x, y, pl, pcb, pcr, mx, my, best_ref, 0); + memcpy(s->block_state, p_state, sizeof(s->block_state)); + return score; + } +} + +static void encode_q_branch2(SnowContext *s, int level, int x, int y){ + const int w= s->b_width << s->block_max_depth; + const int rem_depth= s->block_max_depth - level; + const int index= (x + y*w) << rem_depth; + int trx= (x+1)<block[index]; + const BlockNode *left = x ? &s->block[index-1] : &null_block; + const BlockNode *top = y ? &s->block[index-w] : &null_block; + const BlockNode *tl = y && x ? &s->block[index-w-1] : left; + const BlockNode *tr = y && trxblock[index-w+(1<color[0]; + int pcb= left->color[1]; + int pcr= left->color[2]; + int pmx, pmy; + int ref_context= av_log2(2*left->ref) + av_log2(2*top->ref); + int mx_context= av_log2(2*FFABS(left->mx - top->mx)) + 16*!!b->ref; + int my_context= av_log2(2*FFABS(left->my - top->my)) + 16*!!b->ref; + int s_context= 2*left->level + 2*top->level + tl->level + tr->level; + + if(s->keyframe){ + set_blocks(s, level, x, y, pl, pcb, pcr, 0, 0, 0, BLOCK_INTRA); + return; + } + + if(level!=s->block_max_depth){ + if(same_block(b,b+1) && same_block(b,b+w) && same_block(b,b+w+1)){ + put_rac(&s->c, &s->block_state[4 + s_context], 1); + }else{ + put_rac(&s->c, &s->block_state[4 + s_context], 0); + encode_q_branch2(s, level+1, 2*x+0, 2*y+0); + encode_q_branch2(s, level+1, 2*x+1, 2*y+0); + encode_q_branch2(s, level+1, 2*x+0, 2*y+1); + encode_q_branch2(s, level+1, 2*x+1, 2*y+1); + return; + } + } + if(b->type & BLOCK_INTRA){ + pred_mv(s, &pmx, &pmy, 0, left, top, tr); + put_rac(&s->c, &s->block_state[1 + (left->type&1) + (top->type&1)], 1); + put_symbol(&s->c, &s->block_state[32], b->color[0]-pl , 1); + put_symbol(&s->c, &s->block_state[64], b->color[1]-pcb, 1); + put_symbol(&s->c, &s->block_state[96], b->color[2]-pcr, 1); + set_blocks(s, level, x, y, b->color[0], b->color[1], b->color[2], pmx, pmy, 0, BLOCK_INTRA); + }else{ + pred_mv(s, &pmx, &pmy, b->ref, left, top, tr); + put_rac(&s->c, &s->block_state[1 + (left->type&1) + (top->type&1)], 0); + if(s->ref_frames > 1) + put_symbol(&s->c, &s->block_state[128 + 1024 + 32*ref_context], b->ref, 0); + put_symbol(&s->c, &s->block_state[128 + 32*mx_context], b->mx - pmx, 1); + put_symbol(&s->c, &s->block_state[128 + 32*my_context], b->my - pmy, 1); + set_blocks(s, level, x, y, pl, pcb, pcr, b->mx, b->my, b->ref, 0); + } +} + static int get_dc(SnowContext *s, int mb_x, int mb_y, int plane_index){ int i, x2, y2; Plane *p= &s->plane[plane_index]; @@ -2843,9 +2829,9 @@ static int get_block_rd(SnowContext *s, int mb_x, int mb_y, int plane_index, con * to improve the score of the whole frame, thus iterative motion * estimation does not always converge. */ if(s->avctx->me_cmp == FF_CMP_W97) - distortion = w97_32_c(&s->m, src + sx + sy*ref_stride, dst + sx + sy*ref_stride, ref_stride, 32); + distortion = ff_w97_32_c(&s->m, src + sx + sy*ref_stride, dst + sx + sy*ref_stride, ref_stride, 32); else if(s->avctx->me_cmp == FF_CMP_W53) - distortion = w53_32_c(&s->m, src + sx + sy*ref_stride, dst + sx + sy*ref_stride, ref_stride, 32); + distortion = ff_w53_32_c(&s->m, src + sx + sy*ref_stride, dst + sx + sy*ref_stride, ref_stride, 32); else{ distortion = 0; for(i=0; i<4; i++){ @@ -2938,6 +2924,133 @@ static int get_4block_rd(SnowContext *s, int mb_x, int mb_y, int plane_index){ return distortion + rate*penalty_factor; } +static int encode_subband_c0run(SnowContext *s, SubBand *b, IDWTELEM *src, IDWTELEM *parent, int stride, int orientation){ + const int w= b->width; + const int h= b->height; + int x, y; + + if(1){ + int run=0; + int runs[w*h]; + int run_index=0; + int max_index; + + for(y=0; y 1){ + if(orientation==1) ll= src[y + (x-2)*stride]; + else ll= src[x - 2 + y*stride]; + }*/ + } + if(parent){ + int px= x>>1; + int py= y>>1; + if(pxparent->width && pyparent->height) + p= parent[px + py*2*stride]; + } + if(!(/*ll|*/l|lt|t|rt|p)){ + if(v){ + runs[run_index++]= run; + run=0; + }else{ + run++; + } + } + } + } + max_index= run_index; + runs[run_index++]= run; + run_index=0; + run= runs[run_index++]; + + put_symbol2(&s->c, b->state[30], max_index, 0); + if(run_index <= max_index) + put_symbol2(&s->c, b->state[1], run, 3); + + for(y=0; yc.bytestream_end - s->c.bytestream < w*40){ + av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); + return -1; + } + for(x=0; x 1){ + if(orientation==1) ll= src[y + (x-2)*stride]; + else ll= src[x - 2 + y*stride]; + }*/ + } + if(parent){ + int px= x>>1; + int py= y>>1; + if(pxparent->width && pyparent->height) + p= parent[px + py*2*stride]; + } + if(/*ll|*/l|lt|t|rt|p){ + int context= av_log2(/*FFABS(ll) + */3*FFABS(l) + FFABS(lt) + 2*FFABS(t) + FFABS(rt) + FFABS(p)); + + put_rac(&s->c, &b->state[0][context], !!v); + }else{ + if(!run){ + run= runs[run_index++]; + + if(run_index <= max_index) + put_symbol2(&s->c, b->state[1], run, 3); + assert(v); + }else{ + run--; + assert(!v); + } + } + if(v){ + int context= av_log2(/*FFABS(ll) + */3*FFABS(l) + FFABS(lt) + 2*FFABS(t) + FFABS(rt) + FFABS(p)); + int l2= 2*FFABS(l) + (l<0); + int t2= 2*FFABS(t) + (t<0); + + put_symbol2(&s->c, b->state[context + 2], FFABS(v)-1, context-4); + put_rac(&s->c, &b->state[0][16 + 1 + 3 + quant3bA[l2&0xFF] + 3*quant3bA[t2&0xFF]], v<0); + } + } + } + } + return 0; +} + +static int encode_subband(SnowContext *s, SubBand *b, IDWTELEM *src, IDWTELEM *parent, int stride, int orientation){ +// encode_subband_qtree(s, b, src, parent, stride, orientation); +// encode_subband_z0run(s, b, src, parent, stride, orientation); + return encode_subband_c0run(s, b, src, parent, stride, orientation); +// encode_subband_dzr(s, b, src, parent, stride, orientation); +} + static av_always_inline int check_block(SnowContext *s, int mb_x, int mb_y, int p[3], int intra, const uint8_t *obmc_edged, int *best_rd){ const int b_stride= s->b_width << s->block_max_depth; BlockNode *block= &s->block[mb_x + mb_y * b_stride]; @@ -3198,7 +3311,7 @@ static void iterative_me(SnowContext *s){ } } } - av_log(NULL, AV_LOG_ERROR, "pass:%d changed:%d\n", pass, change); + av_log(s->avctx, AV_LOG_ERROR, "pass:%d changed:%d\n", pass, change); if(!change) break; } @@ -3240,7 +3353,29 @@ static void iterative_me(SnowContext *s){ change++; } } - av_log(NULL, AV_LOG_ERROR, "pass:4mv changed:%d\n", change*4); + av_log(s->avctx, AV_LOG_ERROR, "pass:4mv changed:%d\n", change*4); + } +} + +static void encode_blocks(SnowContext *s, int search){ + int x, y; + int w= s->b_width; + int h= s->b_height; + + if(s->avctx->me_method == ME_ITER && !s->keyframe && search) + iterative_me(s); + + for(y=0; yc.bytestream_end - s->c.bytestream < w*MB_SIZE*MB_SIZE*3){ //FIXME nicer limit + av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); + return; + } + for(x=0; xavctx->me_method == ME_ITER || !search) + encode_q_branch2(s, 0, x, y); + else + encode_q_branch (s, 0, x, y); + } } } @@ -3305,29 +3440,6 @@ static void quantize(SnowContext *s, SubBand *b, IDWTELEM *dst, DWTELEM *src, in } } -static void dequantize_slice_buffered(SnowContext *s, slice_buffer * sb, SubBand *b, IDWTELEM *src, int stride, int start_y, int end_y){ - const int w= b->width; - const int qlog= av_clip(s->qlog + b->qlog, 0, QROOT*16); - const int qmul= qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT); - const int qadd= (s->qbias*qmul)>>QBIAS_SHIFT; - int x,y; - - if(s->qlog == LOSSLESS_QLOG) return; - - for(y=start_y; ystride_line) + b->buf_y_offset) + b->buf_x_offset; - for(x=0; x>(QEXPSHIFT)); //FIXME try different bias - }else if(i>0){ - line[x]= (( i*qmul + qadd)>>(QEXPSHIFT)); - } - } - } -} - static void dequantize(SnowContext *s, SubBand *b, IDWTELEM *src, int stride){ const int w= b->width; const int h= b->height; @@ -3374,36 +3486,6 @@ static void decorrelate(SnowContext *s, SubBand *b, IDWTELEM *src, int stride, i } } -static void correlate_slice_buffered(SnowContext *s, slice_buffer * sb, SubBand *b, IDWTELEM *src, int stride, int inverse, int use_median, int start_y, int end_y){ - const int w= b->width; - int x,y; - - IDWTELEM * line=0; // silence silly "could be used without having been initialized" warning - IDWTELEM * prev; - - if (start_y != 0) - line = slice_buffer_get_line(sb, ((start_y - 1) * b->stride_line) + b->buf_y_offset) + b->buf_x_offset; - - for(y=start_y; ystride_line) + b->buf_y_offset) + b->buf_x_offset; - for(x=0; xwidth; const int h= b->height; @@ -3532,244 +3614,6 @@ static void update_last_header_values(SnowContext *s){ s->last_spatial_decomposition_count = s->spatial_decomposition_count; } -static void decode_qlogs(SnowContext *s){ - int plane_index, level, orientation; - - for(plane_index=0; plane_index<3; plane_index++){ - for(level=0; levelspatial_decomposition_count; level++){ - for(orientation=level ? 1:0; orientation<4; orientation++){ - int q; - if (plane_index==2) q= s->plane[1].band[level][orientation].qlog; - else if(orientation==2) q= s->plane[plane_index].band[level][1].qlog; - else q= get_symbol(&s->c, s->header_state, 1); - s->plane[plane_index].band[level][orientation].qlog= q; - } - } - } -} - -#define GET_S(dst, check) \ - tmp= get_symbol(&s->c, s->header_state, 0);\ - if(!(check)){\ - av_log(s->avctx, AV_LOG_ERROR, "Error " #dst " is %d\n", tmp);\ - return -1;\ - }\ - dst= tmp; - -static int decode_header(SnowContext *s){ - int plane_index, tmp; - uint8_t kstate[32]; - - memset(kstate, MID_STATE, sizeof(kstate)); - - s->keyframe= get_rac(&s->c, kstate); - if(s->keyframe || s->always_reset){ - reset_contexts(s); - s->spatial_decomposition_type= - s->qlog= - s->qbias= - s->mv_scale= - s->block_max_depth= 0; - } - if(s->keyframe){ - GET_S(s->version, tmp <= 0U) - s->always_reset= get_rac(&s->c, s->header_state); - s->temporal_decomposition_type= get_symbol(&s->c, s->header_state, 0); - s->temporal_decomposition_count= get_symbol(&s->c, s->header_state, 0); - GET_S(s->spatial_decomposition_count, 0 < tmp && tmp <= MAX_DECOMPOSITIONS) - s->colorspace_type= get_symbol(&s->c, s->header_state, 0); - s->chroma_h_shift= get_symbol(&s->c, s->header_state, 0); - s->chroma_v_shift= get_symbol(&s->c, s->header_state, 0); - s->spatial_scalability= get_rac(&s->c, s->header_state); -// s->rate_scalability= get_rac(&s->c, s->header_state); - GET_S(s->max_ref_frames, tmp < (unsigned)MAX_REF_FRAMES) - s->max_ref_frames++; - - decode_qlogs(s); - } - - if(!s->keyframe){ - if(get_rac(&s->c, s->header_state)){ - for(plane_index=0; plane_index<2; plane_index++){ - int htaps, i, sum=0; - Plane *p= &s->plane[plane_index]; - p->diag_mc= get_rac(&s->c, s->header_state); - htaps= get_symbol(&s->c, s->header_state, 0)*2 + 2; - if((unsigned)htaps > HTAPS_MAX || htaps==0) - return -1; - p->htaps= htaps; - for(i= htaps/2; i; i--){ - p->hcoeff[i]= get_symbol(&s->c, s->header_state, 0) * (1-2*(i&1)); - sum += p->hcoeff[i]; - } - p->hcoeff[0]= 32-sum; - } - s->plane[2].diag_mc= s->plane[1].diag_mc; - s->plane[2].htaps = s->plane[1].htaps; - memcpy(s->plane[2].hcoeff, s->plane[1].hcoeff, sizeof(s->plane[1].hcoeff)); - } - if(get_rac(&s->c, s->header_state)){ - GET_S(s->spatial_decomposition_count, 0 < tmp && tmp <= MAX_DECOMPOSITIONS) - decode_qlogs(s); - } - } - - s->spatial_decomposition_type+= get_symbol(&s->c, s->header_state, 1); - if(s->spatial_decomposition_type > 1U){ - av_log(s->avctx, AV_LOG_ERROR, "spatial_decomposition_type %d not supported", s->spatial_decomposition_type); - return -1; - } - if(FFMIN(s->avctx-> width>>s->chroma_h_shift, - s->avctx->height>>s->chroma_v_shift) >> (s->spatial_decomposition_count-1) <= 0){ - av_log(s->avctx, AV_LOG_ERROR, "spatial_decomposition_count %d too large for size", s->spatial_decomposition_count); - return -1; - } - - s->qlog += get_symbol(&s->c, s->header_state, 1); - s->mv_scale += get_symbol(&s->c, s->header_state, 1); - s->qbias += get_symbol(&s->c, s->header_state, 1); - s->block_max_depth+= get_symbol(&s->c, s->header_state, 1); - if(s->block_max_depth > 1 || s->block_max_depth < 0){ - av_log(s->avctx, AV_LOG_ERROR, "block_max_depth= %d is too large", s->block_max_depth); - s->block_max_depth= 0; - return -1; - } - - return 0; -} - -static void init_qexp(void){ - int i; - double v=128; - - for(i=0; ipriv_data; - int width, height; - int i, j; - - s->avctx= avctx; - s->max_ref_frames=1; //just make sure its not an invalid value in case of no initial keyframe - - dsputil_init(&s->dsp, avctx); - -#define mcf(dx,dy)\ - s->dsp.put_qpel_pixels_tab [0][dy+dx/4]=\ - s->dsp.put_no_rnd_qpel_pixels_tab[0][dy+dx/4]=\ - s->dsp.put_h264_qpel_pixels_tab[0][dy+dx/4];\ - s->dsp.put_qpel_pixels_tab [1][dy+dx/4]=\ - s->dsp.put_no_rnd_qpel_pixels_tab[1][dy+dx/4]=\ - s->dsp.put_h264_qpel_pixels_tab[1][dy+dx/4]; - - mcf( 0, 0) - mcf( 4, 0) - mcf( 8, 0) - mcf(12, 0) - mcf( 0, 4) - mcf( 4, 4) - mcf( 8, 4) - mcf(12, 4) - mcf( 0, 8) - mcf( 4, 8) - mcf( 8, 8) - mcf(12, 8) - mcf( 0,12) - mcf( 4,12) - mcf( 8,12) - mcf(12,12) - -#define mcfh(dx,dy)\ - s->dsp.put_pixels_tab [0][dy/4+dx/8]=\ - s->dsp.put_no_rnd_pixels_tab[0][dy/4+dx/8]=\ - mc_block_hpel ## dx ## dy ## 16;\ - s->dsp.put_pixels_tab [1][dy/4+dx/8]=\ - s->dsp.put_no_rnd_pixels_tab[1][dy/4+dx/8]=\ - mc_block_hpel ## dx ## dy ## 8; - - mcfh(0, 0) - mcfh(8, 0) - mcfh(0, 8) - mcfh(8, 8) - - if(!qexp[0]) - init_qexp(); - -// dec += FFMAX(s->chroma_h_shift, s->chroma_v_shift); - - width= s->avctx->width; - height= s->avctx->height; - - s->spatial_idwt_buffer= av_mallocz(width*height*sizeof(IDWTELEM)); - s->spatial_dwt_buffer= av_mallocz(width*height*sizeof(DWTELEM)); //FIXME this does not belong here - - for(i=0; iavctx->get_buffer(s->avctx, &s->mconly_picture); - s->scratchbuf = av_malloc(s->mconly_picture.linesize[0]*7*MB_SIZE); - - return 0; -} - -static int common_init_after_header(AVCodecContext *avctx){ - SnowContext *s = avctx->priv_data; - int plane_index, level, orientation; - - for(plane_index=0; plane_index<3; plane_index++){ - int w= s->avctx->width; - int h= s->avctx->height; - - if(plane_index){ - w>>= s->chroma_h_shift; - h>>= s->chroma_v_shift; - } - s->plane[plane_index].width = w; - s->plane[plane_index].height= h; - - for(level=s->spatial_decomposition_count-1; level>=0; level--){ - for(orientation=level ? 1 : 0; orientation<4; orientation++){ - SubBand *b= &s->plane[plane_index].band[level][orientation]; - - b->buf= s->spatial_dwt_buffer; - b->level= level; - b->stride= s->plane[plane_index].width << (s->spatial_decomposition_count - level); - b->width = (w + !(orientation&1))>>1; - b->height= (h + !(orientation>1))>>1; - - b->stride_line = 1 << (s->spatial_decomposition_count - level); - b->buf_x_offset = 0; - b->buf_y_offset = 0; - - if(orientation&1){ - b->buf += (w+1)>>1; - b->buf_x_offset = (w+1)>>1; - } - if(orientation>1){ - b->buf += b->stride>>1; - b->buf_y_offset = b->stride_line >> 1; - } - b->ibuf= s->spatial_idwt_buffer + (b->buf - s->spatial_dwt_buffer); - - if(level) - b->parent= &s->plane[plane_index].band[level-1][orientation]; - //FIXME avoid this realloc - av_freep(&b->x_coeff); - b->x_coeff=av_mallocz(((b->width+1) * b->height+1)*sizeof(x_and_coeff)); - } - w= (w+1)>>1; - h= (h+1)>>1; - } - } - - return 0; -} - static int qscale2qlog(int qscale){ return rint(QROOT*log(qscale / (float)FF_QP2LAMBDA)/log(2)) + 61*QROOT/8; //<64 >60 @@ -3853,325 +3697,6 @@ static void calculate_visual_weight(SnowContext *s, Plane *p){ } } -#define QUANTIZE2 0 - -#if QUANTIZE2==1 -#define Q2_STEP 8 - -static void find_sse(SnowContext *s, Plane *p, int *score, int score_stride, IDWTELEM *r0, IDWTELEM *r1, int level, int orientation){ - SubBand *b= &p->band[level][orientation]; - int x, y; - int xo=0; - int yo=0; - int step= 1 << (s->spatial_decomposition_count - level); - - if(orientation&1) - xo= step>>1; - if(orientation&2) - yo= step>>1; - - //FIXME bias for nonzero ? - //FIXME optimize - memset(score, 0, sizeof(*score)*score_stride*((p->height + Q2_STEP-1)/Q2_STEP)); - for(y=0; yheight; y++){ - for(x=0; xwidth; x++){ - int sx= (x-xo + step/2) / step / Q2_STEP; - int sy= (y-yo + step/2) / step / Q2_STEP; - int v= r0[x + y*p->width] - r1[x + y*p->width]; - assert(sx>=0 && sy>=0 && sx < score_stride); - v= ((v+8)>>4)<<4; - score[sx + sy*score_stride] += v*v; - assert(score[sx + sy*score_stride] >= 0); - } - } -} - -static void dequantize_all(SnowContext *s, Plane *p, IDWTELEM *buffer, int width, int height){ - int level, orientation; - - for(level=0; levelspatial_decomposition_count; level++){ - for(orientation=level ? 1 : 0; orientation<4; orientation++){ - SubBand *b= &p->band[level][orientation]; - IDWTELEM *dst= buffer + (b->ibuf - s->spatial_idwt_buffer); - - dequantize(s, b, dst, b->stride); - } - } -} - -static void dwt_quantize(SnowContext *s, Plane *p, DWTELEM *buffer, int width, int height, int stride, int type){ - int level, orientation, ys, xs, x, y, pass; - IDWTELEM best_dequant[height * stride]; - IDWTELEM idwt2_buffer[height * stride]; - const int score_stride= (width + 10)/Q2_STEP; - int best_score[(width + 10)/Q2_STEP * (height + 10)/Q2_STEP]; //FIXME size - int score[(width + 10)/Q2_STEP * (height + 10)/Q2_STEP]; //FIXME size - int threshold= (s->m.lambda * s->m.lambda) >> 6; - - //FIXME pass the copy cleanly ? - -// memcpy(dwt_buffer, buffer, height * stride * sizeof(DWTELEM)); - ff_spatial_dwt(buffer, width, height, stride, type, s->spatial_decomposition_count); - - for(level=0; levelspatial_decomposition_count; level++){ - for(orientation=level ? 1 : 0; orientation<4; orientation++){ - SubBand *b= &p->band[level][orientation]; - IDWTELEM *dst= best_dequant + (b->ibuf - s->spatial_idwt_buffer); - DWTELEM *src= buffer + (b-> buf - s->spatial_dwt_buffer); - assert(src == b->buf); // code does not depend on this but it is true currently - - quantize(s, b, dst, src, b->stride, s->qbias); - } - } - for(pass=0; pass<1; pass++){ - if(s->qbias == 0) //keyframe - continue; - for(level=0; levelspatial_decomposition_count; level++){ - for(orientation=level ? 1 : 0; orientation<4; orientation++){ - SubBand *b= &p->band[level][orientation]; - IDWTELEM *dst= idwt2_buffer + (b->ibuf - s->spatial_idwt_buffer); - IDWTELEM *best_dst= best_dequant + (b->ibuf - s->spatial_idwt_buffer); - - for(ys= 0; ysspatial_decomposition_count); - find_sse(s, p, best_score, score_stride, idwt2_buffer, s->spatial_idwt_buffer, level, orientation); - memcpy(idwt2_buffer, best_dequant, height * stride * sizeof(IDWTELEM)); - for(y=ys; yheight; y+= Q2_STEP){ - for(x=xs; xwidth; x+= Q2_STEP){ - if(dst[x + y*b->stride]<0) dst[x + y*b->stride]++; - if(dst[x + y*b->stride]>0) dst[x + y*b->stride]--; - //FIXME try more than just -- - } - } - dequantize_all(s, p, idwt2_buffer, width, height); - ff_spatial_idwt(idwt2_buffer, width, height, stride, type, s->spatial_decomposition_count); - find_sse(s, p, score, score_stride, idwt2_buffer, s->spatial_idwt_buffer, level, orientation); - for(y=ys; yheight; y+= Q2_STEP){ - for(x=xs; xwidth; x+= Q2_STEP){ - int score_idx= x/Q2_STEP + (y/Q2_STEP)*score_stride; - if(score[score_idx] <= best_score[score_idx] + threshold){ - best_score[score_idx]= score[score_idx]; - if(best_dst[x + y*b->stride]<0) best_dst[x + y*b->stride]++; - if(best_dst[x + y*b->stride]>0) best_dst[x + y*b->stride]--; - //FIXME copy instead - } - } - } - } - } - } - } - } - memcpy(s->spatial_idwt_buffer, best_dequant, height * stride * sizeof(IDWTELEM)); //FIXME work with that directly instead of copy at the end -} - -#endif /* QUANTIZE2==1 */ - -static av_cold int encode_init(AVCodecContext *avctx) -{ - SnowContext *s = avctx->priv_data; - int plane_index; - - if(avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){ - av_log(avctx, AV_LOG_ERROR, "This codec is under development, files encoded with it may not be decodable with future versions!!!\n" - "Use vstrict=-2 / -strict -2 to use it anyway.\n"); - return -1; - } - - if(avctx->prediction_method == DWT_97 - && (avctx->flags & CODEC_FLAG_QSCALE) - && avctx->global_quality == 0){ - av_log(avctx, AV_LOG_ERROR, "The 9/7 wavelet is incompatible with lossless mode.\n"); - return -1; - } - - s->spatial_decomposition_type= avctx->prediction_method; //FIXME add decorrelator type r transform_type - - s->mv_scale = (avctx->flags & CODEC_FLAG_QPEL) ? 2 : 4; - s->block_max_depth= (avctx->flags & CODEC_FLAG_4MV ) ? 1 : 0; - - for(plane_index=0; plane_index<3; plane_index++){ - s->plane[plane_index].diag_mc= 1; - s->plane[plane_index].htaps= 6; - s->plane[plane_index].hcoeff[0]= 40; - s->plane[plane_index].hcoeff[1]= -10; - s->plane[plane_index].hcoeff[2]= 2; - s->plane[plane_index].fast_mc= 1; - } - - common_init(avctx); - alloc_blocks(s); - - s->version=0; - - s->m.avctx = avctx; - s->m.flags = avctx->flags; - s->m.bit_rate= avctx->bit_rate; - - s->m.me.temp = - s->m.me.scratchpad= av_mallocz((avctx->width+64)*2*16*2*sizeof(uint8_t)); - s->m.me.map = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t)); - s->m.me.score_map = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t)); - s->m.obmc_scratchpad= av_mallocz(MB_SIZE*MB_SIZE*12*sizeof(uint32_t)); - h263_encode_init(&s->m); //mv_penalty - - s->max_ref_frames = FFMAX(FFMIN(avctx->refs, MAX_REF_FRAMES), 1); - - if(avctx->flags&CODEC_FLAG_PASS1){ - if(!avctx->stats_out) - avctx->stats_out = av_mallocz(256); - } - if((avctx->flags&CODEC_FLAG_PASS2) || !(avctx->flags&CODEC_FLAG_QSCALE)){ - if(ff_rate_control_init(&s->m) < 0) - return -1; - } - s->pass1_rc= !(avctx->flags & (CODEC_FLAG_QSCALE|CODEC_FLAG_PASS2)); - - avctx->coded_frame= &s->current_picture; - switch(avctx->pix_fmt){ -// case PIX_FMT_YUV444P: -// case PIX_FMT_YUV422P: - case PIX_FMT_YUV420P: - case PIX_FMT_GRAY8: -// case PIX_FMT_YUV411P: -// case PIX_FMT_YUV410P: - s->colorspace_type= 0; - break; -/* case PIX_FMT_RGB32: - s->colorspace= 1; - break;*/ - default: - av_log(avctx, AV_LOG_ERROR, "pixel format not supported\n"); - return -1; - } -// avcodec_get_chroma_sub_sample(avctx->pix_fmt, &s->chroma_h_shift, &s->chroma_v_shift); - s->chroma_h_shift= 1; - s->chroma_v_shift= 1; - - ff_set_cmp(&s->dsp, s->dsp.me_cmp, s->avctx->me_cmp); - ff_set_cmp(&s->dsp, s->dsp.me_sub_cmp, s->avctx->me_sub_cmp); - - s->avctx->get_buffer(s->avctx, &s->input_picture); - - if(s->avctx->me_method == ME_ITER){ - int i; - int size= s->b_width * s->b_height << 2*s->block_max_depth; - for(i=0; imax_ref_frames; i++){ - s->ref_mvs[i]= av_mallocz(size*sizeof(int16_t[2])); - s->ref_scores[i]= av_mallocz(size*sizeof(uint32_t)); - } - } - - return 0; -} - -#define USE_HALFPEL_PLANE 0 - -static void halfpel_interpol(SnowContext *s, uint8_t *halfpel[4][4], AVFrame *frame){ - int p,x,y; - - assert(!(s->avctx->flags & CODEC_FLAG_EMU_EDGE)); - - for(p=0; p<3; p++){ - int is_chroma= !!p; - int w= s->avctx->width >>is_chroma; - int h= s->avctx->height >>is_chroma; - int ls= frame->linesize[p]; - uint8_t *src= frame->data[p]; - - halfpel[1][p]= (uint8_t*)av_malloc(ls * (h+2*EDGE_WIDTH)) + EDGE_WIDTH*(1+ls); - halfpel[2][p]= (uint8_t*)av_malloc(ls * (h+2*EDGE_WIDTH)) + EDGE_WIDTH*(1+ls); - halfpel[3][p]= (uint8_t*)av_malloc(ls * (h+2*EDGE_WIDTH)) + EDGE_WIDTH*(1+ls); - - halfpel[0][p]= src; - for(y=0; y>5; - } - } - for(y=0; y>5; - } - } - src= halfpel[1][p]; - for(y=0; y>5; - } - } - -//FIXME border! - } -} - -static void release_buffer(AVCodecContext *avctx){ - SnowContext *s = avctx->priv_data; - int i; - - if(s->last_picture[s->max_ref_frames-1].data[0]){ - avctx->release_buffer(avctx, &s->last_picture[s->max_ref_frames-1]); - for(i=0; i<9; i++) - if(s->halfpel_plane[s->max_ref_frames-1][1+i/3][i%3]) - av_free(s->halfpel_plane[s->max_ref_frames-1][1+i/3][i%3] - EDGE_WIDTH*(1+s->current_picture.linesize[i%3])); - } -} - -static int frame_start(SnowContext *s){ - AVFrame tmp; - int w= s->avctx->width; //FIXME round up to x16 ? - int h= s->avctx->height; - - if(s->current_picture.data[0]){ - s->dsp.draw_edges(s->current_picture.data[0], s->current_picture.linesize[0], w , h , EDGE_WIDTH ); - s->dsp.draw_edges(s->current_picture.data[1], s->current_picture.linesize[1], w>>1, h>>1, EDGE_WIDTH/2); - s->dsp.draw_edges(s->current_picture.data[2], s->current_picture.linesize[2], w>>1, h>>1, EDGE_WIDTH/2); - } - - release_buffer(s->avctx); - - tmp= s->last_picture[s->max_ref_frames-1]; - memmove(s->last_picture+1, s->last_picture, (s->max_ref_frames-1)*sizeof(AVFrame)); - memmove(s->halfpel_plane+1, s->halfpel_plane, (s->max_ref_frames-1)*sizeof(void*)*4*4); - if(USE_HALFPEL_PLANE && s->current_picture.data[0]) - halfpel_interpol(s, s->halfpel_plane[0], &s->current_picture); - s->last_picture[0]= s->current_picture; - s->current_picture= tmp; - - if(s->keyframe){ - s->ref_frames= 0; - }else{ - int i; - for(i=0; imax_ref_frames && s->last_picture[i].data[0]; i++) - if(i && s->last_picture[i-1].key_frame) - break; - s->ref_frames= i; - if(s->ref_frames==0){ - av_log(s->avctx,AV_LOG_ERROR, "No reference frames\n"); - return -1; - } - } - - s->current_picture.reference= 1; - if(s->avctx->get_buffer(s->avctx, &s->current_picture) < 0){ - av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; - } - - s->current_picture.key_frame= s->keyframe; - - return 0; -} - static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ SnowContext *s = avctx->priv_data; RangeCoder * const c= &s->c; @@ -4224,6 +3749,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; if(pict->pict_type == FF_P_TYPE){ int block_width = (width +15)>>4; int block_height= (height+15)>>4; @@ -4447,248 +3974,21 @@ redo_frame: return ff_rac_terminate(c); } -static av_cold void common_end(SnowContext *s){ - int plane_index, level, orientation, i; - - av_freep(&s->spatial_dwt_buffer); - av_freep(&s->spatial_idwt_buffer); - - s->m.me.temp= NULL; - av_freep(&s->m.me.scratchpad); - av_freep(&s->m.me.map); - av_freep(&s->m.me.score_map); - av_freep(&s->m.obmc_scratchpad); - - av_freep(&s->block); - av_freep(&s->scratchbuf); - - for(i=0; iref_mvs[i]); - av_freep(&s->ref_scores[i]); - if(s->last_picture[i].data[0]) - s->avctx->release_buffer(s->avctx, &s->last_picture[i]); - } - - for(plane_index=0; plane_index<3; plane_index++){ - for(level=s->spatial_decomposition_count-1; level>=0; level--){ - for(orientation=level ? 1 : 0; orientation<4; orientation++){ - SubBand *b= &s->plane[plane_index].band[level][orientation]; - - av_freep(&b->x_coeff); - } - } - } -} - static av_cold int encode_end(AVCodecContext *avctx) { SnowContext *s = avctx->priv_data; common_end(s); + if (s->input_picture.data[0]) + avctx->release_buffer(avctx, &s->input_picture); av_free(avctx->stats_out); return 0; } -static av_cold int decode_init(AVCodecContext *avctx) -{ - avctx->pix_fmt= PIX_FMT_YUV420P; - - common_init(avctx); - - return 0; -} - -static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt){ - const uint8_t *buf = avpkt->data; - int buf_size = avpkt->size; - SnowContext *s = avctx->priv_data; - RangeCoder * const c= &s->c; - int bytes_read; - AVFrame *picture = data; - int level, orientation, plane_index; - - ff_init_range_decoder(c, buf, buf_size); - ff_build_rac_states(c, 0.05*(1LL<<32), 256-8); - - s->current_picture.pict_type= FF_I_TYPE; //FIXME I vs. P - if(decode_header(s)<0) - return -1; - common_init_after_header(avctx); - - // realloc slice buffer for the case that spatial_decomposition_count changed - slice_buffer_destroy(&s->sb); - slice_buffer_init(&s->sb, s->plane[0].height, (MB_SIZE >> s->block_max_depth) + s->spatial_decomposition_count * 8 + 1, s->plane[0].width, s->spatial_idwt_buffer); - - for(plane_index=0; plane_index<3; plane_index++){ - Plane *p= &s->plane[plane_index]; - p->fast_mc= p->diag_mc && p->htaps==6 && p->hcoeff[0]==40 - && p->hcoeff[1]==-10 - && p->hcoeff[2]==2; - } - - alloc_blocks(s); - - if(frame_start(s) < 0) - return -1; - //keyframe flag duplication mess FIXME - if(avctx->debug&FF_DEBUG_PICT_INFO) - av_log(avctx, AV_LOG_ERROR, "keyframe:%d qlog:%d\n", s->keyframe, s->qlog); - - decode_blocks(s); - - for(plane_index=0; plane_index<3; plane_index++){ - Plane *p= &s->plane[plane_index]; - int w= p->width; - int h= p->height; - int x, y; - int decode_state[MAX_DECOMPOSITIONS][4][1]; /* Stored state info for unpack_coeffs. 1 variable per instance. */ - - if(s->avctx->debug&2048){ - memset(s->spatial_dwt_buffer, 0, sizeof(DWTELEM)*w*h); - predict_plane(s, s->spatial_idwt_buffer, plane_index, 1); - - for(y=0; ycurrent_picture.data[plane_index][y*s->current_picture.linesize[plane_index] + x]; - s->mconly_picture.data[plane_index][y*s->mconly_picture.linesize[plane_index] + x]= v; - } - } - } - - { - for(level=0; levelspatial_decomposition_count; level++){ - for(orientation=level ? 1 : 0; orientation<4; orientation++){ - SubBand *b= &p->band[level][orientation]; - unpack_coeffs(s, b, b->parent, orientation); - } - } - } - - { - const int mb_h= s->b_height << s->block_max_depth; - const int block_size = MB_SIZE >> s->block_max_depth; - const int block_w = plane_index ? block_size/2 : block_size; - int mb_y; - DWTCompose cs[MAX_DECOMPOSITIONS]; - int yd=0, yq=0; - int y; - int end_y; - - ff_spatial_idwt_buffered_init(cs, &s->sb, w, h, 1, s->spatial_decomposition_type, s->spatial_decomposition_count); - for(mb_y=0; mb_y<=mb_h; mb_y++){ - - int slice_starty = block_w*mb_y; - int slice_h = block_w*(mb_y+1); - if (!(s->keyframe || s->avctx->debug&512)){ - slice_starty = FFMAX(0, slice_starty - (block_w >> 1)); - slice_h -= (block_w >> 1); - } - - for(level=0; levelspatial_decomposition_count; level++){ - for(orientation=level ? 1 : 0; orientation<4; orientation++){ - SubBand *b= &p->band[level][orientation]; - int start_y; - int end_y; - int our_mb_start = mb_y; - int our_mb_end = (mb_y + 1); - const int extra= 3; - start_y = (mb_y ? ((block_w * our_mb_start) >> (s->spatial_decomposition_count - level)) + s->spatial_decomposition_count - level + extra: 0); - end_y = (((block_w * our_mb_end) >> (s->spatial_decomposition_count - level)) + s->spatial_decomposition_count - level + extra); - if (!(s->keyframe || s->avctx->debug&512)){ - start_y = FFMAX(0, start_y - (block_w >> (1+s->spatial_decomposition_count - level))); - end_y = FFMAX(0, end_y - (block_w >> (1+s->spatial_decomposition_count - level))); - } - start_y = FFMIN(b->height, start_y); - end_y = FFMIN(b->height, end_y); - - if (start_y != end_y){ - if (orientation == 0){ - SubBand * correlate_band = &p->band[0][0]; - int correlate_end_y = FFMIN(b->height, end_y + 1); - int correlate_start_y = FFMIN(b->height, (start_y ? start_y + 1 : 0)); - decode_subband_slice_buffered(s, correlate_band, &s->sb, correlate_start_y, correlate_end_y, decode_state[0][0]); - correlate_slice_buffered(s, &s->sb, correlate_band, correlate_band->ibuf, correlate_band->stride, 1, 0, correlate_start_y, correlate_end_y); - dequantize_slice_buffered(s, &s->sb, correlate_band, correlate_band->ibuf, correlate_band->stride, start_y, end_y); - } - else - decode_subband_slice_buffered(s, b, &s->sb, start_y, end_y, decode_state[level][orientation]); - } - } - } - - for(; yddsp, cs, &s->sb, w, h, 1, s->spatial_decomposition_type, s->spatial_decomposition_count, yd); - } - - if(s->qlog == LOSSLESS_QLOG){ - for(; yqsb, yq); - for(x=0; xsb, s->spatial_idwt_buffer, plane_index, 1, mb_y); - - y = FFMIN(p->height, slice_starty); - end_y = FFMIN(p->height, slice_h); - while(y < end_y) - slice_buffer_release(&s->sb, y++); - } - - slice_buffer_flush(&s->sb); - } - - } - - emms_c(); - - release_buffer(avctx); - - if(!(s->avctx->debug&2048)) - *picture= s->current_picture; - else - *picture= s->mconly_picture; - - *data_size = sizeof(AVFrame); - - bytes_read= c->bytestream - c->bytestream_start; - if(bytes_read ==0) av_log(s->avctx, AV_LOG_ERROR, "error at end of frame\n"); //FIXME - - return bytes_read; -} - -static av_cold int decode_end(AVCodecContext *avctx) -{ - SnowContext *s = avctx->priv_data; - - slice_buffer_destroy(&s->sb); - - common_end(s); - - return 0; -} - -AVCodec snow_decoder = { - "snow", - CODEC_TYPE_VIDEO, - CODEC_ID_SNOW, - sizeof(SnowContext), - decode_init, - NULL, - decode_end, - decode_frame, - CODEC_CAP_DR1 /*| CODEC_CAP_DRAW_HORIZ_BAND*/, - NULL, - .long_name = NULL_IF_CONFIG_SMALL("Snow"), -}; - -#if CONFIG_SNOW_ENCODER AVCodec snow_encoder = { "snow", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_SNOW, sizeof(SnowContext), encode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/snow.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/snow.h index 5d5ae1e68a..7d847e4b37 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/snow.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/snow.h @@ -23,10 +23,10 @@ #define AVCODEC_SNOW_H #include "dsputil.h" +#include "dwt.h" #define MID_STATE 128 -#define MAX_DECOMPOSITIONS 8 #define MAX_PLANES 4 #define QSHIFT 5 #define QROOT (1< #include "libavcodec/dsputil.h" +#include "dsputil_vis.h" #include "vis.h" -void ff_simple_idct_put_vis(uint8_t *dest, int line_size, DCTELEM *data); -void ff_simple_idct_add_vis(uint8_t *dest, int line_size, DCTELEM *data); -void ff_simple_idct_vis(DCTELEM *data); - /* The trick used in some of this file is the formula from the MMX * motion comp code, which is: * @@ -54,20 +51,18 @@ void ff_simple_idct_vis(DCTELEM *data); * fpsub16 f12, f10, f10 */ -#define ATTR_ALIGN(alignd) __attribute__ ((aligned(alignd))) - #define DUP4(x) {x, x, x, x} #define DUP8(x) {x, x, x, x, x, x, x, x} -static const int16_t constants1[] ATTR_ALIGN(8) = DUP4 (1); -static const int16_t constants2[] ATTR_ALIGN(8) = DUP4 (2); -static const int16_t constants3[] ATTR_ALIGN(8) = DUP4 (3); -static const int16_t constants6[] ATTR_ALIGN(8) = DUP4 (6); -static const int8_t constants_fe[] ATTR_ALIGN(8) = DUP8 (0xfe); -static const int8_t constants_7f[] ATTR_ALIGN(8) = DUP8 (0x7f); -static const int8_t constants128[] ATTR_ALIGN(8) = DUP8 (128); -static const int16_t constants256_512[] ATTR_ALIGN(8) = +DECLARE_ALIGNED(8, static const int16_t, constants1)[] = DUP4 (1); +DECLARE_ALIGNED(8, static const int16_t, constants2)[] = DUP4 (2); +DECLARE_ALIGNED(8, static const int16_t, constants3)[] = DUP4 (3); +DECLARE_ALIGNED(8, static const int16_t, constants6)[] = DUP4 (6); +DECLARE_ALIGNED(8, static const int8_t, constants_fe)[] = DUP8 (0xfe); +DECLARE_ALIGNED(8, static const int8_t, constants_7f)[] = DUP8 (0x7f); +DECLARE_ALIGNED(8, static const int8_t, constants128)[] = DUP8 (128); +DECLARE_ALIGNED(8, static const int16_t, constants256_512)[] = {256, 512, 256, 512}; -static const int16_t constants256_1024[] ATTR_ALIGN(8) = +DECLARE_ALIGNED(8, static const int16_t, constants256_1024)[] = {256, 1024, 256, 1024}; #define REF_0 0 @@ -123,11 +118,9 @@ static const int16_t constants256_1024[] ATTR_ALIGN(8) = #define TMP30 56 #define TMP32 58 -static void MC_put_o_16_vis (uint8_t * dest, const uint8_t * _ref, +static void MC_put_o_16_vis (uint8_t * dest, const uint8_t * ref, const int stride, int height) { - uint8_t *ref = (uint8_t *) _ref; - ref = vis_alignaddr(ref); do { /* 5 cycles */ vis_ld64(ref[0], TMP0); @@ -146,11 +139,9 @@ static void MC_put_o_16_vis (uint8_t * dest, const uint8_t * _ref, } while (--height); } -static void MC_put_o_8_vis (uint8_t * dest, const uint8_t * _ref, +static void MC_put_o_8_vis (uint8_t * dest, const uint8_t * ref, const int stride, int height) { - uint8_t *ref = (uint8_t *) _ref; - ref = vis_alignaddr(ref); do { /* 4 cycles */ vis_ld64(ref[0], TMP0); @@ -167,10 +158,9 @@ static void MC_put_o_8_vis (uint8_t * dest, const uint8_t * _ref, } -static void MC_avg_o_16_vis (uint8_t * dest, const uint8_t * _ref, +static void MC_avg_o_16_vis (uint8_t * dest, const uint8_t * ref, const int stride, int height) { - uint8_t *ref = (uint8_t *) _ref; int stride_8 = stride + 8; ref = vis_alignaddr(ref); @@ -328,11 +318,9 @@ static void MC_avg_o_16_vis (uint8_t * dest, const uint8_t * _ref, vis_st64_2(TMP22, dest, 8); } -static void MC_avg_o_8_vis (uint8_t * dest, const uint8_t * _ref, +static void MC_avg_o_8_vis (uint8_t * dest, const uint8_t * ref, const int stride, int height) { - uint8_t *ref = (uint8_t *) _ref; - ref = vis_alignaddr(ref); vis_ld64(ref[0], TMP0); @@ -422,10 +410,9 @@ static void MC_avg_o_8_vis (uint8_t * dest, const uint8_t * _ref, vis_st64(TMP4, dest[0]); } -static void MC_put_x_16_vis (uint8_t * dest, const uint8_t * _ref, +static void MC_put_x_16_vis (uint8_t * dest, const uint8_t * ref, const int stride, int height) { - uint8_t *ref = (uint8_t *) _ref; unsigned long off = (unsigned long) ref & 0x7; unsigned long off_plus_1 = off + 1; @@ -615,10 +602,9 @@ static void MC_put_x_16_vis (uint8_t * dest, const uint8_t * _ref, vis_st64_2(TMP8, dest, 8); } -static void MC_put_x_8_vis (uint8_t * dest, const uint8_t * _ref, +static void MC_put_x_8_vis (uint8_t * dest, const uint8_t * ref, const int stride, int height) { - uint8_t *ref = (uint8_t *) _ref; unsigned long off = (unsigned long) ref & 0x7; unsigned long off_plus_1 = off + 1; @@ -739,10 +725,9 @@ static void MC_put_x_8_vis (uint8_t * dest, const uint8_t * _ref, dest += stride; } -static void MC_avg_x_16_vis (uint8_t * dest, const uint8_t * _ref, +static void MC_avg_x_16_vis (uint8_t * dest, const uint8_t * ref, const int stride, int height) { - uint8_t *ref = (uint8_t *) _ref; unsigned long off = (unsigned long) ref & 0x7; unsigned long off_plus_1 = off + 1; @@ -830,10 +815,9 @@ static void MC_avg_x_16_vis (uint8_t * dest, const uint8_t * _ref, } while (--height); } -static void MC_avg_x_8_vis (uint8_t * dest, const uint8_t * _ref, +static void MC_avg_x_8_vis (uint8_t * dest, const uint8_t * ref, const int stride, int height) { - uint8_t *ref = (uint8_t *) _ref; unsigned long off = (unsigned long) ref & 0x7; unsigned long off_plus_1 = off + 1; int stride_times_2 = stride << 1; @@ -996,11 +980,9 @@ static void MC_avg_x_8_vis (uint8_t * dest, const uint8_t * _ref, } while (--height); } -static void MC_put_y_16_vis (uint8_t * dest, const uint8_t * _ref, +static void MC_put_y_16_vis (uint8_t * dest, const uint8_t * ref, const int stride, int height) { - uint8_t *ref = (uint8_t *) _ref; - ref = vis_alignaddr(ref); vis_ld64(ref[0], TMP0); @@ -1152,11 +1134,9 @@ static void MC_put_y_16_vis (uint8_t * dest, const uint8_t * _ref, vis_st64_2(TMP2, dest, 8); } -static void MC_put_y_8_vis (uint8_t * dest, const uint8_t * _ref, +static void MC_put_y_8_vis (uint8_t * dest, const uint8_t * ref, const int stride, int height) { - uint8_t *ref = (uint8_t *) _ref; - ref = vis_alignaddr(ref); vis_ld64(ref[0], TMP0); @@ -1244,10 +1224,9 @@ static void MC_put_y_8_vis (uint8_t * dest, const uint8_t * _ref, vis_st64(DST_0, dest[0]); } -static void MC_avg_y_16_vis (uint8_t * dest, const uint8_t * _ref, +static void MC_avg_y_16_vis (uint8_t * dest, const uint8_t * ref, const int stride, int height) { - uint8_t *ref = (uint8_t *) _ref; int stride_8 = stride + 8; int stride_16 = stride + 16; @@ -1373,10 +1352,9 @@ static void MC_avg_y_16_vis (uint8_t * dest, const uint8_t * _ref, } while (--height); } -static void MC_avg_y_8_vis (uint8_t * dest, const uint8_t * _ref, +static void MC_avg_y_8_vis (uint8_t * dest, const uint8_t * ref, const int stride, int height) { - uint8_t *ref = (uint8_t *) _ref; int stride_8 = stride + 8; vis_set_gsr(5 << VIS_GSR_SCALEFACT_SHIFT); @@ -1453,10 +1431,9 @@ static void MC_avg_y_8_vis (uint8_t * dest, const uint8_t * _ref, } while (--height); } -static void MC_put_xy_16_vis (uint8_t * dest, const uint8_t * _ref, +static void MC_put_xy_16_vis (uint8_t * dest, const uint8_t * ref, const int stride, int height) { - uint8_t *ref = (uint8_t *) _ref; unsigned long off = (unsigned long) ref & 0x7; unsigned long off_plus_1 = off + 1; int stride_8 = stride + 8; @@ -1618,10 +1595,9 @@ static void MC_put_xy_16_vis (uint8_t * dest, const uint8_t * _ref, } while (--height); } -static void MC_put_xy_8_vis (uint8_t * dest, const uint8_t * _ref, +static void MC_put_xy_8_vis (uint8_t * dest, const uint8_t * ref, const int stride, int height) { - uint8_t *ref = (uint8_t *) _ref; unsigned long off = (unsigned long) ref & 0x7; unsigned long off_plus_1 = off + 1; int stride_8 = stride + 8; @@ -1723,10 +1699,9 @@ static void MC_put_xy_8_vis (uint8_t * dest, const uint8_t * _ref, } while (--height); } -static void MC_avg_xy_16_vis (uint8_t * dest, const uint8_t * _ref, +static void MC_avg_xy_16_vis (uint8_t * dest, const uint8_t * ref, const int stride, int height) { - uint8_t *ref = (uint8_t *) _ref; unsigned long off = (unsigned long) ref & 0x7; unsigned long off_plus_1 = off + 1; int stride_8 = stride + 8; @@ -1920,10 +1895,9 @@ static void MC_avg_xy_16_vis (uint8_t * dest, const uint8_t * _ref, } while (--height); } -static void MC_avg_xy_8_vis (uint8_t * dest, const uint8_t * _ref, +static void MC_avg_xy_8_vis (uint8_t * dest, const uint8_t * ref, const int stride, int height) { - uint8_t *ref = (uint8_t *) _ref; unsigned long off = (unsigned long) ref & 0x7; unsigned long off_plus_1 = off + 1; int stride_8 = stride + 8; @@ -2064,11 +2038,9 @@ static void MC_avg_xy_8_vis (uint8_t * dest, const uint8_t * _ref, * fpadd16 f12, f10, f10 */ -static void MC_put_no_round_o_16_vis (uint8_t * dest, const uint8_t * _ref, +static void MC_put_no_round_o_16_vis (uint8_t * dest, const uint8_t * ref, const int stride, int height) { - uint8_t *ref = (uint8_t *) _ref; - ref = vis_alignaddr(ref); do { /* 5 cycles */ vis_ld64(ref[0], TMP0); @@ -2087,11 +2059,9 @@ static void MC_put_no_round_o_16_vis (uint8_t * dest, const uint8_t * _ref, } while (--height); } -static void MC_put_no_round_o_8_vis (uint8_t * dest, const uint8_t * _ref, +static void MC_put_no_round_o_8_vis (uint8_t * dest, const uint8_t * ref, const int stride, int height) { - uint8_t *ref = (uint8_t *) _ref; - ref = vis_alignaddr(ref); do { /* 4 cycles */ vis_ld64(ref[0], TMP0); @@ -2108,10 +2078,9 @@ static void MC_put_no_round_o_8_vis (uint8_t * dest, const uint8_t * _ref, } -static void MC_avg_no_round_o_16_vis (uint8_t * dest, const uint8_t * _ref, +static void MC_avg_no_round_o_16_vis (uint8_t * dest, const uint8_t * ref, const int stride, int height) { - uint8_t *ref = (uint8_t *) _ref; int stride_8 = stride + 8; ref = vis_alignaddr(ref); @@ -2269,11 +2238,9 @@ static void MC_avg_no_round_o_16_vis (uint8_t * dest, const uint8_t * _ref, vis_st64_2(TMP22, dest, 8); } -static void MC_avg_no_round_o_8_vis (uint8_t * dest, const uint8_t * _ref, +static void MC_avg_no_round_o_8_vis (uint8_t * dest, const uint8_t * ref, const int stride, int height) { - uint8_t *ref = (uint8_t *) _ref; - ref = vis_alignaddr(ref); vis_ld64(ref[0], TMP0); @@ -2363,10 +2330,9 @@ static void MC_avg_no_round_o_8_vis (uint8_t * dest, const uint8_t * _ref, vis_st64(TMP4, dest[0]); } -static void MC_put_no_round_x_16_vis (uint8_t * dest, const uint8_t * _ref, +static void MC_put_no_round_x_16_vis (uint8_t * dest, const uint8_t * ref, const int stride, int height) { - uint8_t *ref = (uint8_t *) _ref; unsigned long off = (unsigned long) ref & 0x7; unsigned long off_plus_1 = off + 1; @@ -2556,10 +2522,9 @@ static void MC_put_no_round_x_16_vis (uint8_t * dest, const uint8_t * _ref, vis_st64_2(TMP8, dest, 8); } -static void MC_put_no_round_x_8_vis (uint8_t * dest, const uint8_t * _ref, +static void MC_put_no_round_x_8_vis (uint8_t * dest, const uint8_t * ref, const int stride, int height) { - uint8_t *ref = (uint8_t *) _ref; unsigned long off = (unsigned long) ref & 0x7; unsigned long off_plus_1 = off + 1; @@ -2680,10 +2645,9 @@ static void MC_put_no_round_x_8_vis (uint8_t * dest, const uint8_t * _ref, dest += stride; } -static void MC_avg_no_round_x_16_vis (uint8_t * dest, const uint8_t * _ref, +static void MC_avg_no_round_x_16_vis (uint8_t * dest, const uint8_t * ref, const int stride, int height) { - uint8_t *ref = (uint8_t *) _ref; unsigned long off = (unsigned long) ref & 0x7; unsigned long off_plus_1 = off + 1; @@ -2771,10 +2735,9 @@ static void MC_avg_no_round_x_16_vis (uint8_t * dest, const uint8_t * _ref, } while (--height); } -static void MC_avg_no_round_x_8_vis (uint8_t * dest, const uint8_t * _ref, +static void MC_avg_no_round_x_8_vis (uint8_t * dest, const uint8_t * ref, const int stride, int height) { - uint8_t *ref = (uint8_t *) _ref; unsigned long off = (unsigned long) ref & 0x7; unsigned long off_plus_1 = off + 1; int stride_times_2 = stride << 1; @@ -2937,11 +2900,9 @@ static void MC_avg_no_round_x_8_vis (uint8_t * dest, const uint8_t * _ref, } while (--height); } -static void MC_put_no_round_y_16_vis (uint8_t * dest, const uint8_t * _ref, +static void MC_put_no_round_y_16_vis (uint8_t * dest, const uint8_t * ref, const int stride, int height) { - uint8_t *ref = (uint8_t *) _ref; - ref = vis_alignaddr(ref); vis_ld64(ref[0], TMP0); @@ -3093,11 +3054,9 @@ static void MC_put_no_round_y_16_vis (uint8_t * dest, const uint8_t * _ref, vis_st64_2(TMP2, dest, 8); } -static void MC_put_no_round_y_8_vis (uint8_t * dest, const uint8_t * _ref, +static void MC_put_no_round_y_8_vis (uint8_t * dest, const uint8_t * ref, const int stride, int height) { - uint8_t *ref = (uint8_t *) _ref; - ref = vis_alignaddr(ref); vis_ld64(ref[0], TMP0); @@ -3185,10 +3144,9 @@ static void MC_put_no_round_y_8_vis (uint8_t * dest, const uint8_t * _ref, vis_st64(DST_0, dest[0]); } -static void MC_avg_no_round_y_16_vis (uint8_t * dest, const uint8_t * _ref, +static void MC_avg_no_round_y_16_vis (uint8_t * dest, const uint8_t * ref, const int stride, int height) { - uint8_t *ref = (uint8_t *) _ref; int stride_8 = stride + 8; int stride_16 = stride + 16; @@ -3314,10 +3272,9 @@ static void MC_avg_no_round_y_16_vis (uint8_t * dest, const uint8_t * _ref, } while (--height); } -static void MC_avg_no_round_y_8_vis (uint8_t * dest, const uint8_t * _ref, +static void MC_avg_no_round_y_8_vis (uint8_t * dest, const uint8_t * ref, const int stride, int height) { - uint8_t *ref = (uint8_t *) _ref; int stride_8 = stride + 8; vis_set_gsr(5 << VIS_GSR_SCALEFACT_SHIFT); @@ -3394,10 +3351,9 @@ static void MC_avg_no_round_y_8_vis (uint8_t * dest, const uint8_t * _ref, } while (--height); } -static void MC_put_no_round_xy_16_vis (uint8_t * dest, const uint8_t * _ref, +static void MC_put_no_round_xy_16_vis (uint8_t * dest, const uint8_t * ref, const int stride, int height) { - uint8_t *ref = (uint8_t *) _ref; unsigned long off = (unsigned long) ref & 0x7; unsigned long off_plus_1 = off + 1; int stride_8 = stride + 8; @@ -3559,10 +3515,9 @@ static void MC_put_no_round_xy_16_vis (uint8_t * dest, const uint8_t * _ref, } while (--height); } -static void MC_put_no_round_xy_8_vis (uint8_t * dest, const uint8_t * _ref, +static void MC_put_no_round_xy_8_vis (uint8_t * dest, const uint8_t * ref, const int stride, int height) { - uint8_t *ref = (uint8_t *) _ref; unsigned long off = (unsigned long) ref & 0x7; unsigned long off_plus_1 = off + 1; int stride_8 = stride + 8; @@ -3664,10 +3619,9 @@ static void MC_put_no_round_xy_8_vis (uint8_t * dest, const uint8_t * _ref, } while (--height); } -static void MC_avg_no_round_xy_16_vis (uint8_t * dest, const uint8_t * _ref, +static void MC_avg_no_round_xy_16_vis (uint8_t * dest, const uint8_t * ref, const int stride, int height) { - uint8_t *ref = (uint8_t *) _ref; unsigned long off = (unsigned long) ref & 0x7; unsigned long off_plus_1 = off + 1; int stride_8 = stride + 8; @@ -3861,10 +3815,9 @@ static void MC_avg_no_round_xy_16_vis (uint8_t * dest, const uint8_t * _ref, } while (--height); } -static void MC_avg_no_round_xy_8_vis (uint8_t * dest, const uint8_t * _ref, +static void MC_avg_no_round_xy_8_vis (uint8_t * dest, const uint8_t * ref, const int stride, int height) { - uint8_t *ref = (uint8_t *) _ref; unsigned long off = (unsigned long) ref & 0x7; unsigned long off_plus_1 = off + 1; int stride_8 = stride + 8; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/sparc/dsputil_vis.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/sparc/dsputil_vis.h new file mode 100644 index 0000000000..97ff965da2 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/sparc/dsputil_vis.h @@ -0,0 +1,29 @@ +/* + * 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_SPARC_DSPUTIL_VIS_H +#define AVCODEC_SPARC_DSPUTIL_VIS_H + +#include +#include "libavcodec/dsputil.h" + +void ff_simple_idct_put_vis(uint8_t *dest, int line_size, DCTELEM *data); +void ff_simple_idct_add_vis(uint8_t *dest, int line_size, DCTELEM *data); +void ff_simple_idct_vis(DCTELEM *data); + +#endif diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/sparc/simple_idct_vis.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/sparc/simple_idct_vis.c index b78bc664f2..d98bf37651 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/sparc/simple_idct_vis.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/sparc/simple_idct_vis.c @@ -23,8 +23,9 @@ */ #include "libavcodec/dsputil.h" +#include "dsputil_vis.h" -static const DECLARE_ALIGNED_8(int16_t, coeffs[28]) = { +static const DECLARE_ALIGNED(8, int16_t, coeffs)[28] = { - 1259,- 1259,- 1259,- 1259, - 4989,- 4989,- 4989,- 4989, -11045,-11045,-11045,-11045, @@ -33,13 +34,13 @@ static const DECLARE_ALIGNED_8(int16_t, coeffs[28]) = { 25080, 25080, 25080, 25080, 12785, 12785, 12785, 12785 }; -static const DECLARE_ALIGNED_8(uint16_t, scale[4]) = { +static const DECLARE_ALIGNED(8, uint16_t, scale)[4] = { 65536>>6, 65536>>6, 65536>>6, 65536>>6 }; -static const DECLARE_ALIGNED_8(uint16_t, rounder[4]) = { +static const DECLARE_ALIGNED(8, uint16_t, rounder)[4] = { 1<<5, 1<<5, 1<<5, 1<<5 }; -static const DECLARE_ALIGNED_8(uint16_t, expand[4]) = { +static const DECLARE_ALIGNED(8, uint16_t, expand)[4] = { 1<<14, 1<<14, 1<<14, 1<<14 }; @@ -386,7 +387,7 @@ static const DECLARE_ALIGNED_8(uint16_t, expand[4]) = { void ff_simple_idct_vis(DCTELEM *data) { int out1, out2, out3, out4; - DECLARE_ALIGNED_8(int16_t, temp[8*8]); + DECLARE_ALIGNED(8, int16_t, temp)[8*8]; __asm__ volatile( INIT_IDCT diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/sparc/vis.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/sparc/vis.h index 301bebf6b0..adee91bd6f 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/sparc/vis.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/sparc/vis.h @@ -223,9 +223,9 @@ do { register void *__mem __asm__("g1"); \ /* Alignment instructions. */ -static inline void *vis_alignaddr(void *_ptr) +static inline const void *vis_alignaddr(const void *_ptr) { - register void *ptr __asm__("g1"); + register const void *ptr __asm__("g1"); ptr = _ptr; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/sunrast.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/sunrast.c index f5f659604c..456ab85a88 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/sunrast.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/sunrast.c @@ -64,7 +64,7 @@ static int sunrast_decode_frame(AVCodecContext *avctx, void *data, maptype = AV_RB32(buf+24); maplength = AV_RB32(buf+28); - if (type > RT_BYTE_ENCODED && type <= RT_FORMAT_IFF) { + if (type == RT_FORMAT_TIFF || type == RT_FORMAT_IFF) { av_log(avctx, AV_LOG_ERROR, "unsupported (compression) type\n"); return -1; } @@ -87,7 +87,7 @@ static int sunrast_decode_frame(AVCodecContext *avctx, void *data, avctx->pix_fmt = PIX_FMT_PAL8; break; case 24: - avctx->pix_fmt = PIX_FMT_BGR24; + avctx->pix_fmt = (type == RT_FORMAT_RGB) ? PIX_FMT_RGB24 : PIX_FMT_BGR24; break; default: av_log(avctx, AV_LOG_ERROR, "invalid depth\n"); @@ -185,7 +185,7 @@ static av_cold int sunrast_end(AVCodecContext *avctx) { AVCodec sunrast_decoder = { "sunrast", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_SUNRAST, sizeof(SUNRASTContext), sunrast_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/svq1.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/svq1.c index 580b1113f8..d0e113267b 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/svq1.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/svq1.c @@ -26,7 +26,7 @@ */ /** - * @file libavcodec/svq1.c + * @file * Sorenson Vector Quantizer #1 (SVQ1) video codec. * For more information of the SVQ1 algorithm, visit: * http://www.pcisys.net/~melanson/codecs/ @@ -37,7 +37,7 @@ #include "svq1_vlc.h" /* standard video sizes */ -const struct svq1_frame_size ff_svq1_frame_size_table[8] = { +const struct svq1_frame_size ff_svq1_frame_size_table[7] = { { 160, 120 }, { 128, 96 }, { 176, 144 }, { 352, 288 }, - { 704, 576 }, { 240, 180 }, { 320, 240 }, { -1, -1 } + { 704, 576 }, { 240, 180 }, { 320, 240 } }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/svq1.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/svq1.h index bcae245e6e..3ade05d848 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/svq1.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/svq1.h @@ -26,7 +26,7 @@ */ /** - * @file libavcodec/svq1.h + * @file * Sorenson Vector Quantizer #1 (SVQ1) video codec. * For more information of the SVQ1 algorithm, visit: * http://www.pcisys.net/~melanson/codecs/ @@ -43,8 +43,8 @@ #define SVQ1_BLOCK_INTRA 3 struct svq1_frame_size { - int width; - int height; + uint16_t width; + uint16_t height; }; uint16_t ff_svq1_packet_checksum (const uint8_t *data, const int length, @@ -59,6 +59,6 @@ extern const uint8_t ff_svq1_inter_multistage_vlc[6][8][2]; extern const uint16_t ff_svq1_intra_mean_vlc[256][2]; extern const uint16_t ff_svq1_inter_mean_vlc[512][2]; -extern const struct svq1_frame_size ff_svq1_frame_size_table[8]; +extern const struct svq1_frame_size ff_svq1_frame_size_table[7]; #endif /* AVCODEC_SVQ1_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/svq1_cb.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/svq1_cb.h index 592aa84b88..7926ce1377 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/svq1_cb.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/svq1_cb.h @@ -24,7 +24,7 @@ */ /** - * @file libavcodec/svq1_cb.h + * @file * svq1 code books. */ @@ -34,8 +34,10 @@ #include #include +#include "libavutil/mem.h" + /* 6x16-entry codebook for inter-coded 4x2 vectors */ -static const int8_t svq1_inter_codebook_4x2[768] = { +DECLARE_ALIGNED(4, static const int8_t, svq1_inter_codebook_4x2)[768] = { 7, 2, -6, -7, 7, 3, -3, -4, -7, -2, 7, 8, -8, -4, 3, 4, 19, 17, 9, 3,-14,-16,-12, -8,-18,-16, -8, -3, 11, 14, 12, 8, 7,-16,-10, 20, 7,-17,-10, 20, -6, 18, 8,-21, -7, 18, 9,-20, @@ -87,7 +89,7 @@ static const int8_t svq1_inter_codebook_4x2[768] = { }; /* 6x16-entry codebook for inter-coded 4x4 vectors */ -static const int8_t svq1_inter_codebook_4x4[1536] = { +DECLARE_ALIGNED(4, static const int8_t, svq1_inter_codebook_4x4)[1536] = { 4, 0, -6, -7, -4, -8,-13, -9, -8, -8, -1, 6, -2, 5, 22, 27, -16, -7, 11, 10,-18, -7, 13, 10,-15, -4, 12, 8, -9, -1, 9, 5, -2, 2, 15,-16, -3, 2, 19,-19, -3, 2, 19,-19, -2, 3, 15,-14, @@ -187,7 +189,7 @@ static const int8_t svq1_inter_codebook_4x4[1536] = { }; /* 6x16-entry codebook for inter-coded 8x4 vectors */ -static const int8_t svq1_inter_codebook_8x4[3072] = { +DECLARE_ALIGNED(4, static const int8_t, svq1_inter_codebook_8x4)[3072] = { 9, 8, 4, 0, -3, -4, -4, -3, 9, 8, 4, -1, -4, -5, -5, -3, 8, 7, 3, -2, -5, -5, -5, -4, 6, 4, 1, -2, -4, -5, -4, -3, -12,-14,-11, -4, 1, 5, 6, 6, -8,-10, -7, -5, -2, 1, 1, 1, @@ -383,7 +385,7 @@ static const int8_t svq1_inter_codebook_8x4[3072] = { }; /* 6x16-entry codebook for inter-coded 8x8 vectors */ -static const int8_t svq1_inter_codebook_8x8[6144] = { +DECLARE_ALIGNED(4, static const int8_t, svq1_inter_codebook_8x8)[6144] = { -4, -3, 4, 5, 2, 1, 1, 0, -5, -3, 5, 5, 2, 1, 0, 0, -6, -4, 5, 5, 2, 1, 0, 0, -7, -4, 4, 5, 2, 1, 0, 0, -8, -5, 3, 4, 2, 1, 0, 0, -8, -6, 3, 4, 1, 1, 1, 0, @@ -778,7 +780,7 @@ const int8_t* const ff_svq1_inter_codebooks[6] = { }; /* 6x16-entry codebook for intra-coded 4x2 vectors */ -static const int8_t svq1_intra_codebook_4x2[768] = { +DECLARE_ALIGNED(4, static const int8_t, svq1_intra_codebook_4x2)[768] = { 12, 13, 13, 11, -7,-10,-15,-17,-16,-15,-12,-10, 11, 15, 15, 12, 2, 17, 20, 15,-45,-24, 2, 13, 21, 20, -6,-36, 12, 16, -1,-27, -18,-21, 10, 45,-11,-20, -7, 21, 43, -8,-28, 0, 33,-16,-28, 3, @@ -830,7 +832,7 @@ static const int8_t svq1_intra_codebook_4x2[768] = { }; /* 6x16-entry codebook for intra-coded 4x4 vectors */ -static const int8_t svq1_intra_codebook_4x4[1536] = { +DECLARE_ALIGNED(4, static const int8_t, svq1_intra_codebook_4x4)[1536] = { -11, -3, 3, 6,-10, -1, 5, 7, -9, -1, 6, 7, -9, -1, 4, 6, 5, 7, 0,-14, 6, 9, 2,-15, 6, 9, 2,-15, 4, 6, 0,-14, 16, 3, -5, -6, 16, 1, -8, -8, 14, -1, -9, -9, 12, 0, -8, -8, @@ -930,7 +932,7 @@ static const int8_t svq1_intra_codebook_4x4[1536] = { }; /* 6x16-entry codebook for intra-coded 8x4 vectors */ -static const int8_t svq1_intra_codebook_8x4[3072] = { +DECLARE_ALIGNED(4, static const int8_t, svq1_intra_codebook_8x4)[3072] = { 5, 6, 6, 6, 7, 7, 8, 8, 0, 0, 0, 0, 0, 1, 2, 3, -3, -4, -4, -5, -5, -4, -3, -2, -4, -4, -4, -5, -4, -4, -3, -3, 1, 2, 2, 2, 2, 3, 3, 3, 2, 3, 3, 4, 4, 5, 5, 5, @@ -1126,7 +1128,7 @@ static const int8_t svq1_intra_codebook_8x4[3072] = { }; /* 6x16-entry codebook for intra-coded 8x8 vectors */ -static const int8_t svq1_intra_codebook_8x8[6144] = { +DECLARE_ALIGNED(4, static const int8_t, svq1_intra_codebook_8x8)[6144] = { 4, 4, 3, 2, 2, 1, 0, -1, 4, 3, 3, 2, 1, 0, -1, -1, 3, 3, 2, 2, 1, 0, -1, -2, 3, 2, 2, 1, 0, -1, -2, -3, 2, 2, 1, 0, -1, -1, -2, -3, 2, 1, 0, 0, -1, -2, -3, -4, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/svq1dec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/svq1dec.c index 3d7749d4e4..2aa28ab0b0 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/svq1dec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/svq1dec.c @@ -26,7 +26,7 @@ */ /** - * @file libavcodec/svq1.c + * @file * Sorenson Vector Quantizer #1 (SVQ1) video codec. * For more information of the SVQ1 algorithm, visit: * http://www.pcisys.net/~melanson/codecs/ @@ -768,6 +768,7 @@ static av_cold int svq1_decode_init(AVCodecContext *avctx) { MpegEncContext *s = avctx->priv_data; int i; + int offset = 0; MPV_decode_defaults(s); @@ -780,30 +781,38 @@ static av_cold int svq1_decode_init(AVCodecContext *avctx) s->flags= avctx->flags; if (MPV_common_init(s) < 0) return -1; - init_vlc(&svq1_block_type, 2, 4, + INIT_VLC_STATIC(&svq1_block_type, 2, 4, &ff_svq1_block_type_vlc[0][1], 2, 1, - &ff_svq1_block_type_vlc[0][0], 2, 1, INIT_VLC_USE_STATIC); + &ff_svq1_block_type_vlc[0][0], 2, 1, 6); - init_vlc(&svq1_motion_component, 7, 33, + INIT_VLC_STATIC(&svq1_motion_component, 7, 33, &mvtab[0][1], 2, 1, - &mvtab[0][0], 2, 1, INIT_VLC_USE_STATIC); + &mvtab[0][0], 2, 1, 176); for (i = 0; i < 6; i++) { + static const uint8_t sizes[2][6] = {{14, 10, 14, 18, 16, 18}, {10, 10, 14, 14, 14, 16}}; + static VLC_TYPE table[168][2]; + svq1_intra_multistage[i].table = &table[offset]; + svq1_intra_multistage[i].table_allocated = sizes[0][i]; + offset += sizes[0][i]; init_vlc(&svq1_intra_multistage[i], 3, 8, &ff_svq1_intra_multistage_vlc[i][0][1], 2, 1, - &ff_svq1_intra_multistage_vlc[i][0][0], 2, 1, INIT_VLC_USE_STATIC); + &ff_svq1_intra_multistage_vlc[i][0][0], 2, 1, INIT_VLC_USE_NEW_STATIC); + svq1_inter_multistage[i].table = &table[offset]; + svq1_inter_multistage[i].table_allocated = sizes[1][i]; + offset += sizes[1][i]; init_vlc(&svq1_inter_multistage[i], 3, 8, &ff_svq1_inter_multistage_vlc[i][0][1], 2, 1, - &ff_svq1_inter_multistage_vlc[i][0][0], 2, 1, INIT_VLC_USE_STATIC); + &ff_svq1_inter_multistage_vlc[i][0][0], 2, 1, INIT_VLC_USE_NEW_STATIC); } - init_vlc(&svq1_intra_mean, 8, 256, + INIT_VLC_STATIC(&svq1_intra_mean, 8, 256, &ff_svq1_intra_mean_vlc[0][1], 4, 2, - &ff_svq1_intra_mean_vlc[0][0], 4, 2, INIT_VLC_USE_STATIC); + &ff_svq1_intra_mean_vlc[0][0], 4, 2, 632); - init_vlc(&svq1_inter_mean, 9, 512, + INIT_VLC_STATIC(&svq1_inter_mean, 9, 512, &ff_svq1_inter_mean_vlc[0][1], 4, 2, - &ff_svq1_inter_mean_vlc[0][0], 4, 2, INIT_VLC_USE_STATIC); + &ff_svq1_inter_mean_vlc[0][0], 4, 2, 1434); return 0; } @@ -819,7 +828,7 @@ static av_cold int svq1_decode_end(AVCodecContext *avctx) AVCodec svq1_decoder = { "svq1", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_SVQ1, sizeof(MpegEncContext), svq1_decode_init, @@ -828,6 +837,6 @@ AVCodec svq1_decoder = { svq1_decode_frame, CODEC_CAP_DR1, .flush= ff_mpeg_flush, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV410P, PIX_FMT_NONE}, - .long_name= NULL_IF_CONFIG_SMALL("Sorenson Vector Quantizer 1"), + .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/src/add-ons/media/plugins/ffmpeg/libavcodec/svq1enc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/svq1enc.c index 357f39d887..c89be259d7 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/svq1enc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/svq1enc.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/svq1enc.c + * @file * Sorenson Vector Quantizer #1 (SVQ1) video codec. * For more information of the SVQ1 algorithm, visit: * http://www.pcisys.net/~melanson/codecs/ @@ -30,6 +30,8 @@ #include "avcodec.h" #include "dsputil.h" #include "mpegvideo.h" +#include "h263.h" +#include "internal.h" #include "svq1.h" #include "svq1enc_cb.h" @@ -93,19 +95,11 @@ static void svq1_write_header(SVQ1Context *s, int frame_type) /* output 5 unknown bits (2 + 2 + 1) */ put_bits(&s->pb, 5, 2); /* 2 needed by quicktime decoder */ - for (i = 0; i < 7; i++) - { - if ((ff_svq1_frame_size_table[i].width == s->frame_width) && - (ff_svq1_frame_size_table[i].height == s->frame_height)) - { - put_bits(&s->pb, 3, i); - break; - } - } + i= ff_match_2uint16(ff_svq1_frame_size_table, FF_ARRAY_ELEMS(ff_svq1_frame_size_table), s->frame_width, s->frame_height); + put_bits(&s->pb, 3, i); if (i == 7) { - put_bits(&s->pb, 3, 7); put_bits(&s->pb, 12, s->frame_width); put_bits(&s->pb, 12, s->frame_height); } @@ -275,6 +269,7 @@ static int svq1_encode_plane(SVQ1Context *s, int plane, unsigned char *src_plane int block_width, block_height; int level; int threshold[6]; + uint8_t *src = s->scratchbuf + stride * 16; const int lambda= (s->picture.quality*s->picture.quality) >> (2*FF_LAMBDA_SHIFT); /* figure out the acceptable level thresholds in advance */ @@ -333,8 +328,6 @@ 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++) { - uint8_t src[stride*16]; - s->m.new_picture.data[0]= src - y*16*stride; //ugly s->m.mb_y= y; @@ -362,8 +355,6 @@ static int svq1_encode_plane(SVQ1Context *s, int plane, unsigned char *src_plane s->m.first_slice_line=1; for (y = 0; y < block_height; y++) { - uint8_t src[stride*16]; - for(i=0; i<16 && i + 16*ycurrent_picture.data[0]){ avctx->get_buffer(avctx, &s->current_picture); avctx->get_buffer(avctx, &s->last_picture); - s->scratchbuf = av_malloc(s->current_picture.linesize[0] * 16); + s->scratchbuf = av_malloc(s->current_picture.linesize[0] * 16 * 2); } temp= s->current_picture; @@ -583,12 +574,12 @@ static av_cold int svq1_encode_end(AVCodecContext *avctx) AVCodec svq1_encoder = { "svq1", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_SVQ1, sizeof(SVQ1Context), svq1_encode_init, svq1_encode_frame, svq1_encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV410P, PIX_FMT_NONE}, - .long_name= NULL_IF_CONFIG_SMALL("Sorenson Vector Quantizer 1"), + .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/src/add-ons/media/plugins/ffmpeg/libavcodec/svq1enc_cb.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/svq1enc_cb.h index 0c11d2fd37..7eff82ee1f 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/svq1enc_cb.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/svq1enc_cb.h @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/svq1enc_cb.h + * @file * svq1 code books. */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/svq3.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/svq3.c index fc35b5f817..bf7659a80e 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/svq3.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/svq3.c @@ -39,6 +39,18 @@ * correctly decodes this file: * http://samples.mplayerhq.hu/V-codecs/SVQ3/Vertical400kbit.sorenson3.mov */ +#include "internal.h" +#include "dsputil.h" +#include "avcodec.h" +#include "mpegvideo.h" +#include "h264.h" + +#include "h264data.h" //FIXME FIXME FIXME + +#include "h264_mvpred.h" +#include "golomb.h" +#include "rectangle.h" +#include "vdpau_internal.h" #if CONFIG_ZLIB #include @@ -47,7 +59,7 @@ #include "svq1.h" /** - * @file libavcodec/svq3.c + * @file * svq3 decoder. */ @@ -114,7 +126,7 @@ static const uint32_t svq3_dequant_coeff[32] = { }; -static void svq3_luma_dc_dequant_idct_c(DCTELEM *block, int qp) +void ff_svq3_luma_dc_dequant_idct_c(DCTELEM *block, int qp) { const int qmul = svq3_dequant_coeff[qp]; #define stride 16 @@ -151,7 +163,7 @@ static void svq3_luma_dc_dequant_idct_c(DCTELEM *block, int qp) } #undef stride -static void svq3_add_idct_c(uint8_t *dst, DCTELEM *block, int stride, int qp, +void ff_svq3_add_idct_c(uint8_t *dst, DCTELEM *block, int stride, int qp, int dc) { const int qmul = svq3_dequant_coeff[qp]; @@ -466,7 +478,7 @@ static int svq3_decode_mb(H264Context *h, unsigned int mb_type) */ for (m = 0; m < 2; m++) { - if (s->mb_x > 0 && h->intra4x4_pred_mode[mb_xy - 1][0] != -1) { + 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]; } @@ -477,18 +489,18 @@ static int svq3_decode_mb(H264Context *h, 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)); - memset(&h->ref_cache[m][scan8[0] - 1*8], (h->intra4x4_pred_mode[mb_xy - s->mb_stride][4] == -1) ? PART_NOT_AVAILABLE : 1, 4); + 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]; h->ref_cache[m][scan8[0] + 4 - 1*8] = - (h->intra4x4_pred_mode[mb_xy - s->mb_stride + 1][0] == -1 || - h->intra4x4_pred_mode[mb_xy - s->mb_stride ][4] == -1) ? PART_NOT_AVAILABLE : 1; + (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]; - h->ref_cache[m][scan8[0] - 1 - 1*8] = (h->intra4x4_pred_mode[mb_xy - s->mb_stride - 1][3] == -1) ? PART_NOT_AVAILABLE : 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; }else @@ -528,17 +540,17 @@ static int svq3_decode_mb(H264Context *h, unsigned int mb_type) if (mb_type == 8) { if (s->mb_x > 0) { for (i = 0; i < 4; i++) { - h->intra4x4_pred_mode_cache[scan8[0] - 1 + i*8] = h->intra4x4_pred_mode[mb_xy - 1][i]; + h->intra4x4_pred_mode_cache[scan8[0] - 1 + i*8] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - 1]+6-i]; } if (h->intra4x4_pred_mode_cache[scan8[0] - 1] == -1) { h->left_samples_available = 0x5F5F; } } if (s->mb_y > 0) { - h->intra4x4_pred_mode_cache[4+8*0] = h->intra4x4_pred_mode[mb_xy - s->mb_stride][4]; - h->intra4x4_pred_mode_cache[5+8*0] = h->intra4x4_pred_mode[mb_xy - s->mb_stride][5]; - h->intra4x4_pred_mode_cache[6+8*0] = h->intra4x4_pred_mode[mb_xy - s->mb_stride][6]; - h->intra4x4_pred_mode_cache[7+8*0] = h->intra4x4_pred_mode[mb_xy - s->mb_stride][3]; + h->intra4x4_pred_mode_cache[4+8*0] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride]+0]; + h->intra4x4_pred_mode_cache[5+8*0] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride]+1]; + h->intra4x4_pred_mode_cache[6+8*0] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride]+2]; + h->intra4x4_pred_mode_cache[7+8*0] = h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride]+3]; if (h->intra4x4_pred_mode_cache[4+8*0] == -1) { h->top_samples_available = 0x33FF; @@ -571,10 +583,10 @@ static int svq3_decode_mb(H264Context *h, unsigned int mb_type) } } - write_back_intra_pred_mode(h); + ff_h264_write_back_intra_pred_mode(h); if (mb_type == 8) { - check_intra4x4_pred_mode(h); + ff_h264_check_intra4x4_pred_mode(h); h->top_samples_available = (s->mb_y == 0) ? 0x33FF : 0xFFFF; h->left_samples_available = (s->mb_x == 0) ? 0x5F5F : 0xFFFF; @@ -592,7 +604,7 @@ static int svq3_decode_mb(H264Context *h, 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 = check_intra_pred_mode(h, dir)) == -1){ + if ((h->intra16x16_pred_mode = ff_h264_check_intra_pred_mode(h, dir)) == -1){ av_log(h->s.avctx, AV_LOG_ERROR, "check_intra_pred_mode = -1\n"); return -1; } @@ -612,7 +624,7 @@ static int svq3_decode_mb(H264Context *h, unsigned int mb_type) } } if (!IS_INTRA4x4(mb_type)) { - memset(h->intra4x4_pred_mode[mb_xy], DC_PRED, 8); + memset(h->intra4x4_pred_mode+h->mb2br_xy[mb_xy], DC_PRED, 8); } if (!IS_SKIP(mb_type) || s->pict_type == FF_B_TYPE) { memset(h->non_zero_count_cache + 8, 0, 4*9*sizeof(uint8_t)); @@ -685,7 +697,7 @@ static int svq3_decode_mb(H264Context *h, unsigned int mb_type) s->current_picture.mb_type[mb_xy] = mb_type; if (IS_INTRA(mb_type)) { - h->chroma_pred_mode = check_intra_pred_mode(h, DC_PRED8x8); + h->chroma_pred_mode = ff_h264_check_intra_pred_mode(h, DC_PRED8x8); } return 0; @@ -762,14 +774,14 @@ static int svq3_decode_slice_header(H264Context *h) /* reset intra predictors and invalidate motion vector references */ if (s->mb_x > 0) { - memset(h->intra4x4_pred_mode[mb_xy - 1], -1, 4*sizeof(int8_t)); - memset(h->intra4x4_pred_mode[mb_xy - s->mb_x], -1, 8*sizeof(int8_t)*s->mb_x); + memset(h->intra4x4_pred_mode+h->mb2br_xy[mb_xy - 1 ]+3, -1, 4*sizeof(int8_t)); + memset(h->intra4x4_pred_mode+h->mb2br_xy[mb_xy - s->mb_x] , -1, 8*sizeof(int8_t)*s->mb_x); } if (s->mb_y > 0) { - memset(h->intra4x4_pred_mode[mb_xy - s->mb_stride], -1, 8*sizeof(int8_t)*(s->mb_width - s->mb_x)); + memset(h->intra4x4_pred_mode+h->mb2br_xy[mb_xy - s->mb_stride], -1, 8*sizeof(int8_t)*(s->mb_width - s->mb_x)); if (s->mb_x > 0) { - h->intra4x4_pred_mode[mb_xy - s->mb_stride - 1][3] = -1; + h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride - 1]+3] = -1; } } @@ -784,13 +796,19 @@ static av_cold int svq3_decode_init(AVCodecContext *avctx) unsigned char *extradata; unsigned int size; - if (decode_init(avctx) < 0) + if(avctx->thread_count > 1){ + av_log(avctx, AV_LOG_ERROR, "SVQ3 does not support multithreaded decoding, patch welcome! (check latest SVN too)\n"); + return -1; + } + + if (ff_h264_decode_init(avctx) < 0) return -1; s->flags = avctx->flags; s->flags2 = avctx->flags2; s->unrestricted_mv = 1; h->is_complex=1; + avctx->pix_fmt = avctx->codec->pix_fmts[0]; if (!s->context_initialized) { s->width = avctx->width; @@ -805,7 +823,7 @@ static av_cold int svq3_decode_init(AVCodecContext *avctx) h->b_stride = 4*s->mb_width; - alloc_tables(h); + ff_h264_alloc_tables(h); /* prowl for the "SEQH" marker in the extradata */ extradata = (unsigned char *)avctx->extradata; @@ -959,7 +977,7 @@ static int svq3_decode_frame(AVCodecContext *avctx, s->next_p_frame_damaged = 0; } - if (frame_start(h) < 0) + if (ff_h264_frame_start(h) < 0) return -1; if (s->pict_type == FF_B_TYPE) { @@ -1022,7 +1040,7 @@ static int svq3_decode_frame(AVCodecContext *avctx, } if (mb_type != 0) { - hl_decode_mb (h); + ff_h264_hl_decode_mb (h); } if (s->pict_type != FF_B_TYPE && !s->low_delay) { @@ -1053,14 +1071,14 @@ static int svq3_decode_frame(AVCodecContext *avctx, AVCodec svq3_decoder = { "svq3", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_SVQ3, sizeof(H264Context), svq3_decode_init, NULL, - decode_end, + ff_h264_decode_end, svq3_decode_frame, CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_DELAY, - .long_name = NULL_IF_CONFIG_SMALL("Sorenson Vector Quantizer 3"), - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUVJ420P, PIX_FMT_NONE}, + .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/src/add-ons/media/plugins/ffmpeg/libavcodec/synth_filter.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/synth_filter.c new file mode 100644 index 0000000000..a0ae364d79 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/synth_filter.c @@ -0,0 +1,64 @@ +/* + * copyright (c) 2008 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 + */ + +#include "fft.h" +#include "synth_filter.h" + +static void synth_filter_float(FFTContext *imdct, + float *synth_buf_ptr, int *synth_buf_offset, + float synth_buf2[32], const float window[512], + float out[32], const float in[32], float scale, float bias) +{ + float *synth_buf= synth_buf_ptr + *synth_buf_offset; + int i, j; + + ff_imdct_half(imdct, synth_buf, in); + + for (i = 0; i < 16; i++){ + float a= synth_buf2[i ]; + float b= synth_buf2[i + 16]; + float c= 0; + float d= 0; + for (j = 0; j < 512 - *synth_buf_offset; j += 64){ + a += window[i + j ]*(-synth_buf[15 - i + j ]); + b += window[i + j + 16]*( synth_buf[ i + j ]); + c += window[i + j + 32]*( synth_buf[16 + i + j ]); + d += window[i + j + 48]*( synth_buf[31 - i + j ]); + } + for ( ; j < 512; j += 64){ + a += window[i + j ]*(-synth_buf[15 - i + j - 512]); + b += window[i + j + 16]*( synth_buf[ i + j - 512]); + c += window[i + j + 32]*( synth_buf[16 + i + j - 512]); + d += window[i + j + 48]*( synth_buf[31 - i + j - 512]); + } + out[i ] = a*scale + bias; + out[i + 16] = b*scale + bias; + synth_buf2[i ] = c; + synth_buf2[i + 16] = d; + } + *synth_buf_offset= (*synth_buf_offset - 32)&511; +} + +av_cold void ff_synth_filter_init(SynthFilterContext *c) +{ + c->synth_filter_float = synth_filter_float; + + if (ARCH_ARM) ff_synth_filter_init_arm(c); +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/synth_filter.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/synth_filter.h new file mode 100644 index 0000000000..d6209d5dba --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/synth_filter.h @@ -0,0 +1,37 @@ +/* + * copyright (c) 2008 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 + */ + +#ifndef AVCODEC_SYNTH_FILTER_H +#define AVCODEC_SYNTH_FILTER_H + +#include "fft.h" + +typedef struct SynthFilterContext { + void (*synth_filter_float)(FFTContext *imdct, + float *synth_buf_ptr, int *synth_buf_offset, + float synth_buf2[32], const float window[512], + float out[32], const float in[32], + float scale, float bias); +} SynthFilterContext; + +void ff_synth_filter_init(SynthFilterContext *c); +void ff_synth_filter_init_arm(SynthFilterContext *c); + +#endif /* AVCODEC_SYNTH_FILTER_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/tableprint.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/tableprint.c new file mode 100644 index 0000000000..e39606bb15 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/tableprint.c @@ -0,0 +1,40 @@ +/* + * Generate a file for hardcoded tables + * + * Copyright (c) 2009 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 +#include +#include "tableprint.h" + +WRITE_1D_FUNC(int8, int8_t, "%3"PRIi8, 15) +WRITE_1D_FUNC(uint8, uint8_t, "0x%02"PRIx8, 15) +WRITE_1D_FUNC(uint16, uint16_t, "0x%08"PRIx16, 7) +WRITE_1D_FUNC(uint32, uint32_t, "0x%08"PRIx32, 7) +WRITE_1D_FUNC(float, float, "%.18e", 3) + +WRITE_2D_FUNC(int8, int8_t) +WRITE_2D_FUNC(uint8, uint8_t) +WRITE_2D_FUNC(uint32, uint32_t) + +void write_fileheader(void) { + printf("/* This file was generated by libavcodec/tableprint */\n"); + printf("#include \n"); +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/tableprint.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/tableprint.h new file mode 100644 index 0000000000..d81af97e95 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/tableprint.h @@ -0,0 +1,74 @@ +/* + * Generate a file for hardcoded tables + * + * Copyright (c) 2009 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 + */ + +#ifndef AVCODEC_TABLEPRINT_H +#define AVCODEC_TABLEPRINT_H + +#include +#include + +#define WRITE_1D_FUNC_ARGV(name, type, linebrk, fmtstr, ...)\ +void write_##name##_array(const type *data, int len)\ +{\ + int i;\ + printf(" ");\ + for (i = 0; i < len - 1; i++) {\ + printf(" "fmtstr",", __VA_ARGS__);\ + if ((i & linebrk) == linebrk) printf("\n ");\ + }\ + printf(" "fmtstr"\n", __VA_ARGS__);\ +} + +#define WRITE_1D_FUNC(name, type, fmtstr, linebrk)\ + WRITE_1D_FUNC_ARGV(name, type, linebrk, fmtstr, data[i]) + +#define WRITE_2D_FUNC(name, type)\ +void write_##name##_2d_array(const void *arg, int len, int len2)\ +{\ + const type *data = arg;\ + int i;\ + printf(" {\n");\ + for (i = 0; i < len; i++) {\ + write_##name##_array(data + i * len2, len2);\ + printf(i == len - 1 ? " }\n" : " }, {\n");\ + }\ +} + +/** + * \defgroup printfuncs Predefined functions for printing tables + * + * \{ + */ +void write_int8_array (const int8_t *, int); +void write_uint8_array (const uint8_t *, int); +void write_uint16_array (const uint16_t *, int); +void write_uint32_array (const uint32_t *, int); +void write_float_array (const float *, int); +void write_int8_2d_array (const void *, int, int); +void write_uint8_2d_array (const void *, int, int); +void write_uint32_2d_array(const void *, int, int); +/** \} */ // end of printfuncs group + +/** Write a standard file header */ +void write_fileheader(void); + +#endif /* AVCODEC_TABLEPRINT_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/targa.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/targa.c index 3e7903ae52..50fe107ea9 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/targa.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/targa.c @@ -189,7 +189,6 @@ static int decode_frame(AVCodecContext *avctx, *pal++ = (b << 16) | (g << 8) | r; } p->palette_has_changed = 1; - avctx->palctrl->palette_changed = 0; } } if((compr & (~TGA_RLE)) == TGA_NODATA) @@ -244,7 +243,7 @@ static av_cold int targa_end(AVCodecContext *avctx){ AVCodec targa_decoder = { "targa", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_TARGA, sizeof(TargaContext), targa_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/targaenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/targaenc.c index 21747bb368..e5d0042ecb 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/targaenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/targaenc.c @@ -76,7 +76,7 @@ static int targa_encode_frame(AVCodecContext *avctx, unsigned char *outbuf, int buf_size, void *data){ AVFrame *p = data; - int bpp, picsize, datasize; + int bpp, picsize, datasize = -1; uint8_t *out; if(avctx->width > 0xffff || avctx->height > 0xffff) { @@ -104,7 +104,7 @@ static int targa_encode_frame(AVCodecContext *avctx, outbuf[2] = 3; /* uncompressed grayscale image */ outbuf[16] = 8; /* bpp */ break; - case PIX_FMT_RGB555: + case PIX_FMT_RGB555LE: outbuf[2] = 2; /* uncompresses true-color image */ outbuf[16] = 16; /* bpp */ break; @@ -120,7 +120,8 @@ static int targa_encode_frame(AVCodecContext *avctx, out = outbuf + 18; /* skip past the header we just output */ /* try RLE compression */ - datasize = targa_encode_rle(out, picsize, p, bpp, avctx->width, avctx->height); + if (avctx->coder_type != FF_CODER_TYPE_RAW) + datasize = targa_encode_rle(out, picsize, p, bpp, avctx->width, avctx->height); /* if that worked well, mark the picture as RLE compressed */ if(datasize >= 0) @@ -152,11 +153,11 @@ static av_cold int targa_encode_init(AVCodecContext *avctx) AVCodec targa_encoder = { .name = "targa", - .type = CODEC_TYPE_VIDEO, + .type = AVMEDIA_TYPE_VIDEO, .id = CODEC_ID_TARGA, .priv_data_size = sizeof(TargaContext), .init = targa_encode_init, .encode = targa_encode_frame, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_BGR24, PIX_FMT_RGB555, PIX_FMT_GRAY8, PIX_FMT_NONE}, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_BGR24, PIX_FMT_RGB555LE, PIX_FMT_GRAY8, PIX_FMT_NONE}, .long_name= NULL_IF_CONFIG_SMALL("Truevision Targa image"), }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/tiertexseqv.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/tiertexseqv.c index 66055937fe..c5f632e186 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/tiertexseqv.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/tiertexseqv.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/tiertexseqv.c + * @file * Tiertex Limited SEQ video decoder */ @@ -221,7 +221,7 @@ static av_cold int seqvideo_decode_end(AVCodecContext *avctx) AVCodec tiertexseqvideo_decoder = { "tiertexseqvideo", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_TIERTEXSEQVIDEO, sizeof(SeqVideoContext), seqvideo_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/tiff.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/tiff.c index 720a6cf622..2f3cef2b00 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/tiff.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/tiff.c @@ -21,7 +21,7 @@ /** * TIFF image decoder - * @file libavcodec/tiff.c + * @file * @author Konstantin Shishkov */ #include "avcodec.h" @@ -31,7 +31,8 @@ #include "lzw.h" #include "tiff.h" #include "faxcompr.h" - +#include "libavutil/common.h" +#include "libavutil/intreadwrite.h" typedef struct TiffContext { AVCodecContext *avctx; @@ -44,6 +45,7 @@ typedef struct TiffContext { int invert; int fax_opts; int predictor; + int fill_order; int strips, rps, sstype; int sot; @@ -74,6 +76,29 @@ static int tget(const uint8_t **p, int type, int le){ } } +#if CONFIG_ZLIB +static int tiff_uncompress(uint8_t *dst, unsigned long *len, const uint8_t *src, int size) +{ + z_stream zstream; + int zret; + + memset(&zstream, 0, sizeof(zstream)); + zstream.next_in = src; + zstream.avail_in = size; + zstream.next_out = dst; + zstream.avail_out = *len; + zret = inflateInit(&zstream); + if (zret != Z_OK) { + av_log(NULL, AV_LOG_ERROR, "Inflate init error: %d\n", zret); + return zret; + } + zret = inflate(&zstream, Z_SYNC_FLUSH); + inflateEnd(&zstream); + *len = zstream.total_out; + return zret == Z_STREAM_END ? Z_OK : zret; +} +#endif + 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; @@ -82,10 +107,12 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uin uint8_t *zbuf; unsigned long outlen; if(s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE){ + int ret; outlen = width * lines; zbuf = av_malloc(outlen); - if(uncompress(zbuf, &outlen, src, size) != Z_OK){ - av_log(s->avctx, AV_LOG_ERROR, "Uncompressing failed (%lu of %lu)\n", outlen, (unsigned long)width * lines); + ret = tiff_uncompress(zbuf, &outlen, src, size); + if(ret != Z_OK){ + av_log(s->avctx, AV_LOG_ERROR, "Uncompressing failed (%lu of %lu) with error %d\n", outlen, (unsigned long)width * lines, ret); av_free(zbuf); return -1; } @@ -113,16 +140,23 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uin av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n"); return -1; } - for(i = 0; i < size; i++) - src2[i] = ff_reverse[src[i]]; + if(s->fax_opts & 2){ + av_log(s->avctx, AV_LOG_ERROR, "Uncompressed fax mode is not supported (yet)\n"); + av_free(src2); + return -1; + } + if(!s->fill_order){ + memcpy(src2, src, size); + }else{ + for(i = 0; i < size; i++) + src2[i] = av_reverse[src[i]]; + } memset(src2+size, 0, FF_INPUT_BUFFER_PADDING_SIZE); - if(s->compr == TIFF_G3 && !(s->fax_opts & 1)) - s->compr = TIFF_CCITT_RLE; switch(s->compr){ case TIFF_CCITT_RLE: case TIFF_G3: case TIFF_G4: - ret = ff_ccitt_unpack(s->avctx, src2, size, dst, lines, stride, s->compr); + ret = ff_ccitt_unpack(s->avctx, src2, size, dst, lines, stride, s->compr, s->fax_opts); break; } av_free(src2); @@ -375,6 +409,13 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t * return -1; } break; + case TIFF_FILL_ORDER: + if(value < 1 || value > 2){ + av_log(s->avctx, AV_LOG_ERROR, "Unknown FillOrder value %d, trying default one\n", value); + value = 1; + } + s->fill_order = value - 1; + break; case TIFF_PAL: if(s->avctx->pix_fmt != PIX_FMT_PAL8){ av_log(s->avctx, AV_LOG_ERROR, "Palette met but this is not palettized format\n"); @@ -400,8 +441,12 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t * } break; case TIFF_T4OPTIONS: + if(s->compr == TIFF_G3) + s->fax_opts = value; + break; case TIFF_T6OPTIONS: - s->fax_opts = value; + if(s->compr == TIFF_G4) + s->fax_opts = value; break; } return 0; @@ -433,6 +478,7 @@ static int decode_frame(AVCodecContext *avctx, s->le = le; s->invert = 0; s->compr = TIFF_RAW; + s->fill_order = 0; // As TIFF 6.0 specification puts it "An arbitrary but carefully chosen number // that further identifies the file as a TIFF file" if(tget_short(&buf, le) != 42){ @@ -458,8 +504,19 @@ static int decode_frame(AVCodecContext *avctx, } /* now we have the data and may start decoding */ if(!p->data[0]){ - av_log(s->avctx, AV_LOG_ERROR, "Picture initialization missing\n"); - return -1; + s->bpp = 1; + avctx->pix_fmt = PIX_FMT_MONOBLACK; + if(s->width != s->avctx->width || s->height != s->avctx->height){ + if(avcodec_check_dimensions(s->avctx, s->width, s->height)) + return -1; + avcodec_set_dimensions(s->avctx, s->width, s->height); + } + if(s->picture.data[0]) + s->avctx->release_buffer(s->avctx, &s->picture); + if(s->avctx->get_buffer(s->avctx, &s->picture) < 0){ + av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } } if(s->strips == 1 && !s->stripsize){ av_log(avctx, AV_LOG_WARNING, "Image data size missing\n"); @@ -535,7 +592,7 @@ static av_cold int tiff_end(AVCodecContext *avctx) AVCodec tiff_decoder = { "tiff", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_TIFF, sizeof(TiffContext), tiff_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/tiff.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/tiff.h index e53c6e85f3..235a998fcd 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/tiff.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/tiff.h @@ -21,7 +21,7 @@ /** * TIFF tables - * @file libavcodec/tiff.h + * @file * @author Konstantin Shishkov */ #ifndef AVCODEC_TIFF_H @@ -37,6 +37,7 @@ enum TiffTags{ TIFF_BPP, TIFF_COMPR, TIFF_INVERT = 0x106, + TIFF_FILL_ORDER = 0x10A, TIFF_STRIP_OFFS = 0x111, TIFF_SAMPLES_PER_PIXEL = 0x115, TIFF_ROWSPERSTRIP = 0x116, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/tiffenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/tiffenc.c index 3d0619620b..0905ceae19 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/tiffenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/tiffenc.c @@ -21,7 +21,7 @@ /** * TIFF image encoder - * @file libavcodec/tiffenc.c + * @file * @author Bartlomiej Wolowiec */ #include "avcodec.h" @@ -32,6 +32,7 @@ #include "tiff.h" #include "rle.h" #include "lzw.h" +#include "put_bits.h" #define TIFF_MAX_ENTRY 32 @@ -352,7 +353,8 @@ static int encode_frame(AVCodecContext * avctx, unsigned char *buf, for (i = 0; i < s->height; i++) { if (strip_sizes[i / s->rps] == 0) { if(s->compr == TIFF_LZW){ - ff_lzw_encode_init(s->lzws, ptr, s->buf_size - (*s->buf - s->buf_start), 12); + ff_lzw_encode_init(s->lzws, ptr, s->buf_size - (*s->buf - s->buf_start), + 12, FF_LZW_TIFF, put_bits); } strip_offsets[i / s->rps] = ptr - buf; } @@ -372,7 +374,7 @@ static int encode_frame(AVCodecContext * avctx, unsigned char *buf, ptr += n; if(s->compr == TIFF_LZW && (i==s->height-1 || i%s->rps == s->rps-1)){ int ret; - ret = ff_lzw_encode_flush(s->lzws); + ret = ff_lzw_encode_flush(s->lzws, flush_put_bits); strip_sizes[(i / s->rps )] += ret ; ptr += ret; } @@ -442,7 +444,7 @@ fail: AVCodec tiff_encoder = { "tiff", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_TIFF, sizeof(TiffEncoderContext), NULL, @@ -452,7 +454,7 @@ AVCodec tiff_encoder = { 0, NULL, .pix_fmts = - (enum PixelFormat[]) {PIX_FMT_RGB24, PIX_FMT_PAL8, PIX_FMT_GRAY8, + (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, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/tmv.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/tmv.c index 29aaae1fe7..5117cd03cd 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/tmv.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/tmv.c @@ -21,7 +21,7 @@ /** * 8088flex TMV video decoder - * @file libavcodec/tmv.c + * @file * @author Daniel Verkamp * @sa http://www.oldskool.org/pc/8088_Corruption */ @@ -100,7 +100,7 @@ static av_cold int tmv_decode_close(AVCodecContext *avctx) AVCodec tmv_decoder = { .name = "tmv", - .type = CODEC_TYPE_VIDEO, + .type = AVMEDIA_TYPE_VIDEO, .id = CODEC_ID_TMV, .priv_data_size = sizeof(TMVContext), .close = tmv_decode_close, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/truemotion1.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/truemotion1.c index ae08bfe0b2..4306917912 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/truemotion1.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/truemotion1.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/truemotion1.c + * @file * Duck TrueMotion v1 Video Decoder by * Alex Beregszaszi and * Mike Melanson (melanson@pcisys.net) @@ -892,7 +892,7 @@ static av_cold int truemotion1_decode_end(AVCodecContext *avctx) AVCodec truemotion1_decoder = { "truemotion1", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_TRUEMOTION1, sizeof(TrueMotion1Context), truemotion1_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/truemotion2.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/truemotion2.c index ee3d6d9212..5013a9eeb7 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/truemotion2.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/truemotion2.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/truemotion2.c + * @file * Duck TrueMotion2 decoder. */ @@ -813,9 +813,6 @@ static av_cold int decode_init(AVCodecContext *avctx){ TM2Context * const l = avctx->priv_data; int i; - if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) { - return -1; - } if((avctx->width & 3) || (avctx->height & 3)){ av_log(avctx, AV_LOG_ERROR, "Width and height must be multiple of 4\n"); return -1; @@ -848,6 +845,7 @@ static av_cold int decode_init(AVCodecContext *avctx){ static av_cold int decode_end(AVCodecContext *avctx){ TM2Context * const l = avctx->priv_data; + AVFrame *pic = &l->pic; int i; if(l->last) @@ -865,12 +863,16 @@ static av_cold int decode_end(AVCodecContext *avctx){ av_free(l->U2); av_free(l->V2); } + + if (pic->data[0]) + avctx->release_buffer(avctx, pic); + return 0; } AVCodec truemotion2_decoder = { "truemotion2", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_TRUEMOTION2, sizeof(TM2Context), decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/truespeech.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/truespeech.c index 598d414832..37fbef9dea 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/truespeech.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/truespeech.c @@ -24,7 +24,7 @@ #include "truespeech_data.h" /** - * @file libavcodec/truespeech.c + * @file * TrueSpeech decoder. */ @@ -378,7 +378,7 @@ static int truespeech_decode_frame(AVCodecContext *avctx, AVCodec truespeech_decoder = { "truespeech", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_TRUESPEECH, sizeof(TSContext), truespeech_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/tscc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/tscc.c index d1a924da40..2b717c1481 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/tscc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/tscc.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/tscc.c + * @file * TechSmith Camtasia decoder * * Fourcc: TSCC @@ -107,7 +107,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac if(zret != Z_DATA_ERROR) - ff_msrle_decode(avctx, (AVPicture*)&c->pic, c->bpp, c->decomp_buf, c->zstream.avail_out); + ff_msrle_decode(avctx, (AVPicture*)&c->pic, c->bpp, c->decomp_buf, c->decomp_size - c->zstream.avail_out); /* make the palette available on the way out */ if (c->avctx->pix_fmt == PIX_FMT_PAL8) { @@ -141,10 +141,6 @@ static av_cold int decode_init(AVCodecContext *avctx) c->height = avctx->height; - if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) { - return 1; - } - // Needed if zlib unused or init aborted before inflateInit memset(&(c->zstream), 0, sizeof(z_stream)); switch(avctx->bits_per_coded_sample){ @@ -158,7 +154,8 @@ static av_cold int decode_init(AVCodecContext *avctx) return -1; } c->bpp = avctx->bits_per_coded_sample; - c->decomp_size = (avctx->width * c->bpp + (avctx->width + 254) / 255 + 2) * avctx->height + 2;//RLE in the 'best' case + // buffer size for RLE 'best' case when 2-byte code preceeds each pixel and there may be padding after it too + c->decomp_size = (((avctx->width * c->bpp + 7) >> 3) + 3 * avctx->width + 2) * avctx->height + 2; /* Allocate decompression buffer */ if (c->decomp_size) { @@ -202,7 +199,7 @@ static av_cold int decode_end(AVCodecContext *avctx) AVCodec tscc_decoder = { "camtasia", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_TSCC, sizeof(CamtasiaContext), decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/tta.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/tta.c index b26724b528..4bdfd73fbd 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/tta.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/tta.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/tta.c + * @file * TTA (The Lossless True Audio) decoder * (www.true-audio.com or tta.corecodec.org) * @author Alex Beregszaszi @@ -302,6 +302,10 @@ 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)) { + av_log(avctx, AV_LOG_ERROR, "Output buffer size is too small.\n"); + return -1; + } // FIXME: seeking s->total_frames--; if (!s->total_frames && s->last_frame_length) @@ -332,9 +336,14 @@ static int tta_decode_frame(AVCodecContext *avctx, unary--; } - if (k) + if (get_bits_left(&s->gb) < k) + return -1; + + if (k) { + if (k > MIN_CACHE_BITS) + return -1; value = (unary << k) + get_bits(&s->gb, k); - else + } else value = unary; // FIXME: copy paste from original @@ -404,6 +413,8 @@ static int tta_decode_frame(AVCodecContext *avctx, } } + if (get_bits_left(&s->gb) < 32) + return -1; skip_bits(&s->gb, 32); // frame crc // convert to output buffer @@ -438,7 +449,7 @@ static av_cold int tta_decode_close(AVCodecContext *avctx) { AVCodec tta_decoder = { "tta", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_TTA, sizeof(TTAContext), tta_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/twinvq.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/twinvq.c new file mode 100644 index 0000000000..6ab3a465d9 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/twinvq.c @@ -0,0 +1,1127 @@ +/* + * TwinVQ decoder + * Copyright (c) 2009 Vitor Sessak + * + * 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 "dsputil.h" +#include "fft.h" +#include "lsp.h" + +#include +#include + +#include "twinvq_data.h" + +enum FrameType { + FT_SHORT = 0, ///< Short frame (divided in n sub-blocks) + FT_MEDIUM, ///< Medium frame (divided in mmtab; + int size_s = mtab->size / mtab->fmode[FT_SHORT].sub; + + for (i = 0; i < size_s/2; i++) { + float cos_i = tctx->cos_tabs[0][i]; + lpc[i] = eval_lpc_spectrum(cos_vals, cos_i, mtab->n_lsp); + lpc[size_s-i-1] = eval_lpc_spectrum(cos_vals, -cos_i, mtab->n_lsp); + } +} + +static void interpolate(float *out, float v1, float v2, int size) +{ + int i; + float step = (v1 - v2)/(size + 1); + + for (i = 0; i < size; i++) { + v2 += step; + out[i] = v2; + } +} + +static inline float get_cos(int idx, int part, const float *cos_tab, int size) +{ + return part ? -cos_tab[size - idx - 1] : + cos_tab[ idx ]; +} + +/** + * Evaluates the LPC amplitude spectrum envelope from the line spectrum pairs. + * Probably for speed reasons, the coefficients are evaluated as + * siiiibiiiisiiiibiiiisiiiibiiiisiiiibiiiis ... + * where s is an evaluated value, i is a value interpolated from the others + * and b might be either calculated or interpolated, depending on an + * unexplained condition. + * + * @param step the size of a block "siiiibiiii" + * @param in the cosinus of the LSP data + * @param part is 0 for 0...PI (positive cossinus values) and 1 for PI...2PI + (negative cossinus values) + * @param size the size of the whole output + */ +static inline void eval_lpcenv_or_interp(TwinContext *tctx, + enum FrameType ftype, + float *out, const float *in, + int size, int step, int part) +{ + int i; + const ModeTab *mtab = tctx->mtab; + const float *cos_tab = tctx->cos_tabs[ftype]; + + // Fill the 's' + for (i = 0; i < size; i += step) + out[i] = + eval_lpc_spectrum(in, + get_cos(i, part, cos_tab, size), + mtab->n_lsp); + + // Fill the 'iiiibiiii' + for (i = step; i <= size - 2*step; i += step) { + if (out[i + step] + out[i - step] > 1.95*out[i] || + out[i + step] >= out[i - step]) { + interpolate(out + i - step + 1, out[i], out[i-step], step - 1); + } else { + out[i - step/2] = + eval_lpc_spectrum(in, + get_cos(i-step/2, part, cos_tab, size), + mtab->n_lsp); + interpolate(out + i - step + 1, out[i-step/2], out[i-step ], step/2 - 1); + interpolate(out + i - step/2 + 1, out[i ], out[i-step/2], step/2 - 1); + } + } + + interpolate(out + size - 2*step + 1, out[size-step], out[size - 2*step], step - 1); +} + +static void eval_lpcenv_2parts(TwinContext *tctx, enum FrameType ftype, + const float *buf, float *lpc, + int size, int step) +{ + eval_lpcenv_or_interp(tctx, ftype, lpc , buf, size/2, step, 0); + eval_lpcenv_or_interp(tctx, ftype, lpc + size/2, buf, size/2, 2*step, 1); + + interpolate(lpc+size/2-step+1, lpc[size/2], lpc[size/2-step], step); + + memset_float(lpc + size - 2*step + 1, lpc[size - 2*step], 2*step - 1); +} + +/** + * Inverse quantization. Read CB coefficients for cb1 and cb2 from the + * bitstream, sum the corresponding vectors and write the result to *out + * after permutation. + */ +static void dequant(TwinContext *tctx, GetBitContext *gb, float *out, + enum FrameType ftype, + const int16_t *cb0, const int16_t *cb1, int cb_len) +{ + int pos = 0; + int i, j; + + for (i = 0; i < tctx->n_div[ftype]; i++) { + int tmp0, tmp1; + int sign0 = 1; + int sign1 = 1; + const int16_t *tab0, *tab1; + int length = tctx->length[ftype][i >= tctx->length_change[ftype]]; + int bitstream_second_part = (i >= tctx->bits_main_spec_change[ftype]); + + int bits = tctx->bits_main_spec[0][ftype][bitstream_second_part]; + if (bits == 7) { + if (get_bits1(gb)) + sign0 = -1; + bits = 6; + } + tmp0 = get_bits(gb, bits); + + bits = tctx->bits_main_spec[1][ftype][bitstream_second_part]; + + if (bits == 7) { + if (get_bits1(gb)) + sign1 = -1; + + bits = 6; + } + tmp1 = get_bits(gb, bits); + + tab0 = cb0 + tmp0*cb_len; + tab1 = cb1 + tmp1*cb_len; + + for (j = 0; j < length; j++) + out[tctx->permut[ftype][pos+j]] = sign0*tab0[j] + sign1*tab1[j]; + + pos += length; + } + +} + +static inline float mulawinv(float y, float clip, float mu) +{ + y = av_clipf(y/clip, -1, 1); + return clip * FFSIGN(y) * (exp(log(1+mu) * fabs(y)) - 1) / mu; +} + +/** + * Evaluate a*b/400 rounded to the nearest integer. When, for example, + * a*b == 200 and the nearest integer is ill-defined, use a table to emulate + * the following broken float-based implementation used by the binary decoder: + * + * \code + * static int very_broken_op(int a, int b) + * { + * static float test; // Ugh, force gcc to do the division first... + * + * test = a/400.; + * return b * test + 0.5; + * } + * \endcode + * + * @note if this function is replaced by just ROUNDED_DIV(a*b,400.), the stddev + * between the original file (before encoding with Yamaha encoder) and the + * decoded output increases, which leads one to believe that the encoder expects + * exactly this broken calculation. + */ +static int very_broken_op(int a, int b) +{ + int x = a*b + 200; + int size; + const uint8_t *rtab; + + if (x%400 || b%5) + return x/400; + + x /= 400; + + size = tabs[b/5].size; + rtab = tabs[b/5].tab; + return x - rtab[size*av_log2(2*(x - 1)/size)+(x - 1)%size]; +} + +/** + * Sum to data a periodic peak of a given period, width and shape. + * + * @param period the period of the peak divised by 400.0 + */ +static void add_peak(int period, int width, const float *shape, + float ppc_gain, float *speech, int len) +{ + int i, j; + + const float *shape_end = shape + len; + int center; + + // First peak centered around zero + for (i = 0; i < width/2; i++) + speech[i] += ppc_gain * *shape++; + + for (i = 1; i < ROUNDED_DIV(len,width) ; i++) { + center = very_broken_op(period, i); + for (j = -width/2; j < (width+1)/2; j++) + speech[j+center] += ppc_gain * *shape++; + } + + // For the last block, be careful not to go beyond the end of the buffer + center = very_broken_op(period, i); + for (j = -width/2; j < (width + 1)/2 && shape < shape_end; j++) + speech[j+center] += ppc_gain * *shape++; +} + +static void decode_ppc(TwinContext *tctx, int period_coef, const float *shape, + float ppc_gain, float *speech) +{ + const ModeTab *mtab = tctx->mtab; + int isampf = tctx->avctx->sample_rate/1000; + int ibps = tctx->avctx->bit_rate/(1000 * tctx->avctx->channels); + int min_period = ROUNDED_DIV( 40*2*mtab->size, isampf); + int max_period = ROUNDED_DIV(6*40*2*mtab->size, isampf); + int period_range = max_period - min_period; + + // This is actually the period multiplied by 400. It is just linearly coded + // between its maximum and minimum value. + int period = min_period + + ROUNDED_DIV(period_coef*period_range, (1 << mtab->ppc_period_bit) - 1); + int width; + + if (isampf == 22 && ibps == 32) { + // For some unknown reason, NTT decided to code this case differently... + width = ROUNDED_DIV((period + 800)* mtab->peak_per2wid, 400*mtab->size); + } else + width = (period )* mtab->peak_per2wid/(400*mtab->size); + + add_peak(period, width, shape, ppc_gain, speech, mtab->ppc_shape_len); +} + +static void dec_gain(TwinContext *tctx, GetBitContext *gb, enum FrameType ftype, + float *out) +{ + const ModeTab *mtab = tctx->mtab; + int i, j; + int sub = mtab->fmode[ftype].sub; + float step = AMP_MAX / ((1 << GAIN_BITS) - 1); + float sub_step = SUB_AMP_MAX / ((1 << SUB_GAIN_BITS) - 1); + + if (ftype == FT_LONG) { + for (i = 0; i < tctx->avctx->channels; i++) + out[i] = (1./(1<<13)) * + mulawinv(step * 0.5 + step * get_bits(gb, GAIN_BITS), + AMP_MAX, MULAW_MU); + } else { + for (i = 0; i < tctx->avctx->channels; i++) { + float val = (1./(1<<23)) * + mulawinv(step * 0.5 + step * get_bits(gb, GAIN_BITS), + AMP_MAX, MULAW_MU); + + for (j = 0; j < sub; j++) { + out[i*sub + j] = + val*mulawinv(sub_step* 0.5 + + sub_step* get_bits(gb, SUB_GAIN_BITS), + SUB_AMP_MAX, MULAW_MU); + } + } + } +} + +/** + * Rearrange the LSP coefficients so that they have a minimum distance of + * min_dist. This function does it exactly as described in section of 3.2.4 + * of the G.729 specification (but interestingly is different from what the + * reference decoder actually does). + */ +static void rearrange_lsp(int order, float *lsp, float min_dist) +{ + int i; + float min_dist2 = min_dist * 0.5; + for (i = 1; i < order; i++) + if (lsp[i] - lsp[i-1] < min_dist) { + float avg = (lsp[i] + lsp[i-1]) * 0.5; + + lsp[i-1] = avg - min_dist2; + lsp[i ] = avg + min_dist2; + } +} + +static void decode_lsp(TwinContext *tctx, int lpc_idx1, uint8_t *lpc_idx2, + int lpc_hist_idx, float *lsp, float *hist) +{ + const ModeTab *mtab = tctx->mtab; + int i, j; + + const float *cb = mtab->lspcodebook; + const float *cb2 = cb + (1 << mtab->lsp_bit1)*mtab->n_lsp; + const float *cb3 = cb2 + (1 << mtab->lsp_bit2)*mtab->n_lsp; + + const int8_t funny_rounding[4] = { + -2, + mtab->lsp_split == 4 ? -2 : 1, + mtab->lsp_split == 4 ? -2 : 1, + 0 + }; + + j = 0; + for (i = 0; i < mtab->lsp_split; i++) { + int chunk_end = ((i + 1)*mtab->n_lsp + funny_rounding[i])/mtab->lsp_split; + for (; j < chunk_end; j++) + lsp[j] = cb [lpc_idx1 * mtab->n_lsp + j] + + cb2[lpc_idx2[i] * mtab->n_lsp + j]; + } + + rearrange_lsp(mtab->n_lsp, lsp, 0.0001); + + for (i = 0; i < mtab->n_lsp; i++) { + float tmp1 = 1. - cb3[lpc_hist_idx*mtab->n_lsp + i]; + float tmp2 = hist[i] * cb3[lpc_hist_idx*mtab->n_lsp + i]; + hist[i] = lsp[i]; + lsp[i] = lsp[i] * tmp1 + tmp2; + } + + rearrange_lsp(mtab->n_lsp, lsp, 0.0001); + rearrange_lsp(mtab->n_lsp, lsp, 0.000095); + ff_sort_nearly_sorted_floats(lsp, mtab->n_lsp); +} + +static void dec_lpc_spectrum_inv(TwinContext *tctx, float *lsp, + enum FrameType ftype, float *lpc) +{ + int i; + int size = tctx->mtab->size / tctx->mtab->fmode[ftype].sub; + + for (i = 0; i < tctx->mtab->n_lsp; i++) + lsp[i] = 2*cos(lsp[i]); + + switch (ftype) { + case FT_LONG: + eval_lpcenv_2parts(tctx, ftype, lsp, lpc, size, 8); + break; + case FT_MEDIUM: + eval_lpcenv_2parts(tctx, ftype, lsp, lpc, size, 2); + break; + case FT_SHORT: + eval_lpcenv(tctx, lsp, lpc); + break; + } +} + +static void imdct_and_window(TwinContext *tctx, enum FrameType ftype, int wtype, + float *in, float *prev, int ch) +{ + const ModeTab *mtab = tctx->mtab; + int bsize = mtab->size / mtab->fmode[ftype].sub; + int size = mtab->size; + float *buf1 = tctx->tmp_buf; + int j; + int wsize; // Window size + float *out = tctx->curr_frame + 2*ch*mtab->size; + float *out2 = out; + float *prev_buf; + int first_wsize; + + static const uint8_t wtype_to_wsize[] = {0, 0, 2, 2, 2, 1, 0, 1, 1}; + int types_sizes[] = { + mtab->size / mtab->fmode[FT_LONG ].sub, + mtab->size / mtab->fmode[FT_MEDIUM].sub, + mtab->size / (2*mtab->fmode[FT_SHORT ].sub), + }; + + wsize = types_sizes[wtype_to_wsize[wtype]]; + first_wsize = wsize; + prev_buf = prev + (size - bsize)/2; + + for (j = 0; j < mtab->fmode[ftype].sub; j++) { + int sub_wtype = ftype == FT_MEDIUM ? 8 : wtype; + + if (!j && wtype == 4) + sub_wtype = 4; + else if (j == mtab->fmode[ftype].sub-1 && wtype == 7) + sub_wtype = 7; + + wsize = types_sizes[wtype_to_wsize[sub_wtype]]; + + ff_imdct_half(&tctx->mdct_ctx[ftype], buf1 + bsize*j, in + bsize*j); + + tctx->dsp.vector_fmul_window(out2, + prev_buf + (bsize-wsize)/2, + buf1 + bsize*j, + ff_sine_windows[av_log2(wsize)], + 0.0, + wsize/2); + out2 += wsize; + + memcpy(out2, buf1 + bsize*j + wsize/2, (bsize - wsize/2)*sizeof(float)); + + out2 += ftype == FT_MEDIUM ? (bsize-wsize)/2 : bsize - wsize; + + prev_buf = buf1 + bsize*j + bsize/2; + } + + tctx->last_block_pos[ch] = (size + first_wsize)/2; +} + +static void imdct_output(TwinContext *tctx, enum FrameType ftype, int wtype, + float *out) +{ + const ModeTab *mtab = tctx->mtab; + float *prev_buf = tctx->prev_frame + tctx->last_block_pos[0]; + int i, j; + + for (i = 0; i < tctx->avctx->channels; i++) { + imdct_and_window(tctx, ftype, wtype, + tctx->spectrum + i*mtab->size, + prev_buf + 2*i*mtab->size, + i); + } + + if (tctx->avctx->channels == 2) { + for (i = 0; i < mtab->size - tctx->last_block_pos[0]; i++) { + float f1 = prev_buf[ i]; + float f2 = prev_buf[2*mtab->size + i]; + out[2*i ] = f1 + f2; + out[2*i + 1] = f1 - f2; + } + for (j = 0; i < mtab->size; j++,i++) { + float f1 = tctx->curr_frame[ j]; + float f2 = tctx->curr_frame[2*mtab->size + j]; + out[2*i ] = f1 + f2; + out[2*i + 1] = f1 - f2; + } + } else { + memcpy(out, prev_buf, + (mtab->size - tctx->last_block_pos[0]) * sizeof(*out)); + + out += mtab->size - tctx->last_block_pos[0]; + + memcpy(out, tctx->curr_frame, + (tctx->last_block_pos[0]) * sizeof(*out)); + } + +} + +static void dec_bark_env(TwinContext *tctx, const uint8_t *in, int use_hist, + int ch, float *out, float gain, enum FrameType ftype) +{ + const ModeTab *mtab = tctx->mtab; + int i,j; + float *hist = tctx->bark_hist[ftype][ch]; + float val = ((const float []) {0.4, 0.35, 0.28})[ftype]; + int bark_n_coef = mtab->fmode[ftype].bark_n_coef; + int fw_cb_len = mtab->fmode[ftype].bark_env_size / bark_n_coef; + int idx = 0; + + for (i = 0; i < fw_cb_len; i++) + for (j = 0; j < bark_n_coef; j++, idx++) { + float tmp2 = + mtab->fmode[ftype].bark_cb[fw_cb_len*in[j] + i] * (1./4096); + float st = use_hist ? + (1. - val) * tmp2 + val*hist[idx] + 1. : tmp2 + 1.; + + hist[idx] = tmp2; + if (st < -1.) st = 1.; + + memset_float(out, st * gain, mtab->fmode[ftype].bark_tab[idx]); + out += mtab->fmode[ftype].bark_tab[idx]; + } + +} + +static void read_and_decode_spectrum(TwinContext *tctx, GetBitContext *gb, + float *out, enum FrameType ftype) +{ + const ModeTab *mtab = tctx->mtab; + int channels = tctx->avctx->channels; + int sub = mtab->fmode[ftype].sub; + int block_size = mtab->size / sub; + float gain[channels*sub]; + float ppc_shape[mtab->ppc_shape_len * channels * 4]; + uint8_t bark1[channels][sub][mtab->fmode[ftype].bark_n_coef]; + uint8_t bark_use_hist[channels][sub]; + + uint8_t lpc_idx1[channels]; + uint8_t lpc_idx2[channels][tctx->mtab->lsp_split]; + uint8_t lpc_hist_idx[channels]; + + int i, j, k; + + dequant(tctx, gb, out, ftype, + mtab->fmode[ftype].cb0, mtab->fmode[ftype].cb1, + mtab->fmode[ftype].cb_len_read); + + for (i = 0; i < channels; i++) + for (j = 0; j < sub; j++) + for (k = 0; k < mtab->fmode[ftype].bark_n_coef; k++) + bark1[i][j][k] = + get_bits(gb, mtab->fmode[ftype].bark_n_bit); + + for (i = 0; i < channels; i++) + for (j = 0; j < sub; j++) + bark_use_hist[i][j] = get_bits1(gb); + + dec_gain(tctx, gb, ftype, gain); + + for (i = 0; i < channels; i++) { + lpc_hist_idx[i] = get_bits(gb, tctx->mtab->lsp_bit0); + lpc_idx1 [i] = get_bits(gb, tctx->mtab->lsp_bit1); + + for (j = 0; j < tctx->mtab->lsp_split; j++) + lpc_idx2[i][j] = get_bits(gb, tctx->mtab->lsp_bit2); + } + + if (ftype == FT_LONG) { + int cb_len_p = (tctx->n_div[3] + mtab->ppc_shape_len*channels - 1)/ + tctx->n_div[3]; + dequant(tctx, gb, ppc_shape, FT_PPC, mtab->ppc_shape_cb, + mtab->ppc_shape_cb + cb_len_p*PPC_SHAPE_CB_SIZE, cb_len_p); + } + + for (i = 0; i < channels; i++) { + float *chunk = out + mtab->size * i; + float lsp[tctx->mtab->n_lsp]; + + for (j = 0; j < sub; j++) { + dec_bark_env(tctx, bark1[i][j], bark_use_hist[i][j], i, + tctx->tmp_buf, gain[sub*i+j], ftype); + + tctx->dsp.vector_fmul(chunk + block_size*j, tctx->tmp_buf, + block_size); + + } + + if (ftype == FT_LONG) { + float pgain_step = 25000. / ((1 << mtab->pgain_bit) - 1); + int p_coef = get_bits(gb, tctx->mtab->ppc_period_bit); + int g_coef = get_bits(gb, tctx->mtab->pgain_bit); + float v = 1./8192* + mulawinv(pgain_step*g_coef+ pgain_step/2, 25000., PGAIN_MU); + + decode_ppc(tctx, p_coef, ppc_shape + i*mtab->ppc_shape_len, v, + chunk); + } + + decode_lsp(tctx, lpc_idx1[i], lpc_idx2[i], lpc_hist_idx[i], lsp, + tctx->lsp_hist[i]); + + dec_lpc_spectrum_inv(tctx, lsp, ftype, tctx->tmp_buf); + + for (j = 0; j < mtab->fmode[ftype].sub; j++) { + tctx->dsp.vector_fmul(chunk, tctx->tmp_buf, block_size); + chunk += block_size; + } + } +} + +static int twin_decode_frame(AVCodecContext * avctx, void *data, + int *data_size, AVPacket *avpkt) +{ + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + TwinContext *tctx = avctx->priv_data; + GetBitContext gb; + const ModeTab *mtab = tctx->mtab; + float *out = data; + enum FrameType ftype; + int window_type; + static const enum FrameType wtype_to_ftype_table[] = { + FT_LONG, FT_LONG, FT_SHORT, FT_LONG, + FT_MEDIUM, FT_LONG, FT_LONG, FT_MEDIUM, FT_MEDIUM + }; + + if (buf_size*8 < avctx->bit_rate*mtab->size/avctx->sample_rate + 8) { + 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, buf_size * 8); + skip_bits(&gb, get_bits(&gb, 8)); + window_type = get_bits(&gb, WINDOW_TYPE_BITS); + + if (window_type > 8) { + av_log(avctx, AV_LOG_ERROR, "Invalid window type, broken sample?\n"); + return -1; + } + + ftype = wtype_to_ftype_table[window_type]; + + read_and_decode_spectrum(tctx, &gb, tctx->spectrum, ftype); + + imdct_output(tctx, ftype, window_type, out); + + FFSWAP(float*, tctx->curr_frame, tctx->prev_frame); + + if (tctx->avctx->frame_number < 2) { + *data_size=0; + return buf_size; + } + + *data_size = mtab->size*avctx->channels*4; + + return buf_size; +} + +/** + * Init IMDCT and windowing tables + */ +static av_cold void init_mdct_win(TwinContext *tctx) +{ + int i,j; + const ModeTab *mtab = tctx->mtab; + int size_s = mtab->size / mtab->fmode[FT_SHORT].sub; + int size_m = mtab->size / mtab->fmode[FT_MEDIUM].sub; + int channels = tctx->avctx->channels; + float norm = channels == 1 ? 2. : 1.; + + for (i = 0; i < 3; i++) { + int bsize = tctx->mtab->size/tctx->mtab->fmode[i].sub; + ff_mdct_init(&tctx->mdct_ctx[i], av_log2(bsize) + 1, 1, + -sqrt(norm/bsize) / (1<<15)); + } + + tctx->tmp_buf = av_malloc(mtab->size * sizeof(*tctx->tmp_buf)); + + tctx->spectrum = av_malloc(2*mtab->size*channels*sizeof(float)); + tctx->curr_frame = av_malloc(2*mtab->size*channels*sizeof(float)); + tctx->prev_frame = av_malloc(2*mtab->size*channels*sizeof(float)); + + for (i = 0; i < 3; i++) { + int m = 4*mtab->size/mtab->fmode[i].sub; + double freq = 2*M_PI/m; + tctx->cos_tabs[i] = av_malloc((m/4)*sizeof(*tctx->cos_tabs)); + + for (j = 0; j <= m/8; j++) + tctx->cos_tabs[i][j] = cos((2*j + 1)*freq); + for (j = 1; j < m/8; j++) + tctx->cos_tabs[i][m/4-j] = tctx->cos_tabs[i][j]; + } + + + ff_init_ff_sine_windows(av_log2(size_m)); + ff_init_ff_sine_windows(av_log2(size_s/2)); + ff_init_ff_sine_windows(av_log2(mtab->size)); +} + +/** + * Interpret the data as if it were a num_blocks x line_len[0] matrix and for + * each line do a cyclic permutation, i.e. + * abcdefghijklm -> defghijklmabc + * where the amount to be shifted is evaluated depending on the column. + */ +static void permutate_in_line(int16_t *tab, int num_vect, int num_blocks, + int block_size, + const uint8_t line_len[2], int length_div, + enum FrameType ftype) + +{ + int i,j; + + for (i = 0; i < line_len[0]; i++) { + int shift; + + if (num_blocks == 1 || + (ftype == FT_LONG && num_vect % num_blocks) || + (ftype != FT_LONG && num_vect & 1 ) || + i == line_len[1]) { + shift = 0; + } else if (ftype == FT_LONG) { + shift = i; + } else + shift = i*i; + + for (j = 0; j < num_vect && (j+num_vect*i < block_size*num_blocks); j++) + tab[i*num_vect+j] = i*num_vect + (j + shift) % num_vect; + } +} + +/** + * Interpret the input data as in the following table: + * + * \verbatim + * + * abcdefgh + * ijklmnop + * qrstuvw + * x123456 + * + * \endverbatim + * + * and transpose it, giving the output + * aiqxbjr1cks2dlt3emu4fvn5gow6hp + */ +static void transpose_perm(int16_t *out, int16_t *in, int num_vect, + const uint8_t line_len[2], int length_div) +{ + int i,j; + int cont= 0; + for (i = 0; i < num_vect; i++) + for (j = 0; j < line_len[i >= length_div]; j++) + out[cont++] = in[j*num_vect + i]; +} + +static void linear_perm(int16_t *out, int16_t *in, int n_blocks, int size) +{ + int block_size = size/n_blocks; + int i; + + for (i = 0; i < size; i++) + out[i] = block_size * (in[i] % n_blocks) + in[i] / n_blocks; +} + +static av_cold void construct_perm_table(TwinContext *tctx,enum FrameType ftype) +{ + int block_size; + const ModeTab *mtab = tctx->mtab; + int size = tctx->avctx->channels*mtab->fmode[ftype].sub; + int16_t *tmp_perm = (int16_t *) tctx->tmp_buf; + + if (ftype == FT_PPC) { + size = tctx->avctx->channels; + block_size = mtab->ppc_shape_len; + } else + block_size = mtab->size / mtab->fmode[ftype].sub; + + permutate_in_line(tmp_perm, tctx->n_div[ftype], size, + block_size, tctx->length[ftype], + tctx->length_change[ftype], ftype); + + transpose_perm(tctx->permut[ftype], tmp_perm, tctx->n_div[ftype], + tctx->length[ftype], tctx->length_change[ftype]); + + linear_perm(tctx->permut[ftype], tctx->permut[ftype], size, + size*block_size); +} + +static av_cold void init_bitstream_params(TwinContext *tctx) +{ + const ModeTab *mtab = tctx->mtab; + int n_ch = tctx->avctx->channels; + int total_fr_bits = tctx->avctx->bit_rate*mtab->size/ + tctx->avctx->sample_rate; + + int lsp_bits_per_block = n_ch*(mtab->lsp_bit0 + mtab->lsp_bit1 + + mtab->lsp_split*mtab->lsp_bit2); + + int ppc_bits = n_ch*(mtab->pgain_bit + mtab->ppc_shape_bit + + mtab->ppc_period_bit); + + int bsize_no_main_cb[3]; + int bse_bits[3]; + int i; + enum FrameType frametype; + + for (i = 0; i < 3; i++) + // +1 for history usage switch + bse_bits[i] = n_ch * + (mtab->fmode[i].bark_n_coef * mtab->fmode[i].bark_n_bit + 1); + + bsize_no_main_cb[2] = bse_bits[2] + lsp_bits_per_block + ppc_bits + + WINDOW_TYPE_BITS + n_ch*GAIN_BITS; + + for (i = 0; i < 2; i++) + bsize_no_main_cb[i] = + lsp_bits_per_block + n_ch*GAIN_BITS + WINDOW_TYPE_BITS + + mtab->fmode[i].sub*(bse_bits[i] + n_ch*SUB_GAIN_BITS); + + // The remaining bits are all used for the main spectrum coefficients + for (i = 0; i < 4; i++) { + int bit_size; + int vect_size; + int rounded_up, rounded_down, num_rounded_down, num_rounded_up; + if (i == 3) { + bit_size = n_ch * mtab->ppc_shape_bit; + vect_size = n_ch * mtab->ppc_shape_len; + } else { + bit_size = total_fr_bits - bsize_no_main_cb[i]; + vect_size = n_ch * mtab->size; + } + + tctx->n_div[i] = (bit_size + 13) / 14; + + rounded_up = (bit_size + tctx->n_div[i] - 1)/tctx->n_div[i]; + rounded_down = (bit_size )/tctx->n_div[i]; + num_rounded_down = rounded_up * tctx->n_div[i] - bit_size; + num_rounded_up = tctx->n_div[i] - num_rounded_down; + tctx->bits_main_spec[0][i][0] = (rounded_up + 1)/2; + tctx->bits_main_spec[1][i][0] = (rounded_up )/2; + tctx->bits_main_spec[0][i][1] = (rounded_down + 1)/2; + tctx->bits_main_spec[1][i][1] = (rounded_down )/2; + tctx->bits_main_spec_change[i] = num_rounded_up; + + rounded_up = (vect_size + tctx->n_div[i] - 1)/tctx->n_div[i]; + rounded_down = (vect_size )/tctx->n_div[i]; + num_rounded_down = rounded_up * tctx->n_div[i] - vect_size; + num_rounded_up = tctx->n_div[i] - num_rounded_down; + tctx->length[i][0] = rounded_up; + tctx->length[i][1] = rounded_down; + tctx->length_change[i] = num_rounded_up; + } + + for (frametype = FT_SHORT; frametype <= FT_PPC; frametype++) + construct_perm_table(tctx, frametype); +} + +static av_cold int twin_decode_init(AVCodecContext *avctx) +{ + TwinContext *tctx = avctx->priv_data; + int isampf = avctx->sample_rate/1000; + int ibps = avctx->bit_rate/(1000 * avctx->channels); + + tctx->avctx = avctx; + avctx->sample_fmt = SAMPLE_FMT_FLT; + + if (avctx->channels > 2) { + av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels: %i\n", + avctx->channels); + return -1; + } + + switch ((isampf << 8) + ibps) { + case (8 <<8) + 8: tctx->mtab = &mode_08_08; break; + case (11<<8) + 8: tctx->mtab = &mode_11_08; break; + case (11<<8) + 10: tctx->mtab = &mode_11_10; break; + case (16<<8) + 16: tctx->mtab = &mode_16_16; break; + case (22<<8) + 20: tctx->mtab = &mode_22_20; break; + case (22<<8) + 24: tctx->mtab = &mode_22_24; break; + case (22<<8) + 32: tctx->mtab = &mode_22_32; break; + case (44<<8) + 40: tctx->mtab = &mode_44_40; break; + case (44<<8) + 48: tctx->mtab = &mode_44_48; break; + default: + av_log(avctx, AV_LOG_ERROR, "This version does not support %d kHz - %d kbit/s/ch mode.\n", isampf, isampf); + return -1; + } + + dsputil_init(&tctx->dsp, avctx); + init_mdct_win(tctx); + init_bitstream_params(tctx); + + memset_float(tctx->bark_hist[0][0], 0.1, FF_ARRAY_ELEMS(tctx->bark_hist)); + + return 0; +} + +static av_cold int twin_decode_close(AVCodecContext *avctx) +{ + TwinContext *tctx = avctx->priv_data; + int i; + + for (i = 0; i < 3; i++) { + ff_mdct_end(&tctx->mdct_ctx[i]); + av_free(tctx->cos_tabs[i]); + } + + + av_free(tctx->curr_frame); + av_free(tctx->spectrum); + av_free(tctx->prev_frame); + av_free(tctx->tmp_buf); + + return 0; +} + +AVCodec 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"), +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/twinvq_data.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/twinvq_data.h new file mode 100644 index 0000000000..3042cd1beb --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/twinvq_data.h @@ -0,0 +1,11137 @@ +/* + * TwinVQ decoder + * Copyright (c) 2009 Vitor Sessak + * + * 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_TWINVQ_DATA_H +#define AVCODEC_TWINVQ_DATA_H + +#include +#include + +/* + * The bark_tab_* tables are constructed so that + * + * /i-1 \ + * |-- | + * bark |\ bark_tab[j] | == i + * |/ | + * |-- | + * \j=0 / + * + * + * for some slightly nonconventional bark-scale function + */ +static const uint16_t bark_tab_l08_512[] = { + 7, 8, 7, 8, 8, 8, 8, 8, 8, 9, + 9, 10, 10, 11, 11, 12, 12, 14, 15, 16, + 18, 19, 21, 24, 27, 30, 35, 40, 46, 53 +}; + +static const uint16_t bark_tab_l11_512[] = { + 6, 6, 6, 6, 6, 6, 7, 6, 7, 7, + 8, 8, 8, 9, 10, 10, 11, 13, 13, 15, + 17, 18, 21, 25, 27, 33, 38, 45, 54, 66 +}; + +static const uint16_t bark_tab_l16_1024[] = { + 9, 9, 8, 9, 10, 9, 10, 10, 10, 12, + 11, 13, 13, 14, 16, 17, 19, 20, 24, 26, + 30, 35, 40, 48, 56, 68, 83, 102, 128, 165 +}; + +static const uint16_t bark_tab_l22_1024[] = { + 6, 7, 6, 6, 7, 7, 7, 7, 7, 8, + 9, 8, 10, 10, 11, 12, 13, 15, 16, 18, + 21, 24, 27, 33, 38, 46, 55, 68, 84, 107, + 140, 191 +}; + +static const uint16_t bark_tab_l22_512[] = { + 3, 3, 3, 4, 3, 3, 4, 3, 4, 4, + 4, 5, 4, 5, 6, 6, 7, 7, 8, 9, + 10, 12, 14, 16, 20, 22, 28, 34, 42, 53, + 71, 95 +}; + +static const uint16_t bark_tab_l44_2048[] = { + 5, 6, 5, 6, 5, 6, 6, 6, 6, 6, + 7, 7, 7, 8, 8, 9, 9, 10, 11, 11, + 13, 14, 16, 17, 19, 22, 25, 29, 33, 39, + 46, 54, 64, 79, 98, 123, 161, 220, 320, 512 +}; + +static const uint16_t bark_tab_m08_256[] = { + 6, 5, 6, 6, 6, 6, 7, 7, 8, 8, + 9, 10, 11, 13, 15, 18, 20, 25, 31, 39 +}; + +static const uint16_t bark_tab_m11_256[] = { + 4, 5, 4, 5, 5, 5, 6, 5, 7, 7, + 8, 9, 10, 12, 15, 17, 22, 28, 35, 47 +}; + +static const uint16_t bark_tab_m16_512[] = { + 7, 6, 7, 7, 7, 8, 9, 9, 10, 11, + 14, 15, 18, 22, 27, 34, 44, 59, 81, 117 +}; + +static const uint16_t bark_tab_m22_256[] = { + 3, 2, 3, 2, 3, 3, 4, 3, 4, 5, + 5, 7, 8, 9, 13, 16, 22, 30, 44, 70 +}; + +static const uint16_t bark_tab_m22_512[] = { + 5, 5, 5, 6, 5, 7, 6, 7, 9, 9, + 11, 13, 15, 20, 24, 33, 43, 61, 88, 140 +}; + +static const uint16_t bark_tab_m44_512[] = { + 3, 2, 3, 3, 3, 4, 3, 5, 4, 6, + 7, 8, 10, 14, 18, 25, 36, 55, 95, 208 +}; + +static const uint16_t bark_tab_s08_64[] = { + 3, 3, 3, 3, 4, 5, 6, 8, 12, 17 +}; + +static const uint16_t bark_tab_s11_64[] = { + 2, 3, 2, 3, 3, 4, 6, 8, 12, 21 +}; + +static const uint16_t bark_tab_s16_128[] = { + 3, 4, 4, 4, 5, 7, 10, 16, 26, 49 +}; + +static const uint16_t bark_tab_s22_128[] = { + 3, 2, 3, 4, 4, 6, 9, 14, 26, 57 +}; + +static const uint16_t bark_tab_s44_128[] = { + 1, 2, 1, 2, 3, 4, 6, 10, 23, 76 +}; + + +/** + * TwinVQ codebooks. They are coded in a struct so we can use code such as + * + * float val = tab.fcb0808l[get_bits(gb, 12)]; + * + * without risking a segfault on malformed files. + */ +static const struct { + float lsp08[504]; + int16_t fcb08l[640]; + int16_t fcb08m[320]; + int16_t fcb08s[320]; + int16_t shape08[1280]; + + int16_t cb0808l0[1088]; + int16_t cb0808l1[1088]; + int16_t cb0808s0[1152]; + int16_t cb0808s1[1152]; + int16_t cb0808m0[1024]; + int16_t cb0808m1[1024]; + + int16_t cb1108l0[1728]; + int16_t cb1108l1[1728]; + int16_t cb1108m0[1536]; + int16_t cb1108m1[1536]; + int16_t cb1108s0[1856]; + int16_t cb1108s1[1856]; + + int16_t fcb11l[640]; + int16_t fcb11m[320]; + int16_t fcb11s[320]; + int16_t shape11[1280]; + float lsp11[1312]; + + int16_t cb1110l0[1280]; + int16_t cb1110l1[1280]; + int16_t cb1110m0[1152]; + int16_t cb1110m1[1152]; + int16_t cb1110s0[1344]; + int16_t cb1110s1[1344]; + + int16_t fcb16l[640]; + int16_t fcb16m[320]; + int16_t fcb16s[320]; + int16_t shape16[1920]; + float lsp16[1400]; + + int16_t cb1616l0[1024]; + int16_t cb1616l1[1024]; + int16_t cb1616m0[960]; + int16_t cb1616m1[960]; + int16_t cb1616s0[1024]; + int16_t cb1616s1[1024]; + + int16_t cb2220l0[1152]; + int16_t cb2220l1[1152]; + int16_t cb2220m0[1088]; + int16_t cb2220m1[1088]; + int16_t cb2220s0[1152]; + int16_t cb2220s1[1152]; + + int16_t fcb22l_1[512]; + int16_t fcb22m_1[640]; + int16_t fcb22s_1[640]; + int16_t shape22_1[1152]; + float lsp22_1[1312]; + + int16_t cb2224l0[960]; + int16_t cb2224l1[960]; + int16_t cb2224m0[896]; + int16_t cb2224m1[896]; + int16_t cb2224s0[960]; + int16_t cb2224s1[960]; + + int16_t fcb22l_2[512]; + int16_t fcb22m_2[640]; + int16_t fcb22s_2[640]; + int16_t shape22_2[1152]; + float lsp22_2[1312]; + + int16_t cb2232l0[768]; + int16_t cb2232l1[768]; + int16_t cb2232m0[704]; + int16_t cb2232m1[704]; + int16_t cb2232s0[704]; + int16_t cb2232s1[704]; + + int16_t cb4440l0[1088]; + int16_t cb4440l1[1088]; + int16_t cb4440m0[1088]; + int16_t cb4440m1[1088]; + int16_t cb4440s0[1152]; + int16_t cb4440s1[1152]; + + int16_t fcb44l[640]; + int16_t fcb44m[640]; + int16_t fcb44s[640]; + int16_t shape44[1152]; + float lsp44[1640]; + + int16_t cb4448l0[896]; + int16_t cb4448l1[896]; + int16_t cb4448m0[896]; + int16_t cb4448m1[896]; + int16_t cb4448s0[960]; + int16_t cb4448s1[960]; +} tab = { +.cb0808l0 = { + 96, -12592, -12443, 425, 182, -456, -341, -843, + 615, 689, 982, 1470, -518, 231, -538, 282, + 409, -600, -303, -29, 51, -4, -115, 79, + -27, 450, -937, -461, -554, -159, 426, 710, +-29106, -2148, 99, 3426, 1838, 12427, 585, -2080, + -2524, -474, 1572, 718, 578, -344, 188, 328, + 12125, 112, 654, -1232, -1644, 288, 553, 1513, + 966, 1012, 49, 631, -111, -238, -116, -182, + -21, -46, 334, 11013, -454, -261, 12, 21, + 52, -20440, -295, -502, -516, -329, -230, 465, + 59, 270, 971, -127, 505, -194, 43, -30, + 300, 38, 665, -613, 33, -172, -153, 323, + -166, 54, 399, 109, 186, -1765, -222, 138, + 16, 204, 30111, 208, -564, -612, 156, -146, + -345, 321, -138, 202, -184, 93, 710, -15945, +-13401, 234, -1113, 146, -9, 56, -628, -834, + -1268, 872, 61, -1184, -126, -205, 145, -109, + -8248, 113, -146, 1288, 9142, 857, -782, -686, + -256, -650, 1061, -202, 12, -709, -88, 273, + 497, 150, -59, -8807, 240, 532, 16, 1482, + 11012, -444, 1918, -1786, 1934, 172, 598, -1324, + 5638, -3166, 492, -545, -770, 1067, 0, -356, + -421, 1684, 273, -502, 316, 1116, 807, -529, + -831, -13379, -420, 236, 470, -2590, -193, -47, + 580, -1613, 798, 27, -16, -12768, -893, 256, + 0, 1659, 1463, 544, 196, -30444, 314, -421, + 508, -276, -173, 414, -380, -371, -40, -121, + 375, 432, -438, 1, -350, -280, 1198, -373, + 452, 100, -68, 9053, 165, 770, 73, 291, + 717, 515, 596, -323, -4, -2, 803, 738, + 2605, 30, 73, 455, 11280, 1534, -283, 1502, + -9126, -4760, -570, 483, -179, -8628, -1639, 322, + -56, 6149, -3330, 114, 4598, -1976, -34, -56, + 840, 753, 12292, -7100, -492, 320, -412, 908, + 1186, 444, 6546, -788, 5394, 697, 13105, 194, + -394, 294, 2639, 12, -1009, -1426, -36, 2106, + -252, -31979, -66, 341, 996, 298, 105, 6, + 10, 106, -498, -244, -105, -574, 16, -206, + 24, -2067, -381, 10265, -103, -762, -785, -2036, +-11927, 16, -710, -35, -270, -99, 4, 772, + -272, -186, -328, -14936, -57, -1357, -175, -606, + 220, 918, -11, 398, -189, -278, 138, 429, + 509, -701, -43, -42, -630, -560, 11736, -528, + 10286, -633, -870, 423, 550, -888, 297, -170, + 258, 2234, 486, 292, -446, -11858, 10008, 52, + 1203, -164, 810, -1527, -604, -883, -588, -96, + 332, 148, -180, 223, 356, 285, 434, -57, + -172, -520, -432, -72, 294, -93, -134, 316, + 30647, -351, 278, 84, -439, 589, 105, 1001, + 297, 660, 196, 171, 178, -90, -55, 1172, + 21100, 227, -288, 372, 162, 458, -555, -1329, + 380, 366, -104, 105, 674, -378, 1328, 283, + -1928, 549, 762, 454, 55, 606, 12499, 24, + 435, 23, 29, 6170, 1129, -95, 97, 569, + 132, 491, 164, -288, -1011, -134, 1234, -427, + -254, -524, 226, -14114, 328, -70, 1666, -189, + -2352, 1097, 619, 632, -981, 745, 587, -27, + -200, -871, 50, 470, -246, 2610, 581, 254, + 9893, -586, 880, -11894, 386, 1135, 117, 1072, + 116, -830, -160, -1002, -699, -66, -230, -260, + 112, 106, 221, 297, -47, 7642, 170, -330, + -599, -51, -476, 33, 475, 624, 6199, -350, + -406, 184, 906, -528, 382, 401, 348, 26, + -186, 33, -130, -62, -50, 1268, -132, -109, + 1164, -354, 675, 3, -402, -244, 644, 648, + -132, -4, 45, 20386, -136, 568, 126, 376, + 14476, -376, 267, 13518, -260, 111, 1014, 758, + 439, 551, -164, 207, 128, -416, 616, 690, + -9460, -1856, 1123, 826, -265, -762, 1596, -632, + 52, -622, -894, 367, -433, -100, 1873, 756, +-17436, 168, -541, 550, 145, -5612, -1057, -1344, + -656, -194, 216, -500, -245, 246, 64, 688, + 727, 12538, -5492, 252, -908, -424, -532, -659, + -277, -230, -736, -183, 35, -228, 200, -12, + -248, -60, -493, 433, 446, 366, -644, 92, + -324, 29, 833, -21542, -977, 94, 379, 49, + -1058, 248, -178, 85, -961, -1198, -48, 467, + -242, -10202, 1556, 11263, -716, 814, -1686, 3594, + -27, 694, -802, 390, 4144, -663, 44, -546, + 312, -28, -484, 981, -307, 496, 408, 203, + 12543, 296, -1240, 159, 846, -957, -1493, -618, + 1593, 11868, 2616, 1954, 412, -922, -1320, 3325, + -254, -1892, 607, -2223, -8745, -1486, 17, 343, + -50, -562, 22011, -350, -491, -70, -60, 617, + 768, -346, 387, 660, 1409, 222, 616, 173, + -1323, 4017, -207, -525, -13243, 11, 440, -614, + -280, 549, -670, -79, 459, 560, -102, -214, + -54, -1201, 230, -526, 857, 1044, -369, 2470, +-11010, -12586, 243, -205, 838, -920, 348, -738, + 1319, 86, -78, -428, -1909, -155, 2, 508, + 711, -292, 1699, 225, -101, -163, 540, 9692, + 235, -183, -38, 198, -466, -204, -8957, -914, + -299, 193, 10, 723, 643, -533, -1418, 323, + 20, 334, -886, -331, 368, 130, -30233, -152, + -14, 637, 132, -232, -149, -430, 64, -243, + -376, 370, 388, 196, -1098, 117, -794, -16, + -274, 348, 464, -28156, 184, 322, -101, 2, + -27, -183, 610, 256, -160, -573, -226, 588, + 1613, 1028, 9518, -2151, -1602, -528, -356, -116, +-11511, 1828, -2206, -47, -757, -1479, -1429, -14717, + 1686, 253, 802, 462, -37, -916, -289, -401, + 13383, 353, -74, 114, -189, 636, 434, -639, + 1013, 234, 11752, 219, 1464, -132, -12838, 125, + -592, -40, -162, -1772, 506, 479, 422, 36, + 15, -960, 799, 517, 1311, -409, 748, 729, + 446, 11029, -13039, 1257, -651, -13, -742, 1416, + -388, -274, -795, 163, -572, 74, 430, -90, + -126, -74, -598, 140, 125, -20, -20332, 208, + 37, 19, -174, -209, 305, 28, -402, 28, + -315, -1, -134, 440, -832, 79, -635, -304, + 8, -32768, 625, 470, -1224, -351, 546, -1171, + -706, 652, 31, 7484, -448, 916, 1244, -379, + -300, 68, 868, 607, 247, 70, -984, 14314, + 21, -350, -82, 368, 456, -742, 472, 34, + 782, -498, -879, 700, 417, 216, 415, -161, + -181, -608, 1570, 862, -96, -114, 8095, -26, + 168, -363, -804, -36, -770, 139, -171, 6645, + -1425, 4826, -5288, 1358, -11747, -64, 650, -3206, + -1692, 789, -2047, -279, 916, -1648, 1164, 2044, + -144, -717, -392, -216, 372, 348, 1052, -175, + 668, 308, -15, 29112, -406, -774, 365, -1006, + -526, 1076, 59, -672, -87, -106, 174, 96, + 615, 462, -43, -496, 112, 149, -56, -182, + -268, -32768, -205, -676, 165, -1210, -325, 7964, + -44, 546, -699, 285, -418, 355, 238, 550, + 67, 425, 384, -950, -330, -208, -452, 212, + 11610, -190, 37, -907, -11137, -982, 585, -783, + -864, 164, -24, -514, -211, 2, -510, -580, + 595, 128, 100, -229, -55, 290, -539, 40, + -7786, -270, 295, -508, 562, -1196, 218, 33, + 3788, -8954, -1082, 297, -906, -322, 123, 1162, + -343, -11655, 88, -28, 1173, 9, -99, 36, +-11987, 356, 12630, 767, -183, -983, -559, 186, + 1148, 530, -440, 1230, -456, -133, -424, 35, + -357, 418, 1457, -687, 740, -242, 17855, -368, + -1057, -262, -646, 406, -712, -1058, -84, 454 +}, + +.cb0808l1 = { + 982, -26, -721, 359, 509, 13290, 2391, 727, + 325, 328, 269, -156, 346, -242, -31, -356, + 741, 396, -98, 108, 35, -237, -29684, 196, + -69, 462, -339, 24, -1221, 352, -658, 396, + 243, -1658, -458, -1153, 5, -662, -47, 18, + -572, -567, -2084, -980, -210, 150, -396, 14836, + -210, 0, -162, -539, 588, -868, 248, -8576, + 1020, 526, 1056, 262, -149, 818, -1353, -1120, + 767, -738, -634, -14742, -105, 811, 1718, -116, + -64, 307, 920, -1244, 2388, 10213, -4505, -250, + 617, -1725, -645, 1258, 1146, -590, 707, -12, + 372, 1794, 1012, -149, 404, -978, -306, 168, + -1536, 89, 142, 938, -19891, 973, -481, -419, + -904, -455, -1821, -1617, 654, -2022, 1906, -497, +-11346, -330, -11679, -14, 1, 535, -377, 1057, + -214, -213, 430, -13, -3379, -11250, 911, -716, + -240, -10, 260, 132, -611, -64, -594, -8540, + 837, -3717, -1154, 906, 10623, -502, -167, 67, + 119, 13501, -1469, 213, -1048, -1403, 432, -1079, + 45, -230, -730, -203, -595, -1150, -460, -97, + 395, -304, 27816, -300, -16, 153, -671, 551, + 436, -956, -182, 194, 113, -5504, 194, 263, + -332, -517, -244, -396, 540, 56, -371, 446, + 147, -66, 7, -306, 1440, -308, 327, 645, + 597, -6642, 72, 392, -138, -50, -144, -262, + 504, -230, 114, 2076, 8175, 1188, 290, -872, + 202, 69, 82, -281, -126, -291, -158, -152, + -45, 239, 153, -516, -422, -691, 801, 28, + 496, -298, -11118, 10430, -227, -851, 214, -801, + 538, 834, -137, 942, 573, 405, 1308, 2234, + 300, 1269, 12361, -752, 2177, -743, 60, 464, + 946, 302, -422, 116, -1200, -110, -843, 284, + -578, 732, -308, 153, -64, 156, 225, -29232, + -452, -466, -130, 888, 240, 305, -83, 236, + 208, 417, 1530, 294, 594, 351, 508, 137, + -7274, -184, 201, 44, -635, -891, -652, -596, + 380, -652, -8670, -76, -3746, -732, 262, -1860, + -1030, 1366, -279, 444, 911, 209, 330, 251, + -208, -747, 65, -10154, -204, 12960, -325, 347, + -465, -730, -727, 385, -89, -763, -427, 868, + -39, -859, 34, -29, -388, -1324, -218, 2051, + -1593, 5511, 10507, -8516, 2254, 5847, -1474, 1994, + 4704, -1876, 880, -3810, -489, -946, -1225, -1104, + 125, 139, -668, 2232, -537, 179, -215, 63, + 144, 72, 1198, 9750, 248, -709, 308, 10552, + -434, -462, 13569, 1096, -491, -262, 804, -1599, + 679, 569, 604, 1326, 213, -2026, 324, -2612, + -373, -12818, -20, 38, -171, 316, 15516, 306, + 763, 97, 91, -832, 23, -437, -390, 505, + -1226, 2518, 106, -2065, 315, 86, 523, 172, + -1012, -13851, 3358, 2610, -381, -194, 1200, -4106, + -1298, -3637, -1534, 780, 1367, -544, -770, 1690, + 1047, -54, 2136, 12502, 32, 6689, 706, -1172, + 846, -4853, 2146, 2548, -39, -465, -596, 177, + 213, 421, 28, -388, 11, 69, 31, -83, + -28, -166, -150, -19836, -323, 3, 659, 783, + 390, 139, -138, 31, -111, 453, -80, 432, + -519, -259, 686, 11431, 163, -13179, 554, 40, + -379, -120, -692, 340, 169, 120, -476, 643, + 778, 501, -128, 543, 1275, -134, 20568, 201, + 401, 512, -362, -210, -269, -812, 112, 75, + 149, -547, -494, -418, -100, -13621, -1002, 1176, + 1634, -395, -4289, -1531, -47, 850, -1102, 13558, + -403, 683, -164, -2215, -1180, -1750, 344, 630, + -968, 669, 540, 26, -594, 192, -17, -336, + 19645, 1133, 18, -56, 418, -426, -1535, 409, + 732, 186, 268, -20422, -22, 62, -621, 722, + 440, 96, -307, -128, 480, 5, 87, 668, + -361, -599, -22, 652, -176, -114, 214, -12233, + -698, 232, 608, -126, -714, -488, -228, 929, + -1582, -19845, 245, -460, 124, 57, 328, -436, + -158, 236, -196, -534, 209, 69, 229, 210, + -251, 1100, 583, 415, 210, 189, -219, 1242, + 19482, -105, 190, -374, -43, -232, 253, 561, + -297, -376, -1077, -308, 13486, -12462, 64, -190, + -298, -643, 460, 232, -987, -478, 1596, 168, + -722, 616, -873, -98, -948, 231, -1102, 11915, + 746, -495, 1248, 1203, 11067, -32, 160, -94, + -24, -153, -209, -1453, -1059, -313, -922, 1143, + -538, -1348, -323, 679, -54, -232, -470, 2075, +-19135, 628, -774, 35, 247, -86, 721, 512, + 1305, 850, 9760, 248, -2404, -220, 6, -73, + -1370, 567, 1432, -2529, -1508, 14358, -992, -1111, + -940, -111, 968, -530, 576, 102, -1045, 453, + 180, -94, -7936, -310, 512, 996, -32, -1062, + -150, -26, -6687, -181, -336, -1510, 616, 70, + -332, -175, 624, -546, 171, 364, 1011, 68, + -284, -368, 711, 46, 73, -34, -419, 404, + 28270, 283, -324, 335, -131, 316, 212, -27, + -342, -1062, 470, 1269, 454, 286, -1928, -1674, + -739, -389, 1073, -6172, -317, -586, -194, -182, +-13034, -848, 4596, -659, 709, -630, -310, 400, + 344, -276, 430, 876, -2047, -1012, -1672, -180, + 64, 22005, -736, 829, 266, 182, 436, -112, + -36, 131, 252, -63, 154, 368, 107, 93, + -42, -32768, 0, 200, -230, 271, -1776, 4329, + 986, -553, 481, 1888, -2770, 848, -6305, 264, + 12244, 1610, -640, 1348, -2742, -2078, 907, -1115, + 370, -16539, -1571, -176, 24, -515, 234, 954, + 605, 613, -154, 463, 535, -160, 684, 470, + 827, 10458, 150, -669, -6684, 339, -542, -730, + -351, 984, 212, 116, -7, 62, 926, 2175, + -185, -552, 489, -209, 5247, 38, 366, 53, + 16, 263, -142, -535, -224, 338, -174, -125, + 113, -12750, 400, -410, 281, -12, 744, -173, + 486, -12159, -107, -183, -484, 2, 150, 1, + -239, 7, -399, -608, -873, 698, -1623, 701, + -773, 272, -832, -94, -921, 885, 13588, 178, + 192, 148, 1346, 44, 59, -275, -14, -328, + 212, 133, -223, 300, -394, -275, -43, -76, + -47, 322, -208, 21713, 484, 329, 1860, 40, + -916, 502, 130, 477, 1754, 503, 7984, -338, + -323, -230, 354, 928, 430, -89, -94, 108, + -543, 365, -130, 70, 902, -131, 58, 469, + 580, -30949, 36, 232, -410, -451, 104, -8698, + 113, -1682, -42, -279, -92, -280, -477, -386, + -531, 832, 80, -15002, -56, 93, 164, -721, + 8388, -412, -2396, 584, 1004, -310, -2229, -304, + -383, 275, 1062, 1266, 297, -70, -909, 891, + 131, -1046, 539, 32502, 1000, -21, -229, 138, + 1528, -175, 546, 326, 168, -320, 716, -291, + -298, -227, 1094, -59, -12561, 12943, 786, 600, + -206, 889, -761, 54, 332, -1253, -597, 357, + -1124, -50, -168, 1172, 2266, 75, -174, 583, + 408, -157, 14666, 378, 302, -5, 48, 109, + 28, -21, 1044, 529, -859, -1182, -202, 1984, + 308, 402, 66, -1139, 2595, -380, 1119, 309, + 482, -10705, 100, -4591, 11646, -1364, -365, 9521, + -318, -23, 1076, -135, -2742, -833, 78, 910, + 96, -20, -599, 46, 855, -1265, 4748, 2394, + -250, -9096, -962, 191, -346, 348, 342, 1909, + 15330, 266, 540, 271, 2986, 1356, 1542, -1019, + -895, 737, 281, 684, -538, 10414, -922, 287, + 679, 204, -11142, -2321, -346, -1572, -250, -315, + -604, 1336, 311, 1317, -1111, 409, -104, -221, +-14125, -1511, -990, 705, -808, 587, 676, 348 +}, + +.cb0808s0 = { + -7488, -1327, -5244, -2049, -3736, -45, 446, 1558, + -755, -6052, 6034, -4326, 740, -348, 12369, 2115, + -662, -685, -6592, 10176, 8575, -1035, -2752, -4453, + -283, 1547, 4776, -2932, 700, 3425, -3905, 1073, + 2356, -7094, -1705, -435, 4840, -1944, 1188, 780, + -3963, -6170, -1726, 4759, -4356, -2124, -1686, 321, + -901, 1414, -923, -2678, -1198, -14777, -2038, -3528, + 123, 11216, 1904, -1914, 7588, 2744, -4265, -4886, + -3530, -1495, -1709, -5857, 3829, 2196, -4842, -817, + -874, -5649, -2181, -3871, 3774, -1368, 322, -1126, + -996, -3873, 13698, -9369, -848, 3797, -667, -1083, + 2429, -3351, -1672, -3562, -1590, -3507, 552, 6610, + -4137, -10061, -5452, -6142, -1454, 1726, -1298, -4479, + 6126, 1626, -2791, 1584, 1300, 5726, 2584, 11109, + 696, -3344, -2418, 9029, 4346, -3554, 1393, 144, + 2051, 8916, 6174, 5170, 376, 9778, -2298, -4119, + 3733, -35, -2673, 2222, 1383, 2046, 2859, -16131, + 1637, -1195, -662, 2800, -2241, 3801, -5062, -978, + 5670, -5449, -79, 3479, 606, 3766, -1325, -265, + 907, -745, 1005, -14528, -4227, -3955, -7194, 3690, + 2166, -2520, 11555, -511, 5900, -388, -3854, -3440, + 2136, -868, -2986, 722, 1286, -4027, 10382, -1646, + 5193, 2539, 1239, 7819, -67, 3382, -3297, -46, + -3808, 830, 1313, -2188, -4346, 5922, -1057, -6294, + 14317, 2001, 968, 4150, -4121, 1412, -302, -8401, + -1388, 10649, -9513, 1042, 840, -4606, 2098, 1166, + 1472, -802, -2810, 420, -561, -325, 2652, -2866, + 1334, 4878, 958, 83, 456, 1203, -7594, 14590, + -1210, 2202, -1954, -1938, -3413, -1096, 6036, -1675, + -1320, -4485, -10665, 10026, -2484, -3273, 4753, -275, + -3542, 924, 1262, 7348, -2959, -749, -408, 4594, + 4876, -491, 3409, 4616, 110, 557, -1378, -1616, + -4532, 1699, 1412, 579, -494, 716, 197, -23346, + -2284, 156, 1096, -151, -1827, 688, -322, 2371, + -7909, -1324, -1683, 7861, 7074, -451, 258, 9088, + 1900, 8660, 840, 3491, -3275, 3029, -475, -2122, + -5725, -8668, -6069, -3458, 4240, -3007, -5463, 9395, + -2686, 4718, -717, 42, -1802, 3122, -3197, -5212, + -1572, -243, -451, 8213, -2199, -3372, 4110, -8176, +-10525, -5551, 4312, 682, 2069, 1985, -3713, -6780, + 1193, 2831, -2228, 486, -3667, -789, -1691, 4567, + 464, -2114, -2340, -1881, 1921, 1602, 18418, 1535, + -567, 228, -9359, -6027, -267, 3628, 32767, 1423, + -74, -2817, 2112, -128, -1516, -2446, 1673, 2812, + -1582, 2125, 618, 2569, 2714, -1710, 340, 3255, + 848, 3379, -2317, -2361, -1823, 412, -2496, -18164, + -1224, 2552, -3040, 144, -597, 7716, 4916, -2867, + -2172, 2120, -2776, 675, -11985, 1692, -1384, -3588, + 4310, 1020, -4215, -251, -7090, -1916, 1914, -2804, + 6189, -6732, -1370, -3704, 450, -2652, 6553, -38, + 10348, 1244, -2246, -3729, -2158, -1340, 2357, 3118, + 9378, -1727, 3150, -3867, 1277, -15, 769, -2352, + -411, 1428, -14032, -1029, 2828, -1894, 6084, -36, + 518, 13159, 1095, -1185, -3207, -555, -3256, -76, + 3884, 3394, 1010, 1946, 160, -4863, 4714, -7087, + -3985, 5602, 3350, 7822, -5729, -7701, 9296, 3067, + 3582, 5256, 13629, -4012, -2206, -3867, -664, -104, + 4397, -7862, 36, 955, -38, -973, 3458, 5004, + 364, -9116, -2764, -2168, -1892, -7632, -4834, -5788, + -3565, -1245, -4544, 6552, 4601, 2342, 6625, 1040, + 2154, -6985, 5838, -1912, -3439, 1189, -2422, -555, + 3286, -14872, -776, 1228, 2434, 120, 13673, 904, + -1354, 645, -1550, -1377, -1888, 1416, -679, -1685, + 1731, 2404, -5786, 3285, -193, -123, 1973, 3663, + -1388, -14961, -3597, 5555, -1420, 284, 1527, -2575, + 1941, 871, 3900, -2168, -12763, 2970, -408, -3131, + -6426, 1892, 782, 6768, -284, 1034, 9785, 6029, + -3873, -4102, -4349, 2548, -3686, -5622, 4769, -351, + 8178, -7253, 3687, 624, -4386, 4028, -2780, -1938, + -4061, -1872, -1264, 7300, 760, 8530, -821, -874, +-14225, -1143, -5400, -850, -2537, 478, 1668, -1244, + -362, 877, 3481, -1338, -5218, 2091, 3996, -577, + 390, 8626, 820, 181, -988, 5604, 9694, 1112, + -3064, -266, 1234, -486, 1264, -2173, -13671, 3729, + -3212, 2548, 1745, -9363, 8065, 3713, -3343, -4847, + 2808, -4716, -2175, 25, -5718, 4056, 1855, 4663, + 2324, -1166, 543, 2, 3931, -3196, 2771, -920, + -2907, -746, -1241, -306, 2793, -22, -2642, 3048, + 3256, 1804, -1310, 17876, -1816, 56, -1694, -465, + -534, -2274, 6139, -2247, -2515, -1077, 3305, 1519, + 273, 1128, -1637, 2561, -1534, 874, -22808, -1119, + -2551, -10344, -2229, -3510, 194, 2594, 1737, 4713, + 13767, 3532, -311, 8097, -1012, -841, -4360, 793, + -267, -206, 12905, -2683, -6424, 196, 7098, -1690, + -690, 1236, -2882, -2668, -2020, 8291, -2714, -4607, + -923, -2077, -2878, 1687, -10457, -1575, 2172, -3974, + 5795, 1748, -1852, -5143, 4763, -5097, -2840, -1851, + 2634, 5970, 180, -3326, -1655, 1226, 375, 5137, + -2678, -5246, 4327, -3670, 9956, -1976, 2189, 2952, + -6785, -697, 1129, -5768, -5819, 6532, 3650, -1711, + 3857, 47, -9618, -1941, 2524, -1244, 7242, 11646, + -64, 2304, 201, -3707, -700, 149, 2692, -805, + 3978, 2738, -977, -1004, -5776, 12779, 7454, -353, + -4731, -3866, 7076, 146, -3302, 3065, 1955, -343, + -1459, -426, -5906, -1318, 500, -1014, -1002, -2090, + -2924, -20521, 2610, 1581, 397, -3380, -2885, 510, + -1147, 3398, 1914, 99, -119, 144, -3128, 2445, + 1791, 397, 3734, -80, -3410, -3798, -1142, -1515, + -2615, -1540, 5193, 2187, 940, 4969, -2334, -16589, + 325, -2186, -4567, 5121, -894, -6848, -6002, 1832, + -568, 8259, 833, 3420, -4459, -748, 3442, 4358, + -3041, -10203, 9303, -1511, -4821, 1950, -966, 3573, + 453, 705, 16238, -901, -163, -2866, -104, -1767, + -1779, -1249, 3251, 1975, 1254, -838, -390, -3150, + 1020, 2526, -2025, 662, -2817, -1338, -855, -3442, +-21123, 241, -134, -952, -588, 2572, 2080, 8153, + 114, 9732, -6774, -5266, -2462, 2286, -599, -426, + 1396, -7051, -1228, 312, -4495, -2525, 4649, -1305, + -1106, -2366, 2232, 4065, -18674, -1295, -3259, -1004, + -5136, 206, 1177, -5130, 2394, 2518, -1381, 2564, + -138, 4341, 16988, 2546, 6782, -3433, 850, -970, + -255, 1308, 2228, 1704, -1283, 1452, -2608, 1487, + 3106, -2267, -2998, -6814, 1654, 21195, 1555, 968, + 154, 124, -1258, 714, -407, 44, 247, 992, + 2228, 2824, 1435, -341, 1212, -1612, 6126, 1636, + -8368, 578, -5418, 217, -191, 204, -7147, 5110, + 3766, 5055, -5979, 6683, 368, -3597, -4595, 7630, + -3611, -2384, 1369, 6995, -3299, -53, 2036, -4654, + 4259, 9618, -1012, -2964, 4397, -2112, 11885, -1648, + -942, -3474, -544, -1410, -1958, -1535, 2981, -1591, +-16787, 335, 4609, -1990, 3821, -645, 1842, -64, + -3485, 3202, -374, -58, -1410, 7304, -1958, -2142, +-11412, -2533, 513, -6149, -6679, 2152, 3153, 5102, + 2216, -1361, 2260, 4863, -7031, 1538, -5250, -2511, + 96, 3339, -3447, -3708, 7168, -4168, 838, -3134, + 3228, -1531, -5598, 14125, 208, -2150, 819, -1085, + 12282, 6714, -2778, -9252, -5117, -6623, -1711, -4253, + -6306, -1292, -1370, -1027, -908, -2863, -1832, 4645, + -722, -284, -161, -5106, 7110, -12494, -1514, -5453, + -3308, 3520, 1101, -1096, -2325, -746, -33, 2645, + -4458, -797, -684, 1514, 1716, -6204, 6580, -3427, + -650, -10493, 4868, 5833, -2385, -274, 1530, 3892, + -1940, -1415, -2389, -11499, -2064, 937, -333, 1361, + -1583, 5458, -2296, -3263, -8344, -4236, -6357, -2372, + -3115, 1336, -2184, 194, -4262, -7838, 6946, 4535, + 749, 7332, 67, -327, 273, 3211, -1825, -357, + 7039, 3346, 6282, 488, -3940, 10196, 6463, 327, + 4407, 909, 889, -4943, -622, -4049, 2532, 1870, + 652, 1778, 663, 3063, -1012, -1390, 4162, 20486, + -86, 3166, 325, -1912, 511, -634, 1262, -4719, + -1490, 6767, -3314, -125, 4490, -10334, 5386, 9932, + 781, 290, 2198, 1695, 3790, -1878, 7760, -300, + 2021, 5508, 2200, 232, 7138, 1370, -3268, 3496, + 13934, -1230, -2303, 958, 141, 3348, -2867, -987 +}, + +.cb0808s1 = { + 9313, 734, 6610, -3629, -12020, 5317, -244, -1858, + 2, -1812, -6486, 892, 926, -236, 1016, -1249, + -469, -238, -1908, -10594, -4704, -907, -7746, 3847, + 564, -5956, 3395, 371, -5136, 4001, 1180, 769, + -555, -1872, -2943, -1744, 8620, 1485, 9901, -1392, + 3425, -7940, 151, 376, 1984, 3031, 3815, -974, + 537, -7038, 1964, -5625, 4457, -10214, -1787, -2768, + -8514, 176, -3692, 6441, 3148, 602, -2000, 13769, + -2792, 1104, -2067, -6219, 1515, -288, 3240, -5490, + 11589, 3742, -2343, -1752, 3701, 7525, -1676, 845, + 6895, 2884, 3540, 2454, 1010, 2454, -5761, 2035, + 3369, -9628, -862, -7060, 1802, 5676, 2396, 2757, + 5891, -701, -11896, -4061, 7932, -272, 2562, 83, + 560, -5180, -2223, -356, -3343, 2874, -1370, -7612, + 1773, 2006, -4258, 5312, 342, 8196, 4939, 519, + 3568, 4420, 2768, -11872, -3021, 1893, 1690, -5483, + -8129, 7540, -116, -2064, -4473, 1141, 1930, 656, + -7728, -2742, -3276, 2782, 2860, -6082, 5198, -4751, + -486, -789, -16932, -566, 5116, 1196, 832, 4282, + 78, 3088, 2768, 2125, 1027, 1712, 310, 808, + -1595, -106, 3174, 4598, -2945, 1551, -7688, 620, + -1640, 339, 4538, 3339, 532, -351, 260, 249, + -2135, -543, -18362, -648, -3871, 5514, -1782, -11301, + -374, -2078, 1610, 50, -4439, -2546, -3058, 839, + -9221, 2618, 1790, 103, -1061, -363, 285, -3542, + 503, -437, 30, 1382, 75, -2852, -1028, 3095, + 4318, -2316, 739, 801, -22765, 2162, 913, 1698, + 149, 2049, -313, -803, 3393, -1476, 4396, -4003, + 854, -1344, 1062, 10009, 6332, -8522, -2616, -9904, + -390, -3146, -2951, 4222, 5538, 495, 3776, -13684, + 4687, -2187, -905, 4997, 6209, 4775, -1234, 1956, + -4607, 3006, -370, -670, -12448, -5802, 8151, 140, + 1485, -6340, 2139, 1231, 22, -212, 2090, -676, + 2366, -701, -4113, 365, 2970, -577, 918, 7324, + -709, 2035, 5162, 7232, -13287, -3259, -908, -1900, + -4255, -2590, 318, 4891, 696, -40, -1647, 1572, + -1221, 4896, 5241, 49, -2083, -5068, 7645, 8978, + 1628, 2895, -4930, -8068, 2266, 2025, -1868, 3250, + 2642, -785, -14571, 9979, 3481, -2246, 1154, 2646, + 2616, -2033, -2936, -1300, 2490, 879, -1237, -1228, + -724, -1780, 524, -6619, -3339, -2526, 3533, 844, + 2946, 2208, -3522, -12411, -3062, 2380, 448, 604, + -4708, 2403, 1914, -58, 149, -3704, -2019, 4246, + -7020, -3197, -712, -2219, 10036, -2776, -3166, 2648, + 2947, 3386, 6445, 1587, -268, -536, 1895, -9005, + 10791, -982, 8215, 6414, 5166, 4751, 160, 3050, + -865, 6216, -1187, -7077, 1640, 5078, 4354, 1762, + -3869, 1174, -149, 1078, 1884, 5149, 15091, -432, + -2441, -1102, -1194, 1078, -1535, 8289, -2702, 4007, + 694, 72, 685, 2816, 13244, -422, -7094, 432, + 2044, -12004, -276, 2174, -908, -4784, 5725, -250, + 22, 5116, -2, 2686, 955, -8509, -7697, -3735, + 672, -1202, 4299, 4284, 12352, -2362, 5757, 1317, + 4293, 508, 3050, -524, 1097, 3346, -537, -2440, + -1596, -5659, 4188, -625, 1659, 3061, 2791, 1712, + -2991, 966, -16903, 610, -3314, 4160, -3750, 580, + -3407, -340, -11829, -520, -1625, 2905, 674, -147, + -5284, -4278, -5021, 4635, 6299, 2207, 2595, -7811, + -68, 4107, 4314, -1540, -11044, -2214, -803, 232, + -7602, -95, 1130, 4991, -361, 1675, 4487, 3607, + -6192, -130, 137, -1440, 2826, 178, -13834, -984, + 1149, 1230, 1587, 1571, 3286, 5293, -2259, 2021, + -6211, -7608, -2710, 2502, 4315, -539, -8530, -746, + -654, -4003, -5917, -3728, 4522, -10350, -1266, 210, + 5078, -2988, -3866, 3919, 969, -1063, -6300, -4584, + -2420, -2094, -884, 2338, -3150, 5461, -1145, -734, + 1644, 2183, 19114, -1144, -2313, -404, 1236, 3583, + 134, 1802, -4088, -2795, 681, 3738, 1831, 16571, + 917, -2290, -3648, -1588, -158, -528, -792, 394, + -7432, 2446, 402, -391, -73, -1398, 1286, -6503, + 5216, 1094, -939, 1673, -2038, 15842, -1971, 4160, + -1664, 7231, 642, 5770, 4209, -1839, 220, -266, + 165, 2055, 5222, -3344, -6544, 5412, 1514, 586, + 1591, -15256, -2715, 941, 1308, -9170, -2863, 4935, + -2913, -1291, 2791, 7967, 14, -1101, 3774, 3580, + 848, 1337, 1138, -2839, -3564, -5300, 12429, 14, + 1466, -7114, 1198, -3474, -237, -2577, -1305, 445, + 1069, -174, 1684, 3902, 229, 5842, -690, 978, + -754, 1182, -859, 21078, -185, 710, 797, -2155, + 367, -2168, 1002, 3805, -924, 468, -2322, -3590, + 1608, 3387, 18, 1536, -858, 642, -7964, 17689, + 9843, -4878, -3003, 7373, 5934, 4286, 10484, -63, + -4629, 974, -2227, 2602, 3810, 1905, -1668, -2130, + 2020, -2360, 2853, 612, 5070, -1248, -868, -497, + 3478, -1937, -3006, -645, 3589, 3019, -3293, 16469, + -5243, -2918, 1788, -2569, 3717, -9630, -1352, -3870, + -416, -4190, -8863, -6888, -498, -814, -783, -4625, + 5841, 1562, -2173, 481, 280, 816, 4742, -9962, + 11799, -2029, -2460, 4972, -600, -1452, -1901, -2122, + 3130, 2686, -819, -2366, 866, -2093, 1052, -58, + 284, 3830, -4738, -4114, -1321, 1307, -2820, 4915, +-11701, 522, -1982, 7024, 8403, 1762, -46, 532, + 5097, 5013, -615, 3086, 2089, 6899, -1107, -4047, + -2903, 5356, -4802, -965, 6706, 3895, 9022, 1388, + 10971, 5927, -2954, -965, -3473, -5177, -2654, 3418, + -5315, -16695, -6587, -416, 404, 1230, -2586, -3292, + 1390, 14, -481, -4446, 1335, 109, 1060, 3958, + 1275, -5655, 1253, -2411, 207, -12550, 6208, -2447, + -3415, 2503, 848, 3094, 9336, 2647, 2455, 2238, + 2356, -2132, 5347, 915, 2227, -103, 5832, -2504, + 7562, 9568, -6100, 4091, 2668, -1722, 287, 6763, + 4058, -387, -2060, 5522, 3184, 4766, -158, 650, +-11284, 11841, 6230, -4232, 5308, 3174, 4926, -2970, + -4761, -980, 117, 1944, -1974, -5484, 6534, -266, + -7222, 924, -2654, -588, 9609, -2337, 1892, -2110, + 5088, 1856, 7964, -4029, -940, 1429, 805, -4705, + -1362, 892, -189, -8354, 3259, 194, 767, -2877, + -4165, -990, 12185, -160, -2002, -1384, -5388, -1604, + 226, -6353, -4157, 1773, 2360, -4356, -730, -5462, + -4054, -15669, -1528, -394, 4101, -203, 2792, -787, + 3391, -299, 6384, -1630, -7186, -12765, 4618, 934, + -401, 2790, 2284, -4932, -1260, -6009, -2590, -2285, + -1289, 3366, -4192, -4462, 32767, -3135, -1888, 67, + -2874, 150, 4760, -1571, 584, -2187, 358, -1733, + -1286, -4573, -2003, 1872, 940, -1942, -255, -8856, + -1320, -3348, 4854, -509, 2836, -14, 2490, -1537, + 882, 1188, -3132, -15209, -1633, -44, -2827, 368, + -1099, -1073, -467, 6318, 5863, 2840, -5200, 569, + -2984, 6587, 9596, -4924, 457, 4879, -4449, 3528, + 1868, -3894, -3905, 15420, -2590, -599, -4975, 3892, + -1454, -616, 1890, -2700, -3268, -1386, -1065, -3078, + -2454, -1902, 4726, -34, -4218, 1619, -3074, 5540, + -6392, -3570, 2687, -8742, 333, -106, 2326, -1737, + -3775, 397, -3553, -6632, -6066, 9567, 2904, -889, + 1136, 1295, 19390, -268, -3127, -180, 1696, -814, + -775, -4914, -456, -758, -866, 1102, -3740, -374, + 469, -6902, 1440, -10243, -6221, -4797, -3074, -1142, + 297, 5069, -1547, 5474, 716, -454, 3806, 4100, + 2901, -2169, -744, 5032, -5586, -2986, 2286, 2414, + 7860, -2672, -46, -10046, 5348, -1018, 1016, 9142, + 4543, 5587, 2228, -2684, -4594, -2457, -1850, -3651, + -1806, 4826, -11686, 1940, -3529, 1078, -5234, -2420, + -83, -2322, -5134, -775, 677, -9257, -864, -915, + 4494, 411, -4820, 5999, 4472, 5823, -4597, 3121, + -1868, -1539, 2338, -4249, 1154, -13422, 791, -1235, + -1240, 364, 177, -1508, -2527, -2949, -2062, 118, + -3115, 293, -1927, 18644, -1100, 152, -2528, 1914, + -1380, -1624, 302, -831, -920, 320, -879, -1252, + 813, -11, 6960, -522, 3092, -119, 1486, 3068, + 6690, -3079, 13305, 6342, 937, 1632, -1026, 1896, + -2335, -3961, 5510, 2782, 187, -2448, -1251, 756, +-15856, 3179, -1155, 808, -1748, -6593, 1494, -3122, + -98, -3808, 491, 1752, 3188, 2158, -1924, 763, + 1165, 148, -3161, -1284, 18082, -195, -1125, 845 +}, + +.cb0808m0 = { +-18656, -461, 236, -1122, -796, -101, 851, -3748, + 1374, -8549, -3366, -1482, 1026, 2046, 4394, -521, + 232, -486, -1656, 32767, 1954, -1183, -130, 392, + 194, -868, 2883, -168, -1674, -910, -34, 819, + -1105, 1628, -4871, -585, -1170, -572, 451, 3911, + 10770, -35, -4126, 7124, 7110, -860, -3914, -3294, + 272, -647, 220, 11965, -3378, 2726, 1990, 1624, + -3689, 9884, 2394, 3096, -518, 5169, -4018, 3108, + 168, 1256, -410, -3851, -11176, -10479, 2042, 1421, + 1488, -992, -1562, -653, -1191, 2246, 467, 4732, + 154, 729, 7244, -18, 1313, -51, -1824, 1218, + 1473, -6763, -11270, -4295, 4118, 1043, -5782, 1370, + 46, -11027, 4086, -1501, -11, -621, 464, 781, + 13680, 257, 554, 3119, 750, -1857, 1046, -1252, + -512, 739, 14811, 12642, 3841, 2824, 163, 1620, + 39, 4766, 1411, -2197, 525, 658, 419, 5, + 92, 1544, 290, -2038, 10603, -5764, -3335, -6629, + -2579, 4020, -3107, 2779, 849, 5678, 260, 2804, + 99, 1339, 544, 1438, -450, -598, 764, 1568, + -1034, -4560, 2604, -18205, 1644, 1003, -675, 3217, + -334, -832, -1452, 322, 608, 300, -4776, -812, + -36, 627, 1654, -248, -838, 21571, -89, -1626, + 530, -1151, 9440, 522, -6138, 2213, -10095, -562, + 1000, 5037, -122, -3, 7064, 397, -2118, 362, + 15791, -1047, -15010, -1527, -1356, -2805, -560, -3148, + 266, -45, 1324, -3312, -1772, 2382, 189, 6537, + 124, -1272, 156, 588, -2678, -3106, 2828, -3684, + 689, 3884, 4650, 192, -323, -5426, -722, 11486, + -607, 3591, 4299, 2117, 362, -9114, 11700, -3391, + 2357, 7639, 2197, 4350, 2970, -2525, 169, -6112, + 91, 1520, -19, 1558, -4588, -837, -8163, 897, + -7992, 2080, -3102, 774, -10592, -314, -137, -524, + 87, -799, -111, 74, 1312, 862, 266, 243, + 199, -288, 1205, -829, 1650, 2880, -24776, 3867, +-13101, 597, -9778, -2084, -3089, -1112, 548, -638, + 3727, -446, 4877, 2099, 68, -2736, -4914, -7103, + 263, -9228, -782, -2109, 1088, -1881, -1424, -30, + -1353, 586, 4085, -3573, -11921, 2366, 516, -1028, + 834, -234, 2150, -15893, 2305, -3619, -2567, -8366, + 610, 2946, -2383, 2293, 946, -3550, -6770, -1481, + -758, -864, -232, 2855, 40, -2330, 2069, -345, + 1801, -589, -1241, 647, 6988, -2625, 14308, 2801, + 759, -2740, -680, 964, 365, -506, 22268, 1766, + -202, -2751, -293, 3754, 1280, -521, -3355, 4615, + 594, -1783, -39, -46, 48, -2638, -551, 2548, + -1880, 3730, -1726, 939, -345, -7, -1630, -23405, + -1002, 5655, 2100, 440, 1682, 1020, -594, 344, + 1511, -1286, 5518, 473, -11398, -4552, 720, 4701, + 7726, 126, -1953, -484, -1648, -1766, 1589, 996, + -688, -381, 1678, 1498, -528, -860, -667, -823, + 32767, -463, -243, -1242, 1074, 2460, -1411, -459, + -1533, 1462, -2603, -784, -391, 338, 3444, 2170, + -924, 949, 1972, 1520, -3062, -671, 12908, 2636, + 2805, 722, -12016, -26, 616, 1192, 1193, -1028, + -128, -22850, 191, 408, -3105, -592, -440, 1264, + -2580, 847, 850, 2300, -278, 126, 2214, -2693, + -21, -194, -594, -533, 45, 570, 38, 636, + 1276, 171, 29846, 648, 911, -358, 300, 602, + 413, -10167, -54, -1353, 42, -1770, 491, -12154, + -1808, 26, 425, 2009, 910, -8134, 362, 2001, + -114, -2586, -1049, -249, -312, 160, 1677, 27043, + -44, 160, 834, 243, -606, -272, -979, -1605, + 105, -491, 754, -230, 2442, 24, -5139, -395, + -3562, 14436, -1208, -3232, 2555, -12980, -906, 429, + 217, -432, -1263, -244, -225, 912, -64, 780, + 1101, 854, -240, 308, -28630, 518, 32, 976, + -8642, -3041, 1801, -742, -1513, 128, -3189, 857, +-14277, -1802, 1229, -68, -565, 65, 4094, 1614, + -8254, -1153, -640, 16225, 3508, -1383, -3882, -347, + 1346, 3845, 2665, 2340, -1862, -5318, 1402, -1352, +-21682, -694, -1182, 286, -806, 2133, 1848, -532, + -3750, 7564, 1054, 284, -3742, 2559, 2748, 3408, + -1544, -342, -22578, 1225, 958, 2559, 267, 378, + -3608, -1404, -1669, -13, 1135, 153, -625, 1436, + 211, 556, 739, 1094, 10452, 850, 5128, 11469, + 121, 4937, -3643, 1371, -373, -6686, 229, -3256, + -75, 1304, -1023, -452, 288, 12709, 13572, -501, + 1840, -1044, -2014, -4077, -2726, -1010, -3826, -629, + -466, -923, -847, 5784, 898, -12036, 1253, -1741, + 1546, -3710, 2782, -3430, -1810, 263, -8254, 3126, + 55, -376, 202, 968, -1686, 944, -15300, -2664, + 1393, 783, -11080, 1714, -1666, -1064, -4859, -2344, + 334, 1313, -1209, 877, -1828, -2130, -3057, 340, + 8030, -3222, 11622, -5620, 1469, 3340, 2862, -3945, + -868, 351, -1314, 2277, -2346, 12384, 996, -2460, + 1810, 703, -2158, 3168, -9887, 8754, 3503, -1414, + 445, 850, -30, 2389, -617, 3271, -1606, -5633, + 2993, 10009, 5704, -11589, 4278, 1304, -2418, 479, +-16596, -12349, 2915, 327, 895, 1278, 1412, -310, + -653, -1287, 880, -4294, 38, 2179, -2074, -1810, + 198, -1544, -8008, 2456, -2821, -3223, -3713, 11763, + -2081, -141, 4833, 1652, 3598, 551, -1655, -1154, + -60, -302, 739, -1494, 2595, -1006, 2665, 10834, +-11270, -2996, -636, -446, 1816, -1539, 4149, -184, + -100, -55, 265, 2207, 639, -162, -2210, -626, + 605, -21149, 2163, -970, -330, -4655, 3396, -3092, + -544, -650, -304, 93, -1484, -888, -8982, 1871, + 1701, -1423, 1671, -11, -1287, -14292, 592, 1040, + -622, 13202, -660, -12745, -2836, -1832, 3481, 1546, + 235, -646, 2132, -602, 2391, 1534, 3599, -4932, + -296, -1855, -2075, -2646, -219, -10248, 1161, 5955, + 6954, 9109, 3498, -5932, -1787, 373, 1234, 1244, + -813, -76, 9083, -5120, -499, -1774, -2150, 10601, + -170, 1160, 982, -597, 95, 151, -534, 6554, + 840, -958, -720, 2066, -50, -2877, -74, -2068, +-24760, -725, -357, 1273, 1941, 2525, 46, -819, + -230, 1030, 2291, -287, 1092, -2315, 427, -19, + 448, 1698, 9797, 10962, 3034, 2622, -2652, -1128, + -194, -180, -1176, -1794, -22248, 244, -3, -1856, + -1054, -2751, -459, -62, -433, -2274, -1790, -192, + -720, -421, 55, -721, 1960, 1094, 2500, -2353, + -480, -784, -1221, -505, 1738, -9960, -10772, -13657, + 122, 387, -667, -454, 988, 30780, -757, -2319, + 878, 962, 753, 1306, 716, -771, 539, -705, + 508, 1915, 2114, 937, 447, 935, -1432, -1143, + 4435, 11759, -2442, -53, -10601, 1979, 5419, -2296, + -172, -5987, -1168, -2012, 2257, -1451, 97, -1253, + 5548, 884, -14448, 3134, 2549, 172, 5404, 869, + -83, 597, -12416, 762, -1035, -805, -1369, -804, + 664, 9644, -4329, 1130, -1526, -2900, 628, 620, + -6436, -2370, 2107, -11836, 37, 864, 2105, 314, + 216, -529, 810, 3141, 3716, 7019, -2653, 1466, +-14940, 13128, 1218, 2287, -145, -443, -923, 476, + 2411, 5428, -611, 2212, 1450, -3042, -4750, 3562, + 587, -15378, -15151, 600, 1029, -2353, -934, 1986, + 1444, -2171, 1020, -700, -1508, 195, -2466, -798, + 16460, -2164, 520, 2711, -13832, -2024, -871, -5268, + 3556, 117, -416, -8, 2128, -1570, 2052, -3169 +}, + +.cb0808m1 = { + 16492, -295, 2556, 1303, -440, 7584, 3305, -3422, + -1196, -1809, 2142, -1292, 1048, 314, 1945, 578, + 1080, -255, 1109, 617, 1597, 198, -29081, -243, + 54, -33, 76, -418, 1332, 475, 1495, 1554, + -782, 308, -1286, 1044, 300, 1544, 646, 9441, + 2577, -11140, 1421, 1107, -483, -590, 625, 8544, + 446, -1814, 1714, 685, 9620, -4981, -3100, -724, + 8439, -2333, 506, 3557, -1160, -2199, -659, 4107, + 8620, -1406, -3745, 1729, 10756, 868, -82, 2584, + -3140, 3632, 2617, 3880, -1175, -163, 1864, -980, + 551, 201, -433, -1464, 708, 1926, -8471, 3870, + -2376, 15567, 2112, 753, -2450, 72, 1131, 2932, + -139, 6392, 1547, 3, 625, -823, -1750, 811, + -977, -1389, 1300, 1184, 399, 4684, 196, 3679, + -1672, -218, -11023, 98, 492, 4072, 1213, -2004, + 3602, -1787, 1288, -9442, 4157, -4267, 3509, 5317, + -574, -11094, 1078, 6240, 1593, -12773, 408, 3960, + 1116, 1517, -816, -577, -696, 554, 1645, -936, + 83, -20255, -754, 1460, 1110, 1412, -757, 377, + 2373, -1608, -1414, -1028, -3152, 1534, -4145, 2274, + -286, -7058, 2286, 4013, 2515, 2681, -5602, 0, + -1740, 257, 756, 11496, 954, 4513, 3968, 4851, + 278, -511, 829, 2853, -9743, -3723, -1550, -444, + 4256, -679, -11411, -4290, -1470, -4191, -952, -239, + -198, 1361, 9527, 1481, -981, 1403, 991, -255, + 9326, 1832, -1936, -135, 1123, 2756, 1932, 2543, + 795, 12612, 2429, -498, -13185, 3812, -1628, 196, + 1822, 4333, 2760, -676, -2902, 1244, -1974, -7046, +-12216, 1503, -2176, 1916, 365, 636, -11348, -5030, + -3319, -3794, -1016, 1157, -4158, 3424, 344, 4494, + 812, -3074, 4356, 293, -3463, 1232, 1746, 2696, + -8269, -961, -4316, 130, -4278, -14007, 3025, -2703, + 179, -10176, 1511, -1460, -1100, -1171, -1575, -2596, + -2026, -11400, 2689, 1480, 743, -1669, 2728, 742, + -60, 11452, 84, -662, 1424, -15103, -410, 2141, + -1664, -1378, -122, 97, -358, -820, 382, -3865, + 374, 1698, -21, -752, 595, -8771, -731, 9368, + 1698, -2586, -6790, -2507, -1776, 4993, -3867, -2807, + -190, 14465, -13938, 3095, -1198, 374, 1682, 1888, + 286, -576, -2094, 454, -690, 1396, -1139, -422, + 405, 238, 1718, 2048, 13448, -151, -247, 202, + -900, -5630, 3121, -10988, -1615, 1955, -3901, 3360, + 1429, 3928, 1951, -1099, -435, 1572, 1500, 19176, + 731, -439, 3686, -3039, 244, -4270, -34, 1289, + 296, -406, 2216, -1400, -1946, 264, 1536, 2992, + 54, 892, -181, -1545, 278, 24923, 989, 1301, + -1279, -188, -198, -661, 612, -1520, 2355, -12972, + -694, -560, 1364, -2988, -6236, 2555, -6630, 1423, + 440, -598, -1092, 304, -2529, -1698, -909, 2560, + 844, 768, -2988, -661, 18432, 1158, -639, 5070, + 11015, -14, 2313, 756, -1941, -10986, -490, -5235, + 2646, 2406, 170, -546, 337, 6499, -4450, 5598, + 299, -504, 14322, -972, 9356, -2056, 8812, -1599, + -1931, 2084, 119, -983, -305, 1437, 403, 2651, + -159, 229, 209, 1438, -1789, -1159, 1017, 416, + 408, 454, 858, -652, -1554, 1198, 18278, 122, + 433, -165, 162, -10532, 11563, 4754, -2022, 4246, + -1396, -2417, -1796, -1496, -1279, 3877, -1217, -770, + 983, -609, 1766, -184, -5664, 546, 7948, 1978, + -250, 4350, 3498, 2797, 802, 846, -12628, -1092, + -240, 781, -11252, -955, 9944, -222, 1177, 1262, + -534, 1790, -7396, 1452, 4251, 303, -3714, -2295, + -290, -227, 672, 22690, -622, -466, 1599, -496, + 326, 871, -1948, 148, 449, 214, -2175, 713, + 394, 1921, -28716, -786, 1083, -641, 1232, -246, + 1572, 1575, -879, -2962, -57, 369, 1633, -1457, + 1194, -1222, 304, -955, 104, -1249, -935, 135, + -758, 3483, -1190, 1457, 1130, -1284, -3709, 18042, + 6, 25, 1233, -328, 347, -512, 2071, 328, +-18037, 4582, 3841, -434, -745, 332, -576, 3006, + 336, -11505, -646, 3509, -996, 1270, 2041, 1353, + 1193, 2976, 11569, -3165, 1450, 4351, 2522, -10022, + -6, 12602, 874, 518, 475, 1251, -3290, -2674, + 4802, -11794, -946, -426, -2846, 1619, 1105, -1022, + -1, 1759, 646, 10347, -2937, 13505, 1104, 614, + 1149, -800, 2377, -115, 792, -948, -2431, -1779, + -1142, 809, -3130, 447, -15516, 313, 11235, -1346, + -2426, -2737, -1738, 2236, 1094, 802, 1323, 3612, + -213, 1383, 2800, 10394, 1210, -2360, -10203, -1991, + -102, -2669, 2303, -2184, 1830, -1158, -5633, -4083, + -252, 311, 612, -331, -2786, -12421, 9994, -6006, + -4996, -954, 1014, -1147, 860, 1252, 1114, -2069, + 266, -230, -591, -4442, 230, 20603, 1386, 1130, + -1468, -3600, 2168, 836, -1754, -511, -542, 216, + 26, 3476, 1165, -4293, 3098, -245, -579, 1830, + 2248, 5326, -18357, 397, 5466, 734, 3920, -3678, + 319, -1062, -610, -7509, -1064, 1456, -5729, 1088, + 9099, 2266, 241, 201, -10017, -1545, -2799, 1491, + 27098, -60, -1736, 1387, 859, -1474, -79, -1122, + -971, -1302, 906, -1133, -2659, -296, 1344, -2698, + -448, -1476, -212, -1585, 1310, 14353, -2165, -2229, + -656, 5219, -3266, -1850, 7942, 4997, -2295, 519, + 608, -9498, -1700, 1770, -15308, 1286, -2914, 2252, + -717, 2136, 2478, -3747, 2362, -5, -237, 2334, + 701, -774, -672, -20, -599, 623, -700, -713, + -979, -29926, -1090, 848, -141, 1273, -711, 1782, + -221, -103, 170, -185, -1059, 3066, 1321, 1182, + 3641, -217, 1959, 11806, 2390, -10312, -2575, 1612, + 596, -352, 2197, -2041, 2385, -898, -9363, -1144, +-10896, 20, -7842, -1047, 3687, 2147, 2584, -249, + -72, 32767, 1936, 446, -889, -845, -896, 1269, + 448, 327, -3411, 4, 702, -1900, -646, 799, + -770, 662, -911, -856, 287, 1667, -108, -64, + 16, 1578, -2059, -27327, 112, -188, 2504, -692, + 250, 360, 564, 868, 4147, 1340, 18080, -3584, + 445, 364, -2623, -412, -2918, -116, 2611, -2396, + -44, 10934, -1512, -1166, 239, 913, 190, -14681, + -767, 2610, 2931, -2389, 3590, -1680, 6287, -531, + -616, 1317, -1034, -900, 871, -329, 467, 1200, + -1914, 1108, 3150, -6878, 544, -14411, 2807, 5427, + 13361, 1448, -1753, 524, -5851, 1467, -1866, 6888, + -8742, 1372, -1515, 4883, -2248, -1042, 4628, 10768, + 149, -358, -1287, -1289, 32767, -1137, 941, -2112, + 451, -1436, 174, 294, 475, -3667, 1610, 1641, + -599, 626, 2058, 671, 1626, -985, -123, 2040, + 421, 1797, 18448, 2538, -359, -5042, 3096, -1136, + -320, 1823, 30, -12002, -1297, -850, -418, -1497, + -1761, 5073, 10944, 212, -4713, -1614, -1752, -2135, + 483, 1043, -1989, -293, 39, -1049, 67, -7482, + 712, -5358, 896, 12460, -1744, -1793, 1538, 3577, + -6, 418, -72, 1072, 1367, 1080, 3564, 1468, + 482, -1298, -6442, -299, -12934, -757, -4199, 3842, +-11331, -1216, -206, 1598, -1135, -3240, 3294, -286, + -540, 777, 1188, -1189, 4516, 2638, 2071, 9702, + -900, 1002, 18707, -705, -1856, 1185, -4832, -1694, + -3502, -2324, -2826, -4600, 1996, -3110, 110, 117, + 405, -16854, -510, -14725, 1699, 1922, -2117, -2718, + 45, 1064, 507, -1781, 2106, -2310, 1239, 5860 +}, + +.cb1108l0 = { + 2354, 8016, 12528, -947, -348, 1760, 2054, -3960, + -2125, -3578, 3932, 1647, -3316, 6053, 392, -3128, + 3209, -2445, 463, -2835, -1555, 1259, 296, -1465, + 1839, -4811, 420, -215, 469, -1013, -272, 185, +-27061, -1154, 8, 298, 259, -953, -555, 472, + 617, -1127, -673, 982, -398, -1681, 328, 882, + 614, 800, 431, 84, 880, -240, 15758, -14324, + 1301, 1578, 932, -694, -1456, 2435, -1651, 1464, + 227, 1527, 527, -128, 698, 2405, -726, 1489, + 1016, 1938, -1897, -1478, -238, 932, 2507, -519, + -1147, 557, 2334, 700, -12914, 14861, 158, 255, + 1195, -883, 3359, -1045, 2095, 520, 249, 926, + 789, 1392, -185, -1654, 902, 9, -2166, -1916, + 543, -2126, 2842, -332, 1356, -344, 436, -404, + -174, -489, 858, 258, 229, -45, 327, -316, + -1176, -454, 115, -220, -458, -194, 271, -530, + 1572, -574, -25068, 167, 601, -1027, -1705, -3144, + -4231, -1636, -1012, -1002, -519, -825, -458, 945, + 546, 193, -17909, -156, -1067, 826, 338, 1152, + 562, -506, 848, 239, 188, 656, 97, -174, + -59, 242, 1946, -67, 745, 2043, 424, -192, + 574, -524, 1553, 566, 1480, -747, 487, -20623, + 872, -1089, 1034, 1357, 919, 153, 154, 498, + 54, 555, -989, 707, -85, -21, 700, -1424, + 90, 655, -399, 123, -709, 117, 438, 330, + -720, 190, 812, -138, 460, -32768, -162, -410, + -327, -122, -1208, -554, -502, -178, -309, 373, + 4295, -945, -5502, -2752, -6615, -1241, 1278, -1315, + -7683, -986, -419, -50, 2384, -4640, -6246, -11804, + -308, -446, 3486, -4824, 1736, -590, 960, 195, + 593, 164, 3355, 1655, 1233, 66, -787, -347, +-13751, 74, -1209, -812, -4098, -102, 910, -1659, + -2036, -3147, -2075, -2605, -1240, 4499, 1727, -9484, + 549, 728, 3411, 1958, -4439, -1064, 5690, -1600, + -1984, 1695, -588, 4815, -138, -3380, -512, 1553, + 1978, 4310, -730, -402, 828, 2124, 14216, -222, + 2757, -8686, 523, 2516, 1017, 790, -136, -470, + -252, -717, 808, -1113, 13766, -114, -1182, 3053, + -5238, -2231, 1720, -511, -987, 1592, -1257, -2578, + 1777, 1075, 2367, -227, 2330, -672, -2620, -1449, + 2122, 362, 1249, 1338, -327, -21631, -1540, 24, + -2356, -656, 1981, -92, -207, -2188, 34, -457, + -1291, 1231, -460, -128, -396, 593, -671, -1513, + 136, -335, 560, -1121, 490, 1008, 948, 8629, + -3344, 467, 881, -5731, 1120, -300, -1432, 1227, + 1558, 990, -1078, 214, -922, -81, 1120, -15586, + -1176, 1203, -1911, 151, 1484, 1555, -421, -420, + -428, -762, 292, -59, 1075, -649, -841, 494, + 194, 27, -768, -356, 54, 163, -73, 293, + -1717, -392, 750, 234, 751, -111, 26858, 911, + -389, 451, 442, 260, -117, 270, 19, -2429, + 618, -962, 378, 10, -1954, -1336, 525, -258, + -693, -4155, 10265, 2924, -1361, 3197, 10199, 6870, + -2608, -5792, 619, -1994, -2035, -701, 2598, 465, + -575, 311, 175, 162, -1191, 162, -157, -147, + 325, 551, 536, -188, -290, -165, 343, 14, + -268, -27113, 278, 127, -233, -68, 606, 125, + 665, 438, -442, 2510, 800, -1991, -641, -386, + -1574, 78, 946, 189, 106, -2249, -268, -1708, + -1192, 986, 3076, 1807, 21, -5884, -964, 256, +-15916, -1320, -2867, -3562, 491, 3502, -337, -1542, + 496, -3182, 1676, -2371, -4264, -2053, 14342, -5674, + 1744, 1813, -3731, -3761, 1350, 1783, -438, -920, + 2366, 1438, -687, 512, -1934, 323, -3158, 1775, + 1964, -6742, 10162, 7763, 1469, 1967, 851, 2742, + 7413, -3338, 742, 1854, 310, -192, -936, -1770, + -775, -976, -1532, -1436, -670, -4032, 1194, -1336, + -4369, 332, 604, 962, -27563, -972, 842, -743, + 275, 713, -251, -799, -1190, 372, -213, -423, + 202, 1189, -31, 1084, -974, 756, -148, -1669, + 640, -549, -339, -1506, -112, -598, -870, 410, +-13307, 13141, -1911, 2308, -92, -776, 221, 1503, + 1578, 803, -308, -1672, -404, -83, -3517, -1327, + -606, -2426, -61, -513, 318, -1805, 2049, 1887, + -777, 1268, -542, -116, 3550, -18840, -2986, -979, + 2653, -2875, -922, -10520, 804, 107, 3234, -1270, + -608, 1042, 3599, 965, -342, -2096, -267, 1704, + -3939, 791, 2180, -985, 816, -716, -2661, 99, + 1523, 11902, -1782, 775, -12517, 3244, -3762, 2046, + -278, 1539, 2895, -2425, -10, 990, 1484, -1377, + -3399, -984, 3171, 1513, 696, -785, 155, -1072, + 414, 2016, -1932, -3124, -1126, 68, 3855, 1360, + 4074, 17596, 1714, -596, 4000, 1656, 230, -258, + 2266, 843, -1720, 4624, -714, 854, 696, 636, + -1357, 350, -1256, -523, 168, -9933, -766, 198, + 2680, 8060, 2168, -2789, -14255, 1444, -520, 169, + 1032, 1478, 294, -644, -320, 856, 1282, -216, + -1000, -925, 2, -890, 679, -629, 1152, -1329, +-13941, -16385, -1050, -1022, 106, -1151, -41, -709, + 1771, -882, -729, -1420, 1544, -120, 386, -838, + -2744, 1559, 904, 273, -4221, -1065, -312, -1046, + 234, 830, 387, 172, -956, -332, 360, 408, + 125, 90, 348, 915, -264, 911, 263, 124, + -620, -612, 220, 164, 202, 124, -30252, -159, + 1006, -320, 283, -1641, -1312, -9057, 5525, 7520, + -2884, -12194, 2771, -1164, 1842, 1261, -582, 766, + 2498, 393, 953, -617, -756, -323, -1862, 1195, + -1326, -436, -965, 366, -6727, -1226, 9014, 400, + -1258, -812, -279, -404, 1621, 86, 1622, -16, + 96, -515, -257, -39, -134, 1843, -294, -491, + -908, -120, -720, -1162, -1555, 405, -134, 528, + 23596, -77, 183, -444, 2077, 955, 649, 2246, + 3236, 735, -1202, 7954, 9440, 6134, -7267, 28, + -3398, 500, 4965, -1230, 306, 357, 2942, -906, + -4733, 903, -3945, 4447, 1046, -1125, 465, 1183, +-12710, -1018, -11302, 5177, -219, -6232, 1552, 2061, + -1372, -1290, -822, 295, 814, -3003, -527, -614, + -856, 802, 167, 1178, -494, -1625, 754, -1550, + 682, -1286, -480, -694, 86, -67, -1429, -1235, + -559, -311, 322, -308, -56, 296, -158, -24, + -748, -197, 26954, 1054, 209, -226, 165, 681, + -131, 341, 341, 1510, 615, 907, -264, 1355, + 388, 198, -5, 418, -783, 28539, 82, -559, + -459, -344, 279, -114, 966, -529, -423, 286, + -418, -766, 42, 186, 461, 418, -688, 2937, + 2793, 146, 1709, -665, 2022, 293, -1522, -2740, +-15926, -600, -1503, -1732, -2827, -1027, 1702, 252, + -643, 470, -815, 858, -1954, 1190, 1847, -16, + 266, 29, 486, 25985, 139, 220, 433, -330, + 168, -362, -562, 180, 906, 386, -845, 664, + 1064, -616, -1498, -335, -164, -930, -854, -869, + -101, -204, 835, 117, -16034, -4478, 2634, 1629, + -1873, -1156, -373, -526, 2537, 967, -2433, -857, + 1264, -1670, 113, 845, 7654, -1343, 5245, -1605, + 2236, -1190, -48, 3340, -1981, -1606, -1369, -227, + -727, -570, 1136, 1868, 667, 92, -144, 531, + 949, -1086, 530, 1764, 302, 190, -28036, 182, + 825, 229, -656, 585, 444, 200, -1195, -1855, + -387, -781, 1156, 692, -1164, -517, -464, -275, + -328, 218, -970, 174, -384, -561, -38, -720, + -140, 1021, -271, -57, 463, -25313, -342, -40, + 26, 159, -854, 916, -1532, -1033, 265, 105, + -719, -588, 96, -435, -296, -226, 224, 357, + 30, 576, -66, -30037, -72, 374, 32, 256, + 304, -852, -706, 248, -741, -379, 980, 629, + 1344, 3858, -2211, -153, -3914, -3775, 1570, 718, + -1042, -1338, -4409, 1338, 5118, 5186, 3619, 2142, + 9081, -2784, 4169, 3598, 6621, 4562, -170, -614, + 1196, -1174, 5024, 721, -71, 267, 4, 25598, + -369, 356, 331, 1099, 377, -356, -938, 1161, + -863, 1107, -132, 222, 148, 1410, 908, 60, + 377, 1280, 468, 690, 454, 247, -4552, 6122, + -267, 2973, -5932, -6424, -4983, -4193, -3386, 1691, + 1349, 1419, -3730, 300, 12150, -2927, 1588, -34, + -2435, -271, -961, -1744, 1881, -73, -453, -788, + -798, 9166, 2744, 858, 342, 991, -287, 822, + -37, 1156, -1493, 723, -14127, -1755, 2029, -933, + -1276, 632, -5249, 464, -272, 1149, -290, 4693, + -728, -1475, 841, 10, -283, 92, -268, -295, + 358, 160, 405, 2, -381, 679, 716, -190, + 128, 275, 255, 123, -412, -453, -273, 26, + -174, -340, 644, -376, 27584, -25, 66, 3107, + -1707, 911, 500, -1029, 1029, -1557, 9020, -398, + -2512, -582, 1131, -16696, -429, -1284, -3, 2320, + -532, -302, -174, -146, -413, 2152, 1009, 42, + 402, -1471, 157, 5742, -782, -229, 2379, 646, + 2842, -1776, -463, -2749, -3617, -1710, -12281, -566, + 263, -3174, -2337, 9590, -1150, 2465, 4577, 2064, + -648, -2175, -1877, -674, -634, -338, 343, -1492, + 878, -530, 1072, 13670, -4542, 746, 9704, -4188, + -7076, 1179, -740, -589, -876, 268, -1080, -986, + -4584, 2692, 3032, -2067, 230, -3533, 944, -4950, + -1908, 1452, -255, -698, 1460, -606, -250, -154, +-22303, -945, 1626, -588, -482, -1549, -129, 978, + -631, -722, 1094, 1771, -311, 532, -508, 696, + -1128, 1270, 854, -84, 4290, 414, 3351, 1061, + 931, -2936, -9606, -35, 2514, -1095, 567, -452, + -8520, 4037, -431, 2744, -2276, 2647, -1188, -454, + -400, -3698, -315, 11558, -667, 512, 162, -395, +-13015, -11, -1944, -890, -14358, -3850, -4296, 1310, + -580, -248, 1305, 402, -1049, 115, 2085, -1797, + -1172, -321, -919, -313, -512, -131, 1619, 576, + 499, -2024, 130, 14, -76, -6324, 495, 2445, +-16757, -2348, -2706, -1906, 2377, -2252, -619, -2579, + 643, -661, -1276, 935, 893, 992, -2204, -2451, + -395, -508, 1163, -216, -13034, -718, -1018, -1675, + -698, 710, -257, 2658, 1178, 2046, -2270, -2588, +-14442, -1142, -1026, 2247, -536, 314, 123, -1175, + -673, 1576, -2600, 5, 964, 619, -1714, -14811, + -1502, -1646, -1151, -93, -11652, -222, 343, -2203, + -351, -928, -289, 2679, 2101, 742, 747, -2245, + 146, -1828, -2728, 1058, 1048, 3046, 242, 4432, + 246, 350, -13419, 768, -805, 1819, 14332, 1316, + -370, 391, -1421, -1426, -355, -812, -64, 196, + -2917, 1097, -1550, -1246, 436, -62, -813, 1350, + 555, -2236, -1589, 980, -1483, 10122, -2434, 7236, +-15225, 1513, 2090, -1224, -83, -2821, 664, 658, + -3242, -1031, 1509, 2667, -160, -1315, 1060, 891, + 432, -1311, -2503, 1304, 1295, 1745, -722, -2496, + -4409, -3360, -2776, -2793, -4921, 12616, -1031, -443, + 1495, -2416, -4640, 4508, -2944, 2608, 1323, -394, + -415, -2111, -2065, 1030, -3636, -1338, 2916, -3007, + -3680, -3152, -115, 577, 2742, 785, -4429, -1945, + -304, -4883, -133, -3136, -1927, -576, 618, 1780, + 2568, -2102, -158, -3986, -1187, 280, 655, 162, + -1352, -5730, 15372, -1314, 1553, 274, -2873, 4221, + 4610, -4143, -13699, 2760, -1255, -238, 1487, 1583, + 1422, -2272, 4734, -6368, 795, -406, 1498, 1588, + -500, -2744, -875, 2080, 1901, 960, 344, 979, + -258, 952, 2526, -11785, 893, 669, 1361, 518, + -1368, 3854, 2539, 623, -1835, -4177, 2686, -2956, + -2804, 1121, -8890, 1377, 1125, -3990, 140, 3594, + 1757, 2271, 366, 1723, 2150, 13557, -1768, -1433, + -6632, -578, 3266, 2509, 7142, 680, 1532, 1318, + -1123, 5668, 1283, -412, -5404, 2893, -2647, -2695, + -1412, 340, -650, 863, 1895, 2867, 384, 626, + 856, 508, 1365, -295, 960, -26080, 234, -4, + 239, -412, -6, -765, 736, -30, 136, 912, + 538, -792, 413, 871, -437, 305, 30, -194, + 1105, -1113, 3550, -4854, 449, -549, -7626, 3706, + -3698, 1778, 1441, 2240, 73, 513, -3383, -2346, + -1372, 3955, 2973, 1175, -6087, 5071, -2135, 8552, + 4961, -1201, -1458, -2627, -730, 515, -756, 476, + -1104, 2115, -1276, 498, 336, -451, 809, -1030, + 556, -211, -70, -93, 89, -755, 296, 872, + -282, 380, -298, 2774, 660, 1339, -545, 429 +}, + +.cb1108l1 = { +-13570, -9232, -673, 267, -819, 1633, -33, 623, + -850, -4376, -1135, 999, -262, 1928, 695, -1751, + -2793, 772, 5064, -1158, 280, -2144, 1313, 888, + -2482, 469, 2996, -1406, 12525, -1200, -1202, 939, + -3, 847, 818, -924, 135, -1308, -12000, -544, + -592, -3914, 441, 3372, 3188, 1314, -1836, -706, + -844, -1319, 1029, -1754, 172, 2468, -903, -889, +-14602, -2054, 11694, -1980, -730, -1661, 214, 1243, + -337, -646, -95, 1432, -854, -236, 88, -2, + 514, -1643, -84, 3561, 302, 770, -1248, 480, + 664, 738, 1728, -1783, -2227, -702, -3582, -16641, + 1713, 1506, 660, -2471, 2061, -48, -3161, 1697, + 900, -1477, 558, 287, -5515, 1023, -1972, 999, + -1856, -3022, -228, 711, 1270, 2644, -648, 1064, + 3899, -1205, -754, 1080, 1262, 18, 860, 2274, + 655, 494, -221, -15647, 1334, -473, -1648, -341, + 3541, 3109, -1671, 639, -2491, 185, 477, -388, + 5198, -5680, 812, 700, 2180, -536, -19468, -2508, + 2592, 2901, 32, -1165, 1500, -422, -790, -1914, + 971, 111, 1226, -1302, 541, -3862, -832, 642, + 305, -3870, 8921, 570, 180, 1734, -1572, -891, + 17672, -756, 702, 2740, -647, 2122, 102, -1371, + 461, 454, 204, -307, -1248, -2330, 1353, -1783, + -1939, -601, 512, 2118, -2178, 254, 1190, -1252, + 923, 1166, 360, 320, 320, 1210, -142, -416, + 1260, -205, 1403, -1025, 19252, 328, 58, 21, + -1044, 1786, 2153, 697, -436, -1617, -869, -493, + -2419, -3102, 1995, 1519, -1799, -153, 2689, -665, + -1371, -915, 18486, 941, -2612, -1057, 1076, -3351, + -48, -1478, 575, 728, 130, -168, 40, 898, + 2141, 1518, -965, -1910, 896, 838, 1220, 416, + -1494, 1404, -126, 21472, 604, 1740, 102, -812, + -796, -734, 1082, -507, -468, -1732, 1171, 252, + 359, 436, -765, 791, 726, -810, 1838, -1798, + 5662, -2362, 1275, -2829, -4041, 1398, 2681, 480, + 13740, -752, 2252, 1306, -1026, 1834, 54, 9993, + 559, 1370, 711, 1918, -1757, 646, 16, -3262, + 2676, 1751, -2595, 4782, -1050, 2401, -15131, 1100, + 386, 708, -359, 455, -25, -950, 241, -482, + 268, 2327, -2766, -142, -1992, -566, -36, 990, + -6302, 3245, -1394, -1579, 760, -757, -2115, -8542, + -2945, -800, -4027, -3102, -1319, -1989, -1787, -426, + 590, 1031, 467, 31, 2674, 1686, -14352, 1174, + -1446, -813, -1267, 2919, 2052, -1574, -753, 3369, + -1090, 3830, 2042, 11376, 1140, 895, 1130, -720, + -1284, -2277, 49, -724, 397, 13201, -985, 1599, + -365, 1517, -496, 978, 2152, 1391, 1777, 3032, + -936, 280, 1719, -4551, 4874, -941, -160, 956, + -676, -229, -548, 183, -16606, -855, -3433, 1248, + -578, 2254, -532, 3081, -1406, -1859, -605, 1809, + -1001, -114, -1222, 3890, -609, 3114, -2430, -2142, + 440, 1780, 1606, -4211, 1047, -456, 8280, 9, + 5866, -1718, -932, -13049, -562, 3097, -583, -21, + -1972, 1254, -172, 527, 2282, 5064, -5391, 1074, + 357, 1845, 24, -996, 100, -50, 1098, 2905, + -417, -937, -439, 247, 18502, -2380, -2088, -402, + -580, 83, -282, -70, 969, 540, -219, -1132, + -1701, -195, -3030, -2748, -1974, -1304, -1909, 1080, + 1042, 1124, -128, 5816, 2303, 2840, -2420, 35, + 16550, 721, -2079, -1489, 1023, -654, 2025, 1479, + -185, -2449, 500, 3034, 2663, 3911, 1203, 998, + 594, -533, -163, -262, 739, 13, -426, 182, + 394, 350, -30055, -371, 150, -430, 147, -1122, + 43, -390, 298, 831, -194, 158, -114, -257, + -1346, -585, 206, -456, 478, -502, -1710, -1719, + -581, -536, 45, -861, 825, 1093, -255, -685, + 38, -20, 419, -594, 10, -1408, -526, -19191, + 196, -1496, 255, 1844, -8759, -3565, -1009, -926, + -818, -1195, 236, 2898, -182, 14344, -1384, 1064, + 1181, -1846, 543, -583, 170, -3305, -1187, -2406, + -40, -1051, -1071, -28, 1482, -1060, -1057, 3028, + -2023, 913, 1052, 980, -5158, 4642, -14067, 3920, + 1450, -4497, -1591, 842, -2222, -392, -42, -3546, + -258, -3566, 2595, 225, -2696, 4624, 2283, 1483, + -1506, 2164, 151, 380, -3207, -1086, -10594, 2005, + 2379, -2567, -925, -363, -1261, 13174, -73, 1168, + 2215, -1721, 726, 525, 1048, 322, -827, 2117, + 3890, 1346, -3512, 2243, 638, 2259, -1371, -2260, + 10590, 851, -1247, -894, 1871, -882, -1955, 3822, + -3654, -1730, 906, 2074, -548, 885, -2501, -1316, + -3275, -10694, 2031, 1077, 3013, -1105, 2951, 1907, + 1218, 194, 1860, -1662, 178, 915, 1092, 809, + -451, -610, -728, 799, -129, -101, -905, -2, + 2470, 1292, -137, 544, -18795, -1081, -300, -59, + 282, -329, -544, -1324, 2155, 9326, 462, -388, + -303, -2940, -608, -13652, 532, -1350, -1026, 1330, + 5559, -333, 4961, 707, -1832, 1070, 2483, -2016, + -315, 2197, 849, -348, 379, -2179, -15691, 903, + 3192, 3888, 396, 4610, 3261, -2589, -4903, -643, + 3604, -1380, 1524, -2155, 469, -3528, -790, 429, + -3862, 1797, -104, 2364, -1162, -1559, 1011, 1849, + -235, -1952, -2088, 1436, 2502, -3862, -1704, -14859, + -2863, 710, 624, 4373, -6302, -616, -807, -1577, + -2492, -620, -917, 948, 4957, -848, -863, 514, + -2210, 2162, -753, -15168, -2068, 12472, -2611, -723, + 2797, -8573, -2270, 978, -2597, 2215, -684, 2535, + 3114, -261, -178, 2385, -4869, 1161, -32, -1469, + 2074, -1407, 3226, -992, 4546, -3158, 1044, 463, + -5285, 4, -1396, -1395, 1770, -1767, -860, -6, + -2242, -1548, -667, 587, -982, -2246, -1312, 1550, + -542, 5302, -716, 135, -15895, 3382, -478, 1279, + 615, 3365, 1620, -12613, -230, 3101, 3230, -1307, + 2860, 628, 647, -3595, -214, -1631, 2783, 748, + 1088, -57, -6014, 2496, 359, 719, 1476, -750, + -1644, -2125, 3913, -3788, 565, -1118, -1411, 1377, + -1020, -246, 18851, -1438, -1150, -1492, -681, -798, + -776, 960, 911, -1449, 336, -1114, -2111, -877, + -532, 668, 1018, 1098, 408, 2032, -607, -656, + -5997, 3089, 2462, -18368, -1027, 78, -4066, 439, + -845, 1476, 290, 490, -452, 1638, -3381, 80, + 1699, 458, 260, 1215, -516, 1883, -62, 35, + -2540, -1703, -1042, 1751, -422, 1222, 207, -104, + 1112, 151, -473, -522, 26426, 562, 884, -2201, + -281, 238, -839, 1037, -588, 81, -109, -2, + -32, 75, 654, 489, 524, -388, -1408, -906, + -1193, -936, -273, -40, -100, -662, -522, -145, + 119, 614, -922, -25329, -180, -668, -574, 161, + -448, 173, 750, -609, -812, -125, 814, 572, + 2602, 20372, 244, 1820, 724, 515, 932, -1290, + -712, -990, -305, -13, -763, -1157, 481, -764, + 320, 624, -620, 642, -1494, -568, -601, -655, + -790, -1348, 334, -1302, 382, 782, -1122, -641, +-23549, 180, 463, -634, -666, 599, -356, -1071, + 816, -576, 1208, 912, -377, 624, 1049, 42, + -95, 370, 1932, -167, -275, 142, -159, -410, + 595, -562, -632, 748, 1192, 614, -41, -18, + -156, -61, 1280, -686, 363, 759, 756, -19362, + -614, 2151, -1185, 169, 327, 1494, 782, -1313, + -134, 841, 218, -76, -2980, 202, 80, 281, + 89, -61, -1678, 59, -125, 195, 320, -1310, + -56, 806, 47, -65, 249, 18432, -666, -506, + -204, -194, -560, -416, -3641, 330, -268, 842, + 10600, -176, 424, -1744, -3609, -1682, -844, -309, + -538, 435, 14251, -1281, 373, 2748, -702, -1358, + -766, 3480, -679, 4039, 529, -5698, -38, -813, + 1203, 4734, 318, -1044, -5109, 2187, -3474, 415, + 2436, -3021, -1628, -456, -1451, 3406, -1798, 1001, + -8648, 468, 1188, 497, 4628, -948, -4073, -11894, + -2750, -738, 1520, -4070, -810, -5755, -1370, 2978, + 4460, 917, 1221, -324, -1166, 2339, -1221, -2048, + 714, 6884, 3096, 6998, 13, -275, -3879, 790, + 104, 1383, 2056, 1957, -9216, -430, -199, 261, + 764, -109, -210, 795, 884, -334, 1546, -272, + -35, 738, -268, -13, -448, 645, 97, 76, + 1284, -343, -654, 112, 643, 22846, 634, -597, + -621, -784, -380, 951, -452, -685, 140, 688, + -770, 247, -679, -228, -26856, 311, -546, -444, + 606, 69, -195, 18, -220, -334, -42, 543, + -28, 492, 766, 208, -1206, -554, 213, -1112, + -1675, -608, 382, 2011, 5077, -17442, 1367, -702, + -856, -416, -1728, -1987, 2966, -1952, 38, 152, + 712, 210, -589, 3029, -1189, -2016, -8071, 10746, + -2143, -556, -1964, 162, -504, 995, 982, -2565, + -634, -985, -1668, 444, -2098, -411, 488, 1397, + -1134, 1888, -920, -279, 15057, -757, -1258, -3040, + -890, -105, -670, -490, -238, -2419, -1302, 915, + -784, -929, 1653, -89, 1076, 445, 2538, -1424, + 19175, -91, 437, 752, 254, 935, 854, -1666, + -86, -543, 1053, 664, -155, -485, -3994, -50, + 50, -58, -2626, 1801, -314, -16052, -1831, 1009, + 2344, -3030, -938, 1761, -1283, -150, -425, -6660, + -900, 1374, 803, 549, -2683, 837, 483, -655, + 4610, 1259, -45, 834, 1103, -3250, -3604, -2882, + -2463, -5331, 11312, -1653, -3505, -1855, -4962, 8579, + 2370, -2474, 501, -1282, 985, -924, 3452, 456, + -242, 3878, -2095, 2994, 7076, -459, 2574, 16116, + 8277, -88, 572, -38, 0, 1664, -553, 1820, + -2096, 1076, 415, -420, 1900, -1696, -130, 298, + -1555, 201, -404, -1831, -932, 844, 9606, -497, +-16304, 3278, 918, -523, -1573, 2488, -813, 147, + 1540, 3795, 1390, 1061, -78, -10, 574, 2620, + -1143, -512, -582, -1496, 736, -4323, 786, -2873, + -1342, 3932, 14508, 12635, -899, 1730, -673, 386, + -676, 2787, -2780, -2960, 375, 475, -2188, 2250, + 851, 788, 268, 1264, 2973, -94, 1062, 1006, + -697, 669, -635, -986, -4848, -1486, -6, -3914, + 6267, -1560, 8, -503, 5273, -3545, 69, 15146, + 2263, -1490, -548, 1740, 1636, -892, -895, 769, + -471, 226, 6497, -2466, -2037, -1068, 1075, -902, + 13668, -1213, 12424, -3523, -124, -1090, 972, -1134, + -494, -2568, 881, -3081, 369, -254, -618, -914, + 443, -1254, 658, 1322, 546, -14, 778, -116, + -378, -802, -268, 48, 1140, 25942, 503, -637, + -871, 1050, 298, -187, 387, -406, 343, 212, + 110, 723, 695, -47, -50, -568, -66, 347, + -1588, 20, 701, -485, -98, -787, 4502, 1046, + -1628, -2526, 185, 1016, -256, -700, -403, -154, + 103, -752, -689, 2084, -1463, 2294, 360, 17590, + -698, -1262, 788, 116, 755, 751, -440, -610, + -469, 1235, -2314, 1240, -308, 553, 1065, 24442, + -733, 667, 4, -484, 93, -263, -361, -278, + -1524, 176, 1311, 1561, 435, -436, -1079, 260, + -366, 472, -1049, 647, 158, 302, -931, -36, + -990, 736, -444, 1077, -1560, -251, 148, 1000, + 1096, -300, -224, -307, -17646, 39, 206, 74, + 505, -3051, -1285, -793, -724, 718, 324, 803, + 874, 6062, -2235, -3321, -550, 9264, 3483, -4172, + -4024, -471, 858, 2682, -1078, -1922, 2088, 1135, + -878, 545, 2205, 836, -1088, 547, 12461, 2222, + -828, -3841, 4797, -2360, -2510, -4029, -2213, 13736, + 1032, -958, 1895, 264, -1499, -2066, -241, 1324, + -224, -792, 776, 2130, 2600, -2276, -4239, 3260, + 1610, -1620, -1220, -2752, 979, -2028, 19626, -2146, + 684, -729, -235, -289, 588, -600, 245, -879, + -816, 413, -87, -1158, -246, 69, 970, -111, + 500, 1097, 1087, -138, -1356, 30, -434, -452, +-22802, 177, 492, 206, -257, -854, 1445, 37, + 1384, 97, -258, 811, -222, 53, 548, 1744, + 124, -1031, 1076, 186, 453, -173, 1180, -2235, + 583, -392, -1542, -726, 2937, -3635, -856, 1446, + 7796, -2779, -962, -2277, 1651, 1960, -1460, -1277, + -9794, -288, 2459, 2350, -2521, 84, 578, 2286, + 480, 1620, 6421, -200, 170, 1513, 198, -1001, + -491, -1000, 161, -482, 607, 214, 743, -292, + -394, -192, 92, 73, -415, -316, 593, -42, + -346, 456, 44, 950, 129, -189, 806, -221 +}, + +.cb1108s0 = { +-32768, -828, 9569, 331, 6938, 3122, -1008, 2847, + 646, -5690, 1712, -795, -4406, 1368, 307, -526, + -2206, 26, -210, 1358, 746, 1920, 667, 3866, + -413, -720, -4328, -2475, -1189, -863, -3809, -5052, + -8567, 2859, 1915, 4895, 12440, -13002, 2757, -5969, + 4054, 1100, -9430, 4930, 10266, -1522, 7092, -8778, + -1968, 4325, 8440, 3888, -1966, -688, -2455, 2966, + -2380, 1682, 4956, -2310, -3706, 404, 6774, 17562, +-12437, -2667, 4864, -9411, -6436, -9316, -903, -5526, + 3463, -1690, -5250, -12568, 2338, -1310, -3019, 776, + -641, 3483, 54, -10732, -3878, -691, -17615, 4530, + 10267, 7830, 8488, -12624, -4514, -17183, 7070, 3115, + 4176, 383, -4558, 410, 6379, 6242, 4702, 4853, + -217, 446, -3811, -2396, 244, -2120, 3275, 5122, + 180, 4523, 8680, -1868, -6164, 2636, -5056, -4039, +-11618, 4014, 11349, -2616, 8240, -5119, 1988, -2552, + 6060, 3206, -662, 2686, 1116, -10447, -3004, 650, + 7811, -12148, -327, 856, -916, -397, -600, 4621, + 3011, 5539, 5417, -2374, 9667, -4714, 7821, -2819, + 573, 4492, 1882, -26770, 1486, -6963, 1103, 2515, + 8196, 1849, -7492, -5243, 2106, -5290, -11000, -1410, + -3448, -8548, -4536, -7730, 3083, 6109, -14458, -8624, + -381, 7840, 4694, -3906, 8223, 3315, 5849, 13112, +-13132, 6081, 11801, -7624, -376, -6372, -6817, 6834, + 1760, -1435, 1072, 3505, -1494, -709, 5786, 454, + 1807, 2650, 7728, 1357, -1002, -5366, -2368, 2052, + 333, 6312, -336, 8274, -1653, -4309, -6630, 2841, + 2448, 8398, 5376, -7248, -1474, -1842, -4119, 838, + 501, -4206, 4052, -1250, -20943, -3338, -592, -2973, + 7057, -128, -3235, -4313, -2510, -11313, -4925, 3103, + 1448, -5186, -1322, -16815, 1956, -7950, 2641, -2890, + 4396, 2322, -1381, -1911, 448, 2543, 3535, 782, + 3719, -624, 1610, -2843, 7583, 1794, 700, 3107, + 4528, 5461, 2540, -1074, 5976, 741, 576, 4426, + 4400, -4920, 5724, -3734, -1186, 10645, 1100, 10537, + 2828, 11670, -8391, -32572, -9405, -6807, -875, 2277, + 736, -4546, -18693, 1204, -1083, 3422, -3328, 6013, + -2992, 5812, 2744, -11668, -2519, -2384, -3635, 6532, + 6874, -2820, -5222, -12261, -14266, -6663, -1150, -2032, + 2099, 4642, 1638, -4162, -644, 249, -3133, 11830, +-10712, 12370, 4818, -1924, -5639, -6448, 2455, -4898, + -613, 1760, 2393, 1414, 7039, -7018, 5901, -2900, + 3786, -3230, -3718, 3514, -4040, -4676, 6367, -1449, + -2758, -2888, 4066, -7140, 408, -7656, 3156, 19919, + -1858, 6671, 352, -3355, 3074, 5524, -1429, 1954, + -6664, -10082, 4405, -1598, -806, 1779, -6913, 7062, + 5064, 6518, -1042, 3400, -5530, -1192, 590, -3298, + -772, 571, -6239, 9810, -12380, 1302, 1344, -3430, + 3830, 4106, 5792, -6196, 224, -2604, 3954, -12551, + -5539, -8306, 1801, -4521, 3578, -4349, -5716, 4960, + 3620, 1516, 5779, 5550, -3710, 3329, 10542, 4198, + 5148, -3291, 196, 6232, 6943, -1303, -10306, 1862, + 6547, -1544, -2996, 2868, -4389, -6894, 28557, -13130, + 1397, -2331, -4076, 2870, 3592, 6613, 265, -4790, + -3514, -3152, 8710, 230, 3142, -1264, 1822, -769, + 6168, -1792, 2189, 2660, -2664, 3402, -533, -3100, + -476, -1164, 6092, -2930, 3372, -5895, 8507, -918, + -4716, -1582, 23959, 1506, 2360, -117, 2029, -452, + -6575, 964, -13132, -2838, 3800, -3355, 3168, 5230, + 11116, 826, -1711, -3546, 7398, -4092, -2884, 743, + -1784, -3824, -3437, 1050, -3306, 928, -5109, -7999, + 1581, 8609, -4662, -3594, -1618, 9929, -3982, -5591, + -8789, -1444, -12011, 1304, 12668, -5138, 10837, -7951, + -4089, 3921, -5375, -2486, -2590, 11398, -80, 7734, + -4547, -11286, -7098, -7758, 5303, 7380, -11266, -11138, + -8676, 30, 6328, 597, 7852, 3144, -3933, 15142, + 3954, 12197, -507, -1667, 5517, -4187, 709, -1330, + 2094, 4739, 1341, 8276, 8544, -10107, -10151, 3641, + 771, 4798, 4839, -3254, -9246, -7304, 14850, -18155, + 3068, 4993, -4930, 10985, 6270, 8528, 5904, -13010, + -7824, 1300, -706, -156, -4228, 302, 9962, -3087, + 4472, 4541, 13179, -6576, -2541, 8284, -51, 5366, + -4369, 289, 3890, -3671, 1894, 21820, -3031, 5336, + -8412, 2487, -1211, -6759, 1292, 3749, -8904, 638, + 6863, 154, 1145, -684, 6648, -3874, 2005, 4670, + 4408, 4191, 3984, 632, 2957, -1532, -3974, -2576, + -1636, -3714, -136, -4946, 3900, 367, 27072, 1864, + 1426, -3321, 860, -1768, -2009, -3436, 2666, -9899, + -1328, -2330, -3078, -3258, -4600, 5604, -5248, 1703, + 4403, -4781, -8275, 6717, -3860, 10980, -10634, -8360, + -2291, 20311, 7602, -4028, 483, -4886, 2677, -4921, + 6065, 5393, -2145, 6201, -472, 1796, 2869, -3578, + 3053, -2342, -3193, -2589, -3215, 1322, 536, -164, + -314, 4800, -1903, -1338, -11833, -23399, 5562, 4440, + -1864, 2520, -4251, -1464, 5053, -8553, -3852, -5932, + -849, -7113, -3493, -5338, -1671, 1496, 4504, -1830, + 5716, -210, 1397, -2060, 2242, -583, 2604, 5355, + 13938, 13150, 1346, 2649, -1527, -4568, 8891, 7399, + -6492, -10371, -4885, 13056, -8262, -1267, -2959, -868, + 5941, 299, -601, 8834, 1436, 5404, 1914, -3775, + 980, 8848, -2270, -1952, 6902, 8642, -25725, 9556, + 14540, 1998, -13157, 308, -13844, -10126, -2147, 8296, + 1772, 1094, -9712, -8560, -7552, 5527, -1446, -1097, + -5798, -17270, 2860, -210, 2136, 175, 729, 11775, + -5154, -4202, 13342, 3977, 14494, -5659, 9105, -11067, + -3694, 4794, -593, 6817, 1875, -4975, 3663, 4141, + -8317, -8932, 2127, -4176, 1136, -148, 7640, 8127, + -744, 2354, 389, 1600, -6475, -4558, 10735, 11407, + 3896, 13098, 1814, 5191, -3850, 2629, 18430, 8343, + 4630, -4624, -702, -3834, -2276, -2894, -1556, 1437, + 424, 5652, -6260, 2387, -5845, 7496, 10657, -2754, + 4806, 1169, 1308, -4114, -5347, 15076, 5686, 7287, + 3004, -6254, 5186, -14096, 10323, -1974, -9355, -5544, + -986, -5998, 261, 4494, 2467, -1911, -603, -4548, + -1344, 1995, -1603, 10464, 5222, 3714, -5342, -8039, + 12530, -26465, -1813, 4044, 746, 8123, -12078, -4703, + 2971, -4487, 2556, 3904, -2518, 1504, 5774, 5431, + 1120, -934, -5202, -6826, -8774, 7156, -2392, 10643, + -2918, -4298, 3361, -3758, -894, 5828, -203, -4905, + 6480, 11771, -19830, -17545, -4920, -17263, 10066, 10125, + -8980, -19719, 23554, 27907, 2607, -7014, 6128, -23759, + -4802, -7099, 874, 13103, 21667, -8475, -12938, -13122, + -3694, -18860, -3518, -3586, 12658, -793, 10661, 6925, + -730, -11373, -7845, 94, -2627, -6044, -2213, -4381, +-10198, -5816, -56, -4349, 3722, 3911, -1719, -2513, +-13290, 3218, 105, 1876, -76, -1107, 2563, 4520, + 10288, 5862, -7738, 6180, 9863, 1380, 6756, 2632, +-18798, 9314, 7190, -7454, 432, -15141, 8462, 2128, + -2386, -2710, 292, -751, -3125, 6147, 4941, 3146, + 3046, 120, 321, -5884, 5105, -4300, 6264, -317, + 1667, -694, 7950, 5639, -3284, 1089, -6456, -14694, + -3527, -1104, 4313, -20858, 7920, -10782, -13536, 933, + 4523, 2640, 2118, 97, -614, 9834, -9515, 232, + 5086, -6720, -1529, 568, 3139, -3665, -8567, -13771, + 6274, -4370, -5653, -8920, -7667, -9391, -6653, 12489, + -3666, -5103, -12324, 4796, -540, 10396, 3668, -3467, + 7124, -4398, 87, -12139, -204, 1213, -2190, 11948, + -2641, -2434, -5647, 2819, 3148, 3558, -6455, 3705, + 1644, -3090, -4225, -5998, 112, 17789, -7220, 2166, + 4153, 4516, -1100, -1667, -1402, -8837, 6344, -1586, + -3451, 2357, 616, -392, -8163, -11579, 6160, -2783, + 7895, 11321, -11847, 8070, 5231, -6496, -3172, -3470, + -2960, -11437, 465, -470, -2568, 11197, -9417, -4117, + -1162, -1893, -2361, 551, 14478, 3510, -1372, 3117, + -8236, -2904, 14556, 3191, 200, 2166, -13974, 2718, + 3946, 2444, 1982, 5320, 2087, -2222, 1573, 742, + -8828, -3917, -11080, -241, -8472, 6119, 290, -2364, + -3163, 1923, -1964, -582, 2564, -5566, -6411, 2069, + 7392, 9115, 25316, 1504, 2540, -814, -1746, 566, + -1580, -2290, 170, 698, 105, 9567, -6714, -584, + -4934, -379, -491, -978, 4580, 1180, -3355, 1882, + -4343, 4817, 1503, 9968, -8878, -4908, 3419, -4818, + -2254, 6694, -4368, -10849, -5093, 4510, -3129, 152, + 1926, -4490, 1510, -17764, -6699, 962, 3474, 4981, + 25, -7128, 1432, 5386, 3108, -4545, 1092, 1663, + -1363, 3076, -8916, 6158, 244, -1181, -825, -933, + -5570, 17221, -535, -2892, -5031, -1297, -3010, 5840, + 678, 748, 3944, 1630, -3648, -5457, -2618, 876, + 6655, -2834, 2597, -6667, 1330, -40, -4423, 6257, + 743, 6083, -584, -3742, -1401, 1779, -5166, 4559, + 5558, 8588, -6476, 7521, -1561, 4950, -778, 3564, + 11403, -1010, -3151, -14151, -1020, 2595, -3278, 24555, + -4859, -909, 2314, 1301, 2098, -5664, 3938, -4050, + -203, 3368, -2580, 3061, -9266, -6263, -6748, 3890, + 1950, -329, 1050, -1106, 588, 23705, -661, 6913, + 722, -5820, 2147, 3789, -1689, 661, 5389, -8519, + 1152, 3800, 7160, 5234, 1343, 3218, -2900, -391, + -4258, 5084, -4783, 7262, -10013, -811, -5252, 6474, +-17338, -2388, -2596, -8715, 5836, 9523, 639, 4652, + 3071, 3114, -1648, 1563, -931, -10143, 4394, -2838, +-11900, -1012, 841, -5812, -3048, -2715, -196, -5794, +-20022, 1949, 3464, -770, 2200, -3564, 1975, -6242, + -1937, 3954, 5678, -2744, 1888, -3825, 5770, 3869, + 8315, -7386, 1318, 1302, -5534, -4554, 924, -3804, + -4292, -22757, -7972, -7469, -3543, 7858, -10125, -2637, + -4765, -10644, -5944, 1159, -3293, 4363, -1219, -12248, + 5060, -7232, 6947, -1609, -3037, -5084, 6580, 15873, + 5336, 7295, 2386, 2961, 4655, 9714, 5080, 11635, + 1790, 2897, 687, -914, -692, -6653, -8562, -1412, + 244, 4478, 1650, 7175, 1046, -6689, 3693, -3520, + 6046, -1336, 1976, 16822, -1176, 792, -1733, 8286, + -7359, -2402, -8536, 1392, -3271, 6580, -4939, 1562, + 595, -4237, 4872, 4266, -1798, -6589, 7457, 4207, + 9978, -3996, -2236, -3078, 1861, 10101, -2394, -3250, + -7619, -7082, -14305, 5664, -1337, -11019, -3839, 10190, + 7249, 3086, -1782, 24, -3566, 10769, -4102, -6408, + -688, -8987, 3018, -5942, 7478, -368, -7931, -3018, + 6766, -78, 5705, -3264, -1100, 4850, 4518, -28, + -6276, 4905, 7094, -4394, -2846, -88, 434, 2039, + 352, 9827, 12372, 1207, -8561, -4476, 1496, -4927, + 2087, -6730, 1134, -81, 57, -8701, -2918, 3953, + -2844, -1842, 4804, -5315, -401, 7060, -16397, -4802, + -9849, 17542, -11715, -12432, -6676, 9323, -13189, -5761, + 8054, -620, -7431, 3726, 17790, 7880, 251, 2983, + 3736, 7118, 17197, 8613, 1445, -15290, -16184, 11084, + -4971, -5922, -1893, 9067, 9321, -8139, 714, 182, + -3138, 7258, -1874, -2781, 10800, 2915, 5316, -5206, + -2581, 10219, -484, 862, 119, 6628, 1514, 3883, + -880, 7586, -2573, 3279, 3801, 4492, -3850, 9416, + -38, 7518, -574, 4052, -1136, -668, 9672, -9536, + 2551, -4223, -1074, -3616, 8446, 158, 3262, 7965, + 1311, -8634, -6786, 700, 4973, 917, -754, -1156, + 6054, 2067, 10757, 421, 1030, 11351, 2149, -4286, + 12075, 4593, 1193, -5290, -8566, -2965, 6824, -6238, + 2392, -3395, 5350, -2789, 7529, -1873, 3032, -1494, + -2703, -18535, 1583, 9539, 2556, -4422, -6079, -2699, + -7860, -4573, -8236, 4281, -1079, -17578, -2840, 7468, + 4675, -5002, -1268, -1529, -8222, 8285, -766, -4314, + 6048, 11507, 5046, -2444, 3186, 1732, 7872, 6598, + 2828, -2920, 8278, 13263, -10204, 1334, -5552, 10532, + 5412, 2554, -10076, 1128, -3959, -3210, 4091, 1824, + 4984, 5558, -2204, 2080, -3802, 6614, -7380, 3612, + -4624, 6366, -1795, 4038, 6227, -4312, -4910, -2127, + 15077, 4144, -16885, 3757, 2303, -670, 5625, -2590, + -2594, 2491, -3174, 4199, 1152, -1532, -7308, -8578, + 6431, 2975, 6032, 3037, -7451, -2643, 5503, -7856, + -2451, 5309, -3678, 8145, 1864, -8341, -15575, 7716, +-10337, 8935, 12350, -10418, -4092, 734, 10400, 10934, + 5724, 1778, 5836, -3203, -10700, 2766, 4178, -18135, +-16589, -5465, -5005, 7239, 25480, 7310, -6408, 6142, + -7748, -1423, -4318, -321, -2899, 3728, -3184, -3578, +-11598, -1223, -8554, 656, -3945, -4084, -724, 301, + 9539, 9695, -1799, -2602, -1379, -5282, -4709, 11858, + 9562, -7508, 4886, 896, 5780, -160, -12724, -9598, + 1220, -5411, -5072, -6476, -11763, -104, 9311, 5230, + 591, 4342, 263, 13198, -17801, -1892, 2619, 18194, + -2080, 16536, 18497, -25926, 25541, 66, -6648, 1627, + 2794, -3790, 9424, 1387, 20702, 5260, 5211, 1702, + 1019, -11143, -6501, -18711, 10869, -4204, 4994, 1722, + 8569, 3670, 4386, -16874, 8876, -2297, -2743, -4562, + -9207, 8033, -346, -3586, -9451, 3242, 1552, 4278, + -6787, 7118, 3630, 4602, -7371, -12789, -10424, -14922, + -3010, 1885, 4144, -4490, 4074, 7796, -1201, -7244, + 2675, 1221, -7060, -12828, -3520, 1983, -4615, 8207, + 1606, 517, 3646, -7252, 816, -3690, -674, 13100, +-16254, 4727, -8184, -968, -5366, -2288, -20260, 1174, +-19384, -4199, -5292, 582, -13118, 1836, 1698, -2034, +-14601, 6642, -10530, 482, -851, 9968, 7050, -13366, + -8354, 4740, -20050, -193, -1881, -1205, -4042, 7067, + 12872, 5846, -4792, -1833, 2504, -3222, -1607, 2634, + 4587, 6761, 1549, 1124, 9427, 3978, -8305, 7524, + 2507, -5744, 3238, 5238, -3664, 694, -28496, -1674 +}, + +.cb1108s1 = { +-10979, 8698, -630, 4660, 3060, -7292, 10140, 11942, + 1448, -5820, -3144, 3100, 10575, 6888, 3505, 9996, + 2787, -484, 8057, 1503, 6329, 3074, 3954, 9419, + -736, 2333, -1858, 3264, -4026, 16130, -14501, -5284, + -472, 850, -7258, 1542, 1473, -2348, -7055, -9574, + -2275, -4383, 7542, -360, -2945, -3878, 28, 809, + 600, 2246, 587, -1779, -3456, -737, 3242, -2523, + -1862, 6127, 899, 1070, -15614, 10990, -3084, 9546, + 7339, 8899, -1490, -10379, -9193, -3857, 8289, 7261, + 12489, 7814, -6458, 1223, 15486, -10960, -1880, 4922, + -7819, -527, -2370, 3687, 1358, 10367, -14266, -1496, + 1060, -9325, -5582, -3947, -17536, 1470, 4878, 10793, + 2904, -2566, -4995, 6549, 6141, 11048, 3177, -494, + 9087, 797, -2575, -5616, 1197, 2966, -11287, 4658, + -504, 4571, 1814, 18830, 26254, 2399, 8750, 2656, + 8206, -12987, -9119, -1027, -457, 1228, 6137, 2322, + 1732, -5694, -892, -249, -178, -7009, -4368, 402, + -5564, -5183, 2470, -4745, 2788, -3255, -5181, -706, + 40, -4915, 8926, -3633, -2455, 15054, 5376, -867, + -7270, -979, 7053, -7433, 13749, 5039, -2234, 8474, + 7031, -3917, 5127, -7602, 580, 12067, 2252, 149, + 86, -582, -5729, 2193, 4178, -9195, -11824, 3897, + 1298, -1044, 6450, 1885, -19562, 6205, -4610, -2544, + 5192, -4885, 5021, -2373, -102, 7358, -2434, -3512, + -4048, 3070, 45, -1344, 202, -2189, 448, 1172, + 2939, -547, 1003, -6370, 3643, -1157, 3932, -6044, +-12882, 1959, -1574, 2574, 14854, -16317, -6627, 505, + 1102, -9361, -8087, 7525, -1466, 284, 3756, -383, + 5147, 5060, -474, 531, -6144, -1872, -1206, 527, + -4861, -12410, 7508, -7226, 5046, -12233, -4153, 4628, +-14402, -5265, 534, 1528, -13408, -62, -18757, -1280, + -9301, -10254, -8990, -6335, -7724, -3394, 1951, -13271, + -1389, -5274, -4616, -9643, -10295, 1332, -5618, -10737, + -7536, -9314, -7006, -760, 7694, 2955, -404, -2800, + 15250, -3828, 5994, 5408, 8411, 16568, -7280, -6901, + -222, -1554, -862, -1871, 939, -3678, -4348, -3200, + 3220, 1614, 8598, 8162, 1749, -7378, -1658, 931, + 3870, 9183, 1509, -5068, -17, 5733, -8121, 2769, + -3195, -3296, 8940, 2828, -2470, -2448, 7413, -2851, + -1058, -4505, -9653, -5074, 73, -3286, -4014, -1760, + 2562, 13690, -3464, 5438, -3394, 16997, -2944, 291, + 4224, 1175, -2237, -6894, -5479, -1291, 3390, 5455, + 898, 3461, -7914, -4785, 1879, 1059, -3721, -5796, + 5054, -3931, 6315, -2460, 1909, 573, -3373, 3052, + -178, 986, 572, -5976, 5781, -4928, -10539, 580, +-18727, 757, 1759, -4049, 2232, 1890, 4115, 699, + -2934, 4926, 2391, 10848, 5103, 4340, -1518, 2288, + 2283, 8886, -5131, -4429, -4384, -3265, 11933, 3993, + 11474, 3721, 1532, 976, 6112, 1954, -2360, -1783, + 2080, -6356, 2482, -4646, -1992, 1590, 1790, 3290, + -2312, -564, 508, -1688, -7522, -9263, 3059, 1883, + -3005, -1303, -9146, 10282, 1333, 4692, -2083, -15792, + 2208, 1128, -11574, -7149, -1126, -4995, 18963, -6262, + 5045, 2179, -822, -1249, 10092, -338, 5744, 1635, + 2535, 6114, -1339, -8337, -4370, 4288, 2468, 3051, + 12491, -9554, -4034, 522, -1085, 5852, -2759, 4918, +-10717, -194, -11376, 3059, 12075, 1037, 5260, 816, + 5918, -1987, 7924, -6022, -10374, 11607, 25035, -11598, + 16894, 2458, -5461, -2039, 385, 6002, 7574, 1229, + -834, -1032, -7453, 2694, -1447, 3632, 4215, 3541, + 2936, -3294, 1001, -6451, -4595, -11682, 7880, 2261, + 3786, -2849, 2276, -826, 3742, 7586, -334, 2837, + -2331, -12849, 1170, -1150, -5253, -997, -8996, 8124, + 2234, 904, -2294, 3144, 7352, -5452, 1536, -8800, + 1886, -18282, -9787, -8066, -12066, 1536, 4460, -1345, + 1418, 7471, 13451, -7299, 5507, 6795, -184, 8905, + -2040, -4933, 4998, 7317, -6667, -5134, 9094, -8561, + -2534, 3422, 2278, 3118, 205, 5811, 2247, 5946, + 1078, -2105, -6946, 170, -1625, -4734, -1447, -4329, + -4553, -2230, -8738, -15289, 7311, 6665, 5047, 1984, + 11896, 13922, -10490, -9313, 1424, -2991, 1408, 335, + 8914, 3773, 8814, 7917, -4560, -114, -624, 8984, + -1598, -580, 3233, 590, -2172, -3162, -3985, 5394, + 13842, -11625, 73, 12826, -1204, 5119, 10304, -10006, + -2695, 1318, 156, 84, -760, -4638, -3804, 3041, + -782, -2994, -3113, 637, -3256, -5831, 452, -1204, + 1614, -11626, -4769, 10612, -8710, -20019, 10542, -4279, + 6912, -1429, 3812, 2844, 3903, -11622, -8954, 180, + 3898, 3858, 119, 1385, 4038, -5899, -969, -5454, + 13305, -6748, 5934, 8027, -7348, -3797, -29781, -4956, + 2037, -2331, -3292, 8254, 6597, 4446, -7848, 6250, + 1400, -1182, -4966, -3490, -1410, -2286, 3334, 350, + 9271, 2987, -934, -5702, -3881, -97, -671, 5108, + -133, 1302, 11630, -8858, -3027, -42, 3682, -1507, + 3992, 5641, 2778, -8698, -2509, -1360, 77, 2116, + 98, 2853, -6334, 5915, -1214, -2721, 8921, 1380, + -4158, -4315, -4740, -21049, 7044, 866, 2094, -9442, + 9003, -5147, -4897, 3407, -11558, 4280, 4508, 6697, + 1612, 1508, 8547, -14257, -151, -9530, -7250, 11321, +-14430, -4944, -2488, 1349, -248, -1490, 1749, 3970, + -5830, 20767, 4642, 3236, 36, -17079, -11099, 5996, +-10759, -39, 7822, -7527, -1431, 179, -3841, 2298, + 1407, -241, -2303, 9244, -3626, 6609, 1959, -518, + 368, 1678, -5334, -5849, -4986, -2363, 607, 2809, + -1006, -7695, 10022, 2216, -8992, 4282, 807, 14707, + 9528, -11065, 3014, 3157, 5597, 1139, -1298, -3642, + 7839, 860, -4336, 2624, -4171, 1791, -2825, 5362, + -529, 1494, 337, -4487, -671, 5360, 3283, 4933, +-14692, 4033, -4365, 2713, -6903, -1784, -10862, 6173, + 5278, 14859, -852, 10020, 12304, 8898, -3089, 9183, + 1841, 8276, 4929, -261, -1264, 615, 3615, 14535, + 6557, 519, 4228, 7382, -1805, -4529, 4992, 4277, + -342, -9610, -5193, -7022, -23264, 2402, -740, 2875, + -5052, 1983, 4987, 3336, -3806, 1335, -2868, 846, + 7652, 936, 3510, -4570, -3010, -8805, 6177, -4413, + 5879, -15204, -1632, 13416, -4543, 3838, -9293, 1744, + 920, 15544, 3820, -5852, 3935, 2357, -6486, 1932, + 12044, -6374, -2545, -2389, 2755, -8073, -8203, 4659, + 4286, 16128, -987, 434, -4495, -4428, -4816, -10329, + -4529, -13408, -13283, -1136, 4002, -1271, 3547, -5274, + -5577, 701, -365, -2764, 370, -369, 2611, -832, + 3862, 4604, -7786, 11170, -1453, -1568, 10758, 168, + 402, -1985, 1436, -8858, 10080, -8559, 3998, -4310, +-13478, -3104, -11458, 506, -18194, -3724, -6768, 7960, + -4213, 1121, -1658, -1141, -1874, -383, -5090, 748, + -1032, -1207, 1046, -1865, -2387, 2126, -3672, 6733, + -2794, 3797, 15562, -11989, 170, 6129, 658, 929, + 4800, -4296, -955, -2189, -188, 3180, -118, -766, + -2182, -6928, -2254, 6615, -4422, 6324, -31, 3742, + -5832, -5022, 4671, 1574, -6309, 288, -2768, -2492, + -4818, -5192, -248, -3236, -429, 120, 1182, -10486, + -2964, -3713, -5978, 11817, -20052, -6525, 2054, -879, + -602, -2843, 7244, -1372, 417, -172, 3322, -6556, + -7021, 5842, 7357, -2799, 3660, 7579, 4682, -2242, + 73, -9247, 21061, -2060, -3614, 2486, 4793, -2959, + -510, -74, -5982, 2274, -4147, 3260, 1994, -1678, + -7494, -13624, 2560, -7375, -896, -4945, -2838, -11096, + -1969, 5879, 444, -3220, 14630, 4915, -2376, -8475, + 9854, 11380, 11060, 1534, -14413, 4366, -9544, -10646, + -7654, -17916, 3481, -3240, 1776, -2436, -8403, 3679, + -1914, 12537, -5540, -5294, 5995, 5968, -2609, -16882, + 789, -9506, -10075, -12142, -7580, -7090, -2046, 11065, + 7617, -3503, -2013, 3516, 6347, -195, -3119, 2444, + 14, -4998, 767, 4976, -3974, 9038, 579, 1804, + -8206, 32767, -5633, 1018, 13388, 996, -12737, -3179, + -2058, 13663, 1274, -4475, 7386, -1698, 17927, -6118, + 15942, -2922, -3434, 5903, 6333, -9149, 14140, -1488, + 2999, 1151, 2361, -1935, -10243, -11566, -5319, 965, + 5146, 3652, -441, -2173, -3484, 3685, -13595, -1703, + -78, -1408, 18517, -3788, -3266, 3162, 996, 19950, + -8560, 4989, 6593, -5329, 2950, -13896, -3524, 5590, + 4055, 6084, 2493, 12659, -5786, 4858, 7252, -7111, + -7318, 5411, 7393, -8714, -3454, -1562, 1919, -49, + -680, 7285, -398, -2956, 7100, 5563, -538, 1719, + -16, -3824, 437, -6842, 1504, 5694, 1214, 3209, +-15562, -4365, 9329, -25577, 1425, -2598, -8389, -6891, + -3275, 3304, -3993, -6391, -934, 7862, 4844, -134, + 9890, -4646, 2468, -9901, -4111, -3080, -5056, 476, +-13099, 1447, 205, -2424, 7098, -12075, -4646, -13725, + 8367, -2910, -8461, 1387, 3553, -10228, -2771, 4698, + -6483, 12234, -8086, 3329, 2374, 452, -1805, 5083, + 2014, 164, 7143, 81, 6062, 2838, 5318, -4982, + 1440, 2014, -3273, -6658, -798, -3204, 1398, -599, + -5834, 2070, 4644, -17238, 390, -1684, -4932, 8961, +-12217, -3079, 6574, 1387, -5991, -7803, 1285, 7439, + -395, -3048, 2038, -847, -690, -5127, 2228, -4180, + -3499, 530, -584, 9884, -323, 446, -15644, -9162, + -1683, 3643, -3578, 2634, 496, 8097, 109, 1056, + 1422, 5452, 6517, -449, -2389, 302, 6827, 1507, + -3106, -7188, -4909, -441, 12955, -3933, -5322, 5155, +-23171, -2780, -2655, -4048, 12844, -3709, 6555, -5700, + 3780, -6566, -4415, 11091, 11291, 6443, 9146, -796, + -1420, 5600, 12098, -5790, 6619, -10474, -12177, -5890, + 21700, 11148, 3427, 3130, -5727, 14646, 13953, -2721, + 1404, -3102, -4693, 4762, 1757, 2533, 3998, -530, + -758, 5301, -1426, 8948, -720, 6877, -3863, 2396, + 5266, -685, 890, -7188, 2742, -270, 8125, -804, + 32292, 6964, 8599, -3466, -1080, -8423, 2070, -295, + -157, -5432, 152, 2478, -3738, 1104, 1500, -5290, + -2463, -6386, -2537, -2331, -3290, -2398, 159, 6588, + -2547, -2424, -2184, 8316, 5670, -5608, -2600, 2659, + 166, 14828, 2622, -10490, -16378, 64, 434, 4576, + -3010, 2479, -6798, 3431, 360, -1067, 3421, 664, + 4029, -4050, -240, 3875, 672, 3587, 501, 2494, + -48, 9997, 3259, 8551, -7624, 17342, 10765, 4328, + -3721, 1729, -2844, -6330, 5114, 15589, -261, -7554, + 2708, 7260, 5852, -8736, 436, -6160, -588, -5919, + 5752, 3127, -4558, 540, 74, -4048, 3735, 7873, + -2869, -544, -111, 5182, 1032, 2315, -159, 5105, + 4106, -494, 678, -4756, -3865, -7389, -2492, 7193, + 5146, -7926, 12043, 11137, 1719, 2307, -5476, 12679, + 7996, 726, 933, 3222, 7515, 678, -5858, -2716, + 1503, -3014, -2125, 4982, -4984, 467, 986, 5450, + -1472, 5314, -1285, 218, -3411, 4511, 8047, 4268, + -8307, -10587, 17200, 3303, 7553, 5361, 1108, -7982, + 8240, -5856, -3376, -3952, -2884, 4401, -7252, 4078, + 7538, 3420, -13834, -1139, 10742, -2536, 636, 7758, + 4282, -3505, 1190, -7382, -8164, 5306, -408, -5005, + 2776, 7806, 4781, -7903, -2370, 13884, 542, 5643, + 6948, 6471, 2699, 815, 4454, 1882, 2290, -3856, + -3086, 8215, 3234, 4444, -1580, 2835, -3083, 6706, + 7409, 4626, 2658, 2308, 7965, -1034, -2584, 344, + 704, 12280, 10344, -8032, -4410, -6168, 6860, 7977, + -5630, -6680, -5001, -6199, -10378, -1764, -3322, -4284, + -1048, 2721, -11738, -11800, -7975, 2754, 3424, -7641, + -2245, -4945, -194, -1948, -2850, 4111, -21846, -8750, + 4306, 24494, 10428, 26998, 4976, -2701, -3283, -723, + -1539, 6758, -9730, -3517, 6401, -4546, -410, -9900, + -4947, 6996, 10983, 5110, 19948, -78, -1794, 11051, + -14, 316, 6447, -20430, 9363, 9062, -2134, 13711, + 6448, 6655, -5232, 4610, -10352, -3042, -8713, 5777, + -2438, -2602, -7293, -755, 6736, 2960, -3676, -2882, + -9806, 1342, 1242, 2122, 2749, 631, 6502, 2266, +-12996, 13620, 19762, 8096, 702, -4394, -8668, -1460, + -3228, -173, -6239, 4643, -1916, 4098, -2234, 1202, + 1763, 6170, -6320, 12984, -5936, 8301, 6021, 2191, + 466, -4044, -1913, -3458, 8197, -3249, -5935, 2383, + -4241, 4977, -4415, 704, 3488, -8356, 10229, 562, + 14, -4828, -3890, -7599, -4208, -3166, 1132, -16584, + -506, 1397, 6266, 3307, 5782, 2349, 3257, -3017, + 7814, 1216, 7440, -10096, 12698, 944, 1221, -1683, + 152, 6020, -7910, 3897, -6954, -9439, -9838, -3860, + -5383, -4228, -1980, -4045, 7442, -5504, 2145, 636, + 2857, -4538, -820, 4275, -2104, 5076, 5191, -363, +-23254, 1962, -66, 7550, 88, 8721, -1361, 7733, + -2661, 5282, -5112, -24, -975, -3200, -2235, 5144, + 213, -6340, -3974, 1266, -2383, 2432, -124, -233, + -3504, 10604, 806, -918, 11601, 19332, 206, 7456, + -8885, -9692, 3087, 3685, -2183, -7538, 11970, -5098, + -7364, -1173, -3099, 6532, -6850, 4622, -828, 390, + 467, -5364, 4442, -1878, 8949, -4340, -261, -2720, + 6659, 16184, -6552, -3736, -15416, 15774, -306, -4240, + -1807, -10304, 11073, 2743, 3974, -5557, -3499, 5315, +-10742, -378, -4517, -5949, -7664, -2830, -6510, -6096, + 2052, 3425, 1971, -3328, 5326, -1362, 1806, -14286, +-12774, 6058, -3365, -735, -2586, -18658, 6664, 9502, + -1590, 323, 6445, -17766, 14694, -9786, 3696, -4547, + 1601, 3645, -584, 910, 2516, 8197, 3898, 4306, + 631, -2020, 4309, -765, -6591, 2083, 8969, -1474, + -27, 9130, -5808, 8492, -135, 2230, 2296, -4509, + 4600, 4951, 1930, -2564, -5889, -1338, -11737, 6387, + -3649, -5447, -2462, -4751, -1012, 3523, -3504, -9510 +}, + +.cb1108m0 = { + -2417, 4623, 2916, -4257, 120, -10323, 1198, -10252, + -117, 8767, 3160, 2323, 1162, -650, 2237, -4171, + 2386, 432, 1627, -7255, 38, 124, -3658, -1558, +-11711, 10, 8146, 1700, -1975, -16731, 2397, 1056, + -2502, -2660, -2731, -2477, 1488, 1220, 4880, -1156, + 1805, -3, -3009, -6233, -2216, 3440, -3082, 2124, + 70, -2461, 1125, 1919, 11949, -2506, -622, 2209, + -702, 2685, 9183, -510, -2806, -1129, -1823, -1746, + -3600, 2298, -3360, 10793, -1714, 1662, -62, 395, + 14142, -261, -144, -9896, 11481, -884, -2197, 352, + -326, -453, -1984, 2027, -1466, 3290, 94, 3481, + 2533, 4401, 5492, 3803, 247, -896, -1688, -3166, + 1130, -1125, -1973, 322, 867, -1936, 714, -880, + 8, 2313, 23418, -1682, -677, 384, -2140, -386, + 920, -2523, -495, -1494, 3027, -707, 1172, -1403, + 2177, -2137, -885, -1035, -1637, 375, 2452, -3709, + -1171, 2069, 1095, -1937, -686, -956, 2034, 3410, + -3075, -359, -598, -2084, 18550, 1781, -45, 1400, + -1580, -13180, -609, -1376, -3145, -248, 5661, 6886, + -3915, -194, 9876, 1065, 3879, -1726, -837, -660, + -7467, -3055, 3516, 283, -1604, -625, 1165, 3023, + -1531, -1825, 1430, -561, -881, 1346, -129, -1817, + 851, -32768, -294, -188, -116, -646, 1176, 630, + 903, 417, -2487, 352, -789, 571, -127, -2054, + -2112, 418, 1631, 266, -270, 362, -2765, -1198, + -182, 3586, -1272, 1470, -66, -18384, -1230, 823, + 1171, 1350, 1101, 1410, -3730, 1535, -101, -3234, + 2315, -34, -458, 1361, -16497, -990, 1438, 2542, + -1193, 586, -1708, 2689, 2741, 6010, 4209, -5974, + -628, 1556, 2238, 6134, -3040, -2937, 2188, -1660, + 1137, 1316, -2650, 905, -502, -93, -1177, -31964, + -1170, 1504, -1284, -104, 168, 55, 3478, -161, + 2818, -484, -32, -1536, 1218, -854, -351, 4465, + 16922, 681, 4198, 419, -414, 6824, -3906, 11598, + 75, 4904, 1374, 64, -2692, -3759, 3065, -1397, + -202, -347, -2466, 96, 1035, -765, -258, 3711, + 1437, -18250, 566, 976, 2483, 4, -1096, 1906, + 3745, -2621, -2756, 1864, -560, 98, 821, -4094, + 5349, 1369, -5245, -2170, 2932, -1052, 3932, -413, + -400, 31206, 1125, 1631, 43, -764, 1666, 780, + 2036, -564, 64, 1311, -202, 843, -2030, 856, + 1766, -3163, -1158, -626, 316, 127, 1783, 1918, + 3384, -2887, -5885, 1763, 4910, -248, 17100, -3022, + -1880, -2927, -1287, -3308, -1767, -2622, -1460, -250, + 3597, -4526, 946, -1533, 1059, -8, -807, -1283, + 1436, -11184, 643, 398, -1565, 1983, -60, -9862, + 1219, 322, 3132, -2043, 1138, 6258, -3540, 790, + -923, -4692, -1401, 2733, -8918, 4905, 6181, 192, + 82, -1094, 4, -634, -1323, -2865, 1036, 1484, + -2461, -937, 414, 221, 2179, -438, 1273, -2690, + 18442, 2781, 1788, 2264, -1230, 4284, -4708, 1190, + -4810, -975, 230, -3728, 2504, 3602, 3488, 88, + 1322, 487, 2965, -3731, -2341, 5937, 8545, 1716, + 7308, 9017, 6426, 727, 3992, -4584, 388, 3714, + 1164, 18, 445, 1253, 398, -1989, -824, -430, + 745, -5447, 2176, -1986, -3963, 2861, 194, 17739, + 1891, -5368, 4172, 125, 530, -2766, 1179, 401, + 1759, -1609, 31234, 910, 1100, 1036, -948, -1101, + -614, 1768, -344, 840, -696, -842, 320, -1444, + -2560, -3199, 58, -2172, 1375, -3002, -821, -863, +-12096, -2484, -677, -2130, 4450, 3568, -3192, -1114, + -3218, 3121, -503, 5570, -561, 3896, 10566, -3065, + -2768, 1398, 1719, -2708, 1952, -142, 4777, -978, + 2238, -5780, -430, 1228, -1298, -2923, 4353, -1621, + -2368, -2908, -8012, 4398, -502, 518, -6964, 622, + -377, 3758, 6598, 4438, 6849, -7696, 470, 3585, + 466, -14664, 3438, 14706, -1944, -2544, -785, 3653, + 1274, 443, -694, 1968, -3499, 2855, -3930, -1210, + -528, 1931, 3849, -772, -2659, 4499, -3624, -540, + -1645, -949, -382, 979, 595, 165, 429, -80, +-20468, 1040, 544, 2545, -5010, -2122, -2840, -335, + -405, 404, -50, -2996, 1226, 519, -1046, 3745, + -2317, 6211, -14500, 9754, -5802, 5230, -3112, 1506, + 3741, 664, -902, 197, 2476, -3618, 2040, -1066, + 2338, -257, -2580, -293, 2740, -576, 2050, -865, + -3666, -2090, -1831, -32056, 658, 1549, 1602, 1728, + -534, 390, -1517, -627, -4025, -797, -2351, 2759, + -102, 2574, -56, 796, -232, -886, 1639, -2773, + 1007, 830, 5880, -2220, 762, -3834, -2865, -415, + 584, -3498, -4546, -16108, 344, -4072, 551, -5435, + 2007, -1418, 3838, -1662, 1981, 3545, 1424, 769, + 2135, 1705, -15076, -636, 283, 3386, 97, -1048, + -3933, 204, -8616, -556, -2936, 4241, 5100, 1777, + 98, 719, 6202, -1496, 708, 2160, -2396, 4060, + 1513, 2253, -46, -1823, -132, 709, -756, -944, + 575, 1070, -1583, 587, -24575, -1989, 874, -568, + 1040, 1116, -4002, 3196, 2826, 117, 1590, 2456, + 938, 112, -938, -1268, 5056, -2851, 2995, 2559, +-13121, -8374, 3593, -6684, 3663, 766, 747, 1016, + -921, 2241, -1942, 4269, -3312, -1012, 2340, 2781, + -3881, 2532, -1976, -1436, -3219, 420, 22088, -742, + -640, 3270, 1446, 1935, 1279, 1913, 1377, -3297, + -751, 4209, -1052, 2381, 2938, -1330, 2154, 2784, + -2420, 1270, 2334, -526, 1480, -435, 2206, 252, + -510, -1018, -1469, -1294, -950, 424, 1058, -2317, + -846, -20737, -1877, 88, -431, -1268, 116, -378, + -2326, 3115, -246, 30, -4725, 648, 2084, 14286, + -817, 2496, -1947, -4869, -9703, 1505, -2476, -2108, + 747, -449, 3002, -5464, -514, 1805, 2559, 2494, + 12782, -1232, 12091, 2118, 3996, 2592, 1058, 510, + -1384, -3050, 2533, -408, 5219, 3044, 3242, -185, + 2654, -3723, 16, -1723, 1823, 6144, -4806, 182, + 1772, 4841, 16390, -96, 2505, -7713, -5244, -3316, + -6776, 1448, -1470, 4238, 294, 889, -2372, -6281, + -2423, 5423, 2119, 2897, 1378, 817, -993, -1599, +-14662, 3014, -3397, -6182, -245, 4897, 5116, 2285, + -2863, 1174, 415, -6777, 3863, -6009, -4722, -119, + 606, -2247, 4447, 1064, -1935, 2705, -2629, -1144, +-11980, 3805, 882, 1634, 5446, -4300, 643, 3436, + 7632, 592, 998, 674, -2647, 4644, -6854, 1368, + -146, -3395, 10599, 1369, 3852, 1689, 2437, -3937, + 3405, 2517, 1895, -14092, -1142, 2570, 10163, 1608, + -2445, 850, -1678, 3112, -3465, 3138, 4413, -1973, + -4151, 1163, 1822, -3819, -1568, -407, -2642, 424, + 365, -3599, 164, -1448, 1062, 1536, 1590, -1982, + 200, 18572, -230, -638, -1253, 1650, 2280, 4945, + 4527, -2353, -4216, 3752, -3807, 3686, -4816, 2382, +-14833, 1306, 17246, -739, 2012, 3521, 1473, -1436, + 1514, -142, -461, 1038, 2462, 971, 1354, 1272, + 1787, 2420, -922, 3364, 2250, 497, 1349, 2795, +-32768, 425, 1874, -72, 2461, 389, -306, -1180, + -646, 251, 299, -2735, 577, 1055, 1826, 1620, + -1214, 1422, -901, -1273, -2367, -1241, 366, 521, + -433, 55, 4000, 3035, -1390, 2505, 1786, -15397, + 413, -5916, -234, 3559, -6776, -5068, 2251, 36, + -180, 596, 5744, -2450, -1276, -4786, -1872, 24, + 252, 464, 2833, -136, -25600, -33, 873, 2646, + 1471, -1336, -1330, -276, 1778, -242, -951, 1580, + -79, -858, -927, -4310, -604, 7568, -1713, -948, + 192, -260, -1334, -1116, -705, 638, 132, 1186, + -952, 1157, 428, 2039, 1568, 1778, 22453, -2190, + 2176, 1674, -3996, 1294, 1162, 274, 415, -2877, + 464, 505, -1842, -1066, -2241, -761, -291, 8, + -987, -104, 796, -32768, 1302, -809, 571, 1214, + 455, 686, 656, -1752, 886, -790, 644, -1114, + 2358, 11452, -4398, 1334, 13095, 3230, -1818, 4053, + -1990, -1093, 878, 3796, 2712, -1523, -1229, 1077, + 960, 1250, -75, -3233, -7734, 2783, 8430, -327, + -1428, -1687, -4092, 269, 3161, -569, -1267, 1774, + 2772, -2033, 171, -520, 1551, 3719, -3364, -220, + 1904, -1282, -2008, -818, 4261, -886, -19201, -3454, + -478, -2645, -2601, -2124, -3977, 2960, 1563, -432, + -989, 2682, 1734, -9085, 4614, -4454, 2535, -7201, + -220, -10022, -431, -7907, 889, -9658, 6653, 762, + -1827, 5886, 862, -1836, -430, -16363, 5709, 851, + 1814, 304, 5045, 1685, -1004, 5108, -5936, -3143, + 940, 1832, -270, -674, 1441, -241, 3222, -551, + -434, -69, -3584, 349, -1354, -12080, 3639, 5219, + 7583, -1023, 2078, 3263, -5807, -873, 4085, -5153, + -3623, -436, -4717, -1803, -6274, -2049, -247, 2516, + 1922, 10204, 2194, -1574, -535, 656, 1638, -3091, + 1156, 1377, -1220, 4956, -221, 4984, -1154, 4603, + -1618, -5655, -2583, 13494, -2442, -3968, 3086, 1098, + -1625, -13781, -12826, 2659, 3604, -702, -1900, -3508, + -6283, 2320, 1979, -2823, -4890, -1728, 2, -4402, + -437, 1932, -3272, 2853, -3018, 840, -632, -6691, + -484, 9579, 1008, 11677, -2814, -2029, 8048, -1170, + -7366, -2664, 3349, 1319, -1160, -1864, 606, 1568, + 5428, -4763, -2470, 2145, 1798, -502, -1538, -3736, + -1376, 1330, -3567, -78, 478, -743, 890, -800, + -44, -1832, -1761, -1022, -996, -846, 1188, -1042, + -3202, -2439, 1602, 3601, 564, 18338, -17, 1327, + -387, -1998, -1260, 3352, 849, -4780, 1932, -56, + 2625, 10753, -1676, -10536, 2980, 1542, 1177, -3113, + -859, 522, 3092, 9588, 2882, -4540, -1406, -5183, + 50, -4245, 3649, -420, -3612, -5290, -1919, 14559, + -2605, 1169, -2009, 10760, -2372, 339, -2538, 4476, + 3001, -4570, -3158, -3465, 2873, 650, -2099, 76, + 1166, -1469, -2769, -391, 4215, -630, -1448, -1796, + -1573, 5914, 807, -1580, 2072, 99, 580, -2999, + 1079, -202, 17940, -1233, -4909, 1079, 390, -891, + 1834, -2155, -2642, -1703, 1856, -14125, 2081, 3178, + -2480, -4342, -11991, -2050, 1046, 2412, 436, 1046, + -2291, -1718, -3087, 1710, -963, -1914, -3423, 6190, + -1238, -4333, 115, -10550, -2742, -919, -4849, 1502, + -3054, -3304, 2300, -1850, 2337, -6643, 1995, -1279, + -238, 738, -124, 13593, 252, -1424, -165, 2786, + -1717, -838, -11244, -10971, -902, -3330, -2580, -2735, + -171, 4041, -2149, 2502, 6726, -738, -4235, 368, + 6144, -1718, -8620, -1888, 112, -282, -19, 4126, + 10797, 610, -3097, 7783, -2974, -2058, -3558, 470, + -5914, 10322, -20, 85, -1652, 6111, -1398, 2613, + 3733, -3716, 1930, -4325, -1199, -921, -446, 1095, + 1006, 910, -2323, -351, 808, -32768, 274, 1346, + 105, 2360, -1184, 2249, -970, 153, 3180, 1307, + 2207, -962, 2209, -921, 1504, -117, -2111, -3734, + 5738, 8014, 76, 1566, 3013, -462, -3600, 3939, + 4862, 1038, 4312, -790, -426, -1656, 20, -10568, + -6389, -6597, 4230, 2910, 2504, -2962, 256, 814, + -488, 824, -355, 3574, -1890, -2657, -767, 2730, + -1087, -2538, -3522, -4067, 6249, -3354, 13923, 4070, +-11004, 4703, 909, -5968, -5483, -4242, -780, -2489 +}, + +.cb1108m1 = { + 752, -4098, 7726, 592, -9487, 2004, 318, -4322, + 6989, -3350, -478, -4308, 2023, 753, -7081, -3934, + -866, 6267, -5710, 2100, -8467, 100, -4654, -6773, + 4271, 10728, 11618, 1128, 12733, 1471, -5518, -1162, + -2159, -402, -632, -4720, -28, -1412, -1037, 897, + -1242, -1735, -2632, -3460, 3389, -582, 206, 325, + -2547, 46, 1340, -4424, -13408, -4918, -2832, 1454, + 2127, 1276, 2292, -3973, -3230, -7810, 542, 4227, + 2673, -8490, -902, 1361, -1398, -1986, -991, -680, + 602, -2887, -557, 2656, 3214, 1794, 31241, 1462, + -1457, -3750, -1923, -2381, 1313, -128, -172, -647, + -574, 1045, 2438, 1662, 503, 288, 1535, -1016, + 2487, -820, 4692, 2799, -31949, 166, -1655, -2192, + -636, 1357, -2361, -459, -1752, 2782, -293, -144, + 1900, 685, 1766, 1900, -347, -4488, 590, 915, + 798, 1133, -4494, -1388, 75, 884, 13088, -2392, + 679, -315, -7520, 1086, 3873, 3297, -812, -626, + -9443, 2548, -6417, 1619, 7196, -57, 5, 3594, + -1922, 184, 2784, -261, -3310, 2779, 174, 2814, + -965, -2912, -1835, 425, -4285, 896, 2001, 3717, + 775, -1192, 22365, -175, 1522, -711, -1135, 5123, + -517, 870, 4323, 585, -437, 260, -1737, -1984, + 2522, -2539, -973, -8812, -16173, 4678, -4107, 130, + -7832, 1140, 2792, 3394, -692, -4105, -299, 1488, + 1246, 604, 2796, -3767, 579, 188, -1544, 86, + 424, 1204, 4441, -1000, 15227, 3459, -3444, -1631, + -2177, 3497, 1684, 925, 2872, -3905, 5729, 647, + 913, -758, -547, 566, 1787, 792, -1509, -1641, + -926, -1515, -116, 1266, 481, -3944, 28526, -2279, + 5577, 1026, 4082, -605, 696, 1094, -478, 5732, + 7247, 1461, 1521, -234, -42, -878, 270, -554, + 3702, -71, 1362, 7719, 305, -13654, -4985, -1072, + -2044, 6851, 438, -8435, 923, -537, 1511, -1003, + 2056, -2299, -15578, 503, 1944, 3188, 2318, 1761, + 1290, -2322, -568, -1591, -2746, -1966, -9784, 1514, + -5596, 4070, -181, -3006, -1903, -240, -1143, 393, + -1530, -822, 520, 989, -1600, -3374, 946, 678, + 86, -1957, 1947, 1188, 356, 719, -2874, -2245, +-19010, 547, 9067, 439, -2384, 847, -3307, -116, + -1114, -445, -3505, -967, -1252, 4880, 625, 1478, + -2970, -2275, 1337, 422, 3870, -1906, -1033, 1724, + -532, 1734, 1011, -21848, -477, -251, -615, 770, + 7520, 1030, -4372, -446, -3156, -2314, 172, 901, + 70, 1837, 1205, -1344, 2933, 1080, -1290, 1353, + 10205, 1158, 11135, 560, -3480, -2376, 7539, -5418, +-14092, 2138, -253, -9344, -1907, 2177, 687, 2772, + -2730, -546, -4180, 2021, -577, 2530, -3822, -7080, + 971, 2083, -1220, 203, 3187, 3705, -752, -2591, + -704, -17469, -1168, -214, 2518, 308, -585, 1117, + -1893, 2488, 1856, -23, 2418, -2922, 1960, 235, + -1629, -8277, 1088, 2032, 874, 2763, -1867, 60, + 1684, 834, -2676, 1574, -3098, 3250, -3723, -126, + 59, -787, 2710, 930, 1384, 475, -3915, -1162, + 1640, -16818, 2356, -70, 761, 4151, -778, 523, + -183, 19374, -4223, -1379, -1667, -1690, -512, 8742, + -34, 3816, -678, 2749, 2418, -341, -1216, 4280, + -2208, -264, -2884, 4679, -821, 1824, -6724, -1528, +-12042, -9908, 935, 4338, -116, 612, 6, -161, + 1935, 1600, -442, 4059, 2510, 2186, -7678, 3600, + -2460, -1072, -122, -1817, -246, 2786, 9079, 525, + -226, 2628, -2549, 1459, 4533, 1111, -17410, 4529, + -2545, -3272, 403, -2758, -1876, 2734, 2136, -6171, + -2055, 1163, -2820, 2992, 2978, 1458, 1572, 2508, + 13576, -1545, 14861, -796, -6444, 4022, -4358, -529, + 3439, -2630, -2457, 3030, -2972, -398, 471, 2547, + 1127, 1344, 202, 420, -1858, -589, 594, 1478, + 5590, 1682, -1560, -378, -2198, 400, 2231, 566, + -80, -2042, -4557, -2309, 8743, -4258, 1291, 11770, + 718, 2342, 2912, 5170, 2470, 6832, 833, 4990, + 2009, -1258, -898, -1414, 1214, 670, -2104, -5068, + 788, -18997, -743, -864, -356, 1592, -5786, 652, + 4952, -2319, -1097, 2177, -1654, 2879, -1645, -172, + -1581, -3062, -805, -1065, -2222, 20857, -1146, 864, + 1690, -1794, 855, 307, 2320, 3618, 6184, -4129, + 187, -2423, 4946, -3072, -213, -2621, -2026, -5793, + -986, -1597, 2125, 1474, 1766, 360, -4652, -1030, + 1546, -1085, -253, 1016, -96, -1608, -7017, -4855, + 1295, -271, 3751, 341, 19804, -2006, 2322, -2298, + 353, -2077, -764, 212, 150, -1140, 564, -614, + 268, -2023, -332, -699, -937, 1684, -1617, -22863, + 1202, -144, 62, 373, -598, 184, 987, 3721, + -611, 86, 3676, 362, -652, -214, -311, -694, + -1973, 2351, -733, -1601, -1189, 28227, -154, 10, + -347, 3400, 1333, -1695, -773, 1362, -447, -2999, + -626, -1776, 2474, 2195, -1041, -797, 1828, 62, + 3397, -1779, -2924, 1740, -1694, 4083, 15100, 3871, + -7821, -108, 292, 998, 3141, 5813, -918, -1290, + -902, 895, -1336, -50, 2014, -2066, 2383, 68, + 31769, -334, 1243, 1981, -715, 125, -380, -1272, + 1068, -357, -1734, -1138, -630, 1042, 688, -438, + -558, -2460, -2894, 4196, -1004, -2177, -2291, -4701, +-13990, 747, -5558, -2754, 1950, -2780, 8414, -1286, + -946, 220, -2507, -192, 3726, -1361, 1296, -2215, + 872, 8270, -2797, -6732, 1256, -1957, -2916, 107, +-14847, 1868, 4638, 1292, -1006, 5285, 2947, -5028, + 942, 153, 420, -1152, -391, 3612, 4621, 172, + 762, -876, -3561, -14406, -552, -2570, -4448, -15704, + -806, -928, 3380, -686, -2604, -3895, -714, -626, + -1763, 1144, 485, 34, -1922, 1528, -213, 5050, + -804, 185, 96, 3320, -621, -329, -1444, 864, + -1684, 16583, 1872, 3327, 2146, 1132, -8216, 73, + 6524, 1623, -4147, -4985, 1450, -646, -7189, 4524, + -1596, 2120, 3913, 680, 2094, 1660, 752, -1221, + 2414, 3986, -10314, 2096, 129, -5458, 634, -5426, + -594, -9731, 2083, -2284, -5085, -4777, -1323, -1740, + 6157, -841, -126, 247, -1163, -7005, 3863, -764, + -1552, 1356, 10788, -745, -12481, -73, 5234, -3220, + 2979, 635, 3372, -540, -36, 2887, 5221, 931, + -1724, -4824, 780, -49, 120, -739, 890, 714, + -1438, -458, -1861, -16732, -1858, -13282, 2182, -6796, + -3307, 556, -2968, 542, -2358, 1463, -3536, 1866, + 2833, -1369, -1576, -2825, 3561, -1625, 1858, -1052, + -1079, 1302, -2049, 19052, -1188, -4137, 1592, -4705, + 1082, -1168, 2355, 649, -1900, -2582, 1000, -3065, + -2399, 3625, 1062, 860, 2586, -2645, 14755, 3147, + 5002, -6720, 1728, -2114, 5090, -2838, 3020, -5048, + 4182, 2237, 706, -4945, -86, -1908, -1207, 135, + 675, -200, -22134, 1492, 2490, -1324, -1135, -842, + 1457, 185, 1342, 3516, -882, 1069, 1159, -52, + 1844, -1186, 554, 3860, 1824, -2136, -881, -1281, +-13259, -705, -90, 2150, 573, 2787, 1068, -1968, + 121, 805, 4382, -1033, -9220, -744, -1446, 7180, + 257, -5983, -1643, -6198, 1854, -3524, 1060, -118, + 56, -843, 2832, -98, -3493, 368, 6, -1877, + -3615, -1954, 17971, 962, 1532, -1754, 3776, 661, + -2025, -60, -1013, -1222, -3062, -69, -4933, 3064, + -1176, 213, 477, 1081, 1679, -2328, 1984, -21759, + -881, -54, -1101, -1092, 598, 1648, -3384, -213, + 379, -1318, -1972, 630, -536, -1970, -461, -356, +-22416, -1855, -113, 876, -2809, -587, -2323, -56, + 2177, -797, 1649, -4069, 1350, -2075, 101, -1384, + 1703, 1085, 471, 8093, 1020, -4112, 970, 866, + -1456, -341, 1418, -12938, 379, 9787, 1814, 2337, + -1705, 9913, 1026, 1962, -744, -2900, -1690, 1534, + -959, -629, 2330, 3735, 4742, -3139, -2135, 2298, + -2765, -1389, -3634, 27139, 671, 2208, 494, 1015, + -1197, -239, -321, -1145, -679, -637, -3116, 544, + -952, 882, 396, 1087, -3163, -2684, 759, -725, + -2186, -542, 2545, 3669, 24, 1689, 10473, 1836, + -419, 322, 2475, 1908, -1346, 50, -6401, -3644, + 552, 2348, 1327, 11853, 2467, 5493, 1544, 464, + 1796, -2801, 8217, 1014, -2103, 3764, 8091, 170, +-12422, 1708, -2438, -1873, 1970, 2160, -5027, -647, + -118, 2830, 2379, -1091, -5723, 124, 3017, 417, + 55, 1376, -1079, 7122, 3086, 17847, 2468, 3273, + -599, 3302, -922, -2073, -1696, 805, 2022, -1899, + 3188, 1425, -4364, -140, -3760, 437, 1393, -1298, + 17166, -1283, -2904, -692, 518, -404, 944, -1990, + -968, 1323, 2376, -11708, 2187, 3164, -559, 2212, + 1598, -1741, 360, 633, 3075, -660, -1012, 778, + 565, -2020, -123, 5, -2217, -2967, 374, 272, + 336, -1725, -408, -2270, -2645, -1044, -517, 1911, + -386, -4439, -7603, -1000, 7660, 589, 14931, 2901, + 11998, -13102, -1919, 3904, 86, 1617, 7324, 3078, + 1714, 4636, -2504, -194, -3274, -710, 33, -1965, + -2298, 2513, 726, 75, 67, 884, 2104, 4110, + 1936, 10387, 2722, -1970, -12496, 4799, 3086, -2938, + 1719, -2138, -338, -1124, 971, -4200, 480, -3361, + 6220, 5954, 1830, 1001, 2996, 4166, -2854, -437, + -1430, 1072, -312, -12949, 3113, -2479, -2034, 6956, + 2805, 2128, 856, -8803, -4709, -1274, -120, 1252, + 3898, 6526, -3914, -2276, 2754, -2604, -3038, 4136, + 2598, -2172, 4861, -2457, 2, -2693, -808, 3527, + -1184, 392, -2202, 2406, 960, -1064, -2589, 1161, + 2418, 728, -466, -4865, 211, 14720, -2093, -1977, + 85, -12618, -2073, -3028, -1067, 1734, -2491, 9506, + -422, -2718, -2966, 3883, -2852, 336, 1306, -2297, + 2009, 2589, 3071, 192, -1239, -10553, 2, -1174, + -3036, 9939, -27, -1278, 1448, 18655, 761, 931, + 445, -94, 206, 448, -1865, 232, -4353, 4596, + -260, -976, 594, 648, 796, -1376, -1186, 3056, + 3171, -5675, 6179, -1287, 16934, -1478, 1090, 577, + 8075, 1119, 2943, -3208, 1852, 1986, 6003, 901, + -962, -3196, -1907, 392, -2605, 2796, 4082, -456, + -3109, -1219, 123, 2470, 174, -1254, -1350, -4919, + 1271, 12302, -1154, -6317, -3346, -1315, -144, 1214, + -49, 3491, -1029, -2043, -8373, 4197, 4971, 9808, + 9732, 700, 2247, -2755, -2034, 3260, 839, -10554, + 1661, 11484, -3180, -1909, 1089, -813, 3116, -2103, + -3726, -4514, 663, 1152, 3902, 4862, 2739, -3828, + 707, 2712, -8009, -832, -16492, -1472, -2422, -5593, + 322, -1894, 2810, 109, -1788, 2050, 3539, -3112, + -6178, 2487, 2102, -135, 3163, 2096, 4123, -310, + -1090, -2, -2662, -17087, 1373, 1448, 162, 527, + 655, -2248, -3530, 194, 1305, 7590, -5515, 1225, + 1607, -3816, 2185, -2679, -4486, -582, 4981, -1675, + 147, 14790, 119, 11771, -1228, 1012, -6133, -2247, + -3913, 1348, -1846, -513, -6386, -749, 6726, 745, + -809, -799, 3224, 43, -2230, 2598, 2994, -1590, +-11198, -14476, -256, 695, 877, -3680, -2734, -1448, + 1336, -1633, 3327, 3497, 2956, -782, 2958, -1866, + 2876, 2003, -856, 1282, 5068, 391, -10539, 1703 +}, + +.cb1110l0 = { +-14944, -14950, -73, -1141, 1532, -575, -620, -816, + 1185, -1597, -2651, 1426, -1458, 1317, -1320, -19, + -209, -352, -163, 912, -85, -180, -546, -1121, + -435, -345, 229, 364, -850, 632, -426, -359, +-32768, 278, -1021, 310, -31, -355, -442, -234, + 415, -202, -10393, 1645, -378, -2270, 837, -1857, + 556, -935, -1344, 3016, 3452, 1597, 1378, 466, +-13740, -878, 1475, 237, -1301, 9756, -592, 23, + -192, 335, -58, 285, 376, 40, 24, 292, + 426, -1962, -798, 745, 1379, -34, 397, -14748, + -6285, 7343, -6374, 4442, -14800, 1878, -24, 1606, + -728, -476, 1754, -1052, 911, 3139, -1444, -222, + -1968, 1858, 1330, 244, 213, 935, -92, -348, + 155, 418, 29128, 236, -190, -226, -309, -178, + -690, 46, 716, -534, 147, -630, -75, -826, + 37, 4745, -1056, 2400, 1398, 1494, 460, -221, + 2908, -656, -15611, -2940, 2342, -98, 581, -3144, + -471, 3772, 2057, 1583, 13738, -139, 330, 1175, + 429, 63, -14544, -374, 1439, -1226, -422, -690, + 816, 1279, -592, 1642, 700, 1338, 0, -714, + 46, 377, -188, -366, -197, -637, -622, -262, + -69, -637, -1266, 257, 620, -1040, 324, -19064, + -602, -463, -1329, 513, 2699, -421, -1918, 2250, + -404, 403, -1514, 134, 147, 3, 426, 605, + 276, 561, -26, -294, 630, -500, -480, -133, + -712, -1144, 238, -633, 173, -29164, -1182, -274, + -138, -271, -232, 30, 706, -168, -848, 704, + -2132, -248, -108, 669, 1165, 234, 1243, -12201, + 2208, -1971, -829, 10305, -3964, -1502, -409, -3918, + 4520, -2259, -797, 2235, -5560, -1710, -2472, 280, + -1747, -980, -4529, -5208, -1813, 330, 890, -6220, + -710, -5583, -4704, -913, 2920, -12484, -4340, 334, + -1303, 283, -740, -1261, 3556, 3210, -11640, -14438, + -2557, -795, 747, 546, -2488, 1891, 485, 725, + 338, 1579, 2092, 2354, 284, 2812, 490, 1442, + 187, -2699, 1196, -1783, 1228, 2364, 13364, 258, + 2102, -6163, -200, -5475, 2804, -576, 6878, -2852, + 2246, 1186, 584, -136, 5258, 3825, 3045, -1661, + -5246, 2548, -5054, -4383, -1542, 12912, -1580, 1268, + -1415, -2012, 1021, -2106, 979, 2390, 3411, -1076, + -439, 5416, 1333, 440, 3422, -13384, 2540, 2544, + -3668, -2308, 1042, 589, 4166, 5090, 1539, -3447, + 7003, -4396, 319, -590, 481, -471, 22260, -1936, + -297, 1302, 1163, 937, -164, 847, 768, 827, + -430, 792, 472, -1557, 712, -602, -1007, -278, + -974, -3198, 10560, -2124, 335, -1206, 629, -13712, + 12, -1673, -691, -666, -2890, 826, 1792, -1547, + -2016, 807, 1810, 841, -814, 1214, 760, -1056, + 404, -94, 144, 297, -584, 106, 116, -132, + 236, -507, 86, 853, -670, 413, 32767, 730, + 10835, -502, 1297, -3857, -1035, -1602, -164, -1721, + 1468, 507, 1064, 1478, 4323, -760, -882, -4331, + 2564, -10933, 3000, 2101, -2492, -72, 12636, 2743, + -1113, -8334, 6720, 2348, 491, -23, -1065, 1506, + 2090, -1731, -1997, 675, 425, 8165, 695, 2285, + -433, 515, -465, -347, -1006, 357, -55, 57, + 481, -31494, -816, 60, 76, -439, -328, -217, + 265, 123, 839, 218, 1355, 243, -878, -12819, + 5168, 318, 1376, -2931, 12689, -83, -220, 2848, + -770, 150, 1631, 1955, 1552, -1371, -3053, 1752, + -7250, -24, -514, -5568, -1529, -112, 419, -1136, + -672, -1847, -1136, 90, 453, 4810, 13012, -2355, + -2477, 1393, 451, 3390, 12, -2228, 1840, -2543, + -2404, -2969, 186, -444, 204, -265, -11467, 2204, + 1821, 3591, 67, 8821, 4015, -183, -5902, -1468, + 11394, 3062, -128, -476, 2495, -2888, 13482, 686, + -1320, 371, -884, 1829, -1810, 337, -1124, -1442, + 432, 1950, -1203, 663, -10445, 2310, 766, 137, + 4418, 2821, 135, 116, -12164, -3592, 686, 2310, + 1229, 1930, -1756, -1309, 1439, -3741, -305, 1547, + -9940, 3198, 1333, 2403, -2847, -3892, -259, -1766, + 881, 14310, -1711, -840, 2259, 3027, -1527, 1156, + 2904, -75, -728, 1536, -127, 152, -3240, -726, +-11914, 1037, -851, -1893, -748, -3294, -1114, 6072, + 103, -1539, 4573, -1637, 5242, 2705, -9890, 254, + -1565, -407, 1818, -23004, 1110, 119, 256, -707, + -451, -679, 374, -935, -669, 403, -10, -594, + -525, 1403, -1016, -553, 595, -169, 2523, -82, + 947, 11572, -1166, 11668, -4962, 842, -860, 89, + -3308, -640, 558, -851, 622, -1002, -4933, 2762, + 1991, -121, 1401, -111, -49, 868, 135, -1392, + -279, -560, 412, -241, 1414, -802, -1256, -298, + 447, 17738, -320, -1150, 1650, -398, 5626, 6076, + -8919, 455, 12716, -2094, 157, 1361, -1515, 1494, + -6210, -553, -1785, -424, -3049, -4066, -1188, -732, + 1992, -1926, 1495, 1085, -22434, 1187, 391, -1512, + 747, -313, -502, 1331, 456, -323, 246, -581, + 56, 1448, 2071, 535, 782, 520, -136, -290, +-12350, -11858, -456, 2340, -310, 22, 2210, -2531, + -392, -898, 3919, 1354, -332, -4255, 169, 425, + -476, 2577, -1172, 1984, 266, 514, -516, 2481, + 81, 2103, -710, 273, 1405, -14811, 5858, 3621, + -982, 345, 2044, 158, -2050, -602, 954, 342, + 239, 157, -317, -35, -260, 307, -31972, 228, + -77, 225, -154, 643, -883, -518, 32, 372, + 208, -22488, -458, 530, 104, 254, -775, -1264, + -571, 900, -263, -323, -296, 962, 520, 548, + -2196, 42, 1408, -211, -16117, 2052, 12656, -822, + 507, 321, -772, -786, -144, -3539, 892, -3430, + 19, -1831, 1161, 1836, 988, -1134, -704, -2994, + 692, 765, 457, 1624, 502, 13, 364, 337, + 32108, 1517, -225, 189, 141, 985, -572, 262, + -146, 31, 236, 269, -278, -1686, -13968, 1247, + -1009, 1046, 13467, 1276, -268, 307, -1383, 1544, + 136, 949, 70, 446, 1391, -2188, 745, -374, +-14231, -712, -15202, -533, -108, -2244, -1232, 450, + -895, 1086, -782, -1082, -718, -660, 796, -2095, + 2722, -468, -1717, 147, -23566, 377, -220, -1731, + -1416, 486, -241, 266, -802, -322, 1066, -544, + -167, 520, -1297, -100, 622, 670, -188, 711, + 32, 1155, 628, 350, -112, -154, -1048, -44, + 36, -454, 304, 32767, 356, 462, -1194, 549, + 138, 0, 1044, -119, 195, 1098, 521, 3294, + -3776, -224, 4297, -1256, -303, 2107, 300, -13283, + 2933, -3194, -1408, -4152, 4195, 287, -932, 1247, + 13453, 277, 418, -598, 87, 1132, -80, -405, +-13400, 656, -1310, -1447, -3974, 1719, 313, 500, + 1078, -114, 1449, -293, -120, -4754, 5583, 235, + -5140, -865, -484, 15572, 336, -1854, -154, -454, + -1475, -726, -3718, -4048, 1575, 480, 1094, -2209, + -3202, 420, -564, -48, 964, -2667, 2172, -1666, + 112, -730, 203, 3618, -15857, -4853, 48, -1084, + 1512, -937, 3353, -453, 223, 2267, 139, 190, + 1959, -720, 4389, 681, 10383, -112, 12390, -882, + 1695, 3539, -169, 3131, -122, 3627, 252, 185, + -523, 112, -219, 214, -182, -102, 118, 230, + -60, -801, -25, 42, -279, 262, -32358, 344, + -542, 382, -223, -404, 1201, -2646, -163, -803, + 3041, -1009, 3818, 756, 5834, 14249, -1828, 139, + -218, -658, -1314, -4980, -3322, -1461, -1598, -91, + 2464, -954, -5203, -791, 1339, -13598, 594, 702, + -388, -1115, -2377, -370, -3658, -3322, 1871, 2513, + 2910, 4095, -2195, 4291, 886, -567, 1182, -302, + -672, -21, -268, -29244, -199, -1024, -1284, 485, + 1432, -1086, 119, 1030, 418, -643, -1165, 1847, + -30, -844, -909, -416, -604, -609, -289, -391, + -238, -94, -391, -810, 413, 356, 954, -1935, + 30996, 441, 138, 1381, 1130, -2313, 558, -203, + -248, -951, 408, 1815, 256, -429, -892, -695, + 1138, 439, -760, -63, 6498, 570, 15252, -3397, + 170, 935, 338, 1, -528, 524, -541, -281, + -3, 499, -333, 685, 436, 32176, 389, -153, + 572, 256, 53, 16, -902, 724, 2849, 2503, + 80, 667, -1867, 742, 15205, -8715, -2588, -476, + -450, -733, -891, 1178, -1751, -1630, -114, 144, + -138, 10145, -188, -1608, -131, -247, -544, 9774, + -610, -2868, -3472, 345, -9294, 3724, 2634, -5124, + -392, 2551, -649, 782, -18, -160, -351, 12074, + 13865, -1294, 1262, -3135, -2861, 18, 753, 167, + 620, -2432, 1998, 740, 1902, 400, -206, 3518, + -3563, -632, 72, -1810, 1520, -827, -572, 1604, + -613, 3704, -736, 11100, 12702, -3189, -792, -3552, + 1621, 1841, 1236, 1215, -457, 9542, 9278, 2633, + -8801, 862, 1741, -4840, -2620, 616, 324, 2152, + 3632, 880, -472, 1927, -3456, -2105, -965, 3426, + -1893, 3095, -1152, -3542, 182, 998, -386, 1202, + 481, -1951, -510, -931, 1688, 151, -13664, -3894, + -973, -906, 1524, 9576, 2607, 12497, -819, -5214, + 5936, -634, -610, -4148, -421, -486, -1864, -306, + 2421, 724, -219, -1304, -2106, -504, 6762, 5266 +}, + +.cb1110l1 = { + -2972, -1201, -1388, -1762, 340, 21127, -999, 126, + 111, -1224, -1738, 311, -712, -450, -114, -648, + -752, -172, 67, 375, -967, -1032, -10763, -1885, + -2223, -3258, 480, -228, -143, -1299, 13128, -3062, + 1418, 6, -649, -1816, -288, 767, 345, 876, + -491, 948, 540, -167, 1969, -1883, -455, 20584, + -656, 114, 308, 279, 1105, -594, 1332, 255, + -356, -186, -540, 1898, -873, -477, 1404, 30475, + 370, -322, -337, -206, -440, -894, -54, -466, + -640, -408, -256, -560, -1503, 626, -573, -1684, + 419, 407, 2076, 5022, 3143, -1135, -12118, -12082, + -1462, -2060, -5432, -1092, 1575, 1958, -968, 122, + 958, -5312, 677, -1952, -12276, -1594, 1211, -1094, + 1992, -11032, -2993, -834, -1297, -1139, 312, -1546, + -4253, 1191, 21, 2771, 639, -2514, 6623, 746, + 1830, 2967, 1688, -14893, 7988, 4099, -97, 1165, + -2350, 65, -1308, 1834, -2084, 1683, 5118, -1633, + -10, -5282, 403, -1489, -264, 398, -2420, 12854, + -1498, -2642, -1486, 826, 699, -2213, -2296, 11849, + 478, -2202, -561, -250, 199, -2433, -948, -402, + 433, 403, 13031, -124, -180, 1499, -643, 527, + 11368, 5833, 938, 3202, -452, 2875, -1163, -117, + -2047, -1068, 211, 3122, -236, 13548, -702, 352, + -312, -1901, -2145, 2334, -12100, -76, -419, 362, + 3501, -220, -3086, 572, 1537, 3240, -1489, -1012, + 640, -513, 930, 390, 31019, 724, -78, -706, + 183, -157, -122, -847, -1156, 301, 508, -456, + 321, 317, 1300, -512, -1743, 10190, -294, -116, + 4183, 1374, 13360, -1339, 1832, 2547, -702, -2782, + -1464, 1176, -1287, 2256, 2169, 836, 2096, -248, + 1777, 11306, -211, 265, -3834, 336, 1936, -586, + 633, 1037, -1915, 12862, 930, -273, 2333, -3239, + 429, 374, 2518, -671, 570, -2208, 385, -284, +-15613, -1752, 1341, -531, -744, -1111, 290, -2302, + -1012, -2933, -366, -30, -4595, 1400, 560, 48, + 15739, -945, 411, 1876, 2441, -2144, -1222, 12448, + 54, -726, -2743, 2548, 2100, 1307, 408, -198, + -1802, -63, -1919, 933, -329, -528, -15918, 1704, + 3028, 217, 606, -2804, 2052, 9320, 592, 969, + 6836, 647, -671, 584, -1, 3564, -2575, 436, + -2195, 414, -201, 1099, -772, -220, -578, -467, + 125, -934, 271, -21476, 288, 215, 216, 476, + -560, 768, 1142, -169, -1112, -14096, -14436, 2769, + -1464, -61, 1373, -3539, -1067, 1175, -1549, -861, + -332, -1876, 3159, 340, 1711, -2453, 457, 2536, + 1114, -2278, 2464, -3253, -466, 12291, 12484, -2868, + -800, 1142, -4244, -178, 3781, 1542, -663, 1976, + 3105, 145, -100, -1774, -1039, 1627, 15540, 4194, + 5392, 741, 1816, -544, -9100, 4255, -1083, -1266, + 2580, -4200, 1934, 1721, 129, 2276, -2704, -1341, + -1310, -11926, -1478, 199, 755, 619, 4231, -478, + -1627, -1242, 1842, 13170, -2416, 778, 192, 273, + 782, 774, 2188, -838, 3139, -1532, -1639, -1073, + -596, 770, -353, -53, 82, -322, -20584, -344, + -443, 158, -144, -554, 50, 954, -145, -336, + -2050, 596, -950, -2690, 13908, -13783, 4792, 879, + 584, -2987, 967, 192, -585, -783, -1341, -3108, + -1622, 2478, -1362, -1470, -1556, -430, -110, -736, + -8097, 2073, 964, -417, 1669, -5425, -7846, 536, + 12883, -1690, 1143, -242, -438, -2274, 57, 302, + -574, 637, 2816, -1642, 2166, -172, 893, 421, + -614, -565, -338, -526, -1085, -939, -1138, -991, + 1919, 1720, -18845, -1950, -342, 1930, 321, 184, + -956, -374, -462, -216, -6, 26, 386, -50, + 603, -720, 634, -252, 261, -860, 218, 22846, + 11544, -459, -946, 452, -102, -1203, -1802, -1105, + -310, 787, -220, -1113, -2043, 650, 13767, -3638, + -296, -902, -413, 252, -816, -172, -505, -1335, + 890, 768, -523, 808, -331, 20000, -264, 1763, + 133, -1, -464, 949, -954, -147, 1780, -190, + 30, -7422, -4615, -1006, -470, -742, 500, 7509, + 1500, 1550, -3614, 810, 2595, 1506, -12926, 3588, + 402, -2547, 1505, 65, 4, 3382, -2201, -2441, + -1521, -5450, -3820, 282, 5212, 1186, -1056, -2334, + 988, 12987, 390, 4141, -2680, 1663, -8034, -1792, + -225, -674, -7147, 13254, 1631, 10163, -3332, -7, + -675, -735, 772, -2299, -326, 1641, -1174, -1911, + 82, 776, 891, -445, 18590, 238, 1417, -2372, + -9718, -2682, 600, -1401, 604, -1791, -22, 1546, + -1764, 525, -1355, 348, 3260, 1115, 204, 524, + 225, -12776, -679, -15595, -1188, 1078, 82, -859, + 28, 819, -1220, 563, 2309, 331, -1158, -2010, + -264, -383, 1732, -424, -2742, -775, -329, 132, + 391, 1261, 1033, -9812, -11829, 2433, 2690, 606, + -2724, 7216, -296, -1834, -1694, 456, -4732, -400, + -3192, 1428, -316, -13674, -2702, 2320, -6548, -2025, + 1222, 1749, 4005, 2924, -3539, -5104, -2333, -1438, + 2598, 62, -757, 760, 343, 154, -31947, -534, + 1296, 697, 88, 345, -577, -500, -174, -326, + -198, 272, 157, -815, -636, -1163, -867, -273, + 1054, 774, 1624, 989, 107, -1088, -673, 2143, +-22962, -566, 151, 72, -27, 1034, -444, 501, + 1905, -1455, 21, 289, -10670, -789, -2421, -2686, + -327, 804, -3009, 907, 960, 1379, -43, -552, + 2203, -1406, -911, -11094, -529, 4458, -4152, -70, + 3162, -12546, 326, 874, 1426, 3019, 2315, 104, +-12516, -1591, -2877, 772, 1982, 1160, -4491, 3417, + -1524, -2139, 130, 930, 9359, -18308, -376, 4090, + -468, 156, -216, 60, -643, -3440, 256, -835, + -2389, 1660, -542, -1628, 4270, 3574, -3136, 433, + 1069, 30024, 561, 268, 790, 294, 207, -1552, + -736, -97, -215, -98, 690, 686, -202, -736, + -453, 655, 511, -156, 1006, 361, 1424, -1254, + -361, -1253, -1419, -290, 78, 555, 565, -488, + -923, -18193, -630, -908, 188, 925, -1684, 241, + -319, -14478, 17007, -1415, 274, 592, 1344, 1784, + -731, 344, 992, 141, 290, 481, 628, 623, + -1166, -2092, 140, -1056, 13736, 754, 1980, -238, + 2132, -1372, -2216, -12057, -1662, 66, 1742, 2209, + -962, -1574, -3044, 173, -3066, 183, -4476, -1016, + 6160, 780, -1193, -3334, 179, -371, 244, 160, + -686, 669, 330, 426, 65, 159, -664, -186, + 479, -742, 54, 605, 32603, -941, 370, -91, + 856, 825, 1042, 374, 651, 313, 734, -240, + -49, -685, -1994, -604, -875, 44, -884, 886, + 13012, -1506, -4317, -1926, 3050, -1027, -482, -40, + 137, -2560, 1366, -11812, 2112, 2266, -2690, -1339, + -700, -243, 2322, -1042, 4635, -3210, 4281, 47, + 670, 9218, 1165, 814, -62, -2276, 12987, -714, + 2481, 1355, 896, 2840, -1664, 2048, -345, 2285, + 1754, -669, 2284, -288, -575, 944, -1528, 44, + 1071, -706, -543, -1347, 880, 257, 1364, 1444, +-17896, 99, 1539, 1813, -611, 355, -2290, 980, + -787, 132, 300, 2353, 204, -798, -296, -594, + 895, 842, 18755, 1129, 79, -189, 515, 882, + -286, 109, 305, 374, 1323, 861, -18, -78, + 294, -320, 674, 504, -159, -549, -95, -32403, + -90, 658, 1082, 1611, -137, -74, 1160, -794, + -55, 822, 2627, 1203, -3540, 9829, -7860, -9063, + -4015, -894, -2218, 729, -879, -1869, -2446, 4050, + -488, 13211, -290, -820, 371, 14196, 866, -891, + 218, -1838, 2162, 1144, -186, 512, 1416, 546, + 3298, -1253, 128, 1202, 557, -1967, 680, 545, + -139, -3008, 18453, -3322, -137, 163, 1377, 1116, + 2572, -1577, -1846, 651, -1319, 796, -862, 331, + 4383, 2453, -1894, 3264, 14137, 842, -3087, 3740, + -1100, -2400, -1364, 2406, 417, -2393, -868, -3158, + -9712, 3480, -1403, 1896, 201, 1285, -593, -11718, + 99, -539, -186, 45, -2266, -12228, -2658, 2802, + -1198, 1022, -3840, 1401, -1918, 1655, 1725, 96, + -205, -913, 1629, 568, -1285, 1264, -1160, 594, + 223, -336, -1436, -472, -19792, 553, 1494, -195, + 570, 282, -653, -54, -1115, 153, -484, 141, + -188, -278, -173, 464, 13, -634, -42, 390, + -464, -246, 622, 1229, -692, 29175, -574, 1150, + -135, 2685, 2452, 63, -962, -918, -1657, -1978, + -172, -677, -3414, 1345, -3964, 2875, -1412, -654, + -3000, 10739, 11348, -2232, 516, 8303, -189, 2564, + -150, -373, 903, -275, 2394, -1135, 508, 424, + -1704, -2222, -3789, 1938, 216, -12702, 2488, -1364, + -2175, 1114, -819, -2756, 1564, 952, 36, 609, + -933, -1568, 110, 143, -1575, -4236, 528, 15042, + -1920, 348, -2623, 5217, 1911, -1088, 259, -590, + 364, 2081, -3585, 662, 249, -119, -111, 778, + 2167, 11, 2500, 7182, 14452, 4388, 4121, 3623, + 1598, 532, -507, 877, 3830, 372, -2184, -2810, + 11748, -2095, -1079, -3070, -768, 2901, -3587, -2572, + 10008, 563, -4588, 1026, 1117, 1879, -12004, -416, + 317, 2032, 1800, 1058, -84, -296, -1748, 2588, +-11019, -1627, -3264, 2480, 96, 2146, -2672, 2418 +}, + +.cb1110s0 = { +-32746, 360, -2774, -672, -1808, -14, -1037, -1327, + 1409, -2215, 172, 1557, 945, 2031, -702, 1844, + -1106, 472, 2603, -978, 2782, -5691, 1473, -5668, + 7129, 6600, -2160, 108, -1844, 2062, -2395, -740, + 1690, -45, -725, 77, 7236, -12903, -3356, -764, + 1870, 720, -2201, 790, 9950, -3694, -5340, -4031, + 4115, 6863, 2352, 1484, 3606, -4855, 714, 4104, + 6240, 7261, -6855, 4919, -2847, 6701, 7469, -616, +-11442, -1935, 9157, -4072, 133, -5976, 2455, -9360, + -2898, -4353, -7721, -3098, -3505, 2568, -5432, -576, +-10072, 250, 2173, -4196, -4322, 2688, 5220, -6026, + -346, 11678, 2071, -7344, -2182, -530, -180, -2568, + 1524, -1617, -8825, -4845, 2794, -2813, -2669, -2423, + -2709, -8985, 2105, -4629, 708, 2040, -5680, -2470, + -7277, 6841, 6523, 4196, -6788, -1982, 3844, -5000, + 156, 1930, 1780, -3824, -286, 3908, 1703, 7304, + 1145, 144, 1180, 7145, 3175, -13823, 6580, -3066, + -6321, -9739, 4432, -1145, 2923, -2636, 3838, -7037, + -3913, 1262, -1398, 363, -141, -886, -5667, -212, + -2118, -2717, 2724, -18802, -2098, -155, -1399, 782, + 797, 766, 2613, 5374, -3767, -1711, 624, 693, + 2544, -6153, 7179, 6835, -762, 5061, 655, 2600, + 9208, -7030, 7047, 1654, -3404, 176, -5486, 1374, +-15378, -487, 7456, -1954, 2404, -2994, -1608, 2362, + -498, -7952, -6143, -3996, 1596, -3013, 1181, -1534, + -5265, 220, -2677, 1047, -4629, -15066, 3966, -446, +-11713, -5694, -393, -250, -1336, -7394, 1508, 6239, + 3788, 6273, 6215, 822, 2657, 8057, 8391, -658, + -2561, -11587, -2589, -6702, -9227, -1016, -2220, -9702, + 5988, 1859, -6100, -4594, 221, 2529, 2217, 8273, + 1804, -6128, -2859, -8259, -4707, -2494, 1913, -352, + -4561, -289, -1801, -994, -4445, -1001, 5422, 10868, + -7366, 1679, -5195, -6859, 2982, -406, 2400, 4520, + -3611, -1892, 4900, -3504, 771, 2774, -772, -1929, + -7354, 375, 628, 4522, 1069, -969, 8083, -155, + 3178, -1138, 1752, -17288, 4390, -2483, -2071, -1353, + -1155, -456, -2683, 6798, -1908, 1797, -6657, -2770, + 5610, -14518, 5922, -3964, -938, -853, 1416, -1077, + -4562, -160, 5820, -3031, 5091, 1987, -2746, -3779, + 238, -264, -3074, -11718, 9370, 9806, -6302, 3979, + -2938, 4034, 393, -1399, -4466, 2181, 756, 394, + 2264, -3664, 78, 470, -3228, 3942, -1714, 708, + 4988, 1938, -2722, 4555, -5054, -1026, 19312, 354, + 107, -5357, -4364, 597, -2566, -2812, -2278, -446, + 1384, -371, -2566, -388, -3964, -8989, 9136, 3389, + 8440, -5570, -1262, -5874, 2056, -5973, -185, 4540, + -4924, 154, -3653, -1113, -3048, 7099, -2734, 2940, + -6704, 1543, -8120, 10134, -9485, -6645, 4816, -442, + -32, -2430, 4932, -6129, -5050, 6120, -2147, -6910, + -1342, 1075, -2458, 50, -4747, -3080, 1886, 1490, + 18972, 48, 787, 2441, -405, 1668, -1399, 2202, + 2175, -3592, 1548, -2728, -4864, 504, 383, 376, + -1073, 2142, 504, -3114, 6378, -5516, 13462, 196, + 1840, 7087, 792, -3583, 302, 1012, -5504, 270, + 3354, -4486, -2312, -2522, -2872, -3899, -2261, 5211, + 1417, -3075, -151, -985, -772, -1630, 164, 659, + 1496, -349, -621, -32, -2982, -1720, -3475, -7370, + -1541, 1122, 20474, 1726, 4474, -3228, 7024, 3265, + 522, -2193, -2113, 5388, 1912, 5929, 11768, -1162, + 2600, 4048, 652, 3360, -3215, 376, 10028, 6054, + -3814, -1155, 93, 4512, -3581, -4037, 7484, -1481, + 2797, 2635, -12275, -2780, -6235, 5739, 2687, 376, + 5984, -2547, -8834, 4332, 2752, 1942, 1002, -3312, + 5251, -86, -7794, 918, -2413, 3131, -3316, 2095, + -4569, -15382, -5534, 1290, 5179, 2928, 3034, 2365, + 270, -7476, -3024, 6910, 1355, -6262, -2040, 10490, + 1432, 12284, 1125, -3160, 4518, 973, -2351, -1726, + 1967, 1488, 382, 3559, -3742, -2908, -944, -1662, + 682, 902, -4360, 5026, -4252, -1212, -3269, -6024, + -3788, 9128, -2638, -1625, 315, 3087, -3265, -10441, + -7207, -4078, -3266, -7543, -5223, 5460, 2496, -9258, + -227, 4048, 860, -520, 13616, -3458, 3837, 809, + -104, -4062, -4846, -136, -1631, 13977, -1136, 3380, + 1099, -4022, 1831, 3360, -9034, -52, -516, 10144, + 5074, 4866, 8282, -972, 2496, 2336, 8766, 2881, + 2417, -5588, 3064, 3934, -4202, 627, -986, 1750, + 958, -2348, 5006, -2597, -90, 133, 23271, 2431, + -3984, 1894, -2094, -1816, 5007, -3164, 2526, -1862, + 2651, 1809, 7173, 3410, 154, 14930, 3032, -5314, + 44, 8868, -543, -2158, 5341, 258, -8188, 3772, + 2804, 7544, 8339, -3560, -63, -735, 1300, -4308, + -1085, -4986, 1564, -6744, -2605, -310, 1275, 1166, + -640, 4814, 4373, 3103, -1242, 6049, -4786, 597, + 182, 2371, 6950, -2265, 389, -14669, -1942, -2733, + -485, -865, -597, -1376, 1626, -3956, -1244, 1532, + 3918, -3311, 1574, -88, -20573, -5471, -71, -1731, + 1436, 2428, 3982, -4576, -914, 5460, -4973, 1650, + -2364, -2486, 3212, 5424, -2501, 4595, -937, 728, + -5140, -9948, 1437, 10560, -5704, -264, -2752, 949, + 5229, -1445, 430, 827, 4103, -1999, -4625, -4171, + -8769, -8927, 7161, 4539, 6968, 5975, -4626, -2793, + 10080, -10386, -2479, 1724, 2992, 354, 3650, 3328, + 4490, -1931, 7348, 7283, -3304, 4446, -1698, -1224, + -3002, 4340, 1041, 607, -454, -4261, -18071, -1199, + -3902, 570, 5808, 5582, 6710, 235, -205, -4288, + 3472, -686, -103, -3658, -436, -9680, -190, 275, + -919, 2522, -2087, 9096, 5060, -6450, 10282, 3344, + -8167, -7688, 11881, 3101, -1280, -9942, -11741, 2213, + 712, 3976, -4218, -5285, 2797, 2996, 4006, 2053, + 2344, 6200, 141, 2616, -3981, 6970, -4194, -1621, +-13724, 7772, 2800, 2220, 445, -266, 4030, 444, + -228, 2642, 1617, -2511, 1699, 8740, 3438, -2063, + -2093, 1806, 950, -7112, -1513, -2886, -8789, 870, + 3456, -4126, -3330, 541, -10173, -1789, 3156, 4466, + -5965, 479, 5177, -2806, 2506, -1646, -3609, 1617, + -7373, -3146, -2389, 3601, 7850, 89, -3373, 4670, + -4180, -3186, 3056, -1691, 1314, 9234, -7799, 1323, + -4360, -9866, -1930, 8091, -13452, 8503, 1980, 11247, + 7688, -5953, -4165, -3192, 540, 1631, 131, 2250, + 5330, -146, -8724, -3148, 2834, 1148, -3886, 374, + -1836, -3898, 9649, 1119, 10221, 128, 8868, -7301, + 2601, 1252, 2340, -3789, 4682, 181, 4434, -1740, + 4368, 879, -620, 2046, 1842, 844, -925, -2506, + -3344, -8820, -722, -451, 521, 903, -1286, -3059, + -5308, -4759, -2706, -1429, 2762, 927, -1459, -7274, +-12028, 8838, 3987, 2406, 8626, -3128, 6505, -4322, + -197, -2464, 2738, -46, 161, 13919, 2252, 2059, + 981, 204, 1161, 4910, 683, -4311, 2081, -1932, + 1119, -6067, -5325, 8528, -4704, -5522, -6183, 5744, + -3407, -2021, 2688, -3230, 2490, -976, -500, -7834, + 2064, 3191, 4740, 3686, 1762, 2604, -2442, -5720, + -7550, 457, -3478, -8097, -6510, -9105, 8031, -4895, + 500, -2436, 1483, -4415, -2023, -3768, -2497, -1911, + 789, 566, -969, -4204, 6128, -5076, 2664, -4222, + 6755, 1774, 6881, 64, 1205, -9243, 4782, 4432, + 5193, -2258, -4787, -7433, 1755, -794, 1297, -7535, + 12773, 9124, 806, 2348, -8112, 7874, -4348, -1410, + -350, -2528, 576, 661, 272, 4598, 691, 1913, + -3349, -1881, -1854, -779, -821, 8444, 60, 2570, + -1813, -1354, -4512, -5471, 4728, 3289, 2617, -9326, + -6670, -859, -2713, -9839, 4676, -2657, 3106, -1393, + 10278, -3069, -2253, 1015, 2246, -2227, 16, -388, + 7962, 1493, -3122, -2707, 7982, -6106, -1462, -1665, + -1302, 2347, 3640, -15122, -2211, 417, 6819, 959, + -2876, -6868, 11060, -2329, -302, 1595, -4610, 9514, + 12677, -4614, -2899, -141, -4857, 1447, 6400, -2894, + 1696, -2888, 1889, 3489, 2775, -504, -6597, -5258, + -7256, -379, -1249, -136, 3118, -3537, 3295, -3458, + 2103, -399, 15281, -222, -1809, 172, 2257, 1947, + 707, 3562, -5691, 3575, -2210, 5750, 815, 4059, + -16, 1306, -13308, -1733, -1338, -3477, 5247, -1950, + -5148, -678, 8074, 1740, 290, 2033, 4639, -4240, + -536, -5214, -1366, 2491, 501, -59, -4480, 430, + -285, -5947, -755, -14559, 5696, 6960, 4462, 2317, + 6414, -13174, 4962, -899, 5924, 11100, 5303, -970, + -2528, -6239, 2253, 2236, 553, 458, -2229, 8016, + -7082, 2869, -4209, -4460, -6536, 3557, -1766, 7815, + -655, -6029, -5250, -1627, 2646, -3466, -3584, 901, + 10305, -895, -427, 949, -2776, 3436, 769, -4131, + 9019, -4898, -3562, -7978, -359, 1358, -1528, -3095, + 5840, -6214, 2591, -2086, 9480, 640, 2858, 216, + -3625, 5740, -7008, -1097, -2091, -143, 4832, 6210, + -1358, 3998, -714, 835, -4004, 3664, 1980, 1240, + 2902, 510, -1565, 427, -2052, -4208, -1505, 1187, + -1229, 3732, -932, -1014, 4784, 18474, -5111, 3047, + -54, -1547, -3892, 8612, 274, 1446, -3548, -7689, + -423, 1192, -4508, -10403, -8735, -446, 444, -6353, + 4008, -1462, -8906, -1161, -2395, 2442, 2204, -5472, +-17376, 2471, -689, 1394, -3657, -2119, -769, 2872, + 1393, -2701, -3536, 3650, -378, 859, -3338, 1412, + 3010, -3243, -335, -3619, -511, -1931, -7126, -5018, + -9332, -4440, 1906, -2265, 1386, 8072, -6576, -1300, + 5458, -4894, 630, -7146, 2263, 810, 2968, 1124, + -2219, 2292, -3914, -1836, -6683, 1511, -2755, 1396, + 2425, -23842, 2249, -53, -891, -1678, -1766, -1788, + 502, -4210, 211, 10376, -5507, 837, -6196, 2132, + -472, -10153, 7234, -1456, -148, 4886, 2427, 2371, + 1234, -962, 6298, 1016, 1735, -566, -878, -8071 +}, + +.cb1110s1 = { + 2525, 12164, 4861, 9505, -7371, -414, 3002, 576, + -347, -998, 2861, -804, 3034, 810, -788, -539, + -2092, 4970, 1828, -2869, -2802, 6649, 3673, -193, + -4034, 722, 1642, 3792, 8770, 10428, -3303, -3849, + -4520, -234, -4190, -1219, -1300, -4128, 8384, -1150, + 1578, -6174, -1072, -4871, -8180, -6698, 3806, -7386, + -2545, 1052, -550, -1148, -1308, -8834, -2654, 1982, + 8716, 6579, 1360, -2404, 1893, 2680, 3801, 11097, + 1455, 2453, -7585, -7503, -12710, -420, 2023, -656, + 1124, 2872, 9676, -4309, -202, 1458, -6526, -534, + -1535, 924, 3068, -1142, 5073, 1284, -5632, 869, + -1637, -2898, 4900, -10202, -10488, -1097, 1890, 11006, + -44, 1368, -1979, 6507, 316, 961, 8, -4085, + 2561, -2034, -1077, 2594, -465, -5134, -868, 54, + -6694, 9608, -3516, 7165, 11011, 9542, 4780, -2800, + -1130, -1714, -2684, -369, 4746, -2688, 4146, -7652, + 984, -3263, -276, -9134, -2848, -3983, 9994, 3608, + 3234, -596, 263, 3102, -178, -2264, 3820, -4293, + -5752, -3577, -3914, 1095, -1562, 22110, 4610, 69, + -2999, 254, 2178, -2901, -1203, -1292, 2642, -3254, + -1389, 2955, 1340, 542, 810, 1369, 3208, -795, + -3272, -2717, -1129, 8781, -6854, -3028, -616, 729, + 529, -6946, 1621, 9574, -14909, 5398, 854, -774, + -9978, -5417, -2516, -4683, 5715, -66, 3336, -5040, + 640, -7566, 3494, 7016, -2269, 1376, -13994, 6448, + -3948, -1697, -3988, -6559, 2376, 4231, -3131, 2045, + -2417, -5919, -7016, -1695, 9046, -7966, 5187, -2553, + 1402, -2351, -220, 5931, -1823, -2270, 584, -3784, + 2924, 6166, -3035, 2370, 4923, -1080, 682, -7899, +-10827, -1824, -908, 1568, -3565, 4033, -4266, -1948, + 923, 5488, -203, -2396, -907, 2783, -3278, 1415, + 7710, -190, -5208, -2279, 1266, -1132, -3392, 10251, + -1064, 11283, 2162, 2213, -5088, 4479, -4658, -1803, + 1534, -4233, -4073, 6938, 3966, -4878, -332, 5961, + 9217, 488, 6520, 4430, 7988, 9383, -2586, 1206, + -6983, -873, 1251, 1849, 5945, -2144, -2032, -1852, + 416, 3720, 2419, 8462, 3173, 11524, -2894, -5517, + -211, 17830, 3170, 1098, -721, -2066, -1956, -3097, + -1061, 2815, 447, 701, 449, -485, 2609, 1239, + 2257, -1760, 3091, 7538, 3710, -2689, -3092, 6903, + -2457, 3271, 6355, -1486, -828, 1994, -3575, 3949, + 3185, 2606, -4912, -16039, -8833, 1831, 2580, 1993, + -1117, -3408, -7590, -7278, -141, 2696, 805, 1896, + 308, 378, 9308, 2894, -4324, 1042, 837, 4716, + -4702, 2493, -5173, 8616, -468, -14829, 3759, 3251, + -4237, -1340, 5224, 2099, -764, -8263, -1699, 76, + -1464, 2115, -582, 3286, -3653, 1017, 1696, -1414, + -668, -9748, -5730, 2413, -1270, -6070, 17002, 2164, + -5440, 1801, -2123, 800, 2135, 4801, -887, -2141, + -647, -4846, -463, -577, -1846, -555, -1929, 2046, + 8272, -8399, 3886, -5950, -4202, -12600, -2805, 477, + 65, 6140, 1089, -4737, 8967, 1952, -1968, -3660, + 6641, 850, -3304, -1775, 4010, 10819, 14365, -696, + -1331, -1724, -237, -3611, 244, 3005, 4349, -182, + -4124, 2466, 2746, -61, 3391, -1392, 3788, 1582, + 3723, 7140, -2207, -3678, -2675, -252, -7476, 9426, + -6196, 3226, 3554, -6326, -4284, 6346, -4432, 5199, + -2633, -2499, 1200, -1140, -3910, 6624, 16732, 5946, + -766, 2630, -1200, 1988, 5510, -1199, 4126, 1287, + 454, -1795, 2664, 5001, 1058, 500, -437, 2992, + -2012, -160, 796, -4846, -6572, -10088, 603, 483, + -4510, -12799, 3502, -1784, 3510, -3956, 6038, 9044, + -6029, 7170, -1608, 120, 914, -200, 3939, -6274, + 3020, 6235, -2754, 5368, -1693, -6028, 386, -2006, + 1898, -11704, -9973, -525, -2624, 1799, 4140, 3248, + -57, -3731, 3764, 5582, -3830, -2484, -2066, 1517, + -900, -8250, -8191, 2676, 1147, 6752, 6908, 1196, + -2634, 3408, 2980, -1042, 3971, 632, -4946, -5690, + 133, 2445, -446, -1294, -777, 3356, -5628, -6020, + -8042, 5069, -1421, -2701, -15117, 3074, -912, -2574, + 2643, 5252, -2118, 3849, -3793, -850, 4170, 6240, + -697, 6976, -3752, 1155, 7769, -8912, -7728, 4224, + -2362, -3760, 3688, 2402, -3411, -3165, -2550, -8, + -209, -334, -837, 5688, 3425, -4564, 9999, -4780, + 3093, 4346, -5556, 1636, 1755, -14696, 1810, 6547, + -60, 4054, 10539, 6118, -4414, 1760, 3581, -841, + 4471, -23, 180, 259, -4439, -13230, -1326, 1913, + -621, -1641, -2882, -4934, 516, -3886, -4468, -110, + -4526, -5157, 7550, -4449, 813, -4364, 1768, -8829, + 2003, -1372, 1873, -209, 1539, 1076, -12408, -1464, + -1878, 1563, 2020, 704, 1425, -275, -3718, 4618, + -1120, -5057, -3590, 4022, -1977, 620, 143, -2507, + 3697, -3263, 616, -3002, -3347, 21051, -4398, 364, + -1924, 284, -2724, -2297, 4916, 2702, 4866, 4293, + -2781, 1094, -1525, -562, 5487, -2098, 4658, 1362, + -597, -3426, 3173, -5174, 3922, -3844, 1482, 4711, + 5853, 1490, 5499, -17537, 956, 544, 268, -4782, + -504, -4003, -911, 599, 1746, -7322, 1907, 1990, + 16985, 3171, -2645, 1040, -7239, 5618, 304, 3606, + -3377, 3630, 7319, 108, -496, 1026, 3062, -392, + 2366, 1948, -530, 806, 2700, -2676, -2717, 5238, +-16008, -823, -264, -1560, -1014, -760, -3684, -330, + 5644, -1668, -10239, -2583, 7411, -593, 2193, -1479, + -2892, 3834, -3625, -12234, -1103, 1868, -5121, 3879, + 2748, 1936, 2026, 4572, -6037, 3310, -8678, 11724, + 5290, -2316, 4131, 834, -3915, 869, -1734, -5752, + 1255, 9534, -3625, -115, -5912, -125, 2298, -1494, + 5910, -496, -2719, 1320, 3175, -3012, -3906, 4602, + -4760, -5918, -2568, 6632, -8802, -5876, 6358, 2349, + 207, 5191, 8369, -5932, 2710, 7950, 3673, -2592, + 1311, 8384, -4360, 8614, -5662, 1180, 2147, 1044, + 1591, -5555, -1597, 4418, 38, -1579, 4675, -1725, + -1693, -6470, 3066, -7601, -12822, 524, -2986, -3406, + 8860, -1266, -930, 4316, 1171, -2908, 199, -1785, + -2851, -3588, 3072, -3585, -2668, -1123, 1508, 460, + 6780, -19480, 2854, -1574, 1004, 5074, 1907, -1988, + 1177, 74, -1436, 2224, 1232, -3008, -3454, -862, + 604, -653, 2778, 2349, 3242, 8426, -430, 3684, + 4814, -1886, 5118, 1487, 442, -2322, -900, -2854, + -234, -10350, -7922, -745, -1490, -5638, -6014, -4079, + -2979, -351, 9493, -2274, -11362, -8166, -7364, 8261, + 1554, -1722, 4651, -831, 2276, 1502, 2600, 1266, + 4456, -4145, -3837, -3584, 4242, 4058, -2395, -6971, + 4486, 3233, 6226, 1306, -11506, -6223, -5132, 1537, + -4407, 1510, 5732, 2808, 5817, -4972, -2900, 897, + -2441, -1819, 5651, -6988, -10063, -2288, -5820, -1250, + 925, 3120, 6125, -9901, -137, 3684, -6601, 1077, + 3272, 21, 3341, -838, -3643, -1727, -4417, 660, + -6551, -184, -8125, -1780, 5232, 6077, -7968, 6423, + 3823, 3026, 4555, 464, 3318, -5504, 837, -3571, + 3853, -2277, -1864, -742, -5380, 6096, 6856, 1076, + 877, -642, 1926, -4712, -14482, -3323, -2672, 7485, + -2116, -3932, 2233, -3270, 326, 2221, 132, -1893, + -748, 453, 3597, -2308, -4371, 5632, 3609, -1033, + -444, -2591, 17359, -3120, -2604, 3157, -370, 9242, + -1606, 2675, -853, 1475, -416, -3280, -1159, 191, + -3670, 282, 4282, -957, -2978, 3564, 91, -20520, + -3046, 1248, 1277, 3368, 1118, 311, -598, 1406, + -2377, -1444, 1417, -3626, 167, -6440, 3341, 629, + -2523, 4398, -1187, 4322, -383, 1934, -3298, -8530, + 2195, 5220, 510, -1256, -6932, -1061, 5141, -16242, + -1390, -546, -3760, -2029, -929, -6044, -3503, 312, + 8478, 701, 8865, 4715, 1987, 1342, 1400, -71, + -5229, -1547, -8827, 2349, 12836, -1479, 4621, 6003, + -6749, -3184, -5667, -2930, -1074, 3204, 330, 4692, + 2872, -10808, 75, -1260, 18003, 4100, -1462, 1391, + -1667, -2039, -687, -4806, 5913, 2682, 7730, 7034, + 2703, 1666, 120, 1601, 2123, 1402, -4702, -11229, + 7875, -5591, 4634, -2274, 3015, -597, -7520, -1095, + -4814, -173, 5562, 1533, 2807, 8466, 5195, 7806, + 2585, -2877, 6938, -3942, 402, -3825, 4162, 9149, + -6423, 2447, 7041, 2932, -9813, 2124, -58, -3, +-12856, -7973, 1484, 907, 180, 8042, -2124, 4356, + -4117, 1126, -9706, -2101, 3957, -1877, 1139, 7148, + 3707, -1341, 4509, -1220, 4570, -1650, -6504, 7036, +-10268, -328, 4678, -12205, 5062, 6089, -496, -7740, + 2207, 4489, -205, 1386, -2695, -1442, 4730, 892, + 12061, 3818, -3305, 4431, 9300, 3470, 4608, 4315, + 892, 866, -1714, 1529, 2569, -11398, -3068, -282, + 1626, 587, -1568, -1630, -220, -2033, 7141, -2732, + -3541, 3404, 15514, 1883, -2697, -926, 5972, 6485, + -6794, 2111, 2490, 1201, 5467, -2352, 3264, -97, + 2400, -728, -3364, 3417, 1481, 2862, 462, 2855, + -5233, 5740, 7208, -10508, -3254, 1450, -1270, -293, + 3400, -6978, 10035, -1213, 4308, 2641, 8579, 8518, + -2919, -351, -459, -2069, -617, 638, -1347, 107, + 6009, 2035, -280, 2009, 3280, -1236, -14960, -5177, + -2440, 965, -2646, -2095, 5274, 1825, 3705, 3831, + -446, -4018, 7178, -2415, 4344, 1850, -509, -500, + 1056, -4374, 5709, 1336, 3352, 7915, -2302, 12209, +-14362, 6429, 1423, 2912, 6474, -1599, 1116, 2280, + -1738, 3108, -5792, -3554, 623, -1110, -6114, 4488, + 8941, -3176, 13670, -3320, -327, -2657, -7349, 3782, + -1481, 5737, -200, 2968, -9474, 5752, 5056, 4688, + -5352, -432, -906, -3832, -8519, -7, 3667, 3583, + 6250, 8724, 10737, 9371, 950, -1630, -10740, 5788, + 4111, -2910, 437, -2482, 1910, 185, -2168, -3155, + -3515, -1754, 4978, 4298, -6921, 476, -2778, 546 +}, + +.cb1110m0 = { + 3666, -1078, -175, 1370, 2491, -10050, -685, -7617, + 4002, 11104, 903, 5948, 2821, 3050, -2465, 1151, + -848, -2139, 12321, -1408, -1469, 2046, -2693, 2479, + -3498, 3077, -3822, 1841, -2404, -11172, -407, -3062, + -1725, -5475, 597, 1924, -197, 434, -1648, 2678, + -2462, 1148, 599, 1284, -13171, -949, -6508, 754, + 7466, 5924, 1411, -536, 10825, 588, 297, -310, + -593, -896, 784, -242, 716, 501, -52, 4043, + -755, -690, 2630, 17762, -2159, 2126, 954, -1316, + 11129, 1570, 387, -2639, 13953, -311, 5231, -2297, + -3612, -678, -1117, 690, -279, 2403, -1541, 493, + -1692, -2048, -771, -933, 423, 700, 840, 739, + 1956, -944, 612, -2678, 101, 245, -786, 850, + 269, 1355, 21773, 463, -2589, 596, -519, 788, + -43, 1220, 10674, 4847, 1192, 335, 875, -106, + 10644, 2600, 5391, -262, 2296, -5928, -1072, -122, + 2504, 1313, 1117, -981, 350, 375, -810, 8, + 1462, -2020, -2368, 8, 22663, 1537, 87, 908, + 832, -4884, 312, 620, 1042, -4444, 660, 1582, + -2710, -2954, 10012, -9580, 8102, 5696, -1371, -3035, + -3347, 402, 218, 1096, -1924, 88, -2270, 4175, + -1083, -497, -2437, -3332, -824, 212, -2362, 4600, + -7800, -11501, 7795, 236, -1336, -12920, 705, 4532, + -1488, 11746, -3213, -2650, 2524, -2638, -128, -328, + 3402, 453, -242, -2500, 2224, 708, 450, -3014, + -132, 1251, -131, -831, -710, -21985, 222, -2132, + -3261, 490, -3020, -860, 2550, 892, -623, -3666, + -664, -131, 2018, 2817, -12005, 496, -610, -7238, + -3909, -2867, 6872, 1903, 848, 6644, 3812, -5686, + -4055, -377, -2096, -10247, -1068, 1486, 415, -253, + -2186, 1050, 771, -6856, 1044, 7466, 2953, -7514, + 1601, 7015, -1778, -1622, -3364, -1755, 2835, 176, + 2700, 991, 2560, -554, 4867, 1571, -5610, 2610, + 12438, -3751, -9964, -2753, 4856, -2595, -5423, 10025, + 812, 687, 2715, 4013, 3086, -12039, 328, -3992, + 4044, -3920, -111, -553, -1720, 2454, 1706, -1365, + 804, -32329, -471, 897, -4670, 780, -3680, -1409, + -2630, 20, 184, -157, -290, 2794, -546, -160, + 1564, 1146, 628, -4787, -239, 11233, -492, 1955, + 608, 9273, -3220, 3830, 390, -5982, -3342, -3384, + 2356, 1820, -3473, 979, -40, -20190, 47, -200, + 5106, -381, 1824, -197, 2280, 2434, -2633, -1409, + -1109, -1072, 857, 1554, 7459, 6, 12130, -1078, + 1038, -300, -13748, 3201, -762, 2670, -1051, -445, + 914, -172, -558, 2634, -1158, 3129, -74, -3415, + 1086, -8892, 118, -647, 285, 186, 3022, -5077, + 1342, 3453, -7991, -65, 4690, 944, 3717, -1909, + -9783, -367, -1699, -772, -32768, 1286, -408, 340, + -340, 430, 1274, 596, -109, -727, 276, -946, + 139, 1804, -1050, -3562, -1392, -1179, 257, 1639, + 25708, 2278, 2415, 2174, 153, 126, -60, 592, + 994, -334, -268, 1826, -306, -2241, 2774, -3188, + 758, -450, 8023, 542, 6819, -1712, 14195, -2198, + 281, -12, -590, -1153, 4568, -3676, 1973, -5221, + -1839, -603, 3324, 2492, -3070, -846, 123, -1184, + 667, -10886, -65, -2615, 971, 10219, -1245, 7378, + -2122, -2306, 571, -2298, 1958, -4356, -9210, 4321, + 2805, 1888, 11129, 1282, -5819, -2528, -873, 1123, + -5968, -2644, -5515, -2151, -944, -7712, -2007, -2260, + -1920, 2100, -325, 153, 1050, 10, 1462, 650, +-12559, 3530, 754, 4493, 1528, -6991, -4842, 1483, + -2408, 2785, -1651, -830, 1433, -2464, 18899, -1891, + -3137, 996, 2485, 3056, -1061, -4015, -2282, 1356, + -2572, -490, 1209, 1137, 4, -636, -1282, 1001, + -1190, -172, -14049, -4256, -1972, 2225, -4738, -1054, + 5254, 8113, 4294, 36, 11765, -3993, -1084, 3864, + -3016, -10356, 353, 2963, -1228, 536, 609, -343, + 1246, 3617, -3667, 4794, -20360, 473, 725, -1246, + -1649, 1900, -2589, -2869, -2550, -886, -1164, -1876, + 307, 3784, -4782, -476, -700, 2118, -1860, 1533, + -5013, 2356, 3305, 3338, -14312, -1278, -322, 1950, + -954, -1990, 1438, 3358, 7479, 3046, -6677, -3078, + 1717, 3113, -12484, -1302, -221, -510, 10423, -3497, + 4170, -3606, 6983, -2902, 458, 667, 566, 2415, + -403, -2898, -44, -1832, -110, 1799, 1172, 7, + -1534, 90, 686, -26902, 1601, -822, 658, 182, + -151, 345, 1488, 1416, -272, 1560, 9774, 2084, + 16, -14344, 1428, 514, 2658, -1312, 2095, 454, + -1783, -2056, 4529, 1154, -2239, 956, 668, -1396, + -2898, 405, -12659, -12556, -650, -587, 3461, -2470, + 0, -3156, 3186, -4104, 1729, 1438, -1842, -422, + 4476, 1945, -932, -1439, -702, -1398, 3349, 1876, + -999, -2086, -17879, -432, 4036, -2299, 1133, 88, + -2221, -2730, -938, -998, -132, -426, 2084, 2060, + -1134, -313, 402, -538, -2593, 2022, 725, 1566, + -2070, 21622, 1767, -424, -32672, 205, -1239, -3253, + 198, -1257, 2342, -1918, 1505, 452, 1348, -604, + 978, 1079, -4, 2476, -1247, -146, -861, -1928, +-12222, -13042, -1384, -1971, -1428, 1224, -639, -83, + 1034, 3488, -2310, -565, 74, -335, 2774, 602, + 872, -2132, -147, 2160, 244, 162, 12600, 628, +-10194, -1296, 1068, -1824, -4945, 3194, 2066, -895, + -784, 2347, -1982, 73, 1030, 12589, -62, -2272, + 3827, -1776, 2546, -1417, 3310, 4726, -3078, -548, + -8522, 1632, -6667, 1008, 1128, 805, 954, 616, + 499, -31526, -1327, 790, -190, 1058, -1157, 1432, + -16, 411, -3180, 827, 327, 914, 1716, 1442, + 1052, -1635, -1805, -4145, -13678, 3597, -2273, -5920, + 3592, 1136, -211, 717, 3901, -5132, 3036, -601, + 12976, 1633, 10316, -1674, -468, 905, 2331, 841, + -247, -6053, -593, -3281, 4291, 5159, -1053, -1814, + 2613, 2221, 1146, 871, -421, -542, 923, -3567, + -1138, 10051, 10860, -6121, -661, -5677, -890, -266, + 2100, 6223, -70, -2658, -78, 3424, 714, 2138, + -1355, -981, 1990, 772, 938, 1311, -1963, 924, +-22516, 260, -341, 1251, -1578, 23, 1375, 1068, + 2688, -3965, 713, -5342, -257, 37, -6034, -276, + 228, -1240, -7171, -3402, -14677, 1708, -317, -2880, + 874, 1466, 524, 2091, 565, -4220, -265, 52, + -3373, -220, -3175, 2646, 448, -1628, -1986, 2200, + 3722, -15752, 7120, -2036, -2170, -627, -1079, -4060, + 2257, -925, -3418, -13488, -1308, 3476, -783, -3924, + -820, -860, 2418, 2982, -8753, 9001, 294, -11915, + -969, 3329, -761, 1459, -5308, 1811, 379, 306, + 632, -2732, 2512, 1188, -3470, -2167, -572, -2274, + -1657, 24074, -159, -138, -1826, -2527, -3117, -906, + -1770, -1182, 1240, -3064, 2313, -790, 336, -3843, +-13384, -423, 13066, -14, -1908, -32, 2607, 487, + -2426, 195, 135, 2742, 1540, -1034, 856, -2288, + -287, -774, 497, 1760, 191, 178, 298, 38, +-30898, 801, -1456, 2311, 1272, -1845, 334, -933, + 183, -1614, 739, 1881, -13548, -13589, 1496, -2075, + -1281, -1510, 108, 3683, -1120, 752, -980, -277, + -1289, 2016, -290, 1838, -321, -139, -881, -12391, +-14713, 1906, 990, -3202, 2320, 749, 1872, -2545, + -1457, -1727, 734, -327, -316, 1062, -3149, -2959, + 2210, 912, 952, 1926, -8918, 1098, 594, -1439, + -1402, 11097, 3482, -472, 219, -3845, -662, 9715, + 3928, 1254, -2009, 12375, -1724, 13938, 1892, -1390, + 686, 2174, 1010, -1297, -199, 1855, 463, 2601, + 4408, 1978, 1679, -1614, -3, -11965, 16220, 828, + 1497, -747, -484, 519, -1804, -3814, 3287, 2104, + 1149, 478, -3918, 1504, 2376, -316, -520, -1449, + -3918, 664, 2772, -16434, 334, -540, -778, -2812, + -6026, -4392, -2446, 3479, 3742, -624, 3895, 1145, + -344, 333, 11898, -2725, 12873, -1145, -1807, -279, + -452, -1581, 548, -5180, -2012, 3411, 1188, -1407, + -4016, -468, 1904, -1724, -11390, -30, 14402, 1610, + -2138, 1249, 346, 6097, -1433, -655, -174, 3652, + 4010, 954, -1458, -354, -1872, -2689, 880, -846, + -1304, -1725, 1750, -1186, 1520, 499, -583, 18201, + -1083, -3323, 3072, -5440, -182, 1065, -1112, -984, + 2501, -529, 613, 2054, 460, -5245, 2827, -1445, + -2403, -12898, 1504, -8428, -1035, -4620, 1704, -2586 +}, + +.cb1110m1 = { + 1442, 12425, -2072, 741, -3624, 12979, 2031, -364, + 3750, -5082, -1968, 146, 670, -3988, -831, 3962, + 397, 6213, -1178, 816, -88, -432, -9620, 11572, + 194, 289, -1958, -2115, -871, 5372, -3145, 3612, + 1644, 826, 525, -2545, -514, -537, 2485, -1014, + 1276, 541, -936, -302, -1172, 183, 827, 23939, + 1120, -346, -313, 2759, 3934, -3082, -2260, -906, + -967, 1496, 102, -2782, 323, -1109, -37, 2554, + -2920, 998, -930, -1952, -1138, 1842, -1593, 17345, + -1214, -1065, 2182, -1169, 11745, 278, 8310, 1491, + -564, 1169, 8406, 1359, -1249, -2094, -1365, 4069, + 1828, 897, 1258, 1083, 4319, 610, 766, 2273, + 4057, 621, 338, 1317, -20941, 548, -2012, 563, + 1102, -27, 3007, 1129, -1068, 1282, -2939, 2983, + 1958, 1800, 1912, 1728, -606, 1804, -4768, 5068, + -1365, 4543, 399, -14152, -6206, 6187, -2205, 1174, + -1892, -3284, -206, 2872, -2622, -43, 11268, -104, + 292, -1836, -6276, 725, 2066, -604, 11382, -448, + 742, 2854, -910, -838, -1802, 3678, -397, -530, +-10647, 2356, 12161, 1506, 2649, -3335, 3128, 2169, + 5942, 2152, 14124, 428, 187, 248, 1592, -44, + -59, -2934, 1883, -923, 2673, -847, 150, -2142, + -7620, 11078, -595, 6490, -13673, 948, 219, -1314, + -3080, 1339, 11020, 1362, 247, -1863, 1069, -3786, + 1706, 1064, 320, 4535, 136, 3795, 1465, -1356, + -449, 13, -421, 1769, 20470, 2181, -371, 2444, + -744, 2263, -155, -688, -236, -4481, 1551, 2812, + 2476, -1436, -470, -272, 2276, 594, -858, -978, + 1122, 2468, -9350, -353, -1020, 494, 13167, 1770, + 1734, -70, -4630, 12358, -818, -979, -3931, 1000, + -4343, 2570, 5567, 3322, 2930, -236, -4796, 6987, + -1658, 4291, 1118, 1710, -2050, -13566, -2, -23, + 2104, 1101, -316, 1906, 1643, 340, 5940, 3180, + -837, 1978, -10514, 1466, -6936, 3600, 1205, 957, + -211, -8272, 1611, 5330, -5217, -2264, -5681, -3085, + -9201, -62, 3366, 1370, -9494, 244, -5516, 1210, + 2930, -432, -1265, 376, -1910, -1016, -845, 3228, + 1094, -3168, 634, -265, -3426, 4367, -4004, -277, +-15081, 3998, 9671, 3418, 691, 9124, -2723, 1939, + 2311, 581, -4980, 3381, -1502, 878, -1037, 1496, + 3002, 904, -5388, -3300, 263, 1277, -694, 766, + 1781, 1134, 250, -32602, -285, 210, 2550, -383, + 908, 302, 292, -352, 2615, -97, -1863, 1908, + 2685, -502, -3767, 416, 990, -602, -1533, 43, + 1288, 1326, 16638, 433, -1204, 1850, -1609, 1407, + -7196, 2319, 5770, 1584, 1150, -634, -1686, 1359, + -1396, 438, 246, 186, -11262, -1194, -3790, -3267, + 2692, 755, 142, 16276, -2338, -1341, 10433, 38, + -1510, -2520, -3205, 913, 3783, -1622, -4744, 1891, + 2502, -8, -2962, 2091, 14986, 1270, 2931, 682, + 1073, -10215, 1606, -1010, -822, 1168, -1403, 254, + 1156, 3206, 3958, 1739, -402, -654, -4862, -1869, + 2643, -2858, 658, -910, -2548, 5428, -1992, -208, + 1950, -15526, 520, -4212, 3182, 4160, 1524, -2916, + 586, 3213, 675, 185, -629, 669, -838, 502, + -4065, 353, -4072, -1832, -2108, 5034, 2484, 15386, + -2102, 4988, 70, 1011, 2568, 1360, -2821, 3352, +-11074, -2686, 611, 460, 1811, 3093, 34, -9140, + -1163, 26, -875, 2510, 1134, -1322, 2274, -960, + -823, -510, 1092, 1490, 1466, -1978, 32767, -2379, + -1019, -633, -1306, -242, 2050, 1336, -2668, -2195, + -442, 8, 2292, 4344, -2439, -1472, 1035, -14443, + -1820, 6309, -2096, 45, 3617, 1561, 1252, 2828, + 10682, -894, 10841, 2373, -101, 913, 2160, 2653, + 2960, -4433, 1193, 4892, -2123, -7911, 991, -2643, + -1364, -3641, -9736, 444, 869, 2990, 926, -1220, + -1676, 7492, 4376, -3742, -6964, 4531, 7522, -2686, + 164, 1070, -7305, 1863, 542, 146, -800, 18492, + -4849, -3876, 2162, 5111, 2606, 4243, -3035, -2990, + -1710, -426, -5315, -2332, -1020, -268, -1242, -39, + -1684, -32768, 1288, -726, -1768, 304, 702, -2969, + -700, 586, 1541, -1099, -348, -2816, -2181, -1260, + -1658, 2278, 323, -1548, 2513, 11816, -2416, -5837, + -118, 6770, 3360, -4097, -264, -1270, 1064, -9862, + -3669, -56, 603, -1475, 1464, -9553, 6, -3091, + 5331, -396, 892, -2774, -4674, 3667, -9982, -5160, + -1146, -4026, -2032, 2936, 1805, -1026, 1065, -420, + -572, 1756, -479, -583, 30760, -732, 750, 270, + -1541, 28, -1114, -96, -264, 1167, 548, 570, + 84, -1981, -2110, -1136, 358, -6337, -257, -14658, + 1144, -9032, 322, -3730, -3086, -1351, -3320, -4116, + -396, -129, -3202, 1403, -347, 2400, -371, 532, + 1555, -2760, 1078, 804, -1314, 21956, 2231, -2808, + -1947, 838, 12428, -14514, -384, -1554, -675, -885, + 1358, 1612, -3266, -98, 1876, -447, 2241, 3375, + -1765, 2792, 674, -1513, -1132, -3696, 11368, -1916, + -2778, -466, -377, 2090, 3897, 5422, -2550, 2360, + 3279, 8657, 990, -2128, 2592, -970, -2397, -269, + 22742, 694, 310, -2433, 920, -690, 1478, 1370, + -450, 445, -1379, -1244, 2374, 1400, -1040, -5692, + -1700, -1630, -4068, -1193, -719, -2953, -3562, 264, +-13247, -4629, 5, 3245, -5724, 2449, 3190, -5375, + -3560, -3834, 1271, 1568, -762, 2938, 782, -1390, + 243, -466, 1376, 974, -1646, -1784, 249, -514, +-13543, 1904, 10778, -772, -155, 7838, -30, 3634, + -473, -9100, -112, -3990, -840, 1495, -2346, -326, + 3655, 1292, -292, -10972, 3431, -262, 171, -9775, + -985, 578, 312, -2553, 3375, -8316, 1410, -1326, + 2459, -3116, 1079, 7194, 2720, 1998, 2742, 4672, + -1589, -8932, -124, -652, -72, 2409, -926, -3661, + -3762, 14832, -1350, -2234, 1258, -1604, 169, 103, + 1263, -400, -765, 144, 824, 855, -13344, -1629, + 1977, 2995, -1964, -650, -219, -11607, -6062, -792, + -1243, -1438, 1757, 1436, -3739, 812, -856, -9603, + -2428, -11372, 3273, -2318, -8263, 1551, -2054, -3646, + 3149, 2255, 594, -412, -3030, 1558, 694, -1211, + 618, 3256, 6526, -1572, -9054, 6655, -3208, 3616, + 2162, 3137, 4254, 4610, -10040, 1188, 335, -615, + 640, -1990, -314, 6014, -2392, -2174, 343, 6730, + -1320, 183, -97, -3566, 2988, -13343, -1573, -9070, + 428, 2839, 6728, -1109, -1113, -1102, 5012, 1308, + -3943, 3207, 764, -2928, 1144, -3044, 4033, 1846, + 6460, -4165, 8509, 9824, 15708, -642, 748, 124, + -406, 13033, 807, -299, 1319, 1499, -1206, -1102, + -3129, 3795, 47, -2483, -2470, 2287, 4028, 1656, + -364, -1712, -1568, -3940, -2770, -13688, 796, 3380, + 363, 1673, 1160, -3934, 2884, -5060, 832, 4799, + 364, -3030, -10596, -1805, -3256, -2492, -1831, 1088, + 11108, 3236, 5128, 3052, 4486, 84, 2078, 200, + -4071, 1713, 1539, 24597, -1019, 32, -48, 82, + 81, 1171, -1261, -1783, -1693, 2194, 1714, -225, + -1989, 402, 2611, -708, -15901, 222, -507, 12855, + 1162, -1536, -2884, 1911, -1256, -926, -1875, -1448, + -2730, 3059, -1231, 1680, 1824, 1288, -215, -9, + 40, -957, 27662, -1844, -1927, -846, -1144, -439, + -3507, -2844, -1880, 637, 1042, 237, 1007, -387, +-11913, -2584, -142, 624, -494, 1439, 2225, -13017, + -1901, -1253, -1071, -7083, -2154, 814, 3867, 1130, + -2611, -2260, 1548, -12389, -1018, 102, 1178, 1058, +-14863, 2020, 4094, -1259, -861, -886, -3119, 2638, + 1725, -1364, -2086, 183, 507, -978, -3086, -14966, + 759, -1341, -70, 8538, 2974, -140, 2509, -4460, + 2724, -1372, 491, -6138, -345, -2170, -1187, -330, +-11090, 15657, -300, 2105, 496, -2093, -447, 2000, + 3451, 1482, 758, 4142, 562, -4042, 1491, 3183, + 1685, -2729, 1611, 11698, 14918, 25, 842, -2766, + -667, -1564, -2619, 646, 1391, 862, -909, -2141, + -589, 1468, -755, 1324, -765, 634, 195, -19622, + -1006, -1161, 2434, -1808, 4168, 4108, -2580, -635, + -2533, -2170, -3701, -1047, -363, 769, 5064, -8, + -654, 2346, 752, 13736, -4056, 7, 5492, 7326, + -4894, -3860, 3325, -3947, 4721, 5557, -3699, 194, +-12957, 1052, -1317, -2642, -2931, 1050, -3951, 2392, + -9683, 2519, 2880, -3700, -1820, 831, 4370, -1177 +}, + +.cb1616l0 = { + -185, -20290, 476, -272, 31, -638, 806, -61, + 220, 176, 178, -788, -441, -333, -360, -263, + -116, -512, 9794, -727, 8904, 1192, -277, 756, + -670, 795, -311, 240, -617, -675, -970, 756, + 857, 529, -166, 674, 890, -522, 837, 79, + -618, -1308, -13832, 744, 5422, 2688, 531, 398, + 1500, -1965, -209, -346, 613, 2147, 10053, -1398, + 189, -108, 471, -1202, 999, 178, 762, -601, + 1116, 9468, -281, 763, -1204, -822, -20, -160, + -806, 14720, -269, 143, -1362, -532, -788, -1532, + -405, 85, -271, -4959, 276, -34, -28, -66, + 112, -188, -582, -678, 128, 680, 982, 596, + 12154, -10468, -167, -380, 734, -296, 282, -223, + -86, -342, -812, 514, 387, -418, -364, -1216, + 14, 373, 357, 10897, 11235, -714, 206, -618, + -607, 596, 190, 726, 496, -300, 95, 1022, + -153, 212, -540, 252, 281, 238, -234, 28, + 24, 184, 32767, -627, 569, 323, 486, 544, + -348, -589, -284, 238, 228, 475, 83, -7753, + 182, 745, 400, -633, -207, 137, 382, 90, + 78, 715, 448, 463, 937, 10203, -12047, -667, + -370, -1516, -360, 94, 832, 1027, 1013, 92, + -5446, 834, 302, 764, -94, -462, 8095, 1057, + 308, -635, 308, -877, -946, -616, 51, 1090, +-13351, 490, -819, 15182, -384, 411, -546, -242, + 460, -323, 76, 277, 1582, 900, -1119, 345, + 1316, 1138, 2020, 1612, -148, 812, 1241, -10350, + -9495, -965, -69, 1967, -168, -128, 1042, 447, + 491, -133, -5083, -450, -164, 50, 326, 269, + -283, 226, -40, -334, -110, 60, -47, 169, + 9166, 1188, -942, -14, 2112, -230, 634, -741, + -214, -336, -606, 3102, 59, 216, 1805, -1176, + 211, -8, 564, 156, -261, 300, 597, -21842, + 66, -232, -506, -1126, 1057, 603, 1448, -391, + 249, -9445, -10240, 694, 167, -1158, -645, -385, + -209, 330, 519, -345, -600, 192, 78, -229, + 208, -9053, -383, 10646, -264, 84, 295, -148, + 87, 1292, 257, 1080, -564, -2395, -1200, -484, + -48, -513, -383, -11, -516, -17356, -1172, -218, + 124, -327, 31, 328, -80, 231, 58, -951, + 560, -501, -392, 30528, -56, 382, -515, -50, + -155, 338, 0, -414, -899, 95, 11, 378, + -350, 459, 673, 76, 86, 379, 32222, 143, + -48, 425, -394, -60, -348, 450, -489, 220, + 56, 1129, -125, 322, 168, -16, 322, -293, + 294, -38, 328, 141, 692, -82, -160, -32768, + -140, -1543, 1079, 1052, -924, -569, 168, -1782, + 815, 706, -1318, -3436, 2860, 10922, 236, 10311, + 882, -1911, 11, 1638, -189, 245, -858, 11060, + -826, 696, 224, 1707, 1766, 472, 10832, -265, + -161, 163, 478, -258, -284, -86, 496, 425, + -71, -10344, -141, 425, -1457, 1145, -63, -713, + -583, -327, 628, 368, -18, -1746, -525, -338, + -110, -359, 92, -233, -21328, 460, -275, -98, + -58, 51, 208, 56, -1145, -51, -242, 65, + 76, 214, 141, 28, -86, 26, 925, 193, + 9980, -326, 11342, 176, -534, -303, 130, -1575, + 189, -496, -699, 381, 411, 644, 229, -147, + 694, -1998, 523, -1576, 8028, -10385, -1924, 1174, + 608, 2402, 575, -1753, 437, -816, 1267, 147, + 1448, -614, 865, 1076, -156, 5000, 2020, 2021, + 10283, -460, -2381, -3226, -3991, 4904, -284, 105, + -268, 1049, 203, -646, 732, 6490, -128, 932, + 10, -866, 74, -64, 834, 204, 159, -162, + -170, -110, -28908, 52, -512, -72, 327, 615, + 534, -484, 131, -262, 31, -407, 284, 33, + 11118, -170, 318, 12848, -1126, -659, 500, 310, + -403, -234, 237, -544, 1232, -243, -1178, -965, + -117, 108, -1304, 11728, -2254, 1231, -1077, -136, + -632, -103, -256, -1644, -300, 1680, -1175, -956, + -43, 1718, 175, 144, 275, -802, -223, 1116, + 321, -871, -1174, -1175, 1008, 255, 31172, 28, + -621, -222, -12473, -10995, -712, 247, 1762, 418, + -181, 90, 92, -406, -435, -105, -596, 2262, + -116, -1574, -3402, 6796, 7944, 973, -2661, 2260, + 621, -6984, 382, -1375, -2604, 1550, -1453, 1133, + 966, 403, 284, -72, -36, 174, 457, -90, + 38, -437, -476, -370, 469, 32767, -267, 350, + 694, -169, -782, 2110, -620, -782, -669, -6478, + 10550, -3294, 485, 177, 553, -3232, 1628, 2335, + -870, -360, -1112, 2197, -474, -5113, 3346, 878, + 566, -3823, -1175, 357, 10509, 1077, -514, 1012, + 38, 59, 669, 654, 349, -1046, 355, 192, + 57, 95, 11869, -702, 10201, 204, 45, -608, + -444, 921, -1070, -316, 1286, -2566, 2026, -127, + -79, -954, 93, -1288, -10024, 693, 8820, -366, + -84, -6378, 1682, -627, 386, 254, 503, -152, + -336, 38, -341, 373, -85, 1088, -1707, 119, + -242, 242, -326, -162, 109, 70, -114, -831, + -279, -32768, 62, 58, 214, 136, 194, -103, +-10047, -610, 91, -310, 12059, 346, -656, 986, + 478, 364, 1777, -173, -663, -103, 1011, -373, + 200, 1632, -13098, 3651, 418, 478, 68, -217, + 169, 78, -1176, -1191, -1664, -328, 152, -1053, + 547, 527, -10435, -176, 11131, -137, -36, 1062, + 33, 71, -730, 2080, 2061, -372, -637, -84, + 744, 109, -357, 550, 309, -239, -134, 135, +-20461, -177, -690, -488, -36, -415, 275, 64, + 378, 11250, -802, -569, -200, 1499, 13103, -1090, + -175, 189, -162, -751, 1052, -949, -98, 1249, + 479, -1304, 3293, 771, 1642, -381, 1423, 2258, + 1184, 4806, -10950, -3873, 348, -815, -5315, -3306, + -3307, 2337, 776, -125, -48, -435, -155, -30, + 294, 116, 96, -47, 1022, -391, -183, 252, + 826, -32, 293, -1369, 18310, -146, 239, -266, + 34, -154, -704, -498, -135, 228, -563, -210, + -158, -514, -201, -571, -341, -428, 74, -152, + 297, -162, -644, -216, -252, -13810, 705, 464, + 21097, 74, -169, 792, 12, 131, 320, -398, + -446, 44, -362, 388, -22, -13, -209, 1205, + 9341, 590, -683, -351, 177, -1618, 495, 14, + -319, 755, 11352, 249, -989, 1574, -922, -364, + 366, -10348, 337, -558, -124, 12056, 102, 802, + -548, -254, 1532, 7, -282, -459, -839, 171, + -4445, -1610, -1515, -37, 970, 306, -881, -238, + -154, -58, 27, 435, 166, 571, 225, -844, + -9967, -192, -874, -459, -1283, -1431, 1552, -38, + -686, -207, 709, 11982, -383, 1922, -92, -60, + 708, -900, 867, 39, 1470, 517, -182, -456, + 90, 1026, -192, 9988, 942, 48, 789, 981, + 74, -692, -1283, 1239, 1625, -1121, -286, -1115, + 294, 13228, 980, 312, -745, 11711, 1055, 1052, + -907, 201, 688, 364, 1171, 96, -591, -981, + -246, 875, -352, 677, 881, -397, 12890, 10, + 0, 412, 76, 464, 275, -721, -28, -197, + 104, -238, -372, -272, 490, 1426, 963, -13232, + -1190, 790, 161, -321, 1138, 646, 359, -183, + -659, -129, 348, -22703, 1016, -147, 26, -80 +}, + +.cb1616l1 = { + 292, 310, -255, 305, 69, 25001, -16, -668, + 210, 17, -12, 45, -758, -76, -544, -882, + 61, 26, -1682, -8820, 154, -11775, 64, 472, + -464, 245, 478, -1560, 869, 2192, 98, 645, + -95, -9369, -594, -635, -11132, 900, 1606, -904, + 841, 2570, -1464, 961, 1056, 669, 461, 3307, + -157, -644, 121, -694, 170, 116, 393, 1507, + -233, -654, -162, 108, 98, 17471, 347, -11344, + -701, -284, -246, -337, -1903, 14, 9865, 453, +-11318, -3662, 2373, 1106, -1424, -1709, -2743, -860, + 11008, 1579, -38, -1381, 467, -487, -1306, 369, + 426, -424, 128, 1078, 1085, 683, 12552, 792, + -184, -278, 186, 2006, 363, 310, -75, 862, + 377, 490, -256, -1568, -124, -10785, -1456, -524, + -1259, 517, -1844, 914, 769, 945, 739, -1053, + -691, 177, 96, -1070, -162, -707, -594, -9885, + 103, 452, -734, -6774, -753, 192, 88, -292, + 201, -532, 231, -281, -691, -1232, -1768, -753, + 369, 1556, -139, 668, 941, 264, 10372, 9740, + 976, 2519, -88, 941, 446, -130, 2131, -631, + 325, 285, 176, -236, -634, -91, 112, 32767, + -233, -726, 156, 881, -217, -497, -236, -1106, + 283, 164, -328, -629, -27442, -17, 176, -338, + -192, 538, -773, 634, -180, 872, -190, -530, + 586, 6994, 3060, -336, 736, -1268, -1142, -69, + -1359, -1047, -975, -86, 12489, 1162, -509, -478, + 717, -514, -502, -1755, 11064, 7668, 340, 230, + -127, 1490, -63, 680, -297, 125, 1700, 2505, + 3, -2043, 255, 1547, 569, -2483, 733, -896, + 881, 4780, 1544, -13442, 1328, 1937, -4448, -384, + 749, 173, 7350, 156, -144, 52, -527, -34, + -3, -173, 118, -528, -75, 39, 42, -874, +-14636, 474, -413, -106, -115, -431, 54, 722, + 156, -468, 369, 149, -68, -791, 1318, 2150, + 69, 454, 19032, 3, 111, -40, 349, 88, + 385, -54, -395, -224, -519, 0, -219, 179, + -253, -11379, 11005, 1857, -126, -248, 304, -616, + 351, 324, 500, 1494, -1390, 2349, -1257, -1114, + -213, 8156, -2066, 9746, 763, -848, 349, -7, + 723, -966, 469, 91, -252, 1336, 579, 1816, + 1372, -941, 364, 276, -33, 7, -425, -433, + -21, 546, -671, -31271, -926, 101, 147, 302, + -552, 224, 568, -2386, 519, -458, 13171, -1464, + 1161, 639, -10, -877, 331, 3372, -72, 5158, + -706, 906, 2668, 1008, -2732, 3264, 105, 630, + 673, -1948, -196, -13130, 1726, 737, 4829, 93, + 654, 2175, 3858, -5, 245, -471, 369, 5435, + 356, -12934, 61, 1984, 975, 706, -2454, -642, + -93, -780, -443, -1487, -460, 1112, 385, 309, +-10268, 197, -1692, -1870, 50, -1934, 5380, -1193, + 775, -493, -992, -557, 2952, 408, 4616, -1341, + 10774, 5305, 854, 3031, 67, 617, 2436, -2072, + -1469, 804, -578, 243, 264, 9150, 200, 10753, + -350, 182, -52, -406, 508, -761, -161, -1142, + 25, 484, 127, 126, 477, -341, 110, 371, + 32767, 1090, 678, 175, 146, 1020, -897, 878, + -137, -507, -534, 658, 678, 505, -753, -207, + 391, 60, -23279, -772, -1323, -1578, -3, 196, + -749, 220, -482, -785, 456, 38, 1034, -579, + -58, -1539, 421, -746, 238, 1531, 21290, 586, + -441, -276, 1512, 553, -1407, -276, 60, -1068, + 299, 650, -25, 12590, 2058, 925, -295, -1744, + 5152, 4935, -419, 272, -383, -665, -194, -255, + 574, -267, 541, 1031, -282, -648, 622, -1464, + -28, -269, -533, -80, -476, 282, -336, 125, + 104, 464, -8948, 849, 171, 1518, -296, 51, + -27, 3097, -5103, -412, -494, -194, -713, -1277, + 102, 1740, -445, 3432, 1180, 6404, -10908, -970, + 31, 142, -242, -79, -78, -76, 124, 1031, + 83, -55, 1522, -613, -32768, -394, 1306, 287, + 701, -4725, -1085, 415, -122, -538, -675, 82, + 116, -728, -99, 500, 659, -329, 292, -106, + 9243, -340, -11933, -498, 341, -825, -401, -402, + 142, -13, -309, -722, 141, 0, -681, 494, + 671, -1210, 1466, -1335, 11743, -280, 1616, -11481, + 52, 317, 902, -653, -967, -494, -162, -685, + -438, 756, 81, -207, 577, -7476, -353, 918, + -31, -107, 181, 523, -46, -752, 373, -908, + -1808, -916, 632, 1508, -35, -6943, 64, 13072, + -655, 163, 1221, -1655, -2568, -446, -401, 470, + -622, -944, 3744, -458, 203, 125, 238, 5196, + 21, 12193, 1095, 1091, -787, -1157, -980, -1154, + 7707, -29, 106, 1226, 696, -974, -379, -537, + 56, 95, -477, -528, -11245, -1014, 140, 380, + 89, 540, 84, -619, -322, -572, -240, -26, + 727, 310, 43, -790, -31, -24318, 110, 618, + 44, -108, 89, -191, -33, -201, -490, 43, + -136, 1366, -2, 162, -832, 469, -140, -278, + 600, -15775, -1699, 184, 1825, 728, -1803, -876, + 152, 60, -813, 3063, -929, 972, -282, 718, + 8426, -888, 1383, -664, 571, 958, 982, 236, + -548, 66, 1898, -274, 10715, -1693, 79, -1254, + 296, 609, 682, -1074, 272, 157, -18972, 377, + -12, 438, 536, -672, 292, 719, -464, 1106, + -296, -812, 6, -334, 67, 678, 382, 678, + 301, -22165, 184, 80, -671, -86, 139, -298, + 416, -610, 1057, 15, -230, 376, -768, 643, + 58, 27, 178, -742, 60, -500, 485, -19923, + -1016, 717, 1126, 287, 2171, -388, 1453, -21, + -268, -1555, -263, 713, 1709, -1103, -10699, 1788, + -8, -501, -892, 11476, -2006, 466, 8070, -286, + 163, 35, 494, 76, 1428, -2249, 100, -1542, + 319, -214, -701, 10130, -294, -11962, -656, 227, + -512, -1014, 213, -600, -720, 63, -180, 1286, + 1063, -9671, -1056, 1269, 1484, 20, 790, 29, + -9906, -373, 608, 361, -659, 43, -1034, -96, + -219, -65, 392, -19615, -464, 212, 820, -182, + -227, 463, 301, 642, -219, 386, -1170, 108, + -5583, 422, -507, 530, -1058, -131, 20, -14487, + 101, -14, -415, 32, -1133, -917, 944, -832, + 580, 2509, -959, 470, 1184, 432, -1238, 193, +-13382, 2329, 1993, 1035, 80, 3139, -553, 1683, + 390, 1480, 642, 564, -11173, 422, -984, -559, + -686, 168, -777, -810, -1278, -427, -96, 1691, + 29172, -435, -50, -968, 221, 685, 52, -373, + 525, -563, 350, 528, 305, 705, 313, 612, + -254, -220, -1638, -156, 24, 109, -893, -697, + 245, 2579, 667, -142, 12315, -694, 3799, 5, + -438, -473, -426, 59, -5381, -56, 200, -280, + -276, 96, 435, 729, 336, 123, -714, -372, +-12609, -12053, -238, 223, -242, 230, 663, -645, + 98, 515, 3, 724, 510, -48, 1090, -173, + -5024, 536, 635, -143, 702, 172, -196, 164, + 190, -152, -180, 238, -142, -329, 191, -296, + -416, 11775, -496, -95, 392, 994, -584, -925, + -963, 286, -458, 3104, -1990, 968, -1430, 998, + -407, 28485, 436, 42, 378, -210, 148, -149, + -532, 94, -628, 186, -186, -274, 250, -316 +}, + +.cb1616s0 = { + 5604, 1491, -2064, 1321, -2846, -3007, -1899, -896, + 556, 1969, -2225, 18515, 4156, 1333, 3489, -2168, + 1897, -1440, -1514, -13837, 1017, 4797, 453, -2101, + -6822, 923, 185, 754, -201, -4151, 126, -793, + -437, 2474, 4286, -6405, 4007, -1644, -757, -13106, + 2460, -1874, -1867, -1099, -5146, 2945, 2162, -4427, + 1692, 763, 1756, -821, 66, -348, 2001, 702, + 1046, -1365, -570, 1073, 32655, -9, 450, -761, + 908, -200, -572, -1306, 2589, 2406, 1926, 1772, + 11042, -1989, 3914, -1192, 1817, -11710, 2985, -2942, + 15684, 1919, -667, -1267, 5212, 444, 864, -3844, + 438, -2382, 974, 983, -887, -822, 185, 245, + -3192, 1030, 1441, -28152, -2616, -380, 300, 1990, + -94, -999, 285, 553, 2107, 960, -859, 1001, + -1632, 2208, -1302, 1331, -3956, 10593, -1931, -4486, + 9376, -6587, -463, -3605, 2460, 1306, 2, 1987, + 1643, -552, 1327, 1124, -581, 1347, 650, -29514, + 278, 1062, 1459, 951, 2416, 396, -594, 930, + 434, 3308, -2816, 5466, 4831, -2869, -68, -894, + 58, -13036, 210, -1940, -2524, 1139, 2044, -32, + 969, 2187, 516, 581, 8185, 2080, 176, -708, + 1529, 1132, -675, -1384, -10949, 1174, -5245, 580, + 7490, 3258, 4314, 2706, -13676, -1735, 1937, 577, + -108, 2676, 612, -966, -966, 3255, 1401, 1443, + -1850, -252, 9270, 5037, -1492, -1957, -2134, 1198, + 3470, 10482, -468, -671, -1655, -955, 3248, 3360, + 448, -1854, -25145, -2771, -3318, 561, -672, 1791, + 2194, -598, 1673, -420, 547, 122, -160, -172, + 1686, -397, 1187, 11, -879, -58, 323, 180, + -2588, -2139, -1794, -2924, 999, -26969, -1280, -1401, + -770, 6159, -4449, -4174, 5270, -4813, 4139, -2023, + 2694, 2884, 3418, -5948, 3118, -1176, 4691, 8566, +-32768, -681, -553, -216, -216, -931, -507, 579, + -932, -740, 349, 81, 2120, -1222, 564, -1576, + 1241, 159, 2579, 3236, 19205, -744, -1727, -1803, + 1247, -575, -261, 261, 540, -255, -60, -1428, +-14184, -5194, 863, 997, 1043, -828, 466, -12553, + 2106, 56, -566, 1142, 401, 1360, 2322, 629, + 937, 2954, -10086, -12, 2554, -5760, 523, -15184, + 636, 156, 165, -2638, 1134, 658, 4398, -1385, + -1924, 1179, 3222, -908, -1153, 18082, 1011, 1948, + -1007, 352, -172, -6446, -22, -228, -264, 73, + 76, 2229, -1349, 6103, -11588, 576, 3374, -1616, + 7904, 3146, 984, 1056, -1626, 3113, -3674, 203, + -452, -938, 2074, 2409, -1228, -8186, -2766, 11098, + 1598, -8658, -735, 556, 1610, -7419, -5267, 1158, + 2841, 4497, 7551, -2066, 1105, 761, 2549, -1764, + 2870, 3889, -1478, 1912, 2504, -1417, 963, -14602, + 579, 28, -2953, 1589, 3962, -1372, -3304, 566, + 2687, 9700, -2464, -13110, 3005, -772, -3775, -138, + -4244, 5031, 2523, -2883, 582, -446, -274, 3311, + -157, -784, -948, -292, 3085, -781, 954, -2133, + -6693, 13909, -2236, 416, -2589, -3194, 668, -1988, + -2234, 2365, 1034, 1201, -100, 1688, 372, 156, + -254, 931, 576, -4680, 566, -1823, 294, 1645, + 27678, -1353, -1230, 1744, 570, 1679, 608, -35, + -7150, -4383, -11992, -2910, -2096, 512, 1838, 3129, + -410, -2306, -551, -3904, 4140, -12782, -1743, -106, + -4190, -5554, 12975, -573, -3532, -4050, 15, 1307, + 62, 1643, -1988, 5774, 2064, 4734, 1009, 2038, + -2794, -2704, 2275, -279, -1588, -910, 31315, 1249, + -1642, 78, 164, -260, -878, 698, 1189, 159, + -6137, -1994, 775, 3484, 1635, 1121, 4391, -5883, +-11300, 3722, -422, -2180, -3206, -3181, -1490, 291, + 1326, 399, 1952, -8405, 2240, 175, 3541, 4258, + 1518, -781, 1105, 498, -348, 771, 15918, 120, + 379, -2036, -3723, 10948, -1827, 3220, 40, 210, + -294, -813, -2349, -707, 967, 953, 2625, -13614, + -1519, 9454, 11606, -903, 817, 6237, -8878, -160, + -1768, 444, -2812, -1697, -1010, -964, 1846, 2997, + 2633, -1924, 501, -1464, 2402, -986, -1143, 527, + 1187, -929, 20923, -563, 785, -486, -940, 1625, + -796, -697, 348, -428, 1451, 1087, -2252, -2481, + 939, 890, -2508, -1357, -1868, 1395, -6386, -21986, + 2574, -384, -324, 7752, 2996, -641, -7903, -5745, + -4226, -4178, -4394, 9307, 3906, -227, -496, 4556, + 1099, -838, -2546, 1190, 9937, 11057, 3846, -156, + 433, -2873, -1769, 36, 3188, 4490, 4369, 4714, + -4681, -2804, -1525, -947, -5064, -4180, -1348, -1404, + -1097, -3922, -1088, -444, -13636, -1547, 1685, -1625, + -8494, 2492, -72, 9893, 2470, 705, 105, 5609, + -5403, 846, 90, -688, 1184, 6286, -253, -1610, + 3348, -2082, 8838, -2453, -1315, -1235, -719, -4607, + -2138, -5522, -10466, 1900, 1541, -2688, 729, 368, + -8845, 1282, 438, -2532, -2328, 4833, -6145, 4037, + 3584, 7965, -1495, 6999, -5037, -1364, 7095, 4253, + 2711, -8336, 3946, -1347, 192, -820, -328, -1152, + 1554, 869, 5053, 9707, -5888, -4294, -3858, -3344, + 8344, -644, 1750, -1796, -149, -3706, -14823, 656, + -1487, -2466, 640, -2286, -2902, 2906, 44, 211, + -336, 29976, -298, 2092, -688, 1857, 1807, -1705, + 3211, 425, -1046, 128, 1191, -1966, -726, -3040, + -3632, 1212, 2986, 5266, 1086, 3624, 3068, 422, + 989, 24479, 3791, -2229, -3713, -2379, -1370, -1799, + 2742, -3259, -4973, -626, 2287, 5655, 663, -918, + 13266, 7762, -1131, 2490, -3123, 2869, -846, -2828, + 119, 14540, 4588, -2784, -3713, -2547, 3698, 3189, + 3372, -5436, 856, 4382, 4124, 3406, -336, -911, + -137, 4268, -4436, 1566, 1169, -3020, 13980, -162, + -7226, -2550, -946, -2408, -1056, -587, -273, -932, + -219, -8021, -1086, -2587, 3852, 1235, -22, 222, + -1100, -1594, 137, -1985, 10225, 4998, -348, -450, + 6651, -2217, -7705, 2508, 10061, -4512, -2262, 6156, + 2962, 150, -2456, 1089, -927, -609, -3130, -1682, + -1215, -9251, -130, -3776, -309, -13872, -276, -6922, + -82, 2660, -1255, -6562, 2640, 2646, 422, -84, + -6020, -11551, -1710, -3462, -2666, 12510, 3145, -218, + 2956, 447, 30, 2268, -2410, -1400, 660, 431, + 3068, 258, -2862, 3919, 2693, -744, 3070, -2179, + -1192, -932, -2095, -279, 2045, -8205, 15263, -4415, + 2116, 4047, 10308, 3110, 1368, -1547, 10919, 988, + -81, -907, -1728, -1052, -3539, -4769, -2576, -1038, + 9255, 152, 431, 2455, -1544, 1880, -312, 2724, +-13336, -4197, -1199, 709, -695, -1687, 442, -2564, + -1626, -1888, 1870, 3539, -2922, -3506, -7890, -5486, + -1640, 2178, 2173, -3200, -4626, 1116, 13161, -5221, + -852, -1047, -3328, -3975, -4441, 2870, -1458, 5664, + -28, 3853, 1809, 2721, 658, -15262, 3611, 3223, + 595, 44, -5327, -2486, -1806, 606, -2474, -1236, + 983, 1741, -8390, 1948, 1875, -1806, -6294, -814, + -747, 2209, -1332, 2058, -1326, 5808, 1113, -10765, + -584, 4038, 1412, -3356, 24, -12826, -4322, -2287, +-10793, 3008, -6903, -1273, 1590, -608, -514, -309, + -144, -2024, 1822, 4375, 1122, -631, -76, -595, + 192, -11323, 8168, 10180, -646, 2478, 4516, 1095, + 94, 6, 1251, -658, 2620, 626, 3078, 727, + 7769, 966, -3593, -6990, -2358, 1022, 1288, 2733, + -259, -291, 2482, 297, -1268, 10338, 739, -1862 +}, + +.cb1616s1 = { +-12873, -2429, 6659, 4401, -2250, 1684, 1508, 1780, + -1081, -10, -6012, 895, -2373, -1263, 125, 1448, + 4744, 1556, -7267, 2354, -11368, 1155, -7699, -1424, + -914, -591, 2472, 538, 1431, 953, 5, -3066, + -1063, 3, 406, 979, 922, -668, 1633, 2, + 649, -139, 964, 860, -18807, 1944, 2183, -1358, + 1395, -1167, 5369, -3525, 735, -2698, 10556, -1137, + -3979, 1383, -1997, 5995, 6465, 2310, 1781, -311, + 3376, 7199, -2745, -1656, -5702, 3180, 3017, -5673, + -712, -8902, 2058, -570, 170, 2276, 3869, -9332, + -7965, 1130, 2111, 5638, -1507, 2944, 1574, -919, + -1459, -970, 11093, 544, -2952, -146, -4684, -303, + -528, -1199, -890, -2720, -1665, -10952, 373, 1657, + 1960, -1386, 299, -4356, -4527, 8948, 7378, 1580, + 1301, -6057, 7650, -7399, 4646, -1768, 2756, -263, + -286, -334, 1369, -786, -3760, 824, -13524, -5099, + -1693, -347, -1821, 1992, 3462, 1421, 4900, -462, +-13331, -1617, -2350, 4083, -8721, -5880, 4900, 2912, + 235, 10369, -1340, 776, -2598, 14344, -3805, -568, + -3788, 3591, -394, -1077, 3908, 6080, 1953, -1454, + -1013, 507, 10097, 3396, -4662, -763, 2506, 1486, + 3088, 580, -86, 1117, 1606, -3454, -10782, 4870, + 6170, 4020, -5675, 6848, 439, -8765, 3877, 6250, + 734, 3245, -874, -4312, -879, -4368, -1287, 3212, + -2130, -1435, 1619, -280, -3082, -1070, -18921, 940, + -2428, -1548, -1142, -271, 193, -240, -890, 918, + -4350, -5042, -8994, 5060, -6495, 3455, -259, 892, + -1290, 1348, -1049, -12681, -49, 18286, 75, 791, + 1830, -4116, 10240, -12, -459, 2477, -2582, -3344, + -1598, 982, -324, -48, -4229, -8476, 11120, 100, + -6238, 1164, 2369, -2052, 247, 626, 2213, 2279, + -2627, 289, -471, -1136, -1818, 15413, 579, 1034, + -6835, -8645, -12667, 758, -932, -4398, 565, 458, + -2024, -4050, -3100, 1897, 1324, 3191, 1876, 7660, + 385, -1066, -1539, -1317, -2632, 766, 63, 389, + -189, 1136, -653, 802, 755, 70, -29812, 640, +-11953, 10901, 2078, -529, 10373, 2509, -2776, -104, + -2232, 174, -837, 158, 1507, 1963, -273, 1534, + 1084, 8469, 2568, 12662, -2276, 2808, 2052, -7430, + 434, 3777, 991, 664, 2724, 1631, -3632, 2099, + -582, 4140, 757, 11248, 540, -1425, -10204, 1604, + 600, -2034, -1060, 977, 1843, 3831, -933, -816, + 2975, -6413, 1589, -915, -696, 2155, -556, -17893, + 3348, -1239, 1014, -2539, 1588, -320, 2402, -1485, + -8062, -1046, -1458, 200, 1323, 357, -3752, 2836, + 5774, -11638, -913, -648, 1676, 246, -1277, -1065, + 2334, 14911, 228, 880, -2172, 3072, -2520, 1445, + 1442, 2568, -1254, 730, -1950, -192, 12003, -1587, + 2558, 714, 33, 4324, -4642, -231, -279, -255, + 17824, 1292, 3530, -766, -64, 245, 1677, 1716, + 2507, -3594, -3532, 3000, 1996, -5342, -1868, -5642, + -21, 1132, -1202, 1104, -6543, 1242, 457, -1711, +-32768, 49, -458, 295, 858, 2043, 1268, -1257, + -346, 793, 554, 1260, -1082, 985, -1453, 1704, + 2431, -2858, 1466, -5424, -8870, 4714, -1539, 5767, + 110, -2568, -1482, -348, -11580, -2838, 1213, -599, + -1591, -3472, -6907, 6191, 3928, 4708, 1326, -1510, + 6322, 3849, -4112, 7689, 5976, -3298, 372, -5450, + -2208, 6564, -6915, 911, 4216, 1682, -739, -2146, + 203, 350, -816, 351, -3386, -3016, -15045, -10824, + -553, -4969, 138, 256, 1672, -1840, 2851, 15838, + 2934, 1871, -600, -3293, -845, -2696, 1463, -1075, + 720, -1177, -1538, 2415, 7315, -484, 1082, 962, + 766, -845, -10687, -5932, -4410, 3840, 362, 194, + -4576, 10209, -3548, -127, -1202, 246, -734, 770, + 311, -3126, 772, -2422, -1141, -12330, 960, 1567, + 2816, 80, -4414, -778, 665, 2308, -420, -180, + -1242, -423, 12138, 113, -1477, 2899, 214, 348, + -927, -764, 26, -1127, -2288, -32768, 1302, 394, + 646, -453, -946, -838, 1649, -2292, 1182, -1558, + -6413, -265, -1942, -3467, 1863, -3526, 3446, -863, + 886, 202, -202, 15706, 2226, 1763, 894, 936, + 16191, -693, 1682, 6678, 1742, 1365, 700, -1765, + -803, 299, -2194, 1259, 689, 1670, -635, 28, + 11890, -14, -878, -5439, 103, 11124, 528, 1179, + -62, 868, -664, 749, -1128, 1429, -485, 1920, + -866, 1176, 1051, 379, -29470, 2354, -252, -1648, + -412, -804, 1339, -383, -812, 959, 893, -1741, + 1462, -1868, 470, 2112, -1889, -2236, -1668, -755, + -2562, 1354, 6183, -10964, 5651, -1062, 2550, -6225, + -194, 1687, -782, 1568, -85, 10, -8, 1128, + -521, -1090, -1933, -3441, -2698, 3049, -5822, 20847, + 710, 789, -1872, 1082, -1242, 4152, 1624, 10795, + -2149, -134, 1087, 900, -7943, 5178, -3429, -11622, + -3617, -7444, -824, 3462, -579, -830, 1010, -3301, + 12202, -5446, -1763, 340, -744, -509, 554, 1140, + 12266, -1328, 4652, 992, -1931, -708, 1074, 2762, + 2931, -414, -217, 10166, -4167, -903, 660, 1000, + 27, -1037, -1532, 1308, 8655, 9087, -2998, 9928, + -3722, -556, 4812, 3062, 600, 1281, 3879, 114, + -5404, 1869, 2174, 2083, -11631, -301, -3609, 2443, + 2300, 4863, -838, -29, 2166, 1319, 2110, 1387, + -741, -1225, -1729, -13536, -7376, -1520, 619, -4919, + 2517, -4338, -1650, 475, 456, 4372, 792, 3224, + 1963, -547, -2071, 2142, -254, 1549, -6846, 2430, + -96, 19844, 595, 1197, -1367, 2019, 2014, -1547, + -3775, -1186, -9690, -394, -4106, -1728, -1036, 2945, + 509, 14242, -1893, -2494, -3004, 458, -1753, 2628, + 9790, 3450, -1652, -322, 8263, 3952, -2156, -2110, + -442, 1256, 1561, -4913, -3452, 74, 3051, 8907, + -3376, -96, 16654, 557, 520, -446, -2520, -1712, + 2151, -2423, 3761, -3507, 487, 2103, 777, -416, + 509, 468, 3629, -3155, 11460, 2106, -2191, -1014, + 1154, 9317, 704, -282, 3098, 2722, 84, 150, + -5922, 3063, 8373, -11896, -1157, -2286, -1781, 7331, + 1331, -334, -974, -1653, 752, -1970, -89, -3470, + 2418, -1334, 3615, 12770, -116, 1965, -1643, 1480, + -2225, -10686, -1174, 530, -972, -933, 719, 722, + 1530, -317, 105, -14155, 2569, 4506, -8502, -681, + -1544, -542, -2814, -1161, -629, -1776, -3540, -1366, + -3681, 1838, -1630, -703, 12613, -12335, -2020, 2173, + 27, 315, 4766, 4590, -1603, -68, 1154, -2940, + 1198, 7884, 2502, -586, 440, -5124, -2454, -2597, + -826, 7401, 2803, 4552, -3212, 2966, -5567, 588, + 2216, 7444, -2633, -5922, 434, 3423, 4084, 2296, + 13258, 2070, -4624, -1226, 166, -367, -527, 1110, + -1407, -150, 140, 584, -373, -2649, 862, 500, + 3292, -3506, -679, -20109, 1775, -726, 3378, 754, + -1962, -5764, -1338, -3628, -691, 4554, -1890, -6021, + -6566, 2590, 262, 2509, 257, -4386, -2480, 6352, + -2026, 1234, -399, 22808, -2221, -626, -714, -339, + -1196, -455, -80, 713, 1662, 474, -2324, -527, + 4101, -10526, -4617, 10492, -1143, 805, 1360, 3796, + 942, 684, 2596, 1313, 1589, -570, 5476, -27, + 9220, -1493, 2631, -6726, -2976, -14295, 137, -734, + -2015, 658, 323, 83, 2539, -1230, 1714, -2080, + 658, -18803, 2978, 996, -3374, -28, -1335, 150, + 2154, 1069, -852, 293, 535, -1004, -993, -3692 +}, + +.cb1616m0 = { +-16476, -11442, -305, -196, -767, -2167, -1, 378, + -2200, 22, 2405, 944, -1786, -806, 669, 952, + 10435, -2752, -1625, 1060, -12314, 1283, 234, -2405, + 627, 798, -1058, 311, -2794, -2715, 73, -214, + 813, -2749, 10732, -445, -12147, -2507, -1972, 1652, + -1920, 215, 298, 1106, 826, -7445, 69, -1679, + -675, 1249, 1444, -1109, -48, -1452, -2368, 3034, + -492, 13068, 311, -3446, 326, -1426, 2384, -2146, + 2916, 8957, -196, 2212, 447, 1775, 2607, -11962, + -278, 4335, -1743, 135, 212, -41, -92, 164, + -11, -504, 828, -519, -834, 251, 1919, 762, + 24917, -180, -132, -330, 138, 225, 1038, 3, + 32138, -388, 208, -638, -1338, -165, 200, -230, + 225, -777, -2270, 8198, 583, 3946, -1534, 1666, + -1032, 11384, 202, 30, 2758, -505, -2815, 1265, + 64, -17, -360, 636, 134, 502, 259, 872, +-28148, -1046, -348, -86, -739, 55, 448, 168, + -656, 1094, -1074, 4552, -834, 2296, 2356, -572, + -1917, 10979, 3127, -52, -9969, -527, 1994, -1626, + 1041, 3310, -2319, 2232, -11444, -2400, -1788, -1254, + 5265, 3198, 7088, 4522, 1292, -191, -15886, 2787, + 22, -1610, 184, 380, 521, 336, -158, 877, + 468, 6515, -756, -5484, 100, -464, 9244, -2726, + -1644, -2741, -5362, -1635, 894, -1849, 10118, -3264, + -4472, 1255, -3571, -437, -1050, 1505, -11178, -193, +-11513, -24, 719, 212, -1999, -725, 502, -1164, + -1060, -618, -91, -738, 740, -2254, -4635, 2700, + 95, -853, 1093, -11620, -968, 9492, -25, -664, + 367, 1105, 5501, -112, 7516, 10286, 821, -484, + 204, 1425, -3491, -1234, -4240, 3807, 2877, 1824, + 423, 466, -428, -845, -86, 13276, 8436, -690, + -688, 574, -2874, -552, 4540, 926, -5443, 629, + -395, 2090, -17468, 335, 2419, 1275, -3750, -1589, + 470, -1735, 330, 2532, 1094, -6218, -884, -236, + -9678, -9945, -447, 542, -728, -1922, 108, -2193, + -946, 3270, 2121, 2624, 1010, -10742, -102, 2813, +-13070, 1523, -1532, -1291, 420, -1999, 262, -1194, + -4226, -1450, -275, 83, 1168, 1590, -1517, -426, + -1424, 152, 676, 11463, 824, -2092, -1106, -11502, + -2327, -278, 2597, -11, 793, -118, 393, 580, + -499, -743, -77, -427, -408, -692, -29195, -247, + -2014, -922, 97, 581, 5469, -1419, -698, 1490, + -3814, -2818, -13816, 680, 3595, 1544, 2366, -3018, + 2479, 323, 346, -260, 337, 2730, 12214, -1118, +-11301, -3028, 212, -41, 1764, -580, 553, 5454, + -8, -366, -1202, 901, -796, -8350, 4380, -1452, + -300, 1152, 3058, -3476, -27, 13046, 34, -11438, + -1321, -1528, 13237, 114, 2514, 976, -571, -1192, + -2050, -1635, -964, 416, -23, -1083, -9, 32767, + -548, 556, -1217, -56, 325, 1048, -145, 202, + 1520, 44, 402, 400, -611, 8667, -1083, 1068, + 1224, -12031, 2318, -1109, 1266, 1306, 4673, 285, + -5603, 1555, -100, -1059, 403, -213, -680, -904, + 11443, 581, 12160, -638, 309, -65, 933, -2280, + 1958, 2642, 1808, 7945, -2088, 850, -428, 785, + -989, 1234, -1413, 745, -10756, 1943, -184, 3252, + -96, 932, -664, 13222, 11326, -1374, -327, 1901, + 1069, -1540, 104, -139, -904, 106, 1664, 925, + 46, 353, -835, -554, 1618, -956, -437, -727, + -3403, 1038, 968, 436, 46, -4385, 340, -16903, + -498, 47, -554, -399, -2418, -347, 358, 23280, + 234, -172, -338, 1058, -2172, -1, 1710, -64, + -583, -2224, -780, -637, 3500, 108, 1045, 828, + -728, 9466, -2487, -12773, 1924, -1158, 208, 49, + 136, 12055, 42, -1381, -375, -11534, -249, 1602, + 996, 204, -710, 4761, -511, -15761, 166, -1184, + -192, 50, -105, 890, -9566, 2062, -1536, 133, + -185, -643, -172, -894, -355, -16, -1395, 542, + 2160, -481, -1104, -793, 517, -20454, 698, -181, + -135, -434, 1677, -181, -415, -738, -1574, 1664, +-14058, 597, -12354, -460, -313, 1724, -686, 85, + -1162, -648, 865, 165, -225, -1947, 2818, -778, + -4010, 402, 686, 11170, -332, 10336, -757, 4794, + 2204, -477, -292, -366, 8412, -2476, 494, 510, + 10514, 769, 642, -441, 1079, 6954, 4246, -2272, + -290, -224, 1312, 398, 1536, -692, 330, 157, + -946, -100, -1830, 214, -25652, 1382, -1836, -440, + 110, -506, -438, -2370, 126, 562, -3515, 1014, + 8526, -1641, -2493, 4411, -9210, 2110, 625, 114, + 323, 2450, 2407, 682, 1999, -9424, 2480, 69, + -2091, -11845, -3684, -429, -1622, -919, -518, 70, + 1450, -3523, 5126, 5706, -1451, 2633, 820, -204, + 11338, -8014, 753, -103, 290, -923, 1408, 298, + -1962, -887, 9691, -1366, -11048, -55, -223, -1040, + -163, 132, 676, -760, 4990, -310, -9286, -2427, + 14442, -418, -802, -359, -323, 2877, -210, -1436, + 1574, -1206, 265, -155, -225, -32768, 347, 222, + -1165, 200, 924, 1135, -843, -66, -343, -334, + -113, 209, 14, -203, 1214, -896, 910, -1496, + 1831, -7833, -841, -10453, 1605, -8514, -477, -48, + -241, -58, -32768, 213, 108, 450, 1155, -30, + 89, 240, -768, 1332, 290, -1377, 951, 586, + -8939, 1298, 496, 705, -1661, 1798, -1906, -2233, + -1716, -986, -2204, -1149, 2686, 8578, 32767, 645, + -661, -135, 770, -432, -550, -385, -272, 625, + 1234, -729, 19, 1753, -284, -106, -655, 750, + -442, 23143, -328, -520, -506, 790, -1048, -730, + -471, -438, 483, -374, 939, -226, -397, -849, +-12054, -772, -40, -11776, 232, -540, -2497, -679, + 337, 1357, 458, -341, -7542, 1001, 492, -416, + -1496, -8966, 9814, -1752, -674, 2526, -544, -2900, + -1318, -1578, -238, 75, 11181, 1750, -3182, 564, + -570, 528, 1004, 146, 1144, 7430, 158, 9524, + -36, -340, -441, 596, -1659, 1420, -686, -36, + -596, 2215, -1295, -19722, -2149, -1046, -2339, -1166, + 3057, -370, -556, -33, -322, 260, -23, -106, + -323, 147, -57, 179, 458, 684, -1283, 1251, + 1231, -18548, -513, -480, -695, 593, 3072, 1960, + 322, -702, -1043, -544, 6005, 1378, 100, -225, + -848, -1294, -3346, 828, -2610, -3010, 9623, -1329, + 1956, -1098, -3730, 1137, 12413, -1260, 2457, -10844, + 6824, -4289, -653, -302, -4415, 650, -1684, 6129, + -370, -652, -3245, -473, -150, -3018, 1864, -1258, + 928, -2379, 14451, -119, 2282, -248, 3139, 6502, + 4318, 2214, -1627, 126, -422, 326, -622, -302, + 32252, -268, 456, -260, -260, -968, 391, -497, + 152, 1764, -10580, -369, 277, 70, -13137, -1114, + -1111, 464, 2266, -2968, 728, -1216, 1726, 1044, + 344, -16436, 1558, 3178, -551, 604, 442, -891, + 9570, 1596, -541, -2182, 730, -906, 242, 935 +}, + +.cb1616m1 = { + -116, -53, -24868, -544, -783, 97, -912, -1202, + -622, -147, -215, -362, -16, -522, -1694, -358, + -724, 2628, 439, -18106, -1566, 3048, 4133, -1238, + -3233, -1130, -2884, -2762, 1031, -1037, 63, -2219, + 10701, -1518, -10322, 1425, 792, -1820, 380, -777, + -3017, 1531, -1052, -3491, 1085, -428, -765, -113, + 42, -265, 365, 99, -859, 35, 610, 44, + -495, 262, 1689, 2082, 21605, 412, -717, -1163, + -3285, -5062, -1583, 599, -277, -62, 615, 6014, + -1781, 465, -544, -14114, 11277, -20, 696, 663, + 1156, -240, 631, -2802, 333, -2544, -1628, 775, + -960, -553, 496, -378, 526, -421, -426, 290, + 555, 403, 390, -31714, 25, 449, 654, -334, + -1317, 165, 496, 1554, -88, -777, 626, -1511, + -9020, -1725, 12705, -798, -1240, 195, 1932, -833, + -939, 43, 182, 2547, 4879, 9234, 370, 2058, + -7757, 544, 1106, -660, 546, 9983, 225, 124, + 952, -2153, -1732, 2760, -1270, -176, 3334, -6735, + -526, 10475, -627, 7835, -2263, 475, 731, 908, + 8264, 1605, -192, 5026, 2414, 5223, 595, 1093, + 2345, -796, 8663, 1028, 8188, -185, -1506, -3044, + -100, -1818, -6369, -170, 1728, -9249, 886, -2111, + -349, -1146, 2127, 11622, -8043, 2880, 2215, 1693, + -2303, 1698, 1121, -3575, -927, -716, 1940, 2514, +-11672, 1619, 916, -7, -585, 508, -1316, -972, + 778, 9774, -2126, 2368, -56, 6716, 1169, -3656, + -1330, 9530, -12158, 1188, -11426, -353, 945, -1941, + 1750, 962, -1133, 1793, 2318, -2641, 1109, 933, + 804, 505, 60, -1642, -2238, -2328, -1558, -1568, + -27, 952, 4, 1376, -862, -18404, -1828, 4107, + -454, 52, -1202, 1150, 686, -1950, -497, -10883, + 400, -422, 1734, -54, 11165, -3309, 6402, -877, +-19967, -400, 1642, 1305, -2432, -3115, 375, 3898, + 1812, -5305, -946, 1717, -757, 3322, 126, 747, + 1836, 9957, 1904, 658, 13043, -1779, 675, 716, + -453, 670, -1572, 210, -1533, -133, 294, 546, +-24084, -1036, -485, -117, -184, -624, 273, -901, + 866, 609, -1119, 28, 250, 13, 70, 1178, + 882, -632, -21624, -1339, 926, -1814, -1279, 1868, + -181, 383, -679, -1070, 5091, 1148, 1034, 2144, + -2779, -3810, 4536, 1713, 1003, 13322, 2866, -3217, + 2508, 4395, 480, 14, 167, 763, -34, 1034, + -1342, -1349, -100, -225, 464, -914, -1403, -1851, + 23767, 770, -457, -257, -1072, 1201, 583, -59, + 2627, 1469, -7, -11642, 3352, -1003, -6, 11588, + -311, -2435, -2180, -2352, 1952, 5532, 1945, 7281, + 504, 11882, -603, 45, 42, -1396, -1115, -1041, + -1061, 566, -2733, -765, 687, 118, -1174, -20412, + -244, -986, -151, 2888, 1102, -1303, -135, 529, + 1186, 13220, -183, 906, -4209, -4455, 2247, 246, + -6474, 2794, 1450, -6495, -1819, 598, -438, 244, + -1064, -673, -672, -1563, 543, -2278, -3087, -811, + 1866, 80, -18987, -682, 569, -551, 514, 6876, + 7582, 839, -4031, 823, 2342, -1300, 1180, 702, +-10168, -1957, 485, -374, -151, -11066, -461, -12824, + -1221, 1281, -718, 2012, 330, -289, -487, -207, + -722, 394, 156, -2023, -11006, -373, -4, -238, + 10581, 991, -1236, -814, 553, 1295, -2269, 2783, + -1973, 681, 9759, 3674, -1680, -12118, -1340, -2372, + -288, 2143, -328, 809, 312, 2038, 736, -10, + 908, -11319, 74, 6362, -1122, 1546, -184, 1630, + -1851, -2143, 1048, 8858, -462, -6458, -1540, 811, + 130, -3542, -10424, 9353, 388, 1168, -1797, 1796, + -4151, -2329, 1, -272, 846, -642, 248, -1144, + -9863, -1684, -190, 7611, -4147, -692, 5354, -2363, + 609, -4926, 3166, 2094, 857, -369, 118, 725, + -899, -601, -6, 556, -32540, 950, -478, 757, + 136, -560, -754, 562, -448, 223, -704, 616, + 365, 22610, 1191, -1264, -94, 927, -294, -1270, + -16, -2520, -2026, 420, -6621, -504, 9666, 452, + -379, -1888, 536, 1161, -3021, 609, -4890, -231, + 3926, -943, 32767, -615, 300, 870, -742, 429, + -42, 155, 1060, -900, -347, 34, 491, -3625, + -1529, 10175, 178, -7938, -406, 1628, -362, -7340, + -433, 489, 568, 674, 536, -2886, -6118, -16, + -531, 182, 1498, -4194, -306, 63, -1429, 1109, + 631, -10386, -16, -5938, -52, 10638, -793, 35, + -874, 1633, -252, 709, -286, -780, 17172, -32, + 912, 137, -1684, 2781, -5637, 338, 10961, 1401, + 176, 1890, 563, -371, 578, -235, -882, -616, + -591, -672, -821, 12194, 917, 778, -427, 358, + -1411, 2032, -1372, 1891, -1784, 1830, -1808, -464, + 13973, 2016, 8606, -914, -7329, -1853, -2627, 2219, + 2628, 2161, 2185, 2414, 8857, -273, 1016, 2253, + 1070, 907, 367, -430, 574, 1039, 93, 170, + 255, -267, 550, -668, 287, 1827, 19833, 244, + -3731, 4, 21365, -127, 356, 643, 2016, 3290, + 1242, 46, -734, -2298, -316, -6618, -296, -1465, + 657, -1451, 469, 212, 2823, -2803, -11862, 931, + 44, 660, 1576, 1848, -10529, 2813, -1163, -260, + -195, 16320, -3447, -262, -76, -439, -3487, 1292, + 3330, -616, 1477, 1900, 8843, 81, -846, 6845, + -95, -112, -231, 129, 6982, 165, -3115, 2456, + 2032, 12201, 2747, 1691, -728, -1935, -239, 968, + 15578, -2260, -1813, 440, 2188, -3845, 1278, -136, + -1388, -7850, -462, 2921, -1740, -136, 164, 103, + -206, 32767, -459, 1249, 736, -590, -797, 628, + 612, 327, 396, 552, -128, -76, -258, -557, + 429, 170, 532, -347, 169, -593, 28319, -633, + -1339, -997, -258, 324, 628, 3254, -1118, 8902, + -63, 4762, -2820, 2429, 820, -46, -5366, -2193, + -9005, -1304, -597, -10143, 555, -3000, 294, -1577, + -871, -140, 726, 3700, -2226, 903, -253, 10330, + -2946, 656, 725, -668, -920, 1653, 1312, 1623, + -1150, -11970, 2157, 4532, -340, -8648, -616, -1429, + -980, -30, 647, -474, 442, 5098, 188, -1258, + -8172, -10927, -4207, -112, 2501, -3241, -1949, 159, + -525, 1090, 420, 10418, -11897, 1072, -78, -1028, + 3367, -2647, 3421, 2021, 2358, -973, 272, 27911, + 472, -402, 1397, -927, -1032, -1274, 848, 221, + -2745, -710, -692, -409, 1922, 142, 594, 1053, +-11350, -791, 3767, 1569, 541, 11921, 134, 368, + -948, -2689, 896, -1193, 1190, 8514, 1436, 1017, + 599, -3358, 4002, 12936, -675, 1044, -1210, 296, + -1109, 1992, 1282, 774, -13102, -608, -11145, 134, + 278, 944, -888, 350, -1574, 189, -2542, 3476, + -3018, 3368, -9304, -1839, 533, -2, 1057, 686, +-11819, -1146, -973, 1594, 3526, -2890, -1528, 3489, + -475, -259, -9610, -475, -984, -3559, -742, 408, + -130, -2291, 899, 12177, -1934, -162, -3238, 1610 +}, + +.cb2220l0 = { +-12528, 350, 1782, -474, 1439, -14269, -8, -1782, + -753, -1720, 167, -440, -2706, 222, -1629, -288, + 671, -111, 10270, 878, 152, 330, -1000, 639, + -1280, 1111, -2072, 1439, -476, 553, -2974, -614, + 1666, -466, 11811, -1393, 154, 624, -697, 176, + 1108, 504, 250, 572, -6, 704, 16, 647, + -1143, -1407, -411, 23745, 319, -189, -404, -641, + -86, -707, -770, -302, 13, -398, 76, -681, + -525, 354, -1225, -757, -23170, -484, -965, -430, + 13477, 898, 505, -17, 13812, -890, 357, 662, + 1000, -935, -60, 944, 400, -432, -221, 1047, + 307, -180, 5260, 16509, 650, -269, 1563, -6002, + -3082, 186, -3334, -5770, 1010, -394, 128, -699, + 537, -27, 1014, -531, -50, -163, -1664, -1026, + 732, -1296, 21856, 574, 416, -745, -443, -1382, + 272, 791, 1308, -308, -1636, 168, -10922, 119, + -1190, 1123, 1492, 1706, 1076, -2016, 3270, -994, + 876, -2316, -2992, 12625, -412, -159, 5249, 1424, + -304, 557, -431, -360, -340, -561, -292, 1748, + -224, 1789, -352, 386, 136, 76, 1309, -270, +-24204, -515, 1142, 2119, 1144, -173, 1008, -693, + -430, -1052, 1890, -12483, -11416, 2918, 1591, -1202, + -1782, -1335, 1354, 1703, -510, 4287, -854, 1153, + 2018, -518, -960, 11825, 1295, -563, 11252, 190, + 4078, 222, -3115, 3306, 747, 2638, 1015, -1674, + 8032, -2386, 573, -349, -832, 96, 9564, 11708, + -483, 1326, 1804, -2903, -2024, -234, 1009, 3229, + -232, 803, 275, 444, -629, -192, 381, -1289, + -109, -29019, 270, -420, -408, -466, 113, -537, + -266, 296, 180, 506, 1015, -565, -517, 1494, +-11053, 3968, -1735, 3474, -1991, -8326, 8075, 1740, + -3995, -1287, -2558, 1030, 3742, -618, -2600, -1783, + 2696, 1480, 1054, 341, 3762, 4225, -1742, -11582, + 4348, -8756, 493, -404, 3840, -1049, -683, -962, + 163, 10997, -97, -848, -4632, 2794, 2684, 2540, + 739, 8534, 3688, -878, 3138, 2576, 6444, 3674, + -2371, -218, 2864, 12270, 2866, 189, 4549, 4894, + -6378, -1050, -3166, -5897, 2245, 2803, -70, -1909, + 2783, 3951, 153, 11221, -658, 12780, -238, 3418, + -2235, 754, 311, -739, -2414, 702, 1076, 303, + -320, 47, -3288, -234, -1376, 3022, -103, -1780, + 716, 11886, 10942, -5402, -5431, 1196, -624, -885, + -652, -3248, 74, -435, -686, 154, 8675, 3325, + -1779, -341, 564, -901, 1335, -639, 3494, -1820, + 290, -92, -3088, 4775, -2140, 2334, 710, 10536, +-15042, 14823, -1082, -1045, 1008, 734, 241, -1048, + -933, 245, 913, 114, 322, -1798, 246, 1067, + 348, 408, -183, -728, -12915, 685, 1525, 1694, + 183, -168, 12703, -1268, 1613, -2072, 1546, 743, + 2356, 2135, -550, -153, 1327, 2, 12487, -3111, + 2347, -1722, -300, -193, 2222, -1928, -658, -384, + -5738, -1141, 3634, 10312, -69, -1549, 10879, 1795, + -361, -1838, 143, 1202, 327, -15549, -1268, -194, + 3284, -12, -344, -2042, 1663, 334, -798, -873, + 1736, -324, 195, -417, -382, -22936, 812, -478, + -962, -451, 730, 382, -135, 1311, -290, 122, + 148, -775, -305, -32218, -84, 98, 374, 369, + -44, 923, -432, 156, -1471, 236, -39, 143, + -146, 835, 135, 229, -297, 1690, 6786, -12169, + 815, -176, 1868, -9, -3052, 108, 114, 260, + 11337, -2689, -132, 765, -239, 54, 691, -9737, + -627, -474, 12212, 2222, -7595, -239, 1793, 2115, + 563, -2390, -1991, 2906, 675, 923, 146, -3605, + 981, -1725, 92, -562, -21192, 304, -450, -323, + -889, -726, 688, -1186, 2590, 466, 326, -734, + 308, -782, -3219, 963, 454, 1348, -513, 953, + -1414, -320, 1012, -1148, 1185, -17356, -15, 1546, + 1346, 2182, -2457, 1426, -1690, 155, 8793, 1394, + 510, 2608, -203, 2697, 608, 2612, -13542, 177, + 4642, -824, 1877, -1864, 1681, -1033, 1487, -749, + 356, -11, -1, -366, -215, 1531, -38, -922, + -378, -296, 1245, 19967, -2389, -459, -3729, -163, + 6578, 354, -1471, 195, 353, 1831, -605, -2291, + -359, 947, 8409, 3454, 12416, 2434, 3485, 40, + 350, 1640, 738, -9827, 935, -171, -944, 1407, + -399, 571, 2805, -13108, 784, 678, 2405, 328, + -417, 1188, -1596, -649, -1358, -1130, 341, 202, + -2459, 11307, -2250, -3518, -1812, 3338, -924, 10027, + 3004, 703, -184, -666, 223, -1644, -7221, 3507, + 10108, 1324, -412, -371, -92, 2496, 3182, 10, + 10269, -998, -1010, 610, 3296, -1842, 407, 406, + -1609, -181, 2202, -662, -1450, 1360, 1488, -212, + 1501, -214, -555, 168, 275, 301, -950, 3272, + -323, 20632, -21, -1729, 11013, 2149, -9278, 6735, + -593, -7374, -430, -2776, 2343, -1374, 519, -4876, + 827, -2477, -1971, 1249, -23380, -1810, 199, -761, + 2182, 1654, 447, -488, -1219, 364, -53, -382, + -989, 154, -545, -872, 776, -211, 7706, -767, + 8006, -138, 1989, -180, 306, 486, 1112, -648, + -12, 1538, -300, 2458, -5833, -1181, -7680, -6700, + -621, -308, -29995, 602, -24, 94, 752, 517, + 86, -249, 1058, 704, -404, -387, 106, -632, + -159, 1275, -197, -1263, -1210, -1689, -10488, 1950, + -2037, 5974, -3960, 38, 1284, 2851, -2813, -1613, + -1646, 10164, 138, -2956, 196, -118, -484, 860, + 124, -262, 30, -1448, 128, 287, 327, 590, + 27272, 391, -738, -1631, -481, -1511, 82, -574, + -737, -614, -447, -80, 292, -19, 252, -2, +-28117, 332, 141, 1485, -154, 1382, -1755, -422, + -1692, -2144, 910, 1004, 1894, -1537, 897, -458, + 19483, -1321, 2280, 622, 288, -2253, -1001, -976, + -408, -394, 132, -250, -428, -22, 140, 287, + -141, 30981, -293, 631, 729, -2, -231, -127, + 377, -879, -294, -107, 253, -964, 1258, 570, + 71, 9421, 8358, 9295, 8354, -546, 1153, -1807, + 1577, 2911, -1808, 1808, -1631, -1348, -6977, -382, + 1625, -2793, 10633, 1977, -1793, -12480, 1, 2010, + 23, 423, 1102, -1920, -478, 1845, 1016, 465, + 758, 800, -1540, 5448, -10472, -2749, -989, -6362, + 9283, 373, -2560, -5478, -1618, 20, -564, -1074, + 4075, -471, -515, 409, -2069, 359, -788, -11618, + 2524, 917, 2757, 243, -3261, 6922, 6268, -3148, + -2804, -3412, -4262, -1903, 1043, -12255, -162, 1598, + 496, 454, 1401, -1635, -12711, -673, 3392, 1255, + 1602, -1206, -297, -2066, 3009, 1149, 1285, -1307, + 412, 27971, 183, 569, 1304, -706, 824, -635, + -358, -340, -28, -1344, 955, 14, 676, -243, + -20, -11947, 1350, 8122, 196, -10161, 4925, -3764, + 1661, -401, 145, 253, 680, 718, -614, -613, + 498, -293, -4257, -684, -14853, -10522, 698, 1537, + -2016, 1162, -2684, -1578, 8, -238, -3214, -2749, + -1577, -1187, 113, -1457, 1068, 590, 25, -644, + 1000, 2430, -1612, 13246, -2684, -1642, -4648, 816, + -1103, -7556, 5753, -3998, -1338, -776, -1958, -9652, + -1288, -290, -4240, -2788, -8191, 1625, 2558, 1238, + -1824, -39, -3129, -8916, -3302, -5632, -1768, 866, + 708, 684, 3530, -8772, 1485, 677, -10398, 686, + -852, -6974, 5286, -2658, 612, 1180, -3367, 4285, + 5708, 1416, 166, 2787, -3697, 1431, 1648, 7942, + -544, -1064, -514, -840, -870, 1246, -3582, -9310, + -3802, 4025, -8251, 5978, 132, -619, 2792, 9786, + 1244, 242, -1948, -4701, -5904, 951, 7486, -3494, + 48, -4468, -2403, 6090, -2343, -4175, 1336, -2546, + -281, -736, -1758, -1720, 11066, -918, -1354, 3885, + -33, -4116, 1246, -218, -8082, -766, 7796, 1505, + 1559, -964, 1741, -454, -1628, -762, 3034, -804, + -888, -9682, 9603, -2556, 2874, -5456, 3066, -7747, + 956, -660, -1538, -381, -760, 1747, 547, -517, + -697, -1411, 410, -514, -3988, -219, 13358, -2393, + -280, 11230, 2640, 795, 2534, -8094, -1838, 71, + 16, -203, 4224, -96, -2829, 2010, 1961, -1312, + -1266, 3952, 6894, 6996, -8062, 4708, 1193, -3439, + 1549, 935, 170, 614, -868, 43, -246, -188, + -940, 130, 126, -736, 697, -510, -56, 1596 +}, + +.cb2220l1 = { +-13582, 1049, 15596, -101, 707, 2677, 542, -522, + -636, 194, -2361, -1252, 524, -32, 227, -419, + -652, -601, 84, -10428, -1417, 13117, -573, 3774, + -3632, 2025, -1237, -692, -1486, 192, 1221, 452, + 436, -764, -2636, -153, -685, 118, -424, -635, + -458, 209, -577, -12042, 4240, -10861, 49, -1534, + -991, -2416, -280, 2095, -1841, 1278, -94, -423, + -572, -949, 734, -1087, 12449, 6514, -4582, -7845, + -3722, 1446, 2531, -1238, -2070, 1515, -1331, 2382, + 1066, -1298, -1189, 6811, -1868, -1082, -1732, 356, + -2622, 493, -3345, 1367, 1737, 4497, -14734, -1350, + -354, -1340, 8478, -1152, 1832, 1793, 830, 974, +-13918, 522, -1472, -2502, -2625, -157, -360, -17, + -830, 673, 36, -1339, -14860, 522, -13377, 851, + 937, -1103, -44, 408, -364, -953, -392, 1837, + 2342, 1236, 111, -218, -919, 985, 10077, -1065, + 1840, -124, 3780, -11015, 204, 437, -830, 6712, + -1720, 288, -991, 1094, 5647, -1296, -2284, 1642, + 1000, -35, -115, 208, -244, -1099, -832, -2092, + 802, -163, 3343, -964, 314, 126, -1204, 754, +-17838, -826, 4414, 8331, -770, 1246, -3500, 1680, + 833, -108, 494, -910, -6314, -2832, 2553, -6230, + 1165, 3631, -1717, 2404, -32768, 520, -38, 1228, + -708, 58, 260, 771, 588, -448, 389, 156, + 606, -830, 400, -488, -188, 536, -1428, 11982, + -156, -1407, 1796, 1036, 905, 1371, -1472, 325, + 3098, -1436, 6449, 2105, -11183, 1632, -1848, 1019, + 1247, 1308, -1351, -823, 1679, -651, 978, 296, + 1088, 3965, -1414, -11838, 139, 8664, -3452, -1804, + 3088, -2044, -221, -1347, 1232, -909, -1323, -1409, + 1399, 2557, 14552, 1535, -5088, 1699, 1012, 3333, + 3940, 2294, 1189, -2256, -484, -3307, -1333, 464, + -305, -744, -24, -20464, 332, 2968, 308, -649, + 292, -402, 1226, -2575, -1505, -100, 1413, 733, + -1024, 616, -121, -322, 67, -161, -708, 251, + 462, -26697, -1112, -1381, -324, -286, 1091, 662, + 15830, 13124, -1049, -1816, -355, 1848, -801, -1710, + 2513, 458, -798, 386, -726, -356, -1240, -1133, + -388, 631, 91, 1867, 2511, -306, 3097, 14399, + -571, 2191, -2916, 2850, 761, -2442, 698, -2193, + -2739, -1914, -4077, -4631, 12702, 333, 1162, -6248, +-12466, -310, -107, -2465, -163, 1970, -998, -1253, + 2007, 79, -426, -276, 365, 568, -520, 23642, + 276, 1059, 184, 1081, 650, 2286, -191, 883, + -1946, 246, 64, -225, 800, 910, -136, 1187, + 955, -15604, 12847, -747, 874, 506, -646, 1920, + -449, -321, 1152, 1341, 1653, 341, -32, 907, + 673, 1045, 1245, -499, -10331, 4683, -1121, -3164, + 3382, 6397, -1341, -769, 1186, 229, -1354, -7370, + 155, 1858, 5617, -3487, -247, -783, 724, 508, + 14029, -528, 1853, 1572, 580, -708, 528, -1394, + 8922, 2284, 550, 3084, -1726, -3235, -700, 7132, + -3540, -200, 3288, -815, -2189, 1232, 2412, 2088, + -1101, 12592, 806, 1508, 1741, 13, 1124, -3883, + -687, -8180, -3094, -3346, 1781, 11836, -657, -3469, + 1429, -1822, -3433, 87, 3871, 651, -965, -1757, + 6778, 109, 112, -131, 710, 11943, -12107, -3460, + -726, 1002, -3803, 580, 2756, -1293, 116, 457, + 581, 3834, -1678, -977, 1242, -2040, 232, -10034, + 1644, -2290, 1368, 172, -3012, 1423, -2620, 3608, +-10831, -303, -1610, 3246, 562, 5212, 448, -877, + 954, 688, -8981, 579, 717, 1315, -952, 6817, + 662, 3218, 7213, -2116, 10446, 1012, 2270, -858, + 10, -1066, 10618, 6108, -547, 3221, -893, 3888, + -1088, -10085, -247, 1064, -3500, 3123, -2480, -2128, + 2788, -2253, -9756, -472, -166, -680, 727, 74, +-14151, -189, -1734, 610, -1169, 845, 94, -786, + 394, -581, 500, 1981, -10940, 354, 500, 399, + -1952, -373, 2197, -4712, -2582, 2751, 654, 613, + -1254, 1406, 2056, -12518, 1583, -582, 4834, -1541, + 508, -20580, 270, 1214, 515, -1082, 5, 7, + -533, -28, 1270, -1307, 497, -57, -331, 933, + 92, -856, -10458, -4576, -9991, 2426, 6552, -3022, + 279, -562, -192, 1878, -2237, 4978, -1753, 332, + -1462, -853, 238, 478, 9746, -7385, -10290, -8278, + 457, 3121, 841, 48, -3745, -1298, -637, -1820, + -468, -248, 1400, 394, -125, -950, 11524, -1860, + 426, -773, 12669, -1620, -158, 1625, 1045, 768, + -66, -12, 1625, -770, 559, 54, 593, 14468, + 14994, 490, 543, -811, 700, -277, 900, -178, + -2000, 475, 241, 950, 106, -1260, 874, -862, + 18907, -1947, -844, 205, 1253, -83, 1966, 2300, + -2694, 852, 2450, 661, -334, -518, -1136, -2377, + 325, 1152, 511, 881, -22205, 898, 574, -582, + -265, -1362, -253, -40, -780, -1967, 469, 1484, + -818, -926, 958, -415, -7934, -330, 330, 1439, + 1643, 77, 1034, -156, -12094, 3782, -5725, -520, + -598, 2345, 3506, 5333, -322, 99, -48, 1490, + 20, 11393, 3468, -1144, 7013, -3728, 7145, 1432, + 1810, 26, -912, -6530, -1079, 1771, 95, 4007, +-11346, -43, 249, -14616, -249, 1, -725, 244, + 1053, 1815, -626, 408, -344, 1972, 2222, 2288, + -2324, -411, -3993, 494, -706, -5078, -11695, -3645, + -2090, 2465, 5893, -5096, 6815, -537, 5003, 1258, + 185, -1555, -875, -2047, -170, -433, -194, -1020, + 349, -724, -31811, 197, 251, -418, -222, -618, + 278, 554, 363, 183, -898, 14, 350, 745, + -2054, -1623, 806, -770, -1246, 1594, -54, -18501, + 1516, 840, -86, 484, 514, 1209, 978, 564, + -537, 34, -431, 128, 938, -1807, 832, -90, +-29509, -642, 1397, -52, 523, -393, 216, 908, + 9, -63, 710, -949, 3, -184, 175, 613, + -687, -408, 27, -855, 18258, 1282, -948, -219, + 2374, 1668, -4567, 1063, -2045, 12026, 461, 3074, + 1050, -1788, 169, -13442, 612, 19, -2019, 685, + 452, -152, 299, 310, -2327, 348, -215, 1634, + -201, 2162, -10300, 12452, -3733, -420, 2388, 518, + -2308, -160, 1552, 3347, 1650, 3293, -1108, 2065, +-12618, 20, -42, -643, 202, -1298, 251, 2489, + 1322, 2362, 3698, -190, 592, -12484, -937, 2072, + 1531, 302, -409, -899, -1016, -388, 1103, 30006, + 789, -1609, -548, -1002, 1055, 605, -955, 1557, + 452, -623, 810, 597, -696, 10628, -1174, 606, + 2628, -553, -2297, 6668, -2600, 787, 3504, -3606, + 4087, 1052, 6276, -7619, 337, 2565, -13, 1205, + -124, 1222, -28082, -79, -553, 628, 542, 1315, + -609, 322, -895, -377, -694, 610, 239, -152, + -2901, 9890, 716, 1030, -3306, 988, -738, 562, + -2209, -1676, 4507, 1165, -12924, 866, -154, 3664, + -367, -2580, -7286, -572, 2167, 118, 508, -4429, + -480, 842, 2489, -1636, -2042, 1125, 1847, 2586, + -5639, 3361, -760, 11189, 623, -282, 1353, -279, + 515, -816, 713, 322, 417, -2820, -1114, -1563, + 401, -21604, -1300, -972, -2298, -483, 2176, -830, + 2135, -4084, 1095, 1950, -1937, 539, -374, 3197, + 682, 472, -1368, -8095, -12026, 4833, 5586, 467, + 2400, 148, 381, -138, 954, -459, -724, 970, + 156, -1955, -1363, 560, -761, -1708, -1599, -17408, + -1064, -1372, -500, 1160, 735, 441, -773, -228, + 420, -1128, 260, 930, 12879, -926, -231, 1355, + -850, 559, 11377, -1729, 2478, 961, 336, 1056, + 5081, 9788, -555, 4067, 8664, -2720, -1462, 3012, + -7280, 965, 1462, -4703, 3649, 2084, -699, -262, + 408, -188, 2193, -2216, -4509, -736, -1039, -4848, + -8243, -7958, -172, -1318, 9566, 4665, 3363, -3672, + 1581, -551, -2024, 1630, 1543, 90, -1728, -792, + -1799, 2571, 80, -412, -301, -2870, 1796, -5327, + 111, 17342, 592, -2108, 477, 1541, 1266, -1062, + -215, -2210, 223, 1215, -197, 87, -18340, -67, + 804, -398, -118, -3457, -741, -1935, -704, -274, + 566, -872, -1821, 12874, 5057, 2069, 1742, -6205, + -6115, -1614, -294, 187, -5210, 1734, -1466, -2162, + -2266, -642, -148, 440, 2, 233, -319, -637, + -734, -230, 301, 508, -433, 311, -313, -1206 +}, + +.cb2220s0 = { +-15119, 7508, 1337, 4182, -2914, -3733, 2686, -470, + 2249, -3901, 1444, 3805, 99, -1771, -354, -903, + -2755, -709, -4980, 214, -2750, -652, -1042, 1434, + -1090, -612, -2574, 1274, 1310, -760, 1420, -112, + 2776, -4843, 15060, -4929, -3942, -5721, -1628, -1142, + 3023, -1435, 1402, 1010, 623, -3527, 2624, 184, + 988, 98, 340, 16676, -1262, -1162, 3183, -4816, + -592, 1019, -1406, -2478, 2371, -1004, 3944, 803, + 5665, -2261, 16427, 349, 3113, -916, 442, -1754, + -3551, -1351, 1563, -1316, 532, 343, -392, 1509, + -717, -122, 2462, -929, -185, -683, -18780, 2682, + -123, 518, -379, -5160, 245, 1940, 13964, -12311, + 590, -30, 159, -1558, -1940, 36, -1528, -515, + -1178, 856, -395, 29, -5854, -12943, 13286, -2572, + 1049, 768, 3292, -3921, -52, -462, 1968, 4933, + 630, 930, 1026, 2606, 319, -277, 6333, -2119, + -4700, 2164, 1583, 154, 2107, -1467, 339, 634, +-17240, -595, -3525, -2690, -1788, -476, -41, 165, + -1016, -1456, -348, 11289, -2920, -3804, 2357, 12012, + 3848, 1796, 2164, -5555, 4527, -201, 965, -4893, + 3419, 6441, 1691, -77, 348, -769, 27319, -345, + -336, -541, -320, 972, 926, -1026, 1052, 702, + 224, 76, 742, 220, 6292, 8625, -3742, 4139, + -5989, -5615, -641, -231, -837, 6156, 4141, 3792, + 4746, 9972, 1800, -397, -2237, -2218, -7595, -2761, + -496, -1451, 1178, -970, -1226, 2527, -2105, 1778, + 1446, 1986, 9970, -13107, -985, -1142, -1367, -329, + -4498, 590, 36, 2073, -1069, 862, 133, 2516, + -27, 4494, -11602, -1638, 2524, 1449, 5684, -611, + -9452, -2618, 5006, 3481, -639, 379, -2333, -498, + -713, 382, 784, 269, -5692, -350, 524, -18705, + -1042, -1349, 1210, 1770, 3964, 4908, -1131, 17535, + -788, -1896, 30, -2682, 1044, 1604, -3740, 18, + 1771, 331, 4279, 2634, -368, -447, -6995, -1224, + -688, -5368, -236, -8872, 2449, -12189, 4465, 1895, + 2484, 1315, -5446, -457, -575, 101, 2356, -1585, + 3204, -104, -7244, -1678, -801, -2620, -4603, -11876, + -1787, 2962, -1796, -3385, -411, 5796, 2900, -562, + 835, 293, 7127, 4939, 721, -2972, -482, 121, + -2694, -2277, 412, 12770, -342, 718, 3306, 502, + -7281, -307, 552, 7158, 3289, -5051, 5230, -1185, + 3024, -942, -1347, -283, -13937, -208, 2576, -906, + 1848, 5692, -2434, 175, 7837, 1872, -4536, -3341, + -957, 14787, -1598, 9058, 3776, 407, -1734, 1259, + -3011, -131, -3589, -614, 272, -2968, -1611, 3645, + -8126, 2120, 4868, -5462, -13235, -3452, -6077, 5064, + -1593, -1395, -2427, -1139, -958, 1585, -1330, 2178, + -778, 3545, 2836, 7712, 5993, -432, 3575, 929, + -7951, 115, 2180, 3904, -193, 1556, -252, -913, + 2574, 11948, -4525, 1391, -8513, 4540, -12815, -3379, + -4676, 1838, -5676, 1321, -6168, 1397, 1020, 438, + -141, 3424, 392, -512, -1614, -1396, -318, -2451, + 1545, -7132, -1763, -424, 3575, -828, 19216, 1978, + 1624, -1969, -1667, -772, -2031, -781, 1732, 244, + -212, 416, 900, -8960, 1002, -1077, 4667, -3527, + 1586, -13109, -2442, 3829, 4358, 1056, 2960, -1087, + -662, 4775, -6316, 6157, -3736, -2040, -187, 904, + 1254, -636, 2032, -734, -1271, -2691, 3376, 564, + -7769, -5482, 840, 14171, -5828, -966, 1685, -10192, + -388, -434, 3706, 594, 2188, 365, 209, 298, + 1825, -236, 12762, 1644, 3199, -468, 12876, 130, + -2169, -3406, -3571, -4655, 2339, 10757, 1292, 2920, + 289, -314, -591, -1631, -1778, -1296, -254, 469, + -9408, 1154, 334, -4, -1922, 2787, 317, 416, + -1703, 14075, 1601, 638, -2260, -973, -824, 2816, + -2954, 3282, -3716, -882, -3447, 3058, -6701, 1233, + 177, 3579, 3508, -3539, -10511, 7507, 7608, -1928, + 2482, -719, 2278, 5167, 9828, 10572, -3635, -2750, + 3407, -116, 3343, -3432, -3375, 982, 903, -3239, + -444, -1574, -333, 9613, -1914, -532, 1879, -78, +-17944, -7029, 1586, -3122, 360, -401, 1219, -2086, + 3066, 878, 5780, -948, 102, 1952, 418, -416, + 1002, 1380, 1297, -92, -640, -555, -1159, -28517, + -1757, -696, 124, -618, 1590, 300, -598, 924, + -190, -1734, -4196, -5345, -14068, 5971, 8293, -3878, + -1448, -1777, -174, 921, -1555, -866, 560, 232, + -1914, -4002, -772, 1960, -4945, 3424, 6492, 3675, + -800, 5346, 4404, -639, 10697, 1631, -1446, -4469, + -7804, 3721, 4824, -620, 1099, -2956, 5175, -2453, + -4894, 2562, -1842, 4940, 1391, 2818, 1095, -4285, + 6469, -1966, -14564, -2232, 592, 5570, -2682, 2651, + 4678, -7444, -2387, 6812, -12757, -5664, -42, 134, + -2861, -1780, -158, 1410, -4990, 673, 2083, -2639, + 3019, -2, 8305, -1981, -2114, -54, 2892, 1659, +-14913, -74, -1092, -1187, 2465, -2218, 791, -608, + 3077, 26, -1096, -1692, 3234, -7116, -1835, -5244, + 398, 10137, 698, 2298, 498, 7060, 6430, 1393, + 2540, 487, -1534, -1926, -5139, 3425, 4533, 5067, + -535, -924, 938, -1799, 16120, 2037, -3727, -821, + 2986, 2314, -223, 1358, 9, 2697, -1806, -940, + -3630, -1843, -2776, -2246, 580, -1678, 2427, 2126, + -1935, 2956, 849, 18234, 638, 342, 1036, 249, + -24, 2713, -1973, -134, -4469, -2014, -6162, -19776, + 703, -50, 2295, -2294, 1971, 1179, 1014, 2374, + -1480, 1513, 630, 1542, 24716, 3534, 2926, 662, + -2886, -521, -348, 402, 1112, -371, 1587, 1822, + 1880, 1284, 302, 1873, 1284, -924, 6420, 4650, + 7986, 427, 361, -8276, 304, -11911, -1305, -2018, + 189, 258, 839, -942, 479, -3162, -1195, -1138, + 1560, -1850, -5304, -10132, -10533, -1301, -3147, -680, + 56, 4260, -6867, -1350, -1094, -1385, 1831, -2, + -941, 3740, 7701, -855, 3304, 3444, -4467, 269, + -4092, 588, 13957, -1566, -3561, 1936, 2816, 2982, + 1804, 2710, 419, 685, 4468, 488, -9520, -2738, + 3974, -9978, -1681, -2418, 2340, -717, -899, -2855, +-10470, 1030, -2346, -5555, 2559, 2180, -5324, 1832, + 10294, 342, 11318, -2376, -3904, -1524, -3806, 1078, + -1896, 7199, -3522, 1364, 2291, -911, -156, -4327, + -778, -30451, -577, -158, 560, 2749, 799, 2689, + 337, -301, -1218, 1243, 687, -880, -419, 40, + -280, 4, 1834, 9908, 1953, 408, 1080, 8777, + 3861, 552, -6906, -3546, -6666, 35, -1903, 4788, + 5080, 2865, -233, 1031, -4519, -13752, -2417, -1742, + -7389, 3191, -626, -411, -7351, 3063, -1801, -4377, + -2974, -124, 2778, 2733, 349, -1191, -6528, -1699, + 6907, 239, -2765, -5706, 3627, 2096, -20, 2285, + 7164, 3523, -11582, 3616, -614, 6266, -285, 3643, + 1506, 3665, 1261, -2338, 418, -5062, 4893, 2945, + 1923, -2990, -4531, -8858, 2769, -5029, 2202, 3337, + 10703, 716, 5614, -14982, -2366, -5415, 25, -1665, + 4353, 3060, -2159, 1005, -1587, -368, -949, -2788, + 1063, 1307, -59, -46, -6337, 500, -1194, 2914, + 2372, -1393, -1914, 3820, -1160, -135, 3777, -14151, + 5208, -2290, 5738, 1018, 385, 1883, -2626, -9289, + 1082, 1558, -1756, 2720, -519, -13050, -3672, 1759, + -13, 3471, 4071, -5977, 167, -4210, 2219, 1344, + -2412, 4497, -6946, 660, 8774, -3141, 6080, -4478, + 2520, -609, -3080, -741, 7864, 7428, -333, 1154, + -1849, 1478, 460, -338, -6651, -2480, 1692, 2104, + 1642, 2720, 1017, 2759, -1822, -2668, -2265, -1019, + -8926, 1487, 733, -15128, 5543, -4214, -7044, 666, + 7108, 2222, -2454, 4995, 5108, 1481, 2242, 5743, + -487, 9669, 295, 3539, 4836, 487, -1541, 824, + -5946, 6692, -368, -1390, -6103, 4545, 2671, -12272, + 3160, 760, -2080, 3523, -2752, -2940, -718, 2202, + -5523, 2346, -5580, -5007, 6212, -5406, -11348, 1272, + 5389, 2331, 3691, -1184, -3585, -4500, -603, -38, + -5285, -531, 4844, -3850, 3944, -6525, -5723, -2313, + -985, 879, 578, -3217, -3600, -2814, 1432, 11568, + -1461, -1761, -4110, -4104, -103, -1803, 5195, -1477, + 1348, 107, 3902, 1215, 3522, -3404, 9098, -237, + 68, 34, -2524, -12040, -6183, 2122, 470, -1257, + 346, -232, -1725, 5913, -1525, -5873, 1846, -11368, + 1043, -1027, 4201, -3864, -4294, 7756, 1847, -3688 +}, + +.cb2220s1 = { + 32767, -2256, 16, 2156, 267, 1128, 1394, -1936, + -488, -405, -345, 1068, 578, 1504, -1192, -405, + 292, 1149, 4243, 152, 1036, 1782, 2655, -23349, + -1100, -1933, 354, 966, -1554, 1173, -1186, 495, + 618, 1009, -2715, 461, 5974, 939, 3552, 1325, + 3385, -956, 2177, 2101, -145, -1000, 2326, 2466, + 2822, 15822, -581, -713, 4398, 828, -3249, -3942, + 1990, -862, 2272, 348, -2972, 241, -2678, -1881, +-22307, 417, -587, 312, 280, -2524, 2380, 299, + 3931, 178, 2910, -2544, -356, -786, 546, -73, + -862, 240, -1653, 1286, -3875, -2072, -1477, 16800, + -1148, 2099, 3216, 5174, 2177, 3042, -796, 414, + -506, 883, 1837, 1451, 2864, 850, 2395, -414, + 3254, -1937, -16379, -3976, 2178, -1473, 4759, -832, + 8890, 3324, -3053, -407, -1530, -431, -1220, 128, + -3472, 980, 52, -14716, 1732, 1931, -6518, -1784, +-11113, 4466, -24, -8559, 105, 5478, -4116, -2213, + -3006, 1738, -4189, 3310, -753, 1869, 580, -885, + 3089, 8146, -4990, -1825, -524, 3620, -6920, 621, + -1064, 4633, -1509, 80, -10949, -2752, 476, -3684, + 3547, -1967, 3364, 2887, -729, 7921, -4216, -3681, +-14417, -3978, 261, -1146, -1124, -901, 777, 783, + -2, -989, -1582, 3988, 7785, -6371, -2258, 3344, + 354, 13289, 3339, 316, -3186, -2088, -1951, 310, + -545, -704, -40, 4416, -392, -1033, 5650, 99, + -3008, -3716, 2448, -3758, 9463, -1793, -130, 1705, + 6501, -2214, 2970, -10476, 564, -5952, -541, 2077, + -90, 6588, -2858, -1733, -9247, -345, -3170, 4986, + 3353, -4868, 8873, 113, -5223, 1562, -163, -2446, + -4459, -8052, 1106, -10883, 1185, -1756, -152, 3109, + 181, -1427, 8291, 11419, -6265, 2116, -469, 5150, + 1355, 182, -740, 779, -7754, 1868, 144, 3936, + -60, -784, -231, 879, 17032, -2273, 1886, -538, + 1015, 1798, -633, 1090, 1910, 128, -6094, -1946, + -1570, -727, -18457, 498, 784, -4419, 1656, -21, + 154, 2430, 3815, -41, -2708, -1594, 228, -784, + 7284, -452, -7634, -12868, 3564, 5473, -1244, 2231, + 28, 4321, -1464, 1402, -1358, 2241, 656, -1128, + 1160, -2352, 3641, -680, 1816, 6864, -42, 1269, + -280, -1265, -2048, 238, -653, 13571, 3874, -269, + 7977, 2238, -1246, -2066, 4741, 1706, 3498, 595, + 2559, 55, 593, 1681, 1612, 43, -2756, 2702, + 2439, -2471, -809, 1890, 17032, -787, -4280, 1167, + -1926, -4973, -1181, -2764, -4151, 2962, 3444, 844, + 2446, 14013, 3326, -1195, -1829, 1588, 1765, -3140, + 8562, -14425, 4040, 2003, -738, -1032, -3314, -2236, + 548, 768, -2348, 436, 1755, 31, -4616, 1259, + 269, 1543, -1393, 5338, -16463, 2900, -2480, 1659, + 217, -5864, 3878, 5268, 1244, -520, -1202, 1238, + 182, -1049, -695, -320, -6832, -5904, 2914, -2616, + 2586, -10958, -3258, -1846, -4633, 2371, 3251, -3583, + 2631, -4162, 3035, 2718, 616, 2890, 206, 16128, + 979, 3551, -6864, -3221, 5881, 3692, 1718, 234, + -2844, 1668, 102, 2687, -838, 988, 1116, 533, + 4026, -7235, 5972, -13781, -3394, -3518, -294, -6383, + 1675, 4507, 5444, 385, -1931, 930, 699, 1639, + 415, 6720, 7854, 1514, 3192, -2253, -14786, -1307, + 871, 1329, 1881, 6628, 2851, -85, -2284, -4538, + -837, -2232, 269, -2227, 13930, -2063, -7540, 8978, + 1195, 2717, -1282, -972, 1305, 3864, 2412, 2308, + -4824, -3282, -864, -489, -1458, 2192, 15903, 2460, + 2792, -4137, 1034, -359, 5, 2297, -6, -3859, + 478, -1535, 2080, -741, 2030, -603, -2640, -1902, + -8208, 3818, -1273, -8138, 2015, 9169, -3440, -1779, + 4076, -576, -93, -1718, 744, 2563, 6744, -3841, + 1355, 1590, -4196, -13924, 356, 13381, 2552, -2862, + 2790, -578, 3562, 2711, -686, -3783, -489, 1230, + 896, 1208, -1101, -3482, -2478, 772, 1254, 320, + -1825, -327, 1070, -1712, 295, -18141, -2618, 1537, + -603, 3782, -1272, -1901, 414, 169, -6574, -6966, + 2711, -3292, 13204, -1324, 3620, 4962, 2835, 4177, + 4861, -2378, -5534, 3701, -4224, -631, -3199, -653, + 4785, -1045, -2097, 580, 2190, -140, 48, 3075, + -1346, -810, 2016, 566, -2543, 235, -5930, 1956, + 481, 19003, -3938, 6489, 2697, 4796, 3435, 7102, + 3062, 1460, -5814, 2723, 4181, -4979, -2534, -2058, + -136, 3554, -2684, 15252, 4112, -3146, 2812, 7182, + -2642, 5443, -1043, -803, 2786, -1622, 1988, -780, + 1482, -13015, -1762, -1377, -4005, 161, -9568, 8166, + 1832, 330, -6484, 945, -4388, 1090, -524, 1556, + -582, 320, 770, -938, -8757, 977, 1084, -7062, + 3552, 775, -4708, -2281, -552, -10027, 4263, 1197, + -672, -93, 5716, -3825, -4526, 1781, 9799, 4450, + 1981, -3149, -9664, 3119, 3794, -91, 6710, 840, + -1098, 11310, -2933, 785, -2573, 748, 1803, -1401, + -1547, -4118, 849, -580, -1404, 1536, -9382, -1610, + 2335, 403, -2939, -3015, -3753, -7593, 1640, 3346, + -2594, -8028, 5485, 2189, -3369, 2106, 5369, -2573, + -515, 1459, 6996, 1344, -389, -7009, 10332, -840, + -3869, 901, -6449, -2348, -2461, -4103, -810, -2060, + 1040, 117, 32241, -231, 945, 999, -1183, 180, + 1443, 188, 855, -1634, 774, -202, 99, 1714, + 286, -849, 1968, -9743, -15458, -859, -3726, 2257, + 355, -167, -1674, 1808, -488, 1118, -1416, -1685, + 2928, 1471, -1145, -536, 2307, -972, -1191, 1625, + -1436, 378, 20178, -638, 1826, 472, -300, -845, + -1045, 1074, -1041, -510, -39, 516, 4548, 2741, +-10197, -2336, 3828, 2093, -4148, -9138, 4239, 2520, + -3536, -3807, 2998, -2226, -6898, 4838, 2552, -2024, + -5579, 1370, 11706, -7626, 1566, 989, -4934, -1345, + -5962, 4259, 1158, -3712, -2710, -1037, 105, -2733, + 1068, 3682, 3904, 2044, 184, 537, -3438, -1376, + 332, 17812, -3170, 2386, -2090, 3481, -1352, 431, + -1016, -1062, -564, -1752, -2602, 1299, 6720, 789, + 1275, -9801, 5320, 2327, -4048, 4443, -7820, 1112, + 1232, -1139, -920, -744, -845, -3754, 5958, -5388, + 3336, -3578, -4027, 688, -7043, -136, -163, -1395, + 13400, 1729, -1862, 2612, 321, -3874, 947, -990, + -3164, 11487, 46, -1978, -2139, 1222, 3897, -9664, + 3692, 5431, -3364, -3706, 180, -4009, 2563, -313, + 3228, -1631, -9763, -9184, -6058, -4594, 1040, -3323, + 321, -3233, 5035, -1919, -5525, 1899, 1196, -1834, + -391, 549, -2114, -1436, -2624, 2441, 618, -27606, + -841, -936, 1067, 1157, 230, 784, -755, 1798, + -219, -1026, -1119, 320, -2611, -1382, 8776, 1151, + 3739, -607, 2997, -7704, -5870, 1800, 1357, 4973, + -9674, -5182, -50, -886, 2056, -802, -1909, 574, + -1716, -6388, -2882, -3526, -3188, -543, 244, 9648, + 5129, -5069, 598, -9049, 1834, -3375, 1369, 1461, + -1295, -380, -274, 7258, -9353, -2401, 11915, -5087, + 1505, 4211, -719, -902, 1762, -168, 642, 699, + -2067, -933, 1092, -958, 715, -1978, -1968, -1613, + -1263, -777, 1170, -9652, -9570, 612, -3935, 237, + 386, 4237, -1468, -10172, -4964, 2919, -6428, -7184, + 119, 3610, 59, 3168, -5474, -853, -5735, -1765, + 3063, -1352, 944, -1934, -3500, 9282, 5920, 784, + 90, 275, 3211, 2418, -8570, -10498, -2026, -1020, + -2989, 1511, -41, -11462, -1980, 5296, 2614, -21, + 770, -156, -2817, -4748, -8672, 3447, -7231, 4598, + -1347, -689, -3198, 434, 56, -2065, 1798, 13761, + -533, -1280, -796, 2481, 56, 1377, -5473, 9116, + -1185, -602, 2547, -3693, -8880, 2978, 9093, 1829, + 4844, -649, 316, -162, 1520, -5814, 4860, 199, + -1330, -5182, -6269, 2642, 1220, 2816, -4098, -3981, +-13264, -398, 361, 2768, -4786, 1023, -97, 655, + -397, 2403, -1576, -386, -1112, 792, -1195, -759, + 742, 729, -2916, -1020, 21350, -26, -3577, 659, + -1263, 1378, -4339, 1880, 4842, -669, -1203, 5936, + 816, -8356, 3660, 1673, -677, -2370, 1652, 8710, + -1254, 6171, -6868, -891, -6752, -169, -5678, -7588, + -3247, 2982, 5281, -4941, -359, -3354, 851, -1609, +-11194, 610, 261, -1936, 2715, -3540, -2488, 2086, + 6110, 914, -3224, 1777, -1558, 937, 3736, -3109, + 1903, 4250, -4478, 2636, 2292, -1451, 10231, 7600 +}, + +.cb2220m0 = { +-26430, -533, 1599, 208, -293, 2303, 704, 1586, + -1064, -1630, 690, 1697, 623, 1786, 332, 682, + 199, 12695, 475, 1288, -2471, -797, -68, 9659, + -816, -2465, 546, -1421, 1596, -926, 4471, 2360, + 5551, -900, 297, 96, 400, 936, 1548, -1066, + -1625, 652, 1416, -118, -525, 683, 1545, 1340, + 20684, 936, -1033, -773, 8416, 954, -4822, 4223, +-10815, -312, -896, 531, 3140, -1649, 508, 10294, + -315, -2078, 584, 1523, 118, 997, -11837, -605, + -262, -1732, -613, 12220, -2666, -1802, -507, -4410, + -100, 2127, -114, -886, -2806, 500, 1034, -2811, + 12642, 1015, -9193, -4201, 238, 1096, -1159, 1619, + 2534, 1644, -3465, 4797, 639, 2583, -1316, -9884, + 948, 1479, 1186, -1760, -343, -1286, -1653, 678, + -7439, 4542, -6295, -1600, -6978, 48, 448, 369, + 1597, -3696, -2121, 1002, 2428, -11368, 5385, 827, +-10674, -2252, 2240, 1230, -3074, -1894, 296, -2216, + 571, 114, -497, -1675, 1311, -2297, 1843, -350, + -856, 2067, 1198, -588, 270, -470, 2640, 274, + 19586, -762, -11471, -623, -506, 4236, -10981, -214, + -1856, 409, -1276, -935, -1681, 5116, 774, 3008, + 4388, -112, -9493, -1108, 1454, 1385, 1065, 519, + -486, 308, -1141, 289, 1424, -3672, -15989, -3738, + -1592, -258, 3304, 62, 1441, 45, -686, -1070, + -1616, -701, 2313, 1918, 4843, 654, -16902, 263, + 1837, -4062, 2727, -709, 1524, -1628, 2025, -281, + 264, 1238, -1023, -11981, -2990, -1293, 801, -9606, + -604, -210, 1248, 4014, 3652, -11286, -2094, -470, + -1330, 14523, -2388, 1413, -3968, 641, 2936, 161, + -1687, -1260, 1722, -1968, 364, -854, -14386, 10146, + 792, 133, 1746, 261, 3345, -408, 2036, 272, + 1412, 720, -3302, -1495, -4334, 2210, 799, 17546, + 2600, 1314, 764, 1327, 3433, -377, 4296, 2402, + -1074, 470, 7220, -2556, 3326, -4338, -2086, -1945, + 11865, 3525, 1513, 1520, -1814, -13020, -929, -2001, + -1496, 580, -3293, -3146, -2185, 1442, 390, -2026, + -2141, -192, -18700, -2039, -4330, 1691, -250, 1451, + -2913, 2832, -3284, 2899, 1529, -888, 486, -2381, + -1459, -2663, 530, -717, -248, -1714, 12662, 1820, +-11488, -1044, 3035, 3872, -2430, 679, 1075, 475, + -593, 930, -1751, 405, -2308, 2148, 510, -2798, + 445, -240, -6865, 2106, -11323, 670, 4342, 154, + -7748, -1805, 5381, -842, -697, -709, 688, -498, + 5525, 15212, -2006, -4146, -2452, 2392, -3522, -2023, + 1306, 5522, 916, -3616, -287, -653, 333, -330, + 4, -24886, 635, 119, -1949, 899, -36, -37, + 2658, -133, 2064, -534, -549, -1745, -70, 32767, + 1089, -869, 150, -599, -1146, -574, -424, 377, + -648, -303, 590, 453, 1910, -351, 553, 304, + -752, -752, -502, -42, -31211, -634, 449, 638, + 1086, -1406, 1220, 802, -924, -1874, -212, 86, + -200, -1140, 618, -621, -605, -10976, 1699, -603, + 2056, -4448, -1519, 2564, -743, 12304, 1482, 547, + -1589, -817, -217, -1633, -1089, -2270, 181, -634, + 3890, 734, -1319, -2035, 3304, 13144, -9076, -4067, + 70, 1309, 1067, -354, 1529, 1379, -1002, -3324, + -525, -817, -1438, 10834, 1036, 12441, 1242, 2461, + 2858, 2257, 430, -1177, 1142, -870, 844, 1102, + 1208, -1482, 830, 17622, -2753, 6, 174, 4385, + -339, 2157, -155, -68, -190, -1181, 29, -2046, + -2140, 27, 949, 1889, 446, -54, 16696, -49, + -3304, -1929, 1833, 3735, -495, -1225, -11743, -2259, + 891, -1954, 2848, -504, 1164, -2489, 861, 579, +-11547, 976, -42, 1477, -2428, -1561, 112, 74, + -2721, 12046, 632, 1283, -1900, 1990, -1193, 1606, + -1370, -2812, -1309, -1419, -12526, 3391, -4213, -2710, + 269, 90, 14575, -345, 820, 6118, 892, 6302, + -2825, 332, -3071, 2279, 3756, 185, -3029, 2402, + 245, 1010, -273, -32751, -140, -600, 482, 1516, + -462, 1931, 1941, 272, -310, 544, -422, -815, + -1116, 803, -617, -1640, -4336, -11735, 3656, -1176, + 1170, -6209, 2139, -1571, 2067, 1011, 9842, 790, + 1702, -191, 911, 2771, -253, 794, -3862, -1885, + -494, 2070, -2682, 772, 763, 4304, -15657, -2194, + -1998, -963, -5222, -175, 238, 32, 10067, -692, + 2824, -474, 3016, -11994, -51, 713, 2423, 2864, + -338, 4838, -1095, 215, -13471, -2, 704, 752, +-14654, 1396, 484, 564, -886, -775, -1099, 775, + -1035, 1661, -1013, -1118, 449, 822, 14253, -13238, + -1084, -1107, -1672, 996, 472, 2237, -440, 1186, + 1200, -2112, -1388, -1093, -1902, 555, -328, -1493, + -2034, 426, -2144, -388, -20028, 1285, 1122, 730, + 1661, -1576, -2084, 2930, 337, -66, 1591, 8685, + 2361, 146, 1370, 22, 1371, -105, -4190, 371, +-13252, 328, 1301, -995, 3689, 6422, -79, -1407, + -384, 828, 840, 854, 266, 1222, 796, -550, + -729, -1213, -87, 524, 1070, 22334, -2333, 574, + 680, -624, 463, 4047, -236, 114, 1020, -692, + 1575, -320, -3229, 222, 520, 996, 2104, -5404, +-18197, -1105, -184, -1057, 10712, -2509, -7140, -2307, + 1333, 3041, 183, 1241, -7861, -3060, 1432, 9, + -1431, -2605, 2663, 273, 250, 770, -740, 6699, +-10929, -7227, 105, -2983, -1203, 1637, -6072, -6630, + 933, -1526, 658, 2612, 5377, -91, -66, 4944, + 3025, 2723, -869, 142, 10532, 9858, -207, 3072, + -2610, 0, 81, 1078, 2136, -266, 223, 931, + -385, 983, 1029, 108, 2290, -491, 26685, 565, + -140, -662, 680, -2206, -803, -777, -250, -467, + 98, 2944, -12296, -4190, -2254, -748, -2076, 4780, + -510, -221, 1428, -6162, 2693, 6238, -4030, 266, + 6540, 2502, 5147, -4649, 1804, -10514, -3413, 2503, + 2143, -1924, -3811, 3674, 4341, -1054, -3130, -1260, + -576, 887, 25908, -773, 1186, 548, -606, -744, + -995, 1320, -507, 279, 1803, -2451, 880, -31, + -5, 1615, 770, -11818, 1062, -1126, 472, -297, +-12126, -1197, 1912, -962, 1241, 2348, 2332, -3047, + 1561, 3844, 720, -387, 371, 2942, 1174, -2347, + 1244, 10148, -1620, -11788, 1315, -31, -1867, 3450, + -1589, 5180, 3184, -2614, -13, 130, 107, 297, + 113, -1407, 29190, -544, -173, 990, 913, -1848, + -990, 1230, 264, 1896, -6974, -102, -2232, 3826, + -2269, -5027, 94, -12612, 436, -5979, 1757, 1757, + -724, 2378, 2584, 728, -1022, -7274, 668, 744, + -516, 420, -11866, 246, -1357, 2406, 3674, -2594, + 1638, -3037, -2402, 1525, -7304, -1078, 1772, 9264, + 12366, 202, 2, -728, 684, -437, 1446, -3546, + 828, -2106, -2736, 964, -180, 6524, 2250, 514, + -782, 675, 1418, -11225, 2760, -3970, -545, 9128, + -6601, -556, -1966, -4625, -149, -198, -3330, -1575, + -6198, 656, 674, 367, 1809, 155, -5126, 6109, + -572, 4927, 1448, -1855, 1636, 8648, 2010, 8973, + 3087, 10172, 34, -1183, -12, -1057, 192, -2955, + 1034, -374, 2500, 9318, -4090, -5220, -404, -1022, + -1458, -1367, 765, -1193, 1542, 302, -1337, -34, + 1449, 1434, 2210, 404, -3277, -8024, 1363, -7591, + 9096, -9179, 1176, -7311, 544, -8942, -713, -56, + 2623, -35, 1623, 2212, 1733, -712, -1327, -320, + -1966, 11352, -1276, -3804, -550, 520, -4848, 550, + 1488, 944, 10756, -782, 5643, -2647, -6513, -3500, + -2877, 1880, -6634, 2349, 256, 440, 188, -8428, + -4580, 2479, 4763, -1807, -513, -4292, -1729, -6878, + 448, -6706, -1162, 4938, -721, 5465, 1409, -8759, + -898, -4254, -5230, -3886, -7969, 1730, 3656, 1198, + 3537, 33, 4091, -2088, -7646, 1160, 2922, 855, + -1254, -2616, -770, -685, -100, -577, -4927, -792, + -2107, 9613, 2563, 5096, 6143, -3404, -8630, 4164 +}, + +.cb2220m1 = { + 32524, -324, 411, -34, -697, 818, -71, 2326, + -142, -989, -1512, 358, -260, 3791, -575, 93, + 224, 208, -1101, 32767, 1147, -203, 2015, 461, + 668, -296, -3340, -38, 720, -993, 1765, -1344, + 1323, 648, -997, 729, 581, 349, 861, -2035, + 1791, -2142, -822, -1425, 820, -6555, -811, -15708, + -912, 4835, 1500, -604, 527, -937, -640, -1240, + 4692, 1259, 174, -12040, 450, 8196, 2796, -5123, + 1595, 538, -101, -218, 5581, 367, -2700, 277, + 2111, 2718, 1458, 155, -100, 3284, -498, 9961, + -1505, -10336, -1170, 5337, 1032, -14947, 1154, -578, +-11773, -945, -660, 669, 2340, -1038, 1520, 713, + 2663, 422, -1242, 1918, -234, -1793, -1580, -271, + -5628, -2010, -12209, -1784, -4417, -2804, -3123, -4316, + 126, 6353, -2391, -2088, 836, -2550, 521, -1258, + 918, 4471, -528, 4243, -615, 3453, -6683, 1784, + 790, 13200, 700, 322, -815, 6049, -290, 928, + -1121, -1531, -878, -1150, 1404, 325, -530, -435, + -254, -804, -2536, 589, 8439, -1087, -16248, -637, + -1528, 305, -1577, 642, -22699, -139, 1319, 588, + -3079, 800, -597, -1408, -1150, 3145, -868, 3244, + -1004, 1004, -1459, -11618, -4557, -3643, -914, 4238, + -626, 4025, 3227, 537, -4285, 2010, 747, 1595, + 1599, 5994, -797, -911, 2854, -3426, -8488, -1899, + -301, -2146, -111, -522, -1852, 3075, -3864, -1531, + 654, 193, -11264, 5561, 304, 525, 346, -2761, + -1124, 1134, 8354, -12460, -1023, -7634, -2750, -1518, + 5001, 1480, -1039, -502, 1455, 586, 1012, -1270, + 12435, 895, 1169, 466, -10696, -3861, 4381, 1790, + 767, -1808, -537, -1057, -2374, -2058, 9992, -858, + -1568, -678, -3812, -1520, 1521, 230, -1716, 13418, + -1930, -979, 3272, 1116, -4555, -559, -320, 12080, + 13696, -286, 652, 2420, 1725, -277, 213, -1046, + 1642, -576, -1514, -973, -1501, 77, 537, -606, + 1144, -680, -568, 1104, 2176, -969, 1657, -784, + 1107, -1056, -59, -5607, 64, 11913, -178, 8703, + 3744, 276, -50, -12807, 1122, -6138, 1901, -439, + 733, 6829, 3001, -61, -1005, 3816, 3987, -3588, + -778, 2257, 12101, 196, 13796, 355, 1407, 989, + 101, 1041, 988, 1274, -1478, -1127, 1320, -442, + 3452, -1717, 1244, -466, -868, -323, 502, 1243, + -70, 897, 958, 2781, -2492, 788, 744, -12324, + 1111, -11704, -452, -734, 19574, -45, -584, -2387, + -830, 603, 380, 787, -2962, 2046, 2524, -2403, + 699, -4144, 1587, 573, 588, 238, -88, 31, + -278, -32768, -1173, -745, 667, -188, 1221, -369, + -261, 322, -2054, 651, 100, -2092, 315, 1558, + 596, -407, -146, -1234, -30970, -71, 633, 536, + -1345, 1819, 655, 680, -1453, 492, -1265, -1292, + 1780, -68, 1008, 215, -19980, -521, -3148, -256, + 193, 916, 453, 86, 116, 108, 1518, -1420, + -1501, 688, 669, 1196, -1579, -942, 868, 804, + 110, 1126, 202, 1086, 23516, 1070, -1623, 747, + -38, -116, 1176, 554, -2361, 1008, 1085, 1972, + -1794, -96, 464, -20910, -1208, -3857, -466, -2173, + 2461, 2364, -931, -684, 3056, -719, -936, 887, + -3149, 1004, 7085, -2985, -9393, 5142, -9621, 150, + 174, 572, -2232, -390, 1356, 160, -10796, 2256, + 2238, 242, 1663, 485, 12378, 1236, 688, -2908, + 1084, 1047, 4850, -72, -642, 1604, 152, -850, + 670, 968, -3207, 1690, 105, -2516, 11539, 390, + -1117, -588, -10771, 2879, 4742, -8351, 1571, -850, + -605, -1959, 395, 12324, 1750, 2290, -92, 774, + -2897, 1025, -1841, 546, 3904, 3908, 11494, 9, + 1340, -11976, -525, 1522, -43, -43, -1860, -6160, + -199, 2479, 4593, -2876, -2985, 1044, -62, -812, + 10424, -2489, -1098, 796, -1292, -2070, 1096, -1944, + -2145, -4374, 1041, -1014, 9036, -2142, 328, -8232, + 152, -13336, -2225, 13716, -367, -558, -1942, 161, + -472, 2224, -748, 3550, -809, -493, 2121, 1234, + 772, 5146, 2485, -2282, 7546, -1441, 1595, 9176, + 6208, 1292, 1704, 3968, -1500, -1974, -3519, -2826, + 149, -903, 504, -187, -940, 121, -215, -615, + -257, -1954, 958, 2057, -191, 21258, -726, 2081, + 1278, 1670, -854, 2730, -8132, -530, 1004, 2574, + 1430, -2536, -10851, 1389, 155, -140, 2158, 2762, + 3807, 3850, -3728, -954, -11366, 709, 14727, 514, + 694, -87, 857, -249, -419, 617, -418, -1144, + -32, -2182, -839, 1449, -1072, -785, -246, 13634, + 12488, 358, -447, -2262, 926, 1023, -901, -345, + 2260, -1530, -1466, -2973, -2170, 2090, 44, -23476, + 603, -1740, -345, -438, -3004, 1322, -3088, 1274, + 341, -348, -534, 1055, 3026, -932, 514, 8958, +-15489, -374, 1077, 1166, 48, 1016, -918, -27, + -410, -266, -1401, -3888, -2918, -2146, 2815, 1834, + -875, 162, -678, 1876, -2033, 1999, -12854, -1563, + 192, 414, 782, -3109, 1432, -4197, 2358, 8517, + 784, 1256, -1362, 2938, -11355, -5184, -10314, -39, + -2182, -1686, 241, -195, -232, -6169, 206, 181, + -470, 1008, -599, -284, 733, -836, 648, -138, + 2078, 313, 24432, 548, -441, 1446, -1628, -1218, + -64, -716, -2456, 1987, -352, -1025, -1951, 1320, + 350, 744, 2598, -984, -18328, 622, -4, -1572, + 893, -3043, -4365, 127, -1, -226, -1696, 1332, + -1360, 6756, 2596, 12059, 370, -3690, 497, 585, + 1619, -778, 9174, -2046, 2214, 2004, 1133, 1069, + 132, -250, -1555, -906, 561, -12904, -1039, -8006, + 1876, 2300, -1116, 1895, 1782, 3734, -1108, 1338, + -1409, -248, 16117, -1458, 156, -2626, 64, -1199, + -3544, 4283, -3390, -404, 1426, -907, -2768, -780, + -34, -18656, 2003, 515, 3171, -653, 762, -3352, + -154, -1171, -452, -1590, -5936, 519, 1210, 502, + -409, 2262, 695, 1028, 8652, 2532, -2636, 3472, + -1186, 1350, -651, -639, 8382, -3234, 630, -10323, + -2285, -1916, 826, -1449, -738, -344, 1022, -3248, +-20921, -200, 568, -84, 777, -1570, -2756, 2834, + 26, 3878, -1709, 101, 1433, -2238, 305, 61, + -1041, 2399, 628, -1509, -388, 946, 733, -1538, + -650, 19935, 478, -10696, 850, -682, 447, 2311, + 35, -1258, 2332, -11417, 1743, -834, 660, 3170, + 2378, -2734, -762, -1151, -1802, -9324, 4625, 2304, + -1186, 1180, 4894, 662, -7067, 869, 613, 1802, + 4839, 3412, -5460, -862, -4202, 7876, -1057, 2872, + -1336, 1731, -10788, 1088, 3433, 42, -939, 2479, + 6425, 991, -1621, 3222, -2464, 2988, -29, 481, + 11606, -2800, -8315, 7660, -3385, 1217, -728, -3670, + 684, -2295, -724, -567, -2150, -106, -1920, -2143, + 3465, 1968, -1089, -11953, -2704, 3049, -1351, 7225, + 5727, -525, 2639, 1955, 2259, 6489, -1867, 1544, + -3199, -4992, 2420, 4119, -2860, -9505, -2152, 10204, + -1133, -1201, -1468, -2989, 4658, 578, 1115, 368, + 1570, -776, -503, 1554, 1329, -696, -760, 575, + -1527, -3865, 8372, -3378, -8137, -8392, -3471, -1854, + -4852, 5270, -634, 608, 1289, -7660, 4983, -1266, + -2070, -906, 3291, 2459, 4807, -4241, 5773, -2258, + -4500, 2634, -13176, 6412, 282, -5849, 294, -626, + 888, -1088, 656, 192, -630, -3405, -12469, 2882, + 2184, 3920, 2715, -6852, -1111, 869, -161, 341, + 1856, -9450, 2719, -579, -3840, -8763, 1153, -3532, + -571, -766, 8301, 2936, -10501, -1073, 10068, -2930, + 6308, -2747, 3093, -1710, -3865, -1464, -4447, 446, + 898, 5386, -1074, -4651, 6205, 455, -1773, -1270, + 6986, -2493, 4076, 10605, -2522, 977, 4098, 1153, + -434, 4071, -2890, 2920, 9175, 2276, 4699, 642, + -1067, -968, 508, -1752, 728, 3260, -500, 1414, + 5554, 2761, 1973, -4704, 2127, 1397, -1070, -14536 +}, + +.cb2224l0 = { +-12451, 389, 917, 1238, -626, -904, -1877, 2328, +-12808, -1345, 406, 80, 383, -3841, 1188, -907, + 2369, -13409, 11191, -2547, -532, 762, -1627, 680, + -2305, -811, -1118, 3232, 3413, -2010, -453, -6816, + -4100, 1643, 11209, 933, -2272, 1440, -2465, -6862, + 186, 1563, -8468, -1832, -1166, -596, -326, 105, + -115, -352, -624, 31621, 129, -301, -615, -313, + -176, 620, -5, -1354, -3563, 678, -301, 621, + 904, -769, -1314, -956, -2294, -362, 381, -2398, + 17085, 100, 3962, -830, 18705, 237, -1296, 3534, + 1452, 259, 1690, -3106, -3624, -316, -16, 5900, + 2195, -1008, 14335, 14173, -1637, 1130, 1110, 499, + -1516, 500, -720, -494, -1010, -1264, -773, 1389, + 212, 8036, 780, 608, -415, 931, -301, -2186, + 2256, -706, 12972, -3461, -3695, 2073, -2768, -1525, + -7539, -441, -753, 4558, -8171, -1751, -6885, 4077, + 6714, 53, 1090, -3006, 3688, -1162, -59, 302, + 928, -450, 238, 10809, 353, 698, -476, 172, + -2198, -4377, -7518, 1605, 6348, 5147, -165, 165, + -463, -93, 1251, 671, 587, -402, -227, -462, +-27960, 215, -56, -958, -657, 508, 98, -2811, + -1443, 3076, 6218, -9760, -10465, -770, 345, 3076, + -116, -2884, 2215, -2652, 1306, 2638, -124, -317, + 366, 1461, -295, 5073, 460, 1920, 12216, -7032, + 6816, 3037, -2630, -1087, -1315, 123, -582, -2137, + 5061, 291, 1740, -214, 1920, -3470, 10895, 9491, + 3558, -1256, -448, -10304, -2391, 1890, 484, 11057, + 6636, 422, 2316, -1663, -348, 633, 1200, 1788, + -1124, -24435, 140, 869, 738, 223, -1429, 602, + 433, -196, -1127, -1937, -879, -310, -564, 1022, + -4380, 7247, -3938, 4461, 2219, -8465, 9266, -4564, + -3169, -3463, -477, 749, 2460, -776, 294, -171, + 1072, 1748, 1000, -208, 1908, -998, -1898, -10485, + 2360, -11950, -2412, -2609, 3885, -2738, 1348, -559, + -1342, 9366, 1560, -816, 1178, 342, -175, 1286, + 3014, 10641, 246, 3128, 6618, -305, 10906, 6359, + -4395, 1415, 196, 11136, 1772, -3047, 3313, -1231, + -1974, -3021, -1480, -1345, -830, 1551, 2521, -506, + 7821, 7715, 5078, 8215, 2102, 1552, 2247, 3766, + -3158, -1811, 631, 3980, -397, 9030, -1267, -1974, + 1539, -360, -315, 796, -4749, 2076, -1017, 717, + 2290, 11212, 9365, 1626, 379, 2060, 1329, 4, + -25, -1348, 566, -1266, 1670, 2166, 13123, 42, + 2416, -2170, -6380, 172, 316, 40, 300, -487, + 402, -220, 846, -894, -1413, -2227, 1962, 19478, +-14756, 14377, -582, -770, -186, -1008, -1520, -722, + -885, 2622, 311, -753, 480, 539, -1011, -1748, + -832, -603, -2015, 869, -14860, -600, 2110, 484, + -5874, 1532, 3290, -222, -4670, -33, -794, -2061, + -1185, -96, 337, 515, -1887, 26, 20283, -455, + -799, -62, -1083, 236, -1721, -569, -1259, 361, + 1090, -226, 1480, 13367, -638, 940, 3736, 6419, + -5995, 830, -6599, 4549, 1583, -9001, 1104, -1281, + -1270, -94, 1104, -2076, 652, 2263, 1465, -25, + 9046, -8139, -2646, -13200, -534, -15244, -1448, -1390, + 452, 584, -314, -1192, 951, 885, 396, 776, + 1303, 1298, -448, -32641, -234, -62, 31, -164, + -1042, -82, -26, -272, -559, -164, 669, -500, + 516, 1347, 9615, 1123, -1346, -1898, 8341, -10583, + 2286, -5233, 1503, 454, -2024, 4248, -2298, -2117, + 13390, -849, 2078, 1096, -651, -12232, -374, -812, + -3729, -829, -144, 1213, -469, 1112, 1146, 816, + 818, -912, -967, 907, 12, 2443, -759, -1833, + -174, -838, 488, -1560, -18242, -558, 5510, -1316, + 1758, 3957, -7130, -1394, 4962, 3870, -1907, -9247, + 2217, -3880, -4413, 1893, -3085, -202, 599, 1307, + 1574, -1070, -2593, -2722, 9506, -10170, 1105, 4879, + 2208, 38, 5596, -5990, -3205, 35, 9405, -219, + 618, 1308, 353, 3457, 1712, 717, -12937, 25, + 2176, -2590, -1223, 528, 1318, 4588, 7678, 5743, + -8430, -4487, 1364, 8082, -1727, -387, 469, 3172, + 401, -2771, 694, 14554, -2278, 3640, -11084, 924, + -593, -3841, -4338, 227, 750, 2974, -2834, -1765, + 2133, -1181, 5149, 11758, 11949, 3538, 2442, 2801, + 1457, -822, -3419, -2468, 191, -646, -975, -1271, + 832, 3088, -495, -10022, 1817, 1319, -880, 1342, + -1448, -3597, -3310, 8753, -161, -6550, 1422, -640, + -508, 11542, -277, -165, 837, 7389, -942, 11009, + -97, 1548, 1418, -445, 2105, -946, -8676, 5274, + 8842, 576, -1392, -1737, -1276, 5491, 312, 3624, + 2806, 2157, -537, 1656, 1982, -1300, -146, 463, + 496, 16792, -140, -1755, -832, -2123, -399, 5811, + -702, 2891, -3630, -1843, 346, 508, -364, -498, + -558, 32048, -744, 90, -372, 430, 704, 871, + 139, 772, 696, -108, -18, 310, -411, -798, + 465, -165, -321, 745, -27861, -752, 499, -215, + 172, 35, -196, -770, 274, -546, -96, -470, + -8976, 9156, 581, 904, -4644, -7801, 3525, -607, + 6444, 4058, -696, -1107, -632, 1475, 196, -933, + 883, 1101, 278, 433, 544, -497, 4, -1882, + 1504, 594, -30386, 218, 211, 850, -989, 319, + -867, -42, 754, 498, -70, -562, 660, -11561, + 54, 803, 425, 966, -1017, -1224, -12630, 1834, + -41, 98, -1083, 3508, 1750, -1751, 72, -503, + -38, 22211, 252, 88, 221, 690, 82, -1340, + 508, 638, 832, 482, 51, 7954, 2702, -1176, + 8830, -311, 2536, -6072, -4147, 5234, 494, -157, + -1289, -5678, -1617, 1508, -140, -55, 713, 440, +-32583, 105, -394, -613, -972, 578, 1122, -32, + 114, -228, 342, -1237, 1123, 1126, -188, -106, + 11308, -3787, 563, 3423, -9926, 1623, -2551, -1448, + -4125, 918, -1366, -476, -66, 4, 761, 164, + -61, 20445, 238, 296, 492, -1126, -98, -1201, + 14, -1840, -865, 1178, -869, 105, 907, 248, + 1538, 2990, 11691, 7783, 1566, -6704, 2397, 594, + -1825, -383, 4264, 1911, 468, 1018, -676, -2676, + -7756, -2623, 10705, 2710, -8078, -5256, 1699, -2100, + -355, -2086, 10828, 611, 18, -830, 978, -4181, + 1324, -5262, -327, 1796, -9777, 1306, -1934, -8930, + 9520, -2364, -3997, -10209, -6326, 1394, -1758, 868, + 1192, -2916, -23, -1586, -296, 438, -279, -14171, + -1554, -206, 2383, 506, 1181, 8298, -491, -2771, + -4286, -7116, -1680, 506, 1729, -12965, -925, -985, + 420, -1746, -267, -478, -11763, -1030, 187, -3878, + 1516, 2472, -371, 29, 809, -1700, -152, 560, + 1833, 14397, 968, -96, -3242, -2497, -76, 2096, + 9593, -1200, 446, 1505, 8058, 1722, 501, 923, + -1171, -9516, -2536, 7368, -2, -5304, -2440, -352, + 510, 320, 301, 120, 687, -942, 137, 824, + -316, 1312, 510, -1133, -27448, -404, 1041, 272 +}, + +.cb2224l1 = { +-14840, -1361, 12733, 798, -496, 1691, -1668, -1730, + 928, -3233, 338, -578, 156, 784, -787, -242, + -618, -853, -1282, -11766, 3970, 12178, -2034, 244, + -3411, 300, 159, 3494, -3060, -1459, -2484, -10680, + 752, 227, -1612, -922, -549, 158, 2260, -7640, + -4479, -4075, -2412, -7707, 600, -12358, 93, -1666, + -795, -13060, 61, 511, -2102, -2122, 364, -157, + 2310, -1552, 1260, 158, 9503, 7050, 7, -5902, + -7098, 444, 3736, -1836, 3109, -2328, 457, -871, + -327, -780, 661, 8684, 2530, -268, 954, 1380, + -1029, 418, -136, -3515, 1953, -1688, -8623, -3292, + 7758, 2796, 11643, -931, -501, -873, -444, -1342, +-13900, -246, -283, -1779, 998, -1318, 408, 1505, + -462, 10667, -1813, 78, -16514, 360, -2029, 942, + 1674, 171, 317, 244, 1183, 724, 760, 1634, + 863, 793, 126, -326, 980, -629, 22219, -649, + 1274, 717, 1355, -1853, -1792, -1017, -2104, -768, + -1708, 2302, 2353, 11167, 10734, -3412, -2266, 75, + -104, 425, -880, 2072, 2934, -930, 270, -2414, + -925, 1023, -746, -236, -1620, 825, 1324, -101, +-19348, -1291, 585, 2165, 2891, 3662, -577, 1800, + 408, -1486, 107, 351, -319, 1104, 956, 403, + 628, -277, -57, 938, -32768, -71, -441, -208, + -32, 191, 314, -171, 613, 749, 844, -472, + -444, 952, 42, -8026, 2720, 1911, -2780, 12311, + -122, 3569, -91, 6048, -776, 1694, -63, -1272, + 3581, 1622, 2538, 190, -13108, -820, -3056, 1189, + -1428, -244, -752, -6187, -3473, -697, 1368, 1043, + 7702, 352, -140, -12999, -80, 12672, -1473, 3113, + 1505, 667, 2392, 1767, 537, 1949, 657, -130, + 980, 1743, 8269, 2380, -2311, 197, -651, 2531, + 553, -1117, -396, 472, 4565, -12672, 2322, -360, +-12766, 2205, -2651, -10690, -218, 586, 5229, 34, + 59, 1730, 1226, 2106, 4008, -1878, -9520, -1366, + -1174, -290, -1037, 1642, 1234, 305, -1279, -642, + 1126, -13199, -29, 642, 2928, 1936, -260, 588, + 11690, 9282, -3362, 7732, 1073, 2738, 4688, -1507, + -1461, -2271, -1131, 1969, -2152, 1637, -774, 66, + -1190, -206, -491, -1080, 644, -378, 367, 17980, + -1583, 2162, 918, -121, -432, 115, 5, 791, + 1968, -2287, -1574, -9545, 11146, 3540, -4700, -515, + -4548, 881, 591, 1044, -259, -978, 2, 232, + 778, -198, -1161, -378, -83, 421, 282, 26564, + -801, -1628, -1983, -301, 931, 886, 2196, 1453, + 752, 2956, -3478, 490, -1420, 13303, 1293, -9466, + 462, -12829, 11130, 8061, 593, 3697, -611, -534, + -698, -1148, 1598, 293, -726, -698, 289, 180, + 876, -369, -43, 234, -21629, -1448, -753, -480, + 956, 994, 531, -916, 630, 720, -2300, -9544, + -1418, 993, 2130, -2359, 2460, -339, -277, 1577, + 12206, -3507, -1280, 1938, 871, -1850, -809, -3364, + 6918, 1134, 5010, 8772, 2103, -9775, -1404, 5148, + -1494, 1549, 1761, -812, 654, -611, 822, -229, + -384, 10466, -337, 2207, 131, 2818, -2925, -3374, + -8786, -8552, -2282, 88, -1058, 8571, 2900, -529, + -1569, 1882, -981, 204, 2955, -4227, 4196, -3041, + 10804, 1822, 82, 1936, 2380, 12992, -5659, -3449, + 1329, -1668, 1291, -1726, 8328, 314, 2737, -677, + 2384, -910, -878, 687, 640, -721, -912, -12772, + -2079, -398, -1788, -2516, -8711, -1038, -985, -7151, + -9057, 890, 459, -298, 918, -10061, 848, -716, + 1822, 836, -9516, -985, -1379, -409, -2237, 1036, + -1082, -1704, 1333, -1432, 11463, -2355, -5975, -1674, + -640, -554, 8352, 2732, -5251, 4243, -354, 3662, + -592, -9317, -1205, -1084, -995, 11288, -2098, -1620, + 2367, -1286, -5312, -64, 540, -2327, -2703, -2013, + -8649, -1306, -948, 1443, 664, 2400, 4706, 4061, + 387, -20, 1859, 9283, -18175, 806, -1401, 1253, + 596, 2176, -1682, 2209, 733, 1404, -6652, 2754, + 950, 2346, 3629, -6875, 5069, -9302, 1472, 942, + 1184, -10432, 960, 3987, 1985, 421, 300, -716, + 938, 500, -160, 226, -87, -1648, -1857, -1977, + -323, 2305, -13843, -4148, -2978, 5430, -3422, -1138, + -2146, 1548, -1430, 734, -339, 8598, -4568, -496, + 477, 4969, 2593, 2842, 8645, -2365, -7455, -2687, + 249, 7516, -53, 219, 1139, -668, 566, -522, + 1289, 33, -141, -920, 2526, -2797, 16456, -2000, + -758, -194, 10984, 187, 1686, -4799, 9671, 1838, + -1224, 1325, 656, -5434, 3207, 1813, 1833, 14375, + 12259, -95, -536, -1746, -3568, -442, 964, -1472, + 1345, 2692, -589, 520, 616, 357, 326, -1363, + 28603, 700, 473, -908, -1129, 1046, 1106, -471, + -472, -980, 29, 574, -350, -545, -585, -1936, + 279, 882, -880, -52, -30552, 371, -154, -1275, + -1914, 104, -110, 1122, -719, 729, -743, 360, + 766, 198, -11674, 612, -10602, 1157, 186, -3132, + 3070, 1535, 155, 774, -9432, 4966, -6717, 320, + 5167, 112, 2727, 11228, 1368, 1864, 1197, -1519, + 1504, 17863, 49, 2212, 611, -1788, 2932, 395, + 32, -566, 2425, -9457, 673, 670, -247, 1617, +-12578, 1408, 462, -14935, 1438, -808, -1850, -784, + 1856, -1648, 767, -1452, -1652, -1621, 1016, 1428, +-11203, 4217, -6410, 2570, -1016, -1720, -9036, -390, + 62, -1245, 3027, -255, 1646, 1358, -907, -864, + -118, 874, 268, 252, 104, -926, -552, -1206, + 965, -208, -24472, 890, -1516, -630, -885, -804, + -374, -22520, -1143, -777, 532, 185, 603, 1775, + -1887, 413, -458, -1036, -211, 2693, 6976, -9498, + 1437, 10163, 2450, -1574, 4941, 884, -470, -3366, + 4664, 420, -568, 5703, 10, -1692, 143, 1592, +-10966, 2891, -2961, 3938, 1990, 1726, -5247, 3326, + -6575, 584, -277, -441, 1679, -520, 1339, 1077, +-11462, -267, -351, 201, 10939, 4150, 3890, 1484, + 2615, -676, -448, 2316, -1278, 9734, -3039, 2841, + 964, -7557, 156, -7228, -120, 5533, -4322, 1796, + 2555, -9912, -3038, 2236, 1190, 222, -1684, 3273, + -1768, 6233, -6442, 8545, -49, -45, 2366, 293, + 308, -689, 308, 368, -452, 1125, 2326, -2335, +-17793, 2027, -779, 734, -2032, 1246, -2898, 4174, + -74, -40, -3105, -2135, 996, -12714, 3614, 4936, + -1928, 1528, -4158, -1791, -2318, 907, -326, 22513, + -660, 1022, 434, -564, 28, -112, 252, 372, + -842, -2, 648, 2323, -614, 23377, -263, 486, + -408, -362, -821, -724, 972, 1248, 444, -1741, + -420, -1371, 1088, -565, 22, -394, -64, -292, + -103, -501, -30510, -294, -266, 433, -700, 742, + -756, -407, -961, -148, -1416, -1041, -481, 121, + 346, 10240, 12629, 1476, -2647, 1350, -2012, -262, + -5621, 714, 4398, -2732, -10473, 9834, -5165, -991, + -557, -2733, -3460, 5779, 659, 1472, 2029, -2339 +}, + +.cb2224s0 = { +-27522, 2628, -2486, 277, 874, -2351, 2725, 915, + 994, -1209, -439, 2936, 46, 1014, -1816, -3561, +-14386, 3113, -10400, -1025, 2114, 1328, -278, 1182, + -1820, 3928, -1062, -282, -1327, -1468, 5975, 2342, + -630, -4217, 10116, -1254, -2646, -5210, -9942, 1904, + 21, 504, 2325, 1443, 6470, 2598, 8130, 810, + 304, -1059, -645, 14634, -3198, 4277, -669, -7170, + 1554, -2321, 2386, -1072, 2483, -4141, 2841, 3414, + 8014, -3141, 10857, 6634, 3138, 3199, -320, 36, + -1366, -4129, 3157, 2602, 4273, -2435, 2645, 2986, + -3712, -3995, -5476, -4693, -1664, 6384, -11201, 1320, + 2184, -5102, -2984, -1569, -2116, -1513, 14284, -11182, + -2925, -731, -1321, -6363, 1483, 3463, 1292, -2065, + -357, 9108, 6371, 3840, -6905, -8918, 2906, -1658, + 757, 1998, -580, -708, 2198, 1867, 960, 4522, + 1896, -1674, -4943, 2695, -2465, -2078, 9755, -4853, + -2602, 3466, 3897, -3633, 4918, -2049, 3730, -1982, +-10085, -3458, -1866, 32, -1706, 3648, -308, -942, + -1630, 1730, 512, 14612, 3415, 974, 3079, 765, + 897, -270, -1813, -1533, 1118, -2805, -2764, 1130, + -1798, 4594, -3134, 964, -20082, 2574, 32450, -1379, + 52, 358, -226, 1902, 257, -1071, -650, -399, + -381, 2073, 2310, 2164, 8221, 1433, -629, 1440, + 1120, -3362, -4642, 2000, 378, 1208, -2648, 4534, + 3307, 13200, 2780, 3100, -3194, -10606, -11563, -4491, + 2218, -4500, 622, 1313, 2682, 3003, -1387, -3886, + -1567, -4864, 10899, -20606, -1606, -60, 602, 125, + -730, -1112, 979, 325, -13, -185, 1241, -288, + -552, 6042, -7049, -7359, -1456, 493, 11204, -65, + -2170, -5248, 2248, -1046, 591, 2085, -2844, 244, + -3454, 581, 1315, 3043, 304, -620, 405, -19944, + 769, 1076, -1456, -694, 2560, -1046, 2514, 14552, + 1586, -7027, -4710, 1366, 1552, 4354, 3296, 462, + 600, 500, 3225, 5083, -792, 3199, -698, -3589, + -2596, -3350, 2758, -3019, 5664, -9387, 4716, -3125, + 3306, 6268, -592, -622, -4144, -6290, 4990, -748, + 1854, -1042, -2996, -4279, 338, -1864, -8639, -11208, + 932, -722, 1788, -1927, 450, 2191, 11828, -6400, + 5364, -2236, 3212, 8340, -3229, -2846, -4676, -1825, + 2628, -303, -589, 7728, -4216, -3866, -4400, -194, +-11316, 5646, 3716, 4827, 232, -583, 308, -1833, + 2153, -2508, -46, 857, -9587, 2768, 5136, 1462, + 5142, 7990, -3424, 1067, 7462, 4944, 98, 1014, + -4750, 13824, 1130, 2334, 9393, 2416, -4519, 27, + 2000, 929, -204, 481, -2780, -3720, 1267, 269, + -5383, -1999, 1249, -4238, -9351, -7440, -5964, 6154, + -6827, 3112, -2613, -164, 1604, 1245, -50, 8619, + -4044, 4652, 2846, 8359, 5345, -2902, 2295, 4801, + -5016, -6270, 2893, 2732, -3510, -2613, 4548, -6376, + 4510, 10566, 1859, 1038, -8381, 2782, -1622, 159, + -1035, -3232, -3766, 1580, -720, -4476, -3863, -920, + -2135, -458, 352, -2645, 3029, 301, -1145, -478, + 3696, -11700, 9930, 6649, 7290, 2362, 17226, 3238, + 1786, 662, 971, -736, -647, 1745, -506, -777, + 1458, 2406, -1417, -7933, -846, -2654, 1104, 618, + -2783, -10168, -3322, 9498, -939, -2342, -1876, -1914, + 84, 3468, -6533, 7796, -3797, -1318, -2183, 1310, + -895, 4943, 1062, -4468, 142, -244, 884, 613, +-13963, -5853, -947, 18703, -964, 1090, 1070, 1388, + -1572, -1110, 671, 1706, 620, -262, -2421, -2277, + -5665, -5212, 4994, 2379, -593, 2048, 14489, 1165, + -1775, -2093, 2466, 419, 404, 5429, 3089, -1350, + 1975, 2281, 60, 599, -1600, 2286, 2358, 6698, +-16423, 3760, 666, -1309, -1346, 2786, 2364, 1448, + 1114, 17956, -5301, 2430, 1178, -164, 2195, 3927, + -122, -737, 1468, 307, -1863, 1592, -7714, -2428, + 958, 220, 59, 4124, -1945, 11151, 8604, -2077, + -4787, -4578, 1096, 2685, 6478, 8314, -6221, -3842, + 2173, -43, 104, -2510, 3109, -2324, -4238, -4709, + -3233, 3228, 11454, 2428, 578, 780, -1096, 72, +-22624, -1421, -4104, 226, 464, -1726, -1971, 2068, + 1142, 1412, 1412, 798, -2605, -3451, -1104, -2224, + -2250, -3470, -572, -1420, -1292, -58, -217, -21417, + -172, -6368, 30, -2170, 95, 378, -2926, -2180, + 2820, -683, 2018, -4313, -13469, 5396, 1808, -592, + 4732, -6602, -5602, -983, -4130, -477, -1236, -2263, + 3992, -12962, -1778, -2631, -2421, -746, 1964, 1754, + -760, 2753, -116, -3860, 10246, -448, -1318, -100, +-10372, 1420, -210, 2768, 48, -2373, 7721, -3217, + -328, 1543, -2527, 3709, 4024, -916, -4588, -726, + -4302, -982, -14714, 3615, -1190, 9051, 199, 2252, + 1348, -4204, 693, 1241, -14160, -2460, -2017, 2997, + 766, -360, -450, -2919, -7976, 3210, -179, 8935, + 670, 1155, 6888, -2249, 2729, 1810, 6283, 684, + -9717, -1763, -921, -4578, 3941, -6408, 1431, -2742, + -91, -2094, -2118, -9752, 2801, -2497, 147, -5901, + -5270, 13170, 2810, 1576, -3191, 10253, 4226, -1340, + 2456, 1079, 12541, -5124, -8356, -1000, -558, 180, + -2070, -1880, -5718, -687, 10549, 1066, 220, -4147, + -695, 3648, -3460, -3143, -1623, 2150, -11222, -2566, + -6395, 3552, -4176, -698, 1248, 112, -4628, -960, + -724, 1191, 2084, 15207, -346, 371, 190, 5345, + -4283, -7482, 1354, -4424, -3775, -4143, 1444, -14876, + -589, 2498, 1305, -486, 1628, -867, 1584, 1094, + -10, -1260, -1046, 2528, 27472, 910, -1069, 829, + -117, -1097, 770, 252, -1412, 2353, 2200, -11, + 624, 8459, 6320, -9465, 1225, 2532, 5415, 9252, + -1441, -1378, 1081, -1997, -3904, -14740, -5220, 3627, + 5725, 6180, -5336, 72, 4638, 915, -496, 628, + 1880, -420, 2800, -7143, -7578, 3180, -4210, -1111, + 2979, -442, -182, 2778, 2398, -13878, 2209, -282, + -888, 180, 3584, -1005, 2, 999, -3074, 1205, + -4605, 5250, 17255, 2839, 2718, -678, -2651, 160, + 1596, 4685, 2324, 3100, 3744, -1954, -11674, 621, + -678, -6242, -3449, -1890, 3134, -289, -7162, 2268, + -8437, -624, 4999, -5946, 13013, 244, -200, -1494, + -1108, 3768, 445, 2429, -1264, 786, -2993, 3482, + 2448, -968, -1184, 213, -772, 4931, 42, -3850, + 2020, -17970, 84, 3016, -602, 1805, 731, 3522, + -2606, -637, 25535, 680, 1083, 4138, 1602, 190, + -1854, -962, -379, -2499, 2453, -362, -4552, 4689, + 2168, -5930, -10552, -5585, -4694, 2447, 2047, 5420, + 3908, -1449, -90, -68, 496, -12713, -2127, 1406, +-10766, 2438, 2278, 2962, -6411, -22, -1966, 2814, + -1746, -383, -2381, -5981, 10920, -12354, -656, 2260, + 5200, -1908, -2275, 4276, 1174, -932, -532, 2832, + 601, 1551, -8434, -4170, -6411, 9099, -6886, 2243, + 561, 2026, -3598, -1125, 646, -5188, 6017, -632, + 772, -2919, -3776, -9938, 2461, -122, 128, -1416, + -1533, 343, 1318, -13738, -1528, -6418, -1196, 832 +}, + +.cb2224s1 = { + 32767, -749, -1885, -806, 739, -1858, 3902, 1029, + 332, -2122, 1240, 2705, 1362, 190, 1058, -1404, + 1224, 1122, 1208, 190, 1984, -1355, 1694, -21000, + -1012, 2418, -1269, -1154, 1113, 2291, -2317, 315, + 12872, -2296, -1510, 1104, 11324, -1146, -1018, 1326, + -902, 168, 647, -1828, -3838, -5682, 2732, -238, + -134, 13450, 1570, 2424, 996, -3494, -3720, 4897, + 5875, 149, -6367, 6659, -2329, 6916, 1134, 425, +-19014, -479, -1900, 3470, -1777, -811, 1723, -46, + -2103, -1298, 2929, -4279, -639, -2443, 7231, -1187, + -2145, -777, -3287, 4895, 8878, -9318, 289, 4015, + -3148, -598, 2226, 11700, 114, 3237, 9586, -4570, + 2592, 3614, -2272, -2829, -3356, -1095, -5290, 4709, + -1867, -1930, -20722, 937, 892, 1415, 1544, 2950, + 5090, 937, -1411, 123, -31, -1568, 338, -938, + 5465, 5796, 480, -2782, 3351, -2489, -383, 1529, + -5686, 2446, -693, -12796, -599, 1894, -1576, -2244, + -4686, 10165, -1085, 10050, 2681, 1138, 2544, -1809, + -806, 5278, -8730, -3740, -2343, 971, -3254, -165, + -212, -4164, 850, 233, -13694, 442, 1073, 3854, +-12926, -2001, 3468, -765, 829, 2174, 1531, -6036, +-10848, -11009, 803, 1713, 2884, 1992, 75, -2989, + 268, 346, 1998, 4798, 8976, -4632, 1863, -4127, + -612, 4790, 10946, -1296, 8009, -1351, 356, -1711, + 313, 2301, 1318, 8050, 700, 1218, 2270, -2156, + 67, 1537, 1941, 3442, 13321, 691, 2344, 2594, + 1551, 3853, 7279, -10441, 1006, -11862, 5532, -611, + -582, 2257, -2873, 3993, -5133, -2264, -2478, 1576, + 1834, -4931, 10264, -1429, -10404, 393, -3715, -1470, + -2003, 384, 4869, -6780, -1297, 1572, 1043, 6980, + -4382, -3005, 3698, 4176, -1348, -4972, 1574, 9815, + -5995, -979, 3609, 3702, -8503, 668, 3354, 2552, + 9183, -1175, 1224, -2859, 11176, 6088, -1355, 84, + 1271, -380, 5336, 299, -690, -365, -8047, -3679, + -3204, 1334, -13451, -1392, 2200, -3646, -1046, -4292, + 741, -1701, 1722, 2061, -1358, 7266, -6356, 963, + 2190, -1349, -1882, -14128, -4662, 3552, 565, -1109, + 5413, 1239, -2618, 794, -2064, 11805, 9004, -2134, + 2804, 946, 80, -2387, -1205, 11, 1642, -1825, + -2324, -5018, 4208, 5285, 661, 12430, 1907, 784, + 10864, 340, 18, -138, 2885, -2247, 17, 334, + -3172, 2977, 970, 536, -1540, -516, -488, -512, + -1334, -1930, -2418, 1078, 24837, 12, 2060, -252, + -2536, -2206, -3179, -6785, -8842, 8736, 1393, 119, + 1652, 10126, 856, 855, -742, -289, -2208, 3831, + 6909, -6556, 2472, -245, -1729, 1460, -3014, 59, + -58, 132, 3903, -3762, -1419, 13273, 2708, -7752, + 84, 3525, -1305, -334, -13421, 5931, -4845, -2697, + 666, 558, -1102, 632, -2946, 4153, -4018, 4516, + 4875, 4460, -1567, 2233, 386, -754, 1256, 2145, + -1692, -13046, 1581, -518, 4397, 1215, -723, 3413, + -640, -5088, 1711, -714, 2536, 2433, -691, 10758, + -8764, 5541, -2071, -1662, 12955, 12998, 1252, -94, + 802, 2573, -2557, -66, -832, 106, -728, 1050, + -811, -2684, 629, -16524, 1531, -1617, 1348, 204, + 1722, 368, 554, -1752, 114, 1349, 1952, -1007, + 2626, 2035, 8148, -2539, -4296, -4460, -8542, -3089, + -1543, -857, -2617, -1765, 6642, 2167, -1531, -6881, + 86, -414, -5896, -5152, 17445, 1129, -5006, 2936, + -3432, -2226, 1176, 972, 1170, 530, 3390, 260, + -2909, -3550, -5255, 1771, -382, -1690, 17070, 2688, + 566, 2430, -1768, 3373, 1460, -3464, -629, 3119, + 430, -3554, 8357, 7075, 293, 2955, -61, -6919, + -4939, 3678, -6852, 652, 2206, 5918, -2768, -3022, + 5721, -770, -1102, -1057, -2760, 3086, 5611, -160, + 2714, -1042, 2569, -14248, 3846, 8212, 5392, 144, +-11896, 618, 1212, 3283, -3777, -715, -3870, 2528, + -2900, 1645, -1786, -1852, 2776, -1348, -586, 234, + -4, -1666, 46, 2095, -1987, -18728, -2980, 2501, + 4042, 79, -1849, -2013, 8047, -1898, -108, 340, + -4760, 2134, 9000, 347, 10365, 4779, 6660, 1694, + -3253, -2282, -1488, 10406, -8054, -3414, -2934, -1611, + 3172, -2195, 4973, 1249, 2888, -4054, -5738, -2995, + -2282, 1977, -353, -516, 5322, 3225, -4907, 1303, + -4656, 9947, -236, 9382, 2332, 2076, 1470, 3173, + 4712, 2645, 559, 4904, 1511, -1715, -4856, 5750, + -1276, -306, -5980, 14393, 1443, 85, 156, 7718, + 793, 4199, 2122, 1098, 128, -1996, -1397, -20, + -534, -13296, -1518, -2970, -1001, -6474, -6146, 8337, + 5476, 3058, -526, -1295, 1623, -8791, 1257, 2006, + -5725, 3035, -2917, 1280, -8479, 5934, 9870, -13131, + 14, 1088, -9, 1969, 366, -3214, 192, 2764, + 1499, 346, -2031, -2900, -2529, 1072, 11717, 5206, + -44, -2514, -8900, 2892, 2132, 3635, 3735, 2726, + 1398, 6035, -2830, -4568, 424, -8696, 1368, -3860, + 1823, -2620, 4546, -2210, 1660, -1672, -10524, -484, + 950, 11, -4494, -6220, -5653, -13332, 2868, 460, + -4120, -4030, -3277, 522, -3403, 1126, -170, -1892, + -4366, 1304, 3477, -1507, 1111, -594, 1670, -8416, + -1690, 2492, -7109, 2531, 4131, -8123, -4884, 16505, + -240, -63, 32099, 974, -1360, -2395, -2005, -1156, + -877, -416, -922, 1857, 766, 71, 1380, -259, + -272, -1924, 2498, -3290, -16045, -2064, 2966, 2936, + -1265, 2121, 488, 3781, 1484, -1193, 4776, -1001, + -669, 1569, -379, -604, -5, -1943, 757, 359, + -560, 118, 17941, 2323, 215, 7621, -3582, -8130, + -698, 9893, -2752, -417, -1262, -1504, 3319, 1186, + -2192, 3014, 781, -3602, -6190, -7725, 3169, 2038, + 1175, 612, 2477, -4136, -12152, 4538, 567, -116, + -3222, -470, -118, -9257, -635, 3078, -11596, 93, + -4178, 4150, 5985, 4414, -2110, 542, -1125, -1242, + -234, 807, -1385, -2448, 824, 109, -1826, 3032, + 269, 14188, 3468, 908, -12, 2290, 5758, 1685, + 680, 5963, -2763, -173, -34, 3135, 1230, 2226, + 2471, -9546, 2266, -1583, 729, 3506, -10664, -652, + 2212, -620, 2762, -751, -6337, -4339, 4131, -1234, + 5423, -2279, -2884, -929, -12582, 416, 2046, -3854, + 11130, -2738, -670, -202, 6216, -7266, 9726, 1308, + -1761, 4696, -1061, -144, 482, -1586, 4377, -5016, + -3894, 2296, 4340, -555, -3003, -2117, -962, 100, + 4548, -1870, -13885, 1351, -3226, -8114, 377, -391, + -1344, -2148, 4756, -3518, -14429, -670, -238, 400, + 1234, 4389, 1181, 1046, 425, -32, 840, -29846, + 1580, -992, 1844, 1961, -1305, 1055, 418, 52, + -641, 2430, -1773, -5323, 3341, -5367, 14027, 3051, + 3864, 404, 4186, -1875, -5822, -4321, 112, 395, + -177, 1080, -3008, 520, 8, 226, 1430, -1635, + 8, -2632, -3249, -3595, 622, 564, 8404, 14463, + 160, -7828, -4113, -16547, 848, 6320, 2311, 4074, + -2050, 668, 1463, -2322, 1790, 864, 317, -594 +}, + +.cb2224m0 = { +-17338, 5737, -912, 5906, -5315, 920, 2743, -2232, + 1943, -753, 1696, -1818, -2272, -564, -1306, -527, + -156, 9952, 36, 2524, 2053, 1841, -1670, 10622, + 2532, -5616, -324, -1132, -1148, 1920, 10232, -75, + -630, -10796, 1618, 1104, -2557, -603, 2115, 966, + -3763, -3183, -851, 4502, -1565, 10062, 313, -709, + 10707, 867, 3820, -2747, 3470, -1942, -486, 4092, + -6289, -2363, 556, 3190, 5046, -1869, 2886, 10572, + -948, -4191, 1544, -1727, 721, -3153, -712, 934, + 1610, 1070, 1248, 10645, 2340, -11102, -2744, -353, + -65, -4973, -1782, -1037, 1210, 1192, 1138, 1106, + 9422, 652, -9595, -1663, 460, 9107, -2827, 775, + 1131, 4732, 93, 476, 387, 32767, -161, 266, + -406, 604, 675, 83, -589, -639, 220, -830, + 2200, -142, -2000, -128, 902, 823, 287, 717, + 1857, -1626, 208, 2784, -72, -19310, 6190, -2063, + -9101, 3419, 1721, -2092, 332, -6533, -7594, 1138, + 807, -2582, -668, 410, -497, 1526, 96, 944, + 3319, 1294, -335, 1964, -380, -618, 3069, 101, + 18964, -2298, -10304, -1190, -998, -1384, -11466, -256, + -4475, 4027, -3532, 1828, -1311, -3417, -3925, -221, + 27688, 2277, -1227, 1043, -399, -3327, 515, 1665, + -616, 2724, -546, 4608, -576, -103, -9064, -1281, + -563, -3588, 2174, -824, 3379, -2360, 354, 844, + -7044, -2295, -2613, -11152, 1006, -1064, -17007, 1180, + 387, -8448, 836, -578, 2621, -356, -1476, 2362, + 822, 4547, 118, -11628, 352, 367, -958, -12423, + -65, -1591, -2304, -2880, 1684, 1708, -1693, -781, + -71, 10012, -534, -3672, 417, -2048, -1955, 10491, + -1257, 861, -414, -4058, 3042, 1529, -5823, 6877, + -3918, 993, 221, 2576, -7780, 170, -648, -139, + -3410, 7974, -756, 2657, -596, 12527, -199, 13752, + 2198, -938, -2265, 1736, 257, 1517, -676, -1165, + -2874, -2433, 123, -829, 2605, -10270, -3158, 3624, + 2072, 6960, 1490, 4634, 455, -8175, 1139, -4545, + -1491, 3727, -8738, -1951, 593, 14, 2897, 2490, + -2273, -1436, -10992, 3005, -4392, -3434, -4561, -1014, + -9506, -1609, -1248, -1593, -190, -10472, 3264, -2274, + 5097, -633, 473, 427, 725, 1577, 11032, 318, +-12228, 78, -1116, 441, 1930, 4041, -648, -4324, + -224, 2738, 8826, -40, 327, 1761, 2371, 171, + 4039, -3411, -2495, 1150, -12181, -1704, 35, 528, + 417, 626, 1866, -472, 466, 905, -854, -875, + 1194, 24371, 488, 26, 695, 1777, 798, -169, + -16, -1252, 395, 871, 1170, -635, -1637, 2094, + -5427, -16393, -384, 3872, 33, -687, -1777, -4160, + 3020, -1906, 3868, 699, -400, 6755, -3253, 12699, + 1474, 7312, 991, -646, 26770, 2524, 2144, -500, + 1096, -1869, 1036, -1707, 521, -2091, 1445, 2335, + 107, 238, -227, -120, -32768, 591, -257, 867, + -1231, 650, -465, 356, 431, 762, -516, -594, + 512, 242, 2298, 1012, -1538, -11748, 3551, -5608, + -2174, -2428, 10557, 625, 1002, 27865, -589, -1527, + -1552, 156, 1905, 1041, -4190, 2300, 1603, -980, + -1764, 484, 1555, -2664, 381, 11676, -8848, -3060, + 675, -646, 736, -1279, -1261, -1988, 543, -1880, + 1917, -2165, 2846, 11863, 2076, 10381, -307, 4354, + 73, -2788, -2464, 964, -218, 1552, 1846, 1470, + 577, -594, 725, 30798, 43, 13, -1474, 260, + 1218, 1433, -114, 1020, -648, -678, -1879, -65, + 791, 366, 8547, 931, 1091, 1018, 16312, -1116, + -777, -1098, 404, 180, -899, -2865, -10089, -751, + 40, -2358, -2980, 3574, 7905, -190, 9207, -18, +-18766, -270, -5300, -2023, 2422, -1189, 1267, -1085, + -704, 6823, 2164, 2, 125, -2319, 411, 591, + -488, -566, -3394, 304, -12375, -268, 11098, -150, + -2392, -1255, 3172, 162, 1295, 5897, 7944, 6019, + 3329, -2014, 2957, -4933, 4805, 2780, -5453, 2680, + 3220, 2784, -549, -19908, -1222, 550, -3540, 1822, + 4082, 2399, -6844, 2145, 938, -597, 122, -20, +-14986, -1620, 1575, 561, 408, -6305, 760, 1634, + 2652, -8301, -2988, 1864, 2524, 3228, 7466, -2620, + 410, 1364, 1740, 2204, 1999, 1704, -2601, -351, + -104, 10688, -7166, 134, -346, 11852, -13322, -3171, + -1230, 1109, -2336, -962, -563, 1030, 2832, -969, + -1997, 3233, -414, -8246, -2074, 2737, 3557, 1625, + 1036, 845, 1848, 1710, -10388, -4586, 6915, 2734, + -8693, -667, 1568, 1758, 2396, -3262, -2497, -1472, +-11848, -689, 3379, 1692, 1449, 2844, 8524, -15598, + 337, 590, 3303, -1594, -2548, 4529, 433, -1921, + 920, 1061, -1693, 191, 44, 957, -2397, -1126, + 41, 2164, -1587, 568, -17290, 4687, -1028, -403, + 1169, -1282, -1602, 242, -1234, 1870, 1067, 2444, + 1752, -2552, 8775, 1384, 5683, -4770, -12436, -680, +-13344, -196, -276, -299, 734, 12378, 2364, 327, + -1494, 560, -90, 3394, 496, 2357, 629, -17, + 1040, -706, 589, 294, -1135, 25012, 444, 1206, + -298, 1424, 1524, -2188, -64, -1101, -1998, 374, + 1377, -1382, -11349, 1456, -171, -2369, 6966, -2808, + -8987, 3390, -811, 671, 3032, -3396, -9815, 2246, + 4418, -678, 1851, -1592, -11038, -1194, -3612, 2589, + -250, -495, 1203, 1348, -805, 1853, -345, -555, + -8755, -9695, -3768, -1506, -8172, -322, -7163, -6319, + 2052, 116, -4459, -2328, 4857, -2569, 1419, 959, + 1138, 7034, 4836, 3449, 6826, 13411, -893, 981, + -2060, -3710, 3177, -761, -1128, 4386, -127, 6698, + 3426, -2922, -61, 408, 1426, -1238, 15468, 94, + 373, 3597, -2432, -1989, -859, -8976, 2938, -777, + 409, -206, -7758, 3384, 295, -466, 29, 7925, + 2048, 930, 2296, -10030, 330, 7864, -1004, -385, + 2130, 388, 3587, -4480, 1560, -12768, -2606, 8178, + 771, -3519, -1590, -592, 2192, -1126, -77, -3947, + 1868, -1304, 11107, 781, 6240, 4134, -3314, 407, + -6125, 5168, -503, 2155, -990, 143, 219, -9950, + -1186, -1446, 1930, -8963, -4084, -6141, -976, 153, +-13665, 564, 13631, 138, -269, 379, 1333, -1710, + -940, -511, 1214, -2190, 1347, -1397, -1321, 94, + -1802, 6627, 1306, -12347, 2780, -1091, -4362, 5047, + -446, -3472, 6064, 1075, 478, 769, 58, 802, + 562, -1581, 28580, 194, 1338, 573, -555, 617, + -409, -1249, -8, 1133, 952, -120, 2502, 5313, + 969, -1664, 1769, -12199, 5551, -402, 4862, 3270 +}, + +.cb2224m1 = { + 32767, -54, 1385, -206, 19, 522, -1176, -667, + -260, -1388, -1751, -2234, 228, -343, -893, -898, + -1004, 2517, -232, 20996, 507, -1857, 2574, 840, + -615, -1922, 660, 844, 52, 1272, 609, -692, + 21805, 938, 678, -399, -22, -1839, -996, 1560, + 218, 3973, -6547, -1151, -3914, -789, 938, -11509, + -2282, -606, -327, 3088, 797, -1540, -7598, 1378, + -100, 2108, -1907, -11671, 1538, 11136, 310, -2096, + -3037, 3181, 1731, 2043, 3424, -1098, 2046, 545, + -1778, 605, 932, 832, -2356, -1498, 1129, 11542, + 119, -10994, -3720, 4316, 346, -9141, 3921, -918, + -5476, 372, -318, 9254, -681, 4896, 1587, 1620, + 1850, 4057, -1507, -362, -1074, -328, -1502, -3092, + 2735, -378, -11572, -1292, -2575, -3397, -7566, -8977, + 1670, 8659, -655, 884, 1815, -9348, 570, 394, + 1670, 1942, -195, 386, 553, 8885, -9206, -624, + -2312, 15852, 782, 562, -1497, 720, 1804, 1415, + -3809, 3783, -1918, -3496, -637, 581, 1161, 961, + -960, -930, -1673, 904, 11510, -2286, -9964, 2964, + -5752, 2229, 786, -1479, -18882, 1517, 128, 3282, + 157, -2178, -564, -6029, 766, -4599, 3620, -4380, +-20114, -677, 2134, -93, 1486, 648, -4790, 1862, + -1476, -56, -3443, -2622, -2806, -1185, 122, 1801, + -1547, 12241, -2785, 2386, 56, -4075, -10964, -832, + -4744, -1350, 2849, -255, -1375, 163, 1306, 37, + 2304, -1396, -11234, 9712, 1732, -2262, 3632, -431, + -579, -4045, 806, -12168, -1309, 840, -1474, 918, + -1240, -1601, 48, -4137, 6934, 3968, 7370, 4088, + 8648, 2351, 1466, 615, -12314, -2347, 4382, 862, + -4288, -3138, 1886, -4357, 375, 1949, 73, 287, + 135, -60, -1498, -2427, 1263, 3322, -582, 17508, + -1202, 1558, 3351, 484, -439, -571, -370, 11952, + 11656, -1407, -1410, -2976, -459, 397, 1980, -1374, + 1237, 5044, -2074, 405, -10650, -174, -12556, -1962, + 4569, -1293, -200, 3106, 343, 748, 1918, 1084, + -670, 3, -1070, -397, 3965, 9966, -609, 9691, + -900, 137, 2305, -5944, -944, -1500, 638, -703, + -582, 10098, -523, 776, 1266, 4860, 6213, 1181, + -5634, 518, 9116, -4740, 10683, -547, -1295, -91, + 104, -3115, -1724, -17, 1953, -745, 694, -474, + 12248, -596, -674, 765, 674, 4494, 1205, 5883, + -1638, -3996, -664, 8694, -5620, 3968, -717, -10425, + -285, -12605, 368, -3904, 12363, -1288, 1242, -1497, + -3117, 2396, -220, 1700, -2788, 250, 107, -150, + 345, 681, -44, -2466, -389, 2098, 312, 54, + 2734, -22225, -1232, -1778, 1063, -1586, -6658, 344, + -2889, -4348, -3685, -2100, 12, -1755, -6401, -149, + 8150, -10689, -748, 1443, -32768, 1698, 1461, 216, + 1373, -2814, 1014, 1135, -227, -1309, -616, 1566, + 395, -724, 852, 1579, -9647, -1214, 728, 329, + 9244, 179, 7204, -836, -3954, 168, -5722, 152, + -2886, 472, -651, 5114, 8734, -71, 11406, 1098, + -1452, 1190, 598, -880, 14611, 12540, -1523, 1340, + 1015, 1510, -208, 206, 1314, -1532, -246, -3210, + -1637, -197, 197, -32768, 1448, -191, -1720, -217, + 1021, 973, -2099, 56, 606, 39, -1569, -1205, + -2375, -2156, 4798, 2504, -11914, 933, -6015, 2657, + -2911, -5173, -1964, 1576, 5268, 1190, 675, 856, + -1718, -4332, 166, 1556, 19005, 2040, 1198, -2170, + 1824, -3409, 121, 830, -252, -525, 289, -1701, + 292, 854, -1150, -1108, 171, 511, 22114, 662, + -1263, -540, -2306, -2332, 869, -5191, 186, 536, + 410, -7576, 590, 13625, 3519, 3858, -2787, -376, + -6506, 891, 5025, -2054, 8316, -2115, 7668, -5808, + -2464, -2422, 1541, -3851, 1578, 420, -617, -6507, + -858, 160, 3876, -2830, -5970, -3295, 9829, 1099, + 1617, 3502, -3124, -4116, 138, 287, 914, -548, + 1056, -1546, 1218, -227, 11632, -574, -996, -9894, + 808, -5868, -1457, 8374, -2086, -280, 1038, 528, + 1862, 284, 3926, -144, 7168, 1224, 11628, -221, + 1018, 1683, 922, 561, 6910, 1895, 3044, 12613, + -74, -1424, 1654, 8872, 2255, -990, -2039, 269, + 9558, 10122, 958, 466, -1948, -1242, 1042, 886, + -1143, -3444, -8720, 1918, -300, 19074, -1629, 991, + 908, -896, 1207, 3602, -4802, -2912, 4100, 2936, + -1344, 459, -6904, -714, 524, 171, -1430, 1454, + -2725, 1130, -757, 2861, -11174, -2768, 5466, 3662, + 110, -1999, 12376, -2173, -2508, -2838, -2025, -4378, + 134, -9856, 1738, 1027, 1428, 38, -1560, 12824, + 13932, 549, 586, 720, 923, -1040, -2827, -3272, + 1902, -2113, 2624, 3296, -34, 12291, 1449, -12138, + -796, 186, 2777, -1007, 3276, -587, -1917, -130, + 2120, -564, -364, 1005, -615, 1504, -2412, 9219, +-11412, -2490, 1262, -2720, 1608, -3276, 1294, 1882, + -188, 7090, 6029, -4207, -2739, 72, -10035, -1672, + 1509, -124, -1649, 420, -3623, -1069, -11225, -754, + -388, 790, -3209, -330, -2632, -11920, 3178, -1788, + 2585, 4146, 1944, -2757, -10616, 220, -14136, 2158, + -274, 2010, -362, 1107, -348, -1990, 96, -985, + 1599, 1566, 1393, 304, -1380, -924, -285, 620, + -30, -902, 26210, 1485, 1042, -1160, 352, -177, + 1245, 1879, -18, 727, -421, 223, -1298, 1066, + 962, 1306, 3866, 870, -18780, -3873, 107, -1408, + -1261, 808, -818, 1738, 1439, -2156, -1499, -2108, + -4626, 4039, -964, 16682, -1169, 266, 9373, 1238, + -2728, 2381, 12159, 2155, -472, -2293, -513, 3808, + -690, -2190, -1139, -6, 1379, -22803, 1380, -612, + 308, 1394, -902, -1454, -2620, -1080, -2864, -3301, + 108, 218, 8718, -617, -1098, 1436, -2005, -3966, + -2658, 6152, -874, -4636, 8705, -3382, -12072, 418, + -1837, -12582, 270, -788, -1174, 2156, 461, -297, + 478, -632, -356, 5796, -12024, 416, 2602, 3544, + -1240, -970, 4874, 7221, 704, 8940, 2316, 1174, + 2537, 5380, -5, -1818, 3020, -4120, 7042, -9618, + -1622, 3576, 2455, -298, 451, -5298, 7371, -1570, +-12956, 9758, -216, 889, 5395, -2779, -4036, 1736, + -1871, -2036, -1119, 1847, 912, 2292, 850, 220, + 1300, 2228, 399, -2885, -2696, 2399, 3179, 6266, + 1629, 13091, -232, -5322, 1397, -724, 1666, -2012, + 3643, 1400, -2724, -18007, -506, -103, 1318, 2473, + 965, -587, 1135, -904, -510, -10767, 1937, -585, + -73, -1662, 3021, 340, -12475, -1618, -1, -1914 +}, + +.cb2232l0 = { + -9947, -673, 522, -36, 396, -433, 949, -442, +-12495, -2186, 4280, -997, -1715, -7385, -379, 3498, + -572, -9897, 6686, -4736, 577, 1866, 659, -123, + -1682, 420, -866, 4458, 5821, 3155, 7929, -5562, + -1798, 3086, 8556, -65, -8943, 2354, -4187, -3798, + 627, -1859, -9760, -1811, -1724, -45, -1838, 1638, + 499, 148, -335, 20916, -264, -556, -269, -1014, + -1531, 711, -519, 462, -5117, 3944, -950, 8277, + 878, -4803, -5003, -4402, -4722, 2988, -144, -6887, + 10661, -909, 700, -2287, 12126, -101, -761, 1836, + 827, -609, 538, 442, -4504, 1812, 3818, 7359, + 96, -555, 1598, 10040, -554, 924, 3426, -1786, + 2620, -2132, 867, -519, -2299, -672, -508, 201, + -2457, 10872, -5003, 5422, -8890, -104, 2579, 940, + 401, 871, 11167, 1216, 1054, -2876, -1523, -3950, + -1229, -3410, -428, 3648, -9389, -3025, -1752, 7583, + 3953, 1938, 3899, 1435, 8170, 1019, -2320, 1299, + -1152, 226, 394, 11328, -1471, 604, -184, 567, + -3704, -5723, -5938, 423, 9362, 4546, -3318, -3395, + 5084, -4341, -1781, -2619, 1078, -365, 151, -413, +-21591, -968, -202, -183, 849, -481, 407, -11, + -2708, 2472, 2689, -9232, -9482, -1776, 645, -1510, + -1410, -6115, -114, -2550, 1922, 1668, 288, -1302, + 948, 1967, 52, 2393, -1975, 374, 17358, -1332, + 5303, 3195, -2674, 4784, -1418, -1359, -57, -2126, + 4618, 8890, 6455, 1181, 76, 374, 9585, 8762, + 672, -642, 666, -6485, 1751, 3255, -934, 6196, + 892, 171, -102, -44, -326, 1330, -320, -480, + -842, -22376, -561, -141, 635, -6528, 5711, 2400, + 838, 2846, -3212, -5341, -5479, 4961, 2110, -7480, + -4215, 7964, -1308, 1219, 1541, -4418, 6293, -4522, + -4887, -5760, 2790, 1441, 6135, -1133, -1627, 1235, + 914, 572, -1043, -1473, -519, -4618, -1228, -12212, + 1101, -10794, -4292, -4355, 6431, -588, -992, 612, + -1771, 6751, 4871, 581, 620, -352, 277, 727, + 2226, 8552, -43, 2295, 9409, 1122, 7618, 1885, + 1192, -1432, -1103, 8666, -2078, -403, -1787, 1572, + -2200, -7705, -6743, -1277, -1228, 955, 7613, -1536, + 8530, 5703, 5446, 4251, -853, 4910, 1578, 2832, + 1274, -2610, 243, 2820, 951, 9240, 1617, 605, + -6755, -2728, -5658, 3866, -157, 1215, -8470, -2038, + -189, 10411, 7444, -376, 407, -1128, 770, -410, + 503, 1707, 786, -529, 82, -27, 21512, -282, + 81, -1129, -686, -555, 2674, -99, 1284, 2216, + 1238, 404, -3398, 1010, 3966, -1134, -2682, 14222, + -1581, 9779, -1114, 848, 1905, 2129, -3937, -4742, + 1229, 8051, -4344, 3914, 4273, -659, 159, -1188, + -1844, 912, -1256, -478, -16158, -2869, 959, -2096, + -2166, 2360, 7861, -2718, -6358, 7653, 6639, -3239, + -1690, -1242, 3439, 1254, -954, 604, 17512, -288, + 2412, 211, -298, 2656, -5217, -1770, 892, 1979, + -1482, 3498, -40, 10424, -1038, -1862, 9905, 298, + 77, 2179, -4444, 2580, -2069, -6473, 61, 84, + 1035, -645, -662, -824, -743, -104, -1962, -124, + 4976, -5378, -1254, -7055, -3474, -10695, -1254, 2547, + -694, 3194, -82, -2634, 230, 358, -12, 1594, + -90, 598, -76, -21136, -1278, 846, -84, 259, + -2536, -4442, 2337, -1606, -3264, -3126, -591, -1295, + -2440, -2592, 10888, 5821, -862, -5070, 10402, -10633, + 159, -2660, 894, -2112, -1774, 3732, -1020, 422, + 9487, 1608, -992, 2046, 275, -10676, 2606, -999, + 477, -1868, -1690, 4764, -6419, -7550, 8159, 529, + 2308, -394, -2394, 2826, 6680, 496, 3628, -646, + 3186, -657, -2260, -1416, -9202, 496, 6624, 2441, + 1554, -2195, -8458, -3459, 466, 6706, 1056, -8777, + 5436, -4000, -3130, 4794, -6127, 2008, 1602, 195, + 558, -1362, -880, -2662, 9726, -9793, 2989, -3182, + -2378, -1338, 1086, -4682, 372, -399, 11129, -601, + -666, 5206, -1106, 362, 3155, 328, -9862, 719, + 1602, 998, -2342, 857, 1510, 476, 7256, 4652, + -5750, -4991, 4611, 8718, -4434, -4119, -351, -1606, + -1033, -3717, 3585, 9381, -1594, 5052, -7414, -205, + 2356, -5949, -8738, 1526, -1838, 4760, -5444, 623, + 112, -2863, 5710, 4920, 9497, 3759, 10748, -201, + 716, 747, -2559, -4077, -449, -741, -136, -1303, + -572, 1886, -986, -10529, -51, 1360, 2418, 116, + -1490, 1928, -9977, 4720, 227, -11212, 3730, -2996, + 1300, 9935, 356, -4618, -384, 972, 3174, 3732, + -803, 2666, 790, 2067, 2343, -1209, -10147, 21, + 9066, -4564, 2508, -176, 264, 9834, 3360, 7278, + 9386, -1274, 522, -50, 4150, -884, 592, -688, + 309, 20750, 672, -1326, -346, 366, 2058, -607, + 633, 620, -677, 330, 69, 432, 319, 436, + -300, 21845, -318, -676, 320, -386, 889, -724, + -1394, -2664, -431, 2046, -136, 5520, 6700, 1192, + 5779, 9386, -3541, -5638, -16125, -259, 545, -267, + 1972, -2366, -43, 615, 251, 1003, -980, 2262, +-10519, 12166, 2007, -884, -1560, -1250, -491, -438, + 820, 1212, 3512, 354, -1066, -46, 98, 315, + 8532, 944, -1297, 8011, 1029, -383, -1606, -8381, + -1650, 2852, -958, 1757, -4270, 2160, -9283, 2918, + -3718, -224, 6154, -5671, 3764, -554, 5214, -2526, + -31, 547, 6, 1633, -4562, 1424, 1177, -866, + 1648, 653, 6056, -1845, -1271, -350, 596, -2286, + 9893, -6594, 1099, 630, -537, 230, 972, -134, + -491, 79, 306, -74, 253, 208, -1804, 73 +}, + +.cb2232l1 = { +-11397, 378, 12845, -1813, 342, 329, 1165, 550, + 556, -115, 755, 117, 2511, 260, -1189, -1406, + -1528, 1866, 3300, -9678, 1025, 10413, 199, 2878, + -3572, 8701, -1895, -1189, -576, -3384, -162, -10866, + 3253, -1267, 91, 2277, -86, -3394, 6576, -2475, + -1136, -4295, -1610, -8064, 297, -8908, -4433, -2954, + -82, -11426, -4610, 2063, 1522, -7972, -495, 1799, + 2922, -5179, -865, 4739, 11072, 3927, -483, -11111, + -2375, -1432, 1210, -1342, 2418, 1688, 852, -64, + 133, -4582, -7136, 10558, -3417, -3162, 2033, 3149, + -3050, 2532, 568, -2444, 4082, -2859, -10350, -4983, + 6633, 230, 5954, -1140, -657, -998, 1156, 736, + -8894, 64, 939, -260, -1704, -526, -1330, -869, + -2427, 12377, 1296, -120, -10560, 1794, -9090, 1487, + 7162, 519, -382, -3234, -66, 1294, 2363, 1482, + 498, -4053, -752, -154, -587, -293, 16533, 65, + -1211, 1666, 291, 2820, 2222, 2, 865, 344, + -1206, -1214, -2162, 8842, 11063, -2093, 1896, -857, + -144, 321, -9548, 4464, 5038, -282, 1160, -194, + 823, 3479, -8234, 5834, -320, 7114, -184, -2663, +-11670, 472, -2013, -1282, 4390, 4453, -2126, -2483, + -900, -6262, -2237, -539, -1134, 164, 426, -8969, + -1746, -1960, 8172, -2127, -19948, 657, -712, 344, + -443, 458, -564, 56, 756, -157, 274, -1324, + -3372, 2981, 635, -9454, -4916, 2884, 2316, 8200, + -1452, 2135, 1785, -1054, 82, 5007, -4164, 642, + 9241, 5091, 1002, 2467, -8409, -854, -861, -2317, + 405, -1810, -793, -7907, 496, -1005, 3373, -1016, + 9527, -542, 1672, -9105, 280, 11170, 273, 908, + 89, -233, 10850, 870, 436, 1630, 3328, -499, + 5091, 1224, 9135, -480, -1134, 2428, -2904, 5077, + 2014, 2859, 4277, 7763, 8719, -11474, 1619, 1167, + -3188, -1063, -433, -4291, 2646, 1024, 2008, 317, + 746, 327, 6824, 1174, 8978, 5254, -8948, -136, + -2602, -1442, -698, -950, 1800, 296, -1016, 1653, + 3771, -9326, 4536, 7033, 4729, 6630, 1042, 167, + 11485, 12338, -147, 2834, 611, 1844, -313, 486, + -916, -887, -1423, 642, 242, 75, -1875, -645, + -1239, -2118, 1458, -272, -1703, 949, 778, 21826, + 214, -1320, 310, 2680, -1542, -2202, 1072, -132, + -2067, -3593, -8293, -10331, 9030, 402, -2702, 2984, +-12068, 3170, -1098, -1175, -1188, 2998, 1159, -1712, + -904, 236, 42, 823, 548, -546, -1954, 15989, + -2212, 1886, 2300, 2293, 2606, 2905, 2365, -1214, + 1592, 1362, -2210, 1674, -1892, 15049, -1012, -2824, + -792, -11447, 11144, 4853, -357, -1230, 748, 1212, + -294, -424, -2720, 78, -2149, 966, 7794, 1645, + 138, -709, 464, 3614, -10308, 310, -4726, -3694, + 1088, -576, 690, 68, -145, -3282, -9280, -9537, + -1274, 3202, 588, 1790, 1437, 3880, -1803, -1154, + 15082, -2388, -1746, -885, 2267, 1813, 1688, -1039, + 9775, 350, 3218, 10550, 1048, -3731, -3748, 3517, + -910, -663, -413, -1045, -1236, -248, -132, -1196, + 12, 15815, 653, 1429, -371, 4094, -3050, 567, + -5524, -11128, -4261, 1929, -1719, 8236, 686, 1309, + -1057, -715, -2586, 1327, -38, -6180, 3499, -2080, + 8980, -1890, 62, -1004, 3308, 5809, -5778, -3865, + -610, 180, -519, 3129, 9000, 1607, 8484, -4056, + 4741, -4491, -355, -1324, 1203, -1864, -811, -15995, + -121, 1325, -817, -2170, -5753, 731, -1875, -2286, + -9193, -307, 247, 2469, -1738, -12290, 31, 1028, + 670, -66, -1856, 570, -3542, -3401, 144, -320, + -524, 184, -928, -1606, 10978, -3114, -8861, 1467, + 1156, 872, 8276, 5655, -695, 2788, 3733, 2155, + -2044, -10260, 1683, 1859, -263, 17966, -19, 1621, + 50, -261, -4143, 1245, -22, -1564, 809, 2462, + -8005, 1247, -1471, -763, -1686, -698, 2868, 796, + 4036, -3672, 11209, 1102, -9369, -1008, 1273, -906, + -4458, 1642, -3254, 3563, -94, -6267, -604, 8687, + 2388, 2214, 1759, -7788, 4296, -7467, 3547, 3248, + 845, -7784, -2195, -42, 5327, -1002, -3915, -4581, + -1215, -919, -3444, 5142, -1874, -3020, -2627, 1129, + -4456, 1840, -11472, -914, -6366, 3495, -2775, 484, + -5859, 980, -1967, 1350, 929, 6856, -3952, -3365, + 1514, 7423, -675, -2260, 6027, -3072, -6388, -3716, + -2398, 5564, 1447, -86, 1180, -1239, -1372, -435, + -1314, -1978, 942, -2018, 1027, 704, 20417, -94, + -1239, 252, -171, -1100, 1684, 1401, 623, -354, + -2674, -5042, -734, -6631, 7587, 4901, -1596, 6806, + 4230, -859, -867, 1266, -3869, -3972, 1548, -4889, + 2811, 2263, 2468, 354, -6197, -1278, 1947, 5675, + 10612, -1730, 2056, -70, 3034, -583, 879, -3719, + -8623, -1241, 822, 5832, 163, -1075, -784, 398, + 1170, -717, -374, 856, -21602, 89, -513, 260, + 854, 1152, 762, -601, 523, -107, 1033, 1877, + -1456, 226, -20758, 365, -8943, 1305, 193, 948, + 295, 2696, -3165, -1982, -2439, 1067, -12266, -1018, + 3400, -178, 1995, 11745, 1833, 9785, 1171, 582, + -1844, 157, -1242, -4080, 864, -1771, -4257, 721, + -4010, 7990, 142, 730, 1976, -6623, 4637, -7394, + -1143, -835, 3341, 1732, -7266, -448, 5379, 290, + 1855, 6977, 6637, -6561, -1370, -1767, -2769, -1189, + 3872, -4895, -4679, 3906, -1664, 1514, 7908, -7960, + -4147, -1235, -1706, 3314, 144, 1668, -9505, 2268, + 4147, 2515, -1451, 6475, 1675, 106, 981, 201, + 309, 60, -133, -472, 561, -380, 1130, 91 +}, + +.cb2232s0 = { +-26218, 1606, -390, -696, 266, -947, 561, -1526, + -8, 1080, -187, 5671, 2249, -30, -4129, -768, +-10908, 3826, -10422, -144, -1259, -1372, -3553, 1287, + -5151, 6442, -5101, 1386, 791, -1593, 12942, -764, + 424, -6212, 9733, 702, -9721, 524, -4818, -1232, + 6, -484, -818, 955, 6425, 3594, 5156, -286, + 1514, 4466, -1756, 11321, -679, -1481, -477, -8015, + -3059, 4476, 679, -1143, 2877, 2581, 3230, 239, + 12018, -1597, 13431, 11852, 260, 3306, -714, 1299, + -4375, -778, 170, -565, -3510, -6632, 3354, 5901, + -1070, -5912, -3430, -4970, -4712, 2648, -9113, 1561, + 1002, -5659, -3177, 638, 2289, -1050, 12310, -10364, + 2830, -961, -194, -6442, 2206, 3454, -2087, 4327, + 1080, 10257, 8107, 4904, -3141, -2339, 7568, -363, + 3765, 7960, 7067, 1496, -3842, 1805, 2415, 913, + -1641, -5411, -7583, 4597, -1324, 2882, 11310, -2570, + -2877, 3544, 4642, -2249, 7110, -307, -3413, -2871, + -8974, -6358, -5703, 4046, 83, 1887, -3476, -4346, + -2995, -346, -46, 22143, -576, 2597, 696, 1520, + 140, 2937, -3356, -988, 4090, -1246, -3347, 1387, + 2264, 1282, 7040, -806, -12810, -1105, 32767, -4266, + 108, -1998, -680, -1279, -467, -110, 462, 768, + 1678, 1408, -1888, -1115, 9430, 5852, -3578, 5367, + -1096, -4310, -9588, 4350, 6048, 2516, 3214, 4468, + -276, 15175, -848, -2875, -314, -6002, -11743, 448, + 9238, -3026, -3934, 2840, -2070, 1850, 444, 511, + -542, -7382, 6002, -14447, -1498, 176, 812, -2632, + -2291, -3312, 3953, 370, -2154, 1678, -1186, -6382, + 1544, 3534, -3767, -7459, 7265, -3272, 10669, -1677, + -7046, -1679, -132, 2108, -1948, -2938, -5393, -6222, +-11293, 2066, 981, -731, 1869, -2211, 3558, -21513, + -678, -493, -2087, 245, 635, -2011, -3316, 13445, + 2089, -10186, 1114, -1241, 2121, -2305, 3316, -1282, + 2733, 318, 3534, 4844, -1439, 8932, -7649, -556, + -7519, -3442, 5068, -3546, 8586, -8425, 7146, -683, + 665, 3052, -2581, 248, -8320, 2270, 7045, -800, + 5890, 2187, -251, -2552, -3867, 3665, -1643, -11757, + -5542, 1806, 3669, -508, -3436, 600, 10412, -5426, + 1680, -4545, 11536, -1859, -5446, -4594, -4300, -1173, + 282, 2100, -2556, 9486, -7325, -7252, -3155, -775, +-13674, 4272, 3066, 9352, 1647, 1136, 794, -520, + -654, 1539, -2244, 3155, -12039, 731, 3379, -1904, + 6866, 9669, -2384, 2099, -2426, 1633, -3358, -5662, + 2164, 10679, -5330, 7066, 5826, -187, -4840, -1174, + -3694, 976, -2548, 2292, -3517, -1007, -4041, 684, +-14986, -4789, -4135, -4376, -10678, -1482, -10466, 3575, + -1960, 3185, 1198, -196, -892, -5424, 4802, 13608, + -7772, 3952, 4404, -52, 1097, 3182, -2699, 900, + -1258, -8055, -3102, 784, -2574, 1556, 1060, -5417, + 537, 11991, -650, -487, -10250, 6766, -3716, 1062, + 2525, 1039, -3002, 5742, -502, -4583, -144, -144, + -5896, -978, 1786, -1420, 1944, -130, -5202, -1578, + 7821, -11675, 9980, 5065, 5942, -362, 16344, -801, + 1932, 1242, -10, 791, -170, -2468, -479, 3297, + 4328, 11473, -1549, -12316, 209, 1739, 1875, 1305, + -4310, -13049, -4913, 9208, -966, 2570, -138, 890, + 1373, -1324, -965, 8563, -7560, 490, -1392, 5695, + -5656, 5431, 3974, -1131, -1246, -1334, -3859, -3150, +-12976, -6929, 665, 9393, 490, 2212, 18, 542, + 229, -3925, 1836, 4223, 5268, 1200, 471, 20, + -9914, -5774, 8362, 5929, -7087, 2005, 15624, 1626, + 5419, -1492, -1536, -417, 1957, 2585, -404, -1125, + 2296, 596, 836, -356, 745, -2810, 2879, -2354, +-21682, -108, 726, -862, 593, -42, 266, -1356, + -2119, 19613, 814, 2462, -2940, 222, 3595, 5634, + -807, 1219, 2446, 5666, -1839, 7092, -10581, -5136, + -2408, 5726, -1116, -2348, -6318, 8991, 6750, -5321, + -7344, -2194, -5544, 1705, 12500, 9069, -1966, -4914, + 2225, 3537, -1485, -5141, 434, -1620, -5383, -710, + -5443, 3930, 7082, 667, -3289, -3202, -2097, 1970, +-11647, -2927, -2098, -1345, 3449, -2075, 262, -756, + 1829, -271, -1292, 1079, -5746, -344, 3660, -4456, + 3593, -7652, -1367, -828, -2290, 1063, 4234, -17596, + -911, -6068, 1040, -2956, 2704, 1763, 974, 3132, + 697, 1267, 240, -5520, -12368, 10830, -633, -5939, + 2307, 1868, -2216, -1261, 597, -6302, -5145, 3550, + 7519, -6963, 3752, 876, -1912, 30, -9192, 1075, + -4632, 9108, 1139, 911, 9290, 1268, -1006, -1718, + -6668, 3294, -1510, 6527, 456, -1400, 11424, -4168, + -3940, 4738, -4863, 2990, 3202, -441, -4744, 4623, + -4351, 3997, -11016, -737, 136, 7978, -3801, 4170, + 3602, -2217, 849, -2552, -22232, 323, 193, -4, + -1030, 590, 1625, 3208, -10595, 2624, -741, 13121, + -1044, 1601, 5175, 2199, -3833, 1804, -2314, 793, +-11486, -655, -3320, -2975, 4065, -3124, -706, -7264, + -1038, -3082, -5503, -7147, 8367, 1205, -1092, -1694, + -1078, 11584, 8, -1237, -2077, 9732, 4963, 2780, + 674, 581, 8226, -1231, -9252, 644, -3284, -744 +}, + +.cb2232s1 = { + 32767, -45, 422, -1139, -1052, -2085, -695, -612, + 1451, -288, 58, -878, 53, 2912, -1891, -7148, + 1893, 3028, 165, 963, 2260, -7904, 5857, -18824, + -2617, -1030, -872, 1500, 1118, -745, 143, -436, + 1239, -3840, 1785, -2506, 20237, -1026, -1556, -1371, + -660, -1185, 939, 1315, -3658, -5428, 587, -4105, + 1596, 12612, 5781, 1172, -3490, -1182, -333, 6258, + -2594, 2144, -4830, -190, 1972, 2687, 1327, -987, +-15046, 4659, -71, 6890, 1588, -4787, 4318, -3704, + 496, -5601, 1954, -1250, -3389, -5156, 9238, 2298, + -4945, 183, -2036, 114, 12250, -2330, 71, -3395, + -1402, 3668, 531, 10915, 1162, 7738, 9089, -1250, + 1500, 6357, 1155, -5094, -2641, 1657, 470, 2022, + 535, -306, -18031, -903, 2913, -5486, 1769, -1419, + 9082, 2149, 3516, 6960, 833, 1123, 1266, 1672, + -690, 9634, -2986, -4675, 1006, -2205, -2919, -3205, + -2759, 107, -931, -9694, 2340, -862, -2782, -3636, + -9414, 9564, 1057, 8664, 1326, 3928, 1452, -4692, + -3437, 8610, -10466, -6638, -2879, 3408, 861, -3057, + -823, 164, 3153, -3698, -15693, -886, 1456, 3278, + -6160, -57, 1110, 22, -2985, 7299, -1082, -7921, +-12212, 480, -7645, -211, 1586, 3874, 3242, -883, + 6730, -1597, -506, 3744, 7552, -7607, -65, -1442, + 266, 10012, 1594, -2628, 6988, -1049, -516, -691, + 672, 4913, 1788, 14973, 342, 962, 7212, 1124, + 500, 1135, -311, 3886, 12548, 5432, 6219, 3341, + -122, 5636, 6871, -10831, 4010, -10084, 1456, 5216, + -1013, 1102, 4164, -1490, -5186, -242, -4498, 3322, + 3584, -2176, 5704, 515, -11556, 1446, 4303, -3928, + -4227, -7268, 6069, -11330, 822, -2054, -3035, -2516, + -1816, -3796, 8408, 8849, -3030, -8201, 1149, 7388, + 1036, 2586, 5618, -2274, -5037, -1497, 384, 1454, + 8154, 1672, -2409, 3347, 13258, -979, 513, 7826, + 2662, 1818, 5537, -1104, 2645, -10632, -8767, -5667, + -1029, 806, -9040, -4684, 792, -5008, -5807, -3924, + 964, 313, -2521, 1106, -5728, 13534, -8078, 4216, + -1388, -2588, 986, -14536, -1410, 3461, 1360, -1348, + -104, 1493, -2858, -2860, 2045, 18330, 4814, -3628, + -705, -3228, -660, -2664, 2616, 4548, 3753, 1574, + -1319, -1110, 556, 3304, -2803, 13052, 4592, 2922, + 13667, -2322, -3056, -2717, 174, -4222, -4296, -7695, + 1366, 1786, 1041, -110, -1997, 4102, -1855, -900, + 203, 1311, 3412, 4107, 22609, -4112, 427, -2488, + 257, -1267, -1277, -6430, -7193, 10667, 4495, -4317, + 6846, 13213, 7335, -972, -3137, 335, -609, 3131, + 2406, -3762, 2151, -5188, -7675, 2068, -2027, 3722, + -773, -3276, 1539, -7886, 1005, 13693, 4601, -8386, + -508, 5662, -4889, 93, -10603, 4051, -2, 1094, + -4897, -2274, -2377, 2228, -5507, -464, -3455, -227, + 9433, 8093, -2245, 3701, -1047, -6827, 2037, 1926, + -3610, -15420, -581, -6127, -2075, 2501, -2216, 5385, + -2297, -2660, 1563, 3244, 1418, -2012, 2964, 12235, + -8595, 2728, -3541, -6511, 11038, 11326, -183, -1102, + 1038, 1224, 20, 1441, -349, 1240, -7737, -930, + 1411, 6945, 4130, -13544, -2625, 3550, 3149, -730, + 7658, 3098, 673, -2259, 2556, 1543, 1478, -951, + -8128, 4951, 11919, 4588, -8448, 784, -11498, -1908, + 2578, 2936, -7496, -5834, 1987, 3407, -4133, -4924, + -1348, -1300, 916, 899, 20257, 2027, 1450, 4388, + -3748, 3846, 2187, -1158, 4720, -3613, 5312, 4055, + 448, -6383, -8794, -2232, 1920, 834, 27087, -754, + 90, 1410, -985, -1381, -61, 650, 1080, 7035, + -2772, -1233, 13410, 4494, -472, -2896, -5083, -2217, + -5778, 437, -6853, 4996, 3442, 6092, -6497, -3871, + 4024, -898, -73, -3067, -2793, 5640, 6076, -2454, + 3598, -277, 1672, -6858, 2419, 9753, 6292, 8835, + -9909, -4724, -618, 7266, -416, 1965, -4968, 2421, + 1155, 3815, -116, -3725, 7872, -4901, 2383, 1612, + -2186, -2302, 2791, -2226, 1144, -13379, -6602, -806, + 7099, -2098, 4194, -2128, 8663, -4275, 452, -135, + -6053, 1280, 12815, 3278, 8452, 4479, -1648, 1453, + 1407, -966, -1016, 3173, -7333, -4552, -13176, -1744, + 577, -1572, 611, 1202, -146, -5773, 3012, -3016, + -1581, 3162, 3818, -1970, 6195, 1946, -9656, 2861, + -7875, 3133, -7840, 10951, -1684, -306, -227, 9776, + -82, 1736, 1180, 3457, -2874, 5365, -7428, 7604, + 2623, -2998, -2270, 10410, 1252, -2725, -4433, 1758, + -5225, 6522, 6698, 712, 4694, -2392, 240, 423, + -3030, -12708, -3136, -5176, 480, -1624, -12900, 7537, + 4371, 1186, -1828, -757, -1850, -974, -3755, 1415, + -6302, 2642, -3823, -1570, -8090, 8251, 1945, -9213, + 1147, 4128, -4301, 806, -1745, 704, -2496, 1375, + -802, 9, -808, -252, -5453, 3857, 10353, -536, + 1875, -2896, -10792, 3358, 1063, -890, 7200, 3660, + 406, 2840, -6973, -4469, 4638, -8091, 2772, -8035, + 1728, -5315, 7234, -2718, 3707, -1226, -11858, -2397, + 772, 3285, -4089, -1400, 1113, -16680, 1885, -435, + -959, 242, -817, 259, -2010, -1857, -557, -914 +}, + +.cb2232m0 = { +-13394, 14382, -488, -1088, -817, 100, 305, 2267, + 2527, -1584, 995, -5781, -3585, -1826, 803, -4108, + -3137, 12111, -211, 838, 4879, -1964, -1728, 13830, + 2084, -11535, 664, -2499, -3421, -703, 4528, 968, + 1008, -12010, 984, 2658, 422, 1412, 10772, 2216, + -4291, 1329, -2324, 2392, -2029, 12322, 1053, 169, + 12635, -902, -62, -670, -3007, -3322, -2948, 1817, +-10688, -1264, 1949, 2734, 1072, -1429, 2085, 10312, + -1685, -4433, -1287, -9620, -1132, 20, 614, 2470, + 2821, 5934, 3526, 11292, 50, -12970, -11948, 1114, + 1980, -945, -713, -5357, 3766, -447, 969, 2247, + 11854, 2148, -12393, 1518, 610, 4527, 1164, 1347, + -1422, 649, 653, 855, -24, 30152, 20, -564, + -2825, -11, -1408, -80, 239, 305, -3163, -854, + 568, -18, -4212, -403, 288, -3009, 229, -1152, + 16390, -877, -458, 316, -128, -12165, 1088, -828, +-10886, -269, 747, -1026, 1716, -10920, -9204, -3123, + 958, -6128, -260, -851, -1524, -2386, -6472, 228, + 2667, 3158, -140, 1719, 2330, -2730, 3080, 44, + 15743, -2167, -11637, -607, 476, 408, -12505, -1862, + -1892, -440, -3785, -2348, 1229, -338, -438, -797, + 29933, -715, 366, -197, 576, -188, 484, 240, + -4844, 1168, -1054, 863, 875, -295, -16091, -1972, + 3976, 3833, 3056, -770, 1011, -3098, 165, 3973, + -9367, -18, -299, -11254, 1005, 8644, -14788, -2268, + 2644, -8410, 578, 2169, -766, 2764, 2378, 3282, + -2710, 7612, -542, -12062, -2437, -414, -506, -10332, + 2732, 839, -2593, 923, 1159, -1057, -7333, -86, + 2832, 11328, -1616, -302, 4399, -547, 6107, 9983, + -6901, -85, -544, -4916, 366, 4878, -8662, 7313, + -3056, -1027, 2381, 8906, -7270, 509, -1124, -2512, + -1636, 5830, -5868, 2369, -3236, 12557, -2713, 12793, + -2957, 1688, -852, 4723, -122, -2336, -4698, -1306, + -7399, -2090, -1953, -1505, 3335, -10906, -2598, 1322, + 2556, 7210, -1553, 1262, 1878, -10719, 1746, -2736, + 1448, 8734, -9602, 828, 1752, -1632, 8037, 2728, + 562, -1879, -10572, -544, -2254, -1997, -6384, -87, + -5878, -473, 498, -2960, -5698, -11500, 1815, 2050, + 7388, 5230, 2782, 5602, 514, -306, 13022, 523, +-10776, -846, 716, 270, 3350, -6021, 1420, -6175, + -1978, 3967, 11612, 3320, -4100, -2468, 4595, -5338, + 65, 3478, 19, 3501, -15896, -1335, -1861, -1944, + 3935, 3630, 4627, -5892, -458, 383, -211, -594, + -165, 24865, -656, 2300, -404, 257, 214, -643, + 2298, -180, 35, 4974, 834, -998, -1738, 5449, + -9222, -10858, 4188, 9147, -5639, -1691, 990, -1945, + 3421, -3527, 9005, -2038, -2369, 5098, 967, 15840, + 196, -3204, -1079, -776, 11806, -1352, -2053, 2011, + 309, 642, 1541, -1466, -4465, 6679, 5756, 7474, + -58, -1864, 5908, -1576, -30374, -904, -571, -1136, + 425, -22, 666, 1150, -734, 82, 1254, -226, + -437, -890, 1464, -3368, 987, -11885, 1127, -7224, + 1872, -8198, 8775, -2695, 1457, 15102, -899, -1384, + -1975, 1891, 3128, 1465, -1649, -1363, 1483, 303, + -534, -7, -1710, -1377, 769, 12698, -8987, -802, + 4636, 572, 2004, -3513, 442, -9863, 3215, -4550, + 2138, -4346, 5682, 11053, 7220, 9842, 797, -1399, + -2679, -5857, -2143, 3241, 2330, 248, -630, 1044, + 639, -3432, 125, 22083, 1976, -1003, 813, 552, + -571, 4358, -6200, 3635, 5439, -636, 233, -4856, + -3519, -460, 6956, -4215, 1537, 7895, 13910, -7637, + 1392, 1572, 648, 3690, -1988, -2463, -3302, 677, + -924, -535, -6025, 4126, 7178, -4145, 4960, -1860, +-10926, -1470, -9506, -226, -258, 32, -479, 2222, + 94, 11358, 3984, -2732, 2111, -590, -2444, -344, + -425, 598, -1382, -1213, -17632, 1566, 1387, -3521, + -57, -1829, 4788, 574, -206, 7962, 9157, 6459, + -1594, -1355, 4874, 1066, 2006, 1793, -7569, 2369, + 1108, 1305, -3046, -14052, -1736, -4045, -4328, 7497, + 3304, 1518, -5666, -529, 4256, 4667, 932, -1495, +-10414, -414, -2110, -3150, -1250, -8799, -419, 5162, + 8497, -8720, -746, -3015, 6403, 3855, 7350, 165, + -59, -958, 5780, 6044, 1736, 3016, 31, 1012, + 3422, 7598, -6837, -2092, 2262, 6171, -10362, -2108, + -1352, 1798, -4872, -6369, 2507, 2640, 6074, 1835, + 2948, 388, 398, -9295, -5384, -2088, 2096, 742, + 3286, 441, 7135, -2112, -9958, -5612, 2479, 5427, +-10114, -674, 308, -1037, 770, 514, 1868, -252, +-11901, -984, 670, 2506, 5396, -1047, 9113, -10865, + 4872, 1720, 2226, 947, -2336, 2649, 173, -1464, + -2874, 4463, -1270, 3429, 6242, -5380, -7772, -4550, + -8451, 2045, -2855, 5336, -15066, -418, -4886, -648, + 3736, 945, -956, -4825, -116, 130, 1889, 9642, + 3790, -4371, 7180, -1556, 6562, -2207, -7910, 506, +-21594, 662, -338, -943, -1022, 6453, 301, -464, + -457, 840, 3313, 10946, -294, 8156, 138, -1425, + 2397, -792, 6468, 4615, -511, 15938, 494, 274, + -5976, -660, 3894, -2140, 1424, 2003, 4101, 2823 +}, + +.cb2232m1 = { + 20456, -1952, -1581, 869, 628, 76, 1404, 4060, + 508, -3177, -946, -2992, 2422, 1139, -1931, -240, + 1011, 365, -1106, 20973, -1438, 372, 137, -1058, + 1171, -1252, 2794, 1434, 1814, 482, 3948, -2704, + 20422, -241, 441, -1121, 499, 1036, -918, 9708, + -3166, -488, -10379, -3201, -5254, -1871, 5665, -12622, + -7591, 127, 1469, -2267, 1813, -4197, 2065, -602, + -395, -652, 333, -19114, -1092, 4310, 1590, 1688, + -1453, 177, 4402, 1168, 5972, -1295, -3258, 1542, + -4832, 3377, -5545, -3622, -4944, 2064, -2846, 8118, + -845, -6778, -3640, 5729, -907, -11007, -5, 2634, +-11118, 2108, 144, 13299, 251, 336, 563, -75, + 3004, 169, -3892, 1477, 1066, -1571, -1113, -1088, + 517, 465, -21841, -1541, -1094, 1841, -9213, -17478, + 1662, 8, 1192, 1174, 1014, -5659, -695, 316, + -5161, 1803, -1056, -2369, -2919, 2941, -9712, 1975, + 426, 11214, 2288, 6186, -7348, -3062, 3341, 3252, + -4102, -346, -876, -7088, -3330, 4507, 310, -1632, + 299, -2636, -2740, -752, 10159, -7201, -9568, 3134, + -4002, -41, 2479, -1816, -14099, 3575, 1161, 6427, + -2466, 390, -1883, -6265, -1266, -263, 1474, -592, +-21234, 94, 4187, 1, 3227, -3273, 1950, 406, + 543, 1661, -2648, -9252, -2048, -5987, -722, 4932, + -4410, 12504, -1572, 2244, 5610, 307, -9710, -3642, + -6436, 4368, 2956, -2269, -6196, 4069, -766, -3695, + 3416, -5786, -9668, 11677, 1208, -965, 1516, 1132, + 1018, -6168, 1970, -10357, 1379, -725, -8789, 3730, + -65, -4758, -1818, -1050, 9641, 4519, 2886, 2667, + 6348, 2436, -438, 1978, -9374, -1286, 3893, -2073, +-11199, -2081, 3345, -3444, -9480, 2410, 1986, -1869, + 3252, 5949, -2119, -401, -214, 3416, -1067, 18510, + -2986, 3510, 508, -357, -837, -1205, 2884, 11587, + 11565, -555, -2664, -873, 3642, -2068, 1734, -4408, + 330, -181, -1358, 1407, -9739, 809, -10203, -2066, + 3440, -2063, 3238, 3734, 1671, 750, 6890, 4068, + 1238, 493, -1330, 76, 8918, 10855, 85, 12236, + 3570, -1074, 3008, -9424, -3186, 1271, -380, -157, + -4974, 10575, -1378, -219, 1354, -1589, 10936, 2268, + -3787, -1040, 7567, 924, 10490, -806, -1318, -1576, + -209, 93, -3745, -3820, 439, -9828, -6265, -864, + 31342, 35, 1332, 443, -590, 846, 104, 868, + -863, 1526, -1088, 11494, -7055, 3564, 109, -3072, + -2234, -4530, 1866, -3425, 9940, 3158, -1821, -680, + -1124, 2884, 1191, -61, -9698, 7596, -558, -9019, + -1181, 208, -1342, -68, -312, 294, -1468, 1410, + 39, -21081, 724, -2137, 935, -8, -10297, 3509, + -6510, -6558, -6906, -1905, 1915, 5920, -8983, 3416, + 7300, -1372, -1422, 1822, -10433, -2530, 1669, 554, + -3008, -3351, -922, 8279, -5184, 5520, 4785, 683, + -506, -4558, 1938, 8442, -12639, -54, -2907, -820, + 10004, 1780, 485, 1401, -3786, 786, -5937, 2632, + -1540, 972, -3342, 2294, 8076, -1006, 11731, -1825, + 3036, 1085, 1160, -9680, 11111, 7838, -2504, -2112, + 2376, 2534, 3624, 555, 3610, -520, -831, -15, + -498, 167, 711, -22685, -999, -1466, -1643, -394, + 5404, -4247, -2307, 4052, -1156, -1240, -490, -1598, + -4365, -8382, 10493, 464, -16592, 3723, -7709, -821, + -4218, -922, 398, 5635, 2184, 5090, -7144, 2420, + 792, -324, -1278, 3172, 13101, 1608, -3996, -2219, + 2995, -6924, 816, -2482, -406, 3458, 503, -8154, + 3460, 2542, -3703, 8524, -61, -430, 23212, 1203, + 2335, 5556, -476, 923, -565, 593, -1611, 1814, + -1614, -7067, -1957, 10166, -4306, -421, -4026, 1854, + -9881, 667, 7720, -2906, 7003, -1823, 6344, -8614, + -2965, -2720, -62, -802, 1945, 4574, -4604, -8341, + 518, -3543, 95, -4262, -5220, -133, 10270, 1999, + 3234, 8900, -4866, -3708, -4465, 4542, 2545, 1770, + 6995, 3559, 1133, -1152, 14680, 1002, 634, -12913, + 1686, -1645, -1796, -50, 112, -1108, 1070, 686, + 1068, 1555, 896, 3498, 10458, -32, 12017, -737, + 650, -432, 404, 170, 10873, 1864, -1718, 11061, + -1556, -3766, 225, 6999, 1730, -6919, -1895, -2919, + 8250, 10050, -4631, -1488, -4801, -1504, -2736, -110, + -3630, -2752, -11162, 1128, -2580, 11692, -678, 1338, + 2175, -6030, 616, 1651, -7034, -3057, 2420, 1998, + 4383, -1721, -10762, -428, 2902, -906, -4298, 2141, + -1242, 5464, -607, 5389, -8946, -3890, 10884, 1544, + 628, -1969, 13902, -1570, -1080, -689, -4676, -3642, + 753, -11351, -110, -744, 4286, 1163, 3105, 9752, + 11143, 4296, -1698, 1012, 2284, -989, -958, -9481, + 738, 24, 426, 1638, 3898, 8885, 2938, -8826, + 2982, -1679, 8466, -651, 5144, 2736, 751, -84, + 7710, 3077, 2885, 146, -1102, -2569, -2039, 11059, + -9950, -1048, -1031, -33, -5118, -1096, -1986, 2306, + 2400, 9320, 6188, 500, 2090, 61, -11357, 118, + 1505, 1032, -1920, -164, -9744, -4670, -11029, -102, + -960, -1023, -2570, 4102, -3989, -11478, 772, -1515, + -1102, -2194, 1722, -1195, -8144, 746, -9534, 3250 +}, + +.cb4440l0 = { +-14497, -1982, 631, -984, -2115, -3252, 2755, 2017, + -2110, -8864, -792, -1291, -2761, -2365, 698, 1047, + 972, -14703, 10590, -3945, 663, 972, 1204, -2801, + 1295, -1296, 50, 1448, 888, -1879, 122, 78, + -183, -588, 16202, -388, -2240, 1136, 1266, -6445, + 2619, -1664, -6329, -2700, 1557, -497, 598, -110, + 1298, -334, 191, 29897, 387, 419, 76, 152, + 533, 78, 112, 101, 158, 136, -236, 88, + 43, 107, 84, 21, -6385, -1711, 1757, 1411, + 9152, -72, 1428, -1098, 10328, -506, -360, 285, + -36, -2816, 819, 88, 176, -481, -172, 2067, + 3268, 5479, 8605, 11272, -1880, 361, 1582, -4973, + -1379, 3835, 74, -3, 493, -431, 1390, 101, + -550, 59, 476, -469, -583, 568, 732, -1015, + -1104, -698, 23922, 1130, -1268, 280, 204, -59, + -9789, -317, 935, 2944, -10402, -2564, -4648, 1506, + 3834, -1002, 2805, -158, -409, 814, -150, -97, + -3573, -1550, 1356, 5350, -365, -2622, -3454, 310, + 1194, 911, -10928, 937, 7980, -5286, -554, 1999, + -1263, -562, 10, -321, 744, 44, 64, -274, +-30136, 340, -1051, 756, -30, -6, -269, -273, + 12, 95, 1565, -13194, -11810, -485, -1574, 414, + -240, -452, 564, 740, -476, 959, 1079, -1568, + -422, 37, -154, 10117, -68, 1412, 11862, -3420, + 4169, 5178, 527, -1027, -1030, -1985, 448, -716, + 1696, 1942, -254, 308, 1100, -790, 8102, 6630, + 3653, -1018, -587, -6990, -19, 1671, 1425, 8089, + 3708, -1182, 774, 659, 113, 437, 50, 835, + -532, -11209, 1682, -7490, -2592, 1234, -4689, -7301, + -143, 3361, 1121, 177, -473, 513, 136, 965, + -4020, 4639, -1212, 1271, 2905, -6865, 10499, -3800, + -3354, -5029, -3606, -950, 4490, 526, 1006, 2, + 1760, 5819, -55, -1098, -1843, 348, -2062, -9196, + 3712, -11466, -3218, -858, 2720, 589, 320, 861, + 59, 5357, 564, -380, 538, -142, 490, 212, + 1716, 670, 1904, -181, 2979, 943, 16916, 1271, + 988, -802, -1490, 9154, 643, 1725, 1347, -2827, + -4096, 485, -7091, -3180, -4747, -1604, 1576, -5724, + 6104, -139, 1726, 11715, 360, 7519, 2513, 5192, + -2208, -1993, 829, -387, -5724, 4418, 116, -2955, + -226, 249, 377, 2149, -2929, 5021, -3064, 800, + -1459, 11384, 8556, 1740, 368, -2839, -2049, 1438, + -1357, 4084, 1896, -528, 1621, -1760, 13741, 302, + -1018, -9774, -3521, 1302, 1374, 1139, 918, -1724, + -764, 858, 804, -1772, 372, -322, -526, 11924, +-11944, 4012, 1749, 1737, -1545, 68, 889, 280, + 690, -2200, 1068, -484, -171, 455, -44, -3178, + 2243, -590, 749, -792, -19876, 198, 236, 2695, + -3413, 652, 284, -820, -1134, -199, -112, -5650, + -418, 1047, 1090, 2260, -3297, -2164, 13524, 1720, + -326, 910, -1706, 3912, -1175, 1687, -2152, 50, + 35, 1718, 721, 9316, -2256, -4330, 6961, 4432, + -8043, 45, 1370, 3472, 2892, -3224, 1368, 1355, + -562, -694, 746, 198, 1188, 2819, 3131, -2371, + 6438, 847, 2111, -10187, -3451, -9826, -3502, 655, + 649, 1460, 270, 118, 45, 192, 188, -1139, + -258, 663, -84, -27519, -765, -905, 357, -4, + 89, -372, -24, 178, 1127, 209, 1177, -2762, + -587, 1488, 8989, 3217, -2550, 215, 9540, -7196, + 1259, -3716, 2767, -261, -216, 872, -3008, -2076, + 8682, 709, 3629, 87, -3114, -10624, 246, -1670, + -1738, 1229, 7624, -1120, 784, 305, 233, -185, + 280, -1466, -268, 198, 499, 308, -2187, -1149, + -388, -38, -338, -1084, -19424, 40, 1958, -2240, + -86, 264, -9876, -1287, 4086, 3742, 2502, -10078, + 4574, -1493, 1078, 3218, 2410, -364, 1049, 2638, + 35, -1295, 200, -2847, 10818, -12064, 2375, 348, + -353, 2788, -821, -3196, -511, 146, 2015, 235, + -1094, 2622, 2688, -79, 5176, -884, -11814, 794, + 2696, -6704, 3452, 1295, 3872, 2924, 4498, -166, + -598, -1213, 891, 5478, -266, -777, -5, -776, + 1003, -1837, -156, 17910, 453, -297, -1545, 857, + -288, -308, -6373, 2045, -1846, 3007, -2236, -1904, + 815, -2889, 4200, 8320, 9872, -614, -834, 3856, + 414, -234, 1559, -7451, 3641, -1230, 837, -127, + 2652, 411, -532, -12548, -1692, 1034, -2418, -968, + 558, -1564, -1952, 307, -1064, -6776, 1588, -2636, + 949, 8272, -12, -3468, 3481, 6588, 2580, 7393, + 272, 1528, 1818, -2206, -349, -396, -11704, 1487, + 9753, -4665, -24, 2084, -780, 5036, -647, 3668, + 561, 1099, -1094, 534, 1270, -99, 1006, -476, + -528, 12481, 1589, 1593, -1682, 7022, 2664, 8702, + -563, 1082, -206, 87, -1978, -144, 228, 1232, + 889, 14340, 65, -1061, 10510, -95, 649, 53, + -962, -383, 2479, 1322, -1798, 2840, -492, -419, + 90, -680, 79, 1026, -20912, 1593, -742, 1086, + 516, 699, 2393, -64, -2010, 46, -859, 111, + -440, 14281, 272, 797, -10141, -3734, 3126, -3050, + 1300, 73, -1754, -1278, 1890, -2710, 704, 1160, + 1, 269, -24, -622, 124, 138, -522, -510, + 95, -402, -27306, -470, -214, -159, 396, -201, + -372, 122, 136, -1005, 744, 1949, -810, -2648, + -726, -384, 955, 1232, 1354, -345, -19485, 1056, + -193, 1257, -263, 398, -752, 602, 98, 793, + 17, 20186, -189, -2615, -174, 166, 436, 411, + -1046, 374, -471, -253, 233, 8352, 1342, -1279, + 9305, 2190, -3239, -5262, -3454, 1844, 684, 303, + -4434, -6041, -3495, -2482, 389, 353, 159, -14, +-29179, -511, -158, 92, -401, -36, -297, 447, + -605, 269, 85, 212, 8, -118, -130, 207, + 13150, -8712, 2504, 1355, -3268, 1396, -4748, -2200, + -1560, 228, -162, 1179, 3024, 742, -860, 69, + 10, 30006, -538, -489, -125, -214, 364, -682, + -283, 532, -134, 227, -448, -20, -266, 70, + 2, 9310, 14858, 856, -493, -3357, 36, -248, + 214, 281, -73, 3268, 745, -245, -1007, 146, + 392, 36, 8042, 2953, -6603, -7697, 4425, -2498, + 571, -2194, 3388, -794, -561, -2763, 1912, -3030, + 225, 214, -27, 834, -10661, 437, -506, -535, + 8397, 1332, -2406, -8868, -2972, 1385, 296, 865, + 2318, 890, 244, -121, 226, 375, 896, -10381, + -2266, -3404, 983, 1255, 259, 11427, 455, -3041, + 307, -2446, 476, 723, 18, -10224, 510, 552, + -654, -876, -465, 628, -12572, 786, -393, -4162, + 938, -1327, -1695, -608, -1352, -131, -880, 830, + 1016, 21875, -408, -1560, -500, -1682, 453, -930, + 1316, -136, 434, -683, 412, 202, 233, 382, + -2002, -9267, -1034, 8710, 434, -8121, 3035, -3121, + 1792, 2712, -1537, -1082, 854, 1337, -1084, 91, + -4485, 2545, -4412, -1930, -12234, -4802, 4641, 437, + -928, 2163, -3154, 521, -665, -1200, 2654, 931, + -388, -118, -1144, 133, 5089, -1194, -1528, -967, + -795, 188, 1918, 897, -7046, -7617, 7118, 5755, + -2724, -7894, -472, -360, -591, 990, -3032, 7742, + 726, 5490, 9383, 479, -3032, -1904, 7158, 4706, + 2442, -1576, -58, -156, -3977, -2696, 4195, -166, + 3342, -1566, 3767, -4159, -5750, 5505, -7663, 4516, + -4073, -2612, 5136, -290, -666, 1282, 776, -566, + -602, -310, 1003, -648, 2928, -3159, 427, -1168, + -2702, -16990, -205, -343, -1196, -1980, 1653, -512, + -1820, -418, -3368, 3522, -1966, 4964, -5728, -5185, + -210, -1721, 10131, -7060, 3351, 334, -96, -3193, + -1713, -614, -2633, 147, -1552, -2363, -3724, -1731, + -7350, 5453, -2732, -2867, 12458, 416, 0, 4414, + 833, 590, 1617, 405, 73, 868, 232, 195, + 15, -196, -782, 749, -955, -84, 1176, -553 +}, + +.cb4440l1 = { +-12227, -3413, 12848, -1336, 20, 894, 254, -1001, + -1381, -406, -1157, -458, 300, -395, 825, -34, + 74, 382, -1018, -10266, 1338, 11091, 544, 797, + -4304, 1389, -747, 1924, -257, 2615, -37, -4375, + 782, 158, -378, 19, 652, -539, 1012, -4211, + 1263, -925, 96, -9226, 5921, -8209, -71, -1838, + -2201, -7441, -60, 393, -5626, -264, -1002, 85, + 1989, -1616, -216, -914, 9907, 8044, -578, -7830, + -1705, -3624, 2430, 59, 5813, 870, -317, -2545, + -4020, -1330, 1215, 9352, 5425, 324, -4803, -681, + -506, -4710, -6574, -4184, 65, 729, -1310, -1387, + 1385, 2364, 1672, 2493, -438, -1367, -907, 38, +-20220, -1644, 512, -413, 348, -112, -532, 785, + 1332, 7140, -1916, -1766, -11570, 1811, -9167, -76, + -1531, -175, -1739, -771, 2014, 519, 15, 576, + 8736, -979, -28, 1830, 329, -302, 12206, -1501, + 5195, -305, 1456, -581, 1488, 142, 235, -157, + 192, 1540, -922, 11056, 11823, -2964, -1488, 1712, + -2018, -880, -3282, -190, -198, 2436, -248, 222, + 22, 863, 1504, 2078, -2047, 216, -1270, -732, +-18252, 1186, 3178, -730, 432, 934, 1617, 873, + -491, -70, -768, 679, 1398, 537, -364, 172, + -541, -94, -24, -129, -26725, 201, -554, -357, + -71, 60, 96, -1665, 1425, 1244, 332, -1068, + 326, 834, -620, -1473, 1585, 1432, 928, 18782, + -1388, 2897, 448, 40, 1323, 1433, 787, 215, + 3297, 2586, -856, 451, -17700, 735, -43, 405, + -1252, 744, 1012, 677, 312, 206, -279, -432, + 6677, -87, -72, -10400, -106, 11224, 1152, -422, + 2024, 704, 2462, -1197, 232, -119, 4, -879, + 1600, -708, 3496, 279, -143, -1096, -555, 4594, + 1486, 161, 942, 2018, 2474, -16010, -380, -193, +-11415, 457, -276, -11220, -1604, -38, 813, -4044, + 1888, -4265, 1647, -882, 981, -734, -110, 140, + -3050, 1248, -549, -1167, -967, 3586, 688, -1380, + 424, -17959, 2022, 2274, -44, -1406, -432, 1335, + -659, 9555, -3581, 11045, 1870, 806, 599, -2065, + 156, -4420, 16, 2349, -609, -3058, -738, -60, + -548, -119, -49, 26, 1528, -1842, 6306, 14078, + -692, 5480, 321, 1996, 1376, -3086, 490, -54, + 1151, 932, 445, -9887, 15808, 3085, 866, -2020, + -1785, 2126, -920, 414, -290, 138, 244, 994, + -702, 1410, 330, 202, 675, -389, -241, 31306, + 380, 300, -53, 804, -109, 413, -44, 6, + 14, 486, -293, -112, 26, 11632, -836, -3948, + -518, -1364, 11360, 3558, -588, -2084, 490, 381, + -955, 2207, -2953, 1115, -265, 2, 65, 464, + -180, -111, -174, -152, -30508, 121, -207, -835, + 1126, -185, 91, -96, 222, -99, -93, -10138, + -430, -184, -372, -194, 953, -100, 382, -1422, + 13931, -1835, -1657, 821, 408, 808, -601, -463, + 7142, 5596, 3171, 2174, 2740, -11350, 1019, 1449, + -386, 1642, 3703, 4271, 1664, 2232, -674, 983, + 551, 8543, 154, -383, -2419, 1117, -520, -10966, + -4406, -3742, -79, -909, 1813, 5043, 412, 1099, + 1434, 173, 788, -92, -1004, 1288, -87, 931, + 10241, -855, 6, -405, 2580, 11455, 1150, -1916, + 3614, -262, 292, 897, 9673, -381, 1711, -2713, + -1111, 282, -2180, -2282, -2266, -724, -849, -11787, + 888, 3120, -1459, 495, -10812, -792, -274, -984, +-12223, -737, -2394, -299, -578, -2758, 1521, 774, + 1938, 857, -1935, 217, 654, 1452, -3695, 6734, + 804, 134, 946, -2156, 9495, -600, -1962, -5252, + -246, 1269, 8492, 1261, -2205, -106, -1314, 828, + 1013, -12059, 663, 436, -2648, 9863, -630, -2961, + 3004, 1015, -3153, -1475, -25, 399, -846, 430, + -1237, -156, -187, 1115, -502, -363, 386, -2820, + 942, -926, 727, 1130, -20388, -274, 1140, 198, + 199, 2548, 442, 157, -1546, 3693, 892, 460, + 6552, 4858, -2560, -8673, 1930, -8913, 3427, 686, + 61, -8830, -358, 1338, -74, 1180, 2871, -3822, + 104, 2414, -1742, 11425, -4522, 393, -3016, 972, + 34, 117, -16113, -6900, -6964, 1726, -843, -242, + -2141, 803, -1093, 442, 1776, 2429, -1000, 489, + 393, 635, 389, 1126, 12285, -1648, -11396, -2885, + -56, 3840, -174, 3177, -1708, 1189, 1914, 1514, + -189, -88, 276, -240, -120, -2929, 9823, 678, + 568, 26, 10080, -2575, -806, -64, 6406, -82, + -1171, 2169, -1804, -667, -37, 54, 4208, 10829, + 11920, -468, 1916, -809, -370, 144, 3616, -263, + -4352, -124, 300, -246, -440, -115, 447, -407, + 20869, -340, 54, -764, -807, -699, -283, 727, + -922, 1098, 577, -6, -809, -50, -115, -75, + 280, 156, 182, 225, -30432, -212, -417, -245, + 177, 94, 4, -627, 167, 47, 152, 148, + 1325, -2436, -10063, -696, -9966, 1032, -1024, -3702, + 3933, 400, 333, 692, -3858, 2599, -1215, -389, + 393, -666, 2135, 10280, -2443, 1972, 410, -392, + 590, 12322, -523, 1141, 52, -1468, 819, -213, + 162, 116, -614, -10630, -204, -1247, 535, 199, + -6058, 2538, 1644, -11539, -1562, 1462, -1493, -218, + -296, -605, 321, 607, -366, -257, -837, 4536, +-11683, 1266, -3805, 4496, 2854, 8, -8848, 124, + 656, -1041, 411, 144, 916, 445, -91, -260, + -149, -882, -433, -121, 345, 68, 349, 821, + 652, 251, -23053, 1015, 712, -73, 7038, -1520, + 5810, -12604, 2841, 425, 265, 1546, 938, 1851, + -1180, 2751, -498, 1289, -774, 327, 4047, -8132, + -2622, 5449, 3221, -2990, 10107, 1880, 173, -4006, + 399, -332, 642, 297, -4513, -1230, -330, -788, +-21881, 903, -1308, 547, -522, 1885, -1730, -63, + 973, 897, 670, -657, -232, 498, 92, -8, +-11010, 1072, -368, -1864, 11505, 3497, 730, 2158, + -1629, -1351, -1583, 2247, -1506, 2144, -902, 639, + 175, -6006, -986, -4246, -1510, 1785, -9792, -495, + 1995, -9189, -1414, -2550, 1578, 2390, -2989, 1673, + -1980, 21, -4054, 8552, 1155, -301, 1204, 3776, + 262, -1828, -1837, -1014, -9, 2711, 1467, 463, +-11605, 1743, -956, -1213, -3892, 1534, -10298, 22, + -902, -658, -1759, 2507, 1552, -12298, -1050, 623, + -3221, 1522, -36, -446, -5925, 2144, -2844, 15080, + -1984, 3631, 1931, 1894, 1193, -1694, -3172, -813, + -1336, 534, -365, 833, -293, 21759, -1266, -1216, + 996, -2, -393, -858, 759, 969, -230, -151, + 977, -874, 119, -896, 262, -118, 89, 95, + 94, -437, -30375, -462, 360, -588, -334, 86, + -1027, -208, 536, -196, 367, -467, 119, -32, + -2544, 6204, 8830, -264, -7847, 848, 2267, 3877, + -6378, -2249, 1420, -1868, -3443, 3747, -590, 58, + -274, -6065, -8472, 5906, 3109, 5834, 3905, 2086, + 1300, 3828, -518, -528, -3672, 1794, 4353, 408, + 566, -2577, -1137, 2749, -2662, -528, -7479, 5550, + 2932, -336, 3681, -2034, 212, -8733, 1017, 2258, + 8225, 387, 227, 877, 2752, -1375, 2636, 8131, + 3850, -6870, -1158, -3736, -8478, 228, -5809, 97, + -2555, -2956, -928, 678, 112, 1434, -1250, 1240, + -412, -4267, -3811, 4322, -3430, 7705, 5456, -6876, + -3452, 7329, 3142, 220, 662, 1531, -5492, -1388, + 6842, -3631, 362, 5029, 8052, -2367, -5346, 5724, + -358, 2469, 2196, -1426, -272, 534, -192, -531, + -705, -70, -259, 93, 335, -94, -145, -17, + 920, 1186, -818, -599, 343, -19859, 2968, 161, + 128, -4282, 598, 152, 1210, -1317, -1545, -229, + 181, -6488, 5699, 7270, 6271, 8809, 27, -4770, + -804, -168, -247, -680, -129, -470, -152, 915, + 176, -904, 622, 280, 2986, 1034, -1046, -482 +}, + +.cb4440s0 = { +-12085, 8192, -1802, 4587, 5947, -3183, -2629, 1837, + 2434, 252, -612, -4697, -576, 150, -704, -640, + 174, -126, -10309, 350, -3187, 4714, -2829, 12618, + -2172, 3502, 465, -159, -601, 1306, 1174, -448, + -292, -136, 242, 31, -9005, -6203, -10027, 25, + -209, -20, -1292, -1252, 4304, 3681, 4462, -4401, + 4412, 1240, -576, 3618, 595, -237, 2544, -6032, + -1511, 1523, -3668, -3472, 5552, -4901, -272, 5963, + 2740, -878, 13010, 191, -2017, 768, 455, -45, + -6873, -3664, 2639, -961, 3068, -4242, 1327, 2362, + -1909, -1114, 100, -5940, 220, 865, -12952, -76, + -1279, -591, 1092, -3502, 88, -2118, 13053, -10141, + -3024, -533, -1923, -4097, 135, 1672, -1661, 1646, + -370, -361, 644, -197, -6796, -10948, 11692, -974, + 488, 349, 3936, -1506, -149, 513, 1401, -1776, + -391, -210, 57, -56, -344, 1018, 7989, -4957, + 167, 987, -60, 62, 1622, 1207, -69, 338, +-16133, -46, 1018, -1460, -821, -646, 1316, 126, + -4631, -842, -1505, 15833, -6404, -4514, 2946, 2923, + 1198, -3141, -3109, -1613, 1853, -906, -436, -1110, + -282, -214, -3424, -3141, -3988, 284, 22262, 1269, + 1787, -1116, -1429, 1017, 371, -187, -825, 534, + 350, 1088, 26, 176, 8914, 6662, 935, 2074, + -7986, -4780, 2194, 1796, 697, -4040, 2486, 1700, + 9150, -37, -1560, 2449, -162, 128, -7469, -2690, + -281, -4698, 424, 535, 1416, 243, -575, -1160, + 326, -2417, 808, -15816, 994, -302, 26, 894, + -7376, 395, -586, 823, -1341, 972, 100, 241, + 743, 470, 267, -550, 474, 182, 18252, 178, + -182, -7, 3496, 2132, 863, -151, 741, -2158, + -763, -652, -503, -434, -736, 770, -156, -19071, + 443, -354, -243, 66, 4258, 6714, 3577, 17338, + 556, -3570, 1269, -1406, 1668, -349, -90, 781, + 82, 558, 936, -788, -1072, -21, -6472, -3022, + -475, -6997, -2816, -3774, 1683, -13950, 3482, -1872, + 2624, 1064, -318, 1300, -1214, 179, -11, -124, + 4560, -2827, -6314, -5736, 1159, 1309, -5462, -11652, + 4192, 151, -543, -3484, -2288, -119, 745, 1373, + -121, -629, 5204, 7650, -2062, -3370, -2894, -338, + -1361, 1080, -3674, 12852, -6119, -1578, -736, -241, + -1564, -109, -441, 335, 416, 1678, 4802, -3239, + 6182, 154, -3656, -1337, -17027, 1707, -381, -1704, + -377, 1022, -592, 983, -321, 37, -1846, -4500, + 2575, 14162, -560, 9385, 4179, -1340, -3466, 3235, + 1727, 1545, -23, 636, 280, -39, 871, 173, + -8915, -2427, 2146, -3698, -12153, -3773, -3873, 5042, + 112, 788, -1139, 245, 546, 278, -8, -1005, + 443, -76, -1256, 8255, 3841, 6116, 4226, 3705, + -1278, -6470, 5220, 5892, -3468, 2736, 5427, -3336, + -264, 1906, 294, -60, -7078, 7699, -9792, -7108, + -2030, 1055, -6962, 702, -2074, -232, 127, -430, + 658, -272, 757, 138, 159, -340, -4606, 1021, + 146, -7690, 6001, 5660, 3363, -367, 13222, -441, + 13, -874, 668, 2293, 875, 1238, 110, 778, + 1434, -976, 2151, -8169, 1421, 2622, 206, -795, + -816, -14443, -1583, 3356, 2971, -964, -321, -841, + -404, 111, -5595, 4248, -3819, 214, -2520, -712, + -1505, 849, 947, -876, 188, 3221, 863, 105, +-17336, 1818, 14, 17, -6349, 379, 4746, -12405, + -560, -3448, 3664, 8251, 845, 383, 1348, -739, + -780, 1695, 4828, -123, -647, 823, 9940, -183, + -1804, -7112, -161, 578, -619, 11534, 3214, 1586, + 4784, -2540, 1188, -304, -485, -648, -824, -595, + -8817, 4138, 927, -3259, -198, 4022, 2213, -1627, + 645, 14602, -1058, 1481, -1670, -113, 564, -710, + -451, -360, -1261, 2504, 247, 5566, -7262, 1344, + -5106, -1608, 1946, -4240, -7393, 10440, 3306, 1940, + -999, 155, 832, 55, 10218, 11475, -3252, -8295, + 1347, 2405, 3421, -2619, 2262, -2829, 754, -307, + 548, -2040, -1130, 317, 170, 292, 248, 2601, +-18930, -1942, 1417, 1678, 3310, -2578, -1969, 1550, + 3010, 70, 8, 3064, -848, 504, -172, 180, + 1787, -1133, 2427, 1002, -664, -40, 192, -23400, + -1004, 513, -818, -382, 360, 360, 268, 98, + -202, -192, -668, -12924, -11702, 7325, 797, 1937, + 674, -2458, -541, -1497, -1673, -955, -356, -486, + 182, 299, -46, 65, -4232, 1418, 6532, 2356, + -4894, 4870, 3369, -4585, 8743, 1497, -1451, 862, + -8612, -1718, 1716, -2389, 371, 592, 7397, -3188, + -649, 126, -1300, 1374, -1292, 645, -1494, 2736, + -1468, -1808, -17223, -352, 111, -222, -236, 171, + -198, -7994, -3822, 5324, -16856, -517, 119, 314, + -360, -515, 435, 520, -638, 1635, 420, 1191, + 830, 710, 6897, 2925, 3091, 510, 3268, -1702, +-16186, 718, -3127, -463, 763, -1035, 725, -122, + 646, 172, -164, -277, 5853, -7074, -10, -1770, + -2544, 5978, -874, -494, -232, 14465, 1815, -1902, + 987, -1533, 1216, 741, 620, 161, 4414, 4184, + -32, -2944, -4619, -462, 15701, -1026, -140, -2396, + -1747, -538, -1024, 219, 854, -351, 860, -226, + -4390, 732, -2003, -2430, -540, 592, 1622, 1180, + 385, -2052, 4050, 17401, -650, -243, 1709, 1261, + 95, -307, -5110, -666, -7094, -533, -1293, -17357, + 2929, 2389, -119, -413, 317, -962, 709, -1552, + 26, 175, 700, -570, 20120, 1107, 232, 169, + -889, -533, -1276, 22, 959, 866, -954, -792, + 873, -172, 1757, 195, 148, 423, 4490, 8782, + 631, 682, 1832, -3728, -1742, -11130, -1201, 1776, + 9268, -586, -1358, -646, 626, -866, 5, 263, + 3950, -760, -2914, -12751, -12669, 1513, -4, 631, + 1835, 312, -167, 1546, -532, 619, 1176, 1436, + -116, 312, 7054, 3120, 4075, -1320, 715, -206, + -1572, 1350, 17688, -1182, -1568, 680, 6, 207, + 1010, 600, -766, 554, -1483, 644, -8810, 624, + 148, -4015, -1536, -1863, 92, 730, -14806, 386, + -5174, -1420, -331, -254, -104, 275, -7268, 2563, + 11983, -65, 8043, -1623, -2589, -2610, 1328, 3154, + 1935, 3672, -1761, 4984, 661, 209, -1038, 122, + -1019, -28948, 55, 358, -539, 488, 55, 618, + 20, -314, 446, -1016, 618, -93, -94, -331, + -36, 194, -1706, 6628, 396, -146, -765, 10500, + 2619, -82, -10894, -3908, -888, -192, 620, 163, + 78, 774, -293, -104, -4826, -14066, -1883, -3258, + -4577, -1484, 5412, -4274, -4951, 3316, -907, 1948, + -1187, -404, 3654, 400, -70, 459, -3224, -3194, + 2338, 4390, -5, -3167, 3273, 116, -1026, -1668, + 3767, 272, -16662, 137, -1634, -1007, 220, -310, + 982, 8220, -16, -1251, -2644, -3344, 2236, -1573, + 8174, 612, 1142, -10799, 393, -707, 4804, 397, + 1232, -292, 5762, -15608, 2921, -6440, 3544, -2395, + -504, 1890, 172, -1010, 178, 380, -1163, 404, + -1230, 1034, -596, 105, -2038, 1991, 5613, -312, + -4156, -10205, 3092, -4704, -6101, -1620, -1037, -1130, + 1590, 8321, -797, 247, 954, -103, 3838, 2330, + 10064, 3197, -8508, 1300, -1012, -6607, -3861, 5651, + 31, -475, 1582, -1370, 1107, 2164, 743, -567, + 4842, -2930, 3191, -190, -2230, -47, 254, 2147, + 591, -512, 1312, 1159, 811, 1444, -1312, -257, + 16016, 789, -2562, 3983, -373, -9255, 302, -3655, + 5750, -3856, -6941, 3934, -2314, 5556, -4099, -265, + -479, -4843, -130, 20, -4859, 3083, 6482, -3738, + -3936, 590, -6368, -1784, 75, -3903, -6834, -4452, + -871, 764, -1118, 8731, 38, -148, -3368, -6330, + -370, 2234, 907, -2809, -1458, -2306, -402, 2679, + -1222, 1138, 192, -1317, 1012, 15514, 624, 279, + -4032, 2565, 6162, -938, 5760, 1685, 4350, 2939, + -825, -331, 1840, -556, 427, -4642, -23, 8346, + 7577, -467, 3848, 454, -3962, 373, -116, 2314, + 4868, -208, -1367, -1803, 2681, 806, -4279, 3348, + -528, 14027, -238, -457, -2764, 832, -4680, 4354, + 1219, -801, 2414, -5204, -3768, -6524, 5163, -10909, + 1656, 321, 3260, -1773, 214, -135, -4563, 5206, + -4794, 1486, 406, -1026, 281, 1799, -218, 320, + -908, 872, 1056, 2955, -208, -799, 15492, 334 +}, + +.cb4440s1 = { + 27498, -414, -266, 646, 229, 94, -15, 302, + -489, -401, 125, 752, -476, -200, -976, 195, + 4, -402, 2220, 1012, 1731, 2530, -652, -21380, + -679, -867, -195, -114, 1326, 2531, -348, -185, + -114, 178, -694, -298, 8752, 1735, 2640, -2374, + 6191, 1516, 5771, 6705, -253, -8502, 986, 2134, + -1854, 3490, -678, -48, 133, 844, -1635, 1630, + 6056, -756, -1109, 1563, -1445, -139, 580, -1448, +-18675, 846, -390, -259, 1548, -324, 281, 142, + 1792, 1211, 1328, -4308, -1032, -5412, 4742, -201, + -47, -297, -8403, 9715, 7268, -3756, 1573, 677, + -88, -145, 4877, 12946, 3264, 1809, 7230, -2583, + 1627, -1786, -7113, -1480, -2111, -508, 415, 1664, + -483, -538, -249, 80, 7005, -2562, -887, 3801, + 6411, 2222, 36, 875, -5089, 10897, 4014, 4948, + -1580, 1425, -1814, -391, -96, 322, -6484, 1896, + -7790, -950, -4235, -8362, 3118, 4843, 3754, 1070, + -1648, 7692, -1675, 3405, 918, 2270, 573, 193, + 6024, 8912, -4905, -1810, 985, 1877, 2158, -2150, + -386, 3908, 2030, 419, -12599, -570, -150, 1580, + 36, -152, 2, -538, -1565, 6809, -715, -6266, +-12725, -6718, 810, -603, 1547, 1001, 2250, 810, + 1773, -672, 327, 246, 6414, -7511, 916, -327, + 830, 11862, 4373, 1003, 6370, -1730, -2127, 613, + 1627, 626, 763, -864, 207, -233, 3738, -8644, + -1634, -2050, 3906, -451, 12986, -4828, -2973, -4714, + 545, 822, 735, -3539, -256, 65, -93, -94, + 2923, 7075, -3763, 6172, -9544, -2675, -3833, 930, + 418, -4496, 3790, 386, -7797, 234, -609, -259, + 454, 330, 1546, -7634, -1966, 515, -2496, 374, + 2633, -3014, 4126, 9920, -7103, 1441, -150, 7695, + 670, -48, -41, -512, -6849, -1785, 3755, 1860, + 2418, -2346, -1194, -1574, 15510, 444, -1515, 585, + 742, -199, -1115, -122, -11, 140, -7763, 1438, + -317, -444, -17149, -24, 2685, -856, -3166, 1109, + 308, 233, 30, 63, 530, 645, 84, 133, + 6139, -1183, -10673, -12790, -112, -1544, 4623, 576, + -804, 1023, -1646, 1192, 269, 2681, 44, -909, + -14, -414, 48, -4002, 4768, 3440, 3252, 1441, + 101, 372, 3166, -1398, 325, 16184, -711, 486, + 1328, 114, -450, -31, 1152, 2154, -69, -252, + 32, 922, 219, -2055, 421, -1377, 1006, -614, + 234, -40, -84, 204, 27171, 182, 1034, 1536, + 834, -8038, 1243, -3074, -7829, 11165, -1854, -1173, + -871, 4105, 3588, -3191, 188, -2102, 124, -166, + 8070, -11066, 6632, 2739, -7787, 184, -5872, 1360, + -1089, 1273, 84, -1683, -1584, 975, -206, 1160, + 180, 12, -6121, 5436, -14726, 5949, -6756, 834, + 1750, -3142, -878, 7, -220, -1933, -141, 160, + 26, 756, -800, 6, -8104, -6989, 3353, -3518, + 4510, -12430, 736, -2685, -1042, 32, 1184, -519, + -312, -1073, -402, 71, -422, -35, 1791, 12735, + -2281, 2623, -1502, -3878, 6727, 10541, -1110, 2308, + 870, 1124, 874, -1406, 123, 254, 405, 328, + 3828, -7541, 3096, -14145, -672, -1725, -423, -1918, + 4164, -411, 3094, -568, 3575, -2895, -378, -3065, + -232, 449, 8110, 2264, -1383, -557, -10683, -7628, + 4155, 754, -134, 6759, 1051, -2054, -900, -948, + 579, -1277, 151, 462, 11562, -310, -8260, 10238, + -1309, -3052, 345, -689, -1133, -588, 548, 980, + -1332, 881, 368, 776, -704, 422, 12433, 1314, + -1487, -4753, 2679, 3092, -939, 136, -586, 3504, + -1034, -6318, 3506, 420, 2326, 1034, -252, -398, + -6232, 4488, -6166, -1754, 908, 4884, -5188, -2985, + 10793, -116, 4674, 3980, -9, 805, 1568, -1620, + -88, -146, 3027, -16154, 2899, 7839, 5912, -427, + 270, -1467, -387, -351, 615, -322, -2, -1061, + -654, 56, -438, 132, 2388, 460, 2172, 1874, + -3028, 3302, 2035, -704, -1222, -19835, -472, -1858, + -1686, -286, 5, -748, 491, -350, -4344, 103, + 1473, 2440, 13575, -1350, 1456, 10377, 1962, 3036, + -1238, 1580, 607, 1352, 997, 1212, -489, 251, + 4075, -3457, 6186, 786, 300, -2532, -373, -2522, + 3108, -294, 4938, -2980, 1509, 12450, -695, -1128, + -96, 354, -3678, 8494, 2480, 2264, 5162, 11907, + 4721, 1111, 752, 2999, 3924, -1429, 321, 276, + 309, -603, 601, -62, 3337, -3570, 3273, 6618, + -2001, 950, 532, 972, 1619, 956, 65, -609, + -281, -14769, -438, 580, 230, -228, -10108, 12289, + 8904, 872, -3296, 1535, -384, 477, -913, -777, + 546, 445, -1004, -435, -716, -138, 572, 435, + 4626, -864, -5716, -2810, 1291, -4796, -241, 2527, + -2342, -1360, 4161, 1886, -128, -1521, 13726, 1818, + -554, -157, -9665, 2607, -1013, 579, 1122, 1571, + -2684, 11364, -6464, -184, -1542, -5670, -1091, -670, + 1273, -1051, -7, -278, -2551, -548, -10673, -1434, + -343, 317, -3108, -1615, -2239, -14132, 490, -454, + 2467, 1990, 470, -1072, 440, 290, 3006, -4420, + -2083, 3050, 2779, -2349, -590, -4941, 7464, -9000, + -2686, -2045, -8712, -3281, -2476, 648, -148, 408, + -1367, -1113, 27347, -1113, 739, 39, 1443, -208, + -686, 986, 735, -702, 76, 665, -194, -165, + 366, -606, -4908, -3932, -15941, -2810, 4572, 816, + -2092, 4213, -2492, 4006, 926, 210, -1110, -1635, + -270, -226, -362, -187, 1790, 3016, 2216, 3890, + 2018, -1325, 19784, -771, 356, 2118, -98, -688, + 1016, 978, 559, -39, 160, -310, 6622, -1754, +-11104, 204, -2212, 2370, -11610, 1119, 3216, 3102, + 524, 278, -829, 524, 28, 838, 374, -76, + -4593, -2933, 10697, -6510, -4970, -2025, -9383, -3428, + -4112, 2665, 1459, -1411, 421, 481, 842, -341, + 147, -158, 4108, 45, 4935, -21, -7905, 2058, + 1158, 15260, -567, -752, -992, -1094, -1059, 2370, + 820, 655, -261, 280, -3969, 6342, 8521, 3114, + 369, -12269, 1684, 4, 4686, 1985, -3668, -3040, + 677, -254, 57, -161, -989, -379, 7075, -580, + 2846, -3177, -2285, 958, -7096, -154, -515, -3345, + 13487, 3548, -1804, 290, -430, 726, 399, 54, + -2814, 10235, 1958, -3356, -1330, 536, 3218, -14194, + 200, -796, -862, -1480, 1811, -346, 604, -391, + -231, 513, -10495, -6029, -6492, -8746, -357, -221, + -1890, -2669, 8, -1756, -5812, -1048, 2258, 223, + -474, 1154, -226, 348, -1590, 2915, 158, -24059, + 875, -846, 1150, -1000, -844, -116, -246, -219, + -482, -367, 120, 517, -489, 442, 8148, 5040, + 3770, -1006, -51, -3175, -10278, -4468, 1188, 1497, + -6515, -5, -1628, -2387, -1297, -717, 1630, 232, + -3608, -6688, 2444, -792, -246, 411, 1464, 3661, + 3244, -1121, -1602, -15398, -443, 882, 1412, 926, + 16, -73, 2693, 7168, -9399, 528, 7916, -9270, + -1669, -2756, 1304, 3074, -1510, -2089, 1491, -1556, + -422, -414, 132, -192, 5988, 4500, 7572, -10978, + -4875, 3685, 1888, -660, -1750, -515, -2728, -3133, + -2742, 666, -2861, 626, 256, 243, 4587, -3567, + -288, 2314, 4765, -11036, 7322, 7581, 2651, 3264, + -394, -246, -891, -1464, -1717, 123, -517, -486, + -1019, 7215, 554, 722, -4253, 2393, 3053, 2881, + 1538, -2104, 573, 321, 673, 3902, -2855, 944, +-12816, 370, 3496, 952, -1435, 6379, 766, 2273, + -729, 80, -2432, -1150, 2408, -895, 15497, -1231, + -282, -3306, -435, -167, -3528, -5683, -6413, 2501, + -4825, 124, 3128, -425, -2800, -986, -2283, -495, + -3392, -1560, -2093, -11613, -37, 157, -438, -794, + 1988, -45, 1508, 20, 98, -458, -245, 1130, + 110, -525, -771, 1120, 710, -21758, 174, -210, + -4839, -2468, -648, -4388, -11, 2990, -181, -4790, + -4232, 3634, 6427, 2772, 166, -2996, -12005, 1630, + -249, 179, 856, -1250, -4216, 1993, 5164, 4757, + -5071, 4331, -3029, -1276, -11184, -2864, 1238, 6332, + -2431, 1276, -338, -476, -5659, -2410, 2510, 1853, + -4853, -3175, -1896, 10728, 3724, 960, 9963, 305, + -938, -646, -2760, 1436, 113, -74, -3098, -4090, + 2950, 2701, 992, 206, -1393, -2179, -10862, -2396, + -1008, 2639, -1547, -416, 9264, 1824, -360, 401 +}, + +.cb4440m0 = { +-25793, -238, 1193, -2635, -238, 1315, -2277, 1588, + -896, 512, -864, 611, -398, 1277, -212, -358, + 202, 13250, 16, -860, 1618, -1024, 310, 11560, + -746, -3876, 780, -4087, -475, 857, 1017, -1439, + -890, 155, 8556, 362, -1158, 2116, -291, -66, + -1272, 510, -1394, 2259, -4761, 808, -740, -937, + 13993, 191, 273, -7670, 6776, 846, -1907, 955, +-13206, -1956, 1697, 1670, -329, -244, 2395, 6119, + -802, -1007, 649, -974, 170, -2136, -10780, 1020, + 1270, 1954, 1118, 13348, 983, -1394, -594, -514, + -586, 1026, -1821, 548, -298, 3342, 837, -1395, + 13977, 1021, -7792, -2930, 1466, 5494, -843, 2432, + 1378, -68, 174, 407, 76, -877, 691, -9445, + 522, -3448, 2549, -412, -2358, 875, -5044, -952, +-10113, 6574, -6347, -2760, -662, 29, -227, 4884, + 1304, 411, -3320, 2434, 785, -14822, 4412, 2272, + -6407, 2172, -613, -1665, 296, 742, 624, 135, + 5316, -3191, -855, -2061, 485, -3188, 2998, 1382, + 2516, -2438, -3506, -238, 737, -629, 1001, 773, + 17540, 1478, -724, -764, -1231, -1254, -1582, -692, + -351, -1551, -171, 183, 38, -668, 756, -770, + 24344, -905, -7182, 502, -3766, -1690, 1588, 1522, + 1844, 1276, 1458, -777, 1731, 4856, -14860, -1097, + 36, -1310, 846, -1500, 521, -3669, -252, 4480, + -2602, -845, 597, -4512, 1062, -292, -18518, 1972, + -334, -80, -1256, -366, 3640, -436, -12, -1670, + -435, 1496, 1429, -11092, 1012, -936, -1224, -12240, + -3048, 210, 1905, -1197, -357, -9759, -2632, -332, + -3417, 15078, 1496, 2206, 1800, 205, 1384, 3546, + -1853, 755, 1016, 726, 58, -150, -13053, 10375, + -2589, -330, 1616, 3081, 2763, -2617, -1204, 324, + -53, 2968, 1485, 214, 124, -334, -237, 16784, + 2612, 1023, -4298, -2156, 4336, -4307, 4952, 1036, + 81, -762, 3416, 714, -187, -4100, -757, 1124, + 10224, 7059, 424, -316, 1281, -12262, 912, -1999, + 2, -731, -184, 879, -934, -202, -391, -1046, + -338, -101, -17511, -1712, -5580, -2327, -2478, 1770, + -5825, 1499, 578, -130, 1424, -1818, 110, 542, + 22, 988, -4227, 2836, -1447, 1170, 12335, 2179, +-11216, -2500, 64, -912, -954, 654, -802, -455, + -597, 234, -296, 811, 1083, 1848, 4148, 637, + -6608, -2362, -3382, -664, -13088, 2839, 3090, 3294, + -4554, 2518, -55, 837, 1392, 5905, 1287, -1484, + 965, 16533, -3507, -1903, -1562, 2408, 5037, -4816, + 1409, 361, -1890, 170, -610, -1755, -524, -867, + -6238, -20117, -745, -956, -176, 2998, 130, -668, + -843, -267, -364, -573, 495, 127, -66, 32767, + 271, -408, 654, -123, 1831, 151, 996, 82, + 628, -251, 144, 198, -88, 357, 37, 612, + 184, 238, -584, -52, -30025, -415, 404, -566, + 100, 659, -336, 877, 211, -730, -377, 184, + -5256, -1484, -1191, -2108, 24, -7821, 209, -2856, + -1844, 697, 5798, -1191, 427, 11858, 1000, -261, + 184, -686, 1182, -3142, -3138, 139, 144, 117, + 3658, -3566, -1562, 672, 2036, 15051, -5069, -551, + 529, 1696, -214, -2678, -5966, -3707, 2847, -2554, + -1760, -1196, 2088, 6372, 1778, 12935, 2189, 1992, + 1761, 578, -542, -753, -1182, 4321, 1871, 309, + 704, -1259, 884, 19136, -2665, 1096, 3048, -167, + 872, -344, -1092, 464, 3255, -86, 1608, -1062, + -1569, -1699, 4504, -274, 568, 1428, 20571, 1452, + -894, -791, 459, -882, -1048, -2944, -11095, -783, + -832, -2450, 650, 2784, 3156, 529, 457, 483, +-12553, 655, 686, -757, 929, 212, 1242, -201, + -1627, 4826, -1895, 997, -3225, 84, 80, 287, + -2136, 405, -188, -890, -18272, -511, -118, -3642, + -1018, 420, 12650, -474, -540, 6978, 6977, 4418, + 1162, -1332, -1112, -1765, 2640, 562, -1164, 1256, + 595, 567, -483, -31511, -960, -816, 756, 1505, + 12, -518, 234, 184, 679, 328, -600, -137, + 267, -440, 2540, 593, 1023, -11756, 626, -2034, + 5756, -9882, 3175, -1190, 1628, 3920, 3219, 1394, + 834, -140, 4036, 4722, -455, 3105, -1355, -3106, + 1000, 7806, -2227, 687, -1580, 3180, -12302, -1394, + -425, 488, -187, -36, 219, 158, 12006, 1683, + 2151, -2, -1110, -12250, -59, 672, 1844, 2084, + -2101, 1652, -783, 634, -13257, -339, 3932, 2260, +-12452, 152, 316, -688, 79, -912, -2081, 1384, + 188, 1942, -706, 204, 700, 1776, 13901, -13666, + -324, 472, 1055, -646, 82, -769, -877, -443, + -227, -900, 636, -870, 470, -112, -598, -4402, + -2726, 1775, -216, -43, -18675, -863, -4604, 3433, + 674, -155, 208, 1546, 294, -157, -616, 11070, + 1229, -528, 2124, 699, 3624, 54, -516, 194, +-13556, 1902, -506, -1317, 1916, 471, -342, 836, + 18, 906, 614, -8, -951, 1052, -97, 2212, + -924, 310, 6, -733, 122, 23731, 468, 345, + 1545, 1434, 611, 403, -3136, -2214, -54, 1023, + -1390, -5243, -3744, -258, 6871, -1778, 673, -2362, +-13007, -776, -974, -1077, 8386, -3978, -4325, 1236, + 4011, 1161, -263, 1224, -12957, -100, 2801, 1458, + -3081, 578, 17, 1037, -742, 5972, -632, 2904, +-12721, -6733, -478, 182, -1973, -820, -6911, -4904, + -942, -348, -353, -350, 7864, 34, 568, 1985, + 956, 3310, 118, -2067, 12600, 9063, 1609, -1261, + 296, -1248, -1656, -65, 1832, 1525, 1503, 5149, + 4370, -1638, -3868, 320, 1527, -424, 17676, 1780, + 1172, -1132, 1128, 1294, -322, -101, 462, -6668, + -3024, 7573, -11088, 1581, 13, -1398, 550, 4376, + 1623, 1727, 857, -5310, 2528, -529, -401, 539, + 6508, 4246, 4105, -5363, 96, -13407, -694, 5061, + 3445, -3283, -348, -1470, 1114, 602, -404, -129, + 642, 1547, 23110, -2255, 1969, 333, 1297, 116, + -1691, 364, -528, 758, -1239, -1826, -249, -395, + 684, -856, -638, -10000, -2773, -6151, -1244, -3138, + -9688, -1994, 7124, 1368, -1870, -312, 1863, -1006, + 963, 789, 743, -4158, -760, 1384, -7525, -959, + -262, 5752, 4005, -12037, -210, 886, -1961, 4895, + -251, -158, 212, 677, 518, 342, -226, -360, + 466, 17, 28392, -20, 246, -686, -258, 640, + -378, -120, -443, 1078, -2612, 2084, -1706, 4334, + -4675, -4634, 2336, -9998, 9975, -1285, 2778, 3292, + -1717, 138, 2114, -1120, -180, -1146, 11988, 829, + -2530, -8827, 6833, -1191, -1653, 2691, -4067, 1166, + 1971, 303, -544, -1459, -261, 1065, 3410, 2050, + 3163, -515, 5456, -4261, 5483, 1531, -2098, 2020, + 3773, 588, 915, 158, -11876, 282, -1180, 265, + 11036, -66, -1741, -1894, -4234, 3048, 218, -1030, + 2240, -12666, -2290, -1673, -1911, 1480, 287, -81, + 1182, 216, -10734, 2201, -58, -619, 8585, -574, + -4576, 1852, -468, -6759, -7667, 167, 995, -1114, + -1276, -2053, 2178, -8133, -1270, -7822, -10582, 5380, + 3037, 1071, 827, 4972, 1024, -129, -180, -3002, + -846, -736, 9587, 1890, 10287, -1954, 1042, 1558, + -950, 2406, -1852, 2275, 6694, -703, -910, 3854, + 812, 521, -1075, -761, 5357, -3911, 3892, 7944, + 4580, 5031, 1088, 7116, -1746, -5223, 2607, 3227, + 2296, 5603, 211, -731, 6450, -3312, -12378, -326, + 4245, 4168, -799, -3563, -505, 725, -5297, 2196, + 2221, -16, -3472, 315, 626, -6131, 71, 920, + -4383, -1340, -2675, -664, 7412, -1240, -1361, 997, + -3817, -2377, -11717, 1661, 22, 540, -5261, -950, + 7472, 3148, 7647, -4400, 4558, -4412, -869, -1528, + -2618, 8311, 2110, 534, -460, -223, -162, -828, + 274, 1844, 1861, -1583, 6899, 5222, -1772, -2880, + -6400, 4703, 2606, -3990, -1224, -4160, 9032, -299 +}, + +.cb4440m1 = { + 32767, 383, 857, -1579, -423, 1164, -1606, 1218, + -410, 777, -292, 122, 282, -74, -1394, 259, + -734, 102, -82, 32616, 427, -545, -146, -141, + 340, 506, -808, 171, -778, 900, -204, -277, + -228, -426, 566, -481, -1138, -907, 112, 2722, + 871, 115, -7202, 1953, -826, -1812, -396, -14722, + -840, 155, 1114, 5624, 1112, -147, -6383, 926, + 1505, 360, 937, -13391, 969, 7062, 2218, -3531, + 471, 458, 191, -465, 8664, -1168, 546, 2109, + -944, -74, 1644, -81, -760, -1920, 2659, 13330, + 1511, -1148, 1346, 796, -20, -15616, 1246, -1190, +-10882, -774, -70, 3643, -896, 1830, -192, 1018, + 1085, -95, -309, 659, 91, 727, -4486, 486, + -2078, 1235, -14415, -4053, -1619, -2589, -582, -4650, + 4076, -762, -1111, 277, 1448, -742, -314, -979, + 1889, 2679, -1972, 2480, 302, 2869, -9183, -445, + -1817, 12894, 106, 187, -1406, -615, -1174, 746, + -371, 382, 350, -1811, -527, 36, 500, -835, + -106, 1134, -2207, 1021, 348, 908, -21780, 448, + 688, -60, -1790, 1901, -22990, 1467, 596, -912, + -3190, 1484, 269, -409, -474, -1670, 1328, 152, + -402, 359, -734, -13208, 62, -4197, -6242, 5195, + -2841, 5030, 2794, 1264, -1130, 3821, 961, 729, + 1075, 49, -148, 7267, 2596, -5093, -8284, -6875, + -3059, 3909, -4635, 1402, -6334, -342, -3083, -861, + 490, 1257, -630, 128, 2240, 832, 1060, -1802, + -1652, 128, 7816, -14391, -6722, -3328, -2586, 3044, + 1088, 1577, 852, -142, -176, 1371, 1236, 976, + 12165, -1596, -199, -504, -11020, -582, 972, -1468, + -2402, -666, -3327, -2148, 1078, -194, 9675, -2102, + -1236, -70, -942, 291, 1364, 1403, -3362, 12963, + -375, -1728, 1615, -2354, 633, -506, -194, 13037, + 14172, 534, -1026, -425, 2488, -180, -678, -436, + 272, 1507, -334, 840, -1000, -1068, 1029, -306, + 24, -4435, -5994, -1307, 4251, 3968, 2527, -981, + -2626, -4400, -242, -1823, -679, 12831, -22, 51, + -381, 2422, -2376, -8156, -1477, -6974, 1102, -373, + 467, 11314, -554, -432, 824, 7277, 393, -178, + 179, -653, 11848, -1593, 14143, -731, -1036, -2322, + 261, -1992, -1152, -1430, -1354, -51, -285, -1637, + 144, -59, -2182, 5731, 538, -880, 397, 3010, + 707, -1822, -1006, 4686, -5096, 4246, -3096, -3997, + -254, -11025, 394, -345, 18780, -686, -517, -3422, + 104, -2173, 2439, -5400, -10, 1084, 1821, -602, + 1431, 405, 2143, 499, 405, 351, -62, -47, + 1954, -29915, 440, 1054, 559, -1210, 442, 928, + -1, 59, 279, -112, -110, -440, -396, 805, + 311, 858, -431, -1070, -30192, 135, 1246, -345, + 790, 498, 319, -302, -469, -10, 512, -829, + -526, -2052, 2456, 134, -19375, -1210, -1292, 640, + 3232, 2580, 973, -2412, 271, -282, 632, -523, + -847, -138, -990, 2501, 536, -166, 2100, -357, + 122, 466, -4, 2034, 20083, 1578, 444, -344, + -689, 5733, -456, -503, -592, -1350, -1038, 932, + -1916, 1098, -990, -22687, 1544, -442, -396, -570, + -683, -616, -1431, 118, 4113, -312, 2300, 2093, + -2344, -2955, 6343, 4306, -10078, 6286, -5794, -806, + 664, -217, 548, 5072, 4626, -1643, -11619, 779, + 1956, -2960, 614, 2087, 9104, -2418, 775, -4447, + 768, 1599, -1084, 999, 1652, 1090, 630, -1197, + -3495, -912, -9817, 648, 3278, 1828, 13605, 2757, + -831, -1191, -1846, -1441, -278, -8530, -455, -495, + 323, -911, 2500, 14100, 3635, 1016, -936, 5265, + -3092, 2125, -121, -64, -656, -337, 9438, -7600, + 1403, -11917, 2180, 2612, 1664, 1091, -318, -3300, + -427, 282, 1979, 894, -703, 514, 160, 1697, + 6508, 828, 187, -34, -1094, -2861, 240, -5013, + 6004, -4796, -991, 158, 11437, -1730, 354, 1195, + 3790, -10432, -3584, 13872, 336, 2043, 221, 604, + 2930, 1080, -1417, 1878, -878, -459, -419, 364, + -1037, 7764, 3100, 48, 11057, 1936, 2229, 9150, + -472, 1178, -129, 2876, -249, -258, -1181, -329, + -581, -1140, -1967, 347, -539, -394, 775, -1151, + -31, 1052, -1900, -213, -1552, 22484, 164, -113, + 135, -1294, 550, 7738, -7223, -739, 1362, 5518, + 193, -2170, -11861, -1357, 351, 2215, 165, 16, + -606, 727, -158, -772, -13420, -1248, 12422, -812, + 1768, -442, 1269, -1076, 899, 124, -249, -1110, + 653, -3064, -1632, 839, -230, 512, 642, 13230, + 13285, -552, -1113, -595, 864, 537, -1012, -539, + -615, -491, 1014, 800, -10, 534, -1227, -25011, + 1239, -26, 3834, 104, 762, 1259, 2112, -300, + -920, -812, 612, -1061, -378, -246, -7, 11042, +-18492, -1411, -77, 407, -556, 218, 1751, 1069, + -294, 1789, 904, 285, -76, 300, -160, -128, + -3398, -2001, 1689, 4946, -2750, 1427, -12632, -1873, + -1802, -1115, -2777, -4436, 2937, -6408, -467, 487, + 1043, 3914, -81, 1540, -11718, 1368, -12656, -583, + 1009, -416, 249, 1874, 1157, 994, -858, -154, + 294, 333, -26, 73, -1576, -20, -560, -1068, + 1325, -588, 26161, 1580, -411, -587, -1083, -79, + 762, 292, -622, 788, 284, 2014, 78, 554, + -516, 1340, 835, 300, -24827, 558, -705, -22, + 139, -159, -246, -585, 4318, 234, 1308, -198, + -3370, 5724, 2381, 13843, 4, 569, 8002, 1188, + -63, -1698, 4624, -405, -218, 4238, -888, -1180, + 3750, -4848, -9497, 293, -1087, -13274, -33, -2870, + 457, -618, 338, -34, 286, 345, -5321, 904, + -5656, -2082, 12644, -7423, 532, 958, -1997, -1483, + -2982, 3115, -1851, -2025, 1853, -918, -903, 1554, + 540, -16549, 1441, 2939, -1272, 3106, 2374, 3906, + -697, 1144, 750, -379, -6502, 980, 386, 36, + 1109, 1195, 6272, 4264, 1501, 5369, -1560, 3535, + 1084, 739, -1031, -4400, 8452, -430, -1787, -7669, + -231, -115, 4324, -1820, -2098, -786, 7478, -2709, +-14255, 5771, 115, -1700, -111, -1482, -1369, -112, + 122, -472, 233, 2427, 1816, 180, -481, 928, + 82, 84, -700, -448, -946, 1968, 1644, 168, + -167, 16164, 155, -10316, 941, -584, 488, 96, + 5205, 491, -1844, -13055, 1266, -352, -836, 558, + 1546, -1720, 313, 2033, 597, -14351, 4426, 3281, + -559, 2614, 3248, -2265, -10312, -1614, -288, 480, + 1419, -546, -485, 835, 960, 462, 923, 6518, + 834, -711, -12639, 8811, -207, 1806, 337, -1240, + -4796, 2383, 277, 1141, 969, 59, 197, 1365, + -614, -9144, 4824, -436, 4191, -2588, 4509, 391, + -5055, -3231, 6978, -6388, 51, 105, -863, 1050, + 13103, 12769, -420, -1562, -123, 2702, 292, 1061, + 123, 405, 1917, -275, 493, -95, -195, 130, + -2613, 9010, 196, -1382, 5903, 7281, 1585, 2557, + -876, 3166, 6910, 590, -3060, -559, 4722, 393, + 613, -392, -3022, 9892, 1808, 923, 8123, 9873, + -1665, 2349, 2894, 591, 2000, -3734, -917, 220, + 408, 296, -656, 2608, -1700, 400, -10734, 5434, + 6504, -1399, 2175, -1203, -6358, -1221, -5062, 45, + 970, -500, -1322, 1176, 5882, -11687, 6324, -2183, + 2327, 922, -5628, -3507, 2406, 874, 1399, 4518, + -343, 857, -224, 802, -725, -8561, 4432, 1974, + 1825, -2168, -451, -3408, 6587, 7589, 3361, -4711, + -1474, 3151, 1950, 1022, 1466, 9192, 4666, -822, + 1024, 2342, -2220, 1169, 10460, 2993, -988, -4407, + -6727, 902, 1659, 80, 106, 400, 34, 1746, + -6982, 10484, 6333, -845, -3333, 1764, 217, -4730, + -3306, -3664, -2830, 2254, -927, -55, 587, 1812, + 281, 4375, -3614, -1349, 1802, -6184, -2648, -4189, + -9381, -3243, -4147, 384, 2241, 5524, -478, -1534 +}, + +.cb4448l0 = { +-15402, -5156, -1798, -144, -4711, -4700, 2819, -389, + 148, -2600, 1706, -1906, -578, 495, 24, 829, + -383, -12581, 11667, -1039, 1395, 2670, -288, 23, + 628, -248, -512, 79, -326, -5428, -2830, -2476, + -1253, -915, 12042, -674, -110, 2950, 3885, -5799, + 983, 616, -652, -60, -372, 22, -141, -167, + 98, 125, -100, 27211, 133, -127, -271, -272, + -176, 1268, 173, -422, 2431, -3998, -2797, 2328, + 182, 6526, 3318, -6282, -10580, 3966, 8504, 527, + 9507, 6203, 990, -989, 6030, -136, 647, -1100, + -324, -2618, -2499, 500, -132, -842, 1237, 3599, + 2285, 2906, 10766, 11284, -2794, 242, 184, -1934, + 55, -839, -1181, 406, 855, 902, 10490, -327, + -1561, 5742, 428, 2218, 1523, 5229, 9130, -760, + 108, -140, 22229, 1132, 411, 720, 414, -356, + -745, -1276, -899, -562, 369, 5, -7770, 4101, + 3626, 126, -13, -4356, 728, -3197, 1930, -1470, + -6936, -410, 6720, 1897, -530, -4267, -2181, -876, + -472, -2540, -10234, 4008, 10217, -2561, -2021, 716, + -1378, -325, 427, -245, 314, -48, -118, -150, +-30295, -368, 256, 369, -656, -78, -246, -140, + -1250, -635, 1332, -13604, -10383, -1375, 353, 2417, + 2140, -349, 1460, -51, -309, 523, 509, 2352, + 1208, -377, -2023, 9708, 397, 1216, 10610, -4416, + 5520, 3902, -2119, -480, -420, 1170, 36, -3304, + 1550, -266, 1682, -808, 2420, 2700, 16239, 3910, + 572, -375, 85, -9775, -120, 2214, 2779, 11510, + 2628, -416, -1740, -1305, 1226, 78, 78, 635, + 422, -13892, 1302, -4117, -1218, 2681, -8436, -1723, + 2290, 2815, 1172, -181, -675, -475, -763, 2394, + -3639, 7903, -659, 2323, 4837, -6758, 9460, -1480, + -2403, -2783, 1496, 806, -458, -246, 12, -254, + 121, 1477, -633, -513, 791, 208, -390, -177, + -1292, -20471, -4401, -2678, 9026, 128, -265, 822, + 260, 11202, 3132, -1879, -3891, 1884, -842, -107, + 7516, 1208, -1552, -995, 1203, 2150, 11044, 1285, + 2282, 80, 1348, 5342, 2089, 924, 1472, -1454, + -8259, -226, -10259, -2335, -2442, 224, 3257, -1528, + 6685, 1630, 1969, 48, 4802, 6051, 987, 8662, + -2368, -4984, -1974, -4049, -5320, 5003, 299, -400, + 727, 208, -187, 2838, -4547, 9682, -2238, 1065, + -3206, 10091, 4915, 2945, -1635, -198, 1074, -698, + -716, -96, 1390, -2644, 1006, -4154, 10587, 1132, + 2912, -7399, -8350, 785, 156, -290, -142, -374, + -2161, 1066, 1358, -1798, 3050, -19, 452, 10470, +-10948, 4190, -984, -2089, -728, 1503, 4273, 812, + 4950, -3750, 844, -1231, -1582, -2517, 2385, -10537, + 5807, -4621, 332, -357, -12484, 1676, 160, 10762, + -1225, -1374, 14, -1389, -2900, -467, -1260, 459, + -861, 102, 1715, 4295, -7324, -7400, 10435, 287, + 1866, 765, 1730, 3430, -744, -2, -1773, -96, + 2001, 2165, 118, 9296, -4640, -4612, 7134, 5128, + -7967, 404, -433, -433, 2222, -8050, 2023, 2766, + -260, -2440, 1607, 2442, 7763, -486, 3766, 2355, + 7515, 230, 1248, -8873, -8224, -9135, -1402, -1812, + 1223, 152, -2316, -739, -405, -784, -598, 625, + 503, -175, -573, -31693, 502, -478, -554, -934, + 387, -80, -484, -701, -34, -51, -494, -1461, + 1005, 2920, 11532, 2667, -1674, -832, 8680, -5767, + 786, -1558, -2062, 1009, -392, 2099, -7277, -2587, + 6302, 3070, 4496, -1713, -4042, -8109, 1642, -1894, + 3450, 840, 3632, 160, 578, 149, 767, 754, + 208, -870, -672, 252, -30, -213, -482, 50, + -578, -2, -148, 246, -31918, -568, 130, 472, + 761, -27, -51, 454, 144, 124, 5844, -8354, + 9562, -3755, -262, 3286, 1120, 983, -628, -734, + -1732, -1424, 353, -403, 15877, -13552, -335, 337, + 519, 140, 297, 150, 725, -780, 876, -116, + -91, -128, 275, 2499, 9313, -768, -10469, 1148, + 2172, -6417, 3292, -2187, -1108, 3055, 1105, 625, + 794, 68, 337, 1384, -106, -516, 574, 868, + 849, -997, 81, 25796, 28, 206, -3556, -351, + 1058, 1126, -7826, 5310, -4102, 5352, -6835, -4032, + 1487, 230, 5617, 937, 10484, -71, 2653, 1203, + -1, 667, -1489, -10136, 7782, -763, 792, 1434, + -170, 367, 96, -21992, -252, 756, 145, -1476, + 1408, 1523, -819, -576, -476, -1068, -241, -39, + 1547, 9553, -622, -1799, 1861, 6115, -864, 10690, + -586, 470, 200, 1162, 586, 44, -11650, 3453, + 8734, -2754, -178, 236, -2650, 2654, 2699, 1180, + 5325, -458, -40, -218, -6, 126, 6794, 506, + 860, 11863, 652, 1665, -4213, 4863, 1424, 5712, + -663, -688, -10, -1421, -676, -1325, -378, -311, + -490, 19501, 1242, 268, 4581, 1587, -1153, 848, + -1378, -1159, 505, 63, 704, 1942, 2204, -2106, + 44, 479, -1098, 333, -21595, -617, -6444, 3547, + 1282, -1784, 4664, -1330, 2607, 1241, -3579, 247, + -875, 11359, -3013, -136, -12813, -14400, 1857, -998, + 1342, 1187, -338, 1263, 575, 1226, -995, 596, + 446, 293, 767, -356, 70, 786, 466, 202, + 149, 849, -28991, 652, 124, -209, -124, -406, + -5463, -1413, -1300, -5339, -1761, 4770, 2680, -10542, + 3486, 5601, 2932, 1581, 489, 521, -16583, 1, + -1529, 5942, 1234, 4714, -1647, 1150, 2802, 642, + 586, 3836, 240, 307, -490, 67, 771, 816, + -906, 1554, 1090, -2353, -629, 11291, 2941, -2982, + 9473, 1434, -4351, -8017, -5173, 8071, 1931, 1281, + -4055, -3224, -1918, -271, -204, 670, 3491, 107, +-31624, 227, 75, -91, 108, 171, -53, -201, + 373, 63, 118, 126, -104, 127, -88, 1810, + 11688, -10240, 550, 3692, -4978, -1619, 40, 911, + -1080, 580, -767, 333, 192, 403, 308, -904, + 142, 31169, 503, -1101, -146, -144, 35, 181, + -355, 54, 590, 499, 95, -1767, 444, -49, + 2160, 7176, 12032, 6478, -741, -5576, -644, -101, + -1251, -1268, 2365, 10029, 537, -1476, 307, 2108, + -2478, -944, 10725, 349, -4242, -135, 7577, -4492, + 1492, -2512, 7736, -5118, -6756, -2436, -1890, -2390, + 1620, 914, 1658, 47, -11692, -134, -1740, -196, + 9521, -136, -1376, -8682, -1136, 1096, 903, -1148, + -334, -228, -4, -675, -199, 1914, 2827, -11098, + -2129, -2559, -978, 175, 1832, 10075, -2358, -1888 +}, + +.cb4448l1 = { +-11514, -2858, 12392, -305, -206, 929, 473, -3120, + -2766, -1068, -1237, 420, -718, -21, -336, -45, + -478, -1517, 1830, -12644, 259, 11978, 257, 1494, + -1759, 247, -733, 112, -2242, 290, 234, -10260, + 1781, -1806, -4104, 1747, 38, -692, 4971, -9113, + -1925, -1580, -615, -9608, 3779, -11158, 469, -4736, + 299, -2815, 2108, 1910, -2356, 66, 523, -440, + 2298, -4219, -2512, -1110, 11192, 5932, -2629, -7985, + -992, 775, -1134, 3287, 900, -681, -39, -1206, + -1708, -6800, -361, 11024, 8496, -198, -3855, 1486, + -2547, 1773, 50, -276, -286, 785, -7884, 438, + 4590, 2794, 5333, 5476, 2108, 660, 3610, 2308, + -8538, 224, -132, 134, 731, 988, -1368, 3894, + 4318, 9911, -104, 320, -9506, 1721, -5690, 1712, + -8747, -1876, -5122, -1304, -162, 752, 3646, 1621, + 11089, 1117, -1971, 1058, 3070, 180, 23112, 175, + 483, -1028, -538, 497, 1053, 61, 788, -455, + 22, -55, -32, -326, 15956, -2045, 788, 9784, + -1170, -819, -3677, 647, -484, 578, -160, 286, + -421, 289, 8140, 3838, -578, -1866, -2074, 667, +-11951, 1684, 3439, 1280, 158, -1784, 1276, 638, + 562, 2045, -220, 852, -594, -2109, -2665, 2748, + 38, 91, 1377, -624, -18586, -498, -882, 36, + 536, -99, 62, -5275, 3051, 231, -6343, -1751, + 1206, -1646, -1347, -13590, 1431, -271, -442, 21934, + -143, -1824, -378, -463, 816, 379, 336, -291, + -652, 275, -758, 257, -14866, -1304, 7260, -3373, + 1249, -1992, 2734, -2565, -3064, -416, 2424, 279, + 10518, 206, -681, -14338, 666, 1843, -648, 526, + 1982, 366, 684, 1019, 192, 8, -482, -4785, + 2134, -1722, 10674, -1613, 33, 1148, -1566, 10226, + 3397, 667, -1100, -738, 2420, -14282, 451, 90, +-10346, 2673, 1175, -3639, 266, -566, 0, 1672, + 1082, 298, 359, -497, 1784, -570, -2538, 2522, + -3825, 6265, 99, -7927, 3160, 11079, 131, -2080, + 92, -29951, 268, -293, 240, 254, -182, -145, + 303, 12, 86, 596, 246, 136, 1020, -1521, + -1134, -10125, -5691, 6028, -3703, -4295, -3718, -5719, + -564, 660, -321, -1073, 83, -3068, 6167, 12788, + -762, 8057, -1215, 2379, 2142, -3625, -503, -1418, + -304, -649, -501, -12558, 12787, 3737, 1465, -3692, + -1321, 1106, -1136, -651, -50, 1608, 59, -583, + 82, 331, 443, 782, 93, 285, 310, 29149, + -698, -52, -909, -238, -222, -114, 4, 650, + -200, 235, 2541, 598, 378, 11000, 3101, -8228, + 1690, -4313, 6996, -11, -2620, -1458, -1428, 579, + -304, 20, -372, 897, 602, 432, -138, 690, + 593, -1485, 136, 191, -32147, 260, 199, 412, + -168, -41, -384, -362, -14, 242, 366, -318, + -304, 1544, 458, -7790, 3332, -5117, -1937, 868, + 12622, 906, 1941, 4763, 1698, 351, -234, -973, + 9166, 6726, 2686, 248, 3597, -9812, -400, 4155, + 2852, -415, 2218, 876, 1423, 3852, 2965, -410, + 1820, 8268, -1296, 686, 114, 3087, 3007, -9402, + -5751, -3459, -6674, 418, 4137, 4778, 56, -1399, + -1698, -2590, 8343, -2130, 2535, 6148, -134, -2393, + 11551, -338, 735, 630, -658, 13358, 949, -1136, + -217, -985, 182, -1014, 1459, 221, 7713, -1386, + -1427, 1326, 555, 66, 2694, -1535, -268, -13596, + 658, 305, 858, 548, -12748, -582, -1055, -659, +-12155, 940, -2164, -2518, -126, -132, -842, 641, + -483, -446, -5184, -186, -511, 1169, -6092, 6161, + 3082, -664, -2037, 847, 11032, -1306, -1673, -1219, + -36, 1862, 10053, 780, -282, -837, -263, 509, + -588, -12646, -769, -2164, -2219, 524, -3433, -6437, + 3890, -623, -7509, 241, 4042, 264, -1394, 3646, + -6925, -5184, 1218, -1476, -2240, 1882, 182, -3450, + -497, -148, 160, -1579, -19545, -80, 886, 913, + 708, 728, 393, -603, -778, 3414, -778, -1495, + 1205, 2342, 232, -3634, -76, -16792, -684, 1322, + 192, -13248, -658, 7650, 4731, -169, 5148, -1413, + 3026, 2480, -2190, 1004, -2082, 237, 171, -717, + -766, -525, -11802, -3776, -9914, 1374, -3250, 415, + -2787, -175, -1081, 792, 980, 11464, 834, 714, + -993, 150, 77, 2306, 11249, -3058, -3418, -1758, + -239, -119, -1408, 6083, -4276, 1827, 1660, 2287, + -2997, -576, 400, 2062, -3174, -6215, 10026, -1082, + 41, 249, 10026, -6199, -301, 280, 10120, 2249, + 527, -564, 1002, 622, 3341, 408, 2870, 12902, + 13307, 689, 336, -819, -43, 832, -1242, 657, + -106, 42, 1123, 149, -2072, 78, -303, 329, + 21745, -2172, -1204, 448, 1437, -560, -376, 311, + -73, 153, -785, -368, 54, -445, -92, 120, + -59, -377, 402, 567, -25820, 1284, 1288, 200, + -865, -1286, -41, -1862, 402, 179, -2338, -3876, + 4992, -1824, -10092, -3407, -8516, -3556, 130, -5695, + 5846, 2333, 2995, 2110, -6946, 5049, -2377, 1655, + -859, -4737, 1648, 7031, -7344, 4992, 1760, -711, + 3134, 14363, -907, 171, -1971, -3062, -1079, 600, + 603, -224, -440, -11328, -291, -663, 1878, -715, + -2724, 284, -456, -10970, -3225, -2240, 252, -977, + -360, 729, -572, 3981, 1615, -52, -5372, 6095, + -9888, 6873, -3830, 4916, 1834, -1581, -11268, -2316, + -398, 1361, 6151, 2736, -1968, 4624, -180, -260, + -1221, -5633, -1300, -1081, -1433, -509, 366, -388, + 1660, 340, -18997, 694, -1184, -813, 1324, 1261, + 735, -186, 5258, -583, -221, 1707, 149, 1022, + -835, 1089, 2939, 2025, 421, 411, 3609, -13797, + 464, 9214, 2462, -6257, 6032, 1911, 1282, -9673, + 974, -703, -128, 950, 369, 1160, -674, -312, +-13858, 1078, -7606, 8, 2786, 367, -6441, -824, + -195, 714, 484, 108, 475, 289, -1012, -1591, +-10880, -324, -647, -2199, 10378, 5781, 995, -416, + 871, -1240, -380, 70, -1893, 7632, 1727, -908, + -672, -10901, -962, -7322, 794, 1748, -5568, 1215, + 5845, -9575, -2413, -2159, 3077, 1359, -416, 6277, + -85, 1352, -3498, 6130, 1125, -236, 1950, 8481, + 716, -560, -1311, -228, 250, -440, -5320, -1941, + -9710, 4637, 1420, -102, -8222, 616, -2254, -528, + 196, -1315, -749, -97, -285, -15880, 1105, 630, + 368, -809, 29, -1688, -2314, 745, -1627, 19840, + -2380, 4108, 1670, 2763, 275, 530, 492, -589 +}, + +.cb4448s0 = { +-10720, 9997, -1313, 8849, 5152, -226, -2908, 303, + -842, -870, 165, -1372, -105, -154, 170, 2424, + -2476, -2126, -8329, 349, -4509, 5128, -92, 9086, + -7263, 416, -124, 341, -88, 239, 5172, 553, + 1526, 1728, 1955, -1489, -6595, -11237, -10224, -394, + -927, -932, 674, 743, 317, 4628, 8453, -3768, + 2545, 3506, -2406, 9108, 5643, 4660, 4116, -2452, + -1391, -154, -74, 180, 5270, -7922, 46, 11046, + 6076, 735, 7922, -196, -1080, 1445, -687, -2403, + -784, 742, -269, -498, 6010, -4045, 1053, 891, + -1538, 613, -84, -4254, -957, 4682, -14004, 2050, + -647, -718, 557, -2720, 2437, -7675, 11874, -9284, + -734, 775, -2231, 105, 366, 1360, -98, -126, + 508, 2647, 729, 762, -8806, -10413, 9008, -2093, + 1107, 201, 1421, 1181, -259, 1420, 828, 327, + -1956, -573, -874, 354, 2662, -1437, 10864, -9240, + -7648, 1670, 1598, 173, 438, -373, -566, 246, +-11999, 1817, -611, 1, -1652, 1876, 1354, 1270, + -789, 300, -321, 11577, -516, 329, 5723, 4732, + 1717, -6224, -5356, -6292, -370, -3644, -922, -50, + -14, -581, -1554, -1675, -20, -965, 28479, 658, + -498, -488, 504, -601, 437, -585, -245, -196, + 186, 281, -174, 159, 7469, 5890, -5112, 4918, + -9023, -360, 40, -2975, 4784, -437, 1609, 1032, + 2759, -297, 106, 5176, -4315, 568, -9536, -1297, + -6783, -10965, 1285, 264, 330, -508, -522, 624, + 662, 539, 7248, -13780, 40, 2140, -2188, 1925, + -8972, 1147, -1340, 870, 779, -4, -101, -374, + 781, 5733, -5712, -5777, 2080, 875, 13450, -1551, + -3229, -1818, -114, 1265, 501, 636, -576, -623, + -1269, 3006, 1023, 862, 1359, 1950, 588, -22648, + 218, -438, 1547, -408, -844, -263, -106, 14754, + -689, -9466, -978, -21, 1412, 43, 2012, 352, + 908, 277, -960, -747, -230, -1557, -7132, -5707, + 79, -2474, 2177, -5349, 2510, -12720, 2833, -2152, + -1693, 458, 197, -643, 735, -2728, -893, 2758, + 5196, -3566, -4294, -4914, -1222, 188, -8884, -6234, + 2391, -1518, 663, 572, -1465, 1147, 8486, 2037, + 2516, 941, 6092, 11602, -2559, -1702, -1848, -924, + -210, -108, -1052, 8360, -7567, -4588, -169, 3464, + -9206, 1842, -4329, -2499, -341, 592, 918, -102, + 340, 214, 1037, -324, -16289, 10308, -47, -29, + 1340, -603, -2763, -548, 392, 1489, -149, -769, + -67, 13270, -2233, 8257, 1582, 1034, -4270, 916, + 4486, 1191, -102, 159, 109, -536, -664, -987, + -8041, -1759, 4264, -5600, -13815, -1158, 1712, 2516, + -634, 504, 515, 732, -46, -685, -481, 1685, + -1782, 262, -3600, 14721, 6334, 7941, 101, 914, + -2141, -2, 182, 829, -215, -122, 6325, -3752, + -2812, 1618, 3512, -1591, -4276, 6994, -10349, -5675, + -1501, -1766, -1949, 436, 82, -5596, 2592, -1086, + -2804, 2540, 458, -550, -1834, -2401, -7563, 2340, + 1678, -7666, 4538, 27, 6337, 3642, 17068, 5310, + 1115, 1579, -142, -397, -670, 2010, 863, -504, + 845, 848, 770, -8821, 1963, 2782, 162, 1130, + 2597, -13699, -3996, 800, 2499, -1045, -1512, -186, + -59, -119, -5048, 6800, -8766, 784, -7091, -1002, + 335, 1993, -1045, 601, 1804, 166, 1343, 110, + -224, 2247, -344, -5, -4292, 5846, 8591, -11846, + -1303, -1027, 1759, -168, -194, -1281, 489, 378, + -5069, -3321, 11238, -375, -806, 3962, 9660, -2960, + -664, -1067, -627, 271, 1205, 1160, 261, 3725, + 7877, -679, 22, 598, -1086, -420, 2168, -46, +-15552, 420, 1220, 1332, -58, -156, 7777, -4657, + 352, 15316, -4760, -2140, -2577, -1321, 2037, -371, + -1254, -912, -1177, -1367, -103, 4572, -9482, -1599, + 294, 403, -272, -2331, -4365, 13467, 4585, -2554, + -1743, 545, 162, -369, 6074, 11273, -8856, -8175, + 2543, -7, 314, -2033, 2704, -1755, -1431, -791, + -276, 1085, 236, 6553, 1872, 387, 1056, -31, +-20610, -609, 608, 1007, 1604, -1501, -68, -527, + 204, 252, 2533, -721, 1468, 444, -72, 61, + -209, 512, -216, 42, 385, -490, -104, -29030, + -166, -4883, -2754, 788, -430, -867, 565, -1155, + 562, 1076, 1757, -2990, -14971, 8392, 902, 550, + 102, -6579, -6939, -319, 172, -863, 979, 2178, + 630, 160, 952, 946, -3955, 1515, 352, 2557, + -5339, 6166, 4588, -2040, 4031, -535, -2504, 2782, +-12136, 1338, -2758, 458, -671, 155, 6998, -2598, + -931, -396, -922, 2060, 447, -42, -649, -532, + -552, -1945, -16548, 815, -408, 3469, -4118, 875, + -1017, -11150, -511, 3846, -11349, -1928, -781, 2765, + -681, -713, 655, -218, -8032, -465, 295, 1591, + -383, -1889, 1627, 108, 1149, 2513, 388, -5702, +-15693, 24, 470, -4322, 3721, 1584, 1808, 350, + -1765, -620, -2953, 4354, 8512, -12533, -86, -2490, + -192, -507, 2024, 3942, -801, 13444, 738, -2086, + 162, 2013, 837, 56, -384, 3164, 5052, 1158, + -403, -6913, -4290, -2068, 16622, -2738, 856, -2884, + -2432, -410, -1179, -456, 504, -1359, 436, 352, + -6351, 327, -2196, -1502, 302, 338, -839, 235, + -520, 1283, 2710, 18814, 2256, -2, 400, 1300, + -1185, 1024, -3744, -3542, -4350, -763, 1902, -14737, + 5437, 48, -1589, -280, -67, 232, 2276, 1413, + 3284, -308, 1013, 610, 22787, -685, 724, 12, + -359, -1651, -1060, 569, 248, 3836, 605, -413, + 3380, -1360, -1120, -2933, -2368, -977, 10135, 12356, + 3739, -1571, -418, 580, -2662, -11460, -6128, 2867, + 11468, 825, -3201, -501, -138, -755, -554, 168, + 757, -564, 428, -12118, -15179, -1978, 432, -597, + 1528, 3038, -568, 1349, -3377, 914, 498, 928, + -91, -5, 9192, 3000, 2542, -1411, 626, 2705, + -763, 3247, 13736, 3034, 2170, -67, -852, -378, + 1264, -2771, -2415, -4236, 126, -1984, -13336, -1088, + -416, -1979, -520, 2506, -1505, 294, -2398, 218, + -8740, -3873, 2069, -1374, 86, -998, -3851, 1070, + 13357, 955, 3085, -536, 166, 926, 299, 6532, + 1324, -502, -1658, 1829, -1263, 445, -1902, 1452, + -2747, -16422, 1875, 1773, 452, 288, 5992, 1626, + 3659, -917, 2255, -1508, 356, 547, 158, 9, + -117, -1665, -595, 14392, -1013, 49, -4060, 12064, + 3666, -2903, -9145, -396, -4341, -953, 2758, -178, + -204, -462, 98, 222, -3622, -12200, -4484, -94, + -8642, -5694, 4034, -720, -1695, 751, -1668, -266, + -343, 296, -112, -900, -3750, -360, 1002, -7402, + 7758, 7370, 3332, -7517, -769, -1272, 412, -1451, + -89, -227, -11332, -472, -1108, -394, -339, -1981, + -3494, 12110, -564, -5958, -690, -1066, -130, 762, + -50, -1456, -1521, -8428, 994, -867, 2650, -2335, + 354, -2253, 4612, -12364, -2626, 1853, 577, -103 +}, + +.cb4448s1 = { + 25901, -239, 648, 167, -284, 198, -340, -1112, + -55, -242, -214, 528, 112, -259, -284, -250, + 23, 475, 780, -558, 111, 148, -2411, -19826, + -1158, 2799, -964, 44, -1204, 1187, -4036, 1872, + 3541, 768, 159, 1979, 3382, -113, 804, -1021, + 3708, -2577, 9697, 11527, -326, -7058, 4306, 1260, + 3782, 3370, 1595, 705, 2268, 2182, 1509, 1131, + 9877, -7260, -258, 49, 1686, -1472, -2556, -1973, +-22425, 338, 486, 963, 1069, -34, -1027, -90, + -881, -473, 554, -6326, -873, -9744, 10157, -1079, + 584, -1047, -1954, 6204, 2416, -899, 1452, 938, + -439, -664, 4231, 9370, 7800, 170, 9448, -4756, + 1967, 686, -1186, 636, -1719, -1244, -540, -728, + 306, -1778, -7980, -3418, 8318, -1828, 1556, 3487, + 10195, 3741, -510, 2077, -1496, 1241, 384, 477, + -1051, 7922, -4077, -2513, 849, -693, -9170, 4264, + -7940, -1703, 460, -2986, 586, 13, 377, 781, + -7047, 6852, -1350, 7537, -493, -1919, 379, 3108, + 4293, 8467, -3875, 63, 44, 493, 1496, -1577, + -5676, 3318, 6628, 5177, -11082, 1146, 3251, -1159, + -461, 442, 1250, 212, 176, 3586, 137, -9153, +-13772, -8211, 393, 1170, 1717, -671, 298, -233, + 883, -1533, 401, 254, 7700, -4827, 794, 377, + -376, 12240, 7298, 2445, 1168, -562, 1528, 563, + 421, -606, 0, 5792, -1069, 824, 3728, -2729, + 1005, -730, 4318, 644, 17336, -1588, 2100, -365, + 509, -415, 3684, -9128, -1096, -4278, 1549, -1247, + 5519, 11075, -2216, 6004, -3683, 409, -730, -414, + -263, -6623, 8194, 489, -9085, 334, -1104, -814, + 1412, 1522, -1657, -7029, -4142, -1274, -520, -40, + 650, -1886, 9701, 11456, -7567, 1176, 3268, 3016, + 1109, -117, -858, -155, -1249, -230, -216, 3945, + 9142, -2297, 134, -2563, 15131, 857, -1597, -618, + 150, -590, -166, -357, 388, -69, -8767, 2914, + 1087, 4673, -14373, 600, 382, -1893, 844, -242, + 544, -106, 568, -1141, 371, 2663, -1860, -725, + 8066, -1353, -8743, -10433, -1796, 427, -73, 178, + 96, 980, -478, 978, 1767, 6034, 633, 966, + 677, -65, -884, 417, 461, 62, -868, 93, + -100, 519, 16304, 2646, -1260, 12271, -140, 142, + 11138, -892, -2114, -629, 172, 744, -2056, -960, + 61, -980, 2082, -439, -3126, -2564, 1174, -78, + 254, -178, 1599, -436, 19023, 5335, -1686, -782, + 520, -8727, 256, -3588, -5694, 12323, -2091, 1511, + -656, 3872, 2370, -770, 282, 455, -573, -39, + 7845, -12566, 12690, -156, -442, -227, 575, -274, + -1717, 120, -40, 1866, 635, 161, 270, 1039, + 3256, -673, -3343, 4292, -14247, 7142, -4821, -591, + -418, 376, 21, 572, 551, 70, -5536, 79, + 2540, -505, -283, -350, -1279, -1630, 2234, -604, + 5246, -17580, -3022, -1052, -307, 6626, 2794, 1702, + 1875, -1876, 1011, -320, 1268, -282, 1072, 14370, + -8206, 1218, 630, 173, 7486, 15176, -6146, 4903, + -636, -1341, 1360, -1541, -1012, -778, 84, 426, + -124, -746, -252, -11085, 1783, -2833, 809, -744, + 2194, 3328, 7029, -5097, 4934, -3025, -641, 303, + -328, 258, 8674, 53, -3395, 975, -9944, -8550, + 3376, -714, 1078, 1186, 598, 808, -166, -752, + 484, -5088, 1484, -1278, 11394, -1876, -8236, 5159, + -1830, -1520, 2761, 592, -204, -1360, 454, 230, + -5038, -1582, -5617, 1346, -2045, 2306, 17764, 494, + 572, -1930, 339, 550, 784, 151, -753, 4708, + -3058, -8267, 3281, -1054, 870, -1201, -2005, -920, +-10115, 5395, -6423, -798, 367, -221, -5296, -2808, + 8313, -5077, 1655, -200, 114, 46, 350, -2374, + 868, -327, 377, -9570, 1231, 9258, 8752, 3074, + -4411, -308, 2315, 6824, -3303, -896, -1186, 579, + -2561, 2280, 586, -798, 4747, -3487, 1306, -1241, + -487, -90, -52, 3231, -555, -17702, -2681, 1649, + -17, -278, -647, -4225, 2740, -1248, -3826, 1356, + 3572, -1010, 16160, -422, 304, 3970, 1124, -317, + -554, 673, -1191, 3180, -4429, 1581, 1543, -2097, + 4208, -9363, 10146, 1896, 2904, -4112, -1428, -207, + 459, -35, 5395, -8960, 3141, 11004, 308, 3687, + 1540, -2156, -592, 1640, 1003, -280, 797, 204, + 6910, -824, 4724, 4729, 5553, -3165, 483, -12, + 33, -588, -379, 402, 3543, -9646, 74, 9603, + -465, 2872, -2367, -885, 2894, -133, 2758, -721, + 3473, -13322, 1506, -1344, 512, 1066, -8300, 11391, + 11976, -1201, 13, -612, 165, -1823, 154, -123, + 1234, -423, -367, -58, 384, 2687, 2536, 826, + 6223, 1750, -8589, 1126, 9772, -6646, 2043, 1826, + -1037, -2018, 692, -818, -3431, -467, 11006, 3407, + 880, -2047, -10303, 6168, 1428, -307, -18, 661, + -252, 754, 1207, -2797, -3057, -6235, 99, -931, + 1618, 692, 2790, -294, -1200, -5768, -11691, -5305, + -100, 390, -783, -11660, -4675, -13570, 2764, 1414, + -786, 385, 163, 718, 794, 1118, 827, -634, + -75, 6224, 3965, -2092, -1120, -6395, 5474, -12986, + -3985, 635, -544, -1877, -191, 0, 121, 379, + -3059, 132, 26320, -721, 1262, -706, 421, -85, + -38, 665, 590, -208, -196, 168, 10, 1271, + -218, -365, -5843, -5897, -12346, -3026, 5916, -115, + -2671, -1022, -203, 962, 995, -850, 527, -516, + -1641, 452, 68, 1204, 740, 385, 38, 752, + 150, -3088, 20608, -54, -39, 6109, 3224, -92, + -315, 4407, -306, 1317, -395, -1617, 9104, -3493, +-10724, -3059, 283, 81, -9791, -3210, 7307, 4459, + -639, -61, 1152, -184, 2290, 398, -2902, -2776, + -1624, 1153, 242, -8865, -3617, 309, -11933, -3847, + -5750, 3235, -153, -315, 382, 209, -923, 2072, + 458, 164, 3631, 3121, 3220, -828, -8644, 2215, + 3873, 12445, 533, -631, -53, -136, -728, -240, + 420, 2870, -4981, 906, -3272, 4735, 3613, 2412, + -3951, -10587, 7389, 564, 3266, -1348, 524, 1570, + 6611, 3354, -1042, 1862, 1860, -1187, 5761, -1722, + 8231, -7428, -5662, 1239, -2887, -218, 810, -1063, + 15078, 686, -2374, -293, -2031, -245, 4441, 5045, + 1100, 6722, 1787, -587, -380, 132, 5124, -12478, + 95, -1230, 1464, -1871, 929, 1430, 2666, -3768, + 2784, -3697, -8238, -247, 603, -8406, 1330, 1033, + -743, -2546, 2739, 856, -12698, -4970, 2290, -1104, + 34, -1048, -80, 634, -695, -84, 2374, -24793, + -1064, -1080, -254, -812, 252, -1582, -401, 765, + 847, 340, 479, -3163, 150, -187, 8432, 2607, + 2075, 1384, 423, -7361, -10262, -2254, 54, 1065, + 40, 857, 2014, -5076, 198, 657, 482, -422, + -2185, -850, -318, 164, -684, 2698, -1008, 17493, + -64, -6788, -5966, -14352, -2349, 2492, 266, 1077, + 1935, -99, 4270, 2319, -2391, 779, 187, -70 +}, + +.cb4448m0 = { +-20455, 663, -3140, 2540, -2110, -406, 1078, 1968, + -741, -2458, 490, -496, 338, 581, 1079, -616, + 154, 10097, 231, -228, 477, 20, 1372, 11492, + -1112, -3148, 547, 248, -676, 8197, 5902, -1299, + 519, -2808, 11529, -76, 1239, -1032, -542, 353, + -1071, 278, 274, 2781, -7741, 3260, 2711, 175, + 12340, 1110, -2348, -5303, 1440, 581, -70, 262, + -9902, -2375, 530, 1433, 1624, -1475, -947, 13450, + 1318, -1696, 207, 198, 1162, -944, -9329, -1046, + 195, -106, 682, 14624, -854, -2410, 1054, 242, + -348, 581, 463, 716, 760, 2714, 1356, -1359, + 13089, 2565, -10523, 1934, 637, 1218, 1160, 830, + 905, 272, 408, -581, -1426, 613, 2586, -8186, + 3748, -6663, 4372, -114, -4644, 2998, -9440, 685, + -8741, 3363, -5623, -4229, -7058, -1201, -822, 1806, + 8671, -856, -612, 1165, -426, 317, 6867, -80, + -7084, 1143, -1862, 2742, 669, 550, 22, 173, + 4301, -10406, 1042, -346, -1334, -2897, 647, 744, + 14, -1338, -1648, -1235, 3550, -455, 2125, 1188, + 17136, 1188, -6782, -849, 298, -1054, -9254, 409, + -1736, 1410, -7254, -1889, 457, -740, 22, 262, + 32242, 1657, -2308, 2688, -607, 609, 4, 150, + -264, 192, -140, 246, -393, -76, -15050, 390, + 969, 457, 1436, -649, 460, -12150, 1359, 1014, + -2103, -576, 55, -590, 113, -1410, -23431, 182, + -2386, -1568, 904, -218, -281, -188, -178, 63, + 211, 549, 687, -12069, -88, -654, -1070, -13155, + -124, -697, 438, 3174, 1700, 270, 234, -289, + -625, 15749, -2340, 8466, 397, -4460, -1030, 3206, + 1081, -1317, -1030, -72, 487, -1477, -8782, 6984, + -1221, 2395, 3198, 2995, 5862, -1195, -6075, -1020, + -934, 868, -470, -1024, 1202, -998, -1306, 22118, + 344, 540, -3137, -547, 2440, -28, 222, 372, + -424, -199, 1068, -917, -105, -4278, 52, -299, + 6933, 11715, -520, -2853, 58, -8575, 416, -1272, + 1128, -32, -1140, -1873, -495, 235, 2079, -314, + -1328, -2615, -20194, 848, -1553, 387, -6091, 906, +-10180, 8634, -506, 4078, 318, -2657, 1612, -126, + -1424, -4, -1745, -343, 302, 2439, 12190, 941, +-12534, -4756, -176, -90, -1295, 1041, 1875, -450, + 89, 212, 2098, 1708, 1876, 4065, 1682, 1972, + -4916, -951, -10683, 1443, -10978, 772, -1013, -235, + 59, 213, -230, 142, -576, 506, 101, 44, + -137, 26238, -47, -322, -289, 281, 2614, -4538, + 634, 1116, 1191, 2985, -759, -5527, 550, 2107, + -6018, -11013, -425, -221, 901, 217, 546, 213, + 2026, 695, 1074, -2132, -173, -1664, -783, 25065, + -326, 86, -632, 1398, 4708, -2911, 2376, 135, + -1471, -904, -2338, 987, 3216, -4564, 314, 15692, + -214, 1238, 230, -181, -30537, -294, 155, -607, + 218, -309, -180, -246, -102, -988, -644, 111, +-10517, -1604, -1180, -2748, 1191, -12959, -2, -1004, + 28, -196, 1974, -790, 809, 8802, -1204, 332, + 180, -3857, 1025, -5998, -9578, 94, -1069, -2398, + 185, 643, -1479, 322, 2544, 12584, -8308, -3856, + 1286, 1600, -2539, -2752, -2520, -367, -942, 417, + -309, -2162, 2044, 10886, 1764, 11028, 3810, 2955, + -1028, -1017, -1752, -487, -605, 48, 2312, -368, + -1758, -252, 371, 19882, -1994, 1675, 5494, -660, + -1669, 256, -54, -941, 4318, -306, 2143, 273, + -3367, -3088, 6509, -1884, -5400, -576, 11394, 875, + 455, 271, -218, 1401, -44, -5336, -12170, 4664, + -589, -3562, -1934, 5842, 1357, 3232, 1449, -402, +-11228, -96, -1509, 2073, -1751, 776, -439, 775, + -3302, 13521, -325, -118, -172, 411, -396, 6154, + -2455, -52, -4616, 783, -12488, -2085, 5817, -1278, + 635, -1713, 2888, -830, 649, 7482, 10134, 9147, + 3784, 1046, -1934, -2580, 102, -679, -124, 68, + 657, 417, -175, -32768, -80, 375, -941, 224, + 271, -232, 1519, -99, -680, 67, 66, -618, + 252, 1907, 5121, 2456, -2117, -9388, -1441, 636, + 7868, -8340, 1939, 1340, 1511, 711, 6530, -1748, + -183, 90, 2561, 5860, -364, 5117, -4101, -4028, + -944, 10526, -1028, 1047, 707, 12116, -12596, -4006, + 922, -1047, 348, -971, -272, -2388, 435, 246, + -1055, 148, -1852, -12418, -2531, 3524, 4103, -344, + 1667, 2818, -4576, -273, -8337, 183, 497, -144, + -9845, -292, -503, -1212, 4316, -1434, -11058, -3043, + -5817, -981, 813, 0, -718, -467, 10285, -19005, + -82, 776, 1192, 1030, 1560, 1080, -144, 729, + 606, -225, -389, -187, 552, -930, -444, -5959, + -1960, -1315, 2650, -1282, -18790, 1772, 263, 1410, + 812, -458, -476, 744, 2595, -426, -19, 9119, + 4529, -1502, 4673, 3675, 7430, 1084, -6966, -518, +-13552, 1054, 2474, -9499, 1041, 5114, 442, 2927, + 511, -1492, 217, -726, 398, -522, 35, 119, + -332, 106, 816, 437, -1223, 27612, 521, -29, + -462, 367, -966, 476, -2559, -3485, -160, 1487, + -272, -586, -6014, -232, 3679, -1864, 1244, 575, +-14591, -483, -1428, 20, 7874, -2948, -5965, 2383, + 3270, 490, 2750, -547, -9658, -1473, 943, 285, + -2388, -772, -1582, 3181, 3419, 2628, -197, 3376, +-13282, -7684, 3383, 70, -1174, -70, -6703, -7305, + -553, 3588, -826, -12, 7350, -3604, 345, 1098, + 3856, 918, 2038, -39, 11514, 15798, 1327, 1158, + 436, -918, 71, 953, 975, 1147, 174, 411, + 1467, 83, -4536, -1511, 5350, -3314, 13999, 18, + 4107, 1901, 834, 2614, 2356, -369, 943, -341, + -460, 4380, -10014, 3308, -3541, -3225, -621, 8449, + -1383, 4481, -1399, -3646, -936, 923, 221, 346, + 7828, 2406, 3021, -4993, 3012, -10903, -1925, 8153, + 382, -1453, 1238, 601, 1195, -2245, -2792, -4118, + 473, 4898, 12961, -6094, 5905, 1368, -2754, -303, + 768, -31, -1275, 1400, 596, -1326, 619, -1744, + 1145, -3977, 639, -10785, -1693, -11192, -541, -434, +-11384, -1017, 14361, 1398, 521, -3239, 1851, -491, + 237, -1024, 1002, -3002, -303, -33, -6532, 601, + -3726, 7832, 6090, -10107, 957, -1149, 689, 1327, + -51, 1945, 990, -106, 595, 234, 518, 1060, + 77, 837, 28880, -91, -395, -275, -265, -279, + -217, -300, 240, -1055, -406, 4314, -2139, 6349, + -2227, -5996, 963, -10386, 4629, -560, 1080, 134 +}, + +.cb4448m1 = { + 31577, -1322, 1533, -2224, 253, -1485, -92, 294, + 183, -580, 420, 172, -794, -206, -342, -338, + 53, -85, -920, 29517, 1073, -972, -1839, 1004, + 290, 46, 460, -71, -988, 1731, -362, -2070, + 3848, -2, -3842, 734, -1221, -8012, 1104, 6782, + 9673, 1082, -8561, -860, -2135, -1557, -1613, -13999, + 1664, 2268, -1570, -732, 1010, -402, -1139, -428, + 400, 1123, -2108, -11776, -345, 10608, 1245, -3142, + -3244, -1132, 1700, -308, 1573, 543, 678, 5160, + -3062, 433, 2703, -852, -4903, -1880, 1706, 13995, + 2465, -4844, -904, -148, 350, -11168, 1406, 312, +-11900, 397, 769, 5558, -1354, 187, -30, 231, + -1020, 202, 884, -198, -3151, -830, -8490, -670, + -2767, 1517, -12957, -3861, -2794, -1854, -180, 135, + 7140, 4103, -4427, 450, 494, -1033, -1110, -2857, + 11056, -711, -800, 3628, -180, -852, -10300, -2120, + -450, 14464, -511, 303, -1464, -542, -89, -204, + 500, -400, -318, 569, 216, 428, 350, 1973, + -137, -885, -1794, -974, 3977, 3382, -18624, -420, + -1947, 165, -449, 1395, -17313, -286, 2054, -447, + -2740, -1881, -550, -2166, 1360, -6021, -94, 148, + 676, -1619, -1737, -11977, -169, -1664, -7709, 6202, + -5954, 1681, 715, -263, 56, 369, 589, 564, + 1989, 1617, -1648, 9205, 1343, -11508, -7379, -3791, + -3136, 1049, -844, 24, -6714, -1736, -5734, -2907, + 5016, 2167, -5722, -1210, 6232, 428, 2467, -3334, + -1477, -711, 6728, -10274, -4930, -6224, -349, -710, + 1598, -713, -1708, -497, -254, 567, -884, 131, + 11520, -908, -1425, -1862, -13449, -1590, -669, 657, + 505, 236, -4, 21, 846, 100, 8248, -1847, + -131, -186, 181, -806, 3293, -1072, -1208, 14492, + 1555, 1527, 544, -120, -258, 6, -2401, 12455, + 10880, 1091, -2350, -939, -1252, -564, 150, -114, + 1419, 737, -1732, -440, -2303, -226, 536, -2492, + -1085, -10117, -11013, 3786, 5275, -10, 2479, 143, + -1647, -7945, 884, -1618, 2056, 12890, -424, 5986, + -1471, -666, -570, -1466, -499, 64, 566, -1738, + -639, 11380, -612, 1879, 1550, 12469, -299, -1501, + 2634, 1036, 3020, -13, 14974, -2066, -5786, -2667, + 5487, -6768, 468, -385, 778, -805, -536, -304, + 718, 386, 285, 7546, 643, 1462, 913, 4707, + 941, -3338, -194, 6669, -4493, 8869, -837, 400, + -877, -11113, 326, -2318, 13683, -1304, -1966, -933, + 312, 128, 470, -296, -322, 340, -1126, 1811, + 1999, 2885, 3201, 331, -2494, 3999, 660, -80, + -2063, -16771, -1337, 426, 4884, -6026, -40, 2093, + 342, -176, 83, 134, 796, -425, -8934, 2100, + 8550, 160, -221, -252, -32714, 1306, 1332, -609, + -109, 547, 848, 518, -40, 303, -246, -451, + -2177, -716, -750, 1, -21232, 1287, -1303, 2051, + 1659, 1501, -369, -1415, 274, 308, 260, 371, + -1409, -662, -7347, 7161, 3656, -1104, 8862, -5671, + 1370, 1122, 16, 1132, 17593, 6778, -993, 613, + -665, 3004, 3288, -1625, -1823, -1003, 740, -1002, + -888, -677, -1065, -25294, 997, -160, -180, -811, + 188, -333, -2483, -696, 1309, 120, 456, -116, + -2020, -896, 7216, 6328, -9170, 8407, -2986, -1684, + 680, 1752, -684, 613, 337, -629, -11750, -493, + -324, -907, -391, 1053, 14125, 142, 420, -1917, + -378, -1428, -90, -497, 1116, -464, 2170, 805, + -1572, -904, -9020, -534, 6450, -490, 10750, 279, + 765, 961, -3985, -2702, 2423, -4981, -1222, 1654, + -1089, -2157, 1940, 14331, -895, 1726, 1555, 122, + -3552, 1274, -598, -910, 3056, -1704, 6430, -10626, + 1014, -8773, 1009, 1936, -360, -468, -1029, -8841, + -625, 2212, 2234, 2720, 1190, -64, -2078, 4688, + 8690, 5150, -450, 744, -796, -5661, -332, -7938, + 2670, -4054, 1377, -1594, 11554, -4702, -3631, 745, + 742, -90, -1311, 12528, -4664, 834, -853, 1542, + 8560, 2209, 4091, 2876, 2117, -678, 1684, 785, + 304, 7980, 2126, -302, 8239, -2105, 1584, 11894, + -1055, -1391, 596, 2343, 86, 388, -1348, -1007, + 1428, 413, -9231, -10312, -7346, -1108, 1385, -1255, + -3954, 738, -1258, 410, 226, 15115, -1059, -4117, + -50, -504, -1726, 1425, -9974, -346, 688, 464, + 244, -586, -8880, 845, -659, 932, -1309, 290, + -29, -417, -2184, 1011, -9622, 1443, 9009, 1945, + 2698, -708, 10572, 2410, 1200, 4492, -2569, 1444, + 2735, -8604, 2274, -4057, 478, -199, 1285, 12695, + 12321, -2933, -1708, 1198, 675, -492, -560, -52, + -1261, 85, -480, -96, 696, -764, -1402, -31368, + -580, -675, -1678, -58, 600, -522, -292, 647, + -36, 154, -1148, 437, 1561, 588, 603, 7629, +-16973, 29, -828, -589, -919, -1372, -470, -445, + 428, 528, 5828, -353, -32, -1781, -702, -690, + -7196, -3253, 1942, 4600, -12102, -674, -10480, -2336, + 711, -2174, -7474, -1436, -451, -7133, 856, -2652, + 1892, 3464, -546, 676, -13296, -516, -13618, -997, + 938, 1686, 1006, 1358, -1371, 922, 534, -170, + 126, 255, -835, 50, 945, -1066, -1676, 3, + 1038, -437, 26030, 418, 27, -1092, -493, -428, + -606, -1097, -628, 298, 295, -806, 183, 146, + 1352, -84, -722, 833, -25667, 3176, 1001, -322, + -2339, 15, -475, -1257, 2116, 876, 637, -529, + -1108, 302, -2452, 19734, 58, 851, 9845, 1142, + 2168, 706, 11070, 1556, 544, 3002, 2238, -3974, + 2738, -48, -8324, -2186, -355, -14933, 2192, -2481, + 2700, 473, -486, 761, -208, 76, -78, 102, + -4896, 1378, 12377, -8269, 28, 1092, -5071, -1500, + -1190, -804, 1085, -766, 493, 22, -1041, 9136, + -1234, -12247, 967, 2672, -883, 4582, 4871, 1891, + -532, 329, 226, 446, -6710, 312, -914, 1416, + -1852, 3052, 6512, 8971, 5544, 6519, -579, 1021, + -241, 911, 782, -3456, 10158, -1865, 3941, -12300, + 8, 472, 882, -1580, -1799, -1025, -631, -127, +-15316, 8047, -200, -1860, 582, -4363, -1274, 1085, + -48, 2383, 638, 480, 369, -838, -1341, 414, + -114, 2757, 1222, -2194, -3394, 6469, 2418, 738, + -1656, 15594, -1090, 202, 727, -769, 484, 2462, + 4875, 1656, -3835, -16877, 5276, 239, 982, -1872, + -130, 901, 1352, -155, 4939, -8317, 9000, 2503, + 485, 1184, -548, -1356, -7482, -188, -1587, 496 +}, + +.fcb08l = { + -2539, -3275, -2699, -3345, -2843, 5501, 426, 7127, + -149, 3111, -2991, -2297, -2345, 2702, -969, -946, + 2837, 1114, 1800, 1271, 12249, -2282, -2309, 1566, + -2889, -3020, -2083, 3586, 8919, 2651, 4111, -1842, + -1588, -1428, 3251, -102, 156, -320, 722, 1711, + 20565, -3068, -2211, -3164, -3410, -3396, -2882, -2002, + 1730, 4077, -2696, -1694, -2839, 2948, -2739, -2380, + -2252, -1311, -269, 1900, -2796, -444, -2996, -2525, + 5194, 1459, 5042, -1089, 914, 4116, 7644, -3137, + -3156, 4028, -3435, -3240, -2585, 5542, 5119, 9885, + -2995, -3153, -3449, -3101, -3551, -3469, -2196, -1271, + 3869, 5413, -2800, -1990, 3371, -2286, -1022, 3190, + -550, 1723, 968, 1916, -2749, -1530, -2211, -2987, + -3357, -3262, -1042, 10277, 107, 2662, 9819, -2753, + 4269, -3277, 3125, -3131, -2974, -3251, 6466, 9484, + -2034, -2707, -2424, -3170, -2619, -2278, -143, -1641, + 11856, 5975, -1282, -2629, -2396, -2364, -2012, -1085, + -2576, -2422, -2206, 13731, -2261, 2751, -1768, 2482, + -1065, -347, -137, 31, 619, 385, -2257, -2215, + -1698, -2686, 4468, -2563, -1071, -1359, 7757, 3732, + -2856, 9018, -2046, -1494, -2234, -2209, -67, 1340, + 2433, 2965, -2722, -2151, -2966, -2780, -2732, -1509, + -2085, -1532, 6934, -1248, -1936, -2203, -787, -1781, + -895, -1990, 4693, -1818, -1569, 1954, -2283, -2403, + 10514, -3105, -1074, -2838, -1, 1192, 1113, 3309, + -2249, -2451, -1660, 2535, -1439, 3582, -1093, -594, + 1956, 758, 5349, -2524, -2320, -1903, -2055, 5075, + -941, -721, -536, 2197, -2309, -3027, -1460, -2911, + 11344, -2474, -1601, -1749, 3260, 2547, 3819, -1247, + -1449, 2835, -1118, -652, -516, -379, 531, 440, + -569, -2606, -2545, -2447, -1685, 8678, -1868, -2003, + -992, 5888, 8591, -1848, -2010, -2196, -2049, -658, + 3473, 214, 905, 317, -2050, -1083, -2593, 8754, + -2234, -2449, -1688, 2194, 2244, 2502, -1659, -2748, + 4584, -3011, 3702, -2307, -1887, -1960, -1068, 2889, + -3022, -2989, -2295, -2794, 3071, -1588, -43, 2627, + 1278, 2031, -2145, -2551, -2333, -3205, -3237, -2760, + 9082, -454, 4339, 1776, -2738, 4785, -2176, -1896, + 2148, 1350, 768, 249, 1001, 1499, 797, -2182, + -1443, -229, -32, 827, 401, 270, 581, 380, + -2370, -2376, -2679, -3099, -1742, -1149, 4666, -693, + 1109, 7547, -2496, -3063, -2818, -2621, -2016, 5722, + 4932, 1217, 2161, 2449, -2207, -2954, 3769, -2824, + -1809, -2946, -1693, -377, 1565, 4100, -2947, 3063, + -3062, -2919, -3093, -2520, -1712, 2383, 1305, 1867, + 10145, -2912, -3307, 7519, -3502, -1063, -2782, 8595, + -750, -1503, -3141, -2486, 2923, -2574, -1826, -1244, + 3537, 2494, 2583, 1560, -2722, 3284, 2245, -1258, + -658, -394, 483, 719, 1121, 1073, -2949, -1013, + -3048, 597, -3103, -2510, -1970, 7207, 8635, 1917, + -1772, -483, -2318, -1860, -2500, 2981, -1651, 550, + 696, 615, -2121, -2055, -1619, -2126, 3108, 3417, + -485, -47, 848, 1608, -2636, -1707, 3142, 3798, + 479, -1112, 597, -323, 1555, 1531, -2930, 2106, + -2398, -2314, -1835, 0, 2920, 896, 2356, 1259, + -2911, -3184, 593, -3570, -3389, -3263, 7340, 7640, + 6874, 6549, -1912, -1334, -1749, -568, -1718, -405, + -1375, 3456, -1024, -1903, 9384, -2721, -2485, -2377, + -3026, -899, -3133, -3032, -2452, 7715, 2492, -2450, + -1721, -2138, -1497, -55, 760, 2382, 1183, 1105, + -2782, 389, -1528, -927, 664, -531, 1405, 363, + 582, -292, -1678, -2718, -2763, -3140, -2799, -2178, + -2715, -2592, -972, -1226, 3278, -1173, 2916, -1548, + -446, -1241, -209, 379, 689, 538, 3110, 2857, + -1735, -1244, -589, -413, 65, 471, 522, 323, + -2043, -212, 1309, -471, -564, -16, 378, -320, + -437, 228, -2194, -2637, -2513, -2670, -1863, -954, + -2082, -2398, -2270, 5563, -2959, -2444, -2794, -1736, + -1631, -1324, 1482, -481, 2317, 1470, -2871, -2007, + 702, -1980, -491, -146, -695, -145, 2817, 1268, + -3395, -3456, -3069, -3433, -2874, -205, 806, 3038, + 3806, 2623, -2954, -1861, -712, 1017, -326, 44, + -93, 910, 775, 346, -2625, -2570, -2974, -2344, + -2712, -1930, -2213, 3521, -1341, 4327, -141, 835, + -1119, -1336, -1092, -1891, -860, -727, 315, 2562, + 4119, -2638, -2584, -1951, -2710, -2499, -1561, -952, + 2821, 2505, -2388, -1855, -2926, 1742, -2563, -2655, + -1802, 3082, 3063, 2456, -3304, -2670, -2147, -1504, + -309, 1421, 1661, 1546, 560, 615, -2590, -1593, + -1523, 2025, 3167, -841, -356, -648, 309, 1165 +}, + +.fcb08m = { + -2962, -2140, -2166, -1454, -1638, -1100, -835, 686, + 978, 550, -1630, -1021, -1424, -1867, -1118, -474, + 66, 6104, 904, 603, -829, -475, -1368, -1199, + 7255, -890, -465, 114, 118, 224, -2453, -1279, + 8192, -1289, -452, -47, 180, 324, 627, 209, + -2770, 11214, -857, -1720, -895, -531, -291, -264, + 232, -402, -2699, -2561, -2433, -2093, -1315, 86, + 2666, 1663, 1351, 2349, -2788, 4576, 3680, -1365, + -995, -513, 46, 44, 522, 142, -2739, -1654, + -1950, 4573, -659, -536, 285, 72, 875, 627, + 3142, 105, -941, 1245, -489, -495, -229, 44, + -236, -1083, -2336, -1193, -1620, -1859, -1339, -655, + 205, 1032, 5581, 1195, -2635, -1740, 2656, 1976, + -52, 784, -96, -165, 419, -486, 8850, -624, + -792, -1531, -765, -674, -730, -829, -150, -27, + 2255, -1177, 2727, -1430, 737, -902, -780, -729, + 169, 278, 3729, 3763, -32, -1581, -563, -573, + 77, -372, -64, -477, -2500, 526, -1682, 1464, + -830, -124, -548, 561, 202, 1115, -1682, -1552, + -2014, -2127, -1374, -749, -720, 64, 2097, 6944, + -2771, 4929, -1680, -2212, -1430, -801, 114, 891, + 1176, 855, 3571, -2187, -1566, -1694, 84, -46, + 932, 786, 765, 856, -1038, -498, -117, -1582, + -1379, -1162, 6293, -367, 594, 132, -2487, 2119, + -2153, -1749, 833, 1089, 507, 133, 337, 423, + -2777, 2507, 277, -1455, -1019, 1811, 639, -595, + 136, -1050, -2941, 4474, -176, 1095, 1113, -479, + 182, -295, -229, -605, -2035, -1649, -1171, 51, + 0, 125, 2844, -310, -82, -640, -2251, -2138, + -2270, -1567, 2260, 92, 368, 95, 1433, 1346, + 820, -2339, -1822, -895, -69, 158, 190, 911, + 1008, 764, 684, -1756, -1013, -1625, -1610, 6062, + -499, -1036, -139, 1129, 488, 524, -665, -870, + -347, -76, 123, 91, -12, 14, -2867, -2019, + 2858, -1903, -1165, 309, 287, 1250, 767, 776, + -2784, -2446, -1157, 460, 2589, 437, -285, 711, + -299, 402, -2683, -2271, -1714, -1535, -547, 4118, + 510, 1158, 700, 631, -2084, -1236, 509, -1009, + -510, -193, -1075, -793, 727, 2150, -2722, 968, + 1077, -1579, -1410, -894, 401, 1043, 427, 182 +}, + +.fcb08s = { + -2368, -2340, -1735, -1897, -1493, 984, 3062, 2826, + 1049, 164, 1181, -1990, -1833, -1720, -1360, 24, + 1485, 1923, 460, 511, 69, 78, -353, -3, + 3761, -480, -1538, -1063, 540, -64, -1546, -988, + 1514, -1167, -1354, -563, 1435, 880, 1123, 182, + -2243, -2109, -2378, -2201, -1491, -836, -124, 605, + 6159, 3636, -2770, -2959, -2956, -3019, -2154, -648, + 1805, 4698, 2929, 2078, -975, -360, -895, -623, + -593, -879, -345, 4333, 492, -56, -2102, -781, + -476, 1268, 606, -670, 1686, -105, 370, 461, + -221, -868, -1381, 297, 128, -578, -809, -938, + 3896, 490, 4032, 2675, -684, -1108, -1235, -915, + -874, -919, -802, -1040, -1324, -16, 2156, 1943, + -652, -666, -47, -1499, 168, -210, 4213, -1895, + -1734, -1767, -1412, -867, -71, 329, 855, 1294, + -1849, 4393, -1312, -1597, -564, 434, -454, 269, + 892, -31, -1170, 67, 370, -1144, -320, 3706, + -811, -190, -123, -166, -659, -1033, -789, -902, + -347, -280, -108, -313, 452, 3701, -1505, -2610, + -2758, -2550, -2034, -1361, -676, 713, 2263, 8286, + -2241, -2508, -2540, -1721, 182, 1947, 306, 1773, + 1220, 2909, -60, 73, -235, -1631, -1302, -692, + 4171, -830, 49, -188, -471, -2208, -2265, -1518, + -196, 2995, 2571, -579, -68, 805, -1294, 1274, + 4294, -1356, -702, -532, -465, -123, -400, -719, + 336, 3093, 1634, -906, -71, -502, -938, -982, + -742, -1187, -1757, 2890, -1591, 1303, 216, -311, + -404, -29, 501, -543, -1466, 1587, 309, -578, + -173, 34, 1116, 1286, -1184, -1174, -175, -732, + -619, 3508, -80, 191, -1059, -174, -429, -470, + 10000, -933, -1511, -1601, -1571, -1445, -1065, -1407, + -1053, -932, 1183, 7875, -460, -1609, -1618, -1398, + -1154, -1227, -1012, -1450, 20, 28, -235, -110, + 203, 105, 252, -154, -51, -58, 2940, -490, + 17, -51, 131, -106, -526, -566, -822, -1177, + -1335, 2749, 608, -1575, -1322, -1351, 111, 641, + 1441, -9, 733, -207, -273, -665, -630, -588, + -78, 254, 304, 762, -2661, -2677, -1238, -82, + 2569, 3001, 932, -1032, 211, -324, 40, 1395, + -836, -1119, -635, -1425, -1514, -1135, 1509, 2963 +}, + +.fcb11l = { + -3004, -2927, -2672, -2356, -735, 179, 950, 1734, + 1101, 1641, -1610, -1161, -1606, -179, -1634, 3383, + -610, 240, 73, 1128, 818, -1052, -1641, 724, + -1938, -1741, -1211, 3967, 1988, 1445, 3010, 2203, + -1685, -1698, -1838, -759, -144, 515, 999, 1215, + 3239, -1912, -2048, -1739, -1488, -148, 1590, 1370, + 1066, 1270, -2721, -1637, 99, -1964, 224, -946, + -1437, -954, 755, 1420, -2800, -2211, -2304, -2048, + 4853, -714, -383, 2159, 1823, 2328, -1619, -1584, + -1839, 5462, -1703, -802, -227, 485, 1017, 1695, + -2459, 2399, -1820, 2254, -1373, -767, 53, 705, + 1074, 1293, -1582, -2486, -2208, -2341, -2264, -2132, + -1578, -1043, 322, 7685, -2198, -1768, -2106, 16, + -2207, -1495, -1106, -961, -482, 1642, 6785, -1540, + -1540, -1449, -1177, -854, -307, 853, 1279, 1449, + 3253, -1427, 2314, -1473, -985, -1025, -321, 923, + 1140, 1166, -2704, 2664, -2444, -2717, 481, 3083, + -1449, 1225, 3168, 2389, -2124, -1981, -1342, -1939, + -1904, 4736, -885, -826, 3866, 2046, -290, -567, + -1986, -1880, 1966, -465, 1638, 683, 1005, 1099, + -2842, -2537, -2559, -2427, -1243, 4039, 1371, 3897, + 2529, 2400, -2586, -1328, 785, -1697, 1733, 2382, + -442, 190, 901, 1281, -2669, 2198, -1502, -1404, + 2593, -694, -186, 466, 1065, 1199, -1905, -1389, + 6171, -1817, -513, -989, -356, 246, 1619, 1883, + 36, -2178, -1602, 608, -1523, 23, 1265, 578, + 953, 1038, -483, -2278, -2138, -1740, 584, 244, + -54, -192, 915, 1097, -213, -1569, 1861, -1401, + 3686, -1625, -1234, -614, 860, 1311, -1397, 2315, + 1896, -1608, -1326, -1487, -99, 2241, 697, 1156, + 1711, -2099, -1507, -135, 1422, -695, -57, 1390, + 823, 937, -122, 479, 47, -2144, -1514, 955, + -1317, -726, 480, 1153, -2959, -2558, -2573, -1355, + -1879, -1446, 6435, 677, 3124, 3134, 1850, 1834, + -1396, -1417, 1290, -896, -561, 1428, 1007, 1105, + -2101, -2044, 1779, -1913, -1868, 1410, 916, 1232, + 1112, 1335, -2663, -104, -513, -96, -470, 480, + 1516, -150, 298, 714, -2558, 3076, 468, -745, + -945, -443, -849, -989, 341, 1102, 433, 588, + -1772, 462, -527, 670, -128, -108, 583, 701, + -2281, -2149, -2398, -2749, -2557, -1691, -1095, 1336, + 9088, 3844, -1799, -1861, -1908, -2242, -2184, 2313, + 3779, -809, 519, 2229, -1914, -1673, 1764, -634, + -1955, -1721, 405, -499, 243, 1632, -2377, 7289, + -1659, -1752, -1341, -948, -323, 841, 1703, 1774, + -2029, 2384, -1877, -1918, -1729, 1483, 483, 1916, + 576, 1258, -2310, -1796, 2208, -1579, 57, -1735, + -1161, 5177, 1674, 2468, -1907, -1499, 1868, 2275, + -620, -356, -228, 489, 1064, 849, -683, -1204, + -1761, -2211, -606, -764, -1056, 3888, 253, 1518, + -2555, -2075, 119, -1567, 971, -1178, 2683, 1476, + 978, 1419, -2947, -2418, -2164, 1178, 1582, 1470, + 896, 645, 1671, 1462, -2234, -1363, -1184, 1408, + 1042, -1091, -208, -49, 527, 917, 1266, -1444, + -2174, -2447, -2300, -1732, 3076, 5631, 248, 2195, + -2477, -1724, -2434, -2477, -2524, -1828, 2331, 845, + 1423, 1767, -2393, -1946, -857, -462, 344, 17, + -896, 2391, 892, 882, -828, -280, -752, -1136, + -1563, -1040, 1222, -1173, 1763, 1179, -1448, 1946, + -1815, -1588, -1638, -1282, 3302, 132, 509, 1408, + -2760, -2338, -1935, 1353, -1531, -1074, 1156, 3086, + 1374, 1667, 2302, -1623, -1897, -1991, -494, 2603, + -754, 524, 1265, 1304, 3062, -1359, -1365, 1987, + -1334, -916, -146, -40, 635, 1033, 1724, -1057, + 49, -1159, -774, 106, 1053, -153, 134, 691, + -119, -1226, 332, -363, -197, -69, -133, 573, + 190, 216, -2236, -294, 1288, -2110, -1537, -1005, + -1175, 56, 4227, 1623, -2440, -1894, -1623, -2377, + 2287, -1220, -1506, 177, 5689, 2849, -2857, -2166, + -2546, 2174, -2414, -2343, 559, -1020, 4650, 3514, + -2875, 1309, -2557, -2534, -2235, -1901, 1559, 4412, + 2301, 2204, -2969, -2018, -2399, -2834, -2431, 1316, + -1474, 1269, 2533, 3485, -2892, -2387, -2716, -2317, + -2031, -1992, -1311, 8071, 3933, 3807, -2139, 1909, + -2200, -2344, -2060, -1638, -1154, -210, 2781, 2139, + 1119, -1828, -2069, -2306, -1975, -1165, -444, 789, + 2409, 1551, -2929, -103, -1920, -2010, -904, 694, + -188, 4, 1051, 1190, -2649, -2454, -2205, -1651, + -1856, -1552, -1165, 352, 3351, 1266, -1719, 57, + -1828, -420, -938, -1251, -461, 1294, 1158, 893 +}, + +.fcb11m = { + -2704, -2459, -2349, -1535, 2807, 365, 1064, 892, + 830, 1222, -2190, -1542, -2285, 6443, -1607, -1362, + -605, 637, 883, 877, -2378, 2292, 3106, -1057, + 1776, -1094, -859, 249, 199, 256, -1537, 2098, + -1126, 2243, -1186, -193, -211, 211, 502, 308, + 3369, 3197, -1271, -1370, -355, -423, -537, 468, + -237, -99, -1439, -1748, -2185, -1972, -1357, -814, + -470, 815, 1306, 6390, 1983, -1169, -1749, -29, + -1368, 5929, -1539, -900, 576, 701, 1708, -1608, + -1148, 3522, -822, -120, -461, -158, -43, 39, + -2543, 8872, -1347, -1580, 222, -488, -162, 295, + 382, 291, 11143, -1223, -1270, -1399, -392, -563, + -500, -604, -544, -135, -1787, -1313, -1490, -1395, + -1100, -1278, -818, 6172, 768, 1597, -623, -681, + -1128, -1575, 7257, -665, -1021, -439, 932, 703, + -1496, -2168, -1945, -1454, -808, -1261, -354, 875, + 6706, 1956, -1773, -1503, -1536, -1162, -1386, -1885, + -1607, -318, -72, -7, -1932, -1349, 6150, -1852, + -345, -18, -81, 223, 339, 425, 362, -1623, + -1432, -1973, -1042, -1373, 7830, 38, -116, 1000, + 421, -2375, -1808, -1832, -1046, 2077, 955, 1576, + 581, 824, -2021, -1582, -1402, -1420, 69, 3549, + -513, 192, 262, 483, -2503, 4173, -11, -1532, + -893, 282, 187, 320, 176, 259, -2308, 2342, + -2385, -2147, -784, -375, 413, 833, 889, 1297, + 1415, -1085, -1009, -1501, -1246, -1298, 1553, 1384, + 332, 662, 2226, -2399, -1752, -857, 1899, 131, + 501, 209, 217, 346, 4294, -1811, -1694, -1080, + -752, -263, -228, 249, 628, 971, 2508, -1031, + 2871, -1054, 42, -202, -738, -170, -239, -290, + -2751, -2379, -2379, -1999, -1448, -380, 1594, 1279, + 1399, 1633, -2376, -1839, 1367, 1685, 356, -126, + -50, 143, 31, 33, 314, 160, -663, -687, + 25, 388, -267, -188, -188, -129, -2614, 1063, + -1835, -285, 2549, 205, -30, 370, 319, 297, + -87, -2208, -1164, -839, 894, -266, -410, 375, + 1263, 924, -2606, -2325, -1854, 1792, 407, 328, + -110, 575, 1090, 971, -2517, -1583, 1355, -1892, + -490, -203, 846, 724, 597, 779, -1650, -1281, + -1294, 549, -146, -548, 2947, -28, 265, 339 +}, + +.fcb11s = { + -1536, -2360, -2378, -2138, -1380, -346, 1575, 2779, + 3247, 1689, -340, -1788, -1839, 103, 31, 853, + -653, 3159, 365, 154, 404, -835, -716, -35, + 4309, -155, -1214, -1180, -750, -522, -753, 350, + -1660, -1603, -1159, -582, -489, 1067, 2615, 1747, + -1755, -2351, -2314, -1453, 922, 3458, 867, 439, + 493, 1212, -1584, -1655, 1300, 1783, 1641, 1442, + 816, -1283, -1456, -1417, 4998, 1923, -200, -1086, + -1060, -1016, -1074, -1217, -1285, -1245, 633, 390, + -1443, -1099, -507, 3041, 343, -163, -745, -667, + 2333, -2144, -2460, -2247, -2063, -1736, -742, 418, + 3124, 3504, 227, -735, 799, -1326, -20, -543, + 1900, 237, -671, -545, -1727, 121, -1750, 3700, + -485, -553, -77, -212, 942, 62, 1647, -688, + -1506, -1429, -619, -839, 172, 3209, -500, -371, + -1680, -1408, -1122, -563, 3627, -115, 510, 534, + -65, 199, 800, 5040, 631, -744, -612, -1023, + -1099, -1319, -1520, -1460, -1120, -274, -1220, 349, + 1848, -620, -1411, -616, 1771, 1024, -1223, -2195, + -2345, -2144, -1517, -1055, -385, 557, 1482, 6797, + -2274, 818, -460, -707, -274, 646, 654, 731, + 268, 347, 4583, -1289, -1452, -1193, -1072, -681, + -178, -131, -108, 547, -1521, -781, -1298, 239, + -486, -445, 3453, -226, 90, 653, -1237, 624, + 4692, -482, -798, -799, -766, -645, -890, -915, + 3748, -909, -1012, 85, 963, 375, -100, -1010, + -1269, -1508, 2106, -1194, 2632, 595, -826, -221, + -411, -1104, -1365, -1050, -2112, -863, 1943, -727, + -1079, -733, 78, 1990, 363, 953, 1325, 459, + -891, 3364, -410, -362, -547, -994, -1371, -1258, + 12270, -43, -1668, -1868, -2004, -2133, -1863, -1949, + -1805, -1288, -1640, 3783, -1414, -578, -505, -464, + -158, 252, 71, 76, 22, -20, -72, -13, + -19, -95, -14, 2, 23, -5, 1289, 630, + 291, -707, -794, -857, -715, -122, 551, 219, + -2358, -1905, -1397, 277, 572, 343, 789, 526, + 1629, 991, -980, 222, 740, 1199, 19, 1200, + -864, -467, -656, -138, 820, -2005, -924, 154, + 195, 393, 267, -183, 1024, 100, 1243, -872, + -705, -781, -422, -377, -910, -637, 89, 2849 +}, + +.fcb16l = { + -2676, -2246, -3119, -2904, -2707, -1946, 7718, 2292, + 2451, 4206, -1214, -362, 1116, -860, 30, -993, + -888, -1046, -3732, -2268, -2541, 6060, -2220, -1597, + -1650, -1320, 88, 1229, 2118, 2348, 1430, -1865, + -2190, -2122, -1844, -2069, -1746, 15, -1746, 1321, + -2671, -2993, -3247, -2811, -2141, -1360, 1886, 270, + -381, 5676, -2070, -444, -674, -1082, -1144, -346, + -823, 4630, -224, 1940, -2441, -2072, -2194, -295, + 2175, 1209, -734, 168, 923, 1359, -2667, 389, + -2585, -2279, -2195, -1141, -1016, -218, 109, 1926, + 5184, -2226, -1888, -1273, -1044, 25, 461, 886, + 1125, 1249, -2215, -2381, 3109, -1963, 3015, -2027, + -790, 1192, 1646, 2188, -2906, -2598, 484, -2372, + -1372, -1082, 1718, 664, 1391, 2396, -2518, 1937, + -2362, -2510, -1504, 2947, 446, 684, 1947, 2059, + -3263, -3001, -3240, -3034, -2598, 3367, 4407, 2327, + 2450, 2994, -2379, -1875, -1862, 6387, -1956, -1417, + -525, 1098, 1836, 2932, 1408, -1130, -1417, 1693, + -262, -645, -515, 443, 735, 619, -2834, -2246, + -2646, -2521, -811, 6608, -421, 1572, 2015, 3234, + -2086, -1435, 89, 1648, 838, -986, -1159, -1208, + -32, 1354, -2135, -2159, 7796, -2424, -949, -2040, + -1179, 228, 1187, 3008, -2963, -2500, -2074, -2025, + -1439, 1692, -378, -596, -62, 2419, -3522, -3132, + -2899, -3290, -2929, 2844, 49, 4307, 2754, 3897, + -2960, 1305, -1858, -831, -1379, -773, 3257, 979, + 975, 1513, -2849, -1610, 2483, 456, -1395, -634, + 847, 1320, 1116, 1175, 2497, -1554, 2176, -1697, + -997, -799, -120, 339, 996, 1379, 11359, -1557, + -2219, -2237, -1792, -2084, -1009, 781, 3341, 939, + 1954, -1860, -2347, -2117, -2000, -1394, 3825, 106, + 2595, 2162, -2938, -2488, -2112, 772, -1059, 1822, + 159, 1017, 2452, 1506, 1313, -2615, -2479, -2941, + -2220, -2510, -726, 4703, 1778, 3375, -3133, -2664, + -2821, -2771, 1559, -1000, -434, 1874, 4130, 2987, + -2998, -2692, -2326, 1580, -2231, -1347, 4166, 2021, + 1177, 2531, -2880, -2337, -2589, 1505, -2843, -2468, + -339, -1059, 3212, 4264, -3112, -2885, -2889, 975, + -2522, -2278, 721, 5057, 3989, 3373, -3098, -2947, + -1128, -2251, 1935, 2981, 3007, 975, 1983, 2048, + -2861, -2302, -2431, -1460, -1492, -1524, -944, 1556, + 1778, 1549, -2658, -2259, 2768, -2460, -1447, 2957, + 759, 324, 2533, 2477, -2935, -1687, -2554, -2647, + -1431, 118, -365, 10280, 1526, 3447, -2570, 2268, + -2351, -2115, 2588, -9, -834, 1115, 1878, 2365, + 79, 1132, -1619, -1406, -1568, -1766, -224, 825, + 2113, 1382, -548, -2669, -1797, -2691, -2139, -2495, + -210, 1276, 13623, 2315, 1965, -1713, -1610, -2187, + 2534, -1495, -1301, 622, 563, 2154, 2743, 3230, + -1784, -1774, -792, -493, -131, 156, 944, 1211, + -1886, 357, -1018, 225, -285, 1025, -134, 218, + 290, 153, 5869, -2407, -2856, -3051, -2540, -3238, + -2260, -370, -451, 6314, -500, -2554, -2110, -879, + -323, -537, 570, 1228, 1556, 1342, -2486, 3366, + 1838, -937, -959, -683, 63, 937, 652, 1212, + -2164, -1448, 166, -799, -550, -1317, 481, 299, + 5494, 1360, -3147, -2574, -989, 1550, 1952, -1502, + -96, 3517, 1304, 2311, -2931, -2146, -2174, -2052, + 579, 680, 896, 2697, 703, 1365, 4130, -2367, + -2627, -3125, -934, -3093, -2155, -955, 6025, 5024, + -3121, -3064, -2883, -2458, 1723, -842, 3032, 4391, + 2327, 2837, -2536, -2208, -1610, -2189, 6509, -1424, + -1116, 1427, 2830, 3370, 1084, -1562, -1655, -1628, + -491, 2260, -321, 421, 774, 1237, -3267, 977, + -3170, -3144, -2698, -1324, 1424, 3034, 3323, 3347, + -3021, -3061, 2027, -2345, 852, -2832, -1714, 5926, + 4517, 3839, -1490, -2416, -1726, -1268, -1458, -2137, + -1715, -580, 1403, 13408, -3005, -2706, -3063, -2745, + -2777, -2136, 2786, 202, 5141, 3407, -3104, -3001, + -3176, -3388, -3507, -2863, -2097, 2325, 2618, 6146, + -1997, -3152, -1036, -2694, -2587, -2986, -2750, -2219, + -1607, 5944, -2893, -2633, -2229, -2811, -2482, -2115, + -2219, -1180, 5246, 3252, -3111, -2052, -2693, -2934, + -1805, 2583, 353, 1262, 8588, 3900, -2468, -2726, + -1861, -2352, -2237, -2750, -2345, -1936, 9793, 8392, + -3490, -3124, -3596, -3630, -3154, -2390, 743, 6652, + 6366, 6143, -2852, -3547, -3124, -2718, -1094, -494, + 49, -1053, -3005, 32767, -1721, -1229, -1715, -1590, + 1587, -1233, 3384, -252, 312, 1120, -3287, -2926, + -3048, -2828, -2502, -1185, 2028, 3778, 487, 2083 +}, + +.fcb16m = { + 616, -1065, -1622, -1949, -1283, -863, 6819, 517, + 1135, 1282, 2631, -1447, -1477, -1004, 286, 1358, + -135, -340, 147, -130, 5435, -1609, -1916, -1758, + -1066, -1126, 478, 995, 1098, 1437, -1737, -1339, + -1864, -2009, -1038, -1004, -573, 810, 5974, 2840, + 349, -1559, -1496, -1151, -307, -82, 681, 827, + 550, 776, 1930, 166, -1100, -1489, -1185, -1182, + -1210, -326, 858, 1688, -2561, 3514, -736, 1555, + -59, -906, -123, 87, 102, 274, 1902, -459, + 3008, -984, -707, -334, -571, -317, -190, -371, + -2862, 607, 1346, -1517, -1220, -617, 2494, 697, + 190, 64, 3264, 3926, -1249, -1542, -933, -302, + -246, -248, 69, -283, -1766, -750, -1898, -1259, + 6841, -1546, -785, -64, 1208, 1294, -1522, -1742, + -1873, -1898, -1455, 7128, -752, 1718, 1398, 1123, + -2742, 4733, -1552, -2483, -2210, -495, 355, 864, + 830, 759, -2721, -2115, -1891, -1696, -1137, -1559, + -1265, -658, -591, 850, -699, 1262, -551, -1055, + 877, 96, -388, -192, -479, -1091, -2763, -1379, + 3290, 2331, -874, -307, -386, 615, 366, 133, + -2671, 5181, 4339, -894, -871, -634, -165, 409, + 91, -291, -2649, -411, 8039, -1947, -1156, 57, + 351, 1014, 472, -198, -1816, -590, 2887, -1702, + -1113, 3414, -556, 117, 483, -377, -1707, -1146, + -1155, 2518, 2014, -382, 3, -6, 206, -98, + 10770, 274, -1415, -1670, -1020, -1036, -786, -782, + -463, -552, -2500, 10460, -1624, -1787, -707, -1327, + -59, 375, 91, 22, -2776, -2343, -2104, 825, + -759, -823, 482, 1149, 1265, 570, -1676, -1826, + -1848, 6125, -1391, -820, -449, 844, 586, 535, + -2873, -2475, -2607, -2611, -1830, -487, 1643, 1680, + 2088, 2570, -2357, -993, 3189, -1473, 3506, -1203, + -793, 662, 464, 98, -2507, 1617, -1793, -1935, + -1307, -169, 9, 885, 728, 1178, -2010, -1346, + -1375, -187, -548, 2753, -464, -105, 799, 511, + -2170, -2428, -2177, -1497, 2072, 828, 441, 1020, + 873, 1000, -1297, -1531, -1863, -1967, -1516, -1088, + -758, -230, 1561, 6655, -2173, -1787, -1548, -1763, + -1366, -24, -645, 6836, 1480, 1923, -2728, -1859, + 1798, -2010, -1585, -677, -371, 1405, 1254, 1278 +}, + +.fcb16s = { + -2250, -2771, -2879, -2775, -2240, -1363, -272, 1233, + 6172, 5074, -2882, -2419, -2054, -2420, -1252, 347, + 1325, 1799, 1723, 4361, 774, 2066, 1874, 280, + -707, -605, -581, -662, -1104, -2038, 7111, -137, + -883, -1079, -1001, -54, -847, -1013, -1045, -832, + 4696, 3781, -624, -1485, -1360, -1359, -1307, -1219, + -866, -945, 5419, -1512, -2307, -2134, -2056, -1724, + -1653, -630, 157, 3399, -727, -860, -1381, -380, + -716, -1335, 3819, 78, -2, 277, -3185, -3118, + -2715, -3110, -1500, 1626, 3352, 3075, 1956, -539, + 16640, -1204, -2281, -2307, -2272, -2349, -2009, -2184, + -2777, -2375, -1015, 6208, -402, -1331, -1182, -763, + -730, -81, -591, -1184, -1927, 543, 4464, -1095, + -131, -542, -129, 486, -366, -1097, -1594, -554, + -15, -337, 3152, -723, 71, -40, 385, -309, + -769, 290, -853, -1058, -1196, -1557, -595, 3695, + 1129, 438, 1729, -1309, -971, -871, 90, 1418, + 1261, -23, -1382, -223, -1551, -713, -1044, 4495, + -160, -867, -1242, 1188, 159, 120, -1657, -951, + 1536, -159, -1310, 1101, -404, 155, 1717, -24, + -1607, 2347, 2056, -1943, -1313, -1297, -81, 34, + 1441, 354, -2110, -1873, -516, 1102, 2174, 2131, + 0, -946, -729, 61, 107, -14, -108, -50, + 42, -164, -177, -92, -29, 162, 1349, -2380, + -2099, -1692, -980, -49, -94, 331, 1317, 3819, + -482, -782, -775, -909, -640, -1099, -615, -225, + 1556, 2973, -630, 70, -186, -1599, -1076, 4440, + -890, 78, -76, -517, -855, -1886, -1521, -1206, + -1152, -900, 753, 1338, 1758, 2431, -2433, -1569, + -1294, -583, 552, 2040, -154, 250, 513, 2333, + -820, -1987, -2291, -2238, -1880, -1651, -1120, -262, + 2013, 9756, -2803, -2574, -2634, -2789, 356, -1838, + 325, 4584, 3584, 2486, -1524, 1874, -337, -1800, + -1659, 406, 2450, 1252, -245, -1030, 1985, -397, + -1565, -51, 148, 2039, -1212, -729, -700, -11, + 904, 649, 531, -2287, -1640, 766, -725, 171, + -1596, 1387, 3189, -672, -459, -794, -422, -714, + -195, -231, 185, 99, -952, -2248, -2170, -1190, + -457, 1458, 34, 1179, 2427, 1683, -1658, 3749, + -1816, -2000, 2823, -1243, -1415, 713, 875, 75 +}, + +.fcb22l_1 = { + 2198, -2215, -2251, -1966, -1540, -467, 403, 1647, + -2867, -2589, -34, -2314, -602, 2371, 2614, 2218, + -2494, 3659, 2708, -1076, -914, 233, 1149, 1425, + 319, -979, 1023, -682, 110, 239, 427, 703, + -2979, -2513, -2649, -2265, 7420, 526, 2174, 2932, + -2868, -2056, -2232, 1651, -1325, -856, -218, 2091, + 458, 1508, -1208, -845, 244, -441, 558, 752, + -700, -1370, -395, 980, -321, -232, -241, 293, + 10391, -1792, -1948, -1518, -1049, 43, 1524, 2033, + -2434, 303, 1730, -1205, -1432, -1183, -694, 1185, + -2531, -2656, -2751, -1756, -1321, -1100, 287, 8605, + -2868, -2554, 721, -2065, -1671, -771, 675, 2223, + -2690, -2501, -2313, 1829, 3189, 45, 1825, 2024, + -3153, -2824, -2729, -2308, 1686, -370, 482, 2606, + -2972, -2324, 2492, -1762, -1662, 28, 4976, 3214, + -2769, -316, -1146, -1954, 86, -60, -370, 1144, + 5519, -1785, -1538, -1044, -580, -89, 704, 1151, + -2586, -1094, 7473, -1220, -1076, -50, 1029, 1850, + 3546, 3279, -1806, -1191, -528, 682, 1160, 1341, + -2852, 1541, -2358, -1841, -2317, -1351, 993, 2417, + -2675, 2482, -2061, -2089, 3681, 626, 1619, 1818, + -2916, 2821, -2482, -2166, -1084, 1137, 5537, 2864, + -2499, -1782, 2156, 2558, -1117, 127, 1147, 1556, + -2572, 3865, -2008, -1805, -679, 119, 35, 1319, + -2704, -1872, -1756, 6843, -911, 322, 1641, 2461, + -2652, -1957, 1972, -1582, 3082, 84, 1086, 1487, + -2983, -2325, -2780, -2532, -1858, -279, 10092, 4519, + -2364, 2718, -1907, 2678, -1005, 246, 1499, 1679, + -2570, 8779, -2004, -1627, -844, 89, 1712, 2145, + 3316, -1763, -1642, 2819, -599, 9, 906, 1401, + -2289, -2224, 2462, -1580, -843, 2501, -24, 1310, + 3091, -1745, 2398, -1264, -731, 113, 831, 1328, + -2803, -2380, -2808, -2379, -2290, -1376, -234, 2242, + 3537, -2137, -2050, -1260, 2881, 177, 1158, 1424, + -3303, -3123, -3130, -2861, -2075, 2528, -43, 3890, + -3106, -2672, -2554, 1833, -826, 55, 4910, 3324, + 3993, -2176, -2446, -1848, -786, 3346, 1590, 2034, + -2725, -265, 303, 1076, -1985, 3661, 1556, 1983, + -3182, -2712, -2988, -2841, -1332, 4816, 6422, 4184, + -2230, -1248, -2176, -1806, -1617, -878, 3764, 1309, + -2280, 509, -211, 426, 773, 99, 513, 628, + 167, 196, -2256, -1802, -1157, 724, 1405, 1383, + 2384, -409, -672, -453, -205, -89, -12, 240, + 114, -2220, -807, -1302, -1612, -405, 1134, 1381, + 699, -1816, -2151, -1883, 2975, 928, 1527, 1565, + 775, -2141, -1981, -1532, -591, 3338, 683, 1763, + 466, -2028, -2086, 1448, -622, 589, 1294, 1150, + 145, -2382, -1093, -367, 986, 323, 404, 931, + -371, -2868, -2737, -2103, 129, 771, 1498, 1974, + -1481, -1060, -2398, -1125, 285, 2777, 2975, 1431, + -2720, 1748, -2375, -1847, -912, 3829, 808, 2034, + -2492, -2447, -1248, -991, 1449, 1304, 867, 1171, + -2999, -2556, -2763, -2298, 3359, 4277, 1991, 2850, + -2692, -2640, -2593, 1813, -458, 3068, 1012, 2049, + -3258, -2820, -2845, -2395, 2787, -45, 5457, 3568, + -2491, -2114, -1884, 6, -332, -232, 1680, 1139, + 2032, -2383, -2183, -1725, -914, 192, 4175, 2059, + -2922, -2972, -2920, -2210, -1143, 1850, 2468, 1871, + -3138, -99, -2651, -2510, -129, 631, 1677, 1925, + -3302, -3124, -3214, -3143, -2616, -761, 3978, 4234, + -1698, -824, -1975, -742, 2449, -610, 21, 998, + -3047, -2697, -2747, -1919, -1545, 7534, 1243, 3548, + -1863, -1257, 339, -1027, 122, -613, 1989, 953, + -2232, -1759, -1751, -969, -1591, 1917, -325, 889 +}, + +.fcb22m_1 = { + 13531, -1278, -2217, -1956, -1360, -892, -650, -866, + -255, 192, -1139, -1242, -2101, -1682, -1601, 2950, + 2340, 121, 662, 446, -2636, 1711, 615, -1864, + -1297, -1098, -296, 1070, 1284, 891, 7332, -2292, + -2334, -1889, -1170, 1884, -570, 52, 1146, 944, + -2083, -2192, -2420, -2165, -1542, -1474, -278, 4147, + 1506, 1666, 1014, -1657, -2225, -2261, 8568, -1445, + -523, -115, 999, 602, -2762, -2261, 271, -1797, + -1633, -790, 391, 907, 1302, 1076, -1907, -2219, + -2443, -1963, -1495, -1294, 4722, 935, 1691, 1370, + -2355, -1585, -2510, -2297, 2690, -1491, -647, 360, + 1460, 1479, -2041, 368, 10454, -1277, -716, -172, + -538, -287, 169, -232, 960, -1087, -2459, -2196, + -1189, -1967, -1586, -783, 5275, 2811, -1523, -1733, + -2373, -1946, -1586, -1280, -442, -205, 2330, 6319, + -2483, -2115, -2645, -2016, -1464, 89, 529, 1338, + 5291, 3186, 5770, -2311, -2696, -2420, -619, -2322, + 8434, -129, 1661, 1232, -1377, -1277, -1193, 406, + -1332, -1246, -999, -497, 1024, 1500, -2791, -1417, + -2173, 2419, -1492, -734, 2795, 559, 750, 519, + -2714, -509, 4622, 3679, -294, 73, -805, 602, + -99, 94, -2658, -1984, 6907, -1780, -1244, 272, + 874, 140, 1326, 693, -2679, -2274, -2551, 13351, + -2619, 4570, -1739, 2309, 1280, 1235, -1011, -2084, + -1968, -1404, 2568, 3147, -336, 270, 499, 506, + -1567, -2240, -2685, -1951, -2254, 2783, -1411, 8878, + 2321, 1691, -2567, -2450, -2572, -2286, -2038, -1803, + -1316, -315, 464, 1223, -1988, -927, -2035, 2165, + 3663, -919, -328, 229, -2, 217, -2773, -2160, + -2637, -2183, 5081, -1434, 1526, 2830, 1698, 1153, + -2810, -1132, 5408, -1992, 4267, -1357, 809, 563, + 9, -64, -2949, 7061, 4604, -1424, -1839, -610, + -251, 370, 901, 147, -2264, 3135, 3241, -1102, + -397, -1292, 39, 17, 380, 383, -1483, -1458, + 820, 2135, -646, -479, 173, 23, -274, -442, + -978, -1216, -1928, 7260, -1249, -956, -24, 250, + 438, 128, 4080, 152, 2677, -587, -667, -672, + -662, -492, -722, -688, -1907, -787, 3101, -1404, + -1234, -508, 3817, 424, 657, -86, -2179, -599, + 2141, -1446, -1847, 4341, -801, -26, -57, 216, + -1625, -802, 1752, -1301, 2617, -1545, -513, -401, + 234, 658, 1299, -1279, 874, -1408, -1135, -40, + -423, 394, 660, 684, 3341, -937, -1842, -1177, + 1945, -621, 19, -93, 141, -59, -2626, 3368, + -1588, -1959, -1506, 3729, -347, 218, 497, 585, + -2495, -2452, -2118, 578, -225, 378, 40, 1080, + 908, 761, -2070, -1607, 2534, -1535, 1493, 2664, + 215, 634, 317, -233, 4188, -1446, -2129, -1812, + -1428, -1579, -1038, 97, 989, 2038, 3671, -2707, + -2608, -2198, -1119, 1601, 1042, 1325, 1230, 1149, + -2566, -1054, 3659, -2173, -1772, -713, -1080, -101, + 987, 805, -1555, -749, -1510, 3443, -1402, 4172, + -696, 437, 276, 219, -2735, -2453, -2082, 3898, + -867, -582, -726, 1134, 1227, 1121, 2333, -963, + -1474, 2386, -959, -327, -138, 4, 268, 479, + -2889, -2896, -2701, -1975, -593, 1212, 1511, 1087, + 1482, 1612, -1703, 4874, 46, -1364, -1342, -544, + -879, -455, -488, -396, -2616, 849, -2424, -1976, + -1491, -739, 325, 1284, 1831, 1223, -48, -1457, + -2123, -1318, 1617, -1064, 2484, -467, 533, 707, + 351, 422, -525, -657, 202, -476, 133, -679, + -945, -832, 1906, -2981, -2605, -1911, -2541, 11553, + -1585, 1555, 2196, 1616, -2669, -2345, -2423, -1848, + -1756, 4918, -711, 1186, 1873, 1399, -672, -1401, + -1524, -1138, -674, 1285, 195, 884, -377, -1067, + -2125, 377, -1747, -1604, 837, -334, -115, -59, + 160, 483, -2220, 12861, -1633, -1616, -926, -1203, + -113, -90, 378, 148, 5740, 88, -2246, -1598, + -1546, -1694, 2790, -72, 590, 28, -2608, 4312, + -1068, 3091, -632, -651, 366, 63, 744, 375, + 1746, 2753, -2075, -1621, -1033, -471, 972, 199, + 575, 655, -2148, 2407, -2180, -1764, -1030, -1089, + 4083, -80, 417, 384, 1196, -2284, -2549, -1771, + -773, 213, 1188, 788, 1343, 1358, -2584, 7723, + -2171, -2301, -1497, -438, 1001, 110, 671, 939, + 6435, 5777, -1765, -1287, -1181, -1014, 87, -919, + -422, -444, -1930, 4906, -1660, -1558, 3617, -1177, + 261, 9, 261, -47, -2539, 2749, -2476, -2298, + -1047, -1319, -341, -604, 2111, 2779, -2935, 5011, + -1860, -2363, -1686, -1033, 800, 1774, 1700, 1478 +}, + +.fcb22s_1 = { + 11523, -796, -1488, -1897, -1888, -1691, -1767, -1794, + -1622, -1210, -2284, -2777, -2382, -1371, -238, 2997, + 3182, 588, 1129, 704, 248, 1703, -264, -1306, + -1147, -560, -1513, -956, 1667, 1340, 5220, -2276, + -2215, -2049, -1479, -1294, -774, 66, 1270, 2075, + -1435, -1981, -2322, -1896, -1321, -462, 138, 5022, + 2549, 1683, -100, -1744, -1528, -423, 6093, -61, + -288, -623, -650, -828, -1521, 134, 1240, -1399, + -1450, 612, -969, 2585, 945, -312, -1138, -2488, + -2513, -1988, -1607, -773, 3384, 1192, 2651, 2580, + -984, -2015, -1465, -1576, 2273, -1221, 91, 2615, + 840, 1299, -1069, -2151, -1899, -735, 440, 888, + -241, 502, 953, 3613, 1806, -1855, -2303, -1758, + -1318, -1484, -10, 597, 3723, 1992, -488, -2063, + -2284, -2172, -1905, -1547, -937, -18, 3276, 7184, + -1942, -2302, -2399, -1972, -1378, -635, 302, 1081, + 5454, 3358, -447, -807, 205, -1805, -1546, -446, + 6364, -916, 151, -377, -582, -856, -204, -731, + -884, -674, -257, -67, 1564, 2486, 1003, -1508, + -1692, 1515, -889, -622, 2366, 9, -17, -245, + 3733, -1057, -284, 3197, -31, -440, -1115, -1609, + -1834, -1930, 230, 262, 7344, -39, -1746, -562, + -1554, -1838, -1648, -1310, 2157, 80, -102, 238, + -823, -622, -720, -115, -274, 16, -1562, -1785, + -1535, -334, 2604, 3388, -410, -103, -348, -142, + 1676, -441, -2267, -1988, -1421, -680, 1302, 2682, + 383, -10, 1487, -1086, -251, -1134, 141, -84, + -1003, -898, 95, 2304, 802, -1549, -1562, 2650, + 2180, 64, -512, -832, -705, -429, 1826, -2283, + -1976, -1277, 2699, 504, 249, -9, 178, -33, + -1357, -1138, 3005, 293, 229, 1633, -197, -540, + -1245, -1617, -1269, 6639, 2437, -647, -1501, -1097, + -1051, -1150, -1183, -1461, 71, 1529, 2847, 1149, + -705, -1345, -1605, -629, -617, -60, -2081, -1435, + 938, 844, -1055, -841, 1179, 392, 1112, 946, + -1252, -1728, -266, 7063, -1335, -920, -1048, 206, + 48, -619, 4764, 274, 2394, -799, -798, -1003, + -1278, -1800, -1626, -1415, -498, 1439, 1643, -1978, + -1258, -1136, 1285, -9, 596, 141, -2211, 908, + 802, -470, -1125, 3216, -234, -412, 3, -980, + 15, -1047, 1530, 660, 1986, -480, -499, -550, + -733, -531, 1326, -1607, 787, -1136, -1002, -65, + 358, 743, 253, -294, 3498, -1033, -1270, -790, + 537, 1788, 309, -72, -1241, -1999, 609, 2981, + -1025, -1642, -958, 3845, -1221, -962, -965, -1612, + -1993, -33, -1136, 1086, -46, 1178, -229, 139, + 644, 718, -1696, 2411, 1019, -1056, 52, 224, + -487, -395, -40, 125, 3001, -1955, -1950, -784, + -1111, 897, -514, 159, 785, 1095, 2944, -2554, + -2407, -1975, -632, 1030, 1712, 366, 463, 125, + -2354, -796, 5663, -1055, -1151, -870, 348, -676, + 1447, 215, -1005, -1531, -910, 2249, -438, 2889, + 107, -404, -271, -534, -1022, -2117, -1738, 2261, + -257, -788, 32, 1747, 1196, 910, 33, 1, + -23, 28, -25, 19, 13, -29, -23, -48, + -907, -2113, -1978, -1426, -535, 1589, 1908, 2724, + 1646, -897, 758, 2326, 674, -1449, 111, 220, + 475, -162, -1465, -2036, -528, 1308, -2087, -2031, + -1308, 183, 35, 1097, 1008, 1864, -2116, -2303, + -1928, -261, 2342, -292, 1480, 268, 1582, 1079, + -1183, -1154, -777, 309, 1218, 683, 1314, 1677, + -758, -1745, 1422, -1331, -1638, -1100, -303, 5003, + -57, -379, -511, -756, -727, -2315, -1860, -1775, + -676, 3854, -67, -52, 2018, 1532, -160, -197, + -75, -1934, -1134, 2025, 1810, -491, 83, 646, + 390, -297, -441, -342, -479, -486, -296, -30, + 443, 1151, 3508, 6119, -493, -1427, -1393, -1273, + -1280, -1687, -1683, -1511, 5109, -1008, -1137, -638, + -649, -342, -590, -478, -577, -349, -579, 2548, + -463, 2107, -568, -678, -788, -454, -608, -452, + 1934, 1485, -1746, -1007, -1174, -573, 239, -119, + 679, -76, -1687, 1956, -898, -477, 456, -156, + 1460, 13, 92, -987, 554, -2772, -2578, -1694, + -235, 753, 1527, 1106, 1539, 1342, -1305, 6560, + -1526, -1765, -793, -600, 248, -542, -63, -421, + 4828, 1288, -1580, -1826, -1163, -1014, -221, -818, + -109, -61, 1265, 1939, -1265, -414, 1912, -190, + -1157, -675, -756, -935, 2529, 136, -1709, -1727, + -1819, -1504, -1232, -959, 1128, 4142, -1945, 2958, + -900, -1432, -1720, -1380, 381, 1473, 1235, 1062 +}, + +.fcb22l_2 = { + 2441, -2086, -2129, -2146, -1839, -1035, 295, 2465, + -2785, -2597, -81, -2162, -991, 3060, 3056, 2985, + -2415, 4009, 3058, -1165, -1281, -322, 629, 2232, + 481, -2255, 1165, -1455, -621, -29, 923, 1371, + -2822, -2421, -2596, -1908, 6338, 279, 1845, 3532, + -2955, -2571, -2554, 744, -1785, -909, 775, 3156, + 738, 1760, -458, -590, -73, 22, -91, 326, + -1098, -1511, -1000, 1741, -1024, -562, -399, 736, + 9669, -2109, -1872, -1539, -1208, -265, 994, 2364, + -2121, -98, 1523, -1427, -1450, -1157, -294, 1375, + -3007, -2669, -2847, -1777, -1196, -1257, 1065, 9128, + -2948, -2509, 470, -2521, -1947, -728, 503, 3810, + -2538, -2469, -2217, 1957, 2580, -229, 1212, 2263, + -3174, -2660, -2792, -2692, 1226, -512, 555, 3960, + -2979, -2426, 1978, -2182, -1868, -455, 4681, 4580, + -2514, -1642, -1029, -1712, 416, -838, -362, 1208, + 5211, -2128, -1867, -1337, -549, -70, 828, 1508, + -2272, -1611, 7307, -1612, -1244, -461, 749, 2510, + 3669, 3236, -1845, -1333, -866, 268, 850, 1686, + -2805, 1079, -2258, -2075, -2017, -1115, 214, 2735, + -2719, 2676, -2154, -1976, 2884, 393, 1247, 2382, + -3043, 2188, -2703, -2353, -1861, -208, 4419, 4511, + -2187, -1630, 2246, 2331, -1105, -198, 818, 1721, + -2180, 3571, -1841, -1738, -1020, 14, 407, 1028, + -2536, -2171, -2115, 6630, -968, -306, 1438, 3574, + -2411, -1857, 1911, -1546, 2709, 57, 910, 1727, + -3159, -2565, -2675, -2746, -2017, -534, 8461, 6103, + -2299, 2912, -1851, 2660, -1479, -97, 1148, 2204, + -2510, 8781, -2194, -1790, -1114, -110, 1140, 2885, + 3261, -1921, -1633, 2766, -788, -403, 610, 1651, + -2515, -2021, 2415, -1606, -1149, 2479, 297, 1693, + 3823, -1538, 2514, -1261, -904, -236, 550, 1581, + -2903, -2440, -2922, -2749, -2480, -1849, -423, 3613, + 3420, -1876, -1929, -1537, 2955, 58, 1014, 1950, + -3295, -3009, -3161, -2926, -2353, 2355, 351, 5502, + -3140, -2745, -2781, 1247, -1037, 538, 4939, 4382, + 3584, -2284, -2321, -1844, -743, 3156, 1546, 2358, + -562, -101, -497, -1196, -1023, 1972, 1255, 1374, + -3146, -2824, -3057, -2757, -1736, 3746, 5609, 5118, + -2155, -1665, -1701, -1780, -1975, -1127, 3185, 2036, + -2540, 324, -481, 311, 624, 719, 543, 1030, + 550, 513, -2430, -1817, -1129, 62, 1526, 1809, + 2172, -1314, -1035, -586, -292, 233, 209, 543, + -252, -2372, -1961, -1629, -1306, -408, 451, 1339, + 792, -2619, -2316, -1624, 1941, 678, 977, 1710, + 428, -2499, -2369, -2101, -1448, 2988, 874, 2497, + 451, -2263, -2204, 1403, -631, 694, 1424, 1658, + -243, -2104, -378, 355, 1446, 373, 377, 973, + -756, -2802, -2508, -2081, 177, 352, 2428, 2359, + -1533, -2710, -2544, -1102, 419, 3132, 1222, 1942, + -2756, 1844, -2429, -1854, -1283, 3960, 1633, 2917, + -2858, -2784, -2106, -1025, 1588, 905, 1092, 1657, + -3028, -2715, -2782, -2218, 2852, 4006, 2534, 3726, + -2783, -2355, -2146, 2113, -1201, 3361, 1178, 2670, + -3199, -2796, -2682, -2489, 1905, -471, 5097, 4436, + -2197, -1078, -2327, 420, -637, 10, 1647, 1362, + 1815, -2519, -2363, -2174, -1454, -31, 4125, 3446, + -3054, -2953, -2738, -2328, -1636, 1086, 2238, 2132, + -3089, -432, -2674, -2515, -168, 745, 2236, 2305, + -3214, -2953, -3159, -3086, -2748, -1200, 3346, 5127, + -1150, -501, -2109, -1662, 2301, -401, 651, 1320, + -3072, -2608, -2833, -2249, -1387, 7704, 1811, 4960, + -2474, -2589, 83, -499, -785, 194, 1312, 1442, + -2716, -1663, -2088, -1812, -1396, 1862, -369, 1397 +}, + +.fcb22m_2 = { + 8809, -2291, -2452, -1982, -1356, -423, 419, 588, + 897, 1086, 79, -2155, -1957, 367, 1080, 233, + 718, 441, 515, 642, 730, 2454, 774, -2299, + -1526, -784, -359, 96, 385, 482, 4905, -2501, + -2431, -2047, -1139, 131, 743, 999, 1243, 1294, + -2154, -433, -2461, -2201, -1552, -163, -200, 4009, + 1731, 1652, -2381, 5295, -1457, -895, 3480, -1230, + -94, 471, 554, 669, -2458, -1271, 278, -2238, + -1852, -813, 888, 1032, 801, 1008, -258, -538, + -1744, -2087, -1651, -1239, 2222, -4, 783, 882, + 478, 782, -1335, -1453, 1728, -627, -387, -205, + 221, 193, -2282, -518, 7464, -1808, -1134, -199, + 340, 321, 410, 617, 2278, -436, -2082, -1958, + -1493, -885, 628, 794, 855, 989, 232, -1115, + -2617, -2152, -1290, -1299, -458, 222, 3936, 3349, + -2240, -2787, -2689, -2255, -1241, 816, 2307, 1566, + 1685, 1723, 2960, -2134, -2532, -1798, -1128, -1073, + 5380, 1013, 1525, 1415, -1976, 456, -538, -1433, + -1347, 22, -496, 284, 387, 465, -2214, -1863, + -2261, 1049, -1487, -1222, 1610, 621, 1000, 1116, + -2393, -731, 4075, 2375, -1178, -908, -383, 327, + 543, 572, -2071, -2039, 3310, -1903, -1502, -72, + 123, 693, 721, 918, -1866, -1251, -1065, 5630, + -1574, -541, 1, 1014, 813, 887, -2145, -2421, + -2176, -1756, 1856, 408, -1, 759, 1109, 1276, + 3053, -2705, -2467, -2068, -1160, 1405, 459, 1167, + 1219, 1318, -2198, -2037, -2005, -2204, -2039, -1473, + -1529, 264, 1333, 1822, -2121, -1434, -472, 1901, + 2448, -589, -424, 248, 376, 602, -1571, -1032, + -1243, -1619, 5682, -1162, 362, 570, 865, 852, + -1875, -805, 4258, -1569, 2992, -1175, 51, 164, + 314, 648, -2083, 5574, 2553, -1866, -1156, -642, + -198, 330, 446, 602, -2365, 1601, 2873, -2043, + -1510, -1142, -20, 588, 535, 676, -2207, -1637, + 626, 745, -1548, -590, 745, 540, 505, 618, + 749, -1389, 857, 1387, -398, -606, -75, -86, + 11, 78, 3322, -1347, 1978, -1431, -745, -280, + -42, 135, 350, 376, -508, -1349, 2961, -1184, + -647, -1257, 3009, -374, 523, 616, -1848, -41, + 2652, -1609, -1603, 3284, -24, 502, 122, 448, + -2337, -1029, 734, -1533, 1523, -1312, -754, 335, + 510, 774, 769, -117, 139, -1254, -1468, -965, + -375, 2, 227, 518, 3187, -1524, -776, -1253, + 2977, -530, 319, -61, 244, 413, -2290, 3085, + -1763, -1480, -1374, 3272, -87, 323, 421, 652, + -2317, -2182, -1604, -1, -801, 1320, -156, 907, + 799, 918, -1494, -2205, 1137, 69, 1249, 3437, + 925, 29, 419, 448, 3574, -1564, -1713, 2374, + -941, -252, 123, 263, 366, 539, 1059, -1856, + -1753, 766, -1704, 106, 262, 596, 684, 820, + -2503, -1878, 1835, -594, -1024, -2105, -1567, 488, + 794, 883, -1626, -613, -1410, 2846, -1413, 3557, + -348, 460, 332, 577, -907, 700, -1680, 1130, + -1637, -793, -160, -38, 473, 630, 1487, 1872, + -1526, 1379, -806, 121, -383, 149, 259, 413, + 759, -2817, -2758, -2290, -1348, 460, 1782, 1536, + 1513, 1503, -2265, 3193, 117, -1704, -1367, -487, + 125, 365, 594, 651, -2287, 1272, -2537, -2038, + -1515, -578, 2994, 582, 941, 1058, -1556, -1583, + -720, -1584, 956, -1032, 1861, 146, 402, 429, + -2184, 1667, 1241, 289, 52, -232, -265, 210, + 248, 331, 1133, -1813, -1869, -1429, -1484, 5620, + -400, 1316, 1146, 1150, -1975, -818, -1921, -2054, + -1768, 2953, -544, 426, 856, 1107, 493, -2019, + 176, -1915, -1040, 717, -91, 728, 647, 776, + -2360, 739, -2136, 30, 636, -447, -116, 498, + 531, 775, -2250, 8607, -2075, -1928, -1072, -450, + 38, 439, 558, 778, 4484, 1056, -1830, -1716, + -988, -412, 260, 56, 425, 579, -2243, 4094, + -1267, 2172, -990, -562, 97, 304, 533, 609, + 790, 780, -2029, -1947, -1327, 1224, 255, 344, + 516, 660, -591, 1702, -118, -1402, 396, -1387, + 2268, -247, 177, 355, 1393, -2318, -1975, -1563, + 863, -939, -365, 411, 800, 1019, -2370, 4656, + -2301, -2111, -1679, -698, 458, 788, 1004, 1138, + 2285, 4924, -1940, -1955, -1159, -436, 237, 5, + 300, 364, -2492, 2165, -2021, -2072, 1504, -612, + -93, 249, 676, 799, -2411, 1952, -1752, -2418, + -2285, -1323, -621, 837, 1043, 1266, 76, 3160, + -2176, -2176, -1717, -1105, 1045, 410, 728, 940 +}, + +.fcb22s_2 = { + 6946, -1850, -1986, -1590, -1276, -1063, -1026, -1017, + -805, -346, 9, -2911, -2843, -1899, -198, 2193, + 3325, 1315, 37, -528, -371, 599, -751, -2157, + -1912, -855, 988, 1222, 1085, 953, 3212, -2793, + -2564, -1707, -657, 683, 1109, 683, 647, 446, + -1906, -2315, -2569, -2428, -1698, -600, 1100, 3790, + 3368, 2172, 2017, -895, -1354, -734, 2552, -403, + -68, -402, -752, -932, -1205, -1937, 572, -1434, + -500, -579, 291, 1723, 1312, 1695, -238, -1715, + -2029, -1525, -816, -363, 2816, 167, 2196, 1793, + 897, -1081, -262, -1338, 1052, -1231, -94, 1296, + 503, 184, 588, -2057, -911, -1933, -1769, 167, + 1013, 1774, 1414, 1289, 2406, -1906, -2055, -1952, + -1726, -1618, -451, 575, 3021, 2569, -776, -1649, + -2111, -1930, -1499, -1349, -595, 329, 3090, 5458, + -1954, -1309, -1554, -1159, -1132, 329, 714, 760, + 2529, 2417, 1046, -1025, -1114, -1325, -154, -1501, + 4160, -696, 230, 398, -2010, 385, -1344, 36, + -1269, -987, 1009, 1453, 1163, 1591, 916, -1534, + -508, 221, -1596, -1130, 1394, 539, 676, 676, + 1263, 2029, 284, 1592, 161, -124, -572, -1362, + -1946, -2148, -1488, -222, 4967, -1202, -939, -375, + -80, -593, -445, -418, -781, -1560, 31, 4757, + -1417, -954, -402, 193, -316, -278, -926, -895, + -1024, -436, 2673, 1991, 254, 28, -861, -1291, + 1475, -2708, -2689, -2118, -703, 290, 1841, 2048, + 1213, 594, 132, -2598, -2427, -988, -1111, -158, + 478, 2118, 2571, 830, -1430, -678, -773, 1340, + 2473, -798, -751, 215, 274, -65, 335, -1947, + -1796, -1436, 3862, -611, 105, -31, 775, 669, + 1439, -1266, 1670, -739, -1259, -572, -17, -107, + 176, 130, 3899, 3478, -548, -1429, -1176, -1104, + -1147, -1503, -1277, -1068, -258, 2645, 1753, -333, + -827, -1306, -827, -502, -306, -119, -1602, -1644, + 1922, 1127, -628, -1073, 348, 195, 616, 685, + 1750, -898, -1852, 1813, -700, 254, 598, -234, + -433, -1035, 2502, 94, 467, -1672, -905, 776, + 679, -11, -1071, -1845, -1083, -320, 690, 110, + -708, -1077, 2514, 70, -412, -300, -371, -717, + 1700, -1625, -1346, 1954, 14, -64, -121, 181, + -673, -909, 2274, -1389, 2058, -1503, 306, -187, + -209, -69, 1523, -632, -695, -1283, -988, -569, + -798, -521, 398, 2834, 1953, -2215, -1626, 106, + 6, -498, -57, 173, 731, 1002, -1706, 1701, + -328, -1745, -1398, 2176, -19, 311, 492, 667, + -1073, -1803, -1684, 703, -1316, 1803, 659, 913, + 906, 1033, -1982, -102, 945, -1620, 718, 555, + 613, 38, 394, 421, 2738, -1159, -2248, -1852, + -1568, 33, 363, 1490, 935, 561, 1464, -2466, + -1209, -1204, -692, 2009, 129, 354, 372, 380, + -2053, 1122, 2272, -824, -1355, -926, -122, 567, + 526, 923, -1320, 59, -226, 1674, -1512, 1498, + -631, 221, 26, -247, -40, -1615, -1597, 2111, + 34, -813, 200, 219, 758, 1000, 306, 394, + -430, -117, -409, -81, -207, 16, 36, 176, + -1737, -2898, -3005, -2214, -568, 2140, 4132, 2592, + 504, -521, -1509, 3610, 1070, -1890, -1319, -11, + 174, -148, -212, -347, -464, -1068, -2568, -2532, + -1973, -519, 2104, 3713, 1882, -145, -1319, -2375, + -1862, -843, 2061, -266, 1465, 866, 912, 1183, + -1784, 2072, 205, -375, 1112, -374, -534, -430, + -162, -204, 375, 82, -823, -1148, -752, 4681, + -339, -247, -790, -1088, -494, -2302, -2310, -1603, + 46, 3367, -50, 393, 1383, 1457, -1377, -2005, + 643, 326, 312, 1189, -225, 563, 261, -70, + -667, -1191, -2255, -470, 1000, 142, -525, 2285, + 756, 2061, -953, 5888, -1339, -1534, -1252, -16, + -116, -305, -375, -596, 3611, -889, -511, 43, + -809, -659, -737, -510, -258, -108, -1515, 2806, + -1555, 1025, -932, -601, 146, 164, 207, 71, + 1606, 93, -2420, -2311, -1641, -244, 1785, 804, + 1040, 427, -1510, 38, -2490, -1987, 44, 699, + 1407, 988, 1061, 411, 1162, -1382, -2669, -1635, + -905, 1503, 674, 1357, 869, 244, 411, 2612, + -1792, -2147, -1693, 1434, 281, 38, 228, 424, + 2291, 1354, -2128, -1377, -1014, -609, 131, -151, + 418, 602, 111, 2200, -1547, -1153, 1435, -1282, + 6, -111, -1, 92, 238, 613, -2271, -1181, + -1455, -919, -182, 1066, 1932, 1679, -1715, 2825, + -1764, -1759, -741, -829, 501, 746, 1056, 1416 +}, + +.fcb44l = { + 4868, -1851, -2031, -2019, -1751, -552, 756, 929, + 1389, 1590, -2090, -1202, -1317, 516, -1798, -1020, + -694, 4322, 1388, 1904, -2605, -1239, 1005, -757, + -1248, -358, 699, -201, 409, 1093, -2901, -2254, + -2605, -2595, -2104, -1681, 6854, 2692, 3155, 3446, + -2535, -1421, -1745, 898, -2046, -1457, -1044, -269, + 1748, 1873, -2268, -1098, 407, -1865, -2103, 1510, + -1217, -399, 1718, 2017, 3638, -1685, -1547, -1480, + 1637, -744, 580, 586, 1313, 1409, 617, -2020, + -1919, -2179, 932, -937, 559, 1795, 1528, 1596, + -2867, -2553, -2507, -2653, -2365, -1985, -170, 8679, + 4271, 4273, 2263, -1835, -1934, -1719, -1778, 2357, + 125, 1319, 1543, 1765, 3689, -1215, 2369, -1533, + -1611, -771, -123, 1005, 1297, 1465, -2491, 2631, + -1636, -1655, 1244, -1178, 386, 961, 1300, 1553, + -2357, -2404, -2305, -2177, -1714, -383, -98, 258, + 3902, 2475, -2923, -2580, -2685, -2803, -2678, -2428, + -1247, 450, 8174, 5035, -2302, -1629, -1495, 1832, + 1616, -577, 639, 872, 1122, 1437, 785, -1947, + -1976, 823, -1909, -1005, 430, 1244, 1713, 1664, + -2537, 8025, -1705, -2005, -2030, -1155, 64, 1106, + 1975, 2277, -2410, -2639, -2292, -1858, 162, 744, + 555, 1559, 1719, 1806, -2282, -1982, -1914, 1415, + -1785, 2197, 254, 763, 1338, 1741, -2509, -1991, + -2328, -1853, -2299, 5145, -34, 1495, 2913, 3018, + -2009, -1736, 2411, -1595, 1877, -1316, 693, 1042, + 1565, 1744, -2657, -2161, -2222, -2135, 4454, -1784, + 1331, 3208, 2852, 2955, 3738, -1338, -1425, 2090, + -1601, -279, -2, 712, 1220, 1436, -2385, -1265, + 7093, -1561, -1742, -1003, 283, 1009, 1843, 2055, + -2251, -2175, 2310, -1321, -1976, 1874, 164, 2781, + 2721, 2487, 2519, -1101, -1539, -1575, -1487, -724, + -25, 355, 643, 1011, -2296, -1799, -1895, -1700, + 2743, -924, -254, 32, 1504, 1910, -2811, 898, + -2363, -2518, -2408, -1737, -936, 221, 2588, 2527, + -2535, -2360, -2477, -1861, -1882, 1833, 3587, 1307, + 2141, 2274, -433, -1994, -1692, -1318, -1398, -350, + 1518, 1923, 835, 1262, -2246, 3383, 2458, -1464, + -1874, -983, -157, 531, 1490, 1729, 9543, -1713, + -2011, -2015, -1870, -969, -34, 1160, 1724, 1919, + -2530, 140, -1923, -1730, -1720, -605, 629, 1577, + 974, 1373, -2268, -1582, -933, 1124, -1624, -514, + 4156, -118, 1515, 1907, -2267, -574, -1311, -954, + -47, -1259, 15, 364, 854, 1009, -2221, 629, + 994, -1646, -1324, -1509, 2359, 3453, 1393, 1912, + 3586, -2286, -2537, -2560, -2415, -1748, -368, 3093, + 2881, 2611, -2556, 2792, -1558, 1117, -1681, -65, + -36, 516, 1233, 1514, 531, -1814, 998, -1795, + -1693, -871, 725, 868, 1504, 1465, 907, 300, + -2060, -2366, -2392, -1881, -596, 1754, 2169, 2104, + -2755, 2709, -2298, -2627, -2423, -1875, -733, 3886, + 2648, 2821, 623, -541, -163, -319, 85, 84, + 15, 716, 511, 572, 3948, 2773, -1504, -1746, + -1832, -934, -78, 988, 1277, 1518, -2678, 2216, + -2162, -2331, -2076, -968, 3445, 1070, 2077, 2206, + -2892, -2425, -2674, -2905, -2844, -2584, -1381, 3269, + 2696, 3281, -2090, -369, -1515, -1367, -200, 2089, + 739, 700, 866, 1169, -2276, -1057, 2851, 2589, + -1686, -515, -65, 579, 1278, 1593, -2837, -2458, + -2565, -2783, -2843, -2468, -1704, -1531, 1475, 4153, + -2209, -1857, -1873, -2177, 758, -1531, 3207, 1163, + 1506, 1851, -2383, -1683, -1839, 5772, -1815, -465, + 361, 1086, 1912, 2140, -2629, -1688, 1608, -2190, + -2419, -2064, -1253, 1397, 2099, 2306, 513, 1664, + -1683, -1629, -1682, -109, 269, 695, 1072, 1317, + 208, -1602, -1918, -1038, -813, 312, 24, 26, + 761, 990, -2288, -2225, -1948, -1932, -1832, -949, + -450, 920, 805, 1468, -2897, -2633, -2557, 464, + -2174, -1157, 1170, 2230, 2550, 2522, -2643, -1928, + -2255, -2578, 82, -2206, -63, 2663, 2007, 2292, + 226, -2541, -2687, -2753, -2229, -1556, 785, 3837, + 2331, 2492, -2496, -1740, -2465, -2295, -2151, 1142, + 363, 3967, 1943, 2432, -2619, -2400, 520, -2274, + -1900, -1486, 2135, 1407, 2300, 2288, -2811, -3066, + -3128, -3098, -2529, -1475, 2172, 3413, 3613, 3571, + 564, -2347, -2257, -2377, -1944, -1771, -582, 509, + 1683, 1975, -285, -2136, -2529, -2464, -2117, 278, + 1094, 1042, 2192, 1976, 1781, -1874, -2042, -2103, + -1744, -1044, 3373, 1252, 1861, 1873, -2688, -1849, + -2462, -2494, -2105, -1903, 2221, 250, 1653, 2233 +}, + +.fcb44m = { + 13151, -1763, -2583, -2518, -2181, -1036, -537, -112, + 214, 590, -608, -2270, -2228, -1301, -1018, 3687, + -471, -282, 909, 1665, -2426, 1713, -808, -1240, + -1366, -976, -140, 1730, 683, 191, 7253, -2076, + -2733, -2698, -2253, -1116, 376, 687, 1314, 1532, + -820, -1471, -2092, -2047, -1796, -1347, -732, 6348, + 2529, 1441, -1460, -1845, -1046, -1643, 8086, -928, + 90, 660, 428, -188, 604, -2022, 556, -1680, + -1641, -902, 834, 941, 1480, 1906, -2439, -2573, + -3091, -2853, -2419, -1606, 2312, 2624, 2659, 2659, + -1286, -2273, -2400, -1826, 2443, -1391, 685, 1822, + 1810, 1625, -1993, -731, 9737, -1476, -1183, -1244, + 34, -85, 0, 201, 4171, -2430, -2869, -2866, + -2488, -1154, -1253, 282, 2715, 3643, -2130, -2522, + -3259, -3051, -2977, -2204, -1264, 1103, 7113, 7948, + -1271, -1694, -2011, -1294, -1607, 247, -303, 715, + 4276, 1908, -2337, -2111, -2232, -2123, -1648, -1302, + 7686, 1213, 982, 984, -2594, -2127, -1981, -2104, + -2405, -1966, -936, -95, 326, 672, -2263, -893, + -1367, 1288, -1321, -1351, 2503, 747, 390, -247, + -2220, -860, 3641, 3766, -1724, -1487, -531, 239, + 134, -82, -2563, -1537, 3883, -1911, -2109, -1713, + 1056, 726, 977, 1091, -1874, -1366, -1628, 11069, + -1653, -696, 118, -78, 337, 29, 2449, -1438, + -601, -1533, -816, 1262, 540, 79, -460, -1403, + 3204, -1918, -1892, -1911, -1468, -976, -42, 2785, + 1088, 564, -236, -2267, -2324, -2130, -1880, -427, + -258, -543, 903, 5142, -1791, -1611, -1073, 2911, + 2993, -1295, -400, 229, 192, -85, 4461, -1711, + -1431, -1640, 3525, -1398, -101, -219, 327, 415, + -669, -1520, 6595, -1291, 5123, 155, -480, -518, + -552, -890, -2609, 7074, 3220, -1054, -1852, -1165, + -25, 89, -361, -140, -1610, 2214, 2903, -1737, + -1704, -1178, -708, -171, 177, 674, -1075, -890, + 82, 463, -1432, -1048, -703, -759, -247, 344, + 2448, -656, -1135, 4366, -583, -705, 40, -314, + -676, -1271, 4389, -952, 3249, -1606, -1524, -1172, + -490, 97, 128, -91, -66, -1293, 1696, -1114, + -1455, -519, 2620, 479, -257, -1512, -2037, -1281, + 1752, -1285, -1812, 2789, -52, 676, 409, 296, + -1977, -1043, 270, -1615, 2131, -1051, -161, -498, + 767, 1673, 1044, 27, -1107, -1730, -1856, -1264, + -275, -167, 893, 443, 3850, 97, -1244, -1691, + -1566, -1088, -1062, -837, -159, 1830, -1424, 2494, + -1878, -1532, -1991, 2919, 62, 399, 524, 381, + -1340, -2415, -2028, 218, -1342, 410, 815, 533, + 948, 1998, -1213, -1847, 3691, -2123, 1822, -1548, + 537, 987, 356, 123, 3876, -2476, -2021, -2195, + -1562, -737, 2250, 709, 797, 1102, 2065, -2258, + -2394, -1816, -1536, 1059, 4653, 1457, 456, -27, + -2226, -736, 765, -1879, -2188, -1793, -928, 892, + 1793, 2257, -1182, -1646, -1789, 6105, -1936, 4316, + -307, -143, 223, 236, -2213, -1862, -1823, 3326, + -1810, -1384, -453, 1007, 1331, 1405, 4135, -2298, + -1657, 1981, -1702, -853, -318, 298, 760, 1025, + -2537, -2782, -2985, -2687, -2839, 4493, -448, 4249, + 3048, 2678, 1045, 3227, -690, -1390, -976, -652, + 587, 194, -749, -1358, -730, 250, -2404, -2548, + -2157, -1027, 32, 2091, 1059, 1360, 262, -2135, + -2061, -1777, -1614, -246, 2004, 2605, 1516, -948, + -1060, -1076, -1643, -748, 144, 1595, 1730, 531, + -1086, -2182, -483, -2191, -2411, -1983, -2345, 10051, + -841, 1456, 924, 207, 4652, -1831, -2026, -1710, + -2235, 4036, -755, -70, 533, 887, -1899, -2326, + -2129, -2115, -1606, 1443, 2557, 941, 618, 527, + 949, -1547, -2067, -1785, 455, -60, 79, 202, + 912, 954, -2527, 14551, -1893, -2315, -2609, -1844, + 497, 287, -197, 626, 6839, -804, -1299, -1259, + -1109, -97, 976, 144, -343, -1375, -2334, 3740, + -1049, 2980, -1739, -474, 223, 137, 155, -171, + 2962, 1814, -2378, -2643, -2249, -1109, 858, 643, + 1630, 1399, -2098, 974, -1718, -2193, -2146, -1488, + 3353, -147, 1187, 1266, 1559, -2532, -2941, -2759, + -2101, -1098, 1562, 1049, 2045, 2159, -2298, 7439, + -2129, -2361, -2318, -1552, -422, 482, 985, 1111, + 6050, 5657, -1698, -2267, -2127, -1135, -140, -286, + -352, -124, -1230, 3492, -1370, -1221, 2958, -1239, + -472, -722, -169, -89, -2310, 2988, -2367, -2421, + -2589, -2034, -662, 421, 1863, 2736, -2612, 5429, + -2104, -2257, -2440, -1817, 4819, 883, 622, 636 +}, + +.fcb44s = { + 11239, -328, -2011, -1713, -1662, -1290, -1225, -1520, + -1541, -912, 400, -1103, -2698, -162, 263, -964, + 668, 405, 732, 2493, -2491, 1000, -2910, -793, + -1351, -515, 1051, 2002, 1757, 2150, -2010, -2021, + -2254, -1896, -1953, 664, 7067, 2632, 531, -1367, + -2228, 2113, -2019, 2309, -1458, -426, 1242, 338, + 205, -222, -1317, -1806, -2477, -2427, -2477, -1852, + -1472, -911, 2261, 10280, -2369, 382, 3180, -1210, + -1601, -748, -732, 504, 1440, 1142, -13, 610, + -2457, -739, -1318, -1013, -52, -470, 627, 4734, + 1248, 2947, -631, 1560, 2096, -833, -1173, -1475, + -2060, -2189, 967, -1451, -1544, -758, -538, -31, + 1395, 3550, -3, -1999, -1975, -1734, -2680, -2512, + -2037, -1306, -252, 1288, 6012, 4834, -1087, 3259, + 3115, -1369, -1136, -948, -264, -582, -677, -643, + -2500, 1284, -317, -1872, -1150, -1150, 310, 832, + 1597, 2842, 6295, 3806, -671, -1536, -1460, -1256, + -1223, -1504, -1672, -1471, 1358, 1004, -1893, 1114, + -1643, -103, -513, 189, 303, 140, -1618, -648, + -720, 7274, 573, -180, -731, -1226, -1564, -1742, + 151, 2103, -1562, -974, 94, 546, 3536, -205, + -1657, -2534, -2187, 2840, -1248, 451, 2615, 171, + 479, -305, -1299, -1708, -2144, -1593, -1289, 2766, + 2287, -400, 188, -51, 141, 105, -2128, 4976, + -1690, -1216, -1175, 297, 1454, 449, -478, -970, + -1914, -1459, 3036, 2668, -950, -634, -507, -374, + 4, 34, -1664, 2901, 847, 2817, -1154, -1651, + -1262, -1160, -624, 629, 1578, 765, -2002, -2121, + -1527, 1938, -272, 113, 287, 955, -1473, 60, + 8047, 137, -534, -841, -1077, -1504, -1788, -1758, + -1871, 119, 931, 1775, -704, 2792, 354, -501, + -1370, -2038, -1031, -1631, -1914, -879, 377, 7589, + 173, -196, -491, -1658, 3790, -773, -1731, 3028, + 49, -1013, -563, -1232, -953, -730, -2568, -1926, + -679, -267, -324, -962, 51, 461, 2728, 3631, + 3533, -1690, -2846, -2370, -1945, -917, -551, 276, + 2634, 3558, -2592, -1750, -2422, -1586, -1204, -1001, + 4603, 1802, 2673, 1685, 2710, -853, -2321, -1919, + -1603, -868, 3706, 290, 570, 338, -2245, -1704, + -1915, 545, -787, 1635, 1725, 526, 666, 1604, + 642, -1154, 3231, -1232, -1772, -623, 217, 27, + 3, 641, -2411, 1924, -967, -1583, -1499, 2316, + 1354, -115, 333, 559, -1721, 2475, -1942, -2114, + -1196, -571, 1769, 2350, 1315, -607, 4510, -1414, + -2228, -1312, 1439, 469, -248, -399, -270, -721, + -1517, -1247, -771, -36, 6488, 942, -279, -572, + -1041, -1908, -2388, -2281, -2595, -2275, -1529, 51, + 471, 4435, 3002, 2738, 4049, 1562, -2706, -1672, + -1649, -1204, -518, -280, 774, 1344, 6, -1950, + -1521, -1768, -972, 1420, 3011, -191, 644, 1478, + 3220, -313, 3030, -153, -841, -739, -378, -1013, + -1410, -1815, -2104, -1033, -2097, -1992, -943, 2391, + 424, 369, 1601, 3331, 1494, -2060, -2027, 1579, + -1407, 1120, -280, -197, 761, 1048, -710, 4094, + -1533, -1984, -1620, -1132, -515, -485, 971, 2644, + 3979, -661, -1891, -1120, -897, 2484, 1623, 21, + -1534, -2438, 3201, -1510, 858, -1459, -711, -1332, + -833, -240, 763, 1096, -1435, -29, 3174, -1773, + -19, 708, 1680, 403, -910, -2224, -2670, -619, + 1320, -751, -1323, -1022, 2875, 1080, 985, 1, + 191, 7823, -475, -604, -1126, -967, -1139, -1600, + -1767, -1161, -1342, -1960, -2112, -1793, -1596, 3103, + 535, 2001, 3235, 151, -2266, -807, -1977, -1661, + -1255, 2328, 2632, 3189, 621, -1130, -2183, -1127, + 2391, -884, 2173, -690, -354, -516, 352, 954, + 1847, -74, -1260, -1839, 2557, -1221, 228, -630, + -162, 386, 1462, -1889, -2596, -2216, -1869, -518, + 1281, 2329, 2653, 1117, -1535, -1038, -1752, -1862, + -1635, -1067, 994, 5212, 2719, -264, -2021, 1824, + -2110, -619, 1538, -397, -332, -153, 860, 1281, + 6568, -1790, -2459, -1707, -1708, -799, 294, 89, + 475, 992, -1668, -1819, -2010, -1623, 2079, 3255, + -388, 591, 1477, 581, -1544, 476, -1825, -959, + -1296, -1037, -453, 1146, 4693, 839, 2027, 3021, + -1731, -1746, -1964, -1115, 1197, 102, 164, -162, + -2301, -1281, -2022, 3983, -1122, -281, 85, 352, + 1042, 1599, 6463, -93, -2010, -1988, -2282, -2189, + -1915, -1721, 17, 4694, 424, -998, -111, -1995, + -1246, -1176, 78, -116, 1951, 3059, -1974, -1783, + -2243, -1238, 3935, -928, -15, 1265, 1536, 1907 +}, + +.shape08 = { + 5279, 1101, 12974, 5624, 2029, 3853, 5918, 1516, + -2905, -224, -92, -819, 803, 1091, 3091, -3355, + 152, -1214, -7317, -738, -8973, 546, 12035, -937, + 2216, 2113, 1214, -6577, 2006, -1661, -673, -5880, + 496, 454, 3400, 676, -322, 11388, 634, -1169, + 12556, -5804, -7724, 588, -6801, 1080, 354, -1681, + -942, 1926, -487, -580, 156, 79, 15253, 667, + 1155, 655, -719, 1999, -785, 214, 2822, 1020, + -1967, 73, -387, -137, -15225, -1552, -357, 2830, + 2140, 3070, -2552, 2410, 1230, 4131, 999, 248, + 531, -909, 3948, 12858, -8056, 2205, -2837, -171, + -1633, -129, -93, 1852, -1920, 157, 9647, -84, + -150, -1365, -1522, -13197, 6168, -3195, 5890, -1724, + -6407, -1340, -7435, -621, -5732, -2895, 145, 3974, + 728, 9840, -494, 7357, -394, -13614, -256, -1930, + 468, -266, 8001, -153, -365, 7652, 135, 1400, + -3869, 1091, -4935, -2884, 1259, 6819, 1025, -6667, + 1079, -9794, 6827, -4166, 1108, 1149, 18861, 593, + -177, -1067, -644, -2164, 4727, 85, -101, -10805, + -247, 8918, 2261, 5475, 756, 3018, -6535, 1941, + 359, -4229, 1206, 958, -878, 554, -18780, 2289, + 4906, -7412, -7685, 7932, 965, 2460, 4423, -563, + -3668, -3482, 3307, -1737, 971, -7480, 10742, 1978, + 2365, 20, -3625, 466, 2056, -6602, 9396, 3145, + 3162, 1857, -630, -6905, 1660, -3024, -2159, 1109, + 1282, 2767, 210, -2203, 3099, -7889, 1805, -13115, + 988, -6235, 1566, -1399, -9612, 1821, -519, -57, + 3428, -14024, 1141, -2542, -9396, -17, 440, -8591, + 2271, -7811, 1891, -935, -4330, -1303, 362, 426, + 319, 1176, 3176, 2202, -14308, -619, -2942, -2271, + -531, -652, 345, 17681, 1453, -1561, 341, -2077, + 933, 433, 1529, 463, -1095, 4912, -840, 16266, + 973, 1732, -718, 6702, -3659, 4037, -704, -2707, + 1423, 1291, 2300, 149, -933, -1338, 2019, 6173, + 481, 14937, -364, 3896, -443, 992, -896, 378, + -226, -1505, 268, -428, -2622, -289, -2069, 10472, + -3880, -5330, 385, 3053, -4642, 1525, -1557, 716, + 2504, 848, -450, -2018, -458, -705, -7120, -543, + -2138, 2548, -351, 737, 12906, -1012, 63, 15357, + 332, -837, -225, -1299, 2843, 1334, -669, 2083, + -707, 1171, 8219, 2190, 10567, 1370, -1376, -2919, + 2108, 10098, -388, 4442, 164, 490, 7580, 26, + -1848, -2919, 640, 4758, -108, 8194, -1325, -2314, + 447, 5178, -1095, 9902, -693, -3624, -223, 690, + 10495, 776, -919, -1621, 2046, 469, 1454, 3681, + -1090, -1776, 1457, 212, 2054, -994, 698, -496, + 22347, -623, 254, 960, -4073, 531, -2572, -14393, + -1022, 258, -3667, 994, 15242, 5078, -3618, 1925, + -1229, -1754, 1715, 4358, 1286, -2360, -4590, 1824, + 7864, 1423, -2146, -2763, -10635, 474, -829, 1159, + -157, -54, -158, -29, 202, -383, 285, -2, + 862, -364, 415, -123, -145, -9733, 1167, 10199, + -1408, -2992, 2131, -412, 4743, 2992, 3555, -617, + 9606, -2831, 2357, 5300, 625, -678, -500, -128, + -56, -6327, -1122, -2567, 1904, -1804, 709, 3194, + -148, -1371, -6534, -1748, -1490, 14159, 1466, 1395, + 1101, -2725, 503, 68, -1486, 0, 211, -1218, + -3, 20920, 1709, -208, -839, 4574, -6084, -6557, + -103, -984, -375, 8409, 1715, -2170, -5003, -3296, + 13482, 1211, -4159, 3496, 1040, 6925, 213, -1398, + 441, -1231, -814, 842, 1574, 1145, 1359, 437, + -1777, 20566, 259, -4573, -1412, -158, 10144, 1269, + 1405, -12631, -1104, -615, -15892, 355, -3795, -1158, + 3241, 252, 232, -179, -617, -2038, 285, -1014, + -1248, 1835, -1558, 1266, -10207, 629, -312, 11376, + 154, -288, 5915, -353, 60, 2695, -853, -103, + 15659, 2403, -1184, 3, 9236, -10953, 4434, 829, + 2563, -164, -848, -646, 7247, 895, 1726, -752, + -979, 1053, -971, 318, 2180, 927, 804, -262, + 446, 3261, -4926, -4523, 1247, 2039, 12770, -1191, + -1310, -5574, 4763, 657, -4139, 10821, -805, -1109, + -3189, -1721, 167, -10022, -1877, 2123, 328, -7048, + -2130, 2431, 1522, 3209, -8448, 1810, -5412, 9815, + -3677, 6575, -6237, -929, -434, -2375, -13586, 3497, + -1140, 1227, -6354, -507, 329, -1690, 1079, -880, + -3743, -4021, -4645, -6053, 958, 4594, -1122, -11628, + 1537, -3418, -1242, 133, -9335, 1611, -432, 10733, + -885, -468, -13466, 690, 214, 8968, 3441, 5451, + -219, 5492, -377, 409, 3812, 2450, 508, 6542, + 3824, -3705, -514, -8262, 1537, 7969, 946, -2869, + 8762, 417, 5094, 2104, 6694, -342, 1259, -4779, + -1445, -1519, 333, 4385, 652, -386, -580, -1892, + -873, 1862, 2704, 13837, -5415, -1975, 5881, 7150, + 8272, -6412, 704, 1854, 257, -3746, -9789, -9634, + -924, 1393, -3237, 259, -56, 4390, 4902, 1172, + 5114, -2616, -4409, -1180, 4691, 7400, -625, 8873, + 6846, -1224, -213, -5296, -3504, -147, 17828, -1347, + 3251, 1702, 1440, -2364, -491, -227, 1765, -446, + -9746, -2019, 11287, -195, -9559, -312, 888, 5789, + -1753, -11069, 2537, -265, -1762, -779, -8501, -308, + -89, 1973, 3640, 17344, 1326, -689, -398, -3820, + 2167, 229, -636, 2142, -6587, -751, 13243, 465, + -5946, -202, -968, -1060, -240, -10626, 3405, 1302, + -1263, 972, 11351, 100, 2266, -930, -2108, 5350, + -3186, 11130, 2073, -5616, 650, 2000, 1048, 5628, + -531, 674, 8453, 1030, 1152, 12095, 352, 409, + -1029, -1236, -190, -5724, -589, 3550, 1958, -14081, + -339, 1672, -1659, 4518, -75, -638, 5501, 277, + -578, -2185, 157, 2066, 8634, -2403, 1617, -12487, + -1881, 8273, 179, -2152, -1294, -512, -415, 456, + -141, -125, -405, 132, 49, -1978, -19085, -451, + -1480, 324, -5397, 235, -1217, 346, -1258, 3540, + 10075, 10291, 5060, -2057, 6156, -992, 9344, -3718, + 4296, 895, -8464, 341, 1426, 648, 1494, 2895, + -3760, 10139, 15531, -984, -1550, -1319, -1542, -119, + -517, -185, -3368, -9279, -3455, -4257, 1092, -10120, + 5072, 3099, 986, -2562, -12068, 1932, 6489, 950, + -2417, 1362, -567, 591, -715, -515, 3506, -726, + 6319, 214, -364, 3611, 1895, -2005, -273, 1513, + 2379, 475, -4855, -527, -11493, 27, 4343, -2394, + -639, -744, -2601, 10917, 1910, 2449, 1238, -2175, + 5322, -4054, -40, 4274, 684, 8152, 966, 10882, + -13, 4253, -287, -3192, 548, 2020, 189, -6894, + 797, 2160, 579, 4084, 1767, -4011, -640, 7697, + 791, 945, 1230, 6491, 1508, -3762, -433, 11340, + -129, -1131, -5121, 3148, 1544, -7648, 1866, 9660, + 2365, -2110, 782, -82, 3666, -701, 303, 298, + -1934, -125, -1427, -17589, -1188, 175, -7046, -488, + 1121, -6594, 489, -1551, 14349, 1499, -544, 17132, + 198, 2516, 2479, -978, -214, -3399, -1223, 2094, + 130, -1020, 1049, -710, 12801, -498, 297, -1365, + -187, -3169, -123, 9019, 958, 221, 14234, -590, + 961, 3092, 8, 255, -4586, 1789, 2522, -12577, + -91, -822, -805, -714, 5298, 1299, 3306, -1288, + 13176, 235, 1754, -67, 1912, -604, 3240, -2048, + -200, 772, -173, -996, 1368, 2380, 294, 763, + 19665, -196, 528, 182, -2394, 923, 749, -13578, + 855, 589, -9553, 0, 5737, 10399, 9147, -1655, + -3735, 1246, -2429, -1147, -2199, -2953, 614, -1404, + -449, -8524, -2271, 5001, -9517, 2940, -204, 3625, + -258, 32, 1521, -299, -1786, -2836, 1523, 2427, + -835, 3139, -197, 3351, -279, -14766, -1267, 5169, + -1039, -10967, 58, 641, -767, -1193, -591, -716, + -834, 8109, -915, -711, -10427, -1680, -638, 2643, + -850, -258, 10452, 362, -5394, -349, -14727, -655, + 1040, 1722, -10265, 551, -283, 9888, 408, -400, + 5980, 1878, 781, -923, -667, -789, -348, 624, + -260, 14515, -804, 1721, -2, 5356, 1802, 1218, + 498, 1871, -988, 16295, 4163, -2342, -4290, 3121, + 3269, 112, -3492, 1124, -1496, 1863, -1426, -1090, + 1598, -197, 1160, -1660, -1094, 477, -4104, -396, + 1605, 26134, 746, -12876, 2320, -1690, 8626, 39, + 1341, -1254, -1890, 2555, -13996, -1218, 3827, 1216, + -909, -180, 1720, -87, -143, 989, 340, -1426, + -4029, 3141, -9424, 466, -8227, 422, -7379, 2038, + 401, 98, 3602, -1223, -946, 2469, 1159, 727, + -268, 467, 203, -11079, 3850, -3469, -1965, -1857, + -1415, -2477, 3173, 7352, 9483, -5541, 6212, 1886, + -3868, 2728, 577, -5057, 321, 972, -77, 47, + 227, -38, -1037, -222, -347, -341, 1179, -948, + 592, -7485, 2218, -5955, 2698, 11798, 197, 6260, + 1711, 998, 8, -6223, -1184, 1145, -1781, 1376, + 1394, 388, -689, 2279, 6511, 2542, -4903, 3917, + -790, 535, -1903, -4448, 4216, -22, -6715, 5204, + 4807, 3193, -1064, 5403, 4503, -2434, -4296, 1383, + -1514, -4103, 747, 3928, 2987, 9513, 2492, -8691, + -993, -2667, -40, -170, -3116, 611, 2367, 16297, + -1256, -1404, -3462, 466, -524, 5464, 491, 706, + -7491, 2027, 373, -4086, 1620, -7789, 704, 5002, + 1706, 8325, -851, -9883, -3072, 4475, 2696, -8549 +}, + +.shape11 = { + 44, -10592, -832, -413, 612, 530, 379, 753, + 1442, -3006, -858, -1077, -12018, -196, -771, -1142, + -628, -2938, -439, -3323, 20, 12513, -2462, -1270, + -57, -8417, -690, 790, 276, 2349, -341, -1644, + 230, -2176, -202, -14725, 170, 1725, 3030, 683, + -231, 641, -242, -3252, 110, -1440, 2886, -1467, + -1155, 14395, 297, 52, 240, 3938, 9880, -7555, + -1214, 3351, 129, -1269, -168, 669, 13765, -1289, + -465, 10017, -632, -328, -276, -33, 31, 18883, + -148, -131, 525, 1669, 2288, -203, 868, -660, + 248, -409, -91, 295, -9174, -1484, 929, 2824, + 1097, -3205, -113, 2712, -1544, 527, 1419, -963, + -388, 691, -16791, -84, 72, -3802, -357, 1633, +-15182, 62, -6024, -742, -5396, 4470, -198, 1, + 1428, -1691, 18715, 1402, -2539, -375, -8455, -901, + -147, -3274, 9359, -277, -8941, 714, 2834, 2924, + -6326, 907, -123, 10487, -484, -4772, 877, 9840, + -505, -7562, 301, 671, 116, -371, 3740, 359, + 385, -5145, -908, 156, 9639, 3782, -9688, -4214, + -945, -7685, 334, 2185, -1342, 388, -1741, 278, + -231, -912, 905, -1039, 598, 2049, 662, -198, + 22378, 166, 116, -1699, 335, -8380, 1279, 1536, + 14955, 1254, 190, -2519, -608, 364, -561, 5748, + -1178, -923, 3183, -59, 13880, -2530, 241, -564, + -319, -7510, -9, -124, -20346, 305, -25, -400, + 222, -16943, -488, 802, -1685, 3323, -6198, 1000, + -903, -846, -387, 462, 847, 526, 10024, 2020, + 2090, -9563, 1416, 169, -12182, -428, 10388, 869, + 1068, 2201, -1041, -3180, 152, -646, 4, 4017, + -1069, 307, 5283, 3021, -13662, -493, 9, 542, + 152, -2617, -3870, -514, 13497, 1180, -603, 1255, + 2396, 7418, 8902, -11165, -2626, -5719, 1764, 858, + 1105, 1476, -1764, 1969, 977, -1738, -928, -13940, + 1444, -4157, 836, -12243, -369, -256, -15681, 5320, + -5170, -509, 353, -1581, -1455, 965, 716, 209, + -883, -317, -1961, 9128, -8197, 2173, -2434, -1126, + 4066, 1025, -16663, -7013, -147, 1617, -745, -3205, + 1496, 1822, -1199, -2999, 117, 619, -20002, -232, + 142, 3207, 561, -292, -1635, 1035, 37, 2712, + -243, -8269, 305, -2601, 495, 14516, 831, 260, + -54, 4217, 675, -1632, 4962, 793, 1066, 133, + -344, -12428, 95, 6164, -1298, -1860, 3622, -467, + -867, -1178, 11053, 118, -36, -6997, -763, 16019, + 16, 2459, 306, -820, -1135, 847, -709, 928, + -164, -293, -5736, 543, -11548, 5389, -2012, 300, + -228, -1043, 5107, -558, 1187, -140, -13034, -1571, + 740, -4967, -432, -6289, -1778, 3449, -337, -12607, + 344, -3790, -1598, -274, -346, -1494, -108, 325, + -1215, 819, 404, -568, -286, -21364, 15495, -2297, + 606, 117, 10, -193, -972, -292, -573, -1155, + -1289, -1025, 472, 1154, 843, 187, 586, 20569, + -5, -236, -1181, -1092, 700, 891, -603, -601, + 21648, -449, -193, -1103, -298, 2084, -251, 449, + -1414, 17168, -391, 104, -5465, 401, 8839, 781, + 1741, 201, -369, 466, 12358, -636, -945, 3928, + -605, -17445, 5020, -1289, 977, -6202, 1783, -507, + -76, 267, -31, -2731, -1560, -1225, 1348, 11176, + 1669, 754, 1671, -4038, 151, -371, 7283, 243, + 1387, 126, 1007, 1292, -15, 696, 282, -2623, + 1065, -1026, 191, -632, -132, -12957, -32, -1697, + -422, -240, 1352, 10252, 1067, 8296, -1244, -9, + -301, -3014, -249, -372, 10731, 535, 2147, -8959, + 346, -408, -8329, -1905, -48, -8176, 2782, 412, + 1425, -946, -748, 1095, -1370, 9086, -99, -143, + 68, -544, 264, 494, -377, 13, -618, 237, + 193, 3549, 317, -168, -7148, 2351, -244, -13240, + -3355, -2322, -533, 9554, 6906, 124, -694, -901, + -2762, 207, -915, -2520, -143, 8544, -678, -2788, + 12926, 791, 1296, 4861, -1470, 889, 3675, 806, + 290, -11146, 422, 9217, -31, 1608, 140, 3939, + -6903, -276, -704, 2353, -344, -1038, -230, -177, + 670, -617, -129, -857, -8231, 638, -411, -252, +-15709, -1218, 210, 288, 542, 533, -9087, -10493, + -624, 1175, 611, -230, 746, 1455, -590, 830, + 1756, -15800, 823, -1077, 788, 1071, 468, -1654, + 660, 983, -9697, -1300, 662, 2053, -281, 12949, + 389, -915, 197, -1742, -4587, 1746, 707, 1625, + 9021, 2204, 759, 1303, -428, -220, 41, -5499, +-16080, -193, 443, 443, -78, 889, -561, 5629, + -1073, 7019, 222, 1661, 1190, 1108, 94, 5624, + -3796, 407, -706, -122, 744, 363, 1648, -10896, + 595, 953, 85, -267, 195, 851, 17173, -636, + 243, 907, 2029, -700, 351, 1495, -157, -575, +-11664, 1252, 8341, -616, 3708, 5693, -6, -1753, + 1072, 863, -823, -4278, -12043, 750, 597, 3145, + 38, -8140, 3136, 290, 7, 11084, -876, 1842, + 175, 3458, 460, 1615, 11698, -827, 16, -12482, + 428, 411, 2625, -1352, 142, 529, 229, -48, + -965, -145, -592, 655, 499, 22095, 22141, 37, + -1875, 701, 45, 724, 1111, 1631, 262, -252, + -9092, 5325, 408, -637, -612, 647, 1268, 834, + -510, 603, 199, 816, -9904, 9533, -1580, 2669, + 1824, -2092, -701, -271, 7489, 46, -3295, -844, + -304, -226, -260, -692, -5, -527, 37, -49, + -1542, -69, -1087, 20519, 367, 1, 3487, 2535, + -5110, 642, 1223, -2130, -2894, 1752, -1618, 9732, + -1633, 6904, 137, 654, -358, 355, -21, -277, + -68, -188, 132, 530, 372, -315, -11498, 221, + 815, 2480, -1398, -123, 353, 3114, -12025, -1212, + -1111, 916, 6452, -1880, 1867, 307, -66, 1857, + 138, -980, -3088, -174, -41, -393, -656, 847, + 15824, -379, 358, 672, -389, 920, -21145, -393, + 350, -574, 1005, -2083, 26, 79, -203, -7967, + -3302, -5805, 772, -302, 2104, -1240, 13710, 6816, + 2282, -3709, -1512, -81, -2216, -3005, 444, -795, + 751, 2163, 20751, 780, 542, -480, 624, -425, + 769, 2474, -5903, 399, 10564, -112, 69, -1409, + 1885, 2339, 67, -620, 196, -2432, 6046, -1673, + 6512, 809, 7904, -516, 4278, 223, 359, 16512, + 1224, -480, -505, -735, -502, -593, -4565, 1914, + 122, -531, 1442, 464, 69, 292, 410, -581, +-19848, 1059, 132, 1392, 5917, 705, -7706, 2496, + -1487, -791, 11939, 185, -265, -2412, 630, -8028, + 1434, 10315, -1541, -3756, -2403, -1918, 1050, 8057, + 234, 13546, -92, -2172, -671, 11631, 103, 116, + -171, -4604, -267, -602, 15, 454, 6859, -2151, + -8707, -1664, 61, 2518, -969, 903, 1209, -1435, + 13531, 590, 236, -821, 598, 1186, -7690, 134, + -1005, -18177, -148, 519, 900, 951, 406, -3584, + 47, 9439, 1418, -797, -3353, -703, -1798, -1244, + 291, -2784, 14612, 2029, -161, 1040, -4130, 3064, + 1721, -2898, 269, 3367, 1379, 14359, -690, -655, + 2010, -4935, -681, -2606, 11651, 748, 101, 13593, + 629, 28, -540, -854, 1405, 558, -8785, -1016, +-13043, 121, -556, 4959, 1694, -720, -138, -3897, + 182, 1938, 844, 919, -683, 12042, -1101, -155, + -1375, -1509, 11, 220, 821, 21721, -367, -634, + -1468, -174, 1002, -1203, 318, 11672, -2114, 2472, + -1701, 5932, -661, 1094, 2500, -5609, 254, 437, + -911, -1611, -8005, 217, -1139, 1321, -10713, -2183, + 1163, -890, -622, 12820, 1021, -13578, 1040, 3216, + 592, 686, 737, -2881, -1693, 3995, -455, 4666, + -4124, -9316, 2061, 10645, 271, 264, -6829, 641, + 2061, -6683, -512, -747, -9131, 2445, 343, -9944, + -2888, 607, -10855, 871, 418, 504, 936, 1079, + 273, 400, -17752, -391, -1543, -6193, 1482, 737, + 2096, -982, 167, 972, 336, 1063, -1272, -1602, + -1907, 9, -191, -15207, -119, 4047, 1479, -1405, + 526, -18462, -627, -1996, -1022, -1544, 312, 7972, + -227, 797, -5204, -2160, 391, -423, 257, 3836, + 442, -1931, 22, 143, -203, 362, -73, 15679, + -289, -1445, 577, 858, 11408, -1970, -1022, 1550, + 882, -3699, -2697, 3978, 600, 86, 3858, 8683, + -7681, -4856, 4051, -1321, -587, 46, -499, -354, + -655, -15717, 67, 490, -2670, 474, -1374, 5601, + 60, -17615, -808, 87, 367, 579, 1057, 1020, + -394, 1181, -189, -10846, 763, 2635, 282, -3279, + -866, -15257, -449, 112, -15577, 227, 269, 13964, + -1273, 1513, -1487, 195, 319, 2527, -286, -5883, + -5360, -959, 2791, -3335, -945, -1985, -903, -11418, + 8525, 669, 6106, 153, -1169, -1198, -553, 7037, + 528, -4237, 717, -214, 1824, 10108, 961, 9077, + 1899, 10407, -207, -29, 355, -6794, 111, -13627, + 1361, -3577, 291, 4534, 2209, -1579, 109, 523, + 456, 10990, 31, -448, 385, 1481, 2, 15266, + 798, 5759, 860, -16424, -1315, 1631, -456, -977, + -180, -2593, 1191, 5959, -32, 8112, -506, -7766, + -1871, -15310, 662, 196, -20401, 925, 446, -2035, + -620, -686, -249, -2517, 423, 703, 633, 828, + -182, -37, -406, -149, 821, -22255, 652, 522 +}, + +.shape16 = { + -786, 193, -15441, 200, 1050, -16545, -41, 329, + -869, -170, -858, 2725, 217, 447, 2107, -23, + -387, -10280, -383, -320, 387, 16012, -79, -967, + 3528, -2123, -537, -636, -1761, 949, 100, -17, + -446, 261, 22527, 331, 26, -87, -206, -2292, + -1178, -164, 598, 147, 889, -14487, -2823, -1280, + -1892, 33, -1763, 993, 4807, -953, 2181, -588, + 59, -296, 218, 291, -104, 495, -1092, 2232, +-14904, -983, -2919, 795, -17207, -2045, 2988, 597, +-10312, -718, -2196, -5822, 847, 1304, -757, -4714, + -148, 831, -734, 806, 4348, -308, 244, 566, + 2706, 604, -748, -864, -568, -219, -128, -688, + -218, 110, -29289, 482, 76, -1447, -142, -417, + -253, 8124, -19775, 990, 4546, -1012, -8082, 133, + -1612, -2243, -3788, 1568, -2892, 852, -1642, -3479, + -23, 1300, -564, -1037, 249, -14533, -43, 321, + -680, 10, -417, 23426, 397, -108, 1843, 180, + 11976, -9613, 353, 3768, 130, -1035, 4340, 218, + 596, -224, -779, -1680, 1326, 152, -971, -9725, + -355, 5328, -459, 16242, -438, 926, 6210, 1912, + 769, 2621, -148, -1008, 517, 341, -3594, -965, + 11383, -874, -16949, 1167, -3371, -1655, 586, -132, + 3990, -770, 211, 246, 514, -166, -734, 30408, + -258, -521, -20, 339, 499, -2572, 2110, 272, + 1357, 123, 2841, -320, -31, -444, -501, 215, + -42, 595, 108, 484, -223, 937, 475, -72, + -319, 75, -205, -978, -9155, 145, 2020, -3, + 2438, 4046, -1281, -875, 1532, -598, 12288, 369, + -2046, 343, -778, 1769, -2589, -641, 17437, 1793, + -592, -1954, -1607, 6184, 3440, -512, -2710, -1330, + -127, 8765, 83, -243, -315, 709, 256, 1176, + -1198, -463, 970, -302, -568, -997, -1022, 159, + 11008, 27, 13074, 1523, -3239, 2330, -4808, 6115, + -9933, 1449, 2153, -3111, 1780, -731, 121, -881, +-14289, -265, 566, -611, -253, -2965, 250, -105, + -66, 2570, -1922, 2712, 1907, -2025, -454, 173, + 1463, -29, -31955, -113, -1751, -3353, 254, 1001, + 6781, -29, -639, -1289, 288, 498, -21505, 48, + 109, -2151, -223, 1360, -3430, 658, -4185, -1706, + 1244, 1899, 124, 12, -35, 289, 382, 433, + 261, -131, 54, -646, -280, 86, 180, 153, + -169, -20242, -95, 734, -524, 77, 102, 8468, + -421, 29, -3, 51, 1526, -600, -264, 355, + 1949, -985, -291, -86, 10212, -789, -393, -182, + -51, 946, -16716, -954, 1179, -2745, -509, -4774, + -587, -608, 7657, -509, -388, 987, 109, -218, +-17579, -524, -467, -1643, -444, 1430, 2541, -124, + 1785, 27, 7905, -73, -3135, -1241, -254, -2114, + 1175, 780, -50, 4055, 535, 438, 32, -113, + -260, 81, 1102, -59, 29188, -48, 212, -29, + -344, 559, 856, -483, 608, -40, -1498, 112, + 10374, 1198, -434, 4053, 1286, 236, 1823, 16046, + 592, 1583, 78, -5243, 1311, 456, -1342, -546, + -353, 13289, -333, -529, -20859, 183, -167, -1368, + -338, -690, 4248, -205, -666, -634, -1653, 1174, + 234, -18622, 891, 284, -2632, -1516, 289, 11242, + 727, 133, 284, -323, -1370, 908, -13169, -412, + 1155, 410, 610, -3072, -8220, -637, 242, -647, + -2072, 16041, 2292, -8009, 351, -3137, -3075, -1051, + 4569, 125, 23, 1281, 2487, 520, -209, -688, + 205, -1248, 246, -601, 533, -12209, -2298, 826, + -2762, 45, 15123, 721, 1128, 798, -676, 349, + -153, 263, 89, -854, -24, -350, -227, 157, + 587, -240, -185, 663, -32328, -148, -204, -2396, + -597, -344, 8104, -280, -375, 264, 648, 741, + -290, -321, 263, -569, -381, 167, 1757, -29636, + 30, 393, 398, 590, -242, 81, 1601, 3683, + 787, -336, 675, -1080, -713, 261, 18420, 1760, + 609, -4610, -551, 2790, 19807, 1347, -125, -9412, + -261, 548, 1056, 179, -917, -181, 12637, -267, + 621, -11908, 1366, 76, 5875, -742, 394, 155, + -370, 2481, 46, -15392, -344, -9750, -1353, -2242, + -1685, -1286, 2320, -2176, -1729, 705, -1582, 1590, + 1603, 21129, -3555, 2192, -883, 3438, 233, 1965, + -537, 399, -4818, -4085, 559, -292, 1290, -2700, + 10, -301, -1865, 226, 52, -1346, 306, 316, +-12281, -525, 285, 9631, -2, -849, 1620, 128, + 176, -1021, -473, 7929, -133, 2459, -33, -1517, +-22047, -2300, 98, -3513, 334, 4617, -193, -1309, + -1279, 738, -443, 95, 406, 660, -705, -54, + -39, 26396, -766, 249, -2423, 7759, -689, -3909, +-17404, 65, 1849, 945, 15907, 1386, -433, -831, + -6349, -3919, 1870, 8096, 311, 15043, 1709, -315, + 1288, 7522, -215, -5072, 1246, -1486, 3762, 4526, + 1517, -1936, -543, -263, 771, -10215, -425, -5098, + 59, -266, -1012, -380, -2131, 630, 405, 665, + -4550, 1403, 8, -46, -879, 398, -532, -185, + -286, 921, -65, 378, 669, 174, -15280, 91, + -776, 8480, 2463, 184, 2065, -666, -561, 4122, + 594, 732, 4007, -852, -71, 194, -126, 1765, + -1570, 968, -257, -288, 950, 27482, -333, 370, + -1429, 285, 558, 11245, -135, 565, 1296, -261, + -62, 600, 1455, 1457, 820, 357, -1203, 169, + 16611, -893, 359, 231, 418, -547, -95, 3866, + -511, -6344, -205, 923, -239, -16205, -1619, 217, + -3362, -6342, -1551, 649, -492, 264, -55, 170, + 16992, -91, 306, 43, -2770, 582, -1740, 77, + -882, 268, -515, -45, -6093, 24, -5596, 9034, + 284, 3211, 846, 1158, -1118, -604, -514, 1402, + -493, -938, -3892, 242, 643, 1421, -434, -406, + -102, -88, -11733, 161, 518, 978, 1508, 248, + -1036, 1407, -396, 293, 1154, -1435, 495, 8243, + 20, -845, -5373, 659, 2366, 29148, 145, 603, + 4088, -251, -2841, -2526, 20682, -1357, -2454, 660, + -125, 347, 11772, -113, -357, -2181, -1234, 1908, + -432, 16555, -248, 822, 15516, -158, -653, 1573, + 93, -2730, -1111, 958, -1550, -1153, 17, 610, + 781, -372, -1640, 144, -135, -1171, 22140, -427, + -26, 690, -800, -1497, -300, 5438, 390, 11304, + 9253, 1098, 5564, -9, 3856, 965, 2016, -12797, + 1687, 915, 3687, 539, 2496, 702, -1324, -71, +-12955, 7456, 4626, -848, -1815, 831, 2151, 7921, + -3000, 123, 1189, -1489, 222, 4973, 1936, 54, +-10527, -1238, -1157, 628, 14112, -2164, 1478, -985, + -4102, 635, 225, -311, -609, -1015, 301, 507, + -85, 443, 186, -552, -711, -16988, -1327, 220, + 565, -1673, -543, 18633, 331, 127, -342, 22, + -77, -360, -439, -501, -1848, -1147, -483, 1133, + -351, 41, 908, 502, -658, 474, -430, -11348, + -1, -531, 451, 709, 227, -978, 348, -265, + 269, -376, 2511, -188, -111, -387, 809, 1009, + 1570, -755, -11463, 667, -895, 446, 276, 145, + -513, -117, -462, -340, 1457, -963, 191, -788, + -150, -979, -507, -27540, 122, 368, -73, 10051, + -465, 642, 507, -6828, 241, -5025, 1598, -1174, + 2373, -2272, -1910, -108, 15, 166, 2, 10518, + 933, -12716, 510, 778, -424, 414, 4899, 759, + 862, -438, -886, 457, 304, 23639, 136, -203, + 478, -565, 244, -541, 2419, -773, 1107, -217, + 1579, -1037, 476, -97, 995, 17973, 161, 16466, + -178, -718, -1606, 947, 1991, 2266, 1249, 2708, + -611, 1424, -142, -53, 36, 509, 26159, -144, + 357, -37, -234, 587, 311, -509, -1639, -332, + -1618, -382, 302, -8657, -68, -30, 545, -12834, + 158, 158, 135, 621, -354, -871, 451, 1220, + -31, 2, -13414, 60, 3, -380, 541, -44, + 552, -366, 155, -462, 61, -232, -15426, 317, + 688, 1121, 2933, 7151, -168, -9167, -2521, 745, + 2792, -10448, 569, -3823, 630, -4626, -95, -416, + 828, 259, 72, 171, 635, -250, -128, -426, + -153, 260, -771, 314, 235, 26, 32281, -343, + 751, -1443, 324, -684, 1900, -1334, 2022, 30, + 1073, -2406, 2080, -485, -320, 15328, -860, -529, +-16444, -219, 1736, -149, -160, -828, 1089, 413, + 241, 3720, -90, 146, 1109, 243, -321, -256, + -68, 88, -50, 571, 1179, -25030, 104, 929, + 35, 529, 117, -13724, 734, -1344, 456, 5586, + 1566, -12573, -840, -1617, -2494, 1791, 1901, 3066, + -2159, -414, -3856, -9894, -1608, -657, 15355, -773, + -9217, -658, -972, 4730, -2986, -3478, -757, -1416, + -3702, 18089, 629, 7061, 124, 5843, 158, 19017, + -2204, -6976, 1629, -5657, 1101, -1859, -1425, -548, + -1132, -5043, 1074, -592, -196, 1902, 22705, -1228, + 214, -685, -2036, -2368, -315, -914, 533, 218, + 1091, -627, 2031, 13922, 104, -450, 4494, -498, + -361, 24734, 623, 1029, 2437, -1123, -5092, -6551, + 438, 16562, 375, -13102, -193, -2004, 3556, 179, + 1832, 2086, 798, -534, -195, -7105, 796, 3969, +-12269, 1570, 4273, -2692, 1240, -2901, -2045, -2453, + 372, 613, -548, -245, 687, 258, -8964, -1500, + -1519, -993, 17571, -357, 916, -1202, 1752, 2081, + -536, -3185, -1062, 19335, 721, -9958, 1052, -872, + 248, -3133, 456, 1641, 149, -11, 2955, 310, + -3178, -18823, 497, -971, -6587, -1380, 351, 106, + -43, 607, -4754, 213, 1030, 5377, -804, -2557, + 850, 1081, -706, 1325, -14922, -794, -14060, -1953, + 891, -3296, 329, -510, -1126, 1113, 1753, -411, + 1769, 429, -185, -1020, 194, -106, 11470, -591, + -272, 422, 337, 524, -150, 822, 51, -120, + 7193, 802, 640, -140, -42, 28125, -1020, 285, + -465, 3195, 69, 482, -953, 262, -7672, -373, + 5158, 5625, -3003, 550, 5371, 5619, -2200, 5392, + -804, 135, 1300, -3610, -23, -433, 13503, 224, + 911, -14421, -502, -2151, -1667, -1933, 2888, -277, + 547, -989, 3115, -32, -680, -164, 804, 412, + 62, -154, -190, 156, -10938, -360, -88, 843, + 328, -773, -267, -12668, 856, 1496, -243, -586, + 736, -2175, -677, -3069, 7480, -1764, -4024, -2569, + 1805, 194, -6814, -1135, -237, 2682, -156, -890, + 1285, 368, 1802, -683, -163, 1191, -13063, -496, + -335, 17482, 746, 818, 48, 21419, -598, -1753, + -1169, -2135, 40, -9114, 592, -3912, 1980, -264, + -304, 8138, -185, 286, -3024, 48, -1630, 909, + 661, -662, 18085, 240, -201, 69, 192, 305, +-22167, 692, -1135, -996, 398, -74, 18553, -958, + 1223, -5578, 508, -352, 1234, -450, 497, 780, + 79, 51, -221, 255, -26, 13352, -170, 231, + 590, 169, -733, -812, -65, -219, -20939, 200, + 35, -177, -454, 632, -267, -407, -120, 623, + -176, -664, 715, -23, 318, 148, 1125, 16, + 709, -21687, -230, -413, 1398, -1235, -283, 1615, + 175, -299, 349, 400, -112, 21762, -665, 364, + 1089, 1303, -54, 523, -381, -1312, 48, -886, + -1260, 408, 415, -8349, 7115, 180, -774, 3508, + -971, -255, -195, 81, -2674, -977, -355, -1500, + 178, -2081, -4432, -1014, 340, 5818, 138, -106, + 16917, 1203, 349, 3271, 961, 363, 6008, -6043, + 3736, -730, -4201, -514, -6131, -68, -14935, -1781, + -3898, -40, -18944, -461, -1694, -1269, -755, -81, + 2369, 484, 531, 14114, 85, 32, -10142, -142, + 600, -2374, 375, 675, -2663, 155, -947, 6427, + 11476, 1253, 5049, 1063, 2003, -1608, 2463, -2168, + -1128, 1079, 383, -996, 368, 1208, -3554, -959, + 4596, -1209, -4154, 1270, 9365, -2775, -1751, 998, +-20023, -347, 1505, 218, -142, 342, -128, -523, + -159, 75, -467, 257, -133, -142, 712, -621, + 428, -29584, 13, 402, -455, 119, -483, 1121, + -461, 960, 807, -46, 297, 14856, 221, -356, + 221, 15037, -4744, -2555, 447, -1418, 1464, 1391, + -1404, -5812, 512, -2321, 9882, 242, -2298, -137, + -849, -3182, 9394, 1412, 1052, 1369, -904, -494, + -231, 1113, 1087, -13317, 768, -1178, -3011, 24, + 229, 164, -10170, 328, 308, -591, 213, -543, + -82, -790, -875, 794, -558, -7651, -573, 1266, + -2084, 2275, -187, 97, 384, -11830, -185, -472, + 1365, 11636, -1405, 360, -487, -440, -1820, -349, + -293, 285, 25, -139, -415, -540, -108, 1136, + -673, 230, 19202, -545, -542, 919, 1221, -518, + 196, -21900, 795, 115, -16, 459, 3339, -347, + -346, -186, -695, -267, -714, 185, 266, -1218, + 120, -249, 233, -110, -30412, 285, 219, 2256, + 536, -442, 673, -1487, -477, -60, -1806, 183, + -7195, -577, 2230, -7594, -3230, 65, 22963, 111, + 390, 7134, -3716, -5123, -475, -32, -98, -466, + -118, -43, 74, -1071, -902, 1714, 4004, 26, + 97, 1680, 423, 252, 9667, 550, 354, -222, + 19, -224, -807, 365, 593, 363, -851, -28, + 553, 238, -481, 769, 279, 18367, -462, 286, + 4825, -141, 500, 20383, 1618, -31, -514, -2484, + -327, -8506, -705, -872, 530, -9997, -36, -431, + 2824, 3185, 1712, -318, 9513, -10065, 614, -503, + 389, 12830, -113, -15, -1007, -523, -1293, -2102, + -543, -1157, -583, 1228, 262, -674, -1847, -242, + 299, -12025, 547, -591, -9173, 275, 412, 2493, + 997, 1229, 1982, 27554, 245, 106, -1320, -153, + -423, -955, -449, 392, 824, 796, -1181, 1640, + -884, -70, 8789, 10021, -1806, 1019, 90, 1494, + 2071, -911, -1159, 212, 2207, -994, -2500, -497, + 92, -11544, -398, -774, 1474, 32, -671, -171, + -1250, -249, 1161, -654, -205, -36, 1733, 763 +}, + +.shape22_1 = { + 987, -6, -621, -220, -2438, -387, -535, -23, + -934, -68, -4985, 575, 483, 7243, -1075, 917, + 1739, -1832, -580, 1564, 131, -180, -1271, 3672, + 161, 1040, 1737, 2719, 1101, -185, -1410, 221, + -422, -8675, -753, -401, -5388, 13, 762, 1378, + 1113, 1768, -177, 3397, 2162, 267, 2261, -156, + 1708, -848, -79, -1819, -3159, -5548, -745, 7208, + -1039, 7555, -134, 2661, -2112, 2270, -1991, 441, + -6248, 246, 166, 2092, -1402, -242, -13600, -539, + 391, 2395, 11001, -981, 10906, -403, 823, 1647, + -294, 93, 504, -5448, 1213, -1849, -3077, 790, + -841, 12812, -11266, -1882, -805, -274, 1968, -49, + 1189, -80, -281, -40, 409, 2423, 581, -1362, + 207, -869, -589, 3294, -318, -4592, -476, 1014, + -135, -17999, -194, 807, -2946, -222, 44, -514, + -4407, -1201, 1155, -235, 98, 4432, -342, 2386, + 1402, -956, 3357, 1959, 4790, -139, -3494, -4280, + -589, -8422, 363, -746, 640, -360, -1007, -1100, + -7989, -12630, 1006, -1608, -864, -226, -915, -2032, + 1274, 596, 1864, 1067, 1597, 460, -2003, -5560, + -8020, 2354, 379, -3151, 44, 7024, -698, -2901, + 4976, 927, 1223, -93, 172, 189, 6639, -6082, + -726, -524, -3068, -3802, 16, -1039, -105, 2333, + -350, -306, -379, -832, 1282, 56, 3529, 562, + -603, 5954, 294, -1265, 8045, -3990, -169, -123, + -3267, 572, -879, 1562, -1185, 799, -9589, 407, + -590, 65, -2848, 433, -5547, -19, 7180, -7904, + -392, 323, -448, -4481, -3773, -5286, 1957, 226, + -2040, 3292, 2987, -1704, 2835, -149, 1435, 823, + 1775, -2769, 146, 234, -131, -15, 268, 37, + 139, 22, -196, 91, -3503, -5421, 24, -280, + 58, 370, 655, 1412, 113, 306, 16404, -234, + 315, -957, 72, -1129, 1993, -18719, -1415, 1349, + 2340, 541, 313, -1360, 31, 1441, -78, -9905, + -393, 367, -712, -2009, 372, -297, -123, 303, + -458, -323, 46, 8701, -1301, -8768, -43, 1818, + 212, -543, -5077, -8037, -2536, 702, 792, -381, + -272, 1941, 6320, -1871, -13938, -262, -2063, 108, + -861, 485, -440, 768, 5665, -302, 305, -13784, + 2889, -127, -94, 145, 1308, 7911, -8376, -643, + -596, 1357, -943, 1329, -84, -62, 1651, 391, + -2295, -5456, -357, -4611, 1361, 3961, -295, 642, + -698, 8614, 1613, -526, -120, -205, 17, -20171, + 1252, -261, 535, -1244, 92, -315, 878, 380, + 157, 3217, -493, -773, 513, -510, 11304, -899, + -27, 398, -6386, 659, -1001, -2737, -13295, 1219, + -1014, -193, 445, -2393, 344, -25, -599, -2848, + 884, 94, -11, -564, -36, 9939, -3530, 462, + -942, 10089, 824, 2994, -293, 71, 10167, -457, + 711, -964, -2128, 2530, 160, -2558, 2451, 1654, + -3828, 1560, 879, -1023, -8354, 851, -77, -112, + 19572, 2010, -1077, -1329, -1282, 1277, 252, -5622, + 4617, 58, -2315, -459, -1249, 92, 708, -737, + -3323, 182, 1557, -657, 546, -447, 19117, 1645, + -336, -26, -2041, 5926, 4746, -1866, 3922, 2798, + 5320, 7, 470, 842, 229, -567, 742, -3306, + 659, -871, -226, -2593, -1003, -1373, 595, -768, + 20658, 944, 1228, 279, -1531, -618, 361, -4019, + -343, -351, 7143, 293, 92, -2713, -269, -30, + -332, 4093, 216, 239, -563, 1943, -944, -2268, + 70, -209, 440, 1493, -446, 491, -362, 25, + -331, 433, -1585, 173, 1126, -3614, -234, -2649, + 1181, -641, -160, 3727, -841, -2134, -1396, -5758, + -14, 364, -4651, 1151, 194, -5234, 5878, -1348, + -1388, -233, 3810, -860, 9479, -24, -6616, 1387, + -455, 447, -224, -2997, 12, 3502, -73, 470, + -9170, 1677, -740, -592, -1638, 675, -93, -17842, + 1750, -847, 993, -2393, -49, -2029, 1940, 588, + 475, -3467, 55, 5087, 2989, 380, 915, -2782, + 2418, 11303, 1098, 1009, 1372, -5780, -303, 1451, + 972, -7433, -571, 1661, 64, 10265, 1541, -50, + -964, -738, -253, -3105, -695, -546, -775, -18971, + -3094, -2379, 738, 1625, 623, 1073, 782, 723, + -3417, -578, -189, 4108, 1115, -1222, -9102, -4736, + 347, 946, 322, -3699, 193, -15139, 367, 969, + -788, -694, -620, -26, -16, 4, -478, 20792, + -1175, -231, 2566, -1270, 162, 181, -1451, -5370, + -2429, -8910, -3794, -5807, -1655, 248, 4432, 1393, + -2451, -2706, -744, 687, 842, -1281, 2960, -2348, + 153, -1671, -1433, -1250, -1096, 2501, -5393, 4266, + -1098, 880, -1215, 817, -443, 10053, 705, -689, + -2679, -1205, -3302, -809, -918, -1005, 124, -329, + 108, -52, -5305, -419, 128, -8137, 1427, 387, + -235, -2582, 190, -173, -1031, 2672, -985, 3309, + -5927, 7327, -8463, -2, 6035, 743, 552, -14, + -580, -68, -11886, 476, 61, 1172, -529, -988, + 871, -776, -332, 20870, 384, 7795, -10830, 723, + 1690, -519, 962, 663, 1300, -465, 47, -3578, + 56, -8131, 2041, -8524, -1303, 6349, 1903, -6726, + 1156, -224, 1286, -2355, -3415, 985, -502, -2474, + 49, -2789, -3616, -1707, 3363, -140, 1702, -1919, +-11518, -404, 62, -6933, -1187, 10830, 132, 284, + -639, 1349, 2367, -311, -626, 745, 5660, -152, + -121, -5236, -481, 5889, -1263, -8443, -33, 936, + 423, -117, 111, -1055, -103, -321, 1286, -611, + 777, 827, 422, -162, -6767, -241, 289, -441, + -1344, 2706, -1260, -4649, -847, -16107, -263, -1826, + -521, -760, 942, 309, -2692, -4835, -853, -806, + -276, -322, 5647, 1219, -433, -346, -1171, -1028, + 191, -406, 444, 33, 272, 3502, 475, -2178, + 1915, -290, -1037, 833, -695, -121, 415, 556, + 1025, -2268, 334, 2847, -1768, -389, -14034, -3878, + 836, 4605, -1985, -359, 1478, -149, 823, -926, + -828, 135, 469, -645, -328, -94, -178, 2820, + 781, -2361, -5778, 1312, 3918, -1, -3654, -942, + -2495, 615, 210, -17006, -396, -445, 382, 563, + -1738, 95, -9107, 4869, 348, 527, 5688, -145, + -1195, -2367, -749, -187, 6697, 27, 347, 12571, + -64, -427, 3765, 824, -1216, -1126, 5997, 586, + 110, -294, -240, 1646, -186, 1360, 413, -6459, + -1535, -3208, -520, -621, 8613, 1098, -19, -199, +-11446, -657, -353, 906, 678, -19375, -126, 1688, + 644, 1231, -2151, -742, 320, -68, -12426, -2750, + 1483, -1603, -2639, 3028, 2662, -140, 5405, -917, + -407, 207, 9392, -569, 931, -124, -82, 6370, + 477, -12264, 1093, 3427, -732, -50, 232, -67, + 609, 1615, -463, 583, 1808, 1499, -509, -24431, + 231, -72, -192, -333, -7554, -342, -9036, -304, + 136, -15450, 1333, -1147, -1488, -1440, 75, 63, + 747, 297, -251, 30, -301, -1810, -86, 544, +-10446, 1300, 10468, 218, -2471, 1982, 423, 3046, + -1112, -657, -104, 10671, -46, -10953, -6205, -1275, + 1972, 937, -75, -330, -529, -2581, 1510, -1881, + -1372, -1725, 14541, -560, -884, 946, -307, -5031, + 7798, -190, 720, 1525, 29, 868, 1238, 372, + -462, 2467, -2661, 2721, -1514, 723, -2782, -494, + 240, -7147, 587, 751, 1613, 11054, 1074, 275, + 972, -970, 27, -75, 24, -9, 163, 88, + 21, 87, -78, -743, -128, -2336, -235, -743, + -3918, -333, 1088, -195, -166, 782, -119, -3263, + 604, 2155, -258, -1282, -129, 43, -5124, -472, + 685, -14243, -1294, -99, -1922, -284, -422, -1112, + -3194, -1977, 1448, -419, -7172, 20, -70, 2102, + 0, 278, 1882, -10005, 1612, 6020, 71, -141, + 1027, -43, -864, -448, -21257, -336, -2090, 5207, + 674, 722, 1030, 1367, 1963, 6057, 984, -1087, + -3690, 47, -61, 104, -81, 895, 22, 728, + -191, 3219, 5228, -27, -802, 1438, -9026, -1352, + -581, 912, -664, -23, -522, -912, 178, -603, + 571, 574, 406, 564, 175, -405, -2965, -1072, + 1749, -957, -402, 9431, 1649, -409, 291, 5765, + 808, 6754, 727, -37, -254, 1530, 213, 3253, + 357, 371, 45, -1276, -12432, 2799, -1924, -176, + -1107, -183, 198, 3662, 20, -1166, 2507, -3484 +}, + +.shape22_2 = { + 1688, -307, -590, 971, -3616, -1632, -218, 1861, + -1479, -367, -6584, 487, -951, 10808, -232, 444, + 89, -1216, -1577, 1283, 249, -3, -3646, 2205, + -1116, 2630, 2110, 3193, 270, -189, 78, -826, + 1010, -10520, -370, 1234, -5604, -262, 1277, 1440, + 2225, 2466, 305, 2469, -740, 120, 3184, 2125, + 1185, -3230, 1597, -1670, -8283, -9857, -129, 8932, + -1355, 8755, 707, -256, -135, 423, 1543, 1782, + -4875, 403, 373, 1570, -183, 782, -9617, -2539, + 1090, 523, 6929, -1226, 10329, -278, -999, -260, + -1810, 666, -463, -6100, 2040, 256, 532, -1475, + 383, 13137, -10953, -2226, -1243, 1584, -2348, -809, + 3602, -816, 194, 480, 84, 2297, 344, -5181, + -6243, -2616, 2093, 7112, -2373, -1346, 291, -372, + -863, -16911, -1878, 378, -826, 579, 737, -468, + -2288, 264, 634, 108, -254, 4717, -1286, 2885, + 986, -4944, -98, 2007, 991, -2252, -2887, -6141, + -605, -10474, 896, 6, 235, -407, -70, 478, + -8392, -10870, 575, -672, 103, 320, -179, -229, + 445, -380, 1124, 3271, -1327, -275, -239, -10381, + -9102, 1361, 96, -1255, -277, 9316, -415, -2258, + 8992, -117, 1625, -704, -980, 752, 9133, -8792, + -423, -272, -865, -2285, 443, -2014, -2592, 3180, + 1198, 2570, 3360, -7090, 3311, 697, 2229, 46, + -472, 6984, -140, -780, 10391, -1078, 48, -564, + -5073, 1576, -826, -483, 952, 1099, -11536, -652, + 375, 440, -7319, 2646, -2089, 2804, 3795, -6704, + 251, 811, -1224, -1976, -4943, -6671, 780, -2856, + -7907, 2447, 3755, -135, 1127, 328, 553, 3450, + 351, -5054, -5, 1077, 109, -254, -391, -511, + 404, -61, 510, 395, -6044, -7454, 364, -575, + 65, -410, -1921, -248, 128, 311, 17131, -2135, + -563, -884, 2356, -3951, -1176, -16695, -1534, 1977, + 626, 2478, 1554, -1070, 38, -551, 370, -11053, + -331, 1062, -1385, -1681, 1028, 3350, 239, -76, + -156, 49, 397, 7060, -2834, -6527, 22, 1920, + -951, 356, -7674, -8903, -120, 317, -303, 160, + 530, 4611, 1083, 514, -12207, -283, 1413, -848, + -645, -432, 0, -192, 4780, -3485, -1192, -10574, + 1274, -3057, 475, -188, 183, 7865, -11214, -268, + 491, 1422, -28, 149, 515, -1651, 670, -450, + -958, -4288, 567, -182, 668, 4069, -213, -1176, + 148, 8854, -151, 474, 599, 1297, 237, -19186, + 2993, -482, -591, -1322, 25, -628, -828, -203, + -1500, 5519, -84, 723, -1137, 1217, 13045, -707, + -372, -200, -4142, -790, 188, -6760, -8288, 766, + 366, 444, -517, -2679, -1470, -61, 161, -3734, + 3053, 2012, 439, 627, 524, 5538, 549, -473, + -2244, 8399, -6395, 5811, 851, 58, 11376, -6, + -337, -689, -1510, -690, -388, -3587, 2665, 3371, + -1850, -953, -513, 581, -10296, 548, 1092, 565, + 18045, 215, -1486, -1270, 450, -880, 407, -6547, + 8393, 206, -515, -1565, -219, -1872, 1479, 382, + -569, -5002, -1247, -45, -740, -1791, 17177, -1210, + 761, 132, -1627, 4970, 5563, 722, 5614, 430, + 5659, 139, 1193, 1513, 1144, -1319, 561, -5145, + 1010, 199, 656, -3958, 3544, -1758, 810, -1578, + 15976, -139, -1035, -416, -543, -418, 2824, -6541, + 94, -673, 11741, 426, -15, -5280, 780, 1795, + -4616, 8192, -297, -206, 883, 2369, -395, -4266, + -3120, -199, 985, 1240, 352, 232, -170, 176, + 413, -495, -1399, 754, 618, -6103, -179, -2546, + 965, -1362, -806, 838, -3912, -1346, -3135, -937, + 219, 307, -3509, 1210, 2381, -7923, 6358, -885, + 2902, 284, 2560, 1789, 6878, 6, -4418, -2206, + -1091, 1840, -118, -2659, 1008, 2192, 1651, 1363, + -7772, 1252, -1200, 133, -757, 501, -98, -17197, + 98, -543, 1743, 621, -809, -1950, -793, 1168, + -743, -7124, 166, 7875, -4466, 356, -1430, -467, + 8589, 9931, 520, -866, 1945, -599, -434, 113, + 589, -3456, 597, 6076, 1114, 9660, 1532, 2073, + -138, -721, -1030, -1309, 625, -4040, 1211, -18836, + -3963, -4468, 197, 600, -1004, -816, -560, -476, + -2160, -2, 26, 8162, 1057, -178, -11739, -1882, + 1000, -227, 109, -1852, -1163, -17143, 140, -718, + -1150, 33, 1397, -45, -205, 153, -1494, 20509, + -51, -904, -599, 1915, 884, 504, -1819, -4487, + 1252, -1259, -2200, -5601, -448, -686, 5778, 873, + -4282, -533, 295, -450, 1422, 2393, 3267, -3911, + 249, -3605, -3190, -1096, -2422, 274, -1918, 4070, + -206, -432, 1919, -645, -275, 12954, 311, 1479, + -2664, -852, -4809, 1102, -375, 20, 1659, -1179, + 1199, 44, -5590, -1112, -566, -11369, -125, -871, + 158, 1208, 265, -519, -405, 2439, -1129, 1827, + -9461, 8548, -1606, 380, 4924, 662, 1314, -391, + -2024, 827, -13381, -198, -142, 1600, 3329, 125, + -672, -220, 557, 18642, 60, 7296, -10472, -712, + 1188, 808, 64, 479, 555, 264, 394, -611, + -810, -7943, -235, -6889, -1575, 1320, -381, -7414, + 1740, -744, 369, -626, -6899, -2144, -593, 668, + -351, -3756, -5143, -1814, 806, -475, 588, -507, + -9088, -629, 154, -6945, -1105, 10658, -435, 384, + -757, 1183, 3806, -747, -378, 535, 10224, 626, + -866, -1931, -1484, 5818, -750, -9628, -250, 589, + -653, -198, 104, -934, 1207, 46, 960, -1032, + 4236, 4471, -2896, 1551, -7714, -1921, 746, -671, + 5114, 5482, -522, -3344, -1905, -9220, -663, -1355, + -611, 65, 1368, 628, -1276, -6780, -2623, -661, + -117, -437, 5507, 3205, 928, 537, -9487, 80, + -102, -538, -277, 863, -1421, 6054, 1227, 696, + 3582, -508, -1757, 145, -1705, -1201, 4157, -3314, + 2291, -834, 821, 552, -724, 513, -9730, -8944, + 1913, 501, -216, 716, 2766, -823, 2535, 314, + 1774, -3372, 235, 244, -1216, -710, 689, 6736, + -52, 218, -8382, -444, 920, 569, -4890, -2050, + -612, 1708, -481, -15500, -2878, -691, 538, -125, + -81, -862, -10094, 12050, -1392, -326, 133, 61, + -50, 715, -6662, -673, 10745, -596, 44, 3906, + 247, -745, 4950, -210, 497, -1875, 8197, 2141, + 1454, -23, -1480, 2184, -804, 5515, -1311, -8893, + -2880, -3606, -282, -116, 8084, 618, -403, 1106, +-14405, 1159, 229, 742, -184, -19445, -329, -747, + -1240, 1487, -1670, -839, -77, -882, -10986, -2851, + -24, -747, -3615, 1939, 1389, 132, 5367, 1355, + 408, -1272, 11388, 153, 2708, -1503, 169, 7357, + 51, -13586, -404, -304, 626, 163, -1814, -515, + 445, 589, -1194, 770, 555, 246, -165, -21192, + 184, -265, -1116, -485, -8107, -1992, -10805, -880, + -1455, -15154, 2312, -1712, -11, -1899, -400, -2, + 314, -318, -280, -658, -1066, -2584, 1027, 801, +-11960, 1519, 8873, 465, -3229, 1801, -348, 749, + 7, 1079, -2051, 11521, -831, -13425, -6315, -1135, + 1088, 1056, -46, -1006, 374, -5065, 1163, -402, + -50, -1459, 9586, 514, -1439, -638, -155, -5289, + 8043, -612, 739, 1084, -60, 891, 786, -6, + -1078, 2097, -5333, 3497, 23, -913, 1303, 957, + -35, -6418, -146, -971, 2738, 9695, -1722, -2002, + 905, -1749, -917, 122, 379, -325, -455, 230, + 825, -137, -335, -96, -160, 390, 731, -2621, + -5889, -3949, 5138, 839, -1190, -66, 961, -4600, + 2345, 1607, -2448, -6653, -592, -106, -7619, -794, + -1186, -12587, -11, -2224, -225, -2903, 534, 1355, + -7002, 314, 494, 1950, -8545, -2531, -2438, -77, + 886, -1851, 944, -10156, 3003, 1846, 1919, 2019, + 471, 451, -436, -1012, -20121, 275, 98, 1776, + 578, 96, -16, 1156, 3689, 7, -207, 920, + 105, -58, -175, 163, 697, -407, -61, 1261, + 1297, 5061, 5326, -1126, 516, 1208, -11108, 441, + 7, -899, -19, -368, 438, -1911, 602, 716, + 313, 853, 1448, -817, -1453, 1384, -4371, 1043, + 1884, 1619, 2196, 10075, -1548, -1201, -796, 5228, + 2657, 8244, -605, 422, -693, 3171, 657, 5438, + -171, 633, 1579, -1718, -12265, 1083, -976, -293, + -3802, -306, -668, 7818, -1340, -402, 2231, -4472 +}, + +.shape44 = { + -40, -282, 1366, -1173, -3484, 355, -1078, 3800, + 4386, -35, -4192, 523, 1291, 678, 156, 2272, + -1043, 1075, -1849, -314, -522, 392, 2098, -79, + 473, -275, 2, 6398, 451, 94, 173, -431, + 1115, -10788, 35, 1823, -3380, -97, -98, -350, + -23, -1264, -308, 8948, -695, -79, 3520, 308, + 340, -362, -547, 1207, -1182, -10392, -148, 3580, + 481, -425, 862, 4894, 736, -152, -626, 23, + -5853, 39, -143, 418, -103, -1457, -12826, -122, + 283, -225, 10561, -153, 8872, -806, -51, 93, + 420, -209, 345, -7661, -732, -48, 479, -225, + 276, 13385, -12578, -1440, -265, -274, 1105, -3376, + -691, -579, -972, 300, 349, 362, 722, -472, + 185, 814, 14, 4746, 761, -336, 1691, 888, + -1669, -18717, 827, -2605, 921, 155, 68, 112, + -3032, -287, 414, -86, -62, -213, -106, 807, + -619, 598, -178, 3104, -481, -1553, 1250, -8363, + -686, -9608, 116, -47, 321, -89, 939, -35, + -7995, -10159, -526, 145, 363, 2170, 1077, -1223, + -738, 120, -408, -390, -80, -404, -1607, -10187, + -6432, 961, 94, -1459, 489, 6641, 372, 1007, + 5958, -834, 222, 51, 282, -1005, 4473, -8841, + -73, -477, -557, 121, -165, -1195, 438, 139, + -190, -4205, -4278, -4617, -7592, 40, -422, -459, + 594, 7331, 164, 297, 2631, -9075, -78, 372, + -6213, -1053, 182, -71, -386, -604, -11720, 552, + -617, 413, 1292, 4, -485, 1162, 6051, -5168, + -181, 1024, -630, -275, -4067, -8627, 1386, 970, + -423, 2973, 2360, 363, -274, 410, 48, 768, + 2958, -427, 86, 64, -128, -273, -182, -292, + 868, 463, 73, -116, -6509, -5295, -37, 691, + 344, -120, 168, 419, 494, -1175, 18896, -135, + -376, -218, -453, -916, -1040, -22179, -846, -1005, + 264, 159, 597, -952, -825, 393, -328, -14694, + 371, -263, 740, 38, -1001, 1289, -668, 187, + -155, 143, 683, 7133, -563, -8383, -291, 176, + 75, 613, -6965, -11480, 324, -490, 586, 416, + 762, 5777, 64, -47, -4124, -1196, -113, 701, + -211, 2335, 130, 684, 7278, -158, -213, 297, + 10845, -1439, -465, 17, -792, 6499, -10187, -444, + -1416, 482, 636, 1472, 752, 157, -334, -3230, + -19, -6747, 660, -3082, 4057, 6801, -19, 635, + 19, 9807, 526, 126, 444, -190, -418, -26754, + -202, 243, 597, 10, 345, 814, -330, 160, + 344, 3986, 470, 459, 2387, -549, 11889, -1837, + -30, 2608, 615, 2301, -771, -1589, -6935, 1321, + 4287, 295, -558, -1503, -611, 2104, 411, -218, + 1145, -426, 58, -102, 13, 7499, 476, -4032, + -2237, -2658, -1943, 5268, 1039, 389, 7091, -22, + 156, -186, 2432, -878, 305, -1726, 3209, 361, + -1030, 505, 618, -262, -1877, 268, 757, 24, + 24306, 102, 973, 142, -953, -1199, 116, -255, + 5370, -347, -365, 937, -6939, -1189, -760, 531, + -1759, -705, -557, -620, 1151, 250, 21629, -1532, + -128, 1421, -211, 592, 5126, 197, -716, 1113, + 5844, -266, -12, -813, 85, 994, -2106, -3915, + 1402, 533, 521, -883, 87, -386, -2, -4350, + 19790, -180, -363, 60, 101, -1717, 119, -381, + 100, -565, 3264, 3052, 200, -7319, 26, 347, + -482, 10609, -766, 526, -623, 3495, 339, -4406, + -59, -213, 686, -603, 133, 99, 48, 1716, + -1214, 1397, -2396, -384, -901, -3750, -660, -4314, + 313, 192, 292, 259, -644, 176, 2099, 7961, + -29, 642, -2970, 1792, -61, -4348, 578, 1867, + -1868, 32, 5262, 137, 6109, 443, -176, 351, + 400, 1874, -175, -4065, 697, 292, -744, 121, + -5134, 6996, -198, 628, 1073, -599, -116, -17900, + 647, -1049, -663, 1427, -94, 721, 311, 337, + 1376, -2784, 3947, 1342, 1577, -406, -260, -10228, + 109, 2358, 2437, 346, 1261, -308, -2094, 1682, + 144, -675, 183, 428, -950, 1249, -1546, 33, + -254, 681, -1264, -964, -310, 838, 100, -21952, + -1484, -1564, 339, 298, 67, -338, 89, 709, + 53, 258, -359, 2803, 1553, -312, -7993, -1627, + 1189, 476, -123, 336, -767, -18522, 589, 942, + -645, -381, -1913, -582, 55, -876, -509, 25143, + 690, -787, -1136, 114, 162, 342, -231, -8742, + 99, -646, -474, -1384, -110, -98, 8634, -14, + -9676, -312, 358, 496, -676, -97, 1904, -2124, + -66, -1868, 502, -513, -3244, 2079, -1476, 5440, + -40, -381, 500, -238, -471, 12160, 248, -1005, + -2886, 173, -3369, -355, -256, -117, -474, -1282, + -355, 130, -4833, 31, -232, -12931, -826, 322, + 839, 1537, 73, 226, -1888, -483, -2848, -190, + 1271, 3597, -4514, -38, 6093, 347, -68, -415, + -105, -1664, -11461, -110, -399, 389, -511, 935, + -424, -1708, -1026, 23239, 298, 7363, -9206, -566, + 259, -412, -1213, 335, 614, 928, 972, -1919, + -407, 509, 303, -13762, -524, 10360, 1318, -2758, + 2350, -106, -119, -68, -6155, -255, -448, -34, + -64, -4382, 47, 635, -339, 406, -447, -445, +-10592, 233, 160, -5515, -1333, 6755, -952, 172, + -1260, -294, 3480, -352, -231, 415, 482, -498, + -191, -2034, 7934, 7997, -688, -9503, 376, -228, + -500, 222, -1021, -407, 261, 179, 622, 1217, + -443, -763, -508, -719, -4509, 91, 449, -283, + 91, -39, 961, -10148, 1596, -9161, -327, 221, + -470, 676, 12, 1416, 984, -10988, -5500, -189, + -727, 226, 4691, 688, 759, 930, -6444, -114, + -539, -526, -21, -1218, 650, 6088, 419, 6185, + -1200, 84, -1232, -34, -107, 60, 2248, 450, + 1187, 1264, -181, 857, 2235, -2859, -13483, -192, + -586, -207, -5569, 503, 3376, 1243, -700, 2119, + -2186, -296, 896, 299, 177, 184, 1375, 2498, + 161, 579, -3683, 443, -21, -186, -3474, 238, + 274, 277, -325, -8325, -223, 125, 191, 333, + -345, -1391, -7372, 11389, -1055, 4066, -1098, 87, + -203, 443, 363, -959, 15395, 4016, -254, 1611, + -168, -1070, 2709, -768, 506, -1245, 5821, 2499, + 1564, 27, 85, 1989, -1092, 150, -972, 660, + -33, 687, 545, -1564, 720, -196, -52, -1751, +-25380, -1246, -615, 391, -512, -23289, 460, 360, + -85, -723, -250, -163, -48, -921, -3988, 425, + -1268, -1695, 3233, -1093, -1166, 198, 7602, 21, + 354, 733, 12213, -347, 532, -427, 22, 2218, + -578, -3382, -474, -625, 78, -4546, 863, -53, + -357, -1529, 1014, 710, 1356, -430, -1633, -24823, + 95, 26, 590, -591, -7833, -1355, -9771, -502, + -907, -15433, 957, 463, 35, -496, 294, 2129, + 1274, -160, -83, 531, -767, 285, 232, 5983, + -6122, 1620, 4112, -239, -1733, -46, -1321, 467, + 613, -3747, -2284, 13991, 373, -17357, -219, -80, + -210, 1462, 37, -1692, 548, -5845, 420, 54, + -350, -285, 1981, 262, -874, 2844, -435, -6305, + 6449, 72, 631, -94, 96, -442, 1137, 89, + 364, 3392, -3512, -387, 1055, 318, -1111, -6971, + 344, -9105, -96, -9362, 190, -225, 370, 161, + -73, -1830, 174, 48, -518, -3486, 137, -235, + 810, 23, 80, -642, -35, -316, -269, -373, + -2413, -933, 2525, 267, -508, -200, 422, -3470, + -1273, 640, -1956, 139, 394, -1043, -11008, -158, + -1089, -2023, 202, -979, -744, -159, -392, -37, + -1679, 2183, 1365, -2883, -4752, -2255, 109, 1660, + -613, -511, 1284, -7331, 947, 7009, -2072, -321, + -936, -551, -875, 160, -27027, 654, 265, 164, + 376, 726, -149, 2813, -94, 5728, 702, -1118, + -2555, 217, -186, -107, 146, -83, -62, -196, + 708, 146, 3729, -416, 212, -163, -7861, 347, + 83, -1079, -994, 271, -1054, -1647, 139, -20, + 354, 1298, -3420, 1130, 161, 475, -3913, 468, + 23, 285, -1699, 8234, -947, 222, 260, 4276, + -341, 6387, 21, 490, -1908, -1654, -60, 2471, + 733, -135, 109, -1136, -14756, 4922, 1165, 149, + -3976, -66, -594, 6181, -110, 292, 1129, -591 +}, + +.lsp08 = { + 0.2702, 0.5096, 0.6437, 0.7672, 0.9639, 1.0696, 1.2625, 1.5789, + 1.9285, 2.2383, 2.5129, 2.8470, 0.1740, 0.3677, 0.6082, 0.8387, + 1.1084, 1.3721, 1.6362, 1.8733, 2.0640, 2.3442, 2.6087, 2.8548, + 0.1536, 0.3279, 0.5143, 0.6859, 0.9763, 1.2744, 1.5605, 1.8566, + 2.1007, 2.3450, 2.6075, 2.8850, 0.2075, 0.4533, 0.7709, 1.0377, + 1.2953, 1.5132, 1.7826, 2.0351, 2.2590, 2.4996, 2.6795, 2.8748, + 0.1393, 0.2453, 0.3754, 0.5453, 0.8148, 1.1289, 1.4389, 1.7592, + 2.0353, 2.3215, 2.5934, 2.8588, 0.1250, 0.3627, 0.7613, 1.1380, + 1.4163, 1.5565, 1.6920, 1.8130, 1.8678, 2.0427, 2.4318, 2.8544, + 0.2256, 0.4223, 0.6452, 0.8599, 1.0673, 1.3118, 1.5486, 1.8366, + 2.0759, 2.3026, 2.5284, 2.8030, 0.2304, 0.4404, 0.6891, 0.8964, + 1.1510, 1.4202, 1.6483, 1.8580, 2.1181, 2.3686, 2.6078, 2.9128, + 0.2230, 0.3816, 0.5520, 0.6062, 0.7909, 1.0988, 1.4330, 1.7846, + 2.0713, 2.3457, 2.6048, 2.8708, 0.2447, 0.5800, 0.8249, 0.9905, + 1.1721, 1.3990, 1.6694, 1.9064, 2.1307, 2.4255, 2.6815, 2.9117, + 0.1974, 0.3812, 0.5802, 0.7759, 0.9280, 1.1547, 1.4170, 1.6369, + 1.8890, 2.2587, 2.5626, 2.8239, 0.1209, 0.2510, 0.4841, 0.8048, + 1.1197, 1.3563, 1.6073, 1.8926, 2.1350, 2.3669, 2.6291, 2.8985, + 0.2352, 0.4347, 0.6582, 0.8178, 0.9548, 1.1654, 1.4942, 1.8812, + 2.1703, 2.3779, 2.6412, 2.8871, 0.2091, 0.4084, 0.6730, 0.9151, + 1.1259, 1.3262, 1.5937, 1.8129, 2.0237, 2.3317, 2.5778, 2.8620, + 0.1167, 0.2406, 0.4520, 0.7298, 0.9848, 1.2448, 1.5137, 1.7874, + 2.0280, 2.3020, 2.5914, 2.8794, 0.3003, 0.4966, 0.6520, 0.8505, + 1.1600, 1.3981, 1.5805, 1.8346, 2.0757, 2.3102, 2.5760, 2.8499, + 0.2451, 0.4163, 0.5960, 0.7805, 0.9507, 1.2438, 1.5587, 1.8581, + 2.0735, 2.3198, 2.5704, 2.8220, 0.3112, 0.5517, 0.7032, 0.8528, + 1.1489, 1.4257, 1.6848, 1.9388, 2.1577, 2.4265, 2.6678, 2.9051, + 0.2249, 0.3897, 0.5559, 0.7473, 1.0158, 1.3581, 1.6914, 1.9930, + 2.1843, 2.3534, 2.5512, 2.8065, 0.2600, 0.4574, 0.7349, 0.9691, + 1.1696, 1.3848, 1.6335, 1.9021, 2.1174, 2.3481, 2.5902, 2.8390, + 0.2246, 0.3372, 0.4560, 0.5249, 0.7056, 1.0273, 1.3810, 1.7132, + 1.9819, 2.2574, 2.5410, 2.8491, 0.1419, 0.4834, 0.8835, 1.1453, + 1.2839, 1.4224, 1.5593, 1.7877, 2.1285, 2.4070, 2.6043, 2.8511, + 0.1886, 0.3677, 0.5617, 0.8099, 1.1277, 1.3841, 1.5804, 1.8136, + 2.0307, 2.2805, 2.5399, 2.8322, 0.2351, 0.4151, 0.6675, 0.8713, + 1.0464, 1.3292, 1.6586, 1.9281, 2.1355, 2.3495, 2.6222, 2.8782, + 0.2700, 0.4489, 0.6206, 0.7121, 0.7737, 0.9848, 1.3658, 1.7433, + 2.0139, 2.2243, 2.4806, 2.8175, 0.2479, 0.4425, 0.6490, 0.8745, + 1.1161, 1.3849, 1.6773, 1.9566, 2.1491, 2.3624, 2.5685, 2.8114, + 0.2035, 0.3701, 0.5567, 0.7953, 1.0082, 1.2758, 1.5373, 1.7822, + 2.0175, 2.2601, 2.4759, 2.7771, 0.1856, 0.3461, 0.5998, 0.9041, + 1.2383, 1.4612, 1.6667, 1.9305, 2.1617, 2.4107, 2.6477, 2.8656, + 0.2107, 0.3715, 0.5289, 0.6651, 0.8420, 1.1168, 1.4401, 1.7230, + 1.9901, 2.2687, 2.5452, 2.8655, 0.1218, 0.2999, 0.6348, 0.9482, + 1.2745, 1.5876, 1.9129, 2.2348, 2.4020, 2.4922, 2.6351, 2.8357, + 0.1617, 0.3483, 0.5869, 0.8163, 1.0366, 1.2344, 1.4609, 1.7029, + 1.9476, 2.2337, 2.5258, 2.8442, 0.2505, 0.4894, 0.7510, 0.9152, + 1.0845, 1.3657, 1.6528, 1.8346, 2.0160, 2.2811, 2.5338, 2.8136, + 0.0947, 0.1158, 0.0578, -0.0337, -0.0066, 0.0104, -0.0447, -0.0505, +-0.0778, -0.0293, 0.0251, -0.0143, 0.0349, -0.0227, -0.0909, 0.0523, + 0.0325, -0.0410, -0.1045, -0.0899, -0.0009, 0.0075, -0.0575, -0.0855, +-0.0129, 0.0575, 0.0597, 0.0391, 0.0371, -0.0184, -0.0083, 0.0287, + 0.0143, 0.0167, 0.0120, -0.0168, 0.0452, 0.0223, -0.0352, 0.0119, +-0.0496, -0.0965, -0.0661, -0.0072, 0.1099, 0.0843, -0.0087, -0.0478, +-0.0128, -0.0120, -0.0004, 0.0731, 0.1047, 0.0630, 0.0196, -0.0103, +-0.0399, -0.0986, -0.0912, -0.0390, -0.0247, -0.0694, -0.0749, -0.0066, + 0.0223, 0.0634, 0.0343, -0.0134, 0.0727, 0.0241, 0.0066, 0.0437, + 0.0610, 0.0364, 0.0248, -0.0358, -0.0686, -0.0104, 0.0426, 0.0088, +-0.0137, -0.0165, 0.0671, 0.0815, -0.0863, -0.0644, -0.0088, 0.0023, + 0.0482, 0.1174, 0.1270, 0.0594, 0.0165, 0.0949, 0.1098, 0.0137, + 0.4951, 0.4999, 0.4958, 0.4907, 0.4984, 0.4965, 0.4958, 0.4996, + 0.4987, 0.4958, 0.4986, 0.4977, 0.2841, 0.2186, 0.1474, 0.1687, + 0.2217, 0.2632, 0.2706, 0.2624, 0.2162, 0.2453, 0.2460, 0.2531 +}, + +.lsp11 = { + 0.1103, 0.3862, 0.6863, 0.8447, 0.9231, 1.0261, 1.1248, 1.4057, + 1.6621, 1.8010, 1.8692, 2.0704, 2.3490, 2.6060, 2.7539, 2.8977, + 0.1273, 0.2407, 0.3812, 0.6004, 0.7767, 0.9383, 1.1344, 1.3351, + 1.5233, 1.7262, 1.9466, 2.1739, 2.3495, 2.5162, 2.7164, 2.9202, + 0.2010, 0.3330, 0.4488, 0.6465, 0.8046, 0.9889, 1.1479, 1.2964, + 1.4770, 1.6606, 1.8789, 2.1155, 2.3287, 2.5199, 2.7101, 2.9119, + 0.1168, 0.2197, 0.3279, 0.4691, 0.6268, 0.8251, 1.0533, 1.2714, + 1.4712, 1.6762, 1.8831, 2.1114, 2.3230, 2.5297, 2.7365, 2.9270, + 0.1405, 0.3109, 0.4986, 0.6891, 0.8634, 1.0583, 1.2594, 1.4349, + 1.6232, 1.8116, 1.9905, 2.1935, 2.3799, 2.5656, 2.7661, 2.9486, + 0.1703, 0.3057, 0.4403, 0.5225, 0.5969, 0.8110, 1.0729, 1.3215, + 1.5407, 1.7381, 1.9477, 2.1680, 2.3586, 2.5612, 2.7630, 2.9410, + 0.1128, 0.2628, 0.4523, 0.6495, 0.8176, 0.9816, 1.1746, 1.3710, + 1.5568, 1.7518, 1.9497, 2.1452, 2.3346, 2.5389, 2.7362, 2.9264, + 0.1809, 0.3287, 0.5205, 0.7264, 0.9298, 1.1217, 1.2970, 1.4894, + 1.6874, 1.8493, 2.0576, 2.2382, 2.4097, 2.6041, 2.7796, 2.9389, + 0.2502, 0.4709, 0.6892, 0.8346, 0.9209, 1.0455, 1.2399, 1.4616, + 1.6463, 1.8380, 2.0475, 2.2397, 2.4665, 2.6550, 2.7701, 2.8895, + 0.1040, 0.2340, 0.3964, 0.5740, 0.7764, 0.9941, 1.2000, 1.4014, + 1.6024, 1.7974, 1.9939, 2.1959, 2.3783, 2.5663, 2.7613, 2.9484, + 0.1912, 0.3393, 0.4743, 0.6313, 0.8014, 0.9879, 1.1855, 1.3922, + 1.5678, 1.7289, 1.9271, 2.1165, 2.3089, 2.5414, 2.7448, 2.9269, + 0.0965, 0.2025, 0.3398, 0.4990, 0.6934, 0.9386, 1.1730, 1.3766, + 1.5783, 1.7783, 1.9790, 2.1831, 2.3670, 2.5578, 2.7641, 2.9516, + 0.2126, 0.3652, 0.5545, 0.7170, 0.8674, 1.0640, 1.2558, 1.4061, + 1.5904, 1.8095, 1.9760, 2.1505, 2.3549, 2.5575, 2.7023, 2.8877, + 0.1827, 0.3426, 0.4894, 0.6488, 0.7960, 0.9535, 1.1217, 1.2798, + 1.4566, 1.6453, 1.8044, 2.0042, 2.2379, 2.4611, 2.6697, 2.8966, + 0.2034, 0.3822, 0.5231, 0.6960, 0.9200, 1.0394, 1.1616, 1.3772, + 1.5493, 1.7330, 1.9646, 2.1233, 2.3334, 2.5361, 2.7087, 2.9470, + 0.1050, 0.2060, 0.3705, 0.5998, 0.8337, 1.0577, 1.2559, 1.4327, + 1.6334, 1.8165, 1.9853, 2.2058, 2.4063, 2.5818, 2.7625, 2.9458, + 0.1419, 0.4053, 0.6660, 0.8911, 1.0405, 1.1547, 1.2506, 1.3926, + 1.5669, 1.7527, 1.9694, 2.2054, 2.3889, 2.5743, 2.7586, 2.9174, + 0.1514, 0.2825, 0.4309, 0.5772, 0.7470, 0.9703, 1.1462, 1.3316, + 1.5321, 1.7259, 1.9282, 2.1266, 2.3106, 2.5064, 2.7067, 2.9094, + 0.1693, 0.3156, 0.4878, 0.6635, 0.8206, 0.9569, 1.1154, 1.3064, + 1.5109, 1.7184, 1.9179, 2.1036, 2.2763, 2.4820, 2.6949, 2.9105, + 0.1432, 0.2718, 0.4241, 0.5564, 0.6939, 0.9011, 1.1582, 1.3948, + 1.6181, 1.8024, 1.9814, 2.1740, 2.3459, 2.5456, 2.7491, 2.9307, + 0.2294, 0.3857, 0.5590, 0.7434, 0.9189, 1.0941, 1.2740, 1.4456, + 1.6178, 1.7994, 1.9689, 2.1644, 2.3525, 2.5385, 2.7468, 2.9405, + 0.1667, 0.3109, 0.4612, 0.6032, 0.7375, 0.8866, 1.0840, 1.3053, + 1.4982, 1.7044, 1.9146, 2.1117, 2.2942, 2.4983, 2.7084, 2.9132, + 0.1810, 0.3205, 0.4696, 0.6231, 0.7641, 0.9959, 1.2427, 1.4361, + 1.5889, 1.7544, 1.9083, 2.0733, 2.2457, 2.4461, 2.6793, 2.9098, + 0.1164, 0.3753, 0.6068, 0.7503, 1.0100, 1.2131, 1.3793, 1.5302, + 1.6300, 1.7950, 1.9057, 2.1031, 2.3830, 2.5745, 2.6949, 2.8779, + 0.1571, 0.4378, 0.6735, 0.8312, 0.8944, 0.9818, 1.1622, 1.4094, + 1.6423, 1.8066, 1.9258, 2.1838, 2.4363, 2.6279, 2.7358, 2.8790, + 0.1398, 0.2686, 0.4248, 0.6156, 0.7870, 1.0035, 1.2012, 1.3689, + 1.5363, 1.7398, 1.9604, 2.1619, 2.3345, 2.5097, 2.7271, 2.9368, + 0.1913, 0.3338, 0.4987, 0.6446, 0.7852, 1.0163, 1.1886, 1.3610, + 1.5379, 1.7230, 1.8880, 2.0862, 2.2960, 2.4928, 2.7122, 2.9151, + 0.0908, 0.1752, 0.2899, 0.5365, 0.7761, 1.0100, 1.2124, 1.4060, + 1.6019, 1.8010, 1.9774, 2.1905, 2.3733, 2.5623, 2.7660, 2.9565, + 0.1773, 0.3179, 0.4925, 0.6864, 0.8452, 0.9897, 1.1860, 1.3722, + 1.5515, 1.7658, 1.9802, 2.1819, 2.3620, 2.5442, 2.7250, 2.9220, + 0.1286, 0.2341, 0.3689, 0.5364, 0.7176, 0.9350, 1.1083, 1.2943, + 1.4974, 1.7059, 1.9047, 2.1145, 2.3242, 2.5361, 2.7453, 2.9329, + 0.2273, 0.3834, 0.5565, 0.7192, 0.8431, 0.9962, 1.1763, 1.3571, + 1.5774, 1.7419, 1.9202, 2.1131, 2.2919, 2.4898, 2.6895, 2.9180, + 0.1775, 0.3058, 0.4274, 0.6023, 0.8151, 1.0734, 1.3211, 1.5178, + 1.6706, 1.8154, 1.9686, 2.1537, 2.3461, 2.5276, 2.7181, 2.9121, + 0.1653, 0.4304, 0.6361, 0.7824, 0.9183, 1.0452, 1.2071, 1.4077, + 1.6206, 1.8299, 2.0089, 2.1948, 2.3900, 2.5982, 2.7844, 2.9487, + 0.1492, 0.2609, 0.3820, 0.5485, 0.7243, 0.9319, 1.1538, 1.3579, + 1.5266, 1.7002, 1.8873, 2.1016, 2.3175, 2.5221, 2.7241, 2.9243, + 0.2074, 0.3781, 0.5209, 0.6869, 0.8577, 0.9875, 1.1849, 1.3568, + 1.4907, 1.7335, 1.8902, 2.1224, 2.3099, 2.4918, 2.7023, 2.8765, + 0.1359, 0.2254, 0.3286, 0.4432, 0.6586, 0.8964, 1.1125, 1.3523, + 1.5626, 1.7579, 1.9846, 2.1905, 2.3548, 2.5542, 2.7663, 2.9346, + 0.1430, 0.2966, 0.4685, 0.6493, 0.8315, 1.0304, 1.2220, 1.4082, + 1.5995, 1.7888, 1.9774, 2.1737, 2.3607, 2.5577, 2.7558, 2.9405, + 0.1477, 0.2694, 0.4056, 0.5626, 0.7051, 0.8647, 1.0491, 1.2488, + 1.4814, 1.7072, 1.9150, 2.1147, 2.3038, 2.5144, 2.7184, 2.9202, + 0.1690, 0.3033, 0.4580, 0.6686, 0.8536, 1.0293, 1.2124, 1.3998, + 1.5718, 1.7607, 1.9580, 2.1245, 2.2971, 2.4762, 2.6896, 2.9177, + 0.1092, 0.2779, 0.4853, 0.6880, 0.9011, 1.0953, 1.2752, 1.4618, + 1.6623, 1.8484, 2.0264, 2.2152, 2.4017, 2.5835, 2.7671, 2.9436, + 0.1497, 0.3637, 0.6014, 0.8032, 0.9963, 1.1835, 1.3741, 1.5698, + 1.7382, 1.9094, 2.0710, 2.2392, 2.4082, 2.5926, 2.7762, 2.9536, + 0.1434, 0.2492, 0.3966, 0.5934, 0.8033, 1.0657, 1.2796, 1.4276, + 1.5745, 1.7833, 1.9288, 2.1247, 2.3543, 2.5412, 2.7049, 2.8872, + 0.1612, 0.2926, 0.4574, 0.6387, 0.8265, 1.0180, 1.1808, 1.3526, + 1.5564, 1.7536, 1.9187, 2.1192, 2.3149, 2.5006, 2.7101, 2.9217, + 0.0828, 0.1863, 0.3235, 0.5050, 0.7250, 0.9867, 1.2093, 1.3941, + 1.5980, 1.7932, 1.9809, 2.1894, 2.3918, 2.5773, 2.7540, 2.9329, + 0.2001, 0.3655, 0.5290, 0.6761, 0.8027, 0.9972, 1.2090, 1.4255, + 1.6085, 1.7825, 1.9804, 2.1681, 2.3457, 2.5325, 2.7319, 2.9196, + 0.1505, 0.2767, 0.4254, 0.6054, 0.7821, 0.9567, 1.1294, 1.3080, + 1.4984, 1.6954, 1.8666, 2.0736, 2.2875, 2.4969, 2.7072, 2.9163, + 0.1589, 0.4151, 0.5749, 0.6651, 0.8061, 1.0470, 1.2616, 1.3690, + 1.4985, 1.7808, 1.9825, 2.1068, 2.2751, 2.5448, 2.7133, 2.8689, + 0.0916, 0.1846, 0.3788, 0.6329, 0.8774, 1.0687, 1.2653, 1.4561, + 1.6573, 1.8449, 2.0402, 2.2254, 2.3968, 2.5861, 2.7792, 2.9508, + 0.2282, 0.4159, 0.5834, 0.6899, 0.8108, 1.0321, 1.2795, 1.5262, + 1.6936, 1.8469, 2.0922, 2.2607, 2.3795, 2.5301, 2.7386, 2.9530, + 0.1651, 0.3004, 0.4555, 0.6179, 0.7891, 0.9584, 1.1372, 1.3707, + 1.5951, 1.7880, 1.9434, 2.1465, 2.3311, 2.5081, 2.6977, 2.8970, + 0.1279, 0.3828, 0.6330, 0.8323, 0.9652, 1.1175, 1.2319, 1.3511, + 1.5115, 1.6392, 1.7835, 1.9558, 2.2008, 2.4635, 2.6910, 2.9058, + 0.1193, 0.2185, 0.3521, 0.5311, 0.7378, 0.9239, 1.1105, 1.3217, + 1.5362, 1.7504, 1.9536, 2.1627, 2.3560, 2.5506, 2.7548, 2.9453, + 0.1806, 0.3432, 0.4981, 0.6948, 0.8928, 1.0527, 1.2467, 1.4140, + 1.6326, 1.7950, 1.9935, 2.1969, 2.3512, 2.5682, 2.7445, 2.9277, + 0.1846, 0.3112, 0.4568, 0.5891, 0.7317, 0.8493, 1.0204, 1.2022, + 1.3688, 1.6020, 1.8428, 2.0710, 2.2725, 2.4879, 2.7057, 2.9160, + 0.0880, 0.2514, 0.5332, 0.7272, 0.8906, 1.1354, 1.3199, 1.4941, + 1.6010, 1.7151, 1.8712, 2.0643, 2.2755, 2.5375, 2.7054, 2.8891, + 0.1382, 0.2833, 0.4658, 0.6897, 0.9071, 1.0716, 1.2469, 1.4143, + 1.5910, 1.7947, 1.9805, 2.1581, 2.3338, 2.5215, 2.7292, 2.9211, + 0.1061, 0.3494, 0.6327, 0.8570, 0.9748, 1.0560, 1.1529, 1.3250, + 1.6032, 1.8340, 1.9711, 2.1157, 2.3011, 2.5464, 2.8078, 2.9803, + 0.1603, 0.2839, 0.4307, 0.5980, 0.7980, 1.0399, 1.1971, 1.3524, + 1.5715, 1.7838, 1.9468, 2.1498, 2.3627, 2.5514, 2.7327, 2.9148, + 0.1691, 0.3117, 0.4796, 0.6895, 0.8732, 1.0164, 1.1916, 1.3707, + 1.5384, 1.7202, 1.8857, 2.0672, 2.2487, 2.4593, 2.6789, 2.8940, + 0.0965, 0.1702, 0.3191, 0.5721, 0.8100, 1.0241, 1.2272, 1.4196, + 1.6093, 1.8057, 1.9884, 2.2037, 2.3925, 2.5805, 2.7578, 2.9366, + 0.1950, 0.3519, 0.5272, 0.6973, 0.8732, 1.0656, 1.2112, 1.3959, + 1.6116, 1.7821, 1.9445, 2.1592, 2.3348, 2.5142, 2.7440, 2.9297, + 0.1388, 0.2557, 0.4120, 0.5727, 0.7354, 0.9196, 1.0985, 1.2805, + 1.4643, 1.6535, 1.8340, 2.0546, 2.2758, 2.4778, 2.6921, 2.9122, + 0.1823, 0.3336, 0.4957, 0.6771, 0.8563, 1.0137, 1.2299, 1.3849, + 1.5718, 1.7667, 1.9193, 2.1326, 2.3135, 2.5268, 2.7133, 2.8998, + 0.0790, 0.1901, 0.4083, 0.6456, 0.8463, 1.0285, 1.2297, 1.4181, + 1.6159, 1.8056, 1.9971, 2.1912, 2.3816, 2.5746, 2.7692, 2.9497, + 0.0049, 0.0116, 0.0045, 0.0039, -0.0010, -0.0122, -0.0205, -0.0034, +-0.0140, -0.0041, 0.0191, -0.0322, 0.0002, -0.0124, -0.0269, 0.0059, + 0.0586, 0.0339, -0.0389, -0.0319, -0.0079, -0.0205, -0.0363, -0.0211, + 0.0241, 0.0595, 0.0469, 0.0283, 0.0176, -0.0183, -0.0173, -0.0004, + 0.0024, 0.0145, 0.0534, 0.0197, -0.0065, -0.0067, 0.0133, 0.0358, +-0.0104, -0.0386, -0.0109, -0.0078, 0.0275, 0.0565, 0.0251, -0.0027, +-0.0053, 0.0171, 0.0088, 0.0495, 0.0141, 0.0039, -0.0445, -0.0426, +-0.0184, -0.0280, -0.0223, 0.0039, -0.0171, -0.0606, -0.0786, -0.0430, + 0.0544, 0.0595, 0.0320, -0.0012, 0.0108, 0.0185, 0.0066, 0.0408, + 0.0552, -0.0073, -0.0247, -0.0480, -0.0288, 0.0186, 0.0212, -0.0013, + 0.0403, 0.0598, 0.0690, 0.0516, -0.0298, -0.0177, 0.0278, 0.0168, +-0.0106, 0.0251, 0.0386, 0.0331, -0.0052, 0.0133, 0.0291, -0.0158, +-0.0329, -0.0367, 0.0287, 0.0462, -0.0176, 0.0049, 0.0242, -0.0034, + 0.0135, 0.0086, -0.0149, 0.0241, 0.0504, 0.0246, -0.0273, -0.0369, +-0.0108, -0.0449, -0.0625, -0.0414, -0.0292, -0.0571, -0.0440, -0.0088, + 0.0098, 0.0009, -0.0004, 0.0007, -0.0314, -0.0208, -0.0138, -0.0277, +-0.0044, 0.0522, 0.0315, -0.0270, -0.0277, -0.0256, -0.0103, -0.0201, +-0.0287, -0.0279, -0.0182, 0.0472, 0.0613, 0.0450, 0.0413, 0.0333, + 0.0444, 0.0223, 0.0061, 0.0316, 0.0321, 0.0501, 0.0460, 0.0250, + 0.0227, 0.0235, 0.0099, 0.0185, -0.0347, -0.0684, -0.0189, 0.0242, +-0.0190, -0.0273, -0.0012, -0.0253, 0.0293, -0.0231, -0.0219, -0.0010, + 0.0153, 0.0128, -0.0166, -0.0435, -0.0417, -0.0121, -0.0351, -0.0390, + 0.0077, -0.0278, -0.0355, 0.0092, -0.0063, 0.0005, 0.0216, 0.0461, + 0.0538, 0.0451, 0.0298, -0.0130, 0.0058, 0.0206, 0.0471, 0.0499, + 0.0280, 0.0086, -0.0007, -0.0317, 0.0259, 0.0176, 0.0043, 0.0212, + 0.0138, 0.0106, 0.0220, -0.0025, 0.0050, 0.0122, -0.0051, -0.0086, +-0.0472, -0.0005, 0.0193, 0.0032, 0.0246, 0.0222, 0.0090, -0.0320, +-0.0713, -0.0526, -0.0151, -0.0440, -0.0648, -0.0466, -0.0092, 0.0115, +-0.0129, 0.0053, -0.0344, -0.0385, 0.0392, 0.0599, 0.0414, 0.0165, +-0.0098, -0.0320, -0.0261, -0.0055, -0.0139, -0.0110, 0.0084, 0.0172, +-0.0492, -0.0537, -0.0320, -0.0036, 0.0265, 0.0385, 0.0064, -0.0280, +-0.0230, 0.0134, 0.0241, 0.0106, 0.0387, 0.0105, 0.0068, 0.0260, + 0.4940, 0.4911, 0.4849, 0.4820, 0.4837, 0.4839, 0.4824, 0.4799, + 0.4812, 0.4782, 0.4788, 0.4711, 0.4706, 0.4671, 0.4601, 0.4578, + 0.2954, 0.2121, 0.1859, 0.1958, 0.1474, 0.1086, 0.1351, 0.1362, + 0.1486, 0.1342, 0.1215, 0.1423, 0.1634, 0.1588, 0.1539, 0.1857 +}, + +.lsp16 = { + 0.1813, 0.3911, 0.6301, 0.8012, 1.0057, 1.2041, 1.4271, 1.6943, + 1.9402, 2.1733, 2.3521, 2.4989, 2.5839, 2.6846, 2.7634, 2.8950, + 0.1311, 0.3183, 0.4659, 0.5601, 0.6658, 0.7828, 1.0065, 1.2717, + 1.5185, 1.7339, 1.9530, 2.2189, 2.3739, 2.4991, 2.6984, 2.9256, + 0.1627, 0.4519, 0.6323, 0.7012, 0.7848, 0.9801, 1.1810, 1.3222, + 1.5413, 1.8129, 1.9338, 2.0809, 2.3180, 2.5189, 2.7066, 2.9514, + 0.1475, 0.2447, 0.4240, 0.5669, 0.7872, 0.9838, 1.1823, 1.3814, + 1.5358, 1.6820, 1.8794, 2.1419, 2.4132, 2.6112, 2.7911, 2.9511, + 0.1224, 0.2876, 0.5013, 0.6985, 0.8902, 1.0901, 1.2835, 1.4768, + 1.6596, 1.8538, 2.0467, 2.2304, 2.4124, 2.5942, 2.7729, 2.9531, + 0.1741, 0.3034, 0.4677, 0.5879, 0.7258, 0.9648, 1.1417, 1.3220, + 1.5081, 1.7151, 1.9212, 2.1286, 2.3208, 2.4938, 2.6765, 2.8891, + 0.1657, 0.3174, 0.4907, 0.6559, 0.8295, 1.0254, 1.2071, 1.3880, + 1.5737, 1.7845, 1.9027, 2.1139, 2.3323, 2.5157, 2.7323, 2.9015, + 0.1592, 0.2758, 0.4417, 0.6315, 0.8257, 0.9873, 1.1277, 1.2830, + 1.4337, 1.6315, 1.8899, 2.1356, 2.3572, 2.5632, 2.7468, 2.9420, + 0.1524, 0.4325, 0.5931, 0.7036, 0.7696, 0.8923, 1.1739, 1.4773, + 1.6609, 1.7911, 1.9666, 2.1972, 2.3754, 2.5045, 2.6613, 2.8882, + 0.2130, 0.3013, 0.3721, 0.4257, 0.5079, 0.7015, 0.9815, 1.2554, + 1.4648, 1.6966, 1.9138, 2.1075, 2.3318, 2.5292, 2.7453, 2.9347, + 0.1142, 0.3748, 0.6205, 0.7642, 0.8121, 0.9022, 0.9843, 1.1558, + 1.4467, 1.7422, 1.9574, 2.1302, 2.3812, 2.5898, 2.7720, 2.9583, + 0.1255, 0.2339, 0.3570, 0.5323, 0.7458, 1.0003, 1.1729, 1.3567, + 1.5217, 1.6977, 1.8924, 2.0942, 2.3145, 2.5408, 2.7553, 2.9337, + 0.1316, 0.2289, 0.4327, 0.6663, 0.8509, 0.9994, 1.1697, 1.3804, + 1.5609, 1.6903, 1.8572, 2.1019, 2.3687, 2.5789, 2.7715, 2.9472, + 0.1502, 0.2546, 0.3883, 0.5333, 0.6976, 0.9163, 1.1071, 1.3364, + 1.5420, 1.7525, 1.8948, 2.0839, 2.2819, 2.4651, 2.6875, 2.8987, + 0.1593, 0.3014, 0.4573, 0.6354, 0.8157, 0.9805, 1.1783, 1.3747, + 1.5678, 1.7326, 1.9286, 2.1340, 2.3253, 2.5280, 2.7180, 2.9298, + 0.1811, 0.3167, 0.4655, 0.6507, 0.8198, 1.0075, 1.1892, 1.3743, + 1.5227, 1.7090, 1.8849, 2.0743, 2.2750, 2.4830, 2.6896, 2.8953, + 0.1846, 0.3577, 0.5315, 0.7290, 0.9176, 1.1016, 1.2654, 1.4525, + 1.6315, 1.8268, 2.0238, 2.1934, 2.3868, 2.5753, 2.7682, 2.9469, + 0.0876, 0.1439, 0.2048, 0.3654, 0.6281, 0.8853, 1.0907, 1.2992, + 1.5227, 1.7373, 1.9395, 2.1419, 2.3488, 2.5486, 2.7466, 2.9348, + 0.1391, 0.4170, 0.6561, 0.7953, 0.8734, 0.9986, 1.1870, 1.4520, + 1.6042, 1.7910, 2.0135, 2.1870, 2.3358, 2.5066, 2.7409, 2.9955, + 0.0804, 0.1355, 0.2599, 0.4998, 0.7408, 0.9474, 1.1276, 1.3428, + 1.5556, 1.7712, 1.9699, 2.1535, 2.3605, 2.5548, 2.7489, 2.9325, + 0.1304, 0.3087, 0.4979, 0.6584, 0.8414, 1.0329, 1.2244, 1.4189, + 1.6118, 1.8200, 1.9985, 2.1893, 2.3915, 2.5794, 2.7647, 2.9344, + 0.1895, 0.2849, 0.3705, 0.4126, 0.6265, 0.9207, 1.1774, 1.3762, + 1.5757, 1.7728, 1.9568, 2.1662, 2.3615, 2.5575, 2.7561, 2.9416, + 0.1800, 0.3078, 0.4805, 0.6796, 0.8503, 1.0046, 1.1703, 1.3269, + 1.4862, 1.6502, 1.8454, 2.0873, 2.3175, 2.5356, 2.7516, 2.9469, + 0.1950, 0.3233, 0.4568, 0.5940, 0.7589, 0.9978, 1.1701, 1.3383, + 1.5017, 1.6565, 1.8243, 2.0605, 2.2938, 2.5147, 2.7419, 2.9396, + 0.2531, 0.4391, 0.5790, 0.7170, 0.8998, 1.1430, 1.3577, 1.5326, + 1.6328, 1.7627, 1.9726, 2.1762, 2.3563, 2.5478, 2.7385, 2.9067, + 0.1805, 0.2788, 0.3591, 0.3881, 0.5441, 0.8055, 1.0766, 1.3165, + 1.5316, 1.7508, 1.9477, 2.1374, 2.3438, 2.5484, 2.7501, 2.9410, + 0.2044, 0.3671, 0.5396, 0.7042, 0.8582, 0.9831, 1.1261, 1.3194, + 1.4769, 1.6979, 1.8717, 2.0463, 2.2620, 2.4739, 2.7054, 2.9208, + 0.1048, 0.2175, 0.4206, 0.5923, 0.7483, 0.9400, 1.1356, 1.3799, + 1.5958, 1.7320, 1.8984, 2.1296, 2.3594, 2.5492, 2.7387, 2.9305, + 0.0842, 0.1729, 0.3951, 0.6447, 0.8688, 1.0605, 1.2472, 1.4330, + 1.6232, 1.8144, 2.0216, 2.1915, 2.3878, 2.5763, 2.7685, 2.9464, + 0.1461, 0.2593, 0.4105, 0.5677, 0.7328, 0.8919, 1.0484, 1.2302, + 1.4386, 1.6635, 1.8873, 2.1024, 2.3116, 2.5268, 2.7273, 2.9269, + 0.1503, 0.3108, 0.4756, 0.6731, 0.8600, 1.0233, 1.2115, 1.3971, + 1.5915, 1.7892, 1.9517, 2.1603, 2.3487, 2.5460, 2.7308, 2.8998, + 0.2163, 0.3669, 0.5125, 0.6709, 0.8143, 0.9930, 1.2095, 1.4205, + 1.6176, 1.7112, 1.8398, 2.0896, 2.3513, 2.5290, 2.6667, 2.8960, + 0.2133, 0.4382, 0.6287, 0.8702, 1.1088, 1.3749, 1.6062, 1.7446, + 1.8333, 1.9122, 1.9614, 2.0669, 2.1789, 2.3449, 2.6038, 2.8849, + 0.1598, 0.2719, 0.3877, 0.4815, 0.5926, 0.7795, 1.0449, 1.3045, + 1.5210, 1.7391, 1.9462, 2.1397, 2.3553, 2.5458, 2.7540, 2.9392, + 0.2918, 0.5607, 0.6801, 0.7404, 0.8285, 0.9431, 1.1579, 1.4080, + 1.6332, 1.8472, 1.9738, 2.0771, 2.2890, 2.5178, 2.7445, 2.9830, + 0.1664, 0.2842, 0.3965, 0.5463, 0.8162, 1.0346, 1.1849, 1.3446, + 1.5122, 1.7563, 1.9960, 2.2002, 2.3796, 2.5689, 2.7712, 2.9550, + 0.0911, 0.2397, 0.5052, 0.7868, 1.0299, 1.1311, 1.2244, 1.3333, + 1.4395, 1.6790, 1.9369, 2.1717, 2.3689, 2.5538, 2.7340, 2.9326, + 0.1647, 0.2931, 0.3836, 0.4978, 0.6255, 0.9243, 1.1339, 1.3001, + 1.5269, 1.8010, 1.9715, 2.1419, 2.3784, 2.5503, 2.6719, 2.8745, + 0.2440, 0.3802, 0.4756, 0.6613, 0.8627, 1.0292, 1.2291, 1.4060, + 1.5198, 1.7354, 1.9044, 2.1010, 2.3147, 2.4996, 2.7171, 2.9041, + 0.1590, 0.2876, 0.4572, 0.5996, 0.7713, 0.9490, 1.1205, 1.2815, + 1.4516, 1.6385, 1.8179, 2.0457, 2.2759, 2.4785, 2.6861, 2.9080, + 0.2297, 0.4309, 0.5712, 0.6717, 0.8138, 1.0463, 1.2492, 1.4560, + 1.6796, 1.8458, 1.9642, 2.1452, 2.3636, 2.5395, 2.7456, 2.9495, + 0.2975, 0.4678, 0.4996, 0.5809, 0.6279, 0.6884, 0.8606, 1.1386, + 1.4412, 1.6876, 1.8760, 2.0932, 2.3178, 2.5166, 2.7345, 2.9280, + 0.1278, 0.3737, 0.6004, 0.7069, 0.8147, 1.0180, 1.2581, 1.3812, + 1.4855, 1.7268, 1.9970, 2.1258, 2.2936, 2.5702, 2.7563, 2.8983, + 0.1314, 0.2508, 0.3999, 0.5680, 0.7424, 0.9367, 1.1286, 1.3175, + 1.5336, 1.7404, 1.9317, 2.1404, 2.3514, 2.5562, 2.7510, 2.9402, + 0.1043, 0.2367, 0.4293, 0.6376, 0.8160, 0.9836, 1.1779, 1.3850, + 1.5835, 1.7875, 1.9765, 2.1593, 2.3654, 2.5577, 2.7465, 2.9398, + 0.1529, 0.2515, 0.3454, 0.4374, 0.7011, 0.9015, 1.0744, 1.3532, + 1.5699, 1.7545, 2.0021, 2.1259, 2.2278, 2.4546, 2.7264, 2.9425, + 0.1429, 0.2808, 0.4395, 0.6334, 0.8069, 0.9705, 1.1520, 1.3250, + 1.5109, 1.7285, 1.9356, 2.1469, 2.3479, 2.5554, 2.7512, 2.9348, + 0.1625, 0.3022, 0.4756, 0.6315, 0.8032, 0.9924, 1.1596, 1.3204, + 1.4994, 1.6929, 1.8955, 2.1090, 2.3025, 2.5018, 2.6908, 2.8980, + 0.1692, 0.3427, 0.5228, 0.7756, 0.9688, 1.0950, 1.3056, 1.4360, + 1.5675, 1.8049, 1.9376, 2.1151, 2.3407, 2.5012, 2.7192, 2.9258, + 0.0474, 0.1251, 0.1939, 0.3841, 0.6501, 0.9231, 1.1153, 1.3240, + 1.5478, 1.7599, 1.9651, 2.1510, 2.3645, 2.5552, 2.7542, 2.9393, + 0.2196, 0.4656, 0.7492, 0.9922, 1.1678, 1.2489, 1.3112, 1.3657, + 1.4223, 1.5302, 1.7212, 1.9996, 2.2523, 2.4844, 2.7036, 2.9145, + 0.1128, 0.2368, 0.3704, 0.5476, 0.7723, 0.9968, 1.1930, 1.3992, + 1.6013, 1.7957, 1.9888, 2.1857, 2.3825, 2.5705, 2.7616, 2.9434, + 0.1341, 0.2768, 0.4510, 0.6359, 0.8332, 1.0335, 1.2004, 1.3952, + 1.5762, 1.7681, 1.9815, 2.1735, 2.3657, 2.5552, 2.7514, 2.9498, + 0.1247, 0.2559, 0.3516, 0.4726, 0.6861, 0.9483, 1.1852, 1.3858, + 1.5851, 1.7815, 1.9778, 2.1737, 2.3729, 2.5664, 2.7620, 2.9429, + 0.1988, 0.3320, 0.4777, 0.6737, 0.8425, 1.0265, 1.1694, 1.3655, + 1.5463, 1.7135, 1.9385, 2.1650, 2.3529, 2.5367, 2.7545, 2.9585, + 0.1376, 0.2620, 0.4273, 0.6169, 0.7755, 0.9441, 1.1169, 1.3157, + 1.5179, 1.7020, 1.8931, 2.1059, 2.3112, 2.5136, 2.7169, 2.9198, + 0.2112, 0.4385, 0.6091, 0.7618, 0.9553, 1.1543, 1.3445, 1.5396, + 1.7153, 1.9192, 2.1263, 2.3593, 2.5958, 2.8171, 2.9394, 3.0409, + 0.1347, 0.2099, 0.2646, 0.3453, 0.5266, 0.7869, 1.0513, 1.2795, + 1.4880, 1.7181, 1.9294, 2.1332, 2.3362, 2.5442, 2.7433, 2.9362, + 0.3141, 0.5935, 0.7517, 0.8313, 0.8568, 0.9570, 1.0250, 1.1275, + 1.3422, 1.6303, 1.8577, 2.0705, 2.2957, 2.5095, 2.7244, 2.9262, + 0.0962, 0.2116, 0.3961, 0.5641, 0.7122, 0.8883, 1.1023, 1.3481, + 1.5623, 1.7554, 1.9618, 2.1675, 2.3706, 2.5556, 2.7430, 2.9337, + 0.0898, 0.1510, 0.3060, 0.5820, 0.8221, 1.0388, 1.2261, 1.4289, + 1.6054, 1.8103, 1.9941, 2.1844, 2.3742, 2.5711, 2.7632, 2.9474, + 0.1326, 0.2316, 0.3761, 0.5177, 0.6782, 0.8761, 1.0952, 1.3175, + 1.5078, 1.7034, 1.9051, 2.1245, 2.3424, 2.5484, 2.7444, 2.9389, + 0.1740, 0.3293, 0.5174, 0.6824, 0.8394, 1.0372, 1.2046, 1.3723, + 1.5656, 1.7444, 1.9442, 2.1386, 2.3139, 2.4960, 2.7071, 2.9297, + 0.2304, 0.3775, 0.4865, 0.6182, 0.7842, 0.9208, 1.1151, 1.2843, + 1.4641, 1.6988, 1.9209, 2.1260, 2.3099, 2.5229, 2.7414, 2.9276, + 0.0094, 0.0261, -0.0037, 0.0041, -0.0092, -0.0044, -0.0232, -0.0073, +-0.0047, -0.0021, 0.0250, -0.0580, -0.0140, -0.0342, -0.0586, 0.0020, + 0.0449, 0.0155, -0.0523, -0.0279, 0.0299, -0.0183, -0.0736, -0.0639, +-0.0017, 0.0336, 0.0209, 0.0046, 0.0077, -0.0148, -0.0114, -0.0120, + 0.0115, -0.0050, 0.0445, 0.0048, 0.0188, -0.0137, -0.0080, 0.0239, +-0.0184, -0.0524, -0.0195, -0.0126, 0.0284, 0.0632, 0.0141, -0.0093, +-0.0096, 0.0196, 0.0230, 0.0379, 0.0308, 0.0237, -0.0224, -0.0600, +-0.0755, -0.1074, -0.0988, -0.0606, -0.1038, -0.1552, -0.1480, -0.0672, + 0.0504, 0.0676, 0.0336, -0.0042, 0.0729, 0.1013, 0.0868, 0.0846, + 0.0954, 0.0515, -0.0066, -0.0851, -0.0485, 0.0294, 0.0395, 0.0087, + 0.0078, 0.0446, 0.0881, 0.0672, -0.0384, -0.0025, 0.0415, 0.0353, + 0.0080, 0.0052, 0.0190, 0.0182, 0.0069, 0.0168, 0.0374, 0.0037, +-0.0292, -0.0429, 0.0302, 0.0681, -0.0233, -0.0238, -0.0003, -0.0043, + 0.0054, -0.0029, -0.0149, 0.0642, 0.0622, 0.0341, -0.0232, -0.0461, +-0.0082, -0.0469, -0.0618, -0.0326, -0.0452, -0.0649, -0.0597, -0.0398, +-0.0318, -0.0116, 0.0011, 0.0009, -0.0384, -0.0384, -0.0156, -0.0260, +-0.0007, 0.0473, 0.0111, -0.0358, -0.0484, -0.0204, -0.0029, -0.0090, +-0.0285, -0.0495, -0.0376, 0.0917, 0.1192, 0.1026, 0.0745, 0.0397, + 0.0463, 0.0253, 0.0025, 0.0465, 0.0100, 0.0488, 0.0416, 0.0223, + 0.0263, 0.0072, -0.0053, 0.0595, 0.0060, -0.0518, -0.0316, -0.0043, +-0.0133, -0.0233, -0.0075, -0.0251, 0.0277, -0.0067, -0.0136, -0.0004, + 0.0235, 0.0112, -0.0182, -0.0324, -0.0210, -0.0035, -0.0395, -0.0384, + 0.0005, -0.0150, -0.0356, 0.0127, -0.0033, -0.0034, 0.0205, 0.0747, + 0.1138, 0.1015, 0.0995, -0.0161, -0.0045, 0.0129, 0.0472, 0.0575, + 0.0222, 0.0091, 0.0037, -0.0471, 0.0371, 0.0132, 0.0208, 0.0247, + 0.0117, 0.0164, 0.0225, 0.0124, -0.0023, 0.0088, -0.0046, 0.0047, +-0.0393, 0.0018, 0.0148, 0.0020, 0.0044, 0.0165, 0.0229, -0.0208, +-0.0477, -0.0310, -0.0164, -0.0390, -0.0764, -0.0525, -0.0094, 0.0075, +-0.0102, -0.0045, -0.0504, -0.0709, 0.0822, 0.0710, 0.0426, 0.0014, +-0.0371, -0.0400, -0.0157, -0.0155, -0.0173, -0.0138, -0.0015, 0.0134, +-0.0418, -0.0682, -0.0256, 0.0050, 0.0360, 0.0354, 0.0074, -0.0396, +-0.0235, 0.0284, 0.0494, 0.0153, 0.0448, 0.0025, -0.0061, 0.0252, + 0.1000, 0.2260, 0.2158, 0.2116, 0.2198, 0.2055, 0.2110, 0.1873, + 0.1907, 0.2071, 0.2164, 0.2009, 0.2059, 0.2124, 0.2141, 0.2093, + 0.0875, 0.0981, 0.1177, 0.1071, 0.1033, 0.1248, 0.1048, 0.1238, + 0.1166, 0.1008, 0.1062, 0.0992, 0.0994, 0.1067, 0.0999, 0.1187, + 0.0750, 0.0794, 0.0828, 0.0854, 0.0859, 0.0801, 0.0891, 0.0933, + 0.0969, 0.0920, 0.0915, 0.0862, 0.0868, 0.0891, 0.0842, 0.0824, + 0.0625, 0.0930, 0.0815, 0.0853, 0.0898, 0.0828, 0.0822, 0.0910, + 0.0873, 0.0906, 0.0856, 0.0840, 0.0774, 0.0785, 0.0684, 0.0711, + 0.3319, 0.4219, 0.4588, 0.4090, 0.4092, 0.4014, 0.3548, 0.3353, + 0.3708, 0.3352, 0.3720, 0.3538, 0.4084, 0.4289, 0.4060, 0.4210, + 0.0588, 0.0209, -0.0082, -0.0115, -0.0343, -0.0621, -0.0541, -0.0346, +-0.0346, -0.0366, -0.0220, -0.0265, -0.0102, 0.0374, 0.0306, 0.0404, + 0.0306, 0.0090, -0.0054, 0.0333, 0.0047, 0.0238, 0.0141, 0.0165, + 0.0306, 0.0420, 0.0159, 0.0124, 0.0414, 0.0158, -0.0237, 0.0141, + 0.0765, 0.0057, -0.0260, -0.0426, -0.0395, -0.0126, -0.0579, -0.0417 +}, + +.lsp22_1 = { + 0.0664, 0.1875, 0.4300, 0.6730, 0.8793, 1.0640, 1.2563, 1.4433, + 1.6394, 1.8176, 2.0029, 2.1921, 2.3796, 2.5671, 2.7595, 2.9536, + 0.2128, 0.4052, 0.5311, 0.6404, 0.7875, 0.8775, 1.0974, 1.3261, + 1.5563, 1.6790, 1.8339, 2.1195, 2.3226, 2.4609, 2.6440, 2.8947, + 0.2024, 0.3362, 0.4834, 0.6784, 0.9088, 1.0850, 1.2188, 1.4054, + 1.6102, 1.7767, 1.9679, 2.1436, 2.3445, 2.5467, 2.7429, 2.9320, + 0.1181, 0.2279, 0.4413, 0.6114, 0.7710, 0.9427, 1.1142, 1.2707, + 1.4892, 1.7416, 1.9526, 2.1466, 2.3629, 2.5445, 2.7293, 2.9205, + 0.1155, 0.2720, 0.4886, 0.6812, 0.8594, 1.0422, 1.2315, 1.4116, + 1.6137, 1.8020, 1.9758, 2.1743, 2.3602, 2.5568, 2.7472, 2.9374, + 0.1110, 0.3312, 0.4735, 0.5612, 0.7129, 0.8146, 1.0233, 1.3155, + 1.5765, 1.7746, 1.9574, 2.1416, 2.3220, 2.5384, 2.7334, 2.9318, + 0.1656, 0.3350, 0.4215, 0.5609, 0.6759, 0.8503, 1.1405, 1.4094, + 1.6057, 1.6860, 1.7639, 2.0031, 2.2680, 2.5076, 2.7263, 2.9368, + 0.1466, 0.3638, 0.4587, 0.5674, 0.7381, 0.8669, 0.9619, 1.1658, + 1.4667, 1.7440, 1.9335, 2.1018, 2.3022, 2.5281, 2.7359, 2.9261, + 0.1061, 0.2566, 0.4739, 0.6751, 0.8711, 1.0704, 1.2720, 1.4655, + 1.6605, 1.8494, 2.0290, 2.2197, 2.4008, 2.5912, 2.7772, 2.9513, + 0.1116, 0.2364, 0.3971, 0.6316, 0.8583, 1.0335, 1.1686, 1.3302, + 1.5612, 1.7877, 1.9829, 2.2052, 2.3596, 2.5460, 2.7341, 2.9290, + 0.2661, 0.4186, 0.5126, 0.6477, 0.8818, 1.1045, 1.2852, 1.4128, + 1.5851, 1.7593, 1.9399, 2.1757, 2.3684, 2.5136, 2.6927, 2.9064, + 0.1495, 0.2749, 0.4391, 0.6304, 0.8239, 1.0181, 1.1995, 1.3759, + 1.5669, 1.7722, 1.9671, 2.1635, 2.3586, 2.5528, 2.7445, 2.9311, + 0.0912, 0.1759, 0.3066, 0.5660, 0.8005, 0.9568, 1.1832, 1.4504, + 1.6259, 1.7948, 2.0113, 2.2002, 2.3654, 2.5583, 2.7929, 2.9735, + 0.1353, 0.2747, 0.4078, 0.5977, 0.7658, 0.9124, 1.1081, 1.3630, + 1.5875, 1.7847, 1.9323, 2.1181, 2.3321, 2.5046, 2.7183, 2.9225, + 0.1938, 0.4063, 0.4982, 0.6002, 0.7702, 0.9071, 1.1631, 1.3885, + 1.6043, 1.8118, 1.9306, 2.0893, 2.2724, 2.4609, 2.6283, 2.8802, + 0.1857, 0.3351, 0.4381, 0.6101, 0.7561, 0.8555, 1.0384, 1.3171, + 1.5667, 1.6904, 1.7552, 1.9689, 2.2597, 2.5260, 2.7272, 2.9337, + 0.1037, 0.2159, 0.4188, 0.6174, 0.8035, 1.0285, 1.2256, 1.4230, + 1.6400, 1.8322, 2.0144, 2.1988, 2.3810, 2.5682, 2.7613, 2.9438, + 0.1625, 0.2776, 0.4225, 0.6001, 0.7879, 0.9087, 1.0801, 1.2759, + 1.4899, 1.7448, 1.9911, 2.1770, 2.3723, 2.5777, 2.7971, 2.9444, + 0.2111, 0.3640, 0.5839, 0.7290, 0.8051, 1.0023, 1.2315, 1.4143, + 1.5878, 1.7755, 1.9804, 2.1498, 2.3312, 2.5350, 2.7613, 2.9472, + 0.1423, 0.2646, 0.4136, 0.6350, 0.8070, 0.9514, 1.1168, 1.3213, + 1.5776, 1.7721, 1.9404, 2.1545, 2.3385, 2.5137, 2.7396, 2.9553, + 0.1132, 0.2386, 0.4103, 0.5931, 0.7808, 0.9881, 1.1840, 1.3860, + 1.6021, 1.7990, 1.9922, 2.1885, 2.3852, 2.5717, 2.7640, 2.9510, + 0.1267, 0.2602, 0.3913, 0.5944, 0.7598, 0.9198, 1.0781, 1.2715, + 1.5299, 1.7573, 1.9308, 2.1346, 2.3267, 2.5419, 2.7466, 2.9320, + 0.2023, 0.3417, 0.4392, 0.6141, 0.7439, 0.8593, 1.1096, 1.3543, + 1.5185, 1.6553, 1.7862, 2.0341, 2.2718, 2.4834, 2.7103, 2.9466, + 0.1113, 0.2470, 0.3677, 0.5686, 0.7700, 0.9356, 1.0806, 1.2452, + 1.4830, 1.7344, 1.9268, 2.1404, 2.3371, 2.5169, 2.7329, 2.9012, + 0.1664, 0.3554, 0.5573, 0.7471, 0.9245, 1.0998, 1.2787, 1.4655, + 1.6654, 1.8346, 2.0179, 2.2159, 2.4096, 2.5946, 2.7790, 2.9530, + 0.1313, 0.2625, 0.4731, 0.6444, 0.8110, 0.9878, 1.1493, 1.3212, + 1.5719, 1.8138, 1.9861, 2.1943, 2.3714, 2.5578, 2.7346, 2.9296, + 0.1186, 0.3035, 0.5049, 0.6860, 0.8670, 0.9975, 1.1364, 1.3471, + 1.5695, 1.7412, 1.9346, 2.1506, 2.3413, 2.5531, 2.7794, 2.9627, + 0.1108, 0.2697, 0.4787, 0.6344, 0.7909, 0.9586, 1.1440, 1.3511, + 1.5686, 1.7601, 1.9246, 2.1241, 2.3293, 2.5390, 2.7315, 2.9333, + 0.0985, 0.2302, 0.3544, 0.5759, 0.7620, 0.9651, 1.1497, 1.3080, + 1.5500, 1.7845, 1.9518, 2.1734, 2.3565, 2.5665, 2.7605, 2.9102, + 0.1208, 0.2727, 0.4381, 0.5736, 0.7382, 0.8390, 1.0102, 1.2648, + 1.5100, 1.7440, 1.9619, 2.1430, 2.3307, 2.5159, 2.7264, 2.9211, + 0.1582, 0.2777, 0.4475, 0.6551, 0.8591, 1.0084, 1.1414, 1.3291, + 1.5902, 1.7826, 1.9543, 2.1659, 2.3233, 2.5044, 2.6935, 2.9199, + 0.1360, 0.2873, 0.4585, 0.6295, 0.7592, 0.9089, 1.0492, 1.2733, + 1.5391, 1.7768, 1.9372, 2.1329, 2.3168, 2.5015, 2.6857, 2.8837, + 0.0886, 0.1829, 0.3696, 0.6126, 0.8334, 1.0135, 1.2303, 1.4674, + 1.6743, 1.8564, 2.0530, 2.2370, 2.3960, 2.5787, 2.7756, 2.9377, + 0.2005, 0.3537, 0.4700, 0.6249, 0.7385, 0.9097, 1.1759, 1.3811, + 1.5314, 1.6705, 1.8546, 2.1229, 2.3292, 2.5251, 2.7951, 2.9646, + 0.1999, 0.3112, 0.4722, 0.7146, 0.8908, 1.0028, 1.1831, 1.3903, + 1.6125, 1.7514, 1.9083, 2.1248, 2.3271, 2.5339, 2.6945, 2.8918, + 0.1243, 0.2606, 0.4382, 0.5850, 0.7705, 0.9727, 1.1214, 1.3059, + 1.5218, 1.7406, 1.9137, 2.1353, 2.3354, 2.5299, 2.7287, 2.9068, + 0.1039, 0.2426, 0.4265, 0.6284, 0.8152, 0.9941, 1.2004, 1.4038, + 1.5912, 1.7763, 1.9650, 2.1598, 2.3474, 2.5488, 2.7419, 2.9322, + 0.1364, 0.2420, 0.3886, 0.5864, 0.7663, 0.8844, 1.0860, 1.3242, + 1.5518, 1.7893, 2.0004, 2.1562, 2.3619, 2.5516, 2.7687, 2.9181, + 0.1483, 0.2851, 0.4479, 0.6312, 0.7924, 0.9821, 1.1705, 1.3386, + 1.5375, 1.7226, 1.9053, 2.0991, 2.2898, 2.4953, 2.7000, 2.9146, + 0.2332, 0.4561, 0.5407, 0.6212, 0.7524, 0.8215, 0.9522, 1.1685, + 1.5216, 1.7132, 1.8291, 2.0647, 2.2811, 2.4857, 2.7071, 2.9281, + 0.1348, 0.3126, 0.5179, 0.7192, 0.9227, 1.1363, 1.3223, 1.4756, + 1.6509, 1.8191, 1.9991, 2.1976, 2.3877, 2.5768, 2.7590, 2.9386, + 0.1093, 0.2211, 0.4763, 0.6703, 0.8282, 0.9536, 1.1202, 1.3796, + 1.6043, 1.8031, 1.9832, 2.1604, 2.3578, 2.5856, 2.7650, 2.9291, + 0.1865, 0.3027, 0.4580, 0.6719, 0.8400, 1.0082, 1.1901, 1.3782, + 1.5448, 1.6885, 1.9477, 2.1381, 2.2797, 2.5113, 2.7465, 2.9414, + 0.1575, 0.3124, 0.4649, 0.6262, 0.8095, 0.9858, 1.1676, 1.3602, + 1.5646, 1.7582, 1.9550, 2.1671, 2.3628, 2.5734, 2.7670, 2.9519, + 0.1174, 0.2777, 0.4663, 0.6333, 0.8169, 1.0096, 1.1885, 1.3847, + 1.5803, 1.7571, 1.9380, 2.1398, 2.3414, 2.5407, 2.7360, 2.9375, + 0.1073, 0.2264, 0.4083, 0.5973, 0.7474, 0.9514, 1.1349, 1.3337, + 1.5433, 1.7348, 1.9380, 2.1436, 2.3441, 2.5438, 2.7457, 2.9383, + 0.1472, 0.2880, 0.4793, 0.6268, 0.8015, 1.0063, 1.1715, 1.3644, + 1.5525, 1.7410, 1.9258, 2.1227, 2.3214, 2.5149, 2.7148, 2.9196, + 0.1414, 0.2565, 0.4349, 0.6111, 0.7695, 0.9496, 1.1212, 1.3265, + 1.5218, 1.7209, 1.9015, 2.0887, 2.3158, 2.5077, 2.7233, 2.9421, + 0.1252, 0.2667, 0.4454, 0.6431, 0.8371, 1.0124, 1.2110, 1.4160, + 1.6240, 1.8242, 2.0047, 2.1974, 2.3902, 2.5778, 2.7637, 2.9481, + 0.1321, 0.2565, 0.3846, 0.5847, 0.7578, 0.9259, 1.0637, 1.2239, + 1.4690, 1.7346, 1.9750, 2.1882, 2.3712, 2.5509, 2.7280, 2.8885, + 0.1437, 0.2930, 0.4428, 0.6156, 0.8045, 0.9638, 1.1450, 1.3138, + 1.5144, 1.7355, 1.9469, 2.1534, 2.3414, 2.5452, 2.7353, 2.9334, + 0.1692, 0.2770, 0.3831, 0.6100, 0.7825, 0.9302, 1.0690, 1.2481, + 1.4615, 1.6799, 1.9165, 2.1739, 2.3435, 2.5349, 2.7520, 2.9163, + 0.1235, 0.2489, 0.4354, 0.6343, 0.8236, 1.0066, 1.1908, 1.3474, + 1.5656, 1.8275, 2.0620, 2.2548, 2.4135, 2.5913, 2.7639, 2.9334, + 0.1090, 0.1961, 0.3854, 0.5701, 0.7024, 0.8843, 1.1393, 1.3785, + 1.5940, 1.7797, 1.9442, 2.1740, 2.3853, 2.5773, 2.7727, 2.9406, + 0.1560, 0.3477, 0.5011, 0.6287, 0.7612, 0.9896, 1.1510, 1.3420, + 1.5435, 1.6816, 1.8731, 2.0651, 2.2613, 2.4999, 2.7027, 2.8971, + 0.1459, 0.2416, 0.3833, 0.5450, 0.7916, 0.9223, 1.0662, 1.1953, + 1.4029, 1.6616, 1.9320, 2.1459, 2.3386, 2.5081, 2.6799, 2.9195, + 0.1546, 0.3854, 0.6184, 0.8460, 1.0599, 1.2428, 1.3906, 1.5550, + 1.7388, 1.8945, 2.0757, 2.2386, 2.4014, 2.5705, 2.7574, 2.9400, + 0.1080, 0.2307, 0.4112, 0.6067, 0.7725, 0.9467, 1.1285, 1.3205, + 1.5348, 1.7609, 1.9937, 2.1878, 2.3583, 2.5515, 2.7199, 2.9049, + 0.1482, 0.3178, 0.4983, 0.6342, 0.7783, 0.9880, 1.2019, 1.3404, + 1.5223, 1.7296, 1.9211, 2.0943, 2.2928, 2.5008, 2.7136, 2.9224, + 0.1145, 0.2910, 0.4891, 0.6492, 0.8126, 0.9530, 1.1180, 1.3155, + 1.5054, 1.6893, 1.8899, 2.1188, 2.3389, 2.5512, 2.7313, 2.9224, + 0.0939, 0.1689, 0.3250, 0.5792, 0.7698, 0.9245, 1.1574, 1.3865, + 1.5959, 1.7977, 1.9821, 2.1528, 2.3326, 2.5540, 2.7553, 2.9179, + 0.1243, 0.2474, 0.3923, 0.6199, 0.7908, 0.9379, 1.1497, 1.3734, + 1.5582, 1.7420, 1.9539, 2.1385, 2.3240, 2.5277, 2.7311, 2.9178, + 0.1961, 0.3748, 0.5176, 0.6387, 0.8169, 1.0477, 1.2124, 1.3869, + 1.5604, 1.7225, 1.8770, 2.0837, 2.2960, 2.5103, 2.6945, 2.8862, + 0.1295, 0.2403, 0.4149, 0.6189, 0.7913, 0.9130, 1.0832, 1.2787, + 1.4860, 1.7112, 1.9502, 2.1348, 2.2776, 2.4982, 2.7431, 2.9522, + 0.0160, 0.0362, 0.0097, 0.0057, -0.0014, -0.0073, -0.0046, -0.0064, +-0.0121, 0.0019, 0.0149, -0.0440, -0.0479, -0.0382, -0.0480, -0.0182, + 0.0170, 0.0114, -0.0298, -0.0175, -0.0033, -0.0354, -0.0510, -0.0025, + 0.0307, 0.0351, 0.0338, 0.0420, 0.0138, -0.0175, -0.0102, 0.0053, + 0.0084, -0.0003, 0.0412, -0.0027, 0.0145, -0.0039, 0.0083, 0.0400, + 0.0001, -0.0262, 0.0055, -0.0082, 0.0348, 0.0433, 0.0137, -0.0024, +-0.0055, 0.0262, 0.0521, 0.0349, 0.0185, 0.0076, -0.0319, -0.0561, +-0.0460, -0.0253, -0.0097, 0.0163, 0.0184, -0.0037, -0.0480, -0.0371, + 0.0628, 0.0665, 0.0296, -0.0057, 0.0253, 0.0227, 0.0350, 0.0692, + 0.0545, 0.0218, 0.0094, -0.0449, -0.0372, 0.0005, 0.0258, 0.0118, + 0.0285, 0.0760, 0.0822, 0.0527, -0.0299, -0.0049, 0.0170, 0.0195, + 0.0136, 0.0286, 0.0289, 0.0139, 0.0054, 0.0152, 0.0244, 0.0028, +-0.0056, -0.0260, 0.0307, 0.0572, -0.0087, 0.0088, 0.0062, 0.0000, + 0.0125, 0.0000, -0.0292, 0.0820, 0.0872, 0.0646, 0.0346, 0.0076, +-0.0022, -0.0253, -0.0567, -0.0188, -0.0336, -0.0673, -0.0549, -0.0166, +-0.0259, -0.0140, 0.0040, -0.0029, -0.0430, -0.0531, -0.0253, -0.0019, +-0.0071, 0.0393, 0.0072, -0.0327, -0.0236, -0.0235, -0.0177, -0.0186, +-0.0280, -0.0201, -0.0077, 0.0383, 0.0418, 0.0321, 0.0294, 0.0169, + 0.0468, 0.0301, 0.0133, 0.0363, 0.0516, 0.0937, 0.1240, 0.1404, + 0.1325, 0.1178, 0.0999, 0.0251, -0.0037, -0.0495, -0.0703, -0.0219, +-0.0261, -0.0304, -0.0204, -0.0372, 0.0355, 0.0131, -0.0093, -0.0099, +-0.0069, -0.0034, -0.0065, -0.0208, -0.0231, -0.0117, -0.0211, -0.0243, + 0.0046, -0.0107, -0.0070, 0.0123, 0.0230, 0.0152, 0.0164, 0.0412, + 0.0619, 0.0858, 0.0862, -0.0056, 0.0125, 0.0182, 0.0347, 0.0388, + 0.0456, 0.0407, -0.0249, -0.0460, 0.0206, 0.0299, 0.0253, 0.0207, + 0.0177, 0.0238, 0.0253, 0.0030, 0.0042, 0.0020, -0.0081, -0.0136, +-0.0290, -0.0042, 0.0122, 0.0051, 0.0107, 0.0228, 0.0211, -0.0068, +-0.0436, -0.0299, -0.0078, -0.0779, -0.1157, -0.0679, 0.0172, 0.0150, +-0.0051, 0.0081, -0.0512, -0.0616, 0.0576, 0.0799, 0.0803, 0.0336, + 0.0001, -0.0298, -0.0747, -0.0115, -0.0101, -0.0170, -0.0050, 0.0174, +-0.0290, -0.0601, -0.0150, 0.0121, 0.0165, 0.0230, 0.0028, -0.0317, +-0.0165, 0.0356, 0.0451, 0.0120, 0.0321, 0.0084, -0.0058, 0.0122, + 0.1935, 0.1802, 0.2195, 0.2410, 0.2201, 0.1915, 0.1840, 0.1935, + 0.2213, 0.2079, 0.1858, 0.1974, 0.2239, 0.2173, 0.1840, 0.2120, + 0.4912, 0.4777, 0.4607, 0.4395, 0.4426, 0.4388, 0.4416, 0.4345, + 0.4239, 0.4331, 0.4522, 0.4423, 0.4475, 0.4387, 0.4525, 0.4446 +}, + +.lsp22_2 = { + 0.0712, 0.1830, 0.4167, 0.6669, 0.8738, 1.0696, 1.2555, 1.4426, + 1.6427, 1.8138, 1.9966, 2.1925, 2.3872, 2.5748, 2.7713, 2.9597, + 0.1894, 0.3942, 0.5418, 0.6747, 0.7517, 0.8763, 1.1189, 1.3072, + 1.5011, 1.6790, 1.8342, 2.0781, 2.2929, 2.4566, 2.6613, 2.9204, + 0.1767, 0.3403, 0.5173, 0.7055, 0.8899, 1.0696, 1.2302, 1.4111, + 1.5989, 1.7751, 1.9618, 2.1544, 2.3454, 2.5356, 2.7362, 2.9315, + 0.1240, 0.2361, 0.4423, 0.6326, 0.7729, 0.9387, 1.1142, 1.2847, + 1.4746, 1.7126, 1.9482, 2.1642, 2.3536, 2.5506, 2.7593, 2.9197, + 0.1213, 0.2782, 0.5011, 0.6910, 0.8564, 1.0462, 1.2315, 1.4232, + 1.6178, 1.8028, 1.9813, 2.1766, 2.3670, 2.5591, 2.7475, 2.9403, + 0.1382, 0.2995, 0.4693, 0.5874, 0.6929, 0.8102, 1.0094, 1.2960, + 1.5511, 1.7607, 1.9699, 2.1680, 2.3367, 2.5459, 2.7370, 2.9105, + 0.1428, 0.2690, 0.3713, 0.4757, 0.6664, 0.9019, 1.1276, 1.3674, + 1.5471, 1.6695, 1.8261, 2.0572, 2.2753, 2.4963, 2.7187, 2.9114, + 0.1669, 0.3085, 0.4489, 0.5724, 0.6934, 0.8465, 0.9680, 1.1641, + 1.4320, 1.6841, 1.8977, 2.1061, 2.3118, 2.5152, 2.7329, 2.9274, + 0.1128, 0.2709, 0.4803, 0.6878, 0.8673, 1.0693, 1.2749, 1.4657, + 1.6650, 1.8434, 2.0339, 2.2300, 2.4003, 2.5951, 2.7762, 2.9465, + 0.1201, 0.2345, 0.4021, 0.6379, 0.8651, 1.0256, 1.1630, 1.3250, + 1.5395, 1.7808, 2.0011, 2.1997, 2.3618, 2.5505, 2.7561, 2.9351, + 0.2575, 0.4163, 0.5081, 0.6484, 0.8570, 1.0832, 1.2732, 1.3933, + 1.5497, 1.7725, 1.9945, 2.2098, 2.3514, 2.5216, 2.7146, 2.8969, + 0.1367, 0.2656, 0.4470, 0.6398, 0.8146, 1.0125, 1.2142, 1.3960, + 1.5558, 1.7338, 1.9465, 2.1769, 2.4031, 2.5746, 2.7335, 2.9046, + 0.0868, 0.1723, 0.2785, 0.5071, 0.7732, 1.0024, 1.1924, 1.4220, + 1.6149, 1.8064, 1.9951, 2.1935, 2.3777, 2.5748, 2.7661, 2.9488, + 0.1428, 0.2592, 0.3875, 0.5810, 0.7513, 0.9334, 1.1096, 1.3565, + 1.5869, 1.7788, 1.9036, 2.0893, 2.3332, 2.5289, 2.7204, 2.9053, + 0.2313, 0.4066, 0.4960, 0.5853, 0.7799, 0.9201, 1.1365, 1.3499, + 1.5119, 1.7641, 1.9095, 2.0911, 2.2653, 2.4587, 2.7010, 2.8900, + 0.1927, 0.3424, 0.4682, 0.6035, 0.7330, 0.8492, 1.0477, 1.3083, + 1.5602, 1.6945, 1.7806, 2.0066, 2.2566, 2.4864, 2.7021, 2.9180, + 0.0962, 0.1933, 0.3968, 0.6077, 0.8083, 1.0224, 1.2307, 1.4344, + 1.6350, 1.8173, 2.0024, 2.1894, 2.3812, 2.5648, 2.7535, 2.9483, + 0.1469, 0.2679, 0.4272, 0.6080, 0.7949, 0.9247, 1.0741, 1.2722, + 1.5144, 1.7679, 2.0030, 2.1944, 2.3890, 2.5928, 2.8116, 2.9555, + 0.1618, 0.3917, 0.6111, 0.7511, 0.8325, 1.0010, 1.2397, 1.4147, + 1.5764, 1.7359, 1.9300, 2.1325, 2.3096, 2.5480, 2.7725, 2.9697, + 0.1561, 0.2634, 0.4062, 0.6139, 0.8059, 0.9618, 1.0948, 1.3179, + 1.5846, 1.7622, 1.9399, 2.1476, 2.3330, 2.5232, 2.7412, 2.9554, + 0.1076, 0.2320, 0.3977, 0.5798, 0.7707, 0.9975, 1.1884, 1.3793, + 1.6059, 1.8038, 1.9928, 2.1942, 2.3881, 2.5742, 2.7717, 2.9547, + 0.1360, 0.2493, 0.3827, 0.5644, 0.7384, 0.9087, 1.0865, 1.2902, + 1.5185, 1.7246, 1.9170, 2.1175, 2.3324, 2.5442, 2.7441, 2.9437, + 0.1684, 0.2990, 0.4406, 0.5834, 0.7305, 0.9028, 1.0801, 1.2756, + 1.4646, 1.6514, 1.8346, 2.0493, 2.2594, 2.4765, 2.6985, 2.9089, + 0.1145, 0.2295, 0.3421, 0.5032, 0.7007, 0.9057, 1.0830, 1.2733, + 1.4885, 1.6897, 1.8933, 2.1128, 2.3188, 2.5271, 2.7284, 2.9266, + 0.1705, 0.3815, 0.6120, 0.7964, 0.9342, 1.0926, 1.2741, 1.4645, + 1.6552, 1.8040, 1.9778, 2.1931, 2.3836, 2.5827, 2.7905, 2.9494, + 0.1284, 0.2622, 0.4714, 0.6559, 0.8004, 1.0005, 1.1416, 1.3163, + 1.5773, 1.8144, 1.9947, 2.2001, 2.3836, 2.5710, 2.7447, 2.9262, + 0.1164, 0.2882, 0.5349, 0.7310, 0.8483, 0.9729, 1.1331, 1.3350, + 1.5307, 1.7306, 1.9409, 2.1275, 2.3229, 2.5358, 2.7455, 2.9447, + 0.1159, 0.2646, 0.4677, 0.6375, 0.7771, 0.9557, 1.1398, 1.3514, + 1.5717, 1.7512, 1.9337, 2.1323, 2.3272, 2.5409, 2.7377, 2.9212, + 0.1080, 0.2143, 0.3475, 0.5307, 0.7358, 0.9681, 1.1489, 1.3289, + 1.5553, 1.7664, 1.9696, 2.1780, 2.3676, 2.5568, 2.7493, 2.9347, + 0.1331, 0.2430, 0.3879, 0.5092, 0.6324, 0.8119, 1.0327, 1.2657, + 1.4999, 1.7107, 1.9178, 2.1272, 2.3296, 2.5340, 2.7372, 2.9353, + 0.1557, 0.2873, 0.4558, 0.6548, 0.8472, 1.0106, 1.1480, 1.3281, + 1.5856, 1.7740, 1.9564, 2.1651, 2.3295, 2.5207, 2.7005, 2.9151, + 0.1397, 0.2761, 0.4533, 0.6374, 0.7510, 0.8767, 1.0408, 1.2909, + 1.5368, 1.7560, 1.9424, 2.1332, 2.3210, 2.5116, 2.6924, 2.8886, + 0.0945, 0.1653, 0.3601, 0.6129, 0.8378, 1.0333, 1.2417, 1.4539, + 1.6507, 1.8304, 2.0286, 2.2157, 2.3975, 2.5865, 2.7721, 2.9426, + 0.1892, 0.3863, 0.4896, 0.5909, 0.7294, 0.9483, 1.1575, 1.3542, + 1.4796, 1.6535, 1.9070, 2.1435, 2.3281, 2.4967, 2.7039, 2.9222, + 0.1614, 0.3129, 0.5086, 0.7048, 0.8730, 1.0239, 1.1905, 1.3799, + 1.5697, 1.7503, 1.9103, 2.1115, 2.3235, 2.5234, 2.6973, 2.8957, + 0.1199, 0.2590, 0.4273, 0.5935, 0.7542, 0.9625, 1.1225, 1.2998, + 1.5361, 1.7102, 1.9097, 2.1269, 2.3157, 2.5304, 2.7212, 2.9175, + 0.1087, 0.2373, 0.4261, 0.6277, 0.8092, 0.9884, 1.1954, 1.4077, + 1.6048, 1.7799, 1.9693, 2.1662, 2.3426, 2.5501, 2.7459, 2.9257, + 0.1262, 0.2216, 0.3857, 0.5799, 0.7148, 0.8610, 1.0752, 1.3306, + 1.5549, 1.7605, 1.9727, 2.1580, 2.3612, 2.5602, 2.7554, 2.9372, + 0.1445, 0.2832, 0.4469, 0.6283, 0.7991, 0.9796, 1.1504, 1.3323, + 1.5313, 1.7140, 1.8968, 2.0990, 2.2826, 2.4903, 2.7003, 2.9031, + 0.1647, 0.4068, 0.5428, 0.6539, 0.7682, 0.8479, 0.9372, 1.1691, + 1.4776, 1.7314, 1.9071, 2.0918, 2.2774, 2.5029, 2.7152, 2.9221, + 0.1274, 0.3052, 0.5238, 0.7280, 0.9229, 1.1211, 1.3071, 1.4784, + 1.6564, 1.8235, 2.0028, 2.1999, 2.3763, 2.5608, 2.7510, 2.9356, + 0.1076, 0.2195, 0.4815, 0.6873, 0.8241, 0.9443, 1.1066, 1.3687, + 1.6087, 1.8105, 1.9857, 2.1486, 2.3505, 2.5854, 2.7785, 2.9376, + 0.1755, 0.3089, 0.4695, 0.6648, 0.8315, 1.0202, 1.1774, 1.3554, + 1.5393, 1.7141, 1.9247, 2.1284, 2.2983, 2.4975, 2.7296, 2.9401, + 0.1636, 0.3166, 0.4594, 0.6199, 0.8161, 0.9879, 1.1738, 1.3642, + 1.5680, 1.7633, 1.9598, 2.1695, 2.3692, 2.5846, 2.7809, 2.9563, + 0.1219, 0.2662, 0.4620, 0.6491, 0.8353, 1.0150, 1.2065, 1.3944, + 1.5785, 1.7631, 1.9389, 2.1434, 2.3400, 2.5316, 2.7359, 2.9513, + 0.1072, 0.2258, 0.3968, 0.5642, 0.7222, 0.9367, 1.1458, 1.3347, + 1.5424, 1.7373, 1.9303, 2.1432, 2.3451, 2.5415, 2.7444, 2.9394, + 0.1393, 0.2950, 0.4724, 0.6407, 0.8034, 1.0031, 1.1712, 1.3552, + 1.5519, 1.7411, 1.9198, 2.1160, 2.3238, 2.5119, 2.7134, 2.9205, + 0.1358, 0.2613, 0.4239, 0.5991, 0.7643, 0.9379, 1.1213, 1.3115, + 1.5067, 1.7031, 1.8768, 2.0836, 2.3092, 2.5134, 2.7237, 2.9286, + 0.1267, 0.2695, 0.4524, 0.6591, 0.8396, 1.0173, 1.2183, 1.4205, + 1.6306, 1.8162, 2.0106, 2.2082, 2.3773, 2.5787, 2.7551, 2.9387, + 0.1314, 0.2529, 0.3837, 0.5494, 0.7446, 0.9097, 1.0489, 1.2385, + 1.4691, 1.7170, 1.9600, 2.1770, 2.3594, 2.5356, 2.7215, 2.9088, + 0.1538, 0.2931, 0.4449, 0.6041, 0.7959, 0.9666, 1.1355, 1.3214, + 1.5150, 1.7230, 1.9433, 2.1408, 2.3459, 2.5476, 2.7273, 2.9330, + 0.1771, 0.2834, 0.4136, 0.5856, 0.7516, 0.9363, 1.0596, 1.2462, + 1.4737, 1.6627, 1.8810, 2.1150, 2.3202, 2.5274, 2.7403, 2.9490, + 0.1248, 0.2494, 0.4397, 0.6352, 0.8226, 1.0015, 1.1799, 1.3458, + 1.5654, 1.8228, 2.0646, 2.2550, 2.4161, 2.5964, 2.7675, 2.9383, + 0.0933, 0.1993, 0.3105, 0.4371, 0.6417, 0.8935, 1.1244, 1.3508, + 1.5649, 1.7595, 1.9581, 2.1648, 2.3639, 2.5569, 2.7573, 2.9468, + 0.1794, 0.3229, 0.4758, 0.6238, 0.7821, 0.9640, 1.1205, 1.3116, + 1.5054, 1.6803, 1.8658, 2.0651, 2.2793, 2.4856, 2.6867, 2.9105, + 0.1252, 0.2397, 0.3844, 0.5398, 0.7044, 0.8799, 1.0526, 1.2270, + 1.4269, 1.6412, 1.8532, 2.0784, 2.2957, 2.5051, 2.7139, 2.9210, + 0.1391, 0.3494, 0.5738, 0.8024, 1.0098, 1.2094, 1.3830, 1.5509, + 1.7222, 1.8782, 2.0604, 2.2479, 2.4154, 2.5968, 2.7767, 2.9450, + 0.1122, 0.2180, 0.4175, 0.6074, 0.7559, 0.9465, 1.1513, 1.3340, + 1.5215, 1.7491, 1.9911, 2.1894, 2.3433, 2.5377, 2.7380, 2.9183, + 0.1595, 0.3029, 0.4842, 0.6324, 0.7874, 0.9814, 1.1992, 1.3554, + 1.5017, 1.7274, 1.9168, 2.0853, 2.2964, 2.5300, 2.7187, 2.9041, + 0.1350, 0.2747, 0.4791, 0.6638, 0.8050, 0.9644, 1.1238, 1.2987, + 1.4844, 1.6754, 1.8778, 2.0987, 2.3279, 2.5424, 2.7410, 2.9356, + 0.0914, 0.1727, 0.3143, 0.5124, 0.7123, 0.9323, 1.1706, 1.3821, + 1.5864, 1.7828, 1.9701, 2.1560, 2.3445, 2.5486, 2.7433, 2.9372, + 0.1222, 0.2359, 0.3931, 0.5912, 0.7776, 0.9505, 1.1623, 1.3723, + 1.5484, 1.7316, 1.9321, 2.1283, 2.3148, 2.5269, 2.7299, 2.9213, + 0.2089, 0.3872, 0.5090, 0.6413, 0.7967, 1.0226, 1.1897, 1.3908, + 1.5954, 1.7202, 1.8614, 2.1030, 2.2973, 2.5079, 2.7491, 2.8944, + 0.1288, 0.2423, 0.4108, 0.6062, 0.7688, 0.9188, 1.0876, 1.2866, + 1.4897, 1.6910, 1.9219, 2.1076, 2.2805, 2.5023, 2.7155, 2.9203, + 0.0192, 0.0462, 0.0128, 0.0054, -0.0156, -0.0118, -0.0135, 0.0030, +-0.0120, 0.0031, 0.0240, -0.0451, -0.0439, -0.0432, -0.0527, -0.0207, + 0.0253, 0.0084, -0.0305, -0.0144, 0.0046, -0.0378, -0.0467, -0.0102, + 0.0280, 0.0540, 0.0151, 0.0437, 0.0141, -0.0257, -0.0058, 0.0073, + 0.0107, 0.0054, 0.0371, -0.0105, 0.0165, -0.0143, 0.0148, 0.0382, +-0.0054, -0.0284, 0.0001, -0.0218, 0.0258, 0.0517, 0.0157, -0.0032, +-0.0190, 0.0343, 0.0576, 0.0346, 0.0392, -0.0158, -0.0323, -0.0578, +-0.0617, -0.0242, -0.0144, 0.0188, 0.0249, 0.0021, -0.0422, -0.0420, + 0.0750, 0.0762, 0.0325, -0.0066, 0.0332, 0.0376, 0.0388, 0.0630, + 0.0525, 0.0196, 0.0051, -0.0484, -0.0322, 0.0059, 0.0132, 0.0079, + 0.0237, 0.0774, 0.0697, 0.0184, -0.0321, -0.0327, 0.0274, 0.0284, + 0.0057, 0.0289, 0.0478, 0.0142, -0.0053, 0.0114, 0.0292, -0.0032, +-0.0111, -0.0389, 0.0282, 0.0613, 0.0200, -0.0006, 0.0111, 0.0048, + 0.0273, 0.0017, -0.0369, 0.0655, 0.0758, 0.0555, 0.0238, -0.0024, +-0.0100, -0.0419, -0.0696, -0.0158, -0.0479, -0.0744, -0.0356, -0.0245, +-0.0400, -0.0112, 0.0134, 0.0001, -0.0422, -0.0514, -0.0081, 0.0083, +-0.0151, 0.0323, -0.0001, -0.0444, -0.0406, -0.0214, -0.0050, -0.0235, +-0.0205, -0.0264, -0.0324, 0.0334, 0.0392, 0.0265, 0.0289, 0.0180, + 0.0493, 0.0227, 0.0194, 0.0365, 0.0544, 0.0674, 0.0559, 0.0732, + 0.0911, 0.0942, 0.0735, 0.0174, -0.0113, -0.0553, -0.0665, -0.0227, +-0.0259, -0.0266, -0.0239, -0.0379, 0.0329, 0.0173, -0.0210, -0.0114, +-0.0063, 0.0060, -0.0089, -0.0198, -0.0282, -0.0080, -0.0179, -0.0290, + 0.0046, -0.0126, -0.0066, 0.0350, 0.0532, 0.0235, 0.0198, 0.0212, + 0.0449, 0.0681, 0.0677, -0.0049, 0.0086, 0.0120, 0.0356, 0.0454, + 0.0592, 0.0449, -0.0271, -0.0510, -0.0110, 0.0234, 0.0203, 0.0243, + 0.0242, 0.0133, 0.0098, 0.0040, 0.0024, -0.0005, -0.0075, -0.0126, +-0.0393, -0.0052, 0.0165, 0.0016, -0.0193, 0.0239, 0.0336, 0.0029, +-0.0586, -0.0539, -0.0094, -0.0664, -0.0898, -0.0540, -0.0066, 0.0134, +-0.0074, 0.0067, -0.0521, -0.0431, 0.0104, 0.0690, 0.0663, 0.0197, +-0.0017, -0.0518, -0.0597, -0.0171, -0.0054, -0.0140, -0.0080, 0.0172, +-0.0362, -0.0713, -0.0310, 0.0096, 0.0243, 0.0381, -0.0062, -0.0392, +-0.0281, 0.0386, 0.0461, 0.0069, 0.0384, 0.0080, -0.0141, 0.0171, + 0.3368, 0.3128, 0.3304, 0.3392, 0.3185, 0.3037, 0.2789, 0.2692, + 0.2779, 0.2796, 0.2891, 0.2643, 0.2647, 0.2593, 0.2927, 0.3283, + 0.4978, 0.4988, 0.4969, 0.4997, 0.4957, 0.4985, 0.4970, 0.4978, + 0.4938, 0.4951, 0.4994, 0.4971, 0.4981, 0.4983, 0.4967, 0.4789 +}, + +.lsp44 = { + 0.0927, 0.2291, 0.4059, 0.5779, 0.7288, 0.8821, 1.0377, 1.1915, + 1.3433, 1.4931, 1.6475, 1.7989, 1.9381, 2.0858, 2.2321, 2.3765, + 2.5187, 2.6530, 2.7895, 2.9354, 0.0944, 0.1974, 0.3046, 0.4714, + 0.6116, 0.7829, 0.9027, 1.0375, 1.1869, 1.3488, 1.5036, 1.6781, + 1.8276, 1.9983, 2.1449, 2.3089, 2.4534, 2.6113, 2.7553, 2.9062, + 0.1168, 0.2843, 0.4907, 0.6706, 0.8100, 0.9417, 1.0753, 1.2014, + 1.3151, 1.4496, 1.5832, 1.7379, 1.8642, 2.0230, 2.1681, 2.3250, + 2.4676, 2.6242, 2.7602, 2.9066, 0.1353, 0.2335, 0.3370, 0.4380, + 0.5819, 0.7353, 0.8671, 1.0160, 1.1435, 1.2977, 1.4860, 1.6739, + 1.8412, 2.0028, 2.1537, 2.3124, 2.4741, 2.6272, 2.7862, 2.9536, + 0.1003, 0.2226, 0.3584, 0.4971, 0.6291, 0.7710, 0.9157, 1.0669, + 1.2143, 1.3624, 1.5104, 1.6681, 1.8164, 1.9823, 2.1394, 2.3082, + 2.4677, 2.6306, 2.7909, 2.9382, 0.1056, 0.2027, 0.2956, 0.4005, + 0.5215, 0.6708, 0.8545, 1.0557, 1.2344, 1.4023, 1.5676, 1.7278, + 1.8808, 2.0381, 2.1846, 2.3376, 2.4887, 2.6377, 2.7878, 2.9504, + 0.1015, 0.2462, 0.4122, 0.5783, 0.7233, 0.8833, 1.0377, 1.1903, + 1.3341, 1.4727, 1.6138, 1.7582, 1.8912, 2.0370, 2.1701, 2.3125, + 2.4500, 2.6006, 2.7507, 2.9166, 0.1787, 0.2418, 0.3265, 0.5379, + 0.6584, 0.7681, 0.9545, 1.1050, 1.2125, 1.3528, 1.4763, 1.6705, + 1.8136, 1.9594, 2.0936, 2.2724, 2.4394, 2.5919, 2.7037, 2.8747, + 0.0859, 0.1600, 0.2980, 0.4933, 0.6696, 0.8285, 0.9958, 1.1545, + 1.3107, 1.4591, 1.6127, 1.7652, 1.9143, 2.0680, 2.2171, 2.3643, + 2.5141, 2.6611, 2.8143, 2.9691, 0.0910, 0.2110, 0.3364, 0.4718, + 0.5856, 0.7298, 0.8910, 1.0514, 1.1988, 1.3572, 1.5178, 1.6861, + 1.8399, 2.0099, 2.1639, 2.3225, 2.4774, 2.6321, 2.7863, 2.9412, + 0.1904, 0.2874, 0.3681, 0.4981, 0.6248, 0.7880, 0.9121, 1.0750, + 1.2185, 1.3809, 1.5296, 1.7007, 1.8592, 2.0470, 2.1913, 2.3250, + 2.4519, 2.5984, 2.7408, 2.9023, 0.0917, 0.2067, 0.3246, 0.4961, + 0.6310, 0.8024, 0.9438, 1.1008, 1.2362, 1.3892, 1.5407, 1.7033, + 1.8427, 2.0061, 2.1498, 2.3117, 2.4550, 2.6053, 2.7462, 2.9029, + 0.0989, 0.2193, 0.3756, 0.5410, 0.6929, 0.8368, 0.9801, 1.1250, + 1.2677, 1.4184, 1.5677, 1.7292, 1.8770, 2.0311, 2.1803, 2.3306, + 2.4836, 2.6339, 2.7943, 2.9549, 0.0861, 0.1943, 0.3057, 0.4867, + 0.6194, 0.7592, 0.9184, 1.1052, 1.2486, 1.4064, 1.5609, 1.7273, + 1.8703, 2.0291, 2.1686, 2.3225, 2.4628, 2.6115, 2.7471, 2.9005, + 0.0932, 0.2110, 0.3737, 0.5479, 0.7120, 0.8570, 0.9975, 1.1364, + 1.2772, 1.4220, 1.5612, 1.7089, 1.8410, 1.9827, 2.1263, 2.2859, + 2.4459, 2.6172, 2.7788, 2.9395, 0.1193, 0.2341, 0.3523, 0.5029, + 0.6437, 0.7803, 0.9367, 1.1007, 1.2392, 1.3869, 1.5425, 1.7168, + 1.8709, 2.0248, 2.1584, 2.2949, 2.4308, 2.5823, 2.7235, 2.9034, + 0.0834, 0.1988, 0.3557, 0.5261, 0.6767, 0.8427, 1.0029, 1.1683, + 1.3138, 1.4527, 1.6046, 1.7583, 1.9011, 2.0517, 2.1928, 2.3397, + 2.4839, 2.6291, 2.7771, 2.9329, 0.0938, 0.1967, 0.3213, 0.4675, + 0.6068, 0.7664, 0.9418, 1.1120, 1.2535, 1.3932, 1.5243, 1.6801, + 1.8346, 1.9931, 2.1376, 2.3035, 2.4636, 2.6244, 2.7829, 2.9371, + 0.1017, 0.2552, 0.4327, 0.6017, 0.7467, 0.8797, 1.0097, 1.1442, + 1.2628, 1.4049, 1.5541, 1.7090, 1.8461, 1.9982, 2.1486, 2.3029, + 2.4513, 2.6075, 2.7594, 2.9209, 0.1031, 0.2295, 0.3747, 0.5122, + 0.6596, 0.7935, 0.9345, 1.1050, 1.2384, 1.3543, 1.4739, 1.6136, + 1.7447, 1.8914, 2.0434, 2.1916, 2.3557, 2.5396, 2.7419, 2.9401, + 0.1007, 0.2374, 0.3715, 0.5173, 0.6465, 0.8069, 0.9553, 1.1145, + 1.2594, 1.4143, 1.5617, 1.7166, 1.8457, 2.0012, 2.1462, 2.2864, + 2.4258, 2.5910, 2.7372, 2.9018, 0.0808, 0.1726, 0.2849, 0.4592, + 0.6118, 0.7853, 0.9588, 1.1256, 1.2751, 1.4392, 1.5898, 1.7514, + 1.8977, 2.0554, 2.1937, 2.3430, 2.4831, 2.6249, 2.7601, 2.9155, + 0.1669, 0.2574, 0.3694, 0.5569, 0.6773, 0.8061, 1.0160, 1.1667, + 1.2791, 1.4041, 1.5452, 1.7207, 1.8524, 2.0038, 2.1414, 2.3338, + 2.4747, 2.6157, 2.7303, 2.8848, 0.1598, 0.2521, 0.3416, 0.5149, + 0.6703, 0.7941, 0.9408, 1.1164, 1.2017, 1.3293, 1.4908, 1.6783, + 1.8438, 1.9927, 2.1149, 2.2698, 2.4420, 2.6193, 2.7583, 2.9103, + 0.0902, 0.1978, 0.3265, 0.4578, 0.5878, 0.7439, 0.9110, 1.0906, + 1.2556, 1.4125, 1.5688, 1.7295, 1.8829, 2.0472, 2.2058, 2.3537, + 2.5075, 2.6548, 2.8058, 2.9538, 0.0818, 0.1695, 0.2794, 0.4470, + 0.6069, 0.7641, 0.9313, 1.0946, 1.2411, 1.4072, 1.5640, 1.7186, + 1.8651, 2.0254, 2.1726, 2.3286, 2.4784, 2.6287, 2.7750, 2.9339, + 0.1980, 0.3134, 0.4099, 0.4975, 0.6491, 0.8376, 0.9441, 1.0298, + 1.1795, 1.3866, 1.5784, 1.7209, 1.8137, 1.9271, 2.0863, 2.2930, + 2.4696, 2.6184, 2.7587, 2.9251, 0.1338, 0.2341, 0.3566, 0.4797, + 0.6129, 0.7580, 0.9093, 1.0491, 1.1911, 1.3313, 1.4841, 1.6503, + 1.8035, 1.9685, 2.1128, 2.2694, 2.4093, 2.5728, 2.7206, 2.8994, + 0.0937, 0.2034, 0.3447, 0.5032, 0.6370, 0.7993, 0.9674, 1.1323, + 1.2830, 1.4199, 1.5492, 1.7010, 1.8513, 2.0087, 2.1550, 2.3115, + 2.4643, 2.6237, 2.7812, 2.9392, 0.1085, 0.2152, 0.3126, 0.4569, + 0.5718, 0.7213, 0.8837, 1.0604, 1.2053, 1.3755, 1.5397, 1.7001, + 1.8409, 2.0039, 2.1498, 2.3080, 2.4535, 2.6063, 2.7505, 2.9110, + 0.0562, 0.2066, 0.4034, 0.5490, 0.6682, 0.7924, 0.9495, 1.0800, + 1.1869, 1.3156, 1.4834, 1.6619, 1.8404, 2.0199, 2.1509, 2.2755, + 2.4072, 2.5580, 2.6993, 2.8913, 0.0939, 0.2303, 0.3742, 0.5260, + 0.6662, 0.8294, 0.9769, 1.1315, 1.2792, 1.4153, 1.5436, 1.6701, + 1.8215, 1.9920, 2.1310, 2.3005, 2.4534, 2.5786, 2.7204, 2.9068, + 0.1005, 0.2442, 0.3898, 0.5398, 0.6958, 0.8474, 1.0008, 1.1556, + 1.3020, 1.4456, 1.5954, 1.7470, 1.8922, 2.0500, 2.2019, 2.3492, + 2.4963, 2.6412, 2.7890, 2.9423, 0.1022, 0.2031, 0.3213, 0.4402, + 0.5637, 0.7117, 0.8673, 1.0242, 1.1727, 1.3206, 1.4846, 1.6465, + 1.8015, 1.9655, 2.1233, 2.2873, 2.4464, 2.6074, 2.7685, 2.9409, + 0.1985, 0.3497, 0.4622, 0.5982, 0.7489, 0.8752, 0.9925, 1.1679, + 1.3288, 1.4606, 1.5820, 1.7492, 1.8922, 2.0511, 2.1780, 2.3373, + 2.4760, 2.6233, 2.7466, 2.8978, 0.1284, 0.2433, 0.3630, 0.4852, + 0.6117, 0.7460, 0.8904, 1.0360, 1.1738, 1.3142, 1.4696, 1.6185, + 1.7719, 1.9318, 2.0961, 2.2697, 2.4408, 2.6046, 2.7681, 2.9451, + 0.1042, 0.2286, 0.3598, 0.5064, 0.6438, 0.7899, 0.9350, 1.0891, + 1.2323, 1.3807, 1.5225, 1.6747, 1.8153, 1.9669, 2.1145, 2.2832, + 2.4430, 2.6085, 2.7748, 2.9346, 0.0780, 0.1724, 0.2440, 0.3489, + 0.5280, 0.7426, 0.9272, 1.0914, 1.2562, 1.4188, 1.5804, 1.7376, + 1.8909, 2.0473, 2.1946, 2.3457, 2.4950, 2.6424, 2.7926, 2.9549, + 0.1103, 0.2608, 0.4087, 0.5538, 0.6923, 0.8418, 0.9940, 1.1507, + 1.2919, 1.4406, 1.5802, 1.7262, 1.8638, 2.0085, 2.1572, 2.2975, + 2.4329, 2.5866, 2.7380, 2.9107, 0.1297, 0.2532, 0.4003, 0.5329, + 0.6733, 0.7950, 0.9557, 1.0859, 1.2235, 1.3538, 1.5037, 1.6389, + 1.7964, 1.9285, 2.0898, 2.2541, 2.4231, 2.5711, 2.6875, 2.8947, + 0.0871, 0.1968, 0.3425, 0.4949, 0.6424, 0.7959, 0.9534, 1.1132, + 1.2656, 1.4229, 1.5785, 1.7271, 1.8729, 2.0355, 2.1998, 2.3562, + 2.5151, 2.6663, 2.8145, 2.9534, 0.1038, 0.2204, 0.3248, 0.4566, + 0.5947, 0.7443, 0.8811, 1.0379, 1.2031, 1.3772, 1.5430, 1.7092, + 1.8625, 2.0322, 2.1904, 2.3417, 2.4960, 2.6458, 2.7979, 2.9485, + 0.1329, 0.2763, 0.3943, 0.5147, 0.6512, 0.8071, 0.9410, 1.0879, + 1.2298, 1.3850, 1.5282, 1.6674, 1.8137, 1.9993, 2.1344, 2.2749, + 2.4257, 2.5863, 2.7410, 2.9184, 0.1052, 0.2142, 0.3584, 0.5033, + 0.6387, 0.7804, 0.9320, 1.0780, 1.2172, 1.3764, 1.5421, 1.6887, + 1.8246, 1.9833, 2.1245, 2.2797, 2.4237, 2.5779, 2.7257, 2.9097, + 0.1092, 0.2676, 0.4071, 0.5355, 0.6661, 0.8142, 0.9621, 1.1173, + 1.2628, 1.4185, 1.5696, 1.7220, 1.8595, 2.0178, 2.1720, 2.3221, + 2.4718, 2.6259, 2.7775, 2.9334, 0.0929, 0.2017, 0.3073, 0.4570, + 0.5775, 0.7635, 0.9299, 1.0832, 1.2334, 1.3935, 1.5420, 1.7112, + 1.8601, 2.0309, 2.1735, 2.3230, 2.4543, 2.6034, 2.7418, 2.8988, + 0.0775, 0.2005, 0.3490, 0.5200, 0.6747, 0.8383, 0.9885, 1.1738, + 1.3141, 1.4236, 1.5892, 1.7402, 1.8474, 2.0210, 2.1593, 2.2730, + 2.4235, 2.5604, 2.7128, 2.9005, 0.1104, 0.2292, 0.3353, 0.4732, + 0.6152, 0.7675, 0.9164, 1.0907, 1.2594, 1.4064, 1.5218, 1.6426, + 1.8018, 1.9937, 2.1362, 2.2961, 2.4523, 2.6083, 2.7613, 2.9202, + 0.0826, 0.2000, 0.3384, 0.5144, 0.6694, 0.8377, 0.9870, 1.1461, + 1.2950, 1.4495, 1.5872, 1.7387, 1.8793, 2.0329, 2.1723, 2.3114, + 2.4415, 2.5908, 2.7354, 2.9028, 0.1063, 0.2268, 0.3442, 0.4735, + 0.6116, 0.7507, 0.9028, 1.0768, 1.2426, 1.4052, 1.5566, 1.7015, + 1.8243, 1.9742, 2.1276, 2.2824, 2.4262, 2.5953, 2.7627, 2.9290, + 0.1150, 0.2814, 0.4543, 0.6095, 0.7373, 0.8592, 0.9908, 1.1108, + 1.2339, 1.3590, 1.4864, 1.6168, 1.7392, 1.8752, 2.0212, 2.1688, + 2.3128, 2.4869, 2.7019, 2.9239, 0.0948, 0.2074, 0.3433, 0.4943, + 0.6346, 0.7645, 0.8809, 1.0610, 1.2307, 1.3487, 1.4655, 1.6186, + 1.7534, 1.8859, 2.0486, 2.2200, 2.3835, 2.5581, 2.7565, 2.9502, + 0.1062, 0.2239, 0.3683, 0.5197, 0.6704, 0.8184, 0.9642, 1.1127, + 1.2556, 1.3976, 1.5405, 1.6940, 1.8375, 1.9888, 2.1377, 2.2980, + 2.4555, 2.6184, 2.7849, 2.9452, 0.0888, 0.2005, 0.2847, 0.4322, + 0.5763, 0.7577, 0.9262, 1.1095, 1.2719, 1.4331, 1.5843, 1.7452, + 1.8845, 2.0385, 2.1805, 2.3345, 2.4750, 2.6217, 2.7555, 2.9013, + 0.1713, 0.2617, 0.3868, 0.5859, 0.7073, 0.8535, 1.0593, 1.1778, + 1.3109, 1.4508, 1.5910, 1.7463, 1.8911, 2.0651, 2.2035, 2.3355, + 2.4947, 2.6440, 2.7424, 2.8943, 0.1346, 0.2549, 0.4089, 0.5488, + 0.6949, 0.8394, 0.9810, 1.1145, 1.2528, 1.4044, 1.5423, 1.6872, + 1.8274, 1.9726, 2.1403, 2.2809, 2.4128, 2.5564, 2.6887, 2.8895, + 0.0776, 0.1621, 0.2553, 0.4191, 0.5988, 0.7921, 0.9651, 1.1350, + 1.2930, 1.4475, 1.6011, 1.7585, 1.9068, 2.0638, 2.2102, 2.3594, + 2.5096, 2.6581, 2.8099, 2.9654, 0.0864, 0.1778, 0.2854, 0.4235, + 0.5568, 0.7220, 0.8963, 1.0609, 1.2217, 1.3830, 1.5422, 1.7018, + 1.8551, 2.0206, 2.1783, 2.3328, 2.4869, 2.6366, 2.7923, 2.9539, + 0.1144, 0.2576, 0.4186, 0.5594, 0.6875, 0.8221, 0.9598, 1.0944, + 1.2273, 1.3713, 1.5152, 1.6628, 1.8070, 1.9525, 2.0965, 2.2535, + 2.4132, 2.5725, 2.7250, 2.9150, 0.1079, 0.2221, 0.3334, 0.4845, + 0.6083, 0.7516, 0.9018, 1.0594, 1.2060, 1.3673, 1.5212, 1.6880, + 1.8208, 1.9831, 2.1269, 2.2909, 2.4366, 2.6027, 2.7339, 2.8924, + 0.0994, 0.2233, 0.3634, 0.5145, 0.6568, 0.8131, 0.9746, 1.1296, + 1.2666, 1.4116, 1.5748, 1.7264, 1.8649, 2.0217, 2.1716, 2.3293, + 2.4900, 2.6455, 2.7818, 2.9362, 0.1120, 0.2079, 0.3128, 0.4124, + 0.5291, 0.6816, 0.8478, 1.0150, 1.1772, 1.3456, 1.5208, 1.6882, + 1.8458, 2.0078, 2.1627, 2.3198, 2.4733, 2.6251, 2.7796, 2.9489, + 0.0853, 0.2030, 0.3669, 0.5326, 0.6678, 0.8086, 0.9526, 1.1142, + 1.2551, 1.4158, 1.5694, 1.7073, 1.8431, 1.9686, 2.1153, 2.2376, + 2.3686, 2.5591, 2.7320, 2.9104, 0.0905, 0.2166, 0.3539, 0.5201, + 0.6700, 0.8346, 0.9883, 1.1457, 1.2714, 1.3845, 1.5172, 1.6688, + 1.8008, 1.9535, 2.1019, 2.2708, 2.4135, 2.5974, 2.7486, 2.9033, + 0.0084, 0.0374, 0.0164, -0.0153, 0.0288, 0.0107, -0.0255, -0.0242, + 0.0000, -0.0055, -0.0081, -0.0075, -0.0022, -0.0052, -0.0069, -0.0017, + 0.0003, 0.0091, 0.0028, -0.0027, 0.0085, 0.0043, -0.0235, -0.0411, + 0.0202, 0.0359, 0.0376, 0.0321, 0.0306, -0.0358, -0.0276, -0.0090, + 0.0032, 0.0048, 0.0309, 0.0332, 0.0284, 0.0237, 0.0051, -0.0101, +-0.0233, -0.0428, -0.0585, -0.0387, 0.0039, 0.0081, 0.0029, -0.0017, +-0.0006, -0.0068, 0.0044, 0.0182, 0.0376, 0.0387, -0.0334, -0.0269, +-0.0182, -0.0069, -0.0026, 0.0035, -0.0049, -0.0212, -0.0408, -0.0245, + 0.0186, 0.0189, 0.0153, 0.0120, 0.0157, 0.0055, -0.0046, 0.0179, + 0.0284, -0.0032, -0.0261, -0.0205, -0.0039, 0.0174, 0.0299, 0.0207, + 0.0012, -0.0056, 0.0010, 0.0141, -0.0119, 0.0190, 0.0315, 0.0033, +-0.0128, 0.0300, 0.0328, 0.0308, 0.0353, 0.0266, 0.0066, -0.0328, +-0.0273, 0.0054, 0.0145, 0.0175, 0.0015, -0.0171, 0.0062, -0.0164, + 0.0045, -0.0071, 0.0025, 0.0278, 0.0283, 0.0117, -0.0026, -0.0285, +-0.0408, -0.0366, -0.0059, -0.0208, -0.0354, -0.0334, -0.0263, -0.0064, + 0.0072, -0.0006, -0.0235, -0.0037, -0.0307, -0.0294, -0.0163, -0.0197, +-0.0235, 0.0192, 0.0013, -0.0219, -0.0123, -0.0004, -0.0081, -0.0096, +-0.0123, -0.0101, 0.0021, 0.0151, 0.0106, 0.0151, 0.0292, 0.0033, + 0.0283, 0.0124, 0.0058, -0.0017, -0.0038, 0.0152, 0.0141, 0.0132, + 0.0178, 0.0157, 0.0073, 0.0176, 0.0141, 0.0097, -0.0092, -0.0163, +-0.0230, -0.0134, -0.0099, -0.0147, 0.0040, -0.0183, -0.0175, -0.0080, +-0.0083, -0.0290, -0.0417, -0.0398, -0.0269, -0.0199, -0.0143, -0.0053, +-0.0099, -0.0054, -0.0199, -0.0219, -0.0170, 0.0107, 0.0194, 0.0035, + 0.0437, 0.0406, 0.0215, 0.0120, 0.0053, -0.0028, 0.0238, 0.0337, + 0.0217, 0.0011, 0.0227, 0.0244, 0.0327, 0.0378, 0.0437, 0.0356, +-0.0033, 0.0113, 0.0407, 0.0334, -0.0125, -0.0003, -0.0141, -0.0273, +-0.0137, -0.0079, -0.0145, -0.0071, 0.0114, 0.0181, 0.0150, 0.0085, +-0.0077, -0.0038, -0.0219, -0.0263, -0.0187, -0.0233, 0.0133, 0.0265, +-0.0156, -0.0091, -0.0110, -0.0016, 0.0143, 0.0177, 0.0240, 0.0082, +-0.0143, -0.0257, -0.0014, 0.0002, 0.0082, 0.0180, 0.0325, 0.0340, +-0.0153, -0.0389, -0.0240, 0.0082, 0.0140, 0.0046, -0.0138, -0.0378, +-0.0366, 0.0297, 0.0252, 0.0078, 0.0063, 0.0006, 0.0044, 0.0074, + 0.0094, 0.0113, 0.0105, 0.0137, 0.0438, 0.0262, -0.0078, -0.0185, +-0.0215, -0.0407, -0.0435, -0.0208, -0.0004, -0.0144, -0.0205, -0.0248, +-0.0159, -0.0069, -0.0153, 0.0132, 0.0355, 0.0298, 0.0120, 0.0072, + 0.0236, 0.0526, 0.0479, 0.0233, -0.0133, -0.0283, -0.0468, -0.0549, +-0.0370, 0.0032, 0.0056, 0.0023, 0.0050, 0.0024, 0.0279, 0.0116, +-0.0045, -0.0012, 0.0107, 0.0190, 0.0253, 0.0191, 0.0043, 0.0193, +-0.0348, -0.0246, 0.0123, 0.0210, 0.0135, -0.0096, -0.0109, -0.0076, +-0.0156, -0.0290, 0.0160, 0.0194, 0.0219, 0.0259, 0.0250, 0.0195, + 0.4948, 0.4961, 0.4940, 0.4878, 0.4849, 0.4727, 0.4571, 0.4551, + 0.4534, 0.4468, 0.4412, 0.4354, 0.4298, 0.4272, 0.4498, 0.4506, + 0.4560, 0.4592, 0.4758, 0.4941, 0.2476, 0.1771, 0.1974, 0.1881, + 0.1667, 0.1826, 0.2067, 0.2031, 0.1734, 0.1534, 0.1415, 0.1761, + 0.1897, 0.1772, 0.1651, 0.1247, 0.1041, 0.1231, 0.1809, 0.2234 + }, +}; + + +static const uint8_t tab7[][35] = { + {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,1,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,0,0,0,0,1,0,0,0}, + {0,0,0,1,0,0,0,0,0,0,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,1,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,0,0}, + {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,1,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,0,0,0,0,1,0,0,0}, + {0,0,0,1,0,0,0,0,0,0,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,1,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,0,0}, + {0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,0,1,0,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,0,0,0,0,0,0,0,0}, + {0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0} +}; + +static const uint8_t tab8[][5] = { + {0, 0, 0, 1, 1}, + {0, 1, 0, 0, 1}, + {1, 1, 0, 0, 0}, + {1, 0, 0, 1, 0}, + {0, 0, 0, 1, 1}, + {0, 1, 0, 0, 1}, + {1, 1, 0, 0, 0}, + {1, 0, 0, 1, 0}, + {0, 0, 0, 1, 1}, + {0, 1, 0, 0, 1}, + {1, 1, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 1, 0, 1, 0} +}; + +static const uint8_t tab9[][45] = { + { + 0, 0, 0, 0, 0, 0, 0, 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, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 + },{ + 0, 0, 0, 0, 1, 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, 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, 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, 0, 0, 0, 0, 0 + },{ + 0, 0, 0, 0, 0, 0, 0, 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, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 + },{ + 0, 0, 0, 0, 1, 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, 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, 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, 0, 0, 0, 0, 0 + },{ + 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, + 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0 + },{ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + } +}; + +static const uint8_t tab10[][25] = +{ + {1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0}, + {1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0}, + {1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0}, + {1, 1, 1, 1, 1, 1, 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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, + {0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1}, + {0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1}, + {1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0}, + {0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1} +}; + +static const uint8_t tab11[][55] = { + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 1, 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, 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, 0, 0, 1, 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, 0, 0, 0, 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, 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, 0, 0, 0, 0, 0, 0, 0, 0, + }, { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 1, 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, 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, 0, 0, 1, 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, 0, 0, 0, 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, 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, 0, 0, 0, 0, 0, 0, 0, 0, + },{ + 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, + } +}; + +static const uint8_t tab12[][15] = { + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0}, + {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, + {0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0}, + {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, + {0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0}, + {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1}, +}; + +static const struct { + int size; + const uint8_t *tab; +} tabs[] = { + {0 , NULL}, + {5 , &tab8 [0][0]},{5 , &tab8 [0][0]}, {15, &tab12[0][0]}, + {5 , &tab8 [0][0]},{25, &tab10[0][0]}, {15, &tab12[0][0]}, + {35, &tab7 [0][0]},{5 , &tab8 [0][0]}, {45, &tab9 [0][0]}, + {25, &tab10[0][0]},{55, &tab11[0][0]}, {15, &tab12[0][0]} +}; + +#endif /* AVCODEC_TWINVQ_DATA_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/txd.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/txd.c index 5065d08f19..ac8229f9e4 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/txd.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/txd.c @@ -156,7 +156,7 @@ static av_cold int txd_end(AVCodecContext *avctx) { AVCodec txd_decoder = { "txd", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_TXD, sizeof(TXDContext), txd_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ulti.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/ulti.c index ac21f41541..1d04c807fb 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/ulti.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ulti.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/ulti.c + * @file * IBM Ultimotion Video Decoder. */ @@ -55,6 +55,16 @@ static av_cold int ulti_decode_init(AVCodecContext *avctx) return 0; } +static av_cold int ulti_decode_end(AVCodecContext *avctx){ + UltimotionDecodeContext *s = avctx->priv_data; + AVFrame *pic = &s->frame; + + if (pic->data[0]) + avctx->release_buffer(avctx, pic); + + return 0; +} + static const int block_coords[8] = // 4x4 block coords in 8x8 superblock { 0, 0, 0, 4, 4, 4, 4, 0}; @@ -394,16 +404,9 @@ static int ulti_decode_frame(AVCodecContext *avctx, return buf_size; } -static av_cold int ulti_decode_end(AVCodecContext *avctx) -{ -/* UltimotionDecodeContext *s = avctx->priv_data;*/ - - return 0; -} - AVCodec ulti_decoder = { "ultimotion", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_ULTI, sizeof(UltimotionDecodeContext), ulti_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/utils.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/utils.c index 43147a5216..014427d59f 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/utils.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/utils.c @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/utils.c + * @file * utils. */ @@ -31,11 +31,13 @@ #include "libavutil/avstring.h" #include "libavutil/integer.h" #include "libavutil/crc.h" +#include "libavutil/pixdesc.h" #include "avcodec.h" #include "dsputil.h" #include "opt.h" #include "imgconvert.h" #include "audioconvert.h" +#include "libxvid_internal.h" #include "internal.h" #include #include @@ -45,25 +47,6 @@ #include #endif -const uint8_t ff_reverse[256]={ -0x00,0x80,0x40,0xC0,0x20,0xA0,0x60,0xE0,0x10,0x90,0x50,0xD0,0x30,0xB0,0x70,0xF0, -0x08,0x88,0x48,0xC8,0x28,0xA8,0x68,0xE8,0x18,0x98,0x58,0xD8,0x38,0xB8,0x78,0xF8, -0x04,0x84,0x44,0xC4,0x24,0xA4,0x64,0xE4,0x14,0x94,0x54,0xD4,0x34,0xB4,0x74,0xF4, -0x0C,0x8C,0x4C,0xCC,0x2C,0xAC,0x6C,0xEC,0x1C,0x9C,0x5C,0xDC,0x3C,0xBC,0x7C,0xFC, -0x02,0x82,0x42,0xC2,0x22,0xA2,0x62,0xE2,0x12,0x92,0x52,0xD2,0x32,0xB2,0x72,0xF2, -0x0A,0x8A,0x4A,0xCA,0x2A,0xAA,0x6A,0xEA,0x1A,0x9A,0x5A,0xDA,0x3A,0xBA,0x7A,0xFA, -0x06,0x86,0x46,0xC6,0x26,0xA6,0x66,0xE6,0x16,0x96,0x56,0xD6,0x36,0xB6,0x76,0xF6, -0x0E,0x8E,0x4E,0xCE,0x2E,0xAE,0x6E,0xEE,0x1E,0x9E,0x5E,0xDE,0x3E,0xBE,0x7E,0xFE, -0x01,0x81,0x41,0xC1,0x21,0xA1,0x61,0xE1,0x11,0x91,0x51,0xD1,0x31,0xB1,0x71,0xF1, -0x09,0x89,0x49,0xC9,0x29,0xA9,0x69,0xE9,0x19,0x99,0x59,0xD9,0x39,0xB9,0x79,0xF9, -0x05,0x85,0x45,0xC5,0x25,0xA5,0x65,0xE5,0x15,0x95,0x55,0xD5,0x35,0xB5,0x75,0xF5, -0x0D,0x8D,0x4D,0xCD,0x2D,0xAD,0x6D,0xED,0x1D,0x9D,0x5D,0xDD,0x3D,0xBD,0x7D,0xFD, -0x03,0x83,0x43,0xC3,0x23,0xA3,0x63,0xE3,0x13,0x93,0x53,0xD3,0x33,0xB3,0x73,0xF3, -0x0B,0x8B,0x4B,0xCB,0x2B,0xAB,0x6B,0xEB,0x1B,0x9B,0x5B,0xDB,0x3B,0xBB,0x7B,0xFB, -0x07,0x87,0x47,0xC7,0x27,0xA7,0x67,0xE7,0x17,0x97,0x57,0xD7,0x37,0xB7,0x77,0xF7, -0x0F,0x8F,0x4F,0xCF,0x2F,0xAF,0x6F,0xEF,0x1F,0x9F,0x5F,0xDF,0x3F,0xBF,0x7F,0xFF, -}; - static int volatile entangled_thread_counter=0; int (*ff_lockmgr_cb)(void **mutex, enum AVLockOp op); static void *codec_mutex; @@ -118,6 +101,11 @@ void register_avcodec(AVCodec *codec) } #endif +unsigned avcodec_get_edge_width(void) +{ + return EDGE_WIDTH; +} + void avcodec_set_dimensions(AVCodecContext *s, int width, int height){ s->coded_width = width; s->coded_height= height; @@ -136,7 +124,7 @@ typedef struct InternalBuffer{ #define INTERNAL_BUFFER_SIZE 32 -void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){ +void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height, int linesize_align[4]){ int w_align= 1; int h_align= 1; @@ -145,17 +133,19 @@ void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){ case PIX_FMT_YUYV422: case PIX_FMT_UYVY422: case PIX_FMT_YUV422P: + case PIX_FMT_YUV440P: case PIX_FMT_YUV444P: case PIX_FMT_GRAY8: case PIX_FMT_GRAY16BE: case PIX_FMT_GRAY16LE: case PIX_FMT_YUVJ420P: case PIX_FMT_YUVJ422P: + case PIX_FMT_YUVJ440P: case PIX_FMT_YUVJ444P: case PIX_FMT_YUVA420P: w_align= 16; //FIXME check for non mpeg style codecs and use less alignment h_align= 16; - if(s->codec_id == CODEC_ID_MPEG2VIDEO) + 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) h_align= 32; // interlaced is rounded up to 2 MBs break; case PIX_FMT_YUV411P: @@ -197,6 +187,36 @@ void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){ *height= FFALIGN(*height, h_align); if(s->codec_id == CODEC_ID_H264) *height+=2; // some of the optimized chroma MC reads one line too much + + linesize_align[0] = + linesize_align[1] = + linesize_align[2] = + linesize_align[3] = STRIDE_ALIGN; +//STRIDE_ALIGN is 8 for SSE* but this does not work for SVQ1 chroma planes +//we could change STRIDE_ALIGN to 16 for x86/sse but it would increase the +//picture size unneccessarily in some cases. The solution here is not +//pretty and better ideas are welcome! +#if HAVE_MMX + if(s->codec_id == CODEC_ID_SVQ1 || s->codec_id == CODEC_ID_VP5 || + s->codec_id == CODEC_ID_VP6 || s->codec_id == CODEC_ID_VP6F || + s->codec_id == CODEC_ID_VP6A) { + linesize_align[0] = + linesize_align[1] = + linesize_align[2] = 16; + } +#endif +} + +void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){ + int chroma_shift = av_pix_fmt_descriptors[s->pix_fmt].log2_chroma_w; + int linesize_align[4]; + int align; + avcodec_align_dimensions2(s, width, height, linesize_align); + align = FFMAX(linesize_align[0], linesize_align[3]); + linesize_align[1] <<= chroma_shift; + linesize_align[2] <<= chroma_shift; + align = FFMAX3(align, linesize_align[1], linesize_align[2]); + *width=FFALIGN(*width, align); } int avcodec_check_dimensions(void *av_log_ctx, unsigned int w, unsigned int h){ @@ -204,7 +224,7 @@ int avcodec_check_dimensions(void *av_log_ctx, unsigned int w, unsigned int h){ return 0; av_log(av_log_ctx, AV_LOG_ERROR, "picture size invalid (%ux%u)\n", w, h); - return -1; + return AVERROR(EINVAL); } int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){ @@ -261,7 +281,7 @@ int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){ avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift); - avcodec_align_dimensions(s, &w, &h); + avcodec_align_dimensions2(s, &w, &h, stride_align); if(!(s->flags&CODEC_FLAG_EMU_EDGE)){ w+= EDGE_WIDTH*2; @@ -277,16 +297,6 @@ int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){ unaligned = 0; for (i=0; i<4; i++){ -//STRIDE_ALIGN is 8 for SSE* but this does not work for SVQ1 chroma planes -//we could change STRIDE_ALIGN to 16 for x86/sse but it would increase the -//picture size unneccessarily in some cases. The solution here is not -//pretty and better ideas are welcome! -#if HAVE_MMX - if(s->codec_id == CODEC_ID_SVQ1) - stride_align[i]= 16; - else -#endif - stride_align[i] = STRIDE_ALIGN; unaligned |= picture.linesize[i] % stride_align[i]; } } while (unaligned); @@ -384,8 +394,10 @@ int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic){ } /* If internal buffer type return the same buffer */ - if(pic->type == FF_BUFFER_TYPE_INTERNAL) + if(pic->type == FF_BUFFER_TYPE_INTERNAL) { + pic->reordered_opaque= s->reordered_opaque; return 0; + } /* * Not internal type and reget_buffer not overridden, emulate cr buffer @@ -414,6 +426,16 @@ int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, v return 0; } +int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr),void *arg, int *ret, int count){ + int i; + + for(i=0; iwidth && avctx->height) avcodec_set_dimensions(avctx, avctx->width, avctx->height); - if((avctx->coded_width||avctx->coded_height) && avcodec_check_dimensions(avctx,avctx->coded_width,avctx->coded_height)){ - av_freep(&avctx->priv_data); +#define SANE_NB_CHANNELS 128U + if (((avctx->coded_width || avctx->coded_height) + && avcodec_check_dimensions(avctx, avctx->coded_width, avctx->coded_height)) + || avctx->channels > SANE_NB_CHANNELS) { ret = AVERROR(EINVAL); - goto end; + goto free_and_end; } avctx->codec = codec; - avctx->codec_id = codec->id; + if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) && + avctx->codec_id == CODEC_ID_NONE) { + avctx->codec_type = codec->type; + avctx->codec_id = codec->id; + } + if(avctx->codec_id != codec->id || avctx->codec_type != codec->type){ + av_log(avctx, AV_LOG_ERROR, "codec type or id mismatches\n"); + goto free_and_end; + } avctx->frame_number = 0; if(avctx->codec->init){ ret = avctx->codec->init(avctx); if (ret < 0) { - av_freep(&avctx->priv_data); - avctx->codec= NULL; - goto end; + goto free_and_end; } } ret=0; @@ -497,6 +527,10 @@ end: (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE); } return ret; +free_and_end: + av_freep(&avctx->priv_data); + avctx->codec= NULL; + goto end; } int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size, @@ -655,7 +689,7 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, return ret; } -int avcodec_close(AVCodecContext *avctx) +av_cold int avcodec_close(AVCodecContext *avctx) { /* If there is a user-supplied mutex locking routine, call it. */ if (ff_lockmgr_cb) { @@ -672,10 +706,12 @@ int avcodec_close(AVCodecContext *avctx) if (HAVE_THREADS && avctx->thread_opaque) avcodec_thread_free(avctx); - if (avctx->codec->close) + if (avctx->codec && avctx->codec->close) avctx->codec->close(avctx); avcodec_default_free_buffers(avctx); av_freep(&avctx->priv_data); + if(avctx->codec && avctx->codec->encode) + av_freep(&avctx->extradata); avctx->codec = NULL; entangled_thread_counter--; @@ -688,14 +724,18 @@ int avcodec_close(AVCodecContext *avctx) AVCodec *avcodec_find_encoder(enum CodecID id) { - AVCodec *p; + AVCodec *p, *experimental=NULL; p = first_avcodec; while (p) { - if (p->encode != NULL && p->id == id) - return p; + if (p->encode != 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_encoder_by_name(const char *name) @@ -738,6 +778,29 @@ AVCodec *avcodec_find_decoder_by_name(const char *name) return NULL; } +static int get_bit_rate(AVCodecContext *ctx) +{ + int bit_rate; + int bits_per_sample; + + switch(ctx->codec_type) { + case AVMEDIA_TYPE_VIDEO: + case AVMEDIA_TYPE_DATA: + case AVMEDIA_TYPE_SUBTITLE: + case AVMEDIA_TYPE_ATTACHMENT: + bit_rate = ctx->bit_rate; + break; + case AVMEDIA_TYPE_AUDIO: + bits_per_sample = av_get_bits_per_sample(ctx->codec_id); + bit_rate = bits_per_sample ? ctx->sample_rate * ctx->channels * bits_per_sample : ctx->bit_rate; + break; + default: + bit_rate = 0; + break; + } + return bit_rate; +} + void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) { const char *codec_name; @@ -776,7 +839,7 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) } switch(enc->codec_type) { - case CODEC_TYPE_VIDEO: + case AVMEDIA_TYPE_VIDEO: snprintf(buf, buf_size, "Video: %s%s", codec_name, enc->mb_decision ? " (hq)" : ""); @@ -810,9 +873,8 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) snprintf(buf + strlen(buf), buf_size - strlen(buf), ", q=%d-%d", enc->qmin, enc->qmax); } - bitrate = enc->bit_rate; break; - case CODEC_TYPE_AUDIO: + case AVMEDIA_TYPE_AUDIO: snprintf(buf, buf_size, "Audio: %s", codec_name); @@ -826,58 +888,15 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) snprintf(buf + strlen(buf), buf_size - strlen(buf), ", %s", avcodec_get_sample_fmt_name(enc->sample_fmt)); } - - /* for PCM codecs, compute bitrate directly */ - switch(enc->codec_id) { - case CODEC_ID_PCM_F64BE: - case CODEC_ID_PCM_F64LE: - bitrate = enc->sample_rate * enc->channels * 64; - break; - case CODEC_ID_PCM_S32LE: - case CODEC_ID_PCM_S32BE: - case CODEC_ID_PCM_U32LE: - case CODEC_ID_PCM_U32BE: - case CODEC_ID_PCM_F32BE: - case CODEC_ID_PCM_F32LE: - bitrate = enc->sample_rate * enc->channels * 32; - break; - case CODEC_ID_PCM_S24LE: - case CODEC_ID_PCM_S24BE: - case CODEC_ID_PCM_U24LE: - case CODEC_ID_PCM_U24BE: - case CODEC_ID_PCM_S24DAUD: - bitrate = enc->sample_rate * enc->channels * 24; - break; - case CODEC_ID_PCM_S16LE: - case CODEC_ID_PCM_S16BE: - case CODEC_ID_PCM_S16LE_PLANAR: - case CODEC_ID_PCM_U16LE: - case CODEC_ID_PCM_U16BE: - bitrate = enc->sample_rate * enc->channels * 16; - break; - case CODEC_ID_PCM_S8: - case CODEC_ID_PCM_U8: - case CODEC_ID_PCM_ALAW: - case CODEC_ID_PCM_MULAW: - case CODEC_ID_PCM_ZORK: - bitrate = enc->sample_rate * enc->channels * 8; - break; - default: - bitrate = enc->bit_rate; - break; - } break; - case CODEC_TYPE_DATA: + case AVMEDIA_TYPE_DATA: snprintf(buf, buf_size, "Data: %s", codec_name); - bitrate = enc->bit_rate; break; - case CODEC_TYPE_SUBTITLE: + case AVMEDIA_TYPE_SUBTITLE: snprintf(buf, buf_size, "Subtitle: %s", codec_name); - bitrate = enc->bit_rate; break; - case CODEC_TYPE_ATTACHMENT: + case AVMEDIA_TYPE_ATTACHMENT: snprintf(buf, buf_size, "Attachment: %s", codec_name); - bitrate = enc->bit_rate; break; default: snprintf(buf, buf_size, "Invalid Codec type %d", enc->codec_type); @@ -891,6 +910,7 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) snprintf(buf + strlen(buf), buf_size - strlen(buf), ", pass 2"); } + bitrate = get_bit_rate(enc); if (bitrate != 0) { snprintf(buf + strlen(buf), buf_size - strlen(buf), ", %d kb/s", bitrate / 1000); @@ -902,6 +922,17 @@ unsigned avcodec_version( void ) return LIBAVCODEC_VERSION_INT; } +const char *avcodec_configuration(void) +{ + return FFMPEG_CONFIGURATION; +} + +const char *avcodec_license(void) +{ +#define LICENSE_PREFIX "libavcodec license: " + return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1; +} + void avcodec_init(void) { static int initialized = 0; @@ -924,6 +955,8 @@ void avcodec_default_free_buffers(AVCodecContext *s){ if(s->internal_buffer==NULL) return; + if (s->internal_buffer_count) + av_log(s, AV_LOG_WARNING, "Found %i unreleased buffers!\n", s->internal_buffer_count); for(i=0; iinternal_buffer)[i]; for(j=0; j<4; j++){ @@ -957,6 +990,9 @@ int av_get_bits_per_sample(enum CodecID codec_id){ return 3; case CODEC_ID_ADPCM_SBPRO_4: case CODEC_ID_ADPCM_CT: + case CODEC_ID_ADPCM_IMA_WAV: + case CODEC_ID_ADPCM_MS: + case CODEC_ID_ADPCM_YAMAHA: return 4; case CODEC_ID_PCM_ALAW: case CODEC_ID_PCM_MULAW: @@ -1191,6 +1227,12 @@ int av_parse_video_frame_rate(AVRational *frame_rate, const char *arg) return 0; } +int ff_match_2uint16(const uint16_t (*tab)[2], int size, int a, int b){ + int i; + for(i=0; iwidth, avctx->height) < 0) - return -1; - avctx->pix_fmt = PIX_FMT_YUV422P16; + avctx->pix_fmt = PIX_FMT_YUV422P16; avctx->bits_per_raw_sample = 10; - avctx->coded_frame = avcodec_alloc_frame(); + avctx->coded_frame = avcodec_alloc_frame(); return 0; } -static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) +static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, + AVPacket *avpkt) { int h, w; AVFrame *pic = avctx->coded_frame; @@ -67,13 +66,13 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac pic->pict_type = FF_I_TYPE; pic->key_frame = 1; -#define READ_PIXELS(a, b, c) \ - do { \ - val = le2me_32(*src++); \ +#define READ_PIXELS(a, b, c) \ + do { \ + val = le2me_32(*src++); \ *a++ = val << 6; \ *b++ = (val >> 4) & 0xFFC0; \ *c++ = (val >> 14) & 0xFFC0; \ - } while (0); + } while (0) for (h = 0; h < avctx->height; h++) { const uint32_t *src = (const uint32_t*)psrc; @@ -100,9 +99,9 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac } psrc += stride; - y += pic->linesize[0]/2 - avctx->width; - u += pic->linesize[1]/2 - avctx->width/2; - v += pic->linesize[2]/2 - avctx->width/2; + y += pic->linesize[0] / 2 - avctx->width; + u += pic->linesize[1] / 2 - avctx->width / 2; + v += pic->linesize[2] / 2 - avctx->width / 2; } *data_size = sizeof(AVFrame); @@ -113,6 +112,9 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac static av_cold int decode_close(AVCodecContext *avctx) { + AVFrame *pic = avctx->coded_frame; + if (pic->data[0]) + avctx->release_buffer(avctx, pic); av_freep(&avctx->coded_frame); return 0; @@ -120,7 +122,7 @@ static av_cold int decode_close(AVCodecContext *avctx) AVCodec v210_decoder = { "v210", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_V210, 0, decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/v210enc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/v210enc.c index 9a90d243ed..11e0e0eb7a 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/v210enc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/v210enc.c @@ -48,7 +48,8 @@ static av_cold int encode_init(AVCodecContext *avctx) return 0; } -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) { const AVFrame *pic = data; int aligned_width = ((avctx->width + 47) / 48) * 48; @@ -71,7 +72,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, ((*b++ & 0xFFC0) << 4); \ val|= (*c++ & 0xFFC0) << 14; \ bytestream_put_le32(&p, val); \ - } while (0); + } while (0) for (h = 0; h < avctx->height; h++) { uint32_t val; @@ -101,9 +102,9 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, pdst += stride; memset(p, 0, pdst - p); p = pdst; - y += pic->linesize[0]/2 - avctx->width; - u += pic->linesize[1]/2 - avctx->width/2; - v += pic->linesize[2]/2 - avctx->width/2; + y += pic->linesize[0] / 2 - avctx->width; + u += pic->linesize[1] / 2 - avctx->width / 2; + v += pic->linesize[2] / 2 - avctx->width / 2; } return p - buf; @@ -118,12 +119,12 @@ static av_cold int encode_close(AVCodecContext *avctx) AVCodec v210_encoder = { "v210", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_V210, 0, encode_init, encode_frame, encode_close, - .pix_fmts = (enum PixelFormat[]){PIX_FMT_YUV422P16, PIX_FMT_NONE}, + .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV422P16, PIX_FMT_NONE}, .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"), }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/v210x.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/v210x.c index 754b70a1f0..d869d64725 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/v210x.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/v210x.c @@ -27,8 +27,6 @@ static av_cold int decode_init(AVCodecContext *avctx) av_log(avctx, AV_LOG_ERROR, "v210x needs even width\n"); return -1; } - if(avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) - return -1; avctx->pix_fmt = PIX_FMT_YUV422P16; avctx->bits_per_raw_sample= 10; @@ -124,14 +122,25 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac return avpkt->size; } +static av_cold int decode_close(AVCodecContext *avctx) +{ + AVFrame *pic = avctx->coded_frame; + if (pic->data[0]) + avctx->release_buffer(avctx, pic); + av_freep(&avctx->coded_frame); + + return 0; +} + AVCodec v210x_decoder = { "v210x", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_V210X, 0, decode_init, NULL, - NULL, + decode_close, decode_frame, CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"), }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vaapi.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/vaapi.c index be73d0fea6..10f9054278 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vaapi.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vaapi.c @@ -129,7 +129,7 @@ static void *alloc_buffer(struct vaapi_context *vactx, int type, unsigned int si return data; } -void *ff_vaapi_alloc_picture(struct vaapi_context *vactx, unsigned int size) +void *ff_vaapi_alloc_pic_param(struct vaapi_context *vactx, unsigned int size) { return alloc_buffer(vactx, VAPictureParameterBufferType, size, &vactx->pic_param_buf_id); } @@ -185,7 +185,7 @@ int ff_vaapi_common_end_frame(MpegEncContext *s) if (commit_slices(vactx) < 0) goto done; if (vactx->n_slice_buf_ids > 0) { - if (render_picture(vactx, ff_vaapi_get_surface(s->current_picture_ptr)) < 0) + if (render_picture(vactx, ff_vaapi_get_surface_id(s->current_picture_ptr)) < 0) goto done; ff_draw_horiz_band(s, 0, s->avctx->height); } diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vaapi_h264.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/vaapi_h264.c new file mode 100644 index 0000000000..6d4251a263 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vaapi_h264.c @@ -0,0 +1,347 @@ +/* + * H.264 HW decode acceleration through VA API + * + * Copyright (C) 2008-2009 Splitted-Desktop Systems + * + * 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 "vaapi_internal.h" +#include "h264.h" + +/** @file + * This file implements the glue code between FFmpeg's and VA API's + * structures for H.264 decoding. + */ + +/** + * Initializes an empty VA API picture. + * + * VA API requires a fixed-size reference picture array. + */ +static void init_vaapi_pic(VAPictureH264 *va_pic) +{ + va_pic->picture_id = VA_INVALID_ID; + va_pic->flags = VA_PICTURE_H264_INVALID; + va_pic->TopFieldOrderCnt = 0; + va_pic->BottomFieldOrderCnt = 0; +} + +/** + * Translates 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 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. + */ +static void fill_vaapi_pic(VAPictureH264 *va_pic, + Picture *pic, + int pic_structure) +{ + if (pic_structure == 0) + pic_structure = pic->reference; + + va_pic->picture_id = ff_vaapi_get_surface_id(pic); + va_pic->frame_idx = pic->long_ref ? pic->pic_id : pic->frame_num; + + 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) + va_pic->flags |= pic->long_ref ? VA_PICTURE_H264_LONG_TERM_REFERENCE : VA_PICTURE_H264_SHORT_TERM_REFERENCE; + + va_pic->TopFieldOrderCnt = 0; + if (pic->field_poc[0] != INT_MAX) + va_pic->TopFieldOrderCnt = pic->field_poc[0]; + + va_pic->BottomFieldOrderCnt = 0; + if (pic->field_poc[1] != INT_MAX) + va_pic->BottomFieldOrderCnt = pic->field_poc[1]; +} + +/** Decoded Picture Buffer (DPB). */ +typedef struct DPB { + int size; ///< Current number of reference frames in the DPB + int max_size; ///< Max number of reference frames. This is FF_ARRAY_ELEMS(VAPictureParameterBufferH264.ReferenceFrames) + VAPictureH264 *va_pics; ///< Pointer to VAPictureParameterBufferH264.ReferenceFrames array +} DPB; + +/** + * Appends picture to the decoded picture buffer, in a VA API form that + * merges the second field picture attributes with the first, if + * available. The decoded picture buffer's size must be large enough + * to receive the new VA API picture object. + */ +static int dpb_add(DPB *dpb, Picture *pic) +{ + int i; + + if (dpb->size >= dpb->max_size) + return -1; + + for (i = 0; i < dpb->size; i++) { + VAPictureH264 * const va_pic = &dpb->va_pics[i]; + if (va_pic->picture_id == ff_vaapi_get_surface_id(pic)) { + VAPictureH264 temp_va_pic; + fill_vaapi_pic(&temp_va_pic, pic, 0); + + if ((temp_va_pic.flags ^ va_pic->flags) & (VA_PICTURE_H264_TOP_FIELD | VA_PICTURE_H264_BOTTOM_FIELD)) { + va_pic->flags |= temp_va_pic.flags & (VA_PICTURE_H264_TOP_FIELD | VA_PICTURE_H264_BOTTOM_FIELD); + /* Merge second field */ + if (temp_va_pic.flags & VA_PICTURE_H264_TOP_FIELD) { + va_pic->TopFieldOrderCnt = temp_va_pic.TopFieldOrderCnt; + } else { + va_pic->BottomFieldOrderCnt = temp_va_pic.BottomFieldOrderCnt; + } + } + return 0; + } + } + + fill_vaapi_pic(&dpb->va_pics[dpb->size++], pic, 0); + return 0; +} + +/** Fills in VA API reference frames array. */ +static int fill_vaapi_ReferenceFrames(VAPictureParameterBufferH264 *pic_param, + H264Context *h) +{ + DPB dpb; + int i; + + dpb.size = 0; + dpb.max_size = FF_ARRAY_ELEMS(pic_param->ReferenceFrames); + dpb.va_pics = pic_param->ReferenceFrames; + for (i = 0; i < dpb.max_size; i++) + init_vaapi_pic(&dpb.va_pics[i]); + + 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) + return -1; + } + + for (i = 0; i < 16; i++) { + Picture * const pic = h->long_ref[i]; + if (pic && pic->reference && dpb_add(&dpb, pic) < 0) + return -1; + } + return 0; +} + +/** + * Fills 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 FFmpeg reference list + * @param[in] ref_count The number of reference pictures in ref_list + */ +static void fill_vaapi_RefPicList(VAPictureH264 RefPicList[32], + Picture *ref_list, + unsigned int ref_count) +{ + unsigned int i, n = 0; + for (i = 0; i < ref_count; i++) + if (ref_list[i].reference) + fill_vaapi_pic(&RefPicList[n++], &ref_list[i], 0); + + for (; n < 32; n++) + init_vaapi_pic(&RefPicList[n]); +} + +/** + * Fills in prediction weight table. + * + * VA API requires a plain prediction weight table as it does not infer + * any value. + * + * @param[in] h A pointer to the current H.264 context + * @param[in] list The reference frame list index to use + * @param[out] luma_weight_flag VA API plain luma weight flag + * @param[out] luma_weight VA API plain luma weight table + * @param[out] luma_offset VA API plain luma offset table + * @param[out] chroma_weight_flag VA API plain chroma weight flag + * @param[out] chroma_weight VA API plain chroma weight table + * @param[out] chroma_offset VA API plain chroma offset table + */ +static void fill_vaapi_plain_pred_weight_table(H264Context *h, + int list, + unsigned char *luma_weight_flag, + short luma_weight[32], + short luma_offset[32], + unsigned char *chroma_weight_flag, + short chroma_weight[32][2], + short chroma_offset[32][2]) +{ + unsigned int i, j; + + *luma_weight_flag = h->luma_weight_flag[list]; + *chroma_weight_flag = h->chroma_weight_flag[list]; + + for (i = 0; i < h->ref_count[list]; i++) { + /* VA API also wants the inferred (default) values, not + only what is available in the bitstream (7.4.3.2). */ + if (h->luma_weight_flag[list]) { + luma_weight[i] = h->luma_weight[i][list][0]; + luma_offset[i] = h->luma_weight[i][list][1]; + } else { + luma_weight[i] = 1 << h->luma_log2_weight_denom; + luma_offset[i] = 0; + } + for (j = 0; j < 2; j++) { + if (h->chroma_weight_flag[list]) { + chroma_weight[i][j] = h->chroma_weight[i][list][j][0]; + chroma_offset[i][j] = h->chroma_weight[i][list][j][1]; + } else { + chroma_weight[i][j] = 1 << h->chroma_log2_weight_denom; + chroma_offset[i][j] = 0; + } + } + } +} + +/** Initializes and starts decoding a frame with VA API. */ +static int start_frame(AVCodecContext *avctx, + av_unused const uint8_t *buffer, + av_unused uint32_t size) +{ + H264Context * const h = avctx->priv_data; + MpegEncContext * const s = &h->s; + struct vaapi_context * const vactx = avctx->hwaccel_context; + VAPictureParameterBufferH264 *pic_param; + VAIQMatrixBufferH264 *iq_matrix; + + dprintf(avctx, "start_frame()\n"); + + vactx->slice_param_size = sizeof(VASliceParameterBufferH264); + + /* Fill in VAPictureParameterBufferH264. */ + pic_param = ff_vaapi_alloc_pic_param(vactx, sizeof(VAPictureParameterBufferH264)); + if (!pic_param) + return -1; + fill_vaapi_pic(&pic_param->CurrPic, s->current_picture_ptr, s->picture_structure); + if (fill_vaapi_ReferenceFrames(pic_param, h) < 0) + return -1; + pic_param->picture_width_in_mbs_minus1 = s->mb_width - 1; + pic_param->picture_height_in_mbs_minus1 = s->mb_height - 1; + pic_param->bit_depth_luma_minus8 = h->sps.bit_depth_luma - 8; + pic_param->bit_depth_chroma_minus8 = h->sps.bit_depth_chroma - 8; + pic_param->num_ref_frames = h->sps.ref_frame_count; + pic_param->seq_fields.value = 0; /* reset all bits */ + pic_param->seq_fields.bits.chroma_format_idc = h->sps.chroma_format_idc; + pic_param->seq_fields.bits.residual_colour_transform_flag = h->sps.residual_color_transform_flag; /* XXX: only for 4:4:4 high profile? */ + pic_param->seq_fields.bits.gaps_in_frame_num_value_allowed_flag = h->sps.gaps_in_frame_num_allowed_flag; + pic_param->seq_fields.bits.frame_mbs_only_flag = h->sps.frame_mbs_only_flag; + pic_param->seq_fields.bits.mb_adaptive_frame_field_flag = h->sps.mb_aff; + pic_param->seq_fields.bits.direct_8x8_inference_flag = h->sps.direct_8x8_inference_flag; + pic_param->seq_fields.bits.MinLumaBiPredSize8x8 = h->sps.level_idc >= 31; /* A.3.3.2 */ + pic_param->seq_fields.bits.log2_max_frame_num_minus4 = h->sps.log2_max_frame_num - 4; + pic_param->seq_fields.bits.pic_order_cnt_type = h->sps.poc_type; + pic_param->seq_fields.bits.log2_max_pic_order_cnt_lsb_minus4 = h->sps.log2_max_poc_lsb - 4; + 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 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]; + pic_param->second_chroma_qp_index_offset = h->pps.chroma_qp_index_offset[1]; + pic_param->pic_fields.value = 0; /* reset all bits */ + pic_param->pic_fields.bits.entropy_coding_mode_flag = h->pps.cabac; + pic_param->pic_fields.bits.weighted_pred_flag = h->pps.weighted_pred; + pic_param->pic_fields.bits.weighted_bipred_idc = h->pps.weighted_bipred_idc; + pic_param->pic_fields.bits.transform_8x8_mode_flag = h->pps.transform_8x8_mode; + pic_param->pic_fields.bits.field_pic_flag = s->picture_structure != PICT_FRAME; + pic_param->pic_fields.bits.constrained_intra_pred_flag = h->pps.constrained_intra_pred; + pic_param->pic_fields.bits.pic_order_present_flag = h->pps.pic_order_present; + pic_param->pic_fields.bits.deblocking_filter_control_present_flag = h->pps.deblocking_filter_parameters_present; + pic_param->pic_fields.bits.redundant_pic_cnt_present_flag = h->pps.redundant_pic_cnt_present; + pic_param->pic_fields.bits.reference_pic_flag = h->nal_ref_idc != 0; + pic_param->frame_num = h->frame_num; + + /* Fill in VAIQMatrixBufferH264. */ + iq_matrix = ff_vaapi_alloc_iq_matrix(vactx, sizeof(VAIQMatrixBufferH264)); + 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)); + return 0; +} + +/** Ends a hardware decoding based frame. */ +static int end_frame(AVCodecContext *avctx) +{ + H264Context * const h = avctx->priv_data; + + dprintf(avctx, "end_frame()\n"); + return ff_vaapi_common_end_frame(&h->s); +} + +/** Decodes the given H.264 slice with VA API. */ +static int decode_slice(AVCodecContext *avctx, + const uint8_t *buffer, + uint32_t size) +{ + H264Context * const h = avctx->priv_data; + MpegEncContext * const s = &h->s; + VASliceParameterBufferH264 *slice_param; + + dprintf(avctx, "decode_slice(): buffer %p, size %d\n", buffer, size); + + /* Fill in VASliceParameterBufferH264. */ + slice_param = (VASliceParameterBufferH264 *)ff_vaapi_alloc_slice(avctx->hwaccel_context, buffer, size); + if (!slice_param) + return -1; + slice_param->slice_data_bit_offset = get_bits_count(&h->s.gb) + 8; /* bit buffer started beyond nal_unit_type */ + slice_param->first_mb_in_slice = (s->mb_y >> FIELD_OR_MBAFF_PICTURE) * s->mb_width + s->mb_x; + slice_param->slice_type = ff_h264_get_slice_type(h); + slice_param->direct_spatial_mv_pred_flag = h->slice_type == FF_B_TYPE ? h->direct_spatial_mv_pred : 0; + slice_param->num_ref_idx_l0_active_minus1 = h->list_count > 0 ? h->ref_count[0] - 1 : 0; + slice_param->num_ref_idx_l1_active_minus1 = h->list_count > 1 ? h->ref_count[1] - 1 : 0; + slice_param->cabac_init_idc = h->cabac_init_idc; + slice_param->slice_qp_delta = s->qscale - h->pps.init_qp; + slice_param->disable_deblocking_filter_idc = h->deblocking_filter < 2 ? !h->deblocking_filter : h->deblocking_filter; + slice_param->slice_alpha_c0_offset_div2 = h->slice_alpha_c0_offset / 2 - 26; + slice_param->slice_beta_offset_div2 = h->slice_beta_offset / 2 - 26; + slice_param->luma_log2_weight_denom = h->luma_log2_weight_denom; + slice_param->chroma_log2_weight_denom = h->chroma_log2_weight_denom; + + fill_vaapi_RefPicList(slice_param->RefPicList0, h->ref_list[0], h->list_count > 0 ? h->ref_count[0] : 0); + fill_vaapi_RefPicList(slice_param->RefPicList1, h->ref_list[1], h->list_count > 1 ? h->ref_count[1] : 0); + + fill_vaapi_plain_pred_weight_table(h, 0, + &slice_param->luma_weight_l0_flag, slice_param->luma_weight_l0, slice_param->luma_offset_l0, + &slice_param->chroma_weight_l0_flag, slice_param->chroma_weight_l0, slice_param->chroma_offset_l0); + fill_vaapi_plain_pred_weight_table(h, 1, + &slice_param->luma_weight_l1_flag, slice_param->luma_weight_l1, slice_param->luma_offset_l1, + &slice_param->chroma_weight_l1_flag, slice_param->chroma_weight_l1, slice_param->chroma_offset_l1); + return 0; +} + +AVHWAccel h264_vaapi_hwaccel = { + .name = "h264_vaapi", + .type = AVMEDIA_TYPE_VIDEO, + .id = CODEC_ID_H264, + .pix_fmt = PIX_FMT_VAAPI_VLD, + .capabilities = 0, + .start_frame = start_frame, + .end_frame = end_frame, + .decode_slice = decode_slice, + .priv_data_size = 0, +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vaapi_internal.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/vaapi_internal.h index bfc0f80162..2c0fdf945e 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vaapi_internal.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vaapi_internal.h @@ -36,7 +36,7 @@ */ /** Extract VASurfaceID from a Picture */ -static inline VASurfaceID ff_vaapi_get_surface(Picture *pic) +static inline VASurfaceID ff_vaapi_get_surface_id(Picture *pic) { return (uintptr_t)pic->data[3]; } @@ -45,7 +45,7 @@ static inline VASurfaceID ff_vaapi_get_surface(Picture *pic) int ff_vaapi_common_end_frame(MpegEncContext *s); /** Allocate a new picture parameter buffer */ -void *ff_vaapi_alloc_picture(struct vaapi_context *vactx, unsigned int size); +void *ff_vaapi_alloc_pic_param(struct vaapi_context *vactx, unsigned int size); /** Allocate a new IQ matrix buffer */ void *ff_vaapi_alloc_iq_matrix(struct vaapi_context *vactx, unsigned int size); diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vaapi_mpeg2.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/vaapi_mpeg2.c index 2ae075ddf9..2e870dcfa0 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vaapi_mpeg2.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vaapi_mpeg2.c @@ -49,13 +49,13 @@ static int vaapi_mpeg2_start_frame(AVCodecContext *avctx, av_unused const uint8_ vactx->slice_param_size = sizeof(VASliceParameterBufferMPEG2); /* Fill in VAPictureParameterBufferMPEG2 */ - pic_param = ff_vaapi_alloc_picture(vactx, sizeof(VAPictureParameterBufferMPEG2)); + pic_param = ff_vaapi_alloc_pic_param(vactx, sizeof(VAPictureParameterBufferMPEG2)); if (!pic_param) return -1; pic_param->horizontal_size = s->width; pic_param->vertical_size = s->height; - pic_param->forward_reference_picture = 0xffffffff; - pic_param->backward_reference_picture = 0xffffffff; + pic_param->forward_reference_picture = VA_INVALID_ID; + pic_param->backward_reference_picture = VA_INVALID_ID; pic_param->picture_coding_type = s->pict_type; pic_param->f_code = mpeg2_get_f_code(s); pic_param->picture_coding_extension.value = 0; /* reset all bits */ @@ -73,10 +73,10 @@ static int vaapi_mpeg2_start_frame(AVCodecContext *avctx, av_unused const uint8_ switch (s->pict_type) { case FF_B_TYPE: - pic_param->backward_reference_picture = ff_vaapi_get_surface(&s->next_picture); + pic_param->backward_reference_picture = ff_vaapi_get_surface_id(&s->next_picture); // fall-through case FF_P_TYPE: - pic_param->forward_reference_picture = ff_vaapi_get_surface(&s->last_picture); + pic_param->forward_reference_picture = ff_vaapi_get_surface_id(&s->last_picture); break; } @@ -131,6 +131,7 @@ static int vaapi_mpeg2_decode_slice(AVCodecContext *avctx, const uint8_t *buffer if (!slice_param) return -1; slice_param->macroblock_offset = macroblock_offset; + slice_param->slice_horizontal_position = s->mb_x; slice_param->slice_vertical_position = s->mb_y; slice_param->quantiser_scale_code = quantiser_scale_code; slice_param->intra_slice_flag = intra_slice_flag; @@ -139,7 +140,7 @@ static int vaapi_mpeg2_decode_slice(AVCodecContext *avctx, const uint8_t *buffer AVHWAccel mpeg2_vaapi_hwaccel = { .name = "mpeg2_vaapi", - .type = CODEC_TYPE_VIDEO, + .type = AVMEDIA_TYPE_VIDEO, .id = CODEC_ID_MPEG2VIDEO, .pix_fmt = PIX_FMT_VAAPI_VLD, .capabilities = 0, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vaapi_mpeg4.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/vaapi_mpeg4.c index ab9355f354..466ce2fd91 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vaapi_mpeg4.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vaapi_mpeg4.c @@ -51,13 +51,13 @@ static int vaapi_mpeg4_start_frame(AVCodecContext *avctx, av_unused const uint8_ vactx->slice_param_size = sizeof(VASliceParameterBufferMPEG4); /* Fill in VAPictureParameterBufferMPEG4 */ - pic_param = ff_vaapi_alloc_picture(vactx, sizeof(VAPictureParameterBufferMPEG4)); + pic_param = ff_vaapi_alloc_pic_param(vactx, sizeof(VAPictureParameterBufferMPEG4)); if (!pic_param) return -1; pic_param->vop_width = s->width; pic_param->vop_height = s->height; - pic_param->forward_reference_picture = 0xffffffff; - pic_param->backward_reference_picture = 0xffffffff; + pic_param->forward_reference_picture = VA_INVALID_ID; + pic_param->backward_reference_picture = VA_INVALID_ID; pic_param->vol_fields.value = 0; /* reset all bits */ pic_param->vol_fields.bits.short_video_header = avctx->codec->id == CODEC_ID_H263; pic_param->vol_fields.bits.chroma_format = CHROMA_420; @@ -69,6 +69,7 @@ static int vaapi_mpeg4_start_frame(AVCodecContext *avctx, av_unused const uint8_ pic_param->vol_fields.bits.quarter_sample = s->quarter_sample; pic_param->vol_fields.bits.data_partitioned = s->data_partitioning; pic_param->vol_fields.bits.reversible_vlc = s->rvlc; + pic_param->vol_fields.bits.resync_marker_disable = !s->resync_marker; pic_param->no_of_sprite_warping_points = s->num_sprite_warping_points; for (i = 0; i < s->num_sprite_warping_points && i < 3; i++) { pic_param->sprite_trajectory_du[i] = s->sprite_traj[i][0]; @@ -84,15 +85,16 @@ static int vaapi_mpeg4_start_frame(AVCodecContext *avctx, av_unused const uint8_ pic_param->vop_fields.bits.alternate_vertical_scan_flag = s->alternate_scan; pic_param->vop_fcode_forward = s->f_code; pic_param->vop_fcode_backward = s->b_code; + pic_param->vop_time_increment_resolution = avctx->time_base.den; pic_param->num_macroblocks_in_gob = s->mb_width * ff_h263_get_gob_height(s); pic_param->num_gobs_in_vop = (s->mb_width * s->mb_height) / pic_param->num_macroblocks_in_gob; pic_param->TRB = s->pb_time; pic_param->TRD = s->pp_time; if (s->pict_type == FF_B_TYPE) - pic_param->backward_reference_picture = ff_vaapi_get_surface(&s->next_picture); + pic_param->backward_reference_picture = ff_vaapi_get_surface_id(&s->next_picture); if (s->pict_type != FF_I_TYPE) - pic_param->forward_reference_picture = ff_vaapi_get_surface(&s->last_picture); + pic_param->forward_reference_picture = ff_vaapi_get_surface_id(&s->last_picture); /* Fill in VAIQMatrixBufferMPEG4 */ /* Only the first inverse quantisation method uses the weighthing matrices */ @@ -149,7 +151,7 @@ static int vaapi_mpeg4_decode_slice(AVCodecContext *avctx, const uint8_t *buffer #if CONFIG_MPEG4_VAAPI_HWACCEL AVHWAccel mpeg4_vaapi_hwaccel = { .name = "mpeg4_vaapi", - .type = CODEC_TYPE_VIDEO, + .type = AVMEDIA_TYPE_VIDEO, .id = CODEC_ID_MPEG4, .pix_fmt = PIX_FMT_VAAPI_VLD, .capabilities = 0, @@ -163,7 +165,7 @@ AVHWAccel mpeg4_vaapi_hwaccel = { #if CONFIG_H263_VAAPI_HWACCEL AVHWAccel h263_vaapi_hwaccel = { .name = "h263_vaapi", - .type = CODEC_TYPE_VIDEO, + .type = AVMEDIA_TYPE_VIDEO, .id = CODEC_ID_H263, .pix_fmt = PIX_FMT_VAAPI_VLD, .capabilities = 0, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vaapi_vc1.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/vaapi_vc1.c index eae3c160fc..992e1da4b1 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vaapi_vc1.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vaapi_vc1.c @@ -117,17 +117,18 @@ static inline VAMvModeVC1 vc1_get_MVMODE2(VC1Context *v) } /** Pack FFmpeg bitplanes into a VABitPlaneBuffer element */ -static inline uint8_t vc1_pack_bitplanes(const uint8_t *ff_bp[3], int x, int y, int stride) +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 n = y * stride + x; + const int bitplane_index = n / 2; + const int ff_bp_index = y * stride + x; uint8_t v = 0; if (ff_bp[0]) - v = ff_bp[0][n]; + v = ff_bp[0][ff_bp_index]; if (ff_bp[1]) - v |= ff_bp[1][n] << 1; + v |= ff_bp[1][ff_bp_index] << 1; if (ff_bp[2]) - v |= ff_bp[2][n] << 2; - return v; + v |= ff_bp[2][ff_bp_index] << 2; + bitplane[bitplane_index] = (bitplane[bitplane_index] << 4) | v; } static int vaapi_vc1_start_frame(AVCodecContext *avctx, av_unused const uint8_t *buffer, av_unused uint32_t size) @@ -142,12 +143,12 @@ static int vaapi_vc1_start_frame(AVCodecContext *avctx, av_unused const uint8_t vactx->slice_param_size = sizeof(VASliceParameterBufferVC1); /* Fill in VAPictureParameterBufferVC1 */ - pic_param = ff_vaapi_alloc_picture(vactx, sizeof(VAPictureParameterBufferVC1)); + pic_param = ff_vaapi_alloc_pic_param(vactx, sizeof(VAPictureParameterBufferVC1)); if (!pic_param) return -1; - pic_param->forward_reference_picture = 0xffffffff; - pic_param->backward_reference_picture = 0xffffffff; - pic_param->inloop_decoded_picture = 0xffffffff; + pic_param->forward_reference_picture = VA_INVALID_ID; + pic_param->backward_reference_picture = VA_INVALID_ID; + pic_param->inloop_decoded_picture = VA_INVALID_ID; pic_param->sequence_fields.value = 0; /* reset all bits */ pic_param->sequence_fields.bits.pulldown = v->broadcast; pic_param->sequence_fields.bits.interlace = v->interlace; @@ -242,10 +243,10 @@ static int vaapi_vc1_start_frame(AVCodecContext *avctx, av_unused const uint8_t switch (s->pict_type) { case FF_B_TYPE: - pic_param->backward_reference_picture = ff_vaapi_get_surface(&s->next_picture); + pic_param->backward_reference_picture = ff_vaapi_get_surface_id(&s->next_picture); // fall-through case FF_P_TYPE: - pic_param->forward_reference_picture = ff_vaapi_get_surface(&s->last_picture); + pic_param->forward_reference_picture = ff_vaapi_get_surface_id(&s->last_picture); break; } @@ -280,18 +281,16 @@ static int vaapi_vc1_start_frame(AVCodecContext *avctx, av_unused const uint8_t break; } - bitplane = ff_vaapi_alloc_bitplane(vactx, s->mb_height * ((s->mb_width + 1) / 2)); + bitplane = ff_vaapi_alloc_bitplane(vactx, (s->mb_width * s->mb_height + 1) / 2); if (!bitplane) return -1; n = 0; - for (y = 0; y < s->mb_height; y++) { - for (x = 0; x < s->mb_width; x += 2) { - bitplane[n] = vc1_pack_bitplanes(ff_bp, x+1, y, s->mb_stride); - bitplane[n] |= (vc1_pack_bitplanes(ff_bp, x, y, s->mb_stride) << 4); - ++n; - } - } + for (y = 0; y < s->mb_height; y++) + for (x = 0; x < s->mb_width; x++, n++) + vc1_pack_bitplanes(bitplane, n, ff_bp, x, y, s->mb_stride); + if (n & 1) /* move last nibble to the high order */ + bitplane[n/2] <<= 4; } return 0; } @@ -329,7 +328,7 @@ static int vaapi_vc1_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, #if CONFIG_WMV3_VAAPI_HWACCEL AVHWAccel wmv3_vaapi_hwaccel = { .name = "wmv3_vaapi", - .type = CODEC_TYPE_VIDEO, + .type = AVMEDIA_TYPE_VIDEO, .id = CODEC_ID_WMV3, .pix_fmt = PIX_FMT_VAAPI_VLD, .capabilities = 0, @@ -342,7 +341,7 @@ AVHWAccel wmv3_vaapi_hwaccel = { AVHWAccel vc1_vaapi_hwaccel = { .name = "vc1_vaapi", - .type = CODEC_TYPE_VIDEO, + .type = AVMEDIA_TYPE_VIDEO, .id = CODEC_ID_VC1, .pix_fmt = PIX_FMT_VAAPI_VLD, .capabilities = 0, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vb.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/vb.c index 02efa030a5..13c4b0a8d9 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vb.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vb.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/vb.c + * @file * VB Video decoder */ @@ -43,7 +43,7 @@ typedef struct VBDecContext { AVFrame pic; uint8_t *frame, *prev_frame; - uint32_t pal[256]; + uint32_t pal[AVPALETTE_COUNT]; const uint8_t *stream; } VBDecContext; @@ -58,7 +58,7 @@ static const uint16_t vb_patterns[64] = { 0xC631, 0x6310, 0xC060, 0x0136, 0x136C, 0x36C8, 0x6C80, 0x324C }; -static void vb_decode_palette(VBDecContext *c) +static void vb_decode_palette(VBDecContext *c, int data_size) { int start, size, i; @@ -68,6 +68,10 @@ static void vb_decode_palette(VBDecContext *c) av_log(c->avctx, AV_LOG_ERROR, "Palette change runs beyond entry 256\n"); return; } + if(size*3+2 > data_size){ + av_log(c->avctx, AV_LOG_ERROR, "Palette data runs beyond chunk size\n"); + return; + } for(i = start; i <= start + size; i++) c->pal[i] = bytestream_get_be24(&c->stream); } @@ -82,9 +86,10 @@ static inline int check_line(uint8_t *buf, uint8_t *start, uint8_t *end) return buf >= start && (buf + 4) <= end; } -static int vb_decode_framedata(VBDecContext *c, const uint8_t *buf, int offset) +static int vb_decode_framedata(VBDecContext *c, const uint8_t *buf, int data_size, int offset) { uint8_t *prev, *cur; + const uint8_t* data_end = buf + data_size; int blk, blocks, t, blk2; int blocktypes = 0; int x, y, a, b; @@ -99,8 +104,13 @@ static int vb_decode_framedata(VBDecContext *c, const uint8_t *buf, int offset) blocks = (c->avctx->width >> 2) * (c->avctx->height >> 2); blk2 = 0; for(blk = 0; blk < blocks; blk++){ - if(!(blk & 3)) + if(!(blk & 3)) { + if(buf >= data_end){ + av_log(c->avctx, AV_LOG_ERROR, "Data pointer out of bounds\n"); + return -1; + } blocktypes = bytestream_get_byte(&buf); + } switch(blocktypes & 0xC0){ case 0x00: //skip for(y = 0; y < 4; y++) @@ -112,6 +122,10 @@ static int vb_decode_framedata(VBDecContext *c, const uint8_t *buf, int offset) case 0x40: t = bytestream_get_byte(&buf); if(!t){ //raw block + if(buf + 16 > data_end){ + av_log(c->avctx, AV_LOG_ERROR, "Insufficient data\n"); + return -1; + } for(y = 0; y < 4; y++) memcpy(cur + y*width, buf + y*4, 4); buf += 16; @@ -132,6 +146,10 @@ static int vb_decode_framedata(VBDecContext *c, const uint8_t *buf, int offset) memset(cur + y*width, t, 4); break; case 0xC0: // pattern fill + if(buf + 2 > data_end){ + av_log(c->avctx, AV_LOG_ERROR, "Insufficient data\n"); + return -1; + } t = bytestream_get_byte(&buf); pattype = t >> 6; pattern = vb_patterns[t & 0x3F]; @@ -209,7 +227,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac av_log(avctx, AV_LOG_ERROR, "Frame size is too big\n"); return -1; } - vb_decode_framedata(c, c->stream, offset); + vb_decode_framedata(c, c->stream, size, offset); c->stream += size - 4; rest -= size; } @@ -219,7 +237,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac av_log(avctx, AV_LOG_ERROR, "Palette size is too big\n"); return -1; } - vb_decode_palette(c); + vb_decode_palette(c, size); rest -= size; } @@ -251,12 +269,8 @@ static av_cold int decode_init(AVCodecContext *avctx) c->avctx = avctx; avctx->pix_fmt = PIX_FMT_PAL8; - if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) { - return -1; - } - - c->frame = av_malloc( avctx->width * avctx->height); - c->prev_frame = av_malloc( avctx->width * avctx->height); + c->frame = av_mallocz(avctx->width * avctx->height); + c->prev_frame = av_mallocz(avctx->width * avctx->height); return 0; } @@ -275,7 +289,7 @@ static av_cold int decode_end(AVCodecContext *avctx) AVCodec vb_decoder = { "vb", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_VB, sizeof(VBDecContext), decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vc1.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/vc1.c index ec6a660ad9..7d00072b7a 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vc1.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vc1.c @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/vc1.c + * @file * VC-1 and WMV3 decoder common code * */ @@ -781,7 +781,11 @@ int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb) if(v->interlace){ v->fcm = decode012(gb); - if(v->fcm) return -1; // interlaced frames/fields are not implemented + 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; + } } switch(get_unary(gb, 0, 4)) { case 0: diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vc1.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/vc1.h index e90feb2984..d5f0e05465 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vc1.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vc1.h @@ -312,6 +312,8 @@ typedef struct VC1Context{ uint8_t closed_entry; ///< Closed entry point flag (CLOSED_ENTRY syntax element) int parse_only; ///< Context is used within parser + + int warn_interlaced; } VC1Context; /** Find VC-1 marker in buffer diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vc1_parser.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/vc1_parser.c index 55580c95d1..6e559dec9b 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vc1_parser.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vc1_parser.c @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/vc1_parser.c + * @file * VC-1 and WMV3 parser */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vc1data.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/vc1data.c index e4ceb168c5..5298079448 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vc1data.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vc1data.c @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/vc1data.c + * @file * VC-1 tables. */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vc1data.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/vc1data.h index 0f3c47ea1b..934627a781 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vc1data.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vc1data.h @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/vc1data.h + * @file * VC-1 tables. */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vc1dec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/vc1dec.c index 998428d1a9..52392c3f76 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vc1dec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vc1dec.c @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/vc1dec.c + * @file * VC-1 and WMV3 decoder * */ @@ -29,6 +29,7 @@ #include "dsputil.h" #include "avcodec.h" #include "mpegvideo.h" +#include "h263.h" #include "vc1.h" #include "vc1data.h" #include "vc1acdata.h" @@ -124,10 +125,6 @@ static int vc1_init_common(VC1Context *v) &vc1_ac_tables[i][0][1], 8, 4, &vc1_ac_tables[i][0][0], 8, 4, INIT_VLC_USE_NEW_STATIC); } - //FIXME: switching to INIT_VLC_STATIC() results in incorrect decoding - init_vlc(&ff_msmp4_mb_i_vlc, MB_INTRA_VLC_BITS, 64, - &ff_msmp4_mb_i_table[0][1], 4, 2, - &ff_msmp4_mb_i_table[0][0], 4, 2, INIT_VLC_USE_STATIC); done = 1; } @@ -2997,7 +2994,7 @@ static av_cold int vc1_decode_init(AVCodecContext *avctx) avctx->idct_algo=FF_IDCT_WMV2; } - if(ff_h263_decode_init(avctx) < 0) + if(ff_msmpeg4_decode_init(avctx) < 0) return -1; if (vc1_init_common(v) < 0) return -1; @@ -3041,7 +3038,7 @@ static av_cold int vc1_decode_init(AVCodecContext *avctx) } buf2 = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); - if(start[0]) start++; // in WVC1 extradata first byte is its 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 = find_next_marker(start + 4, end); @@ -3193,6 +3190,8 @@ static int vc1_decode_frame(AVCodecContext *avctx, 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"); av_free(buf2);return -1; }else{ buf_size2 = vc1_unescape_buffer(buf, buf_size, buf2); @@ -3320,7 +3319,7 @@ static av_cold int vc1_decode_end(AVCodecContext *avctx) AVCodec vc1_decoder = { "vc1", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_VC1, sizeof(VC1Context), vc1_decode_init, @@ -3336,7 +3335,7 @@ AVCodec vc1_decoder = { #if CONFIG_WMV3_DECODER AVCodec wmv3_decoder = { "wmv3", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_WMV3, sizeof(VC1Context), vc1_decode_init, @@ -3353,7 +3352,7 @@ AVCodec wmv3_decoder = { #if CONFIG_WMV3_VDPAU_DECODER AVCodec wmv3_vdpau_decoder = { "wmv3_vdpau", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_WMV3, sizeof(VC1Context), vc1_decode_init, @@ -3363,14 +3362,14 @@ AVCodec wmv3_vdpau_decoder = { CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_HWACCEL_VDPAU, NULL, .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9 VDPAU"), - .pix_fmts = (enum PixelFormat[]){PIX_FMT_VDPAU_WMV3, PIX_FMT_NONE} + .pix_fmts = (const enum PixelFormat[]){PIX_FMT_VDPAU_WMV3, PIX_FMT_NONE} }; #endif #if CONFIG_VC1_VDPAU_DECODER AVCodec vc1_vdpau_decoder = { "vc1_vdpau", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_VC1, sizeof(VC1Context), vc1_decode_init, @@ -3380,6 +3379,6 @@ AVCodec vc1_vdpau_decoder = { CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_HWACCEL_VDPAU, NULL, .long_name = NULL_IF_CONFIG_SMALL("SMPTE VC-1 VDPAU"), - .pix_fmts = (enum PixelFormat[]){PIX_FMT_VDPAU_VC1, PIX_FMT_NONE} + .pix_fmts = (const enum PixelFormat[]){PIX_FMT_VDPAU_VC1, PIX_FMT_NONE} }; #endif diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vc1dsp.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/vc1dsp.c index 5e79736a50..47b69c8214 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vc1dsp.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vc1dsp.c @@ -20,7 +20,7 @@ */ /** -* @file libavcodec/vc1dsp.c +* @file * VC-1 and WMV3 decoder * */ @@ -581,10 +581,6 @@ VC1_MSPEL_MC(op_avg, avg_) /* pixel functions - really are entry points to vc1_mspel_mc */ -/* this one is defined in dsputil.c */ -void ff_put_vc1_mspel_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int rnd); -void ff_avg_vc1_mspel_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int rnd); - #define PUT_VC1_MSPEL(a, b)\ static void put_vc1_mspel_mc ## a ## b ##_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) { \ put_vc1_mspel_mc(dst, src, stride, a, b, rnd); \ @@ -612,7 +608,7 @@ PUT_VC1_MSPEL(1, 3) PUT_VC1_MSPEL(2, 3) PUT_VC1_MSPEL(3, 3) -void ff_vc1dsp_init(DSPContext* dsp, AVCodecContext *avctx) { +av_cold void ff_vc1dsp_init(DSPContext* dsp, AVCodecContext *avctx) { dsp->vc1_inv_trans_8x8 = vc1_inv_trans_8x8_c; dsp->vc1_inv_trans_4x8 = vc1_inv_trans_4x8_c; dsp->vc1_inv_trans_8x4 = vc1_inv_trans_8x4_c; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vcr1.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/vcr1.c index 6218c7c634..31da94f3d0 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vcr1.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vcr1.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/vcr1.c + * @file * ati vcr1 codec. */ @@ -158,6 +158,15 @@ static av_cold int decode_init(AVCodecContext *avctx){ return 0; } +static av_cold int decode_end(AVCodecContext *avctx){ + VCR1Context *s = avctx->priv_data; + + if (s->picture.data[0]) + avctx->release_buffer(avctx, &s->picture); + + return 0; +} + #if CONFIG_VCR1_ENCODER static av_cold int encode_init(AVCodecContext *avctx){ @@ -169,12 +178,12 @@ static av_cold int encode_init(AVCodecContext *avctx){ AVCodec vcr1_decoder = { "vcr1", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_VCR1, sizeof(VCR1Context), decode_init, NULL, - NULL, + decode_end, decode_frame, CODEC_CAP_DR1, .long_name = NULL_IF_CONFIG_SMALL("ATI VCR1"), @@ -183,7 +192,7 @@ AVCodec vcr1_decoder = { #if CONFIG_VCR1_ENCODER AVCodec vcr1_encoder = { "vcr1", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_VCR1, sizeof(VCR1Context), encode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vdpau.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/vdpau.c index 4a7c86c0a8..bd721e8f8e 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vdpau.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vdpau.c @@ -1,6 +1,6 @@ /* * Video Decode and Presentation API for UNIX (VDPAU) is used for - * HW decode acceleration for MPEG-1/2, H.264 and VC-1. + * HW decode acceleration for MPEG-1/2, MPEG-4 ASP, H.264 and VC-1. * * Copyright (c) 2008 NVIDIA * @@ -54,7 +54,7 @@ void ff_vdpau_h264_set_reference_frames(MpegEncContext *s) for (list = 0; list < 2; ++list) { Picture **lp = list ? h->long_ref : h->short_ref; - int ls = list ? h->long_ref_count : h->short_ref_count; + int ls = list ? 16 : h->short_ref_count; for (i = 0; i < ls; ++i) { pic = lp[i]; @@ -127,7 +127,7 @@ void ff_vdpau_add_data_chunk(MpegEncContext *s, render->bitstream_buffers_used++; } -void ff_vdpau_h264_picture_complete(MpegEncContext *s) +void ff_vdpau_h264_picture_start(MpegEncContext *s) { H264Context *h = s->avctx->priv_data; struct vdpau_render_state *render; @@ -136,10 +136,6 @@ void ff_vdpau_h264_picture_complete(MpegEncContext *s) render = (struct vdpau_render_state *)s->current_picture_ptr->data[0]; assert(render); - render->info.h264.slice_count = h->slice_num; - if (render->info.h264.slice_count < 1) - return; - for (i = 0; i < 2; ++i) { int foc = s->current_picture_ptr->field_poc[i]; if (foc == INT_MAX) @@ -147,8 +143,22 @@ void ff_vdpau_h264_picture_complete(MpegEncContext *s) render->info.h264.field_order_cnt[i] = foc; } + render->info.h264.frame_num = h->frame_num; +} + +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]; + 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.frame_num = h->frame_num; 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; @@ -305,4 +315,58 @@ void ff_vdpau_vc1_decode_picture(MpegEncContext *s, const uint8_t *buf, render->bitstream_buffers_used = 0; } +void ff_vdpau_mpeg4_decode_picture(MpegEncContext *s, const uint8_t *buf, + int buf_size) +{ + struct vdpau_render_state *render, *last, *next; + int i; + + if (!s->current_picture_ptr) return; + + render = (struct vdpau_render_state *)s->current_picture_ptr->data[0]; + assert(render); + + /* fill VdpPictureInfoMPEG4Part2 struct */ + render->info.mpeg4.trd[0] = s->pp_time; + render->info.mpeg4.trb[0] = s->pb_time; + render->info.mpeg4.trd[1] = s->pp_field_time >> 1; + render->info.mpeg4.trb[1] = s->pb_field_time >> 1; + render->info.mpeg4.vop_time_increment_resolution = s->avctx->time_base.den; + render->info.mpeg4.vop_coding_type = 0; + render->info.mpeg4.vop_fcode_forward = s->f_code; + render->info.mpeg4.vop_fcode_backward = s->b_code; + render->info.mpeg4.resync_marker_disable = !s->resync_marker; + render->info.mpeg4.interlaced = !s->progressive_sequence; + render->info.mpeg4.quant_type = s->mpeg_quant; + render->info.mpeg4.quarter_sample = s->quarter_sample; + render->info.mpeg4.short_video_header = s->avctx->codec->id == CODEC_ID_H263; + render->info.mpeg4.rounding_control = s->no_rounding; + render->info.mpeg4.alternate_vertical_scan_flag = s->alternate_scan; + render->info.mpeg4.top_field_first = s->top_field_first; + for (i = 0; i < 64; ++i) { + render->info.mpeg4.intra_quantizer_matrix[i] = s->intra_matrix[i]; + render->info.mpeg4.non_intra_quantizer_matrix[i] = s->inter_matrix[i]; + } + render->info.mpeg4.forward_reference = VDP_INVALID_HANDLE; + render->info.mpeg4.backward_reference = VDP_INVALID_HANDLE; + + switch (s->pict_type) { + case FF_B_TYPE: + next = (struct vdpau_render_state *)s->next_picture.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 FF_P_TYPE: + last = (struct vdpau_render_state *)s->last_picture.data[0]; + assert(last); + render->info.mpeg4.forward_reference = last->surface; + } + + ff_vdpau_add_data_chunk(s, buf, buf_size); + + ff_draw_horiz_band(s, 0, s->avctx->height); + render->bitstream_buffers_used = 0; +} + /* @}*/ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vdpau.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/vdpau.h index 53dbd7c02a..a8fa4d3877 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vdpau.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vdpau.h @@ -70,14 +70,17 @@ struct vdpau_render_state { /** picture parameter information for all supported codecs */ union VdpPictureInfo { - VdpPictureInfoH264 h264; - VdpPictureInfoMPEG1Or2 mpeg; - VdpPictureInfoVC1 vc1; + VdpPictureInfoH264 h264; + VdpPictureInfoMPEG1Or2 mpeg; + VdpPictureInfoVC1 vc1; + VdpPictureInfoMPEG4Part2 mpeg4; } info; - /** Describe size/location of the compressed video data. */ + /** 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/src/add-ons/media/plugins/ffmpeg/libavcodec/vdpau_internal.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/vdpau_internal.h index ce0e00a38a..0a8d0b6b55 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vdpau_internal.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vdpau_internal.h @@ -33,10 +33,14 @@ void ff_vdpau_add_data_chunk(MpegEncContext *s, const uint8_t *buf, void ff_vdpau_mpeg_picture_complete(MpegEncContext *s, const uint8_t *buf, int buf_size, int slice_count); +void ff_vdpau_h264_picture_start(MpegEncContext *s); void ff_vdpau_h264_set_reference_frames(MpegEncContext *s); void ff_vdpau_h264_picture_complete(MpegEncContext *s); void ff_vdpau_vc1_decode_picture(MpegEncContext *s, const uint8_t *buf, int buf_size); +void ff_vdpau_mpeg4_decode_picture(MpegEncContext *s, const uint8_t *buf, + int buf_size); + #endif /* AVCODEC_VDPAU_INTERNAL_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vmdav.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/vmdav.c index 79318b0277..4914d2a09a 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vmdav.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vmdav.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/vmdav.c + * @file * Sierra VMD audio & video decoders * by Vladimir "VAG" Gneushev (vagsoft at mail.ru) * for more information on the Sierra VMD format, visit: @@ -567,7 +567,7 @@ static int vmdaudio_decode_frame(AVCodecContext *avctx, AVCodec vmdvideo_decoder = { "vmdvideo", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_VMDVIDEO, sizeof(VmdVideoContext), vmdvideo_decode_init, @@ -580,7 +580,7 @@ AVCodec vmdvideo_decoder = { AVCodec vmdaudio_decoder = { "vmdaudio", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_VMDAUDIO, sizeof(VmdAudioContext), vmdaudio_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vmnc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/vmnc.c index a97655a27c..49aaeb2992 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vmnc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vmnc.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/vmnc.c + * @file * VMware Screen Codec (VMnc) decoder * As Alex Beregszaszi discovered, this is effectively RFB data dump */ @@ -468,9 +468,6 @@ static av_cold int decode_init(AVCodecContext *avctx) c->width = avctx->width; c->height = avctx->height; - if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) { - return 1; - } c->bpp = avctx->bits_per_coded_sample; c->bpp2 = c->bpp/8; @@ -513,7 +510,7 @@ static av_cold int decode_end(AVCodecContext *avctx) AVCodec vmnc_decoder = { "vmnc", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_VMNC, sizeof(VmncContext), decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vorbis.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/vorbis.c index fd0cafa187..47388d8302 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vorbis.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vorbis.c @@ -1,8 +1,8 @@ /** - * @file libavcodec/vorbis.c + * @file * Common code for Vorbis I encoder and decoder * @author Denes Balatoni ( dbalatoni programozo hu ) - + * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or @@ -32,13 +32,16 @@ /* Helper functions */ -unsigned int ff_vorbis_nth_root(unsigned int x, unsigned int n) { // x^(1/n) - unsigned int ret=0, i, j; +// x^(1/n) +unsigned int ff_vorbis_nth_root(unsigned int x, unsigned int n) +{ + unsigned int ret = 0, i, j; do { ++ret; - for(i=0,j=ret;i 32 checks should be redundant, all calling code should // already ensure that, but since it allows overwriting the stack it seems // reasonable to check redundantly. -int ff_vorbis_len2vlc(uint8_t *bits, uint32_t *codes, uint_fast32_t num) { - uint_fast32_t exit_at_level[33]={404,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +int ff_vorbis_len2vlc(uint8_t *bits, uint32_t *codes, uint_fast32_t num) +{ + uint_fast32_t exit_at_level[33] = { + 404, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - uint_fast8_t i,j; - uint_fast32_t code,p; + uint_fast8_t i, j; + uint_fast32_t code, p; #ifdef V_DEBUG GetBitContext gb; #endif - for(p=0;(bits[p]==0) && (pavccontext, AV_LOG_INFO, "An empty codebook. Heh?! \n"); return 0; } - codes[p]=0; - if (bits[p] > 32) return 1; - for(i=0;i 32) + return 1; + for (i = 0; i < bits[p]; ++i) + exit_at_level[i+1] = 1 << i; #ifdef V_DEBUG av_log(NULL, AV_LOG_INFO, " %d. of %d code len %d code %d - ", p, num, bits[p], codes[p]); init_get_bits(&gb, (uint_fast8_t *)&codes[p], bits[p]); - for(i=0;i 32) return 1; - if (bits[p]==0) continue; + for (; p < num; ++p) { + if (bits[p] > 32) + return 1; + if (bits[p] == 0) + continue; // find corresponding exit(node which the tree can grow further from) - for(i=bits[p];i>0;--i) { - if (exit_at_level[i]) break; - } - if (!i) return 1; // overspecified tree - code=exit_at_level[i]; - exit_at_level[i]=0; + for (i = bits[p]; i > 0; --i) + if (exit_at_level[i]) + break; + if (!i) // overspecified tree + return 1; + code = exit_at_level[i]; + exit_at_level[i] = 0; // construct code (append 0s to end) and introduce new exits - for(j=i+1;j<=bits[p];++j) { - exit_at_level[j]=code+(1<<(j-1)); - } - codes[p]=code; + for (j = i + 1 ;j <= bits[p]; ++j) + exit_at_level[j] = code + (1 << (j - 1)); + codes[p] = code; #ifdef V_DEBUG av_log(NULL, AV_LOG_INFO, " %d. code len %d code %d - ", p, bits[p], codes[p]); init_get_bits(&gb, (uint_fast8_t *)&codes[p], bits[p]); - for(i=0;i list[list[i].low].x) list[i].low = j; + if (tmp > list[list[i].low].x) + list[i].low = j; } else { - if (tmp < list[list[i].high].x) list[i].high = j; + if (tmp < list[list[i].high].x) + list[i].high = j; } } } @@ -146,28 +156,60 @@ void ff_vorbis_ready_floor1_list(vorbis_floor1_entry * list, int values) { } } -static void render_line(int x0, int y0, int x1, int y1, float * buf) { - int dy = y1 - y0; - int adx = x1 - x0; - int base = dy / adx; - int ady = FFABS(dy) - FFABS(base) * adx; - int x = x0; - int y = y0; - int err = 0; - int sy = dy<0 ? -1 : 1; - buf[x] = ff_vorbis_floor1_inverse_db_table[y]; - while (++x < x1) { +static inline void render_line_unrolled(intptr_t x, intptr_t y, int x1, + intptr_t sy, int ady, int adx, + float *buf) +{ + int err = -adx; + x -= x1 - 1; + buf += x1 - 1; + while (++x < 0) { err += ady; - if (err >= adx) { - err -= adx; - y += sy; + if (err >= 0) { + err += ady - adx; + y += sy; + buf[x++] = ff_vorbis_floor1_inverse_db_table[y]; } - y += base; + buf[x] = ff_vorbis_floor1_inverse_db_table[y]; + } + if (x <= 0) { + if (err + ady >= 0) + y += sy; buf[x] = ff_vorbis_floor1_inverse_db_table[y]; } } -void ff_vorbis_floor1_render_list(vorbis_floor1_entry * list, int values, uint_fast16_t * y_list, int * flag, int multiplier, float * out, int samples) { +static void render_line(int x0, int y0, int x1, int y1, float *buf) +{ + int dy = y1 - y0; + int adx = x1 - x0; + int ady = FFABS(dy); + int sy = dy < 0 ? -1 : 1; + buf[x0] = ff_vorbis_floor1_inverse_db_table[y0]; + if (ady*2 <= adx) { // optimized common case + render_line_unrolled(x0, y0, x1, sy, ady, adx, buf); + } else { + int base = dy / adx; + int x = x0; + int y = y0; + int err = -adx; + ady -= FFABS(base) * adx; + while (++x < x1) { + y += base; + err += ady; + if (err >= 0) { + err -= adx; + y += sy; + } + buf[x] = ff_vorbis_floor1_inverse_db_table[y]; + } + } +} + +void ff_vorbis_floor1_render_list(vorbis_floor1_entry * list, int values, + uint_fast16_t *y_list, int *flag, + int multiplier, float *out, int samples) +{ int lx, ly, i; lx = 0; ly = y_list[0] * multiplier; @@ -181,7 +223,9 @@ void ff_vorbis_floor1_render_list(vorbis_floor1_entry * list, int values, uint_f lx = x1; ly = y1; } - if (lx >= samples) break; + if (lx >= samples) + break; } - if (lx < samples) render_line(lx, ly, samples, ly, out); + if (lx < samples) + render_line(lx, ly, samples, ly, out); } diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vorbis.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/vorbis.h index dc99acc2c5..ce9bead425 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vorbis.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vorbis.h @@ -25,6 +25,8 @@ extern const float ff_vorbis_floor1_inverse_db_table[256]; extern const float * const ff_vorbis_vwin[8]; +extern const uint8_t ff_vorbis_channel_layout_offsets[8][8]; +extern const int64_t ff_vorbis_channel_layouts[9]; typedef struct { uint_fast16_t x; @@ -36,7 +38,10 @@ typedef struct { void ff_vorbis_ready_floor1_list(vorbis_floor1_entry * list, int values); unsigned int ff_vorbis_nth_root(unsigned int x, unsigned int n); // x^(1/n) int ff_vorbis_len2vlc(uint8_t *bits, uint32_t *codes, uint_fast32_t num); -void ff_vorbis_floor1_render_list(vorbis_floor1_entry * list, int values, uint_fast16_t * y_list, int * flag, int multiplier, float * out, int samples); +void ff_vorbis_floor1_render_list(vorbis_floor1_entry * list, int values, + uint_fast16_t * y_list, int * flag, + int multiplier, float * out, int samples); +void vorbis_inverse_coupling(float *mag, float *ang, int blocksize); #define ilog(i) av_log2(2*(i)) diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vorbis_data.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/vorbis_data.c index 2b61399e72..9bc7979cdf 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vorbis_data.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vorbis_data.c @@ -21,2136 +21,2161 @@ #include "dsputil.h" #include "vorbis.h" -DECLARE_ALIGNED_16(static const float, vwin64[32]) = { - 0.0009460463F, 0.0085006468F, 0.0235352254F, 0.0458950567F, - 0.0753351908F, 0.1115073077F, 0.1539457973F, 0.2020557475F, - 0.2551056759F, 0.3122276645F, 0.3724270287F, 0.4346027792F, - 0.4975789974F, 0.5601459521F, 0.6211085051F, 0.6793382689F, - 0.7338252629F, 0.7837245849F, 0.8283939355F, 0.8674186656F, - 0.9006222429F, 0.9280614787F, 0.9500073081F, 0.9669131782F, - 0.9793740220F, 0.9880792941F, 0.9937636139F, 0.9971582668F, - 0.9989462667F, 0.9997230082F, 0.9999638688F, 0.9999995525F, +const uint8_t ff_vorbis_channel_layout_offsets[8][8] = { + { 0, }, + { 0, 1, }, + { 0, 2, 1, }, + { 0, 1, 2, 3, }, + { 0, 2, 1, 3, 4, }, + { 0, 2, 1, 5, 3, 4, }, + { 0, 2, 1, 6, 5, 3, 4, }, + { 0, 2, 1, 7, 5, 6, 3, 4}, }; -DECLARE_ALIGNED_16(static const float, vwin128[64]) = { - 0.0002365472F, 0.0021280687F, 0.0059065254F, 0.0115626550F, - 0.0190823442F, 0.0284463735F, 0.0396300935F, 0.0526030430F, - 0.0673285281F, 0.0837631763F, 0.1018564887F, 0.1215504095F, - 0.1427789367F, 0.1654677960F, 0.1895342001F, 0.2148867160F, - 0.2414252576F, 0.2690412240F, 0.2976177952F, 0.3270303960F, - 0.3571473350F, 0.3878306189F, 0.4189369387F, 0.4503188188F, - 0.4818259135F, 0.5133064334F, 0.5446086751F, 0.5755826278F, - 0.6060816248F, 0.6359640047F, 0.6650947483F, 0.6933470543F, - 0.7206038179F, 0.7467589810F, 0.7717187213F, 0.7954024542F, - 0.8177436264F, 0.8386902831F, 0.8582053981F, 0.8762669622F, - 0.8928678298F, 0.9080153310F, 0.9217306608F, 0.9340480615F, - 0.9450138200F, 0.9546851041F, 0.9631286621F, 0.9704194171F, - 0.9766389810F, 0.9818741197F, 0.9862151938F, 0.9897546035F, - 0.9925852598F, 0.9947991032F, 0.9964856900F, 0.9977308602F, - 0.9986155015F, 0.9992144193F, 0.9995953200F, 0.9998179155F, - 0.9999331503F, 0.9999825563F, 0.9999977357F, 0.9999999720F, +const int64_t ff_vorbis_channel_layouts[9] = { + CH_LAYOUT_MONO, + CH_LAYOUT_STEREO, + CH_LAYOUT_SURROUND, + CH_LAYOUT_QUAD, + CH_LAYOUT_5POINT0_BACK, + CH_LAYOUT_5POINT1_BACK, + CH_LAYOUT_5POINT1|CH_BACK_CENTER, + CH_LAYOUT_7POINT1, + 0 }; -DECLARE_ALIGNED_16(static const float, vwin256[128]) = { - 0.0000591390F, 0.0005321979F, 0.0014780301F, 0.0028960636F, - 0.0047854363F, 0.0071449926F, 0.0099732775F, 0.0132685298F, - 0.0170286741F, 0.0212513119F, 0.0259337111F, 0.0310727950F, - 0.0366651302F, 0.0427069140F, 0.0491939614F, 0.0561216907F, - 0.0634851102F, 0.0712788035F, 0.0794969160F, 0.0881331402F, - 0.0971807028F, 0.1066323515F, 0.1164803426F, 0.1267164297F, - 0.1373318534F, 0.1483173323F, 0.1596630553F, 0.1713586755F, - 0.1833933062F, 0.1957555184F, 0.2084333404F, 0.2214142599F, - 0.2346852280F, 0.2482326664F, 0.2620424757F, 0.2761000481F, - 0.2903902813F, 0.3048975959F, 0.3196059553F, 0.3344988887F, - 0.3495595160F, 0.3647705766F, 0.3801144597F, 0.3955732382F, - 0.4111287047F, 0.4267624093F, 0.4424557009F, 0.4581897696F, - 0.4739456913F, 0.4897044744F, 0.5054471075F, 0.5211546088F, - 0.5368080763F, 0.5523887395F, 0.5678780103F, 0.5832575361F, - 0.5985092508F, 0.6136154277F, 0.6285587300F, 0.6433222619F, - 0.6578896175F, 0.6722449294F, 0.6863729144F, 0.7002589187F, - 0.7138889597F, 0.7272497662F, 0.7403288154F, 0.7531143679F, - 0.7655954985F, 0.7777621249F, 0.7896050322F, 0.8011158947F, - 0.8122872932F, 0.8231127294F, 0.8335866365F, 0.8437043850F, - 0.8534622861F, 0.8628575905F, 0.8718884835F, 0.8805540765F, - 0.8888543947F, 0.8967903616F, 0.9043637797F, 0.9115773078F, - 0.9184344360F, 0.9249394562F, 0.9310974312F, 0.9369141608F, - 0.9423961446F, 0.9475505439F, 0.9523851406F, 0.9569082947F, - 0.9611289005F, 0.9650563408F, 0.9687004405F, 0.9720714191F, - 0.9751798427F, 0.9780365753F, 0.9806527301F, 0.9830396204F, - 0.9852087111F, 0.9871715701F, 0.9889398207F, 0.9905250941F, - 0.9919389832F, 0.9931929973F, 0.9942985174F, 0.9952667537F, - 0.9961087037F, 0.9968351119F, 0.9974564312F, 0.9979827858F, - 0.9984239359F, 0.9987892441F, 0.9990876435F, 0.9993276081F, - 0.9995171241F, 0.9996636648F, 0.9997741654F, 0.9998550016F, - 0.9999119692F, 0.9999502656F, 0.9999744742F, 0.9999885497F, - 0.9999958064F, 0.9999989077F, 0.9999998584F, 0.9999999983F, +DECLARE_ALIGNED(16, static const float, vwin64)[32] = { + 0.0009460463F, 0.0085006468F, 0.0235352254F, 0.0458950567F, + 0.0753351908F, 0.1115073077F, 0.1539457973F, 0.2020557475F, + 0.2551056759F, 0.3122276645F, 0.3724270287F, 0.4346027792F, + 0.4975789974F, 0.5601459521F, 0.6211085051F, 0.6793382689F, + 0.7338252629F, 0.7837245849F, 0.8283939355F, 0.8674186656F, + 0.9006222429F, 0.9280614787F, 0.9500073081F, 0.9669131782F, + 0.9793740220F, 0.9880792941F, 0.9937636139F, 0.9971582668F, + 0.9989462667F, 0.9997230082F, 0.9999638688F, 0.9999995525F, }; -DECLARE_ALIGNED_16(static const float, vwin512[256]) = { - 0.0000147849F, 0.0001330607F, 0.0003695946F, 0.0007243509F, - 0.0011972759F, 0.0017882983F, 0.0024973285F, 0.0033242588F, - 0.0042689632F, 0.0053312973F, 0.0065110982F, 0.0078081841F, - 0.0092223540F, 0.0107533880F, 0.0124010466F, 0.0141650703F, - 0.0160451800F, 0.0180410758F, 0.0201524373F, 0.0223789233F, - 0.0247201710F, 0.0271757958F, 0.0297453914F, 0.0324285286F, - 0.0352247556F, 0.0381335972F, 0.0411545545F, 0.0442871045F, - 0.0475306997F, 0.0508847676F, 0.0543487103F, 0.0579219038F, - 0.0616036982F, 0.0653934164F, 0.0692903546F, 0.0732937809F, - 0.0774029356F, 0.0816170305F, 0.0859352485F, 0.0903567428F, - 0.0948806375F, 0.0995060259F, 0.1042319712F, 0.1090575056F, - 0.1139816300F, 0.1190033137F, 0.1241214941F, 0.1293350764F, - 0.1346429333F, 0.1400439046F, 0.1455367974F, 0.1511203852F, - 0.1567934083F, 0.1625545735F, 0.1684025537F, 0.1743359881F, - 0.1803534820F, 0.1864536069F, 0.1926349000F, 0.1988958650F, - 0.2052349715F, 0.2116506555F, 0.2181413191F, 0.2247053313F, - 0.2313410275F, 0.2380467105F, 0.2448206500F, 0.2516610835F, - 0.2585662164F, 0.2655342226F, 0.2725632448F, 0.2796513950F, - 0.2867967551F, 0.2939973773F, 0.3012512852F, 0.3085564739F, - 0.3159109111F, 0.3233125375F, 0.3307592680F, 0.3382489922F, - 0.3457795756F, 0.3533488602F, 0.3609546657F, 0.3685947904F, - 0.3762670121F, 0.3839690896F, 0.3916987634F, 0.3994537572F, - 0.4072317788F, 0.4150305215F, 0.4228476653F, 0.4306808783F, - 0.4385278181F, 0.4463861329F, 0.4542534630F, 0.4621274424F, - 0.4700057001F, 0.4778858615F, 0.4857655502F, 0.4936423891F, - 0.5015140023F, 0.5093780165F, 0.5172320626F, 0.5250737772F, - 0.5329008043F, 0.5407107971F, 0.5485014192F, 0.5562703465F, - 0.5640152688F, 0.5717338914F, 0.5794239366F, 0.5870831457F, - 0.5947092801F, 0.6023001235F, 0.6098534829F, 0.6173671907F, - 0.6248391059F, 0.6322671161F, 0.6396491384F, 0.6469831217F, - 0.6542670475F, 0.6614989319F, 0.6686768267F, 0.6757988210F, - 0.6828630426F, 0.6898676592F, 0.6968108799F, 0.7036909564F, - 0.7105061843F, 0.7172549043F, 0.7239355032F, 0.7305464154F, - 0.7370861235F, 0.7435531598F, 0.7499461068F, 0.7562635986F, - 0.7625043214F, 0.7686670148F, 0.7747504721F, 0.7807535410F, - 0.7866751247F, 0.7925141825F, 0.7982697296F, 0.8039408387F, - 0.8095266395F, 0.8150263196F, 0.8204391248F, 0.8257643590F, - 0.8310013848F, 0.8361496236F, 0.8412085555F, 0.8461777194F, - 0.8510567129F, 0.8558451924F, 0.8605428730F, 0.8651495278F, - 0.8696649882F, 0.8740891432F, 0.8784219392F, 0.8826633797F, - 0.8868135244F, 0.8908724888F, 0.8948404441F, 0.8987176157F, - 0.9025042831F, 0.9062007791F, 0.9098074886F, 0.9133248482F, - 0.9167533451F, 0.9200935163F, 0.9233459472F, 0.9265112712F, - 0.9295901680F, 0.9325833632F, 0.9354916263F, 0.9383157705F, - 0.9410566504F, 0.9437151618F, 0.9462922398F, 0.9487888576F, - 0.9512060252F, 0.9535447882F, 0.9558062262F, 0.9579914516F, - 0.9601016078F, 0.9621378683F, 0.9641014348F, 0.9659935361F, - 0.9678154261F, 0.9695683830F, 0.9712537071F, 0.9728727198F, - 0.9744267618F, 0.9759171916F, 0.9773453842F, 0.9787127293F, - 0.9800206298F, 0.9812705006F, 0.9824637665F, 0.9836018613F, - 0.9846862258F, 0.9857183066F, 0.9866995544F, 0.9876314227F, - 0.9885153662F, 0.9893528393F, 0.9901452948F, 0.9908941823F, - 0.9916009470F, 0.9922670279F, 0.9928938570F, 0.9934828574F, - 0.9940354423F, 0.9945530133F, 0.9950369595F, 0.9954886562F, - 0.9959094633F, 0.9963007242F, 0.9966637649F, 0.9969998925F, - 0.9973103939F, 0.9975965351F, 0.9978595598F, 0.9981006885F, - 0.9983211172F, 0.9985220166F, 0.9987045311F, 0.9988697776F, - 0.9990188449F, 0.9991527924F, 0.9992726499F, 0.9993794157F, - 0.9994740570F, 0.9995575079F, 0.9996306699F, 0.9996944099F, - 0.9997495605F, 0.9997969190F, 0.9998372465F, 0.9998712678F, - 0.9998996704F, 0.9999231041F, 0.9999421807F, 0.9999574732F, - 0.9999695157F, 0.9999788026F, 0.9999857885F, 0.9999908879F, - 0.9999944746F, 0.9999968817F, 0.9999984010F, 0.9999992833F, - 0.9999997377F, 0.9999999317F, 0.9999999911F, 0.9999999999F, +DECLARE_ALIGNED(16, static const float, vwin128)[64] = { + 0.0002365472F, 0.0021280687F, 0.0059065254F, 0.0115626550F, + 0.0190823442F, 0.0284463735F, 0.0396300935F, 0.0526030430F, + 0.0673285281F, 0.0837631763F, 0.1018564887F, 0.1215504095F, + 0.1427789367F, 0.1654677960F, 0.1895342001F, 0.2148867160F, + 0.2414252576F, 0.2690412240F, 0.2976177952F, 0.3270303960F, + 0.3571473350F, 0.3878306189F, 0.4189369387F, 0.4503188188F, + 0.4818259135F, 0.5133064334F, 0.5446086751F, 0.5755826278F, + 0.6060816248F, 0.6359640047F, 0.6650947483F, 0.6933470543F, + 0.7206038179F, 0.7467589810F, 0.7717187213F, 0.7954024542F, + 0.8177436264F, 0.8386902831F, 0.8582053981F, 0.8762669622F, + 0.8928678298F, 0.9080153310F, 0.9217306608F, 0.9340480615F, + 0.9450138200F, 0.9546851041F, 0.9631286621F, 0.9704194171F, + 0.9766389810F, 0.9818741197F, 0.9862151938F, 0.9897546035F, + 0.9925852598F, 0.9947991032F, 0.9964856900F, 0.9977308602F, + 0.9986155015F, 0.9992144193F, 0.9995953200F, 0.9998179155F, + 0.9999331503F, 0.9999825563F, 0.9999977357F, 0.9999999720F, }; -DECLARE_ALIGNED_16(static const float, vwin1024[512]) = { - 0.0000036962F, 0.0000332659F, 0.0000924041F, 0.0001811086F, - 0.0002993761F, 0.0004472021F, 0.0006245811F, 0.0008315063F, - 0.0010679699F, 0.0013339631F, 0.0016294757F, 0.0019544965F, - 0.0023090133F, 0.0026930125F, 0.0031064797F, 0.0035493989F, - 0.0040217533F, 0.0045235250F, 0.0050546946F, 0.0056152418F, - 0.0062051451F, 0.0068243817F, 0.0074729278F, 0.0081507582F, - 0.0088578466F, 0.0095941655F, 0.0103596863F, 0.0111543789F, - 0.0119782122F, 0.0128311538F, 0.0137131701F, 0.0146242260F, - 0.0155642855F, 0.0165333111F, 0.0175312640F, 0.0185581042F, - 0.0196137903F, 0.0206982797F, 0.0218115284F, 0.0229534910F, - 0.0241241208F, 0.0253233698F, 0.0265511886F, 0.0278075263F, - 0.0290923308F, 0.0304055484F, 0.0317471241F, 0.0331170013F, - 0.0345151222F, 0.0359414274F, 0.0373958560F, 0.0388783456F, - 0.0403888325F, 0.0419272511F, 0.0434935347F, 0.0450876148F, - 0.0467094213F, 0.0483588828F, 0.0500359261F, 0.0517404765F, - 0.0534724575F, 0.0552317913F, 0.0570183983F, 0.0588321971F, - 0.0606731048F, 0.0625410369F, 0.0644359070F, 0.0663576272F, - 0.0683061077F, 0.0702812571F, 0.0722829821F, 0.0743111878F, - 0.0763657775F, 0.0784466526F, 0.0805537129F, 0.0826868561F, - 0.0848459782F, 0.0870309736F, 0.0892417345F, 0.0914781514F, - 0.0937401128F, 0.0960275056F, 0.0983402145F, 0.1006781223F, - 0.1030411101F, 0.1054290568F, 0.1078418397F, 0.1102793336F, - 0.1127414119F, 0.1152279457F, 0.1177388042F, 0.1202738544F, - 0.1228329618F, 0.1254159892F, 0.1280227980F, 0.1306532471F, - 0.1333071937F, 0.1359844927F, 0.1386849970F, 0.1414085575F, - 0.1441550230F, 0.1469242403F, 0.1497160539F, 0.1525303063F, - 0.1553668381F, 0.1582254875F, 0.1611060909F, 0.1640084822F, - 0.1669324936F, 0.1698779549F, 0.1728446939F, 0.1758325362F, - 0.1788413055F, 0.1818708232F, 0.1849209084F, 0.1879913785F, - 0.1910820485F, 0.1941927312F, 0.1973232376F, 0.2004733764F, - 0.2036429541F, 0.2068317752F, 0.2100396421F, 0.2132663552F, - 0.2165117125F, 0.2197755102F, 0.2230575422F, 0.2263576007F, - 0.2296754753F, 0.2330109540F, 0.2363638225F, 0.2397338646F, - 0.2431208619F, 0.2465245941F, 0.2499448389F, 0.2533813719F, - 0.2568339669F, 0.2603023956F, 0.2637864277F, 0.2672858312F, - 0.2708003718F, 0.2743298135F, 0.2778739186F, 0.2814324472F, - 0.2850051576F, 0.2885918065F, 0.2921921485F, 0.2958059366F, - 0.2994329219F, 0.3030728538F, 0.3067254799F, 0.3103905462F, - 0.3140677969F, 0.3177569747F, 0.3214578205F, 0.3251700736F, - 0.3288934718F, 0.3326277513F, 0.3363726468F, 0.3401278914F, - 0.3438932168F, 0.3476683533F, 0.3514530297F, 0.3552469734F, - 0.3590499106F, 0.3628615659F, 0.3666816630F, 0.3705099239F, - 0.3743460698F, 0.3781898204F, 0.3820408945F, 0.3858990095F, - 0.3897638820F, 0.3936352274F, 0.3975127601F, 0.4013961936F, - 0.4052852405F, 0.4091796123F, 0.4130790198F, 0.4169831732F, - 0.4208917815F, 0.4248045534F, 0.4287211965F, 0.4326414181F, - 0.4365649248F, 0.4404914225F, 0.4444206167F, 0.4483522125F, - 0.4522859146F, 0.4562214270F, 0.4601584538F, 0.4640966984F, - 0.4680358644F, 0.4719756548F, 0.4759157726F, 0.4798559209F, - 0.4837958024F, 0.4877351199F, 0.4916735765F, 0.4956108751F, - 0.4995467188F, 0.5034808109F, 0.5074128550F, 0.5113425550F, - 0.5152696149F, 0.5191937395F, 0.5231146336F, 0.5270320028F, - 0.5309455530F, 0.5348549910F, 0.5387600239F, 0.5426603597F, - 0.5465557070F, 0.5504457754F, 0.5543302752F, 0.5582089175F, - 0.5620814145F, 0.5659474793F, 0.5698068262F, 0.5736591704F, - 0.5775042283F, 0.5813417176F, 0.5851713571F, 0.5889928670F, - 0.5928059689F, 0.5966103856F, 0.6004058415F, 0.6041920626F, - 0.6079687761F, 0.6117357113F, 0.6154925986F, 0.6192391705F, - 0.6229751612F, 0.6267003064F, 0.6304143441F, 0.6341170137F, - 0.6378080569F, 0.6414872173F, 0.6451542405F, 0.6488088741F, - 0.6524508681F, 0.6560799742F, 0.6596959469F, 0.6632985424F, - 0.6668875197F, 0.6704626398F, 0.6740236662F, 0.6775703649F, - 0.6811025043F, 0.6846198554F, 0.6881221916F, 0.6916092892F, - 0.6950809269F, 0.6985368861F, 0.7019769510F, 0.7054009085F, - 0.7088085484F, 0.7121996632F, 0.7155740484F, 0.7189315023F, - 0.7222718263F, 0.7255948245F, 0.7289003043F, 0.7321880760F, - 0.7354579530F, 0.7387097518F, 0.7419432921F, 0.7451583966F, - 0.7483548915F, 0.7515326059F, 0.7546913723F, 0.7578310265F, - 0.7609514077F, 0.7640523581F, 0.7671337237F, 0.7701953535F, - 0.7732371001F, 0.7762588195F, 0.7792603711F, 0.7822416178F, - 0.7852024259F, 0.7881426654F, 0.7910622097F, 0.7939609356F, - 0.7968387237F, 0.7996954579F, 0.8025310261F, 0.8053453193F, - 0.8081382324F, 0.8109096638F, 0.8136595156F, 0.8163876936F, - 0.8190941071F, 0.8217786690F, 0.8244412960F, 0.8270819086F, - 0.8297004305F, 0.8322967896F, 0.8348709171F, 0.8374227481F, - 0.8399522213F, 0.8424592789F, 0.8449438672F, 0.8474059356F, - 0.8498454378F, 0.8522623306F, 0.8546565748F, 0.8570281348F, - 0.8593769787F, 0.8617030779F, 0.8640064080F, 0.8662869477F, - 0.8685446796F, 0.8707795899F, 0.8729916682F, 0.8751809079F, - 0.8773473059F, 0.8794908626F, 0.8816115819F, 0.8837094713F, - 0.8857845418F, 0.8878368079F, 0.8898662874F, 0.8918730019F, - 0.8938569760F, 0.8958182380F, 0.8977568194F, 0.8996727552F, - 0.9015660837F, 0.9034368465F, 0.9052850885F, 0.9071108577F, - 0.9089142057F, 0.9106951869F, 0.9124538591F, 0.9141902832F, - 0.9159045233F, 0.9175966464F, 0.9192667228F, 0.9209148257F, - 0.9225410313F, 0.9241454187F, 0.9257280701F, 0.9272890704F, - 0.9288285075F, 0.9303464720F, 0.9318430576F, 0.9333183603F, - 0.9347724792F, 0.9362055158F, 0.9376175745F, 0.9390087622F, - 0.9403791881F, 0.9417289644F, 0.9430582055F, 0.9443670283F, - 0.9456555521F, 0.9469238986F, 0.9481721917F, 0.9494005577F, - 0.9506091252F, 0.9517980248F, 0.9529673894F, 0.9541173540F, - 0.9552480557F, 0.9563596334F, 0.9574522282F, 0.9585259830F, - 0.9595810428F, 0.9606175542F, 0.9616356656F, 0.9626355274F, - 0.9636172915F, 0.9645811114F, 0.9655271425F, 0.9664555414F, - 0.9673664664F, 0.9682600774F, 0.9691365355F, 0.9699960034F, - 0.9708386448F, 0.9716646250F, 0.9724741103F, 0.9732672685F, - 0.9740442683F, 0.9748052795F, 0.9755504729F, 0.9762800205F, - 0.9769940950F, 0.9776928703F, 0.9783765210F, 0.9790452223F, - 0.9796991504F, 0.9803384823F, 0.9809633954F, 0.9815740679F, - 0.9821706784F, 0.9827534063F, 0.9833224312F, 0.9838779332F, - 0.9844200928F, 0.9849490910F, 0.9854651087F, 0.9859683274F, - 0.9864589286F, 0.9869370940F, 0.9874030054F, 0.9878568447F, - 0.9882987937F, 0.9887290343F, 0.9891477481F, 0.9895551169F, - 0.9899513220F, 0.9903365446F, 0.9907109658F, 0.9910747662F, - 0.9914281260F, 0.9917712252F, 0.9921042433F, 0.9924273593F, - 0.9927407516F, 0.9930445982F, 0.9933390763F, 0.9936243626F, - 0.9939006331F, 0.9941680631F, 0.9944268269F, 0.9946770982F, - 0.9949190498F, 0.9951528537F, 0.9953786808F, 0.9955967011F, - 0.9958070836F, 0.9960099963F, 0.9962056061F, 0.9963940787F, - 0.9965755786F, 0.9967502693F, 0.9969183129F, 0.9970798704F, - 0.9972351013F, 0.9973841640F, 0.9975272151F, 0.9976644103F, - 0.9977959036F, 0.9979218476F, 0.9980423932F, 0.9981576901F, - 0.9982678862F, 0.9983731278F, 0.9984735596F, 0.9985693247F, - 0.9986605645F, 0.9987474186F, 0.9988300248F, 0.9989085193F, - 0.9989830364F, 0.9990537085F, 0.9991206662F, 0.9991840382F, - 0.9992439513F, 0.9993005303F, 0.9993538982F, 0.9994041757F, - 0.9994514817F, 0.9994959330F, 0.9995376444F, 0.9995767286F, - 0.9996132960F, 0.9996474550F, 0.9996793121F, 0.9997089710F, - 0.9997365339F, 0.9997621003F, 0.9997857677F, 0.9998076311F, - 0.9998277836F, 0.9998463156F, 0.9998633155F, 0.9998788692F, - 0.9998930603F, 0.9999059701F, 0.9999176774F, 0.9999282586F, - 0.9999377880F, 0.9999463370F, 0.9999539749F, 0.9999607685F, - 0.9999667820F, 0.9999720773F, 0.9999767136F, 0.9999807479F, - 0.9999842344F, 0.9999872249F, 0.9999897688F, 0.9999919127F, - 0.9999937009F, 0.9999951749F, 0.9999963738F, 0.9999973342F, - 0.9999980900F, 0.9999986724F, 0.9999991103F, 0.9999994297F, - 0.9999996543F, 0.9999998049F, 0.9999999000F, 0.9999999552F, - 0.9999999836F, 0.9999999957F, 0.9999999994F, 1.0000000000F, +DECLARE_ALIGNED(16, static const float, vwin256)[128] = { + 0.0000591390F, 0.0005321979F, 0.0014780301F, 0.0028960636F, + 0.0047854363F, 0.0071449926F, 0.0099732775F, 0.0132685298F, + 0.0170286741F, 0.0212513119F, 0.0259337111F, 0.0310727950F, + 0.0366651302F, 0.0427069140F, 0.0491939614F, 0.0561216907F, + 0.0634851102F, 0.0712788035F, 0.0794969160F, 0.0881331402F, + 0.0971807028F, 0.1066323515F, 0.1164803426F, 0.1267164297F, + 0.1373318534F, 0.1483173323F, 0.1596630553F, 0.1713586755F, + 0.1833933062F, 0.1957555184F, 0.2084333404F, 0.2214142599F, + 0.2346852280F, 0.2482326664F, 0.2620424757F, 0.2761000481F, + 0.2903902813F, 0.3048975959F, 0.3196059553F, 0.3344988887F, + 0.3495595160F, 0.3647705766F, 0.3801144597F, 0.3955732382F, + 0.4111287047F, 0.4267624093F, 0.4424557009F, 0.4581897696F, + 0.4739456913F, 0.4897044744F, 0.5054471075F, 0.5211546088F, + 0.5368080763F, 0.5523887395F, 0.5678780103F, 0.5832575361F, + 0.5985092508F, 0.6136154277F, 0.6285587300F, 0.6433222619F, + 0.6578896175F, 0.6722449294F, 0.6863729144F, 0.7002589187F, + 0.7138889597F, 0.7272497662F, 0.7403288154F, 0.7531143679F, + 0.7655954985F, 0.7777621249F, 0.7896050322F, 0.8011158947F, + 0.8122872932F, 0.8231127294F, 0.8335866365F, 0.8437043850F, + 0.8534622861F, 0.8628575905F, 0.8718884835F, 0.8805540765F, + 0.8888543947F, 0.8967903616F, 0.9043637797F, 0.9115773078F, + 0.9184344360F, 0.9249394562F, 0.9310974312F, 0.9369141608F, + 0.9423961446F, 0.9475505439F, 0.9523851406F, 0.9569082947F, + 0.9611289005F, 0.9650563408F, 0.9687004405F, 0.9720714191F, + 0.9751798427F, 0.9780365753F, 0.9806527301F, 0.9830396204F, + 0.9852087111F, 0.9871715701F, 0.9889398207F, 0.9905250941F, + 0.9919389832F, 0.9931929973F, 0.9942985174F, 0.9952667537F, + 0.9961087037F, 0.9968351119F, 0.9974564312F, 0.9979827858F, + 0.9984239359F, 0.9987892441F, 0.9990876435F, 0.9993276081F, + 0.9995171241F, 0.9996636648F, 0.9997741654F, 0.9998550016F, + 0.9999119692F, 0.9999502656F, 0.9999744742F, 0.9999885497F, + 0.9999958064F, 0.9999989077F, 0.9999998584F, 0.9999999983F, }; -DECLARE_ALIGNED_16(static const float, vwin2048[1024]) = { - 0.0000009241F, 0.0000083165F, 0.0000231014F, 0.0000452785F, - 0.0000748476F, 0.0001118085F, 0.0001561608F, 0.0002079041F, - 0.0002670379F, 0.0003335617F, 0.0004074748F, 0.0004887765F, - 0.0005774661F, 0.0006735427F, 0.0007770054F, 0.0008878533F, - 0.0010060853F, 0.0011317002F, 0.0012646969F, 0.0014050742F, - 0.0015528307F, 0.0017079650F, 0.0018704756F, 0.0020403610F, - 0.0022176196F, 0.0024022497F, 0.0025942495F, 0.0027936173F, - 0.0030003511F, 0.0032144490F, 0.0034359088F, 0.0036647286F, - 0.0039009061F, 0.0041444391F, 0.0043953253F, 0.0046535621F, - 0.0049191472F, 0.0051920781F, 0.0054723520F, 0.0057599664F, - 0.0060549184F, 0.0063572052F, 0.0066668239F, 0.0069837715F, - 0.0073080449F, 0.0076396410F, 0.0079785566F, 0.0083247884F, - 0.0086783330F, 0.0090391871F, 0.0094073470F, 0.0097828092F, - 0.0101655700F, 0.0105556258F, 0.0109529726F, 0.0113576065F, - 0.0117695237F, 0.0121887200F, 0.0126151913F, 0.0130489335F, - 0.0134899422F, 0.0139382130F, 0.0143937415F, 0.0148565233F, - 0.0153265536F, 0.0158038279F, 0.0162883413F, 0.0167800889F, - 0.0172790660F, 0.0177852675F, 0.0182986882F, 0.0188193231F, - 0.0193471668F, 0.0198822141F, 0.0204244594F, 0.0209738974F, - 0.0215305225F, 0.0220943289F, 0.0226653109F, 0.0232434627F, - 0.0238287784F, 0.0244212519F, 0.0250208772F, 0.0256276481F, - 0.0262415582F, 0.0268626014F, 0.0274907711F, 0.0281260608F, - 0.0287684638F, 0.0294179736F, 0.0300745833F, 0.0307382859F, - 0.0314090747F, 0.0320869424F, 0.0327718819F, 0.0334638860F, - 0.0341629474F, 0.0348690586F, 0.0355822122F, 0.0363024004F, - 0.0370296157F, 0.0377638502F, 0.0385050960F, 0.0392533451F, - 0.0400085896F, 0.0407708211F, 0.0415400315F, 0.0423162123F, - 0.0430993552F, 0.0438894515F, 0.0446864926F, 0.0454904698F, - 0.0463013742F, 0.0471191969F, 0.0479439288F, 0.0487755607F, - 0.0496140836F, 0.0504594879F, 0.0513117642F, 0.0521709031F, - 0.0530368949F, 0.0539097297F, 0.0547893979F, 0.0556758894F, - 0.0565691941F, 0.0574693019F, 0.0583762026F, 0.0592898858F, - 0.0602103410F, 0.0611375576F, 0.0620715250F, 0.0630122324F, - 0.0639596688F, 0.0649138234F, 0.0658746848F, 0.0668422421F, - 0.0678164838F, 0.0687973985F, 0.0697849746F, 0.0707792005F, - 0.0717800645F, 0.0727875547F, 0.0738016591F, 0.0748223656F, - 0.0758496620F, 0.0768835359F, 0.0779239751F, 0.0789709668F, - 0.0800244985F, 0.0810845574F, 0.0821511306F, 0.0832242052F, - 0.0843037679F, 0.0853898056F, 0.0864823050F, 0.0875812525F, - 0.0886866347F, 0.0897984378F, 0.0909166480F, 0.0920412513F, - 0.0931722338F, 0.0943095813F, 0.0954532795F, 0.0966033140F, - 0.0977596702F, 0.0989223336F, 0.1000912894F, 0.1012665227F, - 0.1024480185F, 0.1036357616F, 0.1048297369F, 0.1060299290F, - 0.1072363224F, 0.1084489014F, 0.1096676504F, 0.1108925534F, - 0.1121235946F, 0.1133607577F, 0.1146040267F, 0.1158533850F, - 0.1171088163F, 0.1183703040F, 0.1196378312F, 0.1209113812F, - 0.1221909370F, 0.1234764815F, 0.1247679974F, 0.1260654674F, - 0.1273688740F, 0.1286781995F, 0.1299934263F, 0.1313145365F, - 0.1326415121F, 0.1339743349F, 0.1353129866F, 0.1366574490F, - 0.1380077035F, 0.1393637315F, 0.1407255141F, 0.1420930325F, - 0.1434662677F, 0.1448452004F, 0.1462298115F, 0.1476200814F, - 0.1490159906F, 0.1504175195F, 0.1518246482F, 0.1532373569F, - 0.1546556253F, 0.1560794333F, 0.1575087606F, 0.1589435866F, - 0.1603838909F, 0.1618296526F, 0.1632808509F, 0.1647374648F, - 0.1661994731F, 0.1676668546F, 0.1691395880F, 0.1706176516F, - 0.1721010238F, 0.1735896829F, 0.1750836068F, 0.1765827736F, - 0.1780871610F, 0.1795967468F, 0.1811115084F, 0.1826314234F, - 0.1841564689F, 0.1856866221F, 0.1872218600F, 0.1887621595F, - 0.1903074974F, 0.1918578503F, 0.1934131947F, 0.1949735068F, - 0.1965387630F, 0.1981089393F, 0.1996840117F, 0.2012639560F, - 0.2028487479F, 0.2044383630F, 0.2060327766F, 0.2076319642F, - 0.2092359007F, 0.2108445614F, 0.2124579211F, 0.2140759545F, - 0.2156986364F, 0.2173259411F, 0.2189578432F, 0.2205943168F, - 0.2222353361F, 0.2238808751F, 0.2255309076F, 0.2271854073F, - 0.2288443480F, 0.2305077030F, 0.2321754457F, 0.2338475493F, - 0.2355239869F, 0.2372047315F, 0.2388897560F, 0.2405790329F, - 0.2422725350F, 0.2439702347F, 0.2456721043F, 0.2473781159F, - 0.2490882418F, 0.2508024539F, 0.2525207240F, 0.2542430237F, - 0.2559693248F, 0.2576995986F, 0.2594338166F, 0.2611719498F, - 0.2629139695F, 0.2646598466F, 0.2664095520F, 0.2681630564F, - 0.2699203304F, 0.2716813445F, 0.2734460691F, 0.2752144744F, - 0.2769865307F, 0.2787622079F, 0.2805414760F, 0.2823243047F, - 0.2841106637F, 0.2859005227F, 0.2876938509F, 0.2894906179F, - 0.2912907928F, 0.2930943447F, 0.2949012426F, 0.2967114554F, - 0.2985249520F, 0.3003417009F, 0.3021616708F, 0.3039848301F, - 0.3058111471F, 0.3076405901F, 0.3094731273F, 0.3113087266F, - 0.3131473560F, 0.3149889833F, 0.3168335762F, 0.3186811024F, - 0.3205315294F, 0.3223848245F, 0.3242409552F, 0.3260998886F, - 0.3279615918F, 0.3298260319F, 0.3316931758F, 0.3335629903F, - 0.3354354423F, 0.3373104982F, 0.3391881247F, 0.3410682882F, - 0.3429509551F, 0.3448360917F, 0.3467236642F, 0.3486136387F, - 0.3505059811F, 0.3524006575F, 0.3542976336F, 0.3561968753F, - 0.3580983482F, 0.3600020179F, 0.3619078499F, 0.3638158096F, - 0.3657258625F, 0.3676379737F, 0.3695521086F, 0.3714682321F, - 0.3733863094F, 0.3753063055F, 0.3772281852F, 0.3791519134F, - 0.3810774548F, 0.3830047742F, 0.3849338362F, 0.3868646053F, - 0.3887970459F, 0.3907311227F, 0.3926667998F, 0.3946040417F, - 0.3965428125F, 0.3984830765F, 0.4004247978F, 0.4023679403F, - 0.4043124683F, 0.4062583455F, 0.4082055359F, 0.4101540034F, - 0.4121037117F, 0.4140546246F, 0.4160067058F, 0.4179599190F, - 0.4199142277F, 0.4218695956F, 0.4238259861F, 0.4257833627F, - 0.4277416888F, 0.4297009279F, 0.4316610433F, 0.4336219983F, - 0.4355837562F, 0.4375462803F, 0.4395095337F, 0.4414734797F, - 0.4434380815F, 0.4454033021F, 0.4473691046F, 0.4493354521F, - 0.4513023078F, 0.4532696345F, 0.4552373954F, 0.4572055533F, - 0.4591740713F, 0.4611429123F, 0.4631120393F, 0.4650814151F, - 0.4670510028F, 0.4690207650F, 0.4709906649F, 0.4729606651F, - 0.4749307287F, 0.4769008185F, 0.4788708972F, 0.4808409279F, - 0.4828108732F, 0.4847806962F, 0.4867503597F, 0.4887198264F, - 0.4906890593F, 0.4926580213F, 0.4946266753F, 0.4965949840F, - 0.4985629105F, 0.5005304176F, 0.5024974683F, 0.5044640255F, - 0.5064300522F, 0.5083955114F, 0.5103603659F, 0.5123245790F, - 0.5142881136F, 0.5162509328F, 0.5182129997F, 0.5201742774F, - 0.5221347290F, 0.5240943178F, 0.5260530070F, 0.5280107598F, - 0.5299675395F, 0.5319233095F, 0.5338780330F, 0.5358316736F, - 0.5377841946F, 0.5397355596F, 0.5416857320F, 0.5436346755F, - 0.5455823538F, 0.5475287304F, 0.5494737691F, 0.5514174337F, - 0.5533596881F, 0.5553004962F, 0.5572398218F, 0.5591776291F, - 0.5611138821F, 0.5630485449F, 0.5649815818F, 0.5669129570F, - 0.5688426349F, 0.5707705799F, 0.5726967564F, 0.5746211290F, - 0.5765436624F, 0.5784643212F, 0.5803830702F, 0.5822998743F, - 0.5842146984F, 0.5861275076F, 0.5880382669F, 0.5899469416F, - 0.5918534968F, 0.5937578981F, 0.5956601107F, 0.5975601004F, - 0.5994578326F, 0.6013532732F, 0.6032463880F, 0.6051371429F, - 0.6070255039F, 0.6089114372F, 0.6107949090F, 0.6126758856F, - 0.6145543334F, 0.6164302191F, 0.6183035092F, 0.6201741706F, - 0.6220421700F, 0.6239074745F, 0.6257700513F, 0.6276298674F, - 0.6294868903F, 0.6313410873F, 0.6331924262F, 0.6350408745F, - 0.6368864001F, 0.6387289710F, 0.6405685552F, 0.6424051209F, - 0.6442386364F, 0.6460690702F, 0.6478963910F, 0.6497205673F, - 0.6515415682F, 0.6533593625F, 0.6551739194F, 0.6569852082F, - 0.6587931984F, 0.6605978593F, 0.6623991609F, 0.6641970728F, - 0.6659915652F, 0.6677826081F, 0.6695701718F, 0.6713542268F, - 0.6731347437F, 0.6749116932F, 0.6766850461F, 0.6784547736F, - 0.6802208469F, 0.6819832374F, 0.6837419164F, 0.6854968559F, - 0.6872480275F, 0.6889954034F, 0.6907389556F, 0.6924786566F, - 0.6942144788F, 0.6959463950F, 0.6976743780F, 0.6993984008F, - 0.7011184365F, 0.7028344587F, 0.7045464407F, 0.7062543564F, - 0.7079581796F, 0.7096578844F, 0.7113534450F, 0.7130448359F, - 0.7147320316F, 0.7164150070F, 0.7180937371F, 0.7197681970F, - 0.7214383620F, 0.7231042077F, 0.7247657098F, 0.7264228443F, - 0.7280755871F, 0.7297239147F, 0.7313678035F, 0.7330072301F, - 0.7346421715F, 0.7362726046F, 0.7378985069F, 0.7395198556F, - 0.7411366285F, 0.7427488034F, 0.7443563584F, 0.7459592717F, - 0.7475575218F, 0.7491510873F, 0.7507399471F, 0.7523240803F, - 0.7539034661F, 0.7554780839F, 0.7570479136F, 0.7586129349F, - 0.7601731279F, 0.7617284730F, 0.7632789506F, 0.7648245416F, - 0.7663652267F, 0.7679009872F, 0.7694318044F, 0.7709576599F, - 0.7724785354F, 0.7739944130F, 0.7755052749F, 0.7770111035F, - 0.7785118815F, 0.7800075916F, 0.7814982170F, 0.7829837410F, - 0.7844641472F, 0.7859394191F, 0.7874095408F, 0.7888744965F, - 0.7903342706F, 0.7917888476F, 0.7932382124F, 0.7946823501F, - 0.7961212460F, 0.7975548855F, 0.7989832544F, 0.8004063386F, - 0.8018241244F, 0.8032365981F, 0.8046437463F, 0.8060455560F, - 0.8074420141F, 0.8088331080F, 0.8102188253F, 0.8115991536F, - 0.8129740810F, 0.8143435957F, 0.8157076861F, 0.8170663409F, - 0.8184195489F, 0.8197672994F, 0.8211095817F, 0.8224463853F, - 0.8237777001F, 0.8251035161F, 0.8264238235F, 0.8277386129F, - 0.8290478750F, 0.8303516008F, 0.8316497814F, 0.8329424083F, - 0.8342294731F, 0.8355109677F, 0.8367868841F, 0.8380572148F, - 0.8393219523F, 0.8405810893F, 0.8418346190F, 0.8430825345F, - 0.8443248294F, 0.8455614974F, 0.8467925323F, 0.8480179285F, - 0.8492376802F, 0.8504517822F, 0.8516602292F, 0.8528630164F, - 0.8540601391F, 0.8552515928F, 0.8564373733F, 0.8576174766F, - 0.8587918990F, 0.8599606368F, 0.8611236868F, 0.8622810460F, - 0.8634327113F, 0.8645786802F, 0.8657189504F, 0.8668535195F, - 0.8679823857F, 0.8691055472F, 0.8702230025F, 0.8713347503F, - 0.8724407896F, 0.8735411194F, 0.8746357394F, 0.8757246489F, - 0.8768078479F, 0.8778853364F, 0.8789571146F, 0.8800231832F, - 0.8810835427F, 0.8821381942F, 0.8831871387F, 0.8842303777F, - 0.8852679127F, 0.8862997456F, 0.8873258784F, 0.8883463132F, - 0.8893610527F, 0.8903700994F, 0.8913734562F, 0.8923711263F, - 0.8933631129F, 0.8943494196F, 0.8953300500F, 0.8963050083F, - 0.8972742985F, 0.8982379249F, 0.8991958922F, 0.9001482052F, - 0.9010948688F, 0.9020358883F, 0.9029712690F, 0.9039010165F, - 0.9048251367F, 0.9057436357F, 0.9066565195F, 0.9075637946F, - 0.9084654678F, 0.9093615456F, 0.9102520353F, 0.9111369440F, - 0.9120162792F, 0.9128900484F, 0.9137582595F, 0.9146209204F, - 0.9154780394F, 0.9163296248F, 0.9171756853F, 0.9180162296F, - 0.9188512667F, 0.9196808057F, 0.9205048559F, 0.9213234270F, - 0.9221365285F, 0.9229441704F, 0.9237463629F, 0.9245431160F, - 0.9253344404F, 0.9261203465F, 0.9269008453F, 0.9276759477F, - 0.9284456648F, 0.9292100080F, 0.9299689889F, 0.9307226190F, - 0.9314709103F, 0.9322138747F, 0.9329515245F, 0.9336838721F, - 0.9344109300F, 0.9351327108F, 0.9358492275F, 0.9365604931F, - 0.9372665208F, 0.9379673239F, 0.9386629160F, 0.9393533107F, - 0.9400385220F, 0.9407185637F, 0.9413934501F, 0.9420631954F, - 0.9427278141F, 0.9433873208F, 0.9440417304F, 0.9446910576F, - 0.9453353176F, 0.9459745255F, 0.9466086968F, 0.9472378469F, - 0.9478619915F, 0.9484811463F, 0.9490953274F, 0.9497045506F, - 0.9503088323F, 0.9509081888F, 0.9515026365F, 0.9520921921F, - 0.9526768723F, 0.9532566940F, 0.9538316742F, 0.9544018300F, - 0.9549671786F, 0.9555277375F, 0.9560835241F, 0.9566345562F, - 0.9571808513F, 0.9577224275F, 0.9582593027F, 0.9587914949F, - 0.9593190225F, 0.9598419038F, 0.9603601571F, 0.9608738012F, - 0.9613828546F, 0.9618873361F, 0.9623872646F, 0.9628826591F, - 0.9633735388F, 0.9638599227F, 0.9643418303F, 0.9648192808F, - 0.9652922939F, 0.9657608890F, 0.9662250860F, 0.9666849046F, - 0.9671403646F, 0.9675914861F, 0.9680382891F, 0.9684807937F, - 0.9689190202F, 0.9693529890F, 0.9697827203F, 0.9702082347F, - 0.9706295529F, 0.9710466953F, 0.9714596828F, 0.9718685362F, - 0.9722732762F, 0.9726739240F, 0.9730705005F, 0.9734630267F, - 0.9738515239F, 0.9742360134F, 0.9746165163F, 0.9749930540F, - 0.9753656481F, 0.9757343198F, 0.9760990909F, 0.9764599829F, - 0.9768170175F, 0.9771702164F, 0.9775196013F, 0.9778651941F, - 0.9782070167F, 0.9785450909F, 0.9788794388F, 0.9792100824F, - 0.9795370437F, 0.9798603449F, 0.9801800080F, 0.9804960554F, - 0.9808085092F, 0.9811173916F, 0.9814227251F, 0.9817245318F, - 0.9820228343F, 0.9823176549F, 0.9826090160F, 0.9828969402F, - 0.9831814498F, 0.9834625674F, 0.9837403156F, 0.9840147169F, - 0.9842857939F, 0.9845535692F, 0.9848180654F, 0.9850793052F, - 0.9853373113F, 0.9855921062F, 0.9858437127F, 0.9860921535F, - 0.9863374512F, 0.9865796287F, 0.9868187085F, 0.9870547136F, - 0.9872876664F, 0.9875175899F, 0.9877445067F, 0.9879684396F, - 0.9881894112F, 0.9884074444F, 0.9886225619F, 0.9888347863F, - 0.9890441404F, 0.9892506468F, 0.9894543284F, 0.9896552077F, - 0.9898533074F, 0.9900486502F, 0.9902412587F, 0.9904311555F, - 0.9906183633F, 0.9908029045F, 0.9909848019F, 0.9911640779F, - 0.9913407550F, 0.9915148557F, 0.9916864025F, 0.9918554179F, - 0.9920219241F, 0.9921859437F, 0.9923474989F, 0.9925066120F, - 0.9926633054F, 0.9928176012F, 0.9929695218F, 0.9931190891F, - 0.9932663254F, 0.9934112527F, 0.9935538932F, 0.9936942686F, - 0.9938324012F, 0.9939683126F, 0.9941020248F, 0.9942335597F, - 0.9943629388F, 0.9944901841F, 0.9946153170F, 0.9947383593F, - 0.9948593325F, 0.9949782579F, 0.9950951572F, 0.9952100516F, - 0.9953229625F, 0.9954339111F, 0.9955429186F, 0.9956500062F, - 0.9957551948F, 0.9958585056F, 0.9959599593F, 0.9960595769F, - 0.9961573792F, 0.9962533869F, 0.9963476206F, 0.9964401009F, - 0.9965308483F, 0.9966198833F, 0.9967072261F, 0.9967928971F, - 0.9968769164F, 0.9969593041F, 0.9970400804F, 0.9971192651F, - 0.9971968781F, 0.9972729391F, 0.9973474680F, 0.9974204842F, - 0.9974920074F, 0.9975620569F, 0.9976306521F, 0.9976978122F, - 0.9977635565F, 0.9978279039F, 0.9978908736F, 0.9979524842F, - 0.9980127547F, 0.9980717037F, 0.9981293499F, 0.9981857116F, - 0.9982408073F, 0.9982946554F, 0.9983472739F, 0.9983986810F, - 0.9984488947F, 0.9984979328F, 0.9985458132F, 0.9985925534F, - 0.9986381711F, 0.9986826838F, 0.9987261086F, 0.9987684630F, - 0.9988097640F, 0.9988500286F, 0.9988892738F, 0.9989275163F, - 0.9989647727F, 0.9990010597F, 0.9990363938F, 0.9990707911F, - 0.9991042679F, 0.9991368404F, 0.9991685244F, 0.9991993358F, - 0.9992292905F, 0.9992584038F, 0.9992866914F, 0.9993141686F, - 0.9993408506F, 0.9993667526F, 0.9993918895F, 0.9994162761F, - 0.9994399273F, 0.9994628576F, 0.9994850815F, 0.9995066133F, - 0.9995274672F, 0.9995476574F, 0.9995671978F, 0.9995861021F, - 0.9996043841F, 0.9996220573F, 0.9996391352F, 0.9996556310F, - 0.9996715579F, 0.9996869288F, 0.9997017568F, 0.9997160543F, - 0.9997298342F, 0.9997431088F, 0.9997558905F, 0.9997681914F, - 0.9997800236F, 0.9997913990F, 0.9998023292F, 0.9998128261F, - 0.9998229009F, 0.9998325650F, 0.9998418296F, 0.9998507058F, - 0.9998592044F, 0.9998673362F, 0.9998751117F, 0.9998825415F, - 0.9998896358F, 0.9998964047F, 0.9999028584F, 0.9999090066F, - 0.9999148590F, 0.9999204253F, 0.9999257148F, 0.9999307368F, - 0.9999355003F, 0.9999400144F, 0.9999442878F, 0.9999483293F, - 0.9999521472F, 0.9999557499F, 0.9999591457F, 0.9999623426F, - 0.9999653483F, 0.9999681708F, 0.9999708175F, 0.9999732959F, - 0.9999756132F, 0.9999777765F, 0.9999797928F, 0.9999816688F, - 0.9999834113F, 0.9999850266F, 0.9999865211F, 0.9999879009F, - 0.9999891721F, 0.9999903405F, 0.9999914118F, 0.9999923914F, - 0.9999932849F, 0.9999940972F, 0.9999948336F, 0.9999954989F, - 0.9999960978F, 0.9999966349F, 0.9999971146F, 0.9999975411F, - 0.9999979185F, 0.9999982507F, 0.9999985414F, 0.9999987944F, - 0.9999990129F, 0.9999992003F, 0.9999993596F, 0.9999994939F, - 0.9999996059F, 0.9999996981F, 0.9999997732F, 0.9999998333F, - 0.9999998805F, 0.9999999170F, 0.9999999444F, 0.9999999643F, - 0.9999999784F, 0.9999999878F, 0.9999999937F, 0.9999999972F, - 0.9999999990F, 0.9999999997F, 1.0000000000F, 1.0000000000F, +DECLARE_ALIGNED(16, static const float, vwin512)[256] = { + 0.0000147849F, 0.0001330607F, 0.0003695946F, 0.0007243509F, + 0.0011972759F, 0.0017882983F, 0.0024973285F, 0.0033242588F, + 0.0042689632F, 0.0053312973F, 0.0065110982F, 0.0078081841F, + 0.0092223540F, 0.0107533880F, 0.0124010466F, 0.0141650703F, + 0.0160451800F, 0.0180410758F, 0.0201524373F, 0.0223789233F, + 0.0247201710F, 0.0271757958F, 0.0297453914F, 0.0324285286F, + 0.0352247556F, 0.0381335972F, 0.0411545545F, 0.0442871045F, + 0.0475306997F, 0.0508847676F, 0.0543487103F, 0.0579219038F, + 0.0616036982F, 0.0653934164F, 0.0692903546F, 0.0732937809F, + 0.0774029356F, 0.0816170305F, 0.0859352485F, 0.0903567428F, + 0.0948806375F, 0.0995060259F, 0.1042319712F, 0.1090575056F, + 0.1139816300F, 0.1190033137F, 0.1241214941F, 0.1293350764F, + 0.1346429333F, 0.1400439046F, 0.1455367974F, 0.1511203852F, + 0.1567934083F, 0.1625545735F, 0.1684025537F, 0.1743359881F, + 0.1803534820F, 0.1864536069F, 0.1926349000F, 0.1988958650F, + 0.2052349715F, 0.2116506555F, 0.2181413191F, 0.2247053313F, + 0.2313410275F, 0.2380467105F, 0.2448206500F, 0.2516610835F, + 0.2585662164F, 0.2655342226F, 0.2725632448F, 0.2796513950F, + 0.2867967551F, 0.2939973773F, 0.3012512852F, 0.3085564739F, + 0.3159109111F, 0.3233125375F, 0.3307592680F, 0.3382489922F, + 0.3457795756F, 0.3533488602F, 0.3609546657F, 0.3685947904F, + 0.3762670121F, 0.3839690896F, 0.3916987634F, 0.3994537572F, + 0.4072317788F, 0.4150305215F, 0.4228476653F, 0.4306808783F, + 0.4385278181F, 0.4463861329F, 0.4542534630F, 0.4621274424F, + 0.4700057001F, 0.4778858615F, 0.4857655502F, 0.4936423891F, + 0.5015140023F, 0.5093780165F, 0.5172320626F, 0.5250737772F, + 0.5329008043F, 0.5407107971F, 0.5485014192F, 0.5562703465F, + 0.5640152688F, 0.5717338914F, 0.5794239366F, 0.5870831457F, + 0.5947092801F, 0.6023001235F, 0.6098534829F, 0.6173671907F, + 0.6248391059F, 0.6322671161F, 0.6396491384F, 0.6469831217F, + 0.6542670475F, 0.6614989319F, 0.6686768267F, 0.6757988210F, + 0.6828630426F, 0.6898676592F, 0.6968108799F, 0.7036909564F, + 0.7105061843F, 0.7172549043F, 0.7239355032F, 0.7305464154F, + 0.7370861235F, 0.7435531598F, 0.7499461068F, 0.7562635986F, + 0.7625043214F, 0.7686670148F, 0.7747504721F, 0.7807535410F, + 0.7866751247F, 0.7925141825F, 0.7982697296F, 0.8039408387F, + 0.8095266395F, 0.8150263196F, 0.8204391248F, 0.8257643590F, + 0.8310013848F, 0.8361496236F, 0.8412085555F, 0.8461777194F, + 0.8510567129F, 0.8558451924F, 0.8605428730F, 0.8651495278F, + 0.8696649882F, 0.8740891432F, 0.8784219392F, 0.8826633797F, + 0.8868135244F, 0.8908724888F, 0.8948404441F, 0.8987176157F, + 0.9025042831F, 0.9062007791F, 0.9098074886F, 0.9133248482F, + 0.9167533451F, 0.9200935163F, 0.9233459472F, 0.9265112712F, + 0.9295901680F, 0.9325833632F, 0.9354916263F, 0.9383157705F, + 0.9410566504F, 0.9437151618F, 0.9462922398F, 0.9487888576F, + 0.9512060252F, 0.9535447882F, 0.9558062262F, 0.9579914516F, + 0.9601016078F, 0.9621378683F, 0.9641014348F, 0.9659935361F, + 0.9678154261F, 0.9695683830F, 0.9712537071F, 0.9728727198F, + 0.9744267618F, 0.9759171916F, 0.9773453842F, 0.9787127293F, + 0.9800206298F, 0.9812705006F, 0.9824637665F, 0.9836018613F, + 0.9846862258F, 0.9857183066F, 0.9866995544F, 0.9876314227F, + 0.9885153662F, 0.9893528393F, 0.9901452948F, 0.9908941823F, + 0.9916009470F, 0.9922670279F, 0.9928938570F, 0.9934828574F, + 0.9940354423F, 0.9945530133F, 0.9950369595F, 0.9954886562F, + 0.9959094633F, 0.9963007242F, 0.9966637649F, 0.9969998925F, + 0.9973103939F, 0.9975965351F, 0.9978595598F, 0.9981006885F, + 0.9983211172F, 0.9985220166F, 0.9987045311F, 0.9988697776F, + 0.9990188449F, 0.9991527924F, 0.9992726499F, 0.9993794157F, + 0.9994740570F, 0.9995575079F, 0.9996306699F, 0.9996944099F, + 0.9997495605F, 0.9997969190F, 0.9998372465F, 0.9998712678F, + 0.9998996704F, 0.9999231041F, 0.9999421807F, 0.9999574732F, + 0.9999695157F, 0.9999788026F, 0.9999857885F, 0.9999908879F, + 0.9999944746F, 0.9999968817F, 0.9999984010F, 0.9999992833F, + 0.9999997377F, 0.9999999317F, 0.9999999911F, 0.9999999999F, }; -DECLARE_ALIGNED_16(static const float, vwin4096[2048]) = { - 0.0000002310F, 0.0000020791F, 0.0000057754F, 0.0000113197F, - 0.0000187121F, 0.0000279526F, 0.0000390412F, 0.0000519777F, - 0.0000667623F, 0.0000833949F, 0.0001018753F, 0.0001222036F, - 0.0001443798F, 0.0001684037F, 0.0001942754F, 0.0002219947F, - 0.0002515616F, 0.0002829761F, 0.0003162380F, 0.0003513472F, - 0.0003883038F, 0.0004271076F, 0.0004677584F, 0.0005102563F, - 0.0005546011F, 0.0006007928F, 0.0006488311F, 0.0006987160F, - 0.0007504474F, 0.0008040251F, 0.0008594490F, 0.0009167191F, - 0.0009758351F, 0.0010367969F, 0.0010996044F, 0.0011642574F, - 0.0012307558F, 0.0012990994F, 0.0013692880F, 0.0014413216F, - 0.0015151998F, 0.0015909226F, 0.0016684898F, 0.0017479011F, - 0.0018291565F, 0.0019122556F, 0.0019971983F, 0.0020839845F, - 0.0021726138F, 0.0022630861F, 0.0023554012F, 0.0024495588F, - 0.0025455588F, 0.0026434008F, 0.0027430847F, 0.0028446103F, - 0.0029479772F, 0.0030531853F, 0.0031602342F, 0.0032691238F, - 0.0033798538F, 0.0034924239F, 0.0036068338F, 0.0037230833F, - 0.0038411721F, 0.0039610999F, 0.0040828664F, 0.0042064714F, - 0.0043319145F, 0.0044591954F, 0.0045883139F, 0.0047192696F, - 0.0048520622F, 0.0049866914F, 0.0051231569F, 0.0052614583F, - 0.0054015953F, 0.0055435676F, 0.0056873748F, 0.0058330166F, - 0.0059804926F, 0.0061298026F, 0.0062809460F, 0.0064339226F, - 0.0065887320F, 0.0067453738F, 0.0069038476F, 0.0070641531F, - 0.0072262899F, 0.0073902575F, 0.0075560556F, 0.0077236838F, - 0.0078931417F, 0.0080644288F, 0.0082375447F, 0.0084124891F, - 0.0085892615F, 0.0087678614F, 0.0089482885F, 0.0091305422F, - 0.0093146223F, 0.0095005281F, 0.0096882592F, 0.0098778153F, - 0.0100691958F, 0.0102624002F, 0.0104574281F, 0.0106542791F, - 0.0108529525F, 0.0110534480F, 0.0112557651F, 0.0114599032F, - 0.0116658618F, 0.0118736405F, 0.0120832387F, 0.0122946560F, - 0.0125078917F, 0.0127229454F, 0.0129398166F, 0.0131585046F, - 0.0133790090F, 0.0136013292F, 0.0138254647F, 0.0140514149F, - 0.0142791792F, 0.0145087572F, 0.0147401481F, 0.0149733515F, - 0.0152083667F, 0.0154451932F, 0.0156838304F, 0.0159242777F, - 0.0161665345F, 0.0164106001F, 0.0166564741F, 0.0169041557F, - 0.0171536443F, 0.0174049393F, 0.0176580401F, 0.0179129461F, - 0.0181696565F, 0.0184281708F, 0.0186884883F, 0.0189506084F, - 0.0192145303F, 0.0194802535F, 0.0197477772F, 0.0200171008F, - 0.0202882236F, 0.0205611449F, 0.0208358639F, 0.0211123801F, - 0.0213906927F, 0.0216708011F, 0.0219527043F, 0.0222364019F, - 0.0225218930F, 0.0228091769F, 0.0230982529F, 0.0233891203F, - 0.0236817782F, 0.0239762259F, 0.0242724628F, 0.0245704880F, - 0.0248703007F, 0.0251719002F, 0.0254752858F, 0.0257804565F, - 0.0260874117F, 0.0263961506F, 0.0267066722F, 0.0270189760F, - 0.0273330609F, 0.0276489263F, 0.0279665712F, 0.0282859949F, - 0.0286071966F, 0.0289301753F, 0.0292549303F, 0.0295814607F, - 0.0299097656F, 0.0302398442F, 0.0305716957F, 0.0309053191F, - 0.0312407135F, 0.0315778782F, 0.0319168122F, 0.0322575145F, - 0.0325999844F, 0.0329442209F, 0.0332902231F, 0.0336379900F, - 0.0339875208F, 0.0343388146F, 0.0346918703F, 0.0350466871F, - 0.0354032640F, 0.0357616000F, 0.0361216943F, 0.0364835458F, - 0.0368471535F, 0.0372125166F, 0.0375796339F, 0.0379485046F, - 0.0383191276F, 0.0386915020F, 0.0390656267F, 0.0394415008F, - 0.0398191231F, 0.0401984927F, 0.0405796086F, 0.0409624698F, - 0.0413470751F, 0.0417334235F, 0.0421215141F, 0.0425113457F, - 0.0429029172F, 0.0432962277F, 0.0436912760F, 0.0440880610F, - 0.0444865817F, 0.0448868370F, 0.0452888257F, 0.0456925468F, - 0.0460979992F, 0.0465051816F, 0.0469140931F, 0.0473247325F, - 0.0477370986F, 0.0481511902F, 0.0485670064F, 0.0489845458F, - 0.0494038074F, 0.0498247899F, 0.0502474922F, 0.0506719131F, - 0.0510980514F, 0.0515259060F, 0.0519554756F, 0.0523867590F, - 0.0528197550F, 0.0532544624F, 0.0536908800F, 0.0541290066F, - 0.0545688408F, 0.0550103815F, 0.0554536274F, 0.0558985772F, - 0.0563452297F, 0.0567935837F, 0.0572436377F, 0.0576953907F, - 0.0581488412F, 0.0586039880F, 0.0590608297F, 0.0595193651F, - 0.0599795929F, 0.0604415117F, 0.0609051202F, 0.0613704170F, - 0.0618374009F, 0.0623060704F, 0.0627764243F, 0.0632484611F, - 0.0637221795F, 0.0641975781F, 0.0646746555F, 0.0651534104F, - 0.0656338413F, 0.0661159469F, 0.0665997257F, 0.0670851763F, - 0.0675722973F, 0.0680610873F, 0.0685515448F, 0.0690436684F, - 0.0695374567F, 0.0700329081F, 0.0705300213F, 0.0710287947F, - 0.0715292269F, 0.0720313163F, 0.0725350616F, 0.0730404612F, - 0.0735475136F, 0.0740562172F, 0.0745665707F, 0.0750785723F, - 0.0755922207F, 0.0761075143F, 0.0766244515F, 0.0771430307F, - 0.0776632505F, 0.0781851092F, 0.0787086052F, 0.0792337371F, - 0.0797605032F, 0.0802889018F, 0.0808189315F, 0.0813505905F, - 0.0818838773F, 0.0824187903F, 0.0829553277F, 0.0834934881F, - 0.0840332697F, 0.0845746708F, 0.0851176899F, 0.0856623252F, - 0.0862085751F, 0.0867564379F, 0.0873059119F, 0.0878569954F, - 0.0884096867F, 0.0889639840F, 0.0895198858F, 0.0900773902F, - 0.0906364955F, 0.0911972000F, 0.0917595019F, 0.0923233995F, - 0.0928888909F, 0.0934559745F, 0.0940246485F, 0.0945949110F, - 0.0951667604F, 0.0957401946F, 0.0963152121F, 0.0968918109F, - 0.0974699893F, 0.0980497454F, 0.0986310773F, 0.0992139832F, - 0.0997984614F, 0.1003845098F, 0.1009721267F, 0.1015613101F, - 0.1021520582F, 0.1027443692F, 0.1033382410F, 0.1039336718F, - 0.1045306597F, 0.1051292027F, 0.1057292990F, 0.1063309466F, - 0.1069341435F, 0.1075388878F, 0.1081451776F, 0.1087530108F, - 0.1093623856F, 0.1099732998F, 0.1105857516F, 0.1111997389F, - 0.1118152597F, 0.1124323121F, 0.1130508939F, 0.1136710032F, - 0.1142926379F, 0.1149157960F, 0.1155404755F, 0.1161666742F, - 0.1167943901F, 0.1174236211F, 0.1180543652F, 0.1186866202F, - 0.1193203841F, 0.1199556548F, 0.1205924300F, 0.1212307078F, - 0.1218704860F, 0.1225117624F, 0.1231545349F, 0.1237988013F, - 0.1244445596F, 0.1250918074F, 0.1257405427F, 0.1263907632F, - 0.1270424667F, 0.1276956512F, 0.1283503142F, 0.1290064537F, - 0.1296640674F, 0.1303231530F, 0.1309837084F, 0.1316457312F, - 0.1323092193F, 0.1329741703F, 0.1336405820F, 0.1343084520F, - 0.1349777782F, 0.1356485582F, 0.1363207897F, 0.1369944704F, - 0.1376695979F, 0.1383461700F, 0.1390241842F, 0.1397036384F, - 0.1403845300F, 0.1410668567F, 0.1417506162F, 0.1424358061F, - 0.1431224240F, 0.1438104674F, 0.1444999341F, 0.1451908216F, - 0.1458831274F, 0.1465768492F, 0.1472719844F, 0.1479685308F, - 0.1486664857F, 0.1493658468F, 0.1500666115F, 0.1507687775F, - 0.1514723422F, 0.1521773031F, 0.1528836577F, 0.1535914035F, - 0.1543005380F, 0.1550110587F, 0.1557229631F, 0.1564362485F, - 0.1571509124F, 0.1578669524F, 0.1585843657F, 0.1593031499F, - 0.1600233024F, 0.1607448205F, 0.1614677017F, 0.1621919433F, - 0.1629175428F, 0.1636444975F, 0.1643728047F, 0.1651024619F, - 0.1658334665F, 0.1665658156F, 0.1672995067F, 0.1680345371F, - 0.1687709041F, 0.1695086050F, 0.1702476372F, 0.1709879978F, - 0.1717296843F, 0.1724726938F, 0.1732170237F, 0.1739626711F, - 0.1747096335F, 0.1754579079F, 0.1762074916F, 0.1769583819F, - 0.1777105760F, 0.1784640710F, 0.1792188642F, 0.1799749529F, - 0.1807323340F, 0.1814910049F, 0.1822509628F, 0.1830122046F, - 0.1837747277F, 0.1845385292F, 0.1853036062F, 0.1860699558F, - 0.1868375751F, 0.1876064613F, 0.1883766114F, 0.1891480226F, - 0.1899206919F, 0.1906946164F, 0.1914697932F, 0.1922462194F, - 0.1930238919F, 0.1938028079F, 0.1945829643F, 0.1953643583F, - 0.1961469868F, 0.1969308468F, 0.1977159353F, 0.1985022494F, - 0.1992897859F, 0.2000785420F, 0.2008685145F, 0.2016597005F, - 0.2024520968F, 0.2032457005F, 0.2040405084F, 0.2048365175F, - 0.2056337247F, 0.2064321269F, 0.2072317211F, 0.2080325041F, - 0.2088344727F, 0.2096376240F, 0.2104419547F, 0.2112474618F, - 0.2120541420F, 0.2128619923F, 0.2136710094F, 0.2144811902F, - 0.2152925315F, 0.2161050301F, 0.2169186829F, 0.2177334866F, - 0.2185494381F, 0.2193665340F, 0.2201847712F, 0.2210041465F, - 0.2218246565F, 0.2226462981F, 0.2234690680F, 0.2242929629F, - 0.2251179796F, 0.2259441147F, 0.2267713650F, 0.2275997272F, - 0.2284291979F, 0.2292597739F, 0.2300914518F, 0.2309242283F, - 0.2317581001F, 0.2325930638F, 0.2334291160F, 0.2342662534F, - 0.2351044727F, 0.2359437703F, 0.2367841431F, 0.2376255875F, - 0.2384681001F, 0.2393116776F, 0.2401563165F, 0.2410020134F, - 0.2418487649F, 0.2426965675F, 0.2435454178F, 0.2443953122F, - 0.2452462474F, 0.2460982199F, 0.2469512262F, 0.2478052628F, - 0.2486603262F, 0.2495164129F, 0.2503735194F, 0.2512316421F, - 0.2520907776F, 0.2529509222F, 0.2538120726F, 0.2546742250F, - 0.2555373760F, 0.2564015219F, 0.2572666593F, 0.2581327845F, - 0.2589998939F, 0.2598679840F, 0.2607370510F, 0.2616070916F, - 0.2624781019F, 0.2633500783F, 0.2642230173F, 0.2650969152F, - 0.2659717684F, 0.2668475731F, 0.2677243257F, 0.2686020226F, - 0.2694806601F, 0.2703602344F, 0.2712407419F, 0.2721221789F, - 0.2730045417F, 0.2738878265F, 0.2747720297F, 0.2756571474F, - 0.2765431760F, 0.2774301117F, 0.2783179508F, 0.2792066895F, - 0.2800963240F, 0.2809868505F, 0.2818782654F, 0.2827705647F, - 0.2836637447F, 0.2845578016F, 0.2854527315F, 0.2863485307F, - 0.2872451953F, 0.2881427215F, 0.2890411055F, 0.2899403433F, - 0.2908404312F, 0.2917413654F, 0.2926431418F, 0.2935457567F, - 0.2944492061F, 0.2953534863F, 0.2962585932F, 0.2971645230F, - 0.2980712717F, 0.2989788356F, 0.2998872105F, 0.3007963927F, - 0.3017063781F, 0.3026171629F, 0.3035287430F, 0.3044411145F, - 0.3053542736F, 0.3062682161F, 0.3071829381F, 0.3080984356F, - 0.3090147047F, 0.3099317413F, 0.3108495414F, 0.3117681011F, - 0.3126874163F, 0.3136074830F, 0.3145282972F, 0.3154498548F, - 0.3163721517F, 0.3172951841F, 0.3182189477F, 0.3191434385F, - 0.3200686525F, 0.3209945856F, 0.3219212336F, 0.3228485927F, - 0.3237766585F, 0.3247054271F, 0.3256348943F, 0.3265650560F, - 0.3274959081F, 0.3284274465F, 0.3293596671F, 0.3302925657F, - 0.3312261382F, 0.3321603804F, 0.3330952882F, 0.3340308574F, - 0.3349670838F, 0.3359039634F, 0.3368414919F, 0.3377796651F, - 0.3387184789F, 0.3396579290F, 0.3405980113F, 0.3415387216F, - 0.3424800556F, 0.3434220091F, 0.3443645779F, 0.3453077578F, - 0.3462515446F, 0.3471959340F, 0.3481409217F, 0.3490865036F, - 0.3500326754F, 0.3509794328F, 0.3519267715F, 0.3528746873F, - 0.3538231759F, 0.3547722330F, 0.3557218544F, 0.3566720357F, - 0.3576227727F, 0.3585740610F, 0.3595258964F, 0.3604782745F, - 0.3614311910F, 0.3623846417F, 0.3633386221F, 0.3642931280F, - 0.3652481549F, 0.3662036987F, 0.3671597548F, 0.3681163191F, - 0.3690733870F, 0.3700309544F, 0.3709890167F, 0.3719475696F, - 0.3729066089F, 0.3738661299F, 0.3748261285F, 0.3757866002F, - 0.3767475406F, 0.3777089453F, 0.3786708100F, 0.3796331302F, - 0.3805959014F, 0.3815591194F, 0.3825227796F, 0.3834868777F, - 0.3844514093F, 0.3854163698F, 0.3863817549F, 0.3873475601F, - 0.3883137810F, 0.3892804131F, 0.3902474521F, 0.3912148933F, - 0.3921827325F, 0.3931509650F, 0.3941195865F, 0.3950885925F, - 0.3960579785F, 0.3970277400F, 0.3979978725F, 0.3989683716F, - 0.3999392328F, 0.4009104516F, 0.4018820234F, 0.4028539438F, - 0.4038262084F, 0.4047988125F, 0.4057717516F, 0.4067450214F, - 0.4077186172F, 0.4086925345F, 0.4096667688F, 0.4106413155F, - 0.4116161703F, 0.4125913284F, 0.4135667854F, 0.4145425368F, - 0.4155185780F, 0.4164949044F, 0.4174715116F, 0.4184483949F, - 0.4194255498F, 0.4204029718F, 0.4213806563F, 0.4223585987F, - 0.4233367946F, 0.4243152392F, 0.4252939281F, 0.4262728566F, - 0.4272520202F, 0.4282314144F, 0.4292110345F, 0.4301908760F, - 0.4311709343F, 0.4321512047F, 0.4331316828F, 0.4341123639F, - 0.4350932435F, 0.4360743168F, 0.4370555794F, 0.4380370267F, - 0.4390186540F, 0.4400004567F, 0.4409824303F, 0.4419645701F, - 0.4429468716F, 0.4439293300F, 0.4449119409F, 0.4458946996F, - 0.4468776014F, 0.4478606418F, 0.4488438162F, 0.4498271199F, - 0.4508105483F, 0.4517940967F, 0.4527777607F, 0.4537615355F, - 0.4547454165F, 0.4557293991F, 0.4567134786F, 0.4576976505F, - 0.4586819101F, 0.4596662527F, 0.4606506738F, 0.4616351687F, - 0.4626197328F, 0.4636043614F, 0.4645890499F, 0.4655737936F, - 0.4665585880F, 0.4675434284F, 0.4685283101F, 0.4695132286F, - 0.4704981791F, 0.4714831570F, 0.4724681577F, 0.4734531766F, - 0.4744382089F, 0.4754232501F, 0.4764082956F, 0.4773933406F, - 0.4783783806F, 0.4793634108F, 0.4803484267F, 0.4813334237F, - 0.4823183969F, 0.4833033419F, 0.4842882540F, 0.4852731285F, - 0.4862579608F, 0.4872427462F, 0.4882274802F, 0.4892121580F, - 0.4901967751F, 0.4911813267F, 0.4921658083F, 0.4931502151F, - 0.4941345427F, 0.4951187863F, 0.4961029412F, 0.4970870029F, - 0.4980709667F, 0.4990548280F, 0.5000385822F, 0.5010222245F, - 0.5020057505F, 0.5029891553F, 0.5039724345F, 0.5049555834F, - 0.5059385973F, 0.5069214716F, 0.5079042018F, 0.5088867831F, - 0.5098692110F, 0.5108514808F, 0.5118335879F, 0.5128155277F, - 0.5137972956F, 0.5147788869F, 0.5157602971F, 0.5167415215F, - 0.5177225555F, 0.5187033945F, 0.5196840339F, 0.5206644692F, - 0.5216446956F, 0.5226247086F, 0.5236045035F, 0.5245840759F, - 0.5255634211F, 0.5265425344F, 0.5275214114F, 0.5285000474F, - 0.5294784378F, 0.5304565781F, 0.5314344637F, 0.5324120899F, - 0.5333894522F, 0.5343665461F, 0.5353433670F, 0.5363199102F, - 0.5372961713F, 0.5382721457F, 0.5392478287F, 0.5402232159F, - 0.5411983027F, 0.5421730845F, 0.5431475569F, 0.5441217151F, - 0.5450955548F, 0.5460690714F, 0.5470422602F, 0.5480151169F, - 0.5489876368F, 0.5499598155F, 0.5509316484F, 0.5519031310F, - 0.5528742587F, 0.5538450271F, 0.5548154317F, 0.5557854680F, - 0.5567551314F, 0.5577244174F, 0.5586933216F, 0.5596618395F, - 0.5606299665F, 0.5615976983F, 0.5625650302F, 0.5635319580F, - 0.5644984770F, 0.5654645828F, 0.5664302709F, 0.5673955370F, - 0.5683603765F, 0.5693247850F, 0.5702887580F, 0.5712522912F, - 0.5722153800F, 0.5731780200F, 0.5741402069F, 0.5751019362F, - 0.5760632034F, 0.5770240042F, 0.5779843341F, 0.5789441889F, - 0.5799035639F, 0.5808624549F, 0.5818208575F, 0.5827787673F, - 0.5837361800F, 0.5846930910F, 0.5856494961F, 0.5866053910F, - 0.5875607712F, 0.5885156324F, 0.5894699703F, 0.5904237804F, - 0.5913770586F, 0.5923298004F, 0.5932820016F, 0.5942336578F, - 0.5951847646F, 0.5961353179F, 0.5970853132F, 0.5980347464F, - 0.5989836131F, 0.5999319090F, 0.6008796298F, 0.6018267713F, - 0.6027733292F, 0.6037192993F, 0.6046646773F, 0.6056094589F, - 0.6065536400F, 0.6074972162F, 0.6084401833F, 0.6093825372F, - 0.6103242736F, 0.6112653884F, 0.6122058772F, 0.6131457359F, - 0.6140849604F, 0.6150235464F, 0.6159614897F, 0.6168987862F, - 0.6178354318F, 0.6187714223F, 0.6197067535F, 0.6206414213F, - 0.6215754215F, 0.6225087501F, 0.6234414028F, 0.6243733757F, - 0.6253046646F, 0.6262352654F, 0.6271651739F, 0.6280943862F, - 0.6290228982F, 0.6299507057F, 0.6308778048F, 0.6318041913F, - 0.6327298612F, 0.6336548105F, 0.6345790352F, 0.6355025312F, - 0.6364252945F, 0.6373473211F, 0.6382686070F, 0.6391891483F, - 0.6401089409F, 0.6410279808F, 0.6419462642F, 0.6428637869F, - 0.6437805452F, 0.6446965350F, 0.6456117524F, 0.6465261935F, - 0.6474398544F, 0.6483527311F, 0.6492648197F, 0.6501761165F, - 0.6510866174F, 0.6519963186F, 0.6529052162F, 0.6538133064F, - 0.6547205854F, 0.6556270492F, 0.6565326941F, 0.6574375162F, - 0.6583415117F, 0.6592446769F, 0.6601470079F, 0.6610485009F, - 0.6619491521F, 0.6628489578F, 0.6637479143F, 0.6646460177F, - 0.6655432643F, 0.6664396505F, 0.6673351724F, 0.6682298264F, - 0.6691236087F, 0.6700165157F, 0.6709085436F, 0.6717996889F, - 0.6726899478F, 0.6735793167F, 0.6744677918F, 0.6753553697F, - 0.6762420466F, 0.6771278190F, 0.6780126832F, 0.6788966357F, - 0.6797796728F, 0.6806617909F, 0.6815429866F, 0.6824232562F, - 0.6833025961F, 0.6841810030F, 0.6850584731F, 0.6859350031F, - 0.6868105894F, 0.6876852284F, 0.6885589168F, 0.6894316510F, - 0.6903034275F, 0.6911742430F, 0.6920440939F, 0.6929129769F, - 0.6937808884F, 0.6946478251F, 0.6955137837F, 0.6963787606F, - 0.6972427525F, 0.6981057560F, 0.6989677678F, 0.6998287845F, - 0.7006888028F, 0.7015478194F, 0.7024058309F, 0.7032628340F, - 0.7041188254F, 0.7049738019F, 0.7058277601F, 0.7066806969F, - 0.7075326089F, 0.7083834929F, 0.7092333457F, 0.7100821640F, - 0.7109299447F, 0.7117766846F, 0.7126223804F, 0.7134670291F, - 0.7143106273F, 0.7151531721F, 0.7159946602F, 0.7168350885F, - 0.7176744539F, 0.7185127534F, 0.7193499837F, 0.7201861418F, - 0.7210212247F, 0.7218552293F, 0.7226881526F, 0.7235199914F, - 0.7243507428F, 0.7251804039F, 0.7260089715F, 0.7268364426F, - 0.7276628144F, 0.7284880839F, 0.7293122481F, 0.7301353040F, - 0.7309572487F, 0.7317780794F, 0.7325977930F, 0.7334163868F, - 0.7342338579F, 0.7350502033F, 0.7358654202F, 0.7366795059F, - 0.7374924573F, 0.7383042718F, 0.7391149465F, 0.7399244787F, - 0.7407328655F, 0.7415401041F, 0.7423461920F, 0.7431511261F, - 0.7439549040F, 0.7447575227F, 0.7455589797F, 0.7463592723F, - 0.7471583976F, 0.7479563532F, 0.7487531363F, 0.7495487443F, - 0.7503431745F, 0.7511364244F, 0.7519284913F, 0.7527193726F, - 0.7535090658F, 0.7542975683F, 0.7550848776F, 0.7558709910F, - 0.7566559062F, 0.7574396205F, 0.7582221314F, 0.7590034366F, - 0.7597835334F, 0.7605624194F, 0.7613400923F, 0.7621165495F, - 0.7628917886F, 0.7636658072F, 0.7644386030F, 0.7652101735F, - 0.7659805164F, 0.7667496292F, 0.7675175098F, 0.7682841556F, - 0.7690495645F, 0.7698137341F, 0.7705766622F, 0.7713383463F, - 0.7720987844F, 0.7728579741F, 0.7736159132F, 0.7743725994F, - 0.7751280306F, 0.7758822046F, 0.7766351192F, 0.7773867722F, - 0.7781371614F, 0.7788862848F, 0.7796341401F, 0.7803807253F, - 0.7811260383F, 0.7818700769F, 0.7826128392F, 0.7833543230F, - 0.7840945263F, 0.7848334471F, 0.7855710833F, 0.7863074330F, - 0.7870424941F, 0.7877762647F, 0.7885087428F, 0.7892399264F, - 0.7899698137F, 0.7906984026F, 0.7914256914F, 0.7921516780F, - 0.7928763607F, 0.7935997375F, 0.7943218065F, 0.7950425661F, - 0.7957620142F, 0.7964801492F, 0.7971969692F, 0.7979124724F, - 0.7986266570F, 0.7993395214F, 0.8000510638F, 0.8007612823F, - 0.8014701754F, 0.8021777413F, 0.8028839784F, 0.8035888849F, - 0.8042924592F, 0.8049946997F, 0.8056956048F, 0.8063951727F, - 0.8070934020F, 0.8077902910F, 0.8084858381F, 0.8091800419F, - 0.8098729007F, 0.8105644130F, 0.8112545774F, 0.8119433922F, - 0.8126308561F, 0.8133169676F, 0.8140017251F, 0.8146851272F, - 0.8153671726F, 0.8160478598F, 0.8167271874F, 0.8174051539F, - 0.8180817582F, 0.8187569986F, 0.8194308741F, 0.8201033831F, - 0.8207745244F, 0.8214442966F, 0.8221126986F, 0.8227797290F, - 0.8234453865F, 0.8241096700F, 0.8247725781F, 0.8254341097F, - 0.8260942636F, 0.8267530385F, 0.8274104334F, 0.8280664470F, - 0.8287210782F, 0.8293743259F, 0.8300261889F, 0.8306766662F, - 0.8313257566F, 0.8319734591F, 0.8326197727F, 0.8332646963F, - 0.8339082288F, 0.8345503692F, 0.8351911167F, 0.8358304700F, - 0.8364684284F, 0.8371049907F, 0.8377401562F, 0.8383739238F, - 0.8390062927F, 0.8396372618F, 0.8402668305F, 0.8408949977F, - 0.8415217626F, 0.8421471245F, 0.8427710823F, 0.8433936354F, - 0.8440147830F, 0.8446345242F, 0.8452528582F, 0.8458697844F, - 0.8464853020F, 0.8470994102F, 0.8477121084F, 0.8483233958F, - 0.8489332718F, 0.8495417356F, 0.8501487866F, 0.8507544243F, - 0.8513586479F, 0.8519614568F, 0.8525628505F, 0.8531628283F, - 0.8537613897F, 0.8543585341F, 0.8549542611F, 0.8555485699F, - 0.8561414603F, 0.8567329315F, 0.8573229832F, 0.8579116149F, - 0.8584988262F, 0.8590846165F, 0.8596689855F, 0.8602519327F, - 0.8608334577F, 0.8614135603F, 0.8619922399F, 0.8625694962F, - 0.8631453289F, 0.8637197377F, 0.8642927222F, 0.8648642821F, - 0.8654344172F, 0.8660031272F, 0.8665704118F, 0.8671362708F, - 0.8677007039F, 0.8682637109F, 0.8688252917F, 0.8693854460F, - 0.8699441737F, 0.8705014745F, 0.8710573485F, 0.8716117953F, - 0.8721648150F, 0.8727164073F, 0.8732665723F, 0.8738153098F, - 0.8743626197F, 0.8749085021F, 0.8754529569F, 0.8759959840F, - 0.8765375835F, 0.8770777553F, 0.8776164996F, 0.8781538162F, - 0.8786897054F, 0.8792241670F, 0.8797572013F, 0.8802888082F, - 0.8808189880F, 0.8813477407F, 0.8818750664F, 0.8824009653F, - 0.8829254375F, 0.8834484833F, 0.8839701028F, 0.8844902961F, - 0.8850090636F, 0.8855264054F, 0.8860423218F, 0.8865568131F, - 0.8870698794F, 0.8875815212F, 0.8880917386F, 0.8886005319F, - 0.8891079016F, 0.8896138479F, 0.8901183712F, 0.8906214719F, - 0.8911231503F, 0.8916234067F, 0.8921222417F, 0.8926196556F, - 0.8931156489F, 0.8936102219F, 0.8941033752F, 0.8945951092F, - 0.8950854244F, 0.8955743212F, 0.8960618003F, 0.8965478621F, - 0.8970325071F, 0.8975157359F, 0.8979975490F, 0.8984779471F, - 0.8989569307F, 0.8994345004F, 0.8999106568F, 0.9003854005F, - 0.9008587323F, 0.9013306526F, 0.9018011623F, 0.9022702619F, - 0.9027379521F, 0.9032042337F, 0.9036691074F, 0.9041325739F, - 0.9045946339F, 0.9050552882F, 0.9055145376F, 0.9059723828F, - 0.9064288246F, 0.9068838638F, 0.9073375013F, 0.9077897379F, - 0.9082405743F, 0.9086900115F, 0.9091380503F, 0.9095846917F, - 0.9100299364F, 0.9104737854F, 0.9109162397F, 0.9113573001F, - 0.9117969675F, 0.9122352430F, 0.9126721275F, 0.9131076219F, - 0.9135417273F, 0.9139744447F, 0.9144057750F, 0.9148357194F, - 0.9152642787F, 0.9156914542F, 0.9161172468F, 0.9165416576F, - 0.9169646877F, 0.9173863382F, 0.9178066102F, 0.9182255048F, - 0.9186430232F, 0.9190591665F, 0.9194739359F, 0.9198873324F, - 0.9202993574F, 0.9207100120F, 0.9211192973F, 0.9215272147F, - 0.9219337653F, 0.9223389504F, 0.9227427713F, 0.9231452290F, - 0.9235463251F, 0.9239460607F, 0.9243444371F, 0.9247414557F, - 0.9251371177F, 0.9255314245F, 0.9259243774F, 0.9263159778F, - 0.9267062270F, 0.9270951264F, 0.9274826774F, 0.9278688814F, - 0.9282537398F, 0.9286372540F, 0.9290194254F, 0.9294002555F, - 0.9297797458F, 0.9301578976F, 0.9305347125F, 0.9309101919F, - 0.9312843373F, 0.9316571503F, 0.9320286323F, 0.9323987849F, - 0.9327676097F, 0.9331351080F, 0.9335012816F, 0.9338661320F, - 0.9342296607F, 0.9345918694F, 0.9349527596F, 0.9353123330F, - 0.9356705911F, 0.9360275357F, 0.9363831683F, 0.9367374905F, - 0.9370905042F, 0.9374422108F, 0.9377926122F, 0.9381417099F, - 0.9384895057F, 0.9388360014F, 0.9391811985F, 0.9395250989F, - 0.9398677043F, 0.9402090165F, 0.9405490371F, 0.9408877680F, - 0.9412252110F, 0.9415613678F, 0.9418962402F, 0.9422298301F, - 0.9425621392F, 0.9428931695F, 0.9432229226F, 0.9435514005F, - 0.9438786050F, 0.9442045381F, 0.9445292014F, 0.9448525971F, - 0.9451747268F, 0.9454955926F, 0.9458151963F, 0.9461335399F, - 0.9464506253F, 0.9467664545F, 0.9470810293F, 0.9473943517F, - 0.9477064238F, 0.9480172474F, 0.9483268246F, 0.9486351573F, - 0.9489422475F, 0.9492480973F, 0.9495527087F, 0.9498560837F, - 0.9501582243F, 0.9504591325F, 0.9507588105F, 0.9510572603F, - 0.9513544839F, 0.9516504834F, 0.9519452609F, 0.9522388186F, - 0.9525311584F, 0.9528222826F, 0.9531121932F, 0.9534008923F, - 0.9536883821F, 0.9539746647F, 0.9542597424F, 0.9545436171F, - 0.9548262912F, 0.9551077667F, 0.9553880459F, 0.9556671309F, - 0.9559450239F, 0.9562217272F, 0.9564972429F, 0.9567715733F, - 0.9570447206F, 0.9573166871F, 0.9575874749F, 0.9578570863F, - 0.9581255236F, 0.9583927890F, 0.9586588849F, 0.9589238134F, - 0.9591875769F, 0.9594501777F, 0.9597116180F, 0.9599719003F, - 0.9602310267F, 0.9604889995F, 0.9607458213F, 0.9610014942F, - 0.9612560206F, 0.9615094028F, 0.9617616433F, 0.9620127443F, - 0.9622627083F, 0.9625115376F, 0.9627592345F, 0.9630058016F, - 0.9632512411F, 0.9634955555F, 0.9637387471F, 0.9639808185F, - 0.9642217720F, 0.9644616100F, 0.9647003349F, 0.9649379493F, - 0.9651744556F, 0.9654098561F, 0.9656441534F, 0.9658773499F, - 0.9661094480F, 0.9663404504F, 0.9665703593F, 0.9667991774F, - 0.9670269071F, 0.9672535509F, 0.9674791114F, 0.9677035909F, - 0.9679269921F, 0.9681493174F, 0.9683705694F, 0.9685907506F, - 0.9688098636F, 0.9690279108F, 0.9692448948F, 0.9694608182F, - 0.9696756836F, 0.9698894934F, 0.9701022503F, 0.9703139569F, - 0.9705246156F, 0.9707342291F, 0.9709428000F, 0.9711503309F, - 0.9713568243F, 0.9715622829F, 0.9717667093F, 0.9719701060F, - 0.9721724757F, 0.9723738210F, 0.9725741446F, 0.9727734490F, - 0.9729717369F, 0.9731690109F, 0.9733652737F, 0.9735605279F, - 0.9737547762F, 0.9739480212F, 0.9741402656F, 0.9743315120F, - 0.9745217631F, 0.9747110216F, 0.9748992901F, 0.9750865714F, - 0.9752728681F, 0.9754581829F, 0.9756425184F, 0.9758258775F, - 0.9760082627F, 0.9761896768F, 0.9763701224F, 0.9765496024F, - 0.9767281193F, 0.9769056760F, 0.9770822751F, 0.9772579193F, - 0.9774326114F, 0.9776063542F, 0.9777791502F, 0.9779510023F, - 0.9781219133F, 0.9782918858F, 0.9784609226F, 0.9786290264F, - 0.9787962000F, 0.9789624461F, 0.9791277676F, 0.9792921671F, - 0.9794556474F, 0.9796182113F, 0.9797798615F, 0.9799406009F, - 0.9801004321F, 0.9802593580F, 0.9804173813F, 0.9805745049F, - 0.9807307314F, 0.9808860637F, 0.9810405046F, 0.9811940568F, - 0.9813467232F, 0.9814985065F, 0.9816494095F, 0.9817994351F, - 0.9819485860F, 0.9820968650F, 0.9822442750F, 0.9823908186F, - 0.9825364988F, 0.9826813184F, 0.9828252801F, 0.9829683868F, - 0.9831106413F, 0.9832520463F, 0.9833926048F, 0.9835323195F, - 0.9836711932F, 0.9838092288F, 0.9839464291F, 0.9840827969F, - 0.9842183351F, 0.9843530464F, 0.9844869337F, 0.9846199998F, - 0.9847522475F, 0.9848836798F, 0.9850142993F, 0.9851441090F, - 0.9852731117F, 0.9854013101F, 0.9855287073F, 0.9856553058F, - 0.9857811087F, 0.9859061188F, 0.9860303388F, 0.9861537717F, - 0.9862764202F, 0.9863982872F, 0.9865193756F, 0.9866396882F, - 0.9867592277F, 0.9868779972F, 0.9869959993F, 0.9871132370F, - 0.9872297131F, 0.9873454304F, 0.9874603918F, 0.9875746001F, - 0.9876880581F, 0.9878007688F, 0.9879127348F, 0.9880239592F, - 0.9881344447F, 0.9882441941F, 0.9883532104F, 0.9884614962F, - 0.9885690546F, 0.9886758883F, 0.9887820001F, 0.9888873930F, - 0.9889920697F, 0.9890960331F, 0.9891992859F, 0.9893018312F, - 0.9894036716F, 0.9895048100F, 0.9896052493F, 0.9897049923F, - 0.9898040418F, 0.9899024006F, 0.9900000717F, 0.9900970577F, - 0.9901933616F, 0.9902889862F, 0.9903839343F, 0.9904782087F, - 0.9905718122F, 0.9906647477F, 0.9907570180F, 0.9908486259F, - 0.9909395742F, 0.9910298658F, 0.9911195034F, 0.9912084899F, - 0.9912968281F, 0.9913845208F, 0.9914715708F, 0.9915579810F, - 0.9916437540F, 0.9917288928F, 0.9918134001F, 0.9918972788F, - 0.9919805316F, 0.9920631613F, 0.9921451707F, 0.9922265626F, - 0.9923073399F, 0.9923875052F, 0.9924670615F, 0.9925460114F, - 0.9926243577F, 0.9927021033F, 0.9927792508F, 0.9928558032F, - 0.9929317631F, 0.9930071333F, 0.9930819167F, 0.9931561158F, - 0.9932297337F, 0.9933027728F, 0.9933752362F, 0.9934471264F, - 0.9935184462F, 0.9935891985F, 0.9936593859F, 0.9937290112F, - 0.9937980771F, 0.9938665864F, 0.9939345418F, 0.9940019460F, - 0.9940688018F, 0.9941351118F, 0.9942008789F, 0.9942661057F, - 0.9943307950F, 0.9943949494F, 0.9944585717F, 0.9945216645F, - 0.9945842307F, 0.9946462728F, 0.9947077936F, 0.9947687957F, - 0.9948292820F, 0.9948892550F, 0.9949487174F, 0.9950076719F, - 0.9950661212F, 0.9951240679F, 0.9951815148F, 0.9952384645F, - 0.9952949196F, 0.9953508828F, 0.9954063568F, 0.9954613442F, - 0.9955158476F, 0.9955698697F, 0.9956234132F, 0.9956764806F, - 0.9957290746F, 0.9957811978F, 0.9958328528F, 0.9958840423F, - 0.9959347688F, 0.9959850351F, 0.9960348435F, 0.9960841969F, - 0.9961330977F, 0.9961815486F, 0.9962295521F, 0.9962771108F, - 0.9963242274F, 0.9963709043F, 0.9964171441F, 0.9964629494F, - 0.9965083228F, 0.9965532668F, 0.9965977840F, 0.9966418768F, - 0.9966855479F, 0.9967287998F, 0.9967716350F, 0.9968140559F, - 0.9968560653F, 0.9968976655F, 0.9969388591F, 0.9969796485F, - 0.9970200363F, 0.9970600250F, 0.9970996170F, 0.9971388149F, - 0.9971776211F, 0.9972160380F, 0.9972540683F, 0.9972917142F, - 0.9973289783F, 0.9973658631F, 0.9974023709F, 0.9974385042F, - 0.9974742655F, 0.9975096571F, 0.9975446816F, 0.9975793413F, - 0.9976136386F, 0.9976475759F, 0.9976811557F, 0.9977143803F, - 0.9977472521F, 0.9977797736F, 0.9978119470F, 0.9978437748F, - 0.9978752593F, 0.9979064029F, 0.9979372079F, 0.9979676768F, - 0.9979978117F, 0.9980276151F, 0.9980570893F, 0.9980862367F, - 0.9981150595F, 0.9981435600F, 0.9981717406F, 0.9981996035F, - 0.9982271511F, 0.9982543856F, 0.9982813093F, 0.9983079246F, - 0.9983342336F, 0.9983602386F, 0.9983859418F, 0.9984113456F, - 0.9984364522F, 0.9984612638F, 0.9984857825F, 0.9985100108F, - 0.9985339507F, 0.9985576044F, 0.9985809743F, 0.9986040624F, - 0.9986268710F, 0.9986494022F, 0.9986716583F, 0.9986936413F, - 0.9987153535F, 0.9987367969F, 0.9987579738F, 0.9987788864F, - 0.9987995366F, 0.9988199267F, 0.9988400587F, 0.9988599348F, - 0.9988795572F, 0.9988989278F, 0.9989180487F, 0.9989369222F, - 0.9989555501F, 0.9989739347F, 0.9989920780F, 0.9990099820F, - 0.9990276487F, 0.9990450803F, 0.9990622787F, 0.9990792460F, - 0.9990959841F, 0.9991124952F, 0.9991287812F, 0.9991448440F, - 0.9991606858F, 0.9991763084F, 0.9991917139F, 0.9992069042F, - 0.9992218813F, 0.9992366471F, 0.9992512035F, 0.9992655525F, - 0.9992796961F, 0.9992936361F, 0.9993073744F, 0.9993209131F, - 0.9993342538F, 0.9993473987F, 0.9993603494F, 0.9993731080F, - 0.9993856762F, 0.9993980559F, 0.9994102490F, 0.9994222573F, - 0.9994340827F, 0.9994457269F, 0.9994571918F, 0.9994684793F, - 0.9994795910F, 0.9994905288F, 0.9995012945F, 0.9995118898F, - 0.9995223165F, 0.9995325765F, 0.9995426713F, 0.9995526029F, - 0.9995623728F, 0.9995719829F, 0.9995814349F, 0.9995907304F, - 0.9995998712F, 0.9996088590F, 0.9996176954F, 0.9996263821F, - 0.9996349208F, 0.9996433132F, 0.9996515609F, 0.9996596656F, - 0.9996676288F, 0.9996754522F, 0.9996831375F, 0.9996906862F, - 0.9996981000F, 0.9997053804F, 0.9997125290F, 0.9997195474F, - 0.9997264371F, 0.9997331998F, 0.9997398369F, 0.9997463500F, - 0.9997527406F, 0.9997590103F, 0.9997651606F, 0.9997711930F, - 0.9997771089F, 0.9997829098F, 0.9997885973F, 0.9997941728F, - 0.9997996378F, 0.9998049936F, 0.9998102419F, 0.9998153839F, - 0.9998204211F, 0.9998253550F, 0.9998301868F, 0.9998349182F, - 0.9998395503F, 0.9998440847F, 0.9998485226F, 0.9998528654F, - 0.9998571146F, 0.9998612713F, 0.9998653370F, 0.9998693130F, - 0.9998732007F, 0.9998770012F, 0.9998807159F, 0.9998843461F, - 0.9998878931F, 0.9998913581F, 0.9998947424F, 0.9998980473F, - 0.9999012740F, 0.9999044237F, 0.9999074976F, 0.9999104971F, - 0.9999134231F, 0.9999162771F, 0.9999190601F, 0.9999217733F, - 0.9999244179F, 0.9999269950F, 0.9999295058F, 0.9999319515F, - 0.9999343332F, 0.9999366519F, 0.9999389088F, 0.9999411050F, - 0.9999432416F, 0.9999453196F, 0.9999473402F, 0.9999493044F, - 0.9999512132F, 0.9999530677F, 0.9999548690F, 0.9999566180F, - 0.9999583157F, 0.9999599633F, 0.9999615616F, 0.9999631116F, - 0.9999646144F, 0.9999660709F, 0.9999674820F, 0.9999688487F, - 0.9999701719F, 0.9999714526F, 0.9999726917F, 0.9999738900F, - 0.9999750486F, 0.9999761682F, 0.9999772497F, 0.9999782941F, - 0.9999793021F, 0.9999802747F, 0.9999812126F, 0.9999821167F, - 0.9999829878F, 0.9999838268F, 0.9999846343F, 0.9999854113F, - 0.9999861584F, 0.9999868765F, 0.9999875664F, 0.9999882287F, - 0.9999888642F, 0.9999894736F, 0.9999900577F, 0.9999906172F, - 0.9999911528F, 0.9999916651F, 0.9999921548F, 0.9999926227F, - 0.9999930693F, 0.9999934954F, 0.9999939015F, 0.9999942883F, - 0.9999946564F, 0.9999950064F, 0.9999953390F, 0.9999956547F, - 0.9999959541F, 0.9999962377F, 0.9999965062F, 0.9999967601F, - 0.9999969998F, 0.9999972260F, 0.9999974392F, 0.9999976399F, - 0.9999978285F, 0.9999980056F, 0.9999981716F, 0.9999983271F, - 0.9999984724F, 0.9999986081F, 0.9999987345F, 0.9999988521F, - 0.9999989613F, 0.9999990625F, 0.9999991562F, 0.9999992426F, - 0.9999993223F, 0.9999993954F, 0.9999994625F, 0.9999995239F, - 0.9999995798F, 0.9999996307F, 0.9999996768F, 0.9999997184F, - 0.9999997559F, 0.9999997895F, 0.9999998195F, 0.9999998462F, - 0.9999998698F, 0.9999998906F, 0.9999999088F, 0.9999999246F, - 0.9999999383F, 0.9999999500F, 0.9999999600F, 0.9999999684F, - 0.9999999754F, 0.9999999811F, 0.9999999858F, 0.9999999896F, - 0.9999999925F, 0.9999999948F, 0.9999999965F, 0.9999999978F, - 0.9999999986F, 0.9999999992F, 0.9999999996F, 0.9999999998F, - 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F, +DECLARE_ALIGNED(16, static const float, vwin1024)[512] = { + 0.0000036962F, 0.0000332659F, 0.0000924041F, 0.0001811086F, + 0.0002993761F, 0.0004472021F, 0.0006245811F, 0.0008315063F, + 0.0010679699F, 0.0013339631F, 0.0016294757F, 0.0019544965F, + 0.0023090133F, 0.0026930125F, 0.0031064797F, 0.0035493989F, + 0.0040217533F, 0.0045235250F, 0.0050546946F, 0.0056152418F, + 0.0062051451F, 0.0068243817F, 0.0074729278F, 0.0081507582F, + 0.0088578466F, 0.0095941655F, 0.0103596863F, 0.0111543789F, + 0.0119782122F, 0.0128311538F, 0.0137131701F, 0.0146242260F, + 0.0155642855F, 0.0165333111F, 0.0175312640F, 0.0185581042F, + 0.0196137903F, 0.0206982797F, 0.0218115284F, 0.0229534910F, + 0.0241241208F, 0.0253233698F, 0.0265511886F, 0.0278075263F, + 0.0290923308F, 0.0304055484F, 0.0317471241F, 0.0331170013F, + 0.0345151222F, 0.0359414274F, 0.0373958560F, 0.0388783456F, + 0.0403888325F, 0.0419272511F, 0.0434935347F, 0.0450876148F, + 0.0467094213F, 0.0483588828F, 0.0500359261F, 0.0517404765F, + 0.0534724575F, 0.0552317913F, 0.0570183983F, 0.0588321971F, + 0.0606731048F, 0.0625410369F, 0.0644359070F, 0.0663576272F, + 0.0683061077F, 0.0702812571F, 0.0722829821F, 0.0743111878F, + 0.0763657775F, 0.0784466526F, 0.0805537129F, 0.0826868561F, + 0.0848459782F, 0.0870309736F, 0.0892417345F, 0.0914781514F, + 0.0937401128F, 0.0960275056F, 0.0983402145F, 0.1006781223F, + 0.1030411101F, 0.1054290568F, 0.1078418397F, 0.1102793336F, + 0.1127414119F, 0.1152279457F, 0.1177388042F, 0.1202738544F, + 0.1228329618F, 0.1254159892F, 0.1280227980F, 0.1306532471F, + 0.1333071937F, 0.1359844927F, 0.1386849970F, 0.1414085575F, + 0.1441550230F, 0.1469242403F, 0.1497160539F, 0.1525303063F, + 0.1553668381F, 0.1582254875F, 0.1611060909F, 0.1640084822F, + 0.1669324936F, 0.1698779549F, 0.1728446939F, 0.1758325362F, + 0.1788413055F, 0.1818708232F, 0.1849209084F, 0.1879913785F, + 0.1910820485F, 0.1941927312F, 0.1973232376F, 0.2004733764F, + 0.2036429541F, 0.2068317752F, 0.2100396421F, 0.2132663552F, + 0.2165117125F, 0.2197755102F, 0.2230575422F, 0.2263576007F, + 0.2296754753F, 0.2330109540F, 0.2363638225F, 0.2397338646F, + 0.2431208619F, 0.2465245941F, 0.2499448389F, 0.2533813719F, + 0.2568339669F, 0.2603023956F, 0.2637864277F, 0.2672858312F, + 0.2708003718F, 0.2743298135F, 0.2778739186F, 0.2814324472F, + 0.2850051576F, 0.2885918065F, 0.2921921485F, 0.2958059366F, + 0.2994329219F, 0.3030728538F, 0.3067254799F, 0.3103905462F, + 0.3140677969F, 0.3177569747F, 0.3214578205F, 0.3251700736F, + 0.3288934718F, 0.3326277513F, 0.3363726468F, 0.3401278914F, + 0.3438932168F, 0.3476683533F, 0.3514530297F, 0.3552469734F, + 0.3590499106F, 0.3628615659F, 0.3666816630F, 0.3705099239F, + 0.3743460698F, 0.3781898204F, 0.3820408945F, 0.3858990095F, + 0.3897638820F, 0.3936352274F, 0.3975127601F, 0.4013961936F, + 0.4052852405F, 0.4091796123F, 0.4130790198F, 0.4169831732F, + 0.4208917815F, 0.4248045534F, 0.4287211965F, 0.4326414181F, + 0.4365649248F, 0.4404914225F, 0.4444206167F, 0.4483522125F, + 0.4522859146F, 0.4562214270F, 0.4601584538F, 0.4640966984F, + 0.4680358644F, 0.4719756548F, 0.4759157726F, 0.4798559209F, + 0.4837958024F, 0.4877351199F, 0.4916735765F, 0.4956108751F, + 0.4995467188F, 0.5034808109F, 0.5074128550F, 0.5113425550F, + 0.5152696149F, 0.5191937395F, 0.5231146336F, 0.5270320028F, + 0.5309455530F, 0.5348549910F, 0.5387600239F, 0.5426603597F, + 0.5465557070F, 0.5504457754F, 0.5543302752F, 0.5582089175F, + 0.5620814145F, 0.5659474793F, 0.5698068262F, 0.5736591704F, + 0.5775042283F, 0.5813417176F, 0.5851713571F, 0.5889928670F, + 0.5928059689F, 0.5966103856F, 0.6004058415F, 0.6041920626F, + 0.6079687761F, 0.6117357113F, 0.6154925986F, 0.6192391705F, + 0.6229751612F, 0.6267003064F, 0.6304143441F, 0.6341170137F, + 0.6378080569F, 0.6414872173F, 0.6451542405F, 0.6488088741F, + 0.6524508681F, 0.6560799742F, 0.6596959469F, 0.6632985424F, + 0.6668875197F, 0.6704626398F, 0.6740236662F, 0.6775703649F, + 0.6811025043F, 0.6846198554F, 0.6881221916F, 0.6916092892F, + 0.6950809269F, 0.6985368861F, 0.7019769510F, 0.7054009085F, + 0.7088085484F, 0.7121996632F, 0.7155740484F, 0.7189315023F, + 0.7222718263F, 0.7255948245F, 0.7289003043F, 0.7321880760F, + 0.7354579530F, 0.7387097518F, 0.7419432921F, 0.7451583966F, + 0.7483548915F, 0.7515326059F, 0.7546913723F, 0.7578310265F, + 0.7609514077F, 0.7640523581F, 0.7671337237F, 0.7701953535F, + 0.7732371001F, 0.7762588195F, 0.7792603711F, 0.7822416178F, + 0.7852024259F, 0.7881426654F, 0.7910622097F, 0.7939609356F, + 0.7968387237F, 0.7996954579F, 0.8025310261F, 0.8053453193F, + 0.8081382324F, 0.8109096638F, 0.8136595156F, 0.8163876936F, + 0.8190941071F, 0.8217786690F, 0.8244412960F, 0.8270819086F, + 0.8297004305F, 0.8322967896F, 0.8348709171F, 0.8374227481F, + 0.8399522213F, 0.8424592789F, 0.8449438672F, 0.8474059356F, + 0.8498454378F, 0.8522623306F, 0.8546565748F, 0.8570281348F, + 0.8593769787F, 0.8617030779F, 0.8640064080F, 0.8662869477F, + 0.8685446796F, 0.8707795899F, 0.8729916682F, 0.8751809079F, + 0.8773473059F, 0.8794908626F, 0.8816115819F, 0.8837094713F, + 0.8857845418F, 0.8878368079F, 0.8898662874F, 0.8918730019F, + 0.8938569760F, 0.8958182380F, 0.8977568194F, 0.8996727552F, + 0.9015660837F, 0.9034368465F, 0.9052850885F, 0.9071108577F, + 0.9089142057F, 0.9106951869F, 0.9124538591F, 0.9141902832F, + 0.9159045233F, 0.9175966464F, 0.9192667228F, 0.9209148257F, + 0.9225410313F, 0.9241454187F, 0.9257280701F, 0.9272890704F, + 0.9288285075F, 0.9303464720F, 0.9318430576F, 0.9333183603F, + 0.9347724792F, 0.9362055158F, 0.9376175745F, 0.9390087622F, + 0.9403791881F, 0.9417289644F, 0.9430582055F, 0.9443670283F, + 0.9456555521F, 0.9469238986F, 0.9481721917F, 0.9494005577F, + 0.9506091252F, 0.9517980248F, 0.9529673894F, 0.9541173540F, + 0.9552480557F, 0.9563596334F, 0.9574522282F, 0.9585259830F, + 0.9595810428F, 0.9606175542F, 0.9616356656F, 0.9626355274F, + 0.9636172915F, 0.9645811114F, 0.9655271425F, 0.9664555414F, + 0.9673664664F, 0.9682600774F, 0.9691365355F, 0.9699960034F, + 0.9708386448F, 0.9716646250F, 0.9724741103F, 0.9732672685F, + 0.9740442683F, 0.9748052795F, 0.9755504729F, 0.9762800205F, + 0.9769940950F, 0.9776928703F, 0.9783765210F, 0.9790452223F, + 0.9796991504F, 0.9803384823F, 0.9809633954F, 0.9815740679F, + 0.9821706784F, 0.9827534063F, 0.9833224312F, 0.9838779332F, + 0.9844200928F, 0.9849490910F, 0.9854651087F, 0.9859683274F, + 0.9864589286F, 0.9869370940F, 0.9874030054F, 0.9878568447F, + 0.9882987937F, 0.9887290343F, 0.9891477481F, 0.9895551169F, + 0.9899513220F, 0.9903365446F, 0.9907109658F, 0.9910747662F, + 0.9914281260F, 0.9917712252F, 0.9921042433F, 0.9924273593F, + 0.9927407516F, 0.9930445982F, 0.9933390763F, 0.9936243626F, + 0.9939006331F, 0.9941680631F, 0.9944268269F, 0.9946770982F, + 0.9949190498F, 0.9951528537F, 0.9953786808F, 0.9955967011F, + 0.9958070836F, 0.9960099963F, 0.9962056061F, 0.9963940787F, + 0.9965755786F, 0.9967502693F, 0.9969183129F, 0.9970798704F, + 0.9972351013F, 0.9973841640F, 0.9975272151F, 0.9976644103F, + 0.9977959036F, 0.9979218476F, 0.9980423932F, 0.9981576901F, + 0.9982678862F, 0.9983731278F, 0.9984735596F, 0.9985693247F, + 0.9986605645F, 0.9987474186F, 0.9988300248F, 0.9989085193F, + 0.9989830364F, 0.9990537085F, 0.9991206662F, 0.9991840382F, + 0.9992439513F, 0.9993005303F, 0.9993538982F, 0.9994041757F, + 0.9994514817F, 0.9994959330F, 0.9995376444F, 0.9995767286F, + 0.9996132960F, 0.9996474550F, 0.9996793121F, 0.9997089710F, + 0.9997365339F, 0.9997621003F, 0.9997857677F, 0.9998076311F, + 0.9998277836F, 0.9998463156F, 0.9998633155F, 0.9998788692F, + 0.9998930603F, 0.9999059701F, 0.9999176774F, 0.9999282586F, + 0.9999377880F, 0.9999463370F, 0.9999539749F, 0.9999607685F, + 0.9999667820F, 0.9999720773F, 0.9999767136F, 0.9999807479F, + 0.9999842344F, 0.9999872249F, 0.9999897688F, 0.9999919127F, + 0.9999937009F, 0.9999951749F, 0.9999963738F, 0.9999973342F, + 0.9999980900F, 0.9999986724F, 0.9999991103F, 0.9999994297F, + 0.9999996543F, 0.9999998049F, 0.9999999000F, 0.9999999552F, + 0.9999999836F, 0.9999999957F, 0.9999999994F, 1.0000000000F, }; -DECLARE_ALIGNED_16(static const float, vwin8192[4096]) = { - 0.0000000578F, 0.0000005198F, 0.0000014438F, 0.0000028299F, - 0.0000046780F, 0.0000069882F, 0.0000097604F, 0.0000129945F, - 0.0000166908F, 0.0000208490F, 0.0000254692F, 0.0000305515F, - 0.0000360958F, 0.0000421021F, 0.0000485704F, 0.0000555006F, - 0.0000628929F, 0.0000707472F, 0.0000790635F, 0.0000878417F, - 0.0000970820F, 0.0001067842F, 0.0001169483F, 0.0001275744F, - 0.0001386625F, 0.0001502126F, 0.0001622245F, 0.0001746984F, - 0.0001876343F, 0.0002010320F, 0.0002148917F, 0.0002292132F, - 0.0002439967F, 0.0002592421F, 0.0002749493F, 0.0002911184F, - 0.0003077493F, 0.0003248421F, 0.0003423967F, 0.0003604132F, - 0.0003788915F, 0.0003978316F, 0.0004172335F, 0.0004370971F, - 0.0004574226F, 0.0004782098F, 0.0004994587F, 0.0005211694F, - 0.0005433418F, 0.0005659759F, 0.0005890717F, 0.0006126292F, - 0.0006366484F, 0.0006611292F, 0.0006860716F, 0.0007114757F, - 0.0007373414F, 0.0007636687F, 0.0007904576F, 0.0008177080F, - 0.0008454200F, 0.0008735935F, 0.0009022285F, 0.0009313250F, - 0.0009608830F, 0.0009909025F, 0.0010213834F, 0.0010523257F, - 0.0010837295F, 0.0011155946F, 0.0011479211F, 0.0011807090F, - 0.0012139582F, 0.0012476687F, 0.0012818405F, 0.0013164736F, - 0.0013515679F, 0.0013871235F, 0.0014231402F, 0.0014596182F, - 0.0014965573F, 0.0015339576F, 0.0015718190F, 0.0016101415F, - 0.0016489251F, 0.0016881698F, 0.0017278754F, 0.0017680421F, - 0.0018086698F, 0.0018497584F, 0.0018913080F, 0.0019333185F, - 0.0019757898F, 0.0020187221F, 0.0020621151F, 0.0021059690F, - 0.0021502837F, 0.0021950591F, 0.0022402953F, 0.0022859921F, - 0.0023321497F, 0.0023787679F, 0.0024258467F, 0.0024733861F, - 0.0025213861F, 0.0025698466F, 0.0026187676F, 0.0026681491F, - 0.0027179911F, 0.0027682935F, 0.0028190562F, 0.0028702794F, - 0.0029219628F, 0.0029741066F, 0.0030267107F, 0.0030797749F, - 0.0031332994F, 0.0031872841F, 0.0032417289F, 0.0032966338F, - 0.0033519988F, 0.0034078238F, 0.0034641089F, 0.0035208539F, - 0.0035780589F, 0.0036357237F, 0.0036938485F, 0.0037524331F, - 0.0038114775F, 0.0038709817F, 0.0039309456F, 0.0039913692F, - 0.0040522524F, 0.0041135953F, 0.0041753978F, 0.0042376599F, - 0.0043003814F, 0.0043635624F, 0.0044272029F, 0.0044913028F, - 0.0045558620F, 0.0046208806F, 0.0046863585F, 0.0047522955F, - 0.0048186919F, 0.0048855473F, 0.0049528619F, 0.0050206356F, - 0.0050888684F, 0.0051575601F, 0.0052267108F, 0.0052963204F, - 0.0053663890F, 0.0054369163F, 0.0055079025F, 0.0055793474F, - 0.0056512510F, 0.0057236133F, 0.0057964342F, 0.0058697137F, - 0.0059434517F, 0.0060176482F, 0.0060923032F, 0.0061674166F, - 0.0062429883F, 0.0063190183F, 0.0063955066F, 0.0064724532F, - 0.0065498579F, 0.0066277207F, 0.0067060416F, 0.0067848205F, - 0.0068640575F, 0.0069437523F, 0.0070239051F, 0.0071045157F, - 0.0071855840F, 0.0072671102F, 0.0073490940F, 0.0074315355F, - 0.0075144345F, 0.0075977911F, 0.0076816052F, 0.0077658768F, - 0.0078506057F, 0.0079357920F, 0.0080214355F, 0.0081075363F, - 0.0081940943F, 0.0082811094F, 0.0083685816F, 0.0084565108F, - 0.0085448970F, 0.0086337401F, 0.0087230401F, 0.0088127969F, - 0.0089030104F, 0.0089936807F, 0.0090848076F, 0.0091763911F, - 0.0092684311F, 0.0093609276F, 0.0094538805F, 0.0095472898F, - 0.0096411554F, 0.0097354772F, 0.0098302552F, 0.0099254894F, - 0.0100211796F, 0.0101173259F, 0.0102139281F, 0.0103109863F, - 0.0104085002F, 0.0105064700F, 0.0106048955F, 0.0107037766F, - 0.0108031133F, 0.0109029056F, 0.0110031534F, 0.0111038565F, - 0.0112050151F, 0.0113066289F, 0.0114086980F, 0.0115112222F, - 0.0116142015F, 0.0117176359F, 0.0118215252F, 0.0119258695F, - 0.0120306686F, 0.0121359225F, 0.0122416312F, 0.0123477944F, - 0.0124544123F, 0.0125614847F, 0.0126690116F, 0.0127769928F, - 0.0128854284F, 0.0129943182F, 0.0131036623F, 0.0132134604F, - 0.0133237126F, 0.0134344188F, 0.0135455790F, 0.0136571929F, - 0.0137692607F, 0.0138817821F, 0.0139947572F, 0.0141081859F, - 0.0142220681F, 0.0143364037F, 0.0144511927F, 0.0145664350F, - 0.0146821304F, 0.0147982791F, 0.0149148808F, 0.0150319355F, - 0.0151494431F, 0.0152674036F, 0.0153858168F, 0.0155046828F, - 0.0156240014F, 0.0157437726F, 0.0158639962F, 0.0159846723F, - 0.0161058007F, 0.0162273814F, 0.0163494142F, 0.0164718991F, - 0.0165948361F, 0.0167182250F, 0.0168420658F, 0.0169663584F, - 0.0170911027F, 0.0172162987F, 0.0173419462F, 0.0174680452F, - 0.0175945956F, 0.0177215974F, 0.0178490504F, 0.0179769545F, - 0.0181053098F, 0.0182341160F, 0.0183633732F, 0.0184930812F, - 0.0186232399F, 0.0187538494F, 0.0188849094F, 0.0190164200F, - 0.0191483809F, 0.0192807923F, 0.0194136539F, 0.0195469656F, - 0.0196807275F, 0.0198149394F, 0.0199496012F, 0.0200847128F, - 0.0202202742F, 0.0203562853F, 0.0204927460F, 0.0206296561F, - 0.0207670157F, 0.0209048245F, 0.0210430826F, 0.0211817899F, - 0.0213209462F, 0.0214605515F, 0.0216006057F, 0.0217411086F, - 0.0218820603F, 0.0220234605F, 0.0221653093F, 0.0223076066F, - 0.0224503521F, 0.0225935459F, 0.0227371879F, 0.0228812779F, - 0.0230258160F, 0.0231708018F, 0.0233162355F, 0.0234621169F, - 0.0236084459F, 0.0237552224F, 0.0239024462F, 0.0240501175F, - 0.0241982359F, 0.0243468015F, 0.0244958141F, 0.0246452736F, - 0.0247951800F, 0.0249455331F, 0.0250963329F, 0.0252475792F, - 0.0253992720F, 0.0255514111F, 0.0257039965F, 0.0258570281F, - 0.0260105057F, 0.0261644293F, 0.0263187987F, 0.0264736139F, - 0.0266288747F, 0.0267845811F, 0.0269407330F, 0.0270973302F, - 0.0272543727F, 0.0274118604F, 0.0275697930F, 0.0277281707F, - 0.0278869932F, 0.0280462604F, 0.0282059723F, 0.0283661287F, - 0.0285267295F, 0.0286877747F, 0.0288492641F, 0.0290111976F, - 0.0291735751F, 0.0293363965F, 0.0294996617F, 0.0296633706F, - 0.0298275231F, 0.0299921190F, 0.0301571583F, 0.0303226409F, - 0.0304885667F, 0.0306549354F, 0.0308217472F, 0.0309890017F, - 0.0311566989F, 0.0313248388F, 0.0314934211F, 0.0316624459F, - 0.0318319128F, 0.0320018220F, 0.0321721732F, 0.0323429663F, - 0.0325142013F, 0.0326858779F, 0.0328579962F, 0.0330305559F, - 0.0332035570F, 0.0333769994F, 0.0335508829F, 0.0337252074F, - 0.0338999728F, 0.0340751790F, 0.0342508259F, 0.0344269134F, - 0.0346034412F, 0.0347804094F, 0.0349578178F, 0.0351356663F, - 0.0353139548F, 0.0354926831F, 0.0356718511F, 0.0358514588F, - 0.0360315059F, 0.0362119924F, 0.0363929182F, 0.0365742831F, - 0.0367560870F, 0.0369383297F, 0.0371210113F, 0.0373041315F, - 0.0374876902F, 0.0376716873F, 0.0378561226F, 0.0380409961F, - 0.0382263077F, 0.0384120571F, 0.0385982443F, 0.0387848691F, - 0.0389719315F, 0.0391594313F, 0.0393473683F, 0.0395357425F, - 0.0397245537F, 0.0399138017F, 0.0401034866F, 0.0402936080F, - 0.0404841660F, 0.0406751603F, 0.0408665909F, 0.0410584576F, - 0.0412507603F, 0.0414434988F, 0.0416366731F, 0.0418302829F, - 0.0420243282F, 0.0422188088F, 0.0424137246F, 0.0426090755F, - 0.0428048613F, 0.0430010819F, 0.0431977371F, 0.0433948269F, - 0.0435923511F, 0.0437903095F, 0.0439887020F, 0.0441875285F, - 0.0443867889F, 0.0445864830F, 0.0447866106F, 0.0449871717F, - 0.0451881661F, 0.0453895936F, 0.0455914542F, 0.0457937477F, - 0.0459964738F, 0.0461996326F, 0.0464032239F, 0.0466072475F, - 0.0468117032F, 0.0470165910F, 0.0472219107F, 0.0474276622F, - 0.0476338452F, 0.0478404597F, 0.0480475056F, 0.0482549827F, - 0.0484628907F, 0.0486712297F, 0.0488799994F, 0.0490891998F, - 0.0492988306F, 0.0495088917F, 0.0497193830F, 0.0499303043F, - 0.0501416554F, 0.0503534363F, 0.0505656468F, 0.0507782867F, - 0.0509913559F, 0.0512048542F, 0.0514187815F, 0.0516331376F, - 0.0518479225F, 0.0520631358F, 0.0522787775F, 0.0524948475F, - 0.0527113455F, 0.0529282715F, 0.0531456252F, 0.0533634066F, - 0.0535816154F, 0.0538002515F, 0.0540193148F, 0.0542388051F, - 0.0544587222F, 0.0546790660F, 0.0548998364F, 0.0551210331F, - 0.0553426561F, 0.0555647051F, 0.0557871801F, 0.0560100807F, - 0.0562334070F, 0.0564571587F, 0.0566813357F, 0.0569059378F, - 0.0571309649F, 0.0573564168F, 0.0575822933F, 0.0578085942F, - 0.0580353195F, 0.0582624689F, 0.0584900423F, 0.0587180396F, - 0.0589464605F, 0.0591753049F, 0.0594045726F, 0.0596342635F, - 0.0598643774F, 0.0600949141F, 0.0603258735F, 0.0605572555F, - 0.0607890597F, 0.0610212862F, 0.0612539346F, 0.0614870049F, - 0.0617204968F, 0.0619544103F, 0.0621887451F, 0.0624235010F, - 0.0626586780F, 0.0628942758F, 0.0631302942F, 0.0633667331F, - 0.0636035923F, 0.0638408717F, 0.0640785710F, 0.0643166901F, - 0.0645552288F, 0.0647941870F, 0.0650335645F, 0.0652733610F, - 0.0655135765F, 0.0657542108F, 0.0659952636F, 0.0662367348F, - 0.0664786242F, 0.0667209316F, 0.0669636570F, 0.0672068000F, - 0.0674503605F, 0.0676943384F, 0.0679387334F, 0.0681835454F, - 0.0684287742F, 0.0686744196F, 0.0689204814F, 0.0691669595F, - 0.0694138536F, 0.0696611637F, 0.0699088894F, 0.0701570307F, - 0.0704055873F, 0.0706545590F, 0.0709039458F, 0.0711537473F, - 0.0714039634F, 0.0716545939F, 0.0719056387F, 0.0721570975F, - 0.0724089702F, 0.0726612565F, 0.0729139563F, 0.0731670694F, - 0.0734205956F, 0.0736745347F, 0.0739288866F, 0.0741836510F, - 0.0744388277F, 0.0746944166F, 0.0749504175F, 0.0752068301F, - 0.0754636543F, 0.0757208899F, 0.0759785367F, 0.0762365946F, - 0.0764950632F, 0.0767539424F, 0.0770132320F, 0.0772729319F, - 0.0775330418F, 0.0777935616F, 0.0780544909F, 0.0783158298F, - 0.0785775778F, 0.0788397349F, 0.0791023009F, 0.0793652755F, - 0.0796286585F, 0.0798924498F, 0.0801566492F, 0.0804212564F, - 0.0806862712F, 0.0809516935F, 0.0812175231F, 0.0814837597F, - 0.0817504031F, 0.0820174532F, 0.0822849097F, 0.0825527724F, - 0.0828210412F, 0.0830897158F, 0.0833587960F, 0.0836282816F, - 0.0838981724F, 0.0841684682F, 0.0844391688F, 0.0847102740F, - 0.0849817835F, 0.0852536973F, 0.0855260150F, 0.0857987364F, - 0.0860718614F, 0.0863453897F, 0.0866193211F, 0.0868936554F, - 0.0871683924F, 0.0874435319F, 0.0877190737F, 0.0879950175F, - 0.0882713632F, 0.0885481105F, 0.0888252592F, 0.0891028091F, - 0.0893807600F, 0.0896591117F, 0.0899378639F, 0.0902170165F, - 0.0904965692F, 0.0907765218F, 0.0910568740F, 0.0913376258F, - 0.0916187767F, 0.0919003268F, 0.0921822756F, 0.0924646230F, - 0.0927473687F, 0.0930305126F, 0.0933140545F, 0.0935979940F, - 0.0938823310F, 0.0941670653F, 0.0944521966F, 0.0947377247F, - 0.0950236494F, 0.0953099704F, 0.0955966876F, 0.0958838007F, - 0.0961713094F, 0.0964592136F, 0.0967475131F, 0.0970362075F, - 0.0973252967F, 0.0976147805F, 0.0979046585F, 0.0981949307F, - 0.0984855967F, 0.0987766563F, 0.0990681093F, 0.0993599555F, - 0.0996521945F, 0.0999448263F, 0.1002378506F, 0.1005312671F, - 0.1008250755F, 0.1011192757F, 0.1014138675F, 0.1017088505F, - 0.1020042246F, 0.1022999895F, 0.1025961450F, 0.1028926909F, - 0.1031896268F, 0.1034869526F, 0.1037846680F, 0.1040827729F, - 0.1043812668F, 0.1046801497F, 0.1049794213F, 0.1052790813F, - 0.1055791294F, 0.1058795656F, 0.1061803894F, 0.1064816006F, - 0.1067831991F, 0.1070851846F, 0.1073875568F, 0.1076903155F, - 0.1079934604F, 0.1082969913F, 0.1086009079F, 0.1089052101F, - 0.1092098975F, 0.1095149699F, 0.1098204270F, 0.1101262687F, - 0.1104324946F, 0.1107391045F, 0.1110460982F, 0.1113534754F, - 0.1116612359F, 0.1119693793F, 0.1122779055F, 0.1125868142F, - 0.1128961052F, 0.1132057781F, 0.1135158328F, 0.1138262690F, - 0.1141370863F, 0.1144482847F, 0.1147598638F, 0.1150718233F, - 0.1153841631F, 0.1156968828F, 0.1160099822F, 0.1163234610F, - 0.1166373190F, 0.1169515559F, 0.1172661714F, 0.1175811654F, - 0.1178965374F, 0.1182122874F, 0.1185284149F, 0.1188449198F, - 0.1191618018F, 0.1194790606F, 0.1197966960F, 0.1201147076F, - 0.1204330953F, 0.1207518587F, 0.1210709976F, 0.1213905118F, - 0.1217104009F, 0.1220306647F, 0.1223513029F, 0.1226723153F, - 0.1229937016F, 0.1233154615F, 0.1236375948F, 0.1239601011F, - 0.1242829803F, 0.1246062319F, 0.1249298559F, 0.1252538518F, - 0.1255782195F, 0.1259029586F, 0.1262280689F, 0.1265535501F, - 0.1268794019F, 0.1272056241F, 0.1275322163F, 0.1278591784F, - 0.1281865099F, 0.1285142108F, 0.1288422805F, 0.1291707190F, - 0.1294995259F, 0.1298287009F, 0.1301582437F, 0.1304881542F, - 0.1308184319F, 0.1311490766F, 0.1314800881F, 0.1318114660F, - 0.1321432100F, 0.1324753200F, 0.1328077955F, 0.1331406364F, - 0.1334738422F, 0.1338074129F, 0.1341413479F, 0.1344756472F, - 0.1348103103F, 0.1351453370F, 0.1354807270F, 0.1358164801F, - 0.1361525959F, 0.1364890741F, 0.1368259145F, 0.1371631167F, - 0.1375006805F, 0.1378386056F, 0.1381768917F, 0.1385155384F, - 0.1388545456F, 0.1391939129F, 0.1395336400F, 0.1398737266F, - 0.1402141724F, 0.1405549772F, 0.1408961406F, 0.1412376623F, - 0.1415795421F, 0.1419217797F, 0.1422643746F, 0.1426073268F, - 0.1429506358F, 0.1432943013F, 0.1436383231F, 0.1439827008F, - 0.1443274342F, 0.1446725229F, 0.1450179667F, 0.1453637652F, - 0.1457099181F, 0.1460564252F, 0.1464032861F, 0.1467505006F, - 0.1470980682F, 0.1474459888F, 0.1477942620F, 0.1481428875F, - 0.1484918651F, 0.1488411942F, 0.1491908748F, 0.1495409065F, - 0.1498912889F, 0.1502420218F, 0.1505931048F, 0.1509445376F, - 0.1512963200F, 0.1516484516F, 0.1520009321F, 0.1523537612F, - 0.1527069385F, 0.1530604638F, 0.1534143368F, 0.1537685571F, - 0.1541231244F, 0.1544780384F, 0.1548332987F, 0.1551889052F, - 0.1555448574F, 0.1559011550F, 0.1562577978F, 0.1566147853F, - 0.1569721173F, 0.1573297935F, 0.1576878135F, 0.1580461771F, - 0.1584048838F, 0.1587639334F, 0.1591233255F, 0.1594830599F, - 0.1598431361F, 0.1602035540F, 0.1605643131F, 0.1609254131F, - 0.1612868537F, 0.1616486346F, 0.1620107555F, 0.1623732160F, - 0.1627360158F, 0.1630991545F, 0.1634626319F, 0.1638264476F, - 0.1641906013F, 0.1645550926F, 0.1649199212F, 0.1652850869F, - 0.1656505892F, 0.1660164278F, 0.1663826024F, 0.1667491127F, - 0.1671159583F, 0.1674831388F, 0.1678506541F, 0.1682185036F, - 0.1685866872F, 0.1689552044F, 0.1693240549F, 0.1696932384F, - 0.1700627545F, 0.1704326029F, 0.1708027833F, 0.1711732952F, - 0.1715441385F, 0.1719153127F, 0.1722868175F, 0.1726586526F, - 0.1730308176F, 0.1734033121F, 0.1737761359F, 0.1741492886F, - 0.1745227698F, 0.1748965792F, 0.1752707164F, 0.1756451812F, - 0.1760199731F, 0.1763950918F, 0.1767705370F, 0.1771463083F, - 0.1775224054F, 0.1778988279F, 0.1782755754F, 0.1786526477F, - 0.1790300444F, 0.1794077651F, 0.1797858094F, 0.1801641771F, - 0.1805428677F, 0.1809218810F, 0.1813012165F, 0.1816808739F, - 0.1820608528F, 0.1824411530F, 0.1828217739F, 0.1832027154F, - 0.1835839770F, 0.1839655584F, 0.1843474592F, 0.1847296790F, - 0.1851122175F, 0.1854950744F, 0.1858782492F, 0.1862617417F, - 0.1866455514F, 0.1870296780F, 0.1874141211F, 0.1877988804F, - 0.1881839555F, 0.1885693461F, 0.1889550517F, 0.1893410721F, - 0.1897274068F, 0.1901140555F, 0.1905010178F, 0.1908882933F, - 0.1912758818F, 0.1916637828F, 0.1920519959F, 0.1924405208F, - 0.1928293571F, 0.1932185044F, 0.1936079625F, 0.1939977308F, - 0.1943878091F, 0.1947781969F, 0.1951688939F, 0.1955598998F, - 0.1959512141F, 0.1963428364F, 0.1967347665F, 0.1971270038F, - 0.1975195482F, 0.1979123990F, 0.1983055561F, 0.1986990190F, - 0.1990927873F, 0.1994868607F, 0.1998812388F, 0.2002759212F, - 0.2006709075F, 0.2010661974F, 0.2014617904F, 0.2018576862F, - 0.2022538844F, 0.2026503847F, 0.2030471865F, 0.2034442897F, - 0.2038416937F, 0.2042393982F, 0.2046374028F, 0.2050357071F, - 0.2054343107F, 0.2058332133F, 0.2062324145F, 0.2066319138F, - 0.2070317110F, 0.2074318055F, 0.2078321970F, 0.2082328852F, - 0.2086338696F, 0.2090351498F, 0.2094367255F, 0.2098385962F, - 0.2102407617F, 0.2106432213F, 0.2110459749F, 0.2114490220F, - 0.2118523621F, 0.2122559950F, 0.2126599202F, 0.2130641373F, - 0.2134686459F, 0.2138734456F, 0.2142785361F, 0.2146839168F, - 0.2150895875F, 0.2154955478F, 0.2159017972F, 0.2163083353F, - 0.2167151617F, 0.2171222761F, 0.2175296780F, 0.2179373670F, - 0.2183453428F, 0.2187536049F, 0.2191621529F, 0.2195709864F, - 0.2199801051F, 0.2203895085F, 0.2207991961F, 0.2212091677F, - 0.2216194228F, 0.2220299610F, 0.2224407818F, 0.2228518850F, - 0.2232632699F, 0.2236749364F, 0.2240868839F, 0.2244991121F, - 0.2249116204F, 0.2253244086F, 0.2257374763F, 0.2261508229F, - 0.2265644481F, 0.2269783514F, 0.2273925326F, 0.2278069911F, - 0.2282217265F, 0.2286367384F, 0.2290520265F, 0.2294675902F, - 0.2298834292F, 0.2302995431F, 0.2307159314F, 0.2311325937F, - 0.2315495297F, 0.2319667388F, 0.2323842207F, 0.2328019749F, - 0.2332200011F, 0.2336382988F, 0.2340568675F, 0.2344757070F, - 0.2348948166F, 0.2353141961F, 0.2357338450F, 0.2361537629F, - 0.2365739493F, 0.2369944038F, 0.2374151261F, 0.2378361156F, - 0.2382573720F, 0.2386788948F, 0.2391006836F, 0.2395227380F, - 0.2399450575F, 0.2403676417F, 0.2407904902F, 0.2412136026F, - 0.2416369783F, 0.2420606171F, 0.2424845185F, 0.2429086820F, - 0.2433331072F, 0.2437577936F, 0.2441827409F, 0.2446079486F, - 0.2450334163F, 0.2454591435F, 0.2458851298F, 0.2463113747F, - 0.2467378779F, 0.2471646389F, 0.2475916573F, 0.2480189325F, - 0.2484464643F, 0.2488742521F, 0.2493022955F, 0.2497305940F, - 0.2501591473F, 0.2505879549F, 0.2510170163F, 0.2514463311F, - 0.2518758989F, 0.2523057193F, 0.2527357916F, 0.2531661157F, - 0.2535966909F, 0.2540275169F, 0.2544585931F, 0.2548899193F, - 0.2553214948F, 0.2557533193F, 0.2561853924F, 0.2566177135F, - 0.2570502822F, 0.2574830981F, 0.2579161608F, 0.2583494697F, - 0.2587830245F, 0.2592168246F, 0.2596508697F, 0.2600851593F, - 0.2605196929F, 0.2609544701F, 0.2613894904F, 0.2618247534F, - 0.2622602586F, 0.2626960055F, 0.2631319938F, 0.2635682230F, - 0.2640046925F, 0.2644414021F, 0.2648783511F, 0.2653155391F, - 0.2657529657F, 0.2661906305F, 0.2666285329F, 0.2670666725F, - 0.2675050489F, 0.2679436616F, 0.2683825101F, 0.2688215940F, - 0.2692609127F, 0.2697004660F, 0.2701402532F, 0.2705802739F, - 0.2710205278F, 0.2714610142F, 0.2719017327F, 0.2723426830F, - 0.2727838644F, 0.2732252766F, 0.2736669191F, 0.2741087914F, - 0.2745508930F, 0.2749932235F, 0.2754357824F, 0.2758785693F, - 0.2763215837F, 0.2767648251F, 0.2772082930F, 0.2776519870F, - 0.2780959066F, 0.2785400513F, 0.2789844207F, 0.2794290143F, - 0.2798738316F, 0.2803188722F, 0.2807641355F, 0.2812096211F, - 0.2816553286F, 0.2821012574F, 0.2825474071F, 0.2829937773F, - 0.2834403673F, 0.2838871768F, 0.2843342053F, 0.2847814523F, - 0.2852289174F, 0.2856765999F, 0.2861244996F, 0.2865726159F, - 0.2870209482F, 0.2874694962F, 0.2879182594F, 0.2883672372F, - 0.2888164293F, 0.2892658350F, 0.2897154540F, 0.2901652858F, - 0.2906153298F, 0.2910655856F, 0.2915160527F, 0.2919667306F, - 0.2924176189F, 0.2928687171F, 0.2933200246F, 0.2937715409F, - 0.2942232657F, 0.2946751984F, 0.2951273386F, 0.2955796856F, - 0.2960322391F, 0.2964849986F, 0.2969379636F, 0.2973911335F, - 0.2978445080F, 0.2982980864F, 0.2987518684F, 0.2992058534F, - 0.2996600409F, 0.3001144305F, 0.3005690217F, 0.3010238139F, - 0.3014788067F, 0.3019339995F, 0.3023893920F, 0.3028449835F, - 0.3033007736F, 0.3037567618F, 0.3042129477F, 0.3046693306F, - 0.3051259102F, 0.3055826859F, 0.3060396572F, 0.3064968236F, - 0.3069541847F, 0.3074117399F, 0.3078694887F, 0.3083274307F, - 0.3087855653F, 0.3092438920F, 0.3097024104F, 0.3101611199F, - 0.3106200200F, 0.3110791103F, 0.3115383902F, 0.3119978592F, - 0.3124575169F, 0.3129173627F, 0.3133773961F, 0.3138376166F, - 0.3142980238F, 0.3147586170F, 0.3152193959F, 0.3156803598F, - 0.3161415084F, 0.3166028410F, 0.3170643573F, 0.3175260566F, - 0.3179879384F, 0.3184500023F, 0.3189122478F, 0.3193746743F, - 0.3198372814F, 0.3203000685F, 0.3207630351F, 0.3212261807F, - 0.3216895048F, 0.3221530069F, 0.3226166865F, 0.3230805430F, - 0.3235445760F, 0.3240087849F, 0.3244731693F, 0.3249377285F, - 0.3254024622F, 0.3258673698F, 0.3263324507F, 0.3267977045F, - 0.3272631306F, 0.3277287286F, 0.3281944978F, 0.3286604379F, - 0.3291265482F, 0.3295928284F, 0.3300592777F, 0.3305258958F, - 0.3309926821F, 0.3314596361F, 0.3319267573F, 0.3323940451F, - 0.3328614990F, 0.3333291186F, 0.3337969033F, 0.3342648525F, - 0.3347329658F, 0.3352012427F, 0.3356696825F, 0.3361382849F, - 0.3366070492F, 0.3370759749F, 0.3375450616F, 0.3380143087F, - 0.3384837156F, 0.3389532819F, 0.3394230071F, 0.3398928905F, - 0.3403629317F, 0.3408331302F, 0.3413034854F, 0.3417739967F, - 0.3422446638F, 0.3427154860F, 0.3431864628F, 0.3436575938F, - 0.3441288782F, 0.3446003158F, 0.3450719058F, 0.3455436478F, - 0.3460155412F, 0.3464875856F, 0.3469597804F, 0.3474321250F, - 0.3479046189F, 0.3483772617F, 0.3488500527F, 0.3493229914F, - 0.3497960774F, 0.3502693100F, 0.3507426887F, 0.3512162131F, - 0.3516898825F, 0.3521636965F, 0.3526376545F, 0.3531117559F, - 0.3535860003F, 0.3540603870F, 0.3545349157F, 0.3550095856F, - 0.3554843964F, 0.3559593474F, 0.3564344381F, 0.3569096680F, - 0.3573850366F, 0.3578605432F, 0.3583361875F, 0.3588119687F, - 0.3592878865F, 0.3597639402F, 0.3602401293F, 0.3607164533F, - 0.3611929117F, 0.3616695038F, 0.3621462292F, 0.3626230873F, - 0.3631000776F, 0.3635771995F, 0.3640544525F, 0.3645318360F, - 0.3650093496F, 0.3654869926F, 0.3659647645F, 0.3664426648F, - 0.3669206930F, 0.3673988484F, 0.3678771306F, 0.3683555390F, - 0.3688340731F, 0.3693127322F, 0.3697915160F, 0.3702704237F, - 0.3707494549F, 0.3712286091F, 0.3717078857F, 0.3721872840F, - 0.3726668037F, 0.3731464441F, 0.3736262047F, 0.3741060850F, - 0.3745860843F, 0.3750662023F, 0.3755464382F, 0.3760267915F, - 0.3765072618F, 0.3769878484F, 0.3774685509F, 0.3779493686F, - 0.3784303010F, 0.3789113475F, 0.3793925076F, 0.3798737809F, - 0.3803551666F, 0.3808366642F, 0.3813182733F, 0.3817999932F, - 0.3822818234F, 0.3827637633F, 0.3832458124F, 0.3837279702F, - 0.3842102360F, 0.3846926093F, 0.3851750897F, 0.3856576764F, - 0.3861403690F, 0.3866231670F, 0.3871060696F, 0.3875890765F, - 0.3880721870F, 0.3885554007F, 0.3890387168F, 0.3895221349F, - 0.3900056544F, 0.3904892748F, 0.3909729955F, 0.3914568160F, - 0.3919407356F, 0.3924247539F, 0.3929088702F, 0.3933930841F, - 0.3938773949F, 0.3943618021F, 0.3948463052F, 0.3953309035F, - 0.3958155966F, 0.3963003838F, 0.3967852646F, 0.3972702385F, - 0.3977553048F, 0.3982404631F, 0.3987257127F, 0.3992110531F, - 0.3996964838F, 0.4001820041F, 0.4006676136F, 0.4011533116F, - 0.4016390976F, 0.4021249710F, 0.4026109313F, 0.4030969779F, - 0.4035831102F, 0.4040693277F, 0.4045556299F, 0.4050420160F, - 0.4055284857F, 0.4060150383F, 0.4065016732F, 0.4069883899F, - 0.4074751879F, 0.4079620665F, 0.4084490252F, 0.4089360635F, - 0.4094231807F, 0.4099103763F, 0.4103976498F, 0.4108850005F, - 0.4113724280F, 0.4118599315F, 0.4123475107F, 0.4128351648F, - 0.4133228934F, 0.4138106959F, 0.4142985716F, 0.4147865201F, - 0.4152745408F, 0.4157626330F, 0.4162507963F, 0.4167390301F, - 0.4172273337F, 0.4177157067F, 0.4182041484F, 0.4186926583F, - 0.4191812359F, 0.4196698805F, 0.4201585915F, 0.4206473685F, - 0.4211362108F, 0.4216251179F, 0.4221140892F, 0.4226031241F, - 0.4230922221F, 0.4235813826F, 0.4240706050F, 0.4245598887F, - 0.4250492332F, 0.4255386379F, 0.4260281022F, 0.4265176256F, - 0.4270072075F, 0.4274968473F, 0.4279865445F, 0.4284762984F, - 0.4289661086F, 0.4294559743F, 0.4299458951F, 0.4304358704F, - 0.4309258996F, 0.4314159822F, 0.4319061175F, 0.4323963050F, - 0.4328865441F, 0.4333768342F, 0.4338671749F, 0.4343575654F, - 0.4348480052F, 0.4353384938F, 0.4358290306F, 0.4363196149F, - 0.4368102463F, 0.4373009241F, 0.4377916478F, 0.4382824168F, - 0.4387732305F, 0.4392640884F, 0.4397549899F, 0.4402459343F, - 0.4407369212F, 0.4412279499F, 0.4417190198F, 0.4422101305F, - 0.4427012813F, 0.4431924717F, 0.4436837010F, 0.4441749686F, - 0.4446662742F, 0.4451576169F, 0.4456489963F, 0.4461404118F, - 0.4466318628F, 0.4471233487F, 0.4476148690F, 0.4481064230F, - 0.4485980103F, 0.4490896302F, 0.4495812821F, 0.4500729654F, - 0.4505646797F, 0.4510564243F, 0.4515481986F, 0.4520400021F, - 0.4525318341F, 0.4530236942F, 0.4535155816F, 0.4540074959F, - 0.4544994365F, 0.4549914028F, 0.4554833941F, 0.4559754100F, - 0.4564674499F, 0.4569595131F, 0.4574515991F, 0.4579437074F, - 0.4584358372F, 0.4589279881F, 0.4594201595F, 0.4599123508F, - 0.4604045615F, 0.4608967908F, 0.4613890383F, 0.4618813034F, - 0.4623735855F, 0.4628658841F, 0.4633581984F, 0.4638505281F, - 0.4643428724F, 0.4648352308F, 0.4653276028F, 0.4658199877F, - 0.4663123849F, 0.4668047940F, 0.4672972143F, 0.4677896451F, - 0.4682820861F, 0.4687745365F, 0.4692669958F, 0.4697594634F, - 0.4702519387F, 0.4707444211F, 0.4712369102F, 0.4717294052F, - 0.4722219056F, 0.4727144109F, 0.4732069204F, 0.4736994336F, - 0.4741919498F, 0.4746844686F, 0.4751769893F, 0.4756695113F, - 0.4761620341F, 0.4766545571F, 0.4771470797F, 0.4776396013F, - 0.4781321213F, 0.4786246392F, 0.4791171544F, 0.4796096663F, - 0.4801021744F, 0.4805946779F, 0.4810871765F, 0.4815796694F, - 0.4820721561F, 0.4825646360F, 0.4830571086F, 0.4835495732F, - 0.4840420293F, 0.4845344763F, 0.4850269136F, 0.4855193407F, - 0.4860117569F, 0.4865041617F, 0.4869965545F, 0.4874889347F, - 0.4879813018F, 0.4884736551F, 0.4889659941F, 0.4894583182F, - 0.4899506268F, 0.4904429193F, 0.4909351952F, 0.4914274538F, - 0.4919196947F, 0.4924119172F, 0.4929041207F, 0.4933963046F, - 0.4938884685F, 0.4943806116F, 0.4948727335F, 0.4953648335F, - 0.4958569110F, 0.4963489656F, 0.4968409965F, 0.4973330032F, - 0.4978249852F, 0.4983169419F, 0.4988088726F, 0.4993007768F, - 0.4997926539F, 0.5002845034F, 0.5007763247F, 0.5012681171F, - 0.5017598801F, 0.5022516132F, 0.5027433157F, 0.5032349871F, - 0.5037266268F, 0.5042182341F, 0.5047098086F, 0.5052013497F, - 0.5056928567F, 0.5061843292F, 0.5066757664F, 0.5071671679F, - 0.5076585330F, 0.5081498613F, 0.5086411520F, 0.5091324047F, - 0.5096236187F, 0.5101147934F, 0.5106059284F, 0.5110970230F, - 0.5115880766F, 0.5120790887F, 0.5125700587F, 0.5130609860F, - 0.5135518700F, 0.5140427102F, 0.5145335059F, 0.5150242566F, - 0.5155149618F, 0.5160056208F, 0.5164962331F, 0.5169867980F, - 0.5174773151F, 0.5179677837F, 0.5184582033F, 0.5189485733F, - 0.5194388931F, 0.5199291621F, 0.5204193798F, 0.5209095455F, - 0.5213996588F, 0.5218897190F, 0.5223797256F, 0.5228696779F, - 0.5233595755F, 0.5238494177F, 0.5243392039F, 0.5248289337F, - 0.5253186063F, 0.5258082213F, 0.5262977781F, 0.5267872760F, - 0.5272767146F, 0.5277660932F, 0.5282554112F, 0.5287446682F, - 0.5292338635F, 0.5297229965F, 0.5302120667F, 0.5307010736F, - 0.5311900164F, 0.5316788947F, 0.5321677079F, 0.5326564554F, - 0.5331451366F, 0.5336337511F, 0.5341222981F, 0.5346107771F, - 0.5350991876F, 0.5355875290F, 0.5360758007F, 0.5365640021F, - 0.5370521327F, 0.5375401920F, 0.5380281792F, 0.5385160939F, - 0.5390039355F, 0.5394917034F, 0.5399793971F, 0.5404670159F, - 0.5409545594F, 0.5414420269F, 0.5419294179F, 0.5424167318F, - 0.5429039680F, 0.5433911261F, 0.5438782053F, 0.5443652051F, - 0.5448521250F, 0.5453389644F, 0.5458257228F, 0.5463123995F, - 0.5467989940F, 0.5472855057F, 0.5477719341F, 0.5482582786F, - 0.5487445387F, 0.5492307137F, 0.5497168031F, 0.5502028063F, - 0.5506887228F, 0.5511745520F, 0.5516602934F, 0.5521459463F, - 0.5526315103F, 0.5531169847F, 0.5536023690F, 0.5540876626F, - 0.5545728649F, 0.5550579755F, 0.5555429937F, 0.5560279189F, - 0.5565127507F, 0.5569974884F, 0.5574821315F, 0.5579666794F, - 0.5584511316F, 0.5589354875F, 0.5594197465F, 0.5599039080F, - 0.5603879716F, 0.5608719367F, 0.5613558026F, 0.5618395689F, - 0.5623232350F, 0.5628068002F, 0.5632902642F, 0.5637736262F, - 0.5642568858F, 0.5647400423F, 0.5652230953F, 0.5657060442F, - 0.5661888883F, 0.5666716272F, 0.5671542603F, 0.5676367870F, - 0.5681192069F, 0.5686015192F, 0.5690837235F, 0.5695658192F, - 0.5700478058F, 0.5705296827F, 0.5710114494F, 0.5714931052F, - 0.5719746497F, 0.5724560822F, 0.5729374023F, 0.5734186094F, - 0.5738997029F, 0.5743806823F, 0.5748615470F, 0.5753422965F, - 0.5758229301F, 0.5763034475F, 0.5767838480F, 0.5772641310F, - 0.5777442960F, 0.5782243426F, 0.5787042700F, 0.5791840778F, - 0.5796637654F, 0.5801433322F, 0.5806227778F, 0.5811021016F, - 0.5815813029F, 0.5820603814F, 0.5825393363F, 0.5830181673F, - 0.5834968737F, 0.5839754549F, 0.5844539105F, 0.5849322399F, - 0.5854104425F, 0.5858885179F, 0.5863664653F, 0.5868442844F, - 0.5873219746F, 0.5877995353F, 0.5882769660F, 0.5887542661F, - 0.5892314351F, 0.5897084724F, 0.5901853776F, 0.5906621500F, - 0.5911387892F, 0.5916152945F, 0.5920916655F, 0.5925679016F, - 0.5930440022F, 0.5935199669F, 0.5939957950F, 0.5944714861F, - 0.5949470396F, 0.5954224550F, 0.5958977317F, 0.5963728692F, - 0.5968478669F, 0.5973227244F, 0.5977974411F, 0.5982720163F, - 0.5987464497F, 0.5992207407F, 0.5996948887F, 0.6001688932F, - 0.6006427537F, 0.6011164696F, 0.6015900405F, 0.6020634657F, - 0.6025367447F, 0.6030098770F, 0.6034828621F, 0.6039556995F, - 0.6044283885F, 0.6049009288F, 0.6053733196F, 0.6058455606F, - 0.6063176512F, 0.6067895909F, 0.6072613790F, 0.6077330152F, - 0.6082044989F, 0.6086758295F, 0.6091470065F, 0.6096180294F, - 0.6100888977F, 0.6105596108F, 0.6110301682F, 0.6115005694F, - 0.6119708139F, 0.6124409011F, 0.6129108305F, 0.6133806017F, - 0.6138502139F, 0.6143196669F, 0.6147889599F, 0.6152580926F, - 0.6157270643F, 0.6161958746F, 0.6166645230F, 0.6171330088F, - 0.6176013317F, 0.6180694910F, 0.6185374863F, 0.6190053171F, - 0.6194729827F, 0.6199404828F, 0.6204078167F, 0.6208749841F, - 0.6213419842F, 0.6218088168F, 0.6222754811F, 0.6227419768F, - 0.6232083032F, 0.6236744600F, 0.6241404465F, 0.6246062622F, - 0.6250719067F, 0.6255373795F, 0.6260026799F, 0.6264678076F, - 0.6269327619F, 0.6273975425F, 0.6278621487F, 0.6283265800F, - 0.6287908361F, 0.6292549163F, 0.6297188201F, 0.6301825471F, - 0.6306460966F, 0.6311094683F, 0.6315726617F, 0.6320356761F, - 0.6324985111F, 0.6329611662F, 0.6334236410F, 0.6338859348F, - 0.6343480472F, 0.6348099777F, 0.6352717257F, 0.6357332909F, - 0.6361946726F, 0.6366558704F, 0.6371168837F, 0.6375777122F, - 0.6380383552F, 0.6384988123F, 0.6389590830F, 0.6394191668F, - 0.6398790631F, 0.6403387716F, 0.6407982916F, 0.6412576228F, - 0.6417167645F, 0.6421757163F, 0.6426344778F, 0.6430930483F, - 0.6435514275F, 0.6440096149F, 0.6444676098F, 0.6449254119F, - 0.6453830207F, 0.6458404356F, 0.6462976562F, 0.6467546820F, - 0.6472115125F, 0.6476681472F, 0.6481245856F, 0.6485808273F, - 0.6490368717F, 0.6494927183F, 0.6499483667F, 0.6504038164F, - 0.6508590670F, 0.6513141178F, 0.6517689684F, 0.6522236185F, - 0.6526780673F, 0.6531323146F, 0.6535863598F, 0.6540402024F, - 0.6544938419F, 0.6549472779F, 0.6554005099F, 0.6558535373F, - 0.6563063598F, 0.6567589769F, 0.6572113880F, 0.6576635927F, - 0.6581155906F, 0.6585673810F, 0.6590189637F, 0.6594703380F, - 0.6599215035F, 0.6603724598F, 0.6608232064F, 0.6612737427F, - 0.6617240684F, 0.6621741829F, 0.6626240859F, 0.6630737767F, - 0.6635232550F, 0.6639725202F, 0.6644215720F, 0.6648704098F, - 0.6653190332F, 0.6657674417F, 0.6662156348F, 0.6666636121F, - 0.6671113731F, 0.6675589174F, 0.6680062445F, 0.6684533538F, - 0.6689002450F, 0.6693469177F, 0.6697933712F, 0.6702396052F, - 0.6706856193F, 0.6711314129F, 0.6715769855F, 0.6720223369F, - 0.6724674664F, 0.6729123736F, 0.6733570581F, 0.6738015194F, - 0.6742457570F, 0.6746897706F, 0.6751335596F, 0.6755771236F, - 0.6760204621F, 0.6764635747F, 0.6769064609F, 0.6773491204F, - 0.6777915525F, 0.6782337570F, 0.6786757332F, 0.6791174809F, - 0.6795589995F, 0.6800002886F, 0.6804413477F, 0.6808821765F, - 0.6813227743F, 0.6817631409F, 0.6822032758F, 0.6826431785F, - 0.6830828485F, 0.6835222855F, 0.6839614890F, 0.6844004585F, - 0.6848391936F, 0.6852776939F, 0.6857159589F, 0.6861539883F, - 0.6865917815F, 0.6870293381F, 0.6874666576F, 0.6879037398F, - 0.6883405840F, 0.6887771899F, 0.6892135571F, 0.6896496850F, - 0.6900855733F, 0.6905212216F, 0.6909566294F, 0.6913917963F, - 0.6918267218F, 0.6922614055F, 0.6926958471F, 0.6931300459F, - 0.6935640018F, 0.6939977141F, 0.6944311825F, 0.6948644066F, - 0.6952973859F, 0.6957301200F, 0.6961626085F, 0.6965948510F, - 0.6970268470F, 0.6974585961F, 0.6978900980F, 0.6983213521F, - 0.6987523580F, 0.6991831154F, 0.6996136238F, 0.7000438828F, - 0.7004738921F, 0.7009036510F, 0.7013331594F, 0.7017624166F, - 0.7021914224F, 0.7026201763F, 0.7030486779F, 0.7034769268F, - 0.7039049226F, 0.7043326648F, 0.7047601531F, 0.7051873870F, - 0.7056143662F, 0.7060410902F, 0.7064675586F, 0.7068937711F, - 0.7073197271F, 0.7077454264F, 0.7081708684F, 0.7085960529F, - 0.7090209793F, 0.7094456474F, 0.7098700566F, 0.7102942066F, - 0.7107180970F, 0.7111417274F, 0.7115650974F, 0.7119882066F, - 0.7124110545F, 0.7128336409F, 0.7132559653F, 0.7136780272F, - 0.7140998264F, 0.7145213624F, 0.7149426348F, 0.7153636433F, - 0.7157843874F, 0.7162048668F, 0.7166250810F, 0.7170450296F, - 0.7174647124F, 0.7178841289F, 0.7183032786F, 0.7187221613F, - 0.7191407765F, 0.7195591239F, 0.7199772030F, 0.7203950135F, - 0.7208125550F, 0.7212298271F, 0.7216468294F, 0.7220635616F, - 0.7224800233F, 0.7228962140F, 0.7233121335F, 0.7237277813F, - 0.7241431571F, 0.7245582604F, 0.7249730910F, 0.7253876484F, - 0.7258019322F, 0.7262159422F, 0.7266296778F, 0.7270431388F, - 0.7274563247F, 0.7278692353F, 0.7282818700F, 0.7286942287F, - 0.7291063108F, 0.7295181160F, 0.7299296440F, 0.7303408944F, - 0.7307518669F, 0.7311625609F, 0.7315729763F, 0.7319831126F, - 0.7323929695F, 0.7328025466F, 0.7332118435F, 0.7336208600F, - 0.7340295955F, 0.7344380499F, 0.7348462226F, 0.7352541134F, - 0.7356617220F, 0.7360690478F, 0.7364760907F, 0.7368828502F, - 0.7372893259F, 0.7376955176F, 0.7381014249F, 0.7385070475F, - 0.7389123849F, 0.7393174368F, 0.7397222029F, 0.7401266829F, - 0.7405308763F, 0.7409347829F, 0.7413384023F, 0.7417417341F, - 0.7421447780F, 0.7425475338F, 0.7429500009F, 0.7433521791F, - 0.7437540681F, 0.7441556674F, 0.7445569769F, 0.7449579960F, - 0.7453587245F, 0.7457591621F, 0.7461593084F, 0.7465591631F, - 0.7469587259F, 0.7473579963F, 0.7477569741F, 0.7481556590F, - 0.7485540506F, 0.7489521486F, 0.7493499526F, 0.7497474623F, - 0.7501446775F, 0.7505415977F, 0.7509382227F, 0.7513345521F, - 0.7517305856F, 0.7521263229F, 0.7525217636F, 0.7529169074F, - 0.7533117541F, 0.7537063032F, 0.7541005545F, 0.7544945076F, - 0.7548881623F, 0.7552815182F, 0.7556745749F, 0.7560673323F, - 0.7564597899F, 0.7568519474F, 0.7572438046F, 0.7576353611F, - 0.7580266166F, 0.7584175708F, 0.7588082235F, 0.7591985741F, - 0.7595886226F, 0.7599783685F, 0.7603678116F, 0.7607569515F, - 0.7611457879F, 0.7615343206F, 0.7619225493F, 0.7623104735F, - 0.7626980931F, 0.7630854078F, 0.7634724171F, 0.7638591209F, - 0.7642455188F, 0.7646316106F, 0.7650173959F, 0.7654028744F, - 0.7657880459F, 0.7661729100F, 0.7665574664F, 0.7669417150F, - 0.7673256553F, 0.7677092871F, 0.7680926100F, 0.7684756239F, - 0.7688583284F, 0.7692407232F, 0.7696228080F, 0.7700045826F, - 0.7703860467F, 0.7707671999F, 0.7711480420F, 0.7715285728F, - 0.7719087918F, 0.7722886989F, 0.7726682938F, 0.7730475762F, - 0.7734265458F, 0.7738052023F, 0.7741835454F, 0.7745615750F, - 0.7749392906F, 0.7753166921F, 0.7756937791F, 0.7760705514F, - 0.7764470087F, 0.7768231508F, 0.7771989773F, 0.7775744880F, - 0.7779496827F, 0.7783245610F, 0.7786991227F, 0.7790733676F, - 0.7794472953F, 0.7798209056F, 0.7801941982F, 0.7805671729F, - 0.7809398294F, 0.7813121675F, 0.7816841869F, 0.7820558873F, - 0.7824272684F, 0.7827983301F, 0.7831690720F, 0.7835394940F, - 0.7839095957F, 0.7842793768F, 0.7846488373F, 0.7850179767F, - 0.7853867948F, 0.7857552914F, 0.7861234663F, 0.7864913191F, - 0.7868588497F, 0.7872260578F, 0.7875929431F, 0.7879595055F, - 0.7883257445F, 0.7886916601F, 0.7890572520F, 0.7894225198F, - 0.7897874635F, 0.7901520827F, 0.7905163772F, 0.7908803468F, - 0.7912439912F, 0.7916073102F, 0.7919703035F, 0.7923329710F, - 0.7926953124F, 0.7930573274F, 0.7934190158F, 0.7937803774F, - 0.7941414120F, 0.7945021193F, 0.7948624991F, 0.7952225511F, - 0.7955822752F, 0.7959416711F, 0.7963007387F, 0.7966594775F, - 0.7970178875F, 0.7973759685F, 0.7977337201F, 0.7980911422F, - 0.7984482346F, 0.7988049970F, 0.7991614292F, 0.7995175310F, - 0.7998733022F, 0.8002287426F, 0.8005838519F, 0.8009386299F, - 0.8012930765F, 0.8016471914F, 0.8020009744F, 0.8023544253F, - 0.8027075438F, 0.8030603298F, 0.8034127831F, 0.8037649035F, - 0.8041166906F, 0.8044681445F, 0.8048192647F, 0.8051700512F, - 0.8055205038F, 0.8058706222F, 0.8062204062F, 0.8065698556F, - 0.8069189702F, 0.8072677499F, 0.8076161944F, 0.8079643036F, - 0.8083120772F, 0.8086595151F, 0.8090066170F, 0.8093533827F, - 0.8096998122F, 0.8100459051F, 0.8103916613F, 0.8107370806F, - 0.8110821628F, 0.8114269077F, 0.8117713151F, 0.8121153849F, - 0.8124591169F, 0.8128025108F, 0.8131455666F, 0.8134882839F, - 0.8138306627F, 0.8141727027F, 0.8145144038F, 0.8148557658F, - 0.8151967886F, 0.8155374718F, 0.8158778154F, 0.8162178192F, - 0.8165574830F, 0.8168968067F, 0.8172357900F, 0.8175744328F, - 0.8179127349F, 0.8182506962F, 0.8185883164F, 0.8189255955F, - 0.8192625332F, 0.8195991295F, 0.8199353840F, 0.8202712967F, - 0.8206068673F, 0.8209420958F, 0.8212769820F, 0.8216115256F, - 0.8219457266F, 0.8222795848F, 0.8226131000F, 0.8229462721F, - 0.8232791009F, 0.8236115863F, 0.8239437280F, 0.8242755260F, - 0.8246069801F, 0.8249380901F, 0.8252688559F, 0.8255992774F, - 0.8259293544F, 0.8262590867F, 0.8265884741F, 0.8269175167F, - 0.8272462141F, 0.8275745663F, 0.8279025732F, 0.8282302344F, - 0.8285575501F, 0.8288845199F, 0.8292111437F, 0.8295374215F, - 0.8298633530F, 0.8301889382F, 0.8305141768F, 0.8308390688F, - 0.8311636141F, 0.8314878124F, 0.8318116637F, 0.8321351678F, - 0.8324583246F, 0.8327811340F, 0.8331035957F, 0.8334257098F, - 0.8337474761F, 0.8340688944F, 0.8343899647F, 0.8347106867F, - 0.8350310605F, 0.8353510857F, 0.8356707624F, 0.8359900904F, - 0.8363090696F, 0.8366276999F, 0.8369459811F, 0.8372639131F, - 0.8375814958F, 0.8378987292F, 0.8382156130F, 0.8385321472F, - 0.8388483316F, 0.8391641662F, 0.8394796508F, 0.8397947853F, - 0.8401095697F, 0.8404240037F, 0.8407380873F, 0.8410518204F, - 0.8413652029F, 0.8416782347F, 0.8419909156F, 0.8423032456F, - 0.8426152245F, 0.8429268523F, 0.8432381289F, 0.8435490541F, - 0.8438596279F, 0.8441698502F, 0.8444797208F, 0.8447892396F, - 0.8450984067F, 0.8454072218F, 0.8457156849F, 0.8460237959F, - 0.8463315547F, 0.8466389612F, 0.8469460154F, 0.8472527170F, - 0.8475590661F, 0.8478650625F, 0.8481707063F, 0.8484759971F, - 0.8487809351F, 0.8490855201F, 0.8493897521F, 0.8496936308F, - 0.8499971564F, 0.8503003286F, 0.8506031474F, 0.8509056128F, - 0.8512077246F, 0.8515094828F, 0.8518108872F, 0.8521119379F, - 0.8524126348F, 0.8527129777F, 0.8530129666F, 0.8533126015F, - 0.8536118822F, 0.8539108087F, 0.8542093809F, 0.8545075988F, - 0.8548054623F, 0.8551029712F, 0.8554001257F, 0.8556969255F, - 0.8559933707F, 0.8562894611F, 0.8565851968F, 0.8568805775F, - 0.8571756034F, 0.8574702743F, 0.8577645902F, 0.8580585509F, - 0.8583521566F, 0.8586454070F, 0.8589383021F, 0.8592308420F, - 0.8595230265F, 0.8598148556F, 0.8601063292F, 0.8603974473F, - 0.8606882098F, 0.8609786167F, 0.8612686680F, 0.8615583636F, - 0.8618477034F, 0.8621366874F, 0.8624253156F, 0.8627135878F, - 0.8630015042F, 0.8632890646F, 0.8635762690F, 0.8638631173F, - 0.8641496096F, 0.8644357457F, 0.8647215257F, 0.8650069495F, - 0.8652920171F, 0.8655767283F, 0.8658610833F, 0.8661450820F, - 0.8664287243F, 0.8667120102F, 0.8669949397F, 0.8672775127F, - 0.8675597293F, 0.8678415894F, 0.8681230929F, 0.8684042398F, - 0.8686850302F, 0.8689654640F, 0.8692455412F, 0.8695252617F, - 0.8698046255F, 0.8700836327F, 0.8703622831F, 0.8706405768F, - 0.8709185138F, 0.8711960940F, 0.8714733174F, 0.8717501840F, - 0.8720266939F, 0.8723028469F, 0.8725786430F, 0.8728540824F, - 0.8731291648F, 0.8734038905F, 0.8736782592F, 0.8739522711F, - 0.8742259261F, 0.8744992242F, 0.8747721653F, 0.8750447496F, - 0.8753169770F, 0.8755888475F, 0.8758603611F, 0.8761315177F, - 0.8764023175F, 0.8766727603F, 0.8769428462F, 0.8772125752F, - 0.8774819474F, 0.8777509626F, 0.8780196209F, 0.8782879224F, - 0.8785558669F, 0.8788234546F, 0.8790906854F, 0.8793575594F, - 0.8796240765F, 0.8798902368F, 0.8801560403F, 0.8804214870F, - 0.8806865768F, 0.8809513099F, 0.8812156863F, 0.8814797059F, - 0.8817433687F, 0.8820066749F, 0.8822696243F, 0.8825322171F, - 0.8827944532F, 0.8830563327F, 0.8833178556F, 0.8835790219F, - 0.8838398316F, 0.8841002848F, 0.8843603815F, 0.8846201217F, - 0.8848795054F, 0.8851385327F, 0.8853972036F, 0.8856555182F, - 0.8859134764F, 0.8861710783F, 0.8864283239F, 0.8866852133F, - 0.8869417464F, 0.8871979234F, 0.8874537443F, 0.8877092090F, - 0.8879643177F, 0.8882190704F, 0.8884734671F, 0.8887275078F, - 0.8889811927F, 0.8892345216F, 0.8894874948F, 0.8897401122F, - 0.8899923738F, 0.8902442798F, 0.8904958301F, 0.8907470248F, - 0.8909978640F, 0.8912483477F, 0.8914984759F, 0.8917482487F, - 0.8919976662F, 0.8922467284F, 0.8924954353F, 0.8927437871F, - 0.8929917837F, 0.8932394252F, 0.8934867118F, 0.8937336433F, - 0.8939802199F, 0.8942264417F, 0.8944723087F, 0.8947178210F, - 0.8949629785F, 0.8952077815F, 0.8954522299F, 0.8956963239F, - 0.8959400634F, 0.8961834486F, 0.8964264795F, 0.8966691561F, - 0.8969114786F, 0.8971534470F, 0.8973950614F, 0.8976363219F, - 0.8978772284F, 0.8981177812F, 0.8983579802F, 0.8985978256F, - 0.8988373174F, 0.8990764556F, 0.8993152405F, 0.8995536720F, - 0.8997917502F, 0.9000294751F, 0.9002668470F, 0.9005038658F, - 0.9007405317F, 0.9009768446F, 0.9012128048F, 0.9014484123F, - 0.9016836671F, 0.9019185693F, 0.9021531191F, 0.9023873165F, - 0.9026211616F, 0.9028546546F, 0.9030877954F, 0.9033205841F, - 0.9035530210F, 0.9037851059F, 0.9040168392F, 0.9042482207F, - 0.9044792507F, 0.9047099293F, 0.9049402564F, 0.9051702323F, - 0.9053998569F, 0.9056291305F, 0.9058580531F, 0.9060866248F, - 0.9063148457F, 0.9065427159F, 0.9067702355F, 0.9069974046F, - 0.9072242233F, 0.9074506917F, 0.9076768100F, 0.9079025782F, - 0.9081279964F, 0.9083530647F, 0.9085777833F, 0.9088021523F, - 0.9090261717F, 0.9092498417F, 0.9094731623F, 0.9096961338F, - 0.9099187561F, 0.9101410295F, 0.9103629540F, 0.9105845297F, - 0.9108057568F, 0.9110266354F, 0.9112471656F, 0.9114673475F, - 0.9116871812F, 0.9119066668F, 0.9121258046F, 0.9123445945F, - 0.9125630367F, 0.9127811314F, 0.9129988786F, 0.9132162785F, - 0.9134333312F, 0.9136500368F, 0.9138663954F, 0.9140824073F, - 0.9142980724F, 0.9145133910F, 0.9147283632F, 0.9149429890F, - 0.9151572687F, 0.9153712023F, 0.9155847900F, 0.9157980319F, - 0.9160109282F, 0.9162234790F, 0.9164356844F, 0.9166475445F, - 0.9168590595F, 0.9170702296F, 0.9172810548F, 0.9174915354F, - 0.9177016714F, 0.9179114629F, 0.9181209102F, 0.9183300134F, - 0.9185387726F, 0.9187471879F, 0.9189552595F, 0.9191629876F, - 0.9193703723F, 0.9195774136F, 0.9197841119F, 0.9199904672F, - 0.9201964797F, 0.9204021495F, 0.9206074767F, 0.9208124616F, - 0.9210171043F, 0.9212214049F, 0.9214253636F, 0.9216289805F, - 0.9218322558F, 0.9220351896F, 0.9222377821F, 0.9224400335F, - 0.9226419439F, 0.9228435134F, 0.9230447423F, 0.9232456307F, - 0.9234461787F, 0.9236463865F, 0.9238462543F, 0.9240457822F, - 0.9242449704F, 0.9244438190F, 0.9246423282F, 0.9248404983F, - 0.9250383293F, 0.9252358214F, 0.9254329747F, 0.9256297896F, - 0.9258262660F, 0.9260224042F, 0.9262182044F, 0.9264136667F, - 0.9266087913F, 0.9268035783F, 0.9269980280F, 0.9271921405F, - 0.9273859160F, 0.9275793546F, 0.9277724566F, 0.9279652221F, - 0.9281576513F, 0.9283497443F, 0.9285415014F, 0.9287329227F, - 0.9289240084F, 0.9291147586F, 0.9293051737F, 0.9294952536F, - 0.9296849987F, 0.9298744091F, 0.9300634850F, 0.9302522266F, - 0.9304406340F, 0.9306287074F, 0.9308164471F, 0.9310038532F, - 0.9311909259F, 0.9313776654F, 0.9315640719F, 0.9317501455F, - 0.9319358865F, 0.9321212951F, 0.9323063713F, 0.9324911155F, - 0.9326755279F, 0.9328596085F, 0.9330433577F, 0.9332267756F, - 0.9334098623F, 0.9335926182F, 0.9337750434F, 0.9339571380F, - 0.9341389023F, 0.9343203366F, 0.9345014409F, 0.9346822155F, - 0.9348626606F, 0.9350427763F, 0.9352225630F, 0.9354020207F, - 0.9355811498F, 0.9357599503F, 0.9359384226F, 0.9361165667F, - 0.9362943830F, 0.9364718716F, 0.9366490327F, 0.9368258666F, - 0.9370023733F, 0.9371785533F, 0.9373544066F, 0.9375299335F, - 0.9377051341F, 0.9378800087F, 0.9380545576F, 0.9382287809F, - 0.9384026787F, 0.9385762515F, 0.9387494993F, 0.9389224223F, - 0.9390950209F, 0.9392672951F, 0.9394392453F, 0.9396108716F, - 0.9397821743F, 0.9399531536F, 0.9401238096F, 0.9402941427F, - 0.9404641530F, 0.9406338407F, 0.9408032061F, 0.9409722495F, - 0.9411409709F, 0.9413093707F, 0.9414774491F, 0.9416452062F, - 0.9418126424F, 0.9419797579F, 0.9421465528F, 0.9423130274F, - 0.9424791819F, 0.9426450166F, 0.9428105317F, 0.9429757274F, - 0.9431406039F, 0.9433051616F, 0.9434694005F, 0.9436333209F, - 0.9437969232F, 0.9439602074F, 0.9441231739F, 0.9442858229F, - 0.9444481545F, 0.9446101691F, 0.9447718669F, 0.9449332481F, - 0.9450943129F, 0.9452550617F, 0.9454154945F, 0.9455756118F, - 0.9457354136F, 0.9458949003F, 0.9460540721F, 0.9462129292F, - 0.9463714719F, 0.9465297003F, 0.9466876149F, 0.9468452157F, - 0.9470025031F, 0.9471594772F, 0.9473161384F, 0.9474724869F, - 0.9476285229F, 0.9477842466F, 0.9479396584F, 0.9480947585F, - 0.9482495470F, 0.9484040243F, 0.9485581906F, 0.9487120462F, - 0.9488655913F, 0.9490188262F, 0.9491717511F, 0.9493243662F, - 0.9494766718F, 0.9496286683F, 0.9497803557F, 0.9499317345F, - 0.9500828047F, 0.9502335668F, 0.9503840209F, 0.9505341673F, - 0.9506840062F, 0.9508335380F, 0.9509827629F, 0.9511316810F, - 0.9512802928F, 0.9514285984F, 0.9515765982F, 0.9517242923F, - 0.9518716810F, 0.9520187646F, 0.9521655434F, 0.9523120176F, - 0.9524581875F, 0.9526040534F, 0.9527496154F, 0.9528948739F, - 0.9530398292F, 0.9531844814F, 0.9533288310F, 0.9534728780F, - 0.9536166229F, 0.9537600659F, 0.9539032071F, 0.9540460470F, - 0.9541885858F, 0.9543308237F, 0.9544727611F, 0.9546143981F, - 0.9547557351F, 0.9548967723F, 0.9550375100F, 0.9551779485F, - 0.9553180881F, 0.9554579290F, 0.9555974714F, 0.9557367158F, - 0.9558756623F, 0.9560143112F, 0.9561526628F, 0.9562907174F, - 0.9564284752F, 0.9565659366F, 0.9567031017F, 0.9568399710F, - 0.9569765446F, 0.9571128229F, 0.9572488061F, 0.9573844944F, - 0.9575198883F, 0.9576549879F, 0.9577897936F, 0.9579243056F, - 0.9580585242F, 0.9581924497F, 0.9583260824F, 0.9584594226F, - 0.9585924705F, 0.9587252264F, 0.9588576906F, 0.9589898634F, - 0.9591217452F, 0.9592533360F, 0.9593846364F, 0.9595156465F, - 0.9596463666F, 0.9597767971F, 0.9599069382F, 0.9600367901F, - 0.9601663533F, 0.9602956279F, 0.9604246143F, 0.9605533128F, - 0.9606817236F, 0.9608098471F, 0.9609376835F, 0.9610652332F, - 0.9611924963F, 0.9613194733F, 0.9614461644F, 0.9615725699F, - 0.9616986901F, 0.9618245253F, 0.9619500757F, 0.9620753418F, - 0.9622003238F, 0.9623250219F, 0.9624494365F, 0.9625735679F, - 0.9626974163F, 0.9628209821F, 0.9629442656F, 0.9630672671F, - 0.9631899868F, 0.9633124251F, 0.9634345822F, 0.9635564585F, - 0.9636780543F, 0.9637993699F, 0.9639204056F, 0.9640411616F, - 0.9641616383F, 0.9642818359F, 0.9644017549F, 0.9645213955F, - 0.9646407579F, 0.9647598426F, 0.9648786497F, 0.9649971797F, - 0.9651154328F, 0.9652334092F, 0.9653511095F, 0.9654685337F, - 0.9655856823F, 0.9657025556F, 0.9658191538F, 0.9659354773F, - 0.9660515263F, 0.9661673013F, 0.9662828024F, 0.9663980300F, - 0.9665129845F, 0.9666276660F, 0.9667420750F, 0.9668562118F, - 0.9669700766F, 0.9670836698F, 0.9671969917F, 0.9673100425F, - 0.9674228227F, 0.9675353325F, 0.9676475722F, 0.9677595422F, - 0.9678712428F, 0.9679826742F, 0.9680938368F, 0.9682047309F, - 0.9683153569F, 0.9684257150F, 0.9685358056F, 0.9686456289F, - 0.9687551853F, 0.9688644752F, 0.9689734987F, 0.9690822564F, - 0.9691907483F, 0.9692989750F, 0.9694069367F, 0.9695146337F, - 0.9696220663F, 0.9697292349F, 0.9698361398F, 0.9699427813F, - 0.9700491597F, 0.9701552754F, 0.9702611286F, 0.9703667197F, - 0.9704720490F, 0.9705771169F, 0.9706819236F, 0.9707864695F, - 0.9708907549F, 0.9709947802F, 0.9710985456F, 0.9712020514F, - 0.9713052981F, 0.9714082859F, 0.9715110151F, 0.9716134862F, - 0.9717156993F, 0.9718176549F, 0.9719193532F, 0.9720207946F, - 0.9721219794F, 0.9722229080F, 0.9723235806F, 0.9724239976F, - 0.9725241593F, 0.9726240661F, 0.9727237183F, 0.9728231161F, - 0.9729222601F, 0.9730211503F, 0.9731197873F, 0.9732181713F, - 0.9733163027F, 0.9734141817F, 0.9735118088F, 0.9736091842F, - 0.9737063083F, 0.9738031814F, 0.9738998039F, 0.9739961760F, - 0.9740922981F, 0.9741881706F, 0.9742837938F, 0.9743791680F, - 0.9744742935F, 0.9745691707F, 0.9746637999F, 0.9747581814F, - 0.9748523157F, 0.9749462029F, 0.9750398435F, 0.9751332378F, - 0.9752263861F, 0.9753192887F, 0.9754119461F, 0.9755043585F, - 0.9755965262F, 0.9756884496F, 0.9757801291F, 0.9758715650F, - 0.9759627575F, 0.9760537071F, 0.9761444141F, 0.9762348789F, - 0.9763251016F, 0.9764150828F, 0.9765048228F, 0.9765943218F, - 0.9766835802F, 0.9767725984F, 0.9768613767F, 0.9769499154F, - 0.9770382149F, 0.9771262755F, 0.9772140976F, 0.9773016815F, - 0.9773890275F, 0.9774761360F, 0.9775630073F, 0.9776496418F, - 0.9777360398F, 0.9778222016F, 0.9779081277F, 0.9779938182F, - 0.9780792736F, 0.9781644943F, 0.9782494805F, 0.9783342326F, - 0.9784187509F, 0.9785030359F, 0.9785870877F, 0.9786709069F, - 0.9787544936F, 0.9788378484F, 0.9789209714F, 0.9790038631F, - 0.9790865238F, 0.9791689538F, 0.9792511535F, 0.9793331232F, - 0.9794148633F, 0.9794963742F, 0.9795776561F, 0.9796587094F, - 0.9797395345F, 0.9798201316F, 0.9799005013F, 0.9799806437F, - 0.9800605593F, 0.9801402483F, 0.9802197112F, 0.9802989483F, - 0.9803779600F, 0.9804567465F, 0.9805353082F, 0.9806136455F, - 0.9806917587F, 0.9807696482F, 0.9808473143F, 0.9809247574F, - 0.9810019778F, 0.9810789759F, 0.9811557519F, 0.9812323064F, - 0.9813086395F, 0.9813847517F, 0.9814606433F, 0.9815363147F, - 0.9816117662F, 0.9816869981F, 0.9817620108F, 0.9818368047F, - 0.9819113801F, 0.9819857374F, 0.9820598769F, 0.9821337989F, - 0.9822075038F, 0.9822809920F, 0.9823542638F, 0.9824273195F, - 0.9825001596F, 0.9825727843F, 0.9826451940F, 0.9827173891F, - 0.9827893700F, 0.9828611368F, 0.9829326901F, 0.9830040302F, - 0.9830751574F, 0.9831460720F, 0.9832167745F, 0.9832872652F, - 0.9833575444F, 0.9834276124F, 0.9834974697F, 0.9835671166F, - 0.9836365535F, 0.9837057806F, 0.9837747983F, 0.9838436071F, - 0.9839122072F, 0.9839805990F, 0.9840487829F, 0.9841167591F, - 0.9841845282F, 0.9842520903F, 0.9843194459F, 0.9843865953F, - 0.9844535389F, 0.9845202771F, 0.9845868101F, 0.9846531383F, - 0.9847192622F, 0.9847851820F, 0.9848508980F, 0.9849164108F, - 0.9849817205F, 0.9850468276F, 0.9851117324F, 0.9851764352F, - 0.9852409365F, 0.9853052366F, 0.9853693358F, 0.9854332344F, - 0.9854969330F, 0.9855604317F, 0.9856237309F, 0.9856868310F, - 0.9857497325F, 0.9858124355F, 0.9858749404F, 0.9859372477F, - 0.9859993577F, 0.9860612707F, 0.9861229871F, 0.9861845072F, - 0.9862458315F, 0.9863069601F, 0.9863678936F, 0.9864286322F, - 0.9864891764F, 0.9865495264F, 0.9866096826F, 0.9866696454F, - 0.9867294152F, 0.9867889922F, 0.9868483769F, 0.9869075695F, - 0.9869665706F, 0.9870253803F, 0.9870839991F, 0.9871424273F, - 0.9872006653F, 0.9872587135F, 0.9873165721F, 0.9873742415F, - 0.9874317222F, 0.9874890144F, 0.9875461185F, 0.9876030348F, - 0.9876597638F, 0.9877163057F, 0.9877726610F, 0.9878288300F, - 0.9878848130F, 0.9879406104F, 0.9879962225F, 0.9880516497F, - 0.9881068924F, 0.9881619509F, 0.9882168256F, 0.9882715168F, - 0.9883260249F, 0.9883803502F, 0.9884344931F, 0.9884884539F, - 0.9885422331F, 0.9885958309F, 0.9886492477F, 0.9887024838F, - 0.9887555397F, 0.9888084157F, 0.9888611120F, 0.9889136292F, - 0.9889659675F, 0.9890181273F, 0.9890701089F, 0.9891219128F, - 0.9891735392F, 0.9892249885F, 0.9892762610F, 0.9893273572F, - 0.9893782774F, 0.9894290219F, 0.9894795911F, 0.9895299853F, - 0.9895802049F, 0.9896302502F, 0.9896801217F, 0.9897298196F, - 0.9897793443F, 0.9898286961F, 0.9898778755F, 0.9899268828F, - 0.9899757183F, 0.9900243823F, 0.9900728753F, 0.9901211976F, - 0.9901693495F, 0.9902173314F, 0.9902651436F, 0.9903127865F, - 0.9903602605F, 0.9904075659F, 0.9904547031F, 0.9905016723F, - 0.9905484740F, 0.9905951086F, 0.9906415763F, 0.9906878775F, - 0.9907340126F, 0.9907799819F, 0.9908257858F, 0.9908714247F, - 0.9909168988F, 0.9909622086F, 0.9910073543F, 0.9910523364F, - 0.9910971552F, 0.9911418110F, 0.9911863042F, 0.9912306351F, - 0.9912748042F, 0.9913188117F, 0.9913626580F, 0.9914063435F, - 0.9914498684F, 0.9914932333F, 0.9915364383F, 0.9915794839F, - 0.9916223703F, 0.9916650981F, 0.9917076674F, 0.9917500787F, - 0.9917923323F, 0.9918344286F, 0.9918763679F, 0.9919181505F, - 0.9919597769F, 0.9920012473F, 0.9920425621F, 0.9920837217F, - 0.9921247263F, 0.9921655765F, 0.9922062724F, 0.9922468145F, - 0.9922872030F, 0.9923274385F, 0.9923675211F, 0.9924074513F, - 0.9924472294F, 0.9924868557F, 0.9925263306F, 0.9925656544F, - 0.9926048275F, 0.9926438503F, 0.9926827230F, 0.9927214461F, - 0.9927600199F, 0.9927984446F, 0.9928367208F, 0.9928748486F, - 0.9929128285F, 0.9929506608F, 0.9929883459F, 0.9930258841F, - 0.9930632757F, 0.9931005211F, 0.9931376207F, 0.9931745747F, - 0.9932113836F, 0.9932480476F, 0.9932845671F, 0.9933209425F, - 0.9933571742F, 0.9933932623F, 0.9934292074F, 0.9934650097F, - 0.9935006696F, 0.9935361874F, 0.9935715635F, 0.9936067982F, - 0.9936418919F, 0.9936768448F, 0.9937116574F, 0.9937463300F, - 0.9937808629F, 0.9938152565F, 0.9938495111F, 0.9938836271F, - 0.9939176047F, 0.9939514444F, 0.9939851465F, 0.9940187112F, - 0.9940521391F, 0.9940854303F, 0.9941185853F, 0.9941516044F, - 0.9941844879F, 0.9942172361F, 0.9942498495F, 0.9942823283F, - 0.9943146729F, 0.9943468836F, 0.9943789608F, 0.9944109047F, - 0.9944427158F, 0.9944743944F, 0.9945059408F, 0.9945373553F, - 0.9945686384F, 0.9945997902F, 0.9946308112F, 0.9946617017F, - 0.9946924621F, 0.9947230926F, 0.9947535937F, 0.9947839656F, - 0.9948142086F, 0.9948443232F, 0.9948743097F, 0.9949041683F, - 0.9949338995F, 0.9949635035F, 0.9949929807F, 0.9950223315F, - 0.9950515561F, 0.9950806549F, 0.9951096282F, 0.9951384764F, - 0.9951671998F, 0.9951957987F, 0.9952242735F, 0.9952526245F, - 0.9952808520F, 0.9953089564F, 0.9953369380F, 0.9953647971F, - 0.9953925340F, 0.9954201491F, 0.9954476428F, 0.9954750153F, - 0.9955022670F, 0.9955293981F, 0.9955564092F, 0.9955833003F, - 0.9956100720F, 0.9956367245F, 0.9956632582F, 0.9956896733F, - 0.9957159703F, 0.9957421494F, 0.9957682110F, 0.9957941553F, - 0.9958199828F, 0.9958456937F, 0.9958712884F, 0.9958967672F, - 0.9959221305F, 0.9959473784F, 0.9959725115F, 0.9959975300F, - 0.9960224342F, 0.9960472244F, 0.9960719011F, 0.9960964644F, - 0.9961209148F, 0.9961452525F, 0.9961694779F, 0.9961935913F, - 0.9962175930F, 0.9962414834F, 0.9962652627F, 0.9962889313F, - 0.9963124895F, 0.9963359377F, 0.9963592761F, 0.9963825051F, - 0.9964056250F, 0.9964286361F, 0.9964515387F, 0.9964743332F, - 0.9964970198F, 0.9965195990F, 0.9965420709F, 0.9965644360F, - 0.9965866946F, 0.9966088469F, 0.9966308932F, 0.9966528340F, - 0.9966746695F, 0.9966964001F, 0.9967180260F, 0.9967395475F, - 0.9967609651F, 0.9967822789F, 0.9968034894F, 0.9968245968F, - 0.9968456014F, 0.9968665036F, 0.9968873037F, 0.9969080019F, - 0.9969285987F, 0.9969490942F, 0.9969694889F, 0.9969897830F, - 0.9970099769F, 0.9970300708F, 0.9970500651F, 0.9970699601F, - 0.9970897561F, 0.9971094533F, 0.9971290522F, 0.9971485531F, - 0.9971679561F, 0.9971872617F, 0.9972064702F, 0.9972255818F, - 0.9972445968F, 0.9972635157F, 0.9972823386F, 0.9973010659F, - 0.9973196980F, 0.9973382350F, 0.9973566773F, 0.9973750253F, - 0.9973932791F, 0.9974114392F, 0.9974295059F, 0.9974474793F, - 0.9974653599F, 0.9974831480F, 0.9975008438F, 0.9975184476F, - 0.9975359598F, 0.9975533806F, 0.9975707104F, 0.9975879495F, - 0.9976050981F, 0.9976221566F, 0.9976391252F, 0.9976560043F, - 0.9976727941F, 0.9976894950F, 0.9977061073F, 0.9977226312F, - 0.9977390671F, 0.9977554152F, 0.9977716759F, 0.9977878495F, - 0.9978039361F, 0.9978199363F, 0.9978358501F, 0.9978516780F, - 0.9978674202F, 0.9978830771F, 0.9978986488F, 0.9979141358F, - 0.9979295383F, 0.9979448566F, 0.9979600909F, 0.9979752417F, - 0.9979903091F, 0.9980052936F, 0.9980201952F, 0.9980350145F, - 0.9980497515F, 0.9980644067F, 0.9980789804F, 0.9980934727F, - 0.9981078841F, 0.9981222147F, 0.9981364649F, 0.9981506350F, - 0.9981647253F, 0.9981787360F, 0.9981926674F, 0.9982065199F, - 0.9982202936F, 0.9982339890F, 0.9982476062F, 0.9982611456F, - 0.9982746074F, 0.9982879920F, 0.9983012996F, 0.9983145304F, - 0.9983276849F, 0.9983407632F, 0.9983537657F, 0.9983666926F, - 0.9983795442F, 0.9983923208F, 0.9984050226F, 0.9984176501F, - 0.9984302033F, 0.9984426827F, 0.9984550884F, 0.9984674208F, - 0.9984796802F, 0.9984918667F, 0.9985039808F, 0.9985160227F, - 0.9985279926F, 0.9985398909F, 0.9985517177F, 0.9985634734F, - 0.9985751583F, 0.9985867727F, 0.9985983167F, 0.9986097907F, - 0.9986211949F, 0.9986325297F, 0.9986437953F, 0.9986549919F, - 0.9986661199F, 0.9986771795F, 0.9986881710F, 0.9986990946F, - 0.9987099507F, 0.9987207394F, 0.9987314611F, 0.9987421161F, - 0.9987527045F, 0.9987632267F, 0.9987736829F, 0.9987840734F, - 0.9987943985F, 0.9988046584F, 0.9988148534F, 0.9988249838F, - 0.9988350498F, 0.9988450516F, 0.9988549897F, 0.9988648641F, - 0.9988746753F, 0.9988844233F, 0.9988941086F, 0.9989037313F, - 0.9989132918F, 0.9989227902F, 0.9989322269F, 0.9989416021F, - 0.9989509160F, 0.9989601690F, 0.9989693613F, 0.9989784931F, - 0.9989875647F, 0.9989965763F, 0.9990055283F, 0.9990144208F, - 0.9990232541F, 0.9990320286F, 0.9990407443F, 0.9990494016F, - 0.9990580008F, 0.9990665421F, 0.9990750257F, 0.9990834519F, - 0.9990918209F, 0.9991001331F, 0.9991083886F, 0.9991165877F, - 0.9991247307F, 0.9991328177F, 0.9991408491F, 0.9991488251F, - 0.9991567460F, 0.9991646119F, 0.9991724232F, 0.9991801801F, - 0.9991878828F, 0.9991955316F, 0.9992031267F, 0.9992106684F, - 0.9992181569F, 0.9992255925F, 0.9992329753F, 0.9992403057F, - 0.9992475839F, 0.9992548101F, 0.9992619846F, 0.9992691076F, - 0.9992761793F, 0.9992832001F, 0.9992901701F, 0.9992970895F, - 0.9993039587F, 0.9993107777F, 0.9993175470F, 0.9993242667F, - 0.9993309371F, 0.9993375583F, 0.9993441307F, 0.9993506545F, - 0.9993571298F, 0.9993635570F, 0.9993699362F, 0.9993762678F, - 0.9993825519F, 0.9993887887F, 0.9993949785F, 0.9994011216F, - 0.9994072181F, 0.9994132683F, 0.9994192725F, 0.9994252307F, - 0.9994311434F, 0.9994370107F, 0.9994428327F, 0.9994486099F, - 0.9994543423F, 0.9994600303F, 0.9994656739F, 0.9994712736F, - 0.9994768294F, 0.9994823417F, 0.9994878105F, 0.9994932363F, - 0.9994986191F, 0.9995039592F, 0.9995092568F, 0.9995145122F, - 0.9995197256F, 0.9995248971F, 0.9995300270F, 0.9995351156F, - 0.9995401630F, 0.9995451695F, 0.9995501352F, 0.9995550604F, - 0.9995599454F, 0.9995647903F, 0.9995695953F, 0.9995743607F, - 0.9995790866F, 0.9995837734F, 0.9995884211F, 0.9995930300F, - 0.9995976004F, 0.9996021324F, 0.9996066263F, 0.9996110822F, - 0.9996155004F, 0.9996198810F, 0.9996242244F, 0.9996285306F, - 0.9996327999F, 0.9996370326F, 0.9996412287F, 0.9996453886F, - 0.9996495125F, 0.9996536004F, 0.9996576527F, 0.9996616696F, - 0.9996656512F, 0.9996695977F, 0.9996735094F, 0.9996773865F, - 0.9996812291F, 0.9996850374F, 0.9996888118F, 0.9996925523F, - 0.9996962591F, 0.9996999325F, 0.9997035727F, 0.9997071798F, - 0.9997107541F, 0.9997142957F, 0.9997178049F, 0.9997212818F, - 0.9997247266F, 0.9997281396F, 0.9997315209F, 0.9997348708F, - 0.9997381893F, 0.9997414767F, 0.9997447333F, 0.9997479591F, - 0.9997511544F, 0.9997543194F, 0.9997574542F, 0.9997605591F, - 0.9997636342F, 0.9997666797F, 0.9997696958F, 0.9997726828F, - 0.9997756407F, 0.9997785698F, 0.9997814703F, 0.9997843423F, - 0.9997871860F, 0.9997900016F, 0.9997927894F, 0.9997955494F, - 0.9997982818F, 0.9998009869F, 0.9998036648F, 0.9998063157F, - 0.9998089398F, 0.9998115373F, 0.9998141082F, 0.9998166529F, - 0.9998191715F, 0.9998216642F, 0.9998241311F, 0.9998265724F, - 0.9998289884F, 0.9998313790F, 0.9998337447F, 0.9998360854F, - 0.9998384015F, 0.9998406930F, 0.9998429602F, 0.9998452031F, - 0.9998474221F, 0.9998496171F, 0.9998517885F, 0.9998539364F, - 0.9998560610F, 0.9998581624F, 0.9998602407F, 0.9998622962F, - 0.9998643291F, 0.9998663394F, 0.9998683274F, 0.9998702932F, - 0.9998722370F, 0.9998741589F, 0.9998760591F, 0.9998779378F, - 0.9998797952F, 0.9998816313F, 0.9998834464F, 0.9998852406F, - 0.9998870141F, 0.9998887670F, 0.9998904995F, 0.9998922117F, - 0.9998939039F, 0.9998955761F, 0.9998972285F, 0.9998988613F, - 0.9999004746F, 0.9999020686F, 0.9999036434F, 0.9999051992F, - 0.9999067362F, 0.9999082544F, 0.9999097541F, 0.9999112354F, - 0.9999126984F, 0.9999141433F, 0.9999155703F, 0.9999169794F, - 0.9999183709F, 0.9999197449F, 0.9999211014F, 0.9999224408F, - 0.9999237631F, 0.9999250684F, 0.9999263570F, 0.9999276289F, - 0.9999288843F, 0.9999301233F, 0.9999313461F, 0.9999325529F, - 0.9999337437F, 0.9999349187F, 0.9999360780F, 0.9999372218F, - 0.9999383503F, 0.9999394635F, 0.9999405616F, 0.9999416447F, - 0.9999427129F, 0.9999437665F, 0.9999448055F, 0.9999458301F, - 0.9999468404F, 0.9999478365F, 0.9999488185F, 0.9999497867F, - 0.9999507411F, 0.9999516819F, 0.9999526091F, 0.9999535230F, - 0.9999544236F, 0.9999553111F, 0.9999561856F, 0.9999570472F, - 0.9999578960F, 0.9999587323F, 0.9999595560F, 0.9999603674F, - 0.9999611666F, 0.9999619536F, 0.9999627286F, 0.9999634917F, - 0.9999642431F, 0.9999649828F, 0.9999657110F, 0.9999664278F, - 0.9999671334F, 0.9999678278F, 0.9999685111F, 0.9999691835F, - 0.9999698451F, 0.9999704960F, 0.9999711364F, 0.9999717662F, - 0.9999723858F, 0.9999729950F, 0.9999735942F, 0.9999741834F, - 0.9999747626F, 0.9999753321F, 0.9999758919F, 0.9999764421F, - 0.9999769828F, 0.9999775143F, 0.9999780364F, 0.9999785495F, - 0.9999790535F, 0.9999795485F, 0.9999800348F, 0.9999805124F, - 0.9999809813F, 0.9999814417F, 0.9999818938F, 0.9999823375F, - 0.9999827731F, 0.9999832005F, 0.9999836200F, 0.9999840316F, - 0.9999844353F, 0.9999848314F, 0.9999852199F, 0.9999856008F, - 0.9999859744F, 0.9999863407F, 0.9999866997F, 0.9999870516F, - 0.9999873965F, 0.9999877345F, 0.9999880656F, 0.9999883900F, - 0.9999887078F, 0.9999890190F, 0.9999893237F, 0.9999896220F, - 0.9999899140F, 0.9999901999F, 0.9999904796F, 0.9999907533F, - 0.9999910211F, 0.9999912830F, 0.9999915391F, 0.9999917896F, - 0.9999920345F, 0.9999922738F, 0.9999925077F, 0.9999927363F, - 0.9999929596F, 0.9999931777F, 0.9999933907F, 0.9999935987F, - 0.9999938018F, 0.9999940000F, 0.9999941934F, 0.9999943820F, - 0.9999945661F, 0.9999947456F, 0.9999949206F, 0.9999950912F, - 0.9999952575F, 0.9999954195F, 0.9999955773F, 0.9999957311F, - 0.9999958807F, 0.9999960265F, 0.9999961683F, 0.9999963063F, - 0.9999964405F, 0.9999965710F, 0.9999966979F, 0.9999968213F, - 0.9999969412F, 0.9999970576F, 0.9999971707F, 0.9999972805F, - 0.9999973871F, 0.9999974905F, 0.9999975909F, 0.9999976881F, - 0.9999977824F, 0.9999978738F, 0.9999979624F, 0.9999980481F, - 0.9999981311F, 0.9999982115F, 0.9999982892F, 0.9999983644F, - 0.9999984370F, 0.9999985072F, 0.9999985750F, 0.9999986405F, - 0.9999987037F, 0.9999987647F, 0.9999988235F, 0.9999988802F, - 0.9999989348F, 0.9999989873F, 0.9999990379F, 0.9999990866F, - 0.9999991334F, 0.9999991784F, 0.9999992217F, 0.9999992632F, - 0.9999993030F, 0.9999993411F, 0.9999993777F, 0.9999994128F, - 0.9999994463F, 0.9999994784F, 0.9999995091F, 0.9999995384F, - 0.9999995663F, 0.9999995930F, 0.9999996184F, 0.9999996426F, - 0.9999996657F, 0.9999996876F, 0.9999997084F, 0.9999997282F, - 0.9999997469F, 0.9999997647F, 0.9999997815F, 0.9999997973F, - 0.9999998123F, 0.9999998265F, 0.9999998398F, 0.9999998524F, - 0.9999998642F, 0.9999998753F, 0.9999998857F, 0.9999998954F, - 0.9999999045F, 0.9999999130F, 0.9999999209F, 0.9999999282F, - 0.9999999351F, 0.9999999414F, 0.9999999472F, 0.9999999526F, - 0.9999999576F, 0.9999999622F, 0.9999999664F, 0.9999999702F, - 0.9999999737F, 0.9999999769F, 0.9999999798F, 0.9999999824F, - 0.9999999847F, 0.9999999868F, 0.9999999887F, 0.9999999904F, - 0.9999999919F, 0.9999999932F, 0.9999999943F, 0.9999999953F, - 0.9999999961F, 0.9999999969F, 0.9999999975F, 0.9999999980F, - 0.9999999985F, 0.9999999988F, 0.9999999991F, 0.9999999993F, - 0.9999999995F, 0.9999999997F, 0.9999999998F, 0.9999999999F, - 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F, - 1.0000000000F, 1.0000000000F, 1.0000000000F, 1.0000000000F, +DECLARE_ALIGNED(16, static const float, vwin2048)[1024] = { + 0.0000009241F, 0.0000083165F, 0.0000231014F, 0.0000452785F, + 0.0000748476F, 0.0001118085F, 0.0001561608F, 0.0002079041F, + 0.0002670379F, 0.0003335617F, 0.0004074748F, 0.0004887765F, + 0.0005774661F, 0.0006735427F, 0.0007770054F, 0.0008878533F, + 0.0010060853F, 0.0011317002F, 0.0012646969F, 0.0014050742F, + 0.0015528307F, 0.0017079650F, 0.0018704756F, 0.0020403610F, + 0.0022176196F, 0.0024022497F, 0.0025942495F, 0.0027936173F, + 0.0030003511F, 0.0032144490F, 0.0034359088F, 0.0036647286F, + 0.0039009061F, 0.0041444391F, 0.0043953253F, 0.0046535621F, + 0.0049191472F, 0.0051920781F, 0.0054723520F, 0.0057599664F, + 0.0060549184F, 0.0063572052F, 0.0066668239F, 0.0069837715F, + 0.0073080449F, 0.0076396410F, 0.0079785566F, 0.0083247884F, + 0.0086783330F, 0.0090391871F, 0.0094073470F, 0.0097828092F, + 0.0101655700F, 0.0105556258F, 0.0109529726F, 0.0113576065F, + 0.0117695237F, 0.0121887200F, 0.0126151913F, 0.0130489335F, + 0.0134899422F, 0.0139382130F, 0.0143937415F, 0.0148565233F, + 0.0153265536F, 0.0158038279F, 0.0162883413F, 0.0167800889F, + 0.0172790660F, 0.0177852675F, 0.0182986882F, 0.0188193231F, + 0.0193471668F, 0.0198822141F, 0.0204244594F, 0.0209738974F, + 0.0215305225F, 0.0220943289F, 0.0226653109F, 0.0232434627F, + 0.0238287784F, 0.0244212519F, 0.0250208772F, 0.0256276481F, + 0.0262415582F, 0.0268626014F, 0.0274907711F, 0.0281260608F, + 0.0287684638F, 0.0294179736F, 0.0300745833F, 0.0307382859F, + 0.0314090747F, 0.0320869424F, 0.0327718819F, 0.0334638860F, + 0.0341629474F, 0.0348690586F, 0.0355822122F, 0.0363024004F, + 0.0370296157F, 0.0377638502F, 0.0385050960F, 0.0392533451F, + 0.0400085896F, 0.0407708211F, 0.0415400315F, 0.0423162123F, + 0.0430993552F, 0.0438894515F, 0.0446864926F, 0.0454904698F, + 0.0463013742F, 0.0471191969F, 0.0479439288F, 0.0487755607F, + 0.0496140836F, 0.0504594879F, 0.0513117642F, 0.0521709031F, + 0.0530368949F, 0.0539097297F, 0.0547893979F, 0.0556758894F, + 0.0565691941F, 0.0574693019F, 0.0583762026F, 0.0592898858F, + 0.0602103410F, 0.0611375576F, 0.0620715250F, 0.0630122324F, + 0.0639596688F, 0.0649138234F, 0.0658746848F, 0.0668422421F, + 0.0678164838F, 0.0687973985F, 0.0697849746F, 0.0707792005F, + 0.0717800645F, 0.0727875547F, 0.0738016591F, 0.0748223656F, + 0.0758496620F, 0.0768835359F, 0.0779239751F, 0.0789709668F, + 0.0800244985F, 0.0810845574F, 0.0821511306F, 0.0832242052F, + 0.0843037679F, 0.0853898056F, 0.0864823050F, 0.0875812525F, + 0.0886866347F, 0.0897984378F, 0.0909166480F, 0.0920412513F, + 0.0931722338F, 0.0943095813F, 0.0954532795F, 0.0966033140F, + 0.0977596702F, 0.0989223336F, 0.1000912894F, 0.1012665227F, + 0.1024480185F, 0.1036357616F, 0.1048297369F, 0.1060299290F, + 0.1072363224F, 0.1084489014F, 0.1096676504F, 0.1108925534F, + 0.1121235946F, 0.1133607577F, 0.1146040267F, 0.1158533850F, + 0.1171088163F, 0.1183703040F, 0.1196378312F, 0.1209113812F, + 0.1221909370F, 0.1234764815F, 0.1247679974F, 0.1260654674F, + 0.1273688740F, 0.1286781995F, 0.1299934263F, 0.1313145365F, + 0.1326415121F, 0.1339743349F, 0.1353129866F, 0.1366574490F, + 0.1380077035F, 0.1393637315F, 0.1407255141F, 0.1420930325F, + 0.1434662677F, 0.1448452004F, 0.1462298115F, 0.1476200814F, + 0.1490159906F, 0.1504175195F, 0.1518246482F, 0.1532373569F, + 0.1546556253F, 0.1560794333F, 0.1575087606F, 0.1589435866F, + 0.1603838909F, 0.1618296526F, 0.1632808509F, 0.1647374648F, + 0.1661994731F, 0.1676668546F, 0.1691395880F, 0.1706176516F, + 0.1721010238F, 0.1735896829F, 0.1750836068F, 0.1765827736F, + 0.1780871610F, 0.1795967468F, 0.1811115084F, 0.1826314234F, + 0.1841564689F, 0.1856866221F, 0.1872218600F, 0.1887621595F, + 0.1903074974F, 0.1918578503F, 0.1934131947F, 0.1949735068F, + 0.1965387630F, 0.1981089393F, 0.1996840117F, 0.2012639560F, + 0.2028487479F, 0.2044383630F, 0.2060327766F, 0.2076319642F, + 0.2092359007F, 0.2108445614F, 0.2124579211F, 0.2140759545F, + 0.2156986364F, 0.2173259411F, 0.2189578432F, 0.2205943168F, + 0.2222353361F, 0.2238808751F, 0.2255309076F, 0.2271854073F, + 0.2288443480F, 0.2305077030F, 0.2321754457F, 0.2338475493F, + 0.2355239869F, 0.2372047315F, 0.2388897560F, 0.2405790329F, + 0.2422725350F, 0.2439702347F, 0.2456721043F, 0.2473781159F, + 0.2490882418F, 0.2508024539F, 0.2525207240F, 0.2542430237F, + 0.2559693248F, 0.2576995986F, 0.2594338166F, 0.2611719498F, + 0.2629139695F, 0.2646598466F, 0.2664095520F, 0.2681630564F, + 0.2699203304F, 0.2716813445F, 0.2734460691F, 0.2752144744F, + 0.2769865307F, 0.2787622079F, 0.2805414760F, 0.2823243047F, + 0.2841106637F, 0.2859005227F, 0.2876938509F, 0.2894906179F, + 0.2912907928F, 0.2930943447F, 0.2949012426F, 0.2967114554F, + 0.2985249520F, 0.3003417009F, 0.3021616708F, 0.3039848301F, + 0.3058111471F, 0.3076405901F, 0.3094731273F, 0.3113087266F, + 0.3131473560F, 0.3149889833F, 0.3168335762F, 0.3186811024F, + 0.3205315294F, 0.3223848245F, 0.3242409552F, 0.3260998886F, + 0.3279615918F, 0.3298260319F, 0.3316931758F, 0.3335629903F, + 0.3354354423F, 0.3373104982F, 0.3391881247F, 0.3410682882F, + 0.3429509551F, 0.3448360917F, 0.3467236642F, 0.3486136387F, + 0.3505059811F, 0.3524006575F, 0.3542976336F, 0.3561968753F, + 0.3580983482F, 0.3600020179F, 0.3619078499F, 0.3638158096F, + 0.3657258625F, 0.3676379737F, 0.3695521086F, 0.3714682321F, + 0.3733863094F, 0.3753063055F, 0.3772281852F, 0.3791519134F, + 0.3810774548F, 0.3830047742F, 0.3849338362F, 0.3868646053F, + 0.3887970459F, 0.3907311227F, 0.3926667998F, 0.3946040417F, + 0.3965428125F, 0.3984830765F, 0.4004247978F, 0.4023679403F, + 0.4043124683F, 0.4062583455F, 0.4082055359F, 0.4101540034F, + 0.4121037117F, 0.4140546246F, 0.4160067058F, 0.4179599190F, + 0.4199142277F, 0.4218695956F, 0.4238259861F, 0.4257833627F, + 0.4277416888F, 0.4297009279F, 0.4316610433F, 0.4336219983F, + 0.4355837562F, 0.4375462803F, 0.4395095337F, 0.4414734797F, + 0.4434380815F, 0.4454033021F, 0.4473691046F, 0.4493354521F, + 0.4513023078F, 0.4532696345F, 0.4552373954F, 0.4572055533F, + 0.4591740713F, 0.4611429123F, 0.4631120393F, 0.4650814151F, + 0.4670510028F, 0.4690207650F, 0.4709906649F, 0.4729606651F, + 0.4749307287F, 0.4769008185F, 0.4788708972F, 0.4808409279F, + 0.4828108732F, 0.4847806962F, 0.4867503597F, 0.4887198264F, + 0.4906890593F, 0.4926580213F, 0.4946266753F, 0.4965949840F, + 0.4985629105F, 0.5005304176F, 0.5024974683F, 0.5044640255F, + 0.5064300522F, 0.5083955114F, 0.5103603659F, 0.5123245790F, + 0.5142881136F, 0.5162509328F, 0.5182129997F, 0.5201742774F, + 0.5221347290F, 0.5240943178F, 0.5260530070F, 0.5280107598F, + 0.5299675395F, 0.5319233095F, 0.5338780330F, 0.5358316736F, + 0.5377841946F, 0.5397355596F, 0.5416857320F, 0.5436346755F, + 0.5455823538F, 0.5475287304F, 0.5494737691F, 0.5514174337F, + 0.5533596881F, 0.5553004962F, 0.5572398218F, 0.5591776291F, + 0.5611138821F, 0.5630485449F, 0.5649815818F, 0.5669129570F, + 0.5688426349F, 0.5707705799F, 0.5726967564F, 0.5746211290F, + 0.5765436624F, 0.5784643212F, 0.5803830702F, 0.5822998743F, + 0.5842146984F, 0.5861275076F, 0.5880382669F, 0.5899469416F, + 0.5918534968F, 0.5937578981F, 0.5956601107F, 0.5975601004F, + 0.5994578326F, 0.6013532732F, 0.6032463880F, 0.6051371429F, + 0.6070255039F, 0.6089114372F, 0.6107949090F, 0.6126758856F, + 0.6145543334F, 0.6164302191F, 0.6183035092F, 0.6201741706F, + 0.6220421700F, 0.6239074745F, 0.6257700513F, 0.6276298674F, + 0.6294868903F, 0.6313410873F, 0.6331924262F, 0.6350408745F, + 0.6368864001F, 0.6387289710F, 0.6405685552F, 0.6424051209F, + 0.6442386364F, 0.6460690702F, 0.6478963910F, 0.6497205673F, + 0.6515415682F, 0.6533593625F, 0.6551739194F, 0.6569852082F, + 0.6587931984F, 0.6605978593F, 0.6623991609F, 0.6641970728F, + 0.6659915652F, 0.6677826081F, 0.6695701718F, 0.6713542268F, + 0.6731347437F, 0.6749116932F, 0.6766850461F, 0.6784547736F, + 0.6802208469F, 0.6819832374F, 0.6837419164F, 0.6854968559F, + 0.6872480275F, 0.6889954034F, 0.6907389556F, 0.6924786566F, + 0.6942144788F, 0.6959463950F, 0.6976743780F, 0.6993984008F, + 0.7011184365F, 0.7028344587F, 0.7045464407F, 0.7062543564F, + 0.7079581796F, 0.7096578844F, 0.7113534450F, 0.7130448359F, + 0.7147320316F, 0.7164150070F, 0.7180937371F, 0.7197681970F, + 0.7214383620F, 0.7231042077F, 0.7247657098F, 0.7264228443F, + 0.7280755871F, 0.7297239147F, 0.7313678035F, 0.7330072301F, + 0.7346421715F, 0.7362726046F, 0.7378985069F, 0.7395198556F, + 0.7411366285F, 0.7427488034F, 0.7443563584F, 0.7459592717F, + 0.7475575218F, 0.7491510873F, 0.7507399471F, 0.7523240803F, + 0.7539034661F, 0.7554780839F, 0.7570479136F, 0.7586129349F, + 0.7601731279F, 0.7617284730F, 0.7632789506F, 0.7648245416F, + 0.7663652267F, 0.7679009872F, 0.7694318044F, 0.7709576599F, + 0.7724785354F, 0.7739944130F, 0.7755052749F, 0.7770111035F, + 0.7785118815F, 0.7800075916F, 0.7814982170F, 0.7829837410F, + 0.7844641472F, 0.7859394191F, 0.7874095408F, 0.7888744965F, + 0.7903342706F, 0.7917888476F, 0.7932382124F, 0.7946823501F, + 0.7961212460F, 0.7975548855F, 0.7989832544F, 0.8004063386F, + 0.8018241244F, 0.8032365981F, 0.8046437463F, 0.8060455560F, + 0.8074420141F, 0.8088331080F, 0.8102188253F, 0.8115991536F, + 0.8129740810F, 0.8143435957F, 0.8157076861F, 0.8170663409F, + 0.8184195489F, 0.8197672994F, 0.8211095817F, 0.8224463853F, + 0.8237777001F, 0.8251035161F, 0.8264238235F, 0.8277386129F, + 0.8290478750F, 0.8303516008F, 0.8316497814F, 0.8329424083F, + 0.8342294731F, 0.8355109677F, 0.8367868841F, 0.8380572148F, + 0.8393219523F, 0.8405810893F, 0.8418346190F, 0.8430825345F, + 0.8443248294F, 0.8455614974F, 0.8467925323F, 0.8480179285F, + 0.8492376802F, 0.8504517822F, 0.8516602292F, 0.8528630164F, + 0.8540601391F, 0.8552515928F, 0.8564373733F, 0.8576174766F, + 0.8587918990F, 0.8599606368F, 0.8611236868F, 0.8622810460F, + 0.8634327113F, 0.8645786802F, 0.8657189504F, 0.8668535195F, + 0.8679823857F, 0.8691055472F, 0.8702230025F, 0.8713347503F, + 0.8724407896F, 0.8735411194F, 0.8746357394F, 0.8757246489F, + 0.8768078479F, 0.8778853364F, 0.8789571146F, 0.8800231832F, + 0.8810835427F, 0.8821381942F, 0.8831871387F, 0.8842303777F, + 0.8852679127F, 0.8862997456F, 0.8873258784F, 0.8883463132F, + 0.8893610527F, 0.8903700994F, 0.8913734562F, 0.8923711263F, + 0.8933631129F, 0.8943494196F, 0.8953300500F, 0.8963050083F, + 0.8972742985F, 0.8982379249F, 0.8991958922F, 0.9001482052F, + 0.9010948688F, 0.9020358883F, 0.9029712690F, 0.9039010165F, + 0.9048251367F, 0.9057436357F, 0.9066565195F, 0.9075637946F, + 0.9084654678F, 0.9093615456F, 0.9102520353F, 0.9111369440F, + 0.9120162792F, 0.9128900484F, 0.9137582595F, 0.9146209204F, + 0.9154780394F, 0.9163296248F, 0.9171756853F, 0.9180162296F, + 0.9188512667F, 0.9196808057F, 0.9205048559F, 0.9213234270F, + 0.9221365285F, 0.9229441704F, 0.9237463629F, 0.9245431160F, + 0.9253344404F, 0.9261203465F, 0.9269008453F, 0.9276759477F, + 0.9284456648F, 0.9292100080F, 0.9299689889F, 0.9307226190F, + 0.9314709103F, 0.9322138747F, 0.9329515245F, 0.9336838721F, + 0.9344109300F, 0.9351327108F, 0.9358492275F, 0.9365604931F, + 0.9372665208F, 0.9379673239F, 0.9386629160F, 0.9393533107F, + 0.9400385220F, 0.9407185637F, 0.9413934501F, 0.9420631954F, + 0.9427278141F, 0.9433873208F, 0.9440417304F, 0.9446910576F, + 0.9453353176F, 0.9459745255F, 0.9466086968F, 0.9472378469F, + 0.9478619915F, 0.9484811463F, 0.9490953274F, 0.9497045506F, + 0.9503088323F, 0.9509081888F, 0.9515026365F, 0.9520921921F, + 0.9526768723F, 0.9532566940F, 0.9538316742F, 0.9544018300F, + 0.9549671786F, 0.9555277375F, 0.9560835241F, 0.9566345562F, + 0.9571808513F, 0.9577224275F, 0.9582593027F, 0.9587914949F, + 0.9593190225F, 0.9598419038F, 0.9603601571F, 0.9608738012F, + 0.9613828546F, 0.9618873361F, 0.9623872646F, 0.9628826591F, + 0.9633735388F, 0.9638599227F, 0.9643418303F, 0.9648192808F, + 0.9652922939F, 0.9657608890F, 0.9662250860F, 0.9666849046F, + 0.9671403646F, 0.9675914861F, 0.9680382891F, 0.9684807937F, + 0.9689190202F, 0.9693529890F, 0.9697827203F, 0.9702082347F, + 0.9706295529F, 0.9710466953F, 0.9714596828F, 0.9718685362F, + 0.9722732762F, 0.9726739240F, 0.9730705005F, 0.9734630267F, + 0.9738515239F, 0.9742360134F, 0.9746165163F, 0.9749930540F, + 0.9753656481F, 0.9757343198F, 0.9760990909F, 0.9764599829F, + 0.9768170175F, 0.9771702164F, 0.9775196013F, 0.9778651941F, + 0.9782070167F, 0.9785450909F, 0.9788794388F, 0.9792100824F, + 0.9795370437F, 0.9798603449F, 0.9801800080F, 0.9804960554F, + 0.9808085092F, 0.9811173916F, 0.9814227251F, 0.9817245318F, + 0.9820228343F, 0.9823176549F, 0.9826090160F, 0.9828969402F, + 0.9831814498F, 0.9834625674F, 0.9837403156F, 0.9840147169F, + 0.9842857939F, 0.9845535692F, 0.9848180654F, 0.9850793052F, + 0.9853373113F, 0.9855921062F, 0.9858437127F, 0.9860921535F, + 0.9863374512F, 0.9865796287F, 0.9868187085F, 0.9870547136F, + 0.9872876664F, 0.9875175899F, 0.9877445067F, 0.9879684396F, + 0.9881894112F, 0.9884074444F, 0.9886225619F, 0.9888347863F, + 0.9890441404F, 0.9892506468F, 0.9894543284F, 0.9896552077F, + 0.9898533074F, 0.9900486502F, 0.9902412587F, 0.9904311555F, + 0.9906183633F, 0.9908029045F, 0.9909848019F, 0.9911640779F, + 0.9913407550F, 0.9915148557F, 0.9916864025F, 0.9918554179F, + 0.9920219241F, 0.9921859437F, 0.9923474989F, 0.9925066120F, + 0.9926633054F, 0.9928176012F, 0.9929695218F, 0.9931190891F, + 0.9932663254F, 0.9934112527F, 0.9935538932F, 0.9936942686F, + 0.9938324012F, 0.9939683126F, 0.9941020248F, 0.9942335597F, + 0.9943629388F, 0.9944901841F, 0.9946153170F, 0.9947383593F, + 0.9948593325F, 0.9949782579F, 0.9950951572F, 0.9952100516F, + 0.9953229625F, 0.9954339111F, 0.9955429186F, 0.9956500062F, + 0.9957551948F, 0.9958585056F, 0.9959599593F, 0.9960595769F, + 0.9961573792F, 0.9962533869F, 0.9963476206F, 0.9964401009F, + 0.9965308483F, 0.9966198833F, 0.9967072261F, 0.9967928971F, + 0.9968769164F, 0.9969593041F, 0.9970400804F, 0.9971192651F, + 0.9971968781F, 0.9972729391F, 0.9973474680F, 0.9974204842F, + 0.9974920074F, 0.9975620569F, 0.9976306521F, 0.9976978122F, + 0.9977635565F, 0.9978279039F, 0.9978908736F, 0.9979524842F, + 0.9980127547F, 0.9980717037F, 0.9981293499F, 0.9981857116F, + 0.9982408073F, 0.9982946554F, 0.9983472739F, 0.9983986810F, + 0.9984488947F, 0.9984979328F, 0.9985458132F, 0.9985925534F, + 0.9986381711F, 0.9986826838F, 0.9987261086F, 0.9987684630F, + 0.9988097640F, 0.9988500286F, 0.9988892738F, 0.9989275163F, + 0.9989647727F, 0.9990010597F, 0.9990363938F, 0.9990707911F, + 0.9991042679F, 0.9991368404F, 0.9991685244F, 0.9991993358F, + 0.9992292905F, 0.9992584038F, 0.9992866914F, 0.9993141686F, + 0.9993408506F, 0.9993667526F, 0.9993918895F, 0.9994162761F, + 0.9994399273F, 0.9994628576F, 0.9994850815F, 0.9995066133F, + 0.9995274672F, 0.9995476574F, 0.9995671978F, 0.9995861021F, + 0.9996043841F, 0.9996220573F, 0.9996391352F, 0.9996556310F, + 0.9996715579F, 0.9996869288F, 0.9997017568F, 0.9997160543F, + 0.9997298342F, 0.9997431088F, 0.9997558905F, 0.9997681914F, + 0.9997800236F, 0.9997913990F, 0.9998023292F, 0.9998128261F, + 0.9998229009F, 0.9998325650F, 0.9998418296F, 0.9998507058F, + 0.9998592044F, 0.9998673362F, 0.9998751117F, 0.9998825415F, + 0.9998896358F, 0.9998964047F, 0.9999028584F, 0.9999090066F, + 0.9999148590F, 0.9999204253F, 0.9999257148F, 0.9999307368F, + 0.9999355003F, 0.9999400144F, 0.9999442878F, 0.9999483293F, + 0.9999521472F, 0.9999557499F, 0.9999591457F, 0.9999623426F, + 0.9999653483F, 0.9999681708F, 0.9999708175F, 0.9999732959F, + 0.9999756132F, 0.9999777765F, 0.9999797928F, 0.9999816688F, + 0.9999834113F, 0.9999850266F, 0.9999865211F, 0.9999879009F, + 0.9999891721F, 0.9999903405F, 0.9999914118F, 0.9999923914F, + 0.9999932849F, 0.9999940972F, 0.9999948336F, 0.9999954989F, + 0.9999960978F, 0.9999966349F, 0.9999971146F, 0.9999975411F, + 0.9999979185F, 0.9999982507F, 0.9999985414F, 0.9999987944F, + 0.9999990129F, 0.9999992003F, 0.9999993596F, 0.9999994939F, + 0.9999996059F, 0.9999996981F, 0.9999997732F, 0.9999998333F, + 0.9999998805F, 0.9999999170F, 0.9999999444F, 0.9999999643F, + 0.9999999784F, 0.9999999878F, 0.9999999937F, 0.9999999972F, + 0.9999999990F, 0.9999999997F, 1.0000000000F, 1.0000000000F, +}; + +DECLARE_ALIGNED(16, static const float, vwin4096)[2048] = { + 0.0000002310F, 0.0000020791F, 0.0000057754F, 0.0000113197F, + 0.0000187121F, 0.0000279526F, 0.0000390412F, 0.0000519777F, + 0.0000667623F, 0.0000833949F, 0.0001018753F, 0.0001222036F, + 0.0001443798F, 0.0001684037F, 0.0001942754F, 0.0002219947F, + 0.0002515616F, 0.0002829761F, 0.0003162380F, 0.0003513472F, + 0.0003883038F, 0.0004271076F, 0.0004677584F, 0.0005102563F, + 0.0005546011F, 0.0006007928F, 0.0006488311F, 0.0006987160F, + 0.0007504474F, 0.0008040251F, 0.0008594490F, 0.0009167191F, + 0.0009758351F, 0.0010367969F, 0.0010996044F, 0.0011642574F, + 0.0012307558F, 0.0012990994F, 0.0013692880F, 0.0014413216F, + 0.0015151998F, 0.0015909226F, 0.0016684898F, 0.0017479011F, + 0.0018291565F, 0.0019122556F, 0.0019971983F, 0.0020839845F, + 0.0021726138F, 0.0022630861F, 0.0023554012F, 0.0024495588F, + 0.0025455588F, 0.0026434008F, 0.0027430847F, 0.0028446103F, + 0.0029479772F, 0.0030531853F, 0.0031602342F, 0.0032691238F, + 0.0033798538F, 0.0034924239F, 0.0036068338F, 0.0037230833F, + 0.0038411721F, 0.0039610999F, 0.0040828664F, 0.0042064714F, + 0.0043319145F, 0.0044591954F, 0.0045883139F, 0.0047192696F, + 0.0048520622F, 0.0049866914F, 0.0051231569F, 0.0052614583F, + 0.0054015953F, 0.0055435676F, 0.0056873748F, 0.0058330166F, + 0.0059804926F, 0.0061298026F, 0.0062809460F, 0.0064339226F, + 0.0065887320F, 0.0067453738F, 0.0069038476F, 0.0070641531F, + 0.0072262899F, 0.0073902575F, 0.0075560556F, 0.0077236838F, + 0.0078931417F, 0.0080644288F, 0.0082375447F, 0.0084124891F, + 0.0085892615F, 0.0087678614F, 0.0089482885F, 0.0091305422F, + 0.0093146223F, 0.0095005281F, 0.0096882592F, 0.0098778153F, + 0.0100691958F, 0.0102624002F, 0.0104574281F, 0.0106542791F, + 0.0108529525F, 0.0110534480F, 0.0112557651F, 0.0114599032F, + 0.0116658618F, 0.0118736405F, 0.0120832387F, 0.0122946560F, + 0.0125078917F, 0.0127229454F, 0.0129398166F, 0.0131585046F, + 0.0133790090F, 0.0136013292F, 0.0138254647F, 0.0140514149F, + 0.0142791792F, 0.0145087572F, 0.0147401481F, 0.0149733515F, + 0.0152083667F, 0.0154451932F, 0.0156838304F, 0.0159242777F, + 0.0161665345F, 0.0164106001F, 0.0166564741F, 0.0169041557F, + 0.0171536443F, 0.0174049393F, 0.0176580401F, 0.0179129461F, + 0.0181696565F, 0.0184281708F, 0.0186884883F, 0.0189506084F, + 0.0192145303F, 0.0194802535F, 0.0197477772F, 0.0200171008F, + 0.0202882236F, 0.0205611449F, 0.0208358639F, 0.0211123801F, + 0.0213906927F, 0.0216708011F, 0.0219527043F, 0.0222364019F, + 0.0225218930F, 0.0228091769F, 0.0230982529F, 0.0233891203F, + 0.0236817782F, 0.0239762259F, 0.0242724628F, 0.0245704880F, + 0.0248703007F, 0.0251719002F, 0.0254752858F, 0.0257804565F, + 0.0260874117F, 0.0263961506F, 0.0267066722F, 0.0270189760F, + 0.0273330609F, 0.0276489263F, 0.0279665712F, 0.0282859949F, + 0.0286071966F, 0.0289301753F, 0.0292549303F, 0.0295814607F, + 0.0299097656F, 0.0302398442F, 0.0305716957F, 0.0309053191F, + 0.0312407135F, 0.0315778782F, 0.0319168122F, 0.0322575145F, + 0.0325999844F, 0.0329442209F, 0.0332902231F, 0.0336379900F, + 0.0339875208F, 0.0343388146F, 0.0346918703F, 0.0350466871F, + 0.0354032640F, 0.0357616000F, 0.0361216943F, 0.0364835458F, + 0.0368471535F, 0.0372125166F, 0.0375796339F, 0.0379485046F, + 0.0383191276F, 0.0386915020F, 0.0390656267F, 0.0394415008F, + 0.0398191231F, 0.0401984927F, 0.0405796086F, 0.0409624698F, + 0.0413470751F, 0.0417334235F, 0.0421215141F, 0.0425113457F, + 0.0429029172F, 0.0432962277F, 0.0436912760F, 0.0440880610F, + 0.0444865817F, 0.0448868370F, 0.0452888257F, 0.0456925468F, + 0.0460979992F, 0.0465051816F, 0.0469140931F, 0.0473247325F, + 0.0477370986F, 0.0481511902F, 0.0485670064F, 0.0489845458F, + 0.0494038074F, 0.0498247899F, 0.0502474922F, 0.0506719131F, + 0.0510980514F, 0.0515259060F, 0.0519554756F, 0.0523867590F, + 0.0528197550F, 0.0532544624F, 0.0536908800F, 0.0541290066F, + 0.0545688408F, 0.0550103815F, 0.0554536274F, 0.0558985772F, + 0.0563452297F, 0.0567935837F, 0.0572436377F, 0.0576953907F, + 0.0581488412F, 0.0586039880F, 0.0590608297F, 0.0595193651F, + 0.0599795929F, 0.0604415117F, 0.0609051202F, 0.0613704170F, + 0.0618374009F, 0.0623060704F, 0.0627764243F, 0.0632484611F, + 0.0637221795F, 0.0641975781F, 0.0646746555F, 0.0651534104F, + 0.0656338413F, 0.0661159469F, 0.0665997257F, 0.0670851763F, + 0.0675722973F, 0.0680610873F, 0.0685515448F, 0.0690436684F, + 0.0695374567F, 0.0700329081F, 0.0705300213F, 0.0710287947F, + 0.0715292269F, 0.0720313163F, 0.0725350616F, 0.0730404612F, + 0.0735475136F, 0.0740562172F, 0.0745665707F, 0.0750785723F, + 0.0755922207F, 0.0761075143F, 0.0766244515F, 0.0771430307F, + 0.0776632505F, 0.0781851092F, 0.0787086052F, 0.0792337371F, + 0.0797605032F, 0.0802889018F, 0.0808189315F, 0.0813505905F, + 0.0818838773F, 0.0824187903F, 0.0829553277F, 0.0834934881F, + 0.0840332697F, 0.0845746708F, 0.0851176899F, 0.0856623252F, + 0.0862085751F, 0.0867564379F, 0.0873059119F, 0.0878569954F, + 0.0884096867F, 0.0889639840F, 0.0895198858F, 0.0900773902F, + 0.0906364955F, 0.0911972000F, 0.0917595019F, 0.0923233995F, + 0.0928888909F, 0.0934559745F, 0.0940246485F, 0.0945949110F, + 0.0951667604F, 0.0957401946F, 0.0963152121F, 0.0968918109F, + 0.0974699893F, 0.0980497454F, 0.0986310773F, 0.0992139832F, + 0.0997984614F, 0.1003845098F, 0.1009721267F, 0.1015613101F, + 0.1021520582F, 0.1027443692F, 0.1033382410F, 0.1039336718F, + 0.1045306597F, 0.1051292027F, 0.1057292990F, 0.1063309466F, + 0.1069341435F, 0.1075388878F, 0.1081451776F, 0.1087530108F, + 0.1093623856F, 0.1099732998F, 0.1105857516F, 0.1111997389F, + 0.1118152597F, 0.1124323121F, 0.1130508939F, 0.1136710032F, + 0.1142926379F, 0.1149157960F, 0.1155404755F, 0.1161666742F, + 0.1167943901F, 0.1174236211F, 0.1180543652F, 0.1186866202F, + 0.1193203841F, 0.1199556548F, 0.1205924300F, 0.1212307078F, + 0.1218704860F, 0.1225117624F, 0.1231545349F, 0.1237988013F, + 0.1244445596F, 0.1250918074F, 0.1257405427F, 0.1263907632F, + 0.1270424667F, 0.1276956512F, 0.1283503142F, 0.1290064537F, + 0.1296640674F, 0.1303231530F, 0.1309837084F, 0.1316457312F, + 0.1323092193F, 0.1329741703F, 0.1336405820F, 0.1343084520F, + 0.1349777782F, 0.1356485582F, 0.1363207897F, 0.1369944704F, + 0.1376695979F, 0.1383461700F, 0.1390241842F, 0.1397036384F, + 0.1403845300F, 0.1410668567F, 0.1417506162F, 0.1424358061F, + 0.1431224240F, 0.1438104674F, 0.1444999341F, 0.1451908216F, + 0.1458831274F, 0.1465768492F, 0.1472719844F, 0.1479685308F, + 0.1486664857F, 0.1493658468F, 0.1500666115F, 0.1507687775F, + 0.1514723422F, 0.1521773031F, 0.1528836577F, 0.1535914035F, + 0.1543005380F, 0.1550110587F, 0.1557229631F, 0.1564362485F, + 0.1571509124F, 0.1578669524F, 0.1585843657F, 0.1593031499F, + 0.1600233024F, 0.1607448205F, 0.1614677017F, 0.1621919433F, + 0.1629175428F, 0.1636444975F, 0.1643728047F, 0.1651024619F, + 0.1658334665F, 0.1665658156F, 0.1672995067F, 0.1680345371F, + 0.1687709041F, 0.1695086050F, 0.1702476372F, 0.1709879978F, + 0.1717296843F, 0.1724726938F, 0.1732170237F, 0.1739626711F, + 0.1747096335F, 0.1754579079F, 0.1762074916F, 0.1769583819F, + 0.1777105760F, 0.1784640710F, 0.1792188642F, 0.1799749529F, + 0.1807323340F, 0.1814910049F, 0.1822509628F, 0.1830122046F, + 0.1837747277F, 0.1845385292F, 0.1853036062F, 0.1860699558F, + 0.1868375751F, 0.1876064613F, 0.1883766114F, 0.1891480226F, + 0.1899206919F, 0.1906946164F, 0.1914697932F, 0.1922462194F, + 0.1930238919F, 0.1938028079F, 0.1945829643F, 0.1953643583F, + 0.1961469868F, 0.1969308468F, 0.1977159353F, 0.1985022494F, + 0.1992897859F, 0.2000785420F, 0.2008685145F, 0.2016597005F, + 0.2024520968F, 0.2032457005F, 0.2040405084F, 0.2048365175F, + 0.2056337247F, 0.2064321269F, 0.2072317211F, 0.2080325041F, + 0.2088344727F, 0.2096376240F, 0.2104419547F, 0.2112474618F, + 0.2120541420F, 0.2128619923F, 0.2136710094F, 0.2144811902F, + 0.2152925315F, 0.2161050301F, 0.2169186829F, 0.2177334866F, + 0.2185494381F, 0.2193665340F, 0.2201847712F, 0.2210041465F, + 0.2218246565F, 0.2226462981F, 0.2234690680F, 0.2242929629F, + 0.2251179796F, 0.2259441147F, 0.2267713650F, 0.2275997272F, + 0.2284291979F, 0.2292597739F, 0.2300914518F, 0.2309242283F, + 0.2317581001F, 0.2325930638F, 0.2334291160F, 0.2342662534F, + 0.2351044727F, 0.2359437703F, 0.2367841431F, 0.2376255875F, + 0.2384681001F, 0.2393116776F, 0.2401563165F, 0.2410020134F, + 0.2418487649F, 0.2426965675F, 0.2435454178F, 0.2443953122F, + 0.2452462474F, 0.2460982199F, 0.2469512262F, 0.2478052628F, + 0.2486603262F, 0.2495164129F, 0.2503735194F, 0.2512316421F, + 0.2520907776F, 0.2529509222F, 0.2538120726F, 0.2546742250F, + 0.2555373760F, 0.2564015219F, 0.2572666593F, 0.2581327845F, + 0.2589998939F, 0.2598679840F, 0.2607370510F, 0.2616070916F, + 0.2624781019F, 0.2633500783F, 0.2642230173F, 0.2650969152F, + 0.2659717684F, 0.2668475731F, 0.2677243257F, 0.2686020226F, + 0.2694806601F, 0.2703602344F, 0.2712407419F, 0.2721221789F, + 0.2730045417F, 0.2738878265F, 0.2747720297F, 0.2756571474F, + 0.2765431760F, 0.2774301117F, 0.2783179508F, 0.2792066895F, + 0.2800963240F, 0.2809868505F, 0.2818782654F, 0.2827705647F, + 0.2836637447F, 0.2845578016F, 0.2854527315F, 0.2863485307F, + 0.2872451953F, 0.2881427215F, 0.2890411055F, 0.2899403433F, + 0.2908404312F, 0.2917413654F, 0.2926431418F, 0.2935457567F, + 0.2944492061F, 0.2953534863F, 0.2962585932F, 0.2971645230F, + 0.2980712717F, 0.2989788356F, 0.2998872105F, 0.3007963927F, + 0.3017063781F, 0.3026171629F, 0.3035287430F, 0.3044411145F, + 0.3053542736F, 0.3062682161F, 0.3071829381F, 0.3080984356F, + 0.3090147047F, 0.3099317413F, 0.3108495414F, 0.3117681011F, + 0.3126874163F, 0.3136074830F, 0.3145282972F, 0.3154498548F, + 0.3163721517F, 0.3172951841F, 0.3182189477F, 0.3191434385F, + 0.3200686525F, 0.3209945856F, 0.3219212336F, 0.3228485927F, + 0.3237766585F, 0.3247054271F, 0.3256348943F, 0.3265650560F, + 0.3274959081F, 0.3284274465F, 0.3293596671F, 0.3302925657F, + 0.3312261382F, 0.3321603804F, 0.3330952882F, 0.3340308574F, + 0.3349670838F, 0.3359039634F, 0.3368414919F, 0.3377796651F, + 0.3387184789F, 0.3396579290F, 0.3405980113F, 0.3415387216F, + 0.3424800556F, 0.3434220091F, 0.3443645779F, 0.3453077578F, + 0.3462515446F, 0.3471959340F, 0.3481409217F, 0.3490865036F, + 0.3500326754F, 0.3509794328F, 0.3519267715F, 0.3528746873F, + 0.3538231759F, 0.3547722330F, 0.3557218544F, 0.3566720357F, + 0.3576227727F, 0.3585740610F, 0.3595258964F, 0.3604782745F, + 0.3614311910F, 0.3623846417F, 0.3633386221F, 0.3642931280F, + 0.3652481549F, 0.3662036987F, 0.3671597548F, 0.3681163191F, + 0.3690733870F, 0.3700309544F, 0.3709890167F, 0.3719475696F, + 0.3729066089F, 0.3738661299F, 0.3748261285F, 0.3757866002F, + 0.3767475406F, 0.3777089453F, 0.3786708100F, 0.3796331302F, + 0.3805959014F, 0.3815591194F, 0.3825227796F, 0.3834868777F, + 0.3844514093F, 0.3854163698F, 0.3863817549F, 0.3873475601F, + 0.3883137810F, 0.3892804131F, 0.3902474521F, 0.3912148933F, + 0.3921827325F, 0.3931509650F, 0.3941195865F, 0.3950885925F, + 0.3960579785F, 0.3970277400F, 0.3979978725F, 0.3989683716F, + 0.3999392328F, 0.4009104516F, 0.4018820234F, 0.4028539438F, + 0.4038262084F, 0.4047988125F, 0.4057717516F, 0.4067450214F, + 0.4077186172F, 0.4086925345F, 0.4096667688F, 0.4106413155F, + 0.4116161703F, 0.4125913284F, 0.4135667854F, 0.4145425368F, + 0.4155185780F, 0.4164949044F, 0.4174715116F, 0.4184483949F, + 0.4194255498F, 0.4204029718F, 0.4213806563F, 0.4223585987F, + 0.4233367946F, 0.4243152392F, 0.4252939281F, 0.4262728566F, + 0.4272520202F, 0.4282314144F, 0.4292110345F, 0.4301908760F, + 0.4311709343F, 0.4321512047F, 0.4331316828F, 0.4341123639F, + 0.4350932435F, 0.4360743168F, 0.4370555794F, 0.4380370267F, + 0.4390186540F, 0.4400004567F, 0.4409824303F, 0.4419645701F, + 0.4429468716F, 0.4439293300F, 0.4449119409F, 0.4458946996F, + 0.4468776014F, 0.4478606418F, 0.4488438162F, 0.4498271199F, + 0.4508105483F, 0.4517940967F, 0.4527777607F, 0.4537615355F, + 0.4547454165F, 0.4557293991F, 0.4567134786F, 0.4576976505F, + 0.4586819101F, 0.4596662527F, 0.4606506738F, 0.4616351687F, + 0.4626197328F, 0.4636043614F, 0.4645890499F, 0.4655737936F, + 0.4665585880F, 0.4675434284F, 0.4685283101F, 0.4695132286F, + 0.4704981791F, 0.4714831570F, 0.4724681577F, 0.4734531766F, + 0.4744382089F, 0.4754232501F, 0.4764082956F, 0.4773933406F, + 0.4783783806F, 0.4793634108F, 0.4803484267F, 0.4813334237F, + 0.4823183969F, 0.4833033419F, 0.4842882540F, 0.4852731285F, + 0.4862579608F, 0.4872427462F, 0.4882274802F, 0.4892121580F, + 0.4901967751F, 0.4911813267F, 0.4921658083F, 0.4931502151F, + 0.4941345427F, 0.4951187863F, 0.4961029412F, 0.4970870029F, + 0.4980709667F, 0.4990548280F, 0.5000385822F, 0.5010222245F, + 0.5020057505F, 0.5029891553F, 0.5039724345F, 0.5049555834F, + 0.5059385973F, 0.5069214716F, 0.5079042018F, 0.5088867831F, + 0.5098692110F, 0.5108514808F, 0.5118335879F, 0.5128155277F, + 0.5137972956F, 0.5147788869F, 0.5157602971F, 0.5167415215F, + 0.5177225555F, 0.5187033945F, 0.5196840339F, 0.5206644692F, + 0.5216446956F, 0.5226247086F, 0.5236045035F, 0.5245840759F, + 0.5255634211F, 0.5265425344F, 0.5275214114F, 0.5285000474F, + 0.5294784378F, 0.5304565781F, 0.5314344637F, 0.5324120899F, + 0.5333894522F, 0.5343665461F, 0.5353433670F, 0.5363199102F, + 0.5372961713F, 0.5382721457F, 0.5392478287F, 0.5402232159F, + 0.5411983027F, 0.5421730845F, 0.5431475569F, 0.5441217151F, + 0.5450955548F, 0.5460690714F, 0.5470422602F, 0.5480151169F, + 0.5489876368F, 0.5499598155F, 0.5509316484F, 0.5519031310F, + 0.5528742587F, 0.5538450271F, 0.5548154317F, 0.5557854680F, + 0.5567551314F, 0.5577244174F, 0.5586933216F, 0.5596618395F, + 0.5606299665F, 0.5615976983F, 0.5625650302F, 0.5635319580F, + 0.5644984770F, 0.5654645828F, 0.5664302709F, 0.5673955370F, + 0.5683603765F, 0.5693247850F, 0.5702887580F, 0.5712522912F, + 0.5722153800F, 0.5731780200F, 0.5741402069F, 0.5751019362F, + 0.5760632034F, 0.5770240042F, 0.5779843341F, 0.5789441889F, + 0.5799035639F, 0.5808624549F, 0.5818208575F, 0.5827787673F, + 0.5837361800F, 0.5846930910F, 0.5856494961F, 0.5866053910F, + 0.5875607712F, 0.5885156324F, 0.5894699703F, 0.5904237804F, + 0.5913770586F, 0.5923298004F, 0.5932820016F, 0.5942336578F, + 0.5951847646F, 0.5961353179F, 0.5970853132F, 0.5980347464F, + 0.5989836131F, 0.5999319090F, 0.6008796298F, 0.6018267713F, + 0.6027733292F, 0.6037192993F, 0.6046646773F, 0.6056094589F, + 0.6065536400F, 0.6074972162F, 0.6084401833F, 0.6093825372F, + 0.6103242736F, 0.6112653884F, 0.6122058772F, 0.6131457359F, + 0.6140849604F, 0.6150235464F, 0.6159614897F, 0.6168987862F, + 0.6178354318F, 0.6187714223F, 0.6197067535F, 0.6206414213F, + 0.6215754215F, 0.6225087501F, 0.6234414028F, 0.6243733757F, + 0.6253046646F, 0.6262352654F, 0.6271651739F, 0.6280943862F, + 0.6290228982F, 0.6299507057F, 0.6308778048F, 0.6318041913F, + 0.6327298612F, 0.6336548105F, 0.6345790352F, 0.6355025312F, + 0.6364252945F, 0.6373473211F, 0.6382686070F, 0.6391891483F, + 0.6401089409F, 0.6410279808F, 0.6419462642F, 0.6428637869F, + 0.6437805452F, 0.6446965350F, 0.6456117524F, 0.6465261935F, + 0.6474398544F, 0.6483527311F, 0.6492648197F, 0.6501761165F, + 0.6510866174F, 0.6519963186F, 0.6529052162F, 0.6538133064F, + 0.6547205854F, 0.6556270492F, 0.6565326941F, 0.6574375162F, + 0.6583415117F, 0.6592446769F, 0.6601470079F, 0.6610485009F, + 0.6619491521F, 0.6628489578F, 0.6637479143F, 0.6646460177F, + 0.6655432643F, 0.6664396505F, 0.6673351724F, 0.6682298264F, + 0.6691236087F, 0.6700165157F, 0.6709085436F, 0.6717996889F, + 0.6726899478F, 0.6735793167F, 0.6744677918F, 0.6753553697F, + 0.6762420466F, 0.6771278190F, 0.6780126832F, 0.6788966357F, + 0.6797796728F, 0.6806617909F, 0.6815429866F, 0.6824232562F, + 0.6833025961F, 0.6841810030F, 0.6850584731F, 0.6859350031F, + 0.6868105894F, 0.6876852284F, 0.6885589168F, 0.6894316510F, + 0.6903034275F, 0.6911742430F, 0.6920440939F, 0.6929129769F, + 0.6937808884F, 0.6946478251F, 0.6955137837F, 0.6963787606F, + 0.6972427525F, 0.6981057560F, 0.6989677678F, 0.6998287845F, + 0.7006888028F, 0.7015478194F, 0.7024058309F, 0.7032628340F, + 0.7041188254F, 0.7049738019F, 0.7058277601F, 0.7066806969F, + 0.7075326089F, 0.7083834929F, 0.7092333457F, 0.7100821640F, + 0.7109299447F, 0.7117766846F, 0.7126223804F, 0.7134670291F, + 0.7143106273F, 0.7151531721F, 0.7159946602F, 0.7168350885F, + 0.7176744539F, 0.7185127534F, 0.7193499837F, 0.7201861418F, + 0.7210212247F, 0.7218552293F, 0.7226881526F, 0.7235199914F, + 0.7243507428F, 0.7251804039F, 0.7260089715F, 0.7268364426F, + 0.7276628144F, 0.7284880839F, 0.7293122481F, 0.7301353040F, + 0.7309572487F, 0.7317780794F, 0.7325977930F, 0.7334163868F, + 0.7342338579F, 0.7350502033F, 0.7358654202F, 0.7366795059F, + 0.7374924573F, 0.7383042718F, 0.7391149465F, 0.7399244787F, + 0.7407328655F, 0.7415401041F, 0.7423461920F, 0.7431511261F, + 0.7439549040F, 0.7447575227F, 0.7455589797F, 0.7463592723F, + 0.7471583976F, 0.7479563532F, 0.7487531363F, 0.7495487443F, + 0.7503431745F, 0.7511364244F, 0.7519284913F, 0.7527193726F, + 0.7535090658F, 0.7542975683F, 0.7550848776F, 0.7558709910F, + 0.7566559062F, 0.7574396205F, 0.7582221314F, 0.7590034366F, + 0.7597835334F, 0.7605624194F, 0.7613400923F, 0.7621165495F, + 0.7628917886F, 0.7636658072F, 0.7644386030F, 0.7652101735F, + 0.7659805164F, 0.7667496292F, 0.7675175098F, 0.7682841556F, + 0.7690495645F, 0.7698137341F, 0.7705766622F, 0.7713383463F, + 0.7720987844F, 0.7728579741F, 0.7736159132F, 0.7743725994F, + 0.7751280306F, 0.7758822046F, 0.7766351192F, 0.7773867722F, + 0.7781371614F, 0.7788862848F, 0.7796341401F, 0.7803807253F, + 0.7811260383F, 0.7818700769F, 0.7826128392F, 0.7833543230F, + 0.7840945263F, 0.7848334471F, 0.7855710833F, 0.7863074330F, + 0.7870424941F, 0.7877762647F, 0.7885087428F, 0.7892399264F, + 0.7899698137F, 0.7906984026F, 0.7914256914F, 0.7921516780F, + 0.7928763607F, 0.7935997375F, 0.7943218065F, 0.7950425661F, + 0.7957620142F, 0.7964801492F, 0.7971969692F, 0.7979124724F, + 0.7986266570F, 0.7993395214F, 0.8000510638F, 0.8007612823F, + 0.8014701754F, 0.8021777413F, 0.8028839784F, 0.8035888849F, + 0.8042924592F, 0.8049946997F, 0.8056956048F, 0.8063951727F, + 0.8070934020F, 0.8077902910F, 0.8084858381F, 0.8091800419F, + 0.8098729007F, 0.8105644130F, 0.8112545774F, 0.8119433922F, + 0.8126308561F, 0.8133169676F, 0.8140017251F, 0.8146851272F, + 0.8153671726F, 0.8160478598F, 0.8167271874F, 0.8174051539F, + 0.8180817582F, 0.8187569986F, 0.8194308741F, 0.8201033831F, + 0.8207745244F, 0.8214442966F, 0.8221126986F, 0.8227797290F, + 0.8234453865F, 0.8241096700F, 0.8247725781F, 0.8254341097F, + 0.8260942636F, 0.8267530385F, 0.8274104334F, 0.8280664470F, + 0.8287210782F, 0.8293743259F, 0.8300261889F, 0.8306766662F, + 0.8313257566F, 0.8319734591F, 0.8326197727F, 0.8332646963F, + 0.8339082288F, 0.8345503692F, 0.8351911167F, 0.8358304700F, + 0.8364684284F, 0.8371049907F, 0.8377401562F, 0.8383739238F, + 0.8390062927F, 0.8396372618F, 0.8402668305F, 0.8408949977F, + 0.8415217626F, 0.8421471245F, 0.8427710823F, 0.8433936354F, + 0.8440147830F, 0.8446345242F, 0.8452528582F, 0.8458697844F, + 0.8464853020F, 0.8470994102F, 0.8477121084F, 0.8483233958F, + 0.8489332718F, 0.8495417356F, 0.8501487866F, 0.8507544243F, + 0.8513586479F, 0.8519614568F, 0.8525628505F, 0.8531628283F, + 0.8537613897F, 0.8543585341F, 0.8549542611F, 0.8555485699F, + 0.8561414603F, 0.8567329315F, 0.8573229832F, 0.8579116149F, + 0.8584988262F, 0.8590846165F, 0.8596689855F, 0.8602519327F, + 0.8608334577F, 0.8614135603F, 0.8619922399F, 0.8625694962F, + 0.8631453289F, 0.8637197377F, 0.8642927222F, 0.8648642821F, + 0.8654344172F, 0.8660031272F, 0.8665704118F, 0.8671362708F, + 0.8677007039F, 0.8682637109F, 0.8688252917F, 0.8693854460F, + 0.8699441737F, 0.8705014745F, 0.8710573485F, 0.8716117953F, + 0.8721648150F, 0.8727164073F, 0.8732665723F, 0.8738153098F, + 0.8743626197F, 0.8749085021F, 0.8754529569F, 0.8759959840F, + 0.8765375835F, 0.8770777553F, 0.8776164996F, 0.8781538162F, + 0.8786897054F, 0.8792241670F, 0.8797572013F, 0.8802888082F, + 0.8808189880F, 0.8813477407F, 0.8818750664F, 0.8824009653F, + 0.8829254375F, 0.8834484833F, 0.8839701028F, 0.8844902961F, + 0.8850090636F, 0.8855264054F, 0.8860423218F, 0.8865568131F, + 0.8870698794F, 0.8875815212F, 0.8880917386F, 0.8886005319F, + 0.8891079016F, 0.8896138479F, 0.8901183712F, 0.8906214719F, + 0.8911231503F, 0.8916234067F, 0.8921222417F, 0.8926196556F, + 0.8931156489F, 0.8936102219F, 0.8941033752F, 0.8945951092F, + 0.8950854244F, 0.8955743212F, 0.8960618003F, 0.8965478621F, + 0.8970325071F, 0.8975157359F, 0.8979975490F, 0.8984779471F, + 0.8989569307F, 0.8994345004F, 0.8999106568F, 0.9003854005F, + 0.9008587323F, 0.9013306526F, 0.9018011623F, 0.9022702619F, + 0.9027379521F, 0.9032042337F, 0.9036691074F, 0.9041325739F, + 0.9045946339F, 0.9050552882F, 0.9055145376F, 0.9059723828F, + 0.9064288246F, 0.9068838638F, 0.9073375013F, 0.9077897379F, + 0.9082405743F, 0.9086900115F, 0.9091380503F, 0.9095846917F, + 0.9100299364F, 0.9104737854F, 0.9109162397F, 0.9113573001F, + 0.9117969675F, 0.9122352430F, 0.9126721275F, 0.9131076219F, + 0.9135417273F, 0.9139744447F, 0.9144057750F, 0.9148357194F, + 0.9152642787F, 0.9156914542F, 0.9161172468F, 0.9165416576F, + 0.9169646877F, 0.9173863382F, 0.9178066102F, 0.9182255048F, + 0.9186430232F, 0.9190591665F, 0.9194739359F, 0.9198873324F, + 0.9202993574F, 0.9207100120F, 0.9211192973F, 0.9215272147F, + 0.9219337653F, 0.9223389504F, 0.9227427713F, 0.9231452290F, + 0.9235463251F, 0.9239460607F, 0.9243444371F, 0.9247414557F, + 0.9251371177F, 0.9255314245F, 0.9259243774F, 0.9263159778F, + 0.9267062270F, 0.9270951264F, 0.9274826774F, 0.9278688814F, + 0.9282537398F, 0.9286372540F, 0.9290194254F, 0.9294002555F, + 0.9297797458F, 0.9301578976F, 0.9305347125F, 0.9309101919F, + 0.9312843373F, 0.9316571503F, 0.9320286323F, 0.9323987849F, + 0.9327676097F, 0.9331351080F, 0.9335012816F, 0.9338661320F, + 0.9342296607F, 0.9345918694F, 0.9349527596F, 0.9353123330F, + 0.9356705911F, 0.9360275357F, 0.9363831683F, 0.9367374905F, + 0.9370905042F, 0.9374422108F, 0.9377926122F, 0.9381417099F, + 0.9384895057F, 0.9388360014F, 0.9391811985F, 0.9395250989F, + 0.9398677043F, 0.9402090165F, 0.9405490371F, 0.9408877680F, + 0.9412252110F, 0.9415613678F, 0.9418962402F, 0.9422298301F, + 0.9425621392F, 0.9428931695F, 0.9432229226F, 0.9435514005F, + 0.9438786050F, 0.9442045381F, 0.9445292014F, 0.9448525971F, + 0.9451747268F, 0.9454955926F, 0.9458151963F, 0.9461335399F, + 0.9464506253F, 0.9467664545F, 0.9470810293F, 0.9473943517F, + 0.9477064238F, 0.9480172474F, 0.9483268246F, 0.9486351573F, + 0.9489422475F, 0.9492480973F, 0.9495527087F, 0.9498560837F, + 0.9501582243F, 0.9504591325F, 0.9507588105F, 0.9510572603F, + 0.9513544839F, 0.9516504834F, 0.9519452609F, 0.9522388186F, + 0.9525311584F, 0.9528222826F, 0.9531121932F, 0.9534008923F, + 0.9536883821F, 0.9539746647F, 0.9542597424F, 0.9545436171F, + 0.9548262912F, 0.9551077667F, 0.9553880459F, 0.9556671309F, + 0.9559450239F, 0.9562217272F, 0.9564972429F, 0.9567715733F, + 0.9570447206F, 0.9573166871F, 0.9575874749F, 0.9578570863F, + 0.9581255236F, 0.9583927890F, 0.9586588849F, 0.9589238134F, + 0.9591875769F, 0.9594501777F, 0.9597116180F, 0.9599719003F, + 0.9602310267F, 0.9604889995F, 0.9607458213F, 0.9610014942F, + 0.9612560206F, 0.9615094028F, 0.9617616433F, 0.9620127443F, + 0.9622627083F, 0.9625115376F, 0.9627592345F, 0.9630058016F, + 0.9632512411F, 0.9634955555F, 0.9637387471F, 0.9639808185F, + 0.9642217720F, 0.9644616100F, 0.9647003349F, 0.9649379493F, + 0.9651744556F, 0.9654098561F, 0.9656441534F, 0.9658773499F, + 0.9661094480F, 0.9663404504F, 0.9665703593F, 0.9667991774F, + 0.9670269071F, 0.9672535509F, 0.9674791114F, 0.9677035909F, + 0.9679269921F, 0.9681493174F, 0.9683705694F, 0.9685907506F, + 0.9688098636F, 0.9690279108F, 0.9692448948F, 0.9694608182F, + 0.9696756836F, 0.9698894934F, 0.9701022503F, 0.9703139569F, + 0.9705246156F, 0.9707342291F, 0.9709428000F, 0.9711503309F, + 0.9713568243F, 0.9715622829F, 0.9717667093F, 0.9719701060F, + 0.9721724757F, 0.9723738210F, 0.9725741446F, 0.9727734490F, + 0.9729717369F, 0.9731690109F, 0.9733652737F, 0.9735605279F, + 0.9737547762F, 0.9739480212F, 0.9741402656F, 0.9743315120F, + 0.9745217631F, 0.9747110216F, 0.9748992901F, 0.9750865714F, + 0.9752728681F, 0.9754581829F, 0.9756425184F, 0.9758258775F, + 0.9760082627F, 0.9761896768F, 0.9763701224F, 0.9765496024F, + 0.9767281193F, 0.9769056760F, 0.9770822751F, 0.9772579193F, + 0.9774326114F, 0.9776063542F, 0.9777791502F, 0.9779510023F, + 0.9781219133F, 0.9782918858F, 0.9784609226F, 0.9786290264F, + 0.9787962000F, 0.9789624461F, 0.9791277676F, 0.9792921671F, + 0.9794556474F, 0.9796182113F, 0.9797798615F, 0.9799406009F, + 0.9801004321F, 0.9802593580F, 0.9804173813F, 0.9805745049F, + 0.9807307314F, 0.9808860637F, 0.9810405046F, 0.9811940568F, + 0.9813467232F, 0.9814985065F, 0.9816494095F, 0.9817994351F, + 0.9819485860F, 0.9820968650F, 0.9822442750F, 0.9823908186F, + 0.9825364988F, 0.9826813184F, 0.9828252801F, 0.9829683868F, + 0.9831106413F, 0.9832520463F, 0.9833926048F, 0.9835323195F, + 0.9836711932F, 0.9838092288F, 0.9839464291F, 0.9840827969F, + 0.9842183351F, 0.9843530464F, 0.9844869337F, 0.9846199998F, + 0.9847522475F, 0.9848836798F, 0.9850142993F, 0.9851441090F, + 0.9852731117F, 0.9854013101F, 0.9855287073F, 0.9856553058F, + 0.9857811087F, 0.9859061188F, 0.9860303388F, 0.9861537717F, + 0.9862764202F, 0.9863982872F, 0.9865193756F, 0.9866396882F, + 0.9867592277F, 0.9868779972F, 0.9869959993F, 0.9871132370F, + 0.9872297131F, 0.9873454304F, 0.9874603918F, 0.9875746001F, + 0.9876880581F, 0.9878007688F, 0.9879127348F, 0.9880239592F, + 0.9881344447F, 0.9882441941F, 0.9883532104F, 0.9884614962F, + 0.9885690546F, 0.9886758883F, 0.9887820001F, 0.9888873930F, + 0.9889920697F, 0.9890960331F, 0.9891992859F, 0.9893018312F, + 0.9894036716F, 0.9895048100F, 0.9896052493F, 0.9897049923F, + 0.9898040418F, 0.9899024006F, 0.9900000717F, 0.9900970577F, + 0.9901933616F, 0.9902889862F, 0.9903839343F, 0.9904782087F, + 0.9905718122F, 0.9906647477F, 0.9907570180F, 0.9908486259F, + 0.9909395742F, 0.9910298658F, 0.9911195034F, 0.9912084899F, + 0.9912968281F, 0.9913845208F, 0.9914715708F, 0.9915579810F, + 0.9916437540F, 0.9917288928F, 0.9918134001F, 0.9918972788F, + 0.9919805316F, 0.9920631613F, 0.9921451707F, 0.9922265626F, + 0.9923073399F, 0.9923875052F, 0.9924670615F, 0.9925460114F, + 0.9926243577F, 0.9927021033F, 0.9927792508F, 0.9928558032F, + 0.9929317631F, 0.9930071333F, 0.9930819167F, 0.9931561158F, + 0.9932297337F, 0.9933027728F, 0.9933752362F, 0.9934471264F, + 0.9935184462F, 0.9935891985F, 0.9936593859F, 0.9937290112F, + 0.9937980771F, 0.9938665864F, 0.9939345418F, 0.9940019460F, + 0.9940688018F, 0.9941351118F, 0.9942008789F, 0.9942661057F, + 0.9943307950F, 0.9943949494F, 0.9944585717F, 0.9945216645F, + 0.9945842307F, 0.9946462728F, 0.9947077936F, 0.9947687957F, + 0.9948292820F, 0.9948892550F, 0.9949487174F, 0.9950076719F, + 0.9950661212F, 0.9951240679F, 0.9951815148F, 0.9952384645F, + 0.9952949196F, 0.9953508828F, 0.9954063568F, 0.9954613442F, + 0.9955158476F, 0.9955698697F, 0.9956234132F, 0.9956764806F, + 0.9957290746F, 0.9957811978F, 0.9958328528F, 0.9958840423F, + 0.9959347688F, 0.9959850351F, 0.9960348435F, 0.9960841969F, + 0.9961330977F, 0.9961815486F, 0.9962295521F, 0.9962771108F, + 0.9963242274F, 0.9963709043F, 0.9964171441F, 0.9964629494F, + 0.9965083228F, 0.9965532668F, 0.9965977840F, 0.9966418768F, + 0.9966855479F, 0.9967287998F, 0.9967716350F, 0.9968140559F, + 0.9968560653F, 0.9968976655F, 0.9969388591F, 0.9969796485F, + 0.9970200363F, 0.9970600250F, 0.9970996170F, 0.9971388149F, + 0.9971776211F, 0.9972160380F, 0.9972540683F, 0.9972917142F, + 0.9973289783F, 0.9973658631F, 0.9974023709F, 0.9974385042F, + 0.9974742655F, 0.9975096571F, 0.9975446816F, 0.9975793413F, + 0.9976136386F, 0.9976475759F, 0.9976811557F, 0.9977143803F, + 0.9977472521F, 0.9977797736F, 0.9978119470F, 0.9978437748F, + 0.9978752593F, 0.9979064029F, 0.9979372079F, 0.9979676768F, + 0.9979978117F, 0.9980276151F, 0.9980570893F, 0.9980862367F, + 0.9981150595F, 0.9981435600F, 0.9981717406F, 0.9981996035F, + 0.9982271511F, 0.9982543856F, 0.9982813093F, 0.9983079246F, + 0.9983342336F, 0.9983602386F, 0.9983859418F, 0.9984113456F, + 0.9984364522F, 0.9984612638F, 0.9984857825F, 0.9985100108F, + 0.9985339507F, 0.9985576044F, 0.9985809743F, 0.9986040624F, + 0.9986268710F, 0.9986494022F, 0.9986716583F, 0.9986936413F, + 0.9987153535F, 0.9987367969F, 0.9987579738F, 0.9987788864F, + 0.9987995366F, 0.9988199267F, 0.9988400587F, 0.9988599348F, + 0.9988795572F, 0.9988989278F, 0.9989180487F, 0.9989369222F, + 0.9989555501F, 0.9989739347F, 0.9989920780F, 0.9990099820F, + 0.9990276487F, 0.9990450803F, 0.9990622787F, 0.9990792460F, + 0.9990959841F, 0.9991124952F, 0.9991287812F, 0.9991448440F, + 0.9991606858F, 0.9991763084F, 0.9991917139F, 0.9992069042F, + 0.9992218813F, 0.9992366471F, 0.9992512035F, 0.9992655525F, + 0.9992796961F, 0.9992936361F, 0.9993073744F, 0.9993209131F, + 0.9993342538F, 0.9993473987F, 0.9993603494F, 0.9993731080F, + 0.9993856762F, 0.9993980559F, 0.9994102490F, 0.9994222573F, + 0.9994340827F, 0.9994457269F, 0.9994571918F, 0.9994684793F, + 0.9994795910F, 0.9994905288F, 0.9995012945F, 0.9995118898F, + 0.9995223165F, 0.9995325765F, 0.9995426713F, 0.9995526029F, + 0.9995623728F, 0.9995719829F, 0.9995814349F, 0.9995907304F, + 0.9995998712F, 0.9996088590F, 0.9996176954F, 0.9996263821F, + 0.9996349208F, 0.9996433132F, 0.9996515609F, 0.9996596656F, + 0.9996676288F, 0.9996754522F, 0.9996831375F, 0.9996906862F, + 0.9996981000F, 0.9997053804F, 0.9997125290F, 0.9997195474F, + 0.9997264371F, 0.9997331998F, 0.9997398369F, 0.9997463500F, + 0.9997527406F, 0.9997590103F, 0.9997651606F, 0.9997711930F, + 0.9997771089F, 0.9997829098F, 0.9997885973F, 0.9997941728F, + 0.9997996378F, 0.9998049936F, 0.9998102419F, 0.9998153839F, + 0.9998204211F, 0.9998253550F, 0.9998301868F, 0.9998349182F, + 0.9998395503F, 0.9998440847F, 0.9998485226F, 0.9998528654F, + 0.9998571146F, 0.9998612713F, 0.9998653370F, 0.9998693130F, + 0.9998732007F, 0.9998770012F, 0.9998807159F, 0.9998843461F, + 0.9998878931F, 0.9998913581F, 0.9998947424F, 0.9998980473F, + 0.9999012740F, 0.9999044237F, 0.9999074976F, 0.9999104971F, + 0.9999134231F, 0.9999162771F, 0.9999190601F, 0.9999217733F, + 0.9999244179F, 0.9999269950F, 0.9999295058F, 0.9999319515F, + 0.9999343332F, 0.9999366519F, 0.9999389088F, 0.9999411050F, + 0.9999432416F, 0.9999453196F, 0.9999473402F, 0.9999493044F, + 0.9999512132F, 0.9999530677F, 0.9999548690F, 0.9999566180F, + 0.9999583157F, 0.9999599633F, 0.9999615616F, 0.9999631116F, + 0.9999646144F, 0.9999660709F, 0.9999674820F, 0.9999688487F, + 0.9999701719F, 0.9999714526F, 0.9999726917F, 0.9999738900F, + 0.9999750486F, 0.9999761682F, 0.9999772497F, 0.9999782941F, + 0.9999793021F, 0.9999802747F, 0.9999812126F, 0.9999821167F, + 0.9999829878F, 0.9999838268F, 0.9999846343F, 0.9999854113F, + 0.9999861584F, 0.9999868765F, 0.9999875664F, 0.9999882287F, + 0.9999888642F, 0.9999894736F, 0.9999900577F, 0.9999906172F, + 0.9999911528F, 0.9999916651F, 0.9999921548F, 0.9999926227F, + 0.9999930693F, 0.9999934954F, 0.9999939015F, 0.9999942883F, + 0.9999946564F, 0.9999950064F, 0.9999953390F, 0.9999956547F, + 0.9999959541F, 0.9999962377F, 0.9999965062F, 0.9999967601F, + 0.9999969998F, 0.9999972260F, 0.9999974392F, 0.9999976399F, + 0.9999978285F, 0.9999980056F, 0.9999981716F, 0.9999983271F, + 0.9999984724F, 0.9999986081F, 0.9999987345F, 0.9999988521F, + 0.9999989613F, 0.9999990625F, 0.9999991562F, 0.9999992426F, + 0.9999993223F, 0.9999993954F, 0.9999994625F, 0.9999995239F, + 0.9999995798F, 0.9999996307F, 0.9999996768F, 0.9999997184F, + 0.9999997559F, 0.9999997895F, 0.9999998195F, 0.9999998462F, + 0.9999998698F, 0.9999998906F, 0.9999999088F, 0.9999999246F, + 0.9999999383F, 0.9999999500F, 0.9999999600F, 0.9999999684F, + 0.9999999754F, 0.9999999811F, 0.9999999858F, 0.9999999896F, + 0.9999999925F, 0.9999999948F, 0.9999999965F, 0.9999999978F, + 0.9999999986F, 0.9999999992F, 0.9999999996F, 0.9999999998F, + 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F, +}; + +DECLARE_ALIGNED(16, static const float, vwin8192)[4096] = { + 0.0000000578F, 0.0000005198F, 0.0000014438F, 0.0000028299F, + 0.0000046780F, 0.0000069882F, 0.0000097604F, 0.0000129945F, + 0.0000166908F, 0.0000208490F, 0.0000254692F, 0.0000305515F, + 0.0000360958F, 0.0000421021F, 0.0000485704F, 0.0000555006F, + 0.0000628929F, 0.0000707472F, 0.0000790635F, 0.0000878417F, + 0.0000970820F, 0.0001067842F, 0.0001169483F, 0.0001275744F, + 0.0001386625F, 0.0001502126F, 0.0001622245F, 0.0001746984F, + 0.0001876343F, 0.0002010320F, 0.0002148917F, 0.0002292132F, + 0.0002439967F, 0.0002592421F, 0.0002749493F, 0.0002911184F, + 0.0003077493F, 0.0003248421F, 0.0003423967F, 0.0003604132F, + 0.0003788915F, 0.0003978316F, 0.0004172335F, 0.0004370971F, + 0.0004574226F, 0.0004782098F, 0.0004994587F, 0.0005211694F, + 0.0005433418F, 0.0005659759F, 0.0005890717F, 0.0006126292F, + 0.0006366484F, 0.0006611292F, 0.0006860716F, 0.0007114757F, + 0.0007373414F, 0.0007636687F, 0.0007904576F, 0.0008177080F, + 0.0008454200F, 0.0008735935F, 0.0009022285F, 0.0009313250F, + 0.0009608830F, 0.0009909025F, 0.0010213834F, 0.0010523257F, + 0.0010837295F, 0.0011155946F, 0.0011479211F, 0.0011807090F, + 0.0012139582F, 0.0012476687F, 0.0012818405F, 0.0013164736F, + 0.0013515679F, 0.0013871235F, 0.0014231402F, 0.0014596182F, + 0.0014965573F, 0.0015339576F, 0.0015718190F, 0.0016101415F, + 0.0016489251F, 0.0016881698F, 0.0017278754F, 0.0017680421F, + 0.0018086698F, 0.0018497584F, 0.0018913080F, 0.0019333185F, + 0.0019757898F, 0.0020187221F, 0.0020621151F, 0.0021059690F, + 0.0021502837F, 0.0021950591F, 0.0022402953F, 0.0022859921F, + 0.0023321497F, 0.0023787679F, 0.0024258467F, 0.0024733861F, + 0.0025213861F, 0.0025698466F, 0.0026187676F, 0.0026681491F, + 0.0027179911F, 0.0027682935F, 0.0028190562F, 0.0028702794F, + 0.0029219628F, 0.0029741066F, 0.0030267107F, 0.0030797749F, + 0.0031332994F, 0.0031872841F, 0.0032417289F, 0.0032966338F, + 0.0033519988F, 0.0034078238F, 0.0034641089F, 0.0035208539F, + 0.0035780589F, 0.0036357237F, 0.0036938485F, 0.0037524331F, + 0.0038114775F, 0.0038709817F, 0.0039309456F, 0.0039913692F, + 0.0040522524F, 0.0041135953F, 0.0041753978F, 0.0042376599F, + 0.0043003814F, 0.0043635624F, 0.0044272029F, 0.0044913028F, + 0.0045558620F, 0.0046208806F, 0.0046863585F, 0.0047522955F, + 0.0048186919F, 0.0048855473F, 0.0049528619F, 0.0050206356F, + 0.0050888684F, 0.0051575601F, 0.0052267108F, 0.0052963204F, + 0.0053663890F, 0.0054369163F, 0.0055079025F, 0.0055793474F, + 0.0056512510F, 0.0057236133F, 0.0057964342F, 0.0058697137F, + 0.0059434517F, 0.0060176482F, 0.0060923032F, 0.0061674166F, + 0.0062429883F, 0.0063190183F, 0.0063955066F, 0.0064724532F, + 0.0065498579F, 0.0066277207F, 0.0067060416F, 0.0067848205F, + 0.0068640575F, 0.0069437523F, 0.0070239051F, 0.0071045157F, + 0.0071855840F, 0.0072671102F, 0.0073490940F, 0.0074315355F, + 0.0075144345F, 0.0075977911F, 0.0076816052F, 0.0077658768F, + 0.0078506057F, 0.0079357920F, 0.0080214355F, 0.0081075363F, + 0.0081940943F, 0.0082811094F, 0.0083685816F, 0.0084565108F, + 0.0085448970F, 0.0086337401F, 0.0087230401F, 0.0088127969F, + 0.0089030104F, 0.0089936807F, 0.0090848076F, 0.0091763911F, + 0.0092684311F, 0.0093609276F, 0.0094538805F, 0.0095472898F, + 0.0096411554F, 0.0097354772F, 0.0098302552F, 0.0099254894F, + 0.0100211796F, 0.0101173259F, 0.0102139281F, 0.0103109863F, + 0.0104085002F, 0.0105064700F, 0.0106048955F, 0.0107037766F, + 0.0108031133F, 0.0109029056F, 0.0110031534F, 0.0111038565F, + 0.0112050151F, 0.0113066289F, 0.0114086980F, 0.0115112222F, + 0.0116142015F, 0.0117176359F, 0.0118215252F, 0.0119258695F, + 0.0120306686F, 0.0121359225F, 0.0122416312F, 0.0123477944F, + 0.0124544123F, 0.0125614847F, 0.0126690116F, 0.0127769928F, + 0.0128854284F, 0.0129943182F, 0.0131036623F, 0.0132134604F, + 0.0133237126F, 0.0134344188F, 0.0135455790F, 0.0136571929F, + 0.0137692607F, 0.0138817821F, 0.0139947572F, 0.0141081859F, + 0.0142220681F, 0.0143364037F, 0.0144511927F, 0.0145664350F, + 0.0146821304F, 0.0147982791F, 0.0149148808F, 0.0150319355F, + 0.0151494431F, 0.0152674036F, 0.0153858168F, 0.0155046828F, + 0.0156240014F, 0.0157437726F, 0.0158639962F, 0.0159846723F, + 0.0161058007F, 0.0162273814F, 0.0163494142F, 0.0164718991F, + 0.0165948361F, 0.0167182250F, 0.0168420658F, 0.0169663584F, + 0.0170911027F, 0.0172162987F, 0.0173419462F, 0.0174680452F, + 0.0175945956F, 0.0177215974F, 0.0178490504F, 0.0179769545F, + 0.0181053098F, 0.0182341160F, 0.0183633732F, 0.0184930812F, + 0.0186232399F, 0.0187538494F, 0.0188849094F, 0.0190164200F, + 0.0191483809F, 0.0192807923F, 0.0194136539F, 0.0195469656F, + 0.0196807275F, 0.0198149394F, 0.0199496012F, 0.0200847128F, + 0.0202202742F, 0.0203562853F, 0.0204927460F, 0.0206296561F, + 0.0207670157F, 0.0209048245F, 0.0210430826F, 0.0211817899F, + 0.0213209462F, 0.0214605515F, 0.0216006057F, 0.0217411086F, + 0.0218820603F, 0.0220234605F, 0.0221653093F, 0.0223076066F, + 0.0224503521F, 0.0225935459F, 0.0227371879F, 0.0228812779F, + 0.0230258160F, 0.0231708018F, 0.0233162355F, 0.0234621169F, + 0.0236084459F, 0.0237552224F, 0.0239024462F, 0.0240501175F, + 0.0241982359F, 0.0243468015F, 0.0244958141F, 0.0246452736F, + 0.0247951800F, 0.0249455331F, 0.0250963329F, 0.0252475792F, + 0.0253992720F, 0.0255514111F, 0.0257039965F, 0.0258570281F, + 0.0260105057F, 0.0261644293F, 0.0263187987F, 0.0264736139F, + 0.0266288747F, 0.0267845811F, 0.0269407330F, 0.0270973302F, + 0.0272543727F, 0.0274118604F, 0.0275697930F, 0.0277281707F, + 0.0278869932F, 0.0280462604F, 0.0282059723F, 0.0283661287F, + 0.0285267295F, 0.0286877747F, 0.0288492641F, 0.0290111976F, + 0.0291735751F, 0.0293363965F, 0.0294996617F, 0.0296633706F, + 0.0298275231F, 0.0299921190F, 0.0301571583F, 0.0303226409F, + 0.0304885667F, 0.0306549354F, 0.0308217472F, 0.0309890017F, + 0.0311566989F, 0.0313248388F, 0.0314934211F, 0.0316624459F, + 0.0318319128F, 0.0320018220F, 0.0321721732F, 0.0323429663F, + 0.0325142013F, 0.0326858779F, 0.0328579962F, 0.0330305559F, + 0.0332035570F, 0.0333769994F, 0.0335508829F, 0.0337252074F, + 0.0338999728F, 0.0340751790F, 0.0342508259F, 0.0344269134F, + 0.0346034412F, 0.0347804094F, 0.0349578178F, 0.0351356663F, + 0.0353139548F, 0.0354926831F, 0.0356718511F, 0.0358514588F, + 0.0360315059F, 0.0362119924F, 0.0363929182F, 0.0365742831F, + 0.0367560870F, 0.0369383297F, 0.0371210113F, 0.0373041315F, + 0.0374876902F, 0.0376716873F, 0.0378561226F, 0.0380409961F, + 0.0382263077F, 0.0384120571F, 0.0385982443F, 0.0387848691F, + 0.0389719315F, 0.0391594313F, 0.0393473683F, 0.0395357425F, + 0.0397245537F, 0.0399138017F, 0.0401034866F, 0.0402936080F, + 0.0404841660F, 0.0406751603F, 0.0408665909F, 0.0410584576F, + 0.0412507603F, 0.0414434988F, 0.0416366731F, 0.0418302829F, + 0.0420243282F, 0.0422188088F, 0.0424137246F, 0.0426090755F, + 0.0428048613F, 0.0430010819F, 0.0431977371F, 0.0433948269F, + 0.0435923511F, 0.0437903095F, 0.0439887020F, 0.0441875285F, + 0.0443867889F, 0.0445864830F, 0.0447866106F, 0.0449871717F, + 0.0451881661F, 0.0453895936F, 0.0455914542F, 0.0457937477F, + 0.0459964738F, 0.0461996326F, 0.0464032239F, 0.0466072475F, + 0.0468117032F, 0.0470165910F, 0.0472219107F, 0.0474276622F, + 0.0476338452F, 0.0478404597F, 0.0480475056F, 0.0482549827F, + 0.0484628907F, 0.0486712297F, 0.0488799994F, 0.0490891998F, + 0.0492988306F, 0.0495088917F, 0.0497193830F, 0.0499303043F, + 0.0501416554F, 0.0503534363F, 0.0505656468F, 0.0507782867F, + 0.0509913559F, 0.0512048542F, 0.0514187815F, 0.0516331376F, + 0.0518479225F, 0.0520631358F, 0.0522787775F, 0.0524948475F, + 0.0527113455F, 0.0529282715F, 0.0531456252F, 0.0533634066F, + 0.0535816154F, 0.0538002515F, 0.0540193148F, 0.0542388051F, + 0.0544587222F, 0.0546790660F, 0.0548998364F, 0.0551210331F, + 0.0553426561F, 0.0555647051F, 0.0557871801F, 0.0560100807F, + 0.0562334070F, 0.0564571587F, 0.0566813357F, 0.0569059378F, + 0.0571309649F, 0.0573564168F, 0.0575822933F, 0.0578085942F, + 0.0580353195F, 0.0582624689F, 0.0584900423F, 0.0587180396F, + 0.0589464605F, 0.0591753049F, 0.0594045726F, 0.0596342635F, + 0.0598643774F, 0.0600949141F, 0.0603258735F, 0.0605572555F, + 0.0607890597F, 0.0610212862F, 0.0612539346F, 0.0614870049F, + 0.0617204968F, 0.0619544103F, 0.0621887451F, 0.0624235010F, + 0.0626586780F, 0.0628942758F, 0.0631302942F, 0.0633667331F, + 0.0636035923F, 0.0638408717F, 0.0640785710F, 0.0643166901F, + 0.0645552288F, 0.0647941870F, 0.0650335645F, 0.0652733610F, + 0.0655135765F, 0.0657542108F, 0.0659952636F, 0.0662367348F, + 0.0664786242F, 0.0667209316F, 0.0669636570F, 0.0672068000F, + 0.0674503605F, 0.0676943384F, 0.0679387334F, 0.0681835454F, + 0.0684287742F, 0.0686744196F, 0.0689204814F, 0.0691669595F, + 0.0694138536F, 0.0696611637F, 0.0699088894F, 0.0701570307F, + 0.0704055873F, 0.0706545590F, 0.0709039458F, 0.0711537473F, + 0.0714039634F, 0.0716545939F, 0.0719056387F, 0.0721570975F, + 0.0724089702F, 0.0726612565F, 0.0729139563F, 0.0731670694F, + 0.0734205956F, 0.0736745347F, 0.0739288866F, 0.0741836510F, + 0.0744388277F, 0.0746944166F, 0.0749504175F, 0.0752068301F, + 0.0754636543F, 0.0757208899F, 0.0759785367F, 0.0762365946F, + 0.0764950632F, 0.0767539424F, 0.0770132320F, 0.0772729319F, + 0.0775330418F, 0.0777935616F, 0.0780544909F, 0.0783158298F, + 0.0785775778F, 0.0788397349F, 0.0791023009F, 0.0793652755F, + 0.0796286585F, 0.0798924498F, 0.0801566492F, 0.0804212564F, + 0.0806862712F, 0.0809516935F, 0.0812175231F, 0.0814837597F, + 0.0817504031F, 0.0820174532F, 0.0822849097F, 0.0825527724F, + 0.0828210412F, 0.0830897158F, 0.0833587960F, 0.0836282816F, + 0.0838981724F, 0.0841684682F, 0.0844391688F, 0.0847102740F, + 0.0849817835F, 0.0852536973F, 0.0855260150F, 0.0857987364F, + 0.0860718614F, 0.0863453897F, 0.0866193211F, 0.0868936554F, + 0.0871683924F, 0.0874435319F, 0.0877190737F, 0.0879950175F, + 0.0882713632F, 0.0885481105F, 0.0888252592F, 0.0891028091F, + 0.0893807600F, 0.0896591117F, 0.0899378639F, 0.0902170165F, + 0.0904965692F, 0.0907765218F, 0.0910568740F, 0.0913376258F, + 0.0916187767F, 0.0919003268F, 0.0921822756F, 0.0924646230F, + 0.0927473687F, 0.0930305126F, 0.0933140545F, 0.0935979940F, + 0.0938823310F, 0.0941670653F, 0.0944521966F, 0.0947377247F, + 0.0950236494F, 0.0953099704F, 0.0955966876F, 0.0958838007F, + 0.0961713094F, 0.0964592136F, 0.0967475131F, 0.0970362075F, + 0.0973252967F, 0.0976147805F, 0.0979046585F, 0.0981949307F, + 0.0984855967F, 0.0987766563F, 0.0990681093F, 0.0993599555F, + 0.0996521945F, 0.0999448263F, 0.1002378506F, 0.1005312671F, + 0.1008250755F, 0.1011192757F, 0.1014138675F, 0.1017088505F, + 0.1020042246F, 0.1022999895F, 0.1025961450F, 0.1028926909F, + 0.1031896268F, 0.1034869526F, 0.1037846680F, 0.1040827729F, + 0.1043812668F, 0.1046801497F, 0.1049794213F, 0.1052790813F, + 0.1055791294F, 0.1058795656F, 0.1061803894F, 0.1064816006F, + 0.1067831991F, 0.1070851846F, 0.1073875568F, 0.1076903155F, + 0.1079934604F, 0.1082969913F, 0.1086009079F, 0.1089052101F, + 0.1092098975F, 0.1095149699F, 0.1098204270F, 0.1101262687F, + 0.1104324946F, 0.1107391045F, 0.1110460982F, 0.1113534754F, + 0.1116612359F, 0.1119693793F, 0.1122779055F, 0.1125868142F, + 0.1128961052F, 0.1132057781F, 0.1135158328F, 0.1138262690F, + 0.1141370863F, 0.1144482847F, 0.1147598638F, 0.1150718233F, + 0.1153841631F, 0.1156968828F, 0.1160099822F, 0.1163234610F, + 0.1166373190F, 0.1169515559F, 0.1172661714F, 0.1175811654F, + 0.1178965374F, 0.1182122874F, 0.1185284149F, 0.1188449198F, + 0.1191618018F, 0.1194790606F, 0.1197966960F, 0.1201147076F, + 0.1204330953F, 0.1207518587F, 0.1210709976F, 0.1213905118F, + 0.1217104009F, 0.1220306647F, 0.1223513029F, 0.1226723153F, + 0.1229937016F, 0.1233154615F, 0.1236375948F, 0.1239601011F, + 0.1242829803F, 0.1246062319F, 0.1249298559F, 0.1252538518F, + 0.1255782195F, 0.1259029586F, 0.1262280689F, 0.1265535501F, + 0.1268794019F, 0.1272056241F, 0.1275322163F, 0.1278591784F, + 0.1281865099F, 0.1285142108F, 0.1288422805F, 0.1291707190F, + 0.1294995259F, 0.1298287009F, 0.1301582437F, 0.1304881542F, + 0.1308184319F, 0.1311490766F, 0.1314800881F, 0.1318114660F, + 0.1321432100F, 0.1324753200F, 0.1328077955F, 0.1331406364F, + 0.1334738422F, 0.1338074129F, 0.1341413479F, 0.1344756472F, + 0.1348103103F, 0.1351453370F, 0.1354807270F, 0.1358164801F, + 0.1361525959F, 0.1364890741F, 0.1368259145F, 0.1371631167F, + 0.1375006805F, 0.1378386056F, 0.1381768917F, 0.1385155384F, + 0.1388545456F, 0.1391939129F, 0.1395336400F, 0.1398737266F, + 0.1402141724F, 0.1405549772F, 0.1408961406F, 0.1412376623F, + 0.1415795421F, 0.1419217797F, 0.1422643746F, 0.1426073268F, + 0.1429506358F, 0.1432943013F, 0.1436383231F, 0.1439827008F, + 0.1443274342F, 0.1446725229F, 0.1450179667F, 0.1453637652F, + 0.1457099181F, 0.1460564252F, 0.1464032861F, 0.1467505006F, + 0.1470980682F, 0.1474459888F, 0.1477942620F, 0.1481428875F, + 0.1484918651F, 0.1488411942F, 0.1491908748F, 0.1495409065F, + 0.1498912889F, 0.1502420218F, 0.1505931048F, 0.1509445376F, + 0.1512963200F, 0.1516484516F, 0.1520009321F, 0.1523537612F, + 0.1527069385F, 0.1530604638F, 0.1534143368F, 0.1537685571F, + 0.1541231244F, 0.1544780384F, 0.1548332987F, 0.1551889052F, + 0.1555448574F, 0.1559011550F, 0.1562577978F, 0.1566147853F, + 0.1569721173F, 0.1573297935F, 0.1576878135F, 0.1580461771F, + 0.1584048838F, 0.1587639334F, 0.1591233255F, 0.1594830599F, + 0.1598431361F, 0.1602035540F, 0.1605643131F, 0.1609254131F, + 0.1612868537F, 0.1616486346F, 0.1620107555F, 0.1623732160F, + 0.1627360158F, 0.1630991545F, 0.1634626319F, 0.1638264476F, + 0.1641906013F, 0.1645550926F, 0.1649199212F, 0.1652850869F, + 0.1656505892F, 0.1660164278F, 0.1663826024F, 0.1667491127F, + 0.1671159583F, 0.1674831388F, 0.1678506541F, 0.1682185036F, + 0.1685866872F, 0.1689552044F, 0.1693240549F, 0.1696932384F, + 0.1700627545F, 0.1704326029F, 0.1708027833F, 0.1711732952F, + 0.1715441385F, 0.1719153127F, 0.1722868175F, 0.1726586526F, + 0.1730308176F, 0.1734033121F, 0.1737761359F, 0.1741492886F, + 0.1745227698F, 0.1748965792F, 0.1752707164F, 0.1756451812F, + 0.1760199731F, 0.1763950918F, 0.1767705370F, 0.1771463083F, + 0.1775224054F, 0.1778988279F, 0.1782755754F, 0.1786526477F, + 0.1790300444F, 0.1794077651F, 0.1797858094F, 0.1801641771F, + 0.1805428677F, 0.1809218810F, 0.1813012165F, 0.1816808739F, + 0.1820608528F, 0.1824411530F, 0.1828217739F, 0.1832027154F, + 0.1835839770F, 0.1839655584F, 0.1843474592F, 0.1847296790F, + 0.1851122175F, 0.1854950744F, 0.1858782492F, 0.1862617417F, + 0.1866455514F, 0.1870296780F, 0.1874141211F, 0.1877988804F, + 0.1881839555F, 0.1885693461F, 0.1889550517F, 0.1893410721F, + 0.1897274068F, 0.1901140555F, 0.1905010178F, 0.1908882933F, + 0.1912758818F, 0.1916637828F, 0.1920519959F, 0.1924405208F, + 0.1928293571F, 0.1932185044F, 0.1936079625F, 0.1939977308F, + 0.1943878091F, 0.1947781969F, 0.1951688939F, 0.1955598998F, + 0.1959512141F, 0.1963428364F, 0.1967347665F, 0.1971270038F, + 0.1975195482F, 0.1979123990F, 0.1983055561F, 0.1986990190F, + 0.1990927873F, 0.1994868607F, 0.1998812388F, 0.2002759212F, + 0.2006709075F, 0.2010661974F, 0.2014617904F, 0.2018576862F, + 0.2022538844F, 0.2026503847F, 0.2030471865F, 0.2034442897F, + 0.2038416937F, 0.2042393982F, 0.2046374028F, 0.2050357071F, + 0.2054343107F, 0.2058332133F, 0.2062324145F, 0.2066319138F, + 0.2070317110F, 0.2074318055F, 0.2078321970F, 0.2082328852F, + 0.2086338696F, 0.2090351498F, 0.2094367255F, 0.2098385962F, + 0.2102407617F, 0.2106432213F, 0.2110459749F, 0.2114490220F, + 0.2118523621F, 0.2122559950F, 0.2126599202F, 0.2130641373F, + 0.2134686459F, 0.2138734456F, 0.2142785361F, 0.2146839168F, + 0.2150895875F, 0.2154955478F, 0.2159017972F, 0.2163083353F, + 0.2167151617F, 0.2171222761F, 0.2175296780F, 0.2179373670F, + 0.2183453428F, 0.2187536049F, 0.2191621529F, 0.2195709864F, + 0.2199801051F, 0.2203895085F, 0.2207991961F, 0.2212091677F, + 0.2216194228F, 0.2220299610F, 0.2224407818F, 0.2228518850F, + 0.2232632699F, 0.2236749364F, 0.2240868839F, 0.2244991121F, + 0.2249116204F, 0.2253244086F, 0.2257374763F, 0.2261508229F, + 0.2265644481F, 0.2269783514F, 0.2273925326F, 0.2278069911F, + 0.2282217265F, 0.2286367384F, 0.2290520265F, 0.2294675902F, + 0.2298834292F, 0.2302995431F, 0.2307159314F, 0.2311325937F, + 0.2315495297F, 0.2319667388F, 0.2323842207F, 0.2328019749F, + 0.2332200011F, 0.2336382988F, 0.2340568675F, 0.2344757070F, + 0.2348948166F, 0.2353141961F, 0.2357338450F, 0.2361537629F, + 0.2365739493F, 0.2369944038F, 0.2374151261F, 0.2378361156F, + 0.2382573720F, 0.2386788948F, 0.2391006836F, 0.2395227380F, + 0.2399450575F, 0.2403676417F, 0.2407904902F, 0.2412136026F, + 0.2416369783F, 0.2420606171F, 0.2424845185F, 0.2429086820F, + 0.2433331072F, 0.2437577936F, 0.2441827409F, 0.2446079486F, + 0.2450334163F, 0.2454591435F, 0.2458851298F, 0.2463113747F, + 0.2467378779F, 0.2471646389F, 0.2475916573F, 0.2480189325F, + 0.2484464643F, 0.2488742521F, 0.2493022955F, 0.2497305940F, + 0.2501591473F, 0.2505879549F, 0.2510170163F, 0.2514463311F, + 0.2518758989F, 0.2523057193F, 0.2527357916F, 0.2531661157F, + 0.2535966909F, 0.2540275169F, 0.2544585931F, 0.2548899193F, + 0.2553214948F, 0.2557533193F, 0.2561853924F, 0.2566177135F, + 0.2570502822F, 0.2574830981F, 0.2579161608F, 0.2583494697F, + 0.2587830245F, 0.2592168246F, 0.2596508697F, 0.2600851593F, + 0.2605196929F, 0.2609544701F, 0.2613894904F, 0.2618247534F, + 0.2622602586F, 0.2626960055F, 0.2631319938F, 0.2635682230F, + 0.2640046925F, 0.2644414021F, 0.2648783511F, 0.2653155391F, + 0.2657529657F, 0.2661906305F, 0.2666285329F, 0.2670666725F, + 0.2675050489F, 0.2679436616F, 0.2683825101F, 0.2688215940F, + 0.2692609127F, 0.2697004660F, 0.2701402532F, 0.2705802739F, + 0.2710205278F, 0.2714610142F, 0.2719017327F, 0.2723426830F, + 0.2727838644F, 0.2732252766F, 0.2736669191F, 0.2741087914F, + 0.2745508930F, 0.2749932235F, 0.2754357824F, 0.2758785693F, + 0.2763215837F, 0.2767648251F, 0.2772082930F, 0.2776519870F, + 0.2780959066F, 0.2785400513F, 0.2789844207F, 0.2794290143F, + 0.2798738316F, 0.2803188722F, 0.2807641355F, 0.2812096211F, + 0.2816553286F, 0.2821012574F, 0.2825474071F, 0.2829937773F, + 0.2834403673F, 0.2838871768F, 0.2843342053F, 0.2847814523F, + 0.2852289174F, 0.2856765999F, 0.2861244996F, 0.2865726159F, + 0.2870209482F, 0.2874694962F, 0.2879182594F, 0.2883672372F, + 0.2888164293F, 0.2892658350F, 0.2897154540F, 0.2901652858F, + 0.2906153298F, 0.2910655856F, 0.2915160527F, 0.2919667306F, + 0.2924176189F, 0.2928687171F, 0.2933200246F, 0.2937715409F, + 0.2942232657F, 0.2946751984F, 0.2951273386F, 0.2955796856F, + 0.2960322391F, 0.2964849986F, 0.2969379636F, 0.2973911335F, + 0.2978445080F, 0.2982980864F, 0.2987518684F, 0.2992058534F, + 0.2996600409F, 0.3001144305F, 0.3005690217F, 0.3010238139F, + 0.3014788067F, 0.3019339995F, 0.3023893920F, 0.3028449835F, + 0.3033007736F, 0.3037567618F, 0.3042129477F, 0.3046693306F, + 0.3051259102F, 0.3055826859F, 0.3060396572F, 0.3064968236F, + 0.3069541847F, 0.3074117399F, 0.3078694887F, 0.3083274307F, + 0.3087855653F, 0.3092438920F, 0.3097024104F, 0.3101611199F, + 0.3106200200F, 0.3110791103F, 0.3115383902F, 0.3119978592F, + 0.3124575169F, 0.3129173627F, 0.3133773961F, 0.3138376166F, + 0.3142980238F, 0.3147586170F, 0.3152193959F, 0.3156803598F, + 0.3161415084F, 0.3166028410F, 0.3170643573F, 0.3175260566F, + 0.3179879384F, 0.3184500023F, 0.3189122478F, 0.3193746743F, + 0.3198372814F, 0.3203000685F, 0.3207630351F, 0.3212261807F, + 0.3216895048F, 0.3221530069F, 0.3226166865F, 0.3230805430F, + 0.3235445760F, 0.3240087849F, 0.3244731693F, 0.3249377285F, + 0.3254024622F, 0.3258673698F, 0.3263324507F, 0.3267977045F, + 0.3272631306F, 0.3277287286F, 0.3281944978F, 0.3286604379F, + 0.3291265482F, 0.3295928284F, 0.3300592777F, 0.3305258958F, + 0.3309926821F, 0.3314596361F, 0.3319267573F, 0.3323940451F, + 0.3328614990F, 0.3333291186F, 0.3337969033F, 0.3342648525F, + 0.3347329658F, 0.3352012427F, 0.3356696825F, 0.3361382849F, + 0.3366070492F, 0.3370759749F, 0.3375450616F, 0.3380143087F, + 0.3384837156F, 0.3389532819F, 0.3394230071F, 0.3398928905F, + 0.3403629317F, 0.3408331302F, 0.3413034854F, 0.3417739967F, + 0.3422446638F, 0.3427154860F, 0.3431864628F, 0.3436575938F, + 0.3441288782F, 0.3446003158F, 0.3450719058F, 0.3455436478F, + 0.3460155412F, 0.3464875856F, 0.3469597804F, 0.3474321250F, + 0.3479046189F, 0.3483772617F, 0.3488500527F, 0.3493229914F, + 0.3497960774F, 0.3502693100F, 0.3507426887F, 0.3512162131F, + 0.3516898825F, 0.3521636965F, 0.3526376545F, 0.3531117559F, + 0.3535860003F, 0.3540603870F, 0.3545349157F, 0.3550095856F, + 0.3554843964F, 0.3559593474F, 0.3564344381F, 0.3569096680F, + 0.3573850366F, 0.3578605432F, 0.3583361875F, 0.3588119687F, + 0.3592878865F, 0.3597639402F, 0.3602401293F, 0.3607164533F, + 0.3611929117F, 0.3616695038F, 0.3621462292F, 0.3626230873F, + 0.3631000776F, 0.3635771995F, 0.3640544525F, 0.3645318360F, + 0.3650093496F, 0.3654869926F, 0.3659647645F, 0.3664426648F, + 0.3669206930F, 0.3673988484F, 0.3678771306F, 0.3683555390F, + 0.3688340731F, 0.3693127322F, 0.3697915160F, 0.3702704237F, + 0.3707494549F, 0.3712286091F, 0.3717078857F, 0.3721872840F, + 0.3726668037F, 0.3731464441F, 0.3736262047F, 0.3741060850F, + 0.3745860843F, 0.3750662023F, 0.3755464382F, 0.3760267915F, + 0.3765072618F, 0.3769878484F, 0.3774685509F, 0.3779493686F, + 0.3784303010F, 0.3789113475F, 0.3793925076F, 0.3798737809F, + 0.3803551666F, 0.3808366642F, 0.3813182733F, 0.3817999932F, + 0.3822818234F, 0.3827637633F, 0.3832458124F, 0.3837279702F, + 0.3842102360F, 0.3846926093F, 0.3851750897F, 0.3856576764F, + 0.3861403690F, 0.3866231670F, 0.3871060696F, 0.3875890765F, + 0.3880721870F, 0.3885554007F, 0.3890387168F, 0.3895221349F, + 0.3900056544F, 0.3904892748F, 0.3909729955F, 0.3914568160F, + 0.3919407356F, 0.3924247539F, 0.3929088702F, 0.3933930841F, + 0.3938773949F, 0.3943618021F, 0.3948463052F, 0.3953309035F, + 0.3958155966F, 0.3963003838F, 0.3967852646F, 0.3972702385F, + 0.3977553048F, 0.3982404631F, 0.3987257127F, 0.3992110531F, + 0.3996964838F, 0.4001820041F, 0.4006676136F, 0.4011533116F, + 0.4016390976F, 0.4021249710F, 0.4026109313F, 0.4030969779F, + 0.4035831102F, 0.4040693277F, 0.4045556299F, 0.4050420160F, + 0.4055284857F, 0.4060150383F, 0.4065016732F, 0.4069883899F, + 0.4074751879F, 0.4079620665F, 0.4084490252F, 0.4089360635F, + 0.4094231807F, 0.4099103763F, 0.4103976498F, 0.4108850005F, + 0.4113724280F, 0.4118599315F, 0.4123475107F, 0.4128351648F, + 0.4133228934F, 0.4138106959F, 0.4142985716F, 0.4147865201F, + 0.4152745408F, 0.4157626330F, 0.4162507963F, 0.4167390301F, + 0.4172273337F, 0.4177157067F, 0.4182041484F, 0.4186926583F, + 0.4191812359F, 0.4196698805F, 0.4201585915F, 0.4206473685F, + 0.4211362108F, 0.4216251179F, 0.4221140892F, 0.4226031241F, + 0.4230922221F, 0.4235813826F, 0.4240706050F, 0.4245598887F, + 0.4250492332F, 0.4255386379F, 0.4260281022F, 0.4265176256F, + 0.4270072075F, 0.4274968473F, 0.4279865445F, 0.4284762984F, + 0.4289661086F, 0.4294559743F, 0.4299458951F, 0.4304358704F, + 0.4309258996F, 0.4314159822F, 0.4319061175F, 0.4323963050F, + 0.4328865441F, 0.4333768342F, 0.4338671749F, 0.4343575654F, + 0.4348480052F, 0.4353384938F, 0.4358290306F, 0.4363196149F, + 0.4368102463F, 0.4373009241F, 0.4377916478F, 0.4382824168F, + 0.4387732305F, 0.4392640884F, 0.4397549899F, 0.4402459343F, + 0.4407369212F, 0.4412279499F, 0.4417190198F, 0.4422101305F, + 0.4427012813F, 0.4431924717F, 0.4436837010F, 0.4441749686F, + 0.4446662742F, 0.4451576169F, 0.4456489963F, 0.4461404118F, + 0.4466318628F, 0.4471233487F, 0.4476148690F, 0.4481064230F, + 0.4485980103F, 0.4490896302F, 0.4495812821F, 0.4500729654F, + 0.4505646797F, 0.4510564243F, 0.4515481986F, 0.4520400021F, + 0.4525318341F, 0.4530236942F, 0.4535155816F, 0.4540074959F, + 0.4544994365F, 0.4549914028F, 0.4554833941F, 0.4559754100F, + 0.4564674499F, 0.4569595131F, 0.4574515991F, 0.4579437074F, + 0.4584358372F, 0.4589279881F, 0.4594201595F, 0.4599123508F, + 0.4604045615F, 0.4608967908F, 0.4613890383F, 0.4618813034F, + 0.4623735855F, 0.4628658841F, 0.4633581984F, 0.4638505281F, + 0.4643428724F, 0.4648352308F, 0.4653276028F, 0.4658199877F, + 0.4663123849F, 0.4668047940F, 0.4672972143F, 0.4677896451F, + 0.4682820861F, 0.4687745365F, 0.4692669958F, 0.4697594634F, + 0.4702519387F, 0.4707444211F, 0.4712369102F, 0.4717294052F, + 0.4722219056F, 0.4727144109F, 0.4732069204F, 0.4736994336F, + 0.4741919498F, 0.4746844686F, 0.4751769893F, 0.4756695113F, + 0.4761620341F, 0.4766545571F, 0.4771470797F, 0.4776396013F, + 0.4781321213F, 0.4786246392F, 0.4791171544F, 0.4796096663F, + 0.4801021744F, 0.4805946779F, 0.4810871765F, 0.4815796694F, + 0.4820721561F, 0.4825646360F, 0.4830571086F, 0.4835495732F, + 0.4840420293F, 0.4845344763F, 0.4850269136F, 0.4855193407F, + 0.4860117569F, 0.4865041617F, 0.4869965545F, 0.4874889347F, + 0.4879813018F, 0.4884736551F, 0.4889659941F, 0.4894583182F, + 0.4899506268F, 0.4904429193F, 0.4909351952F, 0.4914274538F, + 0.4919196947F, 0.4924119172F, 0.4929041207F, 0.4933963046F, + 0.4938884685F, 0.4943806116F, 0.4948727335F, 0.4953648335F, + 0.4958569110F, 0.4963489656F, 0.4968409965F, 0.4973330032F, + 0.4978249852F, 0.4983169419F, 0.4988088726F, 0.4993007768F, + 0.4997926539F, 0.5002845034F, 0.5007763247F, 0.5012681171F, + 0.5017598801F, 0.5022516132F, 0.5027433157F, 0.5032349871F, + 0.5037266268F, 0.5042182341F, 0.5047098086F, 0.5052013497F, + 0.5056928567F, 0.5061843292F, 0.5066757664F, 0.5071671679F, + 0.5076585330F, 0.5081498613F, 0.5086411520F, 0.5091324047F, + 0.5096236187F, 0.5101147934F, 0.5106059284F, 0.5110970230F, + 0.5115880766F, 0.5120790887F, 0.5125700587F, 0.5130609860F, + 0.5135518700F, 0.5140427102F, 0.5145335059F, 0.5150242566F, + 0.5155149618F, 0.5160056208F, 0.5164962331F, 0.5169867980F, + 0.5174773151F, 0.5179677837F, 0.5184582033F, 0.5189485733F, + 0.5194388931F, 0.5199291621F, 0.5204193798F, 0.5209095455F, + 0.5213996588F, 0.5218897190F, 0.5223797256F, 0.5228696779F, + 0.5233595755F, 0.5238494177F, 0.5243392039F, 0.5248289337F, + 0.5253186063F, 0.5258082213F, 0.5262977781F, 0.5267872760F, + 0.5272767146F, 0.5277660932F, 0.5282554112F, 0.5287446682F, + 0.5292338635F, 0.5297229965F, 0.5302120667F, 0.5307010736F, + 0.5311900164F, 0.5316788947F, 0.5321677079F, 0.5326564554F, + 0.5331451366F, 0.5336337511F, 0.5341222981F, 0.5346107771F, + 0.5350991876F, 0.5355875290F, 0.5360758007F, 0.5365640021F, + 0.5370521327F, 0.5375401920F, 0.5380281792F, 0.5385160939F, + 0.5390039355F, 0.5394917034F, 0.5399793971F, 0.5404670159F, + 0.5409545594F, 0.5414420269F, 0.5419294179F, 0.5424167318F, + 0.5429039680F, 0.5433911261F, 0.5438782053F, 0.5443652051F, + 0.5448521250F, 0.5453389644F, 0.5458257228F, 0.5463123995F, + 0.5467989940F, 0.5472855057F, 0.5477719341F, 0.5482582786F, + 0.5487445387F, 0.5492307137F, 0.5497168031F, 0.5502028063F, + 0.5506887228F, 0.5511745520F, 0.5516602934F, 0.5521459463F, + 0.5526315103F, 0.5531169847F, 0.5536023690F, 0.5540876626F, + 0.5545728649F, 0.5550579755F, 0.5555429937F, 0.5560279189F, + 0.5565127507F, 0.5569974884F, 0.5574821315F, 0.5579666794F, + 0.5584511316F, 0.5589354875F, 0.5594197465F, 0.5599039080F, + 0.5603879716F, 0.5608719367F, 0.5613558026F, 0.5618395689F, + 0.5623232350F, 0.5628068002F, 0.5632902642F, 0.5637736262F, + 0.5642568858F, 0.5647400423F, 0.5652230953F, 0.5657060442F, + 0.5661888883F, 0.5666716272F, 0.5671542603F, 0.5676367870F, + 0.5681192069F, 0.5686015192F, 0.5690837235F, 0.5695658192F, + 0.5700478058F, 0.5705296827F, 0.5710114494F, 0.5714931052F, + 0.5719746497F, 0.5724560822F, 0.5729374023F, 0.5734186094F, + 0.5738997029F, 0.5743806823F, 0.5748615470F, 0.5753422965F, + 0.5758229301F, 0.5763034475F, 0.5767838480F, 0.5772641310F, + 0.5777442960F, 0.5782243426F, 0.5787042700F, 0.5791840778F, + 0.5796637654F, 0.5801433322F, 0.5806227778F, 0.5811021016F, + 0.5815813029F, 0.5820603814F, 0.5825393363F, 0.5830181673F, + 0.5834968737F, 0.5839754549F, 0.5844539105F, 0.5849322399F, + 0.5854104425F, 0.5858885179F, 0.5863664653F, 0.5868442844F, + 0.5873219746F, 0.5877995353F, 0.5882769660F, 0.5887542661F, + 0.5892314351F, 0.5897084724F, 0.5901853776F, 0.5906621500F, + 0.5911387892F, 0.5916152945F, 0.5920916655F, 0.5925679016F, + 0.5930440022F, 0.5935199669F, 0.5939957950F, 0.5944714861F, + 0.5949470396F, 0.5954224550F, 0.5958977317F, 0.5963728692F, + 0.5968478669F, 0.5973227244F, 0.5977974411F, 0.5982720163F, + 0.5987464497F, 0.5992207407F, 0.5996948887F, 0.6001688932F, + 0.6006427537F, 0.6011164696F, 0.6015900405F, 0.6020634657F, + 0.6025367447F, 0.6030098770F, 0.6034828621F, 0.6039556995F, + 0.6044283885F, 0.6049009288F, 0.6053733196F, 0.6058455606F, + 0.6063176512F, 0.6067895909F, 0.6072613790F, 0.6077330152F, + 0.6082044989F, 0.6086758295F, 0.6091470065F, 0.6096180294F, + 0.6100888977F, 0.6105596108F, 0.6110301682F, 0.6115005694F, + 0.6119708139F, 0.6124409011F, 0.6129108305F, 0.6133806017F, + 0.6138502139F, 0.6143196669F, 0.6147889599F, 0.6152580926F, + 0.6157270643F, 0.6161958746F, 0.6166645230F, 0.6171330088F, + 0.6176013317F, 0.6180694910F, 0.6185374863F, 0.6190053171F, + 0.6194729827F, 0.6199404828F, 0.6204078167F, 0.6208749841F, + 0.6213419842F, 0.6218088168F, 0.6222754811F, 0.6227419768F, + 0.6232083032F, 0.6236744600F, 0.6241404465F, 0.6246062622F, + 0.6250719067F, 0.6255373795F, 0.6260026799F, 0.6264678076F, + 0.6269327619F, 0.6273975425F, 0.6278621487F, 0.6283265800F, + 0.6287908361F, 0.6292549163F, 0.6297188201F, 0.6301825471F, + 0.6306460966F, 0.6311094683F, 0.6315726617F, 0.6320356761F, + 0.6324985111F, 0.6329611662F, 0.6334236410F, 0.6338859348F, + 0.6343480472F, 0.6348099777F, 0.6352717257F, 0.6357332909F, + 0.6361946726F, 0.6366558704F, 0.6371168837F, 0.6375777122F, + 0.6380383552F, 0.6384988123F, 0.6389590830F, 0.6394191668F, + 0.6398790631F, 0.6403387716F, 0.6407982916F, 0.6412576228F, + 0.6417167645F, 0.6421757163F, 0.6426344778F, 0.6430930483F, + 0.6435514275F, 0.6440096149F, 0.6444676098F, 0.6449254119F, + 0.6453830207F, 0.6458404356F, 0.6462976562F, 0.6467546820F, + 0.6472115125F, 0.6476681472F, 0.6481245856F, 0.6485808273F, + 0.6490368717F, 0.6494927183F, 0.6499483667F, 0.6504038164F, + 0.6508590670F, 0.6513141178F, 0.6517689684F, 0.6522236185F, + 0.6526780673F, 0.6531323146F, 0.6535863598F, 0.6540402024F, + 0.6544938419F, 0.6549472779F, 0.6554005099F, 0.6558535373F, + 0.6563063598F, 0.6567589769F, 0.6572113880F, 0.6576635927F, + 0.6581155906F, 0.6585673810F, 0.6590189637F, 0.6594703380F, + 0.6599215035F, 0.6603724598F, 0.6608232064F, 0.6612737427F, + 0.6617240684F, 0.6621741829F, 0.6626240859F, 0.6630737767F, + 0.6635232550F, 0.6639725202F, 0.6644215720F, 0.6648704098F, + 0.6653190332F, 0.6657674417F, 0.6662156348F, 0.6666636121F, + 0.6671113731F, 0.6675589174F, 0.6680062445F, 0.6684533538F, + 0.6689002450F, 0.6693469177F, 0.6697933712F, 0.6702396052F, + 0.6706856193F, 0.6711314129F, 0.6715769855F, 0.6720223369F, + 0.6724674664F, 0.6729123736F, 0.6733570581F, 0.6738015194F, + 0.6742457570F, 0.6746897706F, 0.6751335596F, 0.6755771236F, + 0.6760204621F, 0.6764635747F, 0.6769064609F, 0.6773491204F, + 0.6777915525F, 0.6782337570F, 0.6786757332F, 0.6791174809F, + 0.6795589995F, 0.6800002886F, 0.6804413477F, 0.6808821765F, + 0.6813227743F, 0.6817631409F, 0.6822032758F, 0.6826431785F, + 0.6830828485F, 0.6835222855F, 0.6839614890F, 0.6844004585F, + 0.6848391936F, 0.6852776939F, 0.6857159589F, 0.6861539883F, + 0.6865917815F, 0.6870293381F, 0.6874666576F, 0.6879037398F, + 0.6883405840F, 0.6887771899F, 0.6892135571F, 0.6896496850F, + 0.6900855733F, 0.6905212216F, 0.6909566294F, 0.6913917963F, + 0.6918267218F, 0.6922614055F, 0.6926958471F, 0.6931300459F, + 0.6935640018F, 0.6939977141F, 0.6944311825F, 0.6948644066F, + 0.6952973859F, 0.6957301200F, 0.6961626085F, 0.6965948510F, + 0.6970268470F, 0.6974585961F, 0.6978900980F, 0.6983213521F, + 0.6987523580F, 0.6991831154F, 0.6996136238F, 0.7000438828F, + 0.7004738921F, 0.7009036510F, 0.7013331594F, 0.7017624166F, + 0.7021914224F, 0.7026201763F, 0.7030486779F, 0.7034769268F, + 0.7039049226F, 0.7043326648F, 0.7047601531F, 0.7051873870F, + 0.7056143662F, 0.7060410902F, 0.7064675586F, 0.7068937711F, + 0.7073197271F, 0.7077454264F, 0.7081708684F, 0.7085960529F, + 0.7090209793F, 0.7094456474F, 0.7098700566F, 0.7102942066F, + 0.7107180970F, 0.7111417274F, 0.7115650974F, 0.7119882066F, + 0.7124110545F, 0.7128336409F, 0.7132559653F, 0.7136780272F, + 0.7140998264F, 0.7145213624F, 0.7149426348F, 0.7153636433F, + 0.7157843874F, 0.7162048668F, 0.7166250810F, 0.7170450296F, + 0.7174647124F, 0.7178841289F, 0.7183032786F, 0.7187221613F, + 0.7191407765F, 0.7195591239F, 0.7199772030F, 0.7203950135F, + 0.7208125550F, 0.7212298271F, 0.7216468294F, 0.7220635616F, + 0.7224800233F, 0.7228962140F, 0.7233121335F, 0.7237277813F, + 0.7241431571F, 0.7245582604F, 0.7249730910F, 0.7253876484F, + 0.7258019322F, 0.7262159422F, 0.7266296778F, 0.7270431388F, + 0.7274563247F, 0.7278692353F, 0.7282818700F, 0.7286942287F, + 0.7291063108F, 0.7295181160F, 0.7299296440F, 0.7303408944F, + 0.7307518669F, 0.7311625609F, 0.7315729763F, 0.7319831126F, + 0.7323929695F, 0.7328025466F, 0.7332118435F, 0.7336208600F, + 0.7340295955F, 0.7344380499F, 0.7348462226F, 0.7352541134F, + 0.7356617220F, 0.7360690478F, 0.7364760907F, 0.7368828502F, + 0.7372893259F, 0.7376955176F, 0.7381014249F, 0.7385070475F, + 0.7389123849F, 0.7393174368F, 0.7397222029F, 0.7401266829F, + 0.7405308763F, 0.7409347829F, 0.7413384023F, 0.7417417341F, + 0.7421447780F, 0.7425475338F, 0.7429500009F, 0.7433521791F, + 0.7437540681F, 0.7441556674F, 0.7445569769F, 0.7449579960F, + 0.7453587245F, 0.7457591621F, 0.7461593084F, 0.7465591631F, + 0.7469587259F, 0.7473579963F, 0.7477569741F, 0.7481556590F, + 0.7485540506F, 0.7489521486F, 0.7493499526F, 0.7497474623F, + 0.7501446775F, 0.7505415977F, 0.7509382227F, 0.7513345521F, + 0.7517305856F, 0.7521263229F, 0.7525217636F, 0.7529169074F, + 0.7533117541F, 0.7537063032F, 0.7541005545F, 0.7544945076F, + 0.7548881623F, 0.7552815182F, 0.7556745749F, 0.7560673323F, + 0.7564597899F, 0.7568519474F, 0.7572438046F, 0.7576353611F, + 0.7580266166F, 0.7584175708F, 0.7588082235F, 0.7591985741F, + 0.7595886226F, 0.7599783685F, 0.7603678116F, 0.7607569515F, + 0.7611457879F, 0.7615343206F, 0.7619225493F, 0.7623104735F, + 0.7626980931F, 0.7630854078F, 0.7634724171F, 0.7638591209F, + 0.7642455188F, 0.7646316106F, 0.7650173959F, 0.7654028744F, + 0.7657880459F, 0.7661729100F, 0.7665574664F, 0.7669417150F, + 0.7673256553F, 0.7677092871F, 0.7680926100F, 0.7684756239F, + 0.7688583284F, 0.7692407232F, 0.7696228080F, 0.7700045826F, + 0.7703860467F, 0.7707671999F, 0.7711480420F, 0.7715285728F, + 0.7719087918F, 0.7722886989F, 0.7726682938F, 0.7730475762F, + 0.7734265458F, 0.7738052023F, 0.7741835454F, 0.7745615750F, + 0.7749392906F, 0.7753166921F, 0.7756937791F, 0.7760705514F, + 0.7764470087F, 0.7768231508F, 0.7771989773F, 0.7775744880F, + 0.7779496827F, 0.7783245610F, 0.7786991227F, 0.7790733676F, + 0.7794472953F, 0.7798209056F, 0.7801941982F, 0.7805671729F, + 0.7809398294F, 0.7813121675F, 0.7816841869F, 0.7820558873F, + 0.7824272684F, 0.7827983301F, 0.7831690720F, 0.7835394940F, + 0.7839095957F, 0.7842793768F, 0.7846488373F, 0.7850179767F, + 0.7853867948F, 0.7857552914F, 0.7861234663F, 0.7864913191F, + 0.7868588497F, 0.7872260578F, 0.7875929431F, 0.7879595055F, + 0.7883257445F, 0.7886916601F, 0.7890572520F, 0.7894225198F, + 0.7897874635F, 0.7901520827F, 0.7905163772F, 0.7908803468F, + 0.7912439912F, 0.7916073102F, 0.7919703035F, 0.7923329710F, + 0.7926953124F, 0.7930573274F, 0.7934190158F, 0.7937803774F, + 0.7941414120F, 0.7945021193F, 0.7948624991F, 0.7952225511F, + 0.7955822752F, 0.7959416711F, 0.7963007387F, 0.7966594775F, + 0.7970178875F, 0.7973759685F, 0.7977337201F, 0.7980911422F, + 0.7984482346F, 0.7988049970F, 0.7991614292F, 0.7995175310F, + 0.7998733022F, 0.8002287426F, 0.8005838519F, 0.8009386299F, + 0.8012930765F, 0.8016471914F, 0.8020009744F, 0.8023544253F, + 0.8027075438F, 0.8030603298F, 0.8034127831F, 0.8037649035F, + 0.8041166906F, 0.8044681445F, 0.8048192647F, 0.8051700512F, + 0.8055205038F, 0.8058706222F, 0.8062204062F, 0.8065698556F, + 0.8069189702F, 0.8072677499F, 0.8076161944F, 0.8079643036F, + 0.8083120772F, 0.8086595151F, 0.8090066170F, 0.8093533827F, + 0.8096998122F, 0.8100459051F, 0.8103916613F, 0.8107370806F, + 0.8110821628F, 0.8114269077F, 0.8117713151F, 0.8121153849F, + 0.8124591169F, 0.8128025108F, 0.8131455666F, 0.8134882839F, + 0.8138306627F, 0.8141727027F, 0.8145144038F, 0.8148557658F, + 0.8151967886F, 0.8155374718F, 0.8158778154F, 0.8162178192F, + 0.8165574830F, 0.8168968067F, 0.8172357900F, 0.8175744328F, + 0.8179127349F, 0.8182506962F, 0.8185883164F, 0.8189255955F, + 0.8192625332F, 0.8195991295F, 0.8199353840F, 0.8202712967F, + 0.8206068673F, 0.8209420958F, 0.8212769820F, 0.8216115256F, + 0.8219457266F, 0.8222795848F, 0.8226131000F, 0.8229462721F, + 0.8232791009F, 0.8236115863F, 0.8239437280F, 0.8242755260F, + 0.8246069801F, 0.8249380901F, 0.8252688559F, 0.8255992774F, + 0.8259293544F, 0.8262590867F, 0.8265884741F, 0.8269175167F, + 0.8272462141F, 0.8275745663F, 0.8279025732F, 0.8282302344F, + 0.8285575501F, 0.8288845199F, 0.8292111437F, 0.8295374215F, + 0.8298633530F, 0.8301889382F, 0.8305141768F, 0.8308390688F, + 0.8311636141F, 0.8314878124F, 0.8318116637F, 0.8321351678F, + 0.8324583246F, 0.8327811340F, 0.8331035957F, 0.8334257098F, + 0.8337474761F, 0.8340688944F, 0.8343899647F, 0.8347106867F, + 0.8350310605F, 0.8353510857F, 0.8356707624F, 0.8359900904F, + 0.8363090696F, 0.8366276999F, 0.8369459811F, 0.8372639131F, + 0.8375814958F, 0.8378987292F, 0.8382156130F, 0.8385321472F, + 0.8388483316F, 0.8391641662F, 0.8394796508F, 0.8397947853F, + 0.8401095697F, 0.8404240037F, 0.8407380873F, 0.8410518204F, + 0.8413652029F, 0.8416782347F, 0.8419909156F, 0.8423032456F, + 0.8426152245F, 0.8429268523F, 0.8432381289F, 0.8435490541F, + 0.8438596279F, 0.8441698502F, 0.8444797208F, 0.8447892396F, + 0.8450984067F, 0.8454072218F, 0.8457156849F, 0.8460237959F, + 0.8463315547F, 0.8466389612F, 0.8469460154F, 0.8472527170F, + 0.8475590661F, 0.8478650625F, 0.8481707063F, 0.8484759971F, + 0.8487809351F, 0.8490855201F, 0.8493897521F, 0.8496936308F, + 0.8499971564F, 0.8503003286F, 0.8506031474F, 0.8509056128F, + 0.8512077246F, 0.8515094828F, 0.8518108872F, 0.8521119379F, + 0.8524126348F, 0.8527129777F, 0.8530129666F, 0.8533126015F, + 0.8536118822F, 0.8539108087F, 0.8542093809F, 0.8545075988F, + 0.8548054623F, 0.8551029712F, 0.8554001257F, 0.8556969255F, + 0.8559933707F, 0.8562894611F, 0.8565851968F, 0.8568805775F, + 0.8571756034F, 0.8574702743F, 0.8577645902F, 0.8580585509F, + 0.8583521566F, 0.8586454070F, 0.8589383021F, 0.8592308420F, + 0.8595230265F, 0.8598148556F, 0.8601063292F, 0.8603974473F, + 0.8606882098F, 0.8609786167F, 0.8612686680F, 0.8615583636F, + 0.8618477034F, 0.8621366874F, 0.8624253156F, 0.8627135878F, + 0.8630015042F, 0.8632890646F, 0.8635762690F, 0.8638631173F, + 0.8641496096F, 0.8644357457F, 0.8647215257F, 0.8650069495F, + 0.8652920171F, 0.8655767283F, 0.8658610833F, 0.8661450820F, + 0.8664287243F, 0.8667120102F, 0.8669949397F, 0.8672775127F, + 0.8675597293F, 0.8678415894F, 0.8681230929F, 0.8684042398F, + 0.8686850302F, 0.8689654640F, 0.8692455412F, 0.8695252617F, + 0.8698046255F, 0.8700836327F, 0.8703622831F, 0.8706405768F, + 0.8709185138F, 0.8711960940F, 0.8714733174F, 0.8717501840F, + 0.8720266939F, 0.8723028469F, 0.8725786430F, 0.8728540824F, + 0.8731291648F, 0.8734038905F, 0.8736782592F, 0.8739522711F, + 0.8742259261F, 0.8744992242F, 0.8747721653F, 0.8750447496F, + 0.8753169770F, 0.8755888475F, 0.8758603611F, 0.8761315177F, + 0.8764023175F, 0.8766727603F, 0.8769428462F, 0.8772125752F, + 0.8774819474F, 0.8777509626F, 0.8780196209F, 0.8782879224F, + 0.8785558669F, 0.8788234546F, 0.8790906854F, 0.8793575594F, + 0.8796240765F, 0.8798902368F, 0.8801560403F, 0.8804214870F, + 0.8806865768F, 0.8809513099F, 0.8812156863F, 0.8814797059F, + 0.8817433687F, 0.8820066749F, 0.8822696243F, 0.8825322171F, + 0.8827944532F, 0.8830563327F, 0.8833178556F, 0.8835790219F, + 0.8838398316F, 0.8841002848F, 0.8843603815F, 0.8846201217F, + 0.8848795054F, 0.8851385327F, 0.8853972036F, 0.8856555182F, + 0.8859134764F, 0.8861710783F, 0.8864283239F, 0.8866852133F, + 0.8869417464F, 0.8871979234F, 0.8874537443F, 0.8877092090F, + 0.8879643177F, 0.8882190704F, 0.8884734671F, 0.8887275078F, + 0.8889811927F, 0.8892345216F, 0.8894874948F, 0.8897401122F, + 0.8899923738F, 0.8902442798F, 0.8904958301F, 0.8907470248F, + 0.8909978640F, 0.8912483477F, 0.8914984759F, 0.8917482487F, + 0.8919976662F, 0.8922467284F, 0.8924954353F, 0.8927437871F, + 0.8929917837F, 0.8932394252F, 0.8934867118F, 0.8937336433F, + 0.8939802199F, 0.8942264417F, 0.8944723087F, 0.8947178210F, + 0.8949629785F, 0.8952077815F, 0.8954522299F, 0.8956963239F, + 0.8959400634F, 0.8961834486F, 0.8964264795F, 0.8966691561F, + 0.8969114786F, 0.8971534470F, 0.8973950614F, 0.8976363219F, + 0.8978772284F, 0.8981177812F, 0.8983579802F, 0.8985978256F, + 0.8988373174F, 0.8990764556F, 0.8993152405F, 0.8995536720F, + 0.8997917502F, 0.9000294751F, 0.9002668470F, 0.9005038658F, + 0.9007405317F, 0.9009768446F, 0.9012128048F, 0.9014484123F, + 0.9016836671F, 0.9019185693F, 0.9021531191F, 0.9023873165F, + 0.9026211616F, 0.9028546546F, 0.9030877954F, 0.9033205841F, + 0.9035530210F, 0.9037851059F, 0.9040168392F, 0.9042482207F, + 0.9044792507F, 0.9047099293F, 0.9049402564F, 0.9051702323F, + 0.9053998569F, 0.9056291305F, 0.9058580531F, 0.9060866248F, + 0.9063148457F, 0.9065427159F, 0.9067702355F, 0.9069974046F, + 0.9072242233F, 0.9074506917F, 0.9076768100F, 0.9079025782F, + 0.9081279964F, 0.9083530647F, 0.9085777833F, 0.9088021523F, + 0.9090261717F, 0.9092498417F, 0.9094731623F, 0.9096961338F, + 0.9099187561F, 0.9101410295F, 0.9103629540F, 0.9105845297F, + 0.9108057568F, 0.9110266354F, 0.9112471656F, 0.9114673475F, + 0.9116871812F, 0.9119066668F, 0.9121258046F, 0.9123445945F, + 0.9125630367F, 0.9127811314F, 0.9129988786F, 0.9132162785F, + 0.9134333312F, 0.9136500368F, 0.9138663954F, 0.9140824073F, + 0.9142980724F, 0.9145133910F, 0.9147283632F, 0.9149429890F, + 0.9151572687F, 0.9153712023F, 0.9155847900F, 0.9157980319F, + 0.9160109282F, 0.9162234790F, 0.9164356844F, 0.9166475445F, + 0.9168590595F, 0.9170702296F, 0.9172810548F, 0.9174915354F, + 0.9177016714F, 0.9179114629F, 0.9181209102F, 0.9183300134F, + 0.9185387726F, 0.9187471879F, 0.9189552595F, 0.9191629876F, + 0.9193703723F, 0.9195774136F, 0.9197841119F, 0.9199904672F, + 0.9201964797F, 0.9204021495F, 0.9206074767F, 0.9208124616F, + 0.9210171043F, 0.9212214049F, 0.9214253636F, 0.9216289805F, + 0.9218322558F, 0.9220351896F, 0.9222377821F, 0.9224400335F, + 0.9226419439F, 0.9228435134F, 0.9230447423F, 0.9232456307F, + 0.9234461787F, 0.9236463865F, 0.9238462543F, 0.9240457822F, + 0.9242449704F, 0.9244438190F, 0.9246423282F, 0.9248404983F, + 0.9250383293F, 0.9252358214F, 0.9254329747F, 0.9256297896F, + 0.9258262660F, 0.9260224042F, 0.9262182044F, 0.9264136667F, + 0.9266087913F, 0.9268035783F, 0.9269980280F, 0.9271921405F, + 0.9273859160F, 0.9275793546F, 0.9277724566F, 0.9279652221F, + 0.9281576513F, 0.9283497443F, 0.9285415014F, 0.9287329227F, + 0.9289240084F, 0.9291147586F, 0.9293051737F, 0.9294952536F, + 0.9296849987F, 0.9298744091F, 0.9300634850F, 0.9302522266F, + 0.9304406340F, 0.9306287074F, 0.9308164471F, 0.9310038532F, + 0.9311909259F, 0.9313776654F, 0.9315640719F, 0.9317501455F, + 0.9319358865F, 0.9321212951F, 0.9323063713F, 0.9324911155F, + 0.9326755279F, 0.9328596085F, 0.9330433577F, 0.9332267756F, + 0.9334098623F, 0.9335926182F, 0.9337750434F, 0.9339571380F, + 0.9341389023F, 0.9343203366F, 0.9345014409F, 0.9346822155F, + 0.9348626606F, 0.9350427763F, 0.9352225630F, 0.9354020207F, + 0.9355811498F, 0.9357599503F, 0.9359384226F, 0.9361165667F, + 0.9362943830F, 0.9364718716F, 0.9366490327F, 0.9368258666F, + 0.9370023733F, 0.9371785533F, 0.9373544066F, 0.9375299335F, + 0.9377051341F, 0.9378800087F, 0.9380545576F, 0.9382287809F, + 0.9384026787F, 0.9385762515F, 0.9387494993F, 0.9389224223F, + 0.9390950209F, 0.9392672951F, 0.9394392453F, 0.9396108716F, + 0.9397821743F, 0.9399531536F, 0.9401238096F, 0.9402941427F, + 0.9404641530F, 0.9406338407F, 0.9408032061F, 0.9409722495F, + 0.9411409709F, 0.9413093707F, 0.9414774491F, 0.9416452062F, + 0.9418126424F, 0.9419797579F, 0.9421465528F, 0.9423130274F, + 0.9424791819F, 0.9426450166F, 0.9428105317F, 0.9429757274F, + 0.9431406039F, 0.9433051616F, 0.9434694005F, 0.9436333209F, + 0.9437969232F, 0.9439602074F, 0.9441231739F, 0.9442858229F, + 0.9444481545F, 0.9446101691F, 0.9447718669F, 0.9449332481F, + 0.9450943129F, 0.9452550617F, 0.9454154945F, 0.9455756118F, + 0.9457354136F, 0.9458949003F, 0.9460540721F, 0.9462129292F, + 0.9463714719F, 0.9465297003F, 0.9466876149F, 0.9468452157F, + 0.9470025031F, 0.9471594772F, 0.9473161384F, 0.9474724869F, + 0.9476285229F, 0.9477842466F, 0.9479396584F, 0.9480947585F, + 0.9482495470F, 0.9484040243F, 0.9485581906F, 0.9487120462F, + 0.9488655913F, 0.9490188262F, 0.9491717511F, 0.9493243662F, + 0.9494766718F, 0.9496286683F, 0.9497803557F, 0.9499317345F, + 0.9500828047F, 0.9502335668F, 0.9503840209F, 0.9505341673F, + 0.9506840062F, 0.9508335380F, 0.9509827629F, 0.9511316810F, + 0.9512802928F, 0.9514285984F, 0.9515765982F, 0.9517242923F, + 0.9518716810F, 0.9520187646F, 0.9521655434F, 0.9523120176F, + 0.9524581875F, 0.9526040534F, 0.9527496154F, 0.9528948739F, + 0.9530398292F, 0.9531844814F, 0.9533288310F, 0.9534728780F, + 0.9536166229F, 0.9537600659F, 0.9539032071F, 0.9540460470F, + 0.9541885858F, 0.9543308237F, 0.9544727611F, 0.9546143981F, + 0.9547557351F, 0.9548967723F, 0.9550375100F, 0.9551779485F, + 0.9553180881F, 0.9554579290F, 0.9555974714F, 0.9557367158F, + 0.9558756623F, 0.9560143112F, 0.9561526628F, 0.9562907174F, + 0.9564284752F, 0.9565659366F, 0.9567031017F, 0.9568399710F, + 0.9569765446F, 0.9571128229F, 0.9572488061F, 0.9573844944F, + 0.9575198883F, 0.9576549879F, 0.9577897936F, 0.9579243056F, + 0.9580585242F, 0.9581924497F, 0.9583260824F, 0.9584594226F, + 0.9585924705F, 0.9587252264F, 0.9588576906F, 0.9589898634F, + 0.9591217452F, 0.9592533360F, 0.9593846364F, 0.9595156465F, + 0.9596463666F, 0.9597767971F, 0.9599069382F, 0.9600367901F, + 0.9601663533F, 0.9602956279F, 0.9604246143F, 0.9605533128F, + 0.9606817236F, 0.9608098471F, 0.9609376835F, 0.9610652332F, + 0.9611924963F, 0.9613194733F, 0.9614461644F, 0.9615725699F, + 0.9616986901F, 0.9618245253F, 0.9619500757F, 0.9620753418F, + 0.9622003238F, 0.9623250219F, 0.9624494365F, 0.9625735679F, + 0.9626974163F, 0.9628209821F, 0.9629442656F, 0.9630672671F, + 0.9631899868F, 0.9633124251F, 0.9634345822F, 0.9635564585F, + 0.9636780543F, 0.9637993699F, 0.9639204056F, 0.9640411616F, + 0.9641616383F, 0.9642818359F, 0.9644017549F, 0.9645213955F, + 0.9646407579F, 0.9647598426F, 0.9648786497F, 0.9649971797F, + 0.9651154328F, 0.9652334092F, 0.9653511095F, 0.9654685337F, + 0.9655856823F, 0.9657025556F, 0.9658191538F, 0.9659354773F, + 0.9660515263F, 0.9661673013F, 0.9662828024F, 0.9663980300F, + 0.9665129845F, 0.9666276660F, 0.9667420750F, 0.9668562118F, + 0.9669700766F, 0.9670836698F, 0.9671969917F, 0.9673100425F, + 0.9674228227F, 0.9675353325F, 0.9676475722F, 0.9677595422F, + 0.9678712428F, 0.9679826742F, 0.9680938368F, 0.9682047309F, + 0.9683153569F, 0.9684257150F, 0.9685358056F, 0.9686456289F, + 0.9687551853F, 0.9688644752F, 0.9689734987F, 0.9690822564F, + 0.9691907483F, 0.9692989750F, 0.9694069367F, 0.9695146337F, + 0.9696220663F, 0.9697292349F, 0.9698361398F, 0.9699427813F, + 0.9700491597F, 0.9701552754F, 0.9702611286F, 0.9703667197F, + 0.9704720490F, 0.9705771169F, 0.9706819236F, 0.9707864695F, + 0.9708907549F, 0.9709947802F, 0.9710985456F, 0.9712020514F, + 0.9713052981F, 0.9714082859F, 0.9715110151F, 0.9716134862F, + 0.9717156993F, 0.9718176549F, 0.9719193532F, 0.9720207946F, + 0.9721219794F, 0.9722229080F, 0.9723235806F, 0.9724239976F, + 0.9725241593F, 0.9726240661F, 0.9727237183F, 0.9728231161F, + 0.9729222601F, 0.9730211503F, 0.9731197873F, 0.9732181713F, + 0.9733163027F, 0.9734141817F, 0.9735118088F, 0.9736091842F, + 0.9737063083F, 0.9738031814F, 0.9738998039F, 0.9739961760F, + 0.9740922981F, 0.9741881706F, 0.9742837938F, 0.9743791680F, + 0.9744742935F, 0.9745691707F, 0.9746637999F, 0.9747581814F, + 0.9748523157F, 0.9749462029F, 0.9750398435F, 0.9751332378F, + 0.9752263861F, 0.9753192887F, 0.9754119461F, 0.9755043585F, + 0.9755965262F, 0.9756884496F, 0.9757801291F, 0.9758715650F, + 0.9759627575F, 0.9760537071F, 0.9761444141F, 0.9762348789F, + 0.9763251016F, 0.9764150828F, 0.9765048228F, 0.9765943218F, + 0.9766835802F, 0.9767725984F, 0.9768613767F, 0.9769499154F, + 0.9770382149F, 0.9771262755F, 0.9772140976F, 0.9773016815F, + 0.9773890275F, 0.9774761360F, 0.9775630073F, 0.9776496418F, + 0.9777360398F, 0.9778222016F, 0.9779081277F, 0.9779938182F, + 0.9780792736F, 0.9781644943F, 0.9782494805F, 0.9783342326F, + 0.9784187509F, 0.9785030359F, 0.9785870877F, 0.9786709069F, + 0.9787544936F, 0.9788378484F, 0.9789209714F, 0.9790038631F, + 0.9790865238F, 0.9791689538F, 0.9792511535F, 0.9793331232F, + 0.9794148633F, 0.9794963742F, 0.9795776561F, 0.9796587094F, + 0.9797395345F, 0.9798201316F, 0.9799005013F, 0.9799806437F, + 0.9800605593F, 0.9801402483F, 0.9802197112F, 0.9802989483F, + 0.9803779600F, 0.9804567465F, 0.9805353082F, 0.9806136455F, + 0.9806917587F, 0.9807696482F, 0.9808473143F, 0.9809247574F, + 0.9810019778F, 0.9810789759F, 0.9811557519F, 0.9812323064F, + 0.9813086395F, 0.9813847517F, 0.9814606433F, 0.9815363147F, + 0.9816117662F, 0.9816869981F, 0.9817620108F, 0.9818368047F, + 0.9819113801F, 0.9819857374F, 0.9820598769F, 0.9821337989F, + 0.9822075038F, 0.9822809920F, 0.9823542638F, 0.9824273195F, + 0.9825001596F, 0.9825727843F, 0.9826451940F, 0.9827173891F, + 0.9827893700F, 0.9828611368F, 0.9829326901F, 0.9830040302F, + 0.9830751574F, 0.9831460720F, 0.9832167745F, 0.9832872652F, + 0.9833575444F, 0.9834276124F, 0.9834974697F, 0.9835671166F, + 0.9836365535F, 0.9837057806F, 0.9837747983F, 0.9838436071F, + 0.9839122072F, 0.9839805990F, 0.9840487829F, 0.9841167591F, + 0.9841845282F, 0.9842520903F, 0.9843194459F, 0.9843865953F, + 0.9844535389F, 0.9845202771F, 0.9845868101F, 0.9846531383F, + 0.9847192622F, 0.9847851820F, 0.9848508980F, 0.9849164108F, + 0.9849817205F, 0.9850468276F, 0.9851117324F, 0.9851764352F, + 0.9852409365F, 0.9853052366F, 0.9853693358F, 0.9854332344F, + 0.9854969330F, 0.9855604317F, 0.9856237309F, 0.9856868310F, + 0.9857497325F, 0.9858124355F, 0.9858749404F, 0.9859372477F, + 0.9859993577F, 0.9860612707F, 0.9861229871F, 0.9861845072F, + 0.9862458315F, 0.9863069601F, 0.9863678936F, 0.9864286322F, + 0.9864891764F, 0.9865495264F, 0.9866096826F, 0.9866696454F, + 0.9867294152F, 0.9867889922F, 0.9868483769F, 0.9869075695F, + 0.9869665706F, 0.9870253803F, 0.9870839991F, 0.9871424273F, + 0.9872006653F, 0.9872587135F, 0.9873165721F, 0.9873742415F, + 0.9874317222F, 0.9874890144F, 0.9875461185F, 0.9876030348F, + 0.9876597638F, 0.9877163057F, 0.9877726610F, 0.9878288300F, + 0.9878848130F, 0.9879406104F, 0.9879962225F, 0.9880516497F, + 0.9881068924F, 0.9881619509F, 0.9882168256F, 0.9882715168F, + 0.9883260249F, 0.9883803502F, 0.9884344931F, 0.9884884539F, + 0.9885422331F, 0.9885958309F, 0.9886492477F, 0.9887024838F, + 0.9887555397F, 0.9888084157F, 0.9888611120F, 0.9889136292F, + 0.9889659675F, 0.9890181273F, 0.9890701089F, 0.9891219128F, + 0.9891735392F, 0.9892249885F, 0.9892762610F, 0.9893273572F, + 0.9893782774F, 0.9894290219F, 0.9894795911F, 0.9895299853F, + 0.9895802049F, 0.9896302502F, 0.9896801217F, 0.9897298196F, + 0.9897793443F, 0.9898286961F, 0.9898778755F, 0.9899268828F, + 0.9899757183F, 0.9900243823F, 0.9900728753F, 0.9901211976F, + 0.9901693495F, 0.9902173314F, 0.9902651436F, 0.9903127865F, + 0.9903602605F, 0.9904075659F, 0.9904547031F, 0.9905016723F, + 0.9905484740F, 0.9905951086F, 0.9906415763F, 0.9906878775F, + 0.9907340126F, 0.9907799819F, 0.9908257858F, 0.9908714247F, + 0.9909168988F, 0.9909622086F, 0.9910073543F, 0.9910523364F, + 0.9910971552F, 0.9911418110F, 0.9911863042F, 0.9912306351F, + 0.9912748042F, 0.9913188117F, 0.9913626580F, 0.9914063435F, + 0.9914498684F, 0.9914932333F, 0.9915364383F, 0.9915794839F, + 0.9916223703F, 0.9916650981F, 0.9917076674F, 0.9917500787F, + 0.9917923323F, 0.9918344286F, 0.9918763679F, 0.9919181505F, + 0.9919597769F, 0.9920012473F, 0.9920425621F, 0.9920837217F, + 0.9921247263F, 0.9921655765F, 0.9922062724F, 0.9922468145F, + 0.9922872030F, 0.9923274385F, 0.9923675211F, 0.9924074513F, + 0.9924472294F, 0.9924868557F, 0.9925263306F, 0.9925656544F, + 0.9926048275F, 0.9926438503F, 0.9926827230F, 0.9927214461F, + 0.9927600199F, 0.9927984446F, 0.9928367208F, 0.9928748486F, + 0.9929128285F, 0.9929506608F, 0.9929883459F, 0.9930258841F, + 0.9930632757F, 0.9931005211F, 0.9931376207F, 0.9931745747F, + 0.9932113836F, 0.9932480476F, 0.9932845671F, 0.9933209425F, + 0.9933571742F, 0.9933932623F, 0.9934292074F, 0.9934650097F, + 0.9935006696F, 0.9935361874F, 0.9935715635F, 0.9936067982F, + 0.9936418919F, 0.9936768448F, 0.9937116574F, 0.9937463300F, + 0.9937808629F, 0.9938152565F, 0.9938495111F, 0.9938836271F, + 0.9939176047F, 0.9939514444F, 0.9939851465F, 0.9940187112F, + 0.9940521391F, 0.9940854303F, 0.9941185853F, 0.9941516044F, + 0.9941844879F, 0.9942172361F, 0.9942498495F, 0.9942823283F, + 0.9943146729F, 0.9943468836F, 0.9943789608F, 0.9944109047F, + 0.9944427158F, 0.9944743944F, 0.9945059408F, 0.9945373553F, + 0.9945686384F, 0.9945997902F, 0.9946308112F, 0.9946617017F, + 0.9946924621F, 0.9947230926F, 0.9947535937F, 0.9947839656F, + 0.9948142086F, 0.9948443232F, 0.9948743097F, 0.9949041683F, + 0.9949338995F, 0.9949635035F, 0.9949929807F, 0.9950223315F, + 0.9950515561F, 0.9950806549F, 0.9951096282F, 0.9951384764F, + 0.9951671998F, 0.9951957987F, 0.9952242735F, 0.9952526245F, + 0.9952808520F, 0.9953089564F, 0.9953369380F, 0.9953647971F, + 0.9953925340F, 0.9954201491F, 0.9954476428F, 0.9954750153F, + 0.9955022670F, 0.9955293981F, 0.9955564092F, 0.9955833003F, + 0.9956100720F, 0.9956367245F, 0.9956632582F, 0.9956896733F, + 0.9957159703F, 0.9957421494F, 0.9957682110F, 0.9957941553F, + 0.9958199828F, 0.9958456937F, 0.9958712884F, 0.9958967672F, + 0.9959221305F, 0.9959473784F, 0.9959725115F, 0.9959975300F, + 0.9960224342F, 0.9960472244F, 0.9960719011F, 0.9960964644F, + 0.9961209148F, 0.9961452525F, 0.9961694779F, 0.9961935913F, + 0.9962175930F, 0.9962414834F, 0.9962652627F, 0.9962889313F, + 0.9963124895F, 0.9963359377F, 0.9963592761F, 0.9963825051F, + 0.9964056250F, 0.9964286361F, 0.9964515387F, 0.9964743332F, + 0.9964970198F, 0.9965195990F, 0.9965420709F, 0.9965644360F, + 0.9965866946F, 0.9966088469F, 0.9966308932F, 0.9966528340F, + 0.9966746695F, 0.9966964001F, 0.9967180260F, 0.9967395475F, + 0.9967609651F, 0.9967822789F, 0.9968034894F, 0.9968245968F, + 0.9968456014F, 0.9968665036F, 0.9968873037F, 0.9969080019F, + 0.9969285987F, 0.9969490942F, 0.9969694889F, 0.9969897830F, + 0.9970099769F, 0.9970300708F, 0.9970500651F, 0.9970699601F, + 0.9970897561F, 0.9971094533F, 0.9971290522F, 0.9971485531F, + 0.9971679561F, 0.9971872617F, 0.9972064702F, 0.9972255818F, + 0.9972445968F, 0.9972635157F, 0.9972823386F, 0.9973010659F, + 0.9973196980F, 0.9973382350F, 0.9973566773F, 0.9973750253F, + 0.9973932791F, 0.9974114392F, 0.9974295059F, 0.9974474793F, + 0.9974653599F, 0.9974831480F, 0.9975008438F, 0.9975184476F, + 0.9975359598F, 0.9975533806F, 0.9975707104F, 0.9975879495F, + 0.9976050981F, 0.9976221566F, 0.9976391252F, 0.9976560043F, + 0.9976727941F, 0.9976894950F, 0.9977061073F, 0.9977226312F, + 0.9977390671F, 0.9977554152F, 0.9977716759F, 0.9977878495F, + 0.9978039361F, 0.9978199363F, 0.9978358501F, 0.9978516780F, + 0.9978674202F, 0.9978830771F, 0.9978986488F, 0.9979141358F, + 0.9979295383F, 0.9979448566F, 0.9979600909F, 0.9979752417F, + 0.9979903091F, 0.9980052936F, 0.9980201952F, 0.9980350145F, + 0.9980497515F, 0.9980644067F, 0.9980789804F, 0.9980934727F, + 0.9981078841F, 0.9981222147F, 0.9981364649F, 0.9981506350F, + 0.9981647253F, 0.9981787360F, 0.9981926674F, 0.9982065199F, + 0.9982202936F, 0.9982339890F, 0.9982476062F, 0.9982611456F, + 0.9982746074F, 0.9982879920F, 0.9983012996F, 0.9983145304F, + 0.9983276849F, 0.9983407632F, 0.9983537657F, 0.9983666926F, + 0.9983795442F, 0.9983923208F, 0.9984050226F, 0.9984176501F, + 0.9984302033F, 0.9984426827F, 0.9984550884F, 0.9984674208F, + 0.9984796802F, 0.9984918667F, 0.9985039808F, 0.9985160227F, + 0.9985279926F, 0.9985398909F, 0.9985517177F, 0.9985634734F, + 0.9985751583F, 0.9985867727F, 0.9985983167F, 0.9986097907F, + 0.9986211949F, 0.9986325297F, 0.9986437953F, 0.9986549919F, + 0.9986661199F, 0.9986771795F, 0.9986881710F, 0.9986990946F, + 0.9987099507F, 0.9987207394F, 0.9987314611F, 0.9987421161F, + 0.9987527045F, 0.9987632267F, 0.9987736829F, 0.9987840734F, + 0.9987943985F, 0.9988046584F, 0.9988148534F, 0.9988249838F, + 0.9988350498F, 0.9988450516F, 0.9988549897F, 0.9988648641F, + 0.9988746753F, 0.9988844233F, 0.9988941086F, 0.9989037313F, + 0.9989132918F, 0.9989227902F, 0.9989322269F, 0.9989416021F, + 0.9989509160F, 0.9989601690F, 0.9989693613F, 0.9989784931F, + 0.9989875647F, 0.9989965763F, 0.9990055283F, 0.9990144208F, + 0.9990232541F, 0.9990320286F, 0.9990407443F, 0.9990494016F, + 0.9990580008F, 0.9990665421F, 0.9990750257F, 0.9990834519F, + 0.9990918209F, 0.9991001331F, 0.9991083886F, 0.9991165877F, + 0.9991247307F, 0.9991328177F, 0.9991408491F, 0.9991488251F, + 0.9991567460F, 0.9991646119F, 0.9991724232F, 0.9991801801F, + 0.9991878828F, 0.9991955316F, 0.9992031267F, 0.9992106684F, + 0.9992181569F, 0.9992255925F, 0.9992329753F, 0.9992403057F, + 0.9992475839F, 0.9992548101F, 0.9992619846F, 0.9992691076F, + 0.9992761793F, 0.9992832001F, 0.9992901701F, 0.9992970895F, + 0.9993039587F, 0.9993107777F, 0.9993175470F, 0.9993242667F, + 0.9993309371F, 0.9993375583F, 0.9993441307F, 0.9993506545F, + 0.9993571298F, 0.9993635570F, 0.9993699362F, 0.9993762678F, + 0.9993825519F, 0.9993887887F, 0.9993949785F, 0.9994011216F, + 0.9994072181F, 0.9994132683F, 0.9994192725F, 0.9994252307F, + 0.9994311434F, 0.9994370107F, 0.9994428327F, 0.9994486099F, + 0.9994543423F, 0.9994600303F, 0.9994656739F, 0.9994712736F, + 0.9994768294F, 0.9994823417F, 0.9994878105F, 0.9994932363F, + 0.9994986191F, 0.9995039592F, 0.9995092568F, 0.9995145122F, + 0.9995197256F, 0.9995248971F, 0.9995300270F, 0.9995351156F, + 0.9995401630F, 0.9995451695F, 0.9995501352F, 0.9995550604F, + 0.9995599454F, 0.9995647903F, 0.9995695953F, 0.9995743607F, + 0.9995790866F, 0.9995837734F, 0.9995884211F, 0.9995930300F, + 0.9995976004F, 0.9996021324F, 0.9996066263F, 0.9996110822F, + 0.9996155004F, 0.9996198810F, 0.9996242244F, 0.9996285306F, + 0.9996327999F, 0.9996370326F, 0.9996412287F, 0.9996453886F, + 0.9996495125F, 0.9996536004F, 0.9996576527F, 0.9996616696F, + 0.9996656512F, 0.9996695977F, 0.9996735094F, 0.9996773865F, + 0.9996812291F, 0.9996850374F, 0.9996888118F, 0.9996925523F, + 0.9996962591F, 0.9996999325F, 0.9997035727F, 0.9997071798F, + 0.9997107541F, 0.9997142957F, 0.9997178049F, 0.9997212818F, + 0.9997247266F, 0.9997281396F, 0.9997315209F, 0.9997348708F, + 0.9997381893F, 0.9997414767F, 0.9997447333F, 0.9997479591F, + 0.9997511544F, 0.9997543194F, 0.9997574542F, 0.9997605591F, + 0.9997636342F, 0.9997666797F, 0.9997696958F, 0.9997726828F, + 0.9997756407F, 0.9997785698F, 0.9997814703F, 0.9997843423F, + 0.9997871860F, 0.9997900016F, 0.9997927894F, 0.9997955494F, + 0.9997982818F, 0.9998009869F, 0.9998036648F, 0.9998063157F, + 0.9998089398F, 0.9998115373F, 0.9998141082F, 0.9998166529F, + 0.9998191715F, 0.9998216642F, 0.9998241311F, 0.9998265724F, + 0.9998289884F, 0.9998313790F, 0.9998337447F, 0.9998360854F, + 0.9998384015F, 0.9998406930F, 0.9998429602F, 0.9998452031F, + 0.9998474221F, 0.9998496171F, 0.9998517885F, 0.9998539364F, + 0.9998560610F, 0.9998581624F, 0.9998602407F, 0.9998622962F, + 0.9998643291F, 0.9998663394F, 0.9998683274F, 0.9998702932F, + 0.9998722370F, 0.9998741589F, 0.9998760591F, 0.9998779378F, + 0.9998797952F, 0.9998816313F, 0.9998834464F, 0.9998852406F, + 0.9998870141F, 0.9998887670F, 0.9998904995F, 0.9998922117F, + 0.9998939039F, 0.9998955761F, 0.9998972285F, 0.9998988613F, + 0.9999004746F, 0.9999020686F, 0.9999036434F, 0.9999051992F, + 0.9999067362F, 0.9999082544F, 0.9999097541F, 0.9999112354F, + 0.9999126984F, 0.9999141433F, 0.9999155703F, 0.9999169794F, + 0.9999183709F, 0.9999197449F, 0.9999211014F, 0.9999224408F, + 0.9999237631F, 0.9999250684F, 0.9999263570F, 0.9999276289F, + 0.9999288843F, 0.9999301233F, 0.9999313461F, 0.9999325529F, + 0.9999337437F, 0.9999349187F, 0.9999360780F, 0.9999372218F, + 0.9999383503F, 0.9999394635F, 0.9999405616F, 0.9999416447F, + 0.9999427129F, 0.9999437665F, 0.9999448055F, 0.9999458301F, + 0.9999468404F, 0.9999478365F, 0.9999488185F, 0.9999497867F, + 0.9999507411F, 0.9999516819F, 0.9999526091F, 0.9999535230F, + 0.9999544236F, 0.9999553111F, 0.9999561856F, 0.9999570472F, + 0.9999578960F, 0.9999587323F, 0.9999595560F, 0.9999603674F, + 0.9999611666F, 0.9999619536F, 0.9999627286F, 0.9999634917F, + 0.9999642431F, 0.9999649828F, 0.9999657110F, 0.9999664278F, + 0.9999671334F, 0.9999678278F, 0.9999685111F, 0.9999691835F, + 0.9999698451F, 0.9999704960F, 0.9999711364F, 0.9999717662F, + 0.9999723858F, 0.9999729950F, 0.9999735942F, 0.9999741834F, + 0.9999747626F, 0.9999753321F, 0.9999758919F, 0.9999764421F, + 0.9999769828F, 0.9999775143F, 0.9999780364F, 0.9999785495F, + 0.9999790535F, 0.9999795485F, 0.9999800348F, 0.9999805124F, + 0.9999809813F, 0.9999814417F, 0.9999818938F, 0.9999823375F, + 0.9999827731F, 0.9999832005F, 0.9999836200F, 0.9999840316F, + 0.9999844353F, 0.9999848314F, 0.9999852199F, 0.9999856008F, + 0.9999859744F, 0.9999863407F, 0.9999866997F, 0.9999870516F, + 0.9999873965F, 0.9999877345F, 0.9999880656F, 0.9999883900F, + 0.9999887078F, 0.9999890190F, 0.9999893237F, 0.9999896220F, + 0.9999899140F, 0.9999901999F, 0.9999904796F, 0.9999907533F, + 0.9999910211F, 0.9999912830F, 0.9999915391F, 0.9999917896F, + 0.9999920345F, 0.9999922738F, 0.9999925077F, 0.9999927363F, + 0.9999929596F, 0.9999931777F, 0.9999933907F, 0.9999935987F, + 0.9999938018F, 0.9999940000F, 0.9999941934F, 0.9999943820F, + 0.9999945661F, 0.9999947456F, 0.9999949206F, 0.9999950912F, + 0.9999952575F, 0.9999954195F, 0.9999955773F, 0.9999957311F, + 0.9999958807F, 0.9999960265F, 0.9999961683F, 0.9999963063F, + 0.9999964405F, 0.9999965710F, 0.9999966979F, 0.9999968213F, + 0.9999969412F, 0.9999970576F, 0.9999971707F, 0.9999972805F, + 0.9999973871F, 0.9999974905F, 0.9999975909F, 0.9999976881F, + 0.9999977824F, 0.9999978738F, 0.9999979624F, 0.9999980481F, + 0.9999981311F, 0.9999982115F, 0.9999982892F, 0.9999983644F, + 0.9999984370F, 0.9999985072F, 0.9999985750F, 0.9999986405F, + 0.9999987037F, 0.9999987647F, 0.9999988235F, 0.9999988802F, + 0.9999989348F, 0.9999989873F, 0.9999990379F, 0.9999990866F, + 0.9999991334F, 0.9999991784F, 0.9999992217F, 0.9999992632F, + 0.9999993030F, 0.9999993411F, 0.9999993777F, 0.9999994128F, + 0.9999994463F, 0.9999994784F, 0.9999995091F, 0.9999995384F, + 0.9999995663F, 0.9999995930F, 0.9999996184F, 0.9999996426F, + 0.9999996657F, 0.9999996876F, 0.9999997084F, 0.9999997282F, + 0.9999997469F, 0.9999997647F, 0.9999997815F, 0.9999997973F, + 0.9999998123F, 0.9999998265F, 0.9999998398F, 0.9999998524F, + 0.9999998642F, 0.9999998753F, 0.9999998857F, 0.9999998954F, + 0.9999999045F, 0.9999999130F, 0.9999999209F, 0.9999999282F, + 0.9999999351F, 0.9999999414F, 0.9999999472F, 0.9999999526F, + 0.9999999576F, 0.9999999622F, 0.9999999664F, 0.9999999702F, + 0.9999999737F, 0.9999999769F, 0.9999999798F, 0.9999999824F, + 0.9999999847F, 0.9999999868F, 0.9999999887F, 0.9999999904F, + 0.9999999919F, 0.9999999932F, 0.9999999943F, 0.9999999953F, + 0.9999999961F, 0.9999999969F, 0.9999999975F, 0.9999999980F, + 0.9999999985F, 0.9999999988F, 0.9999999991F, 0.9999999993F, + 0.9999999995F, 0.9999999997F, 0.9999999998F, 0.9999999999F, + 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F, + 1.0000000000F, 1.0000000000F, 1.0000000000F, 1.0000000000F, }; const float ff_vorbis_floor1_inverse_db_table[256]={ - 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F, - 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F, - 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F, - 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F, - 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F, - 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F, - 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F, - 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F, - 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F, - 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F, - 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F, - 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F, - 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F, - 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F, - 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F, - 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F, - 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F, - 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F, - 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F, - 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F, - 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F, - 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F, - 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F, - 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F, - 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F, - 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F, - 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F, - 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F, - 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F, - 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F, - 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F, - 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F, - 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F, - 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F, - 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F, - 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F, - 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F, - 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F, - 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F, - 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F, - 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F, - 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F, - 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F, - 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F, - 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F, - 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F, - 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F, - 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F, - 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F, - 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F, - 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F, - 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F, - 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F, - 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F, - 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F, - 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F, - 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F, - 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F, - 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F, - 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F, - 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F, - 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F, - 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F, - 0.82788260F, 0.88168307F, 0.9389798F, 1.F, + 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F, + 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F, + 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F, + 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F, + 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F, + 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F, + 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F, + 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F, + 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F, + 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F, + 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F, + 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F, + 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F, + 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F, + 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F, + 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F, + 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F, + 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F, + 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F, + 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F, + 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F, + 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F, + 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F, + 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F, + 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F, + 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F, + 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F, + 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F, + 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F, + 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F, + 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F, + 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F, + 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F, + 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F, + 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F, + 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F, + 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F, + 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F, + 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F, + 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F, + 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F, + 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F, + 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F, + 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F, + 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F, + 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F, + 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F, + 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F, + 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F, + 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F, + 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F, + 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F, + 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F, + 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F, + 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F, + 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F, + 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F, + 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F, + 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F, + 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F, + 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F, + 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F, + 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F, + 0.82788260F, 0.88168307F, 0.9389798F, 1.F, }; -const float * const ff_vorbis_vwin[8] = { vwin64, vwin128, vwin256, vwin512, vwin1024, vwin2048, vwin4096, vwin8192 }; - +const float * const ff_vorbis_vwin[8] = { + vwin64, vwin128, vwin256, vwin512, + vwin1024, vwin2048, vwin4096, vwin8192 +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vorbis_dec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/vorbis_dec.c index bb582c2bf0..8c56400c77 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vorbis_dec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vorbis_dec.c @@ -1,8 +1,8 @@ /** - * @file libavcodec/vorbis_dec.c + * @file * Vorbis I decoder * @author Denes Balatoni ( dbalatoni programozo hu ) - + * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or @@ -30,13 +30,15 @@ #include "avcodec.h" #include "get_bits.h" #include "dsputil.h" +#include "fft.h" #include "vorbis.h" #include "xiph.h" #define V_NB_BITS 8 #define V_NB_BITS2 11 -#define V_MAX_VLCS (1<<16) +#define V_MAX_VLCS (1 << 16) +#define V_MAX_PARTITIONS (1 << 20) #ifndef V_DEBUG #define AV_DEBUG(...) @@ -54,7 +56,7 @@ typedef struct { unsigned int nb_bits; } vorbis_codebook; -typedef union vorbis_floor_u vorbis_floor_data; +typedef union vorbis_floor_u vorbis_floor_data; typedef struct vorbis_floor0_s vorbis_floor0; typedef struct vorbis_floor1_s vorbis_floor1; struct vorbis_context_s; @@ -64,23 +66,20 @@ uint_fast8_t (* vorbis_floor_decode_func) typedef struct { uint_fast8_t floor_type; vorbis_floor_decode_func decode; - union vorbis_floor_u - { - struct vorbis_floor0_s - { - uint_fast8_t order; + union vorbis_floor_u { + struct vorbis_floor0_s { + uint_fast8_t order; uint_fast16_t rate; uint_fast16_t bark_map_size; - int_fast32_t * map[2]; + int_fast32_t *map[2]; uint_fast32_t map_size[2]; - uint_fast8_t amplitude_bits; - uint_fast8_t amplitude_offset; - uint_fast8_t num_books; - uint_fast8_t * book_list; - float * lsp; + uint_fast8_t amplitude_bits; + uint_fast8_t amplitude_offset; + uint_fast8_t num_books; + uint_fast8_t *book_list; + float *lsp; } t0; - struct vorbis_floor1_s - { + struct vorbis_floor1_s { uint_fast8_t partitions; uint_fast8_t maximum_class; uint_fast8_t partition_class[32]; @@ -90,7 +89,7 @@ typedef struct { int_fast16_t subclass_books[16][8]; uint_fast8_t multiplier; uint_fast16_t x_list_dim; - vorbis_floor1_entry * list; + vorbis_floor1_entry *list; } t1; } data; } vorbis_floor; @@ -100,27 +99,27 @@ typedef struct { uint_fast32_t begin; uint_fast32_t end; uint_fast32_t partition_size; - uint_fast8_t classifications; - uint_fast8_t classbook; - int_fast16_t books[64][8]; - uint_fast8_t maxpass; + uint_fast8_t classifications; + uint_fast8_t classbook; + int_fast16_t books[64][8]; + uint_fast8_t maxpass; } vorbis_residue; typedef struct { - uint_fast8_t submaps; + uint_fast8_t submaps; uint_fast16_t coupling_steps; uint_fast8_t *magnitude; uint_fast8_t *angle; uint_fast8_t *mux; - uint_fast8_t submap_floor[16]; - uint_fast8_t submap_residue[16]; + uint_fast8_t submap_floor[16]; + uint_fast8_t submap_residue[16]; } vorbis_mapping; typedef struct { - uint_fast8_t blockflag; + uint_fast8_t blockflag; uint_fast16_t windowtype; uint_fast16_t transformtype; - uint_fast8_t mapping; + uint_fast8_t mapping; } vorbis_mode; typedef struct vorbis_context_s { @@ -128,31 +127,31 @@ typedef struct vorbis_context_s { GetBitContext gb; DSPContext dsp; - MDCTContext mdct[2]; - uint_fast8_t first_frame; + FFTContext mdct[2]; + uint_fast8_t first_frame; uint_fast32_t version; - uint_fast8_t audio_channels; + uint_fast8_t audio_channels; uint_fast32_t audio_samplerate; uint_fast32_t bitrate_maximum; uint_fast32_t bitrate_nominal; uint_fast32_t bitrate_minimum; uint_fast32_t blocksize[2]; - const float * win[2]; + const float *win[2]; uint_fast16_t codebook_count; vorbis_codebook *codebooks; - uint_fast8_t floor_count; + uint_fast8_t floor_count; vorbis_floor *floors; - uint_fast8_t residue_count; + uint_fast8_t residue_count; vorbis_residue *residues; - uint_fast8_t mapping_count; + uint_fast8_t mapping_count; vorbis_mapping *mappings; - uint_fast8_t mode_count; - vorbis_mode *modes; - uint_fast8_t mode_number; // mode number for the current packet - uint_fast8_t previous_window; - float *channel_residues; - float *channel_floors; - float *saved; + uint_fast8_t mode_count; + vorbis_mode *modes; + uint_fast8_t mode_number; // mode number for the current packet + uint_fast8_t previous_window; + float *channel_residues; + float *channel_floors; + float *saved; uint_fast32_t add_bias; // for float->int conversion uint_fast32_t exp_bias; } vorbis_context; @@ -160,19 +159,36 @@ typedef struct vorbis_context_s { /* Helper functions */ #define BARK(x) \ - (13.1f*atan(0.00074f*(x))+2.24f*atan(1.85e-8f*(x)*(x))+1e-4f*(x)) + (13.1f * atan(0.00074f * (x)) + 2.24f * atan(1.85e-8f * (x) * (x)) + 1e-4f * (x)) -static float vorbisfloat2float(uint_fast32_t val) { - double mant=val&0x1fffff; - long exp=(val&0x7fe00000L)>>21; - if (val&0x80000000) mant=-mant; +static const char idx_err_str[] = "Index value %d out of range (0 - %d) for %s at %s:%i\n"; +#define VALIDATE_INDEX(idx, limit) \ + if (idx >= limit) {\ + av_log(vc->avccontext, AV_LOG_ERROR,\ + idx_err_str,\ + (int)(idx), (int)(limit - 1), #idx, __FILE__, __LINE__);\ + return -1;\ + } +#define GET_VALIDATED_INDEX(idx, bits, limit) \ + {\ + idx = get_bits(gb, bits);\ + VALIDATE_INDEX(idx, limit)\ + } + +static float vorbisfloat2float(uint_fast32_t val) +{ + double mant = val & 0x1fffff; + long exp = (val & 0x7fe00000L) >> 21; + if (val & 0x80000000) + mant = -mant; return ldexp(mant, exp - 20 - 768); } // Free all allocated memory ----------------------------------------- -static void vorbis_free(vorbis_context *vc) { +static void vorbis_free(vorbis_context *vc) +{ int_fast16_t i; av_freep(&vc->channel_residues); @@ -185,26 +201,25 @@ static void vorbis_free(vorbis_context *vc) { ff_mdct_end(&vc->mdct[0]); ff_mdct_end(&vc->mdct[1]); - for(i=0;icodebook_count;++i) { + for (i = 0; i < vc->codebook_count; ++i) { av_free(vc->codebooks[i].codevectors); free_vlc(&vc->codebooks[i].vlc); } av_freep(&vc->codebooks); - for(i=0;ifloor_count;++i) { - if(vc->floors[i].floor_type==0) { + for (i = 0; i < vc->floor_count; ++i) { + if (vc->floors[i].floor_type == 0) { av_free(vc->floors[i].data.t0.map[0]); av_free(vc->floors[i].data.t0.map[1]); av_free(vc->floors[i].data.t0.book_list); av_free(vc->floors[i].data.t0.lsp); - } - else { + } else { av_free(vc->floors[i].data.t1.list); } } av_freep(&vc->floors); - for(i=0;imapping_count;++i) { + for (i = 0; i < vc->mapping_count; ++i) { av_free(vc->mappings[i].magnitude); av_free(vc->mappings[i].angle); av_free(vc->mappings[i].mux); @@ -216,94 +231,94 @@ static void vorbis_free(vorbis_context *vc) { // Process codebooks part -static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc) { +static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc) +{ uint_fast16_t cb; - uint8_t *tmp_vlc_bits; + uint8_t *tmp_vlc_bits; uint32_t *tmp_vlc_codes; - GetBitContext *gb=&vc->gb; + GetBitContext *gb = &vc->gb; - vc->codebook_count=get_bits(gb,8)+1; + vc->codebook_count = get_bits(gb, 8) + 1; AV_DEBUG(" Codebooks: %d \n", vc->codebook_count); - vc->codebooks=av_mallocz(vc->codebook_count * sizeof(vorbis_codebook)); - tmp_vlc_bits =av_mallocz(V_MAX_VLCS * sizeof(uint8_t)); - tmp_vlc_codes=av_mallocz(V_MAX_VLCS * sizeof(uint32_t)); + vc->codebooks = av_mallocz(vc->codebook_count * sizeof(vorbis_codebook)); + tmp_vlc_bits = av_mallocz(V_MAX_VLCS * sizeof(uint8_t)); + tmp_vlc_codes = av_mallocz(V_MAX_VLCS * sizeof(uint32_t)); - for(cb=0;cbcodebook_count;++cb) { - vorbis_codebook *codebook_setup=&vc->codebooks[cb]; + for (cb = 0; cb < vc->codebook_count; ++cb) { + vorbis_codebook *codebook_setup = &vc->codebooks[cb]; uint_fast8_t ordered; - uint_fast32_t t, used_entries=0; + uint_fast32_t t, used_entries = 0; uint_fast32_t entries; AV_DEBUG(" %d. Codebook \n", cb); - if (get_bits(gb, 24)!=0x564342) { + if (get_bits(gb, 24) != 0x564342) { av_log(vc->avccontext, AV_LOG_ERROR, " %"PRIdFAST16". Codebook setup data corrupt. \n", cb); goto error; } codebook_setup->dimensions=get_bits(gb, 16); - if (codebook_setup->dimensions>16) { - av_log(vc->avccontext, AV_LOG_ERROR, " %"PRIdFAST16". Codebook's dimension is too large (%d). \n", cb, codebook_setup->dimensions); + if (codebook_setup->dimensions > 16 || codebook_setup->dimensions == 0) { + av_log(vc->avccontext, AV_LOG_ERROR, " %"PRIdFAST16". Codebook's dimension is invalid (%d). \n", cb, codebook_setup->dimensions); goto error; } - entries=get_bits(gb, 24); - if (entries>V_MAX_VLCS) { + entries = get_bits(gb, 24); + if (entries > V_MAX_VLCS) { av_log(vc->avccontext, AV_LOG_ERROR, " %"PRIdFAST16". Codebook has too many entries (%"PRIdFAST32"). \n", cb, entries); goto error; } - ordered=get_bits1(gb); + ordered = get_bits1(gb); AV_DEBUG(" codebook_dimensions %d, codebook_entries %d \n", codebook_setup->dimensions, entries); if (!ordered) { uint_fast16_t ce; - uint_fast8_t flag; - uint_fast8_t sparse=get_bits1(gb); + uint_fast8_t flag; + uint_fast8_t sparse = get_bits1(gb); AV_DEBUG(" not ordered \n"); if (sparse) { AV_DEBUG(" sparse \n"); - used_entries=0; - for(ce=0;celookup_type=get_bits(gb, 4); + codebook_setup->lookup_type = get_bits(gb, 4); - AV_DEBUG(" lookup type: %d : %s \n", codebook_setup->lookup_type, codebook_setup->lookup_type ? "vq" : "no lookup" ); + AV_DEBUG(" lookup type: %d : %s \n", codebook_setup->lookup_type, codebook_setup->lookup_type ? "vq" : "no lookup"); // If the codebook is used for (inverse) VQ, calculate codevectors. - if (codebook_setup->lookup_type==1) { + if (codebook_setup->lookup_type == 1) { uint_fast16_t i, j, k; - uint_fast16_t codebook_lookup_values=ff_vorbis_nth_root(entries, codebook_setup->dimensions); + uint_fast16_t codebook_lookup_values = ff_vorbis_nth_root(entries, codebook_setup->dimensions); uint_fast16_t codebook_multiplicands[codebook_lookup_values]; - float codebook_minimum_value=vorbisfloat2float(get_bits_long(gb, 32)); - float codebook_delta_value=vorbisfloat2float(get_bits_long(gb, 32)); - uint_fast8_t codebook_value_bits=get_bits(gb, 4)+1; - uint_fast8_t codebook_sequence_p=get_bits1(gb); + float codebook_minimum_value = vorbisfloat2float(get_bits_long(gb, 32)); + float codebook_delta_value = vorbisfloat2float(get_bits_long(gb, 32)); + uint_fast8_t codebook_value_bits = get_bits(gb, 4)+1; + uint_fast8_t codebook_sequence_p = get_bits1(gb); AV_DEBUG(" We expect %d numbers for building the codevectors. \n", codebook_lookup_values); AV_DEBUG(" delta %f minmum %f \n", codebook_delta_value, codebook_minimum_value); - for(i=0;icodevectors=used_entries ? av_mallocz(used_entries*codebook_setup->dimensions * sizeof(float)) : NULL; - for(j=0, i=0;idimensions; + codebook_setup->codevectors = used_entries ? av_mallocz(used_entries*codebook_setup->dimensions * sizeof(float)) : NULL; + for (j = 0, i = 0; i < entries; ++i) { + uint_fast8_t dim = codebook_setup->dimensions; if (tmp_vlc_bits[i]) { - float last=0.0; - uint_fast32_t lookup_offset=i; + float last = 0.0; + uint_fast32_t lookup_offset = i; #ifdef V_DEBUG av_log(vc->avccontext, AV_LOG_INFO, "Lookup offset %d ,", i); #endif - for(k=0;kcodevectors[j*dim+k]=codebook_multiplicands[multiplicand_offset]*codebook_delta_value+codebook_minimum_value+last; - if (codebook_sequence_p) { - last=codebook_setup->codevectors[j*dim+k]; - } + codebook_setup->codevectors[j * dim + k] = codebook_multiplicands[multiplicand_offset] * codebook_delta_value + codebook_minimum_value + last; + if (codebook_sequence_p) + last = codebook_setup->codevectors[j * dim + k]; lookup_offset/=codebook_lookup_values; } - tmp_vlc_bits[j]=tmp_vlc_bits[i]; + tmp_vlc_bits[j] = tmp_vlc_bits[i]; #ifdef V_DEBUG av_log(vc->avccontext, AV_LOG_INFO, "real lookup offset %d, vector: ", j); - for(k=0;kavccontext, AV_LOG_INFO, " %f ", codebook_setup->codevectors[j*dim+k]); - } + for (k = 0; k < dim; ++k) + av_log(vc->avccontext, AV_LOG_INFO, " %f ", codebook_setup->codevectors[j * dim + k]); av_log(vc->avccontext, AV_LOG_INFO, "\n"); #endif ++j; } } - if (j!=used_entries) { + if (j != used_entries) { av_log(vc->avccontext, AV_LOG_ERROR, "Bug in codevector vector building code. \n"); goto error; } - entries=used_entries; - } - else if (codebook_setup->lookup_type>=2) { + entries = used_entries; + } else if (codebook_setup->lookup_type >= 2) { av_log(vc->avccontext, AV_LOG_ERROR, "Codebook lookup type not supported. \n"); goto error; } @@ -389,14 +401,17 @@ static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc) { av_log(vc->avccontext, AV_LOG_ERROR, " Invalid code lengths while generating vlcs. \n"); goto error; } - codebook_setup->maxdepth=0; - for(t=0;t=codebook_setup->maxdepth) codebook_setup->maxdepth=tmp_vlc_bits[t]; + codebook_setup->maxdepth = 0; + for (t = 0; t < entries; ++t) + if (tmp_vlc_bits[t] >= codebook_setup->maxdepth) + codebook_setup->maxdepth = tmp_vlc_bits[t]; - if(codebook_setup->maxdepth > 3*V_NB_BITS) codebook_setup->nb_bits=V_NB_BITS2; - else codebook_setup->nb_bits=V_NB_BITS; + if (codebook_setup->maxdepth > 3 * V_NB_BITS) + codebook_setup->nb_bits = V_NB_BITS2; + else + codebook_setup->nb_bits = V_NB_BITS; - codebook_setup->maxdepth=(codebook_setup->maxdepth+codebook_setup->nb_bits-1)/codebook_setup->nb_bits; + codebook_setup->maxdepth = (codebook_setup->maxdepth+codebook_setup->nb_bits - 1) / codebook_setup->nb_bits; if (init_vlc(&codebook_setup->vlc, codebook_setup->nb_bits, entries, tmp_vlc_bits, sizeof(*tmp_vlc_bits), sizeof(*tmp_vlc_bits), tmp_vlc_codes, sizeof(*tmp_vlc_codes), sizeof(*tmp_vlc_codes), INIT_VLC_LE)) { av_log(vc->avccontext, AV_LOG_ERROR, " Error generating vlc tables. \n"); @@ -412,24 +427,25 @@ static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc) { error: av_free(tmp_vlc_bits); av_free(tmp_vlc_codes); - return 1; + return -1; } // Process time domain transforms part (unused in Vorbis I) -static int vorbis_parse_setup_hdr_tdtransforms(vorbis_context *vc) { - GetBitContext *gb=&vc->gb; +static int vorbis_parse_setup_hdr_tdtransforms(vorbis_context *vc) +{ + GetBitContext *gb = &vc->gb; uint_fast8_t i; - uint_fast8_t vorbis_time_count=get_bits(gb, 6)+1; + uint_fast8_t vorbis_time_count = get_bits(gb, 6) + 1; - for(i=0;iavccontext, AV_LOG_ERROR, "Vorbis time domain transform data nonzero. \n"); - return 1; + return -1; } } return 0; @@ -439,38 +455,40 @@ static int vorbis_parse_setup_hdr_tdtransforms(vorbis_context *vc) { static uint_fast8_t vorbis_floor0_decode(vorbis_context *vc, vorbis_floor_data *vfu, float *vec); -static void create_map( vorbis_context * vc, uint_fast8_t floor_number ); +static void create_map(vorbis_context *vc, uint_fast8_t floor_number); static uint_fast8_t vorbis_floor1_decode(vorbis_context *vc, vorbis_floor_data *vfu, float *vec); -static int vorbis_parse_setup_hdr_floors(vorbis_context *vc) { - GetBitContext *gb=&vc->gb; +static int vorbis_parse_setup_hdr_floors(vorbis_context *vc) +{ + GetBitContext *gb = &vc->gb; uint_fast16_t i,j,k; - vc->floor_count=get_bits(gb, 6)+1; + vc->floor_count = get_bits(gb, 6) + 1; - vc->floors=av_mallocz(vc->floor_count * sizeof(vorbis_floor)); + vc->floors = av_mallocz(vc->floor_count * sizeof(vorbis_floor)); - for (i=0;ifloor_count;++i) { - vorbis_floor *floor_setup=&vc->floors[i]; + for (i = 0; i < vc->floor_count; ++i) { + vorbis_floor *floor_setup = &vc->floors[i]; - floor_setup->floor_type=get_bits(gb, 16); + floor_setup->floor_type = get_bits(gb, 16); AV_DEBUG(" %d. floor type %d \n", i, floor_setup->floor_type); - if (floor_setup->floor_type==1) { - uint_fast8_t maximum_class=0; - uint_fast8_t rangebits; - uint_fast16_t floor1_values=2; + if (floor_setup->floor_type == 1) { + uint_fast8_t maximum_class = 0; + uint_fast8_t rangebits; + uint_fast16_t floor1_values = 2; - floor_setup->decode=vorbis_floor1_decode; + floor_setup->decode = vorbis_floor1_decode; - floor_setup->data.t1.partitions=get_bits(gb, 5); + floor_setup->data.t1.partitions = get_bits(gb, 5); AV_DEBUG(" %d.floor: %d partitions \n", i, floor_setup->data.t1.partitions); - for(j=0;jdata.t1.partitions;++j) { - floor_setup->data.t1.partition_class[j]=get_bits(gb, 4); - if (floor_setup->data.t1.partition_class[j]>maximum_class) maximum_class=floor_setup->data.t1.partition_class[j]; + for (j = 0; j < floor_setup->data.t1.partitions; ++j) { + floor_setup->data.t1.partition_class[j] = get_bits(gb, 4); + if (floor_setup->data.t1.partition_class[j] > maximum_class) + maximum_class = floor_setup->data.t1.partition_class[j]; AV_DEBUG(" %d. floor %d partition class %d \n", i, j, floor_setup->data.t1.partition_class[j]); @@ -478,44 +496,46 @@ static int vorbis_parse_setup_hdr_floors(vorbis_context *vc) { AV_DEBUG(" maximum class %d \n", maximum_class); - floor_setup->data.t1.maximum_class=maximum_class; + floor_setup->data.t1.maximum_class = maximum_class; - for(j=0;j<=maximum_class;++j) { - floor_setup->data.t1.class_dimensions[j]=get_bits(gb, 3)+1; - floor_setup->data.t1.class_subclasses[j]=get_bits(gb, 2); + for (j = 0; j <= maximum_class; ++j) { + floor_setup->data.t1.class_dimensions[j] = get_bits(gb, 3) + 1; + floor_setup->data.t1.class_subclasses[j] = get_bits(gb, 2); AV_DEBUG(" %d floor %d class dim: %d subclasses %d \n", i, j, floor_setup->data.t1.class_dimensions[j], floor_setup->data.t1.class_subclasses[j]); if (floor_setup->data.t1.class_subclasses[j]) { - floor_setup->data.t1.class_masterbook[j]=get_bits(gb, 8); + GET_VALIDATED_INDEX(floor_setup->data.t1.class_masterbook[j], 8, vc->codebook_count) AV_DEBUG(" masterbook: %d \n", floor_setup->data.t1.class_masterbook[j]); } - for(k=0;k<(1<data.t1.class_subclasses[j]);++k) { - floor_setup->data.t1.subclass_books[j][k]=(int16_t)get_bits(gb, 8)-1; + for (k = 0; k < (1 << floor_setup->data.t1.class_subclasses[j]); ++k) { + int16_t bits = get_bits(gb, 8) - 1; + if (bits != -1) + VALIDATE_INDEX(bits, vc->codebook_count) + floor_setup->data.t1.subclass_books[j][k] = bits; AV_DEBUG(" book %d. : %d \n", k, floor_setup->data.t1.subclass_books[j][k]); } } - floor_setup->data.t1.multiplier=get_bits(gb, 2)+1; - floor_setup->data.t1.x_list_dim=2; + floor_setup->data.t1.multiplier = get_bits(gb, 2) + 1; + floor_setup->data.t1.x_list_dim = 2; - for(j=0;jdata.t1.partitions;++j) { + for (j = 0; j < floor_setup->data.t1.partitions; ++j) floor_setup->data.t1.x_list_dim+=floor_setup->data.t1.class_dimensions[floor_setup->data.t1.partition_class[j]]; - } - floor_setup->data.t1.list=av_mallocz(floor_setup->data.t1.x_list_dim * sizeof(vorbis_floor1_entry)); + floor_setup->data.t1.list = av_mallocz(floor_setup->data.t1.x_list_dim * sizeof(vorbis_floor1_entry)); - rangebits=get_bits(gb, 4); + rangebits = get_bits(gb, 4); floor_setup->data.t1.list[0].x = 0; - floor_setup->data.t1.list[1].x = (1<data.t1.list[1].x = (1 << rangebits); - for(j=0;jdata.t1.partitions;++j) { - for(k=0;kdata.t1.class_dimensions[floor_setup->data.t1.partition_class[j]];++k,++floor1_values) { - floor_setup->data.t1.list[floor1_values].x=get_bits(gb, rangebits); + for (j = 0; j < floor_setup->data.t1.partitions; ++j) { + for (k = 0; k < floor_setup->data.t1.class_dimensions[floor_setup->data.t1.partition_class[j]]; ++k, ++floor1_values) { + floor_setup->data.t1.list[floor1_values].x = get_bits(gb, rangebits); AV_DEBUG(" %d. floor1 Y coord. %d \n", floor1_values, floor_setup->data.t1.list[floor1_values].x); } @@ -523,55 +543,52 @@ static int vorbis_parse_setup_hdr_floors(vorbis_context *vc) { // Precalculate order of x coordinates - needed for decode ff_vorbis_ready_floor1_list(floor_setup->data.t1.list, floor_setup->data.t1.x_list_dim); - } - else if(floor_setup->floor_type==0) { - uint_fast8_t max_codebook_dim=0; + } else if (floor_setup->floor_type == 0) { + uint_fast8_t max_codebook_dim = 0; - floor_setup->decode=vorbis_floor0_decode; + floor_setup->decode = vorbis_floor0_decode; - floor_setup->data.t0.order=get_bits(gb, 8); - floor_setup->data.t0.rate=get_bits(gb, 16); - floor_setup->data.t0.bark_map_size=get_bits(gb, 16); - floor_setup->data.t0.amplitude_bits=get_bits(gb, 6); + floor_setup->data.t0.order = get_bits(gb, 8); + floor_setup->data.t0.rate = get_bits(gb, 16); + floor_setup->data.t0.bark_map_size = get_bits(gb, 16); + floor_setup->data.t0.amplitude_bits = get_bits(gb, 6); /* zero would result in a div by zero later * * 2^0 - 1 == 0 */ if (floor_setup->data.t0.amplitude_bits == 0) { av_log(vc->avccontext, AV_LOG_ERROR, "Floor 0 amplitude bits is 0.\n"); - return 1; + return -1; } - floor_setup->data.t0.amplitude_offset=get_bits(gb, 8); - floor_setup->data.t0.num_books=get_bits(gb, 4)+1; + floor_setup->data.t0.amplitude_offset = get_bits(gb, 8); + floor_setup->data.t0.num_books = get_bits(gb, 4) + 1; /* allocate mem for booklist */ - floor_setup->data.t0.book_list= + floor_setup->data.t0.book_list = av_malloc(floor_setup->data.t0.num_books); - if(!floor_setup->data.t0.book_list) { return 1; } + if (!floor_setup->data.t0.book_list) + return -1; /* read book indexes */ { int idx; uint_fast8_t book_idx; - for (idx=0;idxdata.t0.num_books;++idx) { - book_idx=get_bits(gb, 8); - floor_setup->data.t0.book_list[idx]=book_idx; + for (idx = 0; idx < floor_setup->data.t0.num_books; ++idx) { + GET_VALIDATED_INDEX(floor_setup->data.t0.book_list[idx], 8, vc->codebook_count) if (vc->codebooks[book_idx].dimensions > max_codebook_dim) - max_codebook_dim=vc->codebooks[book_idx].dimensions; - - if (floor_setup->data.t0.book_list[idx]>vc->codebook_count) - return 1; + max_codebook_dim = vc->codebooks[book_idx].dimensions; } } - create_map( vc, i ); + create_map(vc, i); /* allocate mem for lsp coefficients */ { /* codebook dim is for padding if codebook dim doesn't * * divide order+1 then we need to read more data */ - floor_setup->data.t0.lsp= + floor_setup->data.t0.lsp = av_malloc((floor_setup->data.t0.order+1 + max_codebook_dim) * sizeof(float)); - if(!floor_setup->data.t0.lsp) { return 1; } + if (!floor_setup->data.t0.lsp) + return -1; } #ifdef V_DEBUG /* debug output parsed headers */ @@ -589,17 +606,16 @@ static int vorbis_parse_setup_hdr_floors(vorbis_context *vc) { floor_setup->data.t0.book_list); { int idx; - for (idx=0;idxdata.t0.num_books;++idx) { - AV_DEBUG( " Book %d: %u\n", - idx+1, - floor_setup->data.t0.book_list[idx] ); + for (idx = 0; idx < floor_setup->data.t0.num_books; ++idx) { + AV_DEBUG(" Book %d: %u\n", + idx+1, + floor_setup->data.t0.book_list[idx]); } } #endif - } - else { + } else { av_log(vc->avccontext, AV_LOG_ERROR, "Invalid floor type!\n"); - return 1; + return -1; } } return 0; @@ -607,58 +623,65 @@ static int vorbis_parse_setup_hdr_floors(vorbis_context *vc) { // Process residues part -static int vorbis_parse_setup_hdr_residues(vorbis_context *vc){ - GetBitContext *gb=&vc->gb; +static int vorbis_parse_setup_hdr_residues(vorbis_context *vc) +{ + GetBitContext *gb = &vc->gb; uint_fast8_t i, j, k; - vc->residue_count=get_bits(gb, 6)+1; - vc->residues=av_mallocz(vc->residue_count * sizeof(vorbis_residue)); + vc->residue_count = get_bits(gb, 6)+1; + vc->residues = av_mallocz(vc->residue_count * sizeof(vorbis_residue)); AV_DEBUG(" There are %d residues. \n", vc->residue_count); - for(i=0;iresidue_count;++i) { - vorbis_residue *res_setup=&vc->residues[i]; + for (i = 0; i < vc->residue_count; ++i) { + vorbis_residue *res_setup = &vc->residues[i]; uint_fast8_t cascade[64]; uint_fast8_t high_bits; uint_fast8_t low_bits; - res_setup->type=get_bits(gb, 16); + res_setup->type = get_bits(gb, 16); AV_DEBUG(" %d. residue type %d \n", i, res_setup->type); - res_setup->begin=get_bits(gb, 24); - res_setup->end=get_bits(gb, 24); - res_setup->partition_size=get_bits(gb, 24)+1; - res_setup->classifications=get_bits(gb, 6)+1; - res_setup->classbook=get_bits(gb, 8); + res_setup->begin = get_bits(gb, 24); + res_setup->end = get_bits(gb, 24); + res_setup->partition_size = get_bits(gb, 24) + 1; + /* Validations to prevent a buffer overflow later. */ + if (res_setup->begin>res_setup->end || + res_setup->end>vc->blocksize[1] / (res_setup->type == 2 ? 1 : 2) || + (res_setup->end-res_setup->begin) / res_setup->partition_size > V_MAX_PARTITIONS) { + av_log(vc->avccontext, AV_LOG_ERROR, "partition out of bounds: type, begin, end, size, blocksize: %"PRIdFAST16", %"PRIdFAST32", %"PRIdFAST32", %"PRIdFAST32", %"PRIdFAST32"\n", res_setup->type, res_setup->begin, res_setup->end, res_setup->partition_size, vc->blocksize[1] / 2); + return -1; + } + + res_setup->classifications = get_bits(gb, 6) + 1; + GET_VALIDATED_INDEX(res_setup->classbook, 8, vc->codebook_count) AV_DEBUG(" begin %d end %d part.size %d classif.s %d classbook %d \n", res_setup->begin, res_setup->end, res_setup->partition_size, res_setup->classifications, res_setup->classbook); - for(j=0;jclassifications;++j) { - high_bits=0; - low_bits=get_bits(gb, 3); - if (get_bits1(gb)) { - high_bits=get_bits(gb, 5); - } - cascade[j]=(high_bits<<3)+low_bits; + for (j = 0; j < res_setup->classifications; ++j) { + high_bits = 0; + low_bits = get_bits(gb, 3); + if (get_bits1(gb)) + high_bits = get_bits(gb, 5); + cascade[j] = (high_bits << 3) + low_bits; AV_DEBUG(" %d class casscade depth: %d \n", j, ilog(cascade[j])); } - res_setup->maxpass=0; - for(j=0;jclassifications;++j) { - for(k=0;k<8;++k) { - if (cascade[j]&(1<books[j][k]=get_bits(gb, 8); + res_setup->maxpass = 0; + for (j = 0; j < res_setup->classifications; ++j) { + for (k = 0; k < 8; ++k) { + if (cascade[j]&(1 << k)) { + GET_VALIDATED_INDEX(res_setup->books[j][k], 8, vc->codebook_count) AV_DEBUG(" %d class casscade depth %d book: %d \n", j, k, res_setup->books[j][k]); - if (k>res_setup->maxpass) { - res_setup->maxpass=k; - } + if (k>res_setup->maxpass) + res_setup->maxpass = k; } else { - res_setup->books[j][k]=-1; + res_setup->books[j][k] = -1; } } } @@ -668,59 +691,58 @@ static int vorbis_parse_setup_hdr_residues(vorbis_context *vc){ // Process mappings part -static int vorbis_parse_setup_hdr_mappings(vorbis_context *vc) { - GetBitContext *gb=&vc->gb; +static int vorbis_parse_setup_hdr_mappings(vorbis_context *vc) +{ + GetBitContext *gb = &vc->gb; uint_fast8_t i, j; - vc->mapping_count=get_bits(gb, 6)+1; - vc->mappings=av_mallocz(vc->mapping_count * sizeof(vorbis_mapping)); + vc->mapping_count = get_bits(gb, 6)+1; + vc->mappings = av_mallocz(vc->mapping_count * sizeof(vorbis_mapping)); AV_DEBUG(" There are %d mappings. \n", vc->mapping_count); - for(i=0;imapping_count;++i) { - vorbis_mapping *mapping_setup=&vc->mappings[i]; + for (i = 0; i < vc->mapping_count; ++i) { + vorbis_mapping *mapping_setup = &vc->mappings[i]; if (get_bits(gb, 16)) { av_log(vc->avccontext, AV_LOG_ERROR, "Other mappings than type 0 are not compliant with the Vorbis I specification. \n"); - return 1; + return -1; } if (get_bits1(gb)) { - mapping_setup->submaps=get_bits(gb, 4)+1; + mapping_setup->submaps = get_bits(gb, 4) + 1; } else { - mapping_setup->submaps=1; + mapping_setup->submaps = 1; } if (get_bits1(gb)) { - mapping_setup->coupling_steps=get_bits(gb, 8)+1; - mapping_setup->magnitude=av_mallocz(mapping_setup->coupling_steps * sizeof(uint_fast8_t)); - mapping_setup->angle =av_mallocz(mapping_setup->coupling_steps * sizeof(uint_fast8_t)); - for(j=0;jcoupling_steps;++j) { - mapping_setup->magnitude[j]=get_bits(gb, ilog(vc->audio_channels-1)); - mapping_setup->angle[j]=get_bits(gb, ilog(vc->audio_channels-1)); - // FIXME: sanity checks + mapping_setup->coupling_steps = get_bits(gb, 8) + 1; + mapping_setup->magnitude = av_mallocz(mapping_setup->coupling_steps * sizeof(uint_fast8_t)); + mapping_setup->angle = av_mallocz(mapping_setup->coupling_steps * sizeof(uint_fast8_t)); + for (j = 0; j < mapping_setup->coupling_steps; ++j) { + GET_VALIDATED_INDEX(mapping_setup->magnitude[j], ilog(vc->audio_channels - 1), vc->audio_channels) + GET_VALIDATED_INDEX(mapping_setup->angle[j], ilog(vc->audio_channels - 1), vc->audio_channels) } } else { - mapping_setup->coupling_steps=0; + mapping_setup->coupling_steps = 0; } AV_DEBUG(" %d mapping coupling steps: %d \n", i, mapping_setup->coupling_steps); - if(get_bits(gb, 2)) { + if (get_bits(gb, 2)) { av_log(vc->avccontext, AV_LOG_ERROR, "%d. mapping setup data invalid. \n", i); - return 1; // following spec. + return -1; // following spec. } if (mapping_setup->submaps>1) { - mapping_setup->mux=av_mallocz(vc->audio_channels * sizeof(uint_fast8_t)); - for(j=0;jaudio_channels;++j) { - mapping_setup->mux[j]=get_bits(gb, 4); - } + mapping_setup->mux = av_mallocz(vc->audio_channels * sizeof(uint_fast8_t)); + for (j = 0; j < vc->audio_channels; ++j) + mapping_setup->mux[j] = get_bits(gb, 4); } - for(j=0;jsubmaps;++j) { + for (j = 0; j < mapping_setup->submaps; ++j) { skip_bits(gb, 8); // FIXME check? - mapping_setup->submap_floor[j]=get_bits(gb, 8); - mapping_setup->submap_residue[j]=get_bits(gb, 8); + GET_VALIDATED_INDEX(mapping_setup->submap_floor[j], 8, vc->floor_count) + GET_VALIDATED_INDEX(mapping_setup->submap_residue[j], 8, vc->residue_count) AV_DEBUG(" %d mapping %d submap : floor %d, residue %d \n", i, j, mapping_setup->submap_floor[j], mapping_setup->submap_residue[j]); } @@ -730,60 +752,59 @@ static int vorbis_parse_setup_hdr_mappings(vorbis_context *vc) { // Process modes part -static void create_map( vorbis_context * vc, uint_fast8_t floor_number ) +static void create_map(vorbis_context *vc, uint_fast8_t floor_number) { - vorbis_floor * floors=vc->floors; - vorbis_floor0 * vf; + vorbis_floor *floors = vc->floors; + vorbis_floor0 *vf; int idx; int_fast8_t blockflag; - int_fast32_t * map; + int_fast32_t *map; int_fast32_t n; //TODO: could theoretically be smaller? - for (blockflag=0;blockflag<2;++blockflag) - { - n=vc->blocksize[blockflag]/2; - floors[floor_number].data.t0.map[blockflag]= - av_malloc((n+1) * sizeof(int_fast32_t)); // n+sentinel + for (blockflag = 0; blockflag < 2; ++blockflag) { + n = vc->blocksize[blockflag] / 2; + floors[floor_number].data.t0.map[blockflag] = + av_malloc((n+1) * sizeof(int_fast32_t)); // n + sentinel - map=floors[floor_number].data.t0.map[blockflag]; - vf=&floors[floor_number].data.t0; + map = floors[floor_number].data.t0.map[blockflag]; + vf = &floors[floor_number].data.t0; - for (idx=0; idxrate*idx)/(2.0f*n)) * - ((vf->bark_map_size)/ - BARK(vf->rate/2.0f )) ); - if (vf->bark_map_size-1 < map[idx]) { - map[idx]=vf->bark_map_size-1; + for (idx = 0; idx < n; ++idx) { + map[idx] = floor(BARK((vf->rate * idx) / (2.0f * n)) * + ((vf->bark_map_size) / + BARK(vf->rate / 2.0f))); + if (vf->bark_map_size-1 < map[idx]) + map[idx] = vf->bark_map_size - 1; } - } - map[n]=-1; - vf->map_size[blockflag]=n; + map[n] = -1; + vf->map_size[blockflag] = n; } # ifdef V_DEBUG - for(idx=0;idx<=n;++idx) { + for (idx = 0; idx <= n; ++idx) { AV_DEBUG("floor0 map: map at pos %d is %d\n", idx, map[idx]); } # endif } -static int vorbis_parse_setup_hdr_modes(vorbis_context *vc) { - GetBitContext *gb=&vc->gb; +static int vorbis_parse_setup_hdr_modes(vorbis_context *vc) +{ + GetBitContext *gb = &vc->gb; uint_fast8_t i; - vc->mode_count=get_bits(gb, 6)+1; - vc->modes=av_mallocz(vc->mode_count * sizeof(vorbis_mode)); + vc->mode_count = get_bits(gb, 6) + 1; + vc->modes = av_mallocz(vc->mode_count * sizeof(vorbis_mode)); AV_DEBUG(" There are %d modes.\n", vc->mode_count); - for(i=0;imode_count;++i) { - vorbis_mode *mode_setup=&vc->modes[i]; + for (i = 0; i < vc->mode_count; ++i) { + vorbis_mode *mode_setup = &vc->modes[i]; - mode_setup->blockflag=get_bits1(gb); - mode_setup->windowtype=get_bits(gb, 16); //FIXME check - mode_setup->transformtype=get_bits(gb, 16); //FIXME check - mode_setup->mapping=get_bits(gb, 8); //FIXME check + mode_setup->blockflag = get_bits1(gb); + mode_setup->windowtype = get_bits(gb, 16); //FIXME check + mode_setup->transformtype = get_bits(gb, 16); //FIXME check + GET_VALIDATED_INDEX(mode_setup->mapping, 8, vc->mapping_count); AV_DEBUG(" %d mode: blockflag %d, windowtype %d, transformtype %d, mapping %d \n", i, mode_setup->blockflag, mode_setup->windowtype, mode_setup->transformtype, mode_setup->mapping); } @@ -792,43 +813,44 @@ static int vorbis_parse_setup_hdr_modes(vorbis_context *vc) { // Process the whole setup header using the functions above -static int vorbis_parse_setup_hdr(vorbis_context *vc) { - GetBitContext *gb=&vc->gb; +static int vorbis_parse_setup_hdr(vorbis_context *vc) +{ + GetBitContext *gb = &vc->gb; - if ((get_bits(gb, 8)!='v') || (get_bits(gb, 8)!='o') || - (get_bits(gb, 8)!='r') || (get_bits(gb, 8)!='b') || - (get_bits(gb, 8)!='i') || (get_bits(gb, 8)!='s')) { + if ((get_bits(gb, 8) != 'v') || (get_bits(gb, 8) != 'o') || + (get_bits(gb, 8) != 'r') || (get_bits(gb, 8) != 'b') || + (get_bits(gb, 8) != 'i') || (get_bits(gb, 8) != 's')) { av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (no vorbis signature). \n"); - return 1; + return -1; } if (vorbis_parse_setup_hdr_codebooks(vc)) { av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (codebooks). \n"); - return 2; + return -2; } if (vorbis_parse_setup_hdr_tdtransforms(vc)) { av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (time domain transforms). \n"); - return 3; + return -3; } if (vorbis_parse_setup_hdr_floors(vc)) { av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (floors). \n"); - return 4; + return -4; } if (vorbis_parse_setup_hdr_residues(vc)) { av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (residues). \n"); - return 5; + return -5; } if (vorbis_parse_setup_hdr_mappings(vc)) { av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (mappings). \n"); - return 6; + return -6; } if (vorbis_parse_setup_hdr_modes(vc)) { av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (modes). \n"); - return 7; + return -7; } if (!get_bits1(gb)) { av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (framing flag). \n"); - return 8; // framing flag bit unset error + return -8; // framing flag bit unset error } return 0; @@ -836,61 +858,69 @@ static int vorbis_parse_setup_hdr(vorbis_context *vc) { // Process the identification header -static int vorbis_parse_id_hdr(vorbis_context *vc){ - GetBitContext *gb=&vc->gb; +static int vorbis_parse_id_hdr(vorbis_context *vc) +{ + GetBitContext *gb = &vc->gb; uint_fast8_t bl0, bl1; - if ((get_bits(gb, 8)!='v') || (get_bits(gb, 8)!='o') || - (get_bits(gb, 8)!='r') || (get_bits(gb, 8)!='b') || - (get_bits(gb, 8)!='i') || (get_bits(gb, 8)!='s')) { + if ((get_bits(gb, 8) != 'v') || (get_bits(gb, 8) != 'o') || + (get_bits(gb, 8) != 'r') || (get_bits(gb, 8) != 'b') || + (get_bits(gb, 8) != 'i') || (get_bits(gb, 8) != 's')) { av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (no vorbis signature). \n"); - return 1; + return -1; } - vc->version=get_bits_long(gb, 32); //FIXME check 0 - vc->audio_channels=get_bits(gb, 8); //FIXME check >0 - vc->audio_samplerate=get_bits_long(gb, 32); //FIXME check >0 - vc->bitrate_maximum=get_bits_long(gb, 32); - vc->bitrate_nominal=get_bits_long(gb, 32); - vc->bitrate_minimum=get_bits_long(gb, 32); - bl0=get_bits(gb, 4); - bl1=get_bits(gb, 4); - vc->blocksize[0]=(1<blocksize[1]=(1<13 || bl0<6 || bl1>13 || bl1<6 || bl1version = get_bits_long(gb, 32); //FIXME check 0 + vc->audio_channels = get_bits(gb, 8); + if (vc->audio_channels <= 0) { + av_log(vc->avccontext, AV_LOG_ERROR, "Invalid number of channels\n"); + return -1; + } + vc->audio_samplerate = get_bits_long(gb, 32); + if (vc->audio_samplerate <= 0) { + av_log(vc->avccontext, AV_LOG_ERROR, "Invalid samplerate\n"); + return -1; + } + vc->bitrate_maximum = get_bits_long(gb, 32); + vc->bitrate_nominal = get_bits_long(gb, 32); + vc->bitrate_minimum = get_bits_long(gb, 32); + bl0 = get_bits(gb, 4); + bl1 = get_bits(gb, 4); + vc->blocksize[0] = (1 << bl0); + vc->blocksize[1] = (1 << bl1); + if (bl0 > 13 || bl0 < 6 || bl1 > 13 || bl1 < 6 || bl1 < bl0) { av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (illegal blocksize). \n"); - return 3; + return -3; } // output format int16 - if (vc->blocksize[1]/2 * vc->audio_channels * 2 > - AVCODEC_MAX_AUDIO_FRAME_SIZE) { + if (vc->blocksize[1] / 2 * vc->audio_channels * 2 > AVCODEC_MAX_AUDIO_FRAME_SIZE) { av_log(vc->avccontext, AV_LOG_ERROR, "Vorbis channel count makes " "output packets too large.\n"); - return 4; + return -4; } - vc->win[0]=ff_vorbis_vwin[bl0-6]; - vc->win[1]=ff_vorbis_vwin[bl1-6]; + vc->win[0] = ff_vorbis_vwin[bl0 - 6]; + vc->win[1] = ff_vorbis_vwin[bl1 - 6]; if ((get_bits1(gb)) == 0) { av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (framing flag not set). \n"); - return 2; + return -2; } - vc->channel_residues= av_malloc((vc->blocksize[1]/2)*vc->audio_channels * sizeof(float)); - vc->channel_floors = av_malloc((vc->blocksize[1]/2)*vc->audio_channels * sizeof(float)); - vc->saved = av_mallocz((vc->blocksize[1]/4)*vc->audio_channels * sizeof(float)); - vc->previous_window=0; + vc->channel_residues = av_malloc((vc->blocksize[1] / 2) * vc->audio_channels * sizeof(float)); + vc->channel_floors = av_malloc((vc->blocksize[1] / 2) * vc->audio_channels * sizeof(float)); + vc->saved = av_mallocz((vc->blocksize[1] / 4) * vc->audio_channels * sizeof(float)); + vc->previous_window = 0; - ff_mdct_init(&vc->mdct[0], bl0, 1, vc->exp_bias ? -(1<<15) : -1.0); - ff_mdct_init(&vc->mdct[1], bl1, 1, vc->exp_bias ? -(1<<15) : -1.0); + ff_mdct_init(&vc->mdct[0], bl0, 1, vc->exp_bias ? -(1 << 15) : -1.0); + ff_mdct_init(&vc->mdct[1], bl1, 1, vc->exp_bias ? -(1 << 15) : -1.0); AV_DEBUG(" vorbis version %d \n audio_channels %d \n audio_samplerate %d \n bitrate_max %d \n bitrate_nom %d \n bitrate_min %d \n blk_0 %d blk_1 %d \n ", vc->version, vc->audio_channels, vc->audio_samplerate, vc->bitrate_maximum, vc->bitrate_nominal, vc->bitrate_minimum, vc->blocksize[0], vc->blocksize[1]); /* - BLK=vc->blocksize[0]; - for(i=0;iwin[0][i]=sin(0.5*3.14159265358*(sin(((float)i+0.5)/(float)BLK*3.14159265358))*(sin(((float)i+0.5)/(float)BLK*3.14159265358))); + BLK = vc->blocksize[0]; + for (i = 0; i < BLK / 2; ++i) { + vc->win[0][i] = sin(0.5*3.14159265358*(sin(((float)i + 0.5) / (float)BLK*3.14159265358))*(sin(((float)i + 0.5) / (float)BLK*3.14159265358))); } */ @@ -899,10 +929,11 @@ static int vorbis_parse_id_hdr(vorbis_context *vc){ // Process the extradata using the functions above (identification header, setup header) -static av_cold int vorbis_decode_init(AVCodecContext *avccontext) { +static av_cold int vorbis_decode_init(AVCodecContext *avccontext) +{ vorbis_context *vc = avccontext->priv_data ; - uint8_t *headers = avccontext->extradata; - int headers_len=avccontext->extradata_size; + uint8_t *headers = avccontext->extradata; + int headers_len = avccontext->extradata_size; uint8_t *header_start[3]; int header_len[3]; GetBitContext *gb = &(vc->gb); @@ -911,16 +942,16 @@ static av_cold int vorbis_decode_init(AVCodecContext *avccontext) { vc->avccontext = avccontext; dsputil_init(&vc->dsp, avccontext); - if(vc->dsp.float_to_int16_interleave == ff_float_to_int16_interleave_c) { + if (vc->dsp.float_to_int16_interleave == ff_float_to_int16_interleave_c) { vc->add_bias = 385; vc->exp_bias = 0; } else { vc->add_bias = 0; - vc->exp_bias = 15<<23; + vc->exp_bias = 15 << 23; } if (!headers_len) { - av_log(avccontext, AV_LOG_ERROR, "Extradata corrupt.\n"); + av_log(avccontext, AV_LOG_ERROR, "Extradata missing.\n"); return -1; } @@ -930,8 +961,8 @@ static av_cold int vorbis_decode_init(AVCodecContext *avccontext) { } init_get_bits(gb, header_start[0], header_len[0]*8); - hdr_type=get_bits(gb, 8); - if (hdr_type!=1) { + hdr_type = get_bits(gb, 8); + if (hdr_type != 1) { av_log(avccontext, AV_LOG_ERROR, "First header is not the id header.\n"); return -1; } @@ -942,8 +973,8 @@ static av_cold int vorbis_decode_init(AVCodecContext *avccontext) { } init_get_bits(gb, header_start[2], header_len[2]*8); - hdr_type=get_bits(gb, 8); - if (hdr_type!=5) { + hdr_type = get_bits(gb, 8); + if (hdr_type != 5) { av_log(avccontext, AV_LOG_ERROR, "Third header is not the setup header.\n"); vorbis_free(vc); return -1; @@ -954,10 +985,15 @@ static av_cold int vorbis_decode_init(AVCodecContext *avccontext) { return -1; } - avccontext->channels = vc->audio_channels; + if (vc->audio_channels > 8) + avccontext->channel_layout = 0; + else + avccontext->channel_layout = ff_vorbis_channel_layouts[vc->audio_channels - 1]; + + avccontext->channels = vc->audio_channels; avccontext->sample_rate = vc->audio_samplerate; - avccontext->frame_size = FFMIN(vc->blocksize[0], vc->blocksize[1])>>2; - avccontext->sample_fmt = SAMPLE_FMT_S16; + avccontext->frame_size = FFMIN(vc->blocksize[0], vc->blocksize[1]) >> 2; + avccontext->sample_fmt = SAMPLE_FMT_S16; return 0 ; } @@ -967,47 +1003,45 @@ static av_cold int vorbis_decode_init(AVCodecContext *avccontext) { // Read and decode floor static uint_fast8_t vorbis_floor0_decode(vorbis_context *vc, - vorbis_floor_data *vfu, float *vec) { - vorbis_floor0 * vf=&vfu->t0; - float * lsp=vf->lsp; + vorbis_floor_data *vfu, float *vec) +{ + vorbis_floor0 *vf = &vfu->t0; + float *lsp = vf->lsp; uint_fast32_t amplitude; uint_fast32_t book_idx; - uint_fast8_t blockflag=vc->modes[vc->mode_number].blockflag; + uint_fast8_t blockflag = vc->modes[vc->mode_number].blockflag; - amplitude=get_bits(&vc->gb, vf->amplitude_bits); - if (amplitude>0) { + amplitude = get_bits(&vc->gb, vf->amplitude_bits); + if (amplitude > 0) { float last = 0; uint_fast16_t lsp_len = 0; uint_fast16_t idx; vorbis_codebook codebook; - book_idx=get_bits(&vc->gb, ilog(vf->num_books)); - if ( book_idx >= vf->num_books ) { - av_log( vc->avccontext, AV_LOG_ERROR, - "floor0 dec: booknumber too high!\n" ); - book_idx= 0; + book_idx = get_bits(&vc->gb, ilog(vf->num_books)); + if (book_idx >= vf->num_books) { + av_log(vc->avccontext, AV_LOG_ERROR, + "floor0 dec: booknumber too high!\n"); + book_idx = 0; //FIXME: look above } - AV_DEBUG( "floor0 dec: booknumber: %u\n", book_idx ); - codebook=vc->codebooks[vf->book_list[book_idx]]; + AV_DEBUG("floor0 dec: booknumber: %u\n", book_idx); + codebook = vc->codebooks[vf->book_list[book_idx]]; while (lsp_lenorder) { int vec_off; - AV_DEBUG( "floor0 dec: book dimension: %d\n", codebook.dimensions ); - AV_DEBUG( "floor0 dec: maximum depth: %d\n", codebook.maxdepth ); + AV_DEBUG("floor0 dec: book dimension: %d\n", codebook.dimensions); + AV_DEBUG("floor0 dec: maximum depth: %d\n", codebook.maxdepth); /* read temp vector */ - vec_off=get_vlc2(&vc->gb, - codebook.vlc.table, - codebook.nb_bits, - codebook.maxdepth ) * - codebook.dimensions; - AV_DEBUG( "floor0 dec: vector offset: %d\n", vec_off ); + vec_off = get_vlc2(&vc->gb, codebook.vlc.table, + codebook.nb_bits, codebook.maxdepth) + * codebook.dimensions; + AV_DEBUG("floor0 dec: vector offset: %d\n", vec_off); /* copy each vector component and add last to it */ - for (idx=0; idxorder; - float wstep=M_PI/vf->bark_map_size; + int order = vf->order; + float wstep = M_PI / vf->bark_map_size; - for(i=0;imap_size, order, wstep); - i=0; - while(imap_size[blockflag]) { - int j, iter_cond=vf->map[blockflag][i]; - float p=0.5f; - float q=0.5f; - float two_cos_w=2.0f*cos(wstep*iter_cond); // needed all times + i = 0; + while (i < vf->map_size[blockflag]) { + int j, iter_cond = vf->map[blockflag][i]; + float p = 0.5f; + float q = 0.5f; + float two_cos_w = 2.0f * cos(wstep * iter_cond); // needed all times /* similar part for the q and p products */ - for(j=0;j+1amplitude_offset)/ - (((1<amplitude_bits)-1) * sqrt(p+q)) ) - - vf->amplitude_offset ) * .11512925f - ); + q = exp((((amplitude*vf->amplitude_offset) / + (((1 << vf->amplitude_bits) - 1) * sqrt(p + q))) + - vf->amplitude_offset) * .11512925f); } /* fill vector */ - do { vec[i]=q; ++i; }while(vf->map[blockflag][i]==iter_cond); + do { + vec[i] = q; ++i; + } while (vf->map[blockflag][i] == iter_cond); } } - } - else { + } else { /* this channel is unused */ return 1; } @@ -1079,11 +1112,13 @@ static uint_fast8_t vorbis_floor0_decode(vorbis_context *vc, return 0; } -static uint_fast8_t vorbis_floor1_decode(vorbis_context *vc, vorbis_floor_data *vfu, float *vec) { - vorbis_floor1 * vf=&vfu->t1; - GetBitContext *gb=&vc->gb; - uint_fast16_t range_v[4]={ 256, 128, 86, 64 }; - uint_fast16_t range=range_v[vf->multiplier-1]; +static uint_fast8_t vorbis_floor1_decode(vorbis_context *vc, + vorbis_floor_data *vfu, float *vec) +{ + vorbis_floor1 *vf = &vfu->t1; + GetBitContext *gb = &vc->gb; + uint_fast16_t range_v[4] = { 256, 128, 86, 64 }; + uint_fast16_t range = range_v[vf->multiplier-1]; uint_fast16_t floor1_Y[vf->x_list_dim]; uint_fast16_t floor1_Y_final[vf->x_list_dim]; int floor1_flag[vf->x_list_dim]; @@ -1095,45 +1130,45 @@ static uint_fast8_t vorbis_floor1_decode(vorbis_context *vc, vorbis_floor_data * int_fast16_t book; uint_fast16_t offset; uint_fast16_t i,j; - /*u*/int_fast16_t adx, ady, off, predicted; // WTF ? dy/adx= (unsigned)dy/adx ? + /*u*/int_fast16_t adx, ady, off, predicted; // WTF ? dy/adx = (unsigned)dy/adx ? int_fast16_t dy, err; - if (!get_bits1(gb)) return 1; // silence + if (!get_bits1(gb)) // silence + return 1; // Read values (or differences) for the floor's points - floor1_Y[0]=get_bits(gb, ilog(range-1)); - floor1_Y[1]=get_bits(gb, ilog(range-1)); + floor1_Y[0] = get_bits(gb, ilog(range - 1)); + floor1_Y[1] = get_bits(gb, ilog(range - 1)); AV_DEBUG("floor 0 Y %d floor 1 Y %d \n", floor1_Y[0], floor1_Y[1]); - offset=2; - for(i=0;ipartitions;++i) { - class_=vf->partition_class[i]; - cdim=vf->class_dimensions[class_]; - cbits=vf->class_subclasses[class_]; - csub=(1<partitions; ++i) { + class_ = vf->partition_class[i]; + cdim = vf->class_dimensions[class_]; + cbits = vf->class_subclasses[class_]; + csub = (1 << cbits) - 1; + cval = 0; AV_DEBUG("Cbits %d \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); - } + 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); - for(j=0;jsubclass_books[class_][cval & csub]; + for (j = 0; j < cdim; ++j) { + book = vf->subclass_books[class_][cval & csub]; AV_DEBUG("book %d Cbits %d cval %d bits:%d \n", book, cbits, cval, get_bits_count(gb)); - cval=cval>>cbits; - if (book>-1) { - floor1_Y[offset+j]=get_vlc2(gb, vc->codebooks[book].vlc.table, + cval = cval >> cbits; + if (book > -1) { + floor1_Y[offset+j] = get_vlc2(gb, vc->codebooks[book].vlc.table, vc->codebooks[book].nb_bits, 3); } else { - floor1_Y[offset+j]=0; + floor1_Y[offset+j] = 0; } AV_DEBUG(" floor(%d) = %d \n", vf->list[offset+j].x, floor1_Y[offset+j]); @@ -1143,57 +1178,57 @@ static uint_fast8_t vorbis_floor1_decode(vorbis_context *vc, vorbis_floor_data * // Amplitude calculation from the differences - floor1_flag[0]=1; - floor1_flag[1]=1; - floor1_Y_final[0]=floor1_Y[0]; - floor1_Y_final[1]=floor1_Y[1]; + floor1_flag[0] = 1; + floor1_flag[1] = 1; + floor1_Y_final[0] = floor1_Y[0]; + floor1_Y_final[1] = floor1_Y[1]; - for(i=2;ix_list_dim;++i) { + for (i = 2; i < vf->x_list_dim; ++i) { uint_fast16_t val, highroom, lowroom, room; uint_fast16_t high_neigh_offs; uint_fast16_t low_neigh_offs; - low_neigh_offs=vf->list[i].low; - high_neigh_offs=vf->list[i].high; - dy=floor1_Y_final[high_neigh_offs]-floor1_Y_final[low_neigh_offs]; // render_point begin - adx=vf->list[high_neigh_offs].x-vf->list[low_neigh_offs].x; - ady= FFABS(dy); - err=ady*(vf->list[i].x-vf->list[low_neigh_offs].x); - off=(int16_t)err/(int16_t)adx; - if (dy<0) { - predicted=floor1_Y_final[low_neigh_offs]-off; + low_neigh_offs = vf->list[i].low; + high_neigh_offs = vf->list[i].high; + dy = floor1_Y_final[high_neigh_offs] - floor1_Y_final[low_neigh_offs]; // render_point begin + adx = vf->list[high_neigh_offs].x - vf->list[low_neigh_offs].x; + ady = FFABS(dy); + err = ady * (vf->list[i].x - vf->list[low_neigh_offs].x); + off = (int16_t)err / (int16_t)adx; + if (dy < 0) { + predicted = floor1_Y_final[low_neigh_offs] - off; } else { - predicted=floor1_Y_final[low_neigh_offs]+off; + predicted = floor1_Y_final[low_neigh_offs] + off; } // render_point end - val=floor1_Y[i]; - highroom=range-predicted; - lowroom=predicted; + val = floor1_Y[i]; + highroom = range-predicted; + lowroom = predicted; if (highroom < lowroom) { - room=highroom*2; + room = highroom * 2; } else { - room=lowroom*2; // SPEC mispelling + room = lowroom * 2; // SPEC mispelling } if (val) { - floor1_flag[low_neigh_offs]=1; - floor1_flag[high_neigh_offs]=1; - floor1_flag[i]=1; - if (val>=room) { + floor1_flag[low_neigh_offs] = 1; + floor1_flag[high_neigh_offs] = 1; + floor1_flag[i] = 1; + if (val >= room) { if (highroom > lowroom) { - floor1_Y_final[i]=val-lowroom+predicted; + floor1_Y_final[i] = val - lowroom + predicted; } else { - floor1_Y_final[i]=predicted-val+highroom-1; + floor1_Y_final[i] = predicted - val + highroom - 1; } } else { if (val & 1) { - floor1_Y_final[i]=predicted-(val+1)/2; + floor1_Y_final[i] = predicted - (val + 1) / 2; } else { - floor1_Y_final[i]=predicted+val/2; + floor1_Y_final[i] = predicted + val / 2; } } } else { - floor1_flag[i]=0; - floor1_Y_final[i]=predicted; + floor1_flag[i] = 0; + floor1_Y_final[i] = predicted; } AV_DEBUG(" Decoded floor(%d) = %d / val %d \n", vf->list[i].x, floor1_Y_final[i], val); @@ -1210,204 +1245,210 @@ static uint_fast8_t vorbis_floor1_decode(vorbis_context *vc, vorbis_floor_data * // Read and decode residue -static av_always_inline int vorbis_residue_decode_internal(vorbis_context *vc, vorbis_residue *vr, uint_fast8_t ch, uint_fast8_t *do_not_decode, float *vec, uint_fast16_t vlen, int vr_type) { - GetBitContext *gb=&vc->gb; - uint_fast8_t c_p_c=vc->codebooks[vr->classbook].dimensions; - uint_fast16_t n_to_read=vr->end-vr->begin; - uint_fast16_t ptns_to_read=n_to_read/vr->partition_size; +static av_always_inline int vorbis_residue_decode_internal(vorbis_context *vc, + vorbis_residue *vr, + uint_fast8_t ch, + uint_fast8_t *do_not_decode, + float *vec, + uint_fast16_t vlen, + int vr_type) +{ + GetBitContext *gb = &vc->gb; + uint_fast8_t c_p_c = vc->codebooks[vr->classbook].dimensions; + uint_fast16_t n_to_read = vr->end-vr->begin; + uint_fast16_t ptns_to_read = n_to_read/vr->partition_size; uint_fast8_t classifs[ptns_to_read*vc->audio_channels]; uint_fast8_t pass; uint_fast8_t ch_used; uint_fast8_t i,j,l; uint_fast16_t k; - if (vr_type==2) { - for(j=1;jmaxpass;++pass) { // FIXME OPTIMIZE? + for (pass = 0; pass <= vr->maxpass; ++pass) { // FIXME OPTIMIZE? uint_fast16_t voffset; uint_fast16_t partition_count; uint_fast16_t j_times_ptns_to_read; - voffset=vr->begin; - for(partition_count=0;partition_countbegin; + for (partition_count = 0; partition_count < ptns_to_read;) { // SPEC error if (!pass) { uint_fast32_t inverse_class = ff_inverse[vr->classifications]; - for(j_times_ptns_to_read=0, j=0;jcodebooks[vr->classbook].vlc.table, + uint_fast32_t temp = get_vlc2(gb, vc->codebooks[vr->classbook].vlc.table, vc->codebooks[vr->classbook].nb_bits, 3); AV_DEBUG("Classword: %d \n", temp); - assert(vr->classifications > 1 && temp<=65536); //needed for inverse[] - for(i=0;iclassifications > 1 && temp <= 65536); //needed for inverse[] + for (i = 0; i < c_p_c; ++i) { uint_fast32_t temp2; - temp2=(((uint_fast64_t)temp) * inverse_class)>>32; - if (partition_count+c_p_c-1-i < ptns_to_read) { - classifs[j_times_ptns_to_read+partition_count+c_p_c-1-i]=temp-temp2*vr->classifications; - } - temp=temp2; + temp2 = (((uint_fast64_t)temp) * inverse_class) >> 32; + if (partition_count + c_p_c - 1 - i < ptns_to_read) + classifs[j_times_ptns_to_read + partition_count + c_p_c - 1 - i] = temp - temp2 * vr->classifications; + temp = temp2; } } - j_times_ptns_to_read+=ptns_to_read; + j_times_ptns_to_read += ptns_to_read; } } - for(i=0;(ibooks[vqclass][pass]; + uint_fast8_t vqclass = classifs[j_times_ptns_to_read+partition_count]; + int_fast16_t vqbook = vr->books[vqclass][pass]; - if (vqbook>=0 && vc->codebooks[vqbook].codevectors) { + if (vqbook >= 0 && vc->codebooks[vqbook].codevectors) { uint_fast16_t coffs; - unsigned dim= vc->codebooks[vqbook].dimensions; // not uint_fast8_t: 64bit is slower here on amd64 - uint_fast16_t step= dim==1 ? vr->partition_size - : FASTDIV(vr->partition_size, dim); - vorbis_codebook codebook= vc->codebooks[vqbook]; + unsigned dim = vc->codebooks[vqbook].dimensions; // not uint_fast8_t: 64bit is slower here on amd64 + uint_fast16_t step = dim == 1 ? vr->partition_size + : FASTDIV(vr->partition_size, dim); + vorbis_codebook codebook = vc->codebooks[vqbook]; - if (vr_type==0) { + if (vr_type == 0) { - voffs=voffset+j*vlen; - for(k=0;k>1; + } else if (vr_type == 2 && ch == 2 && (voffset & 1) == 0 && (dim & 1) == 0) { // most frequent case optimized + voffs = voffset >> 1; - if(dim==2) { - for(k=0;kpartition_size; + voffset += vr->partition_size; } } } return 0; } -static inline int vorbis_residue_decode(vorbis_context *vc, vorbis_residue *vr, uint_fast8_t ch, uint_fast8_t *do_not_decode, float *vec, uint_fast16_t vlen) +static inline int vorbis_residue_decode(vorbis_context *vc, vorbis_residue *vr, + uint_fast8_t ch, + uint_fast8_t *do_not_decode, + float *vec, uint_fast16_t vlen) { - if (vr->type==2) + if (vr->type == 2) return vorbis_residue_decode_internal(vc, vr, ch, do_not_decode, vec, vlen, 2); - else if (vr->type==1) + else if (vr->type == 1) return vorbis_residue_decode_internal(vc, vr, ch, do_not_decode, vec, vlen, 1); - else if (vr->type==0) + else if (vr->type == 0) return vorbis_residue_decode_internal(vc, vr, ch, do_not_decode, vec, vlen, 0); else { av_log(vc->avccontext, AV_LOG_ERROR, " Invalid residue type while residue decode?! \n"); - return 1; + return -1; } } void vorbis_inverse_coupling(float *mag, float *ang, int blocksize) { int i; - for(i=0; i0.0) { - if (ang[i]>0.0) { - ang[i]=mag[i]-ang[i]; + for (i = 0; i < blocksize; i++) { + if (mag[i] > 0.0) { + if (ang[i] > 0.0) { + ang[i] = mag[i] - ang[i]; } else { - float temp=ang[i]; - ang[i]=mag[i]; - mag[i]+=temp; + float temp = ang[i]; + ang[i] = mag[i]; + mag[i] += temp; } } else { - if (ang[i]>0.0) { - ang[i]+=mag[i]; + if (ang[i] > 0.0) { + ang[i] += mag[i]; } else { - float temp=ang[i]; - ang[i]=mag[i]; - mag[i]-=temp; + float temp = ang[i]; + ang[i] = mag[i]; + mag[i] -= temp; } } } } -static void copy_normalize(float *dst, float *src, int len, int exp_bias, float add_bias) +static void copy_normalize(float *dst, float *src, int len, int exp_bias, + float add_bias) { int i; - if(exp_bias) { + if (exp_bias) { memcpy(dst, src, len * sizeof(float)); } else { - for(i=0; igb; +static int vorbis_parse_audio_packet(vorbis_context *vc) +{ + GetBitContext *gb = &vc->gb; - uint_fast8_t previous_window=vc->previous_window; + uint_fast8_t previous_window = vc->previous_window; uint_fast8_t mode_number; uint_fast8_t blockflag; uint_fast16_t blocksize; @@ -1415,11 +1456,11 @@ static int vorbis_parse_audio_packet(vorbis_context *vc) { uint_fast8_t no_residue[vc->audio_channels]; uint_fast8_t do_not_decode[vc->audio_channels]; vorbis_mapping *mapping; - float *ch_res_ptr=vc->channel_residues; - float *ch_floor_ptr=vc->channel_floors; + float *ch_res_ptr = vc->channel_residues; + float *ch_floor_ptr = vc->channel_floors; uint_fast8_t res_chan[vc->audio_channels]; - uint_fast8_t res_num=0; - int_fast16_t retlen=0; + uint_fast8_t res_num = 0; + int_fast16_t retlen = 0; float fadd_bias = vc->add_bias; if (get_bits1(gb)) { @@ -1427,113 +1468,112 @@ static int vorbis_parse_audio_packet(vorbis_context *vc) { return -1; // packet type not audio } - if (vc->mode_count==1) { - mode_number=0; + if (vc->mode_count == 1) { + mode_number = 0; } else { - mode_number=get_bits(gb, ilog(vc->mode_count-1)); + GET_VALIDATED_INDEX(mode_number, ilog(vc->mode_count-1), vc->mode_count) } - vc->mode_number=mode_number; - mapping=&vc->mappings[vc->modes[mode_number].mapping]; + vc->mode_number = mode_number; + mapping = &vc->mappings[vc->modes[mode_number].mapping]; AV_DEBUG(" Mode number: %d , mapping: %d , blocktype %d \n", mode_number, vc->modes[mode_number].mapping, vc->modes[mode_number].blockflag); - blockflag=vc->modes[mode_number].blockflag; - blocksize=vc->blocksize[blockflag]; - if (blockflag) { + blockflag = vc->modes[mode_number].blockflag; + blocksize = vc->blocksize[blockflag]; + if (blockflag) skip_bits(gb, 2); // previous_window, next_window - } - memset(ch_res_ptr, 0, sizeof(float)*vc->audio_channels*blocksize/2); //FIXME can this be removed ? - memset(ch_floor_ptr, 0, sizeof(float)*vc->audio_channels*blocksize/2); //FIXME can this be removed ? + memset(ch_res_ptr, 0, sizeof(float) * vc->audio_channels * blocksize / 2); //FIXME can this be removed ? + memset(ch_floor_ptr, 0, sizeof(float) * vc->audio_channels * blocksize / 2); //FIXME can this be removed ? // Decode floor - for(i=0;iaudio_channels;++i) { + for (i = 0; i < vc->audio_channels; ++i) { vorbis_floor *floor; - if (mapping->submaps>1) { - floor=&vc->floors[mapping->submap_floor[mapping->mux[i]]]; + if (mapping->submaps > 1) { + floor = &vc->floors[mapping->submap_floor[mapping->mux[i]]]; } else { - floor=&vc->floors[mapping->submap_floor[0]]; + floor = &vc->floors[mapping->submap_floor[0]]; } - no_residue[i]=floor->decode(vc, &floor->data, ch_floor_ptr); - ch_floor_ptr+=blocksize/2; + no_residue[i] = floor->decode(vc, &floor->data, ch_floor_ptr); + ch_floor_ptr += blocksize / 2; } // Nonzero vector propagate - for(i=mapping->coupling_steps-1;i>=0;--i) { + for (i = mapping->coupling_steps - 1; i >= 0; --i) { if (!(no_residue[mapping->magnitude[i]] & no_residue[mapping->angle[i]])) { - no_residue[mapping->magnitude[i]]=0; - no_residue[mapping->angle[i]]=0; + no_residue[mapping->magnitude[i]] = 0; + no_residue[mapping->angle[i]] = 0; } } // Decode residue - for(i=0;isubmaps;++i) { + for (i = 0; i < mapping->submaps; ++i) { vorbis_residue *residue; - uint_fast8_t ch=0; + uint_fast8_t ch = 0; - for(j=0;jaudio_channels;++j) { - if ((mapping->submaps==1) || (i=mapping->mux[j])) { - res_chan[j]=res_num; + for (j = 0; j < vc->audio_channels; ++j) { + if ((mapping->submaps == 1) || (i == mapping->mux[j])) { + res_chan[j] = res_num; if (no_residue[j]) { - do_not_decode[ch]=1; + do_not_decode[ch] = 1; } else { - do_not_decode[ch]=0; + do_not_decode[ch] = 0; } ++ch; ++res_num; } } - residue=&vc->residues[mapping->submap_residue[i]]; + residue = &vc->residues[mapping->submap_residue[i]]; vorbis_residue_decode(vc, residue, ch, do_not_decode, ch_res_ptr, blocksize/2); - ch_res_ptr+=ch*blocksize/2; + ch_res_ptr += ch * blocksize / 2; } // Inverse coupling - for(i=mapping->coupling_steps-1;i>=0;--i) { //warning: i has to be signed + for (i = mapping->coupling_steps - 1; i >= 0; --i) { //warning: i has to be signed float *mag, *ang; - mag=vc->channel_residues+res_chan[mapping->magnitude[i]]*blocksize/2; - ang=vc->channel_residues+res_chan[mapping->angle[i]]*blocksize/2; - vc->dsp.vorbis_inverse_coupling(mag, ang, blocksize/2); + mag = vc->channel_residues+res_chan[mapping->magnitude[i]] * blocksize / 2; + ang = vc->channel_residues+res_chan[mapping->angle[i]] * blocksize / 2; + vc->dsp.vorbis_inverse_coupling(mag, ang, blocksize / 2); } // Dotproduct, MDCT - for(j=vc->audio_channels-1;j>=0;j--) { - ch_floor_ptr=vc->channel_floors+j*blocksize/2; - ch_res_ptr=vc->channel_residues+res_chan[j]*blocksize/2; - vc->dsp.vector_fmul(ch_floor_ptr, ch_res_ptr, blocksize/2); + for (j = vc->audio_channels-1;j >= 0; j--) { + ch_floor_ptr = vc->channel_floors + j * blocksize / 2; + ch_res_ptr = vc->channel_residues + res_chan[j] * blocksize / 2; + vc->dsp.vector_fmul(ch_floor_ptr, ch_res_ptr, blocksize / 2); ff_imdct_half(&vc->mdct[blockflag], ch_res_ptr, ch_floor_ptr); } // Overlap/add, save data for next overlapping FPMATH - retlen = (blocksize + vc->blocksize[previous_window])/4; - for(j=0;jaudio_channels;j++) { - uint_fast16_t bs0=vc->blocksize[0]; - uint_fast16_t bs1=vc->blocksize[1]; - float *residue=vc->channel_residues+res_chan[j]*blocksize/2; - float *saved=vc->saved+j*bs1/4; - float *ret=vc->channel_floors+j*retlen; - float *buf=residue; - const float *win=vc->win[blockflag&previous_window]; + retlen = (blocksize + vc->blocksize[previous_window]) / 4; + for (j = 0; j < vc->audio_channels; j++) { + uint_fast16_t bs0 = vc->blocksize[0]; + uint_fast16_t bs1 = vc->blocksize[1]; + float *residue = vc->channel_residues + res_chan[j] * blocksize / 2; + float *saved = vc->saved + j * bs1 / 4; + float *ret = vc->channel_floors + j * retlen; + float *buf = residue; + const float *win = vc->win[blockflag & previous_window]; - if(blockflag == previous_window) { - vc->dsp.vector_fmul_window(ret, saved, buf, win, fadd_bias, blocksize/4); - } else if(blockflag > previous_window) { - vc->dsp.vector_fmul_window(ret, saved, buf, win, fadd_bias, bs0/4); + if (blockflag == previous_window) { + vc->dsp.vector_fmul_window(ret, saved, buf, win, fadd_bias, blocksize / 4); + } else if (blockflag > previous_window) { + vc->dsp.vector_fmul_window(ret, saved, buf, win, fadd_bias, bs0 / 4); copy_normalize(ret+bs0/2, buf+bs0/4, (bs1-bs0)/4, vc->exp_bias, fadd_bias); } else { - copy_normalize(ret, saved, (bs1-bs0)/4, vc->exp_bias, fadd_bias); - vc->dsp.vector_fmul_window(ret+(bs1-bs0)/4, saved+(bs1-bs0)/4, buf, win, fadd_bias, bs0/4); + copy_normalize(ret, saved, (bs1 - bs0) / 4, vc->exp_bias, fadd_bias); + vc->dsp.vector_fmul_window(ret + (bs1 - bs0) / 4, saved + (bs1 - bs0) / 4, buf, win, fadd_bias, bs0 / 4); } - memcpy(saved, buf+blocksize/4, blocksize/4*sizeof(float)); + memcpy(saved, buf + blocksize / 4, blocksize / 4 * sizeof(float)); } vc->previous_window = blockflag; @@ -1543,11 +1583,11 @@ static int vorbis_parse_audio_packet(vorbis_context *vc) { // Return the decoded audio packet through the standard api static int vorbis_decode_frame(AVCodecContext *avccontext, - void *data, int *data_size, - AVPacket *avpkt) + void *data, int *data_size, + AVPacket *avpkt) { const uint8_t *buf = avpkt->data; - int buf_size = avpkt->size; + int buf_size = avpkt->size; vorbis_context *vc = avccontext->priv_data ; GetBitContext *gb = &(vc->gb); const float *channel_ptrs[vc->audio_channels]; @@ -1555,40 +1595,47 @@ static int vorbis_decode_frame(AVCodecContext *avccontext, int_fast16_t len; - if(!buf_size){ + if (!buf_size) return 0; - } AV_DEBUG("packet length %d \n", buf_size); init_get_bits(gb, buf, buf_size*8); - len=vorbis_parse_audio_packet(vc); + len = vorbis_parse_audio_packet(vc); - if (len<=0) { - *data_size=0; + if (len <= 0) { + *data_size = 0; return buf_size; } if (!vc->first_frame) { - vc->first_frame=1; - *data_size=0; + vc->first_frame = 1; + *data_size = 0; return buf_size ; } AV_DEBUG("parsed %d bytes %d bits, returned %d samples (*ch*bits) \n", get_bits_count(gb)/8, get_bits_count(gb)%8, len); - for(i=0; iaudio_channels; i++) - channel_ptrs[i] = vc->channel_floors+i*len; + if (vc->audio_channels > 8) { + for (i = 0; i < vc->audio_channels; i++) + channel_ptrs[i] = vc->channel_floors + i * len; + } else { + for (i = 0; i < vc->audio_channels; i++) + channel_ptrs[i] = vc->channel_floors + + len * ff_vorbis_channel_layout_offsets[vc->audio_channels - 1][i]; + } + vc->dsp.float_to_int16_interleave(data, channel_ptrs, len, vc->audio_channels); - *data_size=len*2*vc->audio_channels; + *data_size = len * 2 * vc->audio_channels; return buf_size ; } // Close decoder -static av_cold int vorbis_decode_close(AVCodecContext *avccontext) { +static av_cold int vorbis_decode_close(AVCodecContext *avccontext) +{ vorbis_context *vc = avccontext->priv_data; vorbis_free(vc); @@ -1598,7 +1645,7 @@ static av_cold int vorbis_decode_close(AVCodecContext *avccontext) { AVCodec vorbis_decoder = { "vorbis", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_VORBIS, sizeof(vorbis_context), vorbis_decode_init, @@ -1606,5 +1653,6 @@ AVCodec vorbis_decoder = { vorbis_decode_close, vorbis_decode_frame, .long_name = NULL_IF_CONFIG_SMALL("Vorbis"), + .channel_layouts = ff_vorbis_channel_layouts, }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vorbis_enc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/vorbis_enc.c index b6533aca53..934463d1e1 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vorbis_enc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vorbis_enc.c @@ -19,7 +19,7 @@ */ /** - * @file libavcodec/vorbis_enc.c + * @file * Native Vorbis encoder. * @author Oded Shimon */ @@ -27,6 +27,7 @@ #include #include "avcodec.h" #include "dsputil.h" +#include "fft.h" #include "vorbis.h" #include "vorbis_enc_data.h" @@ -38,34 +39,34 @@ typedef struct { int nentries; - uint8_t * lens; - uint32_t * codewords; + uint8_t *lens; + uint32_t *codewords; int ndimentions; float min; float delta; int seq_p; int lookup; - int * quantlist; - float * dimentions; - float * pow2; + int *quantlist; + float *dimentions; + float *pow2; } vorbis_enc_codebook; typedef struct { int dim; int subclass; int masterbook; - int * books; + int *books; } vorbis_enc_floor_class; typedef struct { int partitions; - int * partition_to_class; + int *partition_to_class; int nclasses; - vorbis_enc_floor_class * classes; + vorbis_enc_floor_class *classes; int multiplier; int rangebits; int values; - vorbis_floor1_entry * list; + vorbis_floor1_entry *list; } vorbis_enc_floor; typedef struct { @@ -81,12 +82,12 @@ typedef struct { typedef struct { int submaps; - int * mux; - int * floor; - int * residue; + int *mux; + int *floor; + int *residue; int coupling_steps; - int * magnitude; - int * angle; + int *magnitude; + int *angle; } vorbis_enc_mapping; typedef struct { @@ -98,54 +99,60 @@ typedef struct { int channels; int sample_rate; int log2_blocksize[2]; - MDCTContext mdct[2]; - const float * win[2]; + FFTContext mdct[2]; + const float *win[2]; int have_saved; - float * saved; - float * samples; - float * floor; // also used for tmp values for mdct - float * coeffs; // also used for residue after floor + float *saved; + float *samples; + float *floor; // also used for tmp values for mdct + float *coeffs; // also used for residue after floor float quality; int ncodebooks; - vorbis_enc_codebook * codebooks; + vorbis_enc_codebook *codebooks; int nfloors; - vorbis_enc_floor * floors; + vorbis_enc_floor *floors; int nresidues; - vorbis_enc_residue * residues; + vorbis_enc_residue *residues; int nmappings; - vorbis_enc_mapping * mappings; + vorbis_enc_mapping *mappings; int nmodes; - vorbis_enc_mode * modes; + vorbis_enc_mode *modes; int64_t sample_count; } vorbis_enc_context; -static inline void put_codeword(PutBitContext * pb, vorbis_enc_codebook * cb, int entry) { +static inline void put_codeword(PutBitContext *pb, vorbis_enc_codebook *cb, + int entry) +{ assert(entry >= 0); assert(entry < cb->nentries); assert(cb->lens[entry]); put_bits(pb, cb->lens[entry], cb->codewords[entry]); } -static int cb_lookup_vals(int lookup, int dimentions, int entries) { - if (lookup == 1) return ff_vorbis_nth_root(entries, dimentions); - else if (lookup == 2) return dimentions * entries; +static int cb_lookup_vals(int lookup, int dimentions, int entries) +{ + if (lookup == 1) + return ff_vorbis_nth_root(entries, dimentions); + else if (lookup == 2) + return dimentions *entries; return 0; } -static void ready_codebook(vorbis_enc_codebook * cb) { +static void ready_codebook(vorbis_enc_codebook *cb) +{ int i; ff_vorbis_len2vlc(cb->lens, cb->codewords, cb->nentries); - if (!cb->lookup) + if (!cb->lookup) { cb->pow2 = cb->dimentions = NULL; - else { + } else { int vals = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries); cb->dimentions = av_malloc(sizeof(float) * cb->nentries * cb->ndimentions); cb->pow2 = av_mallocz(sizeof(float) * cb->nentries); @@ -163,7 +170,7 @@ static void ready_codebook(vorbis_enc_codebook * cb) { cb->dimentions[i * cb->ndimentions + j] = last + cb->min + cb->quantlist[off] * cb->delta; if (cb->seq_p) last = cb->dimentions[i * cb->ndimentions + j]; - cb->pow2[i] += cb->dimentions[i * cb->ndimentions + j]*cb->dimentions[i * cb->ndimentions + j]; + cb->pow2[i] += cb->dimentions[i * cb->ndimentions + j] * cb->dimentions[i * cb->ndimentions + j]; div *= vals; } cb->pow2[i] /= 2.; @@ -171,7 +178,8 @@ static void ready_codebook(vorbis_enc_codebook * cb) { } } -static void ready_residue(vorbis_enc_residue * rc, vorbis_enc_context * venc) { +static void ready_residue(vorbis_enc_residue *rc, vorbis_enc_context *venc) +{ int i; assert(rc->type == 2); rc->maxes = av_mallocz(sizeof(float[2]) * rc->classifications); @@ -179,15 +187,18 @@ static void ready_residue(vorbis_enc_residue * rc, vorbis_enc_context * venc) { int j; vorbis_enc_codebook * cb; for (j = 0; j < 8; j++) - if (rc->books[i][j] != -1) break; - if (j == 8) continue; // zero + if (rc->books[i][j] != -1) + break; + if (j == 8) // zero + continue; cb = &venc->codebooks[rc->books[i][j]]; assert(cb->ndimentions >= 2); assert(cb->lookup); for (j = 0; j < cb->nentries; j++) { float a; - if (!cb->lens[j]) continue; + if (!cb->lens[j]) + continue; a = fabs(cb->dimentions[j * cb->ndimentions]); if (a > rc->maxes[i][0]) rc->maxes[i][0] = a; @@ -203,33 +214,35 @@ static void ready_residue(vorbis_enc_residue * rc, vorbis_enc_context * venc) { } } -static void create_vorbis_context(vorbis_enc_context * venc, AVCodecContext * avccontext) { - vorbis_enc_floor * fc; - vorbis_enc_residue * rc; - vorbis_enc_mapping * mc; +static void create_vorbis_context(vorbis_enc_context *venc, + AVCodecContext *avccontext) +{ + vorbis_enc_floor *fc; + vorbis_enc_residue *rc; + vorbis_enc_mapping *mc; int i, book; - venc->channels = avccontext->channels; + venc->channels = avccontext->channels; venc->sample_rate = avccontext->sample_rate; venc->log2_blocksize[0] = venc->log2_blocksize[1] = 11; venc->ncodebooks = FF_ARRAY_ELEMS(cvectors); - venc->codebooks = av_malloc(sizeof(vorbis_enc_codebook) * venc->ncodebooks); + venc->codebooks = av_malloc(sizeof(vorbis_enc_codebook) * venc->ncodebooks); // codebook 0..14 - floor1 book, values 0..255 // codebook 15 residue masterbook // codebook 16..29 residue for (book = 0; book < venc->ncodebooks; book++) { - vorbis_enc_codebook * cb = &venc->codebooks[book]; + vorbis_enc_codebook *cb = &venc->codebooks[book]; int vals; cb->ndimentions = cvectors[book].dim; - cb->nentries = cvectors[book].real_len; - cb->min = cvectors[book].min; - cb->delta = cvectors[book].delta; - cb->lookup = cvectors[book].lookup; - cb->seq_p = 0; + cb->nentries = cvectors[book].real_len; + cb->min = cvectors[book].min; + cb->delta = cvectors[book].delta; + cb->lookup = cvectors[book].lookup; + cb->seq_p = 0; - cb->lens = av_malloc(sizeof(uint8_t) * cb->nentries); + cb->lens = av_malloc(sizeof(uint8_t) * cb->nentries); cb->codewords = av_malloc(sizeof(uint32_t) * cb->nentries); memcpy(cb->lens, cvectors[book].clens, cvectors[book].len); memset(cb->lens + cvectors[book].len, 0, cb->nentries - cvectors[book].len); @@ -246,15 +259,15 @@ static void create_vorbis_context(vorbis_enc_context * venc, AVCodecContext * av } venc->nfloors = 1; - venc->floors = av_malloc(sizeof(vorbis_enc_floor) * venc->nfloors); + venc->floors = av_malloc(sizeof(vorbis_enc_floor) * venc->nfloors); // just 1 floor fc = &venc->floors[0]; - fc->partitions = 8; + fc->partitions = 8; fc->partition_to_class = av_malloc(sizeof(int) * fc->partitions); - fc->nclasses = 0; + fc->nclasses = 0; for (i = 0; i < fc->partitions; i++) { - static const int a[] = {0,1,2,2,3,3,4,4}; + static const int a[] = {0, 1, 2, 2, 3, 3, 4, 4}; fc->partition_to_class[i] = a[i]; fc->nclasses = FFMAX(fc->nclasses, fc->partition_to_class[i]); } @@ -263,16 +276,16 @@ static void create_vorbis_context(vorbis_enc_context * venc, AVCodecContext * av for (i = 0; i < fc->nclasses; i++) { vorbis_enc_floor_class * c = &fc->classes[i]; int j, books; - c->dim = floor_classes[i].dim; - c->subclass = floor_classes[i].subclass; + c->dim = floor_classes[i].dim; + c->subclass = floor_classes[i].subclass; c->masterbook = floor_classes[i].masterbook; - books = (1 << c->subclass); - c->books = av_malloc(sizeof(int) * books); + books = (1 << c->subclass); + c->books = av_malloc(sizeof(int) * books); for (j = 0; j < books; j++) c->books[j] = floor_classes[i].nbooks[j]; } fc->multiplier = 2; - fc->rangebits = venc->log2_blocksize[0] - 1; + fc->rangebits = venc->log2_blocksize[0] - 1; fc->values = 2; for (i = 0; i < fc->partitions; i++) @@ -292,17 +305,17 @@ static void create_vorbis_context(vorbis_enc_context * venc, AVCodecContext * av ff_vorbis_ready_floor1_list(fc->list, fc->values); venc->nresidues = 1; - venc->residues = av_malloc(sizeof(vorbis_enc_residue) * venc->nresidues); + venc->residues = av_malloc(sizeof(vorbis_enc_residue) * venc->nresidues); // single residue rc = &venc->residues[0]; - rc->type = 2; - rc->begin = 0; - rc->end = 1600; - rc->partition_size = 32; + rc->type = 2; + rc->begin = 0; + rc->end = 1600; + rc->partition_size = 32; rc->classifications = 10; - rc->classbook = 15; - rc->books = av_malloc(sizeof(*rc->books) * rc->classifications); + rc->classbook = 15; + rc->books = av_malloc(sizeof(*rc->books) * rc->classifications); { static const int8_t a[10][8] = { { -1, -1, -1, -1, -1, -1, -1, -1, }, @@ -321,40 +334,40 @@ static void create_vorbis_context(vorbis_enc_context * venc, AVCodecContext * av ready_residue(rc, venc); venc->nmappings = 1; - venc->mappings = av_malloc(sizeof(vorbis_enc_mapping) * venc->nmappings); + venc->mappings = av_malloc(sizeof(vorbis_enc_mapping) * venc->nmappings); // single mapping mc = &venc->mappings[0]; mc->submaps = 1; - mc->mux = av_malloc(sizeof(int) * venc->channels); + mc->mux = av_malloc(sizeof(int) * venc->channels); for (i = 0; i < venc->channels; i++) mc->mux[i] = 0; - mc->floor = av_malloc(sizeof(int) * mc->submaps); + mc->floor = av_malloc(sizeof(int) * mc->submaps); mc->residue = av_malloc(sizeof(int) * mc->submaps); for (i = 0; i < mc->submaps; i++) { - mc->floor[i] = 0; + mc->floor[i] = 0; mc->residue[i] = 0; } mc->coupling_steps = venc->channels == 2 ? 1 : 0; - mc->magnitude = av_malloc(sizeof(int) * mc->coupling_steps); - mc->angle = av_malloc(sizeof(int) * mc->coupling_steps); + mc->magnitude = av_malloc(sizeof(int) * mc->coupling_steps); + mc->angle = av_malloc(sizeof(int) * mc->coupling_steps); if (mc->coupling_steps) { mc->magnitude[0] = 0; - mc->angle[0] = 1; + mc->angle[0] = 1; } venc->nmodes = 1; - venc->modes = av_malloc(sizeof(vorbis_enc_mode) * venc->nmodes); + venc->modes = av_malloc(sizeof(vorbis_enc_mode) * venc->nmodes); // single mode venc->modes[0].blockflag = 0; - venc->modes[0].mapping = 0; + venc->modes[0].mapping = 0; venc->have_saved = 0; - venc->saved = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2); - venc->samples = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1])); - venc->floor = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2); - venc->coeffs = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2); + venc->saved = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2); + venc->samples = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1])); + venc->floor = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2); + venc->coeffs = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2); venc->win[0] = ff_vorbis_vwin[venc->log2_blocksize[0] - 6]; venc->win[1] = ff_vorbis_vwin[venc->log2_blocksize[1] - 6]; @@ -363,17 +376,22 @@ static void create_vorbis_context(vorbis_enc_context * venc, AVCodecContext * av ff_mdct_init(&venc->mdct[1], venc->log2_blocksize[1], 0, 1.0); } -static void put_float(PutBitContext * pb, float f) { +static void put_float(PutBitContext *pb, float f) +{ int exp, mant; uint32_t res = 0; mant = (int)ldexp(frexp(f, &exp), 20); exp += 788 - 20; - if (mant < 0) { res |= (1 << 31); mant = -mant; } + if (mant < 0) { + res |= (1 << 31); + mant = -mant; + } res |= mant | (exp << 21); - put_bits(pb, 32, res); + put_bits32(pb, res); } -static void put_codebook_header(PutBitContext * pb, vorbis_enc_codebook * cb) { +static void put_codebook_header(PutBitContext *pb, vorbis_enc_codebook *cb) +{ int i; int ordered = 0; @@ -382,7 +400,8 @@ static void put_codebook_header(PutBitContext * pb, vorbis_enc_codebook * cb) { put_bits(pb, 24, cb->nentries); for (i = 1; i < cb->nentries; i++) - if (cb->lens[i] < cb->lens[i-1]) break; + if (cb->lens[i] < cb->lens[i-1]) + break; if (i == cb->nentries) ordered = 1; @@ -394,7 +413,8 @@ static void put_codebook_header(PutBitContext * pb, vorbis_enc_codebook * cb) { while (i < cb->nentries) { int j; for (j = 0; j+i < cb->nentries; j++) - if (cb->lens[j+i] != len) break; + if (cb->lens[j+i] != len) + break; put_bits(pb, ilog(cb->nentries - i), j); i += j; len++; @@ -402,20 +422,23 @@ static void put_codebook_header(PutBitContext * pb, vorbis_enc_codebook * cb) { } else { int sparse = 0; for (i = 0; i < cb->nentries; i++) - if (!cb->lens[i]) break; + if (!cb->lens[i]) + break; if (i != cb->nentries) sparse = 1; put_bits(pb, 1, sparse); for (i = 0; i < cb->nentries; i++) { - if (sparse) put_bits(pb, 1, !!cb->lens[i]); - if (cb->lens[i]) put_bits(pb, 5, cb->lens[i] - 1); + if (sparse) + put_bits(pb, 1, !!cb->lens[i]); + if (cb->lens[i]) + put_bits(pb, 5, cb->lens[i] - 1); } } put_bits(pb, 4, cb->lookup); if (cb->lookup) { - int tmp = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries); + int tmp = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries); int bits = ilog(cb->quantlist[0]); for (i = 1; i < tmp; i++) @@ -432,7 +455,8 @@ static void put_codebook_header(PutBitContext * pb, vorbis_enc_codebook * cb) { } } -static void put_floor_header(PutBitContext * pb, vorbis_enc_floor * fc) { +static void put_floor_header(PutBitContext *pb, vorbis_enc_floor *fc) +{ int i; put_bits(pb, 16, 1); // type, only floor1 is supported @@ -464,7 +488,8 @@ static void put_floor_header(PutBitContext * pb, vorbis_enc_floor * fc) { put_bits(pb, fc->rangebits, fc->list[i].x); } -static void put_residue_header(PutBitContext * pb, vorbis_enc_residue * rc) { +static void put_residue_header(PutBitContext *pb, vorbis_enc_residue *rc) +{ int i; put_bits(pb, 16, rc->type); @@ -495,10 +520,11 @@ static void put_residue_header(PutBitContext * pb, vorbis_enc_residue * rc) { } } -static int put_main_header(vorbis_enc_context * venc, uint8_t ** out) { +static int put_main_header(vorbis_enc_context *venc, uint8_t **out) +{ int i; PutBitContext pb; - uint8_t buffer[50000] = {0}, * p = buffer; + uint8_t buffer[50000] = {0}, *p = buffer; int buffer_len = sizeof buffer; int len, hlens[3]; @@ -507,18 +533,18 @@ static int put_main_header(vorbis_enc_context * venc, uint8_t ** out) { put_bits(&pb, 8, 1); //magic for (i = 0; "vorbis"[i]; i++) put_bits(&pb, 8, "vorbis"[i]); - put_bits(&pb, 32, 0); // version - put_bits(&pb, 8, venc->channels); - put_bits(&pb, 32, venc->sample_rate); - put_bits(&pb, 32, 0); // bitrate - put_bits(&pb, 32, 0); // bitrate - put_bits(&pb, 32, 0); // bitrate - put_bits(&pb, 4, venc->log2_blocksize[0]); - put_bits(&pb, 4, venc->log2_blocksize[1]); - put_bits(&pb, 1, 1); // framing + put_bits32(&pb, 0); // version + put_bits(&pb, 8, venc->channels); + put_bits32(&pb, venc->sample_rate); + put_bits32(&pb, 0); // bitrate + put_bits32(&pb, 0); // bitrate + put_bits32(&pb, 0); // bitrate + put_bits(&pb, 4, venc->log2_blocksize[0]); + put_bits(&pb, 4, venc->log2_blocksize[1]); + put_bits(&pb, 1, 1); // framing flush_put_bits(&pb); - hlens[0] = (put_bits_count(&pb) + 7) / 8; + hlens[0] = put_bits_count(&pb) >> 3; buffer_len -= hlens[0]; p += hlens[0]; @@ -527,12 +553,12 @@ static int put_main_header(vorbis_enc_context * venc, uint8_t ** out) { put_bits(&pb, 8, 3); //magic for (i = 0; "vorbis"[i]; i++) put_bits(&pb, 8, "vorbis"[i]); - put_bits(&pb, 32, 0); // vendor length TODO - put_bits(&pb, 32, 0); // amount of comments - put_bits(&pb, 1, 1); // framing + put_bits32(&pb, 0); // vendor length TODO + put_bits32(&pb, 0); // amount of comments + put_bits(&pb, 1, 1); // framing flush_put_bits(&pb); - hlens[1] = (put_bits_count(&pb) + 7) / 8; + hlens[1] = put_bits_count(&pb) >> 3; buffer_len -= hlens[1]; p += hlens[1]; @@ -548,7 +574,7 @@ static int put_main_header(vorbis_enc_context * venc, uint8_t ** out) { put_codebook_header(&pb, &venc->codebooks[i]); // time domain, reserved, zero - put_bits(&pb, 6, 0); + put_bits(&pb, 6, 0); put_bits(&pb, 16, 0); // floors @@ -564,7 +590,7 @@ static int put_main_header(vorbis_enc_context * venc, uint8_t ** out) { // mappings put_bits(&pb, 6, venc->nmappings - 1); for (i = 0; i < venc->nmappings; i++) { - vorbis_enc_mapping * mc = &venc->mappings[i]; + vorbis_enc_mapping *mc = &venc->mappings[i]; int j; put_bits(&pb, 16, 0); // mapping type @@ -606,7 +632,7 @@ static int put_main_header(vorbis_enc_context * venc, uint8_t ** out) { put_bits(&pb, 1, 1); // framing flush_put_bits(&pb); - hlens[2] = (put_bits_count(&pb) + 7) / 8; + hlens[2] = put_bits_count(&pb) >> 3; len = hlens[0] + hlens[1] + hlens[2]; p = *out = av_mallocz(64 + len + len/255); @@ -624,7 +650,8 @@ static int put_main_header(vorbis_enc_context * venc, uint8_t ** out) { return p - *out; } -static float get_floor_average(vorbis_enc_floor * fc, float * coeffs, int i) { +static float get_floor_average(vorbis_enc_floor * fc, float *coeffs, int i) +{ int begin = fc->list[fc->list[FFMAX(i-1, 0)].sort].x; int end = fc->list[fc->list[FFMIN(i+1, fc->values - 1)].sort].x; int j; @@ -635,12 +662,14 @@ static float get_floor_average(vorbis_enc_floor * fc, float * coeffs, int i) { return average / (end - begin); } -static void floor_fit(vorbis_enc_context * venc, vorbis_enc_floor * fc, float * coeffs, uint_fast16_t * posts, int samples) { +static void floor_fit(vorbis_enc_context *venc, vorbis_enc_floor *fc, + float *coeffs, uint_fast16_t *posts, int samples) +{ int range = 255 / fc->multiplier + 1; int i; float tot_average = 0.; float averages[fc->values]; - for (i = 0; i < fc->values; i++){ + for (i = 0; i < fc->values; i++) { averages[i] = get_floor_average(fc, coeffs, i); tot_average += averages[i]; } @@ -648,22 +677,27 @@ static void floor_fit(vorbis_enc_context * venc, vorbis_enc_floor * fc, float * tot_average /= venc->quality; for (i = 0; i < fc->values; i++) { - int position = fc->list[fc->list[i].sort].x; + int position = fc->list[fc->list[i].sort].x; float average = averages[i]; int j; average *= pow(tot_average / average, 0.5) * pow(1.25, position/200.); // MAGIC! for (j = 0; j < range - 1; j++) - if (ff_vorbis_floor1_inverse_db_table[j * fc->multiplier] > average) break; + if (ff_vorbis_floor1_inverse_db_table[j * fc->multiplier] > average) + break; posts[fc->list[i].sort] = j; } } -static int render_point(int x0, int y0, int x1, int y1, int x) { +static int render_point(int x0, int y0, int x1, int y1, int x) +{ return y0 + (x - x0) * (y1 - y0) / (x1 - x0); } -static void floor_encode(vorbis_enc_context * venc, vorbis_enc_floor * fc, PutBitContext * pb, uint_fast16_t * posts, float * floor, int samples) { +static void floor_encode(vorbis_enc_context *venc, vorbis_enc_floor *fc, + PutBitContext *pb, uint_fast16_t *posts, + float *floor, int samples) +{ int range = 255 / fc->multiplier + 1; int coded[fc->values]; // first 2 values are unused int i, counter; @@ -686,8 +720,10 @@ static void floor_encode(vorbis_enc_context * venc, vorbis_enc_floor * fc, PutBi coded[i] = 0; // must be used later as flag! continue; } else { - if (!coded[fc->list[i].low ]) coded[fc->list[i].low ] = -1; - if (!coded[fc->list[i].high]) coded[fc->list[i].high] = -1; + if (!coded[fc->list[i].low ]) + coded[fc->list[i].low ] = -1; + if (!coded[fc->list[i].high]) + coded[fc->list[i].high] = -1; } if (posts[i] > predicted) { if (posts[i] - predicted > room) @@ -716,39 +752,46 @@ static void floor_encode(vorbis_enc_context * venc, vorbis_enc_floor * fc, PutBi if (c->books[l] != -1) maxval = venc->codebooks[c->books[l]].nentries; // coded could be -1, but this still works, cause that is 0 - if (coded[counter + k] < maxval) break; + if (coded[counter + k] < maxval) + break; } assert(l != csub); - cval |= l << cshift; + cval |= l << cshift; cshift += c->subclass; } put_codeword(pb, book, cval); } for (k = 0; k < c->dim; k++) { - int book = c->books[cval & (csub-1)]; + int book = c->books[cval & (csub-1)]; int entry = coded[counter++]; cval >>= c->subclass; - if (book == -1) continue; - if (entry == -1) entry = 0; + if (book == -1) + continue; + if (entry == -1) + entry = 0; put_codeword(pb, &venc->codebooks[book], entry); } } - ff_vorbis_floor1_render_list(fc->list, fc->values, posts, coded, fc->multiplier, floor, samples); + ff_vorbis_floor1_render_list(fc->list, fc->values, posts, coded, + fc->multiplier, floor, samples); } -static float * put_vector(vorbis_enc_codebook * book, PutBitContext * pb, float * num) { +static float *put_vector(vorbis_enc_codebook *book, PutBitContext *pb, + float *num) +{ int i, entry = -1; float distance = FLT_MAX; assert(book->dimentions); for (i = 0; i < book->nentries; i++) { float * vec = book->dimentions + i * book->ndimentions, d = book->pow2[i]; int j; - if (!book->lens[i]) continue; + if (!book->lens[i]) + continue; for (j = 0; j < book->ndimentions; j++) d -= vec[j] * num[j]; if (distance > d) { - entry = i; + entry = i; distance = d; } } @@ -756,11 +799,14 @@ static float * put_vector(vorbis_enc_codebook * book, PutBitContext * pb, float return &book->dimentions[entry * book->ndimentions]; } -static void residue_encode(vorbis_enc_context * venc, vorbis_enc_residue * rc, PutBitContext * pb, float * coeffs, int samples, int real_ch) { +static void residue_encode(vorbis_enc_context *venc, vorbis_enc_residue *rc, + PutBitContext *pb, float *coeffs, int samples, + int real_ch) +{ int pass, i, j, p, k; - int psize = rc->partition_size; + int psize = rc->partition_size; int partitions = (rc->end - rc->begin) / psize; - int channels = (rc->type == 2) ? 1 : real_ch; + int channels = (rc->type == 2) ? 1 : real_ch; int classes[channels][partitions]; int classwords = venc->codebooks[rc->classbook].ndimentions; @@ -774,9 +820,9 @@ static void residue_encode(vorbis_enc_context * venc, vorbis_enc_residue * rc, P max2 = FFMAX(max2, fabs(coeffs[samples + k / real_ch])); } - for (i = 0; i < rc->classifications - 1; i++) { - if (max1 < rc->maxes[i][0] && max2 < rc->maxes[i][1]) break; - } + for (i = 0; i < rc->classifications - 1; i++) + if (max1 < rc->maxes[i][0] && max2 < rc->maxes[i][1]) + break; classes[0][p] = i; } @@ -797,15 +843,16 @@ static void residue_encode(vorbis_enc_context * venc, vorbis_enc_residue * rc, P for (j = 0; j < channels; j++) { int nbook = rc->books[classes[j][p]][pass]; vorbis_enc_codebook * book = &venc->codebooks[nbook]; - float * buf = coeffs + samples*j + rc->begin + p*psize; - if (nbook == -1) continue; + float *buf = coeffs + samples*j + rc->begin + p*psize; + if (nbook == -1) + continue; assert(rc->type == 0 || rc->type == 2); assert(!(psize % book->ndimentions)); if (rc->type == 0) { for (k = 0; k < psize; k += book->ndimentions) { - float * a = put_vector(book, pb, &buf[k]); + float *a = put_vector(book, pb, &buf[k]); int l; for (l = 0; l < book->ndimentions; l++) buf[k + l] -= a[l]; @@ -814,14 +861,14 @@ static void residue_encode(vorbis_enc_context * venc, vorbis_enc_residue * rc, P int s = rc->begin + p * psize, a1, b1; a1 = (s % real_ch) * samples; b1 = s / real_ch; - s = real_ch * samples; + s = real_ch * samples; for (k = 0; k < psize; k += book->ndimentions) { int dim, a2 = a1, b2 = b1; - float vec[book->ndimentions], * pv = vec; + float vec[book->ndimentions], *pv = vec; for (dim = book->ndimentions; dim--; ) { *pv++ = coeffs[a2 + b2]; if ((a2 += samples) == s) { - a2=0; + a2 = 0; b2++; } } @@ -829,7 +876,7 @@ static void residue_encode(vorbis_enc_context * venc, vorbis_enc_residue * rc, P for (dim = book->ndimentions; dim--; ) { coeffs[a1 + b1] -= *pv++; if ((a1 += samples) == s) { - a1=0; + a1 = 0; b1++; } } @@ -841,23 +888,26 @@ static void residue_encode(vorbis_enc_context * venc, vorbis_enc_residue * rc, P } } -static int apply_window_and_mdct(vorbis_enc_context * venc, signed short * audio, int samples) { +static int apply_window_and_mdct(vorbis_enc_context *venc, signed short *audio, + int samples) +{ int i, j, channel; const float * win = venc->win[0]; int window_len = 1 << (venc->log2_blocksize[0] - 1); float n = (float)(1 << venc->log2_blocksize[0]) / 4.; // FIXME use dsp - if (!venc->have_saved && !samples) return 0; + if (!venc->have_saved && !samples) + return 0; if (venc->have_saved) { - for (channel = 0; channel < venc->channels; channel++) { - memcpy(venc->samples + channel*window_len*2, venc->saved + channel*window_len, sizeof(float)*window_len); - } + for (channel = 0; channel < venc->channels; channel++) + memcpy(venc->samples + channel * window_len * 2, + venc->saved + channel * window_len, sizeof(float) * window_len); } else { - for (channel = 0; channel < venc->channels; channel++) { - memset(venc->samples + channel*window_len*2, 0, sizeof(float)*window_len); - } + for (channel = 0; channel < venc->channels; channel++) + memset(venc->samples + channel * window_len * 2, 0, + sizeof(float) * window_len); } if (samples) { @@ -868,18 +918,18 @@ static int apply_window_and_mdct(vorbis_enc_context * venc, signed short * audio offset[i] = -audio[j] / 32768. / n * win[window_len - i - 1]; //FIXME find out why the sign has to be fliped } } else { - for (channel = 0; channel < venc->channels; channel++) { - memset(venc->samples + channel*window_len*2 + window_len, 0, sizeof(float)*window_len); - } + for (channel = 0; channel < venc->channels; channel++) + memset(venc->samples + channel * window_len * 2 + window_len, + 0, sizeof(float) * window_len); } - for (channel = 0; channel < venc->channels; channel++) { - ff_mdct_calc(&venc->mdct[0], venc->coeffs + channel*window_len, venc->samples + channel*window_len*2); - } + for (channel = 0; channel < venc->channels; channel++) + ff_mdct_calc(&venc->mdct[0], venc->coeffs + channel * window_len, + venc->samples + channel * window_len * 2); if (samples) { for (channel = 0; channel < venc->channels; channel++) { - float * offset = venc->saved + channel*window_len; + float *offset = venc->saved + channel * window_len; j = channel; for (i = 0; i < samples; i++, j += venc->channels) offset[i] = -audio[j] / 32768. / n * win[i]; //FIXME find out why the sign has to be fliped @@ -891,9 +941,9 @@ static int apply_window_and_mdct(vorbis_enc_context * venc, signed short * audio return 1; } -static av_cold int vorbis_encode_init(AVCodecContext * avccontext) +static av_cold int vorbis_encode_init(AVCodecContext *avccontext) { - vorbis_enc_context * venc = avccontext->priv_data; + vorbis_enc_context *venc = avccontext->priv_data; if (avccontext->channels != 2) { av_log(avccontext, AV_LOG_ERROR, "Current FFmpeg Vorbis encoder only supports 2 channels.\n"); @@ -910,25 +960,28 @@ static av_cold int vorbis_encode_init(AVCodecContext * avccontext) avccontext->extradata_size = put_main_header(venc, (uint8_t**)&avccontext->extradata); - avccontext->frame_size = 1 << (venc->log2_blocksize[0] - 1); + avccontext->frame_size = 1 << (venc->log2_blocksize[0] - 1); - avccontext->coded_frame = avcodec_alloc_frame(); + avccontext->coded_frame = avcodec_alloc_frame(); avccontext->coded_frame->key_frame = 1; return 0; } -static int vorbis_encode_frame(AVCodecContext * avccontext, unsigned char * packets, int buf_size, void *data) +static int vorbis_encode_frame(AVCodecContext *avccontext, + unsigned char *packets, + int buf_size, void *data) { - vorbis_enc_context * venc = avccontext->priv_data; - signed short * audio = data; + vorbis_enc_context *venc = avccontext->priv_data; + signed short *audio = data; int samples = data ? avccontext->frame_size : 0; - vorbis_enc_mode * mode; - vorbis_enc_mapping * mapping; + vorbis_enc_mode *mode; + vorbis_enc_mapping *mapping; PutBitContext pb; int i; - if (!apply_window_and_mdct(venc, audio, samples)) return 0; + if (!apply_window_and_mdct(venc, audio, samples)) + return 0; samples = 1 << (venc->log2_blocksize[0] - 1); init_put_bits(&pb, packets, buf_size); @@ -937,7 +990,7 @@ static int vorbis_encode_frame(AVCodecContext * avccontext, unsigned char * pack put_bits(&pb, ilog(venc->nmodes - 1), 0); // 0 bits, the mode - mode = &venc->modes[0]; + mode = &venc->modes[0]; mapping = &venc->mappings[mode->mapping]; if (mode->blockflag) { put_bits(&pb, 1, 0); @@ -945,40 +998,42 @@ static int vorbis_encode_frame(AVCodecContext * avccontext, unsigned char * pack } for (i = 0; i < venc->channels; i++) { - vorbis_enc_floor * fc = &venc->floors[mapping->floor[mapping->mux[i]]]; + vorbis_enc_floor *fc = &venc->floors[mapping->floor[mapping->mux[i]]]; uint_fast16_t posts[fc->values]; floor_fit(venc, fc, &venc->coeffs[i * samples], posts, samples); floor_encode(venc, fc, &pb, posts, &venc->floor[i * samples], samples); } - for (i = 0; i < venc->channels * samples; i++) { + for (i = 0; i < venc->channels * samples; i++) venc->coeffs[i] /= venc->floor[i]; - } for (i = 0; i < mapping->coupling_steps; i++) { - float * mag = venc->coeffs + mapping->magnitude[i] * samples; - float * ang = venc->coeffs + mapping->angle[i] * samples; + float *mag = venc->coeffs + mapping->magnitude[i] * samples; + float *ang = venc->coeffs + mapping->angle[i] * samples; int j; for (j = 0; j < samples; j++) { float a = ang[j]; ang[j] -= mag[j]; - if (mag[j] > 0) ang[j] = -ang[j]; - if (ang[j] < 0) mag[j] = a; + if (mag[j] > 0) + ang[j] = -ang[j]; + if (ang[j] < 0) + mag[j] = a; } } - residue_encode(venc, &venc->residues[mapping->residue[mapping->mux[0]]], &pb, venc->coeffs, samples, venc->channels); + residue_encode(venc, &venc->residues[mapping->residue[mapping->mux[0]]], + &pb, venc->coeffs, samples, venc->channels); avccontext->coded_frame->pts = venc->sample_count; venc->sample_count += avccontext->frame_size; flush_put_bits(&pb); - return (put_bits_count(&pb) + 7) / 8; + return put_bits_count(&pb) >> 3; } -static av_cold int vorbis_encode_close(AVCodecContext * avccontext) +static av_cold int vorbis_encode_close(AVCodecContext *avccontext) { - vorbis_enc_context * venc = avccontext->priv_data; + vorbis_enc_context *venc = avccontext->priv_data; int i; if (venc->codebooks) @@ -1038,13 +1093,13 @@ static av_cold int vorbis_encode_close(AVCodecContext * avccontext) AVCodec vorbis_encoder = { "vorbis", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_VORBIS, sizeof(vorbis_enc_context), vorbis_encode_init, vorbis_encode_frame, vorbis_encode_close, - .capabilities= CODEC_CAP_DELAY, - .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, + .capabilities= CODEC_CAP_DELAY | CODEC_CAP_EXPERIMENTAL, + .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, .long_name = NULL_IF_CONFIG_SMALL("Vorbis"), }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vorbis_enc_data.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/vorbis_enc_data.h index 7b6347cd87..affc3d6c86 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vorbis_enc_data.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vorbis_enc_data.h @@ -24,96 +24,95 @@ #include static const uint8_t codebook0[] = { - 2, 10, 8, 14, 7, 12, 11, 14, 1, 5, 3, 7, 4, 9, 7, - 13, + 2, 10, 8, 14, 7, 12, 11, 14, 1, 5, 3, 7, 4, 9, 7, 13, }; static const uint8_t codebook1[] = { - 1, 4, 2, 6, 3, 7, 5, 7, + 1, 4, 2, 6, 3, 7, 5, 7, }; static const uint8_t codebook2[] = { - 1, 5, 7, 21, 5, 8, 9, 21, 10, 9, 12, 20, 20, 16, 20, - 20, 4, 8, 9, 20, 6, 8, 9, 20, 11, 11, 13, 20, 20, 15, - 17, 20, 9, 11, 14, 20, 8, 10, 15, 20, 11, 13, 15, 20, 20, - 20, 20, 20, 20, 20, 20, 20, 13, 20, 20, 20, 18, 18, 20, 20, - 20, 20, 20, 20, 3, 6, 8, 20, 6, 7, 9, 20, 10, 9, 12, - 20, 20, 20, 20, 20, 5, 7, 9, 20, 6, 6, 9, 20, 10, 9, - 12, 20, 20, 20, 20, 20, 8, 10, 13, 20, 8, 9, 12, 20, 11, - 10, 12, 20, 20, 20, 20, 20, 18, 20, 20, 20, 15, 17, 18, 20, - 18, 17, 18, 20, 20, 20, 20, 20, 7, 10, 12, 20, 8, 9, 11, - 20, 14, 13, 14, 20, 20, 20, 20, 20, 6, 9, 12, 20, 7, 8, - 11, 20, 12, 11, 13, 20, 20, 20, 20, 20, 9, 11, 15, 20, 8, - 10, 14, 20, 12, 11, 14, 20, 20, 20, 20, 20, 20, 20, 20, 20, - 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 11, 16, 18, - 20, 15, 15, 17, 20, 20, 17, 20, 20, 20, 20, 20, 20, 9, 14, - 16, 20, 12, 12, 15, 20, 17, 15, 18, 20, 20, 20, 20, 20, 16, - 19, 18, 20, 15, 16, 20, 20, 17, 17, 20, 20, 20, 20, 20, 20, - 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, - 20, + 1, 5, 7, 21, 5, 8, 9, 21, 10, 9, 12, 20, 20, 16, 20, + 20, 4, 8, 9, 20, 6, 8, 9, 20, 11, 11, 13, 20, 20, 15, + 17, 20, 9, 11, 14, 20, 8, 10, 15, 20, 11, 13, 15, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 13, 20, 20, 20, 18, 18, 20, 20, + 20, 20, 20, 20, 3, 6, 8, 20, 6, 7, 9, 20, 10, 9, 12, + 20, 20, 20, 20, 20, 5, 7, 9, 20, 6, 6, 9, 20, 10, 9, + 12, 20, 20, 20, 20, 20, 8, 10, 13, 20, 8, 9, 12, 20, 11, + 10, 12, 20, 20, 20, 20, 20, 18, 20, 20, 20, 15, 17, 18, 20, + 18, 17, 18, 20, 20, 20, 20, 20, 7, 10, 12, 20, 8, 9, 11, + 20, 14, 13, 14, 20, 20, 20, 20, 20, 6, 9, 12, 20, 7, 8, + 11, 20, 12, 11, 13, 20, 20, 20, 20, 20, 9, 11, 15, 20, 8, + 10, 14, 20, 12, 11, 14, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 11, 16, 18, + 20, 15, 15, 17, 20, 20, 17, 20, 20, 20, 20, 20, 20, 9, 14, + 16, 20, 12, 12, 15, 20, 17, 15, 18, 20, 20, 20, 20, 20, 16, + 19, 18, 20, 15, 16, 20, 20, 17, 17, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, }; static const uint8_t codebook3[] = { - 2, 3, 7, 13, 4, 4, 7, 15, 8, 6, 9, 17, 21, 16, 15, - 21, 2, 5, 7, 11, 5, 5, 7, 14, 9, 7, 10, 16, 17, 15, - 16, 21, 4, 7, 10, 17, 7, 7, 9, 15, 11, 9, 11, 16, 21, - 18, 15, 21, 18, 21, 21, 21, 15, 17, 17, 19, 21, 19, 18, 20, - 21, 21, 21, 20, + 2, 3, 7, 13, 4, 4, 7, 15, 8, 6, 9, 17, 21, 16, 15, + 21, 2, 5, 7, 11, 5, 5, 7, 14, 9, 7, 10, 16, 17, 15, + 16, 21, 4, 7, 10, 17, 7, 7, 9, 15, 11, 9, 11, 16, 21, + 18, 15, 21, 18, 21, 21, 21, 15, 17, 17, 19, 21, 19, 18, 20, + 21, 21, 21, 20, }; static const uint8_t codebook4[] = { - 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, - 5, 6, 5, 6, 5, 6, 5, 6, 5, 7, 5, 7, 5, 7, 5, - 7, 5, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6, 10, 6, 10, - 6, 11, 6, 11, 7, 11, 7, 12, 7, 12, 7, 12, 7, 12, 7, - 12, 7, 12, 7, 12, 7, 12, 8, 13, 8, 12, 8, 12, 8, 13, - 8, 13, 9, 13, 9, 13, 9, 13, 9, 12, 10, 12, 10, 13, 10, - 14, 11, 14, 12, 14, 13, 14, 13, 14, 14, 15, 16, 15, 15, 15, - 14, 15, 17, 21, 22, 22, 21, 22, 22, 22, 22, 22, 22, 21, 21, - 21, 21, 21, 21, 21, 21, 21, 21, + 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, + 5, 6, 5, 6, 5, 6, 5, 6, 5, 7, 5, 7, 5, 7, 5, + 7, 5, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6, 10, 6, 10, + 6, 11, 6, 11, 7, 11, 7, 12, 7, 12, 7, 12, 7, 12, 7, + 12, 7, 12, 7, 12, 7, 12, 8, 13, 8, 12, 8, 12, 8, 13, + 8, 13, 9, 13, 9, 13, 9, 13, 9, 12, 10, 12, 10, 13, 10, + 14, 11, 14, 12, 14, 13, 14, 13, 14, 14, 15, 16, 15, 15, 15, + 14, 15, 17, 21, 22, 22, 21, 22, 22, 22, 22, 22, 22, 21, 21, + 21, 21, 21, 21, 21, 21, 21, 21, }; static const uint8_t codebook5[] = { - 2, 5, 5, 4, 5, 4, 5, 4, 5, 4, 6, 5, 6, 5, 6, - 5, 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 6, 9, 6, - 9, 6, + 2, 5, 5, 4, 5, 4, 5, 4, 5, 4, 6, 5, 6, 5, 6, + 5, 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 6, 9, 6, + 9, 6, }; static const uint8_t codebook6[] = { - 8, 5, 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, - 4, 9, 4, 9, 4, 9, 4, 8, 4, 8, 4, 9, 5, 9, 5, - 9, 5, 9, 5, 9, 6, 10, 6, 10, 7, 10, 8, 11, 9, 11, - 11, 12, 13, 12, 14, 13, 15, 13, 15, 14, 16, 14, 17, 15, 17, - 15, 15, 16, 16, 15, 16, 16, 16, 15, 18, 16, 15, 17, 17, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, + 8, 5, 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, + 4, 9, 4, 9, 4, 9, 4, 8, 4, 8, 4, 9, 5, 9, 5, + 9, 5, 9, 5, 9, 6, 10, 6, 10, 7, 10, 8, 11, 9, 11, + 11, 12, 13, 12, 14, 13, 15, 13, 15, 14, 16, 14, 17, 15, 17, + 15, 15, 16, 16, 15, 16, 16, 16, 15, 18, 16, 15, 17, 17, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, }; static const uint8_t codebook7[] = { - 1, 5, 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, - 5, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 9, 8, 10, 9, - 10, 9, + 1, 5, 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, + 5, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 9, 8, 10, 9, + 10, 9, }; static const uint8_t codebook8[] = { - 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 5, 5, 6, 5, 6, - 5, 7, 5, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 9, 8, - 9, 9, 9, 9, 10, 10, 10, 11, 9, 12, 9, 12, 9, 15, 10, - 14, 9, 13, 10, 13, 10, 12, 10, 12, 10, 13, 10, 12, 11, 13, - 11, 14, 12, 13, 13, 14, 14, 13, 14, 15, 14, 16, 13, 13, 14, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 15, 15, + 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 5, 5, 6, 5, 6, + 5, 7, 5, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 9, 8, + 9, 9, 9, 9, 10, 10, 10, 11, 9, 12, 9, 12, 9, 15, 10, + 14, 9, 13, 10, 13, 10, 12, 10, 12, 10, 13, 10, 12, 11, 13, + 11, 14, 12, 13, 13, 14, 14, 13, 14, 15, 14, 16, 13, 13, 14, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 15, 15, }; static const uint8_t codebook9[] = { - 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4, 4, 5, - 5, 5, + 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4, 4, 5, + 5, 5, }; static const uint8_t codebook10[] = { - 3, 3, 4, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 5, - 7, 5, 8, 6, 8, 6, 9, 7, 10, 7, 10, 8, 10, 8, 11, - 9, 11, + 3, 3, 4, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 5, + 7, 5, 8, 6, 8, 6, 9, 7, 10, 7, 10, 8, 10, 8, 11, + 9, 11, }; static const uint8_t codebook11[] = { @@ -126,337 +125,337 @@ static const uint8_t codebook11[] = { }; static const uint8_t codebook12[] = { - 4, 5, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, - 5, 4, + 4, 5, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, + 5, 4, }; static const uint8_t codebook13[] = { - 4, 2, 4, 2, 5, 3, 5, 4, 6, 6, 6, 7, 7, 8, 7, - 8, 7, 8, 7, 9, 8, 9, 8, 9, 8, 10, 8, 11, 9, 12, - 9, 12, + 4, 2, 4, 2, 5, 3, 5, 4, 6, 6, 6, 7, 7, 8, 7, + 8, 7, 8, 7, 9, 8, 9, 8, 9, 8, 10, 8, 11, 9, 12, + 9, 12, }; static const uint8_t codebook14[] = { - 2, 5, 2, 6, 3, 6, 4, 7, 4, 7, 5, 9, 5, 11, 6, - 11, 6, 11, 7, 11, 6, 11, 6, 11, 9, 11, 8, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10, 10, - 10, 10, 10, + 2, 5, 2, 6, 3, 6, 4, 7, 4, 7, 5, 9, 5, 11, 6, + 11, 6, 11, 7, 11, 6, 11, 6, 11, 9, 11, 8, 11, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10, 10, 10, + 10, 10, 10, }; static const uint8_t codebook15[] = { - 5, 6, 11, 11, 11, 11, 10, 10, 12, 11, 5, 2, 11, 5, 6, - 6, 7, 9, 11, 13, 13, 10, 7, 11, 6, 7, 8, 9, 10, 12, - 11, 5, 11, 6, 8, 7, 9, 11, 14, 15, 11, 6, 6, 8, 4, - 5, 7, 8, 10, 13, 10, 5, 7, 7, 5, 5, 6, 8, 10, 11, - 10, 7, 7, 8, 6, 5, 5, 7, 9, 9, 11, 8, 8, 11, 8, - 7, 6, 6, 7, 9, 12, 11, 10, 13, 9, 9, 7, 7, 7, 9, - 11, 13, 12, 15, 12, 11, 9, 8, 8, 8, + 5, 6, 11, 11, 11, 11, 10, 10, 12, 11, 5, 2, 11, 5, 6, + 6, 7, 9, 11, 13, 13, 10, 7, 11, 6, 7, 8, 9, 10, 12, + 11, 5, 11, 6, 8, 7, 9, 11, 14, 15, 11, 6, 6, 8, 4, + 5, 7, 8, 10, 13, 10, 5, 7, 7, 5, 5, 6, 8, 10, 11, + 10, 7, 7, 8, 6, 5, 5, 7, 9, 9, 11, 8, 8, 11, 8, + 7, 6, 6, 7, 9, 12, 11, 10, 13, 9, 9, 7, 7, 7, 9, + 11, 13, 12, 15, 12, 11, 9, 8, 8, 8, }; static const uint8_t codebook16[] = { - 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, - 0, 0, 0, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, - 7, 8, 8, 0, 0, 0, 0, 0, 0, 6, 7, 8, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, - 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0, 0, 0, 0, 0, - 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, - 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 8, 9, 0, 0, 0, - 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, - 7, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, - 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0, 0, - 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 7, 8, 9, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, - 0, 0, 0, 8, 9, 8, + 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, + 0, 0, 0, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, + 7, 8, 8, 0, 0, 0, 0, 0, 0, 6, 7, 8, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, + 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0, 0, 0, 0, 0, + 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, + 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 8, 9, 0, 0, 0, + 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, + 7, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, + 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0, 0, + 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 7, 8, 9, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, + 0, 0, 0, 8, 9, 8, }; static const uint8_t codebook17[] = { - 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, - 0, 7, 8, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, - 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 10, 10, 0, 0, - 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, - 0, 7, 7, 0, 0, 0, 10, 10, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, - 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, - 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, - 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, - 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, - 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 10, 10, 0, 0, - 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0, 10, 10, 0, 0, - 0, 0, 0, 0, 0, 8, 10, 10, 0, 0, 0, 9, 9, 0, 0, - 0, 9, 9, 0, 0, 0, 10, 10, + 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, + 0, 7, 8, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, + 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 10, 10, 0, 0, + 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, + 0, 7, 7, 0, 0, 0, 10, 10, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, + 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, + 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, + 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, + 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, + 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 10, 10, 0, 0, + 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0, 10, 10, 0, 0, + 0, 0, 0, 0, 0, 8, 10, 10, 0, 0, 0, 9, 9, 0, 0, + 0, 9, 9, 0, 0, 0, 10, 10, }; static const uint8_t codebook18[] = { - 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 6, 6, 6, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 7, 9, 9, + 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 6, 6, 6, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 7, 9, 9, }; static const uint8_t codebook19[] = { - 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, - 0, 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, - 6, 6, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, - 0, 0, 0, 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, - 0, 0, 0, 0, 0, 0, 9, 9, + 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, + 0, 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, + 6, 6, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, + 0, 0, 0, 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, + 0, 0, 0, 0, 0, 0, 9, 9, }; static const uint8_t codebook20[] = { - 1, 3, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 7, - 8, 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, - 8, 8, 8, 8, 10, 10, 0, 0, 0, 8, 8, 8, 8, 10, 10, - 0, 0, 0, 9, 9, 9, 9, 10, 10, 0, 0, 0, 9, 9, 9, - 9, 10, 10, 0, 0, 0, 10, 10, 10, 10, 11, 11, 0, 0, 0, - 0, 0, 10, 10, 11, 11, + 1, 3, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 7, + 8, 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, + 8, 8, 8, 8, 10, 10, 0, 0, 0, 8, 8, 8, 8, 10, 10, + 0, 0, 0, 9, 9, 9, 9, 10, 10, 0, 0, 0, 9, 9, 9, + 9, 10, 10, 0, 0, 0, 10, 10, 10, 10, 11, 11, 0, 0, 0, + 0, 0, 10, 10, 11, 11, }; static const uint8_t codebook21[] = { - 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 10, 10, - 11, 10, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9, 10, 10, - 10, 10, 11, 11, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9, - 10, 10, 10, 10, 11, 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, - 9, 9, 10, 10, 11, 11, 11, 11, 0, 0, 0, 7, 7, 8, 8, - 9, 9, 9, 9, 10, 10, 11, 11, 11, 12, 0, 0, 0, 8, 8, - 8, 8, 9, 9, 9, 9, 10, 10, 11, 11, 12, 12, 0, 0, 0, - 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 11, 11, 12, 12, 0, - 0, 0, 9, 9, 9, 9, 10, 10, 10, 10, 11, 10, 11, 11, 12, - 12, 0, 0, 0, 0, 0, 9, 9, 10, 10, 10, 10, 11, 11, 11, - 11, 12, 12, 0, 0, 0, 0, 0, 9, 8, 9, 9, 10, 10, 11, - 11, 12, 12, 12, 12, 0, 0, 0, 0, 0, 8, 8, 9, 9, 10, - 10, 11, 11, 12, 11, 12, 12, 0, 0, 0, 0, 0, 9, 10, 10, - 10, 11, 11, 11, 11, 12, 12, 13, 13, 0, 0, 0, 0, 0, 0, - 0, 10, 10, 10, 10, 11, 11, 12, 12, 13, 13, 0, 0, 0, 0, - 0, 0, 0, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 0, 0, - 0, 0, 0, 0, 0, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, - 0, 0, 0, 0, 0, 0, 0, 11, 11, 12, 12, 12, 12, 13, 13, - 13, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 12, 12, 12, - 13, 13, 13, 13, + 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 10, 10, + 11, 10, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9, 10, 10, + 10, 10, 11, 11, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9, + 10, 10, 10, 10, 11, 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, + 9, 9, 10, 10, 11, 11, 11, 11, 0, 0, 0, 7, 7, 8, 8, + 9, 9, 9, 9, 10, 10, 11, 11, 11, 12, 0, 0, 0, 8, 8, + 8, 8, 9, 9, 9, 9, 10, 10, 11, 11, 12, 12, 0, 0, 0, + 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 11, 11, 12, 12, 0, + 0, 0, 9, 9, 9, 9, 10, 10, 10, 10, 11, 10, 11, 11, 12, + 12, 0, 0, 0, 0, 0, 9, 9, 10, 10, 10, 10, 11, 11, 11, + 11, 12, 12, 0, 0, 0, 0, 0, 9, 8, 9, 9, 10, 10, 11, + 11, 12, 12, 12, 12, 0, 0, 0, 0, 0, 8, 8, 9, 9, 10, + 10, 11, 11, 12, 11, 12, 12, 0, 0, 0, 0, 0, 9, 10, 10, + 10, 11, 11, 11, 11, 12, 12, 13, 13, 0, 0, 0, 0, 0, 0, + 0, 10, 10, 10, 10, 11, 11, 12, 12, 13, 13, 0, 0, 0, 0, + 0, 0, 0, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 0, 0, + 0, 0, 0, 0, 0, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, + 0, 0, 0, 0, 0, 0, 0, 11, 11, 12, 12, 12, 12, 13, 13, + 13, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 12, 12, 12, + 13, 13, 13, 13, }; static const uint8_t codebook22[] = { - 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7, 10, 9, 9, - 11, 9, 9, 4, 7, 7, 10, 9, 9, 11, 9, 9, 7, 10, 10, - 11, 11, 10, 12, 11, 11, 6, 9, 9, 11, 10, 10, 11, 10, 10, - 6, 9, 9, 11, 10, 10, 11, 10, 10, 7, 11, 11, 11, 11, 11, - 12, 11, 11, 6, 9, 9, 11, 10, 10, 11, 10, 10, 6, 9, 9, - 11, 10, 10, 11, 10, 10, + 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7, 10, 9, 9, + 11, 9, 9, 4, 7, 7, 10, 9, 9, 11, 9, 9, 7, 10, 10, + 11, 11, 10, 12, 11, 11, 6, 9, 9, 11, 10, 10, 11, 10, 10, + 6, 9, 9, 11, 10, 10, 11, 10, 10, 7, 11, 11, 11, 11, 11, + 12, 11, 11, 6, 9, 9, 11, 10, 10, 11, 10, 10, 6, 9, 9, + 11, 10, 10, 11, 10, 10, }; static const uint8_t codebook23[] = { - 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 10, 5, 5, 6, - 6, 7, 7, 8, 8, 8, 8, 10, 5, 5, 6, 6, 7, 7, 8, - 8, 8, 8, 10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 10, - 10, 10, 7, 7, 8, 7, 8, 8, 8, 8, 10, 10, 10, 8, 8, - 8, 8, 8, 8, 8, 8, 10, 10, 10, 7, 8, 8, 8, 8, 8, - 8, 8, 10, 10, 10, 8, 8, 8, 8, 8, 8, 8, 8, 10, 10, - 10, 10, 10, 8, 8, 8, 8, 8, 8, 10, 10, 10, 10, 10, 9, - 9, 8, 8, 9, 8, 10, 10, 10, 10, 10, 8, 8, 8, 8, 8, - 8, + 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 10, 5, 5, 6, + 6, 7, 7, 8, 8, 8, 8, 10, 5, 5, 6, 6, 7, 7, 8, + 8, 8, 8, 10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 10, + 10, 10, 7, 7, 8, 7, 8, 8, 8, 8, 10, 10, 10, 8, 8, + 8, 8, 8, 8, 8, 8, 10, 10, 10, 7, 8, 8, 8, 8, 8, + 8, 8, 10, 10, 10, 8, 8, 8, 8, 8, 8, 8, 8, 10, 10, + 10, 10, 10, 8, 8, 8, 8, 8, 8, 10, 10, 10, 10, 10, 9, + 9, 8, 8, 9, 8, 10, 10, 10, 10, 10, 8, 8, 8, 8, 8, + 8, }; static const uint8_t codebook24[] = { - 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 6, 5, - 5, 7, 7, 8, 8, 8, 8, 9, 9, 10, 10, 7, 5, 5, 7, - 7, 8, 8, 8, 8, 9, 9, 11, 10, 0, 8, 8, 8, 8, 9, - 9, 9, 9, 10, 10, 11, 11, 0, 8, 8, 8, 8, 9, 9, 9, - 9, 10, 10, 11, 11, 0, 12, 12, 9, 9, 10, 10, 10, 10, 11, - 11, 11, 12, 0, 13, 13, 9, 9, 10, 10, 10, 10, 11, 11, 12, - 12, 0, 0, 0, 10, 10, 10, 10, 11, 11, 12, 12, 12, 12, 0, - 0, 0, 10, 10, 10, 10, 11, 11, 12, 12, 12, 12, 0, 0, 0, - 14, 14, 11, 11, 11, 11, 12, 12, 13, 13, 0, 0, 0, 14, 14, - 11, 11, 11, 11, 12, 12, 13, 13, 0, 0, 0, 0, 0, 12, 12, - 12, 12, 13, 13, 14, 13, 0, 0, 0, 0, 0, 13, 13, 12, 12, - 13, 12, 14, 13, + 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 6, 5, + 5, 7, 7, 8, 8, 8, 8, 9, 9, 10, 10, 7, 5, 5, 7, + 7, 8, 8, 8, 8, 9, 9, 11, 10, 0, 8, 8, 8, 8, 9, + 9, 9, 9, 10, 10, 11, 11, 0, 8, 8, 8, 8, 9, 9, 9, + 9, 10, 10, 11, 11, 0, 12, 12, 9, 9, 10, 10, 10, 10, 11, + 11, 11, 12, 0, 13, 13, 9, 9, 10, 10, 10, 10, 11, 11, 12, + 12, 0, 0, 0, 10, 10, 10, 10, 11, 11, 12, 12, 12, 12, 0, + 0, 0, 10, 10, 10, 10, 11, 11, 12, 12, 12, 12, 0, 0, 0, + 14, 14, 11, 11, 11, 11, 12, 12, 13, 13, 0, 0, 0, 14, 14, + 11, 11, 11, 11, 12, 12, 13, 13, 0, 0, 0, 0, 0, 12, 12, + 12, 12, 13, 13, 14, 13, 0, 0, 0, 0, 0, 13, 13, 12, 12, + 13, 12, 14, 13, }; static const uint8_t codebook25[] = { - 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, - 6, 5, 5, 5, 5, 6, 6, 6, 5, 5, + 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, + 6, 5, 5, 5, 5, 6, 6, 6, 5, 5, }; static const uint8_t codebook26[] = { - 1, 4, 4, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 4, 9, - 8, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 2, 9, 7, 12, - 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 12, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, - 11, 11, 11, 11, + 1, 4, 4, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 4, 9, + 8, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 2, 9, 7, 12, + 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, 12, 11, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, + 11, 11, 11, 11, }; static const uint8_t codebook27[] = { - 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 9, 10, 10, 10, 10, - 6, 5, 5, 7, 7, 8, 8, 10, 8, 11, 10, 12, 12, 13, 13, - 6, 5, 5, 7, 7, 8, 8, 10, 9, 11, 11, 12, 12, 13, 12, - 18, 8, 8, 8, 8, 9, 9, 10, 9, 11, 10, 12, 12, 13, 13, - 18, 8, 8, 8, 8, 9, 9, 10, 10, 11, 11, 13, 12, 14, 13, - 18, 11, 11, 9, 9, 10, 10, 11, 11, 11, 12, 13, 12, 13, 14, - 18, 11, 11, 9, 8, 11, 10, 11, 11, 11, 11, 12, 12, 14, 13, - 18, 18, 18, 10, 11, 10, 11, 12, 12, 12, 12, 13, 12, 14, 13, - 18, 18, 18, 10, 11, 11, 9, 12, 11, 12, 12, 12, 13, 13, 13, - 18, 18, 17, 14, 14, 11, 11, 12, 12, 13, 12, 14, 12, 14, 13, - 18, 18, 18, 14, 14, 11, 10, 12, 9, 12, 13, 13, 13, 13, 13, - 18, 18, 17, 16, 18, 13, 13, 12, 12, 13, 11, 14, 12, 14, 14, - 17, 18, 18, 17, 18, 13, 12, 13, 10, 12, 11, 14, 14, 14, 14, - 17, 18, 18, 18, 18, 15, 16, 12, 12, 13, 10, 14, 12, 14, 15, - 18, 18, 18, 16, 17, 16, 14, 12, 11, 13, 10, 13, 13, 14, 15, + 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 9, 10, 10, 10, 10, + 6, 5, 5, 7, 7, 8, 8, 10, 8, 11, 10, 12, 12, 13, 13, + 6, 5, 5, 7, 7, 8, 8, 10, 9, 11, 11, 12, 12, 13, 12, + 18, 8, 8, 8, 8, 9, 9, 10, 9, 11, 10, 12, 12, 13, 13, + 18, 8, 8, 8, 8, 9, 9, 10, 10, 11, 11, 13, 12, 14, 13, + 18, 11, 11, 9, 9, 10, 10, 11, 11, 11, 12, 13, 12, 13, 14, + 18, 11, 11, 9, 8, 11, 10, 11, 11, 11, 11, 12, 12, 14, 13, + 18, 18, 18, 10, 11, 10, 11, 12, 12, 12, 12, 13, 12, 14, 13, + 18, 18, 18, 10, 11, 11, 9, 12, 11, 12, 12, 12, 13, 13, 13, + 18, 18, 17, 14, 14, 11, 11, 12, 12, 13, 12, 14, 12, 14, 13, + 18, 18, 18, 14, 14, 11, 10, 12, 9, 12, 13, 13, 13, 13, 13, + 18, 18, 17, 16, 18, 13, 13, 12, 12, 13, 11, 14, 12, 14, 14, + 17, 18, 18, 17, 18, 13, 12, 13, 10, 12, 11, 14, 14, 14, 14, + 17, 18, 18, 18, 18, 15, 16, 12, 12, 13, 10, 14, 12, 14, 15, + 18, 18, 18, 16, 17, 16, 14, 12, 11, 13, 10, 13, 13, 14, 15, }; static const uint8_t codebook28[] = { - 2, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, - 8, 8, 10, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 8, 9, - 9, 9, 9, 9, 10, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, - 9, 9, 9, 9, 9, 9, 10, 7, 7, 7, 7, 8, 8, 8, 8, - 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 7, 7, 8, 8, - 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 8, 8, - 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, - 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, - 10, 10, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, - 9, 10, 10, 10, 11, 11, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 11, 10, 11, 11, 11, 9, 9, 9, 9, 9, 9, 10, - 10, 9, 9, 10, 9, 11, 10, 11, 11, 11, 9, 9, 9, 9, 9, - 9, 9, 9, 10, 10, 10, 9, 11, 11, 11, 11, 11, 9, 9, 9, - 9, 10, 10, 9, 9, 9, 9, 10, 9, 11, 11, 11, 11, 11, 11, - 11, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, - 11, 11, 11, 10, 9, 10, 10, 9, 10, 9, 9, 10, 9, 11, 10, - 10, 11, 11, 11, 11, 9, 10, 9, 9, 9, 9, 10, 10, 10, 10, - 11, 11, 11, 11, 11, 11, 10, 10, 10, 9, 9, 10, 9, 10, 9, - 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 9, 9, 9, 9, - 9, 10, 10, 10, + 2, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, + 8, 8, 10, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 8, 9, + 9, 9, 9, 9, 10, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, + 9, 9, 9, 9, 9, 9, 10, 7, 7, 7, 7, 8, 8, 8, 8, + 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 7, 7, 8, 8, + 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 8, 8, + 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, + 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, + 10, 10, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, + 9, 10, 10, 10, 11, 11, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 11, 10, 11, 11, 11, 9, 9, 9, 9, 9, 9, 10, + 10, 9, 9, 10, 9, 11, 10, 11, 11, 11, 9, 9, 9, 9, 9, + 9, 9, 9, 10, 10, 10, 9, 11, 11, 11, 11, 11, 9, 9, 9, + 9, 10, 10, 9, 9, 9, 9, 10, 9, 11, 11, 11, 11, 11, 11, + 11, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, + 11, 11, 11, 10, 9, 10, 10, 9, 10, 9, 9, 10, 9, 11, 10, + 10, 11, 11, 11, 11, 9, 10, 9, 9, 9, 9, 10, 10, 10, 10, + 11, 11, 11, 11, 11, 11, 10, 10, 10, 9, 9, 10, 9, 10, 9, + 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 9, 9, 9, 9, + 9, 10, 10, 10, }; static const struct { int dim; int len; int real_len; - const uint8_t * clens; + const uint8_t *clens; int lookup; float min; float delta; - const uint8_t * quant; + const uint8_t *quant; } cvectors[] = { { 2, 16, 16, codebook0, 0 }, { 2, 8, 8, codebook1, 0 }, @@ -493,7 +492,7 @@ static const struct { int dim; int subclass; int masterbook; - const int * nbooks; + const int *nbooks; } floor_classes[] = { { 3, 0, 0, (const int[]){ 4 } }, { 4, 1, 0, (const int[]){ 5, 6 } }, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vp3.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/vp3.c index d47bc1a411..c08de6ca2c 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vp3.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vp3.c @@ -19,7 +19,7 @@ */ /** - * @file libavcodec/vp3.c + * @file * On2 VP3 Video Decoder * * VP3 Video Decoder by Mike Melanson (mike at multimedia.cx) @@ -42,23 +42,12 @@ #define FRAGMENT_PIXELS 8 -typedef struct Coeff { - struct Coeff *next; - DCTELEM coeff; - uint8_t index; -} Coeff; +static av_cold int vp3_decode_end(AVCodecContext *avctx); //FIXME split things out into their own arrays typedef struct Vp3Fragment { - Coeff *next_coeff; - /* address of first pixel taking into account which plane the fragment - * lives on as well as the plane stride */ - int first_pixel; - /* this is the macroblock that the fragment belongs to */ - uint16_t macroblock; + int16_t dc; uint8_t coding_method; - int8_t motion_x; - int8_t motion_y; uint8_t qpi; } Vp3Fragment; @@ -66,6 +55,11 @@ typedef struct Vp3Fragment { #define SB_PARTIALLY_CODED 1 #define SB_FULLY_CODED 2 +// This is the maximum length of a single long bit run that can be encoded +// for superblock coding or block qps. Theora special-cases this to read a +// bit instead of flipping the current bit to allow for runs longer than 4129. +#define MAXIMUM_LONG_BIT_RUN 4129 + #define MODE_INTER_NO_MV 0 #define MODE_INTRA 1 #define MODE_INTER_PLUS_MV 2 @@ -120,6 +114,13 @@ static const int ModeAlphabet[6][CODING_MODE_COUNT] = }; +static const uint8_t hilbert_offset[16][2] = { + {0,0}, {1,0}, {1,1}, {0,1}, + {0,2}, {0,3}, {1,3}, {1,2}, + {2,2}, {2,3}, {3,3}, {3,2}, + {3,1}, {2,1}, {2,0}, {3,0} +}; + #define MIN_DEQUANT_VAL 2 typedef struct Vp3DecodeContext { @@ -127,12 +128,14 @@ typedef struct Vp3DecodeContext { int theora, theora_tables; int version; int width, height; + int chroma_x_shift, chroma_y_shift; AVFrame golden_frame; AVFrame last_frame; AVFrame current_frame; int keyframe; DSPContext dsp; int flipped_image; + int last_slice_end; int qps[3]; int nqps; @@ -141,8 +144,10 @@ typedef struct Vp3DecodeContext { int superblock_count; int y_superblock_width; int y_superblock_height; + int y_superblock_count; int c_superblock_width; int c_superblock_height; + int c_superblock_count; int u_superblock_start; int v_superblock_start; unsigned char *superblock_coding; @@ -152,14 +157,14 @@ typedef struct Vp3DecodeContext { int macroblock_height; int fragment_count; - int fragment_width; - int fragment_height; + int fragment_width[2]; + int fragment_height[2]; Vp3Fragment *all_fragments; - uint8_t *coeff_counts; - Coeff *coeffs; - Coeff *next_coeff; int fragment_start[3]; + int data_offset[3]; + + int8_t (*motion_val[2])[2]; ScanTable scantable; @@ -171,11 +176,38 @@ typedef struct Vp3DecodeContext { uint8_t qr_size [2][3][64]; uint16_t qr_base[2][3][64]; + /** + * This is a list of all tokens in bitstream order. Reordering takes place + * by pulling from each level during IDCT. As a consequence, IDCT must be + * in Hilbert order, making the minimum slice height 64 for 4:2:0 and 32 + * otherwise. The 32 different tokens with up to 12 bits of extradata are + * collapsed into 3 types, packed as follows: + * (from the low to high bits) + * + * 2 bits: type (0,1,2) + * 0: EOB run, 14 bits for run length (12 needed) + * 1: zero run, 7 bits for run length + * 7 bits for the next coefficient (3 needed) + * 2: coefficient, 14 bits (11 needed) + * + * Coefficients are signed, so are packed in the highest bits for automatic + * sign extension. + */ + int16_t *dct_tokens[3][64]; + int16_t *dct_tokens_base; +#define TOKEN_EOB(eob_run) ((eob_run) << 2) +#define TOKEN_ZERO_RUN(coeff, zero_run) (((coeff) << 9) + ((zero_run) << 2) + 1) +#define TOKEN_COEFF(coeff) (((coeff) << 2) + 2) + + /** + * number of blocks that contain DCT coefficients at the given level or higher + */ + int num_coded_frags[3][64]; + int total_num_coded_frags; + /* this is a list of indexes into the all_fragments array indicating * which of the fragments are coded */ - int *coded_fragment_list; - int coded_fragment_list_index; - int pixel_addresses_initialized; + int *coded_fragment_list[3]; VLC dc_vlc[16]; VLC ac_vlc_1[16]; @@ -190,7 +222,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]); //c_superblock_width : s->y_superblock_width; + int sb_height = plane ? s->c_superblock_height : s->y_superblock_height; + int frag_width = s->fragment_width[!!plane]; + int frag_height = s->fragment_height[!!plane]; - int current_macroblock; - int c_fragment; + for (sb_y = 0; sb_y < sb_height; sb_y++) + for (sb_x = 0; sb_x < sb_width; sb_x++) + for (i = 0; i < 16; i++) { + x = 4*sb_x + hilbert_offset[i][0]; + y = 4*sb_y + hilbert_offset[i][1]; - signed char travel_width[16] = { - 1, 1, 0, -1, - 0, 0, 1, 0, - 1, 0, 1, 0, - 0, -1, 0, 1 - }; - - signed char travel_height[16] = { - 0, 0, 1, 0, - 1, 1, 0, -1, - 0, 1, 0, -1, - -1, 0, -1, 0 - }; - - signed char travel_width_mb[4] = { - 1, 0, 1, 0 - }; - - signed char travel_height_mb[4] = { - 0, 1, 0, -1 - }; - - hilbert_walk_mb[0] = 1; - hilbert_walk_mb[1] = s->macroblock_width; - hilbert_walk_mb[2] = 1; - hilbert_walk_mb[3] = -s->macroblock_width; - - /* iterate through each superblock (all planes) and map the fragments */ - for (i = 0; i < s->superblock_count; i++) { - /* time to re-assign the limits? */ - if (i == 0) { - - /* start of Y superblocks */ - right_edge = s->fragment_width; - bottom_edge = s->fragment_height; - current_width = -1; - current_height = 0; - superblock_row_inc = 3 * s->fragment_width - - (s->y_superblock_width * 4 - s->fragment_width); - - /* the first operation for this variable is to advance by 1 */ - current_fragment = -1; - - } else if (i == s->u_superblock_start) { - - /* start of U superblocks */ - right_edge = s->fragment_width / 2; - bottom_edge = s->fragment_height / 2; - current_width = -1; - current_height = 0; - superblock_row_inc = 3 * (s->fragment_width / 2) - - (s->c_superblock_width * 4 - s->fragment_width / 2); - - /* the first operation for this variable is to advance by 1 */ - current_fragment = s->fragment_start[1] - 1; - - } else if (i == s->v_superblock_start) { - - /* start of V superblocks */ - right_edge = s->fragment_width / 2; - bottom_edge = s->fragment_height / 2; - current_width = -1; - current_height = 0; - superblock_row_inc = 3 * (s->fragment_width / 2) - - (s->c_superblock_width * 4 - s->fragment_width / 2); - - /* the first operation for this variable is to advance by 1 */ - current_fragment = s->fragment_start[2] - 1; - - } - - if (current_width >= right_edge - 1) { - /* reset width and move to next superblock row */ - current_width = -1; - current_height += 4; - - /* fragment is now at the start of a new superblock row */ - current_fragment += superblock_row_inc; - } - - /* iterate through all 16 fragments in a superblock */ - for (j = 0; j < 16; j++) { - current_fragment += travel_width[j] + right_edge * travel_height[j]; - current_width += travel_width[j]; - current_height += travel_height[j]; - - /* check if the fragment is in bounds */ - if ((current_width < right_edge) && - (current_height < bottom_edge)) { - s->superblock_fragments[mapping_index] = current_fragment; - } else { - s->superblock_fragments[mapping_index] = -1; - } - - mapping_index++; - } - } - - /* initialize the superblock <-> macroblock mapping; iterate through - * all of the Y plane superblocks to build this mapping */ - right_edge = s->macroblock_width; - bottom_edge = s->macroblock_height; - current_width = -1; - current_height = 0; - superblock_row_inc = s->macroblock_width - - (s->y_superblock_width * 2 - s->macroblock_width); - mapping_index = 0; - current_macroblock = -1; - for (i = 0; i < s->u_superblock_start; i++) { - - if (current_width >= right_edge - 1) { - /* reset width and move to next superblock row */ - current_width = -1; - current_height += 2; - - /* macroblock is now at the start of a new superblock row */ - current_macroblock += superblock_row_inc; - } - - /* iterate through each potential macroblock in the superblock */ - for (j = 0; j < 4; j++) { - current_macroblock += hilbert_walk_mb[j]; - current_width += travel_width_mb[j]; - current_height += travel_height_mb[j]; - - /* check if the macroblock is in bounds */ - if ((current_width < right_edge) && - (current_height < bottom_edge)) { - s->superblock_macroblocks[mapping_index] = current_macroblock; - } else { - s->superblock_macroblocks[mapping_index] = -1; - } - - mapping_index++; - } - } - - /* initialize the macroblock <-> fragment mapping */ - current_fragment = 0; - current_macroblock = 0; - mapping_index = 0; - for (i = 0; i < s->fragment_height; i += 2) { - - for (j = 0; j < s->fragment_width; j += 2) { - - s->all_fragments[current_fragment].macroblock = current_macroblock; - s->macroblock_fragments[mapping_index++] = current_fragment; - - if (j + 1 < s->fragment_width) { - s->all_fragments[current_fragment + 1].macroblock = current_macroblock; - s->macroblock_fragments[mapping_index++] = current_fragment + 1; - } else - s->macroblock_fragments[mapping_index++] = -1; - - if (i + 1 < s->fragment_height) { - s->all_fragments[current_fragment + s->fragment_width].macroblock = - current_macroblock; - s->macroblock_fragments[mapping_index++] = - current_fragment + s->fragment_width; - } else - s->macroblock_fragments[mapping_index++] = -1; - - if ((j + 1 < s->fragment_width) && (i + 1 < s->fragment_height)) { - s->all_fragments[current_fragment + s->fragment_width + 1].macroblock = - current_macroblock; - s->macroblock_fragments[mapping_index++] = - current_fragment + s->fragment_width + 1; - } else - s->macroblock_fragments[mapping_index++] = -1; - - /* C planes */ - c_fragment = s->fragment_start[1] + - (i * s->fragment_width / 4) + (j / 2); - s->all_fragments[c_fragment].macroblock = s->macroblock_count; - s->macroblock_fragments[mapping_index++] = c_fragment; - - c_fragment = s->fragment_start[2] + - (i * s->fragment_width / 4) + (j / 2); - s->all_fragments[c_fragment].macroblock = s->macroblock_count; - s->macroblock_fragments[mapping_index++] = c_fragment; - - if (j + 2 <= s->fragment_width) - current_fragment += 2; - else - current_fragment++; - current_macroblock++; - } - - current_fragment += s->fragment_width; + if (x < frag_width && y < frag_height) + s->superblock_fragments[j++] = s->fragment_start[plane] + y*frag_width + x; + else + s->superblock_fragments[j++] = -1; + } } return 0; /* successful path out */ } -/* - * This function wipes out all of the fragment data. - */ -static void init_frame(Vp3DecodeContext *s, GetBitContext *gb) -{ - int i; - - /* zero out all of the fragment information */ - s->coded_fragment_list_index = 0; - for (i = 0; i < s->fragment_count; i++) { - s->coeff_counts[i] = 0; - s->all_fragments[i].motion_x = 127; - s->all_fragments[i].motion_y = 127; - s->all_fragments[i].next_coeff= NULL; - s->all_fragments[i].qpi = 0; - s->coeffs[i].index= - s->coeffs[i].coeff=0; - s->coeffs[i].next= NULL; - } -} - /* * This function sets up the dequantization tables used for a particular * frame. @@ -549,15 +362,15 @@ static void init_loop_filter(Vp3DecodeContext *s) */ static int unpack_superblocks(Vp3DecodeContext *s, GetBitContext *gb) { + int superblock_starts[3] = { 0, s->u_superblock_start, s->v_superblock_start }; int bit = 0; int current_superblock = 0; int current_run = 0; - int decode_fully_flags = 0; - int decode_partial_blocks = 0; - int first_c_fragment_seen; + int num_partial_superblocks = 0; int i, j; int current_fragment; + int plane; if (s->keyframe) { memset(s->superblock_coding, SB_FULLY_CODED, s->superblock_count); @@ -566,62 +379,67 @@ static int unpack_superblocks(Vp3DecodeContext *s, GetBitContext *gb) /* unpack the list of partially-coded superblocks */ bit = get_bits1(gb); - /* toggle the bit because as soon as the first run length is - * fetched the bit will be toggled again */ - bit ^= 1; - while (current_superblock < s->superblock_count) { - if (current_run-- == 0) { - bit ^= 1; + while (current_superblock < s->superblock_count && get_bits_left(gb) > 0) { current_run = get_vlc2(gb, - s->superblock_run_length_vlc.table, 6, 2); - if (current_run == 33) + s->superblock_run_length_vlc.table, 6, 2) + 1; + if (current_run == 34) current_run += get_bits(gb, 12); - /* if any of the superblocks are not partially coded, flag - * a boolean to decode the list of fully-coded superblocks */ - if (bit == 0) { - decode_fully_flags = 1; - } else { - - /* make a note of the fact that there are partially coded - * superblocks */ - decode_partial_blocks = 1; - } + if (current_superblock + current_run > s->superblock_count) { + av_log(s->avctx, AV_LOG_ERROR, "Invalid partially coded superblock run length\n"); + return -1; } - s->superblock_coding[current_superblock++] = bit; + + memset(s->superblock_coding + current_superblock, bit, current_run); + + current_superblock += current_run; + if (bit) + num_partial_superblocks += current_run; + + if (s->theora && current_run == MAXIMUM_LONG_BIT_RUN) + bit = get_bits1(gb); + else + bit ^= 1; } /* unpack the list of fully coded superblocks if any of the blocks were * not marked as partially coded in the previous step */ - if (decode_fully_flags) { + if (num_partial_superblocks < s->superblock_count) { + int superblocks_decoded = 0; current_superblock = 0; - current_run = 0; bit = get_bits1(gb); - /* toggle the bit because as soon as the first run length is - * fetched the bit will be toggled again */ - bit ^= 1; - while (current_superblock < s->superblock_count) { + while (superblocks_decoded < s->superblock_count - num_partial_superblocks + && get_bits_left(gb) > 0) { + current_run = get_vlc2(gb, + s->superblock_run_length_vlc.table, 6, 2) + 1; + if (current_run == 34) + current_run += get_bits(gb, 12); + + for (j = 0; j < current_run; current_superblock++) { + if (current_superblock >= s->superblock_count) { + av_log(s->avctx, AV_LOG_ERROR, "Invalid fully coded superblock run length\n"); + return -1; + } /* skip any superblocks already marked as partially coded */ if (s->superblock_coding[current_superblock] == SB_NOT_CODED) { - - if (current_run-- == 0) { - bit ^= 1; - current_run = get_vlc2(gb, - s->superblock_run_length_vlc.table, 6, 2); - if (current_run == 33) - current_run += get_bits(gb, 12); - } s->superblock_coding[current_superblock] = 2*bit; + j++; } - current_superblock++; + } + superblocks_decoded += current_run; + + if (s->theora && current_run == MAXIMUM_LONG_BIT_RUN) + bit = get_bits1(gb); + else + bit ^= 1; } } /* if there were partial blocks, initialize bitstream for * unpacking fragment codings */ - if (decode_partial_blocks) { + if (num_partial_superblocks) { current_run = 0; bit = get_bits1(gb); @@ -633,32 +451,25 @@ static int unpack_superblocks(Vp3DecodeContext *s, GetBitContext *gb) /* figure out which fragments are coded; iterate through each * superblock (all planes) */ - s->coded_fragment_list_index = 0; - s->next_coeff= s->coeffs + s->fragment_count; - s->first_coded_y_fragment = s->first_coded_c_fragment = 0; - s->last_coded_y_fragment = s->last_coded_c_fragment = -1; - first_c_fragment_seen = 0; + s->total_num_coded_frags = 0; memset(s->macroblock_coding, MODE_COPY, s->macroblock_count); - for (i = 0; i < s->superblock_count; i++) { + + for (plane = 0; plane < 3; plane++) { + int sb_start = superblock_starts[plane]; + int sb_end = sb_start + (plane ? s->c_superblock_count : s->y_superblock_count); + int num_coded_frags = 0; + + for (i = sb_start; i < sb_end && get_bits_left(gb) > 0; i++) { /* iterate through all 16 fragments in a superblock */ for (j = 0; j < 16; j++) { /* if the fragment is in bounds, check its coding status */ current_fragment = s->superblock_fragments[i * 16 + j]; - if (current_fragment >= s->fragment_count) { - av_log(s->avctx, AV_LOG_ERROR, " vp3:unpack_superblocks(): bad fragment number (%d >= %d)\n", - current_fragment, s->fragment_count); - return 1; - } if (current_fragment != -1) { - if (s->superblock_coding[i] == SB_NOT_CODED) { + int coded = s->superblock_coding[i]; - /* copy all the fragments from the prior frame */ - s->all_fragments[current_fragment].coding_method = - MODE_COPY; - - } else if (s->superblock_coding[i] == SB_PARTIALLY_CODED) { + if (s->superblock_coding[i] == SB_PARTIALLY_CODED) { /* fragment may or may not be coded; this is the case * that cares about the fragment coding runs */ @@ -667,60 +478,30 @@ static int unpack_superblocks(Vp3DecodeContext *s, GetBitContext *gb) current_run = get_vlc2(gb, s->fragment_run_length_vlc.table, 5, 2); } + coded = bit; + } - if (bit) { + if (coded) { /* default mode; actual mode will be decoded in * the next phase */ s->all_fragments[current_fragment].coding_method = MODE_INTER_NO_MV; - s->all_fragments[current_fragment].next_coeff= s->coeffs + current_fragment; - s->coded_fragment_list[s->coded_fragment_list_index] = + s->coded_fragment_list[plane][num_coded_frags++] = current_fragment; - if ((current_fragment >= s->fragment_start[1]) && - (s->last_coded_y_fragment == -1) && - (!first_c_fragment_seen)) { - s->first_coded_c_fragment = s->coded_fragment_list_index; - s->last_coded_y_fragment = s->first_coded_c_fragment - 1; - first_c_fragment_seen = 1; - } - s->coded_fragment_list_index++; - s->macroblock_coding[s->all_fragments[current_fragment].macroblock] = MODE_INTER_NO_MV; } else { /* not coded; copy this fragment from the prior frame */ s->all_fragments[current_fragment].coding_method = MODE_COPY; } - - } else { - - /* fragments are fully coded in this superblock; actual - * coding will be determined in next step */ - s->all_fragments[current_fragment].coding_method = - MODE_INTER_NO_MV; - s->all_fragments[current_fragment].next_coeff= s->coeffs + current_fragment; - s->coded_fragment_list[s->coded_fragment_list_index] = - current_fragment; - if ((current_fragment >= s->fragment_start[1]) && - (s->last_coded_y_fragment == -1) && - (!first_c_fragment_seen)) { - s->first_coded_c_fragment = s->coded_fragment_list_index; - s->last_coded_y_fragment = s->first_coded_c_fragment - 1; - first_c_fragment_seen = 1; - } - s->coded_fragment_list_index++; - s->macroblock_coding[s->all_fragments[current_fragment].macroblock] = MODE_INTER_NO_MV; - } } } } - - if (!first_c_fragment_seen) - /* only Y fragments coded in this frame */ - s->last_coded_y_fragment = s->coded_fragment_list_index - 1; - else - /* end the list of coded C fragments */ - s->last_coded_c_fragment = s->coded_fragment_list_index - 1; - + s->total_num_coded_frags += num_coded_frags; + for (i = 0; i < 64; i++) + s->num_coded_frags[plane][i] = num_coded_frags; + if (plane < 2) + s->coded_fragment_list[plane+1] = s->coded_fragment_list[plane] + num_coded_frags; + } return 0; } @@ -730,12 +511,14 @@ static int unpack_superblocks(Vp3DecodeContext *s, GetBitContext *gb) */ static int unpack_modes(Vp3DecodeContext *s, GetBitContext *gb) { - int i, j, k; + int i, j, k, sb_x, sb_y; int scheme; int current_macroblock; int current_fragment; int coding_mode; int custom_mode_alphabet[CODING_MODE_COUNT]; + const int *alphabet; + Vp3Fragment *frag; if (s->keyframe) { for (i = 0; i < s->fragment_count; i++) @@ -752,49 +535,75 @@ static int unpack_modes(Vp3DecodeContext *s, GetBitContext *gb) custom_mode_alphabet[i] = MODE_INTER_NO_MV; for (i = 0; i < 8; i++) custom_mode_alphabet[get_bits(gb, 3)] = i; - } + alphabet = custom_mode_alphabet; + } else + alphabet = ModeAlphabet[scheme-1]; /* iterate through all of the macroblocks that contain 1 or more * coded fragments */ - for (i = 0; i < s->u_superblock_start; i++) { + for (sb_y = 0; sb_y < s->y_superblock_height; sb_y++) { + for (sb_x = 0; sb_x < s->y_superblock_width; sb_x++) { + if (get_bits_left(gb) <= 0) + return -1; for (j = 0; j < 4; j++) { - current_macroblock = s->superblock_macroblocks[i * 4 + j]; - if ((current_macroblock == -1) || - (s->macroblock_coding[current_macroblock] == MODE_COPY)) + int mb_x = 2*sb_x + (j>>1); + int mb_y = 2*sb_y + (((j>>1)+j)&1); + current_macroblock = mb_y * s->macroblock_width + mb_x; + + if (mb_x >= s->macroblock_width || mb_y >= s->macroblock_height) + continue; + +#define BLOCK_X (2*mb_x + (k&1)) +#define BLOCK_Y (2*mb_y + (k>>1)) + /* coding modes are only stored if the macroblock has at least one + * luma block coded, otherwise it must be INTER_NO_MV */ + for (k = 0; k < 4; k++) { + current_fragment = BLOCK_Y*s->fragment_width[0] + BLOCK_X; + if (s->all_fragments[current_fragment].coding_method != MODE_COPY) + break; + } + if (k == 4) { + s->macroblock_coding[current_macroblock] = MODE_INTER_NO_MV; continue; - if (current_macroblock >= s->macroblock_count) { - av_log(s->avctx, AV_LOG_ERROR, " vp3:unpack_modes(): bad macroblock number (%d >= %d)\n", - current_macroblock, s->macroblock_count); - return 1; } /* mode 7 means get 3 bits for each coding mode */ if (scheme == 7) coding_mode = get_bits(gb, 3); - else if(scheme == 0) - coding_mode = custom_mode_alphabet - [get_vlc2(gb, s->mode_code_vlc.table, 3, 3)]; else - coding_mode = ModeAlphabet[scheme-1] + coding_mode = alphabet [get_vlc2(gb, s->mode_code_vlc.table, 3, 3)]; s->macroblock_coding[current_macroblock] = coding_mode; - for (k = 0; k < 6; k++) { - current_fragment = - s->macroblock_fragments[current_macroblock * 6 + k]; - if (current_fragment == -1) - continue; - if (current_fragment >= s->fragment_count) { - av_log(s->avctx, AV_LOG_ERROR, " vp3:unpack_modes(): bad fragment number (%d >= %d)\n", - current_fragment, s->fragment_count); - return 1; - } - if (s->all_fragments[current_fragment].coding_method != - MODE_COPY) - s->all_fragments[current_fragment].coding_method = - coding_mode; + for (k = 0; k < 4; k++) { + frag = s->all_fragments + BLOCK_Y*s->fragment_width[0] + BLOCK_X; + if (frag->coding_method != MODE_COPY) + frag->coding_method = coding_mode; } + +#define SET_CHROMA_MODES \ + if (frag[s->fragment_start[1]].coding_method != MODE_COPY) \ + frag[s->fragment_start[1]].coding_method = coding_mode;\ + if (frag[s->fragment_start[2]].coding_method != MODE_COPY) \ + frag[s->fragment_start[2]].coding_method = coding_mode; + + if (s->chroma_y_shift) { + frag = s->all_fragments + mb_y*s->fragment_width[1] + mb_x; + SET_CHROMA_MODES + } else if (s->chroma_x_shift) { + frag = s->all_fragments + 2*mb_y*s->fragment_width[1] + mb_x; + for (k = 0; k < 2; k++) { + SET_CHROMA_MODES + frag += s->fragment_width[1]; + } + } else { + for (k = 0; k < 4; k++) { + frag = s->all_fragments + BLOCK_Y*s->fragment_width[1] + BLOCK_X; + SET_CHROMA_MODES + } + } + } } } } @@ -808,47 +617,40 @@ static int unpack_modes(Vp3DecodeContext *s, GetBitContext *gb) */ static int unpack_vectors(Vp3DecodeContext *s, GetBitContext *gb) { - int i, j, k, l; + int j, k, sb_x, sb_y; int coding_mode; - int motion_x[6]; - int motion_y[6]; + int motion_x[4]; + int motion_y[4]; int last_motion_x = 0; int last_motion_y = 0; int prior_last_motion_x = 0; int prior_last_motion_y = 0; int current_macroblock; int current_fragment; + int frag; if (s->keyframe) return 0; - memset(motion_x, 0, 6 * sizeof(int)); - memset(motion_y, 0, 6 * sizeof(int)); - /* coding mode 0 is the VLC scheme; 1 is the fixed code scheme */ coding_mode = get_bits1(gb); /* iterate through all of the macroblocks that contain 1 or more * coded fragments */ - for (i = 0; i < s->u_superblock_start; i++) { + for (sb_y = 0; sb_y < s->y_superblock_height; sb_y++) { + for (sb_x = 0; sb_x < s->y_superblock_width; sb_x++) { + if (get_bits_left(gb) <= 0) + return -1; for (j = 0; j < 4; j++) { - current_macroblock = s->superblock_macroblocks[i * 4 + j]; - if ((current_macroblock == -1) || + int mb_x = 2*sb_x + (j>>1); + int mb_y = 2*sb_y + (((j>>1)+j)&1); + current_macroblock = mb_y * s->macroblock_width + mb_x; + + if (mb_x >= s->macroblock_width || mb_y >= s->macroblock_height || (s->macroblock_coding[current_macroblock] == MODE_COPY)) continue; - if (current_macroblock >= s->macroblock_count) { - av_log(s->avctx, AV_LOG_ERROR, " vp3:unpack_vectors(): bad macroblock number (%d >= %d)\n", - current_macroblock, s->macroblock_count); - return 1; - } - current_fragment = s->macroblock_fragments[current_macroblock * 6]; - if (current_fragment >= s->fragment_count) { - av_log(s->avctx, AV_LOG_ERROR, " vp3:unpack_vectors(): bad fragment number (%d >= %d\n", - current_fragment, s->fragment_count); - return 1; - } switch (s->macroblock_coding[current_macroblock]) { case MODE_INTER_PLUS_MV: @@ -862,11 +664,6 @@ static int unpack_vectors(Vp3DecodeContext *s, GetBitContext *gb) motion_y[0] = fixed_motion_vector_table[get_bits(gb, 6)]; } - for (k = 1; k < 6; k++) { - motion_x[k] = motion_x[0]; - motion_y[k] = motion_y[0]; - } - /* vector maintenance, only on MODE_INTER_PLUS_MV */ if (s->macroblock_coding[current_macroblock] == MODE_INTER_PLUS_MV) { @@ -884,12 +681,9 @@ static int unpack_vectors(Vp3DecodeContext *s, GetBitContext *gb) /* fetch 4 vectors from the bitstream, one for each * Y fragment, then average for the C fragment vectors */ - motion_x[4] = motion_y[4] = 0; for (k = 0; k < 4; k++) { - for (l = 0; l < s->coded_fragment_list_index; l++) - if (s->coded_fragment_list[l] == s->macroblock_fragments[6*current_macroblock + k]) - break; - if (l < s->coded_fragment_list_index) { + current_fragment = BLOCK_Y*s->fragment_width[0] + BLOCK_X; + if (s->all_fragments[current_fragment].coding_method != MODE_COPY) { if (coding_mode == 0) { motion_x[k] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)]; motion_y[k] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)]; @@ -903,24 +697,13 @@ static int unpack_vectors(Vp3DecodeContext *s, GetBitContext *gb) motion_x[k] = 0; motion_y[k] = 0; } - motion_x[4] += motion_x[k]; - motion_y[4] += motion_y[k]; } - - motion_x[5]= - motion_x[4]= RSHIFT(motion_x[4], 2); - motion_y[5]= - motion_y[4]= RSHIFT(motion_y[4], 2); break; case MODE_INTER_LAST_MV: /* all 6 fragments use the last motion vector */ motion_x[0] = last_motion_x; motion_y[0] = last_motion_y; - for (k = 1; k < 6; k++) { - motion_x[k] = motion_x[0]; - motion_y[k] = motion_y[0]; - } /* no vector maintenance (last vector remains the * last vector) */ @@ -931,10 +714,6 @@ static int unpack_vectors(Vp3DecodeContext *s, GetBitContext *gb) * last motion vector */ motion_x[0] = prior_last_motion_x; motion_y[0] = prior_last_motion_y; - for (k = 1; k < 6; k++) { - motion_x[k] = motion_x[0]; - motion_y[k] = motion_y[0]; - } /* vector maintenance */ prior_last_motion_x = last_motion_x; @@ -945,27 +724,68 @@ static int unpack_vectors(Vp3DecodeContext *s, GetBitContext *gb) default: /* covers intra, inter without MV, golden without MV */ - memset(motion_x, 0, 6 * sizeof(int)); - memset(motion_y, 0, 6 * sizeof(int)); + motion_x[0] = 0; + motion_y[0] = 0; /* no vector maintenance */ break; } /* assign the motion vectors to the correct fragments */ - for (k = 0; k < 6; k++) { + for (k = 0; k < 4; k++) { current_fragment = - s->macroblock_fragments[current_macroblock * 6 + k]; - if (current_fragment == -1) - continue; - if (current_fragment >= s->fragment_count) { - av_log(s->avctx, AV_LOG_ERROR, " vp3:unpack_vectors(): bad fragment number (%d >= %d)\n", - current_fragment, s->fragment_count); - return 1; + BLOCK_Y*s->fragment_width[0] + BLOCK_X; + if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) { + s->motion_val[0][current_fragment][0] = motion_x[k]; + s->motion_val[0][current_fragment][1] = motion_y[k]; + } else { + s->motion_val[0][current_fragment][0] = motion_x[0]; + s->motion_val[0][current_fragment][1] = motion_y[0]; } - s->all_fragments[current_fragment].motion_x = motion_x[k]; - s->all_fragments[current_fragment].motion_y = motion_y[k]; } + + if (s->chroma_y_shift) { + if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) { + motion_x[0] = RSHIFT(motion_x[0] + motion_x[1] + motion_x[2] + motion_x[3], 2); + motion_y[0] = RSHIFT(motion_y[0] + motion_y[1] + motion_y[2] + motion_y[3], 2); + } + motion_x[0] = (motion_x[0]>>1) | (motion_x[0]&1); + motion_y[0] = (motion_y[0]>>1) | (motion_y[0]&1); + frag = mb_y*s->fragment_width[1] + mb_x; + s->motion_val[1][frag][0] = motion_x[0]; + s->motion_val[1][frag][1] = motion_y[0]; + } else if (s->chroma_x_shift) { + if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) { + motion_x[0] = RSHIFT(motion_x[0] + motion_x[1], 1); + motion_y[0] = RSHIFT(motion_y[0] + motion_y[1], 1); + motion_x[1] = RSHIFT(motion_x[2] + motion_x[3], 1); + motion_y[1] = RSHIFT(motion_y[2] + motion_y[3], 1); + } else { + motion_x[1] = motion_x[0]; + motion_y[1] = motion_y[0]; + } + motion_x[0] = (motion_x[0]>>1) | (motion_x[0]&1); + motion_x[1] = (motion_x[1]>>1) | (motion_x[1]&1); + + frag = 2*mb_y*s->fragment_width[1] + mb_x; + for (k = 0; k < 2; k++) { + s->motion_val[1][frag][0] = motion_x[k]; + s->motion_val[1][frag][1] = motion_y[k]; + frag += s->fragment_width[1]; + } + } else { + for (k = 0; k < 4; k++) { + frag = BLOCK_Y*s->fragment_width[1] + BLOCK_X; + if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) { + s->motion_val[1][frag][0] = motion_x[k]; + s->motion_val[1][frag][1] = motion_y[k]; + } else { + s->motion_val[1][frag][0] = motion_x[0]; + s->motion_val[1][frag][1] = motion_y[0]; + } + } + } + } } } @@ -975,7 +795,7 @@ static int unpack_vectors(Vp3DecodeContext *s, GetBitContext *gb) static int unpack_block_qpis(Vp3DecodeContext *s, GetBitContext *gb) { int qpi, i, j, bit, run_length, blocks_decoded, num_blocks_at_qpi; - int num_blocks = s->coded_fragment_list_index; + int num_blocks = s->total_num_coded_frags; for (qpi = 0; qpi < s->nqps-1 && num_blocks > 0; qpi++) { i = blocks_decoded = num_blocks_at_qpi = 0; @@ -992,20 +812,20 @@ static int unpack_block_qpis(Vp3DecodeContext *s, GetBitContext *gb) num_blocks_at_qpi += run_length; for (j = 0; j < run_length; i++) { - if (i > s->coded_fragment_list_index) + if (i >= s->total_num_coded_frags) return -1; - if (s->all_fragments[s->coded_fragment_list[i]].qpi == qpi) { - s->all_fragments[s->coded_fragment_list[i]].qpi += bit; + if (s->all_fragments[s->coded_fragment_list[0][i]].qpi == qpi) { + s->all_fragments[s->coded_fragment_list[0][i]].qpi += bit; j++; } } - if (run_length == 4129) + if (run_length == MAXIMUM_LONG_BIT_RUN) bit = get_bits1(gb); else bit ^= 1; - } while (blocks_decoded < num_blocks); + } while (blocks_decoded < num_blocks && get_bits_left(gb) > 0); num_blocks -= num_blocks_at_qpi; } @@ -1027,72 +847,120 @@ static int unpack_block_qpis(Vp3DecodeContext *s, GetBitContext *gb) */ static int unpack_vlcs(Vp3DecodeContext *s, GetBitContext *gb, VLC *table, int coeff_index, - int first_fragment, int last_fragment, + int plane, int eob_run) { - int i; + int i, j = 0; int token; int zero_run = 0; DCTELEM coeff = 0; - Vp3Fragment *fragment; - uint8_t *perm= s->scantable.permutated; int bits_to_get; + int blocks_ended; + int coeff_i = 0; + int num_coeffs = s->num_coded_frags[plane][coeff_index]; + int16_t *dct_tokens = s->dct_tokens[plane][coeff_index]; - if ((first_fragment >= s->fragment_count) || - (last_fragment >= s->fragment_count)) { + /* local references to structure members to avoid repeated deferences */ + int *coded_fragment_list = s->coded_fragment_list[plane]; + Vp3Fragment *all_fragments = s->all_fragments; + VLC_TYPE (*vlc_table)[2] = table->table; - av_log(s->avctx, AV_LOG_ERROR, " vp3:unpack_vlcs(): bad fragment number (%d -> %d ?)\n", - first_fragment, last_fragment); - return 0; + if (num_coeffs < 0) + av_log(s->avctx, AV_LOG_ERROR, "Invalid number of coefficents at level %d\n", coeff_index); + + if (eob_run > num_coeffs) { + coeff_i = blocks_ended = num_coeffs; + eob_run -= num_coeffs; + } else { + coeff_i = blocks_ended = eob_run; + eob_run = 0; } - for (i = first_fragment; i <= last_fragment; i++) { - int fragment_num = s->coded_fragment_list[i]; + // insert fake EOB token to cover the split between planes or zzi + if (blocks_ended) + dct_tokens[j++] = blocks_ended << 2; - if (s->coeff_counts[fragment_num] > coeff_index) - continue; - fragment = &s->all_fragments[fragment_num]; - - if (!eob_run) { + while (coeff_i < num_coeffs && get_bits_left(gb) > 0) { /* decode a VLC into a token */ - token = get_vlc2(gb, table->table, 5, 3); + token = get_vlc2(gb, vlc_table, 11, 3); /* use the token to get a zero run, a coefficient, and an eob run */ if (token <= 6) { eob_run = eob_run_base[token]; if (eob_run_get_bits[token]) eob_run += get_bits(gb, eob_run_get_bits[token]); - coeff = zero_run = 0; + + // record only the number of blocks ended in this plane, + // any spill will be recorded in the next plane. + if (eob_run > num_coeffs - coeff_i) { + dct_tokens[j++] = TOKEN_EOB(num_coeffs - coeff_i); + blocks_ended += num_coeffs - coeff_i; + eob_run -= num_coeffs - coeff_i; + coeff_i = num_coeffs; + } else { + dct_tokens[j++] = TOKEN_EOB(eob_run); + blocks_ended += eob_run; + coeff_i += eob_run; + eob_run = 0; + } } else { bits_to_get = coeff_get_bits[token]; - if (!bits_to_get) - coeff = coeff_tables[token][0]; - else - coeff = coeff_tables[token][get_bits(gb, bits_to_get)]; + if (bits_to_get) + bits_to_get = get_bits(gb, bits_to_get); + coeff = coeff_tables[token][bits_to_get]; zero_run = zero_run_base[token]; if (zero_run_get_bits[token]) zero_run += get_bits(gb, zero_run_get_bits[token]); - } - } - if (!eob_run) { - s->coeff_counts[fragment_num] += zero_run; - if (s->coeff_counts[fragment_num] < 64){ - fragment->next_coeff->coeff= coeff; - fragment->next_coeff->index= perm[s->coeff_counts[fragment_num]++]; //FIXME perm here already? - fragment->next_coeff->next= s->next_coeff; - s->next_coeff->next=NULL; - fragment->next_coeff= s->next_coeff++; + if (zero_run) { + dct_tokens[j++] = TOKEN_ZERO_RUN(coeff, zero_run); + } else { + // Save DC into the fragment structure. DC prediction is + // done in raster order, so the actual DC can't be in with + // other tokens. We still need the token in dct_tokens[] + // however, or else the structure collapses on itself. + if (!coeff_index) + all_fragments[coded_fragment_list[coeff_i]].dc = coeff; + + dct_tokens[j++] = TOKEN_COEFF(coeff); + } + + if (coeff_index + zero_run > 64) { + av_log(s->avctx, AV_LOG_DEBUG, "Invalid zero run of %d with" + " %d coeffs left\n", zero_run, 64-coeff_index); + zero_run = 64 - coeff_index; + } + + // zero runs code multiple coefficients, + // so don't try to decode coeffs for those higher levels + for (i = coeff_index+1; i <= coeff_index+zero_run; i++) + s->num_coded_frags[plane][i]--; + coeff_i++; } - } else { - s->coeff_counts[fragment_num] |= 128; - eob_run--; - } } + if (blocks_ended > s->num_coded_frags[plane][coeff_index]) + av_log(s->avctx, AV_LOG_ERROR, "More blocks ended than coded!\n"); + + // decrement the number of blocks that have higher coeffecients for each + // EOB run at this level + if (blocks_ended) + for (i = coeff_index+1; i < 64; i++) + s->num_coded_frags[plane][i] -= blocks_ended; + + // setup the next buffer + if (plane < 2) + s->dct_tokens[plane+1][coeff_index] = dct_tokens + j; + else if (coeff_index < 63) + s->dct_tokens[0][coeff_index+1] = dct_tokens + j; + return eob_run; } +static void reverse_dc_prediction(Vp3DecodeContext *s, + int first_fragment, + int fragment_width, + int fragment_height); /* * This function unpacks all of the DCT coefficient data from the * bitstream. @@ -1105,6 +973,10 @@ static int unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb) int ac_y_table; int ac_c_table; int residual_eob_run = 0; + VLC *y_tables[64]; + VLC *c_tables[64]; + + s->dct_tokens[0][0] = s->dct_tokens_base; /* fetch the DC table indexes */ dc_y_table = get_bits(gb, 4); @@ -1112,50 +984,57 @@ static int unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb) /* unpack the Y plane DC coefficients */ residual_eob_run = unpack_vlcs(s, gb, &s->dc_vlc[dc_y_table], 0, - s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run); + 0, residual_eob_run); + + /* reverse prediction of the Y-plane DC coefficients */ + reverse_dc_prediction(s, 0, s->fragment_width[0], s->fragment_height[0]); /* unpack the C plane DC coefficients */ residual_eob_run = unpack_vlcs(s, gb, &s->dc_vlc[dc_c_table], 0, - s->first_coded_c_fragment, s->last_coded_c_fragment, residual_eob_run); + 1, residual_eob_run); + residual_eob_run = unpack_vlcs(s, gb, &s->dc_vlc[dc_c_table], 0, + 2, residual_eob_run); + + /* reverse prediction of the C-plane DC coefficients */ + if (!(s->avctx->flags & CODEC_FLAG_GRAY)) + { + reverse_dc_prediction(s, s->fragment_start[1], + s->fragment_width[1], s->fragment_height[1]); + reverse_dc_prediction(s, s->fragment_start[2], + s->fragment_width[1], s->fragment_height[1]); + } /* fetch the AC table indexes */ ac_y_table = get_bits(gb, 4); ac_c_table = get_bits(gb, 4); - /* unpack the group 1 AC coefficients (coeffs 1-5) */ + /* build tables of AC VLC tables */ for (i = 1; i <= 5; i++) { - residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_1[ac_y_table], i, - s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run); - - residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_1[ac_c_table], i, - s->first_coded_c_fragment, s->last_coded_c_fragment, residual_eob_run); + y_tables[i] = &s->ac_vlc_1[ac_y_table]; + c_tables[i] = &s->ac_vlc_1[ac_c_table]; } - - /* unpack the group 2 AC coefficients (coeffs 6-14) */ for (i = 6; i <= 14; i++) { - residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_2[ac_y_table], i, - s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run); - - residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_2[ac_c_table], i, - s->first_coded_c_fragment, s->last_coded_c_fragment, residual_eob_run); + y_tables[i] = &s->ac_vlc_2[ac_y_table]; + c_tables[i] = &s->ac_vlc_2[ac_c_table]; } - - /* unpack the group 3 AC coefficients (coeffs 15-27) */ for (i = 15; i <= 27; i++) { - residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_3[ac_y_table], i, - s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run); - - residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_3[ac_c_table], i, - s->first_coded_c_fragment, s->last_coded_c_fragment, residual_eob_run); + y_tables[i] = &s->ac_vlc_3[ac_y_table]; + c_tables[i] = &s->ac_vlc_3[ac_c_table]; + } + for (i = 28; i <= 63; i++) { + y_tables[i] = &s->ac_vlc_4[ac_y_table]; + c_tables[i] = &s->ac_vlc_4[ac_c_table]; } - /* unpack the group 4 AC coefficients (coeffs 28-63) */ - for (i = 28; i <= 63; i++) { - residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_4[ac_y_table], i, - s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run); + /* decode all AC coefficents */ + for (i = 1; i <= 63; i++) { + residual_eob_run = unpack_vlcs(s, gb, y_tables[i], i, + 0, residual_eob_run); - residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_4[ac_c_table], i, - s->first_coded_c_fragment, s->last_coded_c_fragment, residual_eob_run); + residual_eob_run = unpack_vlcs(s, gb, c_tables[i], i, + 1, residual_eob_run); + residual_eob_run = unpack_vlcs(s, gb, c_tables[i], i, + 2, residual_eob_run); } return 0; @@ -1168,8 +1047,7 @@ static int unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb) */ #define COMPATIBLE_FRAME(x) \ (compatible_frame[s->all_fragments[x].coding_method] == current_frame_type) -#define FRAME_CODED(x) (s->all_fragments[x].coding_method != MODE_COPY) -#define DC_COEFF(u) (s->coeffs[u].index ? 0 : s->coeffs[u].coeff) //FIXME do somethin to simplify this +#define DC_COEFF(u) s->all_fragments[u].dc static void reverse_dc_prediction(Vp3DecodeContext *s, int first_fragment, @@ -1200,7 +1078,7 @@ static void reverse_dc_prediction(Vp3DecodeContext *s, * 2: up-right multiplier * 3: left multiplier */ - int predictor_transform[16][4] = { + static const int predictor_transform[16][4] = { { 0, 0, 0, 0}, { 0, 0, 0,128}, // PL { 0, 0,128, 0}, // PUR @@ -1225,7 +1103,7 @@ static void reverse_dc_prediction(Vp3DecodeContext *s, * from other INTRA blocks. There are 2 golden frame coding types; * blocks encoding in these modes can only predict from other blocks * that were encoded with these 1 of these 2 modes. */ - unsigned char compatible_frame[8] = { + static const unsigned char compatible_frame[9] = { 1, /* MODE_INTER_NO_MV */ 0, /* MODE_INTRA */ 1, /* MODE_INTER_PLUS_MV */ @@ -1233,7 +1111,8 @@ static void reverse_dc_prediction(Vp3DecodeContext *s, 1, /* MODE_INTER_PRIOR_MV */ 2, /* MODE_USING_GOLDEN */ 2, /* MODE_GOLDEN_MV */ - 1 /* MODE_INTER_FOUR_MV */ + 1, /* MODE_INTER_FOUR_MV */ + 3 /* MODE_COPY */ }; int current_frame_type; @@ -1261,24 +1140,24 @@ static void reverse_dc_prediction(Vp3DecodeContext *s, if(x){ l= i-1; vl = DC_COEFF(l); - if(FRAME_CODED(l) && COMPATIBLE_FRAME(l)) + if(COMPATIBLE_FRAME(l)) transform |= PL; } if(y){ u= i-fragment_width; vu = DC_COEFF(u); - if(FRAME_CODED(u) && COMPATIBLE_FRAME(u)) + if(COMPATIBLE_FRAME(u)) transform |= PU; if(x){ ul= i-fragment_width-1; vul = DC_COEFF(ul); - if(FRAME_CODED(ul) && COMPATIBLE_FRAME(ul)) + if(COMPATIBLE_FRAME(ul)) transform |= PUL; } if(x + 1 < fragment_width){ ur= i-fragment_width+1; vur = DC_COEFF(ur); - if(FRAME_CODED(ur) && COMPATIBLE_FRAME(ur)) + if(COMPATIBLE_FRAME(ur)) transform |= PUR; } } @@ -1301,7 +1180,7 @@ static void reverse_dc_prediction(Vp3DecodeContext *s, /* check for outranging on the [ul u l] and * [ul u ur l] predictors */ - if ((transform == 13) || (transform == 15)) { + if ((transform == 15) || (transform == 13)) { if (FFABS(predicted_dc - vu) > 128) predicted_dc = vu; else if (FFABS(predicted_dc - vl) > 128) @@ -1312,83 +1191,217 @@ static void reverse_dc_prediction(Vp3DecodeContext *s, } /* at long last, apply the predictor */ - if(s->coeffs[i].index){ - *s->next_coeff= s->coeffs[i]; - s->coeffs[i].index=0; - s->coeffs[i].coeff=0; - s->coeffs[i].next= s->next_coeff++; - } - s->coeffs[i].coeff += predicted_dc; + DC_COEFF(i) += predicted_dc; /* save the DC */ last_dc[current_frame_type] = DC_COEFF(i); - if(DC_COEFF(i) && !(s->coeff_counts[i]&127)){ - s->coeff_counts[i]= 129; -// s->all_fragments[i].next_coeff= s->next_coeff; - s->coeffs[i].next= s->next_coeff; - (s->next_coeff++)->next=NULL; - } } } } } +static void apply_loop_filter(Vp3DecodeContext *s, int plane, int ystart, int yend) +{ + int x, y; + int *bounding_values= s->bounding_values_array+127; + + int width = s->fragment_width[!!plane]; + int height = s->fragment_height[!!plane]; + int fragment = s->fragment_start [plane] + ystart * width; + int stride = s->current_frame.linesize[plane]; + uint8_t *plane_data = s->current_frame.data [plane]; + if (!s->flipped_image) stride = -stride; + plane_data += s->data_offset[plane] + 8*ystart*stride; + + for (y = ystart; y < yend; y++) { + + for (x = 0; x < width; x++) { + /* This code basically just deblocks on the edges of coded blocks. + * However, it has to be much more complicated because of the + * braindamaged deblock ordering used in VP3/Theora. Order matters + * because some pixels get filtered twice. */ + if( s->all_fragments[fragment].coding_method != MODE_COPY ) + { + /* do not perform left edge filter for left columns frags */ + if (x > 0) { + s->dsp.vp3_h_loop_filter( + plane_data + 8*x, + stride, bounding_values); + } + + /* do not perform top edge filter for top row fragments */ + if (y > 0) { + s->dsp.vp3_v_loop_filter( + plane_data + 8*x, + stride, bounding_values); + } + + /* do not perform right edge filter for right column + * fragments or if right fragment neighbor is also coded + * in this frame (it will be filtered in next iteration) */ + if ((x < width - 1) && + (s->all_fragments[fragment + 1].coding_method == MODE_COPY)) { + s->dsp.vp3_h_loop_filter( + plane_data + 8*x + 8, + stride, bounding_values); + } + + /* do not perform bottom edge filter for bottom row + * fragments or if bottom fragment neighbor is also coded + * in this frame (it will be filtered in the next row) */ + if ((y < height - 1) && + (s->all_fragments[fragment + width].coding_method == MODE_COPY)) { + s->dsp.vp3_v_loop_filter( + plane_data + 8*x + 8*stride, + stride, bounding_values); + } + } + + fragment++; + } + plane_data += 8*stride; + } +} + +/** + * Pulls DCT tokens from the 64 levels to decode and dequant the coefficients + * for the next block in coding order + */ +static inline int vp3_dequant(Vp3DecodeContext *s, Vp3Fragment *frag, + int plane, int inter, DCTELEM block[64]) +{ + int16_t *dequantizer = s->qmat[frag->qpi][inter][plane]; + uint8_t *perm = s->scantable.permutated; + int i = 0; + + do { + int token = *s->dct_tokens[plane][i]; + switch (token & 3) { + case 0: // EOB + if (--token < 4) // 0-3 are token types, so the EOB run must now be 0 + s->dct_tokens[plane][i]++; + else + *s->dct_tokens[plane][i] = token & ~3; + goto end; + case 1: // zero run + s->dct_tokens[plane][i]++; + i += (token >> 2) & 0x7f; + block[perm[i]] = (token >> 9) * dequantizer[perm[i]]; + i++; + break; + case 2: // coeff + block[perm[i]] = (token >> 2) * dequantizer[perm[i]]; + s->dct_tokens[plane][i++]++; + break; + default: // shouldn't happen + return i; + } + } while (i < 64); +end: + // the actual DC+prediction is in the fragment structure + block[0] = frag->dc * s->qmat[0][inter][plane][0]; + return i; +} + +/** + * called when all pixels up to row y are complete + */ +static void vp3_draw_horiz_band(Vp3DecodeContext *s, int y) +{ + int h, cy; + int offset[4]; + + if(s->avctx->draw_horiz_band==NULL) + return; + + h= y - s->last_slice_end; + y -= h; + + if (!s->flipped_image) { + if (y == 0) + h -= s->height - s->avctx->height; // account for non-mod16 + y = s->height - y - h; + } + + cy = y >> 1; + offset[0] = s->current_frame.linesize[0]*y; + offset[1] = s->current_frame.linesize[1]*cy; + offset[2] = s->current_frame.linesize[2]*cy; + offset[3] = 0; + + emms_c(); + s->avctx->draw_horiz_band(s->avctx, &s->current_frame, offset, y, 3, h); + s->last_slice_end= y + h; +} + /* * Perform the final rendering for a particular slice of data. - * The slice number ranges from 0..(macroblock_height - 1). + * The slice number ranges from 0..(c_superblock_height - 1). */ static void render_slice(Vp3DecodeContext *s, int slice) { - int x; - int16_t *dequantizer; - DECLARE_ALIGNED_16(DCTELEM, block[64]); + int x, y, i, j; + LOCAL_ALIGNED_16(DCTELEM, block, [64]); int motion_x = 0xdeadbeef, motion_y = 0xdeadbeef; int motion_halfpel_index; uint8_t *motion_source; - int plane; - int current_macroblock_entry = slice * s->macroblock_width * 6; + int plane, first_pixel; - if (slice >= s->macroblock_height) + if (slice >= s->c_superblock_height) return; for (plane = 0; plane < 3; plane++) { - uint8_t *output_plane = s->current_frame.data [plane]; - uint8_t * last_plane = s-> last_frame.data [plane]; - uint8_t *golden_plane = s-> golden_frame.data [plane]; + uint8_t *output_plane = s->current_frame.data [plane] + s->data_offset[plane]; + uint8_t * last_plane = s-> last_frame.data [plane] + s->data_offset[plane]; + uint8_t *golden_plane = s-> golden_frame.data [plane] + s->data_offset[plane]; int stride = s->current_frame.linesize[plane]; - int plane_width = s->width >> !!plane; - int plane_height = s->height >> !!plane; - int y = slice * FRAGMENT_PIXELS << !plane ; - int slice_height = y + (FRAGMENT_PIXELS << !plane); - int i = s->macroblock_fragments[current_macroblock_entry + plane + 3*!!plane]; + int plane_width = s->width >> (plane && s->chroma_x_shift); + int plane_height = s->height >> (plane && s->chroma_y_shift); + int8_t (*motion_val)[2] = s->motion_val[!!plane]; + + int sb_x, sb_y = slice << (!plane && s->chroma_y_shift); + int slice_height = sb_y + 1 + (!plane && s->chroma_y_shift); + int slice_width = plane ? s->c_superblock_width : s->y_superblock_width; + + int fragment_width = s->fragment_width[!!plane]; + int fragment_height = s->fragment_height[!!plane]; + int fragment_start = s->fragment_start[plane]; if (!s->flipped_image) stride = -stride; + if (CONFIG_GRAY && plane && (s->avctx->flags & CODEC_FLAG_GRAY)) + continue; if(FFABS(stride) > 2048) return; //various tables are fixed size - /* for each fragment row in the slice (both of them)... */ - for (; y < slice_height; y += 8) { + /* for each superblock row in the slice (both of them)... */ + for (; sb_y < slice_height; sb_y++) { - /* for each fragment in a row... */ - for (x = 0; x < plane_width; x += 8, i++) { + /* for each superblock in a row... */ + for (sb_x = 0; sb_x < slice_width; sb_x++) { - if ((i < 0) || (i >= s->fragment_count)) { - av_log(s->avctx, AV_LOG_ERROR, " vp3:render_slice(): bad fragment number (%d)\n", i); - return; - } + /* for each block in a superblock... */ + for (j = 0; j < 16; j++) { + x = 4*sb_x + hilbert_offset[j][0]; + y = 4*sb_y + hilbert_offset[j][1]; + + i = fragment_start + y*fragment_width + x; + + // bounds check + if (x >= fragment_width || y >= fragment_height) + continue; + + first_pixel = 8*y*stride + 8*x; /* transform if this block was coded */ - if ((s->all_fragments[i].coding_method != MODE_COPY) && - !((s->avctx->flags & CODEC_FLAG_GRAY) && plane)) { - + if (s->all_fragments[i].coding_method != MODE_COPY) { if ((s->all_fragments[i].coding_method == MODE_USING_GOLDEN) || (s->all_fragments[i].coding_method == MODE_GOLDEN_MV)) motion_source= golden_plane; else motion_source= last_plane; - motion_source += s->all_fragments[i].first_pixel; + motion_source += first_pixel; motion_halfpel_index = 0; /* sort out the motion vector if this fragment is coded @@ -1396,17 +1409,11 @@ static void render_slice(Vp3DecodeContext *s, int slice) if ((s->all_fragments[i].coding_method > MODE_INTRA) && (s->all_fragments[i].coding_method != MODE_USING_GOLDEN)) { int src_x, src_y; - motion_x = s->all_fragments[i].motion_x; - motion_y = s->all_fragments[i].motion_y; - if(plane){ - motion_x= (motion_x>>1) | (motion_x&1); - motion_y= (motion_y>>1) | (motion_y&1); - } + motion_x = motion_val[y*fragment_width + x][0]; + motion_y = motion_val[y*fragment_width + x][1]; - src_x= (motion_x>>1) + x; - src_y= (motion_y>>1) + y; - if ((motion_x == 127) || (motion_y == 127)) - av_log(s->avctx, AV_LOG_ERROR, " help! got invalid motion vector! (%X, %X)\n", motion_x, motion_y); + src_x= (motion_x>>1) + 8*x; + src_y= (motion_y>>1) + 8*y; motion_halfpel_index = motion_x & 0x01; motion_source += (motion_x >> 1); @@ -1434,96 +1441,54 @@ static void render_slice(Vp3DecodeContext *s, int slice) put_no_rnd_pixels_tab is better optimzed */ if(motion_halfpel_index != 3){ s->dsp.put_no_rnd_pixels_tab[1][motion_halfpel_index]( - output_plane + s->all_fragments[i].first_pixel, + output_plane + first_pixel, motion_source, stride, 8); }else{ int d= (motion_x ^ motion_y)>>31; // d is 0 if motion_x and _y have the same sign, else -1 s->dsp.put_no_rnd_pixels_l2[1]( - output_plane + s->all_fragments[i].first_pixel, + output_plane + first_pixel, motion_source - d, motion_source + stride + 1 + d, stride, 8); } - dequantizer = s->qmat[s->all_fragments[i].qpi][1][plane]; - }else{ - dequantizer = s->qmat[s->all_fragments[i].qpi][0][plane]; } - /* dequantize the DCT coefficients */ - if(s->avctx->idct_algo==FF_IDCT_VP3){ - Coeff *coeff= s->coeffs + i; s->dsp.clear_block(block); - while(coeff->next){ - block[coeff->index]= coeff->coeff * dequantizer[coeff->index]; - coeff= coeff->next; - } - }else{ - Coeff *coeff= s->coeffs + i; - s->dsp.clear_block(block); - while(coeff->next){ - block[coeff->index]= (coeff->coeff * dequantizer[coeff->index] + 2)>>2; - coeff= coeff->next; - } - } /* invert DCT and place (or add) in final output */ if (s->all_fragments[i].coding_method == MODE_INTRA) { + vp3_dequant(s, s->all_fragments + i, plane, 0, block); if(s->avctx->idct_algo!=FF_IDCT_VP3) block[0] += 128<<3; s->dsp.idct_put( - output_plane + s->all_fragments[i].first_pixel, + output_plane + first_pixel, stride, block); } else { + if (vp3_dequant(s, s->all_fragments + i, plane, 1, block)) { s->dsp.idct_add( - output_plane + s->all_fragments[i].first_pixel, + output_plane + first_pixel, stride, block); + } else { + s->dsp.vp3_idct_dc_add(output_plane + first_pixel, stride, block); + } } } else { /* copy directly from the previous frame */ s->dsp.put_pixels_tab[1][0]( - output_plane + s->all_fragments[i].first_pixel, - last_plane + s->all_fragments[i].first_pixel, + output_plane + first_pixel, + last_plane + first_pixel, stride, 8); } -#if 0 - /* perform the left edge filter if: - * - the fragment is not on the left column - * - the fragment is coded in this frame - * - the fragment is not coded in this frame but the left - * fragment is coded in this frame (this is done instead - * of a right edge filter when rendering the left fragment - * since this fragment is not available yet) */ - if ((x > 0) && - ((s->all_fragments[i].coding_method != MODE_COPY) || - ((s->all_fragments[i].coding_method == MODE_COPY) && - (s->all_fragments[i - 1].coding_method != MODE_COPY)) )) { - horizontal_filter( - output_plane + s->all_fragments[i].first_pixel + 7*stride, - -stride, s->bounding_values_array + 127); } - - /* perform the top edge filter if: - * - the fragment is not on the top row - * - the fragment is coded in this frame - * - the fragment is not coded in this frame but the above - * fragment is coded in this frame (this is done instead - * of a bottom edge filter when rendering the above - * fragment since this fragment is not available yet) */ - if ((y > 0) && - ((s->all_fragments[i].coding_method != MODE_COPY) || - ((s->all_fragments[i].coding_method == MODE_COPY) && - (s->all_fragments[i - fragment_width].coding_method != MODE_COPY)) )) { - vertical_filter( - output_plane + s->all_fragments[i].first_pixel - stride, - -stride, s->bounding_values_array + 127); - } -#endif } + + // Filter up to the last row in the superblock row + apply_loop_filter(s, plane, 4*sb_y - !!sb_y, FFMIN(4*sb_y+3, fragment_height-1)); } } @@ -1535,137 +1500,7 @@ static void render_slice(Vp3DecodeContext *s, int slice) * dispatch (slice - 1); */ - emms_c(); -} - -static void apply_loop_filter(Vp3DecodeContext *s) -{ - int plane; - int x, y; - int *bounding_values= s->bounding_values_array+127; - -#if 0 - int bounding_values_array[256]; - int filter_limit; - - /* find the right loop limit value */ - for (x = 63; x >= 0; x--) { - if (vp31_ac_scale_factor[x] >= s->quality_index) - break; - } - filter_limit = vp31_filter_limit_values[s->quality_index]; - - /* set up the bounding values */ - memset(bounding_values_array, 0, 256 * sizeof(int)); - for (x = 0; x < filter_limit; x++) { - bounding_values[-x - filter_limit] = -filter_limit + x; - bounding_values[-x] = -x; - bounding_values[x] = x; - bounding_values[x + filter_limit] = filter_limit - x; - } -#endif - - for (plane = 0; plane < 3; plane++) { - int width = s->fragment_width >> !!plane; - int height = s->fragment_height >> !!plane; - int fragment = s->fragment_start [plane]; - int stride = s->current_frame.linesize[plane]; - uint8_t *plane_data = s->current_frame.data [plane]; - if (!s->flipped_image) stride = -stride; - - for (y = 0; y < height; y++) { - - for (x = 0; x < width; x++) { - /* do not perform left edge filter for left columns frags */ - if ((x > 0) && - (s->all_fragments[fragment].coding_method != MODE_COPY)) { - s->dsp.vp3_h_loop_filter( - plane_data + s->all_fragments[fragment].first_pixel, - stride, bounding_values); - } - - /* do not perform top edge filter for top row fragments */ - if ((y > 0) && - (s->all_fragments[fragment].coding_method != MODE_COPY)) { - s->dsp.vp3_v_loop_filter( - plane_data + s->all_fragments[fragment].first_pixel, - stride, bounding_values); - } - - /* do not perform right edge filter for right column - * fragments or if right fragment neighbor is also coded - * in this frame (it will be filtered in next iteration) */ - if ((x < width - 1) && - (s->all_fragments[fragment].coding_method != MODE_COPY) && - (s->all_fragments[fragment + 1].coding_method == MODE_COPY)) { - s->dsp.vp3_h_loop_filter( - plane_data + s->all_fragments[fragment + 1].first_pixel, - stride, bounding_values); - } - - /* do not perform bottom edge filter for bottom row - * fragments or if bottom fragment neighbor is also coded - * in this frame (it will be filtered in the next row) */ - if ((y < height - 1) && - (s->all_fragments[fragment].coding_method != MODE_COPY) && - (s->all_fragments[fragment + width].coding_method == MODE_COPY)) { - s->dsp.vp3_v_loop_filter( - plane_data + s->all_fragments[fragment + width].first_pixel, - stride, bounding_values); - } - - fragment++; - } - } - } -} - -/* - * This function computes the first pixel addresses for each fragment. - * This function needs to be invoked after the first frame is allocated - * so that it has access to the plane strides. - */ -static void vp3_calculate_pixel_addresses(Vp3DecodeContext *s) -{ -#define Y_INITIAL(chroma_shift) s->flipped_image ? 1 : s->fragment_height >> chroma_shift -#define Y_FINISHED(chroma_shift) s->flipped_image ? y <= s->fragment_height >> chroma_shift : y > 0 - - int i, x, y; - const int y_inc = s->flipped_image ? 1 : -1; - - /* figure out the first pixel addresses for each of the fragments */ - /* Y plane */ - i = 0; - for (y = Y_INITIAL(0); Y_FINISHED(0); y += y_inc) { - for (x = 0; x < s->fragment_width; x++) { - s->all_fragments[i++].first_pixel = - s->golden_frame.linesize[0] * y * FRAGMENT_PIXELS - - s->golden_frame.linesize[0] + - x * FRAGMENT_PIXELS; - } - } - - /* U plane */ - i = s->fragment_start[1]; - for (y = Y_INITIAL(1); Y_FINISHED(1); y += y_inc) { - for (x = 0; x < s->fragment_width / 2; x++) { - s->all_fragments[i++].first_pixel = - s->golden_frame.linesize[1] * y * FRAGMENT_PIXELS - - s->golden_frame.linesize[1] + - x * FRAGMENT_PIXELS; - } - } - - /* V plane */ - i = s->fragment_start[2]; - for (y = Y_INITIAL(1); Y_FINISHED(1); y += y_inc) { - for (x = 0; x < s->fragment_width / 2; x++) { - s->all_fragments[i++].first_pixel = - s->golden_frame.linesize[2] * y * FRAGMENT_PIXELS - - s->golden_frame.linesize[2] + - x * FRAGMENT_PIXELS; - } - } + vp3_draw_horiz_band(s, FFMIN(64*slice + 64-16, s->height-16)); } /* @@ -1677,8 +1512,7 @@ static av_cold int vp3_decode_init(AVCodecContext *avctx) int i, inter, plane; int c_width; int c_height; - int y_superblock_count; - int c_superblock_count; + int y_fragment_count, c_fragment_count; if (avctx->codec_tag == MKTAG('V','P','3','0')) s->version = 0; @@ -1688,7 +1522,8 @@ static av_cold int vp3_decode_init(AVCodecContext *avctx) s->avctx = avctx; s->width = FFALIGN(avctx->width, 16); s->height = FFALIGN(avctx->height, 16); - avctx->pix_fmt = PIX_FMT_YUV420P; + if (avctx->pix_fmt == PIX_FMT_NONE) + avctx->pix_fmt = PIX_FMT_YUV420P; avctx->chroma_sample_location = AVCHROMA_LOC_CENTER; if(avctx->idct_algo==FF_IDCT_AUTO) avctx->idct_algo=FF_IDCT_VP3; @@ -1701,39 +1536,51 @@ static av_cold int vp3_decode_init(AVCodecContext *avctx) for (i = 0; i < 3; i++) s->qps[i] = -1; + avcodec_get_chroma_sub_sample(avctx->pix_fmt, &s->chroma_x_shift, &s->chroma_y_shift); + s->y_superblock_width = (s->width + 31) / 32; s->y_superblock_height = (s->height + 31) / 32; - y_superblock_count = s->y_superblock_width * s->y_superblock_height; + s->y_superblock_count = s->y_superblock_width * s->y_superblock_height; /* work out the dimensions for the C planes */ - c_width = s->width / 2; - c_height = s->height / 2; + c_width = s->width >> s->chroma_x_shift; + c_height = s->height >> s->chroma_y_shift; s->c_superblock_width = (c_width + 31) / 32; s->c_superblock_height = (c_height + 31) / 32; - c_superblock_count = s->c_superblock_width * s->c_superblock_height; + s->c_superblock_count = s->c_superblock_width * s->c_superblock_height; - s->superblock_count = y_superblock_count + (c_superblock_count * 2); - s->u_superblock_start = y_superblock_count; - s->v_superblock_start = s->u_superblock_start + c_superblock_count; + s->superblock_count = s->y_superblock_count + (s->c_superblock_count * 2); + s->u_superblock_start = s->y_superblock_count; + s->v_superblock_start = s->u_superblock_start + s->c_superblock_count; s->superblock_coding = av_malloc(s->superblock_count); s->macroblock_width = (s->width + 15) / 16; s->macroblock_height = (s->height + 15) / 16; s->macroblock_count = s->macroblock_width * s->macroblock_height; - s->fragment_width = s->width / FRAGMENT_PIXELS; - s->fragment_height = s->height / FRAGMENT_PIXELS; + s->fragment_width[0] = s->width / FRAGMENT_PIXELS; + s->fragment_height[0] = s->height / FRAGMENT_PIXELS; + s->fragment_width[1] = s->fragment_width[0] >> s->chroma_x_shift; + s->fragment_height[1] = s->fragment_height[0] >> s->chroma_y_shift; /* fragment count covers all 8x8 blocks for all 3 planes */ - s->fragment_count = s->fragment_width * s->fragment_height * 3 / 2; - s->fragment_start[1] = s->fragment_width * s->fragment_height; - s->fragment_start[2] = s->fragment_width * s->fragment_height * 5 / 4; + y_fragment_count = s->fragment_width[0] * s->fragment_height[0]; + c_fragment_count = s->fragment_width[1] * s->fragment_height[1]; + s->fragment_count = y_fragment_count + 2*c_fragment_count; + s->fragment_start[1] = y_fragment_count; + s->fragment_start[2] = y_fragment_count + c_fragment_count; s->all_fragments = av_malloc(s->fragment_count * sizeof(Vp3Fragment)); - s->coeff_counts = av_malloc(s->fragment_count * sizeof(*s->coeff_counts)); - s->coeffs = av_malloc(s->fragment_count * sizeof(Coeff) * 65); - s->coded_fragment_list = av_malloc(s->fragment_count * sizeof(int)); - s->pixel_addresses_initialized = 0; + s->coded_fragment_list[0] = av_malloc(s->fragment_count * sizeof(int)); + s->dct_tokens_base = av_malloc(64*s->fragment_count * sizeof(*s->dct_tokens_base)); + s->motion_val[0] = av_malloc(y_fragment_count * sizeof(*s->motion_val[0])); + s->motion_val[1] = av_malloc(c_fragment_count * sizeof(*s->motion_val[1])); + + if (!s->superblock_coding || !s->all_fragments || !s->dct_tokens_base || + !s->coded_fragment_list[0] || !s->motion_val[0] || !s->motion_val[1]) { + vp3_decode_end(avctx); + return -1; + } if (!s->theora_tables) { @@ -1759,61 +1606,61 @@ static av_cold int vp3_decode_init(AVCodecContext *avctx) for (i = 0; i < 16; i++) { /* DC histograms */ - init_vlc(&s->dc_vlc[i], 5, 32, + init_vlc(&s->dc_vlc[i], 11, 32, &dc_bias[i][0][1], 4, 2, &dc_bias[i][0][0], 4, 2, 0); /* group 1 AC histograms */ - init_vlc(&s->ac_vlc_1[i], 5, 32, + init_vlc(&s->ac_vlc_1[i], 11, 32, &ac_bias_0[i][0][1], 4, 2, &ac_bias_0[i][0][0], 4, 2, 0); /* group 2 AC histograms */ - init_vlc(&s->ac_vlc_2[i], 5, 32, + init_vlc(&s->ac_vlc_2[i], 11, 32, &ac_bias_1[i][0][1], 4, 2, &ac_bias_1[i][0][0], 4, 2, 0); /* group 3 AC histograms */ - init_vlc(&s->ac_vlc_3[i], 5, 32, + init_vlc(&s->ac_vlc_3[i], 11, 32, &ac_bias_2[i][0][1], 4, 2, &ac_bias_2[i][0][0], 4, 2, 0); /* group 4 AC histograms */ - init_vlc(&s->ac_vlc_4[i], 5, 32, + init_vlc(&s->ac_vlc_4[i], 11, 32, &ac_bias_3[i][0][1], 4, 2, &ac_bias_3[i][0][0], 4, 2, 0); } } else { - for (i = 0; i < 16; i++) { + for (i = 0; i < 16; i++) { /* DC histograms */ - if (init_vlc(&s->dc_vlc[i], 5, 32, - &s->huffman_table[i][0][1], 4, 2, - &s->huffman_table[i][0][0], 4, 2, 0) < 0) + if (init_vlc(&s->dc_vlc[i], 11, 32, + &s->huffman_table[i][0][1], 8, 4, + &s->huffman_table[i][0][0], 8, 4, 0) < 0) goto vlc_fail; /* group 1 AC histograms */ - if (init_vlc(&s->ac_vlc_1[i], 5, 32, - &s->huffman_table[i+16][0][1], 4, 2, - &s->huffman_table[i+16][0][0], 4, 2, 0) < 0) + if (init_vlc(&s->ac_vlc_1[i], 11, 32, + &s->huffman_table[i+16][0][1], 8, 4, + &s->huffman_table[i+16][0][0], 8, 4, 0) < 0) goto vlc_fail; /* group 2 AC histograms */ - if (init_vlc(&s->ac_vlc_2[i], 5, 32, - &s->huffman_table[i+16*2][0][1], 4, 2, - &s->huffman_table[i+16*2][0][0], 4, 2, 0) < 0) + if (init_vlc(&s->ac_vlc_2[i], 11, 32, + &s->huffman_table[i+16*2][0][1], 8, 4, + &s->huffman_table[i+16*2][0][0], 8, 4, 0) < 0) goto vlc_fail; /* group 3 AC histograms */ - if (init_vlc(&s->ac_vlc_3[i], 5, 32, - &s->huffman_table[i+16*3][0][1], 4, 2, - &s->huffman_table[i+16*3][0][0], 4, 2, 0) < 0) + if (init_vlc(&s->ac_vlc_3[i], 11, 32, + &s->huffman_table[i+16*3][0][1], 8, 4, + &s->huffman_table[i+16*3][0][0], 8, 4, 0) < 0) goto vlc_fail; /* group 4 AC histograms */ - if (init_vlc(&s->ac_vlc_4[i], 5, 32, - &s->huffman_table[i+16*4][0][1], 4, 2, - &s->huffman_table[i+16*4][0][0], 4, 2, 0) < 0) + if (init_vlc(&s->ac_vlc_4[i], 11, 32, + &s->huffman_table[i+16*4][0][1], 8, 4, + &s->huffman_table[i+16*4][0][0], 8, 4, 0) < 0) goto vlc_fail; } } @@ -1836,9 +1683,11 @@ static av_cold int vp3_decode_init(AVCodecContext *avctx) /* work out the block mapping tables */ s->superblock_fragments = av_malloc(s->superblock_count * 16 * sizeof(int)); - s->superblock_macroblocks = av_malloc(s->superblock_count * 4 * sizeof(int)); - s->macroblock_fragments = av_malloc(s->macroblock_count * 6 * sizeof(int)); s->macroblock_coding = av_malloc(s->macroblock_count + 1); + if (!s->superblock_fragments || !s->macroblock_coding) { + vp3_decode_end(avctx); + return -1; + } init_block_mapping(s); for (i = 0; i < 3; i++) { @@ -1906,6 +1755,13 @@ static int vp3_decode_frame(AVCodecContext *avctx, if (avctx->skip_frame >= AVDISCARD_NONKEY && !s->keyframe) return buf_size; + s->current_frame.reference = 3; + s->current_frame.pict_type = s->keyframe ? FF_I_TYPE : FF_P_TYPE; + if (avctx->get_buffer(avctx, &s->current_frame) < 0) { + av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + goto error; + } + if (s->keyframe) { if (!s->theora) { @@ -1924,99 +1780,92 @@ static int vp3_decode_frame(AVCodecContext *avctx, av_log(s->avctx, AV_LOG_ERROR, "Warning, unsupported keyframe coding type?!\n"); skip_bits(&gb, 2); /* reserved? */ } - - if (s->last_frame.data[0] == s->golden_frame.data[0]) { - if (s->golden_frame.data[0]) - avctx->release_buffer(avctx, &s->golden_frame); - s->last_frame= s->golden_frame; /* ensure that we catch any access to this released frame */ - } else { - if (s->golden_frame.data[0]) - avctx->release_buffer(avctx, &s->golden_frame); - if (s->last_frame.data[0]) - avctx->release_buffer(avctx, &s->last_frame); - } - - s->golden_frame.reference = 3; - if(avctx->get_buffer(avctx, &s->golden_frame) < 0) { - av_log(s->avctx, AV_LOG_ERROR, "vp3: get_buffer() failed\n"); - return -1; - } - - /* golden frame is also the current frame */ - s->current_frame= s->golden_frame; - - /* time to figure out pixel addresses? */ - if (!s->pixel_addresses_initialized) - { - vp3_calculate_pixel_addresses(s); - s->pixel_addresses_initialized = 1; - } } else { - /* allocate a new current frame */ - s->current_frame.reference = 3; - if (!s->pixel_addresses_initialized) { - av_log(s->avctx, AV_LOG_ERROR, "vp3: first frame not a keyframe\n"); - return -1; - } - if(avctx->get_buffer(avctx, &s->current_frame) < 0) { - av_log(s->avctx, AV_LOG_ERROR, "vp3: get_buffer() failed\n"); - return -1; + if (!s->golden_frame.data[0]) { + av_log(s->avctx, AV_LOG_WARNING, "vp3: first frame not a keyframe\n"); + + s->golden_frame.reference = 3; + s->golden_frame.pict_type = FF_I_TYPE; + if (avctx->get_buffer(avctx, &s->golden_frame) < 0) { + av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + goto error; + } + s->last_frame = s->golden_frame; + s->last_frame.type = FF_BUFFER_TYPE_COPY; } } s->current_frame.qscale_table= s->qscale_table; //FIXME allocate individual tables per AVFrame s->current_frame.qstride= 0; - init_frame(s, &gb); + memset(s->all_fragments, 0, s->fragment_count * sizeof(Vp3Fragment)); if (unpack_superblocks(s, &gb)){ av_log(s->avctx, AV_LOG_ERROR, "error in unpack_superblocks\n"); - return -1; + goto error; } if (unpack_modes(s, &gb)){ av_log(s->avctx, AV_LOG_ERROR, "error in unpack_modes\n"); - return -1; + goto error; } if (unpack_vectors(s, &gb)){ av_log(s->avctx, AV_LOG_ERROR, "error in unpack_vectors\n"); - return -1; + goto error; } if (unpack_block_qpis(s, &gb)){ av_log(s->avctx, AV_LOG_ERROR, "error in unpack_block_qpis\n"); - return -1; + goto error; } if (unpack_dct_coeffs(s, &gb)){ av_log(s->avctx, AV_LOG_ERROR, "error in unpack_dct_coeffs\n"); - return -1; + goto error; } - reverse_dc_prediction(s, 0, s->fragment_width, s->fragment_height); - if ((avctx->flags & CODEC_FLAG_GRAY) == 0) { - reverse_dc_prediction(s, s->fragment_start[1], - s->fragment_width / 2, s->fragment_height / 2); - reverse_dc_prediction(s, s->fragment_start[2], - s->fragment_width / 2, s->fragment_height / 2); + for (i = 0; i < 3; i++) { + int height = s->height >> (i && s->chroma_y_shift); + if (s->flipped_image) + s->data_offset[i] = 0; + else + s->data_offset[i] = (height-1) * s->current_frame.linesize[i]; } - for (i = 0; i < s->macroblock_height; i++) + s->last_slice_end = 0; + for (i = 0; i < s->c_superblock_height; i++) render_slice(s, i); - apply_loop_filter(s); + // filter the last row + for (i = 0; i < 3; i++) { + int row = (s->height >> (3+(i && s->chroma_y_shift))) - 1; + apply_loop_filter(s, i, row, row+1); + } + vp3_draw_horiz_band(s, s->height); *data_size=sizeof(AVFrame); *(AVFrame*)data= s->current_frame; /* release the last frame, if it is allocated and if it is not the * golden frame */ - if ((s->last_frame.data[0]) && - (s->last_frame.data[0] != s->golden_frame.data[0])) + if (s->last_frame.data[0] && s->last_frame.type != FF_BUFFER_TYPE_COPY) avctx->release_buffer(avctx, &s->last_frame); /* shuffle frames (last = current) */ s->last_frame= s->current_frame; + + if (s->keyframe) { + if (s->golden_frame.data[0]) + avctx->release_buffer(avctx, &s->golden_frame); + s->golden_frame = s->current_frame; + s->last_frame.type = FF_BUFFER_TYPE_COPY; + } + s->current_frame.data[0]= NULL; /* ensure that we catch any access to this released frame */ return buf_size; + +error: + if (s->current_frame.data[0]) + avctx->release_buffer(avctx, &s->current_frame); + return -1; } /* @@ -2029,13 +1878,12 @@ static av_cold int vp3_decode_end(AVCodecContext *avctx) av_free(s->superblock_coding); av_free(s->all_fragments); - av_free(s->coeff_counts); - av_free(s->coeffs); - av_free(s->coded_fragment_list); + av_free(s->coded_fragment_list[0]); + av_free(s->dct_tokens_base); av_free(s->superblock_fragments); - av_free(s->superblock_macroblocks); - av_free(s->macroblock_fragments); av_free(s->macroblock_coding); + av_free(s->motion_val[0]); + av_free(s->motion_val[1]); for (i = 0; i < 16; i++) { free_vlc(&s->dc_vlc[i]); @@ -2051,9 +1899,9 @@ static av_cold int vp3_decode_end(AVCodecContext *avctx) free_vlc(&s->motion_vector_vlc); /* release all frames */ - if (s->golden_frame.data[0] && s->golden_frame.data[0] != s->last_frame.data[0]) + if (s->golden_frame.data[0]) avctx->release_buffer(avctx, &s->golden_frame); - if (s->last_frame.data[0]) + if (s->last_frame.data[0] && s->last_frame.type != FF_BUFFER_TYPE_COPY) avctx->release_buffer(avctx, &s->last_frame); /* no need to release the current_frame since it will always be pointing * to the same frame as either the golden or last frame */ @@ -2096,10 +1944,16 @@ static int read_huffman_tree(AVCodecContext *avctx, GetBitContext *gb) } #if CONFIG_THEORA_DECODER +static const enum PixelFormat theora_pix_fmts[4] = { + PIX_FMT_YUV420P, PIX_FMT_NONE, PIX_FMT_YUV422P, PIX_FMT_YUV444P +}; + static int theora_decode_header(AVCodecContext *avctx, GetBitContext *gb) { Vp3DecodeContext *s = avctx->priv_data; - int visible_width, visible_height; + int visible_width, visible_height, colorspace; + int offset_x = 0, offset_y = 0; + AVRational fps; s->theora = get_bits_long(gb, 24); av_log(avctx, AV_LOG_DEBUG, "Theora bitstream version %X\n", s->theora); @@ -2121,33 +1975,27 @@ static int theora_decode_header(AVCodecContext *avctx, GetBitContext *gb) return -1; } - if (s->theora >= 0x030400) - { - skip_bits(gb, 32); /* total number of superblocks in a frame */ - // fixme, the next field is 36bits long - skip_bits(gb, 32); /* total number of blocks in a frame */ - skip_bits(gb, 4); /* total number of blocks in a frame */ - skip_bits(gb, 32); /* total number of macroblocks in a frame */ - } - if (s->theora >= 0x030200) { visible_width = get_bits_long(gb, 24); visible_height = get_bits_long(gb, 24); - skip_bits(gb, 8); /* offset x */ - skip_bits(gb, 8); /* offset y */ + offset_x = get_bits(gb, 8); /* offset x */ + offset_y = get_bits(gb, 8); /* offset y, from bottom */ } - skip_bits(gb, 32); /* fps numerator */ - skip_bits(gb, 32); /* fps denumerator */ - skip_bits(gb, 24); /* aspect numerator */ - skip_bits(gb, 24); /* aspect denumerator */ + fps.num = get_bits_long(gb, 32); + fps.den = get_bits_long(gb, 32); + if (fps.num && fps.den) { + av_reduce(&avctx->time_base.num, &avctx->time_base.den, + fps.den, fps.num, 1<<30); + } + + avctx->sample_aspect_ratio.num = get_bits_long(gb, 24); + avctx->sample_aspect_ratio.den = get_bits_long(gb, 24); if (s->theora < 0x030200) skip_bits(gb, 5); /* keyframe frequency force */ - skip_bits(gb, 8); /* colorspace */ - if (s->theora >= 0x030400) - skip_bits(gb, 2); /* pixel format: 420,res,422,444 */ + colorspace = get_bits(gb, 8); skip_bits(gb, 24); /* bitrate */ skip_bits(gb, 6); /* quality hint */ @@ -2155,19 +2003,29 @@ static int theora_decode_header(AVCodecContext *avctx, GetBitContext *gb) if (s->theora >= 0x030200) { skip_bits(gb, 5); /* keyframe frequency force */ - - if (s->theora < 0x030400) - skip_bits(gb, 5); /* spare bits */ + avctx->pix_fmt = theora_pix_fmts[get_bits(gb, 2)]; + skip_bits(gb, 3); /* reserved */ } // align_get_bits(gb); if ( visible_width <= s->width && visible_width > s->width-16 - && visible_height <= s->height && visible_height > s->height-16) + && visible_height <= s->height && visible_height > s->height-16 + && !offset_x && (offset_y == s->height - visible_height)) avcodec_set_dimensions(avctx, visible_width, visible_height); else avcodec_set_dimensions(avctx, s->width, s->height); + if (colorspace == 1) { + avctx->color_primaries = AVCOL_PRI_BT470M; + } else if (colorspace == 2) { + avctx->color_primaries = AVCOL_PRI_BT470BG; + } + if (colorspace == 1 || colorspace == 2) { + avctx->colorspace = AVCOL_SPC_BT470BG; + avctx->color_trc = AVCOL_TRC_BT709; + } + return 0; } @@ -2306,7 +2164,7 @@ static av_cold int theora_decode_init(AVCodecContext *avctx) } for(i=0;i<3;i++) { - init_get_bits(&gb, header_start[i], header_len[i]); + init_get_bits(&gb, header_start[i], header_len[i] * 8); ptype = get_bits(&gb, 8); @@ -2347,14 +2205,14 @@ static av_cold int theora_decode_init(AVCodecContext *avctx) AVCodec theora_decoder = { "theora", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_THEORA, sizeof(Vp3DecodeContext), theora_decode_init, NULL, vp3_decode_end, vp3_decode_frame, - CODEC_CAP_DR1, + CODEC_CAP_DR1 | CODEC_CAP_DRAW_HORIZ_BAND, NULL, .long_name = NULL_IF_CONFIG_SMALL("Theora"), }; @@ -2362,14 +2220,14 @@ AVCodec theora_decoder = { AVCodec vp3_decoder = { "vp3", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_VP3, sizeof(Vp3DecodeContext), vp3_decode_init, NULL, vp3_decode_end, vp3_decode_frame, - CODEC_CAP_DR1, + CODEC_CAP_DR1 | CODEC_CAP_DRAW_HORIZ_BAND, NULL, .long_name = NULL_IF_CONFIG_SMALL("On2 VP3"), }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vp3dsp.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/vp3dsp.c index 87b64de385..058eb562c4 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vp3dsp.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vp3dsp.c @@ -19,7 +19,7 @@ */ /** - * @file libavcodec/vp3dsp.c + * @file * Standard C DSP-oriented functions cribbed from the original VP3 * source code. */ @@ -223,6 +223,25 @@ void ff_vp3_idct_add_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/* idct(dest, line_size, block, 2); } +void ff_vp3_idct_dc_add_c(uint8_t *dest/*align 8*/, int line_size, const DCTELEM *block/*align 16*/){ + const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; + int i, dc = block[0]; + dc = (46341*dc)>>16; + dc = (46341*dc + (8<<16))>>20; + + for(i = 0; i < 8; i++){ + dest[0] = cm[dest[0]+dc]; + dest[1] = cm[dest[1]+dc]; + dest[2] = cm[dest[2]+dc]; + dest[3] = cm[dest[3]+dc]; + dest[4] = cm[dest[4]+dc]; + dest[5] = cm[dest[5]+dc]; + dest[6] = cm[dest[6]+dc]; + dest[7] = cm[dest[7]+dc]; + dest += line_size; + } +} + void ff_vp3_v_loop_filter_c(uint8_t *first_pixel, int stride, int *bounding_values) { unsigned char *end; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vp5.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/vp5.c index 1f8434c731..1479344ba4 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vp5.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vp5.c @@ -1,5 +1,5 @@ /** - * @file libavcodec/vp5.c + * @file * VP5 compatible video decoder * * Copyright (C) 2006 Aurelien Jacobs @@ -69,23 +69,6 @@ static int vp5_parse_header(VP56Context *s, const uint8_t *buf, int buf_size, return 1; } -/* Gives very similar result than the vp6 version except in a few cases */ -static int vp5_adjust(int v, int t) -{ - int s2, s1 = v >> 31; - v ^= s1; - v -= s1; - v *= v < 2*t; - v -= t; - s2 = v >> 31; - v ^= s2; - v -= s2; - v = t - v; - v += s1; - v ^= s1; - return v; -} - static void vp5_parse_vector_adjustment(VP56Context *s, VP56mv *vect) { VP56RangeCoder *c = &s->c; @@ -274,7 +257,6 @@ static av_cold int vp5_decode_init(AVCodecContext *avctx) vp56_init(avctx, 1, 0); s->vp56_coord_div = vp5_coord_div; s->parse_vector_adjustment = vp5_parse_vector_adjustment; - s->adjust = vp5_adjust; s->parse_coeff = vp5_parse_coeff; s->default_models_init = vp5_default_models_init; s->parse_vector_models = vp5_parse_vector_models; @@ -286,7 +268,7 @@ static av_cold int vp5_decode_init(AVCodecContext *avctx) AVCodec vp5_decoder = { "vp5", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_VP5, sizeof(VP56Context), vp5_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vp56.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/vp56.c index a5d6308813..74fe5ff5f4 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vp56.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vp56.c @@ -1,5 +1,5 @@ /** - * @file libavcodec/vp56.c + * @file * VP5 and VP6 compatible video decoder (common features) * * Copyright (C) 2006 Aurelien Jacobs @@ -33,6 +33,7 @@ void vp56_init_dequant(VP56Context *s, int quantizer) s->quantizer = quantizer; s->dequant_dc = vp56_dc_dequant[quantizer] << 2; s->dequant_ac = vp56_ac_dequant[quantizer] << 2; + memset(s->qscale_table, quantizer, s->mb_width); } static int vp56_get_vectors_predictors(VP56Context *s, int row, int col, @@ -299,27 +300,12 @@ static void vp56_add_predictors_dc(VP56Context *s, VP56Frame ref_frame) } } -static void vp56_edge_filter(VP56Context *s, uint8_t *yuv, - int pix_inc, int line_inc, int t) -{ - int pix2_inc = 2 * pix_inc; - int i, v; - - for (i=0; i<12; i++) { - v = (yuv[-pix2_inc] + 3*(yuv[0]-yuv[-pix_inc]) - yuv[pix_inc] + 4) >>3; - v = s->adjust(v, t); - yuv[-pix_inc] = av_clip_uint8(yuv[-pix_inc] + v); - yuv[0] = av_clip_uint8(yuv[0] - v); - yuv += line_inc; - } -} - static void vp56_deblock_filter(VP56Context *s, uint8_t *yuv, int stride, int dx, int dy) { int t = vp56_filter_threshold[s->quantizer]; - if (dx) vp56_edge_filter(s, yuv + 10-dx , 1, stride, t); - if (dy) vp56_edge_filter(s, yuv + stride*(10-dy), stride, 1, t); + if (dx) s->vp56dsp.edge_filter_hor(yuv + 10-dx , stride, t); + if (dy) s->vp56dsp.edge_filter_ver(yuv + stride*(10-dy), stride, t); } static void vp56_mc(VP56Context *s, int b, int plane, uint8_t *src, @@ -481,6 +467,7 @@ static int vp56_size_changed(AVCodecContext *avctx) return -1; } + s->qscale_table = av_realloc(s->qscale_table, s->mb_width); s->above_blocks = av_realloc(s->above_blocks, (4*s->mb_width+6) * sizeof(*s->above_blocks)); s->macroblocks = av_realloc(s->macroblocks, @@ -504,8 +491,12 @@ int vp56_decode_frame(AVCodecContext *avctx, void *data, int *data_size, int is_alpha, av_uninit(alpha_offset); if (s->has_alpha) { + if (remaining_buf_size < 3) + return -1; alpha_offset = bytestream_get_be24(&buf); remaining_buf_size -= 3; + if (remaining_buf_size < alpha_offset) + return -1; } for (is_alpha=0; is_alpha < 1+s->has_alpha; is_alpha++) { @@ -639,6 +630,9 @@ int vp56_decode_frame(AVCodecContext *avctx, void *data, int *data_size, FFSWAP(AVFrame *, s->framep[VP56_FRAME_CURRENT], s->framep[VP56_FRAME_PREVIOUS]); + p->qstride = 0; + p->qscale_table = s->qscale_table; + p->qscale_type = FF_QSCALE_TYPE_VP56; *(AVFrame*)data = *p; *data_size = sizeof(AVFrame); @@ -656,6 +650,7 @@ av_cold void vp56_init(AVCodecContext *avctx, int flip, int has_alpha) if (avctx->idct_algo == FF_IDCT_AUTO) avctx->idct_algo = FF_IDCT_VP3; dsputil_init(&s->dsp, avctx); + 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++) @@ -687,9 +682,10 @@ av_cold int vp56_free(AVCodecContext *avctx) { VP56Context *s = avctx->priv_data; - av_free(s->above_blocks); - av_free(s->macroblocks); - av_free(s->edge_emu_buffer_alloc); + av_freep(&s->qscale_table); + av_freep(&s->above_blocks); + av_freep(&s->macroblocks); + av_freep(&s->edge_emu_buffer_alloc); if (s->framep[VP56_FRAME_GOLDEN]->data[0]) avctx->release_buffer(avctx, s->framep[VP56_FRAME_GOLDEN]); if (s->framep[VP56_FRAME_GOLDEN2]->data[0]) diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vp56.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/vp56.h index 6f24c55638..89eba0563e 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vp56.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vp56.h @@ -1,5 +1,5 @@ /** - * @file libavcodec/vp56.h + * @file * VP5 and VP6 compatible video decoder (common features) * * Copyright (C) 2006 Aurelien Jacobs @@ -28,14 +28,13 @@ #include "dsputil.h" #include "get_bits.h" #include "bytestream.h" - +#include "vp56dsp.h" typedef struct vp56_context VP56Context; typedef struct vp56_mv VP56mv; typedef void (*VP56ParseVectorAdjustment)(VP56Context *s, VP56mv *vect); -typedef int (*VP56Adjust)(int v, int t); typedef void (*VP56Filter)(VP56Context *s, uint8_t *dst, uint8_t *src, int offset1, int offset2, int stride, VP56mv mv, int mask, int select, int luma); @@ -90,6 +89,7 @@ typedef struct { struct vp56_context { AVCodecContext *avctx; DSPContext dsp; + VP56DSPContext vp56dsp; ScanTable scantable; AVFrame frames[4]; AVFrame *framep[6]; @@ -110,6 +110,7 @@ struct vp56_context { int quantizer; uint16_t dequant_dc; uint16_t dequant_ac; + int8_t *qscale_table; /* DC predictors management */ VP56RefDc *above_blocks; @@ -120,7 +121,7 @@ struct vp56_context { /* blocks / macroblock */ VP56mb mb_type; VP56Macroblock *macroblocks; - DECLARE_ALIGNED_16(DCTELEM, block_coeff[6][64]); + DECLARE_ALIGNED(16, DCTELEM, block_coeff)[6][64]; /* motion vectors */ VP56mv mv[6]; /* vectors for each block in MB */ @@ -148,7 +149,6 @@ struct vp56_context { const uint8_t *vp56_coord_div; VP56ParseVectorAdjustment parse_vector_adjustment; - VP56Adjust adjust; VP56Filter filter; VP56ParseCoeff parse_coeff; VP56DefaultModelsInit default_models_init; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vp56data.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/vp56data.c index 02306f17eb..b0515c2410 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vp56data.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vp56data.c @@ -1,5 +1,5 @@ /** - * @file libavcodec/vp56data.c + * @file * VP5 and VP6 compatible video decoder (common data) * * Copyright (C) 2006 Aurelien Jacobs diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vp56data.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/vp56data.h index aef69f758f..57b0968d89 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vp56data.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vp56data.h @@ -1,5 +1,5 @@ /** - * @file libavcodec/vp56data.h + * @file * VP5 and VP6 compatible video decoder (common data) * * Copyright (C) 2006 Aurelien Jacobs diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vp56dsp.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/vp56dsp.c new file mode 100644 index 0000000000..9eb9299a36 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vp56dsp.c @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2006 Aurelien Jacobs + * Copyright (c) 2010 Mans Rullgard + * + * 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 +#include "avcodec.h" +#include "vp56dsp.h" + +/* Gives very similar result than the vp6 version except in a few cases */ +static int vp5_adjust(int v, int t) +{ + int s2, s1 = v >> 31; + v ^= s1; + v -= s1; + v *= v < 2*t; + v -= t; + s2 = v >> 31; + v ^= s2; + v -= s2; + v = t - v; + v += s1; + v ^= s1; + return v; +} + +static int vp6_adjust(int v, int t) +{ + int V = v, s = v >> 31; + V ^= s; + V -= s; + if (V-t-1 >= (unsigned)(t-1)) + return v; + V = 2*t - V; + V += s; + V ^= s; + return V; +} + + +#define VP56_EDGE_FILTER(pfx, suf, pix_inc, line_inc) \ +static void pfx##_edge_filter_##suf(uint8_t *yuv, int stride, int t) \ +{ \ + int pix2_inc = 2 * pix_inc; \ + int i, v; \ + \ + for (i=0; i<12; i++) { \ + v = (yuv[-pix2_inc] + 3*(yuv[0]-yuv[-pix_inc]) - yuv[pix_inc] + 4)>>3;\ + v = pfx##_adjust(v, t); \ + yuv[-pix_inc] = av_clip_uint8(yuv[-pix_inc] + v); \ + yuv[0] = av_clip_uint8(yuv[0] - v); \ + yuv += line_inc; \ + } \ +} + +VP56_EDGE_FILTER(vp5, hor, 1, stride) +VP56_EDGE_FILTER(vp5, ver, stride, 1) +VP56_EDGE_FILTER(vp6, hor, 1, stride) +VP56_EDGE_FILTER(vp6, ver, stride, 1) + +void ff_vp56dsp_init(VP56DSPContext *s, enum CodecID codec) +{ + if (codec == CODEC_ID_VP5) { + s->edge_filter_hor = vp5_edge_filter_hor; + s->edge_filter_ver = vp5_edge_filter_ver; + } else { + s->edge_filter_hor = vp6_edge_filter_hor; + s->edge_filter_ver = vp6_edge_filter_ver; + } + + if (ARCH_ARM) ff_vp56dsp_init_arm(s, codec); +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vp56dsp.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/vp56dsp.h new file mode 100644 index 0000000000..2d6941fa29 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vp56dsp.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2010 Mans Rullgard + * + * 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_VP56DSP_H +#define AVCODEC_VP56DSP_H + +#include + +typedef struct VP56DSPContext { + void (*edge_filter_hor)(uint8_t *yuv, int stride, int t); + void (*edge_filter_ver)(uint8_t *yuv, int stride, int t); +} VP56DSPContext; + +void ff_vp56dsp_init(VP56DSPContext *s, enum CodecID codec); +void ff_vp56dsp_init_arm(VP56DSPContext *s, enum CodecID codec); + +#endif /* AVCODEC_VP56DSP_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vp5data.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/vp5data.h index ae04559a4a..5c2d46cde5 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vp5data.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vp5data.h @@ -1,5 +1,5 @@ /** - * @file libavcodec/vp5data.h + * @file * VP5 compatible video decoder * * Copyright (C) 2006 Aurelien Jacobs diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vp6.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/vp6.c index de98e61e6e..58c31f965b 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vp6.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vp6.c @@ -1,5 +1,5 @@ /** - * @file libavcodec/vp6.c + * @file * VP6 compatible video decoder * * Copyright (C) 2006 Aurelien Jacobs @@ -227,6 +227,7 @@ static void vp6_build_huff_tree(VP56Context *s, uint8_t coeff_model[], nodes[map[2*i+1]].count = b + !b; } + 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); @@ -480,19 +481,6 @@ static void vp6_parse_coeff(VP56Context *s) } } -static int vp6_adjust(int v, int t) -{ - int V = v, s = v >> 31; - V ^= s; - V -= s; - if (V-t-1 >= (unsigned)(t-1)) - return v; - V = 2*t - V; - V += s; - V ^= s; - return V; -} - static int vp6_block_variance(uint8_t *src, int stride) { int sum = 0, square_sum = 0; @@ -591,7 +579,6 @@ static av_cold int vp6_decode_init(AVCodecContext *avctx) avctx->codec->id == CODEC_ID_VP6A); s->vp56_coord_div = vp6_coord_div; s->parse_vector_adjustment = vp6_parse_vector_adjustment; - s->adjust = vp6_adjust; s->filter = vp6_filter; s->default_models_init = vp6_default_models_init; s->parse_vector_models = vp6_parse_vector_models; @@ -601,14 +588,31 @@ static av_cold int vp6_decode_init(AVCodecContext *avctx) return 0; } +static av_cold int vp6_decode_free(AVCodecContext *avctx) +{ + VP56Context *s = avctx->priv_data; + int pt, ct, cg; + + vp56_free(avctx); + + for (pt=0; pt<2; pt++) { + free_vlc(&s->dccv_vlc[pt]); + free_vlc(&s->runv_vlc[pt]); + for (ct=0; ct<3; ct++) + for (cg=0; cg<6; cg++) + free_vlc(&s->ract_vlc[pt][ct][cg]); + } + return 0; +} + AVCodec vp6_decoder = { "vp6", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_VP6, sizeof(VP56Context), vp6_decode_init, NULL, - vp56_free, + vp6_decode_free, vp56_decode_frame, CODEC_CAP_DR1, .long_name = NULL_IF_CONFIG_SMALL("On2 VP6"), @@ -617,12 +621,12 @@ AVCodec vp6_decoder = { /* flash version, not flipped upside-down */ AVCodec vp6f_decoder = { "vp6f", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_VP6F, sizeof(VP56Context), vp6_decode_init, NULL, - vp56_free, + vp6_decode_free, vp56_decode_frame, CODEC_CAP_DR1, .long_name = NULL_IF_CONFIG_SMALL("On2 VP6 (Flash version)"), @@ -631,12 +635,12 @@ AVCodec vp6f_decoder = { /* flash version, not flipped upside-down, with alpha channel */ AVCodec vp6a_decoder = { "vp6a", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_VP6A, sizeof(VP56Context), vp6_decode_init, NULL, - vp56_free, + vp6_decode_free, vp56_decode_frame, CODEC_CAP_DR1, .long_name = NULL_IF_CONFIG_SMALL("On2 VP6 (Flash version, with alpha channel)"), diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vp6data.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/vp6data.h index 9bf410b4b5..1cfdbe7bea 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vp6data.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vp6data.h @@ -1,5 +1,5 @@ /** - * @file libavcodec/vp6data.h + * @file * VP6 compatible video decoder * * Copyright (C) 2006 Aurelien Jacobs diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vp6dsp.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/vp6dsp.c index f4b7670d78..69a11ee188 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vp6dsp.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vp6dsp.c @@ -1,5 +1,5 @@ /** - * @file libavcodec/vp6dsp.c + * @file * VP6 DSP-oriented functions * * Copyright (C) 2006 Aurelien Jacobs diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/vqavideo.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/vqavideo.c index aba886489e..a1698394ef 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/vqavideo.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/vqavideo.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/vqavideo.c + * @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 @@ -610,7 +610,7 @@ static av_cold int vqa_decode_end(AVCodecContext *avctx) AVCodec vqa_decoder = { "vqavideo", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_WS_VQA, sizeof(VqaContext), vqa_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/w32thread.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/w32thread.c index a88e3e0717..f7a1430647 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/w32thread.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/w32thread.c @@ -29,10 +29,15 @@ 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 ret; + int argsize; + int *jobnr; + int *ret; + int threadnr; }ThreadContext; @@ -40,13 +45,22 @@ 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) - c->ret= c->func(c->avctx, c->arg); + ret= c->func(c->avctx, (uint8_t *)c->arg + jobnr*c->argsize); else - return 0; + 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); } @@ -65,41 +79,51 @@ void avcodec_thread_free(AVCodecContext *s){ for(i=0; ithread_count; i++){ c[i].func= NULL; - ReleaseSemaphore(c[i].work_sem, 1, 0); + c[i].func2= NULL; + } + ReleaseSemaphore(c[0].work_sem, s->thread_count, 0); + for(i=0; ithread_count; i++){ WaitForSingleObject(c[i].thread, INFINITE); - if(c[i].work_sem) CloseHandle(c[i].work_sem); - if(c[i].done_sem) CloseHandle(c[i].done_sem); 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); } -int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size){ +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); - assert(count <= s->thread_count); /* note, we can be certain that this is not called with the same AVCodecContext by different threads at the same time */ - for(i=0; ithread_count; i++){ + c[i].arg= arg; + c[i].argsize= size; c[i].func= func; - c[i].ret= 12345; - - ReleaseSemaphore(c[i].work_sem, 1, 0); + c[i].ret= ret; + c[i].jobnr = &jobnr; } - for(i=0; ithread_opaque; + int i; + for(i=0; ithread_count; i++) + c[i].func2 = func; + avcodec_thread_execute(s, NULL, arg, ret, count, 0); +} + int avcodec_thread_init(AVCodecContext *s, int thread_count){ int i; ThreadContext *c; @@ -107,18 +131,26 @@ int avcodec_thread_init(AVCodecContext *s, int thread_count){ s->thread_count= thread_count; + if (thread_count <= 1) + return 0; + assert(!s->thread_opaque); c= av_mallocz(sizeof(ThreadContext)*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; ithread_count, NULL))) - goto fail; - if(!(c[i].done_sem = CreateSemaphore(NULL, 0, s->thread_count, NULL))) - goto fail; + 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 ); @@ -127,6 +159,7 @@ int avcodec_thread_init(AVCodecContext *s, int thread_count){ //printf("init done\n"); fflush(stdout); s->execute= avcodec_thread_execute; + s->execute2= avcodec_thread_execute2; return 0; fail: diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/wavpack.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/wavpack.c index 10254f08de..7358d29735 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/wavpack.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/wavpack.c @@ -24,7 +24,7 @@ #include "unary.h" /** - * @file libavcodec/wavpack.c + * @file * WavPack lossless audio decoder */ @@ -67,6 +67,13 @@ enum WP_ID{ WP_ID_CHANINFO }; +typedef struct SavedContext { + int offset; + int size; + int bits_used; + uint32_t crc; +} SavedContext; + #define MAX_TERMS 16 typedef struct Decorr { @@ -107,6 +114,10 @@ typedef struct WavpackContext { int float_shift; int float_max_exp; WvChannel ch[2]; + int samples_left; + int max_samples; + int pos; + SavedContext sc, extra_sc; } WavpackContext; // exponent table copied from WavPack source @@ -378,7 +389,7 @@ static float wv_get_value_float(WavpackContext *s, uint32_t *crc, int S) if(s->got_extra_bits){ const int max_bits = 1 + 23 + 8 + 1; - const int left_bits = s->gb_extra_bits.size_in_bits - get_bits_count(&s->gb_extra_bits); + const int left_bits = get_bits_left(&s->gb_extra_bits); if(left_bits + 8 * FF_INPUT_BUFFER_PADDING_SIZE < max_bits) return 0.0; @@ -439,19 +450,26 @@ static float wv_get_value_float(WavpackContext *s, uint32_t *crc, int S) return value.f; } +static void wv_reset_saved_context(WavpackContext *s) +{ + s->pos = 0; + s->sc.crc = s->extra_sc.crc = 0xFFFFFFFF; +} + static inline int wv_unpack_stereo(WavpackContext *s, GetBitContext *gb, void *dst, const int type) { int i, j, count = 0; int last, t; int A, B, L, L2, R, R2; - int pos = 0; - uint32_t crc = 0xFFFFFFFF; - uint32_t crc_extra_bits = 0xFFFFFFFF; + int pos = s->pos; + uint32_t crc = s->sc.crc; + uint32_t crc_extra_bits = s->extra_sc.crc; int16_t *dst16 = dst; int32_t *dst32 = dst; float *dstfl = dst; - s->one = s->zero = s->zeroes = 0; + if(s->samples_left == s->samples) + s->one = s->zero = s->zeroes = 0; do{ L = wv_get_value(s, gb, 0, &last); if(last) break; @@ -539,15 +557,27 @@ static inline int wv_unpack_stereo(WavpackContext *s, GetBitContext *gb, void *d *dst16++ = wv_get_value_integer(s, &crc_extra_bits, R); } count++; - }while(!last && count < s->samples); + }while(!last && count < s->max_samples); - if(crc != s->CRC){ - av_log(s->avctx, AV_LOG_ERROR, "CRC error\n"); - return -1; - } - if(s->got_extra_bits && crc_extra_bits != s->crc_extra_bits){ - av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n"); - return -1; + s->samples_left -= count; + if(!s->samples_left){ + if(crc != s->CRC){ + av_log(s->avctx, AV_LOG_ERROR, "CRC error\n"); + return -1; + } + if(s->got_extra_bits && crc_extra_bits != s->crc_extra_bits){ + 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; + s->sc.bits_used = get_bits_count(&s->gb); + if(s->got_extra_bits){ + s->extra_sc.crc = crc_extra_bits; + s->extra_sc.bits_used = get_bits_count(&s->gb_extra_bits); + } } return count * 2; } @@ -557,14 +587,15 @@ static inline int wv_unpack_mono(WavpackContext *s, GetBitContext *gb, void *dst int i, j, count = 0; int last, t; int A, S, T; - int pos = 0; - uint32_t crc = 0xFFFFFFFF; - uint32_t crc_extra_bits = 0xFFFFFFFF; + int pos = s->pos; + uint32_t crc = s->sc.crc; + uint32_t crc_extra_bits = s->extra_sc.crc; int16_t *dst16 = dst; int32_t *dst32 = dst; float *dstfl = dst; - s->one = s->zero = s->zeroes = 0; + if(s->samples_left == s->samples) + s->one = s->zero = s->zeroes = 0; do{ T = wv_get_value(s, gb, 0, &last); S = 0; @@ -601,13 +632,25 @@ static inline int wv_unpack_mono(WavpackContext *s, GetBitContext *gb, void *dst count++; }while(!last && count < s->samples); - if(crc != s->CRC){ - av_log(s->avctx, AV_LOG_ERROR, "CRC error\n"); - return -1; - } - if(s->got_extra_bits && crc_extra_bits != s->crc_extra_bits){ - av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n"); - return -1; + s->samples_left -= count; + if(!s->samples_left){ + if(crc != s->CRC){ + av_log(s->avctx, AV_LOG_ERROR, "CRC error\n"); + return -1; + } + if(s->got_extra_bits && crc_extra_bits != s->crc_extra_bits){ + 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; + s->sc.bits_used = get_bits_count(&s->gb); + if(s->got_extra_bits){ + s->extra_sc.crc = crc_extra_bits; + s->extra_sc.bits_used = get_bits_count(&s->gb_extra_bits); + } } return count; } @@ -624,6 +667,8 @@ static av_cold int wavpack_decode_init(AVCodecContext *avctx) avctx->sample_fmt = SAMPLE_FMT_S32; avctx->channel_layout = (avctx->channels==2) ? CH_LAYOUT_STEREO : CH_LAYOUT_MONO; + wv_reset_saved_context(s); + return 0; } @@ -647,11 +692,13 @@ static int wavpack_decode_frame(AVCodecContext *avctx, return 0; } - memset(s->decorr, 0, MAX_TERMS * sizeof(Decorr)); - memset(s->ch, 0, sizeof(s->ch)); - s->extra_bits = 0; - s->and = s->or = s->shift = 0; - s->got_extra_bits = 0; + if(!s->samples_left){ + memset(s->decorr, 0, MAX_TERMS * sizeof(Decorr)); + memset(s->ch, 0, sizeof(s->ch)); + s->extra_bits = 0; + s->and = s->or = s->shift = 0; + s->got_extra_bits = 0; + } s->samples = AV_RL32(buf); buf += 4; if(!s->samples){ @@ -676,10 +723,11 @@ static int wavpack_decode_frame(AVCodecContext *avctx, s->post_shift = 8 * (bpp-1-(s->frame_flags&0x03)) + ((s->frame_flags >> 13) & 0x1f); s->CRC = AV_RL32(buf); buf += 4; - /* should not happen but who knows */ - if(s->samples * bpp * avctx->channels > *data_size){ - av_log(avctx, AV_LOG_ERROR, "Packet size is too big to be handled in lavc!\n"); - return -1; + s->max_samples = *data_size / (bpp * avctx->channels); + s->max_samples = FFMIN(s->max_samples, s->samples); + if(s->samples_left > 0){ + s->max_samples = FFMIN(s->max_samples, s->samples_left); + buf = buf_end; } // parse metadata blocks @@ -847,6 +895,8 @@ static int wavpack_decode_frame(AVCodecContext *avctx, got_float = 1; break; case WP_ID_DATA: + s->sc.offset = buf - avpkt->data; + s->sc.size = size * 8; init_get_bits(&s->gb, buf, size * 8); s->data_size = size * 8; buf += size; @@ -858,6 +908,8 @@ static int wavpack_decode_frame(AVCodecContext *avctx, buf += size; continue; } + s->extra_sc.offset = buf - avpkt->data; + s->extra_sc.size = size * 8; init_get_bits(&s->gb_extra_bits, buf, size * 8); s->crc_extra_bits = get_bits_long(&s->gb_extra_bits, 32); buf += size; @@ -868,40 +920,51 @@ static int wavpack_decode_frame(AVCodecContext *avctx, } if(id & WP_IDF_ODD) buf++; } - if(!got_terms){ - av_log(avctx, AV_LOG_ERROR, "No block with decorrelation terms\n"); - return -1; - } - if(!got_weights){ - av_log(avctx, AV_LOG_ERROR, "No block with decorrelation weights\n"); - return -1; - } - if(!got_samples){ - av_log(avctx, AV_LOG_ERROR, "No block with decorrelation samples\n"); - return -1; - } - if(!got_entropy){ - av_log(avctx, AV_LOG_ERROR, "No block with entropy info\n"); - return -1; - } - if(s->hybrid && !got_hybrid){ - av_log(avctx, AV_LOG_ERROR, "Hybrid config not found\n"); - return -1; - } - if(!got_bs){ - av_log(avctx, AV_LOG_ERROR, "Packed samples not found\n"); - return -1; - } - if(!got_float && avctx->sample_fmt == SAMPLE_FMT_FLT){ - av_log(avctx, AV_LOG_ERROR, "Float information not found\n"); - return -1; - } - if(s->got_extra_bits && avctx->sample_fmt != SAMPLE_FMT_FLT){ - const int size = s->gb_extra_bits.size_in_bits - get_bits_count(&s->gb_extra_bits); - const int wanted = s->samples * s->extra_bits << s->stereo_in; - if(size < wanted){ - av_log(avctx, AV_LOG_ERROR, "Too small EXTRABITS\n"); - s->got_extra_bits = 0; + if(!s->samples_left){ + if(!got_terms){ + av_log(avctx, AV_LOG_ERROR, "No block with decorrelation terms\n"); + return -1; + } + if(!got_weights){ + av_log(avctx, AV_LOG_ERROR, "No block with decorrelation weights\n"); + return -1; + } + if(!got_samples){ + av_log(avctx, AV_LOG_ERROR, "No block with decorrelation samples\n"); + return -1; + } + if(!got_entropy){ + av_log(avctx, AV_LOG_ERROR, "No block with entropy info\n"); + return -1; + } + if(s->hybrid && !got_hybrid){ + av_log(avctx, AV_LOG_ERROR, "Hybrid config not found\n"); + return -1; + } + if(!got_bs){ + av_log(avctx, AV_LOG_ERROR, "Packed samples not found\n"); + return -1; + } + if(!got_float && avctx->sample_fmt == SAMPLE_FMT_FLT){ + av_log(avctx, AV_LOG_ERROR, "Float information not found\n"); + return -1; + } + if(s->got_extra_bits && avctx->sample_fmt != SAMPLE_FMT_FLT){ + const int size = get_bits_left(&s->gb_extra_bits); + const int wanted = s->samples * s->extra_bits << s->stereo_in; + if(size < wanted){ + av_log(avctx, AV_LOG_ERROR, "Too small EXTRABITS\n"); + s->got_extra_bits = 0; + } + } + s->samples_left = s->samples; + }else{ + init_get_bits(&s->gb, avpkt->data + s->sc.offset, s->sc.size); + skip_bits_long(&s->gb, s->sc.bits_used); + if(s->got_extra_bits){ + init_get_bits(&s->gb_extra_bits, avpkt->data + s->extra_sc.offset, + s->extra_sc.size); + skip_bits_long(&s->gb_extra_bits, s->extra_sc.bits_used); } } @@ -952,17 +1015,18 @@ static int wavpack_decode_frame(AVCodecContext *avctx, } *data_size = samplecount * bpp; - return buf_size; + return s->samples_left > 0 ? 0 : buf_size; } AVCodec wavpack_decoder = { "wavpack", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_WAVPACK, sizeof(WavpackContext), wavpack_decode_init, NULL, NULL, wavpack_decode_frame, + .capabilities = CODEC_CAP_SUBFRAMES, .long_name = NULL_IF_CONFIG_SMALL("WavPack"), }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/wma.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/wma.c index 4fc492243f..65780459aa 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/wma.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/wma.c @@ -29,7 +29,7 @@ /* XXX: use same run/length optimization as mpeg decoders */ //FIXME maybe split decode / encode or pass flag static void init_coef_vlc(VLC *vlc, uint16_t **prun_table, - uint16_t **plevel_table, uint16_t **pint_table, + float **plevel_table, uint16_t **pint_table, const CoefVLCTable *vlc_table) { int n = vlc_table->n; @@ -37,12 +37,14 @@ static void init_coef_vlc(VLC *vlc, uint16_t **prun_table, const uint32_t *table_codes = vlc_table->huffcodes; const uint16_t *levels_table = vlc_table->levels; uint16_t *run_table, *level_table, *int_table; + float *flevel_table; int i, l, j, k, level; init_vlc(vlc, VLCBITS, n, table_bits, 1, 1, table_codes, 4, 4, 0); run_table = av_malloc(n * sizeof(uint16_t)); level_table = av_malloc(n * sizeof(uint16_t)); + flevel_table= av_malloc(n * sizeof(*flevel_table)); int_table = av_malloc(n * sizeof(uint16_t)); i = 2; level = 1; @@ -53,13 +55,15 @@ static void init_coef_vlc(VLC *vlc, uint16_t **prun_table, for (j = 0; j < l; j++) { run_table[i] = j; level_table[i] = level; + flevel_table[i]= level; i++; } level++; } *prun_table = run_table; - *plevel_table = level_table; + *plevel_table = flevel_table; *pint_table = int_table; + av_free(level_table); } /** @@ -238,7 +242,7 @@ int ff_wma_init(AVCodecContext *avctx, int flags2) if (s->version == 1) { lpos = 0; for (i = 0; i < 25; i++) { - a = wma_critical_freqs[i]; + a = ff_wma_critical_freqs[i]; b = s->sample_rate; pos = ((block_len * 2 * a) + (b >> 1)) / b; if (pos > block_len) @@ -273,7 +277,7 @@ int ff_wma_init(AVCodecContext *avctx, int flags2) j = 0; lpos = 0; for (i = 0; i < 25; i++) { - a = wma_critical_freqs[i]; + a = ff_wma_critical_freqs[i]; b = s->sample_rate; pos = ((block_len * 2 * a) + (b << 1)) / (4 * b); pos <<= 2; @@ -339,10 +343,8 @@ int ff_wma_init(AVCodecContext *avctx, int flags2) /* init MDCT windows : simple sinus window */ for (i = 0; i < s->nb_block_sizes; i++) { - int n; - n = 1 << (s->frame_len_bits - i); - ff_sine_window_init(ff_sine_windows[s->frame_len_bits - i - 7], n); - s->windows[i] = ff_sine_windows[s->frame_len_bits - i - 7]; + ff_init_ff_sine_windows(s->frame_len_bits - i); + s->windows[i] = ff_sine_windows[s->frame_len_bits - i]; } s->reset_block_lengths = 1; @@ -465,19 +467,22 @@ unsigned int ff_wma_get_large_val(GetBitContext* gb) */ int ff_wma_run_level_decode(AVCodecContext* avctx, GetBitContext* gb, VLC *vlc, - const uint16_t *level_table, const uint16_t *run_table, + const float *level_table, const uint16_t *run_table, int version, WMACoef *ptr, int offset, int num_coefs, int block_len, int frame_len_bits, int coef_nb_bits) { int code, level, sign; + const uint32_t *ilvl = (const uint32_t*)level_table; + uint32_t *iptr = (uint32_t*)ptr; const unsigned int coef_mask = block_len - 1; for (; offset < num_coefs; offset++) { code = get_vlc2(gb, vlc->table, VLCBITS, VLCMAX); if (code > 1) { /** normal code */ offset += run_table[code]; - level = level_table[code]; + sign = get_bits1(gb) - 1; + iptr[offset & coef_mask] = ilvl[code] ^ sign<<31; } else if (code == 1) { /** EOB */ break; @@ -503,9 +508,9 @@ int ff_wma_run_level_decode(AVCodecContext* avctx, GetBitContext* gb, offset += get_bits(gb, 2) + 1; } } + sign = get_bits1(gb) - 1; + ptr[offset & coef_mask] = (level^sign) - sign; } - sign = get_bits1(gb) - 1; - ptr[offset & coef_mask] = (level^sign) - sign; } /** NOTE: EOB can be omitted */ if (offset > num_coefs) { diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/wma.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/wma.h index a207dfc956..11274ad970 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/wma.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/wma.h @@ -25,6 +25,7 @@ #include "get_bits.h" #include "put_bits.h" #include "dsputil.h" +#include "fft.h" /* size of blocks */ #define BLOCK_MIN_BITS 7 @@ -93,7 +94,7 @@ typedef struct WMACodecContext { //FIXME the following 3 tables should be shared between decoders VLC coef_vlc[2]; uint16_t *run_table[2]; - uint16_t *level_table[2]; + float *level_table[2]; uint16_t *int_table[2]; const CoefVLCTable *coef_vlcs[2]; /* frame info */ @@ -111,15 +112,15 @@ typedef struct WMACodecContext { uint8_t ms_stereo; ///< true if mid/side stereo mode uint8_t channel_coded[MAX_CHANNELS]; ///< true if channel is coded int exponents_bsize[MAX_CHANNELS]; ///< log2 ratio frame/exp. length - DECLARE_ALIGNED_16(float, exponents[MAX_CHANNELS][BLOCK_MAX_SIZE]); + DECLARE_ALIGNED(16, float, exponents)[MAX_CHANNELS][BLOCK_MAX_SIZE]; float max_exponent[MAX_CHANNELS]; WMACoef coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE]; - DECLARE_ALIGNED_16(float, coefs[MAX_CHANNELS][BLOCK_MAX_SIZE]); - DECLARE_ALIGNED_16(FFTSample, output[BLOCK_MAX_SIZE * 2]); - MDCTContext mdct_ctx[BLOCK_NB_SIZES]; + DECLARE_ALIGNED(16, float, coefs)[MAX_CHANNELS][BLOCK_MAX_SIZE]; + DECLARE_ALIGNED(16, FFTSample, output)[BLOCK_MAX_SIZE * 2]; + FFTContext mdct_ctx[BLOCK_NB_SIZES]; float *windows[BLOCK_NB_SIZES]; /* output buffer for one frame and the last for IMDCT windowing */ - DECLARE_ALIGNED_16(float, frame_out[MAX_CHANNELS][BLOCK_MAX_SIZE * 2]); + DECLARE_ALIGNED(16, float, frame_out)[MAX_CHANNELS][BLOCK_MAX_SIZE * 2]; /* last frame info */ uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE + 4]; /* padding added */ int last_bitoffset; @@ -139,11 +140,12 @@ typedef struct WMACodecContext { #endif } WMACodecContext; +extern const uint16_t ff_wma_critical_freqs[25]; extern const uint16_t ff_wma_hgain_huffcodes[37]; extern const uint8_t ff_wma_hgain_huffbits[37]; extern const float ff_wma_lsp_codebook[NB_LSP_COEFS][16]; -extern const uint32_t ff_wma_scale_huffcodes[121]; -extern const uint8_t ff_wma_scale_huffbits[121]; +extern const uint32_t ff_aac_scalefactor_code[121]; +extern const uint8_t ff_aac_scalefactor_bits[121]; int av_cold ff_wma_get_frame_len_bits(int sample_rate, int version, unsigned int decode_flags); @@ -153,7 +155,7 @@ int ff_wma_end(AVCodecContext *avctx); unsigned int ff_wma_get_large_val(GetBitContext* gb); int ff_wma_run_level_decode(AVCodecContext* avctx, GetBitContext* gb, VLC *vlc, - const uint16_t *level_table, const uint16_t *run_table, + const float *level_table, const uint16_t *run_table, int version, WMACoef *ptr, int offset, int num_coefs, int block_len, int frame_len_bits, int coef_nb_bits); diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/wmadata.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/wmadata.h index 0a26ea4802..381f182fa0 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/wmadata.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/wmadata.h @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/wmadata.h + * @file * Various WMA tables. */ @@ -30,7 +30,7 @@ #include #include "wma.h" -static const uint16_t wma_critical_freqs[25] = { +const uint16_t ff_wma_critical_freqs[25] = { 100, 200, 300, 400, 510, 630, 770, 920, 1080, 1270, 1480, 1720, 2000, 2320, 2700, 3150, 3700, 4400, 5300, 6400, 7700, 9500, 12000, 15500, @@ -92,44 +92,6 @@ const float ff_wma_lsp_codebook[NB_LSP_COEFS][16] = { { -1.56144989, -1.65944032, -1.72689685, -1.77857740, -1.82203011, -1.86220079, -1.90283983, -1.94820479, }, }; -const uint32_t ff_wma_scale_huffcodes[121] = { - 0x3ffe8, 0x3ffe6, 0x3ffe7, 0x3ffe5, 0x7fff5, 0x7fff1, 0x7ffed, 0x7fff6, - 0x7ffee, 0x7ffef, 0x7fff0, 0x7fffc, 0x7fffd, 0x7ffff, 0x7fffe, 0x7fff7, - 0x7fff8, 0x7fffb, 0x7fff9, 0x3ffe4, 0x7fffa, 0x3ffe3, 0x1ffef, 0x1fff0, - 0x0fff5, 0x1ffee, 0x0fff2, 0x0fff3, 0x0fff4, 0x0fff1, 0x07ff6, 0x07ff7, - 0x03ff9, 0x03ff5, 0x03ff7, 0x03ff3, 0x03ff6, 0x03ff2, 0x01ff7, 0x01ff5, - 0x00ff9, 0x00ff7, 0x00ff6, 0x007f9, 0x00ff4, 0x007f8, 0x003f9, 0x003f7, - 0x003f5, 0x001f8, 0x001f7, 0x000fa, 0x000f8, 0x000f6, 0x00079, 0x0003a, - 0x00038, 0x0001a, 0x0000b, 0x00004, 0x00000, 0x0000a, 0x0000c, 0x0001b, - 0x00039, 0x0003b, 0x00078, 0x0007a, 0x000f7, 0x000f9, 0x001f6, 0x001f9, - 0x003f4, 0x003f6, 0x003f8, 0x007f5, 0x007f4, 0x007f6, 0x007f7, 0x00ff5, - 0x00ff8, 0x01ff4, 0x01ff6, 0x01ff8, 0x03ff8, 0x03ff4, 0x0fff0, 0x07ff4, - 0x0fff6, 0x07ff5, 0x3ffe2, 0x7ffd9, 0x7ffda, 0x7ffdb, 0x7ffdc, 0x7ffdd, - 0x7ffde, 0x7ffd8, 0x7ffd2, 0x7ffd3, 0x7ffd4, 0x7ffd5, 0x7ffd6, 0x7fff2, - 0x7ffdf, 0x7ffe7, 0x7ffe8, 0x7ffe9, 0x7ffea, 0x7ffeb, 0x7ffe6, 0x7ffe0, - 0x7ffe1, 0x7ffe2, 0x7ffe3, 0x7ffe4, 0x7ffe5, 0x7ffd7, 0x7ffec, 0x7fff4, - 0x7fff3, -}; - -const uint8_t ff_wma_scale_huffbits[121] = { - 18, 18, 18, 18, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 18, 19, 18, 17, 17, - 16, 17, 16, 16, 16, 16, 15, 15, - 14, 14, 14, 14, 14, 14, 13, 13, - 12, 12, 12, 11, 12, 11, 10, 10, - 10, 9, 9, 8, 8, 8, 7, 6, - 6, 5, 4, 3, 1, 4, 4, 5, - 6, 6, 7, 7, 8, 8, 9, 9, - 10, 10, 10, 11, 11, 11, 11, 12, - 12, 13, 13, 13, 14, 14, 16, 15, - 16, 15, 18, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, - 19, -}; - static const uint32_t coef0_huffcodes[666] = { 0x00258, 0x0003d, 0x00000, 0x00005, 0x00008, 0x00008, 0x0000c, 0x0001b, 0x0001f, 0x00015, 0x00024, 0x00032, 0x0003a, 0x00026, 0x0002c, 0x0002f, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/wmadec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/wmadec.c index 7a65003457..a24256d457 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/wmadec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/wmadec.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/wmadec.c + * @file * WMA compatible decoder. * This decoder handles Microsoft Windows Media Audio data, versions 1 & 2. * WMA v1 is identified by audio format 0x160 in Microsoft media files @@ -82,20 +82,17 @@ static void dump_floats(WMACodecContext *s, const char *name, int prec, const fl static int wma_decode_init(AVCodecContext * avctx) { WMACodecContext *s = avctx->priv_data; - int i, flags1, flags2; + int i, flags2; uint8_t *extradata; s->avctx = avctx; /* extract flag infos */ - flags1 = 0; flags2 = 0; extradata = avctx->extradata; if (avctx->codec->id == CODEC_ID_WMAV1 && avctx->extradata_size >= 4) { - flags1 = AV_RL16(extradata); flags2 = AV_RL16(extradata+2); } else if (avctx->codec->id == CODEC_ID_WMAV2 && avctx->extradata_size >= 6) { - flags1 = AV_RL32(extradata); flags2 = AV_RL16(extradata+4); } // for(i=0; iextradata_size; i++) @@ -119,9 +116,9 @@ static int wma_decode_init(AVCodecContext * avctx) } if (s->use_exp_vlc) { - init_vlc(&s->exp_vlc, EXPVLCBITS, sizeof(ff_wma_scale_huffbits), //FIXME move out of context - ff_wma_scale_huffbits, 1, 1, - ff_wma_scale_huffcodes, 4, 4, 0); + init_vlc(&s->exp_vlc, EXPVLCBITS, sizeof(ff_aac_scalefactor_bits), //FIXME move out of context + ff_aac_scalefactor_bits, 1, 1, + ff_aac_scalefactor_code, 4, 4, 0); } else { wma_lsp_to_curve_init(s, s->frame_len); } @@ -243,46 +240,143 @@ static void decode_exp_lsp(WMACodecContext *s, int ch) s->block_len, lsp_coefs); } +/** pow(10, i / 16.0) for i in -60..95 */ +static const float pow_tab[] = { + 1.7782794100389e-04, 2.0535250264571e-04, + 2.3713737056617e-04, 2.7384196342644e-04, + 3.1622776601684e-04, 3.6517412725484e-04, + 4.2169650342858e-04, 4.8696752516586e-04, + 5.6234132519035e-04, 6.4938163157621e-04, + 7.4989420933246e-04, 8.6596432336006e-04, + 1.0000000000000e-03, 1.1547819846895e-03, + 1.3335214321633e-03, 1.5399265260595e-03, + 1.7782794100389e-03, 2.0535250264571e-03, + 2.3713737056617e-03, 2.7384196342644e-03, + 3.1622776601684e-03, 3.6517412725484e-03, + 4.2169650342858e-03, 4.8696752516586e-03, + 5.6234132519035e-03, 6.4938163157621e-03, + 7.4989420933246e-03, 8.6596432336006e-03, + 1.0000000000000e-02, 1.1547819846895e-02, + 1.3335214321633e-02, 1.5399265260595e-02, + 1.7782794100389e-02, 2.0535250264571e-02, + 2.3713737056617e-02, 2.7384196342644e-02, + 3.1622776601684e-02, 3.6517412725484e-02, + 4.2169650342858e-02, 4.8696752516586e-02, + 5.6234132519035e-02, 6.4938163157621e-02, + 7.4989420933246e-02, 8.6596432336007e-02, + 1.0000000000000e-01, 1.1547819846895e-01, + 1.3335214321633e-01, 1.5399265260595e-01, + 1.7782794100389e-01, 2.0535250264571e-01, + 2.3713737056617e-01, 2.7384196342644e-01, + 3.1622776601684e-01, 3.6517412725484e-01, + 4.2169650342858e-01, 4.8696752516586e-01, + 5.6234132519035e-01, 6.4938163157621e-01, + 7.4989420933246e-01, 8.6596432336007e-01, + 1.0000000000000e+00, 1.1547819846895e+00, + 1.3335214321633e+00, 1.5399265260595e+00, + 1.7782794100389e+00, 2.0535250264571e+00, + 2.3713737056617e+00, 2.7384196342644e+00, + 3.1622776601684e+00, 3.6517412725484e+00, + 4.2169650342858e+00, 4.8696752516586e+00, + 5.6234132519035e+00, 6.4938163157621e+00, + 7.4989420933246e+00, 8.6596432336007e+00, + 1.0000000000000e+01, 1.1547819846895e+01, + 1.3335214321633e+01, 1.5399265260595e+01, + 1.7782794100389e+01, 2.0535250264571e+01, + 2.3713737056617e+01, 2.7384196342644e+01, + 3.1622776601684e+01, 3.6517412725484e+01, + 4.2169650342858e+01, 4.8696752516586e+01, + 5.6234132519035e+01, 6.4938163157621e+01, + 7.4989420933246e+01, 8.6596432336007e+01, + 1.0000000000000e+02, 1.1547819846895e+02, + 1.3335214321633e+02, 1.5399265260595e+02, + 1.7782794100389e+02, 2.0535250264571e+02, + 2.3713737056617e+02, 2.7384196342644e+02, + 3.1622776601684e+02, 3.6517412725484e+02, + 4.2169650342858e+02, 4.8696752516586e+02, + 5.6234132519035e+02, 6.4938163157621e+02, + 7.4989420933246e+02, 8.6596432336007e+02, + 1.0000000000000e+03, 1.1547819846895e+03, + 1.3335214321633e+03, 1.5399265260595e+03, + 1.7782794100389e+03, 2.0535250264571e+03, + 2.3713737056617e+03, 2.7384196342644e+03, + 3.1622776601684e+03, 3.6517412725484e+03, + 4.2169650342858e+03, 4.8696752516586e+03, + 5.6234132519035e+03, 6.4938163157621e+03, + 7.4989420933246e+03, 8.6596432336007e+03, + 1.0000000000000e+04, 1.1547819846895e+04, + 1.3335214321633e+04, 1.5399265260595e+04, + 1.7782794100389e+04, 2.0535250264571e+04, + 2.3713737056617e+04, 2.7384196342644e+04, + 3.1622776601684e+04, 3.6517412725484e+04, + 4.2169650342858e+04, 4.8696752516586e+04, + 5.6234132519035e+04, 6.4938163157621e+04, + 7.4989420933246e+04, 8.6596432336007e+04, + 1.0000000000000e+05, 1.1547819846895e+05, + 1.3335214321633e+05, 1.5399265260595e+05, + 1.7782794100389e+05, 2.0535250264571e+05, + 2.3713737056617e+05, 2.7384196342644e+05, + 3.1622776601684e+05, 3.6517412725484e+05, + 4.2169650342858e+05, 4.8696752516586e+05, + 5.6234132519035e+05, 6.4938163157621e+05, + 7.4989420933246e+05, 8.6596432336007e+05, +}; + /** * decode exponents coded with VLC codes */ static int decode_exp_vlc(WMACodecContext *s, int ch) { int last_exp, n, code; - const uint16_t *ptr, *band_ptr; - float v, *q, max_scale, *q_end; + const uint16_t *ptr; + float v, max_scale; + uint32_t *q, *q_end, iv; + const float *ptab = pow_tab + 60; + const uint32_t *iptab = (const uint32_t*)ptab; - band_ptr = s->exponent_bands[s->frame_len_bits - s->block_len_bits]; - ptr = band_ptr; - q = s->exponents[ch]; + ptr = s->exponent_bands[s->frame_len_bits - s->block_len_bits]; + q = (uint32_t *)s->exponents[ch]; q_end = q + s->block_len; max_scale = 0; if (s->version == 1) { last_exp = get_bits(&s->gb, 5) + 10; - /* XXX: use a table */ - v = pow(10, last_exp * (1.0 / 16.0)); + v = ptab[last_exp]; + iv = iptab[last_exp]; max_scale = v; n = *ptr++; - do { - *q++ = v; - } while (--n); + switch (n & 3) do { + case 0: *q++ = iv; + case 3: *q++ = iv; + case 2: *q++ = iv; + case 1: *q++ = iv; + } while ((n -= 4) > 0); }else last_exp = 36; while (q < q_end) { code = get_vlc2(&s->gb, s->exp_vlc.table, EXPVLCBITS, EXPMAX); - if (code < 0) + if (code < 0){ + av_log(s->avctx, AV_LOG_ERROR, "Exponent vlc invalid\n"); return -1; + } /* NOTE: this offset is the same as MPEG4 AAC ! */ last_exp += code - 60; - /* XXX: use a table */ - v = pow(10, last_exp * (1.0 / 16.0)); + if ((unsigned)last_exp + 60 > FF_ARRAY_ELEMS(pow_tab)) { + av_log(s->avctx, AV_LOG_ERROR, "Exponent out of range: %d\n", + last_exp); + return -1; + } + v = ptab[last_exp]; + iv = iptab[last_exp]; if (v > max_scale) max_scale = v; n = *ptr++; - do { - *q++ = v; - } while (--n); + switch (n & 3) do { + case 0: *q++ = iv; + case 3: *q++ = iv; + case 2: *q++ = iv; + case 1: *q++ = iv; + } while ((n -= 4) > 0); } s->max_exponent[ch] = max_scale; return 0; @@ -305,16 +399,16 @@ static void wma_window(WMACodecContext *s, float *out) block_len = s->block_len; bsize = s->frame_len_bits - s->block_len_bits; - s->dsp.vector_fmul_add_add(out, in, s->windows[bsize], - out, 0, block_len, 1); + s->dsp.vector_fmul_add(out, in, s->windows[bsize], + out, block_len); } else { block_len = 1 << s->prev_block_len_bits; n = (s->block_len - block_len) / 2; bsize = s->frame_len_bits - s->prev_block_len_bits; - s->dsp.vector_fmul_add_add(out+n, in+n, s->windows[bsize], - out+n, 0, block_len, 1); + s->dsp.vector_fmul_add(out+n, in+n, s->windows[bsize], + out+n, block_len); memcpy(out+n+block_len, in+n+block_len, n*sizeof(float)); } @@ -365,12 +459,16 @@ static int wma_decode_block(WMACodecContext *s) if (s->reset_block_lengths) { s->reset_block_lengths = 0; v = get_bits(&s->gb, n); - if (v >= s->nb_block_sizes) + if (v >= s->nb_block_sizes){ + av_log(s->avctx, AV_LOG_ERROR, "prev_block_len_bits %d out of range\n", s->frame_len_bits - v); return -1; + } s->prev_block_len_bits = s->frame_len_bits - v; v = get_bits(&s->gb, n); - if (v >= s->nb_block_sizes) + if (v >= s->nb_block_sizes){ + av_log(s->avctx, AV_LOG_ERROR, "block_len_bits %d out of range\n", s->frame_len_bits - v); return -1; + } s->block_len_bits = s->frame_len_bits - v; } else { /* update block lengths */ @@ -378,8 +476,10 @@ static int wma_decode_block(WMACodecContext *s) s->block_len_bits = s->next_block_len_bits; } v = get_bits(&s->gb, n); - if (v >= s->nb_block_sizes) + if (v >= s->nb_block_sizes){ + av_log(s->avctx, AV_LOG_ERROR, "next_block_len_bits %d out of range\n", s->frame_len_bits - v); return -1; + } s->next_block_len_bits = s->frame_len_bits - v; } else { /* fixed block len */ @@ -390,8 +490,10 @@ static int wma_decode_block(WMACodecContext *s) /* 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) + if ((s->block_pos + s->block_len) > s->frame_len){ + av_log(s->avctx, AV_LOG_ERROR, "frame_len overflow\n"); return -1; + } if (s->nb_channels == 2) { s->ms_stereo = get_bits1(&s->gb); @@ -455,8 +557,10 @@ static int wma_decode_block(WMACodecContext *s) val = get_bits(&s->gb, 7) - 19; } else { code = get_vlc2(&s->gb, s->hgain_vlc.table, HGAINVLCBITS, HGAINMAX); - if (code < 0) + if (code < 0){ + av_log(s->avctx, AV_LOG_ERROR, "hgain vlc invalid\n"); return -1; + } val += code - 18; } s->high_band_values[ch][i] = val; @@ -538,7 +642,7 @@ static int wma_decode_block(WMACodecContext *s) /* compute power of high bands */ exponents = s->exponents[ch] + - (s->high_band_start[bsize]<high_band_start[bsize]<>esize); last_high_band = 0; /* avoid warning */ for(j=0;jexponent_high_bands[s->frame_len_bits - @@ -554,11 +658,11 @@ static int wma_decode_block(WMACodecContext *s) last_high_band = j; tprintf(s->avctx, "%d: power=%f (%d)\n", j, exp_power[j], n); } - exponents += n<>esize; } /* main freqs and high freqs */ - exponents = s->exponents[ch] + (s->coefs_start<exponents[ch] + (s->coefs_start<>esize); for(j=-1;jhigh_band_start[bsize] - @@ -580,7 +684,7 @@ static int wma_decode_block(WMACodecContext *s) *coefs++ = noise * exponents[i<>esize] * mult1; } - exponents += n<>esize; } else { /* coded values + small noise */ for(i = 0;i < n; i++) { @@ -589,7 +693,7 @@ static int wma_decode_block(WMACodecContext *s) *coefs++ = ((*coefs1++) + noise) * exponents[i<>esize] * mult; } - exponents += n<>esize; } } @@ -625,9 +729,6 @@ static int wma_decode_block(WMACodecContext *s) #endif if (s->ms_stereo && s->channel_coded[1]) { - float a, b; - int i; - /* nominal case for ms stereo: we do it before mdct */ /* no need to optimize this case because it should almost never happen */ @@ -637,12 +738,7 @@ static int wma_decode_block(WMACodecContext *s) s->channel_coded[0] = 1; } - for(i = 0; i < s->block_len; i++) { - a = s->coefs[0][i]; - b = s->coefs[1][i]; - s->coefs[0][i] = a + b; - s->coefs[1][i] = a - b; - } + s->dsp.butterflies_float(s->coefs[0], s->coefs[1], s->block_len); } next: @@ -694,17 +790,28 @@ static int wma_decode_frame(WMACodecContext *s, int16_t *samples) /* convert frame to integer */ n = s->frame_len; incr = s->nb_channels; - for(ch = 0; ch < s->nb_channels; ch++) { - ptr = samples + ch; - iptr = s->frame_out[ch]; + if (s->dsp.float_to_int16_interleave == ff_float_to_int16_interleave_c) { + for(ch = 0; ch < s->nb_channels; ch++) { + ptr = samples + ch; + iptr = s->frame_out[ch]; - for(i=0;iframe_out[ch][0], &s->frame_out[ch][s->frame_len], + s->frame_len * sizeof(float)); + } + } else { + float *output[MAX_CHANNELS]; + for (ch = 0; ch < MAX_CHANNELS; ch++) + output[ch] = s->frame_out[ch]; + s->dsp.float_to_int16_interleave(samples, (const float **)output, n, incr); + for(ch = 0; ch < incr; ch++) { + /* prepare for next block */ + memmove(&s->frame_out[ch][0], &s->frame_out[ch][n], n * sizeof(float)); } - /* prepare for next block */ - memmove(&s->frame_out[ch][0], &s->frame_out[ch][s->frame_len], - s->frame_len * sizeof(float)); } #ifdef TRACE @@ -798,6 +905,7 @@ static int wma_decode_superframe(AVCodecContext *avctx, pos >>= 3; len = buf_size - pos; if (len > MAX_CODED_SUPERFRAME_SIZE || len < 0) { + av_log(s->avctx, AV_LOG_ERROR, "len %d invalid\n", len); goto fail; } s->last_superframe_len = len; @@ -823,28 +931,38 @@ static int wma_decode_superframe(AVCodecContext *avctx, return -1; } +static av_cold void flush(AVCodecContext *avctx) +{ + WMACodecContext *s = avctx->priv_data; + + s->last_bitoffset= + s->last_superframe_len= 0; +} + AVCodec wmav1_decoder = { "wmav1", - CODEC_TYPE_AUDIO, + 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 wmav2_decoder = { "wmav2", - CODEC_TYPE_AUDIO, + 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"), }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/wmaenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/wmaenc.c index 8386983014..7aaeb70baa 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/wmaenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/wmaenc.c @@ -134,7 +134,7 @@ static void encode_exp_vlc(WMACodecContext *s, int ch, const int *exp_param){ int exp = *exp_param++; int code = exp - last_exp + 60; assert(code >= 0 && code < 120); - put_bits(&s->pb, ff_wma_scale_huffbits[code], ff_wma_scale_huffcodes[code]); + put_bits(&s->pb, ff_aac_scalefactor_bits[code], ff_aac_scalefactor_code[code]); /* XXX: use a table */ q+= *ptr++; last_exp= exp; @@ -386,25 +386,25 @@ static int encode_superframe(AVCodecContext *avctx, AVCodec wmav1_encoder = { "wmav1", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_WMAV1, sizeof(WMACodecContext), encode_init, encode_superframe, ff_wma_end, - .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, + .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 1"), }; AVCodec wmav2_encoder = { "wmav2", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_WMAV2, sizeof(WMACodecContext), encode_init, encode_superframe, ff_wma_end, - .sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, + .sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE}, .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 2"), }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/wmaprodata.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/wmaprodata.h index 4dd5c7ebed..53824799d5 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/wmaprodata.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/wmaprodata.h @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/wmaprodata.h + * @file * @brief tables for wmapro decoding */ @@ -352,7 +352,7 @@ static const uint16_t coef0_run[HUFF_COEF0_SIZE] = { 1, 0, 1, 0, 1, 0, }; -static const uint16_t coef0_level[HUFF_COEF0_SIZE] = { +static const float coef0_level[HUFF_COEF0_SIZE] = { 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, @@ -393,7 +393,7 @@ static const uint16_t coef1_run[HUFF_COEF1_SIZE] = { 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, }; -static const uint16_t coef1_level[HUFF_COEF1_SIZE] = { +static const float coef1_level[HUFF_COEF1_SIZE] = { 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, @@ -591,7 +591,7 @@ static const float default_decorrelation_matrices[] = { /** * @brief default decorrelation matrix offsets */ -static const float *default_decorrelation[] = { +static const float * const default_decorrelation[] = { NULL, &default_decorrelation_matrices[0], &default_decorrelation_matrices[1], diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/wmaprodec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/wmaprodec.c index ad4e361a07..3eca10150a 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/wmaprodec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/wmaprodec.c @@ -21,7 +21,7 @@ */ /** - * @file libavcodec/wmaprodec.c + * @file * @brief wmapro decoder implementation * Wmapro is an MDCT based codec comparable to wma standard or AAC. * The decoding therefore consists of the following steps: @@ -86,6 +86,162 @@ * subframe in order to reconstruct the output samples. */ +#include "avcodec.h" +#include "internal.h" +#include "get_bits.h" +#include "put_bits.h" +#include "wmaprodata.h" +#include "dsputil.h" +#include "wma.h" + +/** current decoder limitations */ +#define WMAPRO_MAX_CHANNELS 8 ///< max number of handled channels +#define MAX_SUBFRAMES 32 ///< max number of subframes per channel +#define MAX_BANDS 29 ///< max number of scale factor bands +#define MAX_FRAMESIZE 32768 ///< maximum compressed frame size + +#define WMAPRO_BLOCK_MAX_BITS 12 ///< log2 of max block size +#define WMAPRO_BLOCK_MAX_SIZE (1 << WMAPRO_BLOCK_MAX_BITS) ///< maximum block size +#define WMAPRO_BLOCK_SIZES (WMAPRO_BLOCK_MAX_BITS - BLOCK_MIN_BITS + 1) ///< possible block sizes + + +#define VLCBITS 9 +#define SCALEVLCBITS 8 +#define VEC4MAXDEPTH ((HUFF_VEC4_MAXBITS+VLCBITS-1)/VLCBITS) +#define VEC2MAXDEPTH ((HUFF_VEC2_MAXBITS+VLCBITS-1)/VLCBITS) +#define VEC1MAXDEPTH ((HUFF_VEC1_MAXBITS+VLCBITS-1)/VLCBITS) +#define SCALEMAXDEPTH ((HUFF_SCALE_MAXBITS+SCALEVLCBITS-1)/SCALEVLCBITS) +#define SCALERLMAXDEPTH ((HUFF_SCALE_RL_MAXBITS+VLCBITS-1)/VLCBITS) + +static VLC sf_vlc; ///< scale factor DPCM vlc +static VLC sf_rl_vlc; ///< scale factor run length vlc +static VLC vec4_vlc; ///< 4 coefficients per symbol +static VLC vec2_vlc; ///< 2 coefficients per symbol +static VLC vec1_vlc; ///< 1 coefficient per symbol +static VLC coef_vlc[2]; ///< coefficient run length vlc codes +static float sin64[33]; ///< sinus table for decorrelation + +/** + * @brief frame specific decoder context for a single channel + */ +typedef struct { + int16_t prev_block_len; ///< length of the previous block + uint8_t transmit_coefs; + uint8_t num_subframes; + uint16_t subframe_len[MAX_SUBFRAMES]; ///< subframe length in samples + uint16_t subframe_offset[MAX_SUBFRAMES]; ///< subframe positions in the current frame + uint8_t cur_subframe; ///< current subframe number + uint16_t decoded_samples; ///< number of already processed samples + uint8_t grouped; ///< channel is part of a group + int quant_step; ///< quantization step for the current subframe + int8_t reuse_sf; ///< share scale factors between subframes + int8_t scale_factor_step; ///< scaling step for the current subframe + int max_scale_factor; ///< maximum scale factor for the current subframe + int saved_scale_factors[2][MAX_BANDS]; ///< resampled and (previously) transmitted scale factor values + int8_t scale_factor_idx; ///< index for the transmitted scale factor values (used for resampling) + int* scale_factors; ///< pointer to the scale factor values used for decoding + uint8_t table_idx; ///< index in sf_offsets for the scale factor reference block + float* coeffs; ///< pointer to the subframe decode buffer + DECLARE_ALIGNED(16, float, out)[WMAPRO_BLOCK_MAX_SIZE + WMAPRO_BLOCK_MAX_SIZE / 2]; ///< output buffer +} WMAProChannelCtx; + +/** + * @brief channel group for channel transformations + */ +typedef struct { + uint8_t num_channels; ///< number of channels in the group + int8_t transform; ///< transform on / off + int8_t transform_band[MAX_BANDS]; ///< controls if the transform is enabled for a certain band + float decorrelation_matrix[WMAPRO_MAX_CHANNELS*WMAPRO_MAX_CHANNELS]; + float* channel_data[WMAPRO_MAX_CHANNELS]; ///< transformation coefficients +} WMAProChannelGrp; + +/** + * @brief main decoder context + */ +typedef struct WMAProDecodeCtx { + /* generic decoder variables */ + AVCodecContext* avctx; ///< codec context for av_log + DSPContext dsp; ///< accelerated DSP functions + uint8_t frame_data[MAX_FRAMESIZE + + FF_INPUT_BUFFER_PADDING_SIZE];///< compressed frame data + PutBitContext pb; ///< context for filling the frame_data buffer + FFTContext mdct_ctx[WMAPRO_BLOCK_SIZES]; ///< MDCT context per block size + DECLARE_ALIGNED(16, float, tmp)[WMAPRO_BLOCK_MAX_SIZE]; ///< IMDCT output buffer + float* windows[WMAPRO_BLOCK_SIZES]; ///< windows for the different block sizes + + /* frame size dependent frame information (set during initialization) */ + uint32_t decode_flags; ///< used compression features + uint8_t len_prefix; ///< frame is prefixed with its length + uint8_t dynamic_range_compression; ///< frame contains DRC data + uint8_t bits_per_sample; ///< integer audio sample size for the unscaled IMDCT output (used to scale to [-1.0, 1.0]) + uint16_t samples_per_frame; ///< number of samples to output + uint16_t log2_frame_size; + int8_t num_channels; ///< number of channels in the stream (same as AVCodecContext.num_channels) + int8_t lfe_channel; ///< lfe channel index + uint8_t max_num_subframes; + uint8_t subframe_len_bits; ///< number of bits used for the subframe length + uint8_t max_subframe_len_bit; ///< flag indicating that the subframe is of maximum size when the first subframe length bit is 1 + uint16_t min_samples_per_subframe; + int8_t num_sfb[WMAPRO_BLOCK_SIZES]; ///< scale factor bands per block size + int16_t sfb_offsets[WMAPRO_BLOCK_SIZES][MAX_BANDS]; ///< scale factor band offsets (multiples of 4) + int8_t sf_offsets[WMAPRO_BLOCK_SIZES][WMAPRO_BLOCK_SIZES][MAX_BANDS]; ///< scale factor resample matrix + int16_t subwoofer_cutoffs[WMAPRO_BLOCK_SIZES]; ///< subwoofer cutoff values + + /* packet decode state */ + GetBitContext pgb; ///< bitstream reader context for the packet + uint8_t packet_offset; ///< frame offset in the packet + uint8_t packet_sequence_number; ///< current packet number + int num_saved_bits; ///< saved number of bits + int frame_offset; ///< frame offset in the bit reservoir + int subframe_offset; ///< subframe offset in the bit reservoir + uint8_t packet_loss; ///< set in case of bitstream error + uint8_t packet_done; ///< set when a packet is fully decoded + + /* frame decode state */ + uint32_t frame_num; ///< current frame number (not used for decoding) + GetBitContext gb; ///< bitstream reader context + int buf_bit_size; ///< buffer size in bits + float* samples; ///< current samplebuffer pointer + float* samples_end; ///< maximum samplebuffer pointer + uint8_t drc_gain; ///< gain for the DRC tool + int8_t skip_frame; ///< skip output step + int8_t parsed_all_subframes; ///< all subframes decoded? + + /* subframe/block decode state */ + int16_t subframe_len; ///< current subframe length + int8_t channels_for_cur_subframe; ///< number of channels that contain the subframe + int8_t channel_indexes_for_cur_subframe[WMAPRO_MAX_CHANNELS]; + int8_t num_bands; ///< number of scale factor bands + int16_t* cur_sfb_offsets; ///< sfb offsets for the current block + uint8_t table_idx; ///< index for the num_sfb, sfb_offsets, sf_offsets and subwoofer_cutoffs tables + int8_t esc_len; ///< length of escaped coefficients + + uint8_t num_chgroups; ///< number of channel groups + WMAProChannelGrp chgroup[WMAPRO_MAX_CHANNELS]; ///< channel group information + + WMAProChannelCtx channel[WMAPRO_MAX_CHANNELS]; ///< per channel data +} WMAProDecodeCtx; + + +/** + *@brief helper function to print the most important members of the context + *@param s context + */ +static void av_cold dump_context(WMAProDecodeCtx *s) +{ +#define PRINT(a, b) av_log(s->avctx, AV_LOG_DEBUG, " %s = %d\n", a, b); +#define PRINT_HEX(a, b) av_log(s->avctx, AV_LOG_DEBUG, " %s = %x\n", a, b); + + PRINT("ed sample bit depth", s->bits_per_sample); + PRINT_HEX("ed decode flags", s->decode_flags); + PRINT("samples per frame", s->samples_per_frame); + PRINT("log2 frame size", s->log2_frame_size); + PRINT("max num subframes", s->max_num_subframes); + PRINT("len prefix", s->len_prefix); + PRINT("num channels", s->num_channels); +} + /** *@brief Uninitialize the decoder and free all resources. *@param avctx codec context @@ -93,41 +249,377 @@ */ static av_cold int decode_end(AVCodecContext *avctx) { - WMA3DecodeContext *s = avctx->priv_data; + WMAProDecodeCtx *s = avctx->priv_data; int i; - for (i = 0 ; i < WMAPRO_BLOCK_SIZES ; i++) + for (i = 0; i < WMAPRO_BLOCK_SIZES; i++) ff_mdct_end(&s->mdct_ctx[i]); return 0; } +/** + *@brief Initialize the decoder. + *@param avctx codec context + *@return 0 on success, -1 otherwise + */ +static av_cold int decode_init(AVCodecContext *avctx) +{ + WMAProDecodeCtx *s = avctx->priv_data; + uint8_t *edata_ptr = avctx->extradata; + unsigned int channel_mask; + int i; + int log2_max_num_subframes; + int num_possible_block_sizes; + + s->avctx = avctx; + dsputil_init(&s->dsp, avctx); + init_put_bits(&s->pb, s->frame_data, MAX_FRAMESIZE); + + avctx->sample_fmt = SAMPLE_FMT_FLT; + + if (avctx->extradata_size >= 18) { + s->decode_flags = AV_RL16(edata_ptr+14); + channel_mask = AV_RL32(edata_ptr+2); + s->bits_per_sample = AV_RL16(edata_ptr); + /** dump the extradata */ + for (i = 0; i < avctx->extradata_size; i++) + dprintf(avctx, "[%x] ", avctx->extradata[i]); + dprintf(avctx, "\n"); + + } else { + av_log_ask_for_sample(avctx, "Unknown extradata size\n"); + return AVERROR_INVALIDDATA; + } + + /** generic init */ + s->log2_frame_size = av_log2(avctx->block_align) + 4; + + /** frame info */ + s->skip_frame = 1; /** skip first frame */ + s->packet_loss = 1; + s->len_prefix = (s->decode_flags & 0x40); + + if (!s->len_prefix) { + av_log_ask_for_sample(avctx, "no length prefix\n"); + return AVERROR_INVALIDDATA; + } + + /** get frame len */ + 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; + if (s->max_num_subframes == 16) + s->max_subframe_len_bit = 1; + s->subframe_len_bits = av_log2(log2_max_num_subframes) + 1; + + num_possible_block_sizes = log2_max_num_subframes + 1; + s->min_samples_per_subframe = s->samples_per_frame / s->max_num_subframes; + s->dynamic_range_compression = (s->decode_flags & 0x80); + + if (s->max_num_subframes > MAX_SUBFRAMES) { + av_log(avctx, AV_LOG_ERROR, "invalid number of subframes %i\n", + s->max_num_subframes); + return AVERROR_INVALIDDATA; + } + + s->num_channels = avctx->channels; + + /** extract lfe channel position */ + s->lfe_channel = -1; + + if (channel_mask & 8) { + unsigned int mask; + for (mask = 1; mask < 16; mask <<= 1) { + if (channel_mask & mask) + ++s->lfe_channel; + } + } + + 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); + + INIT_VLC_STATIC(&sf_rl_vlc, VLCBITS, HUFF_SCALE_RL_SIZE, + scale_rl_huffbits, 1, 1, + scale_rl_huffcodes, 4, 4, 1406); + + INIT_VLC_STATIC(&coef_vlc[0], VLCBITS, HUFF_COEF0_SIZE, + coef0_huffbits, 1, 1, + coef0_huffcodes, 4, 4, 2108); + + INIT_VLC_STATIC(&coef_vlc[1], VLCBITS, HUFF_COEF1_SIZE, + coef1_huffbits, 1, 1, + coef1_huffcodes, 4, 4, 3912); + + INIT_VLC_STATIC(&vec4_vlc, VLCBITS, HUFF_VEC4_SIZE, + vec4_huffbits, 1, 1, + vec4_huffcodes, 2, 2, 604); + + INIT_VLC_STATIC(&vec2_vlc, VLCBITS, HUFF_VEC2_SIZE, + vec2_huffbits, 1, 1, + vec2_huffcodes, 2, 2, 562); + + INIT_VLC_STATIC(&vec1_vlc, VLCBITS, HUFF_VEC1_SIZE, + vec1_huffbits, 1, 1, + vec1_huffcodes, 2, 2, 562); + + /** calculate number of scale factor bands and their offsets + for every possible block size */ + for (i = 0; i < num_possible_block_sizes; i++) { + int subframe_len = s->samples_per_frame >> i; + int x; + int band = 1; + + s->sfb_offsets[i][0] = 0; + + for (x = 0; x < MAX_BANDS-1 && s->sfb_offsets[i][band - 1] < subframe_len; x++) { + int offset = (subframe_len * 2 * critical_freq[x]) + / s->avctx->sample_rate + 2; + offset &= ~3; + if (offset > s->sfb_offsets[i][band - 1]) + s->sfb_offsets[i][band++] = offset; + } + s->sfb_offsets[i][band - 1] = subframe_len; + s->num_sfb[i] = band - 1; + } + + + /** Scale factors can be shared between blocks of different size + as every block has a different scale factor band layout. + The matrix sf_offsets is needed to find the correct scale factor. + */ + + for (i = 0; i < num_possible_block_sizes; i++) { + int b; + for (b = 0; b < s->num_sfb[i]; b++) { + int x; + int offset = ((s->sfb_offsets[i][b] + + s->sfb_offsets[i][b + 1] - 1) << i) >> 1; + for (x = 0; x < num_possible_block_sizes; x++) { + int v = 0; + while (s->sfb_offsets[x][v + 1] << x < offset) + ++v; + s->sf_offsets[i][x][b] = v; + } + } + } + + /** init MDCT, FIXME: only init needed sizes */ + for (i = 0; i < WMAPRO_BLOCK_SIZES; i++) + ff_mdct_init(&s->mdct_ctx[i], BLOCK_MIN_BITS+1+i, 1, + 1.0 / (1 << (BLOCK_MIN_BITS + i - 1)) + / (1 << (s->bits_per_sample - 1))); + + /** init MDCT windows: simple sinus window */ + for (i = 0; i < WMAPRO_BLOCK_SIZES; i++) { + const int win_idx = WMAPRO_BLOCK_MAX_BITS - i; + ff_init_ff_sine_windows(win_idx); + s->windows[WMAPRO_BLOCK_SIZES - i - 1] = ff_sine_windows[win_idx]; + } + + /** calculate subwoofer cutoff values */ + for (i = 0; i < num_possible_block_sizes; i++) { + int block_size = s->samples_per_frame >> i; + int cutoff = (440*block_size + 3 * (s->avctx->sample_rate >> 1) - 1) + / s->avctx->sample_rate; + s->subwoofer_cutoffs[i] = av_clip(cutoff, 4, block_size); + } + + /** calculate sine values for the decorrelation matrix */ + for (i = 0; i < 33; i++) + sin64[i] = sin(i*M_PI / 64.0); + + if (avctx->debug & FF_DEBUG_BITSTREAM) + dump_context(s); + + avctx->channel_layout = channel_mask; + return 0; +} + +/** + *@brief Decode the subframe length. + *@param s context + *@param offset sample offset in the frame + *@return decoded subframe length on success, < 0 in case of an error + */ +static int decode_subframe_length(WMAProDecodeCtx *s, int offset) +{ + int frame_len_shift = 0; + int subframe_len; + + /** no need to read from the bitstream when only one length is possible */ + if (offset == s->samples_per_frame - s->min_samples_per_subframe) + return s->min_samples_per_subframe; + + /** 1 bit indicates if the subframe is of maximum length */ + if (s->max_subframe_len_bit) { + if (get_bits1(&s->gb)) + frame_len_shift = 1 + get_bits(&s->gb, s->subframe_len_bits-1); + } else + frame_len_shift = get_bits(&s->gb, s->subframe_len_bits); + + subframe_len = s->samples_per_frame >> frame_len_shift; + + /** sanity check the length */ + if (subframe_len < s->min_samples_per_subframe || + subframe_len > s->samples_per_frame) { + av_log(s->avctx, AV_LOG_ERROR, "broken frame: subframe_len %i\n", + subframe_len); + return AVERROR_INVALIDDATA; + } + return subframe_len; +} + +/** + *@brief Decode how the data in the frame is split into subframes. + * Every WMA frame contains the encoded data for a fixed number of + * samples per channel. The data for every channel might be split + * into several subframes. This function will reconstruct the list of + * subframes for every channel. + * + * If the subframes are not evenly split, the algorithm estimates the + * channels with the lowest number of total samples. + * Afterwards, for each of these channels a bit is read from the + * bitstream that indicates if the channel contains a subframe with the + * next subframe size that is going to be read from the bitstream or not. + * If a channel contains such a subframe, the subframe size gets added to + * the channel's subframe list. + * The algorithm repeats these steps until the frame is properly divided + * between the individual channels. + * + *@param s context + *@return 0 on success, < 0 in case of an error + */ +static int decode_tilehdr(WMAProDecodeCtx *s) +{ + uint16_t num_samples[WMAPRO_MAX_CHANNELS]; /** sum of samples for all currently known subframes of a channel */ + uint8_t contains_subframe[WMAPRO_MAX_CHANNELS]; /** flag indicating if a channel contains the current subframe */ + int channels_for_cur_subframe = s->num_channels; /** number of channels that contain the current subframe */ + int fixed_channel_layout = 0; /** flag indicating that all channels use the same subframe offsets and sizes */ + int min_channel_len = 0; /** smallest sum of samples (channels with this length will be processed first) */ + int c; + + /* Should never consume more than 3073 bits (256 iterations for the + * while loop when always the minimum amount of 128 samples is substracted + * from missing samples in the 8 channel case). + * 1 + BLOCK_MAX_SIZE * MAX_CHANNELS / BLOCK_MIN_SIZE * (MAX_CHANNELS + 4) + */ + + /** reset tiling information */ + for (c = 0; c < s->num_channels; c++) + s->channel[c].num_subframes = 0; + + memset(num_samples, 0, sizeof(num_samples)); + + if (s->max_num_subframes == 1 || get_bits1(&s->gb)) + fixed_channel_layout = 1; + + /** loop until the frame data is split between the subframes */ + do { + int subframe_len; + + /** check which channels contain the subframe */ + for (c = 0; c < s->num_channels; c++) { + if (num_samples[c] == min_channel_len) { + if (fixed_channel_layout || channels_for_cur_subframe == 1 || + (min_channel_len == s->samples_per_frame - s->min_samples_per_subframe)) + contains_subframe[c] = 1; + else + contains_subframe[c] = get_bits1(&s->gb); + } else + contains_subframe[c] = 0; + } + + /** get subframe length, subframe_len == 0 is not allowed */ + if ((subframe_len = decode_subframe_length(s, min_channel_len)) <= 0) + return AVERROR_INVALIDDATA; + + /** add subframes to the individual channels and find new min_channel_len */ + min_channel_len += subframe_len; + for (c = 0; c < s->num_channels; c++) { + WMAProChannelCtx* chan = &s->channel[c]; + + if (contains_subframe[c]) { + if (chan->num_subframes >= MAX_SUBFRAMES) { + av_log(s->avctx, AV_LOG_ERROR, + "broken frame: num subframes > 31\n"); + return AVERROR_INVALIDDATA; + } + chan->subframe_len[chan->num_subframes] = subframe_len; + num_samples[c] += subframe_len; + ++chan->num_subframes; + if (num_samples[c] > s->samples_per_frame) { + av_log(s->avctx, AV_LOG_ERROR, "broken frame: " + "channel len > samples_per_frame\n"); + return AVERROR_INVALIDDATA; + } + } else if (num_samples[c] <= min_channel_len) { + if (num_samples[c] < min_channel_len) { + channels_for_cur_subframe = 0; + min_channel_len = num_samples[c]; + } + ++channels_for_cur_subframe; + } + } + } while (min_channel_len < s->samples_per_frame); + + for (c = 0; c < s->num_channels; c++) { + int i; + int offset = 0; + for (i = 0; i < s->channel[c].num_subframes; i++) { + dprintf(s->avctx, "frame[%i] channel[%i] subframe[%i]" + " len %i\n", s->frame_num, c, i, + s->channel[c].subframe_len[i]); + s->channel[c].subframe_offset[i] = offset; + offset += s->channel[c].subframe_len[i]; + } + } + + return 0; +} + /** *@brief Calculate a decorrelation matrix from the bitstream parameters. *@param s codec context *@param chgroup channel group for which the matrix needs to be calculated */ -static void decode_decorrelation_matrix(WMA3DecodeContext *s, - WMA3ChannelGroup *chgroup) +static void decode_decorrelation_matrix(WMAProDecodeCtx *s, + WMAProChannelGrp *chgroup) { int i; int offset = 0; int8_t rotation_offset[WMAPRO_MAX_CHANNELS * WMAPRO_MAX_CHANNELS]; - memset(chgroup->decorrelation_matrix,0, - sizeof(float) *s->num_channels * s->num_channels); + memset(chgroup->decorrelation_matrix, 0, s->num_channels * + s->num_channels * sizeof(*chgroup->decorrelation_matrix)); for (i = 0; i < chgroup->num_channels * (chgroup->num_channels - 1) >> 1; i++) - rotation_offset[i] = get_bits(&s->gb,6); + rotation_offset[i] = get_bits(&s->gb, 6); for (i = 0; i < chgroup->num_channels; i++) chgroup->decorrelation_matrix[chgroup->num_channels * i + i] = - get_bits1(&s->gb) ? 1.0 : -1.0; + get_bits1(&s->gb) ? 1.0 : -1.0; for (i = 1; i < chgroup->num_channels; i++) { int x; for (x = 0; x < i; x++) { int y; - for (y = 0; y < i + 1 ; y++) { + for (y = 0; y < i + 1; y++) { float v1 = chgroup->decorrelation_matrix[x * chgroup->num_channels + y]; float v2 = chgroup->decorrelation_matrix[i * chgroup->num_channels + y]; int n = rotation_offset[offset + x]; @@ -136,10 +628,10 @@ static void decode_decorrelation_matrix(WMA3DecodeContext *s, if (n < 32) { sinv = sin64[n]; - cosv = sin64[32-n]; + cosv = sin64[32 - n]; } else { - sinv = sin64[64-n]; - cosv = -sin64[n-32]; + sinv = sin64[64 - n]; + cosv = -sin64[n - 32]; } chgroup->decorrelation_matrix[y + x * chgroup->num_channels] = @@ -152,43 +644,325 @@ static void decode_decorrelation_matrix(WMA3DecodeContext *s, } } +/** + *@brief Decode channel transformation parameters + *@param s codec context + *@return 0 in case of success, < 0 in case of bitstream errors + */ +static int decode_channel_transform(WMAProDecodeCtx* s) +{ + int i; + /* should never consume more than 1921 bits for the 8 channel case + * 1 + MAX_CHANNELS * (MAX_CHANNELS + 2 + 3 * MAX_CHANNELS * MAX_CHANNELS + * + MAX_CHANNELS + MAX_BANDS + 1) + */ + + /** in the one channel case channel transforms are pointless */ + s->num_chgroups = 0; + if (s->num_channels > 1) { + int remaining_channels = s->channels_for_cur_subframe; + + if (get_bits1(&s->gb)) { + av_log_ask_for_sample(s->avctx, + "unsupported channel transform bit\n"); + return AVERROR_INVALIDDATA; + } + + for (s->num_chgroups = 0; remaining_channels && + s->num_chgroups < s->channels_for_cur_subframe; s->num_chgroups++) { + WMAProChannelGrp* chgroup = &s->chgroup[s->num_chgroups]; + float** channel_data = chgroup->channel_data; + chgroup->num_channels = 0; + chgroup->transform = 0; + + /** decode channel mask */ + if (remaining_channels > 2) { + for (i = 0; i < s->channels_for_cur_subframe; i++) { + int channel_idx = s->channel_indexes_for_cur_subframe[i]; + if (!s->channel[channel_idx].grouped + && get_bits1(&s->gb)) { + ++chgroup->num_channels; + s->channel[channel_idx].grouped = 1; + *channel_data++ = s->channel[channel_idx].coeffs; + } + } + } else { + chgroup->num_channels = remaining_channels; + for (i = 0; i < s->channels_for_cur_subframe; i++) { + int channel_idx = s->channel_indexes_for_cur_subframe[i]; + if (!s->channel[channel_idx].grouped) + *channel_data++ = s->channel[channel_idx].coeffs; + s->channel[channel_idx].grouped = 1; + } + } + + /** decode transform type */ + if (chgroup->num_channels == 2) { + if (get_bits1(&s->gb)) { + if (get_bits1(&s->gb)) { + av_log_ask_for_sample(s->avctx, + "unsupported channel transform type\n"); + } + } else { + chgroup->transform = 1; + if (s->num_channels == 2) { + chgroup->decorrelation_matrix[0] = 1.0; + chgroup->decorrelation_matrix[1] = -1.0; + chgroup->decorrelation_matrix[2] = 1.0; + chgroup->decorrelation_matrix[3] = 1.0; + } else { + /** cos(pi/4) */ + chgroup->decorrelation_matrix[0] = 0.70703125; + chgroup->decorrelation_matrix[1] = -0.70703125; + chgroup->decorrelation_matrix[2] = 0.70703125; + chgroup->decorrelation_matrix[3] = 0.70703125; + } + } + } else if (chgroup->num_channels > 2) { + if (get_bits1(&s->gb)) { + chgroup->transform = 1; + if (get_bits1(&s->gb)) { + decode_decorrelation_matrix(s, chgroup); + } else { + /** FIXME: more than 6 coupled channels not supported */ + if (chgroup->num_channels > 6) { + av_log_ask_for_sample(s->avctx, + "coupled channels > 6\n"); + } else { + memcpy(chgroup->decorrelation_matrix, + default_decorrelation[chgroup->num_channels], + chgroup->num_channels * chgroup->num_channels * + sizeof(*chgroup->decorrelation_matrix)); + } + } + } + } + + /** decode transform on / off */ + if (chgroup->transform) { + if (!get_bits1(&s->gb)) { + int i; + /** transform can be enabled for individual bands */ + for (i = 0; i < s->num_bands; i++) { + chgroup->transform_band[i] = get_bits1(&s->gb); + } + } else { + memset(chgroup->transform_band, 1, s->num_bands); + } + } + remaining_channels -= chgroup->num_channels; + } + } + return 0; +} + +/** + *@brief Extract the coefficients from the bitstream. + *@param s codec context + *@param c current channel number + *@return 0 on success, < 0 in case of bitstream errors + */ +static int decode_coeffs(WMAProDecodeCtx *s, int c) +{ + /* Integers 0..15 as single-precision floats. The table saves a + costly int to float conversion, and storing the values as + integers allows fast sign-flipping. */ + static const int fval_tab[16] = { + 0x00000000, 0x3f800000, 0x40000000, 0x40400000, + 0x40800000, 0x40a00000, 0x40c00000, 0x40e00000, + 0x41000000, 0x41100000, 0x41200000, 0x41300000, + 0x41400000, 0x41500000, 0x41600000, 0x41700000, + }; + int vlctable; + VLC* vlc; + WMAProChannelCtx* ci = &s->channel[c]; + int rl_mode = 0; + int cur_coeff = 0; + int num_zeros = 0; + const uint16_t* run; + const float* level; + + dprintf(s->avctx, "decode coefficients for channel %i\n", c); + + vlctable = get_bits1(&s->gb); + vlc = &coef_vlc[vlctable]; + + if (vlctable) { + run = coef1_run; + level = coef1_level; + } else { + run = coef0_run; + level = coef0_level; + } + + /** decode vector coefficients (consumes up to 167 bits per iteration for + 4 vector coded large values) */ + while (!rl_mode && cur_coeff + 3 < s->subframe_len) { + int vals[4]; + int i; + unsigned int idx; + + idx = get_vlc2(&s->gb, vec4_vlc.table, VLCBITS, VEC4MAXDEPTH); + + if (idx == HUFF_VEC4_SIZE - 1) { + for (i = 0; i < 4; i += 2) { + idx = get_vlc2(&s->gb, vec2_vlc.table, VLCBITS, VEC2MAXDEPTH); + if (idx == HUFF_VEC2_SIZE - 1) { + int v0, v1; + v0 = get_vlc2(&s->gb, vec1_vlc.table, VLCBITS, VEC1MAXDEPTH); + if (v0 == HUFF_VEC1_SIZE - 1) + v0 += ff_wma_get_large_val(&s->gb); + v1 = get_vlc2(&s->gb, vec1_vlc.table, VLCBITS, VEC1MAXDEPTH); + if (v1 == HUFF_VEC1_SIZE - 1) + v1 += ff_wma_get_large_val(&s->gb); + ((float*)vals)[i ] = v0; + ((float*)vals)[i+1] = v1; + } else { + vals[i] = fval_tab[symbol_to_vec2[idx] >> 4 ]; + vals[i+1] = fval_tab[symbol_to_vec2[idx] & 0xF]; + } + } + } else { + vals[0] = fval_tab[ symbol_to_vec4[idx] >> 12 ]; + vals[1] = fval_tab[(symbol_to_vec4[idx] >> 8) & 0xF]; + vals[2] = fval_tab[(symbol_to_vec4[idx] >> 4) & 0xF]; + vals[3] = fval_tab[ symbol_to_vec4[idx] & 0xF]; + } + + /** decode sign */ + for (i = 0; i < 4; i++) { + if (vals[i]) { + int sign = get_bits1(&s->gb) - 1; + *(uint32_t*)&ci->coeffs[cur_coeff] = vals[i] ^ sign<<31; + num_zeros = 0; + } else { + ci->coeffs[cur_coeff] = 0; + /** switch to run level mode when subframe_len / 128 zeros + were found in a row */ + rl_mode |= (++num_zeros > s->subframe_len >> 8); + } + ++cur_coeff; + } + } + + /** decode run level coded coefficients */ + if (rl_mode) { + memset(&ci->coeffs[cur_coeff], 0, + sizeof(*ci->coeffs) * (s->subframe_len - cur_coeff)); + if (ff_wma_run_level_decode(s->avctx, &s->gb, vlc, + level, run, 1, ci->coeffs, + cur_coeff, s->subframe_len, + s->subframe_len, s->esc_len, 0)) + return AVERROR_INVALIDDATA; + } + + return 0; +} + +/** + *@brief Extract scale factors from the bitstream. + *@param s codec context + *@return 0 on success, < 0 in case of bitstream errors + */ +static int decode_scale_factors(WMAProDecodeCtx* s) +{ + int i; + + /** should never consume more than 5344 bits + * MAX_CHANNELS * (1 + MAX_BANDS * 23) + */ + + for (i = 0; i < s->channels_for_cur_subframe; i++) { + int c = s->channel_indexes_for_cur_subframe[i]; + int* sf; + int* sf_end; + s->channel[c].scale_factors = s->channel[c].saved_scale_factors[!s->channel[c].scale_factor_idx]; + sf_end = s->channel[c].scale_factors + s->num_bands; + + /** resample scale factors for the new block size + * as the scale factors might need to be resampled several times + * before some new values are transmitted, a backup of the last + * transmitted scale factors is kept in saved_scale_factors + */ + if (s->channel[c].reuse_sf) { + const int8_t* sf_offsets = s->sf_offsets[s->table_idx][s->channel[c].table_idx]; + int b; + for (b = 0; b < s->num_bands; b++) + s->channel[c].scale_factors[b] = + s->channel[c].saved_scale_factors[s->channel[c].scale_factor_idx][*sf_offsets++]; + } + + if (!s->channel[c].cur_subframe || get_bits1(&s->gb)) { + + if (!s->channel[c].reuse_sf) { + int val; + /** decode DPCM coded scale factors */ + s->channel[c].scale_factor_step = get_bits(&s->gb, 2) + 1; + val = 45 / s->channel[c].scale_factor_step; + for (sf = s->channel[c].scale_factors; sf < sf_end; sf++) { + val += get_vlc2(&s->gb, sf_vlc.table, SCALEVLCBITS, SCALEMAXDEPTH) - 60; + *sf = val; + } + } else { + int i; + /** run level decode differences to the resampled factors */ + for (i = 0; i < s->num_bands; i++) { + int idx; + int skip; + int val; + int sign; + + idx = get_vlc2(&s->gb, sf_rl_vlc.table, VLCBITS, SCALERLMAXDEPTH); + + if (!idx) { + uint32_t code = get_bits(&s->gb, 14); + val = code >> 6; + sign = (code & 1) - 1; + skip = (code & 0x3f) >> 1; + } else if (idx == 1) { + break; + } else { + skip = scale_rl_run[idx]; + val = scale_rl_level[idx]; + sign = get_bits1(&s->gb)-1; + } + + i += skip; + if (i >= s->num_bands) { + av_log(s->avctx, AV_LOG_ERROR, + "invalid scale factor coding\n"); + return AVERROR_INVALIDDATA; + } + s->channel[c].scale_factors[i] += (val ^ sign) - sign; + } + } + /** swap buffers */ + s->channel[c].scale_factor_idx = !s->channel[c].scale_factor_idx; + s->channel[c].table_idx = s->table_idx; + s->channel[c].reuse_sf = 1; + } + + /** calculate new scale factor maximum */ + s->channel[c].max_scale_factor = s->channel[c].scale_factors[0]; + for (sf = s->channel[c].scale_factors + 1; sf < sf_end; sf++) { + s->channel[c].max_scale_factor = + FFMAX(s->channel[c].max_scale_factor, *sf); + } + + } + return 0; +} + /** *@brief Reconstruct the individual channel data. *@param s codec context */ -static void inverse_channel_transform(WMA3DecodeContext *s) +static void inverse_channel_transform(WMAProDecodeCtx *s) { int i; for (i = 0; i < s->num_chgroups; i++) { - - if (s->chgroup[i].transform == 1) { - /** M/S stereo decoding */ - int16_t* sfb_offsets = s->cur_sfb_offsets; - float* ch0 = *sfb_offsets + s->channel[0].coeffs; - float* ch1 = *sfb_offsets++ + s->channel[1].coeffs; - const char* tb = s->chgroup[i].transform_band; - const char* tb_end = tb + s->num_bands; - - while (tb < tb_end) { - const float* ch0_end = s->channel[0].coeffs + - FFMIN(*sfb_offsets,s->subframe_len); - if (*tb++ == 1) { - while (ch0 < ch0_end) { - const float v1 = *ch0; - const float v2 = *ch1; - *ch0++ = v1 - v2; - *ch1++ = v1 + v2; - } - } else { - while (ch0 < ch0_end) { - *ch0++ *= 181.0 / 128; - *ch1++ *= 181.0 / 128; - } - } - ++sfb_offsets; - } - } else if (s->chgroup[i].transform) { + if (s->chgroup[i].transform) { float data[WMAPRO_MAX_CHANNELS]; const int num_channels = s->chgroup[i].num_channels; float** ch_data = s->chgroup[i].channel_data; @@ -197,10 +971,10 @@ static void inverse_channel_transform(WMA3DecodeContext *s) int16_t* sfb; /** multichannel decorrelation */ - for (sfb = s->cur_sfb_offsets ; - sfb < s->cur_sfb_offsets + s->num_bands;sfb++) { + for (sfb = s->cur_sfb_offsets; + sfb < s->cur_sfb_offsets + s->num_bands; sfb++) { + int y; if (*tb++ == 1) { - int y; /** multiply values with the decorrelation_matrix */ for (y = sfb[0]; y < FFMIN(sfb[1], s->subframe_len); y++) { const float* mat = s->chgroup[i].decorrelation_matrix; @@ -208,8 +982,8 @@ static void inverse_channel_transform(WMA3DecodeContext *s) float* data_ptr = data; float** ch; - for (ch = ch_data;ch < ch_end; ch++) - *data_ptr++ = (*ch)[y]; + for (ch = ch_data; ch < ch_end; ch++) + *data_ptr++ = (*ch)[y]; for (ch = ch_data; ch < ch_end; ch++) { float sum = 0; @@ -220,9 +994,586 @@ static void inverse_channel_transform(WMA3DecodeContext *s) (*ch)[y] = sum; } } + } else if (s->num_channels == 2) { + int len = FFMIN(sfb[1], s->subframe_len) - sfb[0]; + s->dsp.vector_fmul_scalar(ch_data[0] + sfb[0], + ch_data[0] + sfb[0], + 181.0 / 128, len); + s->dsp.vector_fmul_scalar(ch_data[1] + sfb[0], + ch_data[1] + sfb[0], + 181.0 / 128, len); } } } } } +/** + *@brief Apply sine window and reconstruct the output buffer. + *@param s codec context + */ +static void wmapro_window(WMAProDecodeCtx *s) +{ + int i; + for (i = 0; i < s->channels_for_cur_subframe; i++) { + int c = s->channel_indexes_for_cur_subframe[i]; + float* window; + int winlen = s->channel[c].prev_block_len; + float* start = s->channel[c].coeffs - (winlen >> 1); + + if (s->subframe_len < winlen) { + start += (winlen - s->subframe_len) >> 1; + winlen = s->subframe_len; + } + + window = s->windows[av_log2(winlen) - BLOCK_MIN_BITS]; + + winlen >>= 1; + + s->dsp.vector_fmul_window(start, start, start + winlen, + window, 0, winlen); + + s->channel[c].prev_block_len = s->subframe_len; + } +} + +/** + *@brief Decode a single subframe (block). + *@param s codec context + *@return 0 on success, < 0 when decoding failed + */ +static int decode_subframe(WMAProDecodeCtx *s) +{ + int offset = s->samples_per_frame; + int subframe_len = s->samples_per_frame; + int i; + int total_samples = s->samples_per_frame * s->num_channels; + int transmit_coeffs = 0; + int cur_subwoofer_cutoff; + + s->subframe_offset = get_bits_count(&s->gb); + + /** reset channel context and find the next block offset and size + == the next block of the channel with the smallest number of + decoded samples + */ + for (i = 0; i < s->num_channels; i++) { + s->channel[i].grouped = 0; + if (offset > s->channel[i].decoded_samples) { + offset = s->channel[i].decoded_samples; + subframe_len = + s->channel[i].subframe_len[s->channel[i].cur_subframe]; + } + } + + dprintf(s->avctx, + "processing subframe with offset %i len %i\n", offset, subframe_len); + + /** get a list of all channels that contain the estimated block */ + s->channels_for_cur_subframe = 0; + for (i = 0; i < s->num_channels; i++) { + const int cur_subframe = s->channel[i].cur_subframe; + /** substract already processed samples */ + total_samples -= s->channel[i].decoded_samples; + + /** and count if there are multiple subframes that match our profile */ + if (offset == s->channel[i].decoded_samples && + subframe_len == s->channel[i].subframe_len[cur_subframe]) { + total_samples -= s->channel[i].subframe_len[cur_subframe]; + s->channel[i].decoded_samples += + s->channel[i].subframe_len[cur_subframe]; + s->channel_indexes_for_cur_subframe[s->channels_for_cur_subframe] = i; + ++s->channels_for_cur_subframe; + } + } + + /** check if the frame will be complete after processing the + estimated block */ + if (!total_samples) + s->parsed_all_subframes = 1; + + + dprintf(s->avctx, "subframe is part of %i channels\n", + s->channels_for_cur_subframe); + + /** calculate number of scale factor bands and their offsets */ + s->table_idx = av_log2(s->samples_per_frame/subframe_len); + s->num_bands = s->num_sfb[s->table_idx]; + s->cur_sfb_offsets = s->sfb_offsets[s->table_idx]; + cur_subwoofer_cutoff = s->subwoofer_cutoffs[s->table_idx]; + + /** configure the decoder for the current subframe */ + for (i = 0; i < s->channels_for_cur_subframe; i++) { + int c = s->channel_indexes_for_cur_subframe[i]; + + s->channel[c].coeffs = &s->channel[c].out[(s->samples_per_frame >> 1) + + offset]; + } + + s->subframe_len = subframe_len; + s->esc_len = av_log2(s->subframe_len - 1) + 1; + + /** skip extended header if any */ + if (get_bits1(&s->gb)) { + int num_fill_bits; + if (!(num_fill_bits = get_bits(&s->gb, 2))) { + int len = get_bits(&s->gb, 4); + num_fill_bits = get_bits(&s->gb, len) + 1; + } + + if (num_fill_bits >= 0) { + if (get_bits_count(&s->gb) + num_fill_bits > s->num_saved_bits) { + av_log(s->avctx, AV_LOG_ERROR, "invalid number of fill bits\n"); + return AVERROR_INVALIDDATA; + } + + skip_bits_long(&s->gb, num_fill_bits); + } + } + + /** no idea for what the following bit is used */ + if (get_bits1(&s->gb)) { + av_log_ask_for_sample(s->avctx, "reserved bit set\n"); + return AVERROR_INVALIDDATA; + } + + + if (decode_channel_transform(s) < 0) + return AVERROR_INVALIDDATA; + + + for (i = 0; i < s->channels_for_cur_subframe; i++) { + int c = s->channel_indexes_for_cur_subframe[i]; + if ((s->channel[c].transmit_coefs = get_bits1(&s->gb))) + transmit_coeffs = 1; + } + + if (transmit_coeffs) { + int step; + int quant_step = 90 * s->bits_per_sample >> 4; + if ((get_bits1(&s->gb))) { + /** FIXME: might change run level mode decision */ + av_log_ask_for_sample(s->avctx, "unsupported quant step coding\n"); + return AVERROR_INVALIDDATA; + } + /** decode quantization step */ + step = get_sbits(&s->gb, 6); + quant_step += step; + if (step == -32 || step == 31) { + const int sign = (step == 31) - 1; + int quant = 0; + while (get_bits_count(&s->gb) + 5 < s->num_saved_bits && + (step = get_bits(&s->gb, 5)) == 31) { + quant += 31; + } + quant_step += ((quant + step) ^ sign) - sign; + } + if (quant_step < 0) { + av_log(s->avctx, AV_LOG_DEBUG, "negative quant step\n"); + } + + /** decode quantization step modifiers for every channel */ + + if (s->channels_for_cur_subframe == 1) { + s->channel[s->channel_indexes_for_cur_subframe[0]].quant_step = quant_step; + } else { + int modifier_len = get_bits(&s->gb, 3); + for (i = 0; i < s->channels_for_cur_subframe; i++) { + int c = s->channel_indexes_for_cur_subframe[i]; + s->channel[c].quant_step = quant_step; + if (get_bits1(&s->gb)) { + if (modifier_len) { + s->channel[c].quant_step += get_bits(&s->gb, modifier_len) + 1; + } else + ++s->channel[c].quant_step; + } + } + } + + /** decode scale factors */ + if (decode_scale_factors(s) < 0) + return AVERROR_INVALIDDATA; + } + + dprintf(s->avctx, "BITSTREAM: subframe header length was %i\n", + get_bits_count(&s->gb) - s->subframe_offset); + + /** parse coefficients */ + for (i = 0; i < s->channels_for_cur_subframe; i++) { + int c = s->channel_indexes_for_cur_subframe[i]; + if (s->channel[c].transmit_coefs && + get_bits_count(&s->gb) < s->num_saved_bits) { + decode_coeffs(s, c); + } else + memset(s->channel[c].coeffs, 0, + sizeof(*s->channel[c].coeffs) * subframe_len); + } + + dprintf(s->avctx, "BITSTREAM: subframe length was %i\n", + get_bits_count(&s->gb) - s->subframe_offset); + + if (transmit_coeffs) { + /** reconstruct the per channel data */ + inverse_channel_transform(s); + for (i = 0; i < s->channels_for_cur_subframe; i++) { + int c = s->channel_indexes_for_cur_subframe[i]; + const int* sf = s->channel[c].scale_factors; + int b; + + if (c == s->lfe_channel) + memset(&s->tmp[cur_subwoofer_cutoff], 0, sizeof(*s->tmp) * + (subframe_len - cur_subwoofer_cutoff)); + + /** inverse quantization and rescaling */ + for (b = 0; b < s->num_bands; b++) { + const int end = FFMIN(s->cur_sfb_offsets[b+1], s->subframe_len); + const int exp = s->channel[c].quant_step - + (s->channel[c].max_scale_factor - *sf++) * + s->channel[c].scale_factor_step; + const float quant = pow(10.0, exp / 20.0); + int start = s->cur_sfb_offsets[b]; + s->dsp.vector_fmul_scalar(s->tmp + start, + s->channel[c].coeffs + start, + quant, end - start); + } + + /** apply imdct (ff_imdct_half == DCTIV with reverse) */ + ff_imdct_half(&s->mdct_ctx[av_log2(subframe_len) - BLOCK_MIN_BITS], + s->channel[c].coeffs, s->tmp); + } + } + + /** window and overlapp-add */ + wmapro_window(s); + + /** handled one subframe */ + for (i = 0; i < s->channels_for_cur_subframe; i++) { + int c = s->channel_indexes_for_cur_subframe[i]; + if (s->channel[c].cur_subframe >= s->channel[c].num_subframes) { + av_log(s->avctx, AV_LOG_ERROR, "broken subframe\n"); + return AVERROR_INVALIDDATA; + } + ++s->channel[c].cur_subframe; + } + + return 0; +} + +/** + *@brief Decode one WMA frame. + *@param s codec context + *@return 0 if the trailer bit indicates that this is the last frame, + * 1 if there are additional frames + */ +static int decode_frame(WMAProDecodeCtx *s) +{ + GetBitContext* gb = &s->gb; + int more_frames = 0; + int len = 0; + int i; + + /** check for potential output buffer overflow */ + if (s->num_channels * s->samples_per_frame > s->samples_end - s->samples) { + /** return an error if no frame could be decoded at all */ + av_log(s->avctx, AV_LOG_ERROR, + "not enough space for the output samples\n"); + s->packet_loss = 1; + return 0; + } + + /** get frame length */ + if (s->len_prefix) + len = get_bits(gb, s->log2_frame_size); + + dprintf(s->avctx, "decoding frame with length %x\n", len); + + /** decode tile information */ + if (decode_tilehdr(s)) { + s->packet_loss = 1; + return 0; + } + + /** read postproc transform */ + if (s->num_channels > 1 && get_bits1(gb)) { + av_log_ask_for_sample(s->avctx, "Unsupported postproc transform found\n"); + s->packet_loss = 1; + return 0; + } + + /** read drc info */ + if (s->dynamic_range_compression) { + s->drc_gain = get_bits(gb, 8); + dprintf(s->avctx, "drc_gain %i\n", s->drc_gain); + } + + /** no idea what these are for, might be the number of samples + that need to be skipped at the beginning or end of a stream */ + if (get_bits1(gb)) { + int skip; + + /** usually true for the first frame */ + if (get_bits1(gb)) { + skip = get_bits(gb, av_log2(s->samples_per_frame * 2)); + dprintf(s->avctx, "start skip: %i\n", skip); + } + + /** sometimes true for the last frame */ + if (get_bits1(gb)) { + skip = get_bits(gb, av_log2(s->samples_per_frame * 2)); + dprintf(s->avctx, "end skip: %i\n", skip); + } + + } + + dprintf(s->avctx, "BITSTREAM: frame header length was %i\n", + get_bits_count(gb) - s->frame_offset); + + /** reset subframe states */ + s->parsed_all_subframes = 0; + for (i = 0; i < s->num_channels; i++) { + s->channel[i].decoded_samples = 0; + s->channel[i].cur_subframe = 0; + s->channel[i].reuse_sf = 0; + } + + /** decode all subframes */ + while (!s->parsed_all_subframes) { + if (decode_subframe(s) < 0) { + s->packet_loss = 1; + return 0; + } + } + + /** interleave samples and write them to the output buffer */ + for (i = 0; i < s->num_channels; i++) { + float* ptr = s->samples + i; + int incr = s->num_channels; + float* iptr = s->channel[i].out; + float* iend = iptr + s->samples_per_frame; + + // FIXME should create/use a DSP function here + while (iptr < iend) { + *ptr = *iptr++; + ptr += incr; + } + + /** reuse second half of the IMDCT output for the next frame */ + memcpy(&s->channel[i].out[0], + &s->channel[i].out[s->samples_per_frame], + s->samples_per_frame * sizeof(*s->channel[i].out) >> 1); + } + + if (s->skip_frame) { + s->skip_frame = 0; + } else + s->samples += s->num_channels * s->samples_per_frame; + + if (len != (get_bits_count(gb) - s->frame_offset) + 2) { + /** FIXME: not sure if this is always an error */ + av_log(s->avctx, AV_LOG_ERROR, "frame[%i] would have to skip %i bits\n", + s->frame_num, len - (get_bits_count(gb) - s->frame_offset) - 1); + s->packet_loss = 1; + return 0; + } + + /** skip the rest of the frame data */ + skip_bits_long(gb, len - (get_bits_count(gb) - s->frame_offset) - 1); + + /** decode trailer bit */ + more_frames = get_bits1(gb); + + ++s->frame_num; + return more_frames; +} + +/** + *@brief Calculate remaining input buffer length. + *@param s codec context + *@param gb bitstream reader context + *@return remaining size in bits + */ +static int remaining_bits(WMAProDecodeCtx *s, GetBitContext *gb) +{ + return s->buf_bit_size - get_bits_count(gb); +} + +/** + *@brief Fill the bit reservoir with a (partial) frame. + *@param s codec context + *@param gb bitstream reader context + *@param len length of the partial frame + *@param append decides wether to reset the buffer or not + */ +static void save_bits(WMAProDecodeCtx *s, GetBitContext* gb, int len, + int append) +{ + int buflen; + + /** when the frame data does not need to be concatenated, the input buffer + is resetted and additional bits from the previous frame are copyed + and skipped later so that a fast byte copy is possible */ + + if (!append) { + s->frame_offset = get_bits_count(gb) & 7; + s->num_saved_bits = s->frame_offset; + init_put_bits(&s->pb, s->frame_data, MAX_FRAMESIZE); + } + + buflen = (s->num_saved_bits + len + 8) >> 3; + + if (len <= 0 || buflen > MAX_FRAMESIZE) { + av_log_ask_for_sample(s->avctx, "input buffer too small\n"); + s->packet_loss = 1; + return; + } + + s->num_saved_bits += len; + if (!append) { + ff_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); + } + skip_bits_long(gb, len); + + { + PutBitContext tmp = s->pb; + flush_put_bits(&tmp); + } + + init_get_bits(&s->gb, s->frame_data, s->num_saved_bits); + skip_bits(&s->gb, s->frame_offset); +} + +/** + *@brief Decode a single WMA packet. + *@param avctx codec context + *@param data the output buffer + *@param data_size number of bytes that were written to the output buffer + *@param avpkt input packet + *@return number of bytes that were read from the input buffer + */ +static int decode_packet(AVCodecContext *avctx, + void *data, int *data_size, AVPacket* avpkt) +{ + WMAProDecodeCtx *s = avctx->priv_data; + GetBitContext* gb = &s->pgb; + const uint8_t* buf = avpkt->data; + int buf_size = avpkt->size; + int num_bits_prev_frame; + int packet_sequence_number; + + s->samples = data; + s->samples_end = (float*)((int8_t*)data + *data_size); + *data_size = 0; + + if (s->packet_done || s->packet_loss) { + s->packet_done = 0; + s->buf_bit_size = buf_size << 3; + + /** sanity check for the buffer length */ + if (buf_size < avctx->block_align) + return 0; + + buf_size = avctx->block_align; + + /** parse packet header */ + init_get_bits(gb, buf, s->buf_bit_size); + packet_sequence_number = get_bits(gb, 4); + skip_bits(gb, 2); + + /** get number of bits that need to be added to the previous frame */ + num_bits_prev_frame = get_bits(gb, s->log2_frame_size); + dprintf(avctx, "packet[%d]: nbpf %x\n", avctx->frame_number, + num_bits_prev_frame); + + /** check for packet loss */ + if (!s->packet_loss && + ((s->packet_sequence_number + 1) & 0xF) != packet_sequence_number) { + s->packet_loss = 1; + av_log(avctx, AV_LOG_ERROR, "Packet loss detected! seq %x vs %x\n", + s->packet_sequence_number, packet_sequence_number); + } + s->packet_sequence_number = packet_sequence_number; + + if (num_bits_prev_frame > 0) { + /** append the previous frame data to the remaining data from the + previous packet to create a full frame */ + save_bits(s, gb, num_bits_prev_frame, 1); + dprintf(avctx, "accumulated %x bits of frame data\n", + s->num_saved_bits - s->frame_offset); + + /** decode the cross packet frame if it is valid */ + if (!s->packet_loss) + decode_frame(s); + } else if (s->num_saved_bits - s->frame_offset) { + dprintf(avctx, "ignoring %x previously saved bits\n", + s->num_saved_bits - s->frame_offset); + } + + s->packet_loss = 0; + + } else { + int frame_size; + s->buf_bit_size = avpkt->size << 3; + init_get_bits(gb, avpkt->data, s->buf_bit_size); + skip_bits(gb, s->packet_offset); + if (remaining_bits(s, gb) > s->log2_frame_size && + (frame_size = show_bits(gb, s->log2_frame_size)) && + frame_size <= remaining_bits(s, gb)) { + save_bits(s, gb, frame_size, 0); + s->packet_done = !decode_frame(s); + } else + s->packet_done = 1; + } + + if (s->packet_done && !s->packet_loss && + remaining_bits(s, gb) > 0) { + /** save the rest of the data so that it can be decoded + with the next packet */ + save_bits(s, gb, remaining_bits(s, gb), 0); + } + + *data_size = (int8_t *)s->samples - (int8_t *)data; + s->packet_offset = get_bits_count(gb) & 7; + + return (s->packet_loss) ? AVERROR_INVALIDDATA : get_bits_count(gb) >> 3; +} + +/** + *@brief Clear decoder buffers (for seeking). + *@param avctx codec context + */ +static void flush(AVCodecContext *avctx) +{ + WMAProDecodeCtx *s = avctx->priv_data; + int i; + /** reset output buffer as a part of it is used during the windowing of a + new frame */ + for (i = 0; i < s->num_channels; i++) + memset(s->channel[i].out, 0, s->samples_per_frame * + sizeof(*s->channel[i].out)); + s->packet_loss = 1; +} + + +/** + *@brief wmapro decoder + */ +AVCodec wmapro_decoder = { + "wmapro", + AVMEDIA_TYPE_AUDIO, + CODEC_ID_WMAPRO, + sizeof(WMAProDecodeCtx), + decode_init, + NULL, + decode_end, + decode_packet, + .capabilities = CODEC_CAP_SUBFRAMES, + .flush= flush, + .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 9 Professional"), +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/wmavoice.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/wmavoice.c new file mode 100644 index 0000000000..4ec17eb4f6 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/wmavoice.c @@ -0,0 +1,2030 @@ +/* + * Windows Media Audio Voice decoder. + * Copyright (c) 2009 Ronald S. Bultje + * + * 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 + * @brief Windows Media Audio Voice compatible decoder + * @author Ronald S. Bultje + */ + +#include +#include "avcodec.h" +#include "get_bits.h" +#include "put_bits.h" +#include "wmavoice_data.h" +#include "celp_math.h" +#include "celp_filters.h" +#include "acelp_vectors.h" +#include "acelp_filters.h" +#include "lsp.h" +#include "libavutil/lzo.h" +#include "avfft.h" +#include "fft.h" + +#define MAX_BLOCKS 8 ///< maximum number of blocks per frame +#define MAX_LSPS 16 ///< maximum filter order +#define MAX_LSPS_ALIGN16 16 ///< same as #MAX_LSPS; needs to be multiple + ///< of 16 for ASM input buffer alignment +#define MAX_FRAMES 3 ///< maximum number of frames per superframe +#define MAX_FRAMESIZE 160 ///< maximum number of samples per frame +#define MAX_SIGNAL_HISTORY 416 ///< maximum excitation signal history +#define MAX_SFRAMESIZE (MAX_FRAMESIZE * MAX_FRAMES) + ///< maximum number of samples per superframe +#define SFRAME_CACHE_MAXSIZE 256 ///< maximum cache size for frame data that + ///< was split over two packets +#define VLC_NBITS 6 ///< number of bits to read per VLC iteration + +/** + * Frame type VLC coding. + */ +static VLC frame_type_vlc; + +/** + * Adaptive codebook types. + */ +enum { + ACB_TYPE_NONE = 0, ///< no adaptive codebook (only hardcoded fixed) + ACB_TYPE_ASYMMETRIC = 1, ///< adaptive codebook with per-frame pitch, which + ///< we interpolate to get a per-sample pitch. + ///< Signal is generated using an asymmetric sinc + ///< window function + ///< @note see #wmavoice_ipol1_coeffs + ACB_TYPE_HAMMING = 2 ///< Per-block pitch with signal generation using + ///< a Hamming sinc window function + ///< @note see #wmavoice_ipol2_coeffs +}; + +/** + * Fixed codebook types. + */ +enum { + FCB_TYPE_SILENCE = 0, ///< comfort noise during silence + ///< generated from a hardcoded (fixed) codebook + ///< with per-frame (low) gain values + FCB_TYPE_HARDCODED = 1, ///< hardcoded (fixed) codebook with per-block + ///< gain values + FCB_TYPE_AW_PULSES = 2, ///< Pitch-adaptive window (AW) pulse signals, + ///< used in particular for low-bitrate streams + FCB_TYPE_EXC_PULSES = 3, ///< Innovation (fixed) codebook pulse sets in + ///< combinations of either single pulses or + ///< pulse pairs +}; + +/** + * Description of frame types. + */ +static const struct frame_type_desc { + uint8_t n_blocks; ///< amount of blocks per frame (each block + ///< (contains 160/#n_blocks samples) + uint8_t log_n_blocks; ///< log2(#n_blocks) + uint8_t acb_type; ///< Adaptive codebook type (ACB_TYPE_*) + uint8_t fcb_type; ///< Fixed codebook type (FCB_TYPE_*) + uint8_t dbl_pulses; ///< how many pulse vectors have pulse pairs + ///< (rather than just one single pulse) + ///< only if #fcb_type == #FCB_TYPE_EXC_PULSES + uint16_t frame_size; ///< the amount of bits that make up the block + ///< data (per frame) +} frame_descs[17] = { + { 1, 0, ACB_TYPE_NONE, FCB_TYPE_SILENCE, 0, 0 }, + { 2, 1, ACB_TYPE_NONE, FCB_TYPE_HARDCODED, 0, 28 }, + { 2, 1, ACB_TYPE_ASYMMETRIC, FCB_TYPE_AW_PULSES, 0, 46 }, + { 2, 1, ACB_TYPE_ASYMMETRIC, FCB_TYPE_EXC_PULSES, 2, 80 }, + { 2, 1, ACB_TYPE_ASYMMETRIC, FCB_TYPE_EXC_PULSES, 5, 104 }, + { 4, 2, ACB_TYPE_ASYMMETRIC, FCB_TYPE_EXC_PULSES, 0, 108 }, + { 4, 2, ACB_TYPE_ASYMMETRIC, FCB_TYPE_EXC_PULSES, 2, 132 }, + { 4, 2, ACB_TYPE_ASYMMETRIC, FCB_TYPE_EXC_PULSES, 5, 168 }, + { 2, 1, ACB_TYPE_HAMMING, FCB_TYPE_EXC_PULSES, 0, 64 }, + { 2, 1, ACB_TYPE_HAMMING, FCB_TYPE_EXC_PULSES, 2, 80 }, + { 2, 1, ACB_TYPE_HAMMING, FCB_TYPE_EXC_PULSES, 5, 104 }, + { 4, 2, ACB_TYPE_HAMMING, FCB_TYPE_EXC_PULSES, 0, 108 }, + { 4, 2, ACB_TYPE_HAMMING, FCB_TYPE_EXC_PULSES, 2, 132 }, + { 4, 2, ACB_TYPE_HAMMING, FCB_TYPE_EXC_PULSES, 5, 168 }, + { 8, 3, ACB_TYPE_HAMMING, FCB_TYPE_EXC_PULSES, 0, 176 }, + { 8, 3, ACB_TYPE_HAMMING, FCB_TYPE_EXC_PULSES, 2, 208 }, + { 8, 3, ACB_TYPE_HAMMING, FCB_TYPE_EXC_PULSES, 5, 256 } +}; + +/** + * WMA Voice decoding context. + */ +typedef struct { + /** + * @defgroup struct_global Global values + * Global values, specified in the stream header / extradata or used + * all over. + * @{ + */ + GetBitContext gb; ///< packet bitreader. During decoder init, + ///< it contains the extradata from the + ///< demuxer. During decoding, it contains + ///< packet data. + int8_t vbm_tree[25]; ///< converts VLC codes to frame type + + int spillover_bitsize; ///< number of bits used to specify + ///< #spillover_nbits in the packet header + ///< = ceil(log2(ctx->block_align << 3)) + int history_nsamples; ///< number of samples in history for signal + ///< prediction (through ACB) + + /* postfilter specific values */ + int do_apf; ///< whether to apply the averaged + ///< projection filter (APF) + int denoise_strength; ///< strength of denoising in Wiener filter + ///< [0-11] + int denoise_tilt_corr; ///< Whether to apply tilt correction to the + ///< Wiener filter coefficients (postfilter) + int dc_level; ///< Predicted amount of DC noise, based + ///< on which a DC removal filter is used + + int lsps; ///< number of LSPs per frame [10 or 16] + int lsp_q_mode; ///< defines quantizer defaults [0, 1] + int lsp_def_mode; ///< defines different sets of LSP defaults + ///< [0, 1] + int frame_lsp_bitsize; ///< size (in bits) of LSPs, when encoded + ///< per-frame (independent coding) + int sframe_lsp_bitsize; ///< size (in bits) of LSPs, when encoded + ///< per superframe (residual coding) + + int min_pitch_val; ///< base value for pitch parsing code + int max_pitch_val; ///< max value + 1 for pitch parsing + int pitch_nbits; ///< number of bits used to specify the + ///< pitch value in the frame header + int block_pitch_nbits; ///< number of bits used to specify the + ///< first block's pitch value + int block_pitch_range; ///< range of the block pitch + int block_delta_pitch_nbits; ///< number of bits used to specify the + ///< delta pitch between this and the last + ///< block's pitch value, used in all but + ///< first block + int block_delta_pitch_hrange; ///< 1/2 range of the delta (full range is + ///< from -this to +this-1) + uint16_t block_conv_table[4]; ///< boundaries for block pitch unit/scale + ///< conversion + + /** + * @} + * @defgroup struct_packet Packet values + * Packet values, specified in the packet header or related to a packet. + * A packet is considered to be a single unit of data provided to this + * decoder by the demuxer. + * @{ + */ + int spillover_nbits; ///< number of bits of the previous packet's + ///< last superframe preceeding this + ///< packet's first full superframe (useful + ///< for re-synchronization also) + int has_residual_lsps; ///< if set, superframes contain one set of + ///< LSPs that cover all frames, encoded as + ///< independent and residual LSPs; if not + ///< set, each frame contains its own, fully + ///< independent, LSPs + int skip_bits_next; ///< number of bits to skip at the next call + ///< to #wmavoice_decode_packet() (since + ///< they're part of the previous superframe) + + uint8_t sframe_cache[SFRAME_CACHE_MAXSIZE + FF_INPUT_BUFFER_PADDING_SIZE]; + ///< cache for superframe data split over + ///< multiple packets + int sframe_cache_size; ///< set to >0 if we have data from an + ///< (incomplete) superframe from a previous + ///< packet that spilled over in the current + ///< packet; specifies the amount of bits in + ///< #sframe_cache + PutBitContext pb; ///< bitstream writer for #sframe_cache + + /** + * @} + * @defgroup struct_frame Frame and superframe values + * Superframe and frame data - these can change from frame to frame, + * although some of them do in that case serve as a cache / history for + * the next frame or superframe. + * @{ + */ + double prev_lsps[MAX_LSPS]; ///< LSPs of the last frame of the previous + ///< superframe + int last_pitch_val; ///< pitch value of the previous frame + int last_acb_type; ///< frame type [0-2] of the previous frame + int pitch_diff_sh16; ///< ((cur_pitch_val - #last_pitch_val) + ///< << 16) / #MAX_FRAMESIZE + float silence_gain; ///< set for use in blocks if #ACB_TYPE_NONE + + int aw_idx_is_ext; ///< whether the AW index was encoded in + ///< 8 bits (instead of 6) + int aw_pulse_range; ///< the range over which #aw_pulse_set1() + ///< can apply the pulse, relative to the + ///< value in aw_first_pulse_off. The exact + ///< position of the first AW-pulse is within + ///< [pulse_off, pulse_off + this], and + ///< depends on bitstream values; [16 or 24] + int aw_n_pulses[2]; ///< number of AW-pulses in each block; note + ///< that this number can be negative (in + ///< which case it basically means "zero") + int aw_first_pulse_off[2]; ///< index of first sample to which to + ///< apply AW-pulses, or -0xff if unset + int aw_next_pulse_off_cache; ///< the position (relative to start of the + ///< second block) at which pulses should + ///< start to be positioned, serves as a + ///< cache for pitch-adaptive window pulses + ///< between blocks + + int frame_cntr; ///< current frame index [0 - 0xFFFE]; is + ///< only used for comfort noise in #pRNG() + float gain_pred_err[6]; ///< cache for gain prediction + float excitation_history[MAX_SIGNAL_HISTORY]; + ///< cache of the signal of previous + ///< superframes, used as a history for + ///< signal generation + float synth_history[MAX_LSPS]; ///< see #excitation_history + /** + * @} + * @defgroup post_filter Postfilter values + * Varibales used for postfilter implementation, mostly history for + * smoothing and so on, and context variables for FFT/iFFT. + * @{ + */ + RDFTContext rdft, irdft; ///< contexts for FFT-calculation in the + ///< postfilter (for denoise filter) + DCTContext dct, dst; ///< contexts for phase shift (in Hilbert + ///< transform, part of postfilter) + float sin[511], cos[511]; ///< 8-bit cosine/sine windows over [-pi,pi] + ///< range + float postfilter_agc; ///< gain control memory, used in + ///< #adaptive_gain_control() + float dcf_mem[2]; ///< DC filter history + float zero_exc_pf[MAX_SIGNAL_HISTORY + MAX_SFRAMESIZE]; + ///< zero filter output (i.e. excitation) + ///< by postfilter + float denoise_filter_cache[MAX_FRAMESIZE]; + int denoise_filter_cache_size; ///< samples in #denoise_filter_cache + DECLARE_ALIGNED(16, float, tilted_lpcs_pf)[0x80]; + ///< aligned buffer for LPC tilting + DECLARE_ALIGNED(16, float, denoise_coeffs_pf)[0x80]; + ///< aligned buffer for denoise coefficients + DECLARE_ALIGNED(16, float, synth_filter_out_buf)[0x80 + MAX_LSPS_ALIGN16]; + ///< aligned buffer for postfilter speech + ///< synthesis + /** + * @} + */ +} WMAVoiceContext; + +/** + * Sets up the variable bit mode (VBM) tree from container extradata. + * @param gb bit I/O context. + * The bit context (s->gb) should be loaded with byte 23-46 of the + * container extradata (i.e. the ones containing the VBM tree). + * @param vbm_tree pointer to array to which the decoded VBM tree will be + * written. + * @return 0 on success, <0 on error. + */ +static av_cold int decode_vbmtree(GetBitContext *gb, int8_t vbm_tree[25]) +{ + static const uint8_t bits[] = { + 2, 2, 2, 4, 4, 4, + 6, 6, 6, 8, 8, 8, + 10, 10, 10, 12, 12, 12, + 14, 14, 14, 14 + }; + static const uint16_t codes[] = { + 0x0000, 0x0001, 0x0002, // 00/01/10 + 0x000c, 0x000d, 0x000e, // 11+00/01/10 + 0x003c, 0x003d, 0x003e, // 1111+00/01/10 + 0x00fc, 0x00fd, 0x00fe, // 111111+00/01/10 + 0x03fc, 0x03fd, 0x03fe, // 11111111+00/01/10 + 0x0ffc, 0x0ffd, 0x0ffe, // 1111111111+00/01/10 + 0x3ffc, 0x3ffd, 0x3ffe, 0x3fff // 111111111111+xx + }; + int cntr[8], n, res; + + memset(vbm_tree, 0xff, sizeof(vbm_tree)); + memset(cntr, 0, sizeof(cntr)); + for (n = 0; n < 17; n++) { + res = get_bits(gb, 3); + if (cntr[res] > 3) // should be >= 3 + (res == 7)) + return -1; + vbm_tree[res * 3 + cntr[res]++] = n; + } + INIT_VLC_STATIC(&frame_type_vlc, VLC_NBITS, sizeof(bits), + bits, 1, 1, codes, 2, 2, 132); + return 0; +} + +/** + * Set up decoder with parameters from demuxer (extradata etc.). + */ +static av_cold int wmavoice_decode_init(AVCodecContext *ctx) +{ + int n, flags, pitch_range, lsp16_flag; + WMAVoiceContext *s = ctx->priv_data; + + /** + * Extradata layout: + * - byte 0-18: WMAPro-in-WMAVoice extradata (see wmaprodec.c), + * - byte 19-22: flags field (annoyingly in LE; see below for known + * values), + * - byte 23-46: variable bitmode tree (really just 17 * 3 bits, + * rest is 0). + */ + if (ctx->extradata_size != 46) { + av_log(ctx, AV_LOG_ERROR, + "Invalid extradata size %d (should be 46)\n", + ctx->extradata_size); + return -1; + } + flags = AV_RL32(ctx->extradata + 18); + s->spillover_bitsize = 3 + av_ceil_log2(ctx->block_align); + s->do_apf = flags & 0x1; + if (s->do_apf) { + ff_rdft_init(&s->rdft, 7, DFT_R2C); + ff_rdft_init(&s->irdft, 7, IDFT_C2R); + ff_dct_init(&s->dct, 6, DCT_I); + ff_dct_init(&s->dst, 6, DST_I); + + ff_sine_window_init(s->cos, 256); + memcpy(&s->sin[255], s->cos, 256 * sizeof(s->cos[0])); + for (n = 0; n < 255; n++) { + s->sin[n] = -s->sin[510 - n]; + s->cos[510 - n] = s->cos[n]; + } + } + s->denoise_strength = (flags >> 2) & 0xF; + if (s->denoise_strength >= 12) { + av_log(ctx, AV_LOG_ERROR, + "Invalid denoise filter strength %d (max=11)\n", + s->denoise_strength); + return -1; + } + s->denoise_tilt_corr = !!(flags & 0x40); + s->dc_level = (flags >> 7) & 0xF; + s->lsp_q_mode = !!(flags & 0x2000); + s->lsp_def_mode = !!(flags & 0x4000); + lsp16_flag = flags & 0x1000; + if (lsp16_flag) { + s->lsps = 16; + s->frame_lsp_bitsize = 34; + s->sframe_lsp_bitsize = 60; + } else { + s->lsps = 10; + s->frame_lsp_bitsize = 24; + s->sframe_lsp_bitsize = 48; + } + for (n = 0; n < s->lsps; n++) + s->prev_lsps[n] = M_PI * (n + 1.0) / (s->lsps + 1.0); + + init_get_bits(&s->gb, ctx->extradata + 22, (ctx->extradata_size - 22) << 3); + if (decode_vbmtree(&s->gb, s->vbm_tree) < 0) { + av_log(ctx, AV_LOG_ERROR, "Invalid VBM tree; broken extradata?\n"); + return -1; + } + + 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; + s->pitch_nbits = av_ceil_log2(pitch_range); + s->last_pitch_val = 40; + s->last_acb_type = ACB_TYPE_NONE; + s->history_nsamples = s->max_pitch_val + 8; + + if (s->min_pitch_val < 1 || s->history_nsamples > MAX_SIGNAL_HISTORY) { + int min_sr = ((((1 << 8) - 50) * 400) + 0xFF) >> 8, + max_sr = ((((MAX_SIGNAL_HISTORY - 8) << 8) + 205) * 2000 / 37) >> 8; + + av_log(ctx, AV_LOG_ERROR, + "Unsupported samplerate %d (min=%d, max=%d)\n", + ctx->sample_rate, min_sr, max_sr); // 322-22097 Hz + + return -1; + } + + s->block_conv_table[0] = s->min_pitch_val; + s->block_conv_table[1] = (pitch_range * 25) >> 6; + 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; + 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 + + 2 * (s->block_conv_table[1] - 2 * s->min_pitch_val); + s->block_pitch_nbits = av_ceil_log2(s->block_pitch_range); + + ctx->sample_fmt = SAMPLE_FMT_FLT; + + return 0; +} + +/** + * @defgroup postfilter Postfilter functions + * Postfilter functions (gain control, wiener denoise filter, DC filter, + * kalman smoothening, plus surrounding code to wrap it) + * @{ + */ +/** + * Adaptive gain control (as used in postfilter). + * + * Identical to #ff_adaptive_gain_control() in acelp_vectors.c, except + * that the energy here is calculated using sum(abs(...)), whereas the + * other codecs (e.g. AMR-NB, SIPRO) use sqrt(dotproduct(...)). + * + * @param out output buffer for filtered samples + * @param in input buffer containing the samples as they are after the + * postfilter steps so far + * @param speech_synth input buffer containing speech synth before postfilter + * @param size input buffer size + * @param alpha exponential filter factor + * @param gain_mem pointer to filter memory (single float) + */ +static void adaptive_gain_control(float *out, const float *in, + const float *speech_synth, + int size, float alpha, float *gain_mem) +{ + int i; + float speech_energy = 0.0, postfilter_energy = 0.0, gain_scale_factor; + float mem = *gain_mem; + + for (i = 0; i < size; i++) { + speech_energy += fabsf(speech_synth[i]); + postfilter_energy += fabsf(in[i]); + } + gain_scale_factor = (1.0 - alpha) * speech_energy / postfilter_energy; + + for (i = 0; i < size; i++) { + mem = alpha * mem + gain_scale_factor; + out[i] = in[i] * mem; + } + + *gain_mem = mem; +} + +/** + * Kalman smoothing function. + * + * This function looks back pitch +/- 3 samples back into history to find + * the best fitting curve (that one giving the optimal gain of the two + * signals, i.e. the highest dot product between the two), and then + * uses that signal history to smoothen the output of the speech synthesis + * filter. + * + * @param s WMA Voice decoding context + * @param pitch pitch of the speech signal + * @param in input speech signal + * @param out output pointer for smoothened signal + * @param size input/output buffer size + * + * @returns -1 if no smoothening took place, e.g. because no optimal + * fit could be found, or 0 on success. + */ +static int kalman_smoothen(WMAVoiceContext *s, int pitch, + const float *in, float *out, int size) +{ + int n; + float optimal_gain = 0, dot; + const float *ptr = &in[-FFMAX(s->min_pitch_val, pitch - 3)], + *end = &in[-FFMIN(s->max_pitch_val, pitch + 3)], + *best_hist_ptr; + + /* find best fitting point in history */ + do { + dot = ff_dot_productf(in, ptr, size); + if (dot > optimal_gain) { + optimal_gain = dot; + best_hist_ptr = ptr; + } + } while (--ptr >= end); + + if (optimal_gain <= 0) + return -1; + dot = ff_dot_productf(best_hist_ptr, best_hist_ptr, size); + if (dot <= 0) // would be 1.0 + return -1; + + if (optimal_gain <= dot) { + dot = dot / (dot + 0.6 * optimal_gain); // 0.625-1.000 + } else + dot = 0.625; + + /* actual smoothing */ + for (n = 0; n < size; n++) + out[n] = best_hist_ptr[n] + dot * (in[n] - best_hist_ptr[n]); + + return 0; +} + +/** + * Get the tilt factor of a formant filter from its transfer function + * @see #tilt_factor() in amrnbdec.c, which does essentially the same, + * but somehow (??) it does a speech synthesis filter in the + * middle, which is missing here + * + * @param lpcs LPC coefficients + * @param n_lpcs Size of LPC buffer + * @returns the tilt factor + */ +static float tilt_factor(const float *lpcs, int n_lpcs) +{ + float rh0, rh1; + + rh0 = 1.0 + ff_dot_productf(lpcs, lpcs, n_lpcs); + rh1 = lpcs[0] + ff_dot_productf(lpcs, &lpcs[1], n_lpcs - 1); + + return rh1 / rh0; +} + +/** + * Derive denoise filter coefficients (in real domain) from the LPCs. + */ +static void calc_input_response(WMAVoiceContext *s, float *lpcs, + int fcb_type, float *coeffs, int remainder) +{ + float last_coeff, min = 15.0, max = -15.0; + float irange, angle_mul, gain_mul, range, sq; + int n, idx; + + /* Create frequency power spectrum of speech input (i.e. RDFT of LPCs) */ + ff_rdft_calc(&s->rdft, lpcs); +#define log_range(var, assign) do { \ + float tmp = log10f(assign); var = tmp; \ + max = FFMAX(max, tmp); min = FFMIN(min, tmp); \ + } while (0) + log_range(last_coeff, lpcs[1] * lpcs[1]); + for (n = 1; n < 64; n++) + log_range(lpcs[n], lpcs[n * 2] * lpcs[n * 2] + + lpcs[n * 2 + 1] * lpcs[n * 2 + 1]); + log_range(lpcs[0], lpcs[0] * lpcs[0]); +#undef log_range + range = max - min; + lpcs[64] = last_coeff; + + /* Now, use this spectrum to pick out these frequencies with higher + * (relative) power/energy (which we then take to be "not noise"), + * and set up a table (still in lpc[]) of (relative) gains per frequency. + * These frequencies will be maintained, while others ("noise") will be + * decreased in the filter output. */ + irange = 64.0 / range; // so irange*(max-value) is in the range [0, 63] + gain_mul = range * (fcb_type == FCB_TYPE_HARDCODED ? (5.0 / 13.0) : + (5.0 / 14.7)); + angle_mul = gain_mul * (8.0 * M_LN10 / M_PI); + for (n = 0; n <= 64; n++) { + float pow; + + idx = FFMAX(0, lrint((max - lpcs[n]) * irange) - 1); + pow = wmavoice_denoise_power_table[s->denoise_strength][idx]; + lpcs[n] = angle_mul * pow; + + /* 70.57 =~ 1/log10(1.0331663) */ + idx = (pow * gain_mul - 0.0295) * 70.570526123; + if (idx > 127) { // fallback if index falls outside table range + coeffs[n] = wmavoice_energy_table[127] * + powf(1.0331663, idx - 127); + } else + coeffs[n] = wmavoice_energy_table[FFMAX(0, idx)]; + } + + /* calculate the Hilbert transform of the gains, which we do (since this + * is a sinus input) by doing a phase shift (in theory, H(sin())=cos()). + * Hilbert_Transform(RDFT(x)) = Laplace_Transform(x), which calculates the + * "moment" of the LPCs in this filter. */ + ff_dct_calc(&s->dct, lpcs); + ff_dct_calc(&s->dst, lpcs); + + /* Split out the coefficient indexes into phase/magnitude pairs */ + idx = 255 + av_clip(lpcs[64], -255, 255); + coeffs[0] = coeffs[0] * s->cos[idx]; + idx = 255 + av_clip(lpcs[64] - 2 * lpcs[63], -255, 255); + last_coeff = coeffs[64] * s->cos[idx]; + for (n = 63;; n--) { + idx = 255 + av_clip(-lpcs[64] - 2 * lpcs[n - 1], -255, 255); + coeffs[n * 2 + 1] = coeffs[n] * s->sin[idx]; + coeffs[n * 2] = coeffs[n] * s->cos[idx]; + + if (!--n) break; + + idx = 255 + av_clip( lpcs[64] - 2 * lpcs[n - 1], -255, 255); + coeffs[n * 2 + 1] = coeffs[n] * s->sin[idx]; + coeffs[n * 2] = coeffs[n] * s->cos[idx]; + } + coeffs[1] = last_coeff; + + /* move into real domain */ + ff_rdft_calc(&s->irdft, coeffs); + + /* tilt correction and normalize scale */ + memset(&coeffs[remainder], 0, sizeof(coeffs[0]) * (128 - remainder)); + if (s->denoise_tilt_corr) { + float tilt_mem = 0; + + coeffs[remainder - 1] = 0; + ff_tilt_compensation(&tilt_mem, + -1.8 * tilt_factor(coeffs, remainder - 1), + coeffs, remainder); + } + sq = (1.0 / 64.0) * sqrtf(1 / ff_dot_productf(coeffs, coeffs, remainder)); + for (n = 0; n < remainder; n++) + coeffs[n] *= sq; +} + +/** + * This function applies a Wiener filter on the (noisy) speech signal as + * a means to denoise it. + * + * - take RDFT of LPCs to get the power spectrum of the noise + speech; + * - using this power spectrum, calculate (for each frequency) the Wiener + * filter gain, which depends on the frequency power and desired level + * of noise subtraction (when set too high, this leads to artifacts) + * We can do this symmetrically over the X-axis (so 0-4kHz is the inverse + * of 4-8kHz); + * - by doing a phase shift, calculate the Hilbert transform of this array + * of per-frequency filter-gains to get the filtering coefficients; + * - smoothen/normalize/de-tilt these filter coefficients as desired; + * - take RDFT of noisy sound, apply the coefficients and take its IRDFT + * to get the denoised speech signal; + * - the leftover (i.e. output of the IRDFT on denoised speech data beyond + * the frame boundary) are saved and applied to subsequent frames by an + * overlap-add method (otherwise you get clicking-artifacts). + * + * @param s WMA Voice decoding context + * @param s fcb_type Frame (codebook) type + * @param synth_pf input: the noisy speech signal, output: denoised speech + * data; should be 16-byte aligned (for ASM purposes) + * @param size size of the speech data + * @param lpcs LPCs used to synthesize this frame's speech data + */ +static void wiener_denoise(WMAVoiceContext *s, int fcb_type, + float *synth_pf, int size, + const float *lpcs) +{ + int remainder, lim, n; + + if (fcb_type != FCB_TYPE_SILENCE) { + float *tilted_lpcs = s->tilted_lpcs_pf, + *coeffs = s->denoise_coeffs_pf, tilt_mem = 0; + + tilted_lpcs[0] = 1.0; + memcpy(&tilted_lpcs[1], lpcs, sizeof(lpcs[0]) * s->lsps); + memset(&tilted_lpcs[s->lsps + 1], 0, + sizeof(tilted_lpcs[0]) * (128 - s->lsps - 1)); + ff_tilt_compensation(&tilt_mem, 0.7 * tilt_factor(lpcs, s->lsps), + tilted_lpcs, s->lsps + 2); + + /* The IRDFT output (127 samples for 7-bit filter) beyond the frame + * size is applied to the next frame. All input beyond this is zero, + * and thus all output beyond this will go towards zero, hence we can + * limit to min(size-1, 127-size) as a performance consideration. */ + remainder = FFMIN(127 - size, size - 1); + calc_input_response(s, tilted_lpcs, fcb_type, coeffs, remainder); + + /* apply coefficients (in frequency spectrum domain), i.e. complex + * number multiplication */ + memset(&synth_pf[size], 0, sizeof(synth_pf[0]) * (128 - size)); + ff_rdft_calc(&s->rdft, synth_pf); + ff_rdft_calc(&s->rdft, coeffs); + synth_pf[0] *= coeffs[0]; + synth_pf[1] *= coeffs[1]; + for (n = 1; n < 64; n++) { + float v1 = synth_pf[n * 2], v2 = synth_pf[n * 2 + 1]; + synth_pf[n * 2] = v1 * coeffs[n * 2] - v2 * coeffs[n * 2 + 1]; + synth_pf[n * 2 + 1] = v2 * coeffs[n * 2] + v1 * coeffs[n * 2 + 1]; + } + ff_rdft_calc(&s->irdft, synth_pf); + } + + /* merge filter output with the history of previous runs */ + if (s->denoise_filter_cache_size) { + lim = FFMIN(s->denoise_filter_cache_size, size); + for (n = 0; n < lim; n++) + synth_pf[n] += s->denoise_filter_cache[n]; + s->denoise_filter_cache_size -= lim; + memmove(s->denoise_filter_cache, &s->denoise_filter_cache[size], + sizeof(s->denoise_filter_cache[0]) * s->denoise_filter_cache_size); + } + + /* move remainder of filter output into a cache for future runs */ + if (fcb_type != FCB_TYPE_SILENCE) { + lim = FFMIN(remainder, s->denoise_filter_cache_size); + for (n = 0; n < lim; n++) + s->denoise_filter_cache[n] += synth_pf[size + n]; + if (lim < remainder) { + memcpy(&s->denoise_filter_cache[lim], &synth_pf[size + lim], + sizeof(s->denoise_filter_cache[0]) * (remainder - lim)); + s->denoise_filter_cache_size = remainder; + } + } +} + +/** + * Averaging projection filter, the postfilter used in WMAVoice. + * + * This uses the following steps: + * - A zero-synthesis filter (generate excitation from synth signal) + * - Kalman smoothing on excitation, based on pitch + * - Re-synthesized smoothened output + * - Iterative Wiener denoise filter + * - Adaptive gain filter + * - DC filter + * + * @param s WMAVoice decoding context + * @param synth Speech synthesis output (before postfilter) + * @param samples Output buffer for filtered samples + * @param size Buffer size of synth & samples + * @param lpcs Generated LPCs used for speech synthesis + * @param fcb_type Frame type (silence, hardcoded, AW-pulses or FCB-pulses) + * @param pitch Pitch of the input signal + */ +static void postfilter(WMAVoiceContext *s, const float *synth, + float *samples, int size, + const float *lpcs, float *zero_exc_pf, + int fcb_type, int pitch) +{ + float synth_filter_in_buf[MAX_FRAMESIZE / 2], + *synth_pf = &s->synth_filter_out_buf[MAX_LSPS_ALIGN16], + *synth_filter_in = zero_exc_pf; + + assert(size <= MAX_FRAMESIZE / 2); + + /* generate excitation from input signal */ + ff_celp_lp_zero_synthesis_filterf(zero_exc_pf, lpcs, synth, size, s->lsps); + + if (fcb_type >= FCB_TYPE_AW_PULSES && + !kalman_smoothen(s, pitch, zero_exc_pf, synth_filter_in_buf, size)) + synth_filter_in = synth_filter_in_buf; + + /* re-synthesize speech after smoothening, and keep history */ + ff_celp_lp_synthesis_filterf(synth_pf, lpcs, + synth_filter_in, size, s->lsps); + memcpy(&synth_pf[-s->lsps], &synth_pf[size - s->lsps], + sizeof(synth_pf[0]) * s->lsps); + + wiener_denoise(s, fcb_type, synth_pf, size, lpcs); + + adaptive_gain_control(samples, synth_pf, synth, size, 0.99, + &s->postfilter_agc); + + if (s->dc_level > 8) { + /* remove ultra-low frequency DC noise / highpass filter; + * coefficients are identical to those used in SIPR decoding, + * and very closely resemble those used in AMR-NB decoding. */ + ff_acelp_apply_order_2_transfer_function(samples, samples, + (const float[2]) { -1.99997, 1.0 }, + (const float[2]) { -1.9330735188, 0.93589198496 }, + 0.93980580475, s->dcf_mem, size); + } +} +/** + * @} + */ + +/** + * Dequantize LSPs + * @param lsps output pointer to the array that will hold the LSPs + * @param num number of LSPs to be dequantized + * @param values quantized values, contains n_stages values + * @param sizes range (i.e. max value) of each quantized value + * @param n_stages number of dequantization runs + * @param table dequantization table to be used + * @param mul_q LSF multiplier + * @param base_q base (lowest) LSF values + */ +static void dequant_lsps(double *lsps, int num, + const uint16_t *values, + const uint16_t *sizes, + int n_stages, const uint8_t *table, + const double *mul_q, + const double *base_q) +{ + int n, m; + + memset(lsps, 0, num * sizeof(*lsps)); + for (n = 0; n < n_stages; n++) { + const uint8_t *t_off = &table[values[n] * num]; + double base = base_q[n], mul = mul_q[n]; + + for (m = 0; m < num; m++) + lsps[m] += base + mul * t_off[m]; + + table += sizes[n] * num; + } +} + +/** + * @defgroup lsp_dequant LSP dequantization routines + * LSP dequantization routines, for 10/16LSPs and independent/residual coding. + * @note we assume enough bits are available, caller should check. + * lsp10i() consumes 24 bits; lsp10r() consumes an additional 24 bits; + * lsp16i() consumes 34 bits; lsp16r() consumes an additional 26 bits. + * @{ + */ +/** + * Parse 10 independently-coded LSPs. + */ +static void dequant_lsp10i(GetBitContext *gb, double *lsps) +{ + static const uint16_t vec_sizes[4] = { 256, 64, 32, 32 }; + static const double mul_lsf[4] = { + 5.2187144800e-3, 1.4626986422e-3, + 9.6179549166e-4, 1.1325736225e-3 + }; + static const double base_lsf[4] = { + M_PI * -2.15522e-1, M_PI * -6.1646e-2, + M_PI * -3.3486e-2, M_PI * -5.7408e-2 + }; + uint16_t v[4]; + + v[0] = get_bits(gb, 8); + v[1] = get_bits(gb, 6); + v[2] = get_bits(gb, 5); + v[3] = get_bits(gb, 5); + + dequant_lsps(lsps, 10, v, vec_sizes, 4, wmavoice_dq_lsp10i, + mul_lsf, base_lsf); +} + +/** + * Parse 10 independently-coded LSPs, and then derive the tables to + * generate LSPs for the other frames from them (residual coding). + */ +static void dequant_lsp10r(GetBitContext *gb, + double *i_lsps, const double *old, + double *a1, double *a2, int q_mode) +{ + static const uint16_t vec_sizes[3] = { 128, 64, 64 }; + static const double mul_lsf[3] = { + 2.5807601174e-3, 1.2354460219e-3, 1.1763821673e-3 + }; + static const double base_lsf[3] = { + M_PI * -1.07448e-1, M_PI * -5.2706e-2, M_PI * -5.1634e-2 + }; + const float (*ipol_tab)[2][10] = q_mode ? + wmavoice_lsp10_intercoeff_b : wmavoice_lsp10_intercoeff_a; + uint16_t interpol, v[3]; + int n; + + dequant_lsp10i(gb, i_lsps); + + interpol = get_bits(gb, 5); + v[0] = get_bits(gb, 7); + v[1] = get_bits(gb, 6); + v[2] = get_bits(gb, 6); + + for (n = 0; n < 10; n++) { + double delta = old[n] - i_lsps[n]; + a1[n] = ipol_tab[interpol][0][n] * delta + i_lsps[n]; + a1[10 + n] = ipol_tab[interpol][1][n] * delta + i_lsps[n]; + } + + dequant_lsps(a2, 20, v, vec_sizes, 3, wmavoice_dq_lsp10r, + mul_lsf, base_lsf); +} + +/** + * Parse 16 independently-coded LSPs. + */ +static void dequant_lsp16i(GetBitContext *gb, double *lsps) +{ + static const uint16_t vec_sizes[5] = { 256, 64, 128, 64, 128 }; + static const double mul_lsf[5] = { + 3.3439586280e-3, 6.9908173703e-4, + 3.3216608306e-3, 1.0334960326e-3, + 3.1899104283e-3 + }; + static const double base_lsf[5] = { + M_PI * -1.27576e-1, M_PI * -2.4292e-2, + M_PI * -1.28094e-1, M_PI * -3.2128e-2, + M_PI * -1.29816e-1 + }; + uint16_t v[5]; + + v[0] = get_bits(gb, 8); + v[1] = get_bits(gb, 6); + v[2] = get_bits(gb, 7); + v[3] = get_bits(gb, 6); + v[4] = get_bits(gb, 7); + + dequant_lsps( lsps, 5, v, vec_sizes, 2, + wmavoice_dq_lsp16i1, mul_lsf, base_lsf); + dequant_lsps(&lsps[5], 5, &v[2], &vec_sizes[2], 2, + wmavoice_dq_lsp16i2, &mul_lsf[2], &base_lsf[2]); + dequant_lsps(&lsps[10], 6, &v[4], &vec_sizes[4], 1, + wmavoice_dq_lsp16i3, &mul_lsf[4], &base_lsf[4]); +} + +/** + * Parse 16 independently-coded LSPs, and then derive the tables to + * generate LSPs for the other frames from them (residual coding). + */ +static void dequant_lsp16r(GetBitContext *gb, + double *i_lsps, const double *old, + double *a1, double *a2, int q_mode) +{ + static const uint16_t vec_sizes[3] = { 128, 128, 128 }; + static const double mul_lsf[3] = { + 1.2232979501e-3, 1.4062241527e-3, 1.6114744851e-3 + }; + static const double base_lsf[3] = { + M_PI * -5.5830e-2, M_PI * -5.2908e-2, M_PI * -5.4776e-2 + }; + const float (*ipol_tab)[2][16] = q_mode ? + wmavoice_lsp16_intercoeff_b : wmavoice_lsp16_intercoeff_a; + uint16_t interpol, v[3]; + int n; + + dequant_lsp16i(gb, i_lsps); + + interpol = get_bits(gb, 5); + v[0] = get_bits(gb, 7); + v[1] = get_bits(gb, 7); + v[2] = get_bits(gb, 7); + + for (n = 0; n < 16; n++) { + double delta = old[n] - i_lsps[n]; + a1[n] = ipol_tab[interpol][0][n] * delta + i_lsps[n]; + a1[16 + n] = ipol_tab[interpol][1][n] * delta + i_lsps[n]; + } + + dequant_lsps( a2, 10, v, vec_sizes, 1, + wmavoice_dq_lsp16r1, mul_lsf, base_lsf); + dequant_lsps(&a2[10], 10, &v[1], &vec_sizes[1], 1, + wmavoice_dq_lsp16r2, &mul_lsf[1], &base_lsf[1]); + dequant_lsps(&a2[20], 12, &v[2], &vec_sizes[2], 1, + wmavoice_dq_lsp16r3, &mul_lsf[2], &base_lsf[2]); +} + +/** + * @} + * @defgroup aw Pitch-adaptive window coding functions + * The next few functions are for pitch-adaptive window coding. + * @{ + */ +/** + * Parse the offset of the first pitch-adaptive window pulses, and + * the distribution of pulses between the two blocks in this frame. + * @param s WMA Voice decoding context private data + * @param gb bit I/O context + * @param pitch pitch for each block in this frame + */ +static void aw_parse_coords(WMAVoiceContext *s, GetBitContext *gb, + const int *pitch) +{ + static const int16_t start_offset[94] = { + -11, -9, -7, -5, -3, -1, 1, 3, 5, 7, 9, 11, + 13, 15, 18, 17, 19, 20, 21, 22, 23, 24, 25, 26, + 27, 28, 29, 30, 31, 32, 33, 35, 37, 39, 41, 43, + 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, + 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, + 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, + 117, 119, 121, 123, 125, 127, 129, 131, 133, 135, 137, 139, + 141, 143, 145, 147, 149, 151, 153, 155, 157, 159 + }; + int bits, offset; + + /* position of pulse */ + s->aw_idx_is_ext = 0; + if ((bits = get_bits(gb, 6)) >= 54) { + s->aw_idx_is_ext = 1; + bits += (bits - 54) * 3 + get_bits(gb, 2); + } + + /* for a repeated pulse at pulse_off with a pitch_lag of pitch[], count + * the distribution of the pulses in each block contained in this frame. */ + s->aw_pulse_range = FFMIN(pitch[0], pitch[1]) > 32 ? 24 : 16; + for (offset = start_offset[bits]; offset < 0; offset += pitch[0]) ; + s->aw_n_pulses[0] = (pitch[0] - 1 + MAX_FRAMESIZE / 2 - offset) / pitch[0]; + s->aw_first_pulse_off[0] = offset - s->aw_pulse_range / 2; + offset += s->aw_n_pulses[0] * pitch[0]; + s->aw_n_pulses[1] = (pitch[1] - 1 + MAX_FRAMESIZE - offset) / pitch[1]; + s->aw_first_pulse_off[1] = offset - (MAX_FRAMESIZE + s->aw_pulse_range) / 2; + + /* if continuing from a position before the block, reset position to + * start of block (when corrected for the range over which it can be + * spread in aw_pulse_set1()). */ + if (start_offset[bits] < MAX_FRAMESIZE / 2) { + while (s->aw_first_pulse_off[1] - pitch[1] + s->aw_pulse_range > 0) + s->aw_first_pulse_off[1] -= pitch[1]; + if (start_offset[bits] < 0) + while (s->aw_first_pulse_off[0] - pitch[0] + s->aw_pulse_range > 0) + s->aw_first_pulse_off[0] -= pitch[0]; + } +} + +/** + * Apply second set of pitch-adaptive window pulses. + * @param s WMA Voice decoding context private data + * @param gb bit I/O context + * @param block_idx block index in frame [0, 1] + * @param fcb structure containing fixed codebook vector info + */ +static void aw_pulse_set2(WMAVoiceContext *s, GetBitContext *gb, + int block_idx, AMRFixed *fcb) +{ + uint16_t use_mask[7]; // only 5 are used, rest is padding + /* in this function, idx is the index in the 80-bit (+ padding) use_mask + * bit-array. Since use_mask consists of 16-bit values, the lower 4 bits + * of idx are the position of the bit within a particular item in the + * array (0 being the most significant bit, and 15 being the least + * significant bit), and the remainder (>> 4) is the index in the + * use_mask[]-array. This is faster and uses less memory than using a + * 80-byte/80-int array. */ + int pulse_off = s->aw_first_pulse_off[block_idx], + pulse_start, n, idx, range, aidx, start_off = 0; + + /* set offset of first pulse to within this block */ + if (s->aw_n_pulses[block_idx] > 0) + while (pulse_off + s->aw_pulse_range < 1) + pulse_off += fcb->pitch_lag; + + /* find range per pulse */ + if (s->aw_n_pulses[0] > 0) { + if (block_idx == 0) { + range = 32; + } else /* block_idx = 1 */ { + range = 8; + if (s->aw_n_pulses[block_idx] > 0) + pulse_off = s->aw_next_pulse_off_cache; + } + } else + range = 16; + pulse_start = s->aw_n_pulses[block_idx] > 0 ? pulse_off - range / 2 : 0; + + /* aw_pulse_set1() already applies pulses around pulse_off (to be exactly, + * in the range of [pulse_off, pulse_off + s->aw_pulse_range], and thus + * we exclude that range from being pulsed again in this function. */ + memset( use_mask, -1, 5 * sizeof(use_mask[0])); + memset(&use_mask[5], 0, 2 * sizeof(use_mask[0])); + if (s->aw_n_pulses[block_idx] > 0) + for (idx = pulse_off; idx < MAX_FRAMESIZE / 2; idx += fcb->pitch_lag) { + 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; + excl_range -= first_sh; + if (excl_range >= 16) { + *use_mask_ptr++ = 0; + *use_mask_ptr &= 0xFFFF >> (excl_range - 16); + } else + *use_mask_ptr &= 0xFFFF >> excl_range; + } + + /* find the 'aidx'th offset that is not excluded */ + aidx = get_bits(gb, s->aw_n_pulses[0] > 0 ? 5 - 2 * block_idx : 4); + for (n = 0; n <= aidx; pulse_start++) { + for (idx = pulse_start; idx < 0; idx += fcb->pitch_lag) ; + if (idx >= MAX_FRAMESIZE / 2) { // find from zero + if (use_mask[0]) idx = 0x0F; + else if (use_mask[1]) idx = 0x1F; + else if (use_mask[2]) idx = 0x2F; + else if (use_mask[3]) idx = 0x3F; + else if (use_mask[4]) idx = 0x4F; + else return; + idx -= av_log2_16bit(use_mask[idx >> 4]); + } + if (use_mask[idx >> 4] & (0x8000 >> (idx & 15))) { + use_mask[idx >> 4] &= ~(0x8000 >> (idx & 15)); + n++; + start_off = idx; + } + } + + fcb->x[fcb->n] = start_off; + fcb->y[fcb->n] = get_bits1(gb) ? -1.0 : 1.0; + fcb->n++; + + /* set offset for next block, relative to start of that block */ + n = (MAX_FRAMESIZE / 2 - start_off) % fcb->pitch_lag; + s->aw_next_pulse_off_cache = n ? fcb->pitch_lag - n : 0; +} + +/** + * Apply first set of pitch-adaptive window pulses. + * @param s WMA Voice decoding context private data + * @param gb bit I/O context + * @param block_idx block index in frame [0, 1] + * @param fcb storage location for fixed codebook pulse info + */ +static void aw_pulse_set1(WMAVoiceContext *s, GetBitContext *gb, + int block_idx, AMRFixed *fcb) +{ + int val = get_bits(gb, 12 - 2 * (s->aw_idx_is_ext && !block_idx)); + float v; + + if (s->aw_n_pulses[block_idx] > 0) { + int n, v_mask, i_mask, sh, n_pulses; + + if (s->aw_pulse_range == 24) { // 3 pulses, 1:sign + 3:index each + n_pulses = 3; + v_mask = 8; + i_mask = 7; + sh = 4; + } else { // 4 pulses, 1:sign + 2:index each + n_pulses = 4; + v_mask = 4; + i_mask = 3; + sh = 3; + } + + for (n = n_pulses - 1; n >= 0; n--, val >>= sh) { + fcb->y[fcb->n] = (val & v_mask) ? -1.0 : 1.0; + fcb->x[fcb->n] = (val & i_mask) * n_pulses + n + + s->aw_first_pulse_off[block_idx]; + while (fcb->x[fcb->n] < 0) + fcb->x[fcb->n] += fcb->pitch_lag; + if (fcb->x[fcb->n] < MAX_FRAMESIZE / 2) + fcb->n++; + } + } else { + int num2 = (val & 0x1FF) >> 1, delta, idx; + + if (num2 < 1 * 79) { delta = 1; idx = num2 + 1; } + else if (num2 < 2 * 78) { delta = 3; idx = num2 + 1 - 1 * 77; } + else if (num2 < 3 * 77) { delta = 5; idx = num2 + 1 - 2 * 76; } + else { delta = 7; idx = num2 + 1 - 3 * 75; } + v = (val & 0x200) ? -1.0 : 1.0; + + fcb->no_repeat_mask |= 3 << fcb->n; + fcb->x[fcb->n] = idx - delta; + fcb->y[fcb->n] = v; + fcb->x[fcb->n + 1] = idx; + fcb->y[fcb->n + 1] = (val & 1) ? -v : v; + fcb->n += 2; + } +} + +/** + * @} + * + * Generate a random number from frame_cntr and block_idx, which will lief + * in the range [0, 1000 - block_size] (so it can be used as an index in a + * table of size 1000 of which you want to read block_size entries). + * + * @param frame_cntr current frame number + * @param block_num current block index + * @param block_size amount of entries we want to read from a table + * that has 1000 entries + * @return a (non-)random number in the [0, 1000 - block_size] range. + */ +static int pRNG(int frame_cntr, int block_num, int block_size) +{ + /* array to simplify the calculation of z: + * y = (x % 9) * 5 + 6; + * z = (49995 * x) / y; + * Since y only has 9 values, we can remove the division by using a + * LUT and using FASTDIV-style divisions. For each of the 9 values + * of y, we can rewrite z as: + * z = x * (49995 / y) + x * ((49995 % y) / y) + * In this table, each col represents one possible value of y, the + * first number is 49995 / y, and the second is the FASTDIV variant + * of 49995 % y / y. */ + static const unsigned int div_tbl[9][2] = { + { 8332, 3 * 715827883U }, // y = 6 + { 4545, 0 * 390451573U }, // y = 11 + { 3124, 11 * 268435456U }, // y = 16 + { 2380, 15 * 204522253U }, // y = 21 + { 1922, 23 * 165191050U }, // y = 26 + { 1612, 23 * 138547333U }, // y = 31 + { 1388, 27 * 119304648U }, // y = 36 + { 1219, 16 * 104755300U }, // y = 41 + { 1086, 39 * 93368855U } // y = 46 + }; + unsigned int z, y, x = MUL16(block_num, 1877) + frame_cntr; + if (x >= 0xFFFF) x -= 0xFFFF; // max value of x is 8*1877+0xFFFE=0x13AA6, + // so this is effectively a modulo (%) + y = x - 9 * MULH(477218589, x); // x % 9 + z = (uint16_t) (x * div_tbl[y][0] + UMULH(x, div_tbl[y][1])); + // z = x * 49995 / (y * 5 + 6) + return z % (1000 - block_size); +} + +/** + * Parse hardcoded signal for a single block. + * @note see #synth_block(). + */ +static void synth_block_hardcoded(WMAVoiceContext *s, GetBitContext *gb, + int block_idx, int size, + const struct frame_type_desc *frame_desc, + float *excitation) +{ + float gain; + int n, r_idx; + + assert(size <= MAX_FRAMESIZE); + + /* Set the offset from which we start reading wmavoice_std_codebook */ + if (frame_desc->fcb_type == FCB_TYPE_SILENCE) { + r_idx = pRNG(s->frame_cntr, block_idx, size); + gain = s->silence_gain; + } else /* FCB_TYPE_HARDCODED */ { + r_idx = get_bits(gb, 8); + gain = wmavoice_gain_universal[get_bits(gb, 6)]; + } + + /* Clear gain prediction parameters */ + memset(s->gain_pred_err, 0, sizeof(s->gain_pred_err)); + + /* Apply gain to hardcoded codebook and use that as excitation signal */ + for (n = 0; n < size; n++) + excitation[n] = wmavoice_std_codebook[r_idx + n] * gain; +} + +/** + * Parse FCB/ACB signal for a single block. + * @note see #synth_block(). + */ +static void synth_block_fcb_acb(WMAVoiceContext *s, GetBitContext *gb, + int block_idx, int size, + int block_pitch_sh2, + const struct frame_type_desc *frame_desc, + float *excitation) +{ + static const float gain_coeff[6] = { + 0.8169, -0.06545, 0.1726, 0.0185, -0.0359, 0.0458 + }; + float pulses[MAX_FRAMESIZE / 2], pred_err, acb_gain, fcb_gain; + int n, idx, gain_weight; + AMRFixed fcb; + + assert(size <= MAX_FRAMESIZE / 2); + memset(pulses, 0, sizeof(*pulses) * size); + + fcb.pitch_lag = block_pitch_sh2 >> 2; + fcb.pitch_fac = 1.0; + fcb.no_repeat_mask = 0; + fcb.n = 0; + + /* For the other frame types, this is where we apply the innovation + * (fixed) codebook pulses of the speech signal. */ + if (frame_desc->fcb_type == FCB_TYPE_AW_PULSES) { + aw_pulse_set1(s, gb, block_idx, &fcb); + aw_pulse_set2(s, gb, block_idx, &fcb); + } else /* FCB_TYPE_EXC_PULSES */ { + int offset_nbits = 5 - frame_desc->log_n_blocks; + + fcb.no_repeat_mask = -1; + /* similar to ff_decode_10_pulses_35bits(), but with single pulses + * (instead of double) for a subset of pulses */ + for (n = 0; n < 5; n++) { + float sign; + int pos1, pos2; + + sign = get_bits1(gb) ? 1.0 : -1.0; + pos1 = get_bits(gb, offset_nbits); + fcb.x[fcb.n] = n + 5 * pos1; + fcb.y[fcb.n++] = sign; + if (n < frame_desc->dbl_pulses) { + pos2 = get_bits(gb, offset_nbits); + fcb.x[fcb.n] = n + 5 * pos2; + fcb.y[fcb.n++] = (pos1 < pos2) ? -sign : sign; + } + } + } + ff_set_fixed_vector(pulses, &fcb, 1.0, size); + + /* Calculate gain for adaptive & fixed codebook signal. + * see ff_amr_set_fixed_gain(). */ + idx = get_bits(gb, 7); + fcb_gain = expf(ff_dot_productf(s->gain_pred_err, gain_coeff, 6) - + 5.2409161640 + wmavoice_gain_codebook_fcb[idx]); + acb_gain = wmavoice_gain_codebook_acb[idx]; + pred_err = av_clipf(wmavoice_gain_codebook_fcb[idx], + -2.9957322736 /* log(0.05) */, + 1.6094379124 /* log(5.0) */); + + gain_weight = 8 >> frame_desc->log_n_blocks; + memmove(&s->gain_pred_err[gain_weight], s->gain_pred_err, + sizeof(*s->gain_pred_err) * (6 - gain_weight)); + for (n = 0; n < gain_weight; n++) + s->gain_pred_err[n] = pred_err; + + /* Calculation of adaptive codebook */ + if (frame_desc->acb_type == ACB_TYPE_ASYMMETRIC) { + int len; + for (n = 0; n < size; n += len) { + int next_idx_sh16; + int abs_idx = block_idx * size + n; + int pitch_sh16 = (s->last_pitch_val << 16) + + s->pitch_diff_sh16 * abs_idx; + int pitch = (pitch_sh16 + 0x6FFF) >> 16; + int idx_sh16 = ((pitch << 16) - pitch_sh16) * 8 + 0x58000; + idx = idx_sh16 >> 16; + if (s->pitch_diff_sh16) { + if (s->pitch_diff_sh16 > 0) { + next_idx_sh16 = (idx_sh16) &~ 0xFFFF; + } else + next_idx_sh16 = (idx_sh16 + 0x10000) &~ 0xFFFF; + len = av_clip((idx_sh16 - next_idx_sh16) / s->pitch_diff_sh16 / 8, + 1, size - n); + } else + len = size; + + ff_acelp_interpolatef(&excitation[n], &excitation[n - pitch], + wmavoice_ipol1_coeffs, 17, + idx, 9, len); + } + } else /* ACB_TYPE_HAMMING */ { + int block_pitch = block_pitch_sh2 >> 2; + idx = block_pitch_sh2 & 3; + if (idx) { + ff_acelp_interpolatef(excitation, &excitation[-block_pitch], + wmavoice_ipol2_coeffs, 4, + idx, 8, size); + } else + av_memcpy_backptr(excitation, sizeof(float) * block_pitch, + sizeof(float) * size); + } + + /* Interpolate ACB/FCB and use as excitation signal */ + ff_weighted_vector_sumf(excitation, excitation, pulses, + acb_gain, fcb_gain, size); +} + +/** + * Parse data in a single block. + * @note we assume enough bits are available, caller should check. + * + * @param s WMA Voice decoding context private data + * @param gb bit I/O context + * @param block_idx index of the to-be-read block + * @param size amount of samples to be read in this block + * @param block_pitch_sh2 pitch for this block << 2 + * @param lsps LSPs for (the end of) this frame + * @param prev_lsps LSPs for the last frame + * @param frame_desc frame type descriptor + * @param excitation target memory for the ACB+FCB interpolated signal + * @param synth target memory for the speech synthesis filter output + * @return 0 on success, <0 on error. + */ +static void synth_block(WMAVoiceContext *s, GetBitContext *gb, + int block_idx, int size, + int block_pitch_sh2, + const double *lsps, const double *prev_lsps, + const struct frame_type_desc *frame_desc, + float *excitation, float *synth) +{ + double i_lsps[MAX_LSPS]; + float lpcs[MAX_LSPS]; + float fac; + int n; + + if (frame_desc->acb_type == ACB_TYPE_NONE) + synth_block_hardcoded(s, gb, block_idx, size, frame_desc, excitation); + else + synth_block_fcb_acb(s, gb, block_idx, size, block_pitch_sh2, + frame_desc, excitation); + + /* convert interpolated LSPs to LPCs */ + fac = (block_idx + 0.5) / frame_desc->n_blocks; + for (n = 0; n < s->lsps; n++) // LSF -> LSP + i_lsps[n] = cos(prev_lsps[n] + fac * (lsps[n] - prev_lsps[n])); + ff_acelp_lspd2lpc(i_lsps, lpcs, s->lsps >> 1); + + /* Speech synthesis */ + ff_celp_lp_synthesis_filterf(synth, lpcs, excitation, size, s->lsps); +} + +/** + * Synthesize output samples for a single frame. + * @note we assume enough bits are available, caller should check. + * + * @param ctx WMA Voice decoder context + * @param gb bit I/O context (s->gb or one for cross-packet superframes) + * @param frame_idx Frame number within superframe [0-2] + * @param samples pointer to output sample buffer, has space for at least 160 + * samples + * @param lsps LSP array + * @param prev_lsps array of previous frame's LSPs + * @param excitation target buffer for excitation signal + * @param synth target buffer for synthesized speech data + * @return 0 on success, <0 on error. + */ +static int synth_frame(AVCodecContext *ctx, GetBitContext *gb, int frame_idx, + float *samples, + const double *lsps, const double *prev_lsps, + float *excitation, float *synth) +{ + WMAVoiceContext *s = ctx->priv_data; + int n, n_blocks_x2, log_n_blocks_x2, cur_pitch_val; + int pitch[MAX_BLOCKS], last_block_pitch; + + /* Parse frame type ("frame header"), see frame_descs */ + int bd_idx = s->vbm_tree[get_vlc2(gb, frame_type_vlc.table, 6, 3)], + block_nsamples = MAX_FRAMESIZE / frame_descs[bd_idx].n_blocks; + + if (bd_idx < 0) { + av_log(ctx, AV_LOG_ERROR, + "Invalid frame type VLC code, skipping\n"); + return -1; + } + + /* Pitch calculation for ACB_TYPE_ASYMMETRIC ("pitch-per-frame") */ + if (frame_descs[bd_idx].acb_type == ACB_TYPE_ASYMMETRIC) { + /* Pitch is provided per frame, which is interpreted as the pitch of + * the last sample of the last block of this frame. We can interpolate + * the pitch of other blocks (and even pitch-per-sample) by gradually + * incrementing/decrementing prev_frame_pitch to cur_pitch_val. */ + n_blocks_x2 = frame_descs[bd_idx].n_blocks << 1; + log_n_blocks_x2 = frame_descs[bd_idx].log_n_blocks + 1; + cur_pitch_val = s->min_pitch_val + get_bits(gb, s->pitch_nbits); + cur_pitch_val = FFMIN(cur_pitch_val, s->max_pitch_val - 1); + if (s->last_acb_type == ACB_TYPE_NONE || + 20 * abs(cur_pitch_val - s->last_pitch_val) > + (cur_pitch_val + s->last_pitch_val)) + s->last_pitch_val = cur_pitch_val; + + /* pitch per block */ + for (n = 0; n < frame_descs[bd_idx].n_blocks; n++) { + int fac = n * 2 + 1; + + pitch[n] = (MUL16(fac, cur_pitch_val) + + MUL16((n_blocks_x2 - fac), s->last_pitch_val) + + frame_descs[bd_idx].n_blocks) >> log_n_blocks_x2; + } + + /* "pitch-diff-per-sample" for calculation of pitch per sample */ + s->pitch_diff_sh16 = + ((cur_pitch_val - s->last_pitch_val) << 16) / MAX_FRAMESIZE; + } + + /* Global gain (if silence) and pitch-adaptive window coordinates */ + switch (frame_descs[bd_idx].fcb_type) { + case FCB_TYPE_SILENCE: + s->silence_gain = wmavoice_gain_silence[get_bits(gb, 8)]; + break; + case FCB_TYPE_AW_PULSES: + aw_parse_coords(s, gb, pitch); + break; + } + + for (n = 0; n < frame_descs[bd_idx].n_blocks; n++) { + int bl_pitch_sh2; + + /* Pitch calculation for ACB_TYPE_HAMMING ("pitch-per-block") */ + switch (frame_descs[bd_idx].acb_type) { + case ACB_TYPE_HAMMING: { + /* Pitch is given per block. Per-block pitches are encoded as an + * absolute value for the first block, and then delta values + * relative to this value) for all subsequent blocks. The scale of + * this pitch value is semi-logaritmic compared to its use in the + * decoder, so we convert it to normal scale also. */ + int block_pitch, + t1 = (s->block_conv_table[1] - s->block_conv_table[0]) << 2, + t2 = (s->block_conv_table[2] - s->block_conv_table[1]) << 1, + t3 = s->block_conv_table[3] - s->block_conv_table[2] + 1; + + if (n == 0) { + block_pitch = get_bits(gb, s->block_pitch_nbits); + } else + block_pitch = last_block_pitch - s->block_delta_pitch_hrange + + get_bits(gb, s->block_delta_pitch_nbits); + /* Convert last_ so that any next delta is within _range */ + last_block_pitch = av_clip(block_pitch, + s->block_delta_pitch_hrange, + s->block_pitch_range - + s->block_delta_pitch_hrange); + + /* Convert semi-log-style scale back to normal scale */ + if (block_pitch < t1) { + bl_pitch_sh2 = (s->block_conv_table[0] << 2) + block_pitch; + } else { + block_pitch -= t1; + if (block_pitch < t2) { + bl_pitch_sh2 = + (s->block_conv_table[1] << 2) + (block_pitch << 1); + } else { + block_pitch -= t2; + if (block_pitch < t3) { + bl_pitch_sh2 = + (s->block_conv_table[2] + block_pitch) << 2; + } else + bl_pitch_sh2 = s->block_conv_table[3] << 2; + } + } + pitch[n] = bl_pitch_sh2 >> 2; + break; + } + + case ACB_TYPE_ASYMMETRIC: { + bl_pitch_sh2 = pitch[n] << 2; + break; + } + + default: // ACB_TYPE_NONE has no pitch + bl_pitch_sh2 = 0; + break; + } + + synth_block(s, gb, n, block_nsamples, bl_pitch_sh2, + lsps, prev_lsps, &frame_descs[bd_idx], + &excitation[n * block_nsamples], + &synth[n * block_nsamples]); + } + + /* Averaging projection filter, if applicable. Else, just copy samples + * from synthesis buffer */ + if (s->do_apf) { + double i_lsps[MAX_LSPS]; + float lpcs[MAX_LSPS]; + + for (n = 0; n < s->lsps; n++) // LSF -> LSP + i_lsps[n] = cos(0.5 * (prev_lsps[n] + lsps[n])); + ff_acelp_lspd2lpc(i_lsps, lpcs, s->lsps >> 1); + postfilter(s, synth, samples, 80, lpcs, + &s->zero_exc_pf[s->history_nsamples + MAX_FRAMESIZE * frame_idx], + frame_descs[bd_idx].fcb_type, pitch[0]); + + for (n = 0; n < s->lsps; n++) // LSF -> LSP + i_lsps[n] = cos(lsps[n]); + ff_acelp_lspd2lpc(i_lsps, lpcs, s->lsps >> 1); + postfilter(s, &synth[80], &samples[80], 80, lpcs, + &s->zero_exc_pf[s->history_nsamples + MAX_FRAMESIZE * frame_idx + 80], + frame_descs[bd_idx].fcb_type, pitch[0]); + } else + memcpy(samples, synth, 160 * sizeof(synth[0])); + + /* Cache values for next frame */ + s->frame_cntr++; + if (s->frame_cntr >= 0xFFFF) s->frame_cntr -= 0xFFFF; // i.e. modulo (%) + s->last_acb_type = frame_descs[bd_idx].acb_type; + switch (frame_descs[bd_idx].acb_type) { + case ACB_TYPE_NONE: + s->last_pitch_val = 0; + break; + case ACB_TYPE_ASYMMETRIC: + s->last_pitch_val = cur_pitch_val; + break; + case ACB_TYPE_HAMMING: + s->last_pitch_val = pitch[frame_descs[bd_idx].n_blocks - 1]; + break; + } + + return 0; +} + +/** + * Ensure minimum value for first item, maximum value for last value, + * proper spacing between each value and proper ordering. + * + * @param lsps array of LSPs + * @param num size of LSP array + * + * @note basically a double version of #ff_acelp_reorder_lsf(), might be + * useful to put in a generic location later on. Parts are also + * present in #ff_set_min_dist_lsf() + #ff_sort_nearly_sorted_floats(), + * which is in float. + */ +static void stabilize_lsps(double *lsps, int num) +{ + int n, m, l; + + /* set minimum value for first, maximum value for last and minimum + * spacing between LSF values. + * Very similar to ff_set_min_dist_lsf(), but in double. */ + lsps[0] = FFMAX(lsps[0], 0.0015 * M_PI); + for (n = 1; n < num; n++) + lsps[n] = FFMAX(lsps[n], lsps[n - 1] + 0.0125 * M_PI); + lsps[num - 1] = FFMIN(lsps[num - 1], 0.9985 * M_PI); + + /* reorder (looks like one-time / non-recursed bubblesort). + * Very similar to ff_sort_nearly_sorted_floats(), but in double. */ + for (n = 1; n < num; n++) { + if (lsps[n] < lsps[n - 1]) { + for (m = 1; m < num; m++) { + double tmp = lsps[m]; + for (l = m - 1; l >= 0; l--) { + if (lsps[l] <= tmp) break; + lsps[l + 1] = lsps[l]; + } + lsps[l + 1] = tmp; + } + break; + } + } +} + +/** + * Test if there's enough bits to read 1 superframe. + * + * @param orig_gb bit I/O context used for reading. This function + * does not modify the state of the bitreader; it + * only uses it to copy the current stream position + * @param s WMA Voice decoding context private data + * @return -1 if unsupported, 1 on not enough bits or 0 if OK. + */ +static int check_bits_for_superframe(GetBitContext *orig_gb, + WMAVoiceContext *s) +{ + GetBitContext s_gb, *gb = &s_gb; + int n, need_bits, bd_idx; + const struct frame_type_desc *frame_desc; + + /* initialize a copy */ + init_get_bits(gb, orig_gb->buffer, orig_gb->size_in_bits); + skip_bits_long(gb, get_bits_count(orig_gb)); + assert(get_bits_left(gb) == get_bits_left(orig_gb)); + + /* superframe header */ + if (get_bits_left(gb) < 14) + return 1; + if (!get_bits1(gb)) + return -1; // WMAPro-in-WMAVoice superframe + if (get_bits1(gb)) skip_bits(gb, 12); // number of samples in superframe + if (s->has_residual_lsps) { // residual LSPs (for all frames) + if (get_bits_left(gb) < s->sframe_lsp_bitsize) + return 1; + skip_bits_long(gb, s->sframe_lsp_bitsize); + } + + /* frames */ + for (n = 0; n < MAX_FRAMES; n++) { + int aw_idx_is_ext = 0; + + if (!s->has_residual_lsps) { // independent LSPs (per-frame) + if (get_bits_left(gb) < s->frame_lsp_bitsize) return 1; + skip_bits_long(gb, s->frame_lsp_bitsize); + } + bd_idx = s->vbm_tree[get_vlc2(gb, frame_type_vlc.table, 6, 3)]; + if (bd_idx < 0) + return -1; // invalid frame type VLC code + frame_desc = &frame_descs[bd_idx]; + if (frame_desc->acb_type == ACB_TYPE_ASYMMETRIC) { + if (get_bits_left(gb) < s->pitch_nbits) + return 1; + skip_bits_long(gb, s->pitch_nbits); + } + if (frame_desc->fcb_type == FCB_TYPE_SILENCE) { + skip_bits(gb, 8); + } else if (frame_desc->fcb_type == FCB_TYPE_AW_PULSES) { + int tmp = get_bits(gb, 6); + if (tmp >= 0x36) { + skip_bits(gb, 2); + aw_idx_is_ext = 1; + } + } + + /* blocks */ + if (frame_desc->acb_type == ACB_TYPE_HAMMING) { + need_bits = s->block_pitch_nbits + + (frame_desc->n_blocks - 1) * s->block_delta_pitch_nbits; + } else if (frame_desc->fcb_type == FCB_TYPE_AW_PULSES) { + need_bits = 2 * !aw_idx_is_ext; + } else + need_bits = 0; + need_bits += frame_desc->frame_size; + if (get_bits_left(gb) < need_bits) + return 1; + skip_bits_long(gb, need_bits); + } + + return 0; +} + +/** + * Synthesize output samples for a single superframe. If we have any data + * cached in s->sframe_cache, that will be used instead of whatever is loaded + * in s->gb. + * + * WMA Voice superframes contain 3 frames, each containing 160 audio samples, + * to give a total of 480 samples per frame. See #synth_frame() for frame + * parsing. In addition to 3 frames, superframes can also contain the LSPs + * (if these are globally specified for all frames (residually); they can + * also be specified individually per-frame. See the s->has_residual_lsps + * option), and can specify the number of samples encoded in this superframe + * (if less than 480), usually used to prevent blanks at track boundaries. + * + * @param ctx WMA Voice decoder context + * @param samples pointer to output buffer for voice samples + * @param data_size pointer containing the size of #samples on input, and the + * amount of #samples filled on output + * @return 0 on success, <0 on error or 1 if there was not enough data to + * fully parse the superframe + */ +static int synth_superframe(AVCodecContext *ctx, + float *samples, int *data_size) +{ + WMAVoiceContext *s = ctx->priv_data; + GetBitContext *gb = &s->gb, s_gb; + int n, res, n_samples = 480; + double lsps[MAX_FRAMES][MAX_LSPS]; + const double *mean_lsf = s->lsps == 16 ? + wmavoice_mean_lsf16[s->lsp_def_mode] : wmavoice_mean_lsf10[s->lsp_def_mode]; + float excitation[MAX_SIGNAL_HISTORY + MAX_SFRAMESIZE + 12]; + float synth[MAX_LSPS + MAX_SFRAMESIZE]; + + memcpy(synth, s->synth_history, + s->lsps * sizeof(*synth)); + memcpy(excitation, s->excitation_history, + s->history_nsamples * sizeof(*excitation)); + + if (s->sframe_cache_size > 0) { + gb = &s_gb; + init_get_bits(gb, s->sframe_cache, s->sframe_cache_size); + s->sframe_cache_size = 0; + } + + if ((res = check_bits_for_superframe(gb, s)) == 1) return 1; + + /* First bit is speech/music bit, it differentiates between WMAVoice + * speech samples (the actual codec) and WMAVoice music samples, which + * are really WMAPro-in-WMAVoice-superframes. I've never seen those in + * the wild yet. */ + if (!get_bits1(gb)) { + av_log_missing_feature(ctx, "WMAPro-in-WMAVoice support", 1); + return -1; + } + + /* (optional) nr. of samples in superframe; always <= 480 and >= 0 */ + if (get_bits1(gb)) { + if ((n_samples = get_bits(gb, 12)) > 480) { + av_log(ctx, AV_LOG_ERROR, + "Superframe encodes >480 samples (%d), not allowed\n", + n_samples); + return -1; + } + } + /* Parse LSPs, if global for the superframe (can also be per-frame). */ + if (s->has_residual_lsps) { + double prev_lsps[MAX_LSPS], a1[MAX_LSPS * 2], a2[MAX_LSPS * 2]; + + for (n = 0; n < s->lsps; n++) + prev_lsps[n] = s->prev_lsps[n] - mean_lsf[n]; + + if (s->lsps == 10) { + dequant_lsp10r(gb, lsps[2], prev_lsps, a1, a2, s->lsp_q_mode); + } else /* s->lsps == 16 */ + dequant_lsp16r(gb, lsps[2], prev_lsps, a1, a2, s->lsp_q_mode); + + for (n = 0; n < s->lsps; n++) { + lsps[0][n] = mean_lsf[n] + (a1[n] - a2[n * 2]); + lsps[1][n] = mean_lsf[n] + (a1[s->lsps + n] - a2[n * 2 + 1]); + lsps[2][n] += mean_lsf[n]; + } + for (n = 0; n < 3; n++) + stabilize_lsps(lsps[n], s->lsps); + } + + /* Parse frames, optionally preceeded by per-frame (independent) LSPs. */ + for (n = 0; n < 3; n++) { + if (!s->has_residual_lsps) { + int m; + + if (s->lsps == 10) { + dequant_lsp10i(gb, lsps[n]); + } else /* s->lsps == 16 */ + dequant_lsp16i(gb, lsps[n]); + + for (m = 0; m < s->lsps; m++) + lsps[n][m] += mean_lsf[m]; + stabilize_lsps(lsps[n], s->lsps); + } + + if ((res = synth_frame(ctx, gb, n, + &samples[n * MAX_FRAMESIZE], + lsps[n], n == 0 ? s->prev_lsps : lsps[n - 1], + &excitation[s->history_nsamples + n * MAX_FRAMESIZE], + &synth[s->lsps + n * MAX_FRAMESIZE]))) + return res; + } + + /* Statistics? FIXME - we don't check for length, a slight overrun + * will be caught by internal buffer padding, and anything else + * will be skipped, not read. */ + if (get_bits1(gb)) { + res = get_bits(gb, 4); + skip_bits(gb, 10 * (res + 1)); + } + + /* Specify nr. of output samples */ + *data_size = n_samples * sizeof(float); + + /* Update history */ + memcpy(s->prev_lsps, lsps[2], + s->lsps * sizeof(*s->prev_lsps)); + memcpy(s->synth_history, &synth[MAX_SFRAMESIZE], + s->lsps * sizeof(*synth)); + memcpy(s->excitation_history, &excitation[MAX_SFRAMESIZE], + s->history_nsamples * sizeof(*excitation)); + if (s->do_apf) + memmove(s->zero_exc_pf, &s->zero_exc_pf[MAX_SFRAMESIZE], + s->history_nsamples * sizeof(*s->zero_exc_pf)); + + return 0; +} + +/** + * Parse the packet header at the start of each packet (input data to this + * decoder). + * + * @param s WMA Voice decoding context private data + * @return 1 if not enough bits were available, or 0 on success. + */ +static int parse_packet_header(WMAVoiceContext *s) +{ + GetBitContext *gb = &s->gb; + unsigned int res; + + if (get_bits_left(gb) < 11) + return 1; + skip_bits(gb, 4); // packet sequence number + s->has_residual_lsps = get_bits1(gb); + do { + res = get_bits(gb, 6); // number of superframes per packet + // (minus first one if there is spillover) + if (get_bits_left(gb) < 6 * (res == 0x3F) + s->spillover_bitsize) + return 1; + } while (res == 0x3F); + s->spillover_nbits = get_bits(gb, s->spillover_bitsize); + + return 0; +} + +/** + * Copy (unaligned) bits from gb/data/size to pb. + * + * @param pb target buffer to copy bits into + * @param data source buffer to copy bits from + * @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 + * source data + * @param nbits the amount of bits to copy from source to target + * + * @note after calling this function, the current position in the input bit + * I/O context is undefined. + */ +static void copy_bits(PutBitContext *pb, + const uint8_t *data, int size, + GetBitContext *gb, int nbits) +{ + int rmn_bytes, rmn_bits; + + rmn_bits = rmn_bytes = get_bits_left(gb); + if (rmn_bits < nbits) + 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, + FFMIN(nbits - rmn_bits, rmn_bytes << 3)); +} + +/** + * Packet decoding: a packet is anything that the (ASF) demuxer contains, + * and we expect that the demuxer / application provides it to us as such + * (else you'll probably get garbage as output). Every packet has a size of + * ctx->block_align bytes, starts with a packet header (see + * #parse_packet_header()), and then a series of superframes. Superframe + * boundaries may exceed packets, i.e. superframes can split data over + * multiple (two) packets. + * + * For more information about frames, see #synth_superframe(). + */ +static int wmavoice_decode_packet(AVCodecContext *ctx, void *data, + int *data_size, AVPacket *avpkt) +{ + WMAVoiceContext *s = ctx->priv_data; + GetBitContext *gb = &s->gb; + int size, res, pos; + + if (*data_size < 480 * sizeof(float)) { + av_log(ctx, AV_LOG_ERROR, + "Output buffer too small (%d given - %lu needed)\n", + *data_size, 480 * sizeof(float)); + return -1; + } + *data_size = 0; + + /* Packets are sometimes a multiple of ctx->block_align, with a packet + * 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. */ + for (size = avpkt->size; size > ctx->block_align; size -= ctx->block_align); + if (!size) + return 0; + init_get_bits(&s->gb, avpkt->data, size << 3); + + /* size == ctx->block_align is used to indicate whether we are dealing with + * a new packet or a packet of which we already read the packet header + * previously. */ + if (size == ctx->block_align) { // new packet header + if ((res = parse_packet_header(s)) < 0) + return res; + + /* If the packet header specifies a s->spillover_nbits, then we want + * to push out all data of the previous packet (+ spillover) before + * continuing to parse new superframes in the current packet. */ + if (s->spillover_nbits > 0) { + if (s->sframe_cache_size > 0) { + int cnt = get_bits_count(gb); + copy_bits(&s->pb, avpkt->data, size, gb, s->spillover_nbits); + flush_put_bits(&s->pb); + s->sframe_cache_size += s->spillover_nbits; + if ((res = synth_superframe(ctx, data, data_size)) == 0 && + *data_size > 0) { + cnt += s->spillover_nbits; + s->skip_bits_next = cnt & 7; + return cnt >> 3; + } else + skip_bits_long (gb, s->spillover_nbits - cnt + + get_bits_count(gb)); // resync + } else + skip_bits_long(gb, s->spillover_nbits); // resync + } + } else if (s->skip_bits_next) + skip_bits(gb, s->skip_bits_next); + + /* Try parsing superframes in current packet */ + s->sframe_cache_size = 0; + s->skip_bits_next = 0; + pos = get_bits_left(gb); + if ((res = synth_superframe(ctx, data, data_size)) < 0) { + return res; + } else if (*data_size > 0) { + int cnt = get_bits_count(gb); + s->skip_bits_next = cnt & 7; + return cnt >> 3; + } else if ((s->sframe_cache_size = pos) > 0) { + /* rewind bit reader to start of last (incomplete) superframe... */ + init_get_bits(gb, avpkt->data, size << 3); + skip_bits_long(gb, (size << 3) - pos); + assert(get_bits_left(gb) == pos); + + /* ...and cache it for spillover in next packet */ + init_put_bits(&s->pb, s->sframe_cache, SFRAME_CACHE_MAXSIZE); + copy_bits(&s->pb, avpkt->data, size, gb, s->sframe_cache_size); + // FIXME bad - just copy bytes as whole and add use the + // skip_bits_next field + } + + return size; +} + +static av_cold int wmavoice_decode_end(AVCodecContext *ctx) +{ + WMAVoiceContext *s = ctx->priv_data; + + if (s->do_apf) { + ff_rdft_end(&s->rdft); + ff_rdft_end(&s->irdft); + ff_dct_end(&s->dct); + ff_dct_end(&s->dst); + } + + return 0; +} + +static av_cold void wmavoice_flush(AVCodecContext *ctx) +{ + WMAVoiceContext *s = ctx->priv_data; + int n; + + s->postfilter_agc = 0; + s->sframe_cache_size = 0; + s->skip_bits_next = 0; + for (n = 0; n < s->lsps; n++) + s->prev_lsps[n] = M_PI * (n + 1.0) / (s->lsps + 1.0); + memset(s->excitation_history, 0, + sizeof(*s->excitation_history) * MAX_SIGNAL_HISTORY); + memset(s->synth_history, 0, + sizeof(*s->synth_history) * MAX_LSPS); + memset(s->gain_pred_err, 0, + sizeof(s->gain_pred_err)); + + if (s->do_apf) { + memset(&s->synth_filter_out_buf[MAX_LSPS_ALIGN16 - s->lsps], 0, + sizeof(*s->synth_filter_out_buf) * s->lsps); + memset(s->dcf_mem, 0, + sizeof(*s->dcf_mem) * 2); + memset(s->zero_exc_pf, 0, + sizeof(*s->zero_exc_pf) * s->history_nsamples); + memset(s->denoise_filter_cache, 0, sizeof(s->denoise_filter_cache)); + } +} + +AVCodec wmavoice_decoder = { + "wmavoice", + AVMEDIA_TYPE_AUDIO, + CODEC_ID_WMAVOICE, + sizeof(WMAVoiceContext), + wmavoice_decode_init, + NULL, + wmavoice_decode_end, + wmavoice_decode_packet, + CODEC_CAP_SUBFRAMES, + .flush = wmavoice_flush, + .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio Voice"), +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/wmavoice_data.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/wmavoice_data.h new file mode 100644 index 0000000000..cbf65b043e --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/wmavoice_data.h @@ -0,0 +1,3259 @@ +/* + * Windows Media Voice (WMAVoice) tables. + * Copyright (c) 2009 Ronald S. Bultje + * + * 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 + * @brief Windows Media Voice (WMAVoice) tables + * @author Ronald S. Bultje + */ + +#ifndef AVCODEC_WMAVOICE_DATA_H +#define AVCODEC_WMAVOICE_DATA_H + +#include + +static const uint8_t wmavoice_dq_lsp10i[0xf00] = { + 125, 109, 84, 55, 34, 51, 109, 112, 118, 132, + 122, 102, 78, 80, 132, 119, 132, 132, 125, 131, + 109, 91, 131, 131, 136, 136, 137, 137, 140, 145, + 140, 143, 117, 136, 122, 106, 109, 91, 115, 119, + 133, 117, 103, 80, 55, 117, 123, 102, 93, 80, + 139, 116, 70, 39, 95, 89, 103, 113, 112, 122, + 135, 244, 229, 215, 199, 181, 163, 150, 146, 144, + 143, 173, 171, 154, 155, 154, 151, 148, 145, 143, + 132, 138, 116, 85, 117, 94, 108, 117, 107, 116, + 132, 118, 123, 119, 88, 67, 49, 95, 84, 95, + 121, 103, 74, 70, 179, 164, 141, 126, 107, 112, + 119, 95, 103, 149, 139, 148, 144, 147, 148, 141, + 151, 133, 142, 129, 111, 131, 108, 128, 122, 108, + 121, 96, 115, 138, 116, 93, 105, 115, 115, 123, + 129, 106, 136, 180, 147, 130, 108, 141, 131, 118, + 136, 155, 176, 156, 135, 129, 140, 146, 142, 134, + 141, 130, 109, 80, 52, 38, 18, 47, 118, 134, + 155, 141, 100, 78, 72, 89, 79, 96, 92, 98, + 133, 111, 83, 91, 72, 58, 105, 115, 112, 120, + 145, 127, 135, 113, 113, 105, 105, 85, 69, 61, + 115, 96, 116, 145, 159, 170, 175, 175, 168, 155, + 140, 120, 84, 52, 80, 145, 125, 127, 116, 126, + 128, 108, 101, 198, 227, 200, 178, 159, 147, 148, + 121, 88, 46, 109, 124, 126, 126, 137, 147, 147, + 129, 107, 164, 148, 127, 117, 134, 120, 111, 116, + 120, 103, 98, 73, 66, 61, 70, 115, 116, 125, + 126, 100, 77, 188, 162, 140, 114, 128, 139, 123, + 145, 165, 164, 134, 109, 100, 108, 118, 127, 130, + 156, 182, 190, 173, 167, 165, 162, 157, 152, 147, + 150, 164, 179, 183, 173, 155, 140, 136, 134, 135, + 122, 92, 69, 140, 132, 118, 108, 128, 138, 132, + 123, 127, 148, 137, 150, 149, 139, 127, 124, 130, + 136, 138, 112, 70, 41, 37, 132, 140, 129, 125, + 130, 111, 78, 33, 51, 161, 141, 136, 120, 122, + 126, 110, 87, 106, 85, 68, 48, 81, 112, 113, + 135, 125, 98, 85, 102, 80, 100, 87, 86, 116, + 142, 133, 110, 66, 48, 152, 139, 135, 136, 123, + 128, 116, 89, 102, 128, 99, 83, 61, 105, 124, + 120, 94, 73, 83, 78, 100, 122, 124, 128, 132, + 144, 137, 116, 102, 75, 144, 136, 127, 140, 127, + 154, 144, 118, 99, 90, 90, 89, 75, 68, 83, + 123, 103, 89, 198, 180, 154, 138, 122, 136, 120, + 138, 118, 121, 136, 110, 105, 85, 111, 101, 104, + 121, 126, 139, 115, 99, 101, 107, 110, 123, 126, + 127, 115, 88, 109, 164, 134, 138, 138, 120, 121, + 130, 202, 195, 202, 199, 201, 181, 164, 159, 148, + 120, 116, 194, 199, 186, 171, 154, 142, 137, 133, + 137, 129, 112, 149, 134, 112, 149, 138, 120, 134, + 119, 102, 107, 83, 79, 114, 119, 127, 128, 128, + 144, 148, 165, 155, 161, 150, 135, 122, 116, 115, + 120, 99, 80, 120, 123, 124, 111, 89, 70, 108, + 118, 95, 66, 53, 105, 126, 125, 105, 83, 111, + 129, 197, 191, 197, 206, 213, 216, 208, 196, 169, + 133, 109, 127, 164, 134, 121, 99, 92, 82, 71, + 131, 121, 93, 91, 136, 105, 115, 140, 120, 110, + 150, 164, 139, 108, 87, 81, 93, 92, 104, 116, + 133, 114, 125, 126, 111, 136, 110, 156, 147, 133, + 113, 94, 118, 120, 115, 125, 124, 126, 127, 134, + 116, 131, 161, 158, 166, 157, 150, 150, 144, 141, + 125, 185, 169, 142, 140, 143, 139, 131, 134, 138, + 179, 188, 170, 150, 134, 140, 144, 133, 127, 127, + 150, 177, 204, 184, 192, 194, 190, 193, 177, 158, + 114, 113, 138, 116, 137, 135, 132, 131, 127, 134, + 120, 147, 163, 135, 133, 137, 136, 136, 133, 135, + 137, 120, 95, 73, 46, 48, 111, 97, 97, 123, + 139, 130, 109, 76, 52, 72, 61, 61, 125, 127, + 132, 119, 119, 90, 66, 41, 64, 156, 143, 129, + 131, 106, 58, 25, 99, 115, 122, 136, 129, 132, + 134, 123, 97, 53, 27, 114, 125, 114, 120, 123, + 122, 107, 93, 57, 47, 133, 128, 138, 141, 131, + 145, 132, 122, 110, 79, 57, 30, 73, 153, 144, + 150, 132, 85, 59, 133, 125, 130, 115, 100, 96, + 148, 127, 111, 86, 61, 38, 110, 121, 108, 99, + 157, 143, 105, 77, 116, 118, 115, 131, 122, 122, + 133, 119, 134, 108, 86, 61, 129, 165, 143, 127, + 125, 105, 89, 111, 97, 85, 113, 99, 98, 117, + 149, 131, 101, 106, 88, 95, 79, 119, 123, 120, + 125, 109, 81, 100, 201, 183, 156, 138, 115, 116, + 141, 119, 129, 105, 76, 60, 110, 99, 92, 82, + 150, 156, 129, 95, 69, 115, 115, 113, 134, 125, + 118, 97, 67, 96, 203, 197, 171, 151, 133, 125, + 143, 131, 120, 134, 105, 80, 51, 60, 139, 134, + 129, 160, 223, 219, 219, 212, 197, 173, 157, 146, + 132, 112, 164, 144, 119, 102, 92, 76, 73, 94, + 132, 112, 124, 114, 93, 92, 83, 73, 69, 99, + 129, 103, 188, 163, 142, 132, 127, 101, 82, 59, + 140, 141, 111, 74, 46, 105, 113, 99, 127, 122, + 125, 94, 63, 112, 116, 101, 81, 120, 136, 134, + 133, 190, 224, 193, 179, 158, 146, 143, 140, 136, + 152, 161, 132, 120, 112, 94, 114, 102, 92, 116, + 129, 194, 196, 202, 211, 212, 210, 190, 169, 152, + 166, 166, 145, 111, 91, 132, 133, 128, 136, 130, + 118, 94, 72, 74, 92, 86, 89, 92, 106, 123, + 126, 100, 86, 137, 117, 92, 76, 104, 106, 114, + 133, 109, 204, 192, 166, 148, 138, 128, 111, 81, + 118, 99, 79, 146, 169, 141, 123, 102, 131, 120, + 127, 105, 136, 204, 170, 154, 131, 145, 135, 119, + 117, 95, 64, 83, 141, 136, 118, 96, 99, 126, + 115, 93, 98, 102, 95, 105, 106, 114, 119, 128, + 131, 121, 98, 139, 149, 119, 109, 86, 105, 129, + 134, 119, 104, 169, 185, 155, 141, 122, 107, 127, + 136, 115, 85, 108, 87, 126, 102, 128, 136, 129, + 125, 99, 126, 158, 133, 139, 132, 113, 91, 107, + 141, 122, 128, 161, 130, 127, 105, 120, 118, 106, + 122, 140, 161, 168, 187, 184, 176, 158, 144, 140, + 127, 111, 89, 130, 132, 105, 134, 121, 100, 122, + 129, 110, 128, 115, 129, 116, 132, 118, 114, 119, + 138, 133, 132, 188, 183, 159, 161, 147, 134, 140, + 132, 113, 84, 167, 147, 132, 124, 109, 133, 121, + 132, 128, 116, 121, 98, 101, 145, 129, 128, 129, + 124, 112, 152, 158, 136, 161, 139, 165, 158, 142, + 139, 138, 110, 127, 148, 117, 126, 118, 101, 116, + 155, 168, 154, 128, 120, 152, 150, 141, 140, 135, + 127, 111, 109, 134, 104, 133, 110, 112, 132, 114, + 111, 87, 68, 89, 107, 121, 121, 126, 126, 129, + 120, 148, 169, 163, 173, 178, 185, 188, 178, 163, + 122, 97, 86, 117, 101, 138, 118, 142, 155, 139, + 125, 114, 131, 138, 153, 149, 163, 150, 143, 141, + 157, 161, 138, 152, 134, 121, 122, 109, 110, 124, + 151, 171, 196, 168, 145, 139, 147, 151, 146, 139, + 134, 169, 179, 170, 175, 178, 177, 173, 165, 154, + 120, 151, 118, 107, 125, 129, 133, 133, 136, 139, + 119, 141, 159, 151, 160, 165, 168, 169, 162, 152, + 115, 111, 119, 94, 117, 121, 127, 127, 132, 136, + 134, 153, 147, 142, 142, 147, 159, 159, 154, 147, + 110, 106, 139, 135, 143, 142, 147, 146, 147, 147, + 115, 133, 151, 133, 141, 142, 151, 152, 147, 144, + 115, 132, 144, 131, 125, 126, 128, 130, 131, 136, + 138, 118, 96, 71, 48, 26, 43, 130, 125, 125, + 134, 122, 98, 54, 28, 84, 77, 73, 109, 125, + 133, 112, 67, 48, 141, 129, 126, 113, 112, 118, + 143, 123, 89, 54, 71, 73, 75, 131, 123, 123, + 126, 109, 81, 31, 15, 94, 110, 109, 119, 128, + 132, 122, 97, 92, 73, 50, 27, 22, 104, 133, + 133, 119, 94, 48, 34, 168, 160, 154, 151, 130, + 147, 133, 90, 54, 71, 123, 106, 105, 93, 117, + 143, 132, 107, 69, 45, 78, 178, 169, 150, 139, + 138, 123, 116, 96, 69, 49, 32, 113, 103, 112, + 154, 151, 125, 79, 60, 152, 160, 154, 155, 137, + 142, 151, 124, 88, 66, 59, 94, 87, 95, 119, + 166, 154, 122, 92, 138, 132, 124, 114, 97, 97, + 122, 99, 98, 219, 191, 176, 165, 159, 153, 131, + 130, 119, 91, 51, 24, 41, 144, 156, 147, 139, + 139, 122, 81, 65, 124, 111, 104, 90, 94, 98, + 138, 120, 112, 91, 63, 65, 89, 75, 78, 106, + 126, 107, 91, 85, 69, 95, 90, 84, 108, 120, + 155, 139, 100, 78, 120, 110, 109, 91, 77, 73, + 144, 130, 135, 112, 88, 65, 62, 142, 129, 126, + 170, 154, 150, 131, 121, 116, 100, 92, 83, 86, + 131, 122, 98, 107, 102, 75, 54, 38, 117, 130, + 146, 139, 117, 107, 86, 66, 44, 30, 97, 128, + 129, 116, 100, 59, 108, 127, 119, 139, 129, 129, + 124, 106, 79, 49, 154, 190, 166, 152, 133, 123, + 141, 149, 123, 89, 61, 70, 143, 132, 125, 126, + 136, 113, 177, 166, 141, 123, 109, 108, 105, 93, + 137, 117, 147, 123, 99, 85, 109, 98, 91, 75, + 129, 121, 102, 78, 53, 90, 149, 136, 134, 135, + 144, 136, 126, 90, 114, 152, 137, 152, 138, 128, + 133, 115, 107, 129, 99, 78, 60, 129, 125, 118, + 147, 141, 119, 124, 110, 91, 79, 64, 106, 117, + 134, 111, 164, 143, 123, 113, 116, 95, 76, 56, + 147, 159, 140, 109, 83, 84, 140, 135, 127, 129, + 123, 104, 116, 99, 91, 87, 80, 110, 113, 121, + 124, 106, 174, 174, 152, 141, 132, 134, 126, 124, + 140, 190, 240, 215, 212, 189, 173, 158, 144, 137, + 123, 97, 79, 102, 110, 111, 90, 75, 126, 124, + 134, 121, 104, 145, 127, 100, 77, 65, 120, 118, + 123, 106, 87, 41, 68, 119, 106, 115, 109, 119, + 137, 232, 241, 225, 217, 202, 183, 169, 156, 145, + 161, 146, 127, 110, 97, 107, 88, 114, 108, 106, + 141, 244, 216, 192, 172, 163, 148, 143, 144, 144, + 128, 127, 109, 89, 77, 68, 124, 120, 121, 125, + 125, 94, 48, 71, 116, 113, 104, 120, 142, 137, + 133, 129, 115, 82, 68, 120, 99, 133, 134, 124, + 130, 106, 108, 160, 130, 111, 89, 129, 124, 119, + 134, 120, 149, 143, 116, 95, 87, 142, 132, 122, + 126, 114, 108, 107, 80, 141, 133, 123, 137, 124, + 117, 95, 69, 43, 62, 98, 114, 116, 112, 120, + 122, 99, 87, 164, 145, 123, 99, 95, 118, 105, + 126, 101, 102, 120, 113, 110, 92, 139, 134, 126, + 148, 194, 241, 219, 221, 215, 200, 193, 174, 151, + 127, 104, 122, 136, 113, 106, 110, 95, 78, 106, + 131, 163, 217, 199, 194, 175, 164, 155, 142, 138, + 139, 124, 88, 57, 161, 161, 145, 139, 124, 116, + 127, 110, 91, 98, 126, 104, 113, 98, 94, 94, + 145, 138, 114, 90, 75, 130, 117, 107, 99, 90, + 119, 98, 86, 101, 148, 133, 103, 83, 124, 131, + 143, 168, 169, 133, 110, 117, 139, 149, 147, 137, + 124, 106, 80, 138, 194, 163, 142, 119, 106, 130, + 136, 125, 105, 114, 87, 113, 101, 89, 108, 102, + 114, 90, 53, 46, 105, 116, 126, 122, 118, 122, + 124, 102, 92, 195, 167, 160, 144, 154, 154, 132, + 118, 97, 88, 72, 98, 120, 112, 98, 79, 117, + 114, 107, 185, 191, 191, 188, 175, 165, 153, 143, + 119, 97, 90, 89, 120, 151, 136, 113, 99, 112, + 141, 121, 144, 122, 125, 113, 133, 111, 92, 69, + 120, 98, 78, 109, 151, 145, 157, 157, 151, 143, + 130, 110, 120, 188, 159, 141, 119, 112, 109, 98, + 126, 112, 83, 110, 169, 139, 127, 105, 93, 123, + 141, 145, 117, 106, 91, 78, 123, 107, 101, 125, + 117, 95, 71, 147, 176, 153, 148, 133, 135, 127, + 124, 106, 79, 64, 115, 96, 108, 115, 106, 105, + 127, 115, 90, 98, 105, 81, 144, 135, 117, 125, + 126, 104, 98, 165, 138, 136, 112, 149, 148, 131, + 119, 144, 186, 185, 204, 202, 209, 200, 182, 161, + 123, 153, 190, 189, 199, 194, 191, 176, 157, 147, + 121, 103, 119, 98, 100, 120, 106, 97, 95, 126, + 137, 130, 102, 117, 117, 92, 126, 114, 101, 118, + 131, 219, 190, 167, 153, 151, 144, 140, 142, 143, + 114, 102, 151, 152, 132, 120, 112, 120, 127, 131, + 138, 122, 91, 143, 118, 120, 114, 104, 124, 117, + 148, 142, 117, 126, 97, 125, 108, 116, 142, 125, + 126, 106, 91, 169, 208, 178, 158, 138, 127, 135, + 133, 126, 101, 83, 147, 130, 125, 117, 114, 117, + 120, 103, 94, 149, 136, 129, 139, 118, 133, 133, + 147, 152, 126, 132, 119, 97, 132, 129, 114, 126, + 112, 107, 148, 125, 112, 114, 124, 125, 129, 135, + 139, 121, 157, 151, 131, 140, 118, 147, 136, 121, + 115, 105, 159, 167, 185, 191, 196, 190, 176, 160, + 124, 106, 104, 122, 130, 114, 152, 144, 134, 136, + 136, 152, 159, 153, 131, 114, 116, 126, 129, 129, + 124, 109, 87, 131, 107, 115, 130, 107, 144, 131, + 126, 162, 176, 175, 180, 176, 160, 141, 134, 134, + 136, 127, 108, 161, 162, 133, 141, 124, 112, 128, + 130, 115, 110, 140, 107, 155, 134, 131, 156, 137, + 122, 106, 116, 127, 118, 161, 150, 170, 167, 152, + 139, 177, 203, 176, 155, 139, 130, 128, 129, 132, + 137, 119, 125, 103, 110, 123, 107, 120, 108, 101, + 113, 107, 160, 154, 160, 166, 169, 176, 168, 156, + 115, 90, 65, 115, 115, 104, 120, 112, 109, 124, + 131, 123, 100, 109, 185, 158, 141, 132, 116, 119, + 139, 130, 119, 156, 124, 138, 127, 116, 141, 128, + 133, 118, 115, 180, 149, 151, 135, 130, 147, 129, + 117, 90, 80, 119, 124, 128, 132, 130, 128, 135, + 112, 97, 142, 161, 167, 165, 154, 142, 136, 135, + 118, 141, 193, 172, 157, 152, 148, 145, 146, 141, + 125, 147, 165, 166, 149, 133, 123, 122, 128, 131, + 128, 193, 177, 174, 182, 186, 197, 193, 191, 173, + 124, 144, 162, 133, 113, 113, 123, 128, 129, 130, + 117, 98, 121, 122, 137, 132, 110, 97, 111, 130, + 128, 176, 151, 125, 126, 134, 130, 121, 127, 130, + 122, 151, 142, 111, 106, 121, 126, 126, 130, 134, + 148, 167, 186, 153, 129, 122, 124, 128, 130, 128, + 148, 172, 206, 178, 171, 182, 169, 180, 172, 156, + 133, 164, 174, 160, 155, 163, 163, 172, 169, 158, + 132, 150, 147, 142, 152, 140, 140, 140, 134, 135, + 137, 158, 167, 172, 163, 153, 169, 158, 146, 147, + 150, 161, 162, 172, 153, 133, 140, 144, 136, 135, + 109, 84, 101, 120, 129, 134, 133, 136, 137, 143, + 112, 114, 157, 147, 141, 136, 135, 133, 135, 138, + 121, 154, 161, 150, 149, 154, 151, 144, 146, 144, + 111, 117, 125, 125, 130, 131, 135, 137, 143, 148, + 121, 141, 146, 131, 138, 126, 118, 111, 119, 130, + 120, 135, 145, 121, 140, 134, 138, 137, 131, 134, + 115, 137, 132, 137, 139, 138, 138, 139, 145, 149, + 131, 149, 147, 133, 132, 126, 131, 134, 130, 133, + 110, 98, 84, 141, 107, 169, 169, 123, 125, 126, + 118, 210, 98, 126, 132, 138, 128, 139, 156, 157, + 140, 142, 129, 95, 192, 178, 182, 186, 183, 159, + 135, 134, 144, 124, 100, 228, 203, 161, 122, 104, + 139, 159, 134, 161, 121, 126, 192, 152, 218, 180, + 132, 132, 119, 99, 96, 97, 80, 53, 134, 143, + 102, 114, 133, 114, 127, 83, 77, 126, 85, 107, + 110, 114, 194, 186, 139, 116, 147, 104, 129, 138, + 126, 133, 109, 144, 115, 45, 130, 97, 159, 155, + 157, 162, 189, 185, 168, 163, 151, 151, 142, 135, + 144, 147, 120, 74, 192, 186, 149, 118, 71, 84, + 143, 156, 133, 178, 168, 107, 119, 149, 105, 112, + 182, 184, 158, 118, 118, 148, 128, 177, 171, 152, + 139, 135, 126, 209, 171, 150, 123, 100, 190, 158, + 166, 97, 136, 123, 136, 139, 128, 138, 126, 121, + 132, 131, 128, 95, 60, 168, 127, 140, 208, 161, + 109, 102, 119, 162, 150, 137, 107, 200, 156, 136, + 136, 128, 103, 95, 74, 91, 220, 173, 152, 138, + 139, 129, 140, 136, 122, 82, 180, 115, 53, 90, + 121, 107, 99, 148, 116, 139, 100, 63, 191, 155, + 130, 129, 163, 155, 98, 175, 95, 151, 127, 107, + 124, 124, 116, 88, 71, 164, 148, 96, 57, 89, + 125, 117, 77, 63, 162, 144, 113, 109, 137, 134, + 134, 130, 149, 174, 158, 158, 130, 81, 28, 67, + 142, 139, 129, 100, 194, 134, 68, 175, 131, 103, + 136, 132, 122, 96, 119, 82, 115, 249, 215, 168, + 125, 139, 199, 96, 146, 123, 136, 179, 142, 137, + 181, 166, 106, 86, 122, 106, 123, 131, 106, 119, + 129, 189, 188, 147, 126, 110, 101, 114, 147, 136, + 132, 106, 72, 175, 148, 99, 130, 153, 125, 136, + 123, 119, 147, 170, 157, 126, 209, 188, 158, 152, + 101, 89, 142, 131, 161, 150, 148, 124, 89, 119, + 141, 137, 131, 103, 81, 85, 64, 175, 129, 121, + 137, 144, 142, 145, 119, 205, 148, 80, 165, 138, + 143, 137, 167, 165, 148, 149, 110, 234, 217, 170, + 167, 152, 75, 140, 155, 155, 175, 129, 136, 134, + 136, 152, 161, 131, 140, 121, 91, 79, 255, 209, + 132, 147, 120, 114, 177, 128, 110, 61, 89, 131, + 125, 127, 93, 87, 167, 115, 186, 162, 107, 106, + 134, 162, 151, 100, 79, 67, 151, 116, 130, 142, + 162, 153, 155, 143, 122, 85, 202, 187, 135, 125, + 158, 155, 103, 129, 74, 149, 130, 98, 129, 126, + 148, 152, 153, 133, 118, 94, 80, 70, 47, 90, + 124, 118, 143, 184, 158, 126, 70, 82, 111, 113, + 126, 135, 175, 141, 203, 166, 123, 123, 134, 133, + 113, 111, 128, 76, 128, 177, 151, 178, 134, 125, + 120, 120, 193, 106, 98, 134, 101, 86, 101, 114, + 136, 127, 134, 196, 86, 105, 145, 128, 119, 137, + 138, 126, 230, 161, 141, 128, 129, 136, 88, 83, + 103, 118, 178, 123, 89, 101, 161, 173, 165, 147, + 130, 123, 171, 158, 131, 81, 50, 177, 162, 136, + 125, 115, 82, 173, 195, 168, 130, 112, 112, 121, + 152, 148, 167, 87, 82, 161, 142, 147, 98, 89, + 168, 138, 97, 157, 132, 114, 74, 126, 161, 141, + 135, 123, 68, 137, 124, 118, 112, 92, 65, 96, + 191, 181, 161, 151, 141, 145, 129, 102, 97, 111, + 144, 128, 55, 128, 115, 155, 129, 184, 167, 147, + 131, 141, 125, 33, 127, 111, 127, 131, 125, 130, + 137, 130, 121, 195, 172, 177, 176, 149, 98, 97, + 126, 106, 168, 159, 144, 185, 156, 151, 182, 158, + 123, 93, 110, 116, 98, 99, 125, 136, 139, 148, + 79, 112, 149, 128, 147, 136, 118, 105, 166, 152, + 117, 115, 92, 128, 148, 132, 170, 143, 226, 190, + 122, 192, 165, 121, 143, 144, 174, 124, 113, 124, + 122, 135, 34, 93, 118, 111, 111, 136, 123, 116, + 99, 195, 139, 99, 114, 102, 96, 108, 111, 112, + 113, 129, 172, 137, 105, 139, 154, 86, 113, 108, + 132, 79, 63, 120, 93, 162, 90, 103, 94, 95, + 117, 127, 104, 100, 142, 129, 93, 27, 196, 153, + 113, 91, 101, 90, 84, 68, 138, 38, 118, 148, + 87, 103, 125, 109, 96, 152, 100, 56, 31, 62, + 176, 129, 124, 115, 103, 92, 100, 121, 130, 125, + 128, 71, 82, 71, 152, 85, 107, 116, 138, 133, + 103, 116, 139, 144, 72, 37, 118, 141, 109, 95, + 86, 92, 121, 167, 156, 104, 92, 91, 122, 114, + 89, 61, 172, 128, 95, 103, 84, 101, 88, 84, + 116, 125, 108, 62, 74, 108, 160, 143, 189, 164, + 91, 115, 144, 43, 116, 79, 106, 108, 74, 83, + 87, 90, 61, 71, 76, 76, 95, 130, 89, 94, + 114, 107, 101, 145, 161, 147, 143, 163, 147, 129, + 101, 73, 111, 108, 93, 104, 186, 141, 99, 89, + 112, 126, 111, 113, 152, 41, 159, 115, 131, 124, + 117, 101, 115, 130, 124, 87, 59, 177, 63, 85, + 109, 116, 103, 68, 145, 132, 29, 119, 96, 89, + 117, 90, 181, 103, 101, 111, 97, 96, 199, 171, + 113, 120, 93, 119, 101, 64, 56, 55, 63, 90, + 105, 101, 86, 45, 136, 179, 142, 102, 115, 114, + 113, 108, 121, 84, 23, 125, 76, 102, 119, 107, + 120, 104, 73, 177, 83, 114, 128, 85, 152, 126, + 137, 115, 149, 109, 163, 133, 110, 98, 54, 61, + 95, 111, 135, 103, 88, 164, 115, 187, 122, 98, + 129, 132, 95, 86, 71, 119, 146, 111, 38, 67, + 102, 100, 66, 148, 137, 103, 145, 95, 35, 85, + 44, 136, 102, 111, 108, 115, 136, 105, 120, 110, + 108, 147, 112, 169, 116, 146, 81, 120, 94, 84, + 93, 97, 90, 119, 102, 91, 48, 147, 204, 151, + 148, 160, 144, 131, 144, 175, 158, 133, 212, 163, + 172, 152, 151, 112, 148, 151, 145, 179, 160, 124, + 164, 164, 167, 161, 141, 120, 131, 141, 198, 177, + 169, 156, 146, 156, 124, 185, 164, 195, 181, 193, + 201, 147, 148, 168, 165, 159, 162, 148, 150, 148, + 146, 157, 158, 149, 164, 129, 160, 214, 174, 166, + 154, 176, 146, 141, 155, 140, 140, 169, 106, 155, + 166, 162, 134, 193, 157, 155, 146, 196, 171, 107, + 177, 174, 163, 155, 147, 203, 162, 146, 150, 83, + 157, 170, 180, 178, 159, 157, 151, 117, 115, 183, + 170, 180, 174, 150, 177, 173, 136, 181, 196, 184, + 164, 168, 165, 148, 175, 168, 209, 189, 159, 114, + 157, 158, 141, 168, 170, 139, 175, 128, 151, 39, + 128, 154, 159, 161, 148, 180, 131, 165, 159, 131, + 163, 150, 174, 178, 178, 198, 172, 138, 184, 191, + 143, 164, 161, 163, 210, 171, 155, 168, 150, 116, + 182, 170, 145, 152, 141, 139, 191, 149, 160, 202, + 145, 169, 145, 181, 148, 183, 197, 165, 146, 171, + 161, 153, 157, 170, 164, 149, 183, 167, 246, 235, + 162, 144, 170, 152, 173, 150, 113, 135, 156, 154, + 158, 148, 178, 159, 161, 114, 180, 156, 116, 163, + 164, 161, 122, 164, 164, 183, 135, 135, 144, 182, + 160, 147, 163, 152, 169, 185, 159, 177, 99, 211, + 168, 167, 215, 170, 150, 157, 154, 176, 154, 143, + 163, 117, 178, 160, 163, 165, 164, 166, 174, 136, + 159, 169, 152, 123, 199, 149, 169, 140, 159, 208, + 155, 161, 186, 122, 134, 167, 171, 145, 148, 176, + 148, 137, 114, 160, 166, 153, 162, 156, 164, 172, + 155, 148, 155, 182, 114, 150, 157, 154, 140, 159, + 166, 160, 169, 206, 182, 145, 157, 165, 147, 202, + 131, 154, 193, 162, 162, 149, 167, 157, 191, 188, + 149, 205, 147, 166, 150, 150, 159, 153, 171, 160 +}; + +static const uint8_t wmavoice_dq_lsp16i1[0x640] = { + 142, 121, 141, 112, 99, 119, 92, 122, 183, 155, + 122, 98, 75, 78, 85, 101, 108, 134, 128, 123, + 115, 90, 79, 58, 73, 127, 106, 60, 97, 107, + 141, 163, 130, 123, 136, 156, 201, 189, 204, 206, + 140, 116, 69, 60, 117, 123, 106, 124, 91, 63, + 150, 144, 110, 80, 63, 112, 80, 70, 76, 63, + 114, 86, 147, 165, 137, 125, 120, 140, 115, 101, + 101, 99, 166, 158, 158, 104, 126, 131, 134, 143, + 121, 102, 73, 36, 83, 132, 113, 76, 38, 20, + 132, 111, 78, 73, 51, 131, 108, 131, 105, 80, + 148, 138, 101, 65, 47, 115, 86, 50, 124, 129, + 116, 89, 85, 87, 64, 111, 74, 39, 115, 113, + 112, 83, 75, 122, 127, 114, 91, 106, 125, 130, + 131, 108, 79, 136, 112, 110, 147, 164, 144, 124, + 121, 236, 218, 190, 168, 106, 101, 160, 172, 191, + 113, 138, 102, 91, 109, 100, 71, 85, 112, 119, + 121, 96, 51, 64, 126, 135, 114, 76, 34, 104, + 145, 127, 90, 56, 131, 142, 131, 92, 123, 102, + 128, 105, 63, 24, 95, 115, 87, 49, 156, 174, + 123, 105, 88, 58, 55, 141, 119, 99, 75, 81, + 137, 117, 114, 80, 56, 119, 91, 106, 166, 135, + 114, 84, 38, 93, 116, 129, 103, 97, 87, 97, + 115, 184, 193, 173, 157, 117, 88, 114, 151, 121, + 126, 111, 75, 129, 133, 130, 107, 71, 115, 92, + 128, 108, 120, 100, 97, 111, 80, 119, 122, 91, + 114, 94, 149, 129, 136, 114, 88, 132, 110, 85, + 116, 99, 101, 71, 71, 110, 140, 142, 131, 110, + 122, 98, 83, 127, 100, 106, 130, 123, 114, 103, + 113, 87, 140, 116, 113, 140, 161, 171, 145, 129, + 115, 178, 158, 161, 160, 118, 195, 209, 221, 228, + 99, 83, 140, 134, 140, 127, 186, 168, 187, 187, + 107, 114, 100, 111, 111, 104, 130, 131, 116, 128, + 128, 104, 64, 18, 49, 126, 107, 69, 56, 153, + 154, 142, 110, 113, 89, 120, 93, 73, 190, 172, + 119, 96, 57, 21, 60, 126, 122, 81, 99, 117, + 159, 141, 108, 88, 120, 144, 125, 89, 44, 94, + 147, 131, 93, 81, 61, 133, 113, 85, 47, 62, + 123, 121, 87, 53, 90, 120, 94, 76, 70, 48, + 125, 103, 93, 64, 35, 140, 129, 88, 47, 30, + 127, 104, 58, 51, 103, 124, 100, 102, 76, 47, + 115, 87, 54, 46, 77, 182, 218, 174, 163, 145, + 140, 126, 89, 105, 82, 125, 119, 101, 69, 58, + 125, 107, 172, 145, 128, 138, 113, 109, 92, 90, + 117, 93, 83, 93, 132, 125, 102, 67, 148, 161, + 131, 110, 96, 99, 74, 119, 92, 54, 84, 81, + 110, 152, 120, 106, 131, 108, 74, 68, 99, 107, + 121, 97, 120, 101, 78, 132, 110, 127, 164, 134, + 111, 159, 204, 189, 178, 158, 183, 146, 144, 137, + 123, 106, 136, 108, 135, 117, 91, 163, 135, 113, + 119, 177, 134, 122, 121, 132, 109, 157, 131, 113, + 115, 87, 87, 100, 92, 120, 95, 59, 146, 139, + 129, 101, 135, 122, 101, 119, 100, 112, 88, 99, + 118, 90, 123, 125, 107, 121, 98, 73, 104, 80, + 112, 79, 86, 122, 96, 104, 81, 107, 90, 93, + 112, 150, 140, 109, 115, 113, 86, 73, 76, 112, + 130, 111, 101, 112, 84, 123, 97, 63, 134, 115, + 109, 77, 128, 141, 119, 125, 101, 108, 147, 119, + 134, 149, 150, 127, 115, 136, 244, 220, 210, 189, + 105, 138, 171, 156, 174, 117, 162, 133, 146, 141, + 115, 93, 119, 98, 122, 114, 106, 154, 145, 162, + 107, 131, 189, 165, 152, 101, 107, 129, 114, 139, + 116, 186, 186, 161, 180, 100, 89, 137, 116, 116, + 106, 130, 194, 196, 207, 110, 156, 157, 138, 149, + 102, 93, 159, 138, 120, 109, 132, 105, 122, 135, + 148, 128, 85, 76, 102, 168, 154, 141, 117, 100, + 125, 106, 62, 101, 146, 124, 102, 65, 25, 15, + 120, 94, 46, 21, 94, 149, 128, 115, 85, 92, + 119, 93, 70, 52, 30, 162, 151, 123, 91, 80, + 126, 112, 84, 47, 33, 138, 114, 73, 60, 87, + 126, 211, 174, 158, 143, 129, 106, 65, 31, 133, + 119, 95, 52, 99, 173, 123, 96, 119, 206, 178, + 127, 104, 60, 61, 67, 152, 136, 104, 63, 83, + 133, 130, 92, 64, 45, 120, 96, 53, 30, 130, + 128, 103, 74, 59, 35, 135, 114, 77, 30, 57, + 108, 130, 123, 90, 87, 143, 125, 93, 54, 60, + 133, 118, 79, 87, 95, 115, 89, 111, 88, 65, + 124, 102, 70, 40, 47, 148, 131, 123, 130, 104, + 127, 109, 87, 56, 121, 147, 123, 121, 107, 85, + 178, 237, 200, 193, 170, 139, 118, 100, 75, 110, + 133, 121, 81, 73, 68, 120, 195, 157, 141, 131, + 127, 102, 107, 88, 60, 136, 113, 100, 69, 45, + 128, 105, 93, 77, 67, 131, 116, 149, 184, 156, + 115, 85, 35, 45, 112, 128, 108, 68, 73, 111, + 118, 93, 187, 162, 139, 136, 115, 84, 57, 37, + 131, 133, 125, 98, 85, 138, 115, 92, 86, 61, + 116, 96, 70, 52, 110, 115, 109, 135, 104, 88, + 136, 159, 122, 109, 115, 122, 110, 98, 70, 95, + 112, 81, 68, 85, 90, 124, 101, 87, 56, 89, + 109, 82, 98, 100, 115, 124, 102, 76, 88, 63, + 111, 78, 42, 78, 102, 110, 71, 64, 131, 111, + 125, 104, 107, 87, 123, 129, 131, 99, 85, 68, + 147, 137, 102, 99, 75, 120, 155, 142, 109, 91, + 132, 109, 131, 141, 113, 136, 119, 94, 152, 128, + 127, 102, 79, 159, 134, 111, 78, 98, 109, 80, + 115, 86, 51, 63, 103, 116, 86, 170, 149, 123, + 135, 178, 159, 125, 114, 113, 189, 226, 203, 202, + 140, 117, 116, 94, 70, 128, 103, 94, 174, 149, + 118, 98, 83, 84, 106, 115, 157, 120, 94, 95, + 131, 112, 75, 96, 74, 121, 97, 144, 117, 95, + 120, 90, 140, 138, 110, 119, 93, 55, 92, 114, + 114, 87, 151, 125, 100, 111, 82, 83, 160, 139, + 114, 86, 56, 90, 138, 104, 109, 101, 77, 118, + 140, 142, 143, 148, 126, 121, 102, 129, 107, 111, + 113, 79, 58, 111, 91, 120, 94, 63, 115, 98, + 121, 94, 99, 97, 78, 120, 92, 68, 173, 148, + 122, 114, 109, 87, 82, 132, 229, 192, 176, 155, + 137, 116, 123, 97, 115, 132, 115, 86, 120, 95, + 135, 116, 101, 136, 108, 109, 74, 100, 125, 115, + 112, 158, 144, 124, 134, 114, 83, 73, 147, 120, + 120, 104, 150, 122, 116, 110, 104, 192, 183, 174, + 134, 112, 116, 120, 93, 121, 101, 93, 110, 90, + 121, 93, 147, 152, 122, 115, 153, 171, 161, 142, + 123, 95, 116, 114, 93, 113, 89, 96, 77, 93, + 113, 174, 180, 143, 138, 116, 86, 100, 135, 106, + 103, 121, 149, 115, 103, 121, 95, 82, 149, 121, + 117, 92, 93, 111, 114, 123, 209, 196, 193, 183, + 125, 102, 107, 130, 104, 115, 91, 113, 103, 99, + 114, 86, 68, 108, 110, 111, 159, 162, 125, 113, + 125, 235, 234, 225, 214, 99, 74, 118, 121, 127, + 104, 123, 158, 128, 127, 113, 96, 116, 136, 158, + 100, 80, 138, 155, 166, 118, 143, 115, 125, 114, + 119, 137, 133, 136, 139, 151, 188, 172, 174, 173, + 138, 161, 158, 158, 155, 121, 198, 194, 211, 202, + 100, 90, 112, 110, 122, 100, 91, 122, 128, 135, + 101, 109, 127, 101, 114, 105, 126, 160, 147, 143, + 109, 138, 142, 158, 163, 113, 174, 185, 188, 206, + 112, 154, 166, 176, 183, 101, 108, 140, 140, 143, + 106, 135, 130, 137, 126, 103, 114, 115, 128, 126, + 107, 86, 21, 115, 75, 117, 139, 97, 65, 105, + 64, 191, 101, 106, 139, 107, 98, 218, 132, 104, + 73, 136, 165, 84, 118, 150, 111, 58, 130, 107, + 99, 136, 132, 56, 52, 102, 136, 69, 78, 163, + 85, 173, 148, 138, 85, 69, 106, 128, 133, 155, + 104, 91, 149, 56, 104, 103, 101, 172, 96, 57, + 104, 97, 125, 197, 166, 107, 169, 47, 120, 103, + 150, 89, 99, 139, 162, 101, 69, 137, 158, 126, + 191, 173, 127, 79, 155, 51, 131, 112, 86, 74, + 135, 61, 114, 81, 125, 117, 112, 72, 175, 72, + 127, 123, 142, 132, 78, 116, 158, 111, 121, 143, + 108, 102, 89, 20, 194, 81, 99, 107, 65, 150, + 103, 78, 91, 69, 96, 104, 116, 116, 103, 105, + 107, 117, 110, 130, 28, 88, 103, 62, 72, 85, + 125, 126, 141, 126, 178, 121, 102, 57, 46, 124, + 97, 91, 89, 138, 95, 98, 143, 99, 169, 123, + 140, 119, 113, 82, 140, 118, 112, 91, 92, 241, + 134, 89, 95, 112, 78, 167, 140, 145, 121, 100, + 109, 205, 144, 91, 100, 113, 103, 142, 175, 95, + 117, 121, 35, 121, 127, 159, 129, 85, 64, 75, + 116, 98, 103, 127, 129, 66, 68, 110, 96, 86, + 79, 100, 156, 133, 92, 135, 96, 164, 132, 121, + 93, 163, 134, 91, 208, 104, 77, 126, 116, 58, + 136, 118, 132, 81, 61, 73, 115, 66, 129, 123, + 111, 85, 42, 178, 134, 108, 132, 159, 45, 157, + 105, 164, 100, 94, 60, 96, 57, 154, 105, 102, + 103, 114, 96, 12, 91, 119, 115, 67, 92, 64, + 94, 61, 106, 106, 165, 105, 94, 98, 68, 30, + 146, 130, 107, 173, 140, 102, 90, 163, 106, 184, + 100, 53, 68, 131, 92, 105, 111, 68, 153, 186, + 101, 82, 48, 99, 147, 122, 136, 176, 96, 96, + 104, 132, 167, 149, 136, 138, 144, 97, 120, 92 +}; + +static const uint8_t wmavoice_dq_lsp16i2[0x3c0] = { + 23, 12, 107, 119, 110, 205, 214, 212, 208, 201, + 102, 95, 69, 117, 107, 118, 123, 118, 123, 121, + 82, 58, 83, 95, 84, 139, 145, 153, 161, 169, + 102, 100, 138, 121, 101, 129, 130, 138, 150, 139, + 76, 104, 86, 112, 133, 113, 91, 63, 73, 129, + 199, 193, 182, 181, 172, 119, 101, 83, 94, 76, + 161, 157, 152, 157, 158, 110, 90, 121, 96, 79, + 124, 107, 114, 88, 73, 152, 137, 121, 107, 99, + 57, 50, 100, 81, 74, 115, 96, 72, 49, 69, + 83, 68, 40, 53, 103, 36, 131, 107, 84, 64, + 236, 245, 242, 231, 213, 95, 109, 88, 69, 110, + 228, 221, 204, 182, 170, 129, 110, 97, 118, 104, + 98, 76, 98, 75, 61, 93, 77, 113, 91, 72, + 116, 94, 106, 134, 118, 177, 188, 169, 162, 153, + 163, 149, 131, 131, 132, 177, 163, 173, 168, 158, + 113, 131, 107, 113, 100, 132, 143, 131, 134, 142, + 45, 36, 121, 113, 102, 43, 95, 84, 67, 56, + 76, 82, 68, 48, 33, 55, 58, 59, 43, 65, + 66, 85, 66, 81, 94, 102, 82, 54, 33, 94, + 113, 111, 89, 60, 34, 138, 120, 101, 101, 86, + 88, 73, 55, 114, 115, 92, 74, 93, 77, 123, + 90, 117, 99, 79, 59, 97, 75, 97, 122, 104, + 233, 237, 227, 208, 190, 209, 230, 233, 240, 241, + 195, 197, 188, 167, 147, 204, 185, 168, 162, 157, + 142, 124, 119, 123, 106, 117, 110, 81, 121, 123, + 74, 116, 124, 119, 120, 178, 168, 146, 132, 125, + 102, 104, 105, 110, 114, 104, 82, 78, 100, 86, + 120, 102, 105, 93, 143, 127, 108, 128, 106, 88, + 177, 189, 203, 207, 215, 101, 131, 119, 95, 73, + 149, 139, 135, 147, 153, 160, 167, 165, 174, 177, + 120, 109, 134, 140, 145, 131, 130, 142, 139, 161, + 143, 158, 148, 145, 145, 123, 142, 132, 116, 102, + 40, 23, 79, 82, 84, 26, 83, 141, 130, 122, + 65, 46, 43, 89, 86, 28, 75, 80, 79, 98, + 84, 65, 47, 26, 44, 49, 112, 101, 100, 94, + 88, 76, 75, 48, 82, 104, 100, 75, 45, 15, + 99, 83, 63, 34, 30, 66, 55, 94, 118, 113, + 122, 106, 91, 68, 60, 135, 122, 104, 77, 59, + 82, 102, 84, 62, 46, 92, 74, 55, 82, 71, + 145, 134, 118, 93, 75, 79, 62, 83, 65, 55, + 91, 94, 64, 70, 98, 89, 117, 110, 87, 97, + 210, 223, 225, 223, 213, 83, 103, 86, 101, 85, + 126, 106, 81, 79, 105, 216, 219, 217, 199, 179, + 86, 78, 115, 138, 135, 102, 84, 87, 59, 46, + 219, 206, 184, 167, 158, 201, 188, 165, 145, 135, + 87, 113, 142, 152, 155, 190, 170, 153, 149, 146, + 205, 208, 201, 185, 167, 84, 73, 124, 104, 96, + 76, 88, 99, 74, 80, 110, 125, 122, 99, 112, + 108, 84, 70, 130, 137, 161, 152, 136, 119, 105, + 110, 91, 101, 74, 96, 111, 101, 93, 153, 149, + 133, 124, 102, 97, 120, 101, 93, 75, 81, 64, + 111, 94, 107, 79, 58, 188, 206, 215, 221, 232, + 163, 175, 165, 150, 136, 103, 106, 123, 133, 132, + 168, 184, 191, 183, 170, 110, 117, 90, 98, 93, + 104, 87, 122, 98, 127, 129, 110, 127, 113, 125, + 134, 118, 102, 140, 132, 186, 199, 202, 198, 188, + 149, 147, 175, 185, 186, 117, 93, 99, 112, 93, + 107, 138, 138, 129, 128, 96, 129, 104, 118, 134, + 145, 136, 115, 121, 129, 138, 155, 148, 134, 120, + 170, 151, 150, 145, 138, 168, 173, 185, 194, 200, + 144, 159, 172, 168, 156, 121, 121, 138, 173, 168, + 126, 111, 140, 139, 117, 149, 133, 142, 137, 130, + 143, 139, 158, 158, 146, 119, 128, 121, 132, 145, + 122, 136, 159, 153, 141, 133, 133, 130, 129, 126, + 120, 76, 50, 149, 109, 92, 155, 118, 90, 66, + 132, 117, 87, 156, 117, 119, 102, 44, 83, 91, + 109, 73, 106, 84, 29, 55, 130, 112, 81, 241, + 75, 40, 91, 89, 67, 112, 90, 149, 81, 72, + 128, 90, 71, 28, 160, 73, 157, 123, 143, 108, + 63, 88, 70, 81, 97, 75, 111, 149, 113, 96, + 78, 104, 83, 179, 95, 105, 106, 65, 130, 66, + 51, 118, 92, 53, 68, 105, 75, 176, 151, 115, + 94, 75, 68, 95, 220, 103, 125, 105, 43, 95, + 39, 114, 65, 145, 135, 33, 142, 138, 103, 52, + 82, 85, 117, 110, 67, 102, 74, 42, 62, 118, + 144, 121, 82, 57, 102, 67, 75, 44, 129, 96, + 75, 63, 88, 48, 116, 135, 94, 85, 102, 66, + 122, 77, 105, 122, 152, 120, 56, 90, 83, 100, + 90, 128, 63, 80, 103, 126, 117, 103, 80, 193, + 42, 73, 117, 93, 91, 95, 128, 100, 128, 162, + 70, 120, 126, 73, 123, 99, 99, 91, 75, 135, + 81, 125, 111, 77, 13, 94, 78, 85, 187, 157, + 11, 143, 109, 99, 119, 53, 141, 82, 122, 68, + 132, 89, 136, 119, 88, 75, 49, 174, 119, 70, + 138, 121, 108, 78, 52, 104, 90, 96, 93, 93, + 114, 90, 78, 46, 58, 62, 114, 69, 44, 162, + 103, 58, 98, 141, 83, 137, 95, 119, 73, 111, + 81, 46, 126, 111, 123, 107, 117, 122, 121, 54, + 106, 104, 59, 110, 148, 97, 155, 97, 83, 133, + 97, 71, 57, 91, 58, 52, 79, 127, 152, 109, + 96, 92, 145, 107, 149, 102, 61, 125, 61, 170, + 56, 89, 77, 106, 38, 147, 96, 77, 105, 123, + 85, 83, 117, 63, 69, 126, 133, 93, 107, 92, + 77, 115, 95, 111, 103, 61, 87, 103, 98, 155, + 94, 111, 80, 78, 54, 117, 128, 130, 99, 109, + 106, 99, 113, 133, 115, 89, 65, 74, 112, 127 +}; + +static const uint8_t wmavoice_dq_lsp16i3[0x300] = { + 70, 100, 121, 129, 132, 132, 201, 188, 165, 145, 144, 136, + 112, 127, 116, 125, 130, 129, 124, 135, 135, 146, 129, 128, + 162, 158, 144, 151, 135, 129, 103, 86, 111, 113, 112, 122, + 90, 139, 129, 117, 126, 129, 142, 145, 167, 147, 124, 124, + 230, 209, 189, 175, 156, 141, 64, 80, 86, 108, 121, 129, + 44, 79, 115, 113, 115, 128, 133, 106, 79, 109, 125, 127, + 171, 156, 132, 109, 103, 115, 106, 70, 93, 145, 141, 128, + 148, 125, 122, 107, 110, 117, 146, 145, 128, 110, 98, 111, + 237, 212, 185, 156, 139, 133, 84, 55, 26, 77, 114, 127, + 172, 170, 171, 168, 162, 143, 82, 82, 76, 70, 104, 126, + 17, 95, 109, 111, 120, 132, 81, 74, 57, 126, 141, 131, + 110, 127, 162, 148, 129, 123, 177, 172, 155, 151, 145, 134, + 144, 123, 90, 66, 109, 130, 82, 127, 103, 123, 132, 131, + 127, 97, 97, 142, 140, 128, 159, 134, 136, 123, 113, 117, + 131, 140, 154, 169, 158, 134, 96, 109, 150, 122, 105, 120, + 120, 150, 152, 122, 119, 125, 123, 126, 124, 107, 100, 113, + 248, 233, 216, 189, 160, 142, 58, 24, 13, 77, 111, 127, + 183, 189, 182, 157, 140, 131, 96, 83, 59, 43, 73, 119, + 222, 196, 171, 146, 129, 128, 32, 13, 53, 101, 114, 127, + 119, 101, 70, 70, 110, 127, 77, 86, 161, 148, 130, 118, + 199, 183, 170, 167, 156, 141, 30, 115, 142, 133, 131, 130, + 101, 103, 181, 176, 152, 126, 66, 44, 73, 94, 111, 128, + 150, 122, 100, 101, 104, 118, 61, 110, 87, 76, 93, 125, + 190, 170, 150, 134, 135, 129, 112, 89, 63, 123, 141, 132, + 175, 154, 136, 142, 140, 132, 117, 143, 129, 128, 136, 132, + 168, 142, 112, 113, 128, 128, 155, 169, 159, 144, 139, 131, + 61, 136, 144, 124, 112, 123, 86, 81, 104, 121, 129, 130, + 160, 127, 118, 150, 151, 134, 126, 115, 121, 132, 134, 131, + 137, 148, 144, 139, 140, 134, 106, 102, 105, 90, 87, 113, + 134, 129, 128, 121, 121, 123, 153, 151, 129, 139, 142, 134, + 150, 142, 141, 148, 149, 141, 100, 121, 133, 147, 150, 134, + 163, 158, 147, 132, 141, 132, 142, 127, 141, 136, 136, 132, + 232, 218, 205, 189, 169, 146, 243, 224, 201, 171, 147, 138, + 224, 196, 169, 162, 154, 140, 51, 20, 59, 111, 121, 128, + 203, 197, 193, 177, 162, 145, 75, 40, 47, 122, 130, 129, + 102, 77, 47, 83, 121, 129, 111, 108, 84, 56, 63, 114, + 211, 181, 154, 137, 126, 125, 213, 198, 186, 162, 144, 138, + 41, 45, 90, 110, 118, 130, 83, 63, 130, 164, 153, 128, + 195, 167, 142, 123, 113, 119, 19, 42, 105, 113, 120, 132, + 50, 63, 49, 64, 112, 128, 114, 90, 132, 171, 162, 134, + 129, 128, 107, 83, 74, 110, 50, 116, 109, 120, 128, 132, + 94, 59, 73, 111, 117, 126, 197, 170, 166, 153, 138, 132, + 65, 48, 109, 133, 131, 128, 170, 163, 172, 158, 138, 130, + 66, 126, 147, 160, 151, 132, 42, 129, 117, 95, 91, 120, + 97, 165, 164, 142, 133, 125, 163, 142, 114, 88, 97, 122, + 104, 77, 142, 143, 128, 120, 136, 160, 188, 169, 149, 130, + 113, 83, 85, 102, 114, 125, 164, 169, 142, 120, 122, 124, + 98, 152, 132, 105, 92, 117, 42, 71, 125, 155, 151, 137, + 94, 105, 81, 107, 118, 126, 84, 56, 123, 117, 108, 122, + 174, 179, 166, 137, 118, 121, 130, 103, 147, 152, 134, 124, + 148, 127, 94, 117, 144, 134, 129, 106, 102, 95, 106, 118, + 147, 157, 153, 125, 103, 117, 155, 128, 113, 132, 120, 122, + 181, 151, 136, 126, 122, 122, 110, 111, 109, 108, 120, 124, + 97, 130, 103, 89, 107, 124, 179, 158, 158, 142, 131, 128, + 142, 111, 115, 122, 126, 125, 145, 145, 134, 115, 129, 128, + 130, 139, 112, 99, 121, 125, 79, 104, 119, 102, 105, 123, + 116, 121, 136, 125, 126, 127, 124, 100, 122, 119, 111, 119, + 159, 140, 139, 128, 138, 131, 105, 100, 116, 128, 135, 132, + 159, 142, 156, 147, 140, 134, 130, 150, 129, 126, 114, 120, + 138, 124, 146, 131, 109, 119, 93, 115, 125, 131, 125, 129, + 125, 121, 101, 119, 114, 120, 163, 154, 151, 153, 153, 139, + 166, 153, 150, 133, 119, 121, 159, 151, 128, 130, 122, 123, + 147, 154, 144, 133, 128, 127, 129, 131, 134, 140, 148, 138, + 138, 136, 120, 131, 135, 131, 150, 140, 137, 144, 129, 129 +}; + +static const uint8_t wmavoice_dq_lsp10r[0x1400] = { + 128, 128, 129, 129, 130, 130, 131, 130, 129, 129, + 134, 133, 127, 125, 136, 135, 135, 134, 173, 172, + 133, 139, 136, 165, 133, 176, 137, 159, 135, 152, + 147, 161, 147, 152, 149, 156, 146, 146, 140, 136, + 134, 135, 136, 140, 139, 155, 123, 133, 132, 142, + 132, 148, 143, 177, 124, 143, 123, 136, 126, 134, + 126, 125, 125, 124, 129, 128, 123, 123, 133, 133, + 116, 116, 121, 121, 121, 120, 129, 128, 131, 131, + 132, 133, 132, 129, 138, 124, 138, 124, 132, 100, + 135, 94, 149, 111, 152, 115, 150, 128, 141, 133, + 129, 129, 130, 129, 147, 145, 136, 137, 120, 122, + 120, 122, 127, 129, 104, 108, 113, 115, 124, 124, + 140, 139, 147, 145, 132, 130, 184, 177, 201, 196, + 170, 171, 160, 161, 145, 147, 137, 145, 131, 131, + 130, 130, 130, 130, 130, 130, 132, 134, 131, 132, + 131, 133, 141, 144, 142, 149, 84, 93, 103, 104, + 139, 139, 142, 140, 147, 147, 172, 165, 122, 121, + 98, 100, 101, 106, 112, 117, 122, 124, 124, 124, + 134, 133, 133, 133, 146, 142, 147, 145, 156, 156, + 143, 146, 119, 124, 129, 132, 151, 149, 136, 135, + 147, 148, 181, 180, 199, 188, 190, 173, 166, 161, + 147, 142, 153, 149, 154, 146, 150, 146, 138, 134, + 131, 135, 96, 136, 48, 138, 56, 131, 63, 124, + 85, 128, 103, 132, 117, 134, 120, 132, 125, 129, + 131, 130, 129, 128, 129, 128, 163, 168, 117, 120, + 121, 121, 136, 138, 131, 132, 135, 136, 131, 133, + 133, 133, 133, 134, 117, 118, 105, 109, 142, 151, + 144, 159, 131, 138, 121, 126, 123, 123, 121, 124, + 131, 131, 129, 129, 141, 140, 142, 134, 87, 90, + 109, 109, 130, 127, 139, 143, 133, 131, 127, 126, + 134, 135, 134, 136, 97, 98, 130, 132, 134, 137, + 115, 119, 125, 130, 107, 109, 119, 118, 126, 127, + 134, 135, 127, 132, 172, 203, 160, 196, 152, 179, + 152, 172, 148, 168, 153, 172, 145, 156, 137, 140, + 102, 116, 42, 56, 74, 61, 82, 70, 86, 78, + 101, 97, 104, 100, 115, 108, 116, 108, 123, 118, + 149, 143, 166, 129, 168, 96, 142, 95, 135, 98, + 117, 86, 116, 93, 121, 108, 119, 107, 121, 117, + 135, 135, 127, 138, 72, 132, 99, 136, 112, 147, + 120, 152, 136, 155, 138, 146, 140, 142, 134, 139, + 163, 145, 192, 130, 147, 124, 147, 125, 133, 125, + 127, 124, 128, 123, 129, 122, 130, 122, 130, 125, + 130, 137, 135, 180, 124, 133, 130, 129, 132, 133, + 124, 124, 131, 130, 132, 136, 126, 124, 127, 125, + 132, 132, 133, 133, 144, 140, 143, 142, 137, 135, + 143, 138, 152, 149, 221, 219, 158, 161, 143, 141, + 130, 129, 140, 135, 170, 145, 193, 156, 186, 152, + 167, 139, 151, 131, 142, 127, 134, 120, 131, 125, + 135, 133, 141, 125, 199, 109, 137, 126, 134, 123, + 130, 129, 132, 123, 128, 125, 122, 126, 125, 125, + 130, 128, 91, 89, 138, 135, 139, 134, 133, 129, + 132, 130, 125, 128, 136, 135, 129, 127, 126, 126, + 132, 131, 133, 131, 128, 120, 132, 126, 126, 119, + 134, 130, 131, 123, 104, 95, 140, 141, 136, 137, + 133, 133, 133, 134, 117, 98, 74, 49, 112, 111, + 123, 122, 126, 127, 131, 131, 127, 126, 128, 129, + 130, 131, 124, 127, 101, 107, 108, 109, 115, 115, + 100, 99, 130, 128, 134, 136, 125, 127, 128, 130, + 136, 137, 145, 150, 149, 164, 136, 151, 114, 111, + 124, 125, 143, 150, 162, 174, 158, 169, 136, 137, + 131, 131, 131, 131, 132, 133, 111, 110, 122, 121, + 136, 136, 134, 133, 131, 132, 127, 127, 125, 125, + 128, 129, 129, 130, 125, 127, 140, 140, 148, 149, + 133, 136, 146, 153, 110, 118, 127, 129, 128, 129, + 131, 133, 127, 131, 140, 161, 167, 224, 131, 139, + 136, 143, 135, 139, 138, 143, 149, 155, 141, 143, + 134, 132, 120, 111, 83, 83, 121, 126, 102, 107, + 112, 115, 97, 104, 120, 115, 129, 123, 122, 122, + 134, 135, 122, 131, 102, 124, 114, 119, 93, 103, + 78, 79, 67, 72, 66, 73, 78, 82, 103, 102, + 144, 135, 165, 139, 165, 129, 160, 126, 153, 127, + 161, 134, 160, 142, 160, 143, 148, 140, 138, 135, + 138, 95, 147, 54, 143, 78, 140, 112, 142, 113, + 140, 121, 135, 117, 135, 122, 136, 131, 131, 132, + 147, 159, 140, 156, 127, 81, 142, 128, 146, 127, + 144, 125, 146, 128, 149, 130, 144, 135, 133, 128, + 130, 131, 131, 131, 134, 139, 126, 134, 141, 154, + 168, 205, 153, 176, 148, 163, 147, 158, 141, 143, + 131, 135, 126, 146, 108, 157, 107, 156, 119, 146, + 100, 138, 104, 125, 119, 134, 101, 122, 113, 122, + 95, 133, 52, 140, 83, 136, 110, 133, 114, 131, + 123, 131, 133, 131, 138, 135, 132, 132, 127, 127, + 129, 128, 124, 122, 128, 126, 145, 170, 143, 172, + 141, 163, 143, 176, 138, 164, 139, 155, 135, 145, + 135, 136, 136, 127, 132, 76, 128, 76, 127, 63, + 125, 66, 123, 67, 120, 71, 124, 92, 122, 111, + 133, 133, 135, 136, 139, 140, 147, 147, 150, 144, + 156, 147, 150, 145, 154, 146, 120, 123, 123, 124, + 137, 133, 170, 141, 124, 124, 135, 134, 134, 135, + 132, 132, 129, 129, 130, 130, 136, 136, 130, 132, + 147, 159, 135, 158, 115, 146, 120, 148, 117, 136, + 115, 137, 113, 132, 133, 142, 140, 144, 132, 134, + 134, 135, 134, 137, 137, 147, 162, 178, 136, 147, + 134, 144, 123, 132, 111, 113, 113, 113, 124, 124, + 132, 131, 126, 126, 117, 114, 100, 95, 130, 125, + 157, 145, 164, 156, 163, 158, 145, 145, 133, 134, + 134, 134, 127, 126, 113, 102, 136, 130, 124, 122, + 143, 145, 127, 131, 135, 143, 133, 137, 132, 132, + 92, 94, 122, 125, 128, 129, 131, 130, 134, 135, + 132, 128, 129, 127, 132, 132, 131, 129, 127, 127, + 129, 129, 132, 131, 139, 131, 137, 132, 216, 178, + 146, 134, 147, 137, 151, 142, 148, 139, 144, 138, + 128, 127, 129, 129, 123, 131, 71, 91, 126, 128, + 130, 134, 117, 123, 125, 125, 135, 140, 129, 132, + 132, 132, 133, 134, 124, 130, 127, 133, 133, 138, + 142, 149, 135, 141, 145, 149, 154, 164, 135, 138, + 135, 135, 141, 142, 138, 137, 116, 96, 105, 86, + 127, 118, 128, 120, 124, 117, 125, 117, 125, 121, + 131, 131, 132, 134, 144, 145, 112, 112, 121, 123, + 113, 116, 121, 123, 139, 138, 128, 128, 131, 131, + 134, 132, 132, 132, 125, 128, 127, 130, 125, 131, + 120, 128, 90, 119, 68, 98, 99, 112, 115, 124, + 135, 135, 134, 134, 128, 129, 137, 137, 137, 138, + 110, 114, 129, 130, 144, 145, 123, 125, 129, 129, + 132, 133, 129, 130, 168, 187, 140, 149, 137, 144, + 129, 130, 129, 134, 133, 138, 118, 118, 122, 120, + 131, 130, 129, 128, 133, 133, 125, 125, 124, 123, + 181, 179, 129, 129, 131, 127, 139, 136, 130, 128, + 133, 133, 132, 132, 121, 120, 122, 119, 132, 129, + 129, 125, 107, 96, 136, 137, 150, 146, 135, 134, + 131, 131, 130, 130, 126, 123, 126, 123, 128, 125, + 130, 123, 134, 127, 183, 159, 143, 135, 137, 134, + 129, 129, 128, 128, 134, 133, 139, 138, 133, 132, + 129, 127, 154, 151, 150, 144, 146, 146, 141, 142, + 132, 132, 131, 131, 130, 130, 132, 133, 114, 115, + 132, 132, 122, 122, 132, 131, 115, 117, 120, 120, + 129, 129, 130, 130, 130, 129, 130, 131, 129, 131, + 130, 130, 129, 129, 133, 132, 143, 144, 91, 91, + 137, 136, 118, 107, 60, 45, 56, 49, 57, 52, + 60, 56, 71, 75, 77, 80, 92, 97, 106, 106, + 112, 131, 58, 121, 19, 65, 84, 101, 108, 122, + 121, 127, 112, 117, 106, 112, 117, 124, 126, 127, + 130, 129, 138, 133, 166, 155, 192, 179, 192, 177, + 208, 191, 204, 192, 186, 179, 163, 163, 138, 142, + 134, 134, 144, 142, 243, 236, 148, 146, 141, 137, + 145, 141, 151, 144, 147, 143, 135, 139, 134, 133, + 134, 128, 138, 88, 142, 10, 127, 76, 130, 96, + 129, 102, 128, 108, 123, 111, 127, 119, 127, 124, + 136, 136, 139, 139, 142, 140, 246, 241, 158, 167, + 143, 145, 146, 149, 143, 145, 148, 152, 133, 134, + 139, 135, 135, 136, 99, 137, 95, 133, 75, 138, + 67, 135, 73, 128, 83, 132, 96, 126, 115, 127, + 130, 132, 137, 136, 140, 135, 134, 130, 137, 131, + 159, 151, 215, 197, 181, 170, 160, 149, 150, 143, + 145, 148, 186, 207, 141, 147, 135, 137, 122, 122, + 126, 125, 128, 126, 127, 127, 134, 126, 131, 123, + 133, 133, 126, 122, 128, 122, 99, 93, 59, 60, + 82, 82, 106, 107, 119, 123, 124, 128, 128, 129, + 134, 137, 133, 139, 133, 136, 141, 132, 139, 122, + 142, 97, 130, 81, 128, 89, 129, 101, 125, 112, + 137, 140, 129, 148, 101, 159, 118, 180, 122, 178, + 120, 178, 116, 168, 118, 153, 127, 151, 126, 136, + 132, 134, 125, 126, 118, 105, 156, 124, 180, 132, + 163, 124, 148, 121, 131, 112, 127, 115, 125, 122, + 129, 131, 128, 129, 136, 134, 142, 141, 165, 158, + 203, 182, 141, 136, 132, 130, 135, 135, 130, 130, + 133, 133, 132, 132, 127, 126, 106, 105, 112, 110, + 106, 105, 80, 84, 100, 101, 122, 125, 126, 128, + 101, 109, 46, 59, 114, 112, 119, 119, 126, 121, + 129, 124, 128, 125, 125, 122, 123, 120, 125, 122, + 135, 134, 121, 134, 56, 139, 131, 145, 135, 138, + 136, 139, 126, 130, 122, 132, 126, 129, 124, 129, + 153, 169, 146, 179, 138, 139, 151, 143, 148, 138, + 153, 137, 142, 129, 144, 126, 140, 128, 133, 126, + 136, 134, 154, 149, 173, 157, 152, 144, 149, 141, + 137, 136, 127, 121, 123, 121, 121, 126, 120, 123, + 157, 143, 166, 135, 120, 122, 112, 118, 102, 118, + 111, 124, 134, 131, 141, 138, 135, 134, 126, 129, + 140, 123, 152, 76, 131, 116, 138, 136, 126, 134, + 130, 142, 126, 136, 120, 132, 126, 128, 124, 127, + 131, 138, 80, 147, 126, 138, 130, 140, 129, 134, + 133, 135, 131, 132, 126, 127, 127, 125, 125, 123, + 132, 132, 130, 132, 123, 130, 102, 102, 107, 110, + 116, 127, 132, 152, 142, 160, 143, 151, 142, 146, + 132, 132, 132, 132, 125, 126, 132, 140, 158, 199, + 135, 149, 134, 140, 135, 131, 129, 120, 127, 121, + 129, 130, 122, 123, 125, 124, 138, 138, 138, 135, + 140, 141, 101, 94, 105, 98, 121, 122, 127, 128, + 126, 127, 119, 121, 133, 156, 132, 159, 130, 148, + 137, 164, 127, 138, 130, 137, 135, 140, 126, 126, + 128, 129, 129, 129, 126, 124, 130, 128, 143, 138, + 149, 143, 185, 170, 129, 127, 138, 133, 138, 135, + 132, 134, 137, 144, 139, 183, 131, 145, 127, 128, + 128, 127, 128, 122, 129, 125, 145, 139, 135, 131, + 132, 133, 132, 130, 152, 96, 159, 85, 150, 105, + 154, 115, 143, 120, 138, 126, 134, 124, 130, 126, + 128, 127, 121, 123, 122, 123, 116, 125, 84, 87, + 133, 135, 129, 131, 123, 126, 133, 135, 131, 130, + 136, 134, 129, 119, 79, 63, 116, 116, 136, 133, + 133, 130, 140, 143, 127, 127, 124, 125, 127, 128, + 128, 126, 124, 120, 139, 128, 153, 134, 151, 134, + 174, 145, 159, 136, 165, 144, 171, 149, 143, 135, + 134, 134, 133, 133, 121, 119, 177, 162, 166, 154, + 127, 130, 132, 132, 136, 137, 142, 143, 138, 137, + 167, 151, 162, 142, 128, 136, 142, 148, 128, 143, + 145, 153, 140, 149, 132, 141, 128, 139, 127, 133, + 156, 169, 131, 129, 126, 120, 127, 125, 129, 120, + 131, 126, 126, 123, 124, 121, 122, 121, 123, 123, + 138, 140, 149, 156, 145, 152, 105, 102, 131, 126, + 151, 146, 147, 139, 144, 137, 143, 133, 135, 130, + 132, 130, 131, 129, 126, 130, 126, 129, 110, 135, + 115, 139, 108, 146, 105, 147, 121, 134, 124, 133, + 137, 137, 135, 134, 143, 142, 146, 146, 120, 121, + 139, 137, 133, 129, 149, 145, 139, 133, 130, 127, + 134, 134, 134, 134, 125, 124, 117, 119, 120, 113, + 84, 80, 122, 125, 108, 112, 97, 102, 118, 120, + 124, 123, 115, 116, 110, 111, 98, 97, 127, 124, + 129, 127, 120, 117, 114, 109, 106, 104, 116, 116, + 138, 138, 139, 141, 142, 146, 127, 125, 133, 130, + 134, 128, 134, 127, 116, 91, 105, 84, 114, 106, + 128, 128, 126, 126, 131, 137, 126, 129, 133, 139, + 134, 145, 132, 143, 150, 192, 131, 142, 138, 141, + 132, 130, 132, 130, 149, 138, 196, 152, 137, 125, + 134, 125, 139, 128, 133, 125, 141, 134, 134, 135, + 134, 135, 134, 135, 131, 130, 136, 133, 110, 106, + 142, 144, 153, 162, 131, 129, 134, 132, 131, 130, + 126, 125, 132, 130, 168, 153, 126, 124, 130, 126, + 140, 135, 140, 134, 138, 133, 145, 137, 135, 134, + 130, 130, 132, 131, 133, 132, 129, 129, 125, 128, + 128, 130, 133, 139, 143, 152, 193, 215, 152, 160, + 130, 131, 129, 131, 130, 131, 135, 136, 136, 141, + 83, 81, 121, 120, 136, 130, 150, 145, 147, 145, + 134, 133, 135, 133, 146, 142, 135, 131, 127, 128, + 134, 135, 93, 102, 126, 132, 131, 133, 127, 129, + 124, 125, 120, 122, 103, 106, 128, 129, 139, 138, + 127, 128, 134, 134, 143, 138, 139, 134, 135, 133, + 131, 130, 133, 131, 139, 134, 138, 136, 166, 156, + 119, 116, 121, 122, 126, 124, 116, 117, 123, 124, + 131, 131, 129, 129, 130, 128, 141, 138, 135, 132, + 154, 145, 137, 129, 131, 125, 146, 137, 138, 135, + 131, 131, 131, 132, 129, 130, 134, 138, 111, 116, + 113, 118, 123, 125, 122, 124, 143, 147, 138, 140, + 116, 113, 114, 112, 130, 126, 117, 115, 127, 126, + 139, 137, 141, 139, 131, 132, 143, 144, 139, 140, + 130, 130, 129, 128, 136, 134, 119, 117, 152, 143, + 155, 143, 120, 119, 142, 139, 124, 130, 126, 128, + 112, 110, 112, 109, 136, 132, 125, 118, 121, 115, + 103, 101, 109, 100, 125, 120, 121, 117, 122, 121, + 128, 128, 127, 127, 124, 124, 128, 127, 131, 129, + 142, 138, 147, 141, 115, 108, 113, 109, 122, 119, + 136, 133, 150, 139, 142, 131, 119, 111, 151, 137, + 121, 116, 146, 134, 137, 129, 121, 123, 127, 129, + 130, 130, 130, 130, 136, 137, 126, 126, 136, 136, + 133, 133, 139, 139, 142, 143, 119, 120, 134, 134, + 132, 132, 133, 133, 135, 138, 129, 131, 133, 134, + 135, 138, 126, 130, 117, 118, 131, 132, 135, 135, + 129, 129, 128, 128, 126, 129, 127, 129, 123, 125, + 115, 117, 156, 157, 127, 131, 129, 129, 128, 129, + 129, 130, 131, 131, 126, 127, 135, 134, 136, 135, + 140, 136, 117, 113, 132, 128, 104, 97, 109, 106, + 131, 131, 131, 131, 121, 123, 124, 125, 126, 127, + 127, 127, 135, 135, 128, 128, 130, 130, 141, 140, + 129, 129, 129, 129, 129, 127, 127, 125, 149, 146, + 125, 123, 134, 133, 134, 132, 152, 150, 138, 138, + 128, 128, 126, 125, 132, 133, 141, 143, 136, 136, + 126, 127, 126, 127, 129, 131, 128, 129, 135, 134, + 176, 139, 192, 135, 145, 122, 149, 117, 155, 134, + 169, 133, 157, 139, 142, 136, 151, 152, 142, 147, + 166, 174, 103, 107, 141, 134, 140, 136, 144, 135, + 147, 135, 156, 131, 153, 127, 133, 126, 130, 124, + 127, 130, 123, 124, 114, 105, 195, 193, 156, 157, + 165, 158, 126, 122, 149, 141, 174, 173, 152, 147, + 136, 139, 131, 138, 163, 169, 103, 124, 80, 102, + 153, 186, 121, 151, 134, 161, 156, 190, 141, 151, + 121, 123, 124, 127, 119, 127, 133, 134, 157, 156, + 81, 69, 136, 134, 160, 169, 118, 114, 135, 128, + 114, 116, 97, 97, 117, 122, 152, 161, 115, 121, + 106, 122, 135, 137, 111, 113, 125, 135, 141, 145, + 143, 146, 143, 150, 132, 136, 142, 150, 151, 167, + 101, 107, 155, 173, 112, 124, 105, 100, 128, 126, + 127, 130, 133, 134, 142, 121, 131, 116, 176, 145, + 161, 120, 209, 150, 196, 133, 147, 115, 149, 130, + 144, 145, 144, 145, 120, 119, 163, 160, 117, 118, + 123, 117, 154, 119, 193, 98, 149, 101, 137, 116, + 133, 135, 140, 143, 144, 156, 131, 146, 186, 201, + 140, 139, 123, 125, 158, 169, 157, 166, 142, 143, + 130, 131, 132, 132, 128, 128, 141, 142, 147, 149, + 145, 148, 137, 139, 129, 129, 107, 108, 157, 157, + 120, 121, 119, 119, 140, 132, 137, 131, 118, 113, + 143, 136, 134, 135, 164, 158, 133, 125, 127, 124, + 148, 122, 197, 130, 173, 145, 110, 139, 123, 165, + 83, 158, 90, 167, 93, 142, 136, 169, 134, 152, + 130, 126, 154, 138, 227, 150, 156, 114, 147, 114, + 142, 109, 135, 110, 166, 135, 176, 150, 152, 142, + 132, 132, 136, 136, 130, 135, 143, 152, 136, 144, + 152, 160, 177, 185, 112, 112, 165, 166, 160, 161, + 145, 145, 138, 139, 116, 118, 127, 131, 66, 80, + 132, 142, 119, 127, 101, 108, 120, 130, 126, 130, + 135, 135, 142, 139, 153, 137, 55, 30, 142, 139, + 139, 143, 135, 133, 129, 133, 109, 108, 129, 129, + 136, 135, 134, 131, 129, 132, 132, 134, 135, 149, + 79, 206, 123, 137, 135, 143, 130, 140, 131, 134, + 100, 99, 165, 164, 142, 123, 148, 133, 133, 122, + 142, 133, 138, 125, 119, 111, 129, 123, 137, 130, + 131, 132, 123, 129, 174, 185, 196, 181, 127, 111, + 156, 141, 132, 114, 129, 106, 132, 107, 126, 117, + 134, 140, 131, 136, 119, 146, 92, 246, 128, 132, + 125, 129, 132, 140, 128, 141, 126, 145, 137, 142, + 130, 130, 110, 115, 124, 139, 127, 151, 118, 152, + 98, 146, 36, 108, 126, 158, 112, 146, 112, 130, + 138, 136, 145, 138, 153, 145, 116, 125, 90, 103, + 137, 138, 189, 185, 141, 151, 86, 93, 111, 111, + 133, 171, 125, 209, 140, 132, 130, 134, 129, 101, + 142, 120, 142, 132, 135, 126, 141, 140, 140, 134, + 128, 123, 131, 123, 138, 118, 163, 133, 240, 197, + 176, 151, 126, 123, 81, 94, 109, 118, 124, 133, + 135, 133, 137, 134, 154, 135, 140, 155, 69, 190, + 119, 149, 141, 151, 142, 123, 135, 125, 129, 130, + 127, 125, 132, 127, 107, 80, 123, 103, 145, 131, + 133, 107, 140, 103, 135, 106, 170, 145, 159, 143, + 136, 137, 127, 130, 105, 119, 129, 134, 141, 151, + 116, 127, 119, 140, 75, 119, 152, 162, 149, 152, + 72, 138, 9, 143, 118, 160, 126, 134, 141, 147, + 135, 131, 129, 129, 135, 129, 136, 126, 133, 125, + 137, 135, 146, 141, 145, 139, 141, 140, 133, 130, + 213, 208, 139, 130, 139, 136, 117, 117, 126, 125, + 133, 130, 138, 131, 141, 100, 145, 93, 159, 121, + 144, 132, 117, 160, 102, 187, 99, 162, 117, 144, + 132, 132, 134, 134, 140, 141, 127, 126, 128, 131, + 116, 116, 121, 127, 119, 126, 114, 114, 99, 100, + 141, 144, 148, 159, 179, 224, 95, 131, 100, 125, + 87, 110, 112, 132, 134, 147, 111, 125, 122, 122, + 137, 140, 141, 129, 169, 12, 144, 132, 133, 144, + 141, 146, 137, 147, 136, 122, 133, 130, 131, 128, + 141, 142, 128, 139, 15, 69, 160, 159, 142, 130, + 137, 126, 159, 141, 145, 143, 128, 125, 134, 128, + 131, 130, 127, 127, 114, 104, 119, 98, 83, 68, + 139, 120, 173, 142, 199, 154, 191, 153, 158, 145, + 128, 130, 127, 127, 148, 150, 110, 99, 119, 109, + 120, 113, 163, 154, 110, 90, 138, 129, 149, 144, + 131, 134, 124, 142, 76, 217, 130, 129, 140, 138, + 133, 135, 145, 150, 136, 138, 127, 130, 130, 134, + 144, 119, 178, 70, 143, 130, 115, 136, 139, 138, + 129, 109, 136, 116, 147, 122, 126, 112, 126, 123, + 132, 139, 128, 144, 107, 156, 75, 163, 120, 164, + 151, 136, 151, 99, 160, 112, 159, 126, 143, 126, + 140, 138, 137, 135, 152, 108, 251, 85, 138, 116, + 137, 118, 141, 119, 136, 121, 150, 134, 138, 131, + 137, 137, 143, 144, 150, 153, 148, 154, 152, 151, + 117, 104, 124, 96, 93, 67, 146, 138, 149, 148, + 149, 153, 172, 193, 108, 114, 125, 128, 145, 165, + 149, 160, 121, 130, 115, 120, 110, 112, 121, 118, + 145, 146, 141, 142, 127, 127, 103, 95, 138, 143, + 114, 126, 109, 115, 143, 136, 153, 149, 144, 142, + 140, 138, 150, 144, 128, 116, 142, 136, 135, 122, + 93, 88, 164, 163, 141, 142, 171, 182, 154, 160, + 124, 125, 122, 123, 158, 155, 111, 97, 138, 130, + 157, 134, 101, 65, 129, 118, 121, 114, 124, 119, + 131, 133, 125, 129, 136, 147, 135, 152, 131, 133, + 110, 115, 118, 114, 161, 159, 233, 218, 172, 166, + 140, 107, 125, 0, 140, 103, 140, 115, 125, 113, + 132, 135, 128, 133, 138, 146, 131, 145, 127, 133, + 131, 131, 122, 122, 135, 132, 126, 124, 132, 133, + 164, 167, 121, 127, 117, 120, 167, 162, 145, 143, + 135, 134, 136, 134, 156, 146, 195, 177, 127, 139, + 108, 140, 141, 173, 141, 178, 131, 155, 129, 141, + 134, 134, 119, 114, 184, 184, 127, 126, 147, 151, + 130, 140, 146, 159, 134, 145, 131, 136, 137, 142, + 135, 137, 128, 136, 83, 108, 97, 98, 152, 119, + 207, 144, 142, 121, 144, 129, 131, 127, 130, 132, + 124, 125, 108, 107, 94, 116, 81, 114, 139, 173, + 131, 158, 145, 177, 141, 163, 136, 140, 143, 144, + 135, 141, 132, 136, 134, 142, 142, 136, 173, 50, + 143, 106, 142, 127, 134, 139, 127, 133, 125, 125, + 129, 130, 131, 133, 132, 148, 110, 138, 113, 135, + 138, 175, 108, 151, 55, 119, 51, 100, 93, 116, + 121, 121, 146, 151, 99, 120, 127, 137, 107, 122, + 125, 139, 110, 132, 135, 156, 141, 156, 148, 157, + 137, 137, 141, 140, 139, 137, 130, 128, 138, 136, + 132, 134, 115, 110, 177, 179, 81, 86, 100, 98, + 84, 83, 121, 121, 148, 157, 127, 133, 146, 156, + 127, 136, 143, 151, 135, 139, 138, 142, 136, 136, + 201, 164, 151, 129, 123, 136, 147, 148, 127, 142, + 128, 143, 101, 126, 119, 133, 114, 131, 116, 126, + 132, 133, 140, 140, 126, 125, 156, 153, 142, 129, + 140, 130, 77, 69, 134, 132, 146, 148, 135, 136, + 133, 132, 123, 116, 116, 103, 150, 135, 144, 127, + 130, 117, 136, 122, 122, 106, 48, 38, 81, 78, + 145, 146, 135, 136, 123, 122, 126, 133, 133, 138, + 145, 145, 144, 150, 160, 181, 142, 139, 150, 150, + 136, 136, 139, 139, 133, 133, 139, 135, 134, 129, + 140, 137, 153, 145, 132, 131, 151, 144, 68, 66, + 137, 137, 139, 139, 146, 146, 142, 139, 129, 128, + 131, 129, 133, 132, 135, 134, 135, 134, 201, 200, + 137, 136, 146, 143, 155, 153, 157, 158, 131, 138, + 140, 139, 143, 144, 128, 123, 216, 192, 159, 150, + 137, 138, 136, 142, 145, 148, 126, 162, 140, 170, + 186, 95, 131, 140, 143, 148, 133, 128, 130, 133, + 141, 139, 153, 150, 122, 122, 134, 144, 124, 130, + 159, 166, 133, 139, 151, 150, 138, 139, 131, 134, + 121, 121, 131, 129, 148, 180, 121, 135, 118, 131, + 124, 148, 119, 119, 129, 126, 150, 156, 155, 160, + 40, 154, 115, 157, 133, 129, 140, 133, 143, 133, + 143, 132, 144, 130, 141, 131, 134, 130, 137, 133, + 134, 136, 141, 140, 145, 137, 152, 124, 183, 91, + 118, 154, 123, 158, 136, 134, 140, 142, 138, 142, + 138, 135, 131, 131, 138, 129, 121, 128, 146, 219, + 124, 123, 125, 135, 120, 126, 127, 141, 133, 136, + 127, 124, 120, 107, 152, 125, 149, 108, 158, 144, + 196, 185, 174, 164, 151, 149, 138, 131, 140, 137, + 149, 148, 144, 145, 143, 145, 140, 143, 141, 147, + 112, 125, 113, 113, 149, 155, 143, 149, 146, 151, + 138, 138, 141, 138, 144, 129, 134, 125, 143, 140, + 153, 154, 142, 123, 162, 42, 154, 106, 153, 130, + 153, 153, 137, 137, 144, 144, 142, 140, 165, 151, + 161, 140, 144, 134, 156, 124, 167, 143, 166, 155, + 132, 132, 137, 138, 137, 132, 124, 127, 140, 144, + 134, 140, 162, 180, 127, 131, 152, 169, 145, 156, + 133, 134, 131, 133, 130, 132, 147, 149, 125, 117, + 127, 118, 159, 155, 147, 142, 122, 117, 145, 144, + 138, 137, 130, 133, 113, 149, 168, 224, 166, 201, + 129, 151, 147, 154, 136, 135, 140, 136, 152, 141, + 120, 112, 140, 127, 161, 100, 132, 115, 118, 125, + 115, 133, 115, 157, 144, 146, 114, 135, 127, 139, + 138, 141, 135, 135, 137, 136, 147, 142, 143, 144, + 139, 152, 142, 136, 147, 143, 177, 39, 125, 71, + 147, 143, 66, 88, 132, 158, 123, 126, 116, 135, + 119, 124, 128, 135, 133, 140, 137, 126, 137, 130, + 155, 38, 149, 103, 130, 135, 139, 143, 127, 137, + 135, 141, 138, 148, 131, 148, 136, 147, 132, 139, + 136, 140, 115, 129, 115, 151, 136, 160, 87, 131, + 157, 176, 150, 164, 140, 141, 135, 119, 137, 133, + 141, 140, 140, 139, 134, 134, 142, 144, 131, 132, + 131, 134, 131, 132, 116, 114, 129, 133, 205, 207, + 130, 133, 160, 170, 137, 127, 124, 112, 158, 146, + 155, 137, 134, 136, 137, 142, 177, 184, 149, 152, + 135, 134, 133, 132, 135, 129, 144, 136, 139, 134, + 161, 155, 126, 109, 215, 186, 177, 153, 160, 149, + 139, 139, 136, 140, 140, 142, 186, 71, 129, 144, + 131, 165, 142, 152, 140, 151, 141, 143, 137, 139, + 144, 138, 150, 135, 133, 126, 136, 143, 99, 152, + 139, 131, 190, 118, 122, 147, 134, 155, 136, 143, + 138, 135, 137, 132, 147, 144, 150, 144, 138, 134, + 129, 133, 130, 138, 56, 175, 129, 166, 147, 165, + 140, 138, 144, 137, 141, 133, 150, 139, 129, 135, + 40, 83, 126, 130, 110, 120, 100, 110, 126, 128, + 141, 142, 217, 175, 172, 151, 146, 153, 125, 132, + 128, 137, 141, 141, 145, 145, 140, 133, 132, 131, + 129, 144, 128, 177, 133, 195, 147, 120, 138, 131, + 161, 114, 166, 134, 162, 118, 161, 115, 155, 129, + 137, 136, 141, 129, 141, 132, 55, 168, 121, 126, + 136, 139, 120, 133, 149, 147, 132, 141, 131, 136, + 147, 150, 151, 132, 101, 31, 117, 101, 129, 132, + 122, 138, 128, 137, 140, 170, 131, 143, 131, 134, + 149, 192, 122, 158, 136, 146, 133, 166, 143, 141, + 141, 136, 141, 129, 125, 155, 140, 138, 137, 131, + 111, 112, 131, 132, 120, 127, 149, 148, 151, 141, + 156, 148, 133, 129, 127, 124, 144, 137, 142, 139, + 134, 133, 141, 138, 133, 135, 124, 96, 226, 152, + 116, 108, 128, 105, 155, 130, 153, 138, 144, 139, + 142, 141, 137, 135, 142, 143, 156, 162, 136, 89, + 188, 145, 181, 152, 138, 146, 146, 154, 145, 149, + 152, 133, 158, 133, 42, 153, 117, 144, 149, 139, + 125, 139, 134, 128, 150, 128, 143, 125, 135, 132, + 143, 141, 143, 141, 164, 173, 141, 142, 156, 155, + 154, 154, 169, 170, 77, 80, 112, 105, 135, 134, + 126, 143, 120, 172, 111, 144, 120, 154, 107, 153, + 95, 134, 104, 134, 128, 116, 163, 131, 151, 136, + 135, 133, 142, 143, 152, 204, 149, 112, 156, 128, + 150, 126, 127, 129, 139, 175, 143, 141, 138, 135, + 168, 148, 152, 105, 164, 121, 134, 122, 119, 109, + 122, 148, 136, 143, 153, 132, 158, 148, 149, 150, + 133, 131, 142, 141, 150, 149, 156, 173, 138, 155, + 129, 144, 111, 107, 130, 129, 96, 89, 106, 104, + 135, 135, 144, 146, 131, 153, 134, 154, 146, 166, + 117, 138, 163, 187, 190, 216, 149, 156, 149, 152, + 142, 142, 153, 154, 109, 145, 40, 102, 116, 126, + 137, 139, 149, 157, 108, 124, 139, 146, 142, 147, + 130, 126, 120, 111, 172, 146, 169, 136, 150, 135, + 126, 96, 159, 143, 150, 122, 162, 129, 156, 142, + 135, 142, 144, 138, 222, 109, 137, 145, 144, 142, + 141, 143, 138, 136, 124, 150, 133, 144, 137, 145, + 141, 144, 139, 144, 134, 154, 114, 136, 145, 173, + 151, 215, 110, 115, 127, 134, 145, 150, 145, 144, + 144, 142, 139, 131, 147, 132, 141, 119, 143, 106, + 165, 41, 147, 129, 129, 144, 138, 135, 138, 140, + 128, 150, 89, 163, 154, 115, 141, 127, 132, 145, + 135, 157, 143, 145, 140, 141, 127, 135, 127, 129, + 142, 147, 116, 147, 104, 162, 153, 143, 146, 130, + 144, 110, 133, 123, 130, 137, 118, 198, 126, 152, + 154, 146, 139, 127, 147, 112, 207, 151, 156, 136, + 162, 137, 108, 121, 130, 135, 125, 131, 131, 134, + 134, 134, 141, 144, 107, 143, 137, 144, 124, 136, + 115, 147, 130, 157, 119, 167, 71, 144, 97, 128, + 134, 138, 132, 133, 138, 138, 146, 146, 147, 131, + 141, 138, 185, 65, 145, 123, 139, 130, 142, 128, + 139, 136, 157, 147, 124, 119, 164, 148, 170, 154, + 133, 130, 157, 148, 140, 141, 130, 135, 134, 137, + 136, 137, 143, 144, 144, 144, 178, 186, 71, 73, + 120, 118, 127, 124, 152, 151, 155, 146, 141, 138, + 142, 143, 139, 143, 133, 134, 139, 140, 138, 135, + 146, 141, 78, 198, 129, 139, 141, 141, 134, 141, + 137, 136, 120, 120, 124, 118, 143, 148, 148, 152, + 131, 143, 129, 137, 152, 158, 157, 160, 175, 178, + 137, 139, 131, 133, 146, 152, 121, 147, 142, 143, + 129, 136, 149, 145, 197, 114, 103, 141, 124, 140, + 141, 140, 129, 129, 127, 130, 131, 124, 123, 117, + 150, 139, 120, 109, 119, 120, 163, 163, 117, 121, + 139, 139, 136, 136, 94, 74, 150, 145, 126, 127, + 147, 150, 158, 162, 84, 74, 136, 129, 140, 132, + 136, 135, 146, 145, 124, 116, 129, 120, 130, 129, + 130, 109, 122, 111, 160, 141, 135, 113, 131, 121, + 136, 135, 135, 135, 147, 147, 140, 140, 144, 145, + 139, 142, 131, 137, 145, 145, 143, 153, 48, 49, + 145, 143, 151, 147, 158, 146, 135, 124, 124, 116, + 159, 140, 131, 126, 123, 120, 103, 117, 113, 119, + 148, 146, 128, 124, 123, 126, 123, 120, 158, 141, + 148, 137, 146, 143, 125, 143, 89, 107, 116, 123, + 149, 147, 141, 139, 149, 153, 118, 121, 139, 138, + 105, 119, 168, 147, 139, 141, 143, 138, 133, 130, + 126, 126, 143, 142, 146, 144, 124, 123, 143, 145, + 149, 148, 147, 141, 151, 143, 118, 113, 175, 171 +}; + +static const uint8_t wmavoice_dq_lsp16r1[0x500] = { + 147, 145, 193, 168, 188, 156, 141, 145, 141, 139, + 148, 149, 148, 149, 153, 157, 144, 144, 152, 152, + 141, 145, 153, 143, 243, 134, 151, 133, 166, 135, + 150, 149, 135, 132, 32, 39, 110, 111, 109, 114, + 126, 127, 147, 146, 177, 169, 162, 156, 210, 187, + 141, 147, 95, 150, 127, 155, 108, 133, 139, 148, + 138, 138, 140, 140, 147, 146, 134, 130, 136, 134, + 147, 146, 142, 150, 62, 174, 126, 151, 122, 156, + 154, 156, 179, 184, 115, 107, 105, 99, 127, 124, + 146, 131, 140, 44, 132, 125, 156, 146, 153, 153, + 136, 137, 145, 144, 141, 139, 158, 152, 138, 132, + 145, 145, 147, 145, 146, 141, 144, 140, 110, 97, + 140, 141, 143, 142, 130, 123, 127, 117, 126, 120, + 147, 146, 161, 155, 169, 135, 122, 117, 166, 155, + 144, 144, 142, 142, 125, 122, 137, 128, 194, 172, + 127, 85, 148, 143, 153, 141, 147, 147, 140, 143, + 118, 140, 0, 69, 51, 60, 111, 123, 137, 135, + 146, 146, 164, 165, 207, 214, 145, 143, 149, 147, + 178, 168, 197, 170, 134, 154, 148, 159, 115, 140, + 103, 118, 13, 38, 139, 138, 135, 138, 140, 141, + 144, 144, 140, 140, 150, 150, 156, 157, 164, 171, + 143, 143, 140, 142, 118, 120, 172, 172, 160, 163, + 146, 147, 150, 151, 176, 176, 230, 237, 153, 153, + 168, 156, 173, 149, 164, 148, 162, 146, 178, 158, + 147, 145, 143, 145, 111, 126, 111, 130, 89, 118, + 153, 158, 122, 120, 142, 125, 124, 105, 148, 138, + 145, 144, 156, 151, 193, 154, 146, 147, 119, 135, + 142, 141, 145, 145, 152, 147, 142, 141, 146, 146, + 139, 138, 154, 154, 148, 150, 147, 149, 144, 145, + 134, 134, 141, 140, 135, 134, 145, 147, 160, 163, + 144, 145, 149, 146, 115, 67, 127, 119, 141, 135, + 145, 141, 130, 124, 143, 144, 151, 165, 141, 144, + 154, 152, 160, 136, 115, 82, 64, 71, 64, 65, + 143, 143, 151, 149, 240, 251, 165, 173, 173, 179, + 148, 134, 156, 55, 160, 105, 133, 91, 129, 96, + 149, 149, 145, 144, 160, 154, 171, 159, 140, 142, + 154, 163, 178, 244, 147, 140, 153, 150, 137, 121, + 145, 144, 145, 146, 138, 139, 149, 152, 189, 198, + 148, 148, 156, 158, 168, 182, 165, 182, 172, 201, + 143, 142, 99, 92, 152, 152, 143, 143, 127, 127, + 165, 148, 173, 124, 113, 122, 134, 142, 127, 142, + 124, 126, 137, 137, 131, 132, 144, 142, 141, 138, + 172, 176, 138, 111, 152, 136, 167, 154, 156, 137, + 140, 150, 78, 145, 158, 157, 161, 154, 155, 147, + 153, 164, 156, 191, 129, 109, 153, 146, 153, 141, + 138, 137, 141, 138, 115, 94, 144, 141, 155, 147, + 144, 142, 144, 137, 168, 113, 141, 134, 145, 137, + 146, 144, 150, 148, 140, 155, 103, 178, 137, 149, + 145, 147, 148, 153, 175, 201, 138, 146, 110, 108, + 143, 146, 124, 134, 124, 127, 164, 158, 127, 135, + 145, 146, 150, 150, 145, 147, 95, 80, 150, 151, + 149, 149, 162, 162, 144, 152, 170, 169, 145, 154, + 145, 149, 143, 146, 142, 145, 152, 146, 160, 98, + 141, 141, 153, 153, 140, 137, 131, 131, 145, 146, + 133, 132, 127, 124, 158, 150, 173, 164, 178, 167, + 146, 146, 154, 155, 117, 127, 143, 147, 147, 156, + 142, 143, 144, 145, 146, 152, 170, 199, 151, 165, + 146, 147, 139, 140, 147, 149, 132, 134, 147, 149, + 138, 139, 142, 143, 162, 188, 145, 149, 160, 164, + 150, 150, 139, 139, 143, 142, 146, 146, 137, 138, + 142, 142, 141, 140, 152, 153, 164, 171, 110, 112, + 139, 139, 143, 143, 138, 138, 142, 142, 143, 143, + 137, 140, 142, 142, 145, 141, 149, 141, 182, 135, + 146, 146, 150, 150, 144, 145, 150, 151, 135, 137, + 137, 145, 51, 62, 68, 54, 69, 57, 62, 41, + 137, 139, 139, 144, 135, 150, 225, 232, 208, 197, + 136, 135, 141, 143, 145, 150, 160, 169, 213, 247, + 142, 137, 72, 54, 110, 107, 105, 107, 127, 130, + 145, 143, 169, 155, 219, 174, 195, 164, 183, 157, + 155, 157, 239, 232, 169, 164, 170, 172, 156, 159, + 142, 143, 136, 144, 59, 100, 139, 142, 130, 138, + 147, 146, 150, 161, 128, 235, 143, 155, 146, 167, + 154, 149, 128, 151, 42, 149, 55, 136, 59, 127, + 128, 126, 74, 92, 143, 153, 140, 150, 166, 176, + 146, 152, 150, 145, 140, 100, 140, 105, 124, 59, + 195, 191, 146, 148, 144, 136, 136, 133, 129, 122, + 133, 148, 40, 147, 102, 140, 123, 148, 118, 136, + 143, 143, 150, 148, 184, 153, 160, 147, 166, 149, + 58, 68, 127, 135, 141, 145, 143, 147, 150, 151, + 140, 143, 137, 137, 120, 114, 71, 65, 125, 123, + 153, 148, 215, 159, 136, 135, 150, 146, 150, 150, + 148, 138, 166, 94, 150, 145, 145, 139, 147, 145, + 146, 147, 150, 139, 171, 63, 158, 142, 153, 133, + 147, 148, 143, 143, 76, 72, 155, 159, 164, 176, + 149, 149, 173, 195, 145, 165, 138, 144, 150, 167, + 180, 169, 146, 151, 146, 166, 147, 166, 149, 171, + 157, 156, 168, 166, 147, 149, 121, 122, 116, 124, + 145, 145, 147, 148, 172, 189, 168, 180, 144, 146, + 139, 145, 141, 150, 115, 172, 141, 146, 143, 148, + 145, 145, 142, 143, 145, 147, 138, 143, 58, 73, + 141, 142, 146, 145, 163, 149, 218, 161, 147, 132, + 152, 147, 146, 147, 140, 150, 141, 152, 89, 150, + 78, 134, 135, 137, 139, 142, 140, 137, 137, 130, + 144, 144, 152, 151, 145, 140, 181, 170, 191, 168, + 164, 166, 136, 148, 112, 124, 139, 144, 146, 149, + 142, 151, 113, 182, 137, 150, 143, 156, 138, 147, + 154, 156, 108, 102, 118, 119, 133, 139, 113, 111, + 145, 144, 150, 147, 175, 151, 104, 106, 116, 114, + 143, 144, 151, 157, 151, 191, 135, 113, 138, 123, + 146, 146, 155, 157, 106, 145, 132, 127, 140, 125, + 161, 165, 146, 150, 151, 154, 139, 140, 142, 143, + 144, 148, 145, 149, 147, 138, 168, 104, 146, 136, + 138, 140, 91, 108, 111, 110, 145, 140, 158, 154, + 130, 112, 122, 118, 136, 135, 119, 118, 141, 140, + 147, 146, 146, 145, 138, 138, 182, 188, 132, 132, + 144, 144, 156, 155, 168, 172, 123, 128, 144, 151, + 142, 140, 145, 145, 137, 144, 141, 152, 128, 188, + 149, 149, 160, 161, 160, 160, 166, 163, 130, 107, + 143, 143, 142, 142, 149, 149, 132, 132, 170, 174, + 148, 148, 154, 153, 118, 111, 157, 155, 114, 109, + 140, 139, 138, 137, 205, 187, 137, 133, 147, 144, + 144, 145, 147, 149, 105, 125, 108, 117, 155, 162, + 146, 146, 162, 157, 144, 122, 154, 143, 161, 139, + 141, 142, 130, 131, 144, 144, 142, 141, 144, 142, + 132, 132, 141, 141, 150, 151, 139, 141, 151, 153, + 142, 142, 154, 154, 150, 150, 148, 148, 166, 165, + 143, 142, 144, 144, 132, 132, 142, 144, 130, 128, + 142, 142, 143, 143, 153, 153, 147, 142, 129, 125, + 142, 141, 143, 142, 143, 147, 105, 122, 135, 140, + 141, 140, 140, 140, 151, 151, 156, 155, 146, 146, + 133, 134, 140, 142, 142, 145, 141, 146, 112, 133, + 142, 142, 145, 145, 137, 138, 155, 157, 149, 150, + 144, 144, 139, 138, 130, 128, 132, 131, 147, 147, + 139, 140, 142, 143, 115, 121, 141, 143, 137, 141, + 146, 146, 150, 150, 145, 144, 133, 133, 133, 135, + 143, 144, 144, 144, 166, 167, 139, 142, 139, 140, + 150, 149, 138, 138, 142, 140, 148, 147, 160, 155, + 146, 146, 147, 147, 138, 137, 143, 142, 151, 150 +}; + +static const uint8_t wmavoice_dq_lsp16r2[0x500] = { + 98, 98, 119, 121, 109, 112, 128, 135, 115, 121, + 159, 113, 113, 106, 127, 114, 101, 102, 105, 111, + 161, 162, 137, 138, 161, 159, 152, 150, 150, 148, + 128, 79, 131, 102, 142, 120, 133, 119, 130, 117, + 121, 115, 142, 133, 186, 155, 179, 144, 169, 135, + 107, 103, 106, 106, 122, 122, 111, 112, 112, 115, + 127, 123, 118, 115, 128, 125, 123, 119, 115, 109, + 124, 130, 117, 126, 121, 133, 84, 144, 99, 114, + 122, 125, 123, 131, 124, 135, 176, 200, 158, 176, + 68, 74, 86, 87, 117, 115, 119, 116, 135, 128, + 115, 116, 102, 104, 119, 123, 133, 148, 102, 109, + 71, 121, 106, 117, 107, 127, 106, 122, 100, 110, + 117, 115, 129, 128, 87, 84, 116, 116, 151, 157, + 116, 128, 110, 117, 119, 134, 100, 114, 120, 129, + 142, 141, 146, 151, 94, 91, 114, 114, 118, 118, + 114, 112, 112, 109, 115, 112, 123, 123, 147, 148, + 110, 164, 106, 152, 110, 158, 106, 151, 105, 135, + 85, 51, 71, 27, 71, 34, 74, 45, 85, 53, + 145, 134, 140, 130, 136, 134, 118, 122, 118, 126, + 117, 84, 121, 81, 106, 80, 109, 106, 121, 127, + 95, 94, 112, 110, 90, 94, 109, 107, 114, 109, + 117, 118, 118, 123, 107, 107, 86, 93, 29, 31, + 125, 112, 104, 60, 121, 111, 127, 116, 133, 130, + 118, 117, 148, 145, 122, 126, 124, 127, 90, 91, + 113, 110, 119, 118, 152, 147, 115, 112, 132, 131, + 129, 140, 98, 112, 73, 85, 109, 115, 122, 126, + 123, 122, 122, 122, 126, 125, 137, 140, 203, 210, + 164, 176, 114, 114, 125, 122, 119, 112, 125, 120, + 124, 122, 118, 115, 95, 96, 141, 144, 132, 131, + 127, 130, 132, 134, 116, 114, 122, 123, 137, 134, + 111, 111, 112, 116, 106, 118, 77, 101, 104, 115, + 111, 111, 125, 126, 118, 121, 113, 115, 113, 113, + 171, 170, 202, 199, 221, 206, 199, 184, 177, 167, + 73, 90, 61, 93, 43, 74, 51, 71, 51, 72, + 130, 130, 140, 137, 134, 132, 164, 160, 118, 111, + 123, 136, 133, 154, 130, 158, 106, 110, 110, 114, + 97, 97, 91, 94, 70, 69, 125, 123, 141, 140, + 119, 100, 116, 77, 111, 67, 105, 52, 95, 34, + 100, 122, 90, 124, 68, 120, 43, 117, 50, 112, + 130, 129, 192, 188, 123, 118, 124, 117, 121, 115, + 122, 111, 129, 111, 157, 85, 125, 109, 125, 119, + 143, 152, 119, 128, 114, 116, 129, 136, 148, 157, + 119, 117, 115, 115, 150, 148, 163, 154, 109, 102, + 120, 126, 73, 119, 106, 121, 102, 122, 96, 113, + 84, 83, 117, 115, 122, 117, 154, 143, 159, 142, + 118, 122, 114, 117, 115, 122, 114, 130, 99, 156, + 123, 120, 122, 116, 100, 81, 99, 91, 121, 112, + 139, 131, 164, 142, 132, 119, 145, 133, 157, 141, + 112, 109, 118, 116, 142, 134, 108, 110, 96, 99, + 111, 110, 113, 112, 111, 104, 98, 94, 131, 131, + 115, 114, 121, 118, 120, 115, 173, 148, 123, 117, + 121, 124, 122, 124, 140, 146, 78, 82, 96, 93, + 86, 90, 124, 125, 121, 123, 105, 106, 134, 135, + 107, 109, 132, 141, 100, 95, 113, 114, 102, 105, + 113, 130, 98, 145, 116, 115, 124, 117, 115, 105, + 120, 123, 89, 87, 109, 108, 102, 101, 117, 117, + 113, 122, 132, 138, 77, 116, 86, 99, 118, 126, + 123, 120, 117, 111, 124, 119, 129, 118, 63, 58, + 141, 135, 108, 106, 109, 111, 108, 110, 135, 138, + 117, 114, 134, 127, 139, 129, 138, 130, 126, 122, + 121, 118, 124, 121, 133, 130, 98, 85, 130, 123, + 147, 129, 118, 112, 148, 130, 136, 123, 148, 131, + 113, 112, 123, 118, 123, 115, 147, 95, 117, 110, + 118, 119, 112, 113, 112, 113, 119, 119, 120, 120, + 158, 133, 198, 145, 188, 129, 197, 137, 195, 133, + 132, 140, 140, 139, 158, 156, 223, 217, 233, 233, + 48, 56, 34, 37, 82, 84, 102, 102, 108, 110, + 120, 142, 136, 169, 146, 195, 136, 186, 140, 182, + 196, 186, 158, 155, 142, 134, 132, 125, 120, 119, + 97, 105, 72, 75, 82, 85, 81, 84, 107, 109, + 67, 121, 43, 119, 69, 124, 87, 129, 88, 128, + 53, 57, 93, 98, 91, 94, 93, 98, 104, 104, + 124, 123, 133, 133, 182, 181, 119, 121, 114, 116, + 128, 105, 134, 112, 131, 72, 119, 59, 111, 84, + 132, 142, 145, 180, 124, 132, 131, 143, 122, 134, + 88, 85, 103, 103, 136, 140, 131, 143, 114, 132, + 116, 57, 113, 57, 121, 76, 126, 80, 118, 86, + 127, 112, 127, 97, 131, 100, 149, 91, 163, 86, + 122, 119, 128, 121, 128, 116, 142, 127, 173, 139, + 162, 116, 166, 107, 149, 103, 152, 107, 141, 108, + 114, 113, 118, 116, 56, 43, 90, 90, 105, 105, + 132, 134, 110, 107, 106, 105, 82, 84, 84, 84, + 102, 106, 79, 89, 99, 99, 127, 129, 114, 118, + 139, 157, 116, 123, 116, 123, 87, 89, 110, 113, + 119, 126, 97, 97, 155, 163, 142, 153, 143, 146, + 117, 114, 66, 67, 125, 126, 127, 128, 114, 113, + 111, 114, 127, 133, 123, 132, 143, 162, 133, 148, + 105, 108, 114, 114, 110, 109, 57, 48, 109, 106, + 113, 130, 104, 131, 88, 139, 102, 169, 100, 172, + 129, 114, 150, 97, 114, 112, 117, 119, 109, 116, + 92, 107, 96, 116, 90, 125, 101, 122, 125, 140, + 125, 133, 122, 129, 136, 153, 125, 135, 131, 139, + 84, 71, 129, 123, 135, 120, 114, 103, 112, 101, + 108, 121, 115, 156, 106, 123, 116, 131, 127, 139, + 137, 147, 109, 117, 119, 126, 135, 144, 117, 119, + 120, 127, 76, 105, 111, 116, 120, 125, 141, 138, + 107, 104, 162, 155, 135, 130, 127, 123, 127, 121, + 102, 104, 84, 87, 112, 115, 97, 102, 78, 82, + 119, 118, 120, 123, 91, 105, 114, 119, 119, 126, + 130, 126, 134, 126, 158, 134, 133, 99, 116, 100, + 125, 122, 145, 143, 126, 117, 98, 96, 121, 120, + 152, 148, 131, 126, 130, 129, 126, 119, 87, 87, + 131, 131, 139, 137, 101, 102, 104, 105, 86, 83, + 92, 89, 111, 105, 121, 115, 137, 124, 96, 84, + 100, 96, 122, 119, 107, 108, 93, 96, 79, 82, + 128, 123, 108, 106, 123, 120, 150, 150, 143, 140, + 121, 120, 97, 99, 79, 80, 116, 116, 88, 90, + 128, 131, 101, 97, 140, 140, 117, 116, 116, 118, + 137, 135, 100, 91, 115, 112, 134, 121, 107, 99, + 120, 122, 122, 125, 124, 126, 136, 141, 89, 95, + 103, 119, 103, 116, 122, 139, 125, 137, 152, 170, + 121, 122, 124, 124, 98, 97, 137, 140, 96, 92, + 115, 113, 136, 136, 128, 132, 122, 124, 151, 158, + 100, 107, 121, 131, 131, 158, 119, 130, 113, 114, + 114, 109, 148, 130, 103, 95, 127, 116, 137, 120, + 103, 108, 97, 97, 133, 128, 113, 109, 136, 128, + 125, 124, 118, 118, 122, 121, 101, 99, 157, 152, + 138, 134, 124, 115, 113, 101, 123, 112, 124, 110, + 116, 113, 128, 121, 119, 110, 124, 113, 128, 67, + 114, 118, 114, 123, 109, 121, 102, 123, 56, 116, + 117, 111, 112, 99, 124, 114, 112, 79, 114, 88, + 112, 113, 115, 117, 126, 127, 130, 132, 123, 122, + 111, 104, 111, 102, 112, 102, 129, 118, 129, 115, + 123, 124, 130, 133, 114, 117, 125, 127, 112, 117, + 124, 125, 119, 120, 117, 116, 105, 104, 110, 110, + 125, 124, 118, 116, 124, 123, 124, 121, 133, 132, + 111, 111, 124, 124, 120, 119, 116, 116, 134, 130, + 114, 116, 112, 113, 109, 111, 116, 118, 95, 98 +}; + +static const uint8_t wmavoice_dq_lsp16r3[0x600] = { + 84, 82, 95, 94, 125, 131, 98, 102, 94, 93, 104, 104, + 127, 113, 87, 77, 125, 114, 109, 94, 94, 91, 106, 105, + 168, 125, 163, 120, 128, 100, 119, 99, 108, 97, 108, 106, + 86, 85, 128, 125, 79, 73, 103, 102, 123, 123, 116, 117, + 84, 76, 135, 131, 133, 133, 129, 130, 125, 123, 115, 114, + 94, 97, 79, 81, 115, 115, 94, 93, 128, 127, 126, 125, + 124, 111, 105, 114, 104, 117, 109, 110, 124, 125, 118, 117, + 107, 110, 106, 110, 93, 93, 149, 148, 118, 119, 111, 110, + 147, 157, 143, 156, 134, 136, 118, 121, 106, 107, 105, 105, + 114, 83, 114, 46, 106, 53, 110, 83, 107, 94, 105, 103, + 92, 90, 109, 106, 172, 160, 114, 110, 109, 110, 110, 109, + 90, 98, 98, 109, 102, 98, 97, 92, 100, 100, 101, 102, + 123, 117, 124, 98, 82, 80, 117, 115, 112, 110, 109, 108, + 107, 111, 100, 115, 105, 120, 104, 105, 83, 82, 95, 96, + 109, 120, 72, 71, 97, 104, 69, 74, 99, 102, 118, 117, + 137, 133, 142, 135, 105, 110, 121, 121, 125, 122, 114, 112, + 151, 186, 115, 132, 103, 111, 100, 104, 99, 101, 104, 105, + 18, 38, 56, 65, 76, 83, 85, 91, 101, 103, 108, 110, + 144, 135, 126, 121, 115, 113, 79, 80, 118, 117, 117, 117, + 117, 124, 115, 115, 126, 113, 130, 116, 112, 106, 108, 105, + 77, 76, 76, 80, 109, 109, 125, 129, 130, 133, 116, 118, + 96, 86, 109, 99, 102, 69, 84, 69, 107, 103, 114, 113, + 78, 118, 82, 114, 84, 129, 69, 112, 78, 98, 96, 103, + 89, 137, 96, 111, 105, 97, 93, 93, 101, 105, 105, 105, + 141, 123, 102, 93, 91, 79, 87, 81, 102, 99, 109, 108, + 94, 92, 124, 123, 130, 134, 100, 107, 71, 75, 92, 91, + 94, 104, 107, 83, 106, 101, 113, 114, 122, 122, 114, 114, + 118, 124, 103, 106, 95, 116, 90, 93, 107, 104, 109, 107, + 116, 118, 76, 72, 88, 88, 132, 132, 140, 141, 116, 116, + 90, 81, 111, 95, 139, 97, 123, 96, 112, 100, 110, 108, + 112, 116, 133, 140, 112, 120, 80, 85, 55, 55, 85, 84, + 125, 94, 111, 104, 116, 103, 112, 86, 93, 84, 99, 98, + 180, 179, 197, 197, 169, 163, 149, 146, 130, 124, 116, 115, + 76, 47, 36, 11, 43, 28, 66, 53, 82, 80, 102, 99, + 119, 123, 176, 201, 113, 120, 112, 111, 103, 105, 106, 110, + 145, 114, 112, 89, 120, 93, 123, 104, 131, 123, 113, 111, + 97, 109, 82, 106, 75, 104, 103, 115, 120, 124, 111, 114, + 114, 111, 113, 105, 34, 33, 63, 63, 105, 106, 122, 122, + 51, 41, 96, 92, 125, 125, 118, 118, 118, 119, 113, 113, + 111, 180, 108, 178, 107, 171, 110, 160, 105, 136, 102, 117, + 76, 79, 90, 92, 80, 88, 88, 93, 123, 124, 122, 122, + 131, 128, 123, 122, 151, 158, 108, 107, 129, 128, 119, 119, + 97, 99, 114, 120, 121, 125, 151, 157, 82, 89, 95, 96, + 128, 94, 130, 95, 149, 113, 149, 120, 127, 115, 113, 109, + 167, 171, 83, 80, 84, 79, 106, 106, 112, 110, 107, 108, + 130, 139, 81, 88, 107, 106, 112, 112, 119, 118, 114, 112, + 108, 105, 100, 98, 120, 116, 122, 117, 38, 37, 72, 73, + 118, 125, 110, 120, 114, 126, 135, 142, 139, 142, 118, 119, + 119, 119, 156, 145, 78, 75, 94, 94, 112, 110, 113, 113, + 101, 108, 98, 104, 103, 109, 117, 118, 167, 167, 132, 132, + 116, 108, 118, 111, 149, 136, 85, 74, 95, 92, 113, 112, + 74, 69, 104, 107, 96, 100, 117, 121, 103, 105, 103, 103, + 110, 106, 111, 101, 82, 72, 96, 92, 132, 130, 120, 121, + 116, 113, 138, 139, 104, 103, 131, 131, 68, 69, 92, 92, + 97, 97, 146, 151, 122, 132, 97, 95, 117, 116, 115, 116, + 139, 134, 110, 110, 124, 129, 100, 110, 86, 91, 100, 102, + 116, 136, 88, 90, 137, 139, 103, 114, 114, 117, 111, 110, + 82, 83, 104, 102, 97, 99, 97, 97, 58, 56, 84, 84, + 83, 122, 76, 105, 112, 126, 120, 134, 112, 120, 108, 110, + 114, 128, 73, 90, 72, 76, 98, 100, 95, 96, 101, 102, + 101, 108, 118, 126, 94, 102, 81, 83, 138, 140, 131, 130, + 88, 100, 112, 124, 105, 106, 122, 123, 121, 121, 114, 114, + 76, 108, 73, 83, 93, 95, 110, 111, 98, 99, 103, 103, + 105, 112, 98, 108, 114, 95, 117, 98, 120, 116, 116, 115, + 231, 238, 150, 146, 124, 126, 115, 122, 117, 121, 112, 112, + 74, 73, 72, 74, 60, 61, 62, 61, 85, 85, 101, 101, + 67, 69, 50, 51, 83, 83, 110, 110, 118, 113, 112, 111, + 199, 124, 184, 115, 176, 117, 165, 120, 138, 115, 116, 114, + 52, 116, 36, 107, 49, 99, 72, 106, 91, 107, 104, 105, + 140, 138, 141, 135, 154, 147, 166, 159, 139, 136, 116, 115, + 130, 119, 180, 157, 183, 149, 136, 121, 119, 114, 111, 110, + 104, 129, 113, 154, 111, 148, 108, 132, 105, 117, 106, 111, + 114, 35, 99, 65, 113, 94, 110, 98, 111, 107, 107, 106, + 106, 110, 128, 135, 162, 175, 143, 155, 115, 116, 109, 109, + 168, 155, 112, 109, 125, 125, 126, 122, 126, 124, 111, 112, + 128, 96, 160, 77, 151, 77, 121, 80, 114, 94, 107, 103, + 97, 104, 101, 116, 56, 79, 74, 83, 92, 95, 104, 106, + 63, 68, 76, 77, 110, 107, 96, 90, 85, 83, 97, 96, + 116, 110, 46, 42, 103, 100, 122, 120, 102, 101, 104, 104, + 106, 101, 109, 98, 96, 61, 67, 35, 72, 61, 96, 93, + 88, 80, 81, 76, 113, 110, 144, 143, 88, 89, 93, 94, + 95, 96, 100, 101, 136, 132, 166, 160, 148, 147, 115, 116, + 80, 78, 130, 129, 120, 108, 91, 85, 95, 91, 104, 102, + 151, 147, 106, 109, 110, 110, 64, 69, 68, 67, 96, 96, + 90, 166, 97, 128, 99, 120, 104, 121, 109, 118, 105, 109, + 122, 138, 110, 143, 75, 97, 83, 94, 89, 94, 102, 103, + 136, 142, 103, 110, 83, 89, 99, 101, 138, 138, 120, 122, + 168, 88, 105, 90, 109, 107, 110, 111, 106, 105, 103, 102, + 68, 72, 102, 104, 92, 102, 65, 75, 89, 94, 106, 106, + 83, 74, 93, 85, 73, 66, 106, 102, 100, 92, 99, 97, + 93, 99, 101, 96, 116, 112, 125, 120, 88, 88, 96, 96, + 44, 98, 93, 115, 104, 116, 103, 107, 112, 113, 107, 107, + 93, 83, 105, 99, 93, 84, 127, 125, 141, 143, 117, 118, + 106, 103, 126, 121, 137, 123, 123, 114, 147, 142, 127, 123, + 103, 110, 89, 91, 121, 124, 66, 71, 68, 69, 96, 97, + 114, 105, 68, 65, 69, 67, 96, 94, 131, 130, 123, 121, + 111, 104, 130, 121, 95, 95, 72, 74, 88, 88, 105, 104, + 135, 124, 110, 98, 114, 111, 159, 158, 111, 113, 104, 106, + 103, 108, 94, 107, 55, 57, 115, 118, 121, 122, 111, 111, + 97, 99, 106, 111, 119, 126, 59, 62, 111, 112, 124, 125, + 86, 93, 100, 110, 118, 145, 113, 132, 120, 125, 112, 112, + 101, 115, 78, 149, 81, 114, 111, 121, 108, 112, 107, 108, + 104, 104, 94, 96, 84, 83, 135, 132, 71, 69, 88, 86, + 100, 98, 62, 60, 81, 80, 90, 89, 63, 66, 89, 90, + 123, 116, 108, 99, 90, 86, 91, 92, 65, 65, 88, 88, + 84, 79, 115, 109, 123, 111, 99, 99, 134, 136, 121, 123, + 127, 137, 84, 88, 104, 107, 128, 130, 74, 69, 89, 89, + 118, 112, 143, 132, 141, 131, 113, 113, 99, 102, 104, 105, + 117, 115, 100, 99, 131, 126, 90, 88, 145, 144, 128, 127, + 112, 114, 131, 133, 85, 84, 118, 119, 151, 152, 117, 117, + 110, 105, 162, 140, 116, 107, 140, 134, 124, 122, 113, 113, + 107, 110, 124, 133, 98, 103, 99, 107, 109, 113, 112, 112, + 115, 105, 82, 77, 125, 122, 133, 132, 118, 120, 113, 113, + 101, 88, 84, 80, 97, 99, 91, 91, 94, 94, 101, 100, + 121, 86, 139, 108, 106, 93, 103, 99, 112, 108, 108, 107, + 113, 83, 105, 102, 125, 125, 114, 115, 110, 112, 108, 109, + 93, 112, 113, 121, 125, 131, 101, 101, 107, 109, 111, 111, + 98, 102, 117, 126, 80, 84, 107, 109, 83, 84, 96, 97, + 132, 136, 112, 118, 94, 93, 121, 118, 99, 98, 102, 103, + 122, 127, 128, 133, 118, 104, 102, 88, 100, 94, 104, 102, + 115, 116, 102, 105, 140, 142, 135, 130, 90, 88, 100, 101, + 94, 86, 112, 112, 89, 121, 92, 101, 109, 108, 110, 112, + 99, 93, 129, 114, 109, 99, 131, 119, 102, 97, 103, 103, + 103, 116, 124, 101, 115, 95, 105, 101, 94, 91, 100, 100, + 113, 90, 94, 86, 92, 92, 117, 111, 106, 103, 106, 105, + 115, 99, 110, 91, 107, 104, 81, 90, 108, 113, 112, 113, + 113, 114, 93, 101, 101, 102, 101, 126, 93, 103, 104, 105, + 117, 106, 124, 107, 104, 119, 108, 133, 104, 111, 104, 106 +}; + +static const float wmavoice_lsp10_intercoeff_a[32][2][10] = { + { { 0.5108627081, 0.0480548441, -1.5099149644, 0.6736935377, + 0.7536551058, 0.7651474178, 0.8510628343, 0.6667704582, + 0.7576012611, 0.7091397047 }, + { 0.1351471841, -0.1965375543, -1.6313457787, 0.3218626380, + 0.4132472873, 0.4663473070, 0.5805781186, 0.3962165117, + 0.4818550050, 0.4907165468 } }, + { { 0.8556320667, 0.7774704993, -0.0175759494, -0.1882298589, + 0.1892164350, 0.4850396216, 0.6270319819, 0.6327089071, + 0.6513319910, 0.6075088978 }, + { 0.4374088347, 0.3505934179, -0.0762144327, -0.2830760479, + -0.0626451969, 0.1500318050, 0.2602472305, 0.2781780064, + 0.3167395592, 0.3596626520 } }, + { { 0.1899779737, 0.0650856197, 0.1699010432, 0.9122628570, + 0.9097705483, 0.7433397174, 0.6304935217, 0.5164704025, + 0.4174703658, 0.5215242505 }, + { 0.0704856217, 0.0169009864, 0.0188394487, 0.5587704182, + 0.5194473267, 0.3539164960, 0.2426626086, 0.1721164286, + 0.1371548772, 0.2594856918 } }, + { { 0.8858859241, 0.9100474715, 0.8921859264, 0.9332397878, + 1.0225475132, 1.0555013716, 1.0983552337, 1.1290244758, + 1.0363244414, 0.9277705550 }, + { 0.4810934663, 0.5782935023, 0.6835935414, 0.7650781870, + 0.9018090069, 0.9996321201, 1.0219936669, 1.0474705994, + 0.9109474719, 0.7774704993 } }, + { { 0.4359549880, 0.2275702953, 0.0993548632, 0.1763395071, + 0.1055856347, 0.1018471718, 0.1170087159, 0.1221317947, + 0.1834010482, 0.2988780141 }, + { 0.1573702693, 0.1041317880, 0.0506856143, 0.0781702399, + 0.0058932900, -0.0026913285, -0.0031067133, 0.0070702136, + 0.0116394460, 0.0566394627 } }, + { { 0.8528628349, 0.8028782010, 0.4680088460, 0.9055474699, + 1.3742399514, 1.1093629301, 0.4122780561, 0.4003703594, + 0.6360319853, 0.6415704489 }, + { 0.4252934456, 0.3823703527, 0.1676856577, 0.5241550207, + 1.1995706558, 0.9088013172, 0.1224087179, 0.0730471611, + 0.3071857095, 0.3772472739 } }, + { { 0.5508781075, 0.2829549313, -0.0022067130, 0.1042702496, + 1.0318244398, 1.3258476257, 1.3550630212, 0.9931936562, + 0.7195243239, 0.6807550788 }, + { 0.2679318488, 0.0960317850, -0.1357529163, -0.1291759908, + 0.6451012194, 0.9968628883, 0.9510321021, 0.6608166099, + 0.3799472749, 0.3735780418 } }, + { { 0.9967244267, 1.0255244374, 0.9800398052, 0.7939474285, + 0.8288397491, 0.8390166759, 0.8660166860, 0.9247936308, + 0.9127474725, 0.8684397638 }, + { 0.7921474278, 0.9416859448, 0.8547320664, 0.5348165631, + 0.6231550574, 0.6703012288, 0.6987550855, 0.8147858977, + 0.7406397164, 0.6496012211 } }, + { { 0.1439394951, -0.3193529844, -0.2024914026, -0.1854606271, + 0.0877240896, 0.1617318094, 0.3087087870, 0.3777318895, + 0.3910242021, 0.4797780812 }, + { -0.0157067180, -0.1778452396, -0.1554836929, -0.1759760082, + -0.0607759655, -0.0161221027, 0.0393317640, 0.0758856237, + 0.1163856387, 0.1947548985 } }, + { { 1.1021629274, 0.9958244264, 0.4658626914, 0.3089164793, + 0.3740626574, 0.2962472439, 0.3170857131, 0.2420395315, + 0.2649549246, 0.2936857045 }, + { 0.4700857699, 0.1809087396, 0.0311625302, 0.0106009841, + 0.0311625302, 0.0266625285, 0.0221625268, 0.0156548321, + 0.0551163852, 0.1010164022 } }, + { { 0.2925087810, 0.3418011069, 0.7339243293, 0.7322627902, + 0.7288704813, 0.7924935818, 0.7724166512, 0.7819012702, + 0.8325782120, 0.7954705060 }, + { 0.0559471548, -0.0456144214, -0.0462374985, -0.1005144417, + -0.0511528850, -0.0455451906, -0.0044220984, 0.0451471508, + 0.1232394874, 0.2085318267 } }, + { { 0.2230702937, -0.9052532017, 1.2441552877, 1.0825706124, + 0.9088705480, 0.8797243834, 0.8648397624, 0.8091089725, + 0.7633474171, 0.7468704879 }, + { -0.2030452490, -1.4167303145, 1.3542322516, 0.8369397521, + 0.6148473620, 0.5560704172, 0.5450627208, 0.4978473186, + 0.4200319052, 0.4904396236 } }, + { { 0.6088242829, 0.5965704322, 0.6547242999, 0.8554936051, + -0.2989298999, 0.2404472232, 0.3573780358, 0.7499166429, + 0.7691628039, 0.6824858487 }, + { 0.2582395375, 0.2721549273, 0.3462318778, 0.4820626974, + -0.4780299664, -0.0712990463, 0.0200163722, 0.4246703684, + 0.4660011530, 0.4172626734 } }, + { { 1.1749937236, 1.0773090720, 1.0566782951, 1.0249013603, + 0.9947167337, 0.9626628757, 0.9562244117, 0.9072782397, + 0.7654243410, 0.6448935270 }, + { 1.1595552564, 0.9340013266, 0.3959395885, 0.3693549633, + 0.3915780485, 0.3104395568, 0.3499011099, 0.2236933708, + 0.1638087332, 0.1811856627 } }, + { { 0.9572628736, 0.9389859438, 0.6619243026, 0.6849089265, + 0.7276935577, 0.7839781940, 0.7987243533, 0.7748397291, + 0.7101089358, 0.7277627885 }, + { 0.5809935033, 0.5575934947, 0.3544703424, 0.3636780381, + 0.3736472726, 0.4486242235, 0.4684934616, 0.4481396079, + 0.3456780314, 0.4478626847 } }, + { { 0.1259394884, 1.3096476197, 1.0794552267, 1.0009475052, + 0.9061013162, 0.9216782451, 0.8954397738, 0.9160013199, + 0.8575012982, 0.7479089499 }, + { -0.3689222336, 1.5293861628, 0.7323320210, 0.4102703631, + 0.3825780451, 0.2828164697, 0.2644010782, 0.2455010712, + 0.2482010722, 0.2335241437 } }, + { { 0.5380704105, 0.1600702703, -0.0657605827, -0.2390452623, + -0.3885837793, -0.4150299430, -0.3001760542, -0.1451683044, + 0.1312010288, 0.2798395455 }, + { 0.2074933648, 0.0560163856, -0.0956682861, -0.2893068194, + -0.3889991641, -0.3918376267, -0.3550068438, -0.2649375796, + -0.0554451942, 0.1167317927 } }, + { { 0.6092396677, 0.5101011693, 0.4012011290, 0.5416011810, + 0.5715781152, 0.6476627588, 0.6988243163, 0.7306012511, + 0.7531704903, 0.6534781456 }, + { 0.2060395181, 0.1409625709, 0.1024702489, 0.1834010482, + 0.1946856678, 0.2547779977, 0.3134857118, 0.3283011019, + 0.3837549686, 0.3501780331 } }, + { { 0.4516011477, 0.5351627171, 0.8068243563, 0.7049858570, + 0.7165473998, 0.6005858183, 0.4870473146, 0.2500010729, + 0.3132087886, 0.4462703764 }, + { 0.1053087115, 0.1348702610, 0.4457857609, 0.3499703407, + 0.3537780344, 0.2628780007, 0.1665087342, 0.0200856030, + 0.0329625309, 0.1525241137 } }, + { { 0.7058166265, 0.7305320203, 1.1684860289, 1.4524707496, + 1.3212091625, 1.2613245249, 1.1712552607, 1.1154552400, + 1.0487167537, 0.9153782427 }, + { 0.2286087573, 0.2851703167, 1.2016475797, 1.5154707730, + 1.2726091444, 1.1459167898, 0.9801090360, 0.9296397865, + 0.8490551412, 0.6772243083 } }, + { { 0.6686396897, 0.5728935003, 0.4734780788, 0.6970243156, + 0.5852165818, -0.0762836635, -0.2054683268, -0.1380375326, + 0.1282933354, 0.3467164934 }, + { 0.2925087810, 0.2344933748, 0.1677548885, 0.2747856975, + 0.2097087502, -0.2795452774, -0.3761222363, -0.3183837533, + -0.0834836662, 0.1482318044 } }, + { { 0.6559704542, 0.7737320364, 0.9867551923, 0.9912551939, + 0.9508936405, 0.9114320874, 0.8336859047, 0.7905551195, + 0.7672935724, 0.7532397211 }, + { 0.1843702793, 0.2565087676, 0.7571858764, 0.7545551062, + 0.6793704629, 0.5981627405, 0.5078165531, 0.4282011390, + 0.3948318958, 0.4502165318 } }, + { { 0.4430857599, 0.6102781296, 0.8485012949, 0.8573628366, + 0.9078320861, 0.9979705811, 1.0411013663, 1.0524552166, + 1.0194321275, 0.9023628533 }, + { 0.0070009828, 0.0084548295, 0.1613856554, 0.3484472632, + 0.4385857582, 0.5895088911, 0.6367935240, 0.6736935377, + 0.7026320100, 0.5924165845 } }, + { { 1.0532859862, 1.1059706211, 1.1311013997, 1.1250783205, + 1.0425552130, 0.9993551970, 0.9673013389, 0.9386397898, + 0.8836013079, 0.8336859047 }, + { 0.9791398048, 1.1481321752, 1.1275706291, 1.0082167387, + 0.8809705377, 0.8031551242, 0.7287320197, 0.6496704519, + 0.5211088657, 0.4734088480 } }, + { { -0.0251221061, -0.0443682671, 0.1282241046, 0.3850703537, + 0.4252934456, 0.4547857642, 0.4690473080, 0.4873242378, + 0.6001012027, 0.5882627368 }, + { -0.0562759638, -0.0246374905, 0.0070009828, 0.0971394777, + 0.1232394874, 0.1278779507, 0.1302317977, 0.1462241113, + 0.2073549032, 0.2446010709 } }, + { { 1.1749244928, 1.1155937016, 0.9236167073, 0.6288319826, + 0.6515396833, 0.5391781032, 0.5398011804, 0.4997165501, + 0.4066703618, 0.3998857439 }, + { 0.9403013289, 0.7346166372, 0.1841625869, 0.1319625676, + 0.1395087242, 0.0857856274, 0.0952702463, 0.0860625505, + 0.0829471648, 0.1132010221 } }, + { { 0.9047167003, 0.9840551913, 0.9933321178, 0.9360090196, + 0.9164859354, 0.9213320911, 0.8701705337, 0.8815936148, + 0.8414397538, 0.8188012838 }, + { 0.0961010158, -0.0147374868, 0.0202240646, 0.1002548635, + 0.1407548785, 0.1837472022, 0.1858241260, 0.2064549029, + 0.2228626013, 0.2859318554 } }, + { { 0.4034165144, 0.1918472052, 2.1959402561, 0.4763165414, + 0.6577012241, 0.7036704719, 0.6626858413, 0.7650089562, + 0.7702704966, 0.6543781459 }, + { 0.0940933228, -0.1222529113, 2.3491480052, 0.1385394931, + 0.3052472472, 0.3665857315, 0.3350857198, 0.4722319245, + 0.4313857555, 0.3846549690 } }, + { { 0.8215012848, 0.8613782227, 1.0399936736, 1.4082322717, + 0.4075011313, 0.4091626704, 0.5230473280, 0.6101396680, + 0.7510243356, 0.7237474024 }, + { 0.4810934663, 0.5670088828, 0.9207782447, 1.3007860780, + 0.0453548431, 0.0858548582, 0.1803548932, 0.2790087759, + 0.3974626660, 0.4581780732 } }, + { { 1.5921784937, 1.4987169206, 1.1321398616, 0.8235089779, + 0.6888550818, 0.6621319950, 0.6192089021, 0.6533396840, + 0.7196627855, 0.6549319923 }, + { 1.5911400318, 1.4768399894, 0.9358705580, 0.4674549997, + 0.3522549570, 0.3144549429, 0.2985318601, 0.3559241891, + 0.4061857462, 0.3958703578 } }, + { { 0.7975474298, 0.8712782264, 0.8974474669, 0.3008164763, + 0.5562088788, 0.6655935347, 0.8921166956, 1.0918475389, + 0.9544936419, 0.8554936051 }, + { 0.3769703507, 0.4930703938, 0.6619243026, -0.0382759571, + 0.1766856611, 0.3015780151, 0.5952550471, 0.8903859258, + 0.7395320237, 0.6205935180 } }, + { { 0.2206472158, 2.4467634261, 1.2920629978, 1.0239321291, + 0.9014628530, 0.8552166820, 0.8219859004, 0.9005628526, + 0.7614781857, 0.7763628066 }, + { -0.2722068131, 2.8967635930, 1.3039706945, 0.7695089579, + 0.6132550538, 0.5701242685, 0.5737935007, 0.6533396840, + 0.5422934890, 0.5150857866 } }, +}; + +static const float wmavoice_lsp10_intercoeff_b[32][2][10] = { + { { 0.4881048799, -0.1998192370, -0.3872502148, 0.0109423101, + 0.0406953394, 0.1788437665, 0.1673750877, 0.3409781158, + 0.4061202109, 0.5221177042 }, + { 0.1492218077, -0.1372330189, -0.2683691680, -0.0621950924, + -0.0624572337, -0.0068177581, -0.0076041818, 0.0680235624, + 0.1055752933, 0.1199930608 } }, + { { 0.7934338748, 0.0012430847, 0.4239458144, 0.5521328747, + 0.6497149467, 0.6423749924, 0.7170197070, 0.7169541717, + 0.7778364718, 0.8397018015 }, + { 0.2768190503, -0.0491535664, -0.0325731337, 0.0261465013, + 0.0469867289, 0.0649434030, 0.0781815350, 0.1031504869, + 0.1194687784, 0.2451654971 } }, + { { 0.7212139666, 0.1658677757, 0.0101558864, 0.5636015534, + 1.3175852597, 1.1911676526, 1.1266809106, 0.8230558336, + 0.8604109585, 0.8094900250 }, + { 0.3658815324, 0.0816549063, -0.2092563212, 0.1946377754, + 1.0856558084, 0.9491457641, 0.8461242616, 0.5193652213, + 0.5975488424, 0.5293265879 } }, + { { 0.9507186115, 0.9078585207, 0.8773190677, 0.8677509129, + 0.8024122119, 0.8127667904, 0.8246286809, 0.8779088855, + 0.9454102516, 0.9863698184 }, + { 0.6883807778, 0.6900191605, 0.7059442401, 0.6552854478, + 0.5843107104, 0.5553441048, 0.5887671113, 0.6494528055, + 0.7725936472, 0.7792782485 } }, + { { 0.2399882078, 0.1938513517, 0.4441962242, 0.4475385249, + 0.3055235147, 0.1745184362, 0.1174371839, 0.0679580271, + 0.0782470703, 0.1695377529 }, + { 0.0170370936, 0.0253600776, 0.2072205544, 0.1907711923, + 0.1096384823, 0.0327000320, -0.0134368241, -0.0461389422, + -0.0372916758, -0.0243156850 } }, + { { 0.5457104146, 0.3774812818, 0.5235594809, 0.2994287312, + 0.2394639254, 0.5731041729, 0.9971176088, 1.1646913886, + 0.9028123021, 0.7777709365 }, + { 0.2288472056, 0.1181580722, 0.2074171603, 0.0355180502, + -0.0024924278, 0.2596487999, 0.7474936247, 0.9103488624, + 0.5927647650, 0.4772915542 } }, + { { 0.6541713476, 0.6412608922, 0.7625012100, 0.7826205492, + 0.4839106202, 0.3311478198, 0.4577620327, 0.8572652638, + 0.9442306161, 0.8282986581 }, + { 0.2852075696, 0.2614837885, 0.4221763611, 0.4314823747, + 0.1434547007, 0.0435788929, 0.1397191882, 0.5525916219, + 0.6752081811, 0.5487250388 } }, + { { 0.6742251515, 1.0610800683, 1.0500701368, 0.9570100009, + 0.9325653315, 0.9243078828, 0.9148707986, 0.8317720294, + 0.7696445584, 0.6784849465 }, + { 0.2283884585, 0.9739181101, 0.5336519182, 0.4974764287, + 0.3998288214, 0.3674543798, 0.2719694376, 0.2608939707, + 0.2087934017, 0.1675716937 } }, + { { 0.3736146986, -1.5457833707, 0.9216864705, 0.7959242165, + 0.7358283401, 0.7233110964, 0.7271121442, 0.6852350831, + 0.6891672015, 0.6589554250 }, + { 0.1246460676, -1.7167649865, 0.7037160397, 0.4803061783, + 0.4694928527, 0.4654951990, 0.5208069980, 0.5305717587, + 0.5288023055, 0.5278192759 } }, + { { 1.0116009116, 0.9882703424, 0.8393741250, 0.8889843524, + 0.8934407532, 0.8906227350, 0.9222107530, 0.8973073363, + 0.9257496595, 0.9306648076 }, + { 0.5097970665, -0.0106843412, 0.1419473886, 0.2804890275, + 0.3719763160, 0.3694859743, 0.4640534222, 0.5034401417, + 0.5592106879, 0.6652468145 } }, + { { 0.9718209803, 0.7615181804, 0.2172474563, 0.4920369983, + 0.4310891628, 0.5038333535, 0.4668059051, 0.5339140594, + 0.4453758597, 0.4050061107 }, + { 0.6543679535, 0.1205173433, -0.0050483048, 0.1580035388, + 0.1308719218, 0.1700620353, 0.1740596890, 0.2179683447, + 0.1967349052, 0.1703897119 } }, + { { 0.7663022578, 0.4025157690, 1.3811545074, 1.1642981768, + 1.0709758997, 0.9812580645, 1.0092416406, 0.9089070857, + 0.7776398659, 0.8189926445 }, + { 0.3471384346, 0.0602248609, 1.3968829811, 1.0841484964, + 0.8940305710, 0.7313719392, 0.7345176339, 0.5304406881, + 0.4076275229, 0.4535677731 } }, + { { 0.1300854981, 0.1323136985, 0.7564064264, 0.7335346043, + 0.7924508452, 0.6039057672, 0.6896914840, 0.3694859743, + 0.2825861573, 0.3179096878 }, + { -0.0208423138, -0.0530856848, 0.3449102342, 0.3819376826, + 0.4466865659, 0.2807511687, 0.3842969537, 0.1144880950, + 0.0617321730, 0.0767397583 } }, + { { 0.7559476793, 0.8462553322, 0.6452585459, 1.1308751702, + 1.0606868565, 0.9498666525, 0.7425129414, 0.6221901178, + 0.6574481130, 0.6976212561 }, + { 0.3420922160, 0.4310236275, 0.2800958157, 0.9317133725, + 0.8210897744, 0.6144569516, 0.3227593005, 0.2464762032, + 0.2769501209, 0.3521846533 } }, + { { 0.7609938979, 0.6943444908, 1.1490939856, 0.4350868165, + 0.6101971567, 0.6246149242, 0.7370079756, 0.6522052884, + 0.6966382265, 0.7565374970 }, + { 0.3939306438, 0.3449102342, 0.9874839187, 0.0910919905, + 0.2804234922, 0.2888775468, 0.4060546756, 0.3284608722, + 0.3483836055, 0.4819445610 } }, + { { 0.7828826904, 1.1833034158, 1.9916158915, 0.8667678833, + 0.9218830764, 0.8856420517, 0.9373494089, 0.7415299118, + 0.7450032830, 0.7074515522 }, + { 0.4685098231, 1.1713104546, 1.9853245020, 0.6206828058, + 0.6664264500, 0.6033814847, 0.6089519858, 0.3784643114, + 0.4212588668, 0.3441893458 } }, + { { 0.4671335816, 0.4177199602, 0.0804097354, -0.1836975515, + -0.1802241802, -0.0775958896, -0.0250365734, 0.0884050429, + 0.2136430144, 0.3472039700 }, + { 0.1187478900, 0.1122598946, -0.0381436348, -0.2284581661, + -0.2302276194, -0.1738672554, -0.1350048184, -0.0547896028, + 0.0000634491, 0.0545888245 } }, + { { 0.5545576811, 0.4791920781, 0.8204999566, 0.8462553322, + 0.9212277234, 0.8946203887, 0.9659883380, 0.9137566984, + 0.9225384295, 0.9207034409 }, + { 0.1176993251, -0.0429277122, -0.0330318809, 0.0566859543, + 0.0983008742, 0.1593797803, 0.1732077301, 0.2320584357, + 0.2739354968, 0.3753186166 } }, + { { 0.7157745361, 0.6367389560, -1.2036890686, 0.7107283175, + 0.6885118484, 0.7332724631, 0.7436270416, 0.7113181353, + 0.5935511887, 0.6023984551 }, + { 0.3664058149, 0.3280676603, -1.3082178831, 0.3909815550, + 0.3641776145, 0.3926854730, 0.3898674548, 0.4086760879, + 0.3127979338, 0.3949792087 } }, + { { 1.0267395675, 1.0621941686, 1.0415505469, 0.9971176088, + 0.9764739871, 0.9904330075, 0.9591071308, 0.9338760376, + 0.9026156962, 0.9073997736 }, + { 0.9855833948, 1.0548542142, 0.9787021875, 0.8573307991, + 0.8360973597, 0.8193203211, 0.7386463583, 0.7038471103, + 0.6333966553, 0.6434235573 } }, + { { 0.6235008240, 0.7635497749, 0.8094900250, 0.7227212787, + -0.0610809922, -0.1357912421, -0.2359291911, 0.0800165236, + 0.3972729445, 0.5078965425 }, + { 0.2983146310, 0.4983939230, 0.4145742655, 0.3284608722, + -0.3203386664, -0.3495018780, -0.4734291434, -0.1808139980, + 0.1211071610, 0.2001427412 } }, + { { 0.8925887942, 0.8804647624, 0.6153089106, 0.6760601401, + 0.7887153327, 1.0065546930, 1.0829033256, 1.0347348750, + 0.9800128937, 0.9125770628 }, + { 0.5955827832, 0.6195687056, 0.2924164534, 0.3553958833, + 0.5417127609, 0.8713553548, 0.9977729619, 0.8817754686, + 0.7645328045, 0.6604627371 } }, + { { 1.1581378579, 1.0359145105, 0.7731179297, 0.6839243770, + 0.6839899123, 0.6664264500, 0.6910677254, 0.6579068601, + 0.6779606640, 0.6243527830 }, + { 1.1508634388, 0.8400294781, 0.2358594835, 0.2542749047, + 0.2484422624, 0.2620736063, 0.2676441073, 0.2713796198, + 0.3068997562, 0.3223005533 } }, + { { 0.1376220584, 1.2572927773, 0.8593623936, 0.6218624413, + 0.5128116906, 0.5393534899, 0.4436064065, 0.4334484339, + 0.4494390488, 0.4002220333 }, + { -0.1159995794, 1.2433337569, 0.4805027843, 0.2632532418, + 0.1769432425, 0.1868390739, 0.1555131972, 0.1530228555, + 0.1490252018, 0.1559064090 } }, + { { 0.1817273200, -0.0085216761, 0.0739872754, 0.1808098257, + 0.2770811915, 0.3344901204, 0.4292541742, 0.5404020548, + 0.5780193210, 0.5707449019 }, + { -0.0035409927, -0.0188107193, -0.0057691932, 0.0132360458, + 0.0560961366, 0.0534747243, 0.1002013981, 0.1737320125, + 0.1706518531, 0.1637706459 } }, + { { 0.9648087025, 1.0030813217, 0.9501943290, 0.8381944895, + 0.7545059025, 0.7621735334, 0.7121700943, 0.7328792512, + 0.7534573376, 0.7414643764 }, + { 0.1872322857, -0.0081939995, 0.0663851798, 0.0963348150, + 0.0509188473, 0.0565548837, 0.0471833348, 0.0809340179, + 0.1049199402, 0.1751082540 } }, + { { 0.6792713702, 0.9521603882, 0.5296542645, 0.3657504618, + 0.3905883431, 0.3121425807, 0.2726903260, 0.3156159520, + 0.2859284580, 0.3179096878 }, + { 0.2307477295, 0.3771536052, 0.0743804872, 0.0260154307, + 0.0477731526, 0.0391880274, 0.0228042006, 0.0572757721, + 0.0337485969, 0.0492149293 } }, + { { 0.8649328947, 0.9505875409, 1.0443030298, 1.1704584956, + 1.2709241211, 1.3232212961, 1.2477901578, 1.1513877213, + 1.0346038043, 0.9695272446 }, + { 0.4620873630, 0.5685822368, 0.8975039423, 1.0476453304, + 1.2278674245, 1.2290470600, 1.1962138712, 1.0051129162, + 0.8706344664, 0.7477557659 } }, + { { 0.4188340604, 0.6011532843, 0.4726385474, 0.6389671564, + 0.6753392518, 0.7842589319, 0.6147846282, 0.6708828509, + 0.6406055391, 0.5398777723 }, + { 0.1012499630, 0.2312064767, 0.1773364544, 0.2800302804, + 0.3348177969, 0.4343003929, 0.2822584808, 0.3293128312, + 0.3024433553, 0.2401848137 } }, + { { 0.5049474537, 0.7943513691, 0.9536021650, 0.9407572448, + 0.9823721647, 0.9747045338, 1.0145500004, 0.9629737139, + 0.9526191354, 0.9283710718 }, + { 0.0566204190, 0.0973178446, 0.5812305510, 0.5687133074, + 0.6834000945, 0.6616423726, 0.7611905038, 0.6683925092, + 0.6463071108, 0.6118355393 } }, + { { 0.8969141245, 0.9359731674, 0.8756151497, 0.8419300020, + 0.8353109360, 0.6807131469, 0.3358008265, 0.3386188447, + 0.3524467945, 0.4495045841 }, + { 0.5298508704, 0.4606455863, 0.4934132397, 0.4415748119, + 0.4015327394, 0.2052544951, -0.0329663455, -0.0154684186, + 0.0418094397, 0.1631152928 } }, + { { 0.6345762908, 2.5209445655, 1.0373562872, 0.9166402519, + 0.8865595460, 0.8907538056, 0.8522190452, 0.7290782034, + 0.7385808229, 0.6345107555 }, + { 0.2641707361, 2.5696372986, 0.8539884984, 0.6532538533, + 0.6087553799, 0.5851626694, 0.5276226699, 0.4330552220, + 0.3971418738, 0.3599833548 } }, +}; + +static const float wmavoice_lsp16_intercoeff_a[32][2][16] = { + { { 0.5337238312, 0.4810695648, -0.3766536713, -0.1204767227, + -0.0898437500, -0.0070896149, 0.1134738922, 0.1337728500, + 0.3739156723, 0.3849058151, 0.4220180511, 0.5404901505, + 0.5224876404, 0.5502910614, 0.5313453674, 0.4405946732 }, + { 0.1775283813, 0.1679325104, -0.2702789307, -0.1359367371, + -0.1452455521, -0.0888595581, -0.0256662369, -0.0023736954, + 0.1074047089, 0.1431636810, 0.1357412338, 0.2045526505, + 0.2686481476, 0.3404531479, 0.3209333420, 0.1493968964 } }, + { { 0.7402400970, 0.0838251114, 0.6486282349, 0.6145095825, + 0.7331047058, 0.7183008194, 0.7436847687, 0.7627944946, + 0.7653779984, 0.7795667648, 0.8399305344, 0.8393154144, + 0.8219690323, 0.7474164963, 0.6681070328, 0.6490793228 }, + { 0.2850513458, -0.0544128418, -0.0300130844, 0.0204677582, + 0.0328931808, 0.0589332581, 0.0796422958, 0.1187639236, + 0.1320505142, 0.1539077759, 0.2189874649, 0.2865276337, + 0.2973947525, 0.2614307404, 0.2416648865, 0.2428951263 } }, + { { 0.6129922867, 0.7300701141, 0.2073822021, 0.5005893707, + 0.5713691711, 0.5374965668, 0.6293134689, 0.5639057159, + 0.7402811050, 0.6982889175, 0.4668397903, 0.6698703766, + 0.8758535385, 0.8678569794, 0.8678569794, 0.7810840607 }, + { 0.2986249924, 0.3269615173, 0.0096416473, 0.1800708771, + 0.2474060059, 0.2203407288, 0.3007984161, 0.2674179077, + 0.4424810410, 0.4046306610, 0.2063980103, 0.4230022430, + 0.6222190857, 0.6574449539, 0.6776618958, 0.6604385376 } }, + { { 0.7258052826, 0.5073966980, -0.3947381973, 0.5254812241, + 1.0561246872, 0.9706230164, 0.9727144241, 0.9185838699, + 0.8184833527, 0.9093980789, 0.8645353317, 0.7870302200, + 0.6347675323, 0.5123996735, 0.2846002579, 0.3252801895 }, + { 0.4306297302, 0.2182903290, -0.4902458191, 0.1783485413, + 0.7783365250, 0.7152252197, 0.7404451370, 0.6012639999, + 0.5421304703, 0.6619558334, 0.6316919327, 0.5596818924, + 0.3952398300, 0.3567333221, 0.1505041122, 0.1290159225 } }, + { { 0.3077287674, 0.2543363571, 0.2834520340, 0.5282287598, + 0.5350360870, 0.4943971634, 0.4521999359, 0.3086309433, + 0.2372770309, 0.0819387436, -0.1385612488, -0.0848407745, + -0.0380916595, 0.1192150116, 0.3228197098, 0.3012905121 }, + { 0.0567188263, 0.0196886063, 0.0682420731, 0.2102527618, + 0.2452325821, 0.2060699463, 0.1620273590, 0.0784120560, + 0.0418329239, -0.0508041382, -0.2193880081, -0.1644783020, + -0.1361827850, -0.0307512283, 0.1486587524, 0.2356367111 } }, + { { 0.4387903214, 0.5723943710, 0.6147556305, 0.9973602295, + 1.1645498276, 1.1898927689, 1.0326681137, 0.6939010620, + 0.6064310074, 0.4686441422, 0.4646663666, 0.4895582199, + 0.5654230118, 0.6004848480, 0.6179132462, 0.6439123154 }, + { 0.1324195862, 0.2426080704, 0.3132238388, 0.7359752655, + 0.9749288559, 0.9535636902, 0.8105278015, 0.4118890762, + 0.3013315201, 0.2006158829, 0.2331352234, 0.2535161972, + 0.3375005722, 0.4103307724, 0.4102897644, 0.4529380798 } }, + { { 0.7335557938, 0.9203472137, 0.4852113724, 0.8646993637, + 0.7304391861, 0.7503690720, 0.6289854050, 0.6900463104, + 0.6421079636, 0.5184278488, 0.4444904327, 0.2660236359, + 0.2143125534, 0.2406396866, 0.4836940765, 0.5597229004 }, + { 0.3689947128, 0.4967346191, 0.1176567078, 0.5127687454, + 0.3235168457, 0.3426265717, 0.2417469025, 0.3310623169, + 0.2629890442, 0.2130823135, 0.1329116821, 0.0468769073, + -0.0081968307, 0.0146446228, 0.2440433502, 0.3408632278 } }, + { { 0.9425325394, 0.9597969055, 0.6160678864, 0.7050962448, + 0.8063859940, 0.9063224792, 0.9890356064, 1.0038805008, + 1.0338163376, 0.9453620911, 0.9634056091, 0.8068370819, + 0.6859455109, 0.8909034729, 0.9990415573, 1.0122871399 }, + { 0.6895952225, 0.6451835632, 0.3169965744, 0.4268569946, + 0.5666122437, 0.7722673416, 0.8845882416, 0.9061584473, + 0.9550399780, 0.8118810654, 0.8601064682, 0.6129922867, + 0.5069866180, 0.7065315247, 0.7862920761, 0.7766551971 } }, + { { 0.5641517639, -0.0941905975, 0.0412998199, 0.1810550690, + 0.3459482193, 0.4213209152, 0.4401025772, 0.5397109985, + 0.5607891083, 0.6348905563, 0.6861915588, 0.7280607224, + 0.7267074585, 0.6447324753, 0.5948257446, 0.5475025177 }, + { 0.1906919479, -0.0519113541, -0.0608100891, -0.0018815994, + 0.0383062363, 0.0362558365, 0.0529870987, 0.0692672729, + 0.0953073502, 0.1327886581, 0.1390628815, 0.1904459000, + 0.2362518311, 0.2063980103, 0.2311668396, 0.2291574478 } }, + { { 0.9901428223, 0.9589767456, 0.9012374878, 0.8017930984, + 0.8929538727, 0.8512077332, 0.8790111542, 0.8832759857, + 0.8949632645, 0.9159183502, 0.9293279648, 0.9152622223, + 0.9247350693, 0.8753614426, 0.8730239868, 0.8066730499 }, + { 0.4230432510, -0.0464572906, 0.0182533264, 0.1159753799, + 0.2349395752, 0.2740612030, 0.2987070084, 0.3620643616, + 0.3923282623, 0.4694643021, 0.5202322006, 0.5356512070, + 0.5564012527, 0.5362663269, 0.4791831970, 0.5046901703 } }, + { { 0.9785375595, 0.8820457458, 0.3965110779, 0.4790191650, + 0.3907699585, 0.4195575714, 0.2938270569, 0.4091415405, + 0.3659191132, 0.4030723572, 0.4168510437, 0.5030908585, + 0.5023117065, 0.5511522293, 0.5354051590, 0.5563192368 }, + { 0.6592903137, 0.2933759689, 0.0562677383, 0.1286878586, + 0.0758285522, 0.1192560196, 0.0508956909, 0.1175336838, + 0.0684061050, 0.0988750458, 0.0923957825, 0.1819572449, + 0.1965150833, 0.2257537842, 0.3049812317, 0.2993221283 } }, + { { 0.7120265961, 0.7847747803, 0.6065950394, 0.7235908508, + 0.6740531921, 0.6535081863, 0.3734235764, 0.4788551331, + 0.4410867691, 0.6927528381, 1.0758495331, 1.1148891449, + 1.0708875656, 0.8896322250, 0.6401805878, 0.5057153702 }, + { 0.4210338593, 0.4763126373, 0.3229017258, 0.4079113007, + 0.3922462463, 0.3529195786, 0.1258993149, 0.2168960571, + 0.2207508087, 0.4605655670, 0.8759355545, 0.9526205063, + 0.8843832016, 0.7001342773, 0.4503545761, 0.3484086990 } }, + { { 0.5254402161, 0.5349540710, 0.7036199570, 0.6240234375, + 0.6464548111, 0.7537727356, 0.8311548233, 0.7334327698, + 0.3484907150, 0.1846637726, 0.0894021988, 0.3977823257, + 0.7672233582, 0.9224796295, 0.8818407059, 0.7453250885 }, + { 0.2587652206, 0.2524499893, 0.4135704041, 0.3129367828, + 0.3403711319, 0.4473199844, 0.5330266953, 0.4227561951, + 0.1080198288, -0.0044651031, -0.0727024078, 0.1583776474, + 0.5302381516, 0.7313823700, 0.6735610962, 0.5630855560 } }, + { { 0.7936325073, 0.8551034927, 0.9755849838, 0.8953323364, + 0.9345769882, 0.7202281952, 0.8388233185, 0.7941656113, + 0.7550849915, 0.7894906998, 0.8590402603, 0.7813711166, + 0.8483371735, 0.8652324677, 0.8586711884, 0.9584846497 }, + { 0.4781579971, 0.4731960297, 0.8289403915, 0.6175031662, + 0.7262973785, 0.3638277054, 0.5544328690, 0.4761896133, + 0.4388723373, 0.5021476746, 0.5630445480, 0.4562187195, + 0.5190429688, 0.5937595367, 0.6121721268, 0.6973457336 } }, + { { 1.0724458694, 1.0449705124, 0.8594503403, 0.7604160309, + 0.7837905884, 0.8136444092, 0.7623023987, 0.6098756790, + 0.6432561874, 0.6395244598, 0.6853713989, 0.7401580811, + 0.7399530411, 0.7652549744, 0.7675104141, 0.7393789291 }, + { 0.9382266998, 0.8419809341, 0.3087539673, 0.3620233536, + 0.3547649384, 0.4241094589, 0.2857894897, 0.2123851776, + 0.2355957031, 0.2794332504, 0.3219995499, 0.3898267746, + 0.3937635422, 0.4058198929, 0.4228382111, 0.4181222916 } }, + { { 1.0275421143, 1.0940570831, 1.0164289474, 0.9097671509, + 0.9400720596, 0.8976287842, 0.9175586700, 0.8900833130, + 0.9154262543, 0.9492578506, 1.0011329651, 1.0361537933, + 1.0359487534, 0.9320344925, 0.8974237442, 0.8811845779 }, + { 1.0046186447, 1.0860195160, 0.9442958832, 0.7473344803, + 0.7876043320, 0.7410602570, 0.7422084808, 0.6844692230, + 0.7256412506, 0.8455486298, 0.8969316483, 0.9362173080, + 0.9092340469, 0.8227071762, 0.7481546402, 0.7088689804 } }, + { { 0.2205047607, -0.0129537582, 0.0972347260, 0.1154832840, + 0.0951843262, 0.1532516479, 0.1288108826, 0.1749858856, + 0.1591157913, 0.2134923935, 0.2477340698, 0.2634811401, + 0.3032999039, 0.3272485733, 0.3170785904, 0.3172016144 }, + { 0.0032854080, -0.0446119308, 0.0284643173, 0.0155467987, + -0.0063104630, 0.0226001740, 0.0086984634, 0.0262088776, + 0.0173921585, 0.0360507965, 0.0366659164, 0.0215339661, + 0.0412178040, 0.1047391891, 0.1258172989, 0.0609836578 } }, + { { 0.1495609283, 0.3275766373, 0.8598194122, 0.6847562790, + 0.7550849915, 0.5662431717, 0.6930398941, 0.7526245117, + 0.7300291061, 0.7284708023, 0.6608896255, 0.5224056244, + 0.4273900986, 0.5757160187, 0.4625749588, 0.5123586655 }, + { -0.0352210999, -0.0428895950, 0.3110914230, 0.2699604034, + 0.3307752609, 0.2059469223, 0.2332172394, 0.3204412460, + 0.2846412659, 0.3354911804, 0.2448635101, 0.1514062881, + 0.1062564850, 0.2613077164, 0.2123441696, 0.3000602722 } }, + { { 0.6218910217, 0.6033554077, 0.4551525116, 0.3161764145, + 0.2864866257, 0.6195125580, 0.7577505112, 1.0062179565, + 0.8485012054, 0.6777849197, 0.7455301285, 0.3630485535, + 0.2327661514, 0.5563192368, 0.4448595047, 0.3806819916 }, + { 0.2624969482, 0.2679510117, 0.1839666367, 0.0335903168, + 0.0294075012, 0.2902593613, 0.4959144592, 0.7905979156, + 0.5748548508, 0.3753919601, 0.4855394363, 0.1089630127, + 0.0362968445, 0.3632535934, 0.2681150436, 0.2735691071 } }, + { { 0.7064495087, 0.4431781769, 0.7628355026, 0.7271585464, + 0.7812070847, 0.7806739807, 0.8909854889, 0.8958654404, + 0.9126787186, 0.9038209915, 0.9246120453, 0.9624624252, + 0.9732475281, 0.7420034409, 0.5060844421, 0.5189199448 }, + { 0.3457021713, -0.0149221420, 0.3174476624, 0.3580865860, + 0.4243965149, 0.4275541306, 0.5887155533, 0.6478490829, + 0.6320610046, 0.6627349854, 0.6868886948, 0.7396659851, + 0.7551259995, 0.5275316238, 0.3075237274, 0.3806819916 } }, + { { 0.4376831055, 0.4904603958, 0.6262788773, 0.5901098251, + 0.4176712036, 0.0221490860, -0.1612796783, -0.2236118317, + -0.1087894440, -0.0022506714, 0.1051902771, 0.3307752609, + 0.4167690277, 0.4997692108, 0.4645843506, 0.5228567123 }, + { 0.1228237152, 0.1671123505, 0.2931299210, 0.2549924850, + 0.1435737610, -0.1124801636, -0.2181987762, -0.2723293304, + -0.1573429108, -0.0837745667, -0.0325555801, 0.1024427414, + 0.1938495636, 0.2825498581, 0.2247285843, 0.2879629135 } }, + { { 0.6100807190, 0.7900238037, 0.9581155777, 0.8999662399, + 0.9277286530, 0.9720993042, 0.9966220856, 0.9630365372, + 0.9571723938, 0.8992280960, 0.8370189667, 0.7417984009, + 0.7174396515, 0.6122951508, 0.6746683121, 0.7030458450 }, + { 0.0859165192, 0.0914115906, 0.6077432632, 0.5471334457, + 0.5943746567, 0.6805324554, 0.6680250168, 0.6033554077, + 0.6302976608, 0.4874258041, 0.3647298813, 0.2770137787, + 0.2544183731, 0.2608156204, 0.3331537247, 0.4950942993 } }, + { { 0.4051227570, 1.1022176743, 0.8262338638, 0.6573219299, + 0.5948667526, 0.5426225662, 0.4987850189, 0.4370269775, + 0.4421119690, 0.3837165833, 0.3728494644, 0.3706760406, + 0.4169740677, 0.3559951782, 0.2994041443, 0.3896217346 }, + { 0.0716867447, 0.9253911972, 0.2780799866, 0.2460117340, + 0.1675224304, 0.1527595520, 0.1278266907, 0.1226596832, + 0.1165084839, 0.0982189178, 0.0952253342, 0.1113414764, + 0.1498889923, 0.0940361023, 0.0802984238, 0.1560811996 } }, + { { 0.7024717331, 0.7363853455, 0.9629545212, 0.9635286331, + 1.0819597244, 1.1529855728, 1.2984409332, 1.2693252563, + 1.2848672867, 1.2877378464, 1.2133083344, 1.0696573257, + 1.0864706039, 0.9851808548, 0.8312368393, 0.8047866821 }, + { 0.3001422882, 0.2273120880, 0.6279602051, 0.6936140060, + 0.8097076416, 0.9440498352, 1.1028738022, 1.1766471863, + 1.1199741364, 1.1608181000, 1.0665817261, 0.8872537613, + 0.9082908630, 0.7602519989, 0.6542053223, 0.7317514420 } }, + { { 0.0643463135, -0.6808919907, 0.2889881134, 0.6142225266, + 0.6356697083, 0.6825828552, 0.6259508133, 0.4945611954, + 0.5866651535, 0.6357517242, 0.5208883286, 0.4207878113, + 0.5125637054, 0.3758020401, 0.5424175262, 0.6172571182 }, + { -0.0636806488, -0.7585611343, 0.0850553513, 0.2996912003, + 0.3620643616, 0.4444084167, 0.4597454071, 0.3120756149, + 0.4016780853, 0.5026807785, 0.4111919403, 0.3183498383, + 0.3666572571, 0.1829824448, 0.3269205093, 0.4095926285 } }, + { { 0.9277286530, 0.9651279449, 0.9602069855, 0.9327726364, + 0.9208393097, 0.8868436813, 0.9011554718, 0.8569488525, + 0.9015245438, 0.8969726562, 0.9367094040, 0.9445009232, + 0.8617057800, 0.8215589523, 0.8333692551, 0.7939195633 }, + { 0.1719102859, 0.1142530441, 0.1245460510, 0.1646108627, + 0.1408672333, 0.0949792862, 0.0271930695, 0.0265779495, + -0.0064334869, -0.0109033585, 0.0152187347, 0.0252656937, + 0.0166950226, 0.0736141205, 0.1205682755, 0.1895437241 } }, + { { 0.5964250565, 0.6065130234, 0.7228116989, 0.7348270416, + 0.0718097687, 0.2369899750, 0.2456426620, 0.4961194992, + 0.6410417557, 0.6765956879, 0.6771287918, 0.7285938263, + 0.6706905365, 0.5105543137, 0.5068635941, 0.5430326462 }, + { 0.2782440186, 0.2620048523, 0.4424400330, 0.4124631882, + -0.1158838272, 0.0186223984, 0.0059919357, 0.1853609085, + 0.3568563461, 0.3791646957, 0.4100847244, 0.4654865265, + 0.4614677429, 0.3209743500, 0.3199081421, 0.3836755753 } }, + { { 0.8051557541, 0.8506336212, 0.9544658661, 0.5584516525, + 0.5874032974, 0.5727224350, 0.6177902222, 0.7659521103, + 0.9526205063, 1.0424280167, 1.0705595016, 1.0042905807, + 0.6005258560, 0.3886785507, 0.4739751816, 0.6542463303 }, + { 0.4775428772, 0.5541868210, 0.7128057480, 0.2146816254, + 0.2502765656, 0.2488822937, 0.3009214401, 0.4667987823, + 0.6929988861, 0.8599834442, 0.8784780502, 0.7463912964, + 0.3217535019, 0.1274986267, 0.2767267227, 0.5119485855 } }, + { { 0.5978193283, 0.5092830658, 1.0738401413, 0.7688636780, + 0.8214769363, 0.7682075500, 0.4970626831, 0.2783260345, + 0.2652854919, 0.3625154495, 0.5700569153, 0.5044031143, + 0.4003248215, 0.5162544250, 0.5727634430, 0.5538587570 }, + { 0.2752094269, 0.1747808456, 0.8557186127, 0.4280872345, + 0.5143680573, 0.4139804840, 0.1810960770, 0.0109539032, + 0.0317039490, 0.0842351913, 0.3129367828, 0.2614717484, + 0.1564092636, 0.2352676392, 0.3249931335, 0.3505821228 } }, + { { 0.7093610764, 0.7587757111, 1.8517618179, 1.0092525482, + 0.8078622818, 0.8792982101, 0.8210668564, 0.8600654602, + 0.6913585663, 0.6436662674, 0.6216859818, 0.6123771667, + 0.5940465927, 0.5910940170, 0.6505966187, 0.5801038742 }, + { 0.3370904922, 0.4681930542, 1.9236078262, 0.8053607941, + 0.5321245193, 0.6342344284, 0.5054693222, 0.5788326263, + 0.4400615692, 0.4086904526, 0.3924102783, 0.4220180511, + 0.3835115433, 0.4230432510, 0.5190839767, 0.3990535736 } }, + { { 0.6277141571, 1.1122236252, 1.0259838104, 0.9486427307, + 0.9184608459, 0.9059944153, 0.9080038071, 0.8282022476, + 0.8440313339, 0.7887935638, 0.7468013763, 0.6746683121, + 0.6319379807, 0.6246795654, 0.7263793945, 0.7349090576 }, + { 0.2427721024, 1.0851583481, 0.6180362701, 0.5837125778, + 0.4324750900, 0.4684801102, 0.3745307922, 0.3027257919, + 0.3646888733, 0.2409267426, 0.2158298492, 0.2052907944, + 0.2100887299, 0.2276401520, 0.3409452438, 0.4045896530 } }, + { { 0.8391513824, 0.8713426590, 1.1366233826, 1.1440868378, + 1.1443738937, 1.0877418518, 1.0516138077, 1.0099496841, + 0.9216184616, 0.8990640640, 0.9001302719, 0.8993101120, + 0.8055248260, 0.8150796890, 0.7272815704, 0.7196130753 }, + { 0.4634771347, 0.5807189941, 1.1287908554, 1.1066875458, + 1.0765056610, 0.9287538528, 0.8956193924, 0.8026132584, + 0.6725769043, 0.5856809616, 0.5527515411, 0.5183868408, + 0.4529380798, 0.5074377060, 0.4632720947, 0.5554990768 } }, +}; + +static const float wmavoice_lsp16_intercoeff_b[32][2][16] = { + { { 0.5431776047, -0.1212130189, -0.2471650839, 0.0683670044, + 0.1418520808, 0.2518971562, 0.3708084226, 0.4141484499, + 0.5712364912, 0.5852659345, 0.5670641661, 0.6401320100, + 0.6447737217, 0.6726239920, 0.4994724989, 0.5574678183 }, + { 0.2040718794, -0.1271064281, -0.2266163826, -0.0406349897, + -0.0145058036, 0.0283126831, 0.0851084590, 0.0913147926, + 0.1307432652, 0.1926501393, 0.2310355306, 0.2828245163, + 0.3171940446, 0.4424681067, 0.2960716486, 0.3510941863 } }, + { { 0.8073900938, 0.0403081179, 0.5392660499, 0.6928597689, + 0.6499369740, 0.7328097820, 0.7755761147, 0.7766191959, + 0.8820225596, 0.8423333168, 0.8898978233, 0.8488525748, + 0.8654375672, 0.6728326082, 0.6169234514, 0.6755967736 }, + { 0.3653843999, -0.0846008658, -0.0224332213, 0.1120721102, + 0.1020585299, 0.1741876006, 0.2129902244, 0.2160151601, + 0.3619422317, 0.4185815454, 0.5455245376, 0.5363975763, + 0.5429168344, 0.3505726457, 0.3296067119, 0.3620986938 } }, + { { 0.1843576431, 0.0179861784, 0.3122915626, 0.3600125313, + 0.2466817498, 0.2172668576, 0.1975526214, 0.1177569032, + 0.1196866035, 0.0849519968, 0.0962694287, 0.1591672301, + 0.2300446033, 0.3082756996, 0.4047607183, 0.3925045133 }, + { -0.0275964737, -0.0794897676, 0.1168181300, 0.1591150761, + 0.0915755630, 0.0460972190, 0.0562151074, 0.0084419847, + -0.0095511675, -0.0408957601, -0.0376100540, -0.0166962743, + 0.0656028390, 0.1226072311, 0.2293144464, 0.2142419219 } }, + { { 0.4781936407, -1.2478972673, 0.4884679914, 0.7755239606, + 0.6785174012, 0.6590117812, 0.6177057624, 0.6427918673, + 0.5402048230, 0.5512614846, 0.6424267888, 0.4229103327, + 0.5106334686, 0.5136062503, 0.4490395188, 0.4753251672 }, + { 0.2852236032, -1.3815159798, 0.1904075146, 0.4874770641, + 0.4593138695, 0.4182686210, 0.4174863100, 0.4604612589, + 0.4089330435, 0.3891666532, 0.4700576067, 0.2383370996, + 0.2801646590, 0.3398289084, 0.2766703367, 0.3374298215 } }, + { { 0.5925153494, 0.3858809471, 1.0754098296, 0.5752002001, + 0.5516265631, 0.4853909016, 0.4719351530, 0.5018194318, + 0.3037382960, 0.5154316425, 0.8809794784, 0.7755761147, + 0.5941321254, 0.3974069953, 0.5925675035, 0.6097261906 }, + { 0.3008176684, 0.0706617832, 0.8484353423, 0.2574254870, + 0.2815728188, 0.1930673718, 0.2523665428, 0.2691601515, + 0.1271967888, 0.2653007507, 0.6473292708, 0.5275835395, + 0.3928174376, 0.2405275702, 0.4008491635, 0.4556109309 } }, + { { 0.7339050174, 0.4290645123, 0.6859754324, 0.6349166036, + 0.8034263849, 0.8509387374, 0.8591269255, 1.1049811840, + 1.3928194642, 1.3423343301, 1.0849018693, 0.8943830729, + 0.8579795361, 0.6920774579, 0.5613272190, 0.4303162098 }, + { 0.4534726143, 0.0901674032, 0.3465046287, 0.3470261693, + 0.5217422843, 0.5874564052, 0.6014336944, 0.9161834717, + 1.2823571563, 1.2193550467, 0.8868207335, 0.6514494419, + 0.6249030232, 0.4453887343, 0.3665317893, 0.2242033482 } }, + { { 0.4293252826, 0.3303368688, 0.6181751490, 0.9884168506, + 0.9915460944, 0.7939864993, 0.3019129038, 0.2443348169, + 0.4543070793, 0.5617444515, 0.4895110726, 0.6600027084, + 0.6290231943, 0.5580936670, 0.5459417701, 0.4647378922 }, + { 0.1409133077, -0.0050137639, 0.2551307082, 0.6764833927, + 0.7112701535, 0.4648943543, 0.0301380754, -0.0235806108, + 0.1018499136, 0.2422486544, 0.2406318784, 0.4000146985, + 0.3713299632, 0.3259559274, 0.3820737004, 0.2888743877 } }, + { { 0.7733334899, 0.8321111202, 1.3098945022, 1.0331128836, + 1.0380675197, 0.9479974508, 0.9740223289, 0.9442945123, + 0.8926619887, 0.8719046712, 0.8640815616, 0.8404036164, + 0.8359183669, 0.7675965428, 0.6895219088, 0.7266034484 }, + { 0.3655408621, 0.4643206596, 1.2171645761, 0.8341451287, + 0.8387868404, 0.6713201404, 0.6814901829, 0.6294404268, + 0.5172048807, 0.5205948949, 0.5408828259, 0.5298783183, + 0.5781729817, 0.5000983477, 0.4727174640, 0.4326109886 } }, + { { 0.8902629018, 0.4598354101, 0.6392975450, 0.4483093619, + 0.6220867038, 0.6323089004, 0.7063676715, 0.3717993498, + 0.6718416810, 0.7876758575, 0.2807383537, 0.3118221760, + 0.6703813672, 0.7662405372, 0.7122610807, 0.7851724625 }, + { 0.6301705837, 0.1221378446, 0.3532846570, 0.1412783861, + 0.3471826315, 0.3435318470, 0.4466925859, 0.1390357614, + 0.4092981219, 0.5406742096, 0.0690450072, 0.0829179883, + 0.4625995755, 0.5700891018, 0.5542864203, 0.6545265317 } }, + { { -0.1100520492, 0.3803526163, 0.8075987101, 0.6903563738, + 0.8012359142, 0.7835035324, 0.8195941448, 0.8381088376, + 0.8033220768, 0.7511680126, 0.6393496990, 0.6096218824, + 0.6934856176, 0.6690253615, 0.6401841640, 0.5600233674 }, + { -0.1776958704, -0.0293175578, 0.1520742774, 0.1746048331, + 0.2222214937, 0.3052507639, 0.2977927327, 0.3797789216, + 0.3395681381, 0.2976884246, 0.2516885400, 0.2403711081, + 0.3567789793, 0.3302847147, 0.3368039727, 0.3310148716 } }, + { { 0.5587195158, 0.4676063657, 0.1392965317, -0.0990996957, + -0.0816280842, -0.1146416068, -0.0116894841, 0.0521992445, + 0.1626615524, 0.2923687100, 0.4029874802, 0.4528989196, + 0.4694839120, 0.5058352947, 0.5369191170, 0.5105291605 }, + { 0.2193530202, 0.1211469173, 0.0179861784, -0.2022604346, + -0.1409794092, -0.2121175528, -0.1152674556, -0.0594626069, + -0.0122110248, 0.0274260640, 0.1414870024, 0.2044369578, + 0.2167974710, 0.2615978122, 0.3348221183, 0.3707562685 } }, + { { 0.5948622823, 0.7065241337, 0.9414781928, 0.9340723157, + 0.8835350275, 0.9730835557, 0.8503650427, 0.8902629018, + 0.8746688366, 0.6910865307, 0.6404449344, 0.6976057887, + 0.5916287303, 0.6022160053, 0.7729684114, 0.6096740365 }, + { 0.1262058616, 0.1300652623, 0.6594290137, 0.6535877585, + 0.5639349222, 0.6982316375, 0.4828875065, 0.5577285886, + 0.4591052532, 0.2964367270, 0.2695252299, 0.3324751854, + 0.2860580683, 0.2902825475, 0.4623388052, 0.3369604349 } }, + { { 0.8821268678, 0.8539636731, 0.2898653150, 0.7478301525, + 0.5109463930, 0.8577187657, 0.4884679914, 0.7846509218, + 0.7684310079, 0.7032384276, 0.6691296697, 0.8593355417, + 0.9383489490, 0.9808023572, 0.6804992557, 0.6403927803 }, + { 0.5590324402, 0.4209806323, 0.0259135962, 0.4318808317, + 0.2104346752, 0.5453680754, 0.1783599257, 0.4467447400, + 0.4352708459, 0.4089330435, 0.3994410038, 0.5984609127, + 0.6872792840, 0.7321317792, 0.4408513308, 0.4542027712 } }, + { { 0.6371070743, 0.6311093569, 0.7152860165, 0.6929640770, + 0.2292101383, 0.3234525323, 0.9644259810, 0.9881039262, + 0.8722697496, 0.4370440841, 0.4051779509, 0.4944135547, + 0.5392660499, 0.5969484448, 0.4268740416, 0.4990552664 }, + { 0.4233797193, 0.3647063971, 0.4345406890, 0.4180078506, + -0.0006328225, 0.0586141944, 0.7620160580, 0.8152132034, + 0.6707985997, 0.2095480561, 0.2178405523, 0.2776612639, + 0.3142212629, 0.3808741570, 0.2676998377, 0.2804775834 } }, + { { 0.4509170651, 0.9490405321, 0.8557890654, 0.8271043301, + 0.6915559173, 0.7321839333, 0.6257896423, 0.6274064183, + 0.5238284469, 0.5194996595, 0.4116972089, 0.3382642865, + 0.3755022883, 0.4867990613, 0.5686287880, 0.5106856227 }, + { 0.0989292860, 0.6244857907, 0.4700576067, 0.3905226588, + 0.2630059719, 0.3009741306, 0.2150763869, 0.2067838907, + 0.1533781290, 0.1815934777, 0.1023714542, 0.0373874903, + 0.0897501707, 0.1849313378, 0.2852757573, 0.2625887394 } }, + { { 0.9954054952, 0.9554033279, 0.8237664700, 0.9780903459, + 0.7261862159, 0.7884581685, 0.7933084965, 0.7393290401, + 0.8783196211, 1.0409359932, 1.0217954516, 0.9159227014, + 0.8698185086, 0.7057939768, 0.7662926912, 0.7339571714 }, + { 0.7913266420, 0.6739278436, 0.5061482191, 0.7058982849, + 0.3480692506, 0.4338105321, 0.4428853393, 0.3758152127, + 0.5962182879, 0.7925261855, 0.7968549728, 0.6629754901, + 0.6325175166, 0.4598354101, 0.5310778618, 0.5518873334 } }, + { { 0.4638512731, 0.0604917407, 0.1897295117, 0.3403504491, + 0.4708399177, 0.5241413713, 0.6061275601, 0.6446694136, + 0.7313494682, 0.7208143473, 0.6268848777, 0.6081094146, + 0.4913364649, 0.3529717326, 0.4954566360, 0.5767126679 }, + { 0.1353849769, -0.0274400115, 0.0002537966, 0.0272174478, + 0.0555371046, 0.0652899146, 0.1010676026, 0.1073260903, + 0.1568724513, 0.2207611799, 0.1434167027, 0.2262373567, + 0.1177047491, 0.0162650943, 0.2529402375, 0.4087765813 } }, + { { 0.9700064659, 0.9917025566, 0.9159227014, 0.9309430718, + 0.8991290927, 0.9314124584, 0.9059612751, 0.9473194480, + 0.9604622722, 0.9377752542, 0.9197821021, 0.8869771957, + 0.8506779671, 0.8594920039, 0.8320589662, 0.8739908338 }, + { 0.2892394662, 0.0551198721, 0.0892807841, 0.1158793569, + 0.0905846357, 0.0738953352, 0.0395258069, 0.0240360498, + 0.0477139950, 0.0751470327, 0.1171310544, 0.1555164456, + 0.1384620667, 0.1818542480, 0.2104868293, 0.1288135648 } }, + { { 0.4101847410, 0.3326316476, 0.4666675925, 0.5077128410, + 0.5892296433, 0.4272912741, 0.0603352785, -0.8668596745, + -1.1103670001, -0.0900248885, 0.1626615524, 0.1487885714, + 0.4130010605, 0.5119373202, 0.5820323825, 0.5486016273 }, + { 0.0383262634, 0.1300652623, 0.2295230627, 0.2706204653, + 0.3722165823, 0.1698066592, -0.0934670568, -0.8677462935, + -1.0724509954, -0.2164463401, -0.0056917667, -0.0301520228, + 0.1299088001, 0.2579991817, 0.3482257128, 0.2469425201 } }, + { { 0.6031547785, 0.5515222549, 0.4292209744, 0.5027582049, + 0.8167778254, 1.0925685167, 0.9878953099, 0.7019345760, + 0.2509583831, 0.2475162148, 0.5660732388, 0.5145971775, + 0.4824181199, 0.5970005989, 0.5996604562, 0.5384315848 }, + { 0.3677313328, 0.2650399804, 0.1585935354, 0.2213348746, + 0.5566333532, 0.8425940871, 0.7604514360, 0.4523773789, + 0.0681062341, 0.0737388730, 0.3169854283, 0.2868403792, + 0.2661873698, 0.3635068536, 0.4300554395, 0.3743027449 } }, + { { 0.5017672777, 0.6634970307, 0.6869142056, 0.7066284418, + 0.5669598579, 0.0621085167, 0.0634645224, 0.2321307659, + 0.8322675824, 0.9855483770, 0.8296598792, 0.6140028238, + 0.5462546945, 0.6730412245, 0.6856103539, 0.5975221395 }, + { 0.2680649161, 0.3324230313, 0.3688787222, 0.3886451125, + 0.2774004936, -0.1695076823, -0.1353467703, 0.0159000158, + 0.5895425677, 0.7586781979, 0.5639870763, 0.3687744141, + 0.3401418328, 0.4477356672, 0.4782979488, 0.4034568667 } }, + { { 0.8838479519, 0.9025712609, 0.7326533198, 0.8124490380, + 0.8956347704, 1.1007045507, 1.2731780410, 1.2029786706, + 1.0839109421, 0.9664078355, 0.7356782556, 0.6942157745, + 0.6917645335, 0.6383587718, 0.6503020525, 0.5989302993 }, + { 0.5576764345, 0.4596789479, 0.3790487647, 0.5514179468, + 0.7333834767, 0.9612445831, 1.1976589561, 1.1094664335, + 0.8868207335, 0.6789346337, 0.4643206596, 0.4029353261, + 0.4384522438, 0.3871847987, 0.4326109886, 0.3691916466 } }, + { { 0.8520861268, 0.8413423896, 0.7238392830, 0.9103943706, + 0.7072542906, 0.6479029655, 0.4557673931, 0.1908247471, + -0.0569070578, -0.1013423204, 0.2517406940, 0.4854952097, + 0.5820845366, 0.5886037946, 0.6177579165, 0.6226603985 }, + { 0.6160889864, 0.4592095613, 0.4752208591, 0.6685559750, + 0.4326109886, 0.4077335000, 0.2314006090, 0.0173603296, + -0.2208272815, -0.3014574647, 0.0321199298, 0.2559130192, + 0.3603254557, 0.3466089368, 0.4072119594, 0.4776199460 } }, + { { 0.7083495259, 0.9001721740, 0.6795083284, 1.2743254304, + 1.3672639728, 1.2563322783, 0.8557369113, 0.8287732601, + 0.7942472696, 0.8006622195, 0.7034991980, 0.5479236245, + 0.6391932368, 0.6248508692, 0.5495925546, 0.4719351530 }, + { 0.4000146985, 0.6493632793, 0.4583229423, 1.1484255195, + 1.2521599531, 1.1232351065, 0.6150459051, 0.5347808003, + 0.4726653099, 0.5269576907, 0.4278128147, 0.2745841742, + 0.3868718743, 0.4183729291, 0.3474434018, 0.3150035739 } }, + { { 0.9070043564, 0.7648323774, 0.4281778932, 0.5475063920, + 0.4134704471, 0.4706834555, 0.4549329281, 0.4648422003, + 0.4572798610, 0.4823138118, 0.4666154385, 0.4841913581, + 0.4018922448, 0.4297946692, 0.4646857381, 0.6091003418 }, + { 0.4925360084, 0.2065231204, 0.0948612690, 0.1716842055, + 0.0992422104, 0.1332988143, 0.1255800128, 0.1257364750, + 0.0955392718, 0.1118634939, 0.1372103691, 0.1525958180, + 0.0902717113, 0.1591672301, 0.2335910797, 0.3767018318 } }, + { { 0.3185500503, 0.8677845001, 0.7776622772, 0.8160476685, + 0.8624126315, 0.8057211637, 0.8852561116, 0.8471314907, + 0.9145145416, 0.8945916891, 0.8638729453, 0.8531292081, + 0.7425104380, 0.6215651631, 0.6501455903, 0.6341864467 }, + { -0.0499705672, 0.0687842369, 0.3051464558, 0.3368039727, + 0.4942049384, 0.3823344707, 0.5683158636, 0.5044271350, + 0.6278236508, 0.5777035952, 0.5745221972, 0.5502184033, + 0.4244228005, 0.3163595796, 0.3525545001, 0.3582914472 } }, + { { 0.3200625181, 0.9415303469, 0.6067534089, 0.3568832874, + 0.1600538492, 0.2938811779, 0.2037589550, 0.3017564416, + 0.2572168708, 0.4796018004, 0.6938506961, 0.6847758889, + 0.7232134342, 0.6111343503, 0.5159531832, 0.4856516719 }, + { 0.0680540800, 0.6285016537, 0.2514277697, 0.0790064335, + -0.0687981844, 0.0521992445, -0.0055874586, 0.0537117124, + 0.0188206434, 0.1883213520, 0.4493002892, 0.4300554395, + 0.4750122428, 0.3658016324, 0.3119786382, 0.2818335891 } }, + { { 0.6864969730, 1.0815640092, 0.9838794470, 0.8845259547, + 0.9438772798, 0.8888025880, 0.8178730607, 0.8581881523, + 0.7128347754, 0.7120524645, 0.7345308661, 0.7945601940, + 0.7854853868, 0.8261655569, 0.6941114664, 0.6646444201 }, + { 0.2847542167, 0.9535257816, 0.6691818237, 0.5026538968, + 0.5945493579, 0.4125838280, 0.3886451125, 0.3740941286, + 0.2453778982, 0.2928902507, 0.3219922185, 0.4065861106, + 0.3838469386, 0.4289602041, 0.3910441995, 0.3821780086 } }, + { { 1.1335094571, 1.0390062928, 0.7019867301, 0.6203134656, + 0.6951545477, 0.4863818288, 0.6171320677, 0.6247465611, + 0.5907421112, 0.6711115241, 0.7322882414, 0.7042293549, + 0.5635698438, 0.6174449921, 0.6727283001, 0.6431047916 }, + { 1.0146503448, 0.7762541175, 0.2200310230, 0.2459515929, + 0.2703596950, 0.1376276016, 0.2522100806, 0.2622758150, + 0.2389107943, 0.2956544161, 0.3799875379, 0.3653843999, + 0.2561216354, 0.2842326760, 0.4034568667, 0.3700782657 } }, + { { 0.6342907548, 0.9627570510, 0.5214815140, -0.0226939917, + 0.5616401434, 0.7231091261, 0.7417802811, 0.9092991352, + 0.9739701748, 0.7804785967, 0.6771092415, 0.6352295280, + 0.4660417438, 0.5869870186, 0.6692339778, 0.5986173749 }, + { 0.3988673091, 0.6997441053, 0.2316613793, -0.2566571236, + 0.2685343027, 0.4484136701, 0.4490395188, 0.6886874437, + 0.7703085542, 0.5847443938, 0.4539941549, 0.4098196626, + 0.2579991817, 0.3376384377, 0.4754816294, 0.5095382333 } }, + { { 0.4443456531, 2.0296727419, 0.6569256186, 0.6439914107, + 0.6436263323, 0.5507399440, 0.6095175743, 0.6066491008, + 0.5347808003, 0.2529402375, 0.4443978071, 0.7000570297, + 0.8259569407, 0.5927761197, 0.5078171492, 0.4418422580 }, + { 0.2430831194, 1.9133691788, 0.3723730445, 0.3764410615, + 0.3874977231, 0.3212099075, 0.3832210898, 0.4474227428, + 0.3644977808, 0.0814055204, 0.2752621770, 0.4647378922, + 0.6619845629, 0.4304205179, 0.3143777251, 0.2705683112 } }, + { { 0.9740744829, 1.0730628967, 0.9743352532, 0.9098728299, + 0.9453375936, 0.9661470652, 0.9270836711, 0.9643738270, + 0.9989519715, 0.9627048969, 0.9348546267, 0.9865393043, + 0.9399657249, 0.9752218723, 0.8440544009, 0.8819182515 }, + { 0.9258319736, 1.0357205868, 0.8463491797, 0.8108844161, + 0.8391519189, 0.8566235304, 0.8305986524, 0.8880724311, + 0.9181653261, 0.8670021892, 0.8305986524, 0.8995984793, + 0.8300249577, 0.8711223602, 0.7195626497, 0.8138571978 } }, +}; + +static const double wmavoice_mean_lsf10[2][10] = { + { 0.2235394066, 0.4097484909, 0.7025292732, 1.1077160169, + 1.3939179044, 1.6741291716, 1.9552949226, 2.2199793918, + 2.5103400247, 2.7829212906 }, + { 0.1493683393, 0.3714357373, 0.7702730245, 1.0609411394, + 1.3270362536, 1.5806033119, 1.8398507524, 2.1116740248, + 2.3823505771, 2.6865718527 } +}; + +static const double wmavoice_mean_lsf16[2][16] = { + { 0.0999206754, 0.2345933590, 0.4621011210, 0.6772546160, + 0.8346396060, 1.0067495130, 1.1571691668, 1.3292508688, + 1.4941465650, 1.6600755584, 1.8461284908, 2.0529487333, + 2.2690810112, 2.4949894820, 2.7172752965, 2.9164840903 }, + { 0.0918298402, 0.2475621892, 0.4782937721, 0.6284774045, + 0.7861951264, 0.9303736000, 1.0940441024, 1.2521029300, + 1.4434732098, 1.6551410742, 1.8917962963, 2.0967280403, + 2.2981430375, 2.4826173497, 2.6827972461, 2.8811350800 } +}; + +static const float wmavoice_std_codebook[1000] = { + -0.185013, -0.150405, -0.707267, -0.284100, 0.882898, + -0.788627, 0.061005, 0.374431, 0.053843, -0.909826, + 0.543602, 0.219326, 0.285698, 0.154709, -0.455005, + 0.426276, -0.868852, -0.952324, -0.550001, 0.813814, + -0.352815, 0.242122, 0.820495, -0.189574, -0.449538, + 0.499132, -0.247783, 0.598159, 0.732040, -0.564406, + -0.631788, -0.452973, 0.285189, -0.339055, 0.262927, + 0.168087, -0.127682, -0.676067, -0.457481, 0.926161, + -0.585893, -0.913880, 0.145487, 0.699804, 0.240829, + 0.690482, 0.126081, 0.371977, 0.738158, 0.576080, + 0.185791, -0.614657, -0.181799, 0.006285, 0.195768, + 0.368663, -0.494583, 0.947985, -0.033178, -0.762543, + -0.616421, 0.335034, -0.215516, 0.668769, 0.995979, + -0.952588, -0.163144, -0.131704, -0.628655, 0.379374, + -0.205543, -0.214549, 0.465494, 0.939944, -0.514744, + -0.293676, 0.630426, 0.611336, -0.921699, 0.368584, + 0.187416, 0.264092, 0.753927, -0.994382, -0.729623, + -0.050304, 0.374280, -0.224205, -0.102319, -0.658897, + 0.013252, 0.281260, 0.676137, 0.797736, -0.049971, + 0.672115, 0.845148, 0.786885, -0.459588, -0.783507, + 0.166259, 0.334869, 0.001944, -0.368247, 0.274813, + 0.487200, 0.338077, -0.094761, 0.098536, 0.416378, + -0.726176, -0.714048, -0.319530, -0.972249, -0.708430, + -0.049153, -0.022553, 0.665850, 0.726642, 0.875127, + -0.993047, -0.260106, 0.156387, 0.683090, -0.462370, + -0.893584, 0.355205, -0.617222, 0.893301, 0.895617, + -0.400729, 0.059559, 0.230486, 0.601215, 0.691313, + -0.494701, 0.088415, 0.029390, 0.410539, -0.813049, + -0.554232, 0.684362, -0.527097, 0.126238, 0.712113, + -0.235528, -0.922915, -0.310440, -0.569678, 0.803727, + -0.435313, -0.562725, -0.456380, 0.721075, -0.879635, + 0.081250, 0.827491, 0.475570, 0.464029, 0.720792, + 0.371187, -0.936700, -0.219649, -0.398327, 0.664515, + -0.528336, 0.106972, -0.247070, 0.501053, -0.482490, + -0.060119, 0.946821, -0.798127, 0.412784, 0.073058, + 0.913986, -0.822744, 0.150143, -0.396453, -0.392421, + -0.046130, 0.168234, 0.044854, 0.497490, -0.110691, + 0.165219, -0.421259, -0.283200, -0.359212, -0.957231, + -0.562409, -0.988025, -0.893931, 0.217942, -0.386352, + 0.770585, 0.689606, 0.720620, -0.476485, 0.190659, + -0.761870, 0.463395, 0.137480, -0.559997, -0.123821, + -0.789461, -0.646011, 0.053435, 0.360682, -0.042464, + 0.661014, -0.685448, -0.874230, -0.294133, 0.812042, + 0.015078, 0.871086, -0.609218, 0.731878, -0.488126, + -0.566448, -0.830530, -0.476150, -0.460379, 0.387412, + 0.137497, -0.689794, 0.077018, -0.141883, -0.166280, + -0.732322, 0.096247, -0.702884, 0.405158, 0.536250, + 0.173295, 0.615696, 0.890239, -0.773270, -0.023622, + -0.152226, 0.887744, 0.290930, -0.026456, -0.406389, + 0.102972, 0.988622, -0.535303, 0.493754, 0.720500, + -0.023428, 0.927306, 0.889970, 0.500421, -0.533073, + 0.277382, -0.362081, -0.222867, -0.645599, 0.496035, + 0.610853, -0.377922, -0.407718, 0.907969, -0.972764, + -0.871468, 0.081264, 0.642933, -0.981230, 0.307994, + -0.380689, -0.133456, 0.195738, 0.910241, 0.840088, + 0.789349, 0.013213, 0.828710, -0.745954, -0.493033, + 0.549210, 0.230618, -0.565727, 0.439180, -0.268961, + -0.098800, -0.283438, 0.368958, 0.678333, 0.070963, + -0.135007, 0.289186, 0.693041, 0.457275, 0.197155, + 0.720277, 0.585807, -0.721581, 0.363210, 0.604577, + 0.586413, 0.982521, -0.528878, -0.217849, 0.892762, + -0.688791, -0.428500, -0.094025, -0.860081, -0.174454, + 0.412942, 0.689129, -0.943836, 0.847215, 0.128309, + -0.212797, -0.251585, 0.844871, -0.843839, -0.573252, + -0.084167, 0.021154, 0.715935, -0.391126, -0.521570, + -0.086910, -0.670848, -0.935763, 0.191509, 0.692361, + 0.668814, -0.222078, 0.674882, -0.860064, 0.560073, + 0.567644, -0.548855, -0.868427, -0.526382, -0.408936, + -0.042881, 0.886560, -0.719807, 0.013283, 0.733775, + 0.408502, 0.800487, -0.517810, 0.253372, 0.956648, + -0.091062, -0.830794, -0.022198, -0.375127, -0.221920, + 0.456232, 0.537963, 0.107232, 0.520469, -0.270529, + -0.200406, 0.189284, 0.507393, -0.525524, 0.329220, + 0.067466, -0.957881, 0.780365, 0.199039, -0.484262, + -0.628570, -0.843843, -0.597703, -0.348377, 0.169441, + -0.863928, -0.939875, -0.030073, -0.381738, 0.313497, + -0.073425, 0.527200, 0.482703, 0.904377, -0.847927, + -0.739217, 0.360609, 0.690035, 0.368015, -0.118921, + -0.580493, -0.832391, -0.929638, 0.926900, -0.357915, + 0.399582, -0.005634, -0.315796, 0.179947, -0.806596, + 0.393360, 0.732931, -0.415833, -0.724526, 0.957347, + -0.892887, 0.475366, 0.173583, -0.418554, -0.302536, + 0.627315, 0.782000, 0.497542, 0.139082, 0.570111, + 0.732375, -0.454643, 0.302218, -0.019505, 0.881778, + -0.057606, 0.273041, 0.414170, -0.503501, -0.079602, + -0.083941, 0.007178, -0.171925, 0.506856, 0.520953, + 0.631684, -0.099784, 0.253885, -0.784149, 0.175691, + 0.211231, -0.677036, -0.348943, -0.615186, -0.095591, + 0.348521, -0.987871, -0.313590, -0.153938, 0.151210, + -0.743479, -0.421562, 0.696567, 0.558739, 0.558933, + 0.578346, -0.498867, -0.168026, -0.007485, -0.002368, + 0.752372, 0.908575, -0.995190, -0.419553, 0.415430, + 0.525763, -0.787869, -0.684353, -0.220353, -0.572018, + 0.491337, 0.990879, -0.249054, -0.857606, -0.624307, + 0.655355, 0.490915, -0.612178, -0.658235, -0.663023, + 0.539032, -0.401714, -0.084585, 0.235599, -0.842975, + -0.525653, -0.186055, -0.341841, 0.306321, 0.806460, + 0.655791, 0.058693, 0.715035, 0.660601, 0.639140, + 0.130465, 0.186363, 0.851271, 0.446112, 0.966011, + -0.720746, -0.062551, 0.956890, 0.030200, 0.079843, + -0.667418, -0.314445, -0.429243, -0.279596, 0.027320, + -0.092266, -0.740564, 0.625606, 0.823149, 0.495035, + 0.782632, -0.702504, -0.691020, -0.559209, 0.603818, + -0.884560, -0.903419, -0.337489, 0.830475, 0.757182, + -0.698349, -0.039060, -0.056455, -0.847078, -0.592948, + -0.090444, -0.567824, 0.344501, -0.133554, 0.462375, + -0.575656, 0.199028, -0.852070, -0.004899, 0.919432, + 0.175251, 0.902835, -0.821132, -0.199143, 0.725984, + 0.673903, -0.416511, -0.976519, 0.982883, 0.024279, + 0.627298, -0.901677, 0.120861, -0.710191, 0.928798, + -0.121958, -0.408540, -0.110261, 0.821588, -0.255618, + 0.296790, -0.268856, 0.176557, -0.358709, 0.597589, + -0.361067, 0.065635, -0.203382, -0.213137, -0.939264, + -0.283951, 0.962113, 0.963571, -0.105083, -0.237030, + 0.689556, -0.431180, 0.346459, 0.713037, -0.448297, + -0.629262, 0.340335, -0.349973, 0.491599, 0.630144, + -0.421175, -0.630359, -0.778396, 0.468564, -0.808771, + -0.034014, -0.234646, -0.077627, -0.857457, 0.406645, + -0.480038, -0.218524, -0.527720, 0.316580, 0.568338, + -0.466984, -0.967371, 0.530452, -0.503413, -0.072454, + -0.706578, -0.813857, 0.496366, 0.639881, 0.899179, + -0.951931, -0.989381, 0.239514, -0.301904, 0.502218, + -0.130341, 0.276921, 0.871860, 0.091262, -0.254515, + -0.936911, -0.942752, 0.510839, -0.014539, -0.800209, + -0.082516, 0.505423, -0.018733, 0.389763, -0.177997, + -0.450395, 0.922779, -0.145368, -0.919943, -0.580634, + 0.782178, -0.626521, -0.394491, 0.278545, -0.986640, + -0.495312, 0.326614, -0.976021, 0.744203, -0.975290, + 0.526197, -0.386139, 0.301631, 0.398057, 0.705124, + -0.952884, 0.461146, 0.762372, 0.557954, -0.553393, + 0.962163, -0.524562, 0.952030, -0.056570, 0.865202, + -0.225967, 0.493035, 0.787981, 0.628665, 0.573093, + -0.792653, 0.410844, 0.946571, -0.187144, -0.310612, + 0.959931, 0.317544, -0.983998, 0.983911, 0.061747, + -0.959287, 0.510108, 0.675608, 0.342344, -0.091835, + 0.380731, 0.389460, -0.630689, 0.143103, -0.052586, + -0.184083, 0.105266, 0.422852, -0.232052, -0.951303, + 0.288054, 0.541981, 0.541732, 0.076035, 0.170646, + 0.114825, 0.283382, -0.418510, 0.061396, -0.903763, + 0.270879, 0.021327, 0.413782, 0.286881, 0.005238, + -0.524472, 0.327594, -0.484654, -0.848864, -0.330063, + 0.423511, 0.531868, -0.940603, 0.792822, -0.325029, + 0.006811, -0.391261, 0.780237, -0.570337, 0.376687, + 0.828934, 0.717717, -0.081333, 0.370666, -0.206248, + -0.910686, -0.514510, -0.922867, -0.329196, 0.546886, + -0.826629, 0.941683, -0.431786, 0.587152, 0.228564, + 0.573452, -0.937320, -0.443843, -0.911202, -0.786184, + 0.226094, 0.512309, 0.745684, 0.285491, 0.305131, + -0.579345, -0.707698, 0.913870, -0.799108, -0.278035, + 0.290556, -0.970174, -0.560318, -0.790776, 0.400492, + 0.233434, -0.701462, 0.885982, 0.310567, -0.030658, + 0.432868, 0.483938, -0.088976, -0.998918, 0.071090, + -0.860412, 0.574534, 0.133770, -0.304255, 0.663332, + 0.347586, 0.921839, 0.175641, 0.093270, 0.207330, + -0.519228, 0.513925, 0.499633, -0.605358, 0.714817, + -0.778402, 0.685198, 0.744643, -0.338720, 0.894422, + 0.145135, 0.894714, -0.807041, 0.031117, 0.205281, + 0.162301, -0.536015, -0.310781, -0.926675, -0.534932, + 0.760308, -0.787088, -0.960398, -0.105922, -0.091343, + 0.702934, -0.758336, -0.169504, -0.121425, 0.334935, + -0.962173, 0.359347, -0.151140, 0.537460, 0.753989, + -0.436323, 0.759058, 0.439187, -0.691680, -0.579662, + 0.333608, 0.453454, -0.684948, 0.526567, -0.515429, + 0.520333, -0.311132, -0.051443, -0.790448, -0.237807, + 0.413625, 0.969861, -0.024895, 0.453226, -0.136061, + 0.883762, 0.156160, 0.105603, -0.285741, -0.965264, + -0.559462, -0.247914, 0.394083, 0.289398, -0.710455, + 0.148072, 0.853074, -0.951397, -0.412742, -0.838606, + -0.531059, 0.920866, 0.614848, -0.216007, 0.447434, + -0.900580, -0.695673, -0.863698, 0.047977, -0.486121, + -0.101505, -0.538399, -0.516261, 0.873600, 0.914828, + 0.347678, 0.757362, 0.070988, -0.546718, -0.528380, + 0.105724, -0.106180, 0.223706, -0.500194, -0.816782, + 0.513251, 0.647878, -0.963708, 0.561854, -0.764864, + -0.802314, -0.969205, -0.843997, 0.812534, -0.185212, + 0.603436, 0.911954, 0.119114, 0.739738, -0.040069, + 0.632993, -0.361767, 0.421532, -0.883268, -0.488168, + 0.336360, 0.464411, -0.730806, -0.592652, 0.917693, + -0.259186, 0.513071, -0.188487, 0.964520, -0.987122, + -0.005270, 0.477771, 0.660756, 0.031023, 0.039625, + 0.895892, 0.228709, 0.070419, -0.948105, 0.041243, + 0.885207, 0.655331, -0.046803, 0.004321, 0.395069, + 0.913128, -0.362686, -0.966698, 0.334661, -0.245954, + -0.454865, -0.328980, -0.781543, -0.185671, 0.078368, + -0.863850, 0.555143, -0.408560, -0.052338, 0.519663, + -0.395683, 0.942393, -0.002565, -0.734927, -0.026585, + -0.962941, -0.839035, -0.797876, 0.107479, -0.787140, + 0.243367, -0.007314, 0.868191, -0.803435, 0.997007, + 0.263261, -0.890307, -0.365679, 0.296563, 0.444354, + 0.388367, 0.841698, -0.884626, 0.606824, -0.343973, + 0.193743, 0.742974, -0.788830, 0.785182, -0.309364, + 0.730833, -0.610500, -0.366971, -0.271732, -0.345427, + 0.606444, -0.234673, -0.184462, 0.808568, 0.872806, + 0.028398, 0.051936, -0.134508, -0.103410, 0.248500, + -0.137501, -0.840150, 0.358194, 0.496819, 0.456413, + -0.197453, -0.114814, 0.298111, -0.082078, -0.507990, + 0.954138, -0.888336, -0.765016, -0.834692, 0.896847, + -0.074380, 0.896141, -0.713654, 0.558649, -0.375591, + -0.059081, 0.165093, 0.389736, 0.756458, -0.026339, + 0.262542, -0.215144, -0.974403, -0.871966, 0.681446 +}; + +static const float wmavoice_gain_silence[256] = { + 0.0000188351, 0.0000249147, 0.0000294447, 0.0000365973, + 0.0000423193, 0.0000464916, 0.0000498295, 0.0000525713, + 0.0000550747, 0.0000574589, 0.0000596046, 0.0000615120, + 0.0000634193, 0.0000649691, 0.0000665188, 0.0000679493, + 0.0000692606, 0.0000704527, 0.0000716448, 0.0000728369, + 0.0000737906, 0.0000747442, 0.0000755787, 0.0000762939, + 0.0000770092, 0.0000778437, 0.0000785589, 0.0000792742, + 0.0000799894, 0.0000807047, 0.0000814199, 0.0000822544, + 0.0000829697, 0.0000838041, 0.0000845194, 0.0000854731, + 0.0000865459, 0.0000876188, 0.0000889301, 0.0000904799, + 0.0000923872, 0.0000950098, 0.0000988245, 0.0001032352, + 0.0001088381, 0.0001147985, 0.0001225471, 0.0001319647, + 0.0001431704, 0.0001568794, 0.0001744032, 0.0001952648, + 0.0002206564, 0.0002535582, 0.0002965927, 0.0003464222, + 0.0004109144, 0.0004891157, 0.0005909204, 0.0007261038, + 0.0008867979, 0.0010721684, 0.0012696981, 0.0015079975, + 0.0017461777, 0.0019979477, 0.0022052526, 0.0023679733, + 0.0025173426, 0.0026556253, 0.0027927160, 0.0029264688, + 0.0030447245, 0.0031807423, 0.0033060312, 0.0034313202, + 0.0035454035, 0.0036598444, 0.0037686825, 0.0038731098, + 0.0039769411, 0.0040702820, 0.0041661263, 0.0042562485, + 0.0043400526, 0.0044249296, 0.0045082569, 0.0045900345, + 0.0046693087, 0.0047430992, 0.0048171282, 0.0048881769, + 0.0049589872, 0.0050252676, 0.0050880909, 0.0051497221, + 0.0052082539, 0.0052671432, 0.0053246021, 0.0053800344, + 0.0054348707, 0.0054861307, 0.0055367947, 0.0055862665, + 0.0056355000, 0.0056805611, 0.0057252645, 0.0057705641, + 0.0058110952, 0.0058538914, 0.0058966875, 0.0059366226, + 0.0059723854, 0.0060091019, 0.0060437918, 0.0060794353, + 0.0061159134, 0.0061485767, 0.0061824322, 0.0062153339, + 0.0062497854, 0.0062820911, 0.0063197613, 0.0063550472, + 0.0063927174, 0.0064336061, 0.0064769983, 0.0065194368, + 0.0065603256, 0.0066006184, 0.0066410303, 0.0066826344, + 0.0067234039, 0.0067654848, 0.0068060160, 0.0068466663, + 0.0068866014, 0.0069231987, 0.0069609880, 0.0069983006, + 0.0070366859, 0.0070750713, 0.0071122646, 0.0071535110, + 0.0071973801, 0.0072410107, 0.0072846413, 0.0073343515, + 0.0073832273, 0.0074360371, 0.0074878931, 0.0075426102, + 0.0076007843, 0.0076560974, 0.0077134371, 0.0077683926, + 0.0078265667, 0.0078855753, 0.0079488754, 0.0080170631, + 0.0080827475, 0.0081528425, 0.0082212687, 0.0082877874, + 0.0083510876, 0.0084129572, 0.0084775686, 0.0085455179, + 0.0086110830, 0.0086781979, 0.0087503195, 0.0088242292, + 0.0089002848, 0.0089734793, 0.0090423822, 0.0091133118, + 0.0091816187, 0.0092473030, 0.0093164444, 0.0093911886, + 0.0094678402, 0.0095427036, 0.0096175671, 0.0096931458, + 0.0097666979, 0.0098397732, 0.0099166632, 0.0099946260, + 0.0100749731, 0.0101612806, 0.0102528334, 0.0103493929, + 0.0104434490, 0.0105448961, 0.0106583834, 0.0107737780, + 0.0108981133, 0.0110142231, 0.0111318827, 0.0112472773, + 0.0113576651, 0.0114786625, 0.0116028786, 0.0117331743, + 0.0118676424, 0.0120122433, 0.0121580362, 0.0123010874, + 0.0124633312, 0.0126402378, 0.0128232241, 0.0130140781, + 0.0132108927, 0.0134289265, 0.0136625767, 0.0138912201, + 0.0141364336, 0.0144006014, 0.0146615505, 0.0149335861, + 0.0152134895, 0.0155050755, 0.0158376694, 0.0162067413, + 0.0165973902, 0.0169926882, 0.0174319744, 0.0179271698, + 0.0184448957, 0.0190744400, 0.0197248459, 0.0204203129, + 0.0212460756, 0.0221523046, 0.0231562853, 0.0243031979, + 0.0256397724, 0.0271918774, 0.0289602280, 0.0310072899, + 0.0333702564, 0.0363805294, 0.0401413441, 0.0443998575, + 0.0498176813, 0.0562580824, 0.0640066862, 0.0732775927, + 0.0836604834, 0.0962959528, 0.1122496128, 0.1335854530, + 0.1608980894, 0.1990102530, 0.2616490126, 0.3926030397 +}; + +static const float wmavoice_gain_universal[64] = { + 0.0000000000, 0.0000000000, 0.0000015497, 0.0000015497, + 0.0000095367, 0.0000164509, 0.0000379086, 0.0000494719, + 0.0000799894, 0.0001058578, 0.0001349449, 0.0001627207, + 0.0001972914, 0.0002325773, 0.0002671480, 0.0003106594, + 0.0003589392, 0.0004127026, 0.0004582405, 0.0005071163, + 0.0005759001, 0.0006588697, 0.0007554293, 0.0008602142, + 0.0009772778, 0.0011068583, 0.0012603998, 0.0013889074, + 0.0015437603, 0.0016924143, 0.0018980503, 0.0021264553, + 0.0023632050, 0.0025693178, 0.0028522015, 0.0031896830, + 0.0034654140, 0.0037885904, 0.0041683912, 0.0046081543, + 0.0050576925, 0.0055632591, 0.0061818361, 0.0068151951, + 0.0073953867, 0.0081818104, 0.0091186762, 0.0102789402, + 0.0119919777, 0.0134155750, 0.0154829025, 0.0173798800, + 0.0199711323, 0.0229473114, 0.0268185139, 0.0319474936, + 0.0393068790, 0.0460114479, 0.0523469448, 0.0637906790, + 0.0845471621, 0.1105458736, 0.1499300003, 0.2219169140 +}; + +static const float wmavoice_gain_codebook_acb[128] = { + 0.05, 0.14, 0.16, 0.05, 0.17, 0.25, 0.07, 0.21, + 0.12, 0.22, 0.23, 0.13, 0.24, 0.32, 0.14, 0.29, + 0.31, 0.41, 0.43, 0.32, 0.43, 0.51, 0.34, 0.48, + 0.38, 0.47, 0.49, 0.38, 0.49, 0.57, 0.40, 0.54, + 0.49, 0.59, 0.61, 0.50, 0.61, 0.69, 0.52, 0.66, + 0.56, 0.65, 0.67, 0.56, 0.67, 0.75, 0.58, 0.72, + 0.65, 0.74, 0.76, 0.65, 0.76, 0.84, 0.67, 0.81, + 0.71, 0.80, 0.82, 0.71, 0.82, 0.90, 0.73, 0.87, + 0.81, 0.90, 0.92, 0.81, 0.93, 1.01, 0.83, 0.97, + 0.87, 0.96, 0.98, 0.87, 0.98, 1.06, 0.89, 1.03, + 0.92, 1.02, 1.04, 0.93, 1.04, 1.12, 0.95, 1.09, + 0.93, 1.02, 1.04, 0.93, 1.04, 1.12, 0.95, 1.09, + 0.94, 1.04, 1.05, 0.10, 1.06, 1.14, 0.96, 1.11, + 0.98, 1.08, 1.10, 0.99, 1.10, 1.18, 1.01, 1.15, + 1.06, 1.15, 1.17, 1.06, 1.17, 1.25, 1.08, 1.22, + 1.16, 1.25, 1.27, 1.16, 1.28, 1.36, 1.18, 1.32 +}; + +static const float wmavoice_gain_codebook_fcb[128] = { + -0.8439700703 /* log(0.430) */, -0.6143360001 /* log(0.541) */, + -0.1531511795 /* log(0.858) */, -0.0998203353 /* log(0.905) */, + 0.3213585988 /* log(1.379) */, 0.3777512695 /* log(1.459) */, + 0.7158866675 /* log(2.046) */, 1.2700414043 /* log(3.561) */, + -1.6873994539 /* log(0.185) */, -1.2173958247 /* log(0.296) */, + -0.4893903430 /* log(0.613) */, -0.4155154440 /* log(0.660) */, + 0.1257512053 /* log(1.134) */, 0.1947440768 /* log(1.215) */, + 0.5883420662 /* log(1.801) */, 1.1987592373 /* log(3.316) */, + -1.3586791941 /* log(0.257) */, -0.9996723408 /* log(0.368) */, + -0.3768776513 /* log(0.686) */, -0.3119747650 /* log(0.732) */, + 0.1881379421 /* log(1.207) */, 0.2523139286 /* log(1.287) */, + 0.6280751838 /* log(1.874) */, 1.2202397768 /* log(3.388) */, + -0.7381445465 /* log(0.478) */, -0.5310283311 /* log(0.588) */, + -0.0987159729 /* log(0.906) */, -0.0491902442 /* log(0.952) */, + 0.3555743385 /* log(1.427) */, 0.4101209196 /* log(1.507) */, + 0.7390761124 /* log(2.094) */, 1.2831536022 /* log(3.608) */, + -0.2497442331 /* log(0.779) */, -0.1165338163 /* log(0.890) */, + 0.1881379421 /* log(1.207) */, 0.2255406759 /* log(1.253) */, + 0.5469646704 /* log(1.728) */, 0.5922212620 /* log(1.808) */, + 0.8733832309 /* log(2.395) */, 1.3632815868 /* log(3.909) */, + -1.3903023825 /* log(0.249) */, -1.0216512475 /* log(0.360) */, + -0.3900840061 /* log(0.677) */, -0.3229638866 /* log(0.724) */, + 0.1806534997 /* log(1.198) */, 0.2460785226 /* log(1.279) */, + 0.6232610531 /* log(1.865) */, 1.2178757095 /* log(3.380) */, + -0.6033064766 /* log(0.547) */, -0.4185503477 /* log(0.658) */, + -0.0253178080 /* log(0.975) */, 0.0217614918 /* log(1.022) */, + 0.4027948796 /* log(1.496) */, 0.4555243080 /* log(1.577) */, + 0.7714961470 /* log(2.163) */, 1.3023691262 /* log(3.678) */, + -1.1056369036 /* log(0.331) */, -0.8164453969 /* log(0.442) */, + -0.2757535016 /* log(0.759) */, -0.2156715365 /* log(0.806) */, + 0.2468600779 /* log(1.280) */, 0.3082197237 /* log(1.361) */, + 0.6662897264 /* log(1.947) */, 1.2418464568 /* log(3.462) */, + -0.5395680926 /* log(0.583) */, -0.3652833185 /* log(0.694) */, + 0.0109399400 /* log(1.011) */, 0.0554347069 /* log(1.057) */, + 0.4265740713 /* log(1.532) */, 0.4774756441 /* log(1.612) */, + 0.7880027116 /* log(2.199) */, 1.3118401752 /* log(3.713) */, + -0.9571127264 /* log(0.384) */, -0.7031975164 /* log(0.495) */, + -0.2082549388 /* log(0.812) */, -0.1519863570 /* log(0.859) */, + 0.2874320412 /* log(1.333) */, 0.3464225675 /* log(1.414) */, + 0.6931471806 /* log(2.000) */, 1.2570395253 /* log(3.515) */, + -0.2420715612 /* log(0.785) */, -0.1098148660 /* log(0.896) */, + 0.1930966300 /* log(1.213) */, 0.2311117210 /* log(1.260) */, + 0.5504308784 /* log(1.734) */, 0.5960854677 /* log(1.815) */, + 0.8758853172 /* log(2.401) */, 1.3650707247 /* log(3.916) */, + 0.6564831962 /* log(1.928) */, 0.7124594916 /* log(2.039) */, + 0.8569652658 /* log(2.356) */, 0.8767179568 /* log(2.403) */, + 1.0567480846 /* log(2.877) */, 1.0841752409 /* log(2.957) */, + 1.2652560327 /* log(3.544) */, 1.6211688353 /* log(5.059) */, + -1.5417792640 /* log(0.214) */, -1.1239300967 /* log(0.325) */, + -0.4431669753 /* log(0.642) */, -5.2983173665 /* log(0.005) */, + 0.1510028735 /* log(1.163) */, 0.2183319943 /* log(1.244) */, + 0.6043159669 /* log(1.830) */, 1.2074666936 /* log(3.345) */, + -0.5124936809 /* log(0.599) */, -0.3424903089 /* log(0.710) */, + 0.0266419309 /* log(1.027) */, 0.0713899961 /* log(1.074) */, + 0.4369637752 /* log(1.548) */, 0.4879663296 /* log(1.629) */, + 0.7952524035 /* log(2.215) */, 1.3164082337 /* log(3.730) */, + -0.8867319296 /* log(0.412) */, -0.6481738149 /* log(0.523) */, + -0.1743533871 /* log(0.840) */, -0.1199102967 /* log(0.887) */, + 0.3089542077 /* log(1.362) */, 0.3660310389 /* log(1.442) */, + 0.7075430608 /* log(2.029) */, 1.2649738259 /* log(3.543) */, + -0.0943106795 /* log(0.910) */, 0.0207825392 /* log(1.021) */, + 0.2911759617 /* log(1.338) */, 0.3249778572 /* log(1.384) */, + 0.6200387087 /* log(1.859) */, 0.6621723763 /* log(1.939) */, + 0.9266370239 /* log(2.526) */, 1.3962446920 /* log(4.040) */ +}; + +static const float wmavoice_ipol1_coeffs[17*9] = { + 0, + 0.6308171151, 0.7613050340, 0.8632577061, 0.9280143976, + 0.9499985575, 0.9273047447, 0.8618999123, 0.7594153284, + -0.1791058179, -0.1351341452, -0.0589959878, 0.0472882274, + 0.1784339990, 0.3262237605, 0.4801855979, 0.6285545824, + 0, + -0.1921342459, -0.1786532696, -0.1341681625, -0.0575229186, + 0.0492091286, 0.1806929555, 0.3286687729, 0.4826357064, + 0.0807464118, 0.0506337392, 0.0080115446, -0.0428523305, + -0.0958572026, -0.1436148431, -0.1782128509, -0.1921164688, + 0, + 0.0960653644, 0.0803771760, 0.0500416081, 0.0072485465, + -0.0437018941, -0.0966834794, -0.1442930843, -0.1786170151, + -0.0391932014, -0.0189622506, 0.0070230183, 0.0356589290, + 0.0630142610, 0.0847979258, 0.0969368290, 0.0961942221, + 0, + -0.0515680681, -0.0389267015, -0.0185848991, 0.0074699190, + 0.0361179407, 0.0634181346, 0.0850781347, 0.0970333587, + 0.0178811825, 0.0048708571, -0.0108041526, -0.0271167825, + -0.0416534986, -0.0519338618, -0.0557823736, -0.0517020743, + 0, + 0.0267091128, 0.0177022810, 0.0046363524, -0.0110662053, + -0.0273700613, -0.0418578978, -0.0520511451, -0.0557823028, + -0.0069270437, 0.0008217385, 0.0097293532, 0.0185749526, + 0.0259542684, 0.0304777338, 0.0309953480, 0.0268154419, + 0, + -0.0125539196, -0.0068173436, 0.0009580161, 0.0098749646, + 0.0187084037, 0.0260526291, 0.0305201071, 0.0309665180, + 0.0019149571, -0.0022503408, -0.0068592466, -0.0112465904, + -0.0146595868, -0.0163685936, -0.0157934162, -0.0126258885, + 0, + 0.0050976076, 0.0018546581, -0.0023221741, -0.0069331308, + -0.0113109085, -0.0147021576, -0.0163786146, -0.0157635096, + -0.0001162733, 0.0019313511, 0.0040823850, 0.0060192454, + 0.0073876535, 0.0078486321, 0.0071403184, 0.0051400312, + 0, + -0.0017920607, -0.0000857157, 0.0019657183, 0.0041159806, + 0.0060465694, 0.0074030068, 0.0078470460, 0.0071185785, + -0.0004100171, -0.0015364708, -0.0025490071, -0.0033188616, + -0.0037196307, -0.0036417283, -0.0030119629, -0.0018155784, + 0, + 0.0006907531, -0.0004282868, -0.0015539061, -0.0025635813, + -0.0033285026, -0.0037224069, -0.0036361245, -0.0029972247, + 0, 0, 0, 0, 0, 0, 0, 0 +}; + +/** + * Hamming-window sinc function (num = 32, x = [ 0, 31 ]): + * (0.54 + 0.46 * cos(2 * M_PI * x / (num - 1))) * + * sin(x * M_PI / 4) / (x * M_PI / 4) + */ +static const float wmavoice_ipol2_coeffs[32] = { + 1, 0.8563459515, 0.5888634918, 0.2648358640, + 0, -0.1360490318, -0.1434589471, -0.0758505310, + 0, 0.0410402636, 0.0412485781, 0.0200064587, + 0, -0.0081391358, -0.0068223253, -0.0029313546, + 0, 0.0025864919, 0.0053062555, 0.0055688801, + 0, -0.0104795941, -0.0187493577, -0.0160592399, + 0, 0.0212381664, 0.0331059131, 0.0251942366, + 0, -0.0273968070, -0.0392575669, -0.0276240534 +}; + +/** + * LUT for 1.071575641632 * pow(1.0331663, n - 127) + */ +static const float wmavoice_energy_table[128] = { + 0.0169982178, 0.0175619858, 0.0181444519, 0.0187462362, + 0.0193679795, 0.0200103437, 0.0206740128, 0.0213596933, + 0.0220681153, 0.0228000330, 0.0235562258, 0.0243374986, + 0.0251446834, 0.0259786395, 0.0268402549, 0.0277304468, + 0.0286501631, 0.0296003830, 0.0305821182, 0.0315964139, + 0.0326443501, 0.0337270424, 0.0348456436, 0.0360013446, + 0.0371953760, 0.0384290090, 0.0397035571, 0.0410203772, + 0.0423808713, 0.0437864880, 0.0452387238, 0.0467391249, + 0.0482892887, 0.0498908657, 0.0515455612, 0.0532551367, + 0.0550214125, 0.0568462692, 0.0587316496, 0.0606795611, + 0.0626920777, 0.0647713419, 0.0669195677, 0.0691390421, + 0.0714321284, 0.0738012678, 0.0762489827, 0.0787778794, + 0.0813906502, 0.0840900769, 0.0868790336, 0.0897604897, + 0.0927375130, 0.0958132732, 0.0989910450, 0.1022742117, + 0.1056662688, 0.1091708280, 0.1127916204, 0.1165325012, + 0.1203974531, 0.1243905911, 0.1285161668, 0.1327785725, + 0.1371823465, 0.1417321773, 0.1464329093, 0.1512895470, + 0.1563072616, 0.1614913951, 0.1668474671, 0.1723811803, + 0.1780984262, 0.1840052921, 0.1901080668, 0.1964132480, + 0.2029275487, 0.2096579046, 0.2166114816, 0.2237956830, + 0.2312181577, 0.2388868085, 0.2468098001, 0.2549955679, + 0.2634528274, 0.2721905830, 0.2812181375, 0.2905451026, + 0.3001814086, 0.3101373153, 0.3204234225, 0.3310506819, + 0.3420304081, 0.3533742912, 0.3650944090, 0.3772032397, + 0.3897136755, 0.4026390362, 0.4159930832, 0.4297900346, + 0.4440445799, 0.4587718956, 0.4739876619, 0.4897080789, + 0.5059498840, 0.5227303696, 0.5400674019, 0.5579794393, + 0.5764855528, 0.5956054456, 0.6153594745, 0.6357686714, + 0.6568547659, 0.6786402082, 0.7011481929, 0.7244026842, + 0.7484284410, 0.7732510432, 0.7988969192, 0.8253933741, + 0.8527686184, 0.8810517982, 0.9102730265, 0.9404634147, + 0.9716551065, 1.0038813113, 1.0371763400, 1.0715756416 +}; + +/** + * LUT for f(x,y) = pow((y + 6.9) / 64, 0.025 * (x + 1)). + */ +static const float wmavoice_denoise_power_table[12][64] = { + { 0.9458379339, 0.9490436287, 0.9518757236, 0.9544130754, + 0.9567118717, 0.9588135761, 0.9607496688, 0.9625446194, + 0.9642178285, 0.9657849396, 0.9672587526, 0.9686498743, + 0.9699671937, 0.9712182343, 0.9724094211, 0.9735462842, + 0.9746336187, 0.9756756090, 0.9766759291, 0.9776378218, + 0.9785641645, 0.9794575217, 0.9803201890, 0.9811542296, + 0.9819615045, 0.9827436985, 0.9835023412, 0.9842388263, + 0.9849544265, 0.9856503078, 0.9863275406, 0.9869871101, + 0.9876299254, 0.9882568267, 0.9888685922, 0.9894659445, + 0.9900495551, 0.9906200497, 0.9911780119, 0.9917239872, + 0.9922584859, 0.9927819864, 0.9932949377, 0.9937977618, + 0.9942908555, 0.9947745929, 0.9952493267, 0.9957153901, + 0.9961730980, 0.9966227482, 0.9970646231, 0.9974989903, + 0.9979261037, 0.9983462046, 0.9987595223, 0.9991662752, + 0.9995666709, 0.9999609077, 1.0003491745, 1.0007316515, + 1.0011085110, 1.0014799178, 1.0018460292, 1.0022069960 }, + { 0.8946093973, 0.9006838092, 0.9060673931, 0.9109043185, + 0.9152976055, 0.9193234737, 0.9230399260, 0.9264921443, + 0.9297160207, 0.9327405496, 0.9355894944, 0.9382825789, + 0.9408363568, 0.9432648587, 0.9455800822, 0.9477923675, + 0.9499106907, 0.9519428941, 0.9538958704, 0.9557757107, + 0.9575878241, 0.9593370368, 0.9610276730, 0.9626636222, + 0.9642483964, 0.9657851769, 0.9672768552, 0.9687260672, + 0.9701352224, 0.9715065293, 0.9728420173, 0.9741435556, + 0.9754128696, 0.9766515555, 0.9778610927, 0.9790428553, + 0.9801981216, 0.9813280829, 0.9824338513, 0.9835164667, + 0.9845769028, 0.9856160726, 0.9866348334, 0.9876339913, + 0.9886143053, 0.9895764906, 0.9905212223, 0.9914491381, + 0.9923608411, 0.9932569022, 0.9941378627, 0.9950042356, + 0.9958565084, 0.9966951442, 0.9975205834, 0.9983332454, + 0.9991335296, 0.9999218170, 1.0006984708, 1.0014638383, + 1.0022182509, 1.0029620257, 1.0036954662, 1.0044188628 }, + { 0.8461555040, 0.8547882305, 0.8624635555, 0.8693789920, + 0.8756760853, 0.8814598273, 0.8868103032, 0.8917900284, + 0.8964487626, 0.9008267754, 0.9049571273, 0.9088673021, + 0.9125804007, 0.9161160306, 0.9194909803, 0.9227197376, + 0.9258148939, 0.9287874629, 0.9316471355, 0.9344024839, + 0.9370611291, 0.9396298766, 0.9421148300, 0.9445214846, + 0.9468548060, 0.9491192967, 0.9513190517, 0.9534578074, + 0.9555389816, 0.9575657096, 0.9595408742, 0.9614671327, + 0.9633469396, 0.9651825670, 0.9669761222, 0.9687295635, + 0.9704447142, 0.9721232742, 0.9737668316, 0.9753768718, + 0.9769547868, 0.9785018824, 0.9800193854, 0.9815084500, + 0.9829701633, 0.9844055505, 0.9858155796, 0.9872011653, + 0.9885631734, 0.9899024236, 0.9912196934, 0.9925157203, + 0.9937912053, 0.9950468143, 0.9962831814, 0.9975009102, + 0.9987005760, 0.9998827277, 1.0010478892, 1.0021965608, + 1.0033292209, 1.0044463270, 1.0055483173, 1.0066356112 }, + { 0.8003259737, 0.8112313241, 0.8209581209, 0.8297466775, + 0.8377697066, 0.8451556492, 0.8520027051, 0.8583876935, + 0.8643718792, 0.8700049328, 0.8753277020, 0.8803741979, + 0.8851730502, 0.8897485937, 0.8941216918, 0.8983103719, + 0.9023303202, 0.9061952736, 0.9099173316, 0.9135072091, + 0.9169744409, 0.9203275502, 0.9235741882, 0.9267212496, + 0.9297749699, 0.9327410079, 0.9356245146, 0.9384301933, + 0.9411623497, 0.9438249364, 0.9464215906, 0.9489556668, + 0.9514302661, 0.9538482608, 0.9562123167, 0.9585249126, + 0.9607883576, 0.9630048062, 0.9651762722, 0.9673046403, + 0.9693916775, 0.9714390425, 0.9734482944, 0.9754209007, + 0.9773582446, 0.9792616307, 0.9811322918, 0.9829713934, + 0.9847800389, 0.9865592739, 0.9883100900, 0.9900334289, + 0.9917301853, 0.9934012104, 0.9950473143, 0.9966692689, + 0.9982678100, 0.9998436400, 1.0013974295, 1.0029298194, + 1.0044414224, 1.0059328250, 1.0074045889, 1.0088572520 }, + { 0.7569786654, 0.7698939195, 0.7814501054, 0.7919210783, + 0.8015042240, 0.8103467104, 0.8185613167, 0.8262364557, + 0.8334427763, 0.8402376615, 0.8466683811, 0.8527743561, + 0.8585888194, 0.8641400582, 0.8694523567, 0.8745467247, + 0.8794414652, 0.8841526254, 0.8886943552, 0.8930791981, + 0.8973183276, 0.9014217415, 0.9053984227, 0.9092564737, + 0.9130032283, 0.9166453478, 0.9201889007, 0.9236394320, + 0.9270020224, 0.9302813390, 0.9334816797, 0.9366070112, + 0.9396610028, 0.9426470554, 0.9455683275, 0.9484277579, + 0.9512280860, 0.9539718690, 0.9566614986, 0.9592992147, + 0.9618871182, 0.9644271823, 0.9669212630, 0.9693711079, + 0.9717783651, 0.9741445900, 0.9764712529, 0.9787597445, + 0.9810113822, 0.9832274148, 0.9854090274, 0.9875573457, + 0.9896734398, 0.9917583281, 0.9938129803, 0.9958383209, + 0.9978352315, 0.9998045539, 1.0017470919, 1.0036636145, + 1.0055548568, 1.0074215229, 1.0092642871, 1.0110837959 }, + { 0.7159791370, 0.7306629191, 0.7438433845, 0.7558198318, + 0.7668086064, 0.7769714272, 0.7864325139, 0.7952894548, + 0.8036203840, 0.8114888792, 0.8189474022, 0.8260397728, + 0.8328029877, 0.8392685815, 0.8454636629, 0.8514117142, + 0.8571332177, 0.8626461513, 0.8679663850, 0.8731080020, + 0.8780835596, 0.8829043049, 0.8875803529, 0.8921208349, + 0.8965340237, 0.9008274393, 0.9050079382, 0.9090817905, + 0.9130547454, 0.9169320882, 0.9207186893, 0.9244190474, + 0.9280373261, 0.9315773876, 0.9350428208, 0.9384369673, + 0.9417629433, 0.9450236603, 0.9482218422, 0.9513600421, + 0.9544406555, 0.9574659338, 0.9604379957, 0.9633588374, + 0.9662303420, 0.9690542879, 0.9718323569, 0.9745661408, + 0.9772571477, 0.9799068082, 0.9825164805, 0.9850874551, + 0.9876209597, 0.9901181627, 0.9925801775, 0.9950080658, + 0.9974028405, 0.9997654692, 1.0020968764, 1.0043979464, + 1.0066695255, 1.0089124239, 1.0111274185, 1.0133152537 }, + { 0.6772002277, 0.6934309881, 0.7080464599, 0.7213643301, + 0.7336148970, 0.7449707526, 0.7555647772, 0.7655015856, + 0.7748651015, 0.7837237382, 0.7921340426, 0.8001433220, + 0.8077915768, 0.8151129499, 0.8221368310, 0.8288887107, + 0.8353908496, 0.8416628090, 0.8477218755, 0.8535834053, + 0.8592611049, 0.8647672624, 0.8701129393, 0.8753081305, + 0.8803618988, 0.8852824894, 0.8900774261, 0.8947535945, + 0.8993173131, 0.9037743949, 0.9081302004, 0.9123896841, + 0.9165574352, 0.9206377129, 0.9246344779, 0.9285514202, + 0.9323919830, 0.9361593853, 0.9398566405, 0.9434865742, + 0.9470518396, 0.9505549317, 0.9539981992, 0.9573838564, + 0.9607139933, 0.9639905847, 0.9672154989, 0.9703905051, + 0.9735172803, 0.9765974162, 0.9796324243, 0.9826237418, + 0.9855727362, 0.9884807098, 0.9913489039, 0.9941785028, + 0.9969706369, 0.9997263861, 1.0024467831, 1.0051328157, + 1.0077854297, 1.0104055314, 1.0129939892, 1.0155516364 }, + { 0.6405216642, 0.6580962612, 0.6739722363, 0.6884795488, + 0.7018580813, 0.7142880714, 0.7259086094, 0.7368294324, + 0.7471387455, 0.7569085832, 0.7661985859, 0.7750587283, + 0.7835313288, 0.7916525600, 0.7994535998, 0.8069615243, + 0.8142000068, 0.8211898738, 0.8279495504, 0.8344954211, + 0.8408421252, 0.8470027997, 0.8529892811, 0.8588122744, + 0.8644814947, 0.8700057878, 0.8753932324, 0.8806512276, + 0.8857865684, 0.8908055105, 0.8957138271, 0.9005168576, + 0.9052195513, 0.9098265046, 0.9143419945, 0.9187700080, + 0.9231142680, 0.9273782568, 0.9315652364, 0.9356782672, + 0.9397202245, 0.9436938133, 0.9476015819, 0.9514459336, + 0.9552291382, 0.9589533414, 0.9626205741, 0.9662327603, + 0.9697917251, 0.9732992008, 0.9767568340, 0.9801661903, + 0.9835287605, 0.9868459649, 0.9901191578, 0.9933496315, + 0.9965386205, 0.9996873045, 1.0027968119, 1.0058682226, + 1.0089025710, 1.0119008485, 1.0148640056, 1.0177929548 }, + { 0.6058296875, 0.6245620637, 0.6415378101, 0.6570938835, + 0.6714759586, 0.6848691001, 0.6974164561, 0.7092312055, + 0.7204044988, 0.7310109103, 0.7411122884, 0.7507605397, + 0.7599996842, 0.7688674015, 0.7773962122, 0.7856143935, + 0.7935466990, 0.8012149303, 0.8086383963, 0.8158342858, + 0.8228179717, 0.8296032631, 0.8362026133, 0.8426272954, + 0.8488875492, 0.8549927056, 0.8609512936, 0.8667711307, + 0.8724594015, 0.8780227256, 0.8834672161, 0.8887985309, + 0.8940219180, 0.8991422543, 0.9041640810, 0.9090916337, + 0.9139288704, 0.9186794948, 0.9233469789, 0.9279345818, + 0.9324453671, 0.9368822185, 0.9412478543, 0.9455448393, + 0.9497755970, 0.9539424198, 0.9580474782, 0.9620928299, + 0.9660804271, 0.9700121244, 0.9738896845, 0.9777147851, + 0.9814890239, 0.9852139236, 0.9888909370, 0.9925214512, + 0.9961067913, 0.9996482244, 1.0031469629, 1.0066041676, + 1.0100209506, 1.0133983785, 1.0167374742, 1.0200392198 }, + { 0.5730166999, 0.5927366473, 0.6106642672, 0.6271389942, + 0.6424090212, 0.6566617910, 0.6700426292, 0.6826666808, + 0.6946268614, 0.7059993279, 0.7168473476, 0.7272241023, + 0.7371747608, 0.7467380401, 0.7559474006, 0.7648319736, + 0.7734172908, 0.7817258650, 0.7897776570, 0.7975904541, + 0.8051801811, 0.8125611560, 0.8197463039, 0.8267473349, + 0.8335748949, 0.8402386937, 0.8467476129, 0.8531098003, + 0.8593327495, 0.8654233698, 0.8713880464, 0.8772326935, + 0.8829628002, 0.8885834710, 0.8940994619, 0.8995152120, + 0.9048348715, 0.9100623268, 0.9152012229, 0.9202549833, + 0.9252268281, 0.9301197899, 0.9349367288, 0.9396803449, + 0.9443531909, 0.9489576823, 0.9534961076, 0.9579706374, + 0.9623833320, 0.9667361492, 0.9710309512, 0.9752695109, + 0.9794535174, 0.9835845813, 0.9876642399, 0.9916939614, + 0.9956751493, 0.9996091459, 1.0034972362, 1.0073406510, + 1.0111405700, 1.0148981248, 1.0186144013, 1.0222904422 }, + { 0.5419809316, 0.5625329386, 0.5812764912, 0.5985496562, + 0.6146003370, 0.6296162401, 0.6437432340, 0.6570971404, + 0.6697716039, 0.6818435182, 0.6933768712, 0.7044255353, + 0.7150353340, 0.7252456009, 0.7350903742, 0.7445993259, + 0.7537984929, 0.7627108595, 0.7713568269, 0.7797545943, + 0.7879204712, 0.7958691361, 0.8036138516, 0.8111666444, + 0.8185384580, 0.8257392814, 0.8327782597, 0.8396637886, + 0.8464035955, 0.8530048108, 0.8594740287, 0.8658173611, + 0.8720404845, 0.8781486812, 0.8841468762, 0.8900396688, + 0.8958313620, 0.9015259874, 0.9071273286, 0.9126389413, + 0.9180641715, 0.9234061727, 0.9286679198, 0.9338522236, + 0.9389617420, 0.9439989920, 0.9489663591, 0.9538661069, + 0.9587003852, 0.9634712378, 0.9681806094, 0.9728303524, + 0.9774222323, 0.9819579336, 0.9864390644, 0.9908671615, + 0.9952436943, 0.9995700689, 1.0038476318, 1.0080776733, + 1.0122614305, 1.0164000906, 1.0204947932, 1.0245466331 }, + { 0.5126261246, 0.5338683013, 0.5533029807, 0.5712636181, + 0.5879954388, 0.6036845987, 0.6184760989, 0.6324853169, + 0.6458057215, 0.6585142011, 0.6706748475, 0.6823417062, + 0.6935608163, 0.7043717519, 0.7148088052, 0.7249019070, + 0.7346773529, 0.7441583823, 0.7533656456, 0.7623175831, + 0.7710307376, 0.7795200117, 0.7877988829, 0.7958795841, + 0.8037732557, 0.8114900754, 0.8190393682, 0.8264297018, + 0.8336689680, 0.8407644543, 0.8477229049, 0.8545505751, + 0.8612532786, 0.8678364291, 0.8743050768, 0.8806639416, + 0.8869174414, 0.8930697184, 0.8991246621, 0.9050859297, + 0.9109569648, 0.9167410144, 0.9224411436, 0.9280602496, + 0.9336010737, 0.9390662129, 0.9444581300, 0.9497791628, + 0.9550315328, 0.9602173528, 0.9653386345, 0.9703972943, + 0.9753951600, 0.9803339761, 0.9852154088, 0.9900410510, + 0.9948124263, 0.9995309934, 1.0041981497, 1.0088152348, + 1.0133835335, 1.0179042791, 1.0223786564, 1.0268078035 }, +}; + +#endif /* AVCODEC_WMAVOICE_DATA_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/wmv2.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/wmv2.h index 4c7be44bfd..c69c9f48ee 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/wmv2.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/wmv2.h @@ -50,7 +50,7 @@ typedef struct Wmv2Context{ int hshift; ScanTable abt_scantable[2]; - DECLARE_ALIGNED_16(DCTELEM, abt_block2[6][64]); + DECLARE_ALIGNED(16, DCTELEM, abt_block2)[6][64]; }Wmv2Context; void ff_wmv2_common_init(Wmv2Context * w); diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/wmv2dec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/wmv2dec.c index b14b5143aa..a9bb80cae4 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/wmv2dec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/wmv2dec.c @@ -21,6 +21,7 @@ #include "avcodec.h" #include "dsputil.h" #include "mpegvideo.h" +#include "h263.h" #include "mathops.h" #include "msmpeg4.h" #include "msmpeg4data.h" @@ -465,7 +466,7 @@ static av_cold int wmv2_decode_init(AVCodecContext *avctx){ avctx->idct_algo=FF_IDCT_WMV2; } - if(ff_h263_decode_init(avctx) < 0) + if(ff_msmpeg4_decode_init(avctx) < 0) return -1; ff_wmv2_common_init(w); @@ -485,7 +486,7 @@ static av_cold int wmv2_decode_end(AVCodecContext *avctx) AVCodec wmv2_decoder = { "wmv2", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_WMV2, sizeof(Wmv2Context), wmv2_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/wmv2enc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/wmv2enc.c index c17a97305c..7416f85233 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/wmv2enc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/wmv2enc.c @@ -23,6 +23,7 @@ #include "mpegvideo.h" #include "msmpeg4.h" #include "msmpeg4data.h" +#include "h263.h" #include "wmv2.h" @@ -212,12 +213,12 @@ void ff_wmv2_encode_mb(MpegEncContext * s, AVCodec wmv2_encoder = { "wmv2", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_WMV2, sizeof(Wmv2Context), wmv2_encode_init, MPV_encode_picture, MPV_encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, .long_name= NULL_IF_CONFIG_SMALL("Windows Media Video 8"), }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/wnv1.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/wnv1.c index aec474f2de..56634d10ac 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/wnv1.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/wnv1.c @@ -20,12 +20,13 @@ */ /** - * @file libavcodec/wnv1.c + * @file * Winnov WNV1 codec. */ #include "avcodec.h" #include "get_bits.h" +#include "libavutil/common.h" typedef struct WNV1Context{ @@ -51,7 +52,7 @@ static inline int wnv1_get_code(WNV1Context *w, int base_value) int v = get_vlc2(&w->gb, code_vlc.table, CODE_VLC_BITS, 1); if(v==15) - return ff_reverse[ get_bits(&w->gb, 8 - w->shift) ]; + return av_reverse[ get_bits(&w->gb, 8 - w->shift) ]; else return base_value + ((v - 7)<shift); } @@ -87,7 +88,7 @@ static int decode_frame(AVCodecContext *avctx, p->key_frame = 1; for(i=8; igb, rbuf+8, (buf_size-8)*8); if (buf[2] >> 4 == 6) @@ -143,14 +144,24 @@ static av_cold int decode_init(AVCodecContext *avctx){ return 0; } +static av_cold int decode_end(AVCodecContext *avctx){ + WNV1Context * const l = avctx->priv_data; + AVFrame *pic = &l->pic; + + if (pic->data[0]) + avctx->release_buffer(avctx, pic); + + return 0; +} + AVCodec wnv1_decoder = { "wnv1", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_WNV1, sizeof(WNV1Context), decode_init, NULL, - NULL, + decode_end, decode_frame, CODEC_CAP_DR1, .long_name = NULL_IF_CONFIG_SMALL("Winnov WNV1"), diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/ws-snd1.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/ws-snd1.c index 85e04f55d4..a383673db7 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/ws-snd1.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/ws-snd1.c @@ -23,7 +23,7 @@ #include "avcodec.h" /** - * @file libavcodec/ws-snd1.c + * @file * Westwood SNDx codecs. * * Reference documents about VQA format and its audio codecs @@ -147,7 +147,7 @@ static int ws_snd_decode_frame(AVCodecContext *avctx, AVCodec ws_snd1_decoder = { "ws_snd1", - CODEC_TYPE_AUDIO, + AVMEDIA_TYPE_AUDIO, CODEC_ID_WESTWOOD_SND1, 0, ws_snd_decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/Jamfile b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/Jamfile index 072a392d39..5520a055e5 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/Jamfile +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/Jamfile @@ -21,11 +21,14 @@ if $(HAIKU_FFMPEG_USE_MMX) = 1 { dsputil_mmx.c dsputilenc_mmx.c fdct_mmx.c + fft.c idct_mmx_xvid.c + lpc_mmx.c motion_est_mmx.c mpegvideo_mmx.c rv40dsp_mmx.c simple_idct_mmx.c + snowdsp_mmx.c vc1dsp_mmx.c vp3dsp_mmx.c vp6dsp_mmx.c diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/cavsdsp_mmx.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/cavsdsp_mmx.c index 256490c4a6..638eaf7ce8 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/cavsdsp_mmx.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/cavsdsp_mmx.c @@ -113,10 +113,10 @@ static inline void cavs_idct8_1d(int16_t *block, uint64_t bias) static void cavs_idct8_add_mmx(uint8_t *dst, int16_t *block, int stride) { int i; - DECLARE_ALIGNED_8(int16_t, b2[64]); + DECLARE_ALIGNED(8, int16_t, b2)[64]; for(i=0; i<2; i++){ - DECLARE_ALIGNED_8(uint64_t, tmp); + DECLARE_ALIGNED(8, uint64_t, tmp); cavs_idct8_1d(block+4*i, ff_pw_4); @@ -182,12 +182,12 @@ static void cavs_idct8_add_mmx(uint8_t *dst, int16_t *block, int stride) ****************************************************************************/ /* vertical filter [-1 -2 96 42 -7 0] */ -#define QPEL_CAVSV1(A,B,C,D,E,F,OP) \ +#define QPEL_CAVSV1(A,B,C,D,E,F,OP,MUL2) \ "movd (%0), "#F" \n\t"\ "movq "#C", %%mm6 \n\t"\ "pmullw %5, %%mm6 \n\t"\ "movq "#D", %%mm7 \n\t"\ - "pmullw %6, %%mm7 \n\t"\ + "pmullw "MANGLE(MUL2)", %%mm7\n\t"\ "psllw $3, "#E" \n\t"\ "psubw "#E", %%mm6 \n\t"\ "psraw $3, "#E" \n\t"\ @@ -207,7 +207,7 @@ static void cavs_idct8_add_mmx(uint8_t *dst, int16_t *block, int stride) "add %3, %1 \n\t" /* vertical filter [ 0 -1 5 5 -1 0] */ -#define QPEL_CAVSV2(A,B,C,D,E,F,OP) \ +#define QPEL_CAVSV2(A,B,C,D,E,F,OP,MUL2) \ "movd (%0), "#F" \n\t"\ "movq "#C", %%mm6 \n\t"\ "paddw "#D", %%mm6 \n\t"\ @@ -223,10 +223,10 @@ static void cavs_idct8_add_mmx(uint8_t *dst, int16_t *block, int stride) "add %3, %1 \n\t" /* vertical filter [ 0 -7 42 96 -2 -1] */ -#define QPEL_CAVSV3(A,B,C,D,E,F,OP) \ +#define QPEL_CAVSV3(A,B,C,D,E,F,OP,MUL2) \ "movd (%0), "#F" \n\t"\ "movq "#C", %%mm6 \n\t"\ - "pmullw %6, %%mm6 \n\t"\ + "pmullw "MANGLE(MUL2)", %%mm6\n\t"\ "movq "#D", %%mm7 \n\t"\ "pmullw %5, %%mm7 \n\t"\ "psllw $3, "#B" \n\t"\ @@ -270,32 +270,32 @@ static void cavs_idct8_add_mmx(uint8_t *dst, int16_t *block, int stride) "punpcklbw %%mm7, %%mm2 \n\t"\ "punpcklbw %%mm7, %%mm3 \n\t"\ "punpcklbw %%mm7, %%mm4 \n\t"\ - VOP(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, OP)\ - VOP(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, OP)\ - VOP(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, OP)\ - VOP(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, OP)\ - VOP(%%mm4, %%mm5, %%mm0, %%mm1, %%mm2, %%mm3, OP)\ - VOP(%%mm5, %%mm0, %%mm1, %%mm2, %%mm3, %%mm4, OP)\ - VOP(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, OP)\ - VOP(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, OP)\ + VOP(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, OP, MUL2)\ + VOP(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, OP, MUL2)\ + VOP(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, OP, MUL2)\ + VOP(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, OP, MUL2)\ + VOP(%%mm4, %%mm5, %%mm0, %%mm1, %%mm2, %%mm3, OP, MUL2)\ + VOP(%%mm5, %%mm0, %%mm1, %%mm2, %%mm3, %%mm4, OP, MUL2)\ + VOP(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, OP, MUL2)\ + VOP(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, OP, MUL2)\ \ : "+a"(src), "+c"(dst)\ - : "S"((x86_reg)srcStride), "r"((x86_reg)dstStride), "m"(ADD), "m"(MUL1), "m"(MUL2)\ + : "S"((x86_reg)srcStride), "r"((x86_reg)dstStride), "m"(ADD), "m"(MUL1)\ : "memory"\ );\ if(h==16){\ __asm__ volatile(\ - VOP(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, OP)\ - VOP(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, OP)\ - VOP(%%mm4, %%mm5, %%mm0, %%mm1, %%mm2, %%mm3, OP)\ - VOP(%%mm5, %%mm0, %%mm1, %%mm2, %%mm3, %%mm4, OP)\ - VOP(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, OP)\ - VOP(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, OP)\ - VOP(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, OP)\ - VOP(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, OP)\ + VOP(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, OP, MUL2)\ + VOP(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, OP, MUL2)\ + VOP(%%mm4, %%mm5, %%mm0, %%mm1, %%mm2, %%mm3, OP, MUL2)\ + VOP(%%mm5, %%mm0, %%mm1, %%mm2, %%mm3, %%mm4, OP, MUL2)\ + VOP(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, OP, MUL2)\ + VOP(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, OP, MUL2)\ + VOP(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, OP, MUL2)\ + VOP(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, OP, MUL2)\ \ : "+a"(src), "+c"(dst)\ - : "S"((x86_reg)srcStride), "r"((x86_reg)dstStride), "m"(ADD), "m"(MUL1), "m"(MUL2)\ + : "S"((x86_reg)srcStride), "r"((x86_reg)dstStride), "m"(ADD), "m"(MUL1)\ : "memory"\ );\ }\ @@ -423,7 +423,6 @@ static void ff_ ## OPNAME ## cavs_qpel ## SIZE ## _mc03_ ## MMX(uint8_t *dst, ui "pavgb " #temp ", " #a " \n\t"\ "mov" #size " " #a ", " #b " \n\t" -#if __GNUC__ >= 3 QPEL_CAVS(put_, PUT_OP, 3dnow) QPEL_CAVS(avg_, AVG_3DNOW_OP, 3dnow) QPEL_CAVS(put_, PUT_OP, mmx2) @@ -438,11 +437,6 @@ CAVS_MC(put_, 16,mmx2) CAVS_MC(avg_, 8, mmx2) CAVS_MC(avg_, 16,mmx2) -void ff_put_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride); -void ff_avg_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride); -void ff_put_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride); -void ff_avg_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride); - void ff_cavsdsp_init_mmx2(DSPContext* c, AVCodecContext *avctx) { #define dspfunc(PFX, IDX, NUM) \ c->PFX ## _pixels_tab[IDX][ 0] = ff_ ## PFX ## NUM ## _mc00_mmx2; \ @@ -474,5 +468,3 @@ void ff_cavsdsp_init_3dnow(DSPContext* c, AVCodecContext *avctx) { #undef dspfunc c->cavs_idct8_add = cavs_idct8_add_mmx; } - -#endif diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/dsputil_h264_template_mmx.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/dsputil_h264_template_mmx.c index 43f4393098..bc2379e1d0 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/dsputil_h264_template_mmx.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/dsputil_h264_template_mmx.c @@ -27,8 +27,8 @@ */ static void H264_CHROMA_MC8_TMPL(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y, const uint64_t *rnd_reg) { - DECLARE_ALIGNED_8(uint64_t, AA); - DECLARE_ALIGNED_8(uint64_t, DD); + DECLARE_ALIGNED(8, uint64_t, AA); + DECLARE_ALIGNED(8, uint64_t, DD); int i; if(y==0 && x==0) { diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/dsputil_mmx.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/dsputil_mmx.c index 4df9393c3a..cc2f881303 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/dsputil_mmx.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/dsputil_mmx.c @@ -24,7 +24,7 @@ #include "libavutil/x86_cpu.h" #include "libavcodec/dsputil.h" -#include "libavcodec/h263.h" +#include "libavcodec/h264dsp.h" #include "libavcodec/mpegvideo.h" #include "libavcodec/simple_idct.h" #include "dsputil_mmx.h" @@ -40,38 +40,38 @@ int mm_flags; /* multimedia extension flags */ /* pixel operations */ -DECLARE_ALIGNED_8 (const uint64_t, ff_bone) = 0x0101010101010101ULL; -DECLARE_ALIGNED_8 (const uint64_t, ff_wtwo) = 0x0002000200020002ULL; +DECLARE_ALIGNED(8, const uint64_t, ff_bone) = 0x0101010101010101ULL; +DECLARE_ALIGNED(8, const uint64_t, ff_wtwo) = 0x0002000200020002ULL; -DECLARE_ALIGNED_16(const uint64_t, ff_pdw_80000000[2]) = +DECLARE_ALIGNED(16, const uint64_t, ff_pdw_80000000)[2] = {0x8000000080000000ULL, 0x8000000080000000ULL}; -DECLARE_ALIGNED_8 (const uint64_t, ff_pw_3 ) = 0x0003000300030003ULL; -DECLARE_ALIGNED_8 (const uint64_t, ff_pw_4 ) = 0x0004000400040004ULL; -DECLARE_ALIGNED_16(const xmm_reg, ff_pw_5 ) = {0x0005000500050005ULL, 0x0005000500050005ULL}; -DECLARE_ALIGNED_16(const xmm_reg, ff_pw_8 ) = {0x0008000800080008ULL, 0x0008000800080008ULL}; -DECLARE_ALIGNED_8 (const uint64_t, ff_pw_15 ) = 0x000F000F000F000FULL; -DECLARE_ALIGNED_16(const xmm_reg, ff_pw_16 ) = {0x0010001000100010ULL, 0x0010001000100010ULL}; -DECLARE_ALIGNED_8 (const uint64_t, ff_pw_20 ) = 0x0014001400140014ULL; -DECLARE_ALIGNED_16(const xmm_reg, ff_pw_28 ) = {0x001C001C001C001CULL, 0x001C001C001C001CULL}; -DECLARE_ALIGNED_16(const xmm_reg, ff_pw_32 ) = {0x0020002000200020ULL, 0x0020002000200020ULL}; -DECLARE_ALIGNED_8 (const uint64_t, ff_pw_42 ) = 0x002A002A002A002AULL; -DECLARE_ALIGNED_16(const xmm_reg, ff_pw_64 ) = {0x0040004000400040ULL, 0x0040004000400040ULL}; -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(8, const uint64_t, ff_pw_3 ) = 0x0003000300030003ULL; +DECLARE_ALIGNED(8, const uint64_t, ff_pw_4 ) = 0x0004000400040004ULL; +DECLARE_ALIGNED(16, const xmm_reg, ff_pw_5 ) = {0x0005000500050005ULL, 0x0005000500050005ULL}; +DECLARE_ALIGNED(16, const xmm_reg, ff_pw_8 ) = {0x0008000800080008ULL, 0x0008000800080008ULL}; +DECLARE_ALIGNED(8, const uint64_t, ff_pw_15 ) = 0x000F000F000F000FULL; +DECLARE_ALIGNED(16, const xmm_reg, ff_pw_16 ) = {0x0010001000100010ULL, 0x0010001000100010ULL}; +DECLARE_ALIGNED(8, const uint64_t, ff_pw_20 ) = 0x0014001400140014ULL; +DECLARE_ALIGNED(16, const xmm_reg, ff_pw_28 ) = {0x001C001C001C001CULL, 0x001C001C001C001CULL}; +DECLARE_ALIGNED(16, const xmm_reg, ff_pw_32 ) = {0x0020002000200020ULL, 0x0020002000200020ULL}; +DECLARE_ALIGNED(8, const uint64_t, ff_pw_42 ) = 0x002A002A002A002AULL; +DECLARE_ALIGNED(16, const xmm_reg, ff_pw_64 ) = {0x0040004000400040ULL, 0x0040004000400040ULL}; +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_8 (const uint64_t, ff_pb_1 ) = 0x0101010101010101ULL; -DECLARE_ALIGNED_8 (const uint64_t, ff_pb_3 ) = 0x0303030303030303ULL; -DECLARE_ALIGNED_8 (const uint64_t, ff_pb_7 ) = 0x0707070707070707ULL; -DECLARE_ALIGNED_8 (const uint64_t, ff_pb_1F ) = 0x1F1F1F1F1F1F1F1FULL; -DECLARE_ALIGNED_8 (const uint64_t, ff_pb_3F ) = 0x3F3F3F3F3F3F3F3FULL; -DECLARE_ALIGNED_8 (const uint64_t, ff_pb_81 ) = 0x8181818181818181ULL; -DECLARE_ALIGNED_8 (const uint64_t, ff_pb_A1 ) = 0xA1A1A1A1A1A1A1A1ULL; -DECLARE_ALIGNED_8 (const uint64_t, ff_pb_FC ) = 0xFCFCFCFCFCFCFCFCULL; +DECLARE_ALIGNED(8, const uint64_t, ff_pb_1 ) = 0x0101010101010101ULL; +DECLARE_ALIGNED(8, const uint64_t, ff_pb_3 ) = 0x0303030303030303ULL; +DECLARE_ALIGNED(8, const uint64_t, ff_pb_7 ) = 0x0707070707070707ULL; +DECLARE_ALIGNED(8, const uint64_t, ff_pb_1F ) = 0x1F1F1F1F1F1F1F1FULL; +DECLARE_ALIGNED(8, const uint64_t, ff_pb_3F ) = 0x3F3F3F3F3F3F3F3FULL; +DECLARE_ALIGNED(8, const uint64_t, ff_pb_81 ) = 0x8181818181818181ULL; +DECLARE_ALIGNED(8, const uint64_t, ff_pb_A1 ) = 0xA1A1A1A1A1A1A1A1ULL; +DECLARE_ALIGNED(8, const uint64_t, ff_pb_FC ) = 0xFCFCFCFCFCFCFCFCULL; -DECLARE_ALIGNED_16(const double, ff_pd_1[2]) = { 1.0, 1.0 }; -DECLARE_ALIGNED_16(const double, ff_pd_2[2]) = { 2.0, 2.0 }; +DECLARE_ALIGNED(16, const double, ff_pd_1)[2] = { 1.0, 1.0 }; +DECLARE_ALIGNED(16, const double, ff_pd_2)[2] = { 2.0, 2.0 }; #define JUMPALIGN() __asm__ volatile (ASMALIGN(3)::) #define MOVQ_ZERO(regd) __asm__ volatile ("pxor %%" #regd ", %%" #regd ::) @@ -278,7 +278,7 @@ void put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size :"memory"); } -DECLARE_ASM_CONST(8, uint8_t, ff_vector128[8]) = +DECLARE_ASM_CONST(8, uint8_t, ff_vector128)[8] = { 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 }; #define put_signed_pixels_clamped_mmx_half(off) \ @@ -597,7 +597,7 @@ static void add_bytes_l2_mmx(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){ } #if HAVE_7REGS && HAVE_TEN_OPERANDS -static void add_hfyu_median_prediction_cmov(uint8_t *dst, uint8_t *top, uint8_t *diff, int w, int *left, int *left_top) { +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; x86_reg x; int l = *left & 0xff; @@ -703,7 +703,7 @@ static void add_hfyu_median_prediction_cmov(uint8_t *dst, uint8_t *top, uint8_t "paddb %%mm1, %%mm6 \n\t" static void h263_v_loop_filter_mmx(uint8_t *src, int stride, int qscale){ - if(CONFIG_ANY_H263) { + if(CONFIG_H263_DECODER || CONFIG_H263_ENCODER) { const int strength= ff_h263_loop_filter_strength[qscale]; __asm__ volatile( @@ -753,9 +753,9 @@ static inline void transpose4x4(uint8_t *dst, uint8_t *src, int dst_stride, int } static void h263_h_loop_filter_mmx(uint8_t *src, int stride, int qscale){ - if(CONFIG_ANY_H263) { + if(CONFIG_H263_DECODER || CONFIG_H263_ENCODER) { const int strength= ff_h263_loop_filter_strength[qscale]; - DECLARE_ALIGNED(8, uint64_t, temp[4]); + DECLARE_ALIGNED(8, uint64_t, temp)[4]; uint8_t *btemp= (uint8_t*)temp; src -= 2; @@ -1685,7 +1685,6 @@ QPEL_2TAP(avg_, 8, 3dnow) static void just_return(void) { return; } #endif -#if __GNUC__ >= 3 static void gmc_mmx(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy, int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height){ const int w = 8; @@ -1803,7 +1802,6 @@ static void gmc_mmx(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int o src += 4-h*stride; } } -#endif // #if __GNUC__ >= 3 #define PREFETCH(name, op) \ static void name(void *mem, int stride, int h){\ @@ -1821,9 +1819,6 @@ PREFETCH(prefetch_3dnow, prefetch) #include "rv40dsp_mmx.c" /* CAVS specific */ -void ff_cavsdsp_init_mmx2(DSPContext* c, AVCodecContext *avctx); -void ff_cavsdsp_init_3dnow(DSPContext* c, AVCodecContext *avctx); - void ff_put_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) { put_pixels8_mmx(dst, src, stride, 8); } @@ -1838,8 +1833,6 @@ void ff_avg_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) { } /* VC1 specific */ -void ff_vc1dsp_init_mmx(DSPContext* dsp, AVCodecContext *avctx); - void ff_put_vc1_mspel_mc00_mmx(uint8_t *dst, const uint8_t *src, int stride, int rnd) { put_pixels8_mmx(dst, src, stride, 8); } @@ -1847,10 +1840,6 @@ void ff_avg_vc1_mspel_mc00_mmx2(uint8_t *dst, const uint8_t *src, int stride, in avg_pixels8_mmx2(dst, src, stride, 8); } -/* external functions, from idct_mmx.c */ -void ff_mmx_idct(DCTELEM *block); -void ff_mmxext_idct(DCTELEM *block); - /* XXX: those functions should be suppressed ASAP when all IDCTs are converted */ #if CONFIG_GPL @@ -2029,7 +2018,7 @@ static void ac3_downmix_sse(float (*samples)[256], float (*matrix)[2], int out_c } else if(in_ch == 5 && out_ch == 1 && matrix_cmp[0][0]==matrix_cmp[2][0] && matrix_cmp[3][0]==matrix_cmp[4][0]) { MIX5(IF1,IF0); } else { - DECLARE_ALIGNED_16(float, matrix_simd[in_ch][2][4]); + DECLARE_ALIGNED(16, float, matrix_simd)[in_ch][2][4]; j = 2*in_ch*sizeof(float); __asm__ volatile( "1: \n" @@ -2127,110 +2116,46 @@ static void vector_fmul_reverse_sse(float *dst, const float *src0, const float * ); } -static void vector_fmul_add_add_3dnow(float *dst, const float *src0, const float *src1, - const float *src2, int src3, int len, int step){ +static void vector_fmul_add_3dnow(float *dst, const float *src0, const float *src1, + const float *src2, int len){ x86_reg i = (len-4)*4; - if(step == 2 && src3 == 0){ - dst += (len-4)*2; - __asm__ volatile( - "1: \n\t" - "movq (%2,%0), %%mm0 \n\t" - "movq 8(%2,%0), %%mm1 \n\t" - "pfmul (%3,%0), %%mm0 \n\t" - "pfmul 8(%3,%0), %%mm1 \n\t" - "pfadd (%4,%0), %%mm0 \n\t" - "pfadd 8(%4,%0), %%mm1 \n\t" - "movd %%mm0, (%1) \n\t" - "movd %%mm1, 16(%1) \n\t" - "psrlq $32, %%mm0 \n\t" - "psrlq $32, %%mm1 \n\t" - "movd %%mm0, 8(%1) \n\t" - "movd %%mm1, 24(%1) \n\t" - "sub $32, %1 \n\t" - "sub $16, %0 \n\t" - "jge 1b \n\t" - :"+r"(i), "+r"(dst) - :"r"(src0), "r"(src1), "r"(src2) - :"memory" - ); - } - else if(step == 1 && src3 == 0){ - __asm__ volatile( - "1: \n\t" - "movq (%2,%0), %%mm0 \n\t" - "movq 8(%2,%0), %%mm1 \n\t" - "pfmul (%3,%0), %%mm0 \n\t" - "pfmul 8(%3,%0), %%mm1 \n\t" - "pfadd (%4,%0), %%mm0 \n\t" - "pfadd 8(%4,%0), %%mm1 \n\t" - "movq %%mm0, (%1,%0) \n\t" - "movq %%mm1, 8(%1,%0) \n\t" - "sub $16, %0 \n\t" - "jge 1b \n\t" - :"+r"(i) - :"r"(dst), "r"(src0), "r"(src1), "r"(src2) - :"memory" - ); - } - else - ff_vector_fmul_add_add_c(dst, src0, src1, src2, src3, len, step); + __asm__ volatile( + "1: \n\t" + "movq (%2,%0), %%mm0 \n\t" + "movq 8(%2,%0), %%mm1 \n\t" + "pfmul (%3,%0), %%mm0 \n\t" + "pfmul 8(%3,%0), %%mm1 \n\t" + "pfadd (%4,%0), %%mm0 \n\t" + "pfadd 8(%4,%0), %%mm1 \n\t" + "movq %%mm0, (%1,%0) \n\t" + "movq %%mm1, 8(%1,%0) \n\t" + "sub $16, %0 \n\t" + "jge 1b \n\t" + :"+r"(i) + :"r"(dst), "r"(src0), "r"(src1), "r"(src2) + :"memory" + ); __asm__ volatile("femms"); } -static void vector_fmul_add_add_sse(float *dst, const float *src0, const float *src1, - const float *src2, int src3, int len, int step){ +static void vector_fmul_add_sse(float *dst, const float *src0, const float *src1, + const float *src2, int len){ x86_reg i = (len-8)*4; - if(step == 2 && src3 == 0){ - dst += (len-8)*2; - __asm__ volatile( - "1: \n\t" - "movaps (%2,%0), %%xmm0 \n\t" - "movaps 16(%2,%0), %%xmm1 \n\t" - "mulps (%3,%0), %%xmm0 \n\t" - "mulps 16(%3,%0), %%xmm1 \n\t" - "addps (%4,%0), %%xmm0 \n\t" - "addps 16(%4,%0), %%xmm1 \n\t" - "movss %%xmm0, (%1) \n\t" - "movss %%xmm1, 32(%1) \n\t" - "movhlps %%xmm0, %%xmm2 \n\t" - "movhlps %%xmm1, %%xmm3 \n\t" - "movss %%xmm2, 16(%1) \n\t" - "movss %%xmm3, 48(%1) \n\t" - "shufps $0xb1, %%xmm0, %%xmm0 \n\t" - "shufps $0xb1, %%xmm1, %%xmm1 \n\t" - "movss %%xmm0, 8(%1) \n\t" - "movss %%xmm1, 40(%1) \n\t" - "movhlps %%xmm0, %%xmm2 \n\t" - "movhlps %%xmm1, %%xmm3 \n\t" - "movss %%xmm2, 24(%1) \n\t" - "movss %%xmm3, 56(%1) \n\t" - "sub $64, %1 \n\t" - "sub $32, %0 \n\t" - "jge 1b \n\t" - :"+r"(i), "+r"(dst) - :"r"(src0), "r"(src1), "r"(src2) - :"memory" - ); - } - else if(step == 1 && src3 == 0){ - __asm__ volatile( - "1: \n\t" - "movaps (%2,%0), %%xmm0 \n\t" - "movaps 16(%2,%0), %%xmm1 \n\t" - "mulps (%3,%0), %%xmm0 \n\t" - "mulps 16(%3,%0), %%xmm1 \n\t" - "addps (%4,%0), %%xmm0 \n\t" - "addps 16(%4,%0), %%xmm1 \n\t" - "movaps %%xmm0, (%1,%0) \n\t" - "movaps %%xmm1, 16(%1,%0) \n\t" - "sub $32, %0 \n\t" - "jge 1b \n\t" - :"+r"(i) - :"r"(dst), "r"(src0), "r"(src1), "r"(src2) - :"memory" - ); - } - else - ff_vector_fmul_add_add_c(dst, src0, src1, src2, src3, len, step); + __asm__ volatile( + "1: \n\t" + "movaps (%2,%0), %%xmm0 \n\t" + "movaps 16(%2,%0), %%xmm1 \n\t" + "mulps (%3,%0), %%xmm0 \n\t" + "mulps 16(%3,%0), %%xmm1 \n\t" + "addps (%4,%0), %%xmm0 \n\t" + "addps 16(%4,%0), %%xmm1 \n\t" + "movaps %%xmm0, (%1,%0) \n\t" + "movaps %%xmm1, 16(%1,%0) \n\t" + "sub $32, %0 \n\t" + "jge 1b \n\t" + :"+r"(i) + :"r"(dst), "r"(src0), "r"(src1), "r"(src2) + :"memory" + ); } static void vector_fmul_window_3dnow2(float *dst, const float *src0, const float *src1, @@ -2348,6 +2273,40 @@ static void int32_to_float_fmul_scalar_sse2(float *dst, const int *src, float mu ); } +static void vector_clipf_sse(float *dst, const float *src, float min, float max, + int len) +{ + x86_reg i = (len-16)*4; + __asm__ volatile( + "movss %3, %%xmm4 \n" + "movss %4, %%xmm5 \n" + "shufps $0, %%xmm4, %%xmm4 \n" + "shufps $0, %%xmm5, %%xmm5 \n" + "1: \n\t" + "movaps (%2,%0), %%xmm0 \n\t" // 3/1 on intel + "movaps 16(%2,%0), %%xmm1 \n\t" + "movaps 32(%2,%0), %%xmm2 \n\t" + "movaps 48(%2,%0), %%xmm3 \n\t" + "maxps %%xmm4, %%xmm0 \n\t" + "maxps %%xmm4, %%xmm1 \n\t" + "maxps %%xmm4, %%xmm2 \n\t" + "maxps %%xmm4, %%xmm3 \n\t" + "minps %%xmm5, %%xmm0 \n\t" + "minps %%xmm5, %%xmm1 \n\t" + "minps %%xmm5, %%xmm2 \n\t" + "minps %%xmm5, %%xmm3 \n\t" + "movaps %%xmm0, (%1,%0) \n\t" + "movaps %%xmm1, 16(%1,%0) \n\t" + "movaps %%xmm2, 32(%1,%0) \n\t" + "movaps %%xmm3, 48(%1,%0) \n\t" + "sub $64, %0 \n\t" + "jge 1b \n\t" + :"+&r"(i) + :"r"(dst), "r"(src), "m"(min), "m"(max) + :"memory" + ); +} + 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 @@ -2412,25 +2371,31 @@ static void float_to_int16_sse2(int16_t *dst, const float *src, long len){ ); } -#if HAVE_YASM 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); -void ff_add_hfyu_median_prediction_mmx2(uint8_t *dst, uint8_t *top, uint8_t *diff, int w, int *left, int *left_top); +int32_t ff_scalarproduct_int16_mmx2(int16_t *v1, int16_t *v2, int order, int shift); +int32_t ff_scalarproduct_int16_sse2(int16_t *v1, int16_t *v2, int order, int shift); +int32_t ff_scalarproduct_and_madd_int16_mmx2(int16_t *v1, int16_t *v2, int16_t *v3, int order, int mul); +int32_t ff_scalarproduct_and_madd_int16_sse2(int16_t *v1, int16_t *v2, int16_t *v3, int order, int mul); +int32_t ff_scalarproduct_and_madd_int16_ssse3(int16_t *v1, int16_t *v2, int16_t *v3, int order, int mul); +void ff_add_hfyu_median_prediction_mmx2(uint8_t *dst, const uint8_t *top, const uint8_t *diff, int w, int *left, int *left_top); +int ff_add_hfyu_left_prediction_ssse3(uint8_t *dst, const uint8_t *src, int w, int left); +int ff_add_hfyu_left_prediction_sse4(uint8_t *dst, const uint8_t *src, int w, int left); void ff_x264_deblock_v_luma_sse2(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0); void ff_x264_deblock_h_luma_sse2(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0); -void ff_x264_deblock_v8_luma_intra_mmxext(uint8_t *pix, int stride, int alpha, int beta); void ff_x264_deblock_h_luma_intra_mmxext(uint8_t *pix, int stride, int alpha, int beta); -#if CONFIG_GPL && ARCH_X86_32 +void ff_x264_deblock_v_luma_intra_sse2(uint8_t *pix, int stride, int alpha, int beta); +void ff_x264_deblock_h_luma_intra_sse2(uint8_t *pix, int stride, int alpha, int beta); + +#if HAVE_YASM && ARCH_X86_32 +void ff_x264_deblock_v8_luma_intra_mmxext(uint8_t *pix, int stride, int alpha, int beta); static void ff_x264_deblock_v_luma_intra_mmxext(uint8_t *pix, int stride, int alpha, int beta) { ff_x264_deblock_v8_luma_intra_mmxext(pix+0, stride, alpha, beta); ff_x264_deblock_v8_luma_intra_mmxext(pix+8, stride, alpha, beta); } -#endif -void ff_x264_deblock_v_luma_intra_sse2(uint8_t *pix, int stride, int alpha, int beta); -void ff_x264_deblock_h_luma_intra_sse2(uint8_t *pix, int stride, int alpha, int beta); -#else +#elif !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) @@ -2440,7 +2405,7 @@ void ff_x264_deblock_h_luma_intra_sse2(uint8_t *pix, int stride, int alpha, int #define FLOAT_TO_INT16_INTERLEAVE(cpu, body) \ /* 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]);\ + DECLARE_ALIGNED(16, int16_t, tmp)[len];\ int i,j,c;\ for(c=0; cadd_pixels_clamped = add_pixels_clamped_mmx; c->clear_block = clear_block_mmx; c->clear_blocks = clear_blocks_mmx; - if (mm_flags & FF_MM_SSE){ + if ((mm_flags & FF_MM_SSE) && + !(CONFIG_MPEG_XVMC_DECODER && avctx->xvmc_acceleration > 1)){ + /* XvMCCreateBlocks() may not allocate 16-byte aligned blocks */ c->clear_block = clear_block_sse; c->clear_blocks = clear_blocks_sse; } @@ -2715,16 +2601,14 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx) SET_HPEL_FUNCS(avg, 1, 8, mmx); SET_HPEL_FUNCS(avg_no_rnd, 1, 8, mmx); -#if __GNUC__ >= 3 c->gmc= gmc_mmx; -#endif c->add_bytes= add_bytes_mmx; c->add_bytes_l2= add_bytes_l2_mmx; c->draw_edges = draw_edges_mmx; - if (CONFIG_ANY_H263) { + if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) { c->h263_v_loop_filter= h263_v_loop_filter_mmx; c->h263_h_loop_filter= h263_h_loop_filter_mmx; } @@ -2735,16 +2619,6 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx) c->put_rv40_chroma_pixels_tab[0]= put_rv40_chroma_mc8_mmx; c->put_rv40_chroma_pixels_tab[1]= put_rv40_chroma_mc4_mmx; - c->h264_idct_dc_add= - c->h264_idct_add= ff_h264_idct_add_mmx; - c->h264_idct8_dc_add= - c->h264_idct8_add= ff_h264_idct8_add_mmx; - - c->h264_idct_add16 = ff_h264_idct_add16_mmx; - c->h264_idct8_add4 = ff_h264_idct8_add4_mmx; - c->h264_idct_add8 = ff_h264_idct_add8_mmx; - c->h264_idct_add16intra= ff_h264_idct_add16intra_mmx; - if (CONFIG_VP6_DECODER) { c->vp6_filter_diag4 = ff_vp6_filter_diag4_mmx; } @@ -2766,13 +2640,6 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx) c->avg_pixels_tab[1][1] = avg_pixels8_x2_mmx2; c->avg_pixels_tab[1][2] = avg_pixels8_y2_mmx2; - c->h264_idct_dc_add= ff_h264_idct_dc_add_mmx2; - c->h264_idct8_dc_add= ff_h264_idct8_dc_add_mmx2; - c->h264_idct_add16 = ff_h264_idct_add16_mmx2; - c->h264_idct8_add4 = ff_h264_idct8_add4_mmx2; - c->h264_idct_add8 = ff_h264_idct_add8_mmx2; - c->h264_idct_add16intra= ff_h264_idct_add16intra_mmx2; - if(!(avctx->flags & CODEC_FLAG_BITEXACT)){ c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmx2; c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmx2; @@ -2786,6 +2653,9 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx) c->vp3_h_loop_filter= ff_vp3_h_loop_filter_mmx2; } } + if (CONFIG_VP3_DECODER) { + c->vp3_idct_dc_add = ff_vp3_idct_dc_add_mmx2; + } #define SET_QPEL_FUNCS(PFX, IDX, SIZE, CPU) \ c->PFX ## _pixels_tab[IDX][ 0] = PFX ## SIZE ## _mc00_ ## CPU; \ @@ -2833,33 +2703,6 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx) c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_mmx2; c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_mmx2; c->put_h264_chroma_pixels_tab[2]= put_h264_chroma_mc2_mmx2; - c->h264_v_loop_filter_luma= h264_v_loop_filter_luma_mmx2; - c->h264_h_loop_filter_luma= h264_h_loop_filter_luma_mmx2; - c->h264_v_loop_filter_chroma= h264_v_loop_filter_chroma_mmx2; - c->h264_h_loop_filter_chroma= h264_h_loop_filter_chroma_mmx2; - c->h264_v_loop_filter_chroma_intra= h264_v_loop_filter_chroma_intra_mmx2; - c->h264_h_loop_filter_chroma_intra= h264_h_loop_filter_chroma_intra_mmx2; -#if __GNUC__ >= 3 - c->h264_loop_filter_strength= h264_loop_filter_strength_mmx2; -#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; #if HAVE_YASM c->add_hfyu_median_prediction = ff_add_hfyu_median_prediction_mmx2; @@ -2939,16 +2782,11 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx) c->avg_h264_qpel_pixels_tab[1][x+y*4] = avg_h264_qpel8_mc##x##y##_##CPU; if((mm_flags & FF_MM_SSE2) && !(mm_flags & FF_MM_3DNOW)){ // these functions are slower than mmx on AMD, but faster on Intel -/* FIXME works in most codecs, but crashes svq1 due to unaligned chroma c->put_pixels_tab[0][0] = put_pixels16_sse2; c->avg_pixels_tab[0][0] = avg_pixels16_sse2; -*/ H264_QPEL_FUNCS(0, 0, sse2); } if(mm_flags & FF_MM_SSE2){ - c->h264_idct8_add = ff_h264_idct8_add_sse2; - c->h264_idct8_add4= ff_h264_idct8_add4_sse2; - H264_QPEL_FUNCS(0, 1, sse2); H264_QPEL_FUNCS(0, 2, sse2); H264_QPEL_FUNCS(0, 3, sse2); @@ -2987,45 +2825,11 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx) c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_ssse3; c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_ssse3; c->add_png_paeth_prediction= add_png_paeth_prediction_ssse3; - } +#if HAVE_YASM + c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_ssse3; + if (mm_flags & FF_MM_SSE4) // not really sse4, just slow on Conroe + c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_sse4; #endif - -#if CONFIG_GPL && HAVE_YASM - if (mm_flags & FF_MM_MMX2){ -#if ARCH_X86_32 - c->h264_v_loop_filter_luma_intra = ff_x264_deblock_v_luma_intra_mmxext; - c->h264_h_loop_filter_luma_intra = ff_x264_deblock_h_luma_intra_mmxext; -#endif - if( mm_flags&FF_MM_SSE2 ){ -#if ARCH_X86_64 || !defined(__ICC) || __ICC > 1110 - c->h264_v_loop_filter_luma = ff_x264_deblock_v_luma_sse2; - c->h264_h_loop_filter_luma = ff_x264_deblock_h_luma_sse2; - c->h264_v_loop_filter_luma_intra = ff_x264_deblock_v_luma_intra_sse2; - c->h264_h_loop_filter_luma_intra = ff_x264_deblock_h_luma_intra_sse2; -#endif - c->h264_idct_add16 = ff_h264_idct_add16_sse2; - c->h264_idct_add8 = ff_h264_idct_add8_sse2; - c->h264_idct_add16intra = ff_h264_idct_add16intra_sse2; - } - } -#endif - -#if CONFIG_SNOW_DECODER - if(mm_flags & FF_MM_SSE2 & 0){ - c->horizontal_compose97i = ff_snow_horizontal_compose97i_sse2; -#if HAVE_7REGS - c->vertical_compose97i = ff_snow_vertical_compose97i_sse2; -#endif - c->inner_add_yblock = ff_snow_inner_add_yblock_sse2; - } - else{ - if(mm_flags & FF_MM_MMX2){ - c->horizontal_compose97i = ff_snow_horizontal_compose97i_mmx; -#if HAVE_7REGS - c->vertical_compose97i = ff_snow_vertical_compose97i_mmx; -#endif - } - c->inner_add_yblock = ff_snow_inner_add_yblock_mmx; } #endif @@ -3044,27 +2848,40 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx) c->float_to_int16_interleave = float_to_int16_interleave_3dn2; } } + if(mm_flags & FF_MM_MMX2){ +#if HAVE_YASM + c->scalarproduct_int16 = ff_scalarproduct_int16_mmx2; + c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_mmx2; +#endif + } if(mm_flags & FF_MM_SSE){ c->vorbis_inverse_coupling = vorbis_inverse_coupling_sse; c->ac3_downmix = ac3_downmix_sse; c->vector_fmul = vector_fmul_sse; c->vector_fmul_reverse = vector_fmul_reverse_sse; - c->vector_fmul_add_add = vector_fmul_add_add_sse; + c->vector_fmul_add = vector_fmul_add_sse; c->vector_fmul_window = vector_fmul_window_sse; c->int32_to_float_fmul_scalar = int32_to_float_fmul_scalar_sse; + c->vector_clipf = vector_clipf_sse; c->float_to_int16 = float_to_int16_sse; c->float_to_int16_interleave = float_to_int16_interleave_sse; +#if HAVE_YASM + c->scalarproduct_float = ff_scalarproduct_float_sse; +#endif } if(mm_flags & FF_MM_3DNOW) - c->vector_fmul_add_add = vector_fmul_add_add_3dnow; // faster than sse + c->vector_fmul_add = vector_fmul_add_3dnow; // faster than sse if(mm_flags & FF_MM_SSE2){ c->int32_to_float_fmul_scalar = int32_to_float_fmul_scalar_sse2; c->float_to_int16 = float_to_int16_sse2; c->float_to_int16_interleave = float_to_int16_interleave_sse2; - c->add_int16 = add_int16_sse2; - c->sub_int16 = sub_int16_sse2; - c->scalarproduct_int16 = scalarproduct_int16_sse2; +#if HAVE_YASM + c->scalarproduct_int16 = ff_scalarproduct_int16_sse2; + c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_sse2; +#endif } + if((mm_flags & FF_MM_SSSE3) && !(mm_flags & (FF_MM_SSE42|FF_MM_3DNOW)) && HAVE_YASM) // cachesplit + c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_ssse3; } if (CONFIG_ENCODERS) @@ -3105,3 +2922,81 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx) //ff_idct = just_return; #endif } + +#if CONFIG_H264DSP +void ff_h264dsp_init_x86(H264DSPContext *c) +{ + mm_flags = mm_support(); + + if (mm_flags & FF_MM_MMX) { + c->h264_idct_dc_add= + c->h264_idct_add= ff_h264_idct_add_mmx; + c->h264_idct8_dc_add= + c->h264_idct8_add= ff_h264_idct8_add_mmx; + + c->h264_idct_add16 = ff_h264_idct_add16_mmx; + c->h264_idct8_add4 = ff_h264_idct8_add4_mmx; + c->h264_idct_add8 = ff_h264_idct_add8_mmx; + c->h264_idct_add16intra= ff_h264_idct_add16intra_mmx; + + if (mm_flags & FF_MM_MMX2) { + c->h264_idct_dc_add= ff_h264_idct_dc_add_mmx2; + c->h264_idct8_dc_add= ff_h264_idct8_dc_add_mmx2; + c->h264_idct_add16 = ff_h264_idct_add16_mmx2; + c->h264_idct8_add4 = ff_h264_idct8_add4_mmx2; + c->h264_idct_add8 = ff_h264_idct_add8_mmx2; + c->h264_idct_add16intra= ff_h264_idct_add16intra_mmx2; + + c->h264_v_loop_filter_luma= h264_v_loop_filter_luma_mmx2; + c->h264_h_loop_filter_luma= h264_h_loop_filter_luma_mmx2; + c->h264_v_loop_filter_chroma= h264_v_loop_filter_chroma_mmx2; + c->h264_h_loop_filter_chroma= h264_h_loop_filter_chroma_mmx2; + c->h264_v_loop_filter_chroma_intra= h264_v_loop_filter_chroma_intra_mmx2; + c->h264_h_loop_filter_chroma_intra= h264_h_loop_filter_chroma_intra_mmx2; + c->h264_loop_filter_strength= h264_loop_filter_strength_mmx2; + + 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; + } + if(mm_flags & FF_MM_SSE2){ + c->h264_idct8_add = ff_h264_idct8_add_sse2; + c->h264_idct8_add4= ff_h264_idct8_add4_sse2; + } + +#if CONFIG_GPL && HAVE_YASM + if (mm_flags & FF_MM_MMX2){ +#if ARCH_X86_32 + c->h264_v_loop_filter_luma_intra = ff_x264_deblock_v_luma_intra_mmxext; + c->h264_h_loop_filter_luma_intra = ff_x264_deblock_h_luma_intra_mmxext; +#endif + if( mm_flags&FF_MM_SSE2 ){ +#if ARCH_X86_64 || !defined(__ICC) || __ICC > 1110 + c->h264_v_loop_filter_luma = ff_x264_deblock_v_luma_sse2; + c->h264_h_loop_filter_luma = ff_x264_deblock_h_luma_sse2; + c->h264_v_loop_filter_luma_intra = ff_x264_deblock_v_luma_intra_sse2; + c->h264_h_loop_filter_luma_intra = ff_x264_deblock_h_luma_intra_sse2; +#endif + c->h264_idct_add16 = ff_h264_idct_add16_sse2; + c->h264_idct_add8 = ff_h264_idct_add8_sse2; + c->h264_idct_add16intra = ff_h264_idct_add16intra_sse2; + } + } +#endif + } +} +#endif /* CONFIG_H264DSP */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/dsputil_mmx.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/dsputil_mmx.h index 52c5f8dd09..7d1bf7fae6 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/dsputil_mmx.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/dsputil_mmx.h @@ -150,5 +150,27 @@ extern const double ff_pd_2[2]; "psrlw $15, %%" #regd ::) void dsputilenc_init_mmx(DSPContext* c, AVCodecContext *avctx); +void dsputil_init_pix_mmx(DSPContext* c, AVCodecContext *avctx); + +void add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size); +void put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size); +void put_signed_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size); + +void ff_cavsdsp_init_mmx2(DSPContext* c, AVCodecContext *avctx); +void ff_cavsdsp_init_3dnow(DSPContext* c, AVCodecContext *avctx); +void ff_put_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride); +void ff_avg_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride); +void ff_put_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride); +void ff_avg_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride); + +void ff_vc1dsp_init_mmx(DSPContext* dsp, AVCodecContext *avctx); +void ff_put_vc1_mspel_mc00_mmx(uint8_t *dst, const uint8_t *src, int stride, int rnd); +void ff_avg_vc1_mspel_mc00_mmx2(uint8_t *dst, const uint8_t *src, int stride, int rnd); + +void ff_lpc_compute_autocorr_sse2(const int32_t *data, int len, int lag, + double *autoc); + +void ff_mmx_idct(DCTELEM *block); +void ff_mmxext_idct(DCTELEM *block); #endif /* AVCODEC_X86_DSPUTIL_MMX_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/dsputil_mmx_avg_template.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/dsputil_mmx_avg_template.c index c00dad5a72..8220867328 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/dsputil_mmx_avg_template.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/dsputil_mmx_avg_template.c @@ -96,7 +96,7 @@ static void DEF(put_pixels4_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int "add $16, %2 \n\t" "subl $4, %0 \n\t" "jnz 1b \n\t" -#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used +#if !HAVE_EBX_AVAILABLE //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst) #else :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst) @@ -143,7 +143,7 @@ static void DEF(put_pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int "add $32, %2 \n\t" "subl $4, %0 \n\t" "jnz 1b \n\t" -#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used +#if !HAVE_EBX_AVAILABLE //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst) #else :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst) @@ -213,7 +213,7 @@ static void DEF(put_no_rnd_pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src "add $32, %2 \n\t" "subl $4, %0 \n\t" "jnz 1b \n\t" -#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used +#if !HAVE_EBX_AVAILABLE //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst) #else :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst) @@ -268,7 +268,7 @@ static void DEF(avg_pixels4_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int "add $16, %2 \n\t" "subl $4, %0 \n\t" "jnz 1b \n\t" -#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used +#if !HAVE_EBX_AVAILABLE //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst) #else :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst) @@ -320,7 +320,7 @@ static void DEF(avg_pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int "add $32, %2 \n\t" "subl $4, %0 \n\t" "jnz 1b \n\t" -#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used +#if !HAVE_EBX_AVAILABLE //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst) #else :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst) @@ -408,7 +408,7 @@ static void DEF(put_pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int "add $32, %2 \n\t" "subl $2, %0 \n\t" "jnz 1b \n\t" -#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used +#if !HAVE_EBX_AVAILABLE //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst) #else :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst) @@ -462,7 +462,7 @@ static void DEF(avg_pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int "add $32, %2 \n\t" "subl $2, %0 \n\t" "jnz 1b \n\t" -#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used +#if !HAVE_EBX_AVAILABLE //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst) #else :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst) @@ -535,7 +535,7 @@ static void DEF(put_no_rnd_pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t *sr "add $32, %2 \n\t" "subl $2, %0 \n\t" "jnz 1b \n\t" -#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used +#if !HAVE_EBX_AVAILABLE //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst) #else :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst) diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/dsputil_mmx_rnd_template.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/dsputil_mmx_rnd_template.c index 113b6c38eb..2fc1756f60 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/dsputil_mmx_rnd_template.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/dsputil_mmx_rnd_template.c @@ -98,7 +98,7 @@ static void av_unused DEF(put, pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t "add %5, %3 \n\t" "subl $4, %0 \n\t" "jnz 1b \n\t" -#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used +#if !HAVE_EBX_AVAILABLE //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst) #else :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst) @@ -193,7 +193,7 @@ static void av_unused DEF(put, pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t "add $32, %2 \n\t" "subl $2, %0 \n\t" "jnz 1b \n\t" -#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used +#if !HAVE_EBX_AVAILABLE //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst) #else :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst) diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/dsputil_yasm.nasm b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/dsputil_yasm.nasm index 9d5e62e57d..e2478a4845 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/dsputil_yasm.nasm +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/dsputil_yasm.nasm @@ -21,6 +21,13 @@ %include "x86inc.asm" +SECTION_RODATA +pb_f: times 16 db 15 +pb_zzzzzzzz77777777: times 8 db -1 +pb_7: times 8 db 7 +pb_zzzz3333zzzzbbbb: db -1,-1,-1,-1,3,3,3,3,-1,-1,-1,-1,11,11,11,11 +pb_zz11zz55zz99zzdd: db -1,-1,1,1,-1,-1,5,5,-1,-1,9,9,-1,-1,13,13 + section .text align=16 %macro PSWAPD_SSE 2 @@ -92,7 +99,180 @@ FLOAT_TO_INT16_INTERLEAVE6 3dn2 -; void ff_add_hfyu_median_prediction_mmx2(uint8_t *dst, uint8_t *top, uint8_t *diff, int w, int *left, int *left_top) +%macro SCALARPRODUCT 1 +; int scalarproduct_int16(int16_t *v1, int16_t *v2, int order, int shift) +cglobal scalarproduct_int16_%1, 3,3,4, v1, v2, order, shift + shl orderq, 1 + add v1q, orderq + add v2q, orderq + neg orderq + movd m3, shiftm + pxor m2, m2 +.loop: + movu m0, [v1q + orderq] + movu m1, [v1q + orderq + mmsize] + pmaddwd m0, [v2q + orderq] + pmaddwd m1, [v2q + orderq + mmsize] + paddd m2, m0 + paddd m2, m1 + add orderq, mmsize*2 + jl .loop +%if mmsize == 16 + movhlps m0, m2 + paddd m2, m0 + psrad m2, m3 + pshuflw m0, m2, 0x4e +%else + psrad m2, m3 + pshufw m0, m2, 0x4e +%endif + paddd m2, m0 + movd eax, m2 + RET + +; int scalarproduct_and_madd_int16(int16_t *v1, int16_t *v2, int16_t *v3, int order, int mul) +cglobal scalarproduct_and_madd_int16_%1, 4,4,8, v1, v2, v3, order, mul + shl orderq, 1 + movd m7, mulm +%if mmsize == 16 + pshuflw m7, m7, 0 + punpcklqdq m7, m7 +%else + pshufw m7, m7, 0 +%endif + pxor m6, m6 + add v1q, orderq + add v2q, orderq + add v3q, orderq + neg orderq +.loop: + movu m0, [v2q + orderq] + movu m1, [v2q + orderq + mmsize] + mova m4, [v1q + orderq] + mova m5, [v1q + orderq + mmsize] + movu m2, [v3q + orderq] + movu m3, [v3q + orderq + mmsize] + pmaddwd m0, m4 + pmaddwd m1, m5 + pmullw m2, m7 + pmullw m3, m7 + paddd m6, m0 + paddd m6, m1 + paddw m2, m4 + paddw m3, m5 + mova [v1q + orderq], m2 + mova [v1q + orderq + mmsize], m3 + add orderq, mmsize*2 + jl .loop +%if mmsize == 16 + movhlps m0, m6 + paddd m6, m0 + pshuflw m0, m6, 0x4e +%else + pshufw m0, m6, 0x4e +%endif + paddd m6, m0 + movd eax, m6 + RET +%endmacro + +INIT_MMX +SCALARPRODUCT mmx2 +INIT_XMM +SCALARPRODUCT sse2 + +%macro SCALARPRODUCT_LOOP 1 +align 16 +.loop%1: + sub orderq, mmsize*2 +%if %1 + mova m1, m4 + mova m4, [v2q + orderq] + mova m0, [v2q + orderq + mmsize] + palignr m1, m0, %1 + palignr m0, m4, %1 + mova m3, m5 + mova m5, [v3q + orderq] + mova m2, [v3q + orderq + mmsize] + palignr m3, m2, %1 + palignr m2, m5, %1 +%else + mova m0, [v2q + orderq] + mova m1, [v2q + orderq + mmsize] + mova m2, [v3q + orderq] + mova m3, [v3q + orderq + mmsize] +%endif + %define t0 [v1q + orderq] + %define t1 [v1q + orderq + mmsize] +%ifdef ARCH_X86_64 + mova m8, t0 + mova m9, t1 + %define t0 m8 + %define t1 m9 +%endif + pmaddwd m0, t0 + pmaddwd m1, t1 + pmullw m2, m7 + pmullw m3, m7 + paddw m2, t0 + paddw m3, t1 + paddd m6, m0 + paddd m6, m1 + mova [v1q + orderq], m2 + mova [v1q + orderq + mmsize], m3 + jg .loop%1 +%if %1 + jmp .end +%endif +%endmacro + +; int scalarproduct_and_madd_int16(int16_t *v1, int16_t *v2, int16_t *v3, int order, int mul) +cglobal scalarproduct_and_madd_int16_ssse3, 4,5,10, v1, v2, v3, order, mul + shl orderq, 1 + movd m7, mulm + pshuflw m7, m7, 0 + punpcklqdq m7, m7 + pxor m6, m6 + mov r4d, v2d + and r4d, 15 + and v2q, ~15 + and v3q, ~15 + mova m4, [v2q + orderq] + mova m5, [v3q + orderq] + ; linear is faster than branch tree or jump table, because the branches taken are cyclic (i.e. predictable) + cmp r4d, 0 + je .loop0 + cmp r4d, 2 + je .loop2 + cmp r4d, 4 + je .loop4 + cmp r4d, 6 + je .loop6 + cmp r4d, 8 + je .loop8 + cmp r4d, 10 + je .loop10 + cmp r4d, 12 + je .loop12 +SCALARPRODUCT_LOOP 14 +SCALARPRODUCT_LOOP 12 +SCALARPRODUCT_LOOP 10 +SCALARPRODUCT_LOOP 8 +SCALARPRODUCT_LOOP 6 +SCALARPRODUCT_LOOP 4 +SCALARPRODUCT_LOOP 2 +SCALARPRODUCT_LOOP 0 +.end: + movhlps m0, m6 + paddd m6, m0 + pshuflw m0, m6, 0x4e + paddd m6, m0 + movd eax, m6 + RET + + + +; void ff_add_hfyu_median_prediction_mmx2(uint8_t *dst, const uint8_t *top, const uint8_t *diff, int w, int *left, int *left_top) cglobal add_hfyu_median_prediction_mmx2, 6,6,0, dst, top, diff, w, left, left_top movq mm0, [topq] movq mm2, mm0 @@ -150,3 +330,94 @@ cglobal add_hfyu_median_prediction_mmx2, 6,6,0, dst, top, diff, w, left, left_to movzx r2d, byte [topq-1] mov [left_topq], r2d RET + + +%macro ADD_HFYU_LEFT_LOOP 1 ; %1 = is_aligned + add srcq, wq + add dstq, wq + neg wq +%%.loop: + mova m1, [srcq+wq] + mova m2, m1 + psllw m1, 8 + paddb m1, m2 + mova m2, m1 + pshufb m1, m3 + paddb m1, m2 + pshufb m0, m5 + mova m2, m1 + pshufb m1, m4 + paddb m1, m2 +%if mmsize == 16 + mova m2, m1 + pshufb m1, m6 + paddb m1, m2 +%endif + paddb m0, m1 +%if %1 + mova [dstq+wq], m0 +%else + movq [dstq+wq], m0 + movhps [dstq+wq+8], m0 +%endif + add wq, mmsize + jl %%.loop + mov eax, mmsize-1 + sub eax, wd + movd m1, eax + pshufb m0, m1 + movd eax, m0 + RET +%endmacro + +; int ff_add_hfyu_left_prediction(uint8_t *dst, const uint8_t *src, int w, int left) +INIT_MMX +cglobal add_hfyu_left_prediction_ssse3, 3,3,7, dst, src, w, left +.skip_prologue: + mova m5, [pb_7 GLOBAL] + mova m4, [pb_zzzz3333zzzzbbbb GLOBAL] + mova m3, [pb_zz11zz55zz99zzdd GLOBAL] + movd m0, leftm + psllq m0, 56 + ADD_HFYU_LEFT_LOOP 1 + +INIT_XMM +cglobal add_hfyu_left_prediction_sse4, 3,3,7, dst, src, w, left + mova m5, [pb_f GLOBAL] + mova m6, [pb_zzzzzzzz77777777 GLOBAL] + mova m4, [pb_zzzz3333zzzzbbbb GLOBAL] + mova m3, [pb_zz11zz55zz99zzdd GLOBAL] + movd m0, leftm + pslldq m0, 15 + test srcq, 15 + jnz add_hfyu_left_prediction_ssse3.skip_prologue + test dstq, 15 + jnz .unaligned + ADD_HFYU_LEFT_LOOP 1 +.unaligned: + ADD_HFYU_LEFT_LOOP 0 + + +; float ff_scalarproduct_float_sse(const float *v1, const float *v2, int len) +cglobal scalarproduct_float_sse, 3,3,2, v1, v2, offset + neg offsetq + shl offsetq, 2 + sub v1q, offsetq + sub v2q, offsetq + xorps xmm0, xmm0 + .loop: + movaps xmm1, [v1q+offsetq] + mulps xmm1, [v2q+offsetq] + addps xmm0, xmm1 + add offsetq, 16 + js .loop + movhlps xmm1, xmm0 + addps xmm0, xmm1 + movss xmm1, xmm0 + shufps xmm0, xmm0, 1 + addss xmm0, xmm1 +%ifndef ARCH_X86_64 + movd r0m, xmm0 + fld dword r0m +%endif + RET diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/dsputilenc_mmx.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/dsputilenc_mmx.c index 6059436252..f491111ca5 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/dsputilenc_mmx.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/dsputilenc_mmx.c @@ -902,7 +902,7 @@ static void diff_bytes_mmx(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){ dst[i+0] = src1[i+0]-src2[i+0]; } -static void sub_hfyu_median_prediction_mmx2(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w, int *left, int *left_top){ +static void sub_hfyu_median_prediction_mmx2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int w, int *left, int *left_top){ x86_reg i=0; uint8_t l, lt; @@ -1063,7 +1063,7 @@ static void sub_hfyu_median_prediction_mmx2(uint8_t *dst, uint8_t *src1, uint8_t #define HADAMARD8_DIFF_MMX(cpu) \ static int hadamard8_diff_##cpu(void *s, uint8_t *src1, uint8_t *src2, int stride, int h){\ - DECLARE_ALIGNED_8(uint64_t, temp[13]);\ + DECLARE_ALIGNED(8, uint64_t, temp)[13];\ int sum;\ \ assert(h==8);\ @@ -1146,7 +1146,7 @@ WRAPPER8_16_SQ(hadamard8_diff_##cpu, hadamard8_diff16_##cpu) #define HADAMARD8_DIFF_SSE2(cpu) \ static int hadamard8_diff_##cpu(void *s, uint8_t *src1, uint8_t *src2, int stride, int h){\ - DECLARE_ALIGNED_16(uint64_t, temp[4]);\ + DECLARE_ALIGNED(16, uint64_t, temp)[4];\ int sum;\ \ assert(h==8);\ @@ -1348,11 +1348,6 @@ static int ssd_int8_vs_int16_mmx(const int8_t *pix1, const int16_t *pix2, int si #endif //HAVE_SSSE3 -/* FLAC specific */ -void ff_flac_compute_autocorr_sse2(const int32_t *data, int len, int lag, - double *autoc); - - void dsputilenc_init_mmx(DSPContext* c, AVCodecContext *avctx) { if (mm_flags & FF_MM_MMX) { @@ -1414,8 +1409,9 @@ void dsputilenc_init_mmx(DSPContext* c, AVCodecContext *avctx) c->sum_abs_dctelem= sum_abs_dctelem_sse2; c->hadamard8_diff[0]= hadamard8_diff16_sse2; c->hadamard8_diff[1]= hadamard8_diff_sse2; - if (CONFIG_FLAC_ENCODER) - c->flac_compute_autocorr = ff_flac_compute_autocorr_sse2; +#if CONFIG_LPC + c->lpc_compute_autocorr = ff_lpc_compute_autocorr_sse2; +#endif } #if HAVE_SSSE3 diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/fdct_mmx.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/fdct_mmx.c index c87c1a78f3..6e5228528e 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/fdct_mmx.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/fdct_mmx.c @@ -33,8 +33,6 @@ #include "libavutil/common.h" #include "libavcodec/dsputil.h" -#define ATTR_ALIGN(align) __attribute__ ((__aligned__ (align))) - ////////////////////////////////////////////////////////////////////// // // constants for the forward DCT @@ -55,30 +53,30 @@ #define X8(x) x,x,x,x,x,x,x,x //concatenated table, for forward DCT transformation -static const int16_t fdct_tg_all_16[24] ATTR_ALIGN(16) = { +DECLARE_ALIGNED(16, static const int16_t, fdct_tg_all_16)[24] = { X8(13036), // tg * (2<<16) + 0.5 X8(27146), // tg * (2<<16) + 0.5 X8(-21746) // tg * (2<<16) + 0.5 }; -static const int16_t ocos_4_16[8] ATTR_ALIGN(16) = { +DECLARE_ALIGNED(16, static const int16_t, ocos_4_16)[8] = { X8(23170) //cos * (2<<15) + 0.5 }; -static const int16_t fdct_one_corr[8] ATTR_ALIGN(16) = { X8(1) }; +DECLARE_ALIGNED(16, static const int16_t, fdct_one_corr)[8] = { X8(1) }; -static const int32_t fdct_r_row[2] ATTR_ALIGN(8) = {RND_FRW_ROW, RND_FRW_ROW }; +DECLARE_ALIGNED(8, static const int32_t, fdct_r_row)[2] = {RND_FRW_ROW, RND_FRW_ROW }; static struct { - const int32_t fdct_r_row_sse2[4] ATTR_ALIGN(16); -} fdct_r_row_sse2 ATTR_ALIGN(16)= + DECLARE_ALIGNED(16, const int32_t, fdct_r_row_sse2)[4]; +} fdct_r_row_sse2 = {{ RND_FRW_ROW, RND_FRW_ROW, RND_FRW_ROW, RND_FRW_ROW }}; -//static const long fdct_r_row_sse2[4] ATTR_ALIGN(16) = {RND_FRW_ROW, RND_FRW_ROW, RND_FRW_ROW, RND_FRW_ROW}; +//DECLARE_ALIGNED(16, static const long, fdct_r_row_sse2)[4] = {RND_FRW_ROW, RND_FRW_ROW, RND_FRW_ROW, RND_FRW_ROW}; -static const int16_t tab_frw_01234567[] ATTR_ALIGN(8) = { // forward_dct coeff table +DECLARE_ALIGNED(8, static const int16_t, tab_frw_01234567)[] = { // forward_dct coeff table 16384, 16384, 22725, 19266, 16384, 16384, 12873, 4520, 21407, 8867, 19266, -4520, @@ -154,10 +152,10 @@ static const int16_t tab_frw_01234567[] ATTR_ALIGN(8) = { // forward_dct coeff static struct { - const int16_t tab_frw_01234567_sse2[256] ATTR_ALIGN(16); -} tab_frw_01234567_sse2 ATTR_ALIGN(16) = + DECLARE_ALIGNED(16, const int16_t, tab_frw_01234567_sse2)[256]; +} tab_frw_01234567_sse2 = {{ -//static const int16_t tab_frw_01234567_sse2[] ATTR_ALIGN(16) = { // forward_dct coeff table +//DECLARE_ALIGNED(16, static const int16_t, tab_frw_01234567_sse2)[] = { // forward_dct coeff table #define TABLE_SSE2 C4, C4, C1, C3, -C6, -C2, -C1, -C5, \ C4, C4, C5, C7, C2, C6, C3, -C7, \ -C4, C4, C7, C3, C6, -C2, C7, -C5, \ @@ -535,7 +533,7 @@ static av_always_inline void fdct_row_mmx(const int16_t *in, int16_t *out, const void ff_fdct_mmx(int16_t *block) { - int64_t align_tmp[16] ATTR_ALIGN(8); + DECLARE_ALIGNED(8, int64_t, align_tmp)[16]; int16_t * block1= (int16_t*)align_tmp; const int16_t *table= tab_frw_01234567; int i; @@ -553,7 +551,7 @@ void ff_fdct_mmx(int16_t *block) void ff_fdct_mmx2(int16_t *block) { - int64_t align_tmp[16] ATTR_ALIGN(8); + DECLARE_ALIGNED(8, int64_t, align_tmp)[16]; int16_t *block1= (int16_t*)align_tmp; const int16_t *table= tab_frw_01234567; int i; @@ -571,7 +569,7 @@ void ff_fdct_mmx2(int16_t *block) void ff_fdct_sse2(int16_t *block) { - int64_t align_tmp[16] ATTR_ALIGN(16); + DECLARE_ALIGNED(16, int64_t, align_tmp)[16]; int16_t * const block1= (int16_t*)align_tmp; fdct_col_sse2(block, block1, 0); diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/fft.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/fft.c new file mode 100644 index 0000000000..2c46c6361b --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/fft.c @@ -0,0 +1,44 @@ +/* + * 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 "libavcodec/dsputil.h" +#include "fft.h" + +av_cold void ff_fft_init_mmx(FFTContext *s) +{ +#if HAVE_YASM + int has_vectors = mm_support(); + if (has_vectors & FF_MM_SSE && HAVE_SSE) { + /* SSE for P3/P4/K8 */ + s->imdct_calc = ff_imdct_calc_sse; + s->imdct_half = ff_imdct_half_sse; + s->fft_permute = ff_fft_permute_sse; + s->fft_calc = ff_fft_calc_sse; + } else if (has_vectors & FF_MM_3DNOWEXT && HAVE_AMD3DNOWEXT) { + /* 3DNowEx for K7 */ + s->imdct_calc = ff_imdct_calc_3dn2; + s->imdct_half = ff_imdct_half_3dn2; + s->fft_calc = ff_fft_calc_3dn2; + } else if (has_vectors & FF_MM_3DNOW && HAVE_AMD3DNOW) { + /* 3DNow! for K6-2/3 */ + s->imdct_calc = ff_imdct_calc_3dn; + s->imdct_half = ff_imdct_half_3dn; + s->fft_calc = ff_fft_calc_3dn; + } +#endif +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/fft.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/fft.h new file mode 100644 index 0000000000..7ef5839141 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/fft.h @@ -0,0 +1,36 @@ +/* + * 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_X86_FFT_H +#define AVCODEC_X86_FFT_H + +#include "libavcodec/fft.h" + +void ff_fft_permute_sse(FFTContext *s, FFTComplex *z); +void ff_fft_calc_sse(FFTContext *s, FFTComplex *z); +void ff_fft_calc_3dn(FFTContext *s, FFTComplex *z); +void ff_fft_calc_3dn2(FFTContext *s, FFTComplex *z); + +void ff_imdct_calc_3dn(FFTContext *s, FFTSample *output, const FFTSample *input); +void ff_imdct_half_3dn(FFTContext *s, FFTSample *output, const FFTSample *input); +void ff_imdct_calc_3dn2(FFTContext *s, FFTSample *output, const FFTSample *input); +void ff_imdct_half_3dn2(FFTContext *s, FFTSample *output, const FFTSample *input); +void ff_imdct_calc_sse(FFTContext *s, FFTSample *output, const FFTSample *input); +void ff_imdct_half_sse(FFTContext *s, FFTSample *output, const FFTSample *input); + +#endif diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/fft_3dn2.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/fft_3dn2.c index 1f30edc99d..b3bec4675a 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/fft_3dn2.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/fft_3dn2.c @@ -21,8 +21,9 @@ #include "libavutil/x86_cpu.h" #include "libavcodec/dsputil.h" +#include "fft.h" -DECLARE_ALIGNED_8(static const int, m1m1[2]) = { 1<<31, 1<<31 }; +DECLARE_ALIGNED(8, static const int, m1m1)[2] = { 1<<31, 1<<31 }; #ifdef EMULATE_3DNOWEXT #define PSWAPD(s,d)\ @@ -52,14 +53,14 @@ void ff_fft_calc_3dn2(FFTContext *s, FFTComplex *z) FFSWAP(FFTSample, z[i].im, z[i+1].re); } -void ff_imdct_half_3dn2(MDCTContext *s, FFTSample *output, const FFTSample *input) +void ff_imdct_half_3dn2(FFTContext *s, FFTSample *output, const FFTSample *input) { x86_reg j, k; - long n = 1 << s->nbits; + long n = 1 << s->mdct_bits; long n2 = n >> 1; long n4 = n >> 2; long n8 = n >> 3; - const uint16_t *revtab = s->fft.revtab; + const uint16_t *revtab = s->revtab; const FFTSample *tcos = s->tcos; const FFTSample *tsin = s->tsin; const FFTSample *in1, *in2; @@ -100,7 +101,7 @@ void ff_imdct_half_3dn2(MDCTContext *s, FFTSample *output, const FFTSample *inpu ); } - ff_fft_dispatch_3dn2(z, s->fft.nbits); + ff_fft_dispatch_3dn2(z, s->nbits); #define CMUL(j,mm0,mm1)\ "movq (%2,"#j",2), %%mm6 \n"\ @@ -143,10 +144,10 @@ void ff_imdct_half_3dn2(MDCTContext *s, FFTSample *output, const FFTSample *inpu __asm__ volatile("femms"); } -void ff_imdct_calc_3dn2(MDCTContext *s, FFTSample *output, const FFTSample *input) +void ff_imdct_calc_3dn2(FFTContext *s, FFTSample *output, const FFTSample *input) { x86_reg j, k; - long n = 1 << s->nbits; + long n = 1 << s->mdct_bits; long n4 = n >> 2; ff_imdct_half_3dn2(s, output+n4, input); diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/fft_mmx.nasm b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/fft_mmx.nasm index 6c1b26d401..9cb0ae1bfe 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/fft_mmx.nasm +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/fft_mmx.nasm @@ -264,6 +264,7 @@ IF%1 mova Z(1), m3 %endmacro INIT_XMM +%define mova movaps %define Z(x) [r0+mmsize*x] @@ -403,6 +404,7 @@ DEFINE_ARGS z, w, n, o1, o3 %endmacro INIT_XMM +%define mova movaps DECL_PASS pass_sse, PASS_BIG 1 DECL_PASS pass_interleave_sse, PASS_BIG 0 @@ -417,18 +419,23 @@ DECL_PASS pass_interleave_3dn, PASS_BIG 0 %define pass_3dn2 pass_3dn %define pass_interleave_3dn2 pass_interleave_3dn +%ifdef PIC +%define SECTION_REL - $$ +%else +%define SECTION_REL +%endif %macro DECL_FFT 2-3 ; nbits, cpu, suffix -%xdefine list_of_fft fft4%2, fft8%2 +%xdefine list_of_fft fft4%2 SECTION_REL, fft8%2 SECTION_REL %if %1==5 -%xdefine list_of_fft list_of_fft, fft16%2 +%xdefine list_of_fft list_of_fft, fft16%2 SECTION_REL %endif %assign n 1<<%1 %rep 17-%1 %assign n2 n/2 %assign n4 n/4 -%xdefine list_of_fft list_of_fft, fft %+ n %+ %3%2 +%xdefine list_of_fft list_of_fft, fft %+ n %+ %3%2 SECTION_REL align 16 fft %+ n %+ %3%2: @@ -446,10 +453,6 @@ fft %+ n %+ %3%2: %endrep %undef n -%ifidn __OUTPUT_FORMAT__,macho64 -section .rodata -%endif - align 8 dispatch_tab%3%2: pointer list_of_fft @@ -460,6 +463,10 @@ section .text cglobal fft_dispatch%3%2, 2,5,8, z, nbits lea r2, [dispatch_tab%3%2 GLOBAL] mov r2, [r2 + (nbitsq-2)*gprsize] +%ifdef PIC + lea r3, [$$ GLOBAL] + add r2, r3 +%endif call r2 RET %endmacro ; DECL_FFT diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/fft_sse.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/fft_sse.c index e6cb3dce65..a4cce69db1 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/fft_sse.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/fft_sse.c @@ -21,8 +21,9 @@ #include "libavutil/x86_cpu.h" #include "libavcodec/dsputil.h" +#include "fft.h" -DECLARE_ALIGNED(16, static const int, m1m1m1m1[4]) = +DECLARE_ALIGNED(16, static const int, m1m1m1m1)[4] = { 1 << 31, 1 << 31, 1 << 31, 1 << 31 }; void ff_fft_dispatch_sse(FFTComplex *z, int nbits); @@ -70,14 +71,14 @@ void ff_fft_permute_sse(FFTContext *s, FFTComplex *z) memcpy(z, s->tmp_buf, n*sizeof(FFTComplex)); } -void ff_imdct_half_sse(MDCTContext *s, FFTSample *output, const FFTSample *input) +void ff_imdct_half_sse(FFTContext *s, FFTSample *output, const FFTSample *input) { av_unused x86_reg i, j, k, l; - long n = 1 << s->nbits; + long n = 1 << s->mdct_bits; long n2 = n >> 1; long n4 = n >> 2; long n8 = n >> 3; - const uint16_t *revtab = s->fft.revtab + n8; + const uint16_t *revtab = s->revtab + n8; const FFTSample *tcos = s->tcos; const FFTSample *tsin = s->tsin; FFTComplex *z = (FFTComplex *)output; @@ -128,7 +129,7 @@ void ff_imdct_half_sse(MDCTContext *s, FFTSample *output, const FFTSample *input #endif } - ff_fft_dispatch_sse(z, s->fft.nbits); + ff_fft_dispatch_sse(z, s->nbits); /* post rotation + reinterleave + reorder */ @@ -171,10 +172,10 @@ void ff_imdct_half_sse(MDCTContext *s, FFTSample *output, const FFTSample *input ); } -void ff_imdct_calc_sse(MDCTContext *s, FFTSample *output, const FFTSample *input) +void ff_imdct_calc_sse(FFTContext *s, FFTSample *output, const FFTSample *input) { x86_reg j, k; - long n = 1 << s->nbits; + long n = 1 << s->mdct_bits; long n4 = n >> 2; ff_imdct_half_sse(s, output+n4, input); diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/h264_i386.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/h264_i386.h index 29b214a85f..26c163be3c 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/h264_i386.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/h264_i386.h @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/x86/h264_i386.h + * @file * H.264 / AVC / MPEG4 part10 codec. * non-MMX i386-specific optimizations for H.264 * @author Michael Niedermayer diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/h264dsp_mmx.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/h264dsp_mmx.c index e754c27da2..fd16a02d6a 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/h264dsp_mmx.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/h264dsp_mmx.c @@ -20,8 +20,8 @@ #include "dsputil_mmx.h" -DECLARE_ALIGNED_8 (static const uint64_t, ff_pb_3_1 ) = 0x0103010301030103ULL; -DECLARE_ALIGNED_8 (static const uint64_t, ff_pb_7_3 ) = 0x0307030703070307ULL; +DECLARE_ALIGNED(8, static const uint64_t, ff_pb_3_1 ) = 0x0103010301030103ULL; +DECLARE_ALIGNED(8, static const uint64_t, ff_pb_7_3 ) = 0x0307030703070307ULL; /***********************************/ /* IDCT */ @@ -157,12 +157,12 @@ static inline void h264_idct8_1d(int16_t *block) static void ff_h264_idct8_add_mmx(uint8_t *dst, int16_t *block, int stride) { int i; - DECLARE_ALIGNED_8(int16_t, b2[64]); + DECLARE_ALIGNED(8, int16_t, b2)[64]; block[0] += 32; for(i=0; i<2; i++){ - DECLARE_ALIGNED_8(uint64_t, tmp); + DECLARE_ALIGNED(8, uint64_t, tmp); h264_idct8_1d(block+4*i); @@ -617,7 +617,7 @@ static void ff_h264_idct_add8_sse2(uint8_t **dest, const int *block_offset, DCTE "pavgb %%mm2, "#tmp" \n\t"\ "pavgb "#tmp", "#q2" \n\t" /* avg(p2,avg(p0,q0)) */\ "pxor "q2addr", "#tmp" \n\t"\ - "pand %8, "#tmp" \n\t" /* (p2^avg(p0,q0))&1 */\ + "pand %9, "#tmp" \n\t" /* (p2^avg(p0,q0))&1 */\ "psubusb "#tmp", "#q2" \n\t" /* (p2+((p0+q0+1)>>1))>>1 */\ "movq "#p1", "#tmp" \n\t"\ "psubusb "#tc0", "#tmp" \n\t"\ @@ -628,51 +628,51 @@ static void ff_h264_idct_add8_sse2(uint8_t **dest, const int *block_offset, DCTE static inline void h264_loop_filter_luma_mmx2(uint8_t *pix, int stride, int alpha1, int beta1, int8_t *tc0) { - DECLARE_ALIGNED_8(uint64_t, tmp0[2]); + DECLARE_ALIGNED(8, uint64_t, tmp0)[2]; __asm__ volatile( - "movq (%1,%3), %%mm0 \n\t" //p1 - "movq (%1,%3,2), %%mm1 \n\t" //p0 - "movq (%2), %%mm2 \n\t" //q0 - "movq (%2,%3), %%mm3 \n\t" //q1 - H264_DEBLOCK_MASK(%6, %7) + "movq (%2,%4), %%mm0 \n\t" //p1 + "movq (%2,%4,2), %%mm1 \n\t" //p0 + "movq (%3), %%mm2 \n\t" //q0 + "movq (%3,%4), %%mm3 \n\t" //q1 + H264_DEBLOCK_MASK(%7, %8) - "movd %5, %%mm4 \n\t" + "movd %6, %%mm4 \n\t" "punpcklbw %%mm4, %%mm4 \n\t" "punpcklwd %%mm4, %%mm4 \n\t" "pcmpeqb %%mm3, %%mm3 \n\t" "movq %%mm4, %%mm6 \n\t" "pcmpgtb %%mm3, %%mm4 \n\t" - "movq %%mm6, 8+%0 \n\t" + "movq %%mm6, %1 \n\t" "pand %%mm4, %%mm7 \n\t" "movq %%mm7, %0 \n\t" /* filter p1 */ - "movq (%1), %%mm3 \n\t" //p2 + "movq (%2), %%mm3 \n\t" //p2 DIFF_GT2_MMX(%%mm1, %%mm3, %%mm5, %%mm6, %%mm4) // |p2-p0|>beta-1 "pand %%mm7, %%mm6 \n\t" // mask & |p2-p0|beta-1 "pand %0, %%mm6 \n\t" - "movq 8+%0, %%mm5 \n\t" // can be merged with the and below but is slower then + "movq %1, %%mm5 \n\t" // can be merged with the and below but is slower then "pand %%mm6, %%mm5 \n\t" "psubb %%mm6, %%mm7 \n\t" - "movq (%2,%3), %%mm3 \n\t" - H264_DEBLOCK_Q1(%%mm3, %%mm4, "(%2,%3,2)", "(%2,%3)", %%mm5, %%mm6) + "movq (%3,%4), %%mm3 \n\t" + H264_DEBLOCK_Q1(%%mm3, %%mm4, "(%3,%4,2)", "(%3,%4)", %%mm5, %%mm6) /* filter p0, q0 */ - H264_DEBLOCK_P0_Q0(%8, unused) - "movq %%mm1, (%1,%3,2) \n\t" - "movq %%mm2, (%2) \n\t" + H264_DEBLOCK_P0_Q0(%9, unused) + "movq %%mm1, (%2,%4,2) \n\t" + "movq %%mm2, (%3) \n\t" - : "=m"(*tmp0) + : "=m"(tmp0[0]), "=m"(tmp0[1]) : "r"(pix-3*stride), "r"(pix), "r"((x86_reg)stride), "m"(*tmp0/*unused*/), "m"(*(uint32_t*)tc0), "m"(alpha1), "m"(beta1), "m"(ff_bone) @@ -690,7 +690,7 @@ static void h264_h_loop_filter_luma_mmx2(uint8_t *pix, int stride, int alpha, in { //FIXME: could cut some load/stores by merging transpose with filter // also, it only needs to transpose 6x8 - DECLARE_ALIGNED_8(uint8_t, trans[8*8]); + DECLARE_ALIGNED(8, uint8_t, trans)[8*8]; int i; for(i=0; i<2; i++, pix+=8*stride, tc0+=2) { if((tc0[0] & tc0[1]) < 0) @@ -734,7 +734,7 @@ static void h264_v_loop_filter_chroma_mmx2(uint8_t *pix, int stride, int alpha, static void h264_h_loop_filter_chroma_mmx2(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) { //FIXME: could cut some load/stores by merging transpose with filter - DECLARE_ALIGNED_8(uint8_t, trans[8*4]); + DECLARE_ALIGNED(8, uint8_t, trans)[8*4]; transpose4x4(trans, pix-2, 8, stride); transpose4x4(trans+4, pix-2+4*stride, 8, stride); h264_loop_filter_chroma_mmx2(trans+2*8, 8, alpha-1, beta-1, tc0); @@ -784,7 +784,7 @@ static void h264_v_loop_filter_chroma_intra_mmx2(uint8_t *pix, int stride, int a static void h264_h_loop_filter_chroma_intra_mmx2(uint8_t *pix, int stride, int alpha, int beta) { //FIXME: could cut some load/stores by merging transpose with filter - DECLARE_ALIGNED_8(uint8_t, trans[8*4]); + DECLARE_ALIGNED(8, uint8_t, trans)[8*4]; transpose4x4(trans, pix-2, 8, stride); transpose4x4(trans+4, pix-2+4*stride, 8, stride); h264_loop_filter_chroma_intra_mmx2(trans+2*8, 8, alpha-1, beta-1); @@ -792,88 +792,108 @@ static void h264_h_loop_filter_chroma_intra_mmx2(uint8_t *pix, int stride, int a transpose4x4(pix-2+4*stride, trans+4, stride, 8); } -#if __GNUC__ >= 3 static void h264_loop_filter_strength_mmx2( int16_t bS[2][4][4], uint8_t nnz[40], int8_t ref[2][40], int16_t mv[2][40][2], int bidir, int edges, int step, int mask_mv0, int mask_mv1, int field ) { int dir; __asm__ volatile( - "pxor %%mm7, %%mm7 \n\t" - "movq %0, %%mm6 \n\t" - "movq %1, %%mm5 \n\t" - "movq %2, %%mm4 \n\t" - ::"m"(ff_pb_1), "m"(ff_pb_3), "m"(ff_pb_7) + "movq %0, %%mm7 \n" + "movq %1, %%mm6 \n" + ::"m"(ff_pb_1), "m"(ff_pb_3) ); if(field) __asm__ volatile( - "movq %0, %%mm5 \n\t" - "movq %1, %%mm4 \n\t" - ::"m"(ff_pb_3_1), "m"(ff_pb_7_3) + "movq %0, %%mm6 \n" + ::"m"(ff_pb_3_1) ); + __asm__ volatile( + "movq %%mm6, %%mm5 \n" + "paddb %%mm5, %%mm5 \n" + :); // could do a special case for dir==0 && edges==1, but it only reduces the // average filter time by 1.2% for( dir=1; dir>=0; dir-- ) { - const int d_idx = dir ? -8 : -1; + const x86_reg d_idx = dir ? -8 : -1; const int mask_mv = dir ? mask_mv1 : mask_mv0; - DECLARE_ALIGNED_8(const uint64_t, mask_dir) = dir ? 0 : 0xffffffffffffffffULL; - int b_idx, edge, l; + DECLARE_ALIGNED(8, const uint64_t, mask_dir) = dir ? 0 : 0xffffffffffffffffULL; + int b_idx, edge; for( b_idx=12, edge=0; edge= 0; l-- ) { + if(bidir) { __asm__ volatile( - "movd %0, %%mm1 \n\t" - "punpckldq %1, %%mm1 \n\t" - "movq %%mm1, %%mm2 \n\t" - "psrlw $7, %%mm2 \n\t" - "pand %%mm6, %%mm2 \n\t" - "por %%mm2, %%mm1 \n\t" // ref_cache with -2 mapped to -1 - "punpckldq %%mm1, %%mm2 \n\t" - "pcmpeqb %%mm2, %%mm1 \n\t" - "paddb %%mm6, %%mm1 \n\t" - "punpckhbw %%mm7, %%mm1 \n\t" // ref[b] != ref[bn] - "por %%mm1, %%mm0 \n\t" - - "movq %2, %%mm1 \n\t" - "movq %3, %%mm2 \n\t" - "psubw %4, %%mm1 \n\t" - "psubw %5, %%mm2 \n\t" - "packsswb %%mm2, %%mm1 \n\t" - "paddb %%mm5, %%mm1 \n\t" - "pminub %%mm4, %%mm1 \n\t" - "pcmpeqb %%mm4, %%mm1 \n\t" // abs(mv[b] - mv[bn]) >= limit - "por %%mm1, %%mm0 \n\t" - ::"m"(ref[l][b_idx]), - "m"(ref[l][b_idx+d_idx]), - "m"(mv[l][b_idx][0]), - "m"(mv[l][b_idx+2][0]), - "m"(mv[l][b_idx+d_idx][0]), - "m"(mv[l][b_idx+d_idx+2][0]) + "movd (%1,%0), %%mm2 \n" + "punpckldq 40(%1,%0), %%mm2 \n" // { ref0[bn], ref1[bn] } + "pshufw $0x44, (%1), %%mm0 \n" // { ref0[b], ref0[b] } + "pshufw $0x44, 40(%1), %%mm1 \n" // { ref1[b], ref1[b] } + "pshufw $0x4E, %%mm2, %%mm3 \n" + "psubb %%mm2, %%mm0 \n" // { ref0[b]!=ref0[bn], ref0[b]!=ref1[bn] } + "psubb %%mm3, %%mm1 \n" // { ref1[b]!=ref1[bn], ref1[b]!=ref0[bn] } + "1: \n" + "por %%mm1, %%mm0 \n" + "movq (%2,%0,4), %%mm1 \n" + "movq 8(%2,%0,4), %%mm2 \n" + "movq %%mm1, %%mm3 \n" + "movq %%mm2, %%mm4 \n" + "psubw (%2), %%mm1 \n" + "psubw 8(%2), %%mm2 \n" + "psubw 160(%2), %%mm3 \n" + "psubw 168(%2), %%mm4 \n" + "packsswb %%mm2, %%mm1 \n" + "packsswb %%mm4, %%mm3 \n" + "paddb %%mm6, %%mm1 \n" + "paddb %%mm6, %%mm3 \n" + "psubusb %%mm5, %%mm1 \n" // abs(mv[b] - mv[bn]) >= limit + "psubusb %%mm5, %%mm3 \n" + "packsswb %%mm3, %%mm1 \n" + "add $40, %0 \n" + "cmp $40, %0 \n" + "jl 1b \n" + "sub $80, %0 \n" + "pshufw $0x4E, %%mm1, %%mm1 \n" + "por %%mm1, %%mm0 \n" + "pshufw $0x4E, %%mm0, %%mm1 \n" + "pminub %%mm1, %%mm0 \n" + ::"r"(d_idx), + "r"(ref[0]+b_idx), + "r"(mv[0]+b_idx) + ); + } else { + __asm__ volatile( + "movd (%1), %%mm0 \n" + "psubb (%1,%0), %%mm0 \n" // ref[b] != ref[bn] + "movq (%2), %%mm1 \n" + "movq 8(%2), %%mm2 \n" + "psubw (%2,%0,4), %%mm1 \n" + "psubw 8(%2,%0,4), %%mm2 \n" + "packsswb %%mm2, %%mm1 \n" + "paddb %%mm6, %%mm1 \n" + "psubusb %%mm5, %%mm1 \n" // abs(mv[b] - mv[bn]) >= limit + "packsswb %%mm1, %%mm1 \n" + "por %%mm1, %%mm0 \n" + ::"r"(d_idx), + "r"(ref[0]+b_idx), + "r"(mv[0]+b_idx) ); } } __asm__ volatile( - "movd %0, %%mm1 \n\t" - "por %1, %%mm1 \n\t" - "punpcklbw %%mm7, %%mm1 \n\t" - "pcmpgtw %%mm7, %%mm1 \n\t" // nnz[b] || nnz[bn] + "movd %0, %%mm1 \n" + "por %1, %%mm1 \n" // nnz[b] || nnz[bn] ::"m"(nnz[b_idx]), "m"(nnz[b_idx+d_idx]) ); __asm__ volatile( - "pcmpeqw %%mm7, %%mm0 \n\t" - "pcmpeqw %%mm7, %%mm0 \n\t" - "psrlw $15, %%mm0 \n\t" // nonzero -> 1 - "psrlw $14, %%mm1 \n\t" - "movq %%mm0, %%mm2 \n\t" - "por %%mm1, %%mm2 \n\t" - "psrlw $1, %%mm1 \n\t" - "pandn %%mm2, %%mm1 \n\t" - "movq %%mm1, %0 \n\t" + "pminub %%mm7, %%mm1 \n" + "pminub %%mm7, %%mm0 \n" + "psllw $1, %%mm1 \n" + "pxor %%mm2, %%mm2 \n" + "pmaxub %%mm0, %%mm1 \n" + "punpcklbw %%mm2, %%mm1 \n" + "movq %%mm1, %0 \n" :"=m"(*bS[dir][edge]) ::"memory" ); @@ -895,7 +915,6 @@ static void h264_loop_filter_strength_mmx2( int16_t bS[2][4][4], uint8_t nnz[40] :"memory" ); } -#endif // #if __GNUC__ >= 3 /***********************************/ /* motion compensation */ @@ -945,8 +964,8 @@ static av_noinline void OPNAME ## h264_qpel4_h_lowpass_ ## MMX(uint8_t *dst, uin \ __asm__ volatile(\ "pxor %%mm7, %%mm7 \n\t"\ - "movq %5, %%mm4 \n\t"\ - "movq %6, %%mm5 \n\t"\ + "movq "MANGLE(ff_pw_5) ", %%mm4\n\t"\ + "movq "MANGLE(ff_pw_16)", %%mm5\n\t"\ "1: \n\t"\ "movd -1(%0), %%mm1 \n\t"\ "movd (%0), %%mm2 \n\t"\ @@ -976,7 +995,7 @@ static av_noinline void OPNAME ## h264_qpel4_h_lowpass_ ## MMX(uint8_t *dst, uin "decl %2 \n\t"\ " jnz 1b \n\t"\ : "+a"(src), "+c"(dst), "+g"(h)\ - : "d"((x86_reg)srcStride), "S"((x86_reg)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\ + : "d"((x86_reg)srcStride), "S"((x86_reg)dstStride)\ : "memory"\ );\ }\ @@ -1119,7 +1138,7 @@ static av_noinline void OPNAME ## h264_qpel8_h_lowpass_ ## MMX(uint8_t *dst, uin int h=8;\ __asm__ volatile(\ "pxor %%mm7, %%mm7 \n\t"\ - "movq %5, %%mm6 \n\t"\ + "movq "MANGLE(ff_pw_5)", %%mm6\n\t"\ "1: \n\t"\ "movq (%0), %%mm0 \n\t"\ "movq 1(%0), %%mm2 \n\t"\ @@ -1153,7 +1172,7 @@ static av_noinline void OPNAME ## h264_qpel8_h_lowpass_ ## MMX(uint8_t *dst, uin "punpcklbw %%mm7, %%mm5 \n\t"\ "paddw %%mm3, %%mm2 \n\t"\ "paddw %%mm5, %%mm4 \n\t"\ - "movq %6, %%mm5 \n\t"\ + "movq "MANGLE(ff_pw_16)", %%mm5\n\t"\ "paddw %%mm5, %%mm2 \n\t"\ "paddw %%mm5, %%mm4 \n\t"\ "paddw %%mm2, %%mm0 \n\t"\ @@ -1167,7 +1186,7 @@ static av_noinline void OPNAME ## h264_qpel8_h_lowpass_ ## MMX(uint8_t *dst, uin "decl %2 \n\t"\ " jnz 1b \n\t"\ : "+a"(src), "+c"(dst), "+g"(h)\ - : "d"((x86_reg)srcStride), "S"((x86_reg)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\ + : "d"((x86_reg)srcStride), "S"((x86_reg)dstStride)\ : "memory"\ );\ }\ @@ -1621,7 +1640,7 @@ static av_noinline void OPNAME ## h264_qpel8_h_lowpass_ ## MMX(uint8_t *dst, uin int h=8;\ __asm__ volatile(\ "pxor %%xmm7, %%xmm7 \n\t"\ - "movdqa %5, %%xmm6 \n\t"\ + "movdqa "MANGLE(ff_pw_5)", %%xmm6\n\t"\ "1: \n\t"\ "lddqu -2(%0), %%xmm1 \n\t"\ "movdqa %%xmm1, %%xmm0 \n\t"\ @@ -1641,7 +1660,7 @@ static av_noinline void OPNAME ## h264_qpel8_h_lowpass_ ## MMX(uint8_t *dst, uin "paddw %%xmm4, %%xmm1 \n\t"\ "psllw $2, %%xmm2 \n\t"\ "psubw %%xmm1, %%xmm2 \n\t"\ - "paddw %6, %%xmm0 \n\t"\ + "paddw "MANGLE(ff_pw_16)", %%xmm0\n\t"\ "pmullw %%xmm6, %%xmm2 \n\t"\ "paddw %%xmm0, %%xmm2 \n\t"\ "psraw $5, %%xmm2 \n\t"\ @@ -1652,8 +1671,7 @@ static av_noinline void OPNAME ## h264_qpel8_h_lowpass_ ## MMX(uint8_t *dst, uin "decl %2 \n\t"\ " jnz 1b \n\t"\ : "+a"(src), "+c"(dst), "+g"(h)\ - : "D"((x86_reg)srcStride), "S"((x86_reg)dstStride),\ - "m"(ff_pw_5), "m"(ff_pw_16)\ + : "D"((x86_reg)srcStride), "S"((x86_reg)dstStride)\ : "memory"\ );\ }\ @@ -1951,7 +1969,7 @@ static void OPNAME ## h264_qpel ## SIZE ## _mc30_ ## MMX(uint8_t *dst, uint8_t * #define H264_MC_V(OPNAME, SIZE, MMX, ALIGN) \ static void OPNAME ## h264_qpel ## SIZE ## _mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED(ALIGN, uint8_t, temp[SIZE*SIZE]);\ + DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*SIZE];\ put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src, SIZE, stride);\ OPNAME ## pixels ## SIZE ## _l2_ ## MMX(dst, src, temp, stride, stride, SIZE);\ }\ @@ -1961,43 +1979,43 @@ static void OPNAME ## h264_qpel ## SIZE ## _mc02_ ## MMX(uint8_t *dst, uint8_t * }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED(ALIGN, uint8_t, temp[SIZE*SIZE]);\ + DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*SIZE];\ put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src, SIZE, stride);\ OPNAME ## pixels ## SIZE ## _l2_ ## MMX(dst, src+stride, temp, stride, stride, SIZE);\ }\ #define H264_MC_HV(OPNAME, SIZE, MMX, ALIGN) \ static void OPNAME ## h264_qpel ## SIZE ## _mc11_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED(ALIGN, uint8_t, temp[SIZE*SIZE]);\ + DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*SIZE];\ put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src, SIZE, stride);\ OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, temp, stride, SIZE);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc31_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED(ALIGN, uint8_t, temp[SIZE*SIZE]);\ + DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*SIZE];\ put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src+1, SIZE, stride);\ OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, temp, stride, SIZE);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc13_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED(ALIGN, uint8_t, temp[SIZE*SIZE]);\ + DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*SIZE];\ put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src, SIZE, stride);\ OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src+stride, temp, stride, SIZE);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc33_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED(ALIGN, uint8_t, temp[SIZE*SIZE]);\ + DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*SIZE];\ put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src+1, SIZE, stride);\ OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src+stride, temp, stride, SIZE);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc22_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED(ALIGN, uint16_t, temp[SIZE*(SIZE<8?12:24)]);\ + DECLARE_ALIGNED(ALIGN, uint16_t, temp)[SIZE*(SIZE<8?12:24)];\ OPNAME ## h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(dst, temp, src, stride, SIZE, stride);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc21_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED(ALIGN, uint8_t, temp[SIZE*(SIZE<8?12:24)*2 + SIZE*SIZE]);\ + DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*(SIZE<8?12:24)*2 + SIZE*SIZE];\ uint8_t * const halfHV= temp;\ int16_t * const halfV= (int16_t*)(temp + SIZE*SIZE);\ assert(((int)temp & 7) == 0);\ @@ -2006,7 +2024,7 @@ static void OPNAME ## h264_qpel ## SIZE ## _mc21_ ## MMX(uint8_t *dst, uint8_t * }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED(ALIGN, uint8_t, temp[SIZE*(SIZE<8?12:24)*2 + SIZE*SIZE]);\ + DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*(SIZE<8?12:24)*2 + SIZE*SIZE];\ uint8_t * const halfHV= temp;\ int16_t * const halfV= (int16_t*)(temp + SIZE*SIZE);\ assert(((int)temp & 7) == 0);\ @@ -2015,7 +2033,7 @@ static void OPNAME ## h264_qpel ## SIZE ## _mc23_ ## MMX(uint8_t *dst, uint8_t * }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc12_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED(ALIGN, uint8_t, temp[SIZE*(SIZE<8?12:24)*2 + SIZE*SIZE]);\ + DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*(SIZE<8?12:24)*2 + SIZE*SIZE];\ uint8_t * const halfHV= temp;\ int16_t * const halfV= (int16_t*)(temp + SIZE*SIZE);\ assert(((int)temp & 7) == 0);\ @@ -2024,7 +2042,7 @@ static void OPNAME ## h264_qpel ## SIZE ## _mc12_ ## MMX(uint8_t *dst, uint8_t * }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ - DECLARE_ALIGNED(ALIGN, uint8_t, temp[SIZE*(SIZE<8?12:24)*2 + SIZE*SIZE]);\ + DECLARE_ALIGNED(ALIGN, uint8_t, temp)[SIZE*(SIZE<8?12:24)*2 + SIZE*SIZE];\ uint8_t * const halfHV= temp;\ int16_t * const halfV= (int16_t*)(temp + SIZE*SIZE);\ assert(((int)temp & 7) == 0);\ @@ -2087,7 +2105,7 @@ H264_MC_816(H264_MC_HV, ssse3) #endif /* rnd interleaved with rnd div 8, use p+1 to access rnd div 8 */ -DECLARE_ALIGNED_8(static const uint64_t, h264_rnd_reg[4]) = { +DECLARE_ALIGNED(8, static const uint64_t, h264_rnd_reg)[4] = { 0x0020002000200020ULL, 0x0004000400040004ULL, 0x001C001C001C001CULL, 0x0003000300030003ULL }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/idct_mmx.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/idct_mmx.c index aed934c04d..d6ab04e8d2 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/idct_mmx.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/idct_mmx.c @@ -23,10 +23,9 @@ #include "libavutil/common.h" #include "libavcodec/dsputil.h" +#include "dsputil_mmx.h" #include "mmx.h" -#define ATTR_ALIGN(align) __attribute__ ((__aligned__ (align))) - #define ROW_SHIFT 11 #define COL_SHIFT 6 @@ -399,10 +398,10 @@ static inline void idct_col (int16_t * const col, const int offset) #define T3 43790 #define C4 23170 - static const short t1_vector[] ATTR_ALIGN(8) = {T1,T1,T1,T1}; - static const short t2_vector[] ATTR_ALIGN(8) = {T2,T2,T2,T2}; - static const short t3_vector[] ATTR_ALIGN(8) = {T3,T3,T3,T3}; - static const short c4_vector[] ATTR_ALIGN(8) = {C4,C4,C4,C4}; + DECLARE_ALIGNED(8, static const short, t1_vector)[] = {T1,T1,T1,T1}; + DECLARE_ALIGNED(8, static const short, t2_vector)[] = {T2,T2,T2,T2}; + DECLARE_ALIGNED(8, static const short, t3_vector)[] = {T3,T3,T3,T3}; + DECLARE_ALIGNED(8, static const short, c4_vector)[] = {C4,C4,C4,C4}; /* column code adapted from Peter Gubanov */ /* http://www.elecard.com/peter/idct.shtml */ @@ -541,20 +540,20 @@ static inline void idct_col (int16_t * const col, const int offset) } -static const int32_t rounder0[] ATTR_ALIGN(8) = +DECLARE_ALIGNED(8, static const int32_t, rounder0)[] = rounder ((1 << (COL_SHIFT - 1)) - 0.5); -static const int32_t rounder4[] ATTR_ALIGN(8) = rounder (0); -static const int32_t rounder1[] ATTR_ALIGN(8) = +DECLARE_ALIGNED(8, static const int32_t, rounder4)[] = rounder (0); +DECLARE_ALIGNED(8, static const int32_t, rounder1)[] = rounder (1.25683487303); /* C1*(C1/C4+C1+C7)/2 */ -static const int32_t rounder7[] ATTR_ALIGN(8) = +DECLARE_ALIGNED(8, static const int32_t, rounder7)[] = rounder (-0.25); /* C1*(C7/C4+C7-C1)/2 */ -static const int32_t rounder2[] ATTR_ALIGN(8) = +DECLARE_ALIGNED(8, static const int32_t, rounder2)[] = rounder (0.60355339059); /* C2 * (C6+C2)/2 */ -static const int32_t rounder6[] ATTR_ALIGN(8) = +DECLARE_ALIGNED(8, static const int32_t, rounder6)[] = rounder (-0.25); /* C2 * (C6-C2)/2 */ -static const int32_t rounder3[] ATTR_ALIGN(8) = +DECLARE_ALIGNED(8, static const int32_t, rounder3)[] = rounder (0.087788325588); /* C3*(-C3/C4+C3+C5)/2 */ -static const int32_t rounder5[] ATTR_ALIGN(8) = +DECLARE_ALIGNED(8, static const int32_t, rounder5)[] = rounder (-0.441341716183); /* C3*(-C5/C4+C5-C3)/2 */ #undef COL_SHIFT @@ -563,13 +562,13 @@ static const int32_t rounder5[] ATTR_ALIGN(8) = #define declare_idct(idct,table,idct_row_head,idct_row,idct_row_tail,idct_row_mid) \ void idct (int16_t * const block) \ { \ - static const int16_t table04[] ATTR_ALIGN(16) = \ + DECLARE_ALIGNED(16, static const int16_t, table04)[] = \ table (22725, 21407, 19266, 16384, 12873, 8867, 4520); \ - static const int16_t table17[] ATTR_ALIGN(16) = \ + DECLARE_ALIGNED(16, static const int16_t, table17)[] = \ table (31521, 29692, 26722, 22725, 17855, 12299, 6270); \ - static const int16_t table26[] ATTR_ALIGN(16) = \ + DECLARE_ALIGNED(16, static const int16_t, table26)[] = \ table (29692, 27969, 25172, 21407, 16819, 11585, 5906); \ - static const int16_t table35[] ATTR_ALIGN(16) = \ + DECLARE_ALIGNED(16, static const int16_t, table35)[] = \ table (26722, 25172, 22654, 19266, 15137, 10426, 5315); \ \ idct_row_head (block, 0*8, table04); \ @@ -594,9 +593,6 @@ void idct (int16_t * const block) \ idct_col (block, 4); \ } -void ff_mmx_idct(DCTELEM *block); -void ff_mmxext_idct(DCTELEM *block); - declare_idct (ff_mmxext_idct, mmxext_table, mmxext_row_head, mmxext_row, mmxext_row_tail, mmxext_row_mid) diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/idct_mmx_xvid.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/idct_mmx_xvid.c index d4fdd7a54a..466cf75bc4 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/idct_mmx_xvid.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/idct_mmx_xvid.c @@ -41,6 +41,7 @@ #include #include "libavcodec/avcodec.h" +#include "idct_xvid.h" //============================================================================= // Macros and other preprocessor constants @@ -64,13 +65,13 @@ //----------------------------------------------------------------------------- -DECLARE_ALIGNED(8, static const int16_t, tg_1_16[4*4]) = { +DECLARE_ALIGNED(8, static const int16_t, tg_1_16)[4*4] = { 13036,13036,13036,13036, // tg * (2<<16) + 0.5 27146,27146,27146,27146, // tg * (2<<16) + 0.5 -21746,-21746,-21746,-21746, // tg * (2<<16) + 0.5 23170,23170,23170,23170}; // cos * (2<<15) + 0.5 -DECLARE_ALIGNED(8, static const int32_t, rounder_0[2*8]) = { +DECLARE_ALIGNED(8, static const int32_t, rounder_0)[2*8] = { 65536,65536, 3597,3597, 2260,2260, @@ -140,7 +141,7 @@ DECLARE_ALIGNED(8, static const int32_t, rounder_0[2*8]) = { //----------------------------------------------------------------------------- // Table for rows 0,4 - constants are multiplied by cos_4_16 -DECLARE_ALIGNED(8, static const int16_t, tab_i_04_mmx[32*4]) = { +DECLARE_ALIGNED(8, static const int16_t, tab_i_04_mmx)[32*4] = { 16384,16384,16384,-16384, // movq-> w06 w04 w02 w00 21407,8867,8867,-21407, // w07 w05 w03 w01 16384,-16384,16384,16384, // w14 w12 w10 w08 @@ -182,7 +183,7 @@ DECLARE_ALIGNED(8, static const int16_t, tab_i_04_mmx[32*4]) = { //----------------------------------------------------------------------------- // %3 for rows 0,4 - constants are multiplied by cos_4_16 -DECLARE_ALIGNED(8, static const int16_t, tab_i_04_xmm[32*4]) = { +DECLARE_ALIGNED(8, static const int16_t, tab_i_04_xmm)[32*4] = { 16384,21407,16384,8867, // movq-> w05 w04 w01 w00 16384,8867,-16384,-21407, // w07 w06 w03 w02 16384,-8867,16384,-21407, // w13 w12 w09 w08 diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/idct_sse2_xvid.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/idct_sse2_xvid.c index 4b83a44d18..fc670e25d4 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/idct_sse2_xvid.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/idct_sse2_xvid.c @@ -40,9 +40,10 @@ #include "libavcodec/dsputil.h" #include "idct_xvid.h" +#include "dsputil_mmx.h" /*! - * @file libavcodec/x86/idct_sse2_xvid.c + * @file * @brief SSE2 idct compatible with xvidmmx */ @@ -51,41 +52,41 @@ #define ROW_SHIFT 11 #define COL_SHIFT 6 -DECLARE_ASM_CONST(16, int16_t, tan1[]) = {X8(13036)}; // tan( pi/16) -DECLARE_ASM_CONST(16, int16_t, tan2[]) = {X8(27146)}; // tan(2pi/16) = sqrt(2)-1 -DECLARE_ASM_CONST(16, int16_t, tan3[]) = {X8(43790)}; // tan(3pi/16)-1 -DECLARE_ASM_CONST(16, int16_t, sqrt2[])= {X8(23170)}; // 0.5/sqrt(2) -DECLARE_ASM_CONST(8, uint8_t, m127[]) = {X8(127)}; +DECLARE_ASM_CONST(16, int16_t, tan1)[] = {X8(13036)}; // tan( pi/16) +DECLARE_ASM_CONST(16, int16_t, tan2)[] = {X8(27146)}; // tan(2pi/16) = sqrt(2)-1 +DECLARE_ASM_CONST(16, int16_t, tan3)[] = {X8(43790)}; // tan(3pi/16)-1 +DECLARE_ASM_CONST(16, int16_t, sqrt2)[]= {X8(23170)}; // 0.5/sqrt(2) +DECLARE_ASM_CONST(8, uint8_t, m127)[] = {X8(127)}; -DECLARE_ASM_CONST(16, int16_t, iTab1[]) = { +DECLARE_ASM_CONST(16, int16_t, iTab1)[] = { 0x4000, 0x539f, 0xc000, 0xac61, 0x4000, 0xdd5d, 0x4000, 0xdd5d, 0x4000, 0x22a3, 0x4000, 0x22a3, 0xc000, 0x539f, 0x4000, 0xac61, 0x3249, 0x11a8, 0x4b42, 0xee58, 0x11a8, 0x4b42, 0x11a8, 0xcdb7, 0x58c5, 0x4b42, 0xa73b, 0xcdb7, 0x3249, 0xa73b, 0x4b42, 0xa73b }; -DECLARE_ASM_CONST(16, int16_t, iTab2[]) = { +DECLARE_ASM_CONST(16, int16_t, iTab2)[] = { 0x58c5, 0x73fc, 0xa73b, 0x8c04, 0x58c5, 0xcff5, 0x58c5, 0xcff5, 0x58c5, 0x300b, 0x58c5, 0x300b, 0xa73b, 0x73fc, 0x58c5, 0x8c04, 0x45bf, 0x187e, 0x6862, 0xe782, 0x187e, 0x6862, 0x187e, 0xba41, 0x7b21, 0x6862, 0x84df, 0xba41, 0x45bf, 0x84df, 0x6862, 0x84df }; -DECLARE_ASM_CONST(16, int16_t, iTab3[]) = { +DECLARE_ASM_CONST(16, int16_t, iTab3)[] = { 0x539f, 0x6d41, 0xac61, 0x92bf, 0x539f, 0xd2bf, 0x539f, 0xd2bf, 0x539f, 0x2d41, 0x539f, 0x2d41, 0xac61, 0x6d41, 0x539f, 0x92bf, 0x41b3, 0x1712, 0x6254, 0xe8ee, 0x1712, 0x6254, 0x1712, 0xbe4d, 0x73fc, 0x6254, 0x8c04, 0xbe4d, 0x41b3, 0x8c04, 0x6254, 0x8c04 }; -DECLARE_ASM_CONST(16, int16_t, iTab4[]) = { +DECLARE_ASM_CONST(16, int16_t, iTab4)[] = { 0x4b42, 0x6254, 0xb4be, 0x9dac, 0x4b42, 0xd746, 0x4b42, 0xd746, 0x4b42, 0x28ba, 0x4b42, 0x28ba, 0xb4be, 0x6254, 0x4b42, 0x9dac, 0x3b21, 0x14c3, 0x587e, 0xeb3d, 0x14c3, 0x587e, 0x14c3, 0xc4df, 0x6862, 0x587e, 0x979e, 0xc4df, 0x3b21, 0x979e, 0x587e, 0x979e }; -DECLARE_ASM_CONST(16, int32_t, walkenIdctRounders[]) = { +DECLARE_ASM_CONST(16, int32_t, walkenIdctRounders)[] = { 65536, 65536, 65536, 65536, 3597, 3597, 3597, 3597, 2260, 2260, 2260, 2260, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/idct_xvid.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/idct_xvid.h index 6e29f0d8da..5fdc20d3ea 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/idct_xvid.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/idct_xvid.h @@ -19,7 +19,7 @@ */ /*! - * @file libavcodec/x86/idct_xvid.h + * @file * header for Xvid IDCT functions */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/flacdsp_mmx.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/lpc_mmx.c similarity index 88% rename from src/add-ons/media/plugins/ffmpeg/libavcodec/x86/flacdsp_mmx.c rename to src/add-ons/media/plugins/ffmpeg/libavcodec/x86/lpc_mmx.c index 01c0d7ae8a..2ef5fa6de3 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/flacdsp_mmx.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/lpc_mmx.c @@ -1,5 +1,5 @@ /* - * MMX optimized FLAC DSP utils + * MMX optimized LPC DSP utils * Copyright (c) 2007 Loren Merritt * * This file is part of FFmpeg. @@ -65,7 +65,7 @@ static void apply_welch_window_sse2(const int32_t *data, int len, double *w_data #undef WELCH } -void ff_flac_compute_autocorr_sse2(const int32_t *data, int len, int lag, +void ff_lpc_compute_autocorr_sse2(const int32_t *data, int len, int lag, double *autoc) { double tmp[len + lag + 2]; @@ -89,12 +89,12 @@ void ff_flac_compute_autocorr_sse2(const int32_t *data, int len, int lag, "movsd "MANGLE(ff_pd_1)", %%xmm1 \n\t" "movsd "MANGLE(ff_pd_1)", %%xmm2 \n\t" "1: \n\t" - "movapd (%4,%0), %%xmm3 \n\t" - "movupd -8(%5,%0), %%xmm4 \n\t" - "movapd (%5,%0), %%xmm5 \n\t" + "movapd (%2,%0), %%xmm3 \n\t" + "movupd -8(%3,%0), %%xmm4 \n\t" + "movapd (%3,%0), %%xmm5 \n\t" "mulpd %%xmm3, %%xmm4 \n\t" "mulpd %%xmm3, %%xmm5 \n\t" - "mulpd -16(%5,%0), %%xmm3 \n\t" + "mulpd -16(%3,%0), %%xmm3 \n\t" "addpd %%xmm4, %%xmm1 \n\t" "addpd %%xmm5, %%xmm0 \n\t" "addpd %%xmm3, %%xmm2 \n\t" @@ -106,11 +106,12 @@ void ff_flac_compute_autocorr_sse2(const int32_t *data, int len, int lag, "addsd %%xmm3, %%xmm0 \n\t" "addsd %%xmm4, %%xmm1 \n\t" "addsd %%xmm5, %%xmm2 \n\t" - "movsd %%xmm0, %1 \n\t" - "movsd %%xmm1, %2 \n\t" - "movsd %%xmm2, %3 \n\t" - :"+&r"(i), "=m"(autoc[j]), "=m"(autoc[j+1]), "=m"(autoc[j+2]) - :"r"(data1+len), "r"(data1+len-j) + "movsd %%xmm0, (%1) \n\t" + "movsd %%xmm1, 8(%1) \n\t" + "movsd %%xmm2, 16(%1) \n\t" + :"+&r"(i) + :"r"(autoc+j), "r"(data1+len), "r"(data1+len-j) + :"memory" ); } else { __asm__ volatile( diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/mathops.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/mathops.h index a66c601878..5949dfe3d4 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/mathops.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/mathops.h @@ -31,17 +31,17 @@ "imull %3 \n\t"\ "shrdl %4, %%edx, %%eax \n\t"\ : "=a"(rt), "=d"(dummy)\ - : "a" ((int)ra), "rm" ((int)rb), "i"(shift));\ + : "a" ((int)(ra)), "rm" ((int)(rb)), "i"(shift));\ rt; }) #define MULH(ra, rb) \ ({ int rt, dummy;\ - __asm__ ("imull %3\n\t" : "=d"(rt), "=a"(dummy): "a" ((int)ra), "rm" ((int)rb));\ + __asm__ ("imull %3\n\t" : "=d"(rt), "=a"(dummy): "a" ((int)(ra)), "rm" ((int)(rb)));\ rt; }) #define MUL64(ra, rb) \ ({ int64_t rt;\ - __asm__ ("imull %2\n\t" : "=A"(rt) : "a" ((int)ra), "g" ((int)rb));\ + __asm__ ("imull %2\n\t" : "=A"(rt) : "a" ((int)(ra)), "g" ((int)(rb)));\ rt; }) #endif @@ -66,4 +66,35 @@ static inline av_const int mid_pred(int a, int b, int c) } #endif +#if HAVE_CMOV +#define COPY3_IF_LT(x, y, a, b, c, d)\ +__asm__ volatile(\ + "cmpl %0, %3 \n\t"\ + "cmovl %3, %0 \n\t"\ + "cmovl %4, %1 \n\t"\ + "cmovl %5, %2 \n\t"\ + : "+&r" (x), "+&r" (a), "+r" (c)\ + : "r" (y), "r" (b), "r" (d)\ +); +#endif + +// avoid +32 for shift optimization (gcc should do that ...) +#define NEG_SSR32 NEG_SSR32 +static inline int32_t NEG_SSR32( int32_t a, int8_t s){ + __asm__ ("sarl %1, %0\n\t" + : "+r" (a) + : "ic" ((uint8_t)(-s)) + ); + return a; +} + +#define NEG_USR32 NEG_USR32 +static inline uint32_t NEG_USR32(uint32_t a, int8_t s){ + __asm__ ("shrl %1, %0\n\t" + : "+r" (a) + : "ic" ((uint8_t)(-s)) + ); + return a; +} + #endif /* AVCODEC_X86_MATHOPS_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/motion_est_mmx.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/motion_est_mmx.c index 4673ebc853..0272410dc5 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/motion_est_mmx.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/motion_est_mmx.c @@ -24,8 +24,9 @@ #include "libavutil/x86_cpu.h" #include "libavcodec/dsputil.h" +#include "dsputil_mmx.h" -DECLARE_ASM_CONST(8, uint64_t, round_tab[3])={ +DECLARE_ASM_CONST(8, uint64_t, round_tab)[3]={ 0x0000000000000000ULL, 0x0001000100010001ULL, 0x0002000200020002ULL, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/mpegvideo_mmx_template.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/mpegvideo_mmx_template.c index dbc94d36dc..0d927921e2 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/mpegvideo_mmx_template.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/mpegvideo_mmx_template.c @@ -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]); + DECLARE_ALIGNED(16, int16_t, temp_block)[64]; assert((7&(int)(&temp_block[0])) == 0); //did gcc align it correctly? diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/rv40dsp_mmx.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/rv40dsp_mmx.c index 47461c68aa..2b154c0a0b 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/rv40dsp_mmx.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/rv40dsp_mmx.c @@ -24,7 +24,7 @@ #include "dsputil_mmx.h" /* bias interleaved with bias div 8, use p+1 to access bias div 8 */ -DECLARE_ALIGNED_8(static const uint64_t, rv40_bias_reg[4][8]) = { +DECLARE_ALIGNED(8, static const uint64_t, rv40_bias_reg)[4][8] = { { 0x0000000000000000ULL, 0x0000000000000000ULL, 0x0010001000100010ULL, 0x0002000200020002ULL, 0x0020002000200020ULL, 0x0004000400040004ULL, 0x0010001000100010ULL, 0x0002000200020002ULL }, { 0x0020002000200020ULL, 0x0004000400040004ULL, 0x001C001C001C001CULL, 0x0003000300030003ULL, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/simple_idct_mmx.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/simple_idct_mmx.c index 578674451a..5ea4c84ed9 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/simple_idct_mmx.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/simple_idct_mmx.c @@ -21,6 +21,7 @@ */ #include "libavcodec/dsputil.h" #include "libavcodec/simple_idct.h" +#include "dsputil_mmx.h" /* 23170.475006 @@ -51,7 +52,7 @@ DECLARE_ASM_CONST(8, uint64_t, wm1010)= 0xFFFF0000FFFF0000ULL; DECLARE_ASM_CONST(8, uint64_t, d40000)= 0x0000000000040000ULL; -DECLARE_ALIGNED(8, static const int16_t, coeffs[])= { +DECLARE_ALIGNED(8, static const int16_t, coeffs)[]= { 1<<(ROW_SHIFT-1), 0, 1<<(ROW_SHIFT-1), 0, // 1<<(COL_SHIFT-1), 0, 1<<(COL_SHIFT-1), 0, // 0, 1<<(COL_SHIFT-1-16), 0, 1<<(COL_SHIFT-1-16), @@ -210,7 +211,7 @@ row[7] = input[13]; static inline void idct(int16_t *block) { - DECLARE_ALIGNED(8, int64_t, align_tmp[16]); + DECLARE_ALIGNED(8, int64_t, align_tmp)[16]; int16_t * const temp= (int16_t*)align_tmp; __asm__ volatile( diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/snowdsp_mmx.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/snowdsp_mmx.c index e7868eae9d..263f0bbf69 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/snowdsp_mmx.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/snowdsp_mmx.c @@ -22,10 +22,12 @@ #include "libavutil/x86_cpu.h" #include "libavcodec/avcodec.h" #include "libavcodec/snow.h" +#include "libavcodec/dwt.h" +#include "dsputil_mmx.h" -void ff_snow_horizontal_compose97i_sse2(IDWTELEM *b, int width){ +static void ff_snow_horizontal_compose97i_sse2(IDWTELEM *b, int width){ const int w2= (width+1)>>1; - DECLARE_ALIGNED_16(IDWTELEM, temp[width>>1]); + DECLARE_ALIGNED(16, IDWTELEM, temp)[width>>1]; const int w_l= (width>>1); const int w_r= w2 - 1; int i; @@ -212,7 +214,7 @@ void ff_snow_horizontal_compose97i_sse2(IDWTELEM *b, int width){ } } -void ff_snow_horizontal_compose97i_mmx(IDWTELEM *b, int width){ +static void ff_snow_horizontal_compose97i_mmx(IDWTELEM *b, int width){ const int w2= (width+1)>>1; IDWTELEM temp[width >> 1]; const int w_l= (width>>1); @@ -435,7 +437,7 @@ void ff_snow_horizontal_compose97i_mmx(IDWTELEM *b, int width){ "movdqa %%"s2", %%"t2" \n\t"\ "movdqa %%"s3", %%"t3" \n\t" -void ff_snow_vertical_compose97i_sse2(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width){ +static void ff_snow_vertical_compose97i_sse2(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width){ x86_reg i = width; while(i & 0x1F) @@ -533,7 +535,7 @@ void ff_snow_vertical_compose97i_sse2(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, "movq %%"s3", %%"t3" \n\t" -void ff_snow_vertical_compose97i_mmx(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width){ +static void ff_snow_vertical_compose97i_mmx(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width){ x86_reg i = width; while(i & 15) { @@ -846,7 +848,7 @@ snow_inner_add_yblock_mmx_mix("16", "8") snow_inner_add_yblock_mmx_end("32") } -void ff_snow_inner_add_yblock_sse2(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h, +static void ff_snow_inner_add_yblock_sse2(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h, int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8){ if (b_w == 16) @@ -860,7 +862,7 @@ void ff_snow_inner_add_yblock_sse2(const uint8_t *obmc, const int obmc_stride, u ff_snow_inner_add_yblock(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8); } -void ff_snow_inner_add_yblock_mmx(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h, +static void ff_snow_inner_add_yblock_mmx(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h, int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8){ if (b_w == 16) inner_add_yblock_bw_16_obmc_32_mmx(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8); @@ -869,3 +871,27 @@ void ff_snow_inner_add_yblock_mmx(const uint8_t *obmc, const int obmc_stride, ui else ff_snow_inner_add_yblock(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8); } + +void ff_dwt_init_x86(DWTContext *c) +{ + mm_flags = mm_support(); + + if (mm_flags & FF_MM_MMX) { + if(mm_flags & FF_MM_SSE2 & 0){ + c->horizontal_compose97i = ff_snow_horizontal_compose97i_sse2; +#if HAVE_7REGS + c->vertical_compose97i = ff_snow_vertical_compose97i_sse2; +#endif + c->inner_add_yblock = ff_snow_inner_add_yblock_sse2; + } + else{ + if(mm_flags & FF_MM_MMX2){ + c->horizontal_compose97i = ff_snow_horizontal_compose97i_mmx; +#if HAVE_7REGS + c->vertical_compose97i = ff_snow_vertical_compose97i_mmx; +#endif + } + c->inner_add_yblock = ff_snow_inner_add_yblock_mmx; + } + } +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/vc1dsp_mmx.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/vc1dsp_mmx.c index 3071d02808..e0b1f5b99a 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/vc1dsp_mmx.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/vc1dsp_mmx.c @@ -73,7 +73,7 @@ "movq %%mm"#R1", "#OFF"(%1) \n\t" \ "add %2, %0 \n\t" -DECLARE_ALIGNED_16(const uint64_t, ff_pw_9) = 0x0009000900090009ULL; +DECLARE_ALIGNED(16, const uint64_t, ff_pw_9) = 0x0009000900090009ULL; /** Sacrifying mm6 allows to pipeline loads from src */ static void vc1_put_ver_16b_shift2_mmx(int16_t *dst, @@ -442,7 +442,7 @@ static void OP ## vc1_mspel_mc(uint8_t *dst, const uint8_t *src, int stride,\ static const int shift_value[] = { 0, 5, 1, 5 };\ int shift = (shift_value[hmode]+shift_value[vmode])>>1;\ int r;\ - DECLARE_ALIGNED_16(int16_t, tmp[12*8]);\ + DECLARE_ALIGNED(16, int16_t, tmp)[12*8];\ \ r = (1<<(shift-1)) + rnd-1;\ vc1_put_shift_ver_16bits[vmode](tmp, src-1, stride, r, shift);\ @@ -463,9 +463,6 @@ static void OP ## vc1_mspel_mc(uint8_t *dst, const uint8_t *src, int stride,\ VC1_MSPEL_MC(put_) VC1_MSPEL_MC(avg_) -void ff_put_vc1_mspel_mc00_mmx(uint8_t *dst, const uint8_t *src, int stride, int rnd); -void ff_avg_vc1_mspel_mc00_mmx2(uint8_t *dst, const uint8_t *src, int stride, int rnd); - /** Macro to ease bicubic filter interpolation functions declarations */ #define DECLARE_FUNCTION(a, b) \ static void put_vc1_mspel_mc ## a ## b ## _mmx(uint8_t *dst, const uint8_t *src, int stride, int rnd) { \ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/vp3dsp_mmx.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/vp3dsp_mmx.c index 27d4640217..44a8477a89 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/vp3dsp_mmx.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/vp3dsp_mmx.c @@ -19,13 +19,14 @@ */ /** - * @file libavcodec/x86/vp3dsp_mmx.c + * @file * MMX-optimized functions cribbed from the original VP3 source code. */ #include "libavutil/x86_cpu.h" #include "libavcodec/dsputil.h" #include "dsputil_mmx.h" +#include "vp3dsp_mmx.h" extern const uint16_t ff_vp3_idct_data[]; @@ -394,3 +395,44 @@ void ff_vp3_idct_add_mmx(uint8_t *dest, int line_size, DCTELEM *block) ff_vp3_idct_mmx(block); add_pixels_clamped_mmx(block, dest, line_size); } + +void ff_vp3_idct_dc_add_mmx2(uint8_t *dest, int linesize, const DCTELEM *block) +{ + int dc = block[0]; + dc = (46341*dc)>>16; + dc = (46341*dc + (8<<16))>>20; + + __asm__ volatile( + "movd %3, %%mm0 \n\t" + "pshufw $0, %%mm0, %%mm0 \n\t" + "pxor %%mm1, %%mm1 \n\t" + "psubw %%mm0, %%mm1 \n\t" + "packuswb %%mm0, %%mm0 \n\t" + "packuswb %%mm1, %%mm1 \n\t" + +#define DC_ADD \ + "movq (%0), %%mm2 \n\t" \ + "movq (%0,%1), %%mm3 \n\t" \ + "paddusb %%mm0, %%mm2 \n\t" \ + "movq (%0,%1,2), %%mm4 \n\t" \ + "paddusb %%mm0, %%mm3 \n\t" \ + "movq (%0,%2), %%mm5 \n\t" \ + "paddusb %%mm0, %%mm4 \n\t" \ + "paddusb %%mm0, %%mm5 \n\t" \ + "psubusb %%mm1, %%mm2 \n\t" \ + "psubusb %%mm1, %%mm3 \n\t" \ + "movq %%mm2, (%0) \n\t" \ + "psubusb %%mm1, %%mm4 \n\t" \ + "movq %%mm3, (%0,%1) \n\t" \ + "psubusb %%mm1, %%mm5 \n\t" \ + "movq %%mm4, (%0,%1,2) \n\t" \ + "movq %%mm5, (%0,%2) \n\t" + + DC_ADD + "lea (%0,%1,4), %0 \n\t" + DC_ADD + + : "+r"(dest) + : "r"((x86_reg)linesize), "r"((x86_reg)3*linesize), "r"(dc) + ); +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/vp3dsp_mmx.h b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/vp3dsp_mmx.h index e565a33023..e0ebf0b0f4 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/vp3dsp_mmx.h +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/vp3dsp_mmx.h @@ -28,6 +28,7 @@ void ff_vp3_idct_mmx(int16_t *data); void ff_vp3_idct_put_mmx(uint8_t *dest, int line_size, DCTELEM *block); void ff_vp3_idct_add_mmx(uint8_t *dest, int line_size, DCTELEM *block); +void ff_vp3_idct_dc_add_mmx2(uint8_t *dest, int line_size, const DCTELEM *block); void ff_vp3_v_loop_filter_mmx2(uint8_t *src, int stride, int *bounding_values); void ff_vp3_h_loop_filter_mmx2(uint8_t *src, int stride, int *bounding_values); diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/vp3dsp_sse2.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/vp3dsp_sse2.c index 6f90dc6ed1..e0ebd42427 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/vp3dsp_sse2.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/vp3dsp_sse2.c @@ -19,14 +19,15 @@ */ /** - * @file libavcodec/x86/vp3dsp_sse2.c + * @file * SSE2-optimized functions cribbed from the original VP3 source code. */ #include "libavcodec/dsputil.h" #include "dsputil_mmx.h" +#include "vp3dsp_sse2.h" -DECLARE_ALIGNED_16(const uint16_t, ff_vp3_idct_data[7 * 8]) = +DECLARE_ALIGNED(16, const uint16_t, ff_vp3_idct_data)[7 * 8] = { 64277,64277,64277,64277,64277,64277,64277,64277, 60547,60547,60547,60547,60547,60547,60547,60547, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/vp6dsp_mmx.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/vp6dsp_mmx.c index 39e40d568e..905b3a7f0d 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/vp6dsp_mmx.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/vp6dsp_mmx.c @@ -1,5 +1,5 @@ /** - * @file libavcodec/x86/vp6dsp_mmx.c + * @file * MMX-optimized functions for the VP6 decoder * * Copyright (C) 2009 Sebastien Lucas diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/vp6dsp_sse2.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/vp6dsp_sse2.c index c72a0cacb8..bfd733aa7f 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/vp6dsp_sse2.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/vp6dsp_sse2.c @@ -1,5 +1,5 @@ /** - * @file libavcodec/x86/vp6dsp_mmx.c + * @file * SSE2-optimized functions for the VP6 decoder * * Copyright (C) 2009 Zuxy Meng diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/x86inc.asm b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/x86inc.asm index 52624c3aca..c29ef3ee34 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/x86inc.asm +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/x86/x86inc.asm @@ -53,7 +53,7 @@ ; in memory) must use an address mode that does fit. ; So all accesses to global variables must use this macro, e.g. ; mov eax, [foo GLOBAL] -; instead of +; instead of ; mov eax, [foo] ; ; x86_32 doesn't require PIC. @@ -84,7 +84,7 @@ ; PROLOGUE can also be invoked by adding the same options to cglobal ; e.g. -; cglobal foo, 2,3, dst, src, tmp +; cglobal foo, 2,3,0, dst, src, tmp ; declares a function (foo), taking two args (dst and src) and one local variable (tmp) ; TODO Some functions can use some args directly from the stack. If they're the @@ -221,6 +221,7 @@ DECLARE_REG_TMP_SIZE 0,1,2,3,4,5,6,7 CAT_UNDEF arg_name %+ %%i, d CAT_UNDEF arg_name %+ %%i, w CAT_UNDEF arg_name %+ %%i, b + CAT_UNDEF arg_name %+ %%i, m CAT_UNDEF arg_name, %%i %assign %%i %%i+1 %endrep @@ -232,6 +233,7 @@ DECLARE_REG_TMP_SIZE 0,1,2,3,4,5,6,7 %xdefine %1d r %+ %%i %+ d %xdefine %1w r %+ %%i %+ w %xdefine %1b r %+ %%i %+ b + %xdefine %1m r %+ %%i %+ m CAT_XDEFINE arg_name, %%i, %1 %assign %%i %%i+1 %rotate 1 @@ -436,6 +438,7 @@ DECLARE_REG 6, ebp, ebp, bp, null, [esp + stack_offset + 28] %ifdef PREFIX %xdefine %1 _ %+ %1 %endif + %xdefine %1.skip_prologue %1 %+ .skip_prologue %ifidn __OUTPUT_FORMAT__,elf global %1:function hidden %else @@ -597,9 +600,6 @@ INIT_MMX %endmacro ;Substitutions that reduce instruction size but are functionally equivalent -%define movdqa movaps -%define movdqu movups - %macro add 2 %ifnum %2 %if %2==128 diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/xan.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/xan.c index 91c22c3d2f..3f6aa8cee5 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/xan.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/xan.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/xan.c + * @file * Xan video decoder for Wing Commander III computer game * by Mario Brito (mbrito@student.dei.uc.pt) * and Mike Melanson (melanson@pcisys.net) @@ -74,15 +74,16 @@ static av_cold int xan_decode_init(AVCodecContext *avctx) avctx->pix_fmt = PIX_FMT_PAL8; - if(avcodec_check_dimensions(avctx, avctx->width, avctx->height)) - return -1; - s->buffer1_size = avctx->width * avctx->height; s->buffer1 = av_malloc(s->buffer1_size); + if (!s->buffer1) + return -1; s->buffer2_size = avctx->width * avctx->height; s->buffer2 = av_malloc(s->buffer2_size + 130); - if (!s->buffer1 || !s->buffer2) + if (!s->buffer2) { + av_freep(&s->buffer1); return -1; + } return 0; } @@ -156,12 +157,8 @@ static void xan_unpack(unsigned char *dest, const unsigned char *src, int dest_l av_memcpy_backptr(dest, back, size2); dest += size2; } else { - int finish; - size = ((opcode & 0x1f) << 2) + 4; - - finish = size > 0x70; - if (finish) - size = opcode & 3; + int finish = opcode >= 0xfc; + size = finish ? opcode & 3 : ((opcode & 0x1f) << 2) + 4; memcpy(dest, src, size); dest += size; src += size; if (finish) @@ -185,13 +182,14 @@ static inline void xan_wc3_output_pixel_run(XanContext *s, line_inc = stride - width; index = y * stride + x; current_x = x; - while((pixel_count--) && (index < s->frame_size)) { + while(pixel_count && (index < s->frame_size)) { + int count = FFMIN(pixel_count, width - current_x); + memcpy(palette_plane + index, pixel_buffer, count); + pixel_count -= count; + index += count; + pixel_buffer += count; + current_x += count; - /* don't do a memcpy() here; keyframes generally copy an entire - * frame of data and the stride needs to be accounted for */ - palette_plane[index++] = *pixel_buffer++; - - current_x++; if (current_x >= width) { index += line_inc; current_x = 0; @@ -217,18 +215,21 @@ static inline void xan_wc3_copy_pixel_run(XanContext *s, 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)) { + int count = FFMIN3(pixel_count, width - curframe_x, width - prevframe_x); - palette_plane[curframe_index++] = - prev_palette_plane[prevframe_index++]; + memcpy(palette_plane + curframe_index, prev_palette_plane + prevframe_index, count); + pixel_count -= count; + curframe_index += count; + prevframe_index += count; + curframe_x += count; + prevframe_x += count; - curframe_x++; if (curframe_x >= width) { curframe_index += line_inc; curframe_x = 0; } - prevframe_x++; if (prevframe_x >= width) { prevframe_index += line_inc; prevframe_x = 0; @@ -373,7 +374,7 @@ static int xan_decode_frame(AVCodecContext *avctx, palette_control->palette_changed = 0; memcpy(s->current_frame.data[1], palette_control->palette, - AVPALETTE_SIZE); + AVPALETTE_SIZE); s->current_frame.palette_has_changed = 1; s->buf = buf; @@ -408,15 +409,15 @@ static av_cold int xan_decode_end(AVCodecContext *avctx) if (s->current_frame.data[0]) avctx->release_buffer(avctx, &s->current_frame); - av_free(s->buffer1); - av_free(s->buffer2); + av_freep(&s->buffer1); + av_freep(&s->buffer2); return 0; } AVCodec xan_wc3_decoder = { "xan_wc3", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_XAN_WC3, sizeof(XanContext), xan_decode_init, @@ -430,7 +431,7 @@ AVCodec xan_wc3_decoder = { /* AVCodec xan_wc4_decoder = { "xan_wc4", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_XAN_WC4, sizeof(XanContext), xan_decode_init, @@ -438,5 +439,6 @@ AVCodec xan_wc4_decoder = { xan_decode_end, xan_decode_frame, CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Wing Commander IV / Xxan"), }; */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/xl.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/xl.c index fb4241f255..f7d025eca4 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/xl.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/xl.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/xl.c + * @file * Miro VideoXL codec. */ @@ -128,14 +128,24 @@ static av_cold int decode_init(AVCodecContext *avctx){ return 0; } +static av_cold int decode_end(AVCodecContext *avctx){ + VideoXLContext * const a = avctx->priv_data; + AVFrame *pic = &a->pic; + + if (pic->data[0]) + avctx->release_buffer(avctx, pic); + + return 0; +} + AVCodec xl_decoder = { "xl", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_VIXL, sizeof(VideoXLContext), decode_init, NULL, - NULL, + decode_end, decode_frame, CODEC_CAP_DR1, .long_name = NULL_IF_CONFIG_SMALL("Miro VideoXL"), diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/xsubdec.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/xsubdec.c index 368caf4a6d..0055ebb20b 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/xsubdec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/xsubdec.c @@ -132,7 +132,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVCodec xsub_decoder = { "xsub", - CODEC_TYPE_SUBTITLE, + AVMEDIA_TYPE_SUBTITLE, CODEC_ID_XSUB, 0, decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/xsubenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/xsubenc.c index 55fcb627f5..903cbd2098 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/xsubenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/xsubenc.c @@ -154,7 +154,7 @@ static int xsub_encode(AVCodecContext *avctx, unsigned char *buf, snprintf(buf, 28, "[%02d:%02d:%02d.%03d-%02d:%02d:%02d.%03d]", start_tc[3], start_tc[2], start_tc[1], start_tc[0], - end_tc[3], end_tc[3], end_tc[1], end_tc[0]); + end_tc[3], end_tc[2], end_tc[1], end_tc[0]); // Width and height must probably be multiples of 2. // 2 pixels required on either side of subtitle. @@ -212,7 +212,7 @@ static av_cold int xsub_encoder_init(AVCodecContext *avctx) AVCodec xsub_encoder = { "xsub", - CODEC_TYPE_SUBTITLE, + AVMEDIA_TYPE_SUBTITLE, CODEC_ID_XSUB, 0, xsub_encoder_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/yop.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/yop.c new file mode 100644 index 0000000000..1eb76b128e --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/yop.c @@ -0,0 +1,260 @@ +/** + * @file + * Psygnosis YOP decoder + * + * Copyright (C) 2010 Mohamed Naufal Basheer + * derived from the code by + * Copyright (C) 2009 Thomas P. Higdon + * + * 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 "avcodec.h" +#include "get_bits.h" + +typedef struct YopDecContext { + AVFrame frame; + AVCodecContext *avctx; + + int num_pal_colors; + int first_color[2]; + int frame_data_length; + int row_pos; + + uint8_t *low_nibble; + uint8_t *srcptr; + uint8_t *dstptr; + uint8_t *dstbuf; +} YopDecContext; + +// These tables are taken directly from: +// http://wiki.multimedia.cx/index.php?title=Psygnosis_YOP + +/** + * Lookup table for painting macroblocks. Bytes 0-2 of each entry contain + * the macroblock positions to be painted (taken as (0, B0, B1, B2)). + * Byte 3 contains the number of bytes consumed on the input, + * equal to max(bytes 0-2) + 1. + */ +static const uint8_t paint_lut[15][4] = + {{1, 2, 3, 4}, {1, 2, 0, 3}, + {1, 2, 1, 3}, {1, 2, 2, 3}, + {1, 0, 2, 3}, {1, 0, 0, 2}, + {1, 0, 1, 2}, {1, 1, 2, 3}, + {0, 1, 2, 3}, {0, 1, 0, 2}, + {1, 1, 0, 2}, {0, 1, 1, 2}, + {0, 0, 1, 2}, {0, 0, 0, 1}, + {1, 1, 1, 2}, + }; + +/** + * Lookup table for copying macroblocks. Each entry contains the respective + * x and y pixel offset for the copy source. + */ +static const int8_t motion_vector[16][2] = + {{-4, -4}, {-2, -4}, + { 0, -4}, { 2, -4}, + {-4, -2}, {-4, 0}, + {-3, -3}, {-1, -3}, + { 1, -3}, { 3, -3}, + {-3, -1}, {-2, -2}, + { 0, -2}, { 2, -2}, + { 4, -2}, {-2, 0}, + }; + +static av_cold int yop_decode_init(AVCodecContext *avctx) +{ + YopDecContext *s = avctx->priv_data; + s->avctx = avctx; + + if (avctx->width & 1 || avctx->height & 1 || + avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) { + av_log(avctx, AV_LOG_ERROR, "YOP has invalid dimensions\n"); + return -1; + } + + avctx->pix_fmt = PIX_FMT_PAL8; + + s->num_pal_colors = avctx->extradata[0]; + s->first_color[0] = avctx->extradata[1]; + s->first_color[1] = avctx->extradata[2]; + + if (s->num_pal_colors + s->first_color[0] > 256 || + s->num_pal_colors + s->first_color[1] > 256) { + av_log(avctx, AV_LOG_ERROR, + "YOP: palette parameters invalid, header probably corrupt\n"); + return AVERROR_INVALIDDATA; + } + + return 0; +} + +static av_cold int yop_decode_close(AVCodecContext *avctx) +{ + YopDecContext *s = avctx->priv_data; + if (s->frame.data[0]) + avctx->release_buffer(avctx, &s->frame); + return 0; +} + +/** + * Paints a macroblock using the pattern in paint_lut. + * @param s codec context + * @param tag the tag that was in the nibble + */ +static void yop_paint_block(YopDecContext *s, int tag) +{ + s->dstptr[0] = s->srcptr[0]; + s->dstptr[1] = s->srcptr[paint_lut[tag][0]]; + s->dstptr[s->frame.linesize[0]] = s->srcptr[paint_lut[tag][1]]; + s->dstptr[s->frame.linesize[0] + 1] = s->srcptr[paint_lut[tag][2]]; + + // The number of src bytes consumed is in the last part of the lut entry. + s->srcptr += paint_lut[tag][3]; +} + +/** + * Copies a previously painted macroblock to the current_block. + * @param copy_tag the tag that was in the nibble + */ +static int yop_copy_previous_block(YopDecContext *s, int copy_tag) +{ + uint8_t *bufptr; + + // Calculate position for the copy source + bufptr = s->dstptr + motion_vector[copy_tag][0] + + s->frame.linesize[0] * motion_vector[copy_tag][1]; + if (bufptr < s->dstbuf) { + av_log(s->avctx, AV_LOG_ERROR, + "YOP: cannot decode, file probably corrupt\n"); + return AVERROR_INVALIDDATA; + } + + s->dstptr[0] = bufptr[0]; + s->dstptr[1] = bufptr[1]; + s->dstptr[s->frame.linesize[0]] = bufptr[s->frame.linesize[0]]; + s->dstptr[s->frame.linesize[0] + 1] = bufptr[s->frame.linesize[0] + 1]; + + return 0; +} + +/** + * Returns the next nibble in sequence, consuming a new byte on the input + * only if necessary. + */ +static uint8_t yop_get_next_nibble(YopDecContext *s) +{ + int ret; + + if (s->low_nibble) { + ret = *s->low_nibble & 0xf; + s->low_nibble = NULL; + }else { + s->low_nibble = s->srcptr++; + ret = *s->low_nibble >> 4; + } + return ret; +} + +/** + * Takes s->dstptr to the next macroblock in sequence. + */ +static void yop_next_macroblock(YopDecContext *s) +{ + // If we are advancing to the next row of macroblocks + if (s->row_pos == s->frame.linesize[0] - 2) { + s->dstptr += s->frame.linesize[0]; + s->row_pos = 0; + }else { + s->row_pos += 2; + } + s->dstptr += 2; +} + +static int yop_decode_frame(AVCodecContext *avctx, void *data, int *data_size, + AVPacket *avpkt) +{ + YopDecContext *s = avctx->priv_data; + int tag, firstcolor, is_odd_frame; + int ret, i; + uint32_t *palette; + + if (s->frame.data[0]) + avctx->release_buffer(avctx, &s->frame); + + ret = avctx->get_buffer(avctx, &s->frame); + if (ret < 0) { + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return ret; + } + + s->frame.linesize[0] = avctx->width; + + s->dstbuf = s->frame.data[0]; + s->dstptr = s->frame.data[0]; + s->srcptr = avpkt->data + 4; + s->row_pos = 0; + s->low_nibble = NULL; + + is_odd_frame = avpkt->data[0]; + firstcolor = s->first_color[is_odd_frame]; + palette = (uint32_t *)s->frame.data[1]; + + for (i = 0; i < s->num_pal_colors; i++, s->srcptr += 3) + palette[i + firstcolor] = (s->srcptr[0] << 18) | + (s->srcptr[1] << 10) | + (s->srcptr[2] << 2); + + s->frame.palette_has_changed = 1; + + while (s->dstptr - s->dstbuf < + avctx->width * avctx->height && + s->srcptr - avpkt->data < avpkt->size) { + + tag = yop_get_next_nibble(s); + + if (tag != 0xf) { + yop_paint_block(s, tag); + }else { + tag = yop_get_next_nibble(s); + ret = yop_copy_previous_block(s, tag); + if (ret < 0) { + avctx->release_buffer(avctx, &s->frame); + return ret; + } + } + yop_next_macroblock(s); + } + + *data_size = sizeof(AVFrame); + *(AVFrame *) data = s->frame; + return avpkt->size; +} + +AVCodec yop_decoder = { + "yop", + AVMEDIA_TYPE_VIDEO, + CODEC_ID_YOP, + sizeof(YopDecContext), + yop_decode_init, + NULL, + yop_decode_close, + yop_decode_frame, + .long_name = NULL_IF_CONFIG_SMALL("Psygnosis YOP Video"), +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/zmbv.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/zmbv.c index de2eb9c4c6..8af8c840a0 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/zmbv.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/zmbv.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/zmbv.c + * @file * Zip Motion Blocks Video decoder */ @@ -434,6 +434,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac } if(c->bw == 0 || c->bh == 0) { av_log(avctx, AV_LOG_ERROR, "Unsupported block size %ix%i\n", c->bw, c->bh); + return -1; } if(c->comp != 0 && c->comp != 1) { av_log(avctx, AV_LOG_ERROR, "Unsupported compression type %i\n", c->comp); @@ -602,9 +603,6 @@ static av_cold int decode_init(AVCodecContext *avctx) c->width = avctx->width; c->height = avctx->height; - if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) { - return 1; - } c->bpp = avctx->bits_per_coded_sample; // Needed if zlib unused or init aborted before inflateInit @@ -657,7 +655,7 @@ static av_cold int decode_end(AVCodecContext *avctx) AVCodec zmbv_decoder = { "zmbv", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_ZMBV, sizeof(ZmbvContext), decode_init, diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/zmbvenc.c b/src/add-ons/media/plugins/ffmpeg/libavcodec/zmbvenc.c index 21882d503f..95f2906268 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/zmbvenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavcodec/zmbvenc.c @@ -20,7 +20,7 @@ */ /** - * @file libavcodec/zmbvenc.c + * @file * Zip Motion Blocks Video encoder */ @@ -61,21 +61,26 @@ static int score_tab[256]; * XXX should be optimized and moved to DSPContext * TODO handle out of edge ME */ -static inline int block_cmp(uint8_t *src, int stride, uint8_t *src2, int stride2, int bw, int bh) +static inline int block_cmp(uint8_t *src, int stride, uint8_t *src2, int stride2, + int bw, int bh, int *xored) { int sum = 0; int i, j; - uint8_t histogram[256]={0}; + uint8_t histogram[256] = {0}; + *xored = 0; for(j = 0; j < bh; j++){ - for(i = 0; i < bw; i++) - histogram[src[i] ^ src2[i]]++; + for(i = 0; i < bw; i++){ + int t = src[i] ^ src2[i]; + histogram[t]++; + *xored |= t; + } src += stride; src2 += stride2; } - for(i=1; i<256; i++) - sum+= score_tab[histogram[i]]; + for(i = 1; i < 256; i++) + sum += score_tab[histogram[i]]; return sum; } @@ -83,22 +88,22 @@ static inline int block_cmp(uint8_t *src, int stride, uint8_t *src2, int stride2 /** Motion estimation function * TODO make better ME decisions */ -static int zmbv_me(ZmbvEncContext *c, uint8_t *src, int sstride, uint8_t *prev, int pstride, - int x, int y, int *mx, int *my) +static int zmbv_me(ZmbvEncContext *c, uint8_t *src, int sstride, uint8_t *prev, + int pstride, int x, int y, int *mx, int *my, int *xored) { int dx, dy, tx, ty, tv, bv, bw, bh; *mx = *my = 0; bw = FFMIN(ZMBV_BLOCK, c->avctx->width - x); bh = FFMIN(ZMBV_BLOCK, c->avctx->height - y); - bv = block_cmp(src, sstride, prev, pstride, bw, bh); + bv = block_cmp(src, sstride, prev, pstride, bw, bh, xored); if(!bv) return 0; for(ty = FFMAX(y - c->range, 0); ty < FFMIN(y + c->range, c->avctx->height - bh); ty++){ for(tx = FFMAX(x - c->range, 0); tx < FFMIN(x + c->range, c->avctx->width - bw); tx++){ if(tx == x && ty == y) continue; // we already tested this block dx = tx - x; dy = ty - y; - tv = block_cmp(src, sstride, prev + dx + dy*pstride, pstride, bw, bh); + tv = block_cmp(src, sstride, prev + dx + dy*pstride, pstride, bw, bh, xored); if(tv < bv){ bv = tv; *mx = dx; @@ -173,7 +178,7 @@ static int encode_frame(AVCodecContext *avctx, uint8_t *buf, int buf_size, void work_size += avctx->width; } }else{ - int x, y, bh2, bw2; + int x, y, bh2, bw2, xored; uint8_t *tsrc, *tprev; uint8_t *mv; int mx, my, bv; @@ -192,11 +197,11 @@ static int encode_frame(AVCodecContext *avctx, uint8_t *buf, int buf_size, void tsrc = src + x; tprev = prev + x; - bv = zmbv_me(c, tsrc, p->linesize[0], tprev, c->pstride, x, y, &mx, &my); - mv[0] = (mx << 1) | !!bv; + bv = zmbv_me(c, tsrc, p->linesize[0], tprev, c->pstride, x, y, &mx, &my, &xored); + mv[0] = (mx << 1) | !!xored; mv[1] = my << 1; tprev += mx + my * c->pstride; - if(bv){ + if(xored){ for(j = 0; j < bh2; j++){ for(i = 0; i < bw2; i++) c->work_buf[work_size++] = tsrc[i] ^ tprev[i]; @@ -263,10 +268,6 @@ static av_cold int encode_init(AVCodecContext *avctx) return -1; } - if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) { - return -1; - } - // Needed if zlib unused or init aborted before deflateInit memset(&(c->zstream), 0, sizeof(z_stream)); c->comp_size = avctx->width * avctx->height + 1024 + @@ -324,12 +325,12 @@ static av_cold int encode_end(AVCodecContext *avctx) AVCodec zmbv_encoder = { "zmbv", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_ZMBV, sizeof(ZmbvEncContext), encode_init, encode_frame, encode_end, - .pix_fmts = (enum PixelFormat[]){PIX_FMT_PAL8, PIX_FMT_NONE}, + .pix_fmts = (const enum PixelFormat[]){PIX_FMT_PAL8, PIX_FMT_NONE}, .long_name = NULL_IF_CONFIG_SMALL("Zip Motion Blocks Video"), }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/4xm.c b/src/add-ons/media/plugins/ffmpeg/libavformat/4xm.c index 631f8216a5..a697f8de8d 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/4xm.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/4xm.c @@ -20,7 +20,7 @@ */ /** - * @file libavformat/4xm.c + * @file * 4X Technologies file demuxer * by Mike Melanson (melanson@pcisys.net) * for more information on the .4xm file format, visit: @@ -149,7 +149,7 @@ static int fourxm_read_header(AVFormatContext *s, fourxm->video_stream_index = st->index; - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_4XM; st->codec->extradata_size = 4; st->codec->extradata = av_malloc(4); @@ -198,7 +198,7 @@ static int fourxm_read_header(AVFormatContext *s, fourxm->tracks[current_track].stream_index = st->index; - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_tag = 0; st->codec->channels = fourxm->tracks[current_track].channels; st->codec->sample_rate = fourxm->tracks[current_track].sample_rate; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/Jamfile b/src/add-ons/media/plugins/ffmpeg/libavformat/Jamfile index 85c6ba0524..383a3ab16a 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/Jamfile +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/Jamfile @@ -17,9 +17,13 @@ SubDirC++Flags $(HAIKU_FFMPEG_DEFINES) ; StaticLibrary libavformat.a : 4xm.c adtsenc.c + aea.c aiff.c + aiffdec.c + aiffenc.c allformats.c amr.c + anm.c apc.c ape.c apetag.c @@ -32,6 +36,7 @@ StaticLibrary libavformat.a : au.c audiointerleave.c avc.c + avi.c avidec.c avienc.c avio.c @@ -41,7 +46,12 @@ StaticLibrary libavformat.a : avs.c bethsoftvid.c bfi.c + bink.c c93.c + caf.c + cafdec.c + cdg.c + concat.c crcenc.c cutils.c daud.c @@ -54,8 +64,11 @@ StaticLibrary libavformat.a : ffmdec.c ffmenc.c file.c # TODO: Remove? (I/O protocol) + filmstripdec.c + filmstripenc.c flacdec.c flacenc.c + flacenc_header.c flic.c flvdec.c flvenc.c @@ -66,6 +79,7 @@ StaticLibrary libavformat.a : gxf.c gxfenc.c # http.c # (I/O protocol) +# httpauth.c (I/O protocol) id3v1.c id3v2.c idcin.c @@ -75,7 +89,9 @@ StaticLibrary libavformat.a : ipmovie.c isom.c iss.c + iv8.c # libnut.c // No libnut.so support +# librtmp.c // No libertmp.so support # lmlm4.c matroska.c matroskadec.c @@ -86,6 +102,7 @@ StaticLibrary libavformat.a : mmf.c mov.c movenc.c + movenchint.c mp3.c mpc8.c mpc.c @@ -108,8 +125,10 @@ StaticLibrary libavformat.a : nuv.c oggdec.c oggenc.c + oggparsedirac.c oggparseflac.c oggparseogm.c + oggparseskeleton.c oggparsespeex.c oggparsetheora.c oggparsevorbis.c @@ -132,11 +151,22 @@ StaticLibrary libavformat.a : rtp_h264.c rtp_mpv.c rtpdec.c + rtpdec_amr.c + rtpdec_asf.c + rtpdec_h263.c + rtpdec_h264.c + rtpdec_xiph.c rtpenc.c + rtpenc_aac.c + rtpenc_amr.c + rtpenc_h263.c rtpenc_h264.c + rtpenc_mpv.c # rtpproto.c # (I/O protocol) # rtsp.c +# rtspenc.c # sdp.c + seek.c segafilm.c sierravmd.c siff.c @@ -156,11 +186,13 @@ StaticLibrary libavformat.a : voc.c vocdec.c vocenc.c + vorbiscomment.c wav.c wc3movie.c westwood.c wv.c xa.c + yop.c yuv4mpeg.c ; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/adts.h b/src/add-ons/media/plugins/ffmpeg/libavformat/adts.h new file mode 100644 index 0000000000..1da57beff9 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/adts.h @@ -0,0 +1,45 @@ +/* + * ADTS muxer. + * Copyright (c) 2006 Baptiste Coudurier + * Mans Rullgard + * + * 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_ADTS_H +#define AVFORMAT_ADTS_H + +#include "avformat.h" +#include "libavcodec/mpeg4audio.h" + +#define ADTS_HEADER_SIZE 7 + +typedef struct { + int write_adts; + int objecttype; + int sample_rate_index; + int channel_conf; + int pce_size; + uint8_t pce_data[MAX_PCE_SIZE]; +} ADTSContext; + +int ff_adts_write_frame_header(ADTSContext *ctx, uint8_t *buf, + int size, int pce_size); +int ff_adts_decode_extradata(AVFormatContext *s, ADTSContext *adts, + uint8_t *buf, int size); + +#endif /* AVFORMAT_ADTS_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/adtsenc.c b/src/add-ons/media/plugins/ffmpeg/libavformat/adtsenc.c index 260c5932a3..ecc8dc40de 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/adtsenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/adtsenc.c @@ -23,21 +23,10 @@ #include "libavcodec/get_bits.h" #include "libavcodec/put_bits.h" #include "libavcodec/avcodec.h" -#include "libavcodec/mpeg4audio.h" #include "avformat.h" +#include "adts.h" -#define ADTS_HEADER_SIZE 7 - -typedef struct { - int write_adts; - int objecttype; - int sample_rate_index; - int channel_conf; - int pce_size; - uint8_t pce_data[MAX_PCE_SIZE]; -} ADTSContext; - -static int decode_extradata(AVFormatContext *s, ADTSContext *adts, uint8_t *buf, int size) +int ff_adts_decode_extradata(AVFormatContext *s, ADTSContext *adts, uint8_t *buf, int size) { GetBitContext gb; PutBitContext pb; @@ -86,17 +75,16 @@ static int adts_write_header(AVFormatContext *s) AVCodecContext *avc = s->streams[0]->codec; if(avc->extradata_size > 0 && - decode_extradata(s, adts, avc->extradata, avc->extradata_size) < 0) + ff_adts_decode_extradata(s, adts, avc->extradata, avc->extradata_size) < 0) return -1; return 0; } -static int adts_write_frame_header(AVFormatContext *s, int size) +int ff_adts_write_frame_header(ADTSContext *ctx, + uint8_t *buf, int size, int pce_size) { - ADTSContext *ctx = s->priv_data; PutBitContext pb; - uint8_t buf[ADTS_HEADER_SIZE]; init_put_bits(&pb, buf, ADTS_HEADER_SIZE); @@ -115,16 +103,11 @@ static int adts_write_frame_header(AVFormatContext *s, int size) /* adts_variable_header */ put_bits(&pb, 1, 0); /* copyright_identification_bit */ put_bits(&pb, 1, 0); /* copyright_identification_start */ - put_bits(&pb, 13, ADTS_HEADER_SIZE + size + ctx->pce_size); /* aac_frame_length */ + put_bits(&pb, 13, ADTS_HEADER_SIZE + size + pce_size); /* aac_frame_length */ put_bits(&pb, 11, 0x7ff); /* adts_buffer_fullness */ put_bits(&pb, 2, 0); /* number_of_raw_data_blocks_in_frame */ flush_put_bits(&pb); - put_buffer(s->pb, buf, ADTS_HEADER_SIZE); - if (ctx->pce_size) { - put_buffer(s->pb, ctx->pce_data, ctx->pce_size); - ctx->pce_size = 0; - } return 0; } @@ -133,11 +116,18 @@ static int adts_write_packet(AVFormatContext *s, AVPacket *pkt) { ADTSContext *adts = s->priv_data; ByteIOContext *pb = s->pb; + uint8_t buf[ADTS_HEADER_SIZE]; if (!pkt->size) return 0; - if(adts->write_adts) - adts_write_frame_header(s, pkt->size); + if(adts->write_adts) { + ff_adts_write_frame_header(adts, buf, pkt->size, adts->pce_size); + put_buffer(pb, buf, ADTS_HEADER_SIZE); + if(adts->pce_size) { + put_buffer(pb, adts->pce_data, adts->pce_size); + adts->pce_size = 0; + } + } put_buffer(pb, pkt->data, pkt->size); put_flush_packet(pb); diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/aea.c b/src/add-ons/media/plugins/ffmpeg/libavformat/aea.c new file mode 100644 index 0000000000..518995c4b0 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/aea.c @@ -0,0 +1,108 @@ +/* + * MD STUDIO audio demuxer + * + * Copyright (c) 2009 Benjamin Larsson + * + * 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 "raw.h" +#include "libavutil/intreadwrite.h" + +#define AT1_SU_SIZE 212 + +static int aea_read_probe(AVProbeData *p) +{ + if (p->buf_size <= 2048+212) + return 0; + + /* Magic is '00 08 00 00' in Little Endian*/ + if (AV_RL32(p->buf)==0x800) { + int bsm_s, bsm_e, inb_s, inb_e, ch; + ch = p->buf[264]; + bsm_s = p->buf[2048]; + inb_s = p->buf[2048+1]; + inb_e = p->buf[2048+210]; + bsm_e = p->buf[2048+211]; + + if (ch != 1 && ch != 2) + return 0; + + /* Check so that the redundant bsm bytes and info bytes are valid + * the block size mode bytes have to be the same + * the info bytes have to be the same + */ + if (bsm_s == bsm_e && inb_s == inb_e) + return AVPROBE_SCORE_MAX / 4 + 1; + } + return 0; +} + +static int aea_read_header(AVFormatContext *s, + AVFormatParameters *ap) +{ + AVStream *st = av_new_stream(s, 0); + if (!st) + return AVERROR(ENOMEM); + + /* Parse the amount of channels and skip to pos 2048(0x800) */ + url_fskip(s->pb, 264); + st->codec->channels = get_byte(s->pb); + url_fskip(s->pb, 1783); + + + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codec->codec_id = CODEC_ID_ATRAC1; + st->codec->sample_rate = 44100; + st->codec->bit_rate = 292000; + + if (st->codec->channels != 1 && st->codec->channels != 2) { + av_log(s,AV_LOG_ERROR,"Channels %d not supported!\n",st->codec->channels); + return -1; + } + + st->codec->channel_layout = (st->codec->channels == 1) ? CH_LAYOUT_MONO : CH_LAYOUT_STEREO; + + st->codec->block_align = AT1_SU_SIZE * st->codec->channels; + return 0; +} + +static int aea_read_packet(AVFormatContext *s, AVPacket *pkt) +{ + int ret = av_get_packet(s->pb, pkt, s->streams[0]->codec->block_align); + + pkt->stream_index = 0; + if (ret <= 0) + return AVERROR(EIO); + + return ret; +} + +AVInputFormat aea_demuxer = { + "aea", + NULL_IF_CONFIG_SMALL("MD STUDIO audio"), + 0, + aea_read_probe, + aea_read_header, + aea_read_packet, + 0, + pcm_read_seek, + .flags= AVFMT_GENERIC_INDEX, + .extensions = "aea", +}; + diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/aiff.h b/src/add-ons/media/plugins/ffmpeg/libavformat/aiff.h new file mode 100644 index 0000000000..047f81dc1d --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/aiff.h @@ -0,0 +1,53 @@ +/* + * AIFF/AIFF-C muxer/demuxer common header + * Copyright (c) 2006 Patrick Guimond + * + * 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 + * common header for AIFF muxer and demuxer + */ + +#ifndef AVFORMAT_AIFF_H +#define AVFORMAT_AIFF_H + +#include "avformat.h" +#include "riff.h" + +static const AVCodecTag ff_codec_aiff_tags[] = { + { CODEC_ID_PCM_S16BE, MKTAG('N','O','N','E') }, + { CODEC_ID_PCM_S8, MKTAG('N','O','N','E') }, + { CODEC_ID_PCM_S24BE, MKTAG('N','O','N','E') }, + { CODEC_ID_PCM_S32BE, MKTAG('N','O','N','E') }, + { CODEC_ID_PCM_F32BE, MKTAG('f','l','3','2') }, + { CODEC_ID_PCM_F64BE, MKTAG('f','l','6','4') }, + { CODEC_ID_PCM_ALAW, MKTAG('a','l','a','w') }, + { CODEC_ID_PCM_MULAW, MKTAG('u','l','a','w') }, + { CODEC_ID_MACE3, MKTAG('M','A','C','3') }, + { CODEC_ID_MACE6, MKTAG('M','A','C','6') }, + { CODEC_ID_GSM, MKTAG('G','S','M',' ') }, + { CODEC_ID_ADPCM_G726, MKTAG('G','7','2','6') }, + { CODEC_ID_PCM_S16LE, MKTAG('s','o','w','t') }, + { CODEC_ID_ADPCM_IMA_QT, MKTAG('i','m','a','4') }, + { CODEC_ID_QDM2, MKTAG('Q','D','M','2') }, + { CODEC_ID_QCELP, MKTAG('Q','c','l','p') }, + { CODEC_ID_NONE, 0 }, +}; + +#endif /* AVFORMAT_AIFF_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/aiffdec.c b/src/add-ons/media/plugins/ffmpeg/libavformat/aiffdec.c new file mode 100644 index 0000000000..f72af00f4c --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/aiffdec.c @@ -0,0 +1,324 @@ +/* + * AIFF/AIFF-C demuxer + * Copyright (c) 2006 Patrick Guimond + * + * 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/intfloat_readwrite.h" +#include "avformat.h" +#include "raw.h" +#include "aiff.h" + +#define AIFF 0 +#define AIFF_C_VERSION1 0xA2805140 + +typedef struct { + int64_t data_end; +} AIFFInputContext; + +static enum CodecID aiff_codec_get_id(int bps) +{ + if (bps <= 8) + return CODEC_ID_PCM_S8; + if (bps <= 16) + return CODEC_ID_PCM_S16BE; + if (bps <= 24) + return CODEC_ID_PCM_S24BE; + if (bps <= 32) + return CODEC_ID_PCM_S32BE; + + /* bigger than 32 isn't allowed */ + return CODEC_ID_NONE; +} + +/* returns the size of the found tag */ +static int get_tag(ByteIOContext *pb, uint32_t * tag) +{ + int size; + + if (url_feof(pb)) + return AVERROR(EIO); + + *tag = get_le32(pb); + size = get_be32(pb); + + if (size < 0) + size = 0x7fffffff; + + return size; +} + +/* Metadata string read */ +static void get_meta(AVFormatContext *s, const char *key, int size) +{ + uint8_t *str = av_malloc(size+1); + int res; + + if (!str) { + url_fskip(s->pb, size); + return; + } + + res = get_buffer(s->pb, str, size); + if (res < 0) + return; + + str[res] = 0; + av_metadata_set2(&s->metadata, key, str, AV_METADATA_DONT_STRDUP_VAL); +} + +/* Returns the number of sound data frames or negative on error */ +static unsigned int get_aiff_header(ByteIOContext *pb, AVCodecContext *codec, + int size, unsigned version) +{ + AVExtFloat ext; + double sample_rate; + unsigned int num_frames; + + if (size & 1) + size++; + codec->codec_type = AVMEDIA_TYPE_AUDIO; + codec->channels = get_be16(pb); + num_frames = get_be32(pb); + codec->bits_per_coded_sample = get_be16(pb); + + get_buffer(pb, (uint8_t*)&ext, sizeof(ext));/* Sample rate is in */ + sample_rate = av_ext2dbl(ext); /* 80 bits BE IEEE extended float */ + codec->sample_rate = sample_rate; + size -= 18; + + /* Got an AIFF-C? */ + if (version == AIFF_C_VERSION1) { + codec->codec_tag = get_le32(pb); + codec->codec_id = ff_codec_get_id(ff_codec_aiff_tags, codec->codec_tag); + + switch (codec->codec_id) { + case CODEC_ID_PCM_S16BE: + codec->codec_id = aiff_codec_get_id(codec->bits_per_coded_sample); + codec->bits_per_coded_sample = av_get_bits_per_sample(codec->codec_id); + break; + case CODEC_ID_ADPCM_IMA_QT: + codec->block_align = 34*codec->channels; + codec->frame_size = 64; + break; + case CODEC_ID_MACE3: + codec->block_align = 2*codec->channels; + codec->frame_size = 6; + break; + case CODEC_ID_MACE6: + codec->block_align = 1*codec->channels; + codec->frame_size = 6; + break; + case CODEC_ID_GSM: + codec->block_align = 33; + codec->frame_size = 160; + break; + case CODEC_ID_QCELP: + codec->block_align = 35; + codec->frame_size= 160; + break; + default: + break; + } + size -= 4; + } else { + /* Need the codec type */ + codec->codec_id = aiff_codec_get_id(codec->bits_per_coded_sample); + codec->bits_per_coded_sample = av_get_bits_per_sample(codec->codec_id); + } + + /* Block align needs to be computed in all cases, as the definition + * is specific to applications -> here we use the WAVE format definition */ + if (!codec->block_align) + codec->block_align = (codec->bits_per_coded_sample * codec->channels) >> 3; + + codec->bit_rate = (codec->frame_size ? codec->sample_rate/codec->frame_size : + codec->sample_rate) * (codec->block_align << 3); + + /* Chunk is over */ + if (size) + url_fseek(pb, size, SEEK_CUR); + + return num_frames; +} + +static int aiff_probe(AVProbeData *p) +{ + /* check file header */ + if (p->buf[0] == 'F' && p->buf[1] == 'O' && + p->buf[2] == 'R' && p->buf[3] == 'M' && + p->buf[8] == 'A' && p->buf[9] == 'I' && + p->buf[10] == 'F' && (p->buf[11] == 'F' || p->buf[11] == 'C')) + return AVPROBE_SCORE_MAX; + else + return 0; +} + +/* aiff input */ +static int aiff_read_header(AVFormatContext *s, + AVFormatParameters *ap) +{ + int size, filesize; + int64_t offset = 0; + uint32_t tag; + unsigned version = AIFF_C_VERSION1; + ByteIOContext *pb = s->pb; + AVStream * st; + AIFFInputContext *aiff = s->priv_data; + + /* check FORM header */ + filesize = get_tag(pb, &tag); + if (filesize < 0 || tag != MKTAG('F', 'O', 'R', 'M')) + return AVERROR_INVALIDDATA; + + /* AIFF data type */ + tag = get_le32(pb); + if (tag == MKTAG('A', 'I', 'F', 'F')) /* Got an AIFF file */ + version = AIFF; + else if (tag != MKTAG('A', 'I', 'F', 'C')) /* An AIFF-C file then */ + return AVERROR_INVALIDDATA; + + filesize -= 4; + + st = av_new_stream(s, 0); + if (!st) + return AVERROR(ENOMEM); + + while (filesize > 0) { + /* parse different chunks */ + size = get_tag(pb, &tag); + if (size < 0) + return size; + + filesize -= size + 8; + + switch (tag) { + case MKTAG('C', 'O', 'M', 'M'): /* Common chunk */ + /* Then for the complete header info */ + st->nb_frames = get_aiff_header(pb, st->codec, size, version); + if (st->nb_frames < 0) + return st->nb_frames; + if (offset > 0) // COMM is after SSND + goto got_sound; + break; + case MKTAG('F', 'V', 'E', 'R'): /* Version chunk */ + version = get_be32(pb); + break; + case MKTAG('N', 'A', 'M', 'E'): /* Sample name chunk */ + get_meta(s, "title" , size); + break; + case MKTAG('A', 'U', 'T', 'H'): /* Author chunk */ + get_meta(s, "author" , size); + break; + case MKTAG('(', 'c', ')', ' '): /* Copyright chunk */ + get_meta(s, "copyright", size); + break; + case MKTAG('A', 'N', 'N', 'O'): /* Annotation chunk */ + get_meta(s, "comment" , size); + break; + case MKTAG('S', 'S', 'N', 'D'): /* Sampled sound chunk */ + aiff->data_end = url_ftell(pb) + size; + offset = get_be32(pb); /* Offset of sound data */ + get_be32(pb); /* BlockSize... don't care */ + offset += url_ftell(pb); /* Compute absolute data offset */ + if (st->codec->block_align) /* Assume COMM already parsed */ + goto got_sound; + if (url_is_streamed(pb)) { + av_log(s, AV_LOG_ERROR, "file is not seekable\n"); + return -1; + } + url_fskip(pb, size - 8); + break; + case MKTAG('w', 'a', 'v', 'e'): + if ((uint64_t)size > (1<<30)) + return -1; + st->codec->extradata = av_mallocz(size + FF_INPUT_BUFFER_PADDING_SIZE); + if (!st->codec->extradata) + return AVERROR(ENOMEM); + st->codec->extradata_size = size; + get_buffer(pb, st->codec->extradata, size); + break; + default: /* Jump */ + if (size & 1) /* Always even aligned */ + size++; + url_fskip (pb, size); + } + } + + if (!st->codec->block_align) { + av_log(s, AV_LOG_ERROR, "could not find COMM tag\n"); + return -1; + } + +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 ? + st->nb_frames * st->codec->frame_size : st->nb_frames; + + /* Position the stream at the first block */ + url_fseek(pb, offset, SEEK_SET); + + return 0; +} + +#define MAX_SIZE 4096 + +static int aiff_read_packet(AVFormatContext *s, + AVPacket *pkt) +{ + AVStream *st = s->streams[0]; + AIFFInputContext *aiff = s->priv_data; + int64_t max_size; + int res, size; + + /* calculate size of remaining data */ + max_size = aiff->data_end - url_ftell(s->pb); + if (max_size <= 0) + return AVERROR_EOF; + + /* Now for that packet */ + if (st->codec->block_align >= 33) // GSM, QCLP, IMA4 + size = st->codec->block_align; + else + size = (MAX_SIZE / st->codec->block_align) * st->codec->block_align; + size = FFMIN(max_size, size); + res = av_get_packet(s->pb, pkt, size); + if (res < 0) + return res; + + /* Only one stream in an AIFF file */ + pkt->stream_index = 0; + return 0; +} + +AVInputFormat aiff_demuxer = { + "aiff", + NULL_IF_CONFIG_SMALL("Audio IFF"), + sizeof(AIFFInputContext), + aiff_probe, + aiff_read_header, + aiff_read_packet, + NULL, + pcm_read_seek, + .codec_tag= (const AVCodecTag* const []){ff_codec_aiff_tags, 0}, +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/aiffenc.c b/src/add-ons/media/plugins/ffmpeg/libavformat/aiffenc.c new file mode 100644 index 0000000000..e3c6a0b1bf --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/aiffenc.c @@ -0,0 +1,160 @@ +/* + * AIFF/AIFF-C muxer + * Copyright (c) 2006 Patrick Guimond + * + * 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 "aiff.h" + +typedef struct { + int64_t form; + int64_t frames; + int64_t ssnd; +} AIFFOutputContext; + +static int aiff_write_header(AVFormatContext *s) +{ + AIFFOutputContext *aiff = s->priv_data; + ByteIOContext *pb = s->pb; + AVCodecContext *enc = s->streams[0]->codec; + AVExtFloat sample_rate; + int aifc = 0; + + /* First verify if format is ok */ + if (!enc->codec_tag) + return -1; + if (enc->codec_tag != MKTAG('N','O','N','E')) + aifc = 1; + + /* FORM AIFF header */ + put_tag(pb, "FORM"); + aiff->form = url_ftell(pb); + put_be32(pb, 0); /* file length */ + put_tag(pb, aifc ? "AIFC" : "AIFF"); + + if (aifc) { // compressed audio + enc->bits_per_coded_sample = 16; + if (!enc->block_align) { + av_log(s, AV_LOG_ERROR, "block align not set\n"); + return -1; + } + /* Version chunk */ + put_tag(pb, "FVER"); + put_be32(pb, 4); + put_be32(pb, 0xA2805140); + } + + /* Common chunk */ + put_tag(pb, "COMM"); + put_be32(pb, aifc ? 24 : 18); /* size */ + put_be16(pb, enc->channels); /* Number of channels */ + + aiff->frames = url_ftell(pb); + put_be32(pb, 0); /* Number of frames */ + + if (!enc->bits_per_coded_sample) + enc->bits_per_coded_sample = av_get_bits_per_sample(enc->codec_id); + if (!enc->bits_per_coded_sample) { + av_log(s, AV_LOG_ERROR, "could not compute bits per sample\n"); + return -1; + } + if (!enc->block_align) + enc->block_align = (enc->bits_per_coded_sample * enc->channels) >> 3; + + put_be16(pb, enc->bits_per_coded_sample); /* Sample size */ + + sample_rate = av_dbl2ext((double)enc->sample_rate); + put_buffer(pb, (uint8_t*)&sample_rate, sizeof(sample_rate)); + + if (aifc) { + put_le32(pb, enc->codec_tag); + put_be16(pb, 0); + } + + /* Sound data chunk */ + put_tag(pb, "SSND"); + aiff->ssnd = url_ftell(pb); /* Sound chunk size */ + put_be32(pb, 0); /* Sound samples data size */ + put_be32(pb, 0); /* Data offset */ + put_be32(pb, 0); /* Block-size (block align) */ + + av_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codec->sample_rate); + + /* Data is starting here */ + put_flush_packet(pb); + + return 0; +} + +static int aiff_write_packet(AVFormatContext *s, AVPacket *pkt) +{ + ByteIOContext *pb = s->pb; + put_buffer(pb, pkt->data, pkt->size); + return 0; +} + +static int aiff_write_trailer(AVFormatContext *s) +{ + ByteIOContext *pb = s->pb; + AIFFOutputContext *aiff = s->priv_data; + AVCodecContext *enc = s->streams[0]->codec; + + /* Chunks sizes must be even */ + int64_t file_size, end_size; + end_size = file_size = url_ftell(pb); + if (file_size & 1) { + put_byte(pb, 0); + end_size++; + } + + if (!url_is_streamed(s->pb)) { + /* File length */ + url_fseek(pb, aiff->form, SEEK_SET); + put_be32(pb, file_size - aiff->form - 4); + + /* Number of sample frames */ + url_fseek(pb, aiff->frames, SEEK_SET); + put_be32(pb, (file_size-aiff->ssnd-12)/enc->block_align); + + /* Sound Data chunk size */ + url_fseek(pb, aiff->ssnd, SEEK_SET); + put_be32(pb, file_size - aiff->ssnd - 4); + + /* return to the end */ + url_fseek(pb, end_size, SEEK_SET); + + put_flush_packet(pb); + } + + return 0; +} + +AVOutputFormat 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, + .codec_tag= (const AVCodecTag* const []){ff_codec_aiff_tags, 0}, +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/allformats.c b/src/add-ons/media/plugins/ffmpeg/libavformat/allformats.c index d80d37aae7..27a955594b 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/allformats.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/allformats.c @@ -50,8 +50,10 @@ void av_register_all(void) REGISTER_DEMUXER (AAC, aac); REGISTER_MUXDEMUX (AC3, ac3); REGISTER_MUXER (ADTS, adts); + REGISTER_DEMUXER (AEA, aea); REGISTER_MUXDEMUX (AIFF, aiff); REGISTER_MUXDEMUX (AMR, amr); + REGISTER_DEMUXER (ANM, anm); REGISTER_DEMUXER (APC, apc); REGISTER_DEMUXER (APE, ape); REGISTER_MUXDEMUX (ASF, asf); @@ -64,8 +66,11 @@ void av_register_all(void) REGISTER_DEMUXER (AVS, avs); REGISTER_DEMUXER (BETHSOFTVID, bethsoftvid); REGISTER_DEMUXER (BFI, bfi); + REGISTER_DEMUXER (BINK, bink); REGISTER_DEMUXER (C93, c93); + REGISTER_DEMUXER (CAF, caf); REGISTER_DEMUXER (CAVSVIDEO, cavsvideo); + REGISTER_DEMUXER (CDG, cdg); REGISTER_MUXER (CRC, crc); REGISTER_MUXDEMUX (DAUD, daud); REGISTER_MUXDEMUX (DIRAC, dirac); @@ -78,6 +83,7 @@ void av_register_all(void) REGISTER_DEMUXER (EA_CDATA, ea_cdata); REGISTER_MUXDEMUX (EAC3, eac3); REGISTER_MUXDEMUX (FFM, ffm); + REGISTER_MUXDEMUX (FILMSTRIP, filmstrip); REGISTER_MUXDEMUX (FLAC, flac); REGISTER_DEMUXER (FLIC, flic); REGISTER_MUXDEMUX (FLV, flv); @@ -97,6 +103,7 @@ void av_register_all(void) REGISTER_DEMUXER (IPMOVIE, ipmovie); REGISTER_MUXER (IPOD, ipod); REGISTER_DEMUXER (ISS, iss); + REGISTER_DEMUXER (IV8, iv8); REGISTER_DEMUXER (LMLM4, lmlm4); REGISTER_MUXDEMUX (M4V, m4v); REGISTER_MUXDEMUX (MATROSKA, matroska); @@ -160,13 +167,12 @@ void av_register_all(void) REGISTER_DEMUXER (QCP, qcp); REGISTER_DEMUXER (R3D, r3d); REGISTER_MUXDEMUX (RAWVIDEO, rawvideo); - REGISTER_DEMUXER (REDIR, redir); REGISTER_DEMUXER (RL2, rl2); REGISTER_MUXDEMUX (RM, rm); REGISTER_MUXDEMUX (ROQ, roq); REGISTER_DEMUXER (RPL, rpl); REGISTER_MUXER (RTP, rtp); - REGISTER_DEMUXER (RTSP, rtsp); + REGISTER_MUXDEMUX (RTSP, rtsp); REGISTER_DEMUXER (SDP, sdp); #if CONFIG_SDP_DEMUXER av_register_rtp_dynamic_payload_handlers(); @@ -197,10 +203,12 @@ void av_register_all(void) REGISTER_DEMUXER (W64, w64); REGISTER_MUXDEMUX (WAV, wav); REGISTER_DEMUXER (WC3, wc3); + REGISTER_MUXER (WEBM, webm); REGISTER_DEMUXER (WSAUD, wsaud); REGISTER_DEMUXER (WSVQA, wsvqa); REGISTER_DEMUXER (WV, wv); REGISTER_DEMUXER (XA, xa); + REGISTER_DEMUXER (YOP, yop); REGISTER_MUXDEMUX (YUV4MPEGPIPE, yuv4mpegpipe); /* external libraries */ @@ -212,7 +220,14 @@ void av_register_all(void) REGISTER_PROTOCOL (HTTP, http); REGISTER_PROTOCOL (PIPE, pipe); REGISTER_PROTOCOL (RTMP, rtmp); +#if CONFIG_LIBRTMP + REGISTER_PROTOCOL (RTMP, rtmpt); + REGISTER_PROTOCOL (RTMP, rtmpe); + REGISTER_PROTOCOL (RTMP, rtmpte); + REGISTER_PROTOCOL (RTMP, rtmps); +#endif REGISTER_PROTOCOL (RTP, rtp); REGISTER_PROTOCOL (TCP, tcp); REGISTER_PROTOCOL (UDP, udp); + REGISTER_PROTOCOL (CONCAT, concat); } diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/amr.c b/src/add-ons/media/plugins/ffmpeg/libavformat/amr.c index cbc4ec50d4..d16b4c03cd 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/amr.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/amr.c @@ -108,7 +108,7 @@ static int amr_read_header(AVFormatContext *s, st->codec->sample_rate = 8000; } st->codec->channels = 1; - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; av_set_pts_info(st, 64, 1, st->codec->sample_rate); return 0; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/anm.c b/src/add-ons/media/plugins/ffmpeg/libavformat/anm.c new file mode 100644 index 0000000000..ba77e186c5 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/anm.c @@ -0,0 +1,235 @@ +/* + * Deluxe Paint Animation demuxer + * Copyright (c) 2009 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 + */ + +/** + * @file + * Deluxe Paint Animation demuxer + */ + +#include "libavutil/intreadwrite.h" +#include "avformat.h" + +typedef struct { + int base_record; + unsigned int nb_records; + int size; +} Page; + +typedef struct { + unsigned int nb_pages; /** total pages in file */ + unsigned int nb_records; /** total records in file */ + int page_table_offset; +#define MAX_PAGES 256 /** Deluxe Paint hardcoded value */ + Page pt[MAX_PAGES]; /** page table */ + int page; /** current page (or AVERROR_xxx code) */ + int record; /** current record (with in page) */ +} AnmDemuxContext; + +#define LPF_TAG MKTAG('L','P','F',' ') +#define ANIM_TAG MKTAG('A','N','I','M') + +static int probe(AVProbeData *p) +{ + /* verify tags and video dimensions */ + if (AV_RL32(&p->buf[0]) == LPF_TAG && + AV_RL32(&p->buf[16]) == ANIM_TAG && + AV_RL16(&p->buf[20]) && AV_RL16(&p->buf[22])) + return AVPROBE_SCORE_MAX; + return 0; +} + +/** + * @return page containing the requested record or AVERROR_XXX + */ +static int find_record(const AnmDemuxContext *anm, int record) +{ + int i; + + if (record >= anm->nb_records) + return AVERROR_EOF; + + for (i = 0; i < MAX_PAGES; i++) { + const Page *p = &anm->pt[i]; + if (p->nb_records > 0 && record >= p->base_record && record < p->base_record + p->nb_records) + return i; + } + + return AVERROR_INVALIDDATA; +} + +static int read_header(AVFormatContext *s, + AVFormatParameters *ap) +{ + AnmDemuxContext *anm = s->priv_data; + ByteIOContext *pb = s->pb; + AVStream *st; + int i, ret; + + url_fskip(pb, 4); /* magic number */ + if (get_le16(pb) != MAX_PAGES) { + av_log_ask_for_sample(s, "max_pages != " AV_STRINGIFY(MAX_PAGES) "\n"); + return AVERROR_INVALIDDATA; + } + + anm->nb_pages = get_le16(pb); + anm->nb_records = get_le32(pb); + url_fskip(pb, 2); /* max records per page */ + anm->page_table_offset = get_le16(pb); + if (get_le32(pb) != ANIM_TAG) + return AVERROR_INVALIDDATA; + + /* video stream */ + st = av_new_stream(s, 0); + if (!st) + return AVERROR(ENOMEM); + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_ANM; + st->codec->codec_tag = 0; /* no fourcc */ + st->codec->width = get_le16(pb); + st->codec->height = get_le16(pb); + if (get_byte(pb) != 0) + goto invalid; + url_fskip(pb, 1); /* frame rate multiplier info */ + + /* ignore last delta record (used for looping) */ + if (get_byte(pb)) /* has_last_delta */ + anm->nb_records = FFMAX(anm->nb_records - 1, 0); + + url_fskip(pb, 1); /* last_delta_valid */ + + if (get_byte(pb) != 0) + goto invalid; + + if (get_byte(pb) != 1) + goto invalid; + + url_fskip(pb, 1); /* other recs per frame */ + + if (get_byte(pb) != 1) + goto invalid; + + url_fskip(pb, 32); /* record_types */ + st->nb_frames = get_le32(pb); + av_set_pts_info(st, 64, 1, get_le16(pb)); + url_fskip(pb, 58); + + /* 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; + } + ret = get_buffer(pb, st->codec->extradata, st->codec->extradata_size); + if (ret < 0) + goto close_and_return; + + /* read page table */ + ret = url_fseek(pb, anm->page_table_offset, SEEK_SET); + if (ret < 0) + goto close_and_return; + + for (i = 0; i < MAX_PAGES; i++) { + Page *p = &anm->pt[i]; + p->base_record = get_le16(pb); + p->nb_records = get_le16(pb); + p->size = get_le16(pb); + } + + /* find page of first frame */ + anm->page = find_record(anm, 0); + if (anm->page < 0) { + ret = anm->page; + goto close_and_return; + } + + 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; +} + +static int read_packet(AVFormatContext *s, + AVPacket *pkt) +{ + AnmDemuxContext *anm = s->priv_data; + ByteIOContext *pb = s->pb; + Page *p; + int tmp, record_size; + + if (url_feof(s->pb)) + return AVERROR(EIO); + + if (anm->page < 0) + return anm->page; + +repeat: + p = &anm->pt[anm->page]; + + /* parse page header */ + if (anm->record < 0) { + url_fseek(pb, anm->page_table_offset + MAX_PAGES*6 + (anm->page<<16), SEEK_SET); + url_fskip(pb, 8 + 2*p->nb_records); + anm->record = 0; + } + + /* if we have fetched all records in this page, then find the + next page and repeat */ + if (anm->record >= p->nb_records) { + anm->page = find_record(anm, p->base_record + p->nb_records); + if (anm->page < 0) + return anm->page; + anm->record = -1; + goto repeat; + } + + /* fetch record size */ + tmp = url_ftell(pb); + url_fseek(pb, anm->page_table_offset + MAX_PAGES*6 + (anm->page<<16) + + 8 + anm->record * 2, SEEK_SET); + record_size = get_le16(pb); + url_fseek(pb, tmp, SEEK_SET); + + /* fetch record */ + pkt->size = av_get_packet(s->pb, pkt, record_size); + if (pkt->size < 0) + return pkt->size; + if (p->base_record + anm->record == 0) + pkt->flags |= AV_PKT_FLAG_KEY; + + anm->record++; + return 0; +} + +AVInputFormat anm_demuxer = { + "anm", + NULL_IF_CONFIG_SMALL("Deluxe Paint Animation"), + sizeof(AnmDemuxContext), + probe, + read_header, + read_packet, +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/apc.c b/src/add-ons/media/plugins/ffmpeg/libavformat/apc.c index 14701d9229..9b4a8adc1d 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/apc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/apc.c @@ -43,7 +43,7 @@ static int apc_read_header(AVFormatContext *s, AVFormatParameters *ap) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_ADPCM_IMA_WS; get_le32(pb); /* number of samples */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/ape.c b/src/add-ons/media/plugins/ffmpeg/libavformat/ape.c index cc2e657b99..91acf7240d 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/ape.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/ape.c @@ -248,7 +248,7 @@ static int ape_read_header(AVFormatContext * s, AVFormatParameters * ap) } ape->frames = av_malloc(ape->totalframes * sizeof(APEFrame)); if(!ape->frames) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); ape->firstframe = ape->junklength + ape->descriptorlength + ape->headerlength + ape->seektablelength + ape->wavheaderlength; ape->currentframe = 0; @@ -301,7 +301,7 @@ static int ape_read_header(AVFormatContext * s, AVFormatParameters * ap) total_blocks = (ape->totalframes == 0) ? 0 : ((ape->totalframes - 1) * ape->blocksperframe) + ape->finalframeblocks; - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_APE; st->codec->codec_tag = MKTAG('A', 'P', 'E', ' '); st->codec->channels = ape->channels; @@ -310,8 +310,8 @@ static int ape_read_header(AVFormatContext * s, AVFormatParameters * ap) st->codec->frame_size = MAC_SUBFRAME_SIZE; st->nb_frames = ape->totalframes; - s->start_time = 0; - s->duration = (int64_t) total_blocks * AV_TIME_BASE / ape->samplerate; + st->start_time = 0; + st->duration = total_blocks / MAC_SUBFRAME_SIZE; av_set_pts_info(st, 64, MAC_SUBFRAME_SIZE, ape->samplerate); st->codec->extradata = av_malloc(APE_EXTRADATA_SIZE); @@ -338,9 +338,9 @@ static int ape_read_packet(AVFormatContext * s, AVPacket * pkt) uint32_t extra_size = 8; if (url_feof(s->pb)) - return AVERROR_IO; + return AVERROR(EIO); if (ape->currentframe > ape->totalframes) - return AVERROR_IO; + return AVERROR(EIO); url_fseek (s->pb, ape->frames[ape->currentframe].pos, SEEK_SET); @@ -351,7 +351,7 @@ static int ape_read_packet(AVFormatContext * s, AVPacket * pkt) nblocks = ape->blocksperframe; if (av_new_packet(pkt, ape->frames[ape->currentframe].size + extra_size) < 0) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); AV_WL32(pkt->data , nblocks); AV_WL32(pkt->data + 4, ape->frames[ape->currentframe].skip); diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/apetag.c b/src/add-ons/media/plugins/ffmpeg/libavformat/apetag.c index 435dd3fdcf..d30c13222a 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/apetag.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/apetag.c @@ -22,6 +22,7 @@ #include "libavutil/intreadwrite.h" #include "avformat.h" +#include "apetag.h" #define ENABLE_DEBUG 0 @@ -33,9 +34,9 @@ static int ape_tag_read_field(AVFormatContext *s) { ByteIOContext *pb = s->pb; - uint8_t key[1024], value[1024]; + uint8_t key[1024], *value; uint32_t size, flags; - int i, l, c; + int i, c; size = get_le32(pb); /* field size */ flags = get_le32(pb); /* field flags */ @@ -51,13 +52,14 @@ static int ape_tag_read_field(AVFormatContext *s) av_log(s, AV_LOG_WARNING, "Invalid APE tag key '%s'.\n", key); return -1; } - l = FFMIN(size, sizeof(value)-1); - get_buffer(pb, value, l); - value[l] = 0; - url_fskip(pb, size-l); - if (l < size) - av_log(s, AV_LOG_WARNING, "Too long '%s' tag was truncated.\n", key); - av_metadata_set(&s->metadata, key, value); + if (size >= UINT_MAX) + return -1; + value = av_malloc(size+1); + if (!value) + return AVERROR(ENOMEM); + get_buffer(pb, value, size); + value[size] = 0; + av_metadata_set2(&s->metadata, key, value, AV_METADATA_DONT_STRDUP_VAL); return 0; } @@ -107,16 +109,4 @@ void ff_ape_parse_tag(AVFormatContext *s) for (i=0; ititle); - av_log(s, AV_LOG_DEBUG, "author = %s\n", s->author); - av_log(s, AV_LOG_DEBUG, "copyright = %s\n", s->copyright); - av_log(s, AV_LOG_DEBUG, "comment = %s\n", s->comment); - av_log(s, AV_LOG_DEBUG, "album = %s\n", s->album); - av_log(s, AV_LOG_DEBUG, "year = %d\n", s->year); - av_log(s, AV_LOG_DEBUG, "track = %d\n", s->track); - av_log(s, AV_LOG_DEBUG, "genre = %s\n", s->genre); -#endif } diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/asf.c b/src/add-ons/media/plugins/ffmpeg/libavformat/asf.c index 79ef61444b..e25ac030aa 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/asf.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/asf.c @@ -106,6 +106,10 @@ const ff_asf_guid ff_asf_metadata_header = { 0xea, 0xcb, 0xf8, 0xc5, 0xaf, 0x5b, 0x77, 0x48, 0x84, 0x67, 0xaa, 0x8c, 0x44, 0xfa, 0x4c, 0xca }; +const ff_asf_guid ff_asf_marker_header = { + 0x01, 0xCD, 0x87, 0xF4, 0x51, 0xA9, 0xCF, 0x11, 0x8E, 0xE6, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65 +}; + /* I am not a number !!! This GUID is the one found on the PC used to generate the stream */ const ff_asf_guid ff_asf_my_guid = { @@ -116,13 +120,52 @@ const ff_asf_guid ff_asf_language_guid = { 0xa9, 0x46, 0x43, 0x7c, 0xe0, 0xef, 0xfc, 0x4b, 0xb2, 0x29, 0x39, 0x3e, 0xde, 0x41, 0x5c, 0x85 }; +const ff_asf_guid ff_asf_content_encryption = { + 0xfb, 0xb3, 0x11, 0x22, 0x23, 0xbd, 0xd2, 0x11, 0xb4, 0xb7, 0x00, 0xa0, 0xc9, 0x55, 0xfc, 0x6e +}; + +const ff_asf_guid ff_asf_ext_content_encryption = { + 0x14, 0xe6, 0x8a, 0x29, 0x22, 0x26, 0x17, 0x4c, 0xb9, 0x35, 0xda, 0xe0, 0x7e, 0xe9, 0x28, 0x9c +}; + +const ff_asf_guid ff_asf_digital_signature = { + 0xfc, 0xb3, 0x11, 0x22, 0x23, 0xbd, 0xd2, 0x11, 0xb4, 0xb7, 0x00, 0xa0, 0xc9, 0x55, 0xfc, 0x6e +}; + +/* List of official tags at http://msdn.microsoft.com/en-us/library/dd743066(VS.85).aspx */ const AVMetadataConv ff_asf_metadata_conv[] = { - { "AlbumArtist", "artist" }, - { "AlbumTitle" , "album" }, - { "Author" , "author" }, - { "Genre" , "genre" }, - { "Copyright" , "copyright" }, - { "TrackNumber", "track" }, - { "Year" , "year" }, + { "WM/AlbumArtist" , "album_artist"}, + { "WM/AlbumTitle" , "album" }, + { "Author" , "artist" }, + { "Description" , "comment" }, + { "WM/Composer" , "composer" }, + { "WM/EncodedBy" , "encoded_by" }, + { "WM/EncodingSettings", "encoder" }, + { "WM/Genre" , "genre" }, + { "WM/Language" , "language" }, + { "WM/OriginalFilename", "filename" }, + { "WM/PartOfSet" , "disc" }, + { "WM/Publisher" , "publisher" }, + { "WM/Tool" , "encoder" }, + { "WM/TrackNumber" , "track" }, + { "WM/Track" , "track" }, +// { "Year" , "date" }, TODO: conversion year<->date { 0 } }; + +int ff_put_str16_nolen(ByteIOContext *s, const char *tag) +{ + const uint8_t *q = tag; + int ret = 0; + + while (*q) { + uint32_t ch; + uint16_t tmp; + + GET_UTF8(ch, *q++, break;) + PUT_UTF16(ch, tmp, put_le16(s, tmp);ret += 2;) + } + put_le16(s, 0); + ret += 2; + return ret; +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/asf.h b/src/add-ons/media/plugins/ffmpeg/libavformat/asf.h index 314c0f8882..85e54ccfe9 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/asf.h +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/asf.h @@ -158,8 +158,12 @@ extern const ff_asf_guid ff_asf_simple_index_header; extern const ff_asf_guid ff_asf_ext_stream_embed_stream_header; extern const ff_asf_guid ff_asf_ext_stream_audio_stream; extern const ff_asf_guid ff_asf_metadata_header; +extern const ff_asf_guid ff_asf_marker_header; extern const ff_asf_guid ff_asf_my_guid; extern const ff_asf_guid ff_asf_language_guid; +extern const ff_asf_guid ff_asf_content_encryption; +extern const ff_asf_guid ff_asf_ext_content_encryption; +extern const ff_asf_guid ff_asf_digital_signature; extern const AVMetadataConv ff_asf_metadata_conv[]; @@ -225,5 +229,6 @@ extern const AVMetadataConv ff_asf_metadata_conv[]; #define ASF_PL_FLAG_KEY_FRAME 0x80 //1000 0000 extern AVInputFormat asf_demuxer; +int ff_put_str16_nolen(ByteIOContext *s, const char *tag); #endif /* AVFORMAT_ASF_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/asfdec.c b/src/add-ons/media/plugins/ffmpeg/libavformat/asfdec.c index 0995b5aa82..8aea8c7ef6 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/asfdec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/asfdec.c @@ -82,6 +82,7 @@ static void print_guid(const ff_asf_guid *g) else PRINT_IF_GUID(g, ff_asf_ext_stream_embed_stream_header); else PRINT_IF_GUID(g, ff_asf_ext_stream_audio_stream); else PRINT_IF_GUID(g, ff_asf_metadata_header); + else PRINT_IF_GUID(g, ff_asf_marker_header); else PRINT_IF_GUID(g, stream_bitrate_guid); else PRINT_IF_GUID(g, ff_asf_language_guid); else @@ -122,9 +123,12 @@ static void get_str16(ByteIOContext *pb, char *buf, int buf_size) static void get_str16_nolen(ByteIOContext *pb, int len, char *buf, int buf_size) { char* q = buf; - for (; len > 1; len -= 2) { + while (len > 1) { uint8_t tmp; - PUT_UTF8(get_le16(pb), tmp, if (q - buf < buf_size - 1) *q++ = tmp;) + uint32_t ch; + + GET_UTF16(ch, (len -= 2) >= 0 ? get_le16(pb) : 0, break;) + PUT_UTF8(ch, tmp, if (q - buf < buf_size - 1) *q++ = tmp;) } if (len > 0) url_fskip(pb, len); @@ -152,19 +156,28 @@ static int get_value(ByteIOContext *pb, int type){ static void get_tag(AVFormatContext *s, const char *key, int type, int len) { - char value[1024]; - if (type <= 1) { // unicode or byte - get_str16_nolen(s->pb, len, value, sizeof(value)); - } else if (type <= 5) { // boolean or DWORD or QWORD or WORD + char *value; + + if ((unsigned)len >= (UINT_MAX - 1)/2) + return; + + value = av_malloc(2*len+1); + if (!value) + return; + + if (type == 0) { // UTF16-LE + get_str16_nolen(s->pb, len, value, 2*len + 1); + } else if (type > 1 && type <= 5) { // boolean or DWORD or QWORD or WORD uint64_t num = get_value(s->pb, type); - snprintf(value, sizeof(value), "%"PRIu64, num); + snprintf(value, len, "%"PRIu64, num); } else { url_fskip(s->pb, len); + av_freep(&value); + av_log(s, AV_LOG_DEBUG, "Unsupported value type %d in tag %s.\n", type, key); return; } - if (!strncmp(key, "WM/", 3)) - key += 3; - av_metadata_set(&s->metadata, key, value); + av_metadata_set2(&s->metadata, key, value, 0); + av_freep(&value); } static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) @@ -191,9 +204,10 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) get_byte(pb); memset(&asf->asfid2avid, -1, sizeof(asf->asfid2avid)); for(;;) { + uint64_t gpos= url_ftell(pb); get_guid(pb, &g); gsize = get_le64(pb); - dprintf(s, "%08"PRIx64": ", url_ftell(pb) - 24); + dprintf(s, "%08"PRIx64": ", gpos); print_guid(&g); dprintf(s, " size=0x%"PRIx64"\n", gsize); if (!guidcmp(&g, &ff_asf_data_header)) { @@ -223,7 +237,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) asf->hdr.max_bitrate = get_le32(pb); s->packet_size = asf->hdr.max_pktsize; } else if (!guidcmp(&g, &ff_asf_stream_header)) { - enum CodecType type; + enum AVMediaType type; int type_specific_size, sizeX; uint64_t total_size; unsigned int tag1; @@ -245,21 +259,21 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) asf_st->stream_language_index = 128; // invalid stream index means no language info if(!(asf->hdr.flags & 0x01)) { // if we aren't streaming... - st->duration = asf->hdr.send_time / + st->duration = asf->hdr.play_time / (10000000 / 1000) - start_time; } get_guid(pb, &g); test_for_ext_stream_audio = 0; if (!guidcmp(&g, &ff_asf_audio_stream)) { - type = CODEC_TYPE_AUDIO; + type = AVMEDIA_TYPE_AUDIO; } else if (!guidcmp(&g, &ff_asf_video_stream)) { - type = CODEC_TYPE_VIDEO; + type = AVMEDIA_TYPE_VIDEO; } else if (!guidcmp(&g, &ff_asf_command_stream)) { - type = CODEC_TYPE_DATA; + type = AVMEDIA_TYPE_DATA; } else if (!guidcmp(&g, &ff_asf_ext_stream_embed_stream_header)) { test_for_ext_stream_audio = 1; - type = CODEC_TYPE_UNKNOWN; + type = AVMEDIA_TYPE_UNKNOWN; } else { return -1; } @@ -276,7 +290,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) if (test_for_ext_stream_audio) { get_guid(pb, &g); if (!guidcmp(&g, &ff_asf_ext_stream_audio_stream)) { - type = CODEC_TYPE_AUDIO; + type = AVMEDIA_TYPE_AUDIO; is_dvr_ms_audio=1; get_guid(pb, &g); get_le32(pb); @@ -288,7 +302,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) } st->codec->codec_type = type; - if (type == CODEC_TYPE_AUDIO) { + if (type == AVMEDIA_TYPE_AUDIO) { ff_get_wav_header(pb, st->codec, type_specific_size); if (is_dvr_ms_audio) { // codec_id and codec_tag are unreliable in dvr_ms @@ -338,7 +352,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) st->codec->frame_size = 1; break; } - } else if (type == CODEC_TYPE_VIDEO) { + } else if (type == AVMEDIA_TYPE_VIDEO) { get_le32(pb); get_le32(pb); get_byte(pb); @@ -428,9 +442,13 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) char name[1024]; name_len = get_le16(pb); + if (name_len%2) // must be even, broken lavf versions wrote len-1 + name_len += 1; get_str16_nolen(pb, name_len, name, sizeof(name)); value_type = get_le16(pb); value_len = get_le16(pb); + if (!value_type && value_len%2) + value_len += 1; get_tag(s, name, value_type, value_len); } } else if (!guidcmp(&g, &ff_asf_metadata_header)) { @@ -504,6 +522,32 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) get_guid(pb, &g); v1 = get_le32(pb); v2 = get_le16(pb); + } else if (!guidcmp(&g, &ff_asf_marker_header)) { + int i, count, name_len; + char name[1024]; + + get_le64(pb); // reserved 16 bytes + get_le64(pb); // ... + count = get_le32(pb); // markers count + get_le16(pb); // reserved 2 bytes + name_len = get_le16(pb); // name length + for(i=0;ikeylen) { + if (!guidcmp(&g, &ff_asf_content_encryption)) { + av_log(s, AV_LOG_WARNING, "DRM protected stream detected, decoding will likely fail!\n"); + } else if (!guidcmp(&g, &ff_asf_ext_content_encryption)) { + av_log(s, AV_LOG_WARNING, "Ext DRM protected stream detected, decoding will likely fail!\n"); + } else if (!guidcmp(&g, &ff_asf_digital_signature)) { + av_log(s, AV_LOG_WARNING, "Digital signature detected, decoding will likely fail!\n"); + } + } } + if(url_ftell(pb) != gpos + gsize) + av_log(s, AV_LOG_DEBUG, "gpos mismatch our pos=%"PRIu64", end=%"PRIu64"\n", url_ftell(pb)-gpos, gsize); + url_fseek(pb, gpos + gsize, SEEK_SET); } get_guid(pb, &g); get_le64(pb); @@ -564,7 +619,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) const char primary_tag[3] = { rfc1766[0], rfc1766[1], '\0' }; // ignore country code if any const char *iso6392 = av_convert_lang_to(primary_tag, AV_LANG_ISO639_2_BIBL); if (iso6392) - av_metadata_set(&st->metadata, "language", iso6392); + av_metadata_set2(&st->metadata, "language", iso6392, 0); } } } @@ -586,7 +641,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) * Load a single ASF packet into the demuxer. * @param s demux context * @param pb context to read data from - * @returns 0 on success, <0 on error + * @return 0 on success, <0 on error */ static int ff_asf_get_packet(AVFormatContext *s, ByteIOContext *pb) { @@ -749,7 +804,7 @@ static int asf_read_frame_header(AVFormatContext *s, ByteIOContext *pb){ * @param s demux context * @param pb context to read data from * @param pkt pointer to store packet data into - * @returns 0 if data was stored in pkt, <0 on error or 1 if more ASF + * @return 0 if data was stored in pkt, <0 on error or 1 if more ASF * packets need to be loaded (through asf_get_packet()) */ static int ff_asf_parse_packet(AVFormatContext *s, ByteIOContext *pb, AVPacket *pkt) @@ -836,12 +891,12 @@ static int ff_asf_parse_packet(AVFormatContext *s, ByteIOContext *pb, AVPacket * asf_st->pkt.pos = asf_st->packet_pos= asf->packet_pos; //printf("new packet: stream:%d key:%d packet_key:%d audio:%d size:%d\n", -//asf->stream_index, asf->packet_key_frame, asf_st->pkt.flags & PKT_FLAG_KEY, -//s->streams[asf->stream_index]->codec->codec_type == CODEC_TYPE_AUDIO, asf->packet_obj_size); - if (s->streams[asf->stream_index]->codec->codec_type == CODEC_TYPE_AUDIO) +//asf->stream_index, asf->packet_key_frame, asf_st->pkt.flags & AV_PKT_FLAG_KEY, +//s->streams[asf->stream_index]->codec->codec_type == AVMEDIA_TYPE_AUDIO, asf->packet_obj_size); + if (s->streams[asf->stream_index]->codec->codec_type == AVMEDIA_TYPE_AUDIO) asf->packet_key_frame = 1; if (asf->packet_key_frame) - asf_st->pkt.flags |= PKT_FLAG_KEY; + asf_st->pkt.flags |= AV_PKT_FLAG_KEY; } /* read data */ @@ -1016,7 +1071,7 @@ static int64_t asf_read_pts(AVFormatContext *s, int stream_index, int64_t *ppos, pts= pkt->pts; av_free_packet(pkt); - if(pkt->flags&PKT_FLAG_KEY){ + if(pkt->flags&AV_PKT_FLAG_KEY){ i= pkt->stream_index; asf_st= s->streams[i]->priv_data; @@ -1048,7 +1103,7 @@ static void asf_build_simple_index(AVFormatContext *s, int stream_index) url_fseek(s->pb, asf->data_object_offset + asf->data_object_size, SEEK_SET); get_guid(s->pb, &g); if (!guidcmp(&g, &index_guid)) { - int64_t itime; + int64_t itime, last_pos=-1; int pct, ict; int64_t av_unused gsize= get_le64(s->pb); get_guid(s->pb, &g); @@ -1063,8 +1118,11 @@ static void asf_build_simple_index(AVFormatContext *s, int stream_index) int64_t pos = s->data_offset + s->packet_size*(int64_t)pktnum; int64_t index_pts= av_rescale(itime, i, 10000); + if(pos != last_pos){ av_log(s, AV_LOG_DEBUG, "pktnum:%d, pktct:%d\n", pktnum, pktct); av_add_index_entry(s->streams[stream_index], pos, index_pts, s->packet_size, 0, AVINDEX_KEYFRAME); + last_pos=pos; + } } asf->index_read= 1; } diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/asfenc.c b/src/add-ons/media/plugins/ffmpeg/libavformat/asfenc.c index b749ce7434..9f8d69ac5c 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/asfenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/asfenc.c @@ -203,21 +203,19 @@ static void put_guid(ByteIOContext *s, const ff_asf_guid *g) put_buffer(s, *g, sizeof(*g)); } -static void put_str16_nolen(ByteIOContext *s, const char *tag); static void put_str16(ByteIOContext *s, const char *tag) { - put_le16(s,strlen(tag) + 1); - put_str16_nolen(s, tag); -} + int len; + uint8_t *pb; + ByteIOContext *dyn_buf; + if (url_open_dyn_buf(&dyn_buf) < 0) + return; -static void put_str16_nolen(ByteIOContext *s, const char *tag) -{ - int c; - - do{ - c = (uint8_t)*tag++; - put_le16(s, c); - }while(c); + ff_put_str16_nolen(dyn_buf, tag); + len = url_close_dyn_buf(dyn_buf, &pb); + put_le16(s, len); + put_buffer(s, pb, len); + av_freep(&pb); } static int64_t put_header(ByteIOContext *pb, const ff_asf_guid *g) @@ -272,7 +270,7 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data { ASFContext *asf = s->priv_data; ByteIOContext *pb = s->pb; - AVMetadataTag *title, *author, *copyright, *comment; + AVMetadataTag *tags[5]; int header_size, n, extra_size, extra_size2, wav_extra_size, file_time; int has_title; int metadata_count; @@ -281,13 +279,14 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data int bit_rate; int64_t duration; - title = av_metadata_get(s->metadata, "title" , NULL, 0); - author = av_metadata_get(s->metadata, "author" , NULL, 0); - copyright = av_metadata_get(s->metadata, "copyright", NULL, 0); - comment = av_metadata_get(s->metadata, "comment" , NULL, 0); + tags[0] = av_metadata_get(s->metadata, "title" , NULL, 0); + tags[1] = av_metadata_get(s->metadata, "author" , NULL, 0); + tags[2] = av_metadata_get(s->metadata, "copyright", NULL, 0); + tags[3] = av_metadata_get(s->metadata, "comment" , NULL, 0); + tags[4] = av_metadata_get(s->metadata, "rating" , NULL, 0); duration = asf->duration + PREROLL_TIME * 10000; - has_title = title || author || copyright || comment; + has_title = tags[0] || tags[1] || tags[2] || tags[3] || tags[4]; metadata_count = s->metadata ? s->metadata->count : 0; bit_rate = 0; @@ -335,16 +334,22 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data /* title and other infos */ if (has_title) { + int len; + uint8_t *buf; + ByteIOContext *dyn_buf; + + if (url_open_dyn_buf(&dyn_buf) < 0) + return AVERROR(ENOMEM); + hpos = put_header(pb, &ff_asf_comment_header); - put_le16(pb, title ? 2 * (strlen(title->value ) + 1) : 0); - put_le16(pb, author ? 2 * (strlen(author->value ) + 1) : 0); - put_le16(pb, copyright ? 2 * (strlen(copyright->value) + 1) : 0); - put_le16(pb, comment ? 2 * (strlen(comment->value ) + 1) : 0); - put_le16(pb, 0); - if (title ) put_str16_nolen(pb, title->value ); - if (author ) put_str16_nolen(pb, author->value ); - if (copyright) put_str16_nolen(pb, copyright->value); - if (comment ) put_str16_nolen(pb, comment->value ); + + for (n = 0; n < FF_ARRAY_ELEMS(tags); n++) { + len = tags[n] ? ff_put_str16_nolen(dyn_buf, tags[n]->value) : 0; + put_le16(pb, len); + } + len = url_close_dyn_buf(dyn_buf, &buf); + put_buffer(pb, buf, len); + av_freep(&buf); end_header(pb, hpos); } if (metadata_count) { @@ -352,14 +357,9 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data hpos = put_header(pb, &ff_asf_extended_content_header); put_le16(pb, metadata_count); while ((tag = av_metadata_get(s->metadata, "", tag, AV_METADATA_IGNORE_SUFFIX))) { - put_le16(pb, 2*(strlen(tag->key) + 3) + 1); - put_le16(pb, 'W'); - put_le16(pb, 'M'); - put_le16(pb, '/'); - put_str16_nolen(pb, tag->key); + put_str16(pb, tag->key); put_le16(pb, 0); - put_le16(pb, 2*strlen(tag->value) + 1); - put_str16_nolen(pb, tag->value); + put_str16(pb, tag->value); } end_header(pb, hpos); } @@ -375,13 +375,13 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data switch(enc->codec_type) { - case CODEC_TYPE_AUDIO: + case AVMEDIA_TYPE_AUDIO: wav_extra_size = 0; extra_size = 18 + wav_extra_size; extra_size2 = 8; break; default: - case CODEC_TYPE_VIDEO: + case AVMEDIA_TYPE_VIDEO: wav_extra_size = enc->extradata_size; extra_size = 0x33 + wav_extra_size; extra_size2 = 0; @@ -389,7 +389,7 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data } hpos = put_header(pb, &ff_asf_stream_header); - if (enc->codec_type == CODEC_TYPE_AUDIO) { + if (enc->codec_type == AVMEDIA_TYPE_AUDIO) { put_guid(pb, &ff_asf_audio_stream); put_guid(pb, &ff_asf_audio_conceal_spread); } else { @@ -403,7 +403,7 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data put_le16(pb, n + 1); /* stream number */ put_le32(pb, 0); /* ??? */ - if (enc->codec_type == CODEC_TYPE_AUDIO) { + 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)) { @@ -449,26 +449,41 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data put_le32(pb, s->nb_streams); for(n=0;nnb_streams;n++) { AVCodec *p; + const char *desc; + int len; + uint8_t *buf; + ByteIOContext *dyn_buf; enc = s->streams[n]->codec; p = avcodec_find_encoder(enc->codec_id); - if(enc->codec_type == CODEC_TYPE_AUDIO) + if(enc->codec_type == AVMEDIA_TYPE_AUDIO) put_le16(pb, 2); - else if(enc->codec_type == CODEC_TYPE_VIDEO) + else if(enc->codec_type == AVMEDIA_TYPE_VIDEO) put_le16(pb, 1); else put_le16(pb, -1); if(enc->codec_id == CODEC_ID_WMAV2) - put_str16(pb, "Windows Media Audio V8"); + desc = "Windows Media Audio V8"; else - put_str16(pb, p ? p->name : enc->codec_name); + desc = p ? p->name : enc->codec_name; + + if ( url_open_dyn_buf(&dyn_buf) < 0) + return AVERROR(ENOMEM); + + ff_put_str16_nolen(dyn_buf, desc); + len = url_close_dyn_buf(dyn_buf, &buf); + put_le16(pb, len / 2); // "number of characters" = length in bytes / 2 + + put_buffer(pb, buf, len); + av_freep(&buf); + put_le16(pb, 0); /* no parameters */ /* id */ - if (enc->codec_type == CODEC_TYPE_AUDIO) { + if (enc->codec_type == AVMEDIA_TYPE_AUDIO) { put_le16(pb, 2); put_le16(pb, enc->codec_tag); } else { @@ -653,7 +668,7 @@ static void put_payload_header( int val; val = stream->num; - if (flags & PKT_FLAG_KEY) + if (flags & AV_PKT_FLAG_KEY) val |= ASF_PL_FLAG_KEY_FRAME; put_byte(pb, val); @@ -707,7 +722,7 @@ static void put_frame( // multi payloads frag_len1 = asf->packet_size_left - PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS - PACKET_HEADER_MIN_SIZE - 1; - if(frag_len1 < payload_len && avst->codec->codec_type == CODEC_TYPE_AUDIO){ + if(frag_len1 < payload_len && avst->codec->codec_type == AVMEDIA_TYPE_AUDIO){ flush_packet(s); continue; } @@ -755,8 +770,8 @@ static int asf_write_packet(AVFormatContext *s, AVPacket *pkt) codec = s->streams[pkt->stream_index]->codec; stream = &asf->streams[pkt->stream_index]; - if(codec->codec_type == CODEC_TYPE_AUDIO) - flags &= ~PKT_FLAG_KEY; + if(codec->codec_type == AVMEDIA_TYPE_AUDIO) + flags &= ~AV_PKT_FLAG_KEY; pts = (pkt->pts != AV_NOPTS_VALUE) ? pkt->pts : pkt->dts; assert(pts != AV_NOPTS_VALUE); @@ -767,7 +782,7 @@ static int asf_write_packet(AVFormatContext *s, AVPacket *pkt) put_frame(s, stream, s->streams[pkt->stream_index], pkt->dts, pkt->data, pkt->size, flags); /* check index */ - if ((!asf->is_streamed) && (flags & PKT_FLAG_KEY)) { + if ((!asf->is_streamed) && (flags & AV_PKT_FLAG_KEY)) { start_sec = (int)(duration / INT64_C(10000000)); if (start_sec != (int)(asf->last_indexed_pts / INT64_C(10000000))) { for(i=asf->nb_index_count;icodec->codec_type = CODEC_TYPE_SUBTITLE; + st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; st->codec->codec_id= CODEC_ID_SSA; header_remaining= INT_MAX; @@ -165,7 +165,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) end= strchr(p, '\n'); av_new_packet(pkt, end ? end-p+1 : strlen(p)); - pkt->flags |= PKT_FLAG_KEY; + pkt->flags |= AV_PKT_FLAG_KEY; pkt->pos= p - ass->event_buffer + s->streams[0]->codec->extradata_size; pkt->pts= pkt->dts= get_pts(p); memcpy(pkt->data, p, pkt->size); diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/au.c b/src/add-ons/media/plugins/ffmpeg/libavformat/au.c index cc243ea483..f8f718d4ff 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/au.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/au.c @@ -44,7 +44,7 @@ static const AVCodecTag codec_au_tags[] = { { CODEC_ID_PCM_F32BE, 6 }, { CODEC_ID_PCM_F64BE, 7 }, { CODEC_ID_PCM_ALAW, 27 }, - { 0, 0 }, + { CODEC_ID_NONE, 0 }, }; #if CONFIG_AU_MUXER @@ -148,7 +148,7 @@ static int au_read_header(AVFormatContext *s, st = av_new_stream(s, 0); if (!st) return -1; - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_tag = id; st->codec->codec_id = codec; st->codec->channels = channels; @@ -157,18 +157,18 @@ static int au_read_header(AVFormatContext *s, return 0; } -#define MAX_SIZE 4096 +#define BLOCK_SIZE 1024 static int au_read_packet(AVFormatContext *s, AVPacket *pkt) { int ret; - if (url_feof(s->pb)) - return AVERROR(EIO); - ret= av_get_packet(s->pb, pkt, MAX_SIZE); + ret= av_get_packet(s->pb, pkt, BLOCK_SIZE * + s->streams[0]->codec->channels * + av_get_bits_per_sample(s->streams[0]->codec->codec_id) >> 3); if (ret < 0) - return AVERROR(EIO); + return ret; pkt->stream_index = 0; /* note: we need to modify the packet size here to handle the last diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/audiointerleave.c b/src/add-ons/media/plugins/ffmpeg/libavformat/audiointerleave.c index a3a6531348..3c235c069e 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/audiointerleave.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/audiointerleave.c @@ -32,7 +32,7 @@ void ff_audio_interleave_close(AVFormatContext *s) AVStream *st = s->streams[i]; AudioInterleaveContext *aic = st->priv_data; - if (st->codec->codec_type == CODEC_TYPE_AUDIO) + if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) av_fifo_free(aic->fifo); } } @@ -50,7 +50,7 @@ int ff_audio_interleave_init(AVFormatContext *s, AVStream *st = s->streams[i]; AudioInterleaveContext *aic = st->priv_data; - if (st->codec->codec_type == CODEC_TYPE_AUDIO) { + if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { aic->sample_size = (st->codec->channels * av_get_bits_per_sample(st->codec->codec_id)) / 8; if (!aic->sample_size) { @@ -103,7 +103,7 @@ int ff_audio_rechunk_interleave(AVFormatContext *s, AVPacket *out, AVPacket *pkt if (pkt) { AVStream *st = s->streams[pkt->stream_index]; AudioInterleaveContext *aic = st->priv_data; - if (st->codec->codec_type == CODEC_TYPE_AUDIO) { + if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { unsigned new_size = av_fifo_size(aic->fifo) + pkt->size; if (new_size > aic->fifo_size) { if (av_fifo_realloc2(aic->fifo, new_size) < 0) @@ -122,7 +122,7 @@ int ff_audio_rechunk_interleave(AVFormatContext *s, AVPacket *out, AVPacket *pkt for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - if (st->codec->codec_type == CODEC_TYPE_AUDIO) { + if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { AVPacket new_pkt; while (ff_interleave_new_audio_packet(s, &new_pkt, i, flush)) ff_interleave_add_packet(s, &new_pkt, compare_ts); diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/avc.c b/src/add-ons/media/plugins/ffmpeg/libavformat/avc.c index 0731e39698..7c991961c9 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/avc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/avc.c @@ -22,8 +22,9 @@ #include "libavutil/intreadwrite.h" #include "avformat.h" #include "avio.h" +#include "avc.h" -const uint8_t *ff_avc_find_startcode(const uint8_t *p, const uint8_t *end) +static const uint8_t *ff_avc_find_startcode_internal(const uint8_t *p, const uint8_t *end) { const uint8_t *a = p + 4 - ((intptr_t)p & 3); @@ -39,15 +40,15 @@ const uint8_t *ff_avc_find_startcode(const uint8_t *p, const uint8_t *end) if ((x - 0x01010101) & (~x) & 0x80808080) { // generic if (p[1] == 0) { if (p[0] == 0 && p[2] == 1) - return p-1; - if (p[2] == 0 && p[3] == 1) return p; + if (p[2] == 0 && p[3] == 1) + return p+1; } if (p[3] == 0) { if (p[2] == 0 && p[4] == 1) - return p+1; - if (p[4] == 0 && p[5] == 1) return p+2; + if (p[4] == 0 && p[5] == 1) + return p+3; } } } @@ -60,6 +61,12 @@ const uint8_t *ff_avc_find_startcode(const uint8_t *p, const uint8_t *end) return end + 3; } +const uint8_t *ff_avc_find_startcode(const uint8_t *p, const uint8_t *end){ + const uint8_t *out= ff_avc_find_startcode_internal(p, end); + if(p #include /* FILE */ #include "libavcodec/avcodec.h" @@ -52,7 +63,9 @@ struct AVFormatContext; /* * Public Metadata API. * The metadata API allows libavformat to export metadata tags to a client - * application using a sequence of key/value pairs. + * 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: * 1. Keys are unique; there can never be 2 tags with the same key. This is * also meant semantically, i.e., a demuxer should not knowingly produce @@ -62,15 +75,51 @@ struct AVFormatContext; * 2. Metadata is flat, not hierarchical; there are no subtags. If you * want to store, e.g., the email address of the child of producer Alice * and actor Bob, that could have key=alice_and_bobs_childs_email_address. - * 3. A tag whose value is localized for a particular language is appended - * with a dash character ('-') and the ISO 639-2/B 3-letter language code. - * For example: Author-ger=Michael, Author-eng=Mike - * The original/default language is in the unqualified "Author" tag. - * A demuxer should set a default if it sets any translated tag. + * 3. Several modifiers can be applied to the tag name. This is done by + * appending a dash character ('-') and the modifier name in the order + * they appear in the list below -- e.g. foo-eng-sort, not foo-sort-eng. + * a) language -- a tag whose value is localized for a particular language + * is appended with the ISO 639-2/B 3-letter language code. + * For example: Author-ger=Michael, Author-eng=Mike + * The original/default language is in the unqualified "Author" tag. + * A demuxer should set a default if it sets any translated tag. + * b) sorting -- a modified version of a tag that should be used for + * sorting will have '-sort' appended. E.g. artist="The Beatles", + * artist-sort="Beatles, The". + * + * 4. Tag names are normally exported exactly as stored in the container to + * allow lossless remuxing to the same format. For container-independent + * handling of metadata, av_metadata_conv() can convert it to ffmpeg generic + * format. Follows a list of generic tag names: + * + * album -- name of the set this work belongs to + * album_artist -- main creator of the set/album, if different from artist. + * e.g. "Various Artists" for compilation albums. + * artist -- main creator of the work + * comment -- any additional description of the file. + * composer -- who composed the work, if different from artist. + * copyright -- name of copyright holder. + * date -- date when the work was created, preferably in ISO 8601. + * disc -- number of a subset, e.g. disc in a multi-disc collection. + * encoder -- name/settings of the software/hardware that produced the file. + * encoded_by -- person/group who created the file. + * filename -- original name of the file. + * genre -- . + * language -- main language in which the work is performed, preferably + * in ISO 639-2 format. + * performer -- artist who performed the work, if different from artist. + * E.g for "Also sprach Zarathustra", artist would be "Richard + * Strauss" and performer "London Philharmonic Orchestra". + * publisher -- name of the label/publisher. + * title -- name of the work. + * track -- number of this work in the set, can be in form current/total. */ #define AV_METADATA_MATCH_CASE 1 #define AV_METADATA_IGNORE_SUFFIX 2 +#define AV_METADATA_DONT_STRDUP_KEY 4 +#define AV_METADATA_DONT_STRDUP_VAL 8 +#define AV_METADATA_DONT_OVERWRITE 16 ///< Don't overwrite existing tags. typedef struct { char *key; @@ -83,23 +132,36 @@ typedef struct AVMetadataConv AVMetadataConv; /** * Gets a metadata element with matching key. * @param prev Set to the previous matching element to find the next. + * If set to NULL the first matching element is returned. * @param flags Allows case as well as suffix-insensitive comparisons. * @return Found tag or NULL, changing key or value leads to undefined behavior. */ AVMetadataTag * av_metadata_get(AVMetadata *m, const char *key, const AVMetadataTag *prev, int flags); +#if LIBAVFORMAT_VERSION_MAJOR == 52 /** * Sets the given tag in m, overwriting an existing tag. * @param key tag key to add to m (will be av_strduped) * @param value tag value to add to m (will be av_strduped) * @return >= 0 on success otherwise an error code <0 + * @deprecated Use av_metadata_set2() instead. */ -int av_metadata_set(AVMetadata **pm, const char *key, const char *value); +attribute_deprecated int av_metadata_set(AVMetadata **pm, const char *key, const char *value); +#endif + +/** + * Sets the given tag in m, overwriting an existing tag. + * @param key tag key to add to m (will be av_strduped depending on flags) + * @param value tag value to add to m (will be av_strduped depending on flags) + * @return >= 0 on success otherwise an error code <0 + */ +int av_metadata_set2(AVMetadata **pm, const char *key, const char *value, int flags); /** * Converts all the metadata sets from ctx according to the source and - * destination conversion tables. + * destination conversion tables. If one of the tables is NULL, then + * tags are converted to/from ffmpeg generic tag names. * @param d_conv destination tags format conversion table * @param s_conv source tags format conversion table */ @@ -145,8 +207,8 @@ struct AVCodecTag; /** This structure contains the data a format has to probe a file. */ typedef struct AVProbeData { const char *filename; - unsigned char *buf; - int buf_size; + unsigned char *buf; /**< Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero. */ + int buf_size; /**< Size of buf except extra allocated bytes */ } AVProbeData; #define AVPROBE_SCORE_MAX 100 ///< maximum score, half of that is used for file-extension-based detection @@ -185,6 +247,7 @@ typedef struct AVFormatParameters { #define AVFMT_GENERIC_INDEX 0x0100 /**< Use generic index building code. */ #define AVFMT_TS_DISCONT 0x0200 /**< Format allows timestamp discontinuities. */ #define AVFMT_VARIABLE_FPS 0x0400 /**< Format allows variable fps. */ +#define AVFMT_NODIMENSIONS 0x0800 /**< Format does not need width/height */ typedef struct AVOutputFormat { const char *name; @@ -448,8 +511,24 @@ typedef struct AVStream { * Number of packets to buffer for codec probing * NOT PART OF PUBLIC API */ -#define MAX_PROBE_PACKETS 100 +#define MAX_PROBE_PACKETS 2500 int probe_packets; + + /** + * last packet in packet_buffer for this stream when muxing. + * used internally, NOT PART OF PUBLIC API, dont read or write from outside of libav* + */ + struct AVPacketList *last_in_packet_buffer; + + /** + * Average framerate + */ + AVRational avg_frame_rate; + + /** + * Number of frames that have been demuxed during av_find_stream_info() + */ + int codec_info_nb_frames; } AVStream; #define AV_PROGRAM_RUNNING 1 @@ -486,7 +565,11 @@ typedef struct AVChapter { AVMetadata *metadata; } AVChapter; +#if LIBAVFORMAT_VERSION_MAJOR < 53 #define MAX_STREAMS 20 +#else +#define MAX_STREAMS 100 +#endif /** * Format I/O context. @@ -530,8 +613,9 @@ typedef struct AVFormatContext { It is deduced from the AVStream values. */ int64_t start_time; /** Decoding: duration of the stream, in AV_TIME_BASE fractional - seconds. NEVER set this value directly: it is deduced from the - AVStream values. */ + seconds. Only set this value if you know none of the individual stream + durations and also dont set any of them. This is deduced from the + AVStream values if not set. */ int64_t duration; /** decoding: total file size, 0 if unknown */ int64_t file_size; @@ -566,6 +650,10 @@ typedef struct AVFormatContext { #define AVFMT_FLAG_GENPTS 0x0001 ///< Generate missing pts even if it requires parsing future frames. #define AVFMT_FLAG_IGNIDX 0x0002 ///< Ignore index. #define AVFMT_FLAG_NONBLOCK 0x0004 ///< Do not block when reading packets from input. +#define AVFMT_FLAG_IGNDTS 0x0008 ///< Ignore DTS on frames that contain both DTS & PTS +#define AVFMT_FLAG_NOFILLIN 0x0010 ///< Do not infer any values from other values, just return what is stored in the container +#define AVFMT_FLAG_NOPARSE 0x0020 ///< Do not use AVParsers, you also must set AVFMT_FLAG_NOFILLIN as the fillin code works on frames and no parsing -> no frames. Also seeking to frames can not work if parsing to find frame boundaries has been disabled +#define AVFMT_FLAG_RTP_HINT 0x0040 ///< Add RTP hinting to the output file int loop_input; /** decoding: size of data to probe; encoding: unused. */ @@ -643,8 +731,17 @@ typedef struct AVFormatContext { * Remaining size available for raw_packet_buffer, in bytes. * NOT PART OF PUBLIC API */ -#define RAW_PACKET_BUFFER_SIZE 32000 +#define RAW_PACKET_BUFFER_SIZE 2500000 int raw_packet_buffer_remaining_size; + + /** + * Start time of the stream in real world time, in microseconds + * since the unix epoch (00:00 1st January 1970). That is, pts=0 + * in the stream was captured at this real world time. + * - encoding: Set by user. + * - decoding: Unused. + */ + int64_t start_time_realtime; } AVFormatContext; typedef struct AVPacketList { @@ -679,19 +776,41 @@ enum CodecID av_guess_image2_codec(const char *filename); /* utils.c */ void av_register_input_format(AVInputFormat *format); void av_register_output_format(AVOutputFormat *format); -AVOutputFormat *guess_stream_format(const char *short_name, +#if LIBAVFORMAT_VERSION_MAJOR < 53 +attribute_deprecated AVOutputFormat *guess_stream_format(const char *short_name, const char *filename, const char *mime_type); -AVOutputFormat *guess_format(const char *short_name, - const char *filename, - const char *mime_type); + +/** + * @deprecated Use av_guess_format() instead. + */ +attribute_deprecated AVOutputFormat *guess_format(const char *short_name, + const char *filename, + const char *mime_type); +#endif + +/** + * Returns the output format in the list of registered output formats + * which best matches the provided parameters, or returns NULL if + * there is no match. + * + * @param short_name if non-NULL checks if short_name matches with the + * names of the registered formats + * @param filename if non-NULL checks if filename terminates with the + * extensions of the registered formats + * @param mime_type if non-NULL checks if mime_type matches with the + * MIME type of the registered formats + */ +AVOutputFormat *av_guess_format(const char *short_name, + const char *filename, + const char *mime_type); /** * Guesses the codec ID based upon muxer and filename. */ enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name, const char *filename, const char *mime_type, - enum CodecType type); + enum AVMediaType type); /** * Sends a nice hexadecimal dump of a buffer to the specified file stream. @@ -769,6 +888,19 @@ AVInputFormat *av_find_input_format(const char *short_name); */ AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened); +/** + * Guesses the file format. + * + * @param is_opened Whether the file is already opened; determines whether + * demuxers with or without AVFMT_NOFILE are probed. + * @param score_max A probe score larger that this is required to accept a + * detection, the variable is set to the actual detection + * score afterwards. + * If the score is <= AVPROBE_SCORE_MAX / 4 it is recommended + * to retry with a larger probe buffer. + */ +AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max); + /** * Allocates all the structures needed to read an input stream. * This does not open the needed codecs for decoding the stream[s]. @@ -890,7 +1022,7 @@ int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, * @param ts target timestamp * @param max_ts largest acceptable timestamp * @param flags flags - * @returns >=0 on success, error code otherwise + * @return >=0 on success, error code otherwise * * @NOTE This is part of the new seek API which is still under construction. * Thus do not use this yet. It may change at any time, do not expect @@ -1212,48 +1344,12 @@ int av_filename_number_test(const char *filename); */ int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size); -#ifdef HAVE_AV_CONFIG_H - -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);\ -} while(0) -#else -#define dynarray_add(tab, nb_ptr, elem)\ -do {\ - ff_dynarray_add((intptr_t **)(tab), nb_ptr, (intptr_t)(elem));\ -} while(0) -#endif - -time_t mktimegm(struct tm *tm); -struct tm *brktimegm(time_t secs, struct tm *tm); -const char *small_strptime(const char *p, const char *fmt, - struct tm *dt); - -struct in_addr; -int resolve_host(struct in_addr *sin_addr, const char *hostname); - -void url_split(char *proto, int proto_size, - char *authorization, int authorization_size, - char *hostname, int hostname_size, - int *port_ptr, - char *path, int path_size, - const char *url); - /** * Returns a positive value if the given filename has one of the given * extensions, 0 otherwise. * * @param extensions a comma-separated list of filename extensions */ -int match_ext(const char *filename, const char *extensions); - -#endif /* HAVE_AV_CONFIG_H */ +int av_match_ext(const char *filename, const char *extensions); #endif /* AVFORMAT_AVFORMAT_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/avi.c b/src/add-ons/media/plugins/ffmpeg/libavformat/avi.c new file mode 100644 index 0000000000..705ad03ab0 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/avi.c @@ -0,0 +1,45 @@ +/* + * AVI common data + * Copyright (c) 2010 Anton Khirnov + * + * 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 "avi.h" + +const AVMetadataConv ff_avi_metadata_conv[] = { + { "IART", "artist" }, + { "ICMT", "comment" }, + { "ICOP", "copyright" }, + { "ICRD", "date" }, + { "IGNR", "genre" }, + { "ILNG", "language" }, + { "INAM", "title" }, + { "IPRD", "album" }, + { "IPRT", "track" }, + { "ISFT", "encoder" }, + { "ITCH", "encoded_by"}, + { "strn", "title" }, + { 0 }, +}; + +const char ff_avi_tags[][5] = { + "IARL", "IART", "ICMS", "ICMT", "ICOP", "ICRD", "ICRP", "IDIM", "IDPI", + "IENG", "IGNR", "IKEY", "ILGT", "ILNG", "IMED", "INAM", "IPLT", "IPRD", + "IPRT", "ISBJ", "ISFT", "ISHP", "ISRC", "ISRF", "ITCH", + {0} +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/avi.h b/src/add-ons/media/plugins/ffmpeg/libavformat/avi.h index 2214c03b98..f345c14760 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/avi.h +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/avi.h @@ -21,6 +21,8 @@ #ifndef AVFORMAT_AVI_H #define AVFORMAT_AVI_H +#include "metadata.h" + #define AVIF_HASINDEX 0x00000010 // Index at end of file? #define AVIF_MUSTUSEINDEX 0x00000020 #define AVIF_ISINTERLEAVED 0x00000100 @@ -34,4 +36,11 @@ /* index flags */ #define AVIIF_INDEX 0x10 +extern const AVMetadataConv ff_avi_metadata_conv[]; + +/** + * A list of AVI info tags. + */ +extern const char ff_avi_tags[][5]; + #endif /* AVFORMAT_AVI_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/avidec.c b/src/add-ons/media/plugins/ffmpeg/libavformat/avidec.c index 71235ec47d..485c4eb93a 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/avidec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/avidec.c @@ -132,7 +132,7 @@ static int read_braindead_odml_indx(AVFormatContext *s, int frame_num){ longs_pre_entry,index_type, entries_in_use, chunk_id, base); #endif - if(stream_id > s->nb_streams || stream_id < 0) + if(stream_id >= s->nb_streams || stream_id < 0) return -1; st= s->streams[stream_id]; ast = st->priv_data; @@ -170,8 +170,8 @@ static int read_braindead_odml_indx(AVFormatContext *s, int frame_num){ if(last_pos == pos || pos == base - 8) avi->non_interleaved= 1; - if(last_pos != pos) - av_add_index_entry(st, pos, ast->cum_len / FFMAX(1, ast->sample_size), len, 0, key ? AVINDEX_KEYFRAME : 0); + if(last_pos != pos && (len || !ast->sample_size)) + av_add_index_entry(st, pos, ast->cum_len, len, 0, key ? AVINDEX_KEYFRAME : 0); if(ast->sample_size) ast->cum_len += len; @@ -222,22 +222,43 @@ static void clean_index(AVFormatContext *s){ ts= st->index_entries[0].timestamp; for(j=0; jsample_size, FFMIN(max, size-j), 0, AVINDEX_KEYFRAME); + av_add_index_entry(st, pos+j, ts+j, FFMIN(max, size-j), 0, AVINDEX_KEYFRAME); } } } -static int avi_read_tag(AVFormatContext *s, const char *key, unsigned int size) +static int avi_read_tag(AVFormatContext *s, AVStream *st, uint32_t tag, uint32_t size) { ByteIOContext *pb = s->pb; - uint8_t value[1024]; + char key[5] = {0}, *value; - int64_t i = url_ftell(pb); size += (size & 1); - get_strz(pb, value, sizeof(value)); - url_fseek(pb, i+size, SEEK_SET); - return av_metadata_set(&s->metadata, key, value); + if (size == UINT_MAX) + return -1; + value = av_malloc(size+1); + if (!value) + return -1; + get_buffer(pb, value, size); + value[size]=0; + + AV_WL32(key, tag); + + if(st) + return av_metadata_set2(&st->metadata, key, value, + AV_METADATA_DONT_STRDUP_VAL); + else + return av_metadata_set2(&s->metadata, key, value, + AV_METADATA_DONT_STRDUP_VAL); +} + +static void avi_read_info(AVFormatContext *s, uint64_t end) +{ + while (url_ftell(s->pb) < end) { + uint32_t tag = get_le32(s->pb); + uint32_t size = get_le32(s->pb); + avi_read_tag(s, NULL, tag, size); + } } static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) @@ -246,7 +267,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) ByteIOContext *pb = s->pb; unsigned int tag, tag1, handler; int codec_type, stream_index, frame_period, bit_rate; - unsigned int size, nb_frames; + unsigned int size; int i; AVStream *st; AVIStream *ast = NULL; @@ -291,6 +312,9 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) dprintf(NULL, "movi end=%"PRIx64"\n", avi->movi_end); goto end_of_header; } + else if (tag1 == MKTAG('I', 'N', 'F', 'O')) + avi_read_info(s, list_end); + break; case MKTAG('d', 'm', 'l', 'h'): avi->is_odml = 1; @@ -407,10 +431,9 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) av_set_pts_info(st, 64, ast->scale, ast->rate); ast->cum_len=get_le32(pb); /* start */ - nb_frames = get_le32(pb); + st->nb_frames = get_le32(pb); st->start_time = 0; - st->duration = nb_frames; get_le32(pb); /* buffer size */ get_le32(pb); /* quality */ ast->sample_size = get_le32(pb); /* sample ssize */ @@ -419,24 +442,26 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) switch(tag1) { case MKTAG('v', 'i', 'd', 's'): - codec_type = CODEC_TYPE_VIDEO; + codec_type = AVMEDIA_TYPE_VIDEO; ast->sample_size = 0; break; case MKTAG('a', 'u', 'd', 's'): - codec_type = CODEC_TYPE_AUDIO; + codec_type = AVMEDIA_TYPE_AUDIO; break; case MKTAG('t', 'x', 't', 's'): //FIXME - codec_type = CODEC_TYPE_DATA; //CODEC_TYPE_SUB ? FIXME + codec_type = AVMEDIA_TYPE_DATA; //AVMEDIA_TYPE_SUB ? FIXME break; case MKTAG('d', 'a', 't', 's'): - codec_type = CODEC_TYPE_DATA; + codec_type = AVMEDIA_TYPE_DATA; break; default: av_log(s, AV_LOG_ERROR, "unknown stream type %X\n", tag1); goto fail; } + if(ast->sample_size == 0) + st->duration = st->nb_frames; ast->frame_offset= ast->cum_len; url_fskip(pb, size - 12 * 4); break; @@ -450,11 +475,11 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) size = FFMIN(size, list_end - cur_pos); st = s->streams[stream_index]; switch(codec_type) { - case CODEC_TYPE_VIDEO: + case AVMEDIA_TYPE_VIDEO: if(amv_file_format){ st->codec->width=avih_width; st->codec->height=avih_height; - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_AMV; url_fskip(pb, size); break; @@ -471,8 +496,8 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) get_le32(pb); /* ClrUsed */ get_le32(pb); /* ClrImportant */ - if (tag1 == MKTAG('D', 'X', 'S', 'B')) { - st->codec->codec_type = CODEC_TYPE_SUBTITLE; + if (tag1 == MKTAG('D', 'X', 'S', 'B') || tag1 == MKTAG('D','X','S','A')) { + st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; st->codec->codec_tag = tag1; st->codec->codec_id = CODEC_ID_XSUB; break; @@ -509,10 +534,15 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) #ifdef DEBUG print_tag("video", tag1, 0); #endif - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_tag = tag1; st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tag1); st->need_parsing = AVSTREAM_PARSE_HEADERS; // This is needed to get the pict type which is necessary for generating correct pts. + // Support "Resolution 1:1" for Avid AVI Codec + if(tag1 == MKTAG('A', 'V', 'R', 'n') && + st->codec->extradata_size >= 31 && + !memcmp(&st->codec->extradata[28], "1:1", 3)) + st->codec->codec_id = CODEC_ID_RAWVIDEO; if(st->codec->codec_tag==0 && st->codec->height > 0 && st->codec->extradata_size < 1U<<30){ st->codec->extradata_size+= 9; @@ -524,13 +554,13 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) // url_fskip(pb, size - 5 * 4); break; - case CODEC_TYPE_AUDIO: + case AVMEDIA_TYPE_AUDIO: ff_get_wav_header(pb, st->codec, size); if(ast->sample_size && st->codec->block_align && ast->sample_size != st->codec->block_align){ av_log(s, AV_LOG_WARNING, "sample size (%d) != block align (%d)\n", ast->sample_size, st->codec->block_align); ast->sample_size= st->codec->block_align; } - if (size%2) /* 2-aligned (fix for Stargate SG-1 - 3x18 - Shades of Grey.avi) */ + if (size&1) /* 2-aligned (fix for Stargate SG-1 - 3x18 - Shades of Grey.avi) */ url_fskip(pb, 1); /* Force parsing as several audio frames can be in * one packet and timestamps refer to packet start. */ @@ -550,7 +580,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) st->codec->codec_id = CODEC_ID_ADPCM_IMA_AMV; break; default: - st->codec->codec_type = CODEC_TYPE_DATA; + st->codec->codec_type = AVMEDIA_TYPE_DATA; st->codec->codec_id= CODEC_ID_NONE; st->codec->codec_tag= 0; url_fskip(pb, size); @@ -590,27 +620,11 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) } url_fseek(pb, size, SEEK_CUR); break; - case MKTAG('I', 'N', 'A', 'M'): - avi_read_tag(s, "Title", size); - break; - case MKTAG('I', 'A', 'R', 'T'): - avi_read_tag(s, "Artist", size); - break; - case MKTAG('I', 'C', 'O', 'P'): - avi_read_tag(s, "Copyright", size); - break; - case MKTAG('I', 'C', 'M', 'T'): - avi_read_tag(s, "Comment", size); - break; - case MKTAG('I', 'G', 'N', 'R'): - avi_read_tag(s, "Genre", size); - break; - case MKTAG('I', 'P', 'R', 'D'): - avi_read_tag(s, "Album", size); - break; - case MKTAG('I', 'P', 'R', 'T'): - avi_read_tag(s, "Track", size); - break; + case MKTAG('s', 't', 'r', 'n'): + if(s->nb_streams){ + avi_read_tag(s, s->streams[s->nb_streams-1], tag, size); + break; + } default: if(size > 1000000){ av_log(s, AV_LOG_ERROR, "Something went wrong during header parsing, " @@ -636,6 +650,16 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) avi_load_index(s); avi->index_loaded = 1; avi->non_interleaved |= guess_ni_flag(s); + for(i=0; inb_streams; i++){ + AVStream *st = s->streams[i]; + if(st->nb_index_entries) + break; + } + 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; + } + if(avi->non_interleaved) { av_log(s, AV_LOG_INFO, "non-interleaved AVI\n"); clean_index(s); @@ -679,13 +703,19 @@ static int avi_read_packet(AVFormatContext *s, AVPacket *pkt) AVStream *st = s->streams[i]; AVIStream *ast = st->priv_data; int64_t ts= ast->frame_offset; + int64_t last_ts; - if(ast->sample_size) - ts /= ast->sample_size; - ts = av_rescale_q(ts, st->time_base, AV_TIME_BASE_Q); + if(!st->nb_index_entries) + continue; + + last_ts = st->index_entries[st->nb_index_entries - 1].timestamp; + if(!ast->remaining && ts > last_ts) + continue; + + ts = av_rescale_q(ts, st->time_base, (AVRational){FFMAX(1, ast->sample_size), AV_TIME_BASE}); // av_log(s, AV_LOG_DEBUG, "%"PRId64" %d/%d %"PRId64"\n", ts, st->time_base.num, st->time_base.den, ast->frame_offset); - if(ts < best_ts && st->nb_index_entries){ + if(ts < best_ts){ best_ts= ts; best_st= st; best_stream_index= i; @@ -695,14 +725,13 @@ static int avi_read_packet(AVFormatContext *s, AVPacket *pkt) return -1; best_ast = best_st->priv_data; - best_ts = av_rescale_q(best_ts, AV_TIME_BASE_Q, best_st->time_base); + best_ts = av_rescale_q(best_ts, (AVRational){FFMAX(1, best_ast->sample_size), AV_TIME_BASE}, best_st->time_base); if(best_ast->remaining) i= av_index_search_timestamp(best_st, best_ts, AVSEEK_FLAG_ANY | AVSEEK_FLAG_BACKWARD); else{ i= av_index_search_timestamp(best_st, best_ts, AVSEEK_FLAG_ANY); if(i>=0) - best_ast->frame_offset= best_st->index_entries[i].timestamp - * FFMAX(1, best_ast->sample_size); + best_ast->frame_offset= best_st->index_entries[i].timestamp; } // av_log(s, AV_LOG_DEBUG, "%d\n", i); @@ -730,7 +759,8 @@ resync: if(ast->sample_size <= 1) // minorityreport.AVI block_align=1024 sample_size=1 IMA-ADPCM size= INT_MAX; else if(ast->sample_size < 32) - size= 64*ast->sample_size; + // arbitrary multiplier to avoid tiny packets for raw PCM data + size= 1024*ast->sample_size; else size= ast->sample_size; @@ -757,7 +787,7 @@ resync: size = dv_produce_packet(avi->dv_demux, pkt, pkt->data, pkt->size); pkt->destruct = dstr; - pkt->flags |= PKT_FLAG_KEY; + pkt->flags |= AV_PKT_FLAG_KEY; } else { /* XXX: How to handle B-frames in AVI? */ pkt->dts = ast->frame_offset; @@ -767,20 +797,20 @@ resync: //av_log(s, AV_LOG_DEBUG, "dts:%"PRId64" offset:%"PRId64" %d/%d smpl_siz:%d base:%d st:%d size:%d\n", pkt->dts, ast->frame_offset, ast->scale, ast->rate, ast->sample_size, AV_TIME_BASE, avi->stream_index, size); pkt->stream_index = avi->stream_index; - if (st->codec->codec_type == CODEC_TYPE_VIDEO) { + if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { AVIndexEntry *e; int index; assert(st->index_entries); - index= av_index_search_timestamp(st, pkt->dts, 0); + index= av_index_search_timestamp(st, ast->frame_offset, 0); e= &st->index_entries[index]; if(index >= 0 && e->timestamp == ast->frame_offset){ if (e->flags & AVINDEX_KEYFRAME) - pkt->flags |= PKT_FLAG_KEY; + pkt->flags |= AV_PKT_FLAG_KEY; } } else { - pkt->flags |= PKT_FLAG_KEY; + pkt->flags |= AV_PKT_FLAG_KEY; } if(ast->sample_size) ast->frame_offset += pkt->size; @@ -821,11 +851,23 @@ resync: goto resync; } + //parse stray LIST + if(d[0] == 'L' && d[1] == 'I' && d[2] == 'S' && d[3] == 'T'){ + url_fskip(pb, 4); + goto resync; + } + n= get_stream_idx(d); if(!((i-avi->last_pkt_pos)&1) && get_stream_idx(d+1) < s->nb_streams) continue; + //detect ##ix chunk and skip + if(d[2] == 'i' && d[3] == 'x' && n < s->nb_streams){ + url_fskip(pb, size); + goto resync; + } + //parse ##dc/##wb if(n < s->nb_streams){ AVStream *st; @@ -839,8 +881,8 @@ resync: //workaround for broken small-file-bug402.avi if( d[2] == 'w' && d[3] == 'b' && n==0 - && st ->codec->codec_type == CODEC_TYPE_VIDEO - && st1->codec->codec_type == CODEC_TYPE_AUDIO + && st ->codec->codec_type == AVMEDIA_TYPE_VIDEO + && st1->codec->codec_type == AVMEDIA_TYPE_AUDIO && ast->prefix == 'd'*256+'c' && (d[2]*256+d[3] == ast1->prefix || !ast1->prefix_count) ){ @@ -853,9 +895,9 @@ resync: if( (st->discard >= AVDISCARD_DEFAULT && size==0) - /*|| (st->discard >= AVDISCARD_NONKEY && !(pkt->flags & PKT_FLAG_KEY))*/ //FIXME needs a little reordering + /*|| (st->discard >= AVDISCARD_NONKEY && !(pkt->flags & AV_PKT_FLAG_KEY))*/ //FIXME needs a little reordering || st->discard >= AVDISCARD_ALL){ - if(ast->sample_size) ast->frame_offset += pkt->size; + if(ast->sample_size) ast->frame_offset += size; else ast->frame_offset++; url_fskip(pb, size); goto resync; @@ -888,10 +930,10 @@ resync: ast->packet_size= size + 8; ast->remaining= size; - { + if(size || !ast->sample_size){ uint64_t pos= url_ftell(pb) - 8; if(!st->index_entries || !st->nb_index_entries || st->index_entries[st->nb_index_entries - 1].pos < pos){ - av_add_index_entry(st, pos, ast->frame_offset / FFMAX(1, ast->sample_size), size, 0, AVINDEX_KEYFRAME); + av_add_index_entry(st, pos, ast->frame_offset, size, 0, AVINDEX_KEYFRAME); } } goto resync; @@ -947,8 +989,8 @@ static int avi_read_idx1(AVFormatContext *s, int size) if(last_pos == pos) avi->non_interleaved= 1; - else - av_add_index_entry(st, pos, ast->cum_len / FFMAX(1, ast->sample_size), len, 0, (flags&AVIIF_INDEX) ? AVINDEX_KEYFRAME : 0); + else if(len || !ast->sample_size) + av_add_index_entry(st, pos, ast->cum_len, len, 0, (flags&AVIIF_INDEX) ? AVINDEX_KEYFRAME : 0); if(ast->sample_size) ast->cum_len += len; else @@ -995,8 +1037,10 @@ static int avi_load_index(AVFormatContext *s) ByteIOContext *pb = s->pb; uint32_t tag, size; int64_t pos= url_ftell(pb); + int ret = -1; - url_fseek(pb, avi->movi_end, SEEK_SET); + if (url_fseek(pb, avi->movi_end, SEEK_SET) < 0) + goto the_end; // maybe truncated file #ifdef DEBUG_SEEK printf("movi_end=0x%"PRIx64"\n", avi->movi_end); #endif @@ -1017,19 +1061,20 @@ static int avi_load_index(AVFormatContext *s) case MKTAG('i', 'd', 'x', '1'): if (avi_read_idx1(s, size) < 0) goto skip; - else + ret = 0; goto the_end; break; default: skip: size += (size & 1); - url_fskip(pb, size); + if (url_fseek(pb, size, SEEK_CUR) < 0) + goto the_end; // something is wrong here break; } } the_end: url_fseek(pb, pos, SEEK_SET); - return 0; + return ret; } static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) @@ -1038,6 +1083,7 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp AVStream *st; int i, index; int64_t pos; + AVIStream *ast; if (!avi->index_loaded) { /* we only load the index on demand */ @@ -1047,13 +1093,14 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp assert(stream_index>= 0); st = s->streams[stream_index]; - index= av_index_search_timestamp(st, timestamp, flags); + ast= st->priv_data; + index= av_index_search_timestamp(st, timestamp * FFMAX(ast->sample_size, 1), flags); if(index<0) return -1; /* find the position */ pos = st->index_entries[index].pos; - timestamp = st->index_entries[index].timestamp; + timestamp = st->index_entries[index].timestamp / FFMAX(ast->sample_size, 1); // av_log(s, AV_LOG_DEBUG, "XX %"PRId64" %d %"PRId64"\n", timestamp, index, st->index_entries[index].timestamp); @@ -1086,7 +1133,7 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp assert((int64_t)st2->time_base.num*ast2->rate == (int64_t)st2->time_base.den*ast2->scale); index = av_index_search_timestamp( st2, - av_rescale_q(timestamp, st->time_base, st2->time_base), + av_rescale_q(timestamp, st->time_base, st2->time_base) * FFMAX(ast2->sample_size, 1), flags | AVSEEK_FLAG_BACKWARD); if(index<0) index=0; @@ -1101,8 +1148,6 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp // av_log(s, AV_LOG_DEBUG, "%"PRId64" %d %"PRId64"\n", timestamp, index, st2->index_entries[index].timestamp); /* extract the current frame number */ ast2->frame_offset = st2->index_entries[index].timestamp; - if(ast2->sample_size) - ast2->frame_offset *=ast2->sample_size; } /* do the seek */ @@ -1149,4 +1194,5 @@ AVInputFormat avi_demuxer = { avi_read_packet, avi_read_close, avi_read_seek, + .metadata_conv = ff_avi_metadata_conv, }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/avienc.c b/src/add-ons/media/plugins/ffmpeg/libavformat/avienc.c index 5ae95e2b6a..b4a31ec54a 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/avienc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/avienc.c @@ -21,6 +21,7 @@ #include "avformat.h" #include "avi.h" #include "riff.h" +#include "libavutil/intreadwrite.h" /* * TODO: @@ -42,14 +43,19 @@ typedef struct AVIIndex { typedef struct { int64_t riff_start, movi_list, odml_list; - int64_t frames_hdr_all, frames_hdr_strm[MAX_STREAMS]; - int audio_strm_length[MAX_STREAMS]; + int64_t frames_hdr_all; int riff_id; - int packet_count[MAX_STREAMS]; - - AVIIndex indexes[MAX_STREAMS]; } AVIContext; +typedef struct { + int64_t frames_hdr_strm; + int audio_strm_length; + int packet_count; + int entry; + + AVIIndex indexes; +} AVIStream ; + static inline AVIIentry* avi_get_ientry(AVIIndex* idx, int ent_id) { int cl = ent_id / AVI_INDEX_CLUSTER_SIZE; @@ -57,15 +63,18 @@ static inline AVIIentry* avi_get_ientry(AVIIndex* idx, int ent_id) return &idx->cluster[cl][id]; } -static int64_t avi_start_new_riff(AVIContext *avi, ByteIOContext *pb, +static int64_t avi_start_new_riff(AVFormatContext *s, ByteIOContext *pb, const char* riff_tag, const char* list_tag) { + AVIContext *avi= s->priv_data; int64_t loff; int i; avi->riff_id++; - for (i=0; iindexes[i].entry = 0; + for (i=0; inb_streams; i++){ + AVIStream *avist= s->streams[i]->priv_data; + avist->indexes.entry = 0; + } avi->riff_start = ff_start_tag(pb, "RIFF"); put_tag(pb, riff_tag); @@ -74,14 +83,14 @@ static int64_t avi_start_new_riff(AVIContext *avi, ByteIOContext *pb, return loff; } -static char* avi_stream2fourcc(char* tag, int index, enum CodecType type) +static char* avi_stream2fourcc(char* tag, int index, enum AVMediaType type) { tag[0] = '0'; tag[1] = '0' + index; - if (type == CODEC_TYPE_VIDEO) { + if (type == AVMEDIA_TYPE_VIDEO) { tag[2] = 'd'; tag[3] = 'c'; - } else if (type == CODEC_TYPE_SUBTITLE) { + } else if (type == AVMEDIA_TYPE_SUBTITLE) { // note: this is not an official code tag[2] = 's'; tag[3] = 'b'; @@ -106,15 +115,6 @@ static void avi_write_info_tag(ByteIOContext *pb, const char *tag, const char *s } } -static void avi_write_info_tag2(AVFormatContext *s, const char *fourcc, const char *key1, const char *key2) -{ - AVMetadataTag *tag= av_metadata_get(s->metadata, key1, NULL, 0); - if(!tag && key2) - tag= av_metadata_get(s->metadata, key2, NULL, 0); - if(tag) - avi_write_info_tag(s->pb, fourcc, tag->value); -} - static int avi_write_counters(AVFormatContext* s, int riff_id) { ByteIOContext *pb = s->pb; @@ -125,17 +125,19 @@ static int avi_write_counters(AVFormatContext* s, int riff_id) file_size = url_ftell(pb); for(n = 0; n < s->nb_streams; n++) { - assert(avi->frames_hdr_strm[n]); + AVIStream *avist= s->streams[n]->priv_data; + + assert(avist->frames_hdr_strm); stream = s->streams[n]->codec; - url_fseek(pb, avi->frames_hdr_strm[n], SEEK_SET); + url_fseek(pb, avist->frames_hdr_strm, SEEK_SET); ff_parse_specific_params(stream, &au_byterate, &au_ssize, &au_scale); if(au_ssize == 0) { - put_le32(pb, avi->packet_count[n]); + put_le32(pb, avist->packet_count); } else { - put_le32(pb, avi->audio_strm_length[n] / au_ssize); + put_le32(pb, avist->audio_strm_length / au_ssize); } - if(stream->codec_type == CODEC_TYPE_VIDEO) - nb_frames = FFMAX(nb_frames, avi->packet_count[n]); + if(stream->codec_type == AVMEDIA_TYPE_VIDEO) + nb_frames = FFMAX(nb_frames, avist->packet_count); } if(riff_id == 1) { assert(avi->frames_hdr_all); @@ -154,10 +156,17 @@ static int avi_write_header(AVFormatContext *s) int bitrate, n, i, nb_frames, au_byterate, au_ssize, au_scale; AVCodecContext *stream, *video_enc; int64_t list1, list2, strh, strf; + AVMetadataTag *t = NULL; + + for(n=0;nnb_streams;n++) { + s->streams[n]->priv_data= av_mallocz(sizeof(AVIStream)); + if(!s->streams[n]->priv_data) + return AVERROR(ENOMEM); + } /* header list */ avi->riff_id = 0; - list1 = avi_start_new_riff(avi, pb, "AVI ", "hdrl"); + list1 = avi_start_new_riff(s, pb, "AVI ", "hdrl"); /* avi header */ put_tag(pb, "avih"); @@ -168,7 +177,7 @@ static int avi_write_header(AVFormatContext *s) for(n=0;nnb_streams;n++) { stream = s->streams[n]->codec; bitrate += stream->bit_rate; - if (stream->codec_type == CODEC_TYPE_VIDEO) + if (stream->codec_type == AVMEDIA_TYPE_VIDEO) video_enc = stream; } @@ -204,6 +213,7 @@ static int avi_write_header(AVFormatContext *s) /* stream list */ for(i=0;istreams[i]->priv_data; list2 = ff_start_tag(pb, "LIST"); put_tag(pb, "strl"); @@ -212,16 +222,16 @@ static int avi_write_header(AVFormatContext *s) /* stream generic header */ strh = ff_start_tag(pb, "strh"); switch(stream->codec_type) { - case CODEC_TYPE_SUBTITLE: + case AVMEDIA_TYPE_SUBTITLE: // XSUB subtitles behave like video tracks, other subtitles // are not (yet) supported. if (stream->codec_id != CODEC_ID_XSUB) break; - case CODEC_TYPE_VIDEO: put_tag(pb, "vids"); break; - case CODEC_TYPE_AUDIO: put_tag(pb, "auds"); break; -// case CODEC_TYPE_TEXT : put_tag(pb, "txts"); break; - case CODEC_TYPE_DATA : put_tag(pb, "dats"); break; + case AVMEDIA_TYPE_VIDEO: put_tag(pb, "vids"); break; + case AVMEDIA_TYPE_AUDIO: put_tag(pb, "auds"); break; +// case AVMEDIA_TYPE_TEXT : put_tag(pb, "txts"); break; + case AVMEDIA_TYPE_DATA : put_tag(pb, "dats"); break; } - if(stream->codec_type == CODEC_TYPE_VIDEO || + if(stream->codec_type == AVMEDIA_TYPE_VIDEO || stream->codec_id == CODEC_ID_XSUB) put_le32(pb, stream->codec_tag); else @@ -238,16 +248,16 @@ static int avi_write_header(AVFormatContext *s) av_set_pts_info(s->streams[i], 64, au_scale, au_byterate); put_le32(pb, 0); /* start */ - avi->frames_hdr_strm[i] = url_ftell(pb); /* remember this offset to fill later */ + avist->frames_hdr_strm = url_ftell(pb); /* remember this offset to fill later */ if (url_is_streamed(pb)) put_le32(pb, AVI_MAX_RIFF_SIZE); /* FIXME: this may be broken, but who cares */ else put_le32(pb, 0); /* length, XXX: filled later */ /* suggested buffer size */ //FIXME set at the end to largest chunk - if(stream->codec_type == CODEC_TYPE_VIDEO) + if(stream->codec_type == AVMEDIA_TYPE_VIDEO) put_le32(pb, 1024 * 1024); - else if(stream->codec_type == CODEC_TYPE_AUDIO) + else if(stream->codec_type == AVMEDIA_TYPE_AUDIO) put_le32(pb, 12 * 1024); else put_le32(pb, 0); @@ -258,17 +268,17 @@ static int avi_write_header(AVFormatContext *s) put_le16(pb, stream->height); ff_end_tag(pb, strh); - if(stream->codec_type != CODEC_TYPE_DATA){ + if(stream->codec_type != AVMEDIA_TYPE_DATA){ strf = ff_start_tag(pb, "strf"); switch(stream->codec_type) { - case CODEC_TYPE_SUBTITLE: + case AVMEDIA_TYPE_SUBTITLE: // XSUB subtitles behave like video tracks, other subtitles // are not (yet) supported. if (stream->codec_id != CODEC_ID_XSUB) break; - case CODEC_TYPE_VIDEO: + case AVMEDIA_TYPE_VIDEO: ff_put_bmp_header(pb, stream, ff_codec_bmp_tags, 0); break; - case CODEC_TYPE_AUDIO: + case AVMEDIA_TYPE_AUDIO: if (ff_put_wav_header(pb, stream) < 0) { return -1; } @@ -277,6 +287,15 @@ static int avi_write_header(AVFormatContext *s) return -1; } ff_end_tag(pb, strf); + if ((t = av_metadata_get(s->streams[i]->metadata, "strn", NULL, 0))) { + avi_write_info_tag(s->pb, t->key, t->value); + t = NULL; + } + //FIXME a limitation of metadata conversion system + else if ((t = av_metadata_get(s->streams[i]->metadata, "INAM", NULL, 0))) { + avi_write_info_tag(s->pb, "strn", t->value); + t = NULL; + } } if (!url_is_streamed(pb)) { @@ -288,8 +307,8 @@ static int avi_write_header(AVFormatContext *s) * like to get away without making AVI an OpenDML one * for compatibility reasons. */ - avi->indexes[i].entry = avi->indexes[i].ents_allocated = 0; - avi->indexes[i].indx_start = ff_start_tag(pb, "JUNK"); + avist->indexes.entry = avist->indexes.ents_allocated = 0; + avist->indexes.indx_start = ff_start_tag(pb, "JUNK"); put_le16(pb, 4); /* wLongsPerEntry */ put_byte(pb, 0); /* bIndexSubType (0 == frame index) */ put_byte(pb, 0); /* bIndexType (0 == AVI_INDEX_OF_INDEXES) */ @@ -300,10 +319,10 @@ static int avi_write_header(AVFormatContext *s) put_le32(pb, 0); Must be 0. */ for (j=0; j < AVI_MASTER_INDEX_SIZE * 2; j++) put_le64(pb, 0); - ff_end_tag(pb, avi->indexes[i].indx_start); + ff_end_tag(pb, avist->indexes.indx_start); } - if( stream->codec_type == CODEC_TYPE_VIDEO + if( stream->codec_type == AVMEDIA_TYPE_VIDEO && s->streams[i]->sample_aspect_ratio.num>0 && s->streams[i]->sample_aspect_ratio.den>0){ int vprp= ff_start_tag(pb, "vprp"); @@ -353,15 +372,10 @@ static int avi_write_header(AVFormatContext *s) list2 = ff_start_tag(pb, "LIST"); put_tag(pb, "INFO"); - avi_write_info_tag2(s, "INAM", "Title", NULL); - avi_write_info_tag2(s, "IART", "Artist", "Author"); - avi_write_info_tag2(s, "ICOP", "Copyright", NULL); - avi_write_info_tag2(s, "ICMT", "Comment", NULL); - avi_write_info_tag2(s, "IPRD", "Album", NULL); - avi_write_info_tag2(s, "IGNR", "Genre", NULL); - avi_write_info_tag2(s, "IPRT", "Track", NULL); - if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) - avi_write_info_tag(pb, "ISFT", LIBAVFORMAT_IDENT); + for (i = 0; *ff_avi_tags[i]; i++) { + if ((t = av_metadata_get(s->metadata, ff_avi_tags[i], NULL, AV_METADATA_MATCH_CASE))) + avi_write_info_tag(s->pb, t->key, t->value); + } ff_end_tag(pb, list2); /* some padding for easier tag editing */ @@ -392,6 +406,7 @@ static int avi_write_ix(AVFormatContext *s) return -1; for (i=0;inb_streams;i++) { + AVIStream *avist= s->streams[i]->priv_data; int64_t ix, pos; avi_stream2fourcc(&tag[0], i, s->streams[i]->codec->codec_type); @@ -400,19 +415,19 @@ static int avi_write_ix(AVFormatContext *s) /* Writing AVI OpenDML leaf index chunk */ ix = url_ftell(pb); put_tag(pb, &ix_tag[0]); /* ix?? */ - put_le32(pb, avi->indexes[i].entry * 8 + 24); + put_le32(pb, avist->indexes.entry * 8 + 24); /* chunk size */ put_le16(pb, 2); /* wLongsPerEntry */ put_byte(pb, 0); /* bIndexSubType (0 == frame index) */ put_byte(pb, 1); /* bIndexType (1 == AVI_INDEX_OF_CHUNKS) */ - put_le32(pb, avi->indexes[i].entry); + put_le32(pb, avist->indexes.entry); /* nEntriesInUse */ put_tag(pb, &tag[0]); /* dwChunkId */ put_le64(pb, avi->movi_list);/* qwBaseOffset */ put_le32(pb, 0); /* dwReserved_3 (must be 0) */ - for (j=0; jindexes[i].entry; j++) { - AVIIentry* ie = avi_get_ientry(&avi->indexes[i], j); + for (j=0; jindexes.entry; j++) { + AVIIentry* ie = avi_get_ientry(&avist->indexes, j); put_le32(pb, ie->pos + 8); put_le32(pb, ((uint32_t)ie->len & ~0x80000000) | (ie->flags & 0x10 ? 0 : 0x80000000)); @@ -421,14 +436,14 @@ static int avi_write_ix(AVFormatContext *s) pos = url_ftell(pb); /* Updating one entry in the AVI OpenDML master index */ - url_fseek(pb, avi->indexes[i].indx_start - 8, SEEK_SET); + url_fseek(pb, avist->indexes.indx_start - 8, SEEK_SET); put_tag(pb, "indx"); /* enabling this entry */ url_fskip(pb, 8); put_le32(pb, avi->riff_id); /* nEntriesInUse */ url_fskip(pb, 16*avi->riff_id); put_le64(pb, ix); /* qwOffset */ put_le32(pb, pos - ix); /* dwSize */ - put_le32(pb, avi->indexes[i].entry); /* dwDuration */ + put_le32(pb, avist->indexes.entry); /* dwDuration */ url_fseek(pb, pos, SEEK_SET); } @@ -444,19 +459,24 @@ static int avi_write_idx1(AVFormatContext *s) char tag[5]; if (!url_is_streamed(pb)) { + AVIStream *avist; AVIIentry* ie = 0, *tie; - int entry[MAX_STREAMS]; int empty, stream_id = -1; idx_chunk = ff_start_tag(pb, "idx1"); - memset(&entry[0], 0, sizeof(entry)); + for(i=0; inb_streams; i++){ + avist= s->streams[i]->priv_data; + avist->entry=0; + } + do { empty = 1; for (i=0; inb_streams; i++) { - if (avi->indexes[i].entry <= entry[i]) + avist= s->streams[i]->priv_data; + if (avist->indexes.entry <= avist->entry) continue; - tie = avi_get_ientry(&avi->indexes[i], entry[i]); + tie = avi_get_ientry(&avist->indexes, avist->entry); if (empty || tie->pos < ie->pos) { ie = tie; stream_id = i; @@ -464,13 +484,14 @@ static int avi_write_idx1(AVFormatContext *s) empty = 0; } if (!empty) { + avist= s->streams[stream_id]->priv_data; avi_stream2fourcc(&tag[0], stream_id, s->streams[stream_id]->codec->codec_type); put_tag(pb, &tag[0]); put_le32(pb, ie->flags); put_le32(pb, ie->pos); put_le32(pb, ie->len); - entry[stream_id]++; + avist->entry++; } } while (!empty); ff_end_tag(pb, idx_chunk); @@ -487,11 +508,12 @@ static int avi_write_packet(AVFormatContext *s, AVPacket *pkt) unsigned char tag[5]; unsigned int flags=0; const int stream_index= pkt->stream_index; + AVIStream *avist= s->streams[stream_index]->priv_data; 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); - while(enc->block_align==0 && pkt->dts != AV_NOPTS_VALUE && pkt->dts > avi->packet_count[stream_index]){ + while(enc->block_align==0 && pkt->dts != AV_NOPTS_VALUE && pkt->dts > avist->packet_count){ AVPacket empty_packet; av_init_packet(&empty_packet); @@ -501,7 +523,7 @@ static int avi_write_packet(AVFormatContext *s, AVPacket *pkt) avi_write_packet(s, &empty_packet); // av_log(s, AV_LOG_DEBUG, "dup %"PRId64" %d\n", pkt->dts, avi->packet_count[stream_index]); } - avi->packet_count[stream_index]++; + avist->packet_count++; // Make sure to put an OpenDML chunk when the file size exceeds the limits if (!url_is_streamed(pb) && @@ -514,18 +536,18 @@ static int avi_write_packet(AVFormatContext *s, AVPacket *pkt) avi_write_idx1(s); ff_end_tag(pb, avi->riff_start); - avi->movi_list = avi_start_new_riff(avi, pb, "AVIX", "movi"); + avi->movi_list = avi_start_new_riff(s, pb, "AVIX", "movi"); } avi_stream2fourcc(&tag[0], stream_index, enc->codec_type); - if(pkt->flags&PKT_FLAG_KEY) + if(pkt->flags&AV_PKT_FLAG_KEY) flags = 0x10; - if (enc->codec_type == CODEC_TYPE_AUDIO) { - avi->audio_strm_length[stream_index] += size; + if (enc->codec_type == AVMEDIA_TYPE_AUDIO) { + avist->audio_strm_length += size; } if (!url_is_streamed(s->pb)) { - AVIIndex* idx = &avi->indexes[stream_index]; + AVIIndex* idx = &avist->indexes; int cl = idx->entry / AVI_INDEX_CLUSTER_SIZE; int id = idx->entry % AVI_INDEX_CLUSTER_SIZE; if (idx->ents_allocated <= idx->entry) { @@ -579,12 +601,14 @@ static int avi_write_trailer(AVFormatContext *s) for (n=nb_frames=0;nnb_streams;n++) { AVCodecContext *stream = s->streams[n]->codec; - if (stream->codec_type == CODEC_TYPE_VIDEO) { - if (nb_frames < avi->packet_count[n]) - nb_frames = avi->packet_count[n]; + AVIStream *avist= s->streams[n]->priv_data; + + if (stream->codec_type == AVMEDIA_TYPE_VIDEO) { + if (nb_frames < avist->packet_count) + nb_frames = avist->packet_count; } else { if (stream->codec_id == CODEC_ID_MP2 || stream->codec_id == CODEC_ID_MP3) { - nb_frames += avi->packet_count[n]; + nb_frames += avist->packet_count; } } } @@ -596,11 +620,12 @@ static int avi_write_trailer(AVFormatContext *s) } put_flush_packet(pb); - for (i=0; iindexes[i].ents_allocated/AVI_INDEX_CLUSTER_SIZE; j++) - av_free(avi->indexes[i].cluster[j]); - av_freep(&avi->indexes[i].cluster); - avi->indexes[i].ents_allocated = avi->indexes[i].entry = 0; + for (i=0; inb_streams; i++) { + AVIStream *avist= s->streams[i]->priv_data; + for (j=0; jindexes.ents_allocated/AVI_INDEX_CLUSTER_SIZE; j++) + av_free(avist->indexes.cluster[j]); + av_freep(&avist->indexes.cluster); + avist->indexes.ents_allocated = avist->indexes.entry = 0; } return res; @@ -619,4 +644,5 @@ AVOutputFormat avi_muxer = { avi_write_trailer, .codec_tag= (const AVCodecTag* const []){ff_codec_bmp_tags, ff_codec_wav_tags, 0}, .flags= AVFMT_VARIABLE_FPS, + .metadata_conv = ff_avi_metadata_conv, }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/avio.c b/src/add-ons/media/plugins/ffmpeg/libavformat/avio.c index b6329a927d..48399d081f 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/avio.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/avio.c @@ -19,10 +19,16 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +/* needed for usleep() */ +#define _XOPEN_SOURCE 600 +#include #include "libavutil/avstring.h" #include "libavcodec/opt.h" #include "os_support.h" #include "avformat.h" +#if CONFIG_NETWORK +#include "network.h" +#endif #if LIBAVFORMAT_VERSION_MAJOR >= 53 /** @name Logging context. */ @@ -35,7 +41,7 @@ static const char *urlcontext_to_name(void *ptr) } static const AVOption options[] = {{NULL}}; static const AVClass urlcontext_class = - { "URLContext", urlcontext_to_name, options }; + { "URLContext", urlcontext_to_name, options, LIBAVUTIL_VERSION_INT }; /*@}*/ #endif @@ -73,7 +79,11 @@ int url_open_protocol (URLContext **puc, struct URLProtocol *up, URLContext *uc; int err; - uc = av_malloc(sizeof(URLContext) + strlen(filename) + 1); +#if CONFIG_NETWORK + if (!ff_network_init()) + return AVERROR(EIO); +#endif + uc = av_mallocz(sizeof(URLContext) + strlen(filename) + 1); if (!uc) { err = AVERROR(ENOMEM); goto fail; @@ -90,11 +100,10 @@ int url_open_protocol (URLContext **puc, struct URLProtocol *up, err = up->url_open(uc, filename, flags); if (err < 0) { av_free(uc); - *puc = NULL; - return err; + goto fail; } - //We must be carefull here as url_seek() could be slow, for example for http + //We must be careful here as url_seek() could be slow, for example for http if( (flags & (URL_WRONLY | URL_RDWR)) || !strcmp(up->name, "file")) if(!uc->is_streamed && url_seek(uc, 0, SEEK_SET) < 0) @@ -103,6 +112,9 @@ int url_open_protocol (URLContext **puc, struct URLProtocol *up, return 0; fail: *puc = NULL; +#if CONFIG_NETWORK + ff_network_close(); +#endif return err; } @@ -152,12 +164,21 @@ int url_read(URLContext *h, unsigned char *buf, int size) int url_read_complete(URLContext *h, unsigned char *buf, int size) { int ret, len; + int fast_retries = 5; len = 0; while (len < size) { ret = url_read(h, buf+len, size-len); - if (ret < 1) - return ret; + if (ret == AVERROR(EAGAIN)) { + ret = 0; + if (fast_retries) + fast_retries--; + else + usleep(1000); + } else if (ret < 1) + return ret < 0 ? ret : len; + if (ret) + fast_retries = FFMAX(fast_retries, 2); len += ret; } return len; @@ -180,8 +201,8 @@ int64_t url_seek(URLContext *h, int64_t pos, int whence) int64_t ret; if (!h->prot->url_seek) - return AVERROR(EPIPE); - ret = h->prot->url_seek(h, pos, whence); + return AVERROR(ENOSYS); + ret = h->prot->url_seek(h, pos, whence & ~AVSEEK_FORCE); return ret; } @@ -192,6 +213,9 @@ int url_close(URLContext *h) if (h->prot->url_close) ret = h->prot->url_close(h); +#if CONFIG_NETWORK + ff_network_close(); +#endif av_free(h); return ret; } diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/avio.h b/src/add-ons/media/plugins/ffmpeg/libavformat/avio.h index d44e300497..9ffe935675 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/avio.h +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/avio.h @@ -21,7 +21,7 @@ #define AVFORMAT_AVIO_H /** - * @file libavformat/avio.h + * @file * unbuffered I/O operations * * @warning This file has to be considered an internal but installed @@ -50,7 +50,7 @@ typedef struct URLContext { int is_streamed; /**< true if streamed (no seek possible), default = false */ int max_packet_size; /**< if non zero, the stream is packetized with this max packet size */ void *priv_data; - char *filename; /**< specified filename */ + char *filename; /**< specified URL */ } URLContext; typedef struct URLPollEntry { @@ -65,15 +65,86 @@ typedef struct URLPollEntry { typedef int URLInterruptCB(void); +/** + * Creates an URLContext for accessing to the resource indicated by + * url, and opens it using the URLProtocol up. + * + * @param puc pointer to the location where, in case of success, the + * function puts the pointer to the created URLContext + * @param flags flags which control how the resource indicated by url + * is to be opened + * @return 0 in case of success, a negative value corresponding to an + * AVERROR code in case of failure + */ int url_open_protocol (URLContext **puc, struct URLProtocol *up, - const char *filename, int flags); -int url_open(URLContext **h, const char *filename, int flags); + const char *url, int flags); + +/** + * Creates an URLContext for accessing to the resource indicated by + * url, and opens it. + * + * @param puc pointer to the location where, in case of success, the + * function puts the pointer to the created URLContext + * @param flags flags which control how the resource indicated by url + * is to be opened + * @return 0 in case of success, a negative value corresponding to an + * AVERROR code in case of failure + */ +int url_open(URLContext **h, const char *url, int flags); + +/** + * Reads up to size bytes from the resource accessed by h, and stores + * the read bytes in buf. + * + * @return The number of bytes actually read, or a negative value + * corresponding to an AVERROR code in case of error. A value of zero + * indicates that it is not possible to read more from the accessed + * resource (except if the value of the size argument is also zero). + */ int url_read(URLContext *h, unsigned char *buf, int size); + +/** + * Read as many bytes as possible (up to size), calling the + * read function multiple times if necessary. + * Will also retry if the read function returns AVERROR(EAGAIN). + * This makes special short-read handling in applications + * unnecessary, if the return value is < size then it is + * certain there was either an error or the end of file was reached. + */ int url_read_complete(URLContext *h, unsigned char *buf, int size); int url_write(URLContext *h, unsigned char *buf, int size); + +/** + * Changes the position that will be used by the next read/write + * operation on the resource accessed by h. + * + * @param pos specifies the new position to set + * @param whence specifies how pos should be interpreted, it must be + * one of SEEK_SET (seek from the beginning), SEEK_CUR (seek from the + * current position), SEEK_END (seek from the end), or AVSEEK_SIZE + * (return the filesize of the requested resource, pos is ignored). + * @return a negative value corresponding to an AVERROR code in case + * of failure, or the resulting file position, measured in bytes from + * the beginning of the file. You can use this feature together with + * SEEK_CUR to read the current file position. + */ int64_t url_seek(URLContext *h, int64_t pos, int whence); + +/** + * Closes the resource accessed by the URLContext h, and frees the + * memory used by it. + * + * @return a negative value if an error condition occurred, 0 + * otherwise + */ int url_close(URLContext *h); -int url_exist(const char *filename); + +/** + * Returns a non-zero value if the resource indicated by url + * exists, 0 otherwise. + */ +int url_exist(const char *url); + int64_t url_filesize(URLContext *h); /** @@ -141,9 +212,17 @@ int64_t av_url_read_seek(URLContext *h, int stream_index, */ #define AVSEEK_SIZE 0x10000 +/** + * Oring this flag as into the "whence" parameter to a seek function causes it to + * seek by any means (like reopening and linear reading) or other normally unreasonble + * means that can be extreemly slow. + * This may be ignored by the seek code. + */ +#define AVSEEK_FORCE 0x20000 + typedef struct URLProtocol { const char *name; - int (*url_open)(URLContext *h, const char *filename, int flags); + int (*url_open)(URLContext *h, const char *url, int flags); int (*url_read)(URLContext *h, unsigned char *buf, int size); int (*url_write)(URLContext *h, unsigned char *buf, int size); int64_t (*url_seek)(URLContext *h, int64_t pos, int whence); @@ -175,6 +254,9 @@ URLProtocol *av_protocol_next(URLProtocol *p); attribute_deprecated int register_protocol(URLProtocol *protocol); #endif +/** + * Registers the URLProtocol protocol. + */ int av_register_protocol(URLProtocol *protocol); /** @@ -294,7 +376,7 @@ void put_flush_packet(ByteIOContext *s); /** * Reads size bytes from ByteIOContext into buf. - * @returns number of bytes read or AVERROR + * @return number of bytes read or AVERROR */ int get_buffer(ByteIOContext *s, unsigned char *buf, int size); @@ -302,7 +384,7 @@ int get_buffer(ByteIOContext *s, unsigned char *buf, int size); * Reads size bytes from ByteIOContext into buf. * This reads at most 1 packet. If that is not enough fewer bytes will be * returned. - * @returns number of bytes read or AVERROR + * @return number of bytes read or AVERROR */ int get_partial_buffer(ByteIOContext *s, unsigned char *buf, int size); @@ -327,21 +409,59 @@ static inline int url_is_streamed(ByteIOContext *s) return s->is_streamed; } -/** @note when opened as read/write, the buffers are only used for - writing */ +/** + * Creates and initializes a ByteIOContext for accessing the + * resource referenced by the URLContext h. + * @note When the URLContext h has been opened in read+write mode, the + * ByteIOContext can be used only for writing. + * + * @param s Used to return the pointer to the created ByteIOContext. + * In case of failure the pointed to value is set to NULL. + * @return 0 in case of success, a negative value corresponding to an + * AVERROR code in case of failure + */ int url_fdopen(ByteIOContext **s, URLContext *h); /** @warning must be called before any I/O */ int url_setbufsize(ByteIOContext *s, int buf_size); +#if LIBAVFORMAT_VERSION_MAJOR < 53 /** Reset the buffer for reading or writing. * @note Will drop any data currently in the buffer without transmitting it. * @param flags URL_RDONLY to set up the buffer for reading, or URL_WRONLY * to set up the buffer for writing. */ int url_resetbuf(ByteIOContext *s, int flags); +#endif + +/** + * Rewinds the ByteIOContext using the specified buffer containing the first buf_size bytes of the file. + * Used after probing to avoid seeking. + * Joins buf and s->buffer, taking any overlap into consideration. + * @note s->buffer must overlap with buf or they can't be joined and the function fails + * @note This function is NOT part of the public API + * + * @param s The read-only ByteIOContext to rewind + * @param buf The probe buffer containing the first buf_size bytes of the file + * @param buf_size The size of buf + * @return 0 in case of success, a negative value corresponding to an + * AVERROR code in case of failure + */ +int ff_rewind_with_probe_data(ByteIOContext *s, unsigned char *buf, int buf_size); + +/** + * Creates and initializes a ByteIOContext for accessing the + * resource indicated by url. + * @note When the resource indicated by url has been opened in + * read+write mode, the ByteIOContext can be used only for writing. + * + * @param s Used to return the pointer to the created ByteIOContext. + * In case of failure the pointed to value is set to NULL. + * @param flags flags which control how the resource indicated by url + * is to be opened + * @return 0 in case of success, a negative value corresponding to an + * AVERROR code in case of failure + */ +int url_fopen(ByteIOContext **s, const char *url, int flags); -/** @note when opened as read/write, the buffers are only used for - writing */ -int url_fopen(ByteIOContext **s, const char *filename, int flags); int url_fclose(ByteIOContext *s); URLContext *url_fileno(ByteIOContext *s); diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/aviobuf.c b/src/add-ons/media/plugins/ffmpeg/libavformat/aviobuf.c index f270139a9b..8684903464 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/aviobuf.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/aviobuf.c @@ -28,6 +28,9 @@ #define IO_BUFFER_SIZE 32768 static void fill_buffer(ByteIOContext *s); +#if LIBAVFORMAT_VERSION_MAJOR >= 53 +static int url_resetbuf(ByteIOContext *s, int flags); +#endif int init_put_byte(ByteIOContext *s, unsigned char *buffer, @@ -104,12 +107,8 @@ void put_byte(ByteIOContext *s, int b) void put_buffer(ByteIOContext *s, const unsigned char *buf, int size) { - int len; - while (size > 0) { - len = (s->buf_end - s->buf_ptr); - if (len > size) - len = size; + int len = FFMIN(s->buf_end - s->buf_ptr, size); memcpy(s->buf_ptr, buf, len); s->buf_ptr += len; @@ -131,6 +130,8 @@ int64_t url_fseek(ByteIOContext *s, int64_t offset, int whence) { int64_t offset1; int64_t pos; + int force = whence & AVSEEK_FORCE; + whence &= ~AVSEEK_FORCE; if(!s) return AVERROR(EINVAL); @@ -151,15 +152,15 @@ int64_t url_fseek(ByteIOContext *s, int64_t offset, int whence) offset1 >= 0 && offset1 <= (s->buf_end - s->buffer)) { /* can do the seek inside the buffer */ s->buf_ptr = s->buffer + offset1; - } else if(s->is_streamed && !s->write_flag && - offset1 >= 0 && offset1 < (s->buf_end - s->buffer) + (1<<16)){ + } else if(s->is_streamed && !s->write_flag && offset1 >= 0 && + (whence != SEEK_END || force)) { while(s->pos < offset && !s->eof_reached) fill_buffer(s); if (s->eof_reached) - return AVERROR(EPIPE); + return AVERROR_EOF; s->buf_ptr = s->buf_end + offset - s->pos; } else { - int64_t res = AVERROR(EPIPE); + int64_t res; #if CONFIG_MUXERS || CONFIG_NETWORK if (s->write_flag) { @@ -167,7 +168,9 @@ int64_t url_fseek(ByteIOContext *s, int64_t offset, int whence) s->must_flush = 1; } #endif /* CONFIG_MUXERS || CONFIG_NETWORK */ - if (!s->seek || (res = s->seek(s->opaque, offset, SEEK_SET)) < 0) + if (!s->seek) + return AVERROR(EPIPE); + if ((res = s->seek(s->opaque, offset, SEEK_SET)) < 0) return res; if (!s->write_flag) s->buf_end = s->buffer; @@ -196,7 +199,7 @@ int64_t url_fsize(ByteIOContext *s) return AVERROR(EINVAL); if (!s->seek) - return AVERROR(EPIPE); + return AVERROR(ENOSYS); size = s->seek(s->opaque, 0, AVSEEK_SIZE); if(size<0){ if ((size = s->seek(s->opaque, -1, SEEK_END)) < 0) @@ -294,6 +297,7 @@ static void fill_buffer(ByteIOContext *s) { uint8_t *dst= !s->max_packet_size && s->buf_end - s->buffer < s->buffer_size ? s->buf_ptr : s->buffer; int len= s->buffer_size - (dst - s->buffer); + int max_buffer_size = s->max_packet_size ? s->max_packet_size : IO_BUFFER_SIZE; assert(s->buf_ptr == s->buf_end); @@ -307,6 +311,14 @@ static void fill_buffer(ByteIOContext *s) s->checksum_ptr= s->buffer; } + /* make buffer smaller in case it ended up large after probing */ + if (s->buffer_size > max_buffer_size) { + url_setbufsize(s, max_buffer_size); + + s->checksum_ptr = dst = s->buffer; + len = s->buffer_size; + } + if(s->read_packet) len = s->read_packet(s->opaque, dst, len); else @@ -415,6 +427,10 @@ int get_buffer(ByteIOContext *s, unsigned char *buf, int size) size -= len; } } + if (size1 == size) { + if (url_ferror(s)) return url_ferror(s); + if (url_feof(s)) return AVERROR_EOF; + } return size1 - size; } @@ -434,6 +450,10 @@ int get_partial_buffer(ByteIOContext *s, unsigned char *buf, int size) len = size; memcpy(buf, s->buf_ptr, len); s->buf_ptr += len; + if (!len) { + if (url_ferror(s)) return url_ferror(s); + if (url_feof(s)) return AVERROR_EOF; + } return len; } @@ -531,7 +551,6 @@ int url_fdopen(ByteIOContext **s, URLContext *h) uint8_t *buffer; int buffer_size, max_packet_size; - max_packet_size = url_get_max_packet_size(h); if (max_packet_size) { buffer_size = max_packet_size; /* no need to bufferize more than one packet */ @@ -579,11 +598,19 @@ int url_setbufsize(ByteIOContext *s, int buf_size) return 0; } +#if LIBAVFORMAT_VERSION_MAJOR < 53 int url_resetbuf(ByteIOContext *s, int flags) +#else +static int url_resetbuf(ByteIOContext *s, int flags) +#endif { +#if LIBAVFORMAT_VERSION_MAJOR < 53 URLContext *h = s->opaque; if ((flags & URL_RDWR) || (h && h->flags != flags && !h->flags & URL_RDWR)) return AVERROR(EINVAL); +#else + assert(flags == URL_WRONLY || flags == URL_RDONLY); +#endif if (flags & URL_WRONLY) { s->buf_end = s->buffer + s->buffer_size; @@ -595,6 +622,42 @@ int url_resetbuf(ByteIOContext *s, int flags) return 0; } +int ff_rewind_with_probe_data(ByteIOContext *s, unsigned char *buf, int buf_size) +{ + int64_t buffer_start; + int buffer_size; + int overlap, new_size; + + if (s->write_flag) + return AVERROR(EINVAL); + + buffer_size = s->buf_end - s->buffer; + + /* the buffers must touch or overlap */ + if ((buffer_start = s->pos - buffer_size) > buf_size) + return AVERROR(EINVAL); + + overlap = buf_size - buffer_start; + new_size = buf_size + buffer_size - overlap; + + if (new_size > buf_size) { + if (!(buf = av_realloc(buf, new_size))) + return AVERROR(ENOMEM); + + memcpy(buf + buf_size, s->buffer + overlap, buffer_size - overlap); + buf_size = new_size; + } + + av_free(s->buffer); + s->buf_ptr = s->buffer = buf; + s->pos = s->buffer_size = buf_size; + s->buf_end = s->buf_ptr + buf_size; + s->eof_reached = 0; + s->must_flush = 0; + + return 0; +} + int url_fopen(ByteIOContext **s, const char *filename, int flags) { URLContext *h; @@ -682,8 +745,13 @@ int64_t av_url_read_fseek(ByteIOContext *s, int stream_index, return AVERROR(ENOSYS); ret = s->read_seek(h, stream_index, timestamp, flags); if(ret >= 0) { + int64_t pos; s->buf_ptr = s->buf_end; // Flush buffer - s->pos = s->seek(h, 0, SEEK_CUR); + pos = s->seek(h, 0, SEEK_CUR); + if (pos >= 0) + s->pos = pos; + else if (pos != AVERROR(ENOSYS)) + ret = pos; } return ret; } diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/avisynth.c b/src/add-ons/media/plugins/ffmpeg/libavformat/avisynth.c index 7ca52d9892..e2a8a3cf5a 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/avisynth.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/avisynth.c @@ -85,7 +85,7 @@ static int avisynth_read_header(AVFormatContext *s, AVFormatParameters *ap) continue; st = av_new_stream(s, id); - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->block_align = wvfmt.nBlockAlign; st->codec->channels = wvfmt.nChannels; @@ -111,7 +111,7 @@ static int avisynth_read_header(AVFormatContext *s, AVFormatParameters *ap) continue; st = av_new_stream(s, id); - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->r_frame_rate.num = stream->info.dwRate; st->r_frame_rate.den = stream->info.dwScale; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/avlanguage.c b/src/add-ons/media/plugins/ffmpeg/libavformat/avlanguage.c index fbe88e78e4..525bf07d27 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/avlanguage.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/avlanguage.c @@ -29,10 +29,10 @@ typedef struct LangEntry { uint16_t next_equivalent; } LangEntry; -const uint16_t lang_table_counts[] = { 484, 20, 184 }; -const uint16_t lang_table_offsets[] = { 0, 484, 504 }; +static const uint16_t lang_table_counts[] = { 484, 20, 184 }; +static const uint16_t lang_table_offsets[] = { 0, 484, 504 }; -static LangEntry lang_table[] = { +static const LangEntry lang_table[] = { /*----- AV_LANG_ISO639_2_BIBL entries (484) -----*/ /*0000*/ { "aar", 504 }, /*0001*/ { "abk", 505 }, diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/avs.c b/src/add-ons/media/plugins/ffmpeg/libavformat/avs.c index 1fcb19fdde..caf3a892bb 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/avs.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/avs.c @@ -113,7 +113,7 @@ avs_read_video_packet(AVFormatContext * s, AVPacket * pkt, pkt->size = ret + palette_size; pkt->stream_index = avs->st_video->index; if (sub_type == 0) - pkt->flags |= PKT_FLAG_KEY; + pkt->flags |= AV_PKT_FLAG_KEY; return 0; } @@ -134,7 +134,7 @@ static int avs_read_audio_packet(AVFormatContext * s, AVPacket * pkt) return ret; pkt->stream_index = avs->st_audio->index; - pkt->flags |= PKT_FLAG_KEY; + pkt->flags |= AV_PKT_FLAG_KEY; return size; } @@ -178,7 +178,7 @@ static int avs_read_packet(AVFormatContext * s, AVPacket * pkt) avs->st_video = av_new_stream(s, AVS_VIDEO); if (avs->st_video == NULL) return AVERROR(ENOMEM); - avs->st_video->codec->codec_type = CODEC_TYPE_VIDEO; + avs->st_video->codec->codec_type = AVMEDIA_TYPE_VIDEO; avs->st_video->codec->codec_id = CODEC_ID_AVS; avs->st_video->codec->width = avs->width; avs->st_video->codec->height = avs->height; @@ -195,7 +195,7 @@ static int avs_read_packet(AVFormatContext * s, AVPacket * pkt) avs->st_audio = av_new_stream(s, AVS_AUDIO); if (avs->st_audio == NULL) return AVERROR(ENOMEM); - avs->st_audio->codec->codec_type = CODEC_TYPE_AUDIO; + avs->st_audio->codec->codec_type = AVMEDIA_TYPE_AUDIO; } avs->remaining_audio_size = size - 4; size = avs_read_audio_packet(s, pkt); diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/bethsoftvid.c b/src/add-ons/media/plugins/ffmpeg/libavformat/bethsoftvid.c index e599255f16..4f9d1c1b1a 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/bethsoftvid.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/bethsoftvid.c @@ -20,7 +20,7 @@ */ /** - * @file libavformat/bethsoftvid.c + * @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 @@ -74,7 +74,7 @@ static int vid_read_header(AVFormatContext *s, if (!stream) return AVERROR(ENOMEM); av_set_pts_info(stream, 32, 1, 60); // 16 ms increments, i.e. 60 fps - stream->codec->codec_type = CODEC_TYPE_VIDEO; + stream->codec->codec_type = AVMEDIA_TYPE_VIDEO; stream->codec->codec_id = CODEC_ID_BETHSOFTVID; stream->codec->width = get_le16(pb); stream->codec->height = get_le16(pb); @@ -86,7 +86,7 @@ static int vid_read_header(AVFormatContext *s, stream = av_new_stream(s, 0); if (!stream) return AVERROR(ENOMEM); - stream->codec->codec_type = CODEC_TYPE_AUDIO; + stream->codec->codec_type = AVMEDIA_TYPE_AUDIO; stream->codec->codec_id = CODEC_ID_PCM_U8; stream->codec->channels = 1; stream->codec->sample_rate = 11025; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/bfi.c b/src/add-ons/media/plugins/ffmpeg/libavformat/bfi.c index cecbfbabd0..94014a4912 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/bfi.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/bfi.c @@ -20,7 +20,7 @@ */ /** - * @file libavformat/bfi.c + * @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 @@ -87,12 +87,12 @@ static int bfi_read_header(AVFormatContext * s, AVFormatParameters * ap) /* Set up the video codec... */ av_set_pts_info(vstream, 32, 1, fps); - vstream->codec->codec_type = CODEC_TYPE_VIDEO; + vstream->codec->codec_type = AVMEDIA_TYPE_VIDEO; vstream->codec->codec_id = CODEC_ID_BFI; vstream->codec->pix_fmt = PIX_FMT_PAL8; /* Set up the audio codec now... */ - astream->codec->codec_type = CODEC_TYPE_AUDIO; + astream->codec->codec_type = AVMEDIA_TYPE_AUDIO; astream->codec->codec_id = CODEC_ID_PCM_U8; astream->codec->channels = 1; astream->codec->bits_per_coded_sample = 8; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/bink.c b/src/add-ons/media/plugins/ffmpeg/libavformat/bink.c new file mode 100644 index 0000000000..afa629f355 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/bink.c @@ -0,0 +1,269 @@ +/* + * Bink demuxer + * Copyright (c) 2008-2010 Peter Ross (pross@xvid.org) + * Copyright (c) 2009 Daniel Verkamp (daniel@drv.nu) + * + * 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 + * Bink demuxer + * + * Technical details here: + * http://wiki.multimedia.cx/index.php?title=Bink_Container + */ + +#include "libavutil/intreadwrite.h" +#include "avformat.h" + +enum BinkAudFlags { + BINK_AUD_16BITS = 0x4000, ///< prefer 16-bit output + BINK_AUD_STEREO = 0x2000, + BINK_AUD_USEDCT = 0x1000, +}; + +#define BINK_EXTRADATA_SIZE 1 +#define BINK_MAX_AUDIO_TRACKS 256 +#define BINK_MAX_WIDTH 7680 +#define BINK_MAX_HEIGHT 4800 + +typedef struct { + uint32_t file_size; + + uint32_t num_audio_tracks; + int current_track; ///< audio track to return in next packet + int64_t video_pts; + int64_t audio_pts[BINK_MAX_AUDIO_TRACKS]; + + uint32_t remain_packet_size; +} BinkDemuxContext; + +static int probe(AVProbeData *p) +{ + const uint8_t *b = p->buf; + + if ( b[0] == 'B' && b[1] == 'I' && b[2] == 'K' && + (b[3] == 'b' || b[3] == 'f' || b[3] == 'g' || b[3] == 'h' || b[3] == 'i') && + AV_RL32(b+8) > 0 && // num_frames + AV_RL32(b+20) > 0 && AV_RL32(b+20) <= BINK_MAX_WIDTH && + AV_RL32(b+24) > 0 && AV_RL32(b+24) <= BINK_MAX_HEIGHT && + AV_RL32(b+28) > 0 && AV_RL32(b+32) > 0) // fps num,den + return AVPROBE_SCORE_MAX; + return 0; +} + +static int read_header(AVFormatContext *s, AVFormatParameters *ap) +{ + BinkDemuxContext *bink = s->priv_data; + ByteIOContext *pb = s->pb; + uint32_t fps_num, fps_den; + AVStream *vst, *ast; + unsigned int i; + uint32_t pos, next_pos; + uint16_t flags; + int keyframe; + + vst = av_new_stream(s, 0); + if (!vst) + return AVERROR(ENOMEM); + + vst->codec->codec_tag = get_le32(pb); + + bink->file_size = get_le32(pb) + 8; + vst->duration = get_le32(pb); + + if (vst->duration > 1000000) { + av_log(s, AV_LOG_ERROR, "invalid header: more than 1000000 frames\n"); + return AVERROR(EIO); + } + + if (get_le32(pb) > bink->file_size) { + av_log(s, AV_LOG_ERROR, + "invalid header: largest frame size greater than file size\n"); + return AVERROR(EIO); + } + + url_fskip(pb, 4); + + vst->codec->width = get_le32(pb); + vst->codec->height = get_le32(pb); + + fps_num = get_le32(pb); + fps_den = get_le32(pb); + if (fps_num == 0 || fps_den == 0) { + av_log(s, AV_LOG_ERROR, "invalid header: invalid fps (%d/%d)\n", fps_num, fps_den); + return AVERROR(EIO); + } + av_set_pts_info(vst, 64, fps_den, fps_num); + + vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codec->codec_id = CODEC_ID_BINKVIDEO; + vst->codec->extradata = av_mallocz(4 + FF_INPUT_BUFFER_PADDING_SIZE); + vst->codec->extradata_size = 4; + get_buffer(pb, vst->codec->extradata, 4); + + bink->num_audio_tracks = get_le32(pb); + + if (bink->num_audio_tracks > BINK_MAX_AUDIO_TRACKS) { + av_log(s, AV_LOG_ERROR, + "invalid header: more than "AV_STRINGIFY(BINK_MAX_AUDIO_TRACKS)" audio tracks (%d)\n", + bink->num_audio_tracks); + return AVERROR(EIO); + } + + if (bink->num_audio_tracks) { + url_fskip(pb, 4 * bink->num_audio_tracks); + + for (i = 0; i < bink->num_audio_tracks; i++) { + ast = av_new_stream(s, 1); + if (!ast) + return AVERROR(ENOMEM); + ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; + ast->codec->codec_tag = 0; + ast->codec->sample_rate = get_le16(pb); + av_set_pts_info(ast, 64, 1, ast->codec->sample_rate); + flags = get_le16(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; + } + + url_fskip(pb, 4 * bink->num_audio_tracks); + } + + /* frame index table */ + next_pos = get_le32(pb); + for (i = 0; i < vst->duration; i++) { + pos = next_pos; + if (i == vst->duration - 1) { + next_pos = bink->file_size; + keyframe = 0; + } else { + next_pos = get_le32(pb); + keyframe = pos & 1; + } + pos &= ~1; + next_pos &= ~1; + + if (next_pos <= pos) { + av_log(s, AV_LOG_ERROR, "invalid frame index table\n"); + return AVERROR(EIO); + } + av_add_index_entry(vst, pos, i, next_pos - pos, 0, + keyframe ? AVINDEX_KEYFRAME : 0); + } + + url_fskip(pb, 4); + + bink->current_track = -1; + return 0; +} + +static int read_packet(AVFormatContext *s, AVPacket *pkt) +{ + BinkDemuxContext *bink = s->priv_data; + ByteIOContext *pb = s->pb; + int ret; + + if (bink->current_track < 0) { + int index_entry; + AVStream *st = s->streams[0]; // stream 0 is video stream with index + + if (bink->video_pts >= st->duration) + return AVERROR(EIO); + + index_entry = av_index_search_timestamp(st, bink->video_pts, + AVSEEK_FLAG_ANY); + if (index_entry < 0) { + av_log(s, AV_LOG_ERROR, + "could not find index entry for frame %"PRId64"\n", + bink->video_pts); + return AVERROR(EIO); + } + + bink->remain_packet_size = st->index_entries[index_entry].size; + bink->current_track = 0; + } + + while (bink->current_track < bink->num_audio_tracks) { + uint32_t audio_size = get_le32(pb); + if (audio_size > bink->remain_packet_size - 4) { + av_log(s, AV_LOG_ERROR, + "frame %"PRId64": audio size in header (%u) > size of packet left (%u)\n", + bink->video_pts, audio_size, bink->remain_packet_size); + return AVERROR(EIO); + } + bink->remain_packet_size -= 4 + audio_size; + bink->current_track++; + if (audio_size >= 4) { + /* get one audio packet per track */ + if ((ret = av_get_packet(pb, pkt, audio_size)) < 0) + return ret; + pkt->stream_index = bink->current_track; + pkt->pts = bink->audio_pts[bink->current_track - 1]; + + /* Each audio packet reports the number of decompressed samples + (in bytes). We use this value to calcuate the audio PTS */ + if (pkt->size >= 4) + bink->audio_pts[bink->current_track -1] += + AV_RL32(pkt->data) / (2 * s->streams[bink->current_track]->codec->channels); + return 0; + } else { + url_fseek(pb, audio_size, SEEK_CUR); + } + } + + /* get video packet */ + if ((ret = av_get_packet(pb, pkt, bink->remain_packet_size)) < 0) + return ret; + pkt->stream_index = 0; + pkt->pts = bink->video_pts++; + pkt->flags |= AV_PKT_FLAG_KEY; + + /* -1 instructs the next call to read_packet() to read the next frame */ + bink->current_track = -1; + + return 0; +} + +static int read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) +{ + BinkDemuxContext *bink = s->priv_data; + AVStream *vst = s->streams[0]; + + if (url_is_streamed(s->pb)) + return -1; + + /* seek to the first frame */ + url_fseek(s->pb, vst->index_entries[0].pos, SEEK_SET); + bink->video_pts = 0; + memset(bink->audio_pts, 0, sizeof(bink->audio_pts)); + bink->current_track = -1; + return 0; +} + +AVInputFormat bink_demuxer = { + "bink", + NULL_IF_CONFIG_SMALL("Bink"), + sizeof(BinkDemuxContext), + probe, + read_header, + read_packet, + NULL, + read_seek, +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/c93.c b/src/add-ons/media/plugins/ffmpeg/libavformat/c93.c index 11a0314c74..033b36bd25 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/c93.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/c93.c @@ -21,6 +21,7 @@ #include "avformat.h" #include "voc.h" +#include "libavutil/intreadwrite.h" typedef struct { uint16_t index; @@ -43,13 +44,16 @@ typedef struct { static int probe(AVProbeData *p) { - if (p->buf[0] == 0x01 && p->buf[1] == 0x00 && - p->buf[4] == 0x01 + p->buf[2] && - p->buf[8] == p->buf[4] + p->buf[6] && - p->buf[12] == p->buf[8] + p->buf[10]) - return AVPROBE_SCORE_MAX; - - return 0; + int i; + int index = 1; + if (p->buf_size < 16) + return 0; + for (i = 0; i < 16; i += 4) { + if (AV_RL16(p->buf + i) != index || !p->buf[i + 2] || !p->buf[i + 3]) + return 0; + index += p->buf[i + 2]; + } + return AVPROBE_SCORE_MAX; } static int read_header(AVFormatContext *s, @@ -79,7 +83,7 @@ static int read_header(AVFormatContext *s, if (!video) return AVERROR(ENOMEM); - video->codec->codec_type = CODEC_TYPE_VIDEO; + video->codec->codec_type = AVMEDIA_TYPE_VIDEO; video->codec->codec_id = CODEC_ID_C93; video->codec->width = 320; video->codec->height = 192; @@ -116,13 +120,13 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) c93->audio = av_new_stream(s, 1); if (!c93->audio) return AVERROR(ENOMEM); - c93->audio->codec->codec_type = CODEC_TYPE_AUDIO; + c93->audio->codec->codec_type = AVMEDIA_TYPE_AUDIO; } url_fskip(pb, 26); /* VOC header */ ret = voc_get_packet(s, pkt, c93->audio, datasize - 26); if (ret > 0) { pkt->stream_index = 1; - pkt->flags |= PKT_FLAG_KEY; + pkt->flags |= AV_PKT_FLAG_KEY; return ret; } } @@ -178,7 +182,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) /* only the first frame is guaranteed to not reference previous frames */ if (c93->current_block == 0 && c93->current_frame == 0) { - pkt->flags |= PKT_FLAG_KEY; + pkt->flags |= AV_PKT_FLAG_KEY; pkt->data[0] |= C93_FIRST_FRAME; } return 0; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/caf.c b/src/add-ons/media/plugins/ffmpeg/libavformat/caf.c new file mode 100644 index 0000000000..a814ab0d3c --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/caf.c @@ -0,0 +1,58 @@ +/* + * CAF common code + * Copyright (c) 2007 Justin Ruggles + * + * 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 + * CAF common code + */ + +#include "avformat.h" +#include "riff.h" +#include "caf.h" + +/** + * 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') }, + /* 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') }, + /* 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') },*/ + { CODEC_ID_NONE, 0 }, +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/caf.h b/src/add-ons/media/plugins/ffmpeg/libavformat/caf.h new file mode 100644 index 0000000000..e1f93a6b31 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/caf.h @@ -0,0 +1,34 @@ +/* + * CAF common code + * Copyright (c) 2007 Justin Ruggles + * + * 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 + * CAF common code + */ + +#ifndef AVFORMAT_CAF_H +#define AVFORMAT_CAF_H + +#include "riff.h" + +extern const AVCodecTag ff_codec_caf_tags[]; + +#endif /* AVFORMAT_CAF_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/cafdec.c b/src/add-ons/media/plugins/ffmpeg/libavformat/cafdec.c new file mode 100644 index 0000000000..c020579551 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/cafdec.c @@ -0,0 +1,379 @@ +/* + * Core Audio Format demuxer + * Copyright (c) 2007 Justin Ruggles + * Copyright (c) 2009 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 + */ + +/** + * @file + * Core Audio Format demuxer + */ + +#include "avformat.h" +#include "riff.h" +#include "isom.h" +#include "libavutil/intreadwrite.h" +#include "caf.h" + +typedef struct { + int bytes_per_packet; ///< bytes in a packet, or 0 if variable + int frames_per_packet; ///< frames in a packet, or 0 if variable + int64_t num_bytes; ///< total number of bytes in stream + + int64_t packet_cnt; ///< packet counter + int64_t frame_cnt; ///< frame counter + + int64_t data_start; ///< data start position, in bytes + int64_t data_size; ///< raw data size, in bytes +} CaffContext; + +static int probe(AVProbeData *p) +{ + if (AV_RB32(p->buf) == MKBETAG('c','a','f','f') && AV_RB16(&p->buf[4]) == 1) + return AVPROBE_SCORE_MAX; + return 0; +} + +/** Read audio description chunk */ +static int read_desc_chunk(AVFormatContext *s) +{ + ByteIOContext *pb = s->pb; + CaffContext *caf = s->priv_data; + AVStream *st; + int flags; + + /* new audio stream */ + st = av_new_stream(s, 0); + if (!st) + return AVERROR(ENOMEM); + + /* parse format description */ + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codec->sample_rate = av_int2dbl(get_be64(pb)); + st->codec->codec_tag = get_be32(pb); + flags = get_be32(pb); + caf->bytes_per_packet = get_be32(pb); + st->codec->block_align = caf->bytes_per_packet; + caf->frames_per_packet = get_be32(pb); + st->codec->channels = get_be32(pb); + st->codec->bits_per_coded_sample = get_be32(pb); + + /* calculate bit rate for constant size packets */ + if (caf->frames_per_packet > 0 && caf->bytes_per_packet > 0) { + st->codec->bit_rate = (uint64_t)st->codec->sample_rate * (uint64_t)caf->bytes_per_packet * 8 + / (uint64_t)caf->frames_per_packet; + } else { + st->codec->bit_rate = 0; + } + + /* determine codec */ + if (st->codec->codec_tag == MKBETAG('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); + return 0; +} + +/** Read magic cookie chunk */ +static int read_kuki_chunk(AVFormatContext *s, int64_t size) +{ + ByteIOContext *pb = s->pb; + AVStream *st = s->streams[0]; + + if (size < 0 || size > INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE) + return -1; + + if (st->codec->codec_id == CODEC_ID_AAC) { + /* The magic cookie format for AAC is an mp4 esds atom. + The lavc AAC decoder requires the data from the codec specific + description as extradata input. */ + int strt, skip; + MOVAtom atom; + + strt = url_ftell(pb); + ff_mov_read_esds(s, pb, atom); + skip = size - (url_ftell(pb) - strt); + if (skip < 0 || !st->codec->extradata || + st->codec->codec_id != CODEC_ID_AAC) { + av_log(s, AV_LOG_ERROR, "invalid AAC magic cookie\n"); + return AVERROR_INVALIDDATA; + } + url_fskip(pb, skip); + } else { + st->codec->extradata = av_mallocz(size + FF_INPUT_BUFFER_PADDING_SIZE); + if (!st->codec->extradata) + return AVERROR(ENOMEM); + get_buffer(pb, st->codec->extradata, size); + st->codec->extradata_size = size; + } + + return 0; +} + +/** Read packet table chunk */ +static int read_pakt_chunk(AVFormatContext *s, int64_t size) +{ + ByteIOContext *pb = s->pb; + AVStream *st = s->streams[0]; + CaffContext *caf = s->priv_data; + int64_t pos = 0, ccount; + int num_packets, i; + + ccount = url_ftell(pb); + + num_packets = get_be64(pb); + if (num_packets < 0 || INT32_MAX / sizeof(AVIndexEntry) < num_packets) + return AVERROR_INVALIDDATA; + + st->nb_frames = get_be64(pb); /* valid frames */ + st->nb_frames += get_be32(pb); /* priming frames */ + st->nb_frames += get_be32(pb); /* remainder frames */ + + st->duration = 0; + for (i = 0; i < num_packets; i++) { + av_add_index_entry(s->streams[0], pos, st->duration, 0, 0, AVINDEX_KEYFRAME); + pos += caf->bytes_per_packet ? caf->bytes_per_packet : ff_mp4_read_descr_len(pb); + st->duration += caf->frames_per_packet ? caf->frames_per_packet : ff_mp4_read_descr_len(pb); + } + + if (url_ftell(pb) - ccount != size) { + av_log(s, AV_LOG_ERROR, "error reading packet table\n"); + return -1; + } + + caf->num_bytes = pos; + return 0; +} + +/** Read information chunk */ +static void read_info_chunk(AVFormatContext *s, int64_t size) +{ + ByteIOContext *pb = s->pb; + unsigned int i; + unsigned int nb_entries = get_be32(pb); + for (i = 0; i < nb_entries; i++) { + char key[32]; + char value[1024]; + get_strz(pb, key, sizeof(key)); + get_strz(pb, value, sizeof(value)); + av_metadata_set2(&s->metadata, key, value, 0); + } +} + +static int read_header(AVFormatContext *s, + AVFormatParameters *ap) +{ + ByteIOContext *pb = s->pb; + CaffContext *caf = s->priv_data; + AVStream *st; + uint32_t tag = 0; + int found_data, ret; + int64_t size; + + url_fskip(pb, 8); /* magic, version, file flags */ + + /* audio description chunk */ + if (get_be32(pb) != MKBETAG('d','e','s','c')) { + av_log(s, AV_LOG_ERROR, "desc chunk not present\n"); + return AVERROR_INVALIDDATA; + } + size = get_be64(pb); + if (size != 32) + return AVERROR_INVALIDDATA; + + ret = read_desc_chunk(s); + if (ret) + return ret; + st = s->streams[0]; + + /* parse each chunk */ + found_data = 0; + while (!url_feof(pb)) { + + /* stop at data chunk if seeking is not supported or + data chunk size is unknown */ + if (found_data && (caf->data_size < 0 || url_is_streamed(pb))) + break; + + tag = get_be32(pb); + size = get_be64(pb); + if (url_feof(pb)) + break; + + switch (tag) { + case MKBETAG('d','a','t','a'): + url_fskip(pb, 4); /* edit count */ + caf->data_start = url_ftell(pb); + caf->data_size = size < 0 ? -1 : size - 4; + if (caf->data_size > 0 && !url_is_streamed(pb)) + url_fskip(pb, caf->data_size); + found_data = 1; + break; + + /* magic cookie chunk */ + case MKBETAG('k','u','k','i'): + if (read_kuki_chunk(s, size)) + return AVERROR_INVALIDDATA; + break; + + /* packet table chunk */ + case MKBETAG('p','a','k','t'): + if (read_pakt_chunk(s, size)) + return AVERROR_INVALIDDATA; + break; + + case MKBETAG('i','n','f','o'): + read_info_chunk(s, size); + 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)); +#undef _ + case MKBETAG('f','r','e','e'): + if (size < 0) + return AVERROR_INVALIDDATA; + url_fskip(pb, size); + break; + } + } + + if (!found_data) + return AVERROR_INVALIDDATA; + + if (caf->bytes_per_packet > 0 && caf->frames_per_packet > 0) { + if (caf->data_size > 0) + st->nb_frames = (caf->data_size / caf->bytes_per_packet) * caf->frames_per_packet; + } else if (st->nb_index_entries) { + st->codec->bit_rate = st->codec->sample_rate * caf->data_size * 8 / + st->duration; + } else { + av_log(s, AV_LOG_ERROR, "Missing packet table. It is required when " + "block size or frame size are variable.\n"); + return AVERROR_INVALIDDATA; + } + s->file_size = url_fsize(pb); + s->file_size = FFMAX(0, s->file_size); + + av_set_pts_info(st, 64, 1, st->codec->sample_rate); + st->start_time = 0; + + /* position the stream at the start of data */ + if (caf->data_size >= 0) + url_fseek(pb, caf->data_start, SEEK_SET); + + return 0; +} + +#define CAF_MAX_PKT_SIZE 4096 + +static int read_packet(AVFormatContext *s, AVPacket *pkt) +{ + ByteIOContext *pb = s->pb; + AVStream *st = s->streams[0]; + CaffContext *caf = s->priv_data; + int res, pkt_size = 0, pkt_frames = 0; + int64_t left = CAF_MAX_PKT_SIZE; + + if (url_feof(pb)) + return AVERROR(EIO); + + /* don't read past end of data chunk */ + if (caf->data_size > 0) { + left = (caf->data_start + caf->data_size) - url_ftell(pb); + if (left <= 0) + return AVERROR(EIO); + } + + pkt_frames = caf->frames_per_packet; + pkt_size = caf->bytes_per_packet; + + if (pkt_size > 0 && pkt_frames == 1) { + pkt_size = (CAF_MAX_PKT_SIZE / pkt_size) * pkt_size; + pkt_size = FFMIN(pkt_size, left); + pkt_frames = pkt_size / caf->bytes_per_packet; + } else if (st->nb_index_entries) { + if (caf->packet_cnt < st->nb_index_entries - 1) { + pkt_size = st->index_entries[caf->packet_cnt + 1].pos - st->index_entries[caf->packet_cnt].pos; + pkt_frames = st->index_entries[caf->packet_cnt + 1].timestamp - st->index_entries[caf->packet_cnt].timestamp; + } else if (caf->packet_cnt == st->nb_index_entries - 1) { + pkt_size = caf->num_bytes - st->index_entries[caf->packet_cnt].pos; + pkt_frames = st->duration - st->index_entries[caf->packet_cnt].timestamp; + } else { + return AVERROR(EIO); + } + } + + if (pkt_size == 0 || pkt_frames == 0 || pkt_size > left) + return AVERROR(EIO); + + res = av_get_packet(pb, pkt, pkt_size); + if (res < 0) + return res; + + pkt->size = res; + pkt->stream_index = 0; + pkt->dts = pkt->pts = caf->frame_cnt; + + caf->packet_cnt++; + caf->frame_cnt += pkt_frames; + + return 0; +} + +static int read_seek(AVFormatContext *s, int stream_index, + int64_t timestamp, int flags) +{ + AVStream *st = s->streams[0]; + CaffContext *caf = s->priv_data; + int64_t pos; + + timestamp = FFMAX(timestamp, 0); + + if (caf->frames_per_packet > 0 && caf->bytes_per_packet > 0) { + /* calculate new byte position based on target frame position */ + pos = caf->bytes_per_packet * timestamp / caf->frames_per_packet; + if (caf->data_size > 0) + pos = FFMIN(pos, caf->data_size); + caf->packet_cnt = pos / caf->bytes_per_packet; + caf->frame_cnt = caf->frames_per_packet * caf->packet_cnt; + } else if (st->nb_index_entries) { + caf->packet_cnt = av_index_search_timestamp(st, timestamp, flags); + caf->frame_cnt = st->index_entries[caf->packet_cnt].timestamp; + pos = st->index_entries[caf->packet_cnt].pos; + } else { + return -1; + } + + url_fseek(s->pb, pos + caf->data_start, SEEK_SET); + return 0; +} + +AVInputFormat caf_demuxer = { + "caf", + NULL_IF_CONFIG_SMALL("Apple Core Audio Format"), + sizeof(CaffContext), + probe, + read_header, + read_packet, + NULL, + read_seek, + .codec_tag = (const AVCodecTag*[]){ff_codec_caf_tags, 0}, +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/cdg.c b/src/add-ons/media/plugins/ffmpeg/libavformat/cdg.c new file mode 100644 index 0000000000..2f4fb2771d --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/cdg.c @@ -0,0 +1,66 @@ +/* + * CD Graphics Demuxer + * Copyright (c) 2009 Michael Tison + * + * 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" + +#define CDG_PACKET_SIZE 24 + +static int read_header(AVFormatContext *s, AVFormatParameters *ap) +{ + AVStream *vst; + int ret; + + vst = av_new_stream(s, 0); + if (!vst) + return AVERROR(ENOMEM); + + vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codec->codec_id = CODEC_ID_CDGRAPHICS; + + /// 75 sectors/sec * 4 packets/sector = 300 packets/sec + av_set_pts_info(vst, 32, 1, 300); + + ret = url_fsize(s->pb); + if (ret > 0) + vst->duration = (ret * vst->time_base.den) / (CDG_PACKET_SIZE * 300); + + return 0; +} + +static int read_packet(AVFormatContext *s, AVPacket *pkt) +{ + int ret; + + ret = av_get_packet(s->pb, pkt, CDG_PACKET_SIZE); + + pkt->stream_index = 0; + return ret; +} + +AVInputFormat cdg_demuxer = { + "cdg", + NULL_IF_CONFIG_SMALL("CD Graphics Format"), + 0, + NULL, + read_header, + read_packet, + .extensions = "cdg" +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/concat.c b/src/add-ons/media/plugins/ffmpeg/libavformat/concat.c new file mode 100644 index 0000000000..3a19d0a2ff --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/concat.c @@ -0,0 +1,198 @@ +/* + * Concat URL protocol + * Copyright (c) 2006 Steve Lhomme + * Copyright (c) 2007 Wolfram Gloger + * Copyright (c) 2010 Michele Orrù + * + * 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 "libavutil/avstring.h" +#include "libavutil/mem.h" + +#define AV_CAT_SEPARATOR "|" + +struct concat_nodes { + URLContext *uc; ///< node's URLContext + int64_t size; ///< url filesize +}; + +struct concat_data { + struct concat_nodes *nodes; ///< list of nodes to concat + size_t length; ///< number of cat'ed nodes + size_t current; ///< index of currently read node +}; + +static av_cold int concat_close(URLContext *h) +{ + int err = 0; + size_t i; + struct concat_data *data = h->priv_data; + struct concat_nodes *nodes = data->nodes; + + for (i = 0; i != data->length; i++) + err |= url_close(nodes[i].uc); + + av_freep(&data->nodes); + av_freep(&h->priv_data); + + return err < 0 ? -1 : 0; +} + +static av_cold int concat_open(URLContext *h, const char *uri, int flags) +{ + char *node_uri = NULL, *tmp_uri; + int err = 0; + int64_t size; + size_t len, i; + URLContext *uc; + struct concat_data *data; + struct concat_nodes *nodes; + + av_strstart(uri, "concat:", &uri); + + /* creating data */ + if (!(data = av_mallocz(sizeof(*data)))) + return AVERROR(ENOMEM); + h->priv_data = data; + + for (i = 0, len = 1; uri[i]; i++) + if (uri[i] == *AV_CAT_SEPARATOR) + /* integer overflow */ + if (++len == UINT_MAX / sizeof(*nodes)) { + av_freep(&h->priv_data); + return AVERROR(ENAMETOOLONG); + } + + if (!(nodes = av_malloc(sizeof(*nodes) * len))) { + av_freep(&h->priv_data); + return AVERROR(ENOMEM); + } else + data->nodes = nodes; + + /* handle input */ + if (!*uri) + err = AVERROR(ENOENT); + for (i = 0; *uri; i++) { + /* parsing uri */ + len = strcspn(uri, AV_CAT_SEPARATOR); + if (!(tmp_uri = av_realloc(node_uri, len+1))) { + err = AVERROR(ENOMEM); + break; + } else + node_uri = tmp_uri; + av_strlcpy(node_uri, uri, len+1); + uri += len + strspn(uri+len, AV_CAT_SEPARATOR); + + /* creating URLContext */ + if ((err = url_open(&uc, node_uri, flags)) < 0) + break; + + /* creating size */ + if ((size = url_filesize(uc)) < 0) { + url_close(uc); + err = AVERROR(ENOSYS); + break; + } + + /* assembling */ + nodes[i].uc = uc; + nodes[i].size = size; + } + av_free(node_uri); + data->length = i; + + if (err < 0) + concat_close(h); + else if (!(nodes = av_realloc(nodes, data->length * sizeof(*nodes)))) { + concat_close(h); + err = AVERROR(ENOMEM); + } else + data->nodes = nodes; + return err; +} + +static int concat_read(URLContext *h, unsigned char *buf, int size) +{ + int result, total = 0; + struct concat_data *data = h->priv_data; + struct concat_nodes *nodes = data->nodes; + size_t i = data->current; + + while (size > 0) { + result = url_read(nodes[i].uc, buf, size); + if (result < 0) + return total ? total : result; + if (!result) + if (i + 1 == data->length || + url_seek(nodes[++i].uc, 0, SEEK_SET) < 0) + break; + total += result; + buf += result; + size -= result; + } + data->current = i; + return total; +} + +static int64_t concat_seek(URLContext *h, int64_t pos, int whence) +{ + int64_t result; + struct concat_data *data = h->priv_data; + struct concat_nodes *nodes = data->nodes; + size_t i; + + switch (whence) { + case SEEK_END: + for (i = data->length - 1; + i && pos < -nodes[i].size; + i--) + pos += nodes[i].size; + break; + case SEEK_CUR: + /* get the absolute position */ + for (i = 0; i != data->current; i++) + pos += nodes[i].size; + pos += url_seek(nodes[i].uc, 0, SEEK_CUR); + whence = SEEK_SET; + /* fall through with the absolute position */ + case SEEK_SET: + for (i = 0; i != data->length - 1 && pos >= nodes[i].size; i++) + pos -= nodes[i].size; + break; + default: + return AVERROR(EINVAL); + } + + result = url_seek(nodes[i].uc, pos, whence); + if (result >= 0) { + data->current = i; + while (i) + result += nodes[--i].size; + } + return result; +} + +URLProtocol concat_protocol = { + "concat", + concat_open, + concat_read, + NULL, + concat_seek, + concat_close, +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/cutils.c b/src/add-ons/media/plugins/ffmpeg/libavformat/cutils.c index 4967d5b90c..5092d99f6a 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/cutils.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/cutils.c @@ -19,6 +19,7 @@ * 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) diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/daud.c b/src/add-ons/media/plugins/ffmpeg/libavformat/daud.c index cdd831ba4b..9b0e008347 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/daud.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/daud.c @@ -24,7 +24,7 @@ static int daud_header(AVFormatContext *s, AVFormatParameters *ap) { AVStream *st = av_new_stream(s, 0); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_PCM_S24DAUD; st->codec->codec_tag = MKTAG('d', 'a', 'u', 'd'); st->codec->channels = 6; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/dsicin.c b/src/add-ons/media/plugins/ffmpeg/libavformat/dsicin.c index ba94babbfe..af5e2d9472 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/dsicin.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/dsicin.c @@ -20,7 +20,7 @@ */ /** - * @file libavformat/dsicin.c + * @file * Delphine Software International CIN file demuxer */ @@ -113,7 +113,7 @@ static int cin_read_header(AVFormatContext *s, AVFormatParameters *ap) av_set_pts_info(st, 32, 1, 12); cin->video_stream_index = st->index; - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_DSICINVIDEO; st->codec->codec_tag = 0; /* no fourcc */ st->codec->width = hdr->video_frame_width; @@ -126,7 +126,7 @@ static int cin_read_header(AVFormatContext *s, AVFormatParameters *ap) av_set_pts_info(st, 32, 1, 22050); cin->audio_stream_index = st->index; - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_DSICINAUDIO; st->codec->codec_tag = 0; /* no tag */ st->codec->channels = 1; @@ -162,6 +162,7 @@ static int cin_read_packet(AVFormatContext *s, AVPacket *pkt) ByteIOContext *pb = s->pb; CinFrameHeader *hdr = &cin->frame_header; int rc, palette_type, pkt_size; + int ret; if (cin->audio_buffer_size == 0) { rc = cin_read_frame_header(cin, pb); @@ -178,8 +179,9 @@ static int cin_read_packet(AVFormatContext *s, AVPacket *pkt) /* palette and video packet */ pkt_size = (palette_type + 3) * hdr->pal_colors_count + hdr->video_frame_size; - if (av_new_packet(pkt, 4 + pkt_size)) - return AVERROR(ENOMEM); + ret = av_new_packet(pkt, 4 + pkt_size); + if (ret < 0) + return ret; pkt->stream_index = cin->video_stream_index; pkt->pts = cin->video_stream_pts++; @@ -189,8 +191,13 @@ static int cin_read_packet(AVFormatContext *s, AVPacket *pkt) pkt->data[2] = hdr->pal_colors_count >> 8; pkt->data[3] = hdr->video_frame_type; - if (get_buffer(pb, &pkt->data[4], pkt_size) != pkt_size) - return AVERROR(EIO); + ret = get_buffer(pb, &pkt->data[4], pkt_size); + if (ret < 0) { + av_free_packet(pkt); + return ret; + } + if (ret < pkt_size) + av_shrink_packet(pkt, 4 + ret); /* sound buffer will be processed on next read_packet() call */ cin->audio_buffer_size = hdr->audio_frame_size; @@ -198,16 +205,13 @@ static int cin_read_packet(AVFormatContext *s, AVPacket *pkt) } /* audio packet */ - if (av_new_packet(pkt, cin->audio_buffer_size)) - return AVERROR(ENOMEM); + ret = av_get_packet(pb, pkt, cin->audio_buffer_size); + if (ret < 0) + return ret; pkt->stream_index = cin->audio_stream_index; pkt->pts = cin->audio_stream_pts; cin->audio_stream_pts += cin->audio_buffer_size * 2 / cin->file_header.audio_frame_size; - - if (get_buffer(pb, pkt->data, cin->audio_buffer_size) != cin->audio_buffer_size) - return AVERROR(EIO); - cin->audio_buffer_size = 0; return 0; } diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/dv.c b/src/add-ons/media/plugins/ffmpeg/libavformat/dv.c index a75b4a6b0d..b6f9c6ae54 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/dv.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/dv.c @@ -214,14 +214,14 @@ static int dv_extract_audio_info(DVDemuxContext* c, uint8_t* frame) if (!c->ast[i]) break; av_set_pts_info(c->ast[i], 64, 1, 30000); - c->ast[i]->codec->codec_type = CODEC_TYPE_AUDIO; + c->ast[i]->codec->codec_type = AVMEDIA_TYPE_AUDIO; c->ast[i]->codec->codec_id = CODEC_ID_PCM_S16LE; av_init_packet(&c->audio_pkt[i]); c->audio_pkt[i].size = 0; c->audio_pkt[i].data = c->audio_buf[i]; c->audio_pkt[i].stream_index = c->ast[i]->index; - c->audio_pkt[i].flags |= PKT_FLAG_KEY; + c->audio_pkt[i].flags |= AV_PKT_FLAG_KEY; } c->ast[i]->codec->sample_rate = dv_audio_frequency[freq]; c->ast[i]->codec->channels = 2; @@ -290,7 +290,7 @@ DVDemuxContext* dv_init_demux(AVFormatContext *s) c->frames = 0; c->abytes = 0; - c->vst->codec->codec_type = CODEC_TYPE_VIDEO; + c->vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; c->vst->codec->codec_id = CODEC_ID_DVVIDEO; c->vst->codec->bit_rate = 25000000; c->vst->start_time = 0; @@ -322,7 +322,7 @@ int dv_produce_packet(DVDemuxContext *c, AVPacket *pkt, uint8_t *ppcm[4] = {0}; if (buf_size < DV_PROFILE_BYTES || - !(c->sys = dv_frame_profile(c->sys, buf, buf_size)) || + !(c->sys = ff_dv_frame_profile(c->sys, buf, buf_size)) || buf_size < c->sys->frame_size) { return -1; /* Broken frame, or not enough data */ } @@ -355,7 +355,7 @@ int dv_produce_packet(DVDemuxContext *c, AVPacket *pkt, av_init_packet(pkt); pkt->data = buf; pkt->size = size; - pkt->flags |= PKT_FLAG_KEY; + pkt->flags |= AV_PKT_FLAG_KEY; pkt->stream_index = c->vst->id; pkt->pts = c->frames; @@ -368,14 +368,14 @@ 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 = dv_codec_profile(c->vst->codec); + const DVprofile* sys = ff_dv_codec_profile(c->vst->codec); int64_t offset; int64_t size = url_fsize(s->pb); int64_t max_offset = ((size-1) / sys->frame_size) * sys->frame_size; offset = sys->frame_size * timestamp; - if (offset > max_offset) offset = max_offset; + if (size >= 0 && offset > max_offset) offset = max_offset; else if (offset < 0) offset = 0; return offset; @@ -431,7 +431,7 @@ static int dv_read_header(AVFormatContext *s, url_fseek(s->pb, -DV_PROFILE_BYTES, SEEK_CUR) < 0) return AVERROR(EIO); - c->dv_demux->sys = dv_frame_profile(c->dv_demux->sys, c->buf, DV_PROFILE_BYTES); + c->dv_demux->sys = ff_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; @@ -488,6 +488,8 @@ static int dv_probe(AVProbeData *p) { unsigned state, marker_pos = 0; int i; + int matches = 0; + int secondary_matches = 0; if (p->buf_size < 5) return 0; @@ -495,14 +497,23 @@ static int dv_probe(AVProbeData *p) state = AV_RB32(p->buf); for (i = 4; i < p->buf_size; i++) { if ((state & 0xffffff7f) == 0x1f07003f) - return AVPROBE_SCORE_MAX*3/4; // not max to avoid dv in mov to match + matches++; + // any section header, also with seq/chan num != 0, + // should appear around every 12000 bytes, at least 10 per frame + if ((state & 0xff07ff7f) == 0x1f07003f) + secondary_matches++; if (state == 0x003f0700 || state == 0xff3f0700) marker_pos = i; if (state == 0xff3f0701 && i - marker_pos == 80) - return AVPROBE_SCORE_MAX/4; + matches++; state = (state << 8) | p->buf[i]; } + if (matches && p->buf_size / matches < 1024*1024) { + if (matches > 4 || (secondary_matches >= 10 && p->buf_size / secondary_matches < 24000)) + return AVPROBE_SCORE_MAX*3/4; // not max to avoid dv in mov to match + return AVPROBE_SCORE_MAX/4; + } return 0; } diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/dvenc.c b/src/add-ons/media/plugins/ffmpeg/libavformat/dvenc.c index c87697dd13..0176ac9767 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/dvenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/dvenc.c @@ -29,7 +29,9 @@ */ #include #include + #include "avformat.h" +#include "internal.h" #include "libavcodec/dvdata.h" #include "dv.h" #include "libavutil/fifo.h" @@ -239,7 +241,7 @@ int dv_assemble_frame(DVMuxContext *c, AVStream* st, reqasize = 4 * dv_audio_frame_size(c->sys, c->frames); switch (st->codec->codec_type) { - case CODEC_TYPE_VIDEO: + case AVMEDIA_TYPE_VIDEO: /* FIXME: we have to have more sensible approach than this one */ if (c->has_video) av_log(st->codec, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient audio data or severe sync problem.\n", c->frames); @@ -247,7 +249,7 @@ int dv_assemble_frame(DVMuxContext *c, AVStream* st, memcpy(*frame, data, c->sys->frame_size); c->has_video = 1; break; - case CODEC_TYPE_AUDIO: + case AVMEDIA_TYPE_AUDIO: for (i = 0; i < c->n_ast && st != c->ast[i]; i++); /* FIXME: we have to have more sensible approach than this one */ @@ -299,11 +301,11 @@ DVMuxContext* dv_init_mux(AVFormatContext* s) /* We have to sort out where audio and where video stream is */ for (i=0; inb_streams; i++) { switch (s->streams[i]->codec->codec_type) { - case CODEC_TYPE_VIDEO: + case AVMEDIA_TYPE_VIDEO: if (vst) return NULL; vst = s->streams[i]; break; - case CODEC_TYPE_AUDIO: + case AVMEDIA_TYPE_AUDIO: if (c->n_ast > 1) return NULL; c->ast[c->n_ast++] = s->streams[i]; break; @@ -321,7 +323,7 @@ DVMuxContext* dv_init_mux(AVFormatContext* s) c->ast[i]->codec->channels != 2)) goto bail_out; } - c->sys = dv_codec_profile(vst->codec); + c->sys = ff_dv_codec_profile(vst->codec); if (!c->sys) goto bail_out; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/dxa.c b/src/add-ons/media/plugins/ffmpeg/libavformat/dxa.c index 5b6cd67b59..c00c917d0b 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/dxa.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/dxa.c @@ -36,9 +36,15 @@ typedef struct{ static int dxa_probe(AVProbeData *p) { + int w, h; + if (p->buf_size < 15) + return 0; + w = AV_RB16(p->buf + 11); + h = AV_RB16(p->buf + 13); /* check file header */ if (p->buf[0] == 'D' && p->buf[1] == 'E' && - p->buf[2] == 'X' && p->buf[3] == 'A') + p->buf[2] == 'X' && p->buf[3] == 'A' && + w && w <= 2048 && h && h <= 2048) return AVPROBE_SCORE_MAX; else return 0; @@ -113,7 +119,7 @@ static int dxa_read_header(AVFormatContext *s, AVFormatParameters *ap) } /* now we are ready: build format streams */ - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_DXA; st->codec->width = w; st->codec->height = h; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/eacdata.c b/src/add-ons/media/plugins/ffmpeg/libavformat/eacdata.c index f4ea2f2e98..32c3343320 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/eacdata.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/eacdata.c @@ -20,9 +20,9 @@ */ /** - * @file libavformat/eacdata.c + * @file * Electronic Arts cdata Format Demuxer - * by Peter Ross (suxen_drol at hotmail dot com) + * by Peter Ross (pross@xvid.org) * * Technical details here: * http://wiki.multimedia.cx/index.php?title=EA_Command_And_Conquer_3_Audio_Codec @@ -67,7 +67,7 @@ static int cdata_read_header(AVFormatContext *s, AVFormatParameters *ap) st = av_new_stream(s, 0); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = CODEC_TYPE_AUDIO; + 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; @@ -83,10 +83,11 @@ static int cdata_read_packet(AVFormatContext *s, AVPacket *pkt) CdataDemuxContext *cdata = s->priv_data; int packet_size = 76*cdata->channels; - if (av_get_packet(s->pb, pkt, packet_size) != packet_size) - return AVERROR(EIO); + int ret = av_get_packet(s->pb, pkt, packet_size); + if (ret < 0) + return ret; pkt->pts = cdata->audio_pts++; - return 1; + return 0; } AVInputFormat ea_cdata_demuxer = { diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/electronicarts.c b/src/add-ons/media/plugins/ffmpeg/libavformat/electronicarts.c index 9f82e623f2..86d7f91e66 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/electronicarts.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/electronicarts.c @@ -20,7 +20,7 @@ */ /** - * @file libavformat/electronicarts.c + * @file * Electronic Arts Multimedia file demuxer (WVE/UV2/etc.) * by Robin Kay (komadori at gekkou.co.uk) */ @@ -192,6 +192,7 @@ static int process_audio_header_elements(AVFormatContext *s) case 16: ea->audio_codec = CODEC_ID_MP3; break; case -1: break; default: + ea->audio_codec = CODEC_ID_NONE; av_log(s, AV_LOG_ERROR, "unsupported stream type; revision2=%i\n", revision2); return 0; } @@ -389,9 +390,13 @@ static int ea_probe(AVProbeData *p) case MPCh_TAG: case MVhd_TAG: case MVIh_TAG: - return AVPROBE_SCORE_MAX; + break; + default: + return 0; } - return 0; + if (AV_RL32(&p->buf[4]) > 0xfffff && AV_RB32(&p->buf[4]) > 0xfffff) + return 0; + return AVPROBE_SCORE_MAX; } static int ea_read_header(AVFormatContext *s, @@ -409,7 +414,7 @@ static int ea_read_header(AVFormatContext *s, if (!st) return AVERROR(ENOMEM); ea->video_stream_index = st->index; - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = ea->video_codec; st->codec->codec_tag = 0; /* no fourcc */ st->codec->time_base = ea->time_base; @@ -423,7 +428,7 @@ static int ea_read_header(AVFormatContext *s, if (!st) return AVERROR(ENOMEM); av_set_pts_info(st, 33, 1, ea->sample_rate); - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = ea->audio_codec; st->codec->codec_tag = 0; /* no tag */ st->codec->channels = ea->num_channels; @@ -515,7 +520,7 @@ static int ea_read_packet(AVFormatContext *s, case pQGT_TAG: case TGQs_TAG: case MADk_TAG: - key = PKT_FLAG_KEY; + key = AV_PKT_FLAG_KEY; case MVIf_TAG: case fVGT_TAG: case MADm_TAG: @@ -532,7 +537,7 @@ static int ea_read_packet(AVFormatContext *s, case MV0K_TAG: case MPCh_TAG: case pIQT_TAG: - key = PKT_FLAG_KEY; + key = AV_PKT_FLAG_KEY; case MV0F_TAG: get_video_packet: ret = av_get_packet(pb, pkt, chunk_size); diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/ffmdec.c b/src/add-ons/media/plugins/ffmpeg/libavformat/ffmdec.c index dc4da29f09..b2a4bc20fb 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/ffmdec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/ffmdec.c @@ -301,7 +301,7 @@ static int ffm_read_header(AVFormatContext *s, AVFormatParameters *ap) codec->debug = get_be32(pb); /* specific info */ switch(codec->codec_type) { - case CODEC_TYPE_VIDEO: + case AVMEDIA_TYPE_VIDEO: codec->time_base.num = get_be32(pb); codec->time_base.den = get_be32(pb); codec->width = get_be16(pb); @@ -336,11 +336,25 @@ static int ffm_read_header(AVFormatContext *s, AVFormatParameters *ap) codec->rc_buffer_aggressivity = av_int2dbl(get_be64(pb)); codec->codec_tag = get_be32(pb); codec->thread_count = get_byte(pb); + codec->coder_type = get_be32(pb); + codec->me_cmp = get_be32(pb); + codec->partitions = get_be32(pb); + codec->me_subpel_quality = get_be32(pb); + codec->me_range = get_be32(pb); + codec->keyint_min = get_be32(pb); + codec->scenechange_threshold = get_be32(pb); + codec->b_frame_strategy = get_be32(pb); + codec->qcompress = av_int2dbl(get_be64(pb)); + codec->qblur = av_int2dbl(get_be64(pb)); + codec->max_qdiff = get_be32(pb); + codec->refs = get_be32(pb); + codec->directpred = get_be32(pb); break; - case CODEC_TYPE_AUDIO: + case AVMEDIA_TYPE_AUDIO: codec->sample_rate = get_be32(pb); codec->channels = get_le16(pb); codec->frame_size = get_le16(pb); + codec->sample_fmt = (int16_t) get_le16(pb); break; default: goto fail; @@ -418,7 +432,7 @@ static int ffm_read_packet(AVFormatContext *s, AVPacket *pkt) } pkt->pos = url_ftell(s->pb); if (ffm->header[1] & FLAG_KEY_FRAME) - pkt->flags |= PKT_FLAG_KEY; + pkt->flags |= AV_PKT_FLAG_KEY; ffm->read_state = READ_HEADER; if (ffm_read_data(s, pkt->data, size, 0) != size) { @@ -498,6 +512,16 @@ static int ffm_probe(AVProbeData *p) return 0; } +static int ffm_close(AVFormatContext *s) +{ + int i; + + for (i = 0; i < s->nb_streams; i++) + av_freep(&s->streams[i]->codec->rc_eq); + + return 0; +} + AVInputFormat ffm_demuxer = { "ffm", NULL_IF_CONFIG_SMALL("FFM (FFserver live feed) format"), @@ -505,6 +529,6 @@ AVInputFormat ffm_demuxer = { ffm_probe, ffm_read_header, ffm_read_packet, - NULL, + ffm_close, ffm_seek, }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/ffmenc.c b/src/add-ons/media/plugins/ffmpeg/libavformat/ffmenc.c index 3de4984dfe..c5c59db711 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/ffmenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/ffmenc.c @@ -119,7 +119,7 @@ static int ffm_write_header(AVFormatContext *s) put_be32(pb, codec->debug); /* specific info */ switch(codec->codec_type) { - case CODEC_TYPE_VIDEO: + case AVMEDIA_TYPE_VIDEO: put_be32(pb, codec->time_base.num); put_be32(pb, codec->time_base.den); put_be16(pb, codec->width); @@ -154,11 +154,25 @@ static int ffm_write_header(AVFormatContext *s) put_be64(pb, av_dbl2int(codec->rc_buffer_aggressivity)); put_be32(pb, codec->codec_tag); put_byte(pb, codec->thread_count); + put_be32(pb, codec->coder_type); + put_be32(pb, codec->me_cmp); + put_be32(pb, codec->partitions); + put_be32(pb, codec->me_subpel_quality); + put_be32(pb, codec->me_range); + put_be32(pb, codec->keyint_min); + put_be32(pb, codec->scenechange_threshold); + put_be32(pb, codec->b_frame_strategy); + put_be64(pb, av_dbl2int(codec->qcompress)); + put_be64(pb, av_dbl2int(codec->qblur)); + put_be32(pb, codec->max_qdiff); + put_be32(pb, codec->refs); + put_be32(pb, codec->directpred); break; - case CODEC_TYPE_AUDIO: + case AVMEDIA_TYPE_AUDIO: put_be32(pb, codec->sample_rate); put_le16(pb, codec->channels); put_le16(pb, codec->frame_size); + put_le16(pb, codec->sample_fmt); break; default: return -1; @@ -196,7 +210,7 @@ static int ffm_write_packet(AVFormatContext *s, AVPacket *pkt) /* packet size & key_frame */ header[0] = pkt->stream_index; header[1] = 0; - if (pkt->flags & PKT_FLAG_KEY) + if (pkt->flags & AV_PKT_FLAG_KEY) header[1] |= FLAG_KEY_FRAME; AV_WB24(header+2, pkt->size); AV_WB24(header+5, pkt->duration); diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/file.c b/src/add-ons/media/plugins/ffmpeg/libavformat/file.c index d2cb5302d4..8873d5fcaf 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/file.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/file.c @@ -26,6 +26,7 @@ #include #endif #include +#include #include #include #include "os_support.h" @@ -52,7 +53,7 @@ static int file_open(URLContext *h, const char *filename, int flags) #endif fd = open(filename, access, 0666); if (fd == -1) - return AVERROR(ENOENT); + return AVERROR(errno); h->priv_data = (void *) (intptr_t) fd; return 0; } @@ -73,6 +74,11 @@ static int file_write(URLContext *h, unsigned char *buf, int size) static int64_t file_seek(URLContext *h, int64_t pos, int whence) { int fd = (intptr_t) h->priv_data; + if (whence == AVSEEK_SIZE) { + struct stat st; + int ret = fstat(fd, &st); + return ret < 0 ? AVERROR(errno) : st.st_size; + } return lseek(fd, pos, whence); } diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/filmstripdec.c b/src/add-ons/media/plugins/ffmpeg/libavformat/filmstripdec.c new file mode 100644 index 0000000000..0442fc370d --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/filmstripdec.c @@ -0,0 +1,111 @@ +/* + * Adobe Filmstrip demuxer + * Copyright (c) 2010 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 + */ + +/** + * @file + * Adobe Filmstrip demuxer + */ + +#include "libavutil/intreadwrite.h" +#include "avformat.h" + +#define RAND_TAG MKBETAG('R','a','n','d') + +typedef struct { + int leading; +} FilmstripDemuxContext; + +static int read_header(AVFormatContext *s, + AVFormatParameters *ap) +{ + FilmstripDemuxContext *film = s->priv_data; + ByteIOContext *pb = s->pb; + AVStream *st; + + if (url_is_streamed(s->pb)) + return AVERROR(EIO); + + url_fseek(pb, url_fsize(pb) - 36, SEEK_SET); + if (get_be32(pb) != RAND_TAG) { + av_log(s, AV_LOG_ERROR, "magic number not found"); + return AVERROR_INVALIDDATA; + } + + st = av_new_stream(s, 0); + if (!st) + return AVERROR(ENOMEM); + + st->nb_frames = get_be32(pb); + if (get_be16(pb) != 0) { + av_log_ask_for_sample(s, "unsupported packing method\n"); + return AVERROR_INVALIDDATA; + } + + url_fskip(pb, 2); + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_RAWVIDEO; + st->codec->pix_fmt = PIX_FMT_RGBA; + st->codec->codec_tag = 0; /* no fourcc */ + st->codec->width = get_be16(pb); + st->codec->height = get_be16(pb); + film->leading = get_be16(pb); + av_set_pts_info(st, 64, 1, get_be16(pb)); + + url_fseek(pb, 0, SEEK_SET); + + return 0; +} + +static int read_packet(AVFormatContext *s, + AVPacket *pkt) +{ + FilmstripDemuxContext *film = s->priv_data; + AVStream *st = s->streams[0]; + + if (url_feof(s->pb)) + return AVERROR(EIO); + pkt->dts = url_ftell(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); + url_fskip(s->pb, st->codec->width * film->leading * 4); + if (pkt->size < 0) + return pkt->size; + pkt->flags |= AV_PKT_FLAG_KEY; + return 0; +} + +static int read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) +{ + AVStream *st = s->streams[stream_index]; + url_fseek(s->pb, FFMAX(timestamp, 0) * st->codec->width * st->codec->height * 4, SEEK_SET); + return 0; +} + +AVInputFormat filmstrip_demuxer = { + "filmstrip", + NULL_IF_CONFIG_SMALL("Adobe Filmstrip"), + sizeof(FilmstripDemuxContext), + NULL, + read_header, + read_packet, + NULL, + read_seek, + .extensions = "flm", +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/filmstripenc.c b/src/add-ons/media/plugins/ffmpeg/libavformat/filmstripenc.c new file mode 100644 index 0000000000..4e10c28af2 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/filmstripenc.c @@ -0,0 +1,85 @@ +/* + * Adobe Filmstrip muxer + * Copyright (c) 2010 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 + */ + +/** + * @file + * Adobe Filmstrip muxer + */ + +#include "libavutil/intreadwrite.h" +#include "avformat.h" + +#define RAND_TAG MKBETAG('R','a','n','d') + +typedef struct { + int nb_frames; +} FilmstripMuxContext; + +static int write_header(AVFormatContext *s) +{ + if (s->streams[0]->codec->pix_fmt != PIX_FMT_RGBA) { + av_log(s, AV_LOG_ERROR, "only PIX_FMT_RGBA is supported\n"); + return AVERROR_INVALIDDATA; + } + return 0; +} + +static int write_packet(AVFormatContext *s, AVPacket *pkt) +{ + FilmstripMuxContext *film = s->priv_data; + put_buffer(s->pb, pkt->data, pkt->size); + film->nb_frames++; + return 0; +} + +static int write_trailer(AVFormatContext *s) +{ + FilmstripMuxContext *film = s->priv_data; + ByteIOContext *pb = s->pb; + AVStream *st = s->streams[0]; + int i; + + put_be32(pb, RAND_TAG); + put_be32(pb, film->nb_frames); + put_be16(pb, 0); // packing method + put_be16(pb, 0); // reserved + put_be16(pb, st->codec->width); + put_be16(pb, st->codec->height); + put_be16(pb, 0); // leading + put_be16(pb, 1/av_q2d(st->codec->time_base)); + for (i = 0; i < 16; i++) + put_byte(pb, 0x00); // reserved + put_flush_packet(pb); + return 0; +} + +AVOutputFormat 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, +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/flacdec.c b/src/add-ons/media/plugins/ffmpeg/libavformat/flacdec.c index 067d4fafe9..2ceef964e8 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/flacdec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/flacdec.c @@ -24,6 +24,7 @@ #include "raw.h" #include "id3v2.h" #include "oggdec.h" +#include "vorbiscomment.h" static int flac_read_header(AVFormatContext *s, AVFormatParameters *ap) @@ -35,7 +36,7 @@ static int flac_read_header(AVFormatContext *s, AVStream *st = av_new_stream(s, 0); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_FLAC; st->need_parsing = AVSTREAM_PARSE_FULL; /* the parameters will be extracted from the compressed bitstream */ @@ -66,11 +67,11 @@ static int flac_read_header(AVFormatContext *s, case FLAC_METADATA_TYPE_VORBIS_COMMENT: buffer = av_mallocz(metadata_size + FF_INPUT_BUFFER_PADDING_SIZE); if (!buffer) { - return AVERROR_NOMEM; + return AVERROR(ENOMEM); } if (get_buffer(s->pb, buffer, metadata_size) != metadata_size) { av_freep(&buffer); - return AVERROR_IO; + return AVERROR(EIO); } break; /* skip metadata block for unsupported types */ @@ -113,7 +114,7 @@ static int flac_read_header(AVFormatContext *s, } /* process supported blocks other than STREAMINFO */ if (metadata_type == FLAC_METADATA_TYPE_VORBIS_COMMENT) { - if (vorbis_comment(s, buffer, metadata_size)) { + if (ff_vorbis_comment(s, &s->metadata, buffer, metadata_size)) { av_log(s, AV_LOG_WARNING, "error parsing VorbisComment metadata\n"); } } diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/flacenc.c b/src/add-ons/media/plugins/ffmpeg/libavformat/flacenc.c index 81844cc2d2..91a080f3a3 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/flacenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/flacenc.c @@ -22,32 +22,68 @@ #include "libavcodec/flac.h" #include "avformat.h" #include "flacenc.h" +#include "metadata.h" +#include "vorbiscomment.h" +#include "libavcodec/bytestream.h" -int ff_flac_write_header(ByteIOContext *pb, AVCodecContext *codec) + +static int flac_write_block_padding(ByteIOContext *pb, unsigned int n_padding_bytes, + int last_block) { - static const uint8_t header[8] = { - 0x66, 0x4C, 0x61, 0x43, 0x80, 0x00, 0x00, 0x22 - }; - uint8_t *streaminfo; - enum FLACExtradataFormat format; - - if (!ff_flac_is_extradata_valid(codec, &format, &streaminfo)) - return -1; - - /* write "fLaC" stream marker and first metadata block header if needed */ - if (format == FLAC_EXTRADATA_FORMAT_STREAMINFO) { - put_buffer(pb, header, 8); + put_byte(pb, last_block ? 0x81 : 0x01); + put_be24(pb, n_padding_bytes); + while (n_padding_bytes > 0) { + put_byte(pb, 0); + n_padding_bytes--; } + return 0; +} - /* write STREAMINFO or full header */ - put_buffer(pb, codec->extradata, codec->extradata_size); +static int flac_write_block_comment(ByteIOContext *pb, AVMetadata *m, + int last_block, int bitexact) +{ + const char *vendor = bitexact ? "ffmpeg" : LIBAVFORMAT_IDENT; + unsigned int len, count; + uint8_t *p, *p0; + + len = ff_vorbiscomment_length(m, vendor, &count); + p0 = av_malloc(len+4); + if (!p0) + return AVERROR(ENOMEM); + p = p0; + + bytestream_put_byte(&p, last_block ? 0x84 : 0x04); + bytestream_put_be24(&p, len); + ff_vorbiscomment_write(&p, m, vendor, count); + + put_buffer(pb, p0, len+4); + av_freep(&p0); + p = NULL; return 0; } static int flac_write_header(struct AVFormatContext *s) { - return ff_flac_write_header(s->pb, s->streams[0]->codec); + int ret; + AVCodecContext *codec = s->streams[0]->codec; + + ret = ff_flac_write_header(s->pb, codec, 0); + if (ret) + return ret; + + ret = flac_write_block_comment(s->pb, s->metadata, 0, + codec->flags & CODEC_FLAG_BITEXACT); + if (ret) + return ret; + + /* The command line flac encoder defaults to placing a seekpoint + * every 10s. So one might add padding to allow that later + * but there seems to be no simple way to get the duration here. + * So let's try the flac default of 8192 bytes */ + flac_write_block_padding(s->pb, 8192, 1); + + return ret; } static int flac_write_trailer(struct AVFormatContext *s) @@ -92,4 +128,5 @@ AVOutputFormat flac_muxer = { flac_write_packet, flac_write_trailer, .flags= AVFMT_NOTIMESTAMPS, + .metadata_conv = ff_vorbiscomment_metadata_conv, }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/flacenc.h b/src/add-ons/media/plugins/ffmpeg/libavformat/flacenc.h index a9b7f6210a..8ad1c267ab 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/flacenc.h +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/flacenc.h @@ -22,8 +22,11 @@ #ifndef AVFORMAT_FLACENC_H #define AVFORMAT_FLACENC_H +#include "libavcodec/flac.h" +#include "libavcodec/bytestream.h" #include "avformat.h" -int ff_flac_write_header(ByteIOContext *pb, AVCodecContext *codec); +int ff_flac_write_header(ByteIOContext *pb, AVCodecContext *codec, + int last_block); #endif /* AVFORMAT_FLACENC_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/flacenc_header.c b/src/add-ons/media/plugins/ffmpeg/libavformat/flacenc_header.c new file mode 100644 index 0000000000..92a129a7d6 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/flacenc_header.c @@ -0,0 +1,49 @@ +/* + * raw FLAC muxer + * Copyright (C) 2009 Justin Ruggles + * + * 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 "libavcodec/flac.h" +#include "libavcodec/bytestream.h" +#include "avformat.h" +#include "flacenc.h" + +int ff_flac_write_header(ByteIOContext *pb, AVCodecContext *codec, + int last_block) +{ + uint8_t header[8] = { + 0x66, 0x4C, 0x61, 0x43, 0x00, 0x00, 0x00, 0x22 + }; + uint8_t *streaminfo; + enum FLACExtradataFormat format; + + header[4] = last_block ? 0x80 : 0x00; + if (!ff_flac_is_extradata_valid(codec, &format, &streaminfo)) + return -1; + + /* write "fLaC" stream marker and first metadata block header if needed */ + if (format == FLAC_EXTRADATA_FORMAT_STREAMINFO) { + put_buffer(pb, header, 8); + } + + /* write STREAMINFO or full header */ + put_buffer(pb, codec->extradata, codec->extradata_size); + + return 0; +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/flic.c b/src/add-ons/media/plugins/ffmpeg/libavformat/flic.c index b382a25f96..27145db086 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/flic.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/flic.c @@ -20,15 +20,15 @@ */ /** - * @file libavformat/flic.c + * @file * FLI/FLC file demuxer * by Mike Melanson (melanson@pcisys.net) * for more information on the .fli/.flc file format and all of its many * variations, visit: * http://www.compuphase.com/flic.htm * - * This demuxer handles standard 0xAF11- and 0xAF12-type FLIs. It also - * handles special FLIs from the PC game "Magic Carpet". + * This demuxer handles standard 0xAF11- and 0xAF12-type FLIs. It also handles + * special FLIs from the PC games "Magic Carpet" and "X-COM: Terror from the Deep". */ #include "libavutil/intreadwrite.h" @@ -42,12 +42,16 @@ #define FLIC_CHUNK_MAGIC_2 0xF5FA #define FLIC_MC_SPEED 5 /* speed for Magic Carpet game FLIs */ #define FLIC_DEFAULT_SPEED 5 /* for FLIs that have 0 speed */ +#define FLIC_TFTD_CHUNK_AUDIO 0xAAAA /* Audio chunk. Used in Terror from the Deep. + Has 10 B extra header not accounted for in the chunk header */ +#define FLIC_TFTD_SAMPLE_RATE 22050 #define FLIC_HEADER_SIZE 128 #define FLIC_PREAMBLE_SIZE 6 typedef struct FlicDemuxContext { int video_stream_index; + int audio_stream_index; int frame_number; } FlicDemuxContext; @@ -83,9 +87,10 @@ static int flic_read_header(AVFormatContext *s, FlicDemuxContext *flic = s->priv_data; ByteIOContext *pb = s->pb; unsigned char header[FLIC_HEADER_SIZE]; - AVStream *st; + AVStream *st, *ast; int speed; int magic_number; + unsigned char preamble[FLIC_PREAMBLE_SIZE]; flic->frame_number = 0; @@ -103,7 +108,7 @@ static int flic_read_header(AVFormatContext *s, if (!st) return AVERROR(ENOMEM); flic->video_stream_index = st->index; - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_FLIC; st->codec->codec_tag = 0; /* no fourcc */ st->codec->width = AV_RL16(&header[0x08]); @@ -123,11 +128,47 @@ static int flic_read_header(AVFormatContext *s, st->codec->extradata = av_malloc(FLIC_HEADER_SIZE); memcpy(st->codec->extradata, header, FLIC_HEADER_SIZE); - /* Time to figure out the framerate: If there is a FLIC chunk magic - * number at offset 0x10, assume this is from the Bullfrog game, - * Magic Carpet. */ - if (AV_RL16(&header[0x10]) == FLIC_CHUNK_MAGIC_1) { + /* peek at the preamble to detect TFTD videos - they seem to always start with an audio chunk */ + if (get_buffer(pb, preamble, FLIC_PREAMBLE_SIZE) != FLIC_PREAMBLE_SIZE) { + av_log(s, AV_LOG_ERROR, "Failed to peek at preamble\n"); + return AVERROR(EIO); + } + url_fseek(pb, -FLIC_PREAMBLE_SIZE, SEEK_CUR); + + /* Time to figure out the framerate: + * If the first preamble's magic number is 0xAAAA then this file is from + * X-COM: Terror from the Deep. If on the other hand there is a FLIC chunk + * magic number at offset 0x10 assume this file is from Magic Carpet instead. + * If neither of the above is true then this is a normal FLIC file. + */ + 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); + if (!ast) + return AVERROR(ENOMEM); + + flic->audio_stream_index = ast->index; + + /* all audio frames are the same size, so use the size of the first chunk for block_align */ + ast->codec->block_align = AV_RL32(&preamble[0]); + ast->codec->codec_type = CODEC_TYPE_AUDIO; + ast->codec->codec_id = CODEC_ID_PCM_U8; + ast->codec->codec_tag = 0; + ast->codec->sample_rate = FLIC_TFTD_SAMPLE_RATE; + ast->codec->channels = 1; + ast->codec->sample_fmt = SAMPLE_FMT_U8; + ast->codec->bit_rate = st->codec->sample_rate * 8; + ast->codec->bits_per_coded_sample = 8; + ast->codec->channel_layout = CH_LAYOUT_MONO; + ast->codec->extradata_size = 0; + + /* Since the header information is incorrect we have to figure out the + * framerate using block_align and the fact that the audio is 22050 Hz. + * We usually have two cases: 2205 -> 10 fps and 1470 -> 15 fps */ + av_set_pts_info(st, 64, ast->codec->block_align, FLIC_TFTD_SAMPLE_RATE); + av_set_pts_info(ast, 64, 1, FLIC_TFTD_SAMPLE_RATE); + } else if (AV_RL16(&header[0x10]) == FLIC_CHUNK_MAGIC_1) { av_set_pts_info(st, 64, FLIC_MC_SPEED, 70); /* rewind the stream since the first chunk is at offset 12 */ @@ -189,6 +230,25 @@ static int flic_read_packet(AVFormatContext *s, av_free_packet(pkt); ret = AVERROR(EIO); } + packet_read = 1; + } else if (magic == FLIC_TFTD_CHUNK_AUDIO) { + if (av_new_packet(pkt, size)) { + ret = AVERROR(EIO); + break; + } + + /* skip useless 10B sub-header (yes, it's not accounted for in the chunk header) */ + url_fseek(pb, 10, SEEK_CUR); + + pkt->stream_index = flic->audio_stream_index; + pkt->pos = url_ftell(pb); + ret = get_buffer(pb, pkt->data, size); + + if (ret != size) { + av_free_packet(pkt); + ret = AVERROR(EIO); + } + packet_read = 1; } else { /* not interested in this chunk */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/flv.h b/src/add-ons/media/plugins/ffmpeg/libavformat/flv.h index 3e7a9a5991..55266a16e3 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/flv.h +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/flv.h @@ -1,5 +1,5 @@ /** - * @file libavformat/flv.h + * @file * FLV common header * * Copyright (c) 2006 The FFmpeg Project diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/flvdec.c b/src/add-ons/media/plugins/ffmpeg/libavformat/flvdec.c index a34041e748..fcdf2143af 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/flvdec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/flvdec.c @@ -39,44 +39,18 @@ static int flv_probe(AVProbeData *p) const uint8_t *d; d = p->buf; - if (d[0] == 'F' && d[1] == 'L' && d[2] == 'V' && d[3] < 5 && d[5]==0) { + if (d[0] == 'F' && d[1] == 'L' && d[2] == 'V' && d[3] < 5 && d[5]==0 && AV_RB32(d+5)>8) { return AVPROBE_SCORE_MAX; } return 0; } -/** - * Builds a Speex header. - * This is not needed for the libavcodec libspeex decoder, but is needed for - * stream copy and for decoders which require a header. - */ -static void flv_build_speex_header(uint8_t *extradata) -{ - memset(extradata, 0, 80); - bytestream_put_buffer(&extradata, "Speex ", 8); // speex_string - bytestream_put_buffer(&extradata, "1.2rc1", 6); // speex_version - extradata += 14; // speex_version padding - bytestream_put_le32(&extradata, 1); // speex_version_id - bytestream_put_le32(&extradata, 80); // header_size - bytestream_put_le32(&extradata, 16000); // rate - bytestream_put_le32(&extradata, 1); // mode - bytestream_put_le32(&extradata, 4); // mode_bitstream_version - bytestream_put_le32(&extradata, 1); // nb_channels - bytestream_put_le32(&extradata, -1); // bitrate - bytestream_put_le32(&extradata, 320); // frame_size - // vbr = 0 - // frames_per_packet = 0 - // extra_headers = 0 - // reserved1 = 0 - // reserved2 = 0 -} - static void flv_set_audio_codec(AVFormatContext *s, AVStream *astream, int flv_codecid) { AVCodecContext *acodec = astream->codec; switch(flv_codecid) { //no distinction between S16 and S8 PCM codec flags case FLV_CODECID_PCM: - acodec->codec_id = acodec->bits_per_coded_sample == 8 ? CODEC_ID_PCM_S8 : + acodec->codec_id = acodec->bits_per_coded_sample == 8 ? CODEC_ID_PCM_U8 : #if HAVE_BIGENDIAN CODEC_ID_PCM_S16BE; #else @@ -84,19 +58,12 @@ static void flv_set_audio_codec(AVFormatContext *s, AVStream *astream, int flv_c #endif break; case FLV_CODECID_PCM_LE: - acodec->codec_id = acodec->bits_per_coded_sample == 8 ? CODEC_ID_PCM_S8 : CODEC_ID_PCM_S16LE; break; + acodec->codec_id = acodec->bits_per_coded_sample == 8 ? CODEC_ID_PCM_U8 : CODEC_ID_PCM_S16LE; break; case FLV_CODECID_AAC : acodec->codec_id = CODEC_ID_AAC; break; case FLV_CODECID_ADPCM: acodec->codec_id = CODEC_ID_ADPCM_SWF; break; case FLV_CODECID_SPEEX: acodec->codec_id = CODEC_ID_SPEEX; acodec->sample_rate = 16000; - acodec->extradata = av_mallocz(80 + FF_INPUT_BUFFER_PADDING_SIZE); - if (acodec->extradata) { - acodec->extradata_size = 80; - flv_build_speex_header(acodec->extradata); - } else { - av_log(s, AV_LOG_WARNING, "Unable to create Speex extradata\n"); - } break; case FLV_CODECID_MP3 : acodec->codec_id = CODEC_ID_MP3 ; astream->need_parsing = AVSTREAM_PARSE_FULL; break; case FLV_CODECID_NELLYMOSER_8KHZ_MONO: @@ -115,6 +82,7 @@ static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream, int flv_co switch(flv_codecid) { case FLV_CODECID_H263 : vcodec->codec_id = CODEC_ID_FLV1 ; break; 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 ; case FLV_CODECID_VP6A : if(flv_codecid == FLV_CODECID_VP6A) @@ -220,15 +188,17 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream, AVStream *vst if(amf_type == AMF_DATA_TYPE_BOOL) { av_strlcpy(str_val, num_val > 0 ? "true" : "false", sizeof(str_val)); - av_metadata_set(&s->metadata, key, str_val); + av_metadata_set2(&s->metadata, key, str_val, 0); } else if(amf_type == AMF_DATA_TYPE_NUMBER) { snprintf(str_val, sizeof(str_val), "%.f", num_val); - av_metadata_set(&s->metadata, key, str_val); + av_metadata_set2(&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_STRING) - av_metadata_set(&s->metadata, key, str_val); + av_metadata_set2(&s->metadata, key, str_val, 0); } return 0; @@ -253,8 +223,8 @@ 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 == CODEC_TYPE_AUDIO) astream = stream; - else if(stream->codec->codec_type == CODEC_TYPE_VIDEO) vstream = stream; + if (stream->codec->codec_type == AVMEDIA_TYPE_AUDIO) astream = stream; + else if(stream->codec->codec_type == AVMEDIA_TYPE_VIDEO) vstream = stream; } //parse the second object (we want a mixed array) @@ -268,7 +238,7 @@ static AVStream *create_stream(AVFormatContext *s, int is_audio){ AVStream *st = av_new_stream(s, is_audio); if (!st) return NULL; - st->codec->codec_type = is_audio ? CODEC_TYPE_AUDIO : CODEC_TYPE_VIDEO; + st->codec->codec_type = is_audio ? AVMEDIA_TYPE_AUDIO : AVMEDIA_TYPE_VIDEO; av_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */ return st; } @@ -302,6 +272,7 @@ static int flv_read_header(AVFormatContext *s, offset = get_be32(s->pb); url_fseek(s->pb, offset, SEEK_SET); + url_fskip(s->pb, 4); s->start_time = 0; @@ -327,9 +298,8 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) int64_t dts, pts = AV_NOPTS_VALUE; AVStream *st = NULL; - for(;;){ + for(;;url_fskip(s->pb, 4)){ /* pkt size is repeated at end. skip it */ pos = url_ftell(s->pb); - url_fskip(s->pb, 4); /* size of previous packet */ type = get_byte(s->pb); size = get_be24(s->pb); dts = get_be24(s->pb); @@ -394,7 +364,7 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) } // if not streamed and no duration from metadata then seek to end to find the duration from the timestamps - if(!url_is_streamed(s->pb) && s->duration==AV_NOPTS_VALUE){ + if(!url_is_streamed(s->pb) && (!s->duration || s->duration==AV_NOPTS_VALUE)){ int size; const int64_t pos= url_ftell(s->pb); const int64_t fsize= url_fsize(s->pb); @@ -402,7 +372,9 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) size= get_be32(s->pb); url_fseek(s->pb, fsize-3-size, SEEK_SET); if(size == get_be24(s->pb) + 11){ - s->duration= get_be24(s->pb) * (int64_t)AV_TIME_BASE / 1000; + uint32_t ts = get_be24(s->pb); + ts |= get_byte(s->pb) << 24; + s->duration = ts * (int64_t)AV_TIME_BASE / 1000; } url_fseek(s->pb, pos, SEEK_SET); } @@ -441,21 +413,22 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) MPEG4AudioConfig cfg; ff_mpeg4audio_get_config(&cfg, st->codec->extradata, st->codec->extradata_size); - if (cfg.chan_config > 7) - return -1; - st->codec->channels = ff_mpeg4audio_channels[cfg.chan_config]; + st->codec->channels = cfg.channels; st->codec->sample_rate = cfg.sample_rate; dprintf(s, "mp4a config channels %d sample rate %d\n", st->codec->channels, st->codec->sample_rate); } - return AVERROR(EAGAIN); + ret = AVERROR(EAGAIN); + goto leave; } } /* skip empty data packets */ - if (!size) - return AVERROR(EAGAIN); + if (!size) { + ret = AVERROR(EAGAIN); + goto leave; + } ret= av_get_packet(s->pb, pkt, size); if (ret < 0) { @@ -469,11 +442,46 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) pkt->stream_index = st->index; if (is_audio || ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY)) - pkt->flags |= PKT_FLAG_KEY; + pkt->flags |= AV_PKT_FLAG_KEY; +leave: + url_fskip(s->pb, 4); return ret; } +static int flv_read_seek(AVFormatContext *s, int stream_index, + int64_t ts, int flags) +{ + return av_url_read_fseek(s->pb, stream_index, ts, flags); +} + +#if 0 /* don't know enough to implement this */ +static int flv_read_seek2(AVFormatContext *s, int stream_index, + int64_t min_ts, int64_t ts, int64_t max_ts, int flags) +{ + int ret = AVERROR(ENOSYS); + + if (ts - min_ts > (uint64_t)(max_ts - ts)) flags |= AVSEEK_FLAG_BACKWARD; + + if (url_is_streamed(s->pb)) { + if (stream_index < 0) { + stream_index = av_find_default_stream_index(s); + if (stream_index < 0) + return -1; + + /* timestamp for default must be expressed in AV_TIME_BASE units */ + ts = av_rescale_rnd(ts, 1000, AV_TIME_BASE, + flags & AVSEEK_FLAG_BACKWARD ? AV_ROUND_DOWN : AV_ROUND_UP); + } + ret = av_url_read_fseek(s->pb, stream_index, ts, flags); + } + + if (ret == AVERROR(ENOSYS)) + ret = av_seek_frame(s, stream_index, ts, flags); + return ret; +} +#endif + AVInputFormat flv_demuxer = { "flv", NULL_IF_CONFIG_SMALL("FLV format"), @@ -481,6 +489,10 @@ AVInputFormat flv_demuxer = { flv_probe, flv_read_header, flv_read_packet, + .read_seek = flv_read_seek, +#if 0 + .read_seek2 = flv_read_seek2, +#endif .extensions = "flv", .value = CODEC_ID_FLV1, }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/flvenc.c b/src/add-ons/media/plugins/ffmpeg/libavformat/flvenc.c index 3ca1874cf1..c351117132 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/flvenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/flvenc.c @@ -29,6 +29,7 @@ static const AVCodecTag flv_video_codec_ids[] = { {CODEC_ID_FLV1, FLV_CODECID_H263 }, {CODEC_ID_FLASHSV, FLV_CODECID_SCREEN}, + {CODEC_ID_FLASHSV2, FLV_CODECID_SCREEN2}, {CODEC_ID_VP6F, FLV_CODECID_VP6 }, {CODEC_ID_VP6, FLV_CODECID_VP6 }, {CODEC_ID_H264, FLV_CODECID_H264 }, @@ -37,12 +38,13 @@ static const AVCodecTag flv_video_codec_ids[] = { static const AVCodecTag flv_audio_codec_ids[] = { {CODEC_ID_MP3, FLV_CODECID_MP3 >> FLV_AUDIO_CODECID_OFFSET}, - {CODEC_ID_PCM_S8, FLV_CODECID_PCM >> FLV_AUDIO_CODECID_OFFSET}, + {CODEC_ID_PCM_U8, FLV_CODECID_PCM >> FLV_AUDIO_CODECID_OFFSET}, {CODEC_ID_PCM_S16BE, FLV_CODECID_PCM >> FLV_AUDIO_CODECID_OFFSET}, {CODEC_ID_PCM_S16LE, FLV_CODECID_PCM_LE >> FLV_AUDIO_CODECID_OFFSET}, {CODEC_ID_ADPCM_SWF, FLV_CODECID_ADPCM >> FLV_AUDIO_CODECID_OFFSET}, {CODEC_ID_AAC, FLV_CODECID_AAC >> FLV_AUDIO_CODECID_OFFSET}, {CODEC_ID_NELLYMOSER, FLV_CODECID_NELLYMOSER >> FLV_AUDIO_CODECID_OFFSET}, + {CODEC_ID_SPEEX, FLV_CODECID_SPEEX >> FLV_AUDIO_CODECID_OFFSET}, {CODEC_ID_NONE, 0} }; @@ -59,7 +61,22 @@ static int get_audio_flags(AVCodecContext *enc){ if (enc->codec_id == CODEC_ID_AAC) // specs force these parameters return FLV_CODECID_AAC | FLV_SAMPLERATE_44100HZ | FLV_SAMPLESSIZE_16BIT | FLV_STEREO; - else { + else if (enc->codec_id == CODEC_ID_SPEEX) { + if (enc->sample_rate != 16000) { + av_log(enc, AV_LOG_ERROR, "flv only supports wideband (16kHz) Speex audio\n"); + return -1; + } + if (enc->channels != 1) { + 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) { case 44100: flags |= FLV_SAMPLERATE_44100HZ; @@ -90,7 +107,7 @@ static int get_audio_flags(AVCodecContext *enc){ case CODEC_ID_MP3: flags |= FLV_CODECID_MP3 | FLV_SAMPLESSIZE_16BIT; break; - case CODEC_ID_PCM_S8: + case CODEC_ID_PCM_U8: flags |= FLV_CODECID_PCM | FLV_SAMPLESSIZE_8BIT; break; case CODEC_ID_PCM_S16BE: @@ -149,7 +166,7 @@ static int flv_write_header(AVFormatContext *s) for(i=0; inb_streams; i++){ AVCodecContext *enc = s->streams[i]->codec; - if (enc->codec_type == CODEC_TYPE_VIDEO) { + 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); } else { @@ -204,7 +221,7 @@ static int flv_write_header(AVFormatContext *s) put_amf_string(pb, "duration"); flv->duration_offset= url_ftell(pb); - put_amf_double(pb, 0); // delayed write + put_amf_double(pb, s->duration / AV_TIME_BASE); // fill in the guessed duration, it'll be corrected later if incorrect if(video_enc){ put_amf_string(pb, "width"); @@ -231,7 +248,7 @@ static int flv_write_header(AVFormatContext *s) put_amf_double(pb, audio_enc->sample_rate); put_amf_string(pb, "audiosamplesize"); - put_amf_double(pb, audio_enc->codec_id == CODEC_ID_PCM_S8 ? 8 : 16); + put_amf_double(pb, audio_enc->codec_id == CODEC_ID_PCM_U8 ? 8 : 16); put_amf_string(pb, "stereo"); put_amf_bool(pb, audio_enc->channels == 2); @@ -258,7 +275,7 @@ static int flv_write_header(AVFormatContext *s) AVCodecContext *enc = s->streams[i]->codec; if (enc->codec_id == CODEC_ID_AAC || enc->codec_id == CODEC_ID_H264) { int64_t pos; - put_byte(pb, enc->codec_type == CODEC_TYPE_VIDEO ? + put_byte(pb, enc->codec_type == AVMEDIA_TYPE_VIDEO ? FLV_TAG_TYPE_VIDEO : FLV_TAG_TYPE_AUDIO); put_be24(pb, 0); // size patched later put_be24(pb, 0); // ts @@ -325,7 +342,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) else flags_size= 1; - if (enc->codec_type == CODEC_TYPE_VIDEO) { + if (enc->codec_type == AVMEDIA_TYPE_VIDEO) { put_byte(pb, FLV_TAG_TYPE_VIDEO); flags = enc->codec_tag; @@ -334,9 +351,9 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) return -1; } - flags |= pkt->flags & PKT_FLAG_KEY ? FLV_FRAME_KEY : FLV_FRAME_INTER; + flags |= pkt->flags & AV_PKT_FLAG_KEY ? FLV_FRAME_KEY : FLV_FRAME_INTER; } else { - assert(enc->codec_type == CODEC_TYPE_AUDIO); + assert(enc->codec_type == AVMEDIA_TYPE_AUDIO); flags = get_audio_flags(enc); assert(size); @@ -399,5 +416,5 @@ AVOutputFormat flv_muxer = { flv_write_packet, flv_write_trailer, .codec_tag= (const AVCodecTag* const []){flv_video_codec_ids, flv_audio_codec_ids, 0}, - .flags= AVFMT_GLOBALHEADER, + .flags= AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS, }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/gif.c b/src/add-ons/media/plugins/ffmpeg/libavformat/gif.c index 2b802a9dca..4741915bac 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/gif.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/gif.c @@ -266,7 +266,7 @@ static int gif_write_header(AVFormatContext *s) video_enc = NULL; for(i=0;inb_streams;i++) { enc = s->streams[i]->codec; - if (enc->codec_type != CODEC_TYPE_AUDIO) + if (enc->codec_type != AVMEDIA_TYPE_AUDIO) video_enc = enc; } @@ -329,7 +329,7 @@ static int gif_write_video(AVFormatContext *s, static int gif_write_packet(AVFormatContext *s, AVPacket *pkt) { AVCodecContext *codec = s->streams[pkt->stream_index]->codec; - if (codec->codec_type == CODEC_TYPE_AUDIO) + if (codec->codec_type == AVMEDIA_TYPE_AUDIO) return 0; /* just ignore audio */ else return gif_write_video(s, codec, pkt->data, pkt->size); diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/gopher.c b/src/add-ons/media/plugins/ffmpeg/libavformat/gopher.c index abd1cc394a..f5bb4a3718 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/gopher.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/gopher.c @@ -24,6 +24,7 @@ #include "libavutil/avstring.h" #include "avformat.h" +#include "internal.h" #include "network.h" typedef struct { @@ -89,13 +90,13 @@ static int gopher_open(URLContext *h, const char *uri, int flags) h->priv_data = s; /* needed in any case to build the host string */ - url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port, - path, sizeof(path), uri); + ff_url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port, + path, sizeof(path), uri); if (port < 0) port = 70; - snprintf(buf, sizeof(buf), "tcp://%s:%d", hostname, port); + ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL); s->hd = NULL; err = url_open(&s->hd, buf, URL_RDWR); diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/gxf.c b/src/add-ons/media/plugins/ffmpeg/libavformat/gxf.c index d7aaabf161..ea8a2fff7f 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/gxf.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/gxf.c @@ -87,34 +87,34 @@ static int get_sindex(AVFormatContext *s, int id, int format) { switch (format) { case 3: case 4: - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_MJPEG; break; case 13: case 15: - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_DVVIDEO; break; case 14: case 16: - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_DVVIDEO; break; case 11: case 12: case 20: - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_MPEG2VIDEO; st->need_parsing = AVSTREAM_PARSE_HEADERS; //get keyframe flag etc. break; case 22: case 23: - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_MPEG1VIDEO; st->need_parsing = AVSTREAM_PARSE_HEADERS; //get keyframe flag etc. break; case 9: - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_PCM_S24LE; st->codec->channels = 1; st->codec->sample_rate = 48000; @@ -123,7 +123,7 @@ static int get_sindex(AVFormatContext *s, int id, int format) { st->codec->bits_per_coded_sample = 24; break; case 10: - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_PCM_S16LE; st->codec->channels = 1; st->codec->sample_rate = 48000; @@ -132,7 +132,7 @@ static int get_sindex(AVFormatContext *s, int id, int format) { st->codec->bits_per_coded_sample = 16; break; case 17: - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_AC3; st->codec->channels = 2; st->codec->sample_rate = 48000; @@ -141,11 +141,11 @@ static int get_sindex(AVFormatContext *s, int id, int format) { case 7: case 8: case 24: - st->codec->codec_type = CODEC_TYPE_DATA; + st->codec->codec_type = AVMEDIA_TYPE_DATA; st->codec->codec_id = CODEC_ID_NONE; break; default: - st->codec->codec_type = CODEC_TYPE_UNKNOWN; + st->codec->codec_type = AVMEDIA_TYPE_UNKNOWN; st->codec->codec_id = CODEC_ID_NONE; break; } @@ -313,7 +313,7 @@ static int gxf_header(AVFormatContext *s, AVFormatParameters *ap) { 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 * si.fields_per_frame; + 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) @@ -344,15 +344,17 @@ static int gxf_header(AVFormatContext *s, AVFormatParameters *ap) { if (!main_timebase.num || !main_timebase.den) { // this may not always be correct, but simply the best we can get main_timebase.num = fps.den; - main_timebase.den = fps.num; + main_timebase.den = fps.num * 2; } } else av_log(s, AV_LOG_INFO, "UMF packet too short\n"); } else av_log(s, AV_LOG_INFO, "UMF packet missing\n"); url_fskip(pb, len); + // set a fallback value, 60000/1001 is specified for audio-only files + // so use that regardless of why we do not know the video frame rate. if (!main_timebase.num || !main_timebase.den) - main_timebase = (AVRational){1, 50}; // set some arbitrary fallback + main_timebase = (AVRational){1001, 60000}; for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; av_set_pts_info(st, 32, main_timebase.num, main_timebase.den); diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/gxfenc.c b/src/add-ons/media/plugins/ffmpeg/libavformat/gxfenc.c index 501691e78d..a6f4b7260e 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/gxfenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/gxfenc.c @@ -93,7 +93,7 @@ static const AVCodecTag gxf_media_types[] = { { CODEC_ID_MPEG2VIDEO, 20 }, /* MPEG HD */ { CODEC_ID_MPEG1VIDEO, 22 }, /* NTSC */ { CODEC_ID_MPEG1VIDEO, 23 }, /* PAL */ - { 0, 0 }, + { CODEC_ID_NONE, 0 }, }; #define SERVER_PATH "EXT:/PDR/default/" @@ -644,7 +644,7 @@ static int gxf_write_header(AVFormatContext *s) st->priv_data = sc; sc->media_type = ff_codec_get_tag(gxf_media_types, st->codec->codec_id); - if (st->codec->codec_type == CODEC_TYPE_AUDIO) { + if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { if (st->codec->codec_id != CODEC_ID_PCM_S16LE) { av_log(s, AV_LOG_ERROR, "only 16 BIT PCM LE allowed for now\n"); return -1; @@ -667,7 +667,7 @@ static int gxf_write_header(AVFormatContext *s) gxf->audio_tracks++; gxf->flags |= 0x04000000; /* audio is 16 bit pcm */ media_info = 'A'; - } else if (st->codec->codec_type == CODEC_TYPE_VIDEO) { + } else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { if (i != 0) { av_log(s, AV_LOG_ERROR, "video stream must be the first track\n"); return -1; @@ -811,7 +811,7 @@ static int gxf_write_media_preamble(AVFormatContext *s, AVPacket *pkt, int size) /* If the video is frame-encoded, the frame numbers shall be represented by * even field numbers. * see SMPTE360M-2004 6.4.2.1.3 Media field number */ - if (st->codec->codec_type == CODEC_TYPE_VIDEO) { + if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { field_nb = gxf->nb_fields; } else { field_nb = av_rescale_rnd(pkt->dts, gxf->time_base.den, @@ -821,7 +821,7 @@ static int gxf_write_media_preamble(AVFormatContext *s, AVPacket *pkt, int size) put_byte(pb, sc->media_type); put_byte(pb, st->index); put_be32(pb, field_nb); - if (st->codec->codec_type == CODEC_TYPE_AUDIO) { + if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { put_be16(pb, 0); put_be16(pb, size / 2); } else if (st->codec->codec_id == CODEC_ID_MPEG2VIDEO) { @@ -859,13 +859,13 @@ static int gxf_write_packet(AVFormatContext *s, AVPacket *pkt) gxf_write_packet_header(pb, PKT_MEDIA); if (st->codec->codec_id == CODEC_ID_MPEG2VIDEO && pkt->size % 4) /* MPEG-2 frames must be padded */ padding = 4 - pkt->size % 4; - else if (st->codec->codec_type == CODEC_TYPE_AUDIO) + else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) padding = GXF_AUDIO_PACKET_SIZE - pkt->size; gxf_write_media_preamble(s, pkt, pkt->size + padding); put_buffer(pb, pkt->data, pkt->size); gxf_write_padding(pb, padding); - if (st->codec->codec_type == CODEC_TYPE_VIDEO) { + 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)); @@ -901,7 +901,7 @@ static int gxf_compare_field_nb(AVFormatContext *s, AVPacket *next, AVPacket *cu for (i = 0; i < 2; i++) { AVStream *st = s->streams[pkt[i]->stream_index]; sc[i] = st->priv_data; - if (st->codec->codec_type == CODEC_TYPE_AUDIO) { + if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { field_nb[i] = av_rescale_rnd(pkt[i]->dts, gxf->time_base.den, (int64_t)48000*gxf->time_base.num, AV_ROUND_UP); field_nb[i] &= ~1; // compare against even field number because audio must be before video @@ -915,7 +915,7 @@ static int gxf_compare_field_nb(AVFormatContext *s, AVPacket *next, AVPacket *cu static int gxf_interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush) { - if (pkt && s->streams[pkt->stream_index]->codec->codec_type == CODEC_TYPE_VIDEO) + if (pkt && s->streams[pkt->stream_index]->codec->codec_type == AVMEDIA_TYPE_VIDEO) pkt->duration = 2; // enforce 2 fields return ff_audio_rechunk_interleave(s, out, pkt, flush, av_interleave_packet_per_dts, gxf_compare_field_nb); diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/http.c b/src/add-ons/media/plugins/ffmpeg/libavformat/http.c index 35eb89a1e5..e697578486 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/http.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/http.c @@ -19,13 +19,14 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libavutil/base64.h" #include "libavutil/avstring.h" #include "avformat.h" #include #include +#include "internal.h" #include "network.h" #include "os_support.h" +#include "httpauth.h" /* XXX: POST protocol is not completely implemented because ffmpeg uses only a subset of it. */ @@ -43,6 +44,7 @@ typedef struct { int64_t chunksize; /**< Used if "Transfer-Encoding: chunked" otherwise -1. */ int64_t off, filesize; char location[URL_SIZE]; + HTTPAuthState auth_state; } HTTPContext; static int http_connect(URLContext *h, const char *path, const char *hoststr, @@ -59,6 +61,7 @@ static int http_open_cnx(URLContext *h) char path1[1024]; char buf[1024]; int port, use_proxy, err, location_changed = 0, redirects = 0; + HTTPAuthType cur_auth_type; HTTPContext *s = h->priv_data; URLContext *hd = NULL; @@ -69,17 +72,13 @@ static int http_open_cnx(URLContext *h) /* fill the dest addr */ redo: /* needed in any case to build the host string */ - url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port, - path1, sizeof(path1), s->location); - if (port > 0) { - snprintf(hoststr, sizeof(hoststr), "%s:%d", hostname, port); - } else { - av_strlcpy(hoststr, hostname, sizeof(hoststr)); - } + ff_url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port, + path1, sizeof(path1), s->location); + ff_url_join(hoststr, sizeof(hoststr), NULL, NULL, hostname, port, NULL); if (use_proxy) { - url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port, - NULL, 0, proxy_path); + ff_url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port, + NULL, 0, proxy_path); path = s->location; } else { if (path1[0] == '\0') @@ -90,14 +89,22 @@ static int http_open_cnx(URLContext *h) if (port < 0) port = 80; - snprintf(buf, sizeof(buf), "tcp://%s:%d", hostname, port); + ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL); err = url_open(&hd, buf, URL_RDWR); if (err < 0) goto fail; s->hd = hd; + cur_auth_type = s->auth_state.auth_type; if (http_connect(h, path, hoststr, auth, &location_changed) < 0) goto fail; + if (s->http_code == 401) { + if (cur_auth_type == HTTP_AUTH_NONE && s->auth_state.auth_type != HTTP_AUTH_NONE) { + url_close(hd); + goto redo; + } else + goto fail; + } if ((s->http_code == 302 || s->http_code == 303) && location_changed == 1) { /* url moved, get next */ url_close(hd); @@ -128,6 +135,7 @@ static int http_open(URLContext *h, const char *uri, int flags) s->filesize = -1; s->chunksize = -1; s->off = 0; + memset(&s->auth_state, 0, sizeof(s->auth_state)); av_strlcpy(s->location, uri, URL_SIZE); ret = http_open_cnx(h); @@ -196,8 +204,9 @@ static int process_line(URLContext *h, char *line, int line_count, dprintf(NULL, "http_code=%d\n", s->http_code); - /* error codes are 4xx and 5xx */ - if (s->http_code >= 400 && s->http_code < 600) + /* error codes are 4xx and 5xx, but regard 401 as a success, so we + * don't abort until all headers have been parsed. */ + if (s->http_code >= 400 && s->http_code < 600 && s->http_code != 401) return -1; } else { while (*p != '\0' && *p != ':') @@ -228,6 +237,10 @@ static int process_line(URLContext *h, char *line, int line_count, } else if (!strcmp (tag, "Transfer-Encoding") && !strncasecmp(p, "chunked", 7)) { s->filesize = -1; s->chunksize = 0; + } else if (!strcmp (tag, "WWW-Authenticate")) { + ff_http_auth_handle_header(&s->auth_state, tag, p); + } else if (!strcmp (tag, "Authentication-Info")) { + ff_http_auth_handle_header(&s->auth_state, tag, p); } } return 1; @@ -239,32 +252,33 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr, HTTPContext *s = h->priv_data; int post, err; char line[1024]; - char *auth_b64; - int auth_b64_len = (strlen(auth) + 2) / 3 * 4 + 1; + char *authstr = NULL; int64_t off = s->off; /* send http header */ post = h->flags & URL_WRONLY; - auth_b64 = av_malloc(auth_b64_len); - av_base64_encode(auth_b64, auth_b64_len, auth, strlen(auth)); + authstr = ff_http_auth_create_response(&s->auth_state, auth, path, + post ? "POST" : "GET"); snprintf(s->buffer, sizeof(s->buffer), "%s %s HTTP/1.1\r\n" "User-Agent: %s\r\n" "Accept: */*\r\n" "Range: bytes=%"PRId64"-\r\n" "Host: %s\r\n" - "Authorization: Basic %s\r\n" + "%s" "Connection: close\r\n" + "%s" "\r\n", post ? "POST" : "GET", path, LIBAVFORMAT_IDENT, s->off, hoststr, - auth_b64); + authstr ? authstr : "", + post ? "Transfer-Encoding: chunked\r\n" : ""); - av_freep(&auth_b64); + av_freep(&authstr); if (http_write(h, s->buffer, strlen(s->buffer)) < 0) return AVERROR(EIO); @@ -275,6 +289,8 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr, s->off = 0; s->filesize = -1; if (post) { + /* always use chunked encoding for upload data */ + s->chunksize = 0; return 0; } @@ -344,16 +360,45 @@ static int http_read(URLContext *h, uint8_t *buf, int size) /* used only when posting data */ static int http_write(URLContext *h, uint8_t *buf, int size) { + char temp[11]; /* 32-bit hex + CRLF + nul */ + int ret; + char crlf[] = "\r\n"; HTTPContext *s = h->priv_data; - return url_write(s->hd, buf, size); + + if (s->chunksize == -1) { + /* headers are sent without any special encoding */ + return url_write(s->hd, buf, size); + } + + /* silently ignore zero-size data since chunk encoding that would + * signal EOF */ + if (size > 0) { + /* upload data using chunked encoding */ + snprintf(temp, sizeof(temp), "%x\r\n", size); + + if ((ret = url_write(s->hd, temp, strlen(temp))) < 0 || + (ret = url_write(s->hd, buf, size)) < 0 || + (ret = url_write(s->hd, crlf, sizeof(crlf) - 1)) < 0) + return ret; + } + return size; } static int http_close(URLContext *h) { + int ret = 0; + char footer[] = "0\r\n\r\n"; HTTPContext *s = h->priv_data; + + /* signal end of chunked encoding if used */ + if ((h->flags & URL_WRONLY) && s->chunksize != -1) { + ret = url_write(s->hd, footer, sizeof(footer) - 1); + ret = ret > 0 ? 0 : ret; + } + url_close(s->hd); av_free(s); - return 0; + return ret; } static int64_t http_seek(URLContext *h, int64_t off, int whence) @@ -361,6 +406,8 @@ static int64_t http_seek(URLContext *h, int64_t off, int whence) HTTPContext *s = h->priv_data; URLContext *old_hd = s->hd; int64_t old_off = s->off; + uint8_t old_buf[BUFFER_SIZE]; + int old_buf_size; if (whence == AVSEEK_SIZE) return s->filesize; @@ -368,6 +415,8 @@ static int64_t http_seek(URLContext *h, int64_t off, int whence) return -1; /* we save the old context in case the seek fails */ + old_buf_size = s->buf_end - s->buf_ptr; + memcpy(old_buf, s->buf_ptr, old_buf_size); s->hd = NULL; if (whence == SEEK_CUR) off += s->off; @@ -377,6 +426,9 @@ static int64_t http_seek(URLContext *h, int64_t off, int whence) /* if it fails, continue on old connection */ if (http_open_cnx(h) < 0) { + memcpy(s->buffer, old_buf, old_buf_size); + s->buf_ptr = s->buffer; + s->buf_end = s->buffer + old_buf_size; s->hd = old_hd; s->off = old_off; return -1; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/httpauth.c b/src/add-ons/media/plugins/ffmpeg/libavformat/httpauth.c new file mode 100644 index 0000000000..cef27569a8 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/httpauth.c @@ -0,0 +1,321 @@ +/* + * HTTP authentication + * Copyright (c) 2010 Martin Storsjo + * + * 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 "httpauth.h" +#include "libavutil/base64.h" +#include "libavutil/avstring.h" +#include "internal.h" +#include "libavutil/random_seed.h" +#include "libavutil/md5.h" +#include "avformat.h" +#include + +static void parse_key_value(const char *params, + void (*callback_get_buf)(HTTPAuthState *state, + const char *key, int key_len, + char **dest, int *dest_len), HTTPAuthState *state) +{ + const char *ptr = params; + + /* Parse key=value pairs. */ + for (;;) { + const char *key; + char *dest = NULL, *dest_end; + int key_len, dest_len = 0; + + /* Skip whitespace and potential commas. */ + while (*ptr && (isspace(*ptr) || *ptr == ',')) + ptr++; + if (!*ptr) + break; + + key = ptr; + + if (!(ptr = strchr(key, '='))) + break; + ptr++; + key_len = ptr - key; + + callback_get_buf(state, key, key_len, &dest, &dest_len); + dest_end = dest + dest_len - 1; + + if (*ptr == '\"') { + ptr++; + while (*ptr && *ptr != '\"') { + if (*ptr == '\\') { + if (!ptr[1]) + break; + if (dest && dest < dest_end) + *dest++ = ptr[1]; + ptr += 2; + } else { + if (dest && dest < dest_end) + *dest++ = *ptr; + ptr++; + } + } + if (*ptr == '\"') + ptr++; + } else { + for (; *ptr && !(isspace(*ptr) || *ptr == ','); ptr++) + if (dest && dest < dest_end) + *dest++ = *ptr; + } + if (dest) + *dest = 0; + } +} + +static void handle_basic_params(HTTPAuthState *state, const char *key, + int key_len, char **dest, int *dest_len) +{ + if (!strncmp(key, "realm=", key_len)) { + *dest = state->realm; + *dest_len = sizeof(state->realm); + } +} + +static void handle_digest_params(HTTPAuthState *state, const char *key, + int key_len, char **dest, int *dest_len) +{ + DigestParams *digest = &state->digest_params; + + if (!strncmp(key, "realm=", key_len)) { + *dest = state->realm; + *dest_len = sizeof(state->realm); + } else if (!strncmp(key, "nonce=", key_len)) { + *dest = digest->nonce; + *dest_len = sizeof(digest->nonce); + } else if (!strncmp(key, "opaque=", key_len)) { + *dest = digest->opaque; + *dest_len = sizeof(digest->opaque); + } else if (!strncmp(key, "algorithm=", key_len)) { + *dest = digest->algorithm; + *dest_len = sizeof(digest->algorithm); + } else if (!strncmp(key, "qop=", key_len)) { + *dest = digest->qop; + *dest_len = sizeof(digest->qop); + } +} + +static void handle_digest_update(HTTPAuthState *state, const char *key, + int key_len, char **dest, int *dest_len) +{ + DigestParams *digest = &state->digest_params; + + if (!strncmp(key, "nextnonce=", key_len)) { + *dest = digest->nonce; + *dest_len = sizeof(digest->nonce); + } +} + +static void choose_qop(char *qop, int size) +{ + char *ptr = strstr(qop, "auth"); + char *end = ptr + strlen("auth"); + + if (ptr && (!*end || isspace(*end) || *end == ',') && + (ptr == qop || isspace(ptr[-1]) || ptr[-1] == ',')) { + av_strlcpy(qop, "auth", size); + } else { + qop[0] = 0; + } +} + +void ff_http_auth_handle_header(HTTPAuthState *state, const char *key, + const char *value) +{ + if (!strcmp(key, "WWW-Authenticate")) { + const char *p; + if (av_stristart(value, "Basic ", &p) && + state->auth_type <= HTTP_AUTH_BASIC) { + state->auth_type = HTTP_AUTH_BASIC; + state->realm[0] = 0; + parse_key_value(p, handle_basic_params, state); + } else if (av_stristart(value, "Digest ", &p) && + state->auth_type <= HTTP_AUTH_DIGEST) { + state->auth_type = HTTP_AUTH_DIGEST; + memset(&state->digest_params, 0, sizeof(DigestParams)); + state->realm[0] = 0; + parse_key_value(p, handle_digest_params, state); + choose_qop(state->digest_params.qop, + sizeof(state->digest_params.qop)); + } + } else if (!strcmp(key, "Authentication-Info")) { + parse_key_value(value, handle_digest_update, state); + } +} + + +static void update_md5_strings(struct AVMD5 *md5ctx, ...) +{ + va_list vl; + + va_start(vl, md5ctx); + while (1) { + const char* str = va_arg(vl, const char*); + if (!str) + break; + av_md5_update(md5ctx, str, strlen(str)); + } + va_end(vl); +} + +/* Generate a digest reply, according to RFC 2617. */ +static char *make_digest_auth(HTTPAuthState *state, const char *username, + const char *password, const char *uri, + const char *method) +{ + DigestParams *digest = &state->digest_params; + int len; + uint32_t cnonce_buf[2]; + char cnonce[17]; + char nc[9]; + int i; + char A1hash[33], A2hash[33], response[33]; + struct AVMD5 *md5ctx; + uint8_t hash[16]; + char *authstr; + + digest->nc++; + snprintf(nc, sizeof(nc), "%08x", digest->nc); + + /* Generate a client nonce. */ + for (i = 0; i < 2; i++) + cnonce_buf[i] = ff_random_get_seed(); + ff_data_to_hex(cnonce, (const uint8_t*) cnonce_buf, sizeof(cnonce_buf), 1); + cnonce[2*sizeof(cnonce_buf)] = 0; + + md5ctx = av_malloc(av_md5_size); + if (!md5ctx) + return NULL; + + av_md5_init(md5ctx); + update_md5_strings(md5ctx, username, ":", state->realm, ":", password, NULL); + av_md5_final(md5ctx, hash); + ff_data_to_hex(A1hash, hash, 16, 1); + A1hash[32] = 0; + + if (!strcmp(digest->algorithm, "") || !strcmp(digest->algorithm, "MD5")) { + } else if (!strcmp(digest->algorithm, "MD5-sess")) { + av_md5_init(md5ctx); + update_md5_strings(md5ctx, A1hash, ":", digest->nonce, ":", cnonce, NULL); + av_md5_final(md5ctx, hash); + ff_data_to_hex(A1hash, hash, 16, 1); + A1hash[32] = 0; + } else { + /* Unsupported algorithm */ + av_free(md5ctx); + return NULL; + } + + av_md5_init(md5ctx); + update_md5_strings(md5ctx, method, ":", uri, NULL); + av_md5_final(md5ctx, hash); + ff_data_to_hex(A2hash, hash, 16, 1); + A2hash[32] = 0; + + av_md5_init(md5ctx); + update_md5_strings(md5ctx, A1hash, ":", digest->nonce, NULL); + if (!strcmp(digest->qop, "auth") || !strcmp(digest->qop, "auth-int")) { + update_md5_strings(md5ctx, ":", nc, ":", cnonce, ":", digest->qop, NULL); + } + update_md5_strings(md5ctx, ":", A2hash, NULL); + av_md5_final(md5ctx, hash); + ff_data_to_hex(response, hash, 16, 1); + response[32] = 0; + + av_free(md5ctx); + + if (!strcmp(digest->qop, "") || !strcmp(digest->qop, "auth")) { + } else if (!strcmp(digest->qop, "auth-int")) { + /* qop=auth-int not supported */ + return NULL; + } else { + /* Unsupported qop value. */ + return NULL; + } + + len = strlen(username) + strlen(state->realm) + strlen(digest->nonce) + + strlen(uri) + strlen(response) + strlen(digest->algorithm) + + strlen(digest->opaque) + strlen(digest->qop) + strlen(cnonce) + + strlen(nc) + 150; + + authstr = av_malloc(len); + if (!authstr) + return NULL; + snprintf(authstr, len, "Authorization: Digest "); + + /* TODO: Escape the quoted strings properly. */ + av_strlcatf(authstr, len, "username=\"%s\"", username); + av_strlcatf(authstr, len, ",realm=\"%s\"", state->realm); + av_strlcatf(authstr, len, ",nonce=\"%s\"", digest->nonce); + av_strlcatf(authstr, len, ",uri=\"%s\"", uri); + av_strlcatf(authstr, len, ",response=\"%s\"", response); + if (digest->algorithm[0]) + av_strlcatf(authstr, len, ",algorithm=%s", digest->algorithm); + if (digest->opaque[0]) + av_strlcatf(authstr, len, ",opaque=\"%s\"", digest->opaque); + if (digest->qop[0]) { + av_strlcatf(authstr, len, ",qop=\"%s\"", digest->qop); + av_strlcatf(authstr, len, ",cnonce=\"%s\"", cnonce); + av_strlcatf(authstr, len, ",nc=%s", nc); + } + + av_strlcatf(authstr, len, "\r\n"); + + return authstr; +} + +char *ff_http_auth_create_response(HTTPAuthState *state, const char *auth, + const char *path, const char *method) +{ + char *authstr = NULL; + + if (!auth || !strchr(auth, ':')) + return NULL; + + if (state->auth_type == HTTP_AUTH_BASIC) { + int auth_b64_len = (strlen(auth) + 2) / 3 * 4 + 1; + int len = auth_b64_len + 30; + char *ptr; + authstr = av_malloc(len); + if (!authstr) + return NULL; + snprintf(authstr, len, "Authorization: Basic "); + ptr = authstr + strlen(authstr); + av_base64_encode(ptr, auth_b64_len, auth, strlen(auth)); + av_strlcat(ptr, "\r\n", len); + } else if (state->auth_type == HTTP_AUTH_DIGEST) { + char *username = av_strdup(auth), *password; + + if (!username) + return NULL; + + if ((password = strchr(username, ':'))) { + *password++ = 0; + authstr = make_digest_auth(state, username, password, path, method); + } + av_free(username); + } + return authstr; +} + diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/httpauth.h b/src/add-ons/media/plugins/ffmpeg/libavformat/httpauth.h new file mode 100644 index 0000000000..ebab3fca29 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/httpauth.h @@ -0,0 +1,72 @@ +/* + * HTTP authentication + * Copyright (c) 2010 Martin Storsjo + * + * 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_HTTPAUTH_H +#define AVFORMAT_HTTPAUTH_H + +/** + * Authentication types, ordered from weakest to strongest. + */ +typedef enum HTTPAuthType { + HTTP_AUTH_NONE = 0, /**< No authentication specified */ + HTTP_AUTH_BASIC, /**< HTTP 1.0 Basic auth from RFC 1945 + * (also in RFC 2617) */ + HTTP_AUTH_DIGEST, /**< HTTP 1.1 Digest auth from RFC 2617 */ +} HTTPAuthType; + +typedef struct { + char nonce[300]; /**< Server specified nonce */ + char algorithm[10]; /**< Server specified digest algorithm */ + char qop[30]; /**< Quality of protection, containing the one + * that we've chosen to use, from the + * alternatives that the server offered. */ + char opaque[300]; /**< A server-specified string that should be + * included in authentication responses, not + * included in the actual digest calculation. */ + int nc; /**< Nonce count, the number of earlier replies + * where this particular nonce has been used. */ +} DigestParams; + +/** + * HTTP Authentication state structure. Must be zero-initialized + * before used with the functions below. + */ +typedef struct { + /** + * The currently chosen auth type. + */ + HTTPAuthType auth_type; + /** + * Authentication realm + */ + char realm[200]; + /** + * The parameters specifiec to digest authentication. + */ + DigestParams digest_params; +} HTTPAuthState; + +void ff_http_auth_handle_header(HTTPAuthState *state, const char *key, + const char *value); +char *ff_http_auth_create_response(HTTPAuthState *state, const char *auth, + const char *path, const char *method); + +#endif /* AVFORMAT_HTTPAUTH_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/id3v1.c b/src/add-ons/media/plugins/ffmpeg/libavformat/id3v1.c index 7281974182..c72fca49cb 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/id3v1.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/id3v1.c @@ -21,8 +21,9 @@ #include "id3v1.h" #include "libavcodec/avcodec.h" +#include "libavutil/avstring.h" -const char *ff_id3v1_genre_str[ID3v1_GENRE_MAX + 1] = { +const char * const ff_id3v1_genre_str[ID3v1_GENRE_MAX + 1] = { [0] = "Blues", [1] = "Classic Rock", [2] = "Country", @@ -149,6 +150,28 @@ const char *ff_id3v1_genre_str[ID3v1_GENRE_MAX + 1] = { [123] = "A capella", [124] = "Euro-House", [125] = "Dance Hall", + [126] = "Goa", + [127] = "Drum & Bass", + [128] = "Club-House", + [129] = "Hardcore", + [130] = "Terror", + [131] = "Indie", + [132] = "BritPop", + [133] = "Negerpunk", + [134] = "Polsk Punk", + [135] = "Beat", + [136] = "Christian Gangsta", + [137] = "Heavy Metal", + [138] = "Black Metal", + [139] = "Crossover", + [140] = "Contemporary Christian", + [141] = "Christian Rock", + [142] = "Merengue", + [143] = "Salsa", + [144] = "Thrash Metal", + [145] = "Anime", + [146] = "JPop", + [147] = "SynthPop", }; static void get_string(AVFormatContext *s, const char *key, @@ -169,7 +192,7 @@ static void get_string(AVFormatContext *s, const char *key, *q = '\0'; if (*str) - av_metadata_set(&s->metadata, key, str); + av_metadata_set2(&s->metadata, key, str, 0); } /** @@ -179,7 +202,6 @@ static void get_string(AVFormatContext *s, const char *key, */ static int parse_tag(AVFormatContext *s, const uint8_t *buf) { - char str[5]; int genre; if (!(buf[0] == 'T' && @@ -187,17 +209,15 @@ static int parse_tag(AVFormatContext *s, const uint8_t *buf) buf[2] == 'G')) return -1; get_string(s, "title", buf + 3, 30); - get_string(s, "author", buf + 33, 30); + get_string(s, "artist", buf + 33, 30); get_string(s, "album", buf + 63, 30); - get_string(s, "year", buf + 93, 4); + get_string(s, "date", buf + 93, 4); get_string(s, "comment", buf + 97, 30); - if (buf[125] == 0 && buf[126] != 0) { - snprintf(str, sizeof(str), "%d", buf[126]); - av_metadata_set(&s->metadata, "track", str); - } + if (buf[125] == 0 && buf[126] != 0) + av_metadata_set2(&s->metadata, "track", av_d2str(buf[126]), AV_METADATA_DONT_STRDUP_VAL); genre = buf[127]; if (genre <= ID3v1_GENRE_MAX) - av_metadata_set(&s->metadata, "genre", ff_id3v1_genre_str[genre]); + av_metadata_set2(&s->metadata, "genre", ff_id3v1_genre_str[genre], 0); return 0; } diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/id3v1.h b/src/add-ons/media/plugins/ffmpeg/libavformat/id3v1.h index b5dcedc551..8eb58be2d1 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/id3v1.h +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/id3v1.h @@ -26,12 +26,12 @@ #define ID3v1_TAG_SIZE 128 -#define ID3v1_GENRE_MAX 125 +#define ID3v1_GENRE_MAX 147 /** * ID3v1 genres */ -extern const char *ff_id3v1_genre_str[ID3v1_GENRE_MAX + 1]; +extern const char * const ff_id3v1_genre_str[ID3v1_GENRE_MAX + 1]; /** * Read an ID3v1 tag diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/id3v2.c b/src/add-ons/media/plugins/ffmpeg/libavformat/id3v2.c index 0cf2cb1a07..6fa11db6c0 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/id3v2.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/id3v2.c @@ -79,8 +79,10 @@ static unsigned int get_size(ByteIOContext *s, int len) static void read_ttag(AVFormatContext *s, int taglen, const char *key) { char *q, dst[512]; + const char *val = NULL; int len, dstlen = sizeof(dst) - 1; unsigned genre; + unsigned int (*get)(ByteIOContext*) = get_be16; dst[0] = 0; if (taglen < 1) @@ -92,33 +94,69 @@ static void read_ttag(AVFormatContext *s, int taglen, const char *key) case 0: /* ISO-8859-1 (0 - 255 maps directly into unicode) */ q = dst; - while (taglen--) { + while (taglen-- && q - dst < dstlen - 7) { uint8_t tmp; - PUT_UTF8(get_byte(s->pb), tmp, if (q - dst < dstlen - 1) *q++ = tmp;) + PUT_UTF8(get_byte(s->pb), tmp, *q++ = tmp;) } - *q = '\0'; + *q = 0; + break; + + case 1: /* UTF-16 with BOM */ + taglen -= 2; + switch (get_be16(s->pb)) { + case 0xfffe: + get = get_le16; + case 0xfeff: + break; + default: + av_log(s, AV_LOG_ERROR, "Incorrect BOM value in tag %s.\n", key); + return; + } + // fall-through + + case 2: /* UTF-16BE without BOM */ + q = dst; + while (taglen > 1 && q - dst < dstlen - 7) { + uint32_t ch; + uint8_t tmp; + + GET_UTF16(ch, ((taglen -= 2) >= 0 ? get(s->pb) : 0), break;) + PUT_UTF8(ch, tmp, *q++ = tmp;) + } + *q = 0; break; case 3: /* UTF-8 */ - len = FFMIN(taglen, dstlen - 1); + len = FFMIN(taglen, dstlen); get_buffer(s->pb, dst, len); dst[len] = 0; break; + default: + av_log(s, AV_LOG_WARNING, "Unknown encoding in tag %s\n.", key); } - if (!strcmp(key, "genre") + if (!(strcmp(key, "TCON") && strcmp(key, "TCO")) && (sscanf(dst, "(%d)", &genre) == 1 || sscanf(dst, "%d", &genre) == 1) && genre <= ID3v1_GENRE_MAX) - av_strlcpy(dst, ff_id3v1_genre_str[genre], sizeof(dst)); + 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); + key = dst; + val = dst + FFMIN(len + 1, dstlen); + } + else if (*dst) + val = dst; - if (*dst) - av_metadata_set(&s->metadata, key, dst); + if (val) + av_metadata_set2(&s->metadata, key, val, 0); } void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags) { int isv34, tlen; - uint32_t tag; + char tag[5]; int64_t next; int taghdrlen; const char *reason; @@ -154,14 +192,16 @@ void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags) while (len >= taghdrlen) { if (isv34) { - tag = get_be32(s->pb); + get_buffer(s->pb, tag, 4); + tag[4] = 0; if(version==3){ tlen = get_be32(s->pb); }else tlen = get_size(s->pb, 4); get_be16(s->pb); /* flags */ } else { - tag = get_be24(s->pb); + get_buffer(s->pb, tag, 3); + tag[3] = 0; tlen = get_be24(s->pb); } len -= taghdrlen + tlen; @@ -171,36 +211,13 @@ void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags) next = url_ftell(s->pb) + tlen; - switch (tag) { - case MKBETAG('T', 'I', 'T', '2'): - case MKBETAG(0, 'T', 'T', '2'): - read_ttag(s, tlen, "title"); - break; - case MKBETAG('T', 'P', 'E', '1'): - case MKBETAG(0, 'T', 'P', '1'): - read_ttag(s, tlen, "author"); - break; - case MKBETAG('T', 'A', 'L', 'B'): - case MKBETAG(0, 'T', 'A', 'L'): - read_ttag(s, tlen, "album"); - break; - case MKBETAG('T', 'C', 'O', 'N'): - case MKBETAG(0, 'T', 'C', 'O'): - read_ttag(s, tlen, "genre"); - break; - case MKBETAG('T', 'C', 'O', 'P'): - case MKBETAG(0, 'T', 'C', 'R'): - read_ttag(s, tlen, "copyright"); - break; - case MKBETAG('T', 'R', 'C', 'K'): - case MKBETAG(0, 'T', 'R', 'K'): - read_ttag(s, tlen, "track"); - break; - case 0: - /* padding, skip to end */ + if (tag[0] == 'T') + read_ttag(s, tlen, tag); + else if (!tag[0]) { + if (tag[1]) + av_log(s, AV_LOG_WARNING, "invalid frame id, assuming padding"); url_fskip(s->pb, len); - len = 0; - continue; + break; } /* Skip to end of tag */ url_fseek(s->pb, next, SEEK_SET); @@ -214,3 +231,43 @@ void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags) av_log(s, AV_LOG_INFO, "ID3v2.%d tag skipped, cannot handle %s\n", version, reason); url_fskip(s->pb, len); } + +const AVMetadataConv ff_id3v2_metadata_conv[] = { + { "TALB", "album"}, + { "TAL", "album"}, + { "TCOM", "composer"}, + { "TCON", "genre"}, + { "TCO", "genre"}, + { "TCOP", "copyright"}, + { "TDRL", "date"}, + { "TDRC", "date"}, + { "TENC", "encoded_by"}, + { "TEN", "encoded_by"}, + { "TIT2", "title"}, + { "TT2", "title"}, + { "TLAN", "language"}, + { "TPE1", "artist"}, + { "TP1", "artist"}, + { "TPE2", "album_artist"}, + { "TP2", "album_artist"}, + { "TPE3", "performer"}, + { "TP3", "performer"}, + { "TPOS", "disc"}, + { "TPUB", "publisher"}, + { "TRCK", "track"}, + { "TRK", "track"}, + { "TSOA", "album-sort"}, + { "TSOP", "artist-sort"}, + { "TSOT", "title-sort"}, + { "TSSE", "encoder"}, + { 0 } +}; + +const char ff_id3v2_tags[][4] = { + "TALB", "TBPM", "TCOM", "TCON", "TCOP", "TDEN", "TDLY", "TDOR", "TDRC", + "TDRL", "TDTG", "TENC", "TEXT", "TFLT", "TIPL", "TIT1", "TIT2", "TIT3", + "TKEY", "TLAN", "TLEN", "TMCL", "TMED", "TMOO", "TOAL", "TOFN", "TOLY", + "TOPE", "TOWN", "TPE1", "TPE2", "TPE3", "TPE4", "TPOS", "TPRO", "TPUB", + "TRCK", "TRSN", "TRSO", "TSOA", "TSOP", "TSOT", "TSRC", "TSSE", "TSST", + { 0 }, +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/id3v2.h b/src/add-ons/media/plugins/ffmpeg/libavformat/id3v2.h index 791c00c595..70030d297f 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/id3v2.h +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/id3v2.h @@ -24,6 +24,7 @@ #include #include "avformat.h" +#include "metadata.h" #define ID3v2_HEADER_SIZE 10 @@ -51,4 +52,12 @@ void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags) */ void ff_id3v2_read(AVFormatContext *s); +extern const AVMetadataConv ff_id3v2_metadata_conv[]; + +/** + * A list of ID3v2.4 text information frames. + * http://www.id3.org/id3v2.4.0-frames + */ +extern const char ff_id3v2_tags[][4]; + #endif /* AVFORMAT_ID3V2_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/idcin.c b/src/add-ons/media/plugins/ffmpeg/libavformat/idcin.c index 0a5f825df6..cd4ebf83fc 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/idcin.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/idcin.c @@ -20,7 +20,7 @@ */ /** - * @file libavformat/idcin.c + * @file * id Quake II CIN file demuxer by Mike Melanson (melanson@pcisys.net) * For more information about the id CIN format, visit: * http://www.csse.monash.edu.au/~timf/ @@ -105,6 +105,11 @@ static int idcin_probe(AVProbeData *p) * audio channels: 0 for no audio, or 1 or 2 */ + /* check we have enough data to do all checks, otherwise the + 0-padding may cause a wrong recognition */ + if (p->buf_size < 20) + return 0; + /* check the video width */ number = AV_RL32(&p->buf[0]); if ((number == 0) || (number > 1024)) @@ -155,7 +160,7 @@ static int idcin_read_header(AVFormatContext *s, return AVERROR(ENOMEM); av_set_pts_info(st, 33, 1, IDCIN_FPS); idcin->video_stream_index = st->index; - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_IDCIN; st->codec->codec_tag = 0; /* no fourcc */ st->codec->width = width; @@ -178,7 +183,7 @@ static int idcin_read_header(AVFormatContext *s, return AVERROR(ENOMEM); av_set_pts_info(st, 33, 1, IDCIN_FPS); idcin->audio_stream_index = st->index; - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_tag = 1; st->codec->channels = channels; st->codec->sample_rate = sample_rate; @@ -255,8 +260,8 @@ static int idcin_read_packet(AVFormatContext *s, url_fseek(pb, 4, SEEK_CUR); chunk_size -= 4; ret= av_get_packet(pb, pkt, chunk_size); - if (ret != chunk_size) - return AVERROR(EIO); + if (ret < 0) + return ret; pkt->stream_index = idcin->video_stream_index; pkt->pts = idcin->pts; } else { @@ -266,8 +271,8 @@ static int idcin_read_packet(AVFormatContext *s, else chunk_size = idcin->audio_chunk_size1; ret= av_get_packet(pb, pkt, chunk_size); - if (ret != chunk_size) - return AVERROR(EIO); + if (ret < 0) + return ret; pkt->stream_index = idcin->audio_stream_index; pkt->pts = idcin->pts; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/idroq.c b/src/add-ons/media/plugins/ffmpeg/libavformat/idroq.c index c570eecf0d..6b036d9c07 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/idroq.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/idroq.c @@ -20,7 +20,7 @@ */ /** - * @file libavformat/idroq.c + * @file * id RoQ format file demuxer * by Mike Melanson (melanson@pcisys.net) * for more information on the .roq file format, visit: @@ -89,7 +89,7 @@ static int roq_read_header(AVFormatContext *s, return AVERROR(ENOMEM); av_set_pts_info(st, 63, 1, framerate); roq->video_stream_index = st->index; - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_ROQ; st->codec->codec_tag = 0; /* no fourcc */ @@ -171,7 +171,7 @@ static int roq_read_packet(AVFormatContext *s, return AVERROR(ENOMEM); av_set_pts_info(st, 32, 1, RoQ_AUDIO_SAMPLE_RATE); roq->audio_stream_index = st->index; - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_ROQ_DPCM; st->codec->codec_tag = 0; /* no tag */ st->codec->channels = roq->audio_channels = chunk_type == RoQ_SOUND_STEREO ? 2 : 1; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/iff.c b/src/add-ons/media/plugins/ffmpeg/libavformat/iff.c index 812ed23404..db74b8dc96 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/iff.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/iff.c @@ -1,6 +1,8 @@ /* * IFF (.iff) file demuxer * Copyright (c) 2008 Jaikrishnan Menon + * Copyright (c) 2010 Peter Ross + * Copyright (c) 2010 Sebastian Vater * * This file is part of FFmpeg. * @@ -20,7 +22,7 @@ */ /** - * @file libavformat/iff.c + * @file * IFF file demuxer * by Jaikrishnan Menon * for more information on the .iff file format, visit: @@ -28,6 +30,7 @@ */ #include "libavutil/intreadwrite.h" +#include "libavcodec/iff.h" #include "avformat.h" #define ID_8SVX MKTAG('8','S','V','X') @@ -35,6 +38,10 @@ #define ID_ATAK MKTAG('A','T','A','K') #define ID_RLSE MKTAG('R','L','S','E') #define ID_CHAN MKTAG('C','H','A','N') +#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_CMAP MKTAG('C','M','A','P') #define ID_FORM MKTAG('F','O','R','M') #define ID_ANNO MKTAG('A','N','N','O') @@ -46,6 +53,7 @@ #define ID_NAME MKTAG('N','A','M','E') #define ID_TEXT MKTAG('T','E','X','T') #define ID_BODY MKTAG('B','O','D','Y') +#define ID_ANNO MKTAG('A','N','N','O') #define LEFT 2 #define RIGHT 4 @@ -53,9 +61,19 @@ #define PACKET_SIZE 1024 -typedef enum {COMP_NONE, COMP_FIB, COMP_EXP} svx8_compression_type; +typedef enum { + COMP_NONE, + COMP_FIB, + COMP_EXP +} svx8_compression_type; + +typedef enum { + BITMAP_RAW, + BITMAP_BYTERUN1 +} bitmap_compression_type; typedef struct { + uint64_t body_pos; uint32_t body_size; uint32_t sent_bytes; uint32_t audio_frame_count; @@ -79,7 +97,7 @@ static int iff_probe(AVProbeData *p) const uint8_t *d = p->buf; if ( AV_RL32(d) == ID_FORM && - AV_RL32(d+8) == ID_8SVX) + (AV_RL32(d+8) == ID_8SVX || AV_RL32(d+8) == ID_PBM || AV_RL32(d+8) == ID_ILBM) ) return AVPROBE_SCORE_MAX; return 0; } @@ -91,69 +109,139 @@ static int iff_read_header(AVFormatContext *s, ByteIOContext *pb = s->pb; AVStream *st; uint32_t chunk_id, data_size; - int padding, done = 0; + int compression = -1; + char *buf; st = av_new_stream(s, 0); if (!st) - return AVERROR(ENOMEM); + return AVERROR(ENOMEM); st->codec->channels = 1; - url_fskip(pb, 12); + url_fskip(pb, 8); + // codec_tag used by ByteRun1 decoder to distinguish progressive (PBM) and interlaced (ILBM) content + st->codec->codec_tag = get_le32(pb); - while(!done && !url_feof(pb)) { + while(!url_feof(pb)) { + uint64_t orig_pos; chunk_id = get_le32(pb); data_size = get_be32(pb); - padding = data_size & 1; + orig_pos = url_ftell(pb); switch(chunk_id) { case ID_VHDR: + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + + if (data_size < 14) + return AVERROR_INVALIDDATA; url_fskip(pb, 12); st->codec->sample_rate = get_be16(pb); - url_fskip(pb, 1); - st->codec->codec_tag = get_byte(pb); - url_fskip(pb, 4); + if (data_size >= 16) { + url_fskip(pb, 1); + compression = get_byte(pb); + } break; case ID_BODY: + iff->body_pos = url_ftell(pb); iff->body_size = data_size; - done = 1; break; case ID_CHAN: + if (data_size < 4) + return AVERROR_INVALIDDATA; st->codec->channels = (get_be32(pb) < 6) ? 1 : 2; break; - default: - url_fseek(pb, data_size + padding, SEEK_CUR); + case ID_CMAP: + st->codec->extradata_size = data_size; + st->codec->extradata = av_malloc(data_size); + if (!st->codec->extradata) + return AVERROR(ENOMEM); + if (get_buffer(pb, st->codec->extradata, data_size) < 0) + return AVERROR(EIO); + break; + + case ID_BMHD: + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + if (data_size <= 8) + return AVERROR_INVALIDDATA; + st->codec->width = get_be16(pb); + st->codec->height = get_be16(pb); + url_fskip(pb, 4); // x, y offset + st->codec->bits_per_coded_sample = get_byte(pb); + if (data_size >= 11) { + url_fskip(pb, 1); // masking + compression = get_byte(pb); + } + if (data_size >= 16) { + url_fskip(pb, 3); // paddding, transparent + st->sample_aspect_ratio.num = get_byte(pb); + st->sample_aspect_ratio.den = get_byte(pb); + } + break; + + case ID_ANNO: + buf = av_malloc(data_size + 1); + if (!buf) + break; + get_buffer(pb, buf, data_size); + buf[data_size] = 0; + av_metadata_set2(&s->metadata, "comment", buf, AV_METADATA_DONT_STRDUP_VAL); break; } + + url_fskip(pb, data_size - (url_ftell(pb) - orig_pos) + (data_size & 1)); } - if(!st->codec->sample_rate) - return AVERROR_INVALIDDATA; + url_fseek(pb, iff->body_pos, SEEK_SET); - av_set_pts_info(st, 32, 1, st->codec->sample_rate); - st->codec->codec_type = CODEC_TYPE_AUDIO; + switch(st->codec->codec_type) { + case AVMEDIA_TYPE_AUDIO: + av_set_pts_info(st, 32, 1, st->codec->sample_rate); - switch(st->codec->codec_tag) { - case COMP_NONE: - st->codec->codec_id = CODEC_ID_PCM_S8; + switch(compression) { + case COMP_NONE: + st->codec->codec_id = CODEC_ID_PCM_S8; + break; + case COMP_FIB: + st->codec->codec_id = CODEC_ID_8SVX_FIB; + break; + case COMP_EXP: + st->codec->codec_id = CODEC_ID_8SVX_EXP; + break; + default: + av_log(s, AV_LOG_ERROR, "iff: unknown compression method\n"); + return -1; + } + + 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; break; - case COMP_FIB: - st->codec->codec_id = CODEC_ID_8SVX_FIB; - break; - case COMP_EXP: - st->codec->codec_id = CODEC_ID_8SVX_EXP; + + case AVMEDIA_TYPE_VIDEO: + switch (compression) { + case BITMAP_RAW: + if (st->codec->codec_tag == ID_ILBM) { + st->codec->codec_id = CODEC_ID_IFF_ILBM; + } else { + st->codec->codec_id = CODEC_ID_RAWVIDEO; + st->codec->pix_fmt = PIX_FMT_PAL8; + st->codec->codec_tag = 0; + } + break; + case BITMAP_BYTERUN1: + st->codec->codec_id = CODEC_ID_IFF_BYTERUN1; + break; + default: + av_log(s, AV_LOG_ERROR, "unknown compression method\n"); + return AVERROR_INVALIDDATA; + } break; default: - av_log(s, AV_LOG_ERROR, "iff: unknown compression method\n"); return -1; } - 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; - return 0; } @@ -162,9 +250,10 @@ static int iff_read_packet(AVFormatContext *s, { IffDemuxContext *iff = s->priv_data; ByteIOContext *pb = s->pb; + AVStream *st = s->streams[0]; int ret; - if(iff->sent_bytes > iff->body_size) + if(iff->sent_bytes >= iff->body_size) return AVERROR(EIO); if(s->streams[0]->codec->channels == 2) { @@ -176,18 +265,37 @@ static int iff_read_packet(AVFormatContext *s, return AVERROR(ENOMEM); } interleave_stereo(sample_buffer, pkt->data, PACKET_SIZE); - } - else { + } else if (s->streams[0]->codec->codec_id == CODEC_ID_RAWVIDEO) { + if(av_new_packet(pkt, iff->body_size + AVPALETTE_SIZE) < 0) { + return AVERROR(ENOMEM); + } + + ret = ff_cmap_read_palette(st->codec, (uint32_t*)(pkt->data + iff->body_size)); + if (ret < 0) + return ret; + av_freep(&st->codec->extradata); + st->codec->extradata_size = 0; + + ret = get_buffer(pb, pkt->data, iff->body_size); + } else if (s->streams[0]->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + ret = av_get_packet(pb, pkt, iff->body_size); + } else { ret = av_get_packet(pb, pkt, PACKET_SIZE); } if(iff->sent_bytes == 0) - pkt->flags |= PKT_FLAG_KEY; + pkt->flags |= AV_PKT_FLAG_KEY; - iff->sent_bytes += PACKET_SIZE; + if(s->streams[0]->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + iff->sent_bytes += PACKET_SIZE; + } else { + iff->sent_bytes = iff->body_size; + } pkt->stream_index = 0; - pkt->pts = iff->audio_frame_count; - iff->audio_frame_count += ret / s->streams[0]->codec->channels; + if(s->streams[0]->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + pkt->pts = iff->audio_frame_count; + iff->audio_frame_count += ret / s->streams[0]->codec->channels; + } return ret; } diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/img2.c b/src/add-ons/media/plugins/ffmpeg/libavformat/img2.c index a90381dc4b..85bee971c7 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/img2.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/img2.c @@ -128,7 +128,9 @@ static int find_image_range(int *pfirst_index, int *plast_index, if (av_get_frame_filename(buf, sizeof(buf), path, first_index) < 0){ *pfirst_index = *plast_index = 1; - return 0; + if(url_exist(buf)) + return 0; + return -1; } if (url_exist(buf)) break; @@ -221,7 +223,7 @@ static int img_read_header(AVFormatContext *s1, AVFormatParameters *ap) if (!s->is_pipe) { if (find_image_range(&first_index, &last_index, s->path) < 0) - return AVERROR(EIO); + return AVERROR(ENOENT); s->img_first = first_index; s->img_last = last_index; s->img_number = first_index; @@ -230,17 +232,17 @@ static int img_read_header(AVFormatContext *s1, AVFormatParameters *ap) st->duration = last_index - first_index + 1; } - if(ap->video_codec_id){ - st->codec->codec_type = CODEC_TYPE_VIDEO; - st->codec->codec_id = ap->video_codec_id; - }else if(ap->audio_codec_id){ - st->codec->codec_type = CODEC_TYPE_AUDIO; - st->codec->codec_id = ap->audio_codec_id; + if(s1->video_codec_id){ + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = s1->video_codec_id; + }else if(s1->audio_codec_id){ + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codec->codec_id = s1->audio_codec_id; }else{ - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = av_str2id(img_tags, s->path); } - if(st->codec->codec_type == CODEC_TYPE_VIDEO && ap->pix_fmt != PIX_FMT_NONE) + if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO && ap->pix_fmt != PIX_FMT_NONE) st->codec->pix_fmt = ap->pix_fmt; return 0; @@ -267,6 +269,8 @@ static int img_read_packet(AVFormatContext *s1, AVPacket *pkt) return AVERROR(EIO); for(i=0; i<3; i++){ if (url_fopen(&f[i], filename, URL_RDONLY) < 0) { + if(i==1) + break; av_log(s1, AV_LOG_ERROR, "Could not open file : %s\n",filename); return AVERROR(EIO); } @@ -288,7 +292,7 @@ static int img_read_packet(AVFormatContext *s1, AVPacket *pkt) av_new_packet(pkt, size[0] + size[1] + size[2]); pkt->stream_index = 0; - pkt->flags |= PKT_FLAG_KEY; + pkt->flags |= AV_PKT_FLAG_KEY; pkt->size= 0; for(i=0; i<3; i++){ @@ -341,8 +345,10 @@ static int img_write_packet(AVFormatContext *s, AVPacket *pkt) if (!img->is_pipe) { if (av_get_frame_filename(filename, sizeof(filename), - img->path, img->img_number) < 0 && img->img_number>1) + img->path, img->img_number) < 0 && img->img_number>1) { + av_log(s, AV_LOG_ERROR, "Could not get frame filename from pattern\n"); return AVERROR(EIO); + } for(i=0; i<3; i++){ if (url_fopen(&pb[i], filename, URL_WRONLY) < 0) { av_log(s, AV_LOG_ERROR, "Could not open file : %s\n",filename); @@ -442,7 +448,7 @@ AVOutputFormat image2_muxer = { img_write_header, img_write_packet, NULL, - .flags= AVFMT_NOTIMESTAMPS | AVFMT_NOFILE + .flags= AVFMT_NOTIMESTAMPS | AVFMT_NODIMENSIONS | AVFMT_NOFILE }; #endif #if CONFIG_IMAGE2PIPE_MUXER @@ -456,6 +462,6 @@ AVOutputFormat image2pipe_muxer = { CODEC_ID_MJPEG, img_write_header, img_write_packet, - .flags= AVFMT_NOTIMESTAMPS + .flags= AVFMT_NOTIMESTAMPS | AVFMT_NODIMENSIONS }; #endif diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/internal.h b/src/add-ons/media/plugins/ffmpeg/libavformat/internal.h index 15f4dd7848..a395c2f24b 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/internal.h +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/internal.h @@ -24,9 +24,31 @@ #include #include "avformat.h" -char *ff_data_to_hex(char *buf, const uint8_t *src, int size); +void ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem); -void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned int idx); +#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);\ +} while(0) +#else +#define dynarray_add(tab, nb_ptr, elem)\ +do {\ + ff_dynarray_add((intptr_t **)(tab), nb_ptr, (intptr_t)(elem));\ +} while(0) +#endif + +time_t mktimegm(struct tm *tm); +struct tm *brktimegm(time_t secs, struct tm *tm); +const char *small_strptime(const char *p, const char *fmt, + struct tm *dt); + +char *ff_data_to_hex(char *buf, const uint8_t *src, int size, int lowercase); + +void ff_program_add_stream_index(AVFormatContext *ac, int progid, unsigned int idx); /** * Add packet to AVFormatContext->packet_buffer list, determining its @@ -35,4 +57,101 @@ void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned int i void ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, int (*compare)(AVFormatContext *, AVPacket *, AVPacket *)); +void ff_read_frame_flush(AVFormatContext *s); + +#define NTP_OFFSET 2208988800ULL +#define NTP_OFFSET_US (NTP_OFFSET * 1000000ULL) + +/** Gets the current time since NTP epoch in microseconds. */ +uint64_t ff_ntp_time(void); + +/** + * Probes 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 + * with the highest score is returned. + * + * @param pb the bytestream to probe, it may be closed and opened again + * @param fmt the input format is put here + * @param filename the filename of the stream + * @param logctx the log context + * @param offset the offset within the bytestream to probe from + * @param max_probe_size the maximum probe buffer size (zero for default) + * @return 0 in case of success, a negative value corresponding to an + * AVERROR code otherwise + */ +int ff_probe_input_buffer(ByteIOContext **pb, AVInputFormat **fmt, + const char *filename, void *logctx, + unsigned int offset, unsigned int max_probe_size); + +/** + * Splits a URL string into components. To reassemble components back into + * a URL, use ff_url_join instead of using snprintf directly. + * + * The pointers to buffers for storing individual components may be null, + * in order to ignore that component. Buffers for components not found are + * set to empty strings. If the port isn't found, it is set to a negative + * value. + * + * @see ff_url_join + * + * @param proto the buffer for the protocol + * @param proto_size the size of the proto buffer + * @param authorization the buffer for the authorization + * @param authorization_size the size of the authorization buffer + * @param hostname the buffer for the host name + * @param hostname_size the size of the hostname buffer + * @param port_ptr a pointer to store the port number in + * @param path the buffer for the path + * @param path_size the size of the path buffer + * @param url the URL to split + */ +void ff_url_split(char *proto, int proto_size, + char *authorization, int authorization_size, + char *hostname, int hostname_size, + int *port_ptr, + char *path, int path_size, + const char *url); + +/** + * Assembles a URL string from components. This is the reverse operation + * of ff_url_split. + * + * Note, this requires networking to be initialized, so the caller must + * ensure ff_network_init has been called. + * + * @see ff_url_split + * + * @param str the buffer to fill with the url + * @param size the size of the str buffer + * @param proto the protocol identifier, if null, the separator + * after the identifier is left out, too + * @param authorization an optional authorization string, may be null + * @param hostname the host name string + * @param port the port number, left out from the string if negative + * @param fmt a generic format string for everything to add after the + * host/port, may be null + * @return the number of characters written to the destination buffer + */ +int ff_url_join(char *str, int size, const char *proto, + const char *authorization, const char *hostname, + int port, const char *fmt, ...); + +/** + * Appends the media-specific SDP fragment for the media stream c + * to the buffer buff. + * + * Note, the buffer needs to be initialized, since it is appended to + * existing content. + * + * @param buff the buffer to append the SDP fragment to + * @param size the size of the buff buffer + * @param c the AVCodecContext of the media to describe + * @param dest_addr the destination address of the media stream, may be NULL + * @param port the destination port of the media stream, 0 if unknown + * @param ttl the time to live of the stream, 0 if not multicast + */ +void ff_sdp_write_media(char *buff, int size, AVCodecContext *c, + const char *dest_addr, int port, int ttl); + #endif /* AVFORMAT_INTERNAL_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/ipmovie.c b/src/add-ons/media/plugins/ffmpeg/libavformat/ipmovie.c index f992b68782..372a926266 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/ipmovie.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/ipmovie.c @@ -20,7 +20,7 @@ */ /** - * @file libavformat/ipmovie.c + * @file * Interplay MVE file demuxer * by Mike Melanson (melanson@pcisys.net) * For more information regarding the Interplay MVE file format, visit: @@ -46,8 +46,6 @@ static inline void debug_ipmovie(const char *format, ...) { } #endif -#define IPMOVIE_SIGNATURE "Interplay MVE File\x1A\0" -#define IPMOVIE_SIGNATURE_SIZE 20 #define CHUNK_PREAMBLE_SIZE 4 #define OPCODE_PREAMBLE_SIZE 4 @@ -95,6 +93,7 @@ typedef struct IPMVEContext { uint64_t frame_pts_inc; + unsigned int video_bpp; unsigned int video_width; unsigned int video_height; int64_t video_pts; @@ -377,6 +376,11 @@ static int process_ipmovie_chunk(IPMVEContext *s, ByteIOContext *pb, } s->video_width = AV_RL16(&scratch[0]) * 8; s->video_height = AV_RL16(&scratch[2]) * 8; + if (opcode_version < 2 || !AV_RL16(&scratch[6])) { + s->video_bpp = 8; + } else { + s->video_bpp = 16; + } debug_ipmovie("video resolution: %d x %d\n", s->video_width, s->video_height); break; @@ -499,12 +503,18 @@ static int process_ipmovie_chunk(IPMVEContext *s, ByteIOContext *pb, return chunk_type; } +static const char signature[] = "Interplay MVE File\x1A\0\x1A"; + static int ipmovie_probe(AVProbeData *p) { - if (strncmp(p->buf, IPMOVIE_SIGNATURE, IPMOVIE_SIGNATURE_SIZE) != 0) - return 0; + uint8_t *b = p->buf; + uint8_t *b_end = p->buf + p->buf_size - sizeof(signature); + do { + if (memcmp(b++, signature, sizeof(signature)) == 0) + return AVPROBE_SCORE_MAX; + } while (b < b_end); - return AVPROBE_SCORE_MAX; + return 0; } static int ipmovie_read_header(AVFormatContext *s, @@ -516,14 +526,22 @@ static int ipmovie_read_header(AVFormatContext *s, AVStream *st; unsigned char chunk_preamble[CHUNK_PREAMBLE_SIZE]; int chunk_type; + uint8_t signature_buffer[sizeof(signature)]; + get_buffer(pb, signature_buffer, sizeof(signature_buffer)); + while (memcmp(signature_buffer, signature, sizeof(signature))) { + memmove(signature_buffer, signature_buffer + 1, sizeof(signature_buffer) - 1); + signature_buffer[sizeof(signature_buffer) - 1] = get_byte(pb); + if (url_feof(pb)) + return AVERROR_EOF; + } /* initialize private context members */ ipmovie->video_pts = ipmovie->audio_frame_count = 0; ipmovie->audio_chunk_offset = ipmovie->video_chunk_offset = ipmovie->decode_map_chunk_offset = 0; /* on the first read, this will position the stream at the first chunk */ - ipmovie->next_chunk_offset = IPMOVIE_SIGNATURE_SIZE + 6; + ipmovie->next_chunk_offset = url_ftell(pb) + 4; /* process the first chunk which should be CHUNK_INIT_VIDEO */ if (process_ipmovie_chunk(ipmovie, pb, &pkt) != CHUNK_INIT_VIDEO) @@ -548,11 +566,12 @@ static int ipmovie_read_header(AVFormatContext *s, return AVERROR(ENOMEM); av_set_pts_info(st, 63, 1, 1000000); ipmovie->video_stream_index = st->index; - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_INTERPLAY_VIDEO; st->codec->codec_tag = 0; /* no fourcc */ st->codec->width = ipmovie->video_width; st->codec->height = ipmovie->video_height; + st->codec->bits_per_coded_sample = ipmovie->video_bpp; /* palette considerations */ st->codec->palctrl = &ipmovie->palette_control; @@ -563,7 +582,7 @@ static int ipmovie_read_header(AVFormatContext *s, return AVERROR(ENOMEM); av_set_pts_info(st, 32, 1, ipmovie->audio_sample_rate); ipmovie->audio_stream_index = st->index; - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = ipmovie->audio_type; st->codec->codec_tag = 0; /* no tag */ st->codec->channels = ipmovie->audio_channels; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/isom.c b/src/add-ons/media/plugins/ffmpeg/libavformat/isom.c index 23d716fef3..a6e67e2267 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/isom.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/isom.c @@ -32,6 +32,7 @@ const AVCodecTag ff_mp4_obj_type[] = { { CODEC_ID_MPEG4 , 0x20 }, { CODEC_ID_H264 , 0x21 }, { CODEC_ID_AAC , 0x40 }, + { CODEC_ID_MP4ALS , 0x40 }, /* 14496-3 ALS */ { CODEC_ID_MPEG2VIDEO, 0x61 }, /* MPEG2 Main */ { CODEC_ID_MPEG2VIDEO, 0x60 }, /* MPEG2 Simple */ { CODEC_ID_MPEG2VIDEO, 0x62 }, /* MPEG2 SNR */ @@ -54,7 +55,7 @@ const AVCodecTag ff_mp4_obj_type[] = { { CODEC_ID_VORBIS , 0xDD }, /* non standard, gpac uses it */ { CODEC_ID_DVD_SUBTITLE, 0xE0 }, /* non standard, see unsupported-embedded-subs-2.mp4 */ { CODEC_ID_QCELP , 0xE1 }, - { 0, 0 }, + { CODEC_ID_NONE , 0 }, }; const AVCodecTag codec_movvideo_tags[] = { @@ -64,7 +65,9 @@ const AVCodecTag codec_movvideo_tags[] = { { CODEC_ID_RAWVIDEO, MKTAG('y', 'u', 'v', '2') }, /* Uncompressed YUV422 */ { CODEC_ID_RAWVIDEO, MKTAG('A', 'V', 'U', 'I') }, /* YUV with alpha-channel (AVID Uncompressed) */ { CODEC_ID_RAWVIDEO, MKTAG('2', 'v', 'u', 'y') }, /* UNCOMPRESSED 8BIT 4:2:2 */ + { CODEC_ID_RAWVIDEO, MKTAG('y', 'u', 'v', 's') }, /* same as 2vuy but byte swapped */ + { CODEC_ID_R210, MKTAG('r', '2', '1', '0') }, /* UNCOMPRESSED 10BIT RGB */ { CODEC_ID_V210, MKTAG('v', '2', '1', '0') }, /* UNCOMPRESSED 10BIT 4:2:2 */ { CODEC_ID_MJPEG, MKTAG('j', 'p', 'e', 'g') }, /* PhotoJPEG */ @@ -168,6 +171,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_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 */ { CODEC_ID_DPX, MKTAG('d', 'p', 'x', ' ') }, /* DPX */ @@ -183,7 +188,9 @@ const AVCodecTag codec_movaudio_tags[] = { { CODEC_ID_PCM_S16LE, MKTAG('s', 'o', 'w', 't') }, /* */ { CODEC_ID_PCM_S16LE, MKTAG('l', 'p', 'c', 'm') }, { CODEC_ID_PCM_F32BE, MKTAG('f', 'l', '3', '2') }, + { CODEC_ID_PCM_F32LE, MKTAG('f', 'l', '3', '2') }, { CODEC_ID_PCM_F64BE, MKTAG('f', 'l', '6', '4') }, + { CODEC_ID_PCM_F64LE, MKTAG('f', 'l', '6', '4') }, { CODEC_ID_PCM_S8, MKTAG('s', 'o', 'w', 't') }, { CODEC_ID_PCM_U8, MKTAG('r', 'a', 'w', ' ') }, /* 8 bits unsigned */ { CODEC_ID_PCM_U8, MKTAG('N', 'O', 'N', 'E') }, /* uncompressed */ @@ -237,35 +244,35 @@ const AVCodecTag ff_codec_movsubtitle_tags[] = { /* cf. QTFileFormat.pdf p253, qtff.pdf p205 */ /* http://developer.apple.com/documentation/mac/Text/Text-368.html */ /* deprecated by putting the code as 3*5bit ascii */ -static const char * const mov_mdhd_language_map[] = { +static const char mov_mdhd_language_map[][4] = { /* 0-9 */ "eng", "fra", "ger", "ita", "dut", "sve", "spa", "dan", "por", "nor", "heb", "jpn", "ara", "fin", "gre", "ice", "mlt", "tur", "hr "/*scr*/, "chi"/*ace?*/, - "urd", "hin", "tha", "kor", "lit", "pol", "hun", "est", "lav", NULL, - "fo ", NULL, "rus", "chi", NULL, "iri", "alb", "ron", "ces", "slk", + "urd", "hin", "tha", "kor", "lit", "pol", "hun", "est", "lav", "", + "fo ", "", "rus", "chi", "", "iri", "alb", "ron", "ces", "slk", "slv", "yid", "sr ", "mac", "bul", "ukr", "bel", "uzb", "kaz", "aze", /*?*/ - "aze", "arm", "geo", "mol", "kir", "tgk", "tuk", "mon", NULL, "pus", + "aze", "arm", "geo", "mol", "kir", "tgk", "tuk", "mon", "", "pus", "kur", "kas", "snd", "tib", "nep", "san", "mar", "ben", "asm", "guj", - "pa ", "ori", "mal", "kan", "tam", "tel", NULL, "bur", "khm", "lao", + "pa ", "ori", "mal", "kan", "tam", "tel", "", "bur", "khm", "lao", /* roman? arabic? */ "vie", "ind", "tgl", "may", "may", "amh", "tir", "orm", "som", "swa", /*==rundi?*/ - NULL, "run", NULL, "mlg", "epo", NULL, NULL, NULL, NULL, NULL, + "", "run", "", "mlg", "epo", "", "", "", "", "", /* 100 */ - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "wel", "baq", + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "wel", "baq", "cat", "lat", "que", "grn", "aym", "tat", "uig", "dzo", "jav" }; -int ff_mov_iso639_to_lang(const char *lang, int mp4) +int ff_mov_iso639_to_lang(const char lang[4], int mp4) { int i, code = 0; /* old way, only for QT? */ - for (i = 0; !mp4 && i < FF_ARRAY_ELEMS(mov_mdhd_language_map); i++) { - if (mov_mdhd_language_map[i] && !strcmp(lang, mov_mdhd_language_map[i])) + for (i = 0; lang[0] && !mp4 && i < FF_ARRAY_ELEMS(mov_mdhd_language_map); i++) { + if (!strcmp(lang, mov_mdhd_language_map[i])) return i; } /* XXX:can we do that in mov too? */ @@ -276,20 +283,20 @@ int ff_mov_iso639_to_lang(const char *lang, int mp4) lang = "und"; /* 5bit ascii */ for (i = 0; i < 3; i++) { - unsigned char c = (unsigned char)lang[i]; - if (c < 0x60) - return -1; - if (c > 0x60 + 0x1f) + uint8_t c = lang[i]; + c -= 0x60; + if (c > 0x1f) return -1; code <<= 5; - code |= (c - 0x60); + code |= c; } return code; } -int ff_mov_lang_to_iso639(unsigned code, char *to) +int ff_mov_lang_to_iso639(unsigned code, char to[4]) { int i; + memset(to, 0, 4); /* is it the mangled iso code? */ /* see http://www.geocities.com/xhelmboyx/quicktime/formats/mp4-layout.txt */ if (code > 138) { @@ -302,8 +309,8 @@ int ff_mov_lang_to_iso639(unsigned code, char *to) /* old fashion apple lang code */ if (code >= FF_ARRAY_ELEMS(mov_mdhd_language_map)) return 0; - if (!mov_mdhd_language_map[code]) + if (!mov_mdhd_language_map[code][0]) return 0; - strncpy(to, mov_mdhd_language_map[code], 4); + memcpy(to, mov_mdhd_language_map[code], 4); return 1; } diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/isom.h b/src/add-ons/media/plugins/ffmpeg/libavformat/isom.h index 445a900b05..92997a7962 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/isom.h +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/isom.h @@ -34,8 +34,8 @@ extern const AVCodecTag codec_movvideo_tags[]; extern const AVCodecTag codec_movaudio_tags[]; extern const AVCodecTag ff_codec_movsubtitle_tags[]; -int ff_mov_iso639_to_lang(const char *lang, int mp4); -int ff_mov_lang_to_iso639(unsigned code, char *to); +int ff_mov_iso639_to_lang(const char lang[4], int mp4); +int ff_mov_lang_to_iso639(unsigned code, char to[4]); /* the QuickTime file format is quite convoluted... * it has lots of index tables, each indexing something in another one... @@ -56,11 +56,14 @@ typedef struct { typedef struct { uint32_t type; char *path; + char *dir; + char volume[28]; + char filename[64]; + int16_t nlvl_to, nlvl_from; } MOVDref; typedef struct { uint32_t type; - int64_t offset; int64_t size; /* total size (excluding the size and type fields) */ } MOVAtom; @@ -135,6 +138,11 @@ typedef struct MOVContext { MOVTrackExt *trex_data; unsigned trex_count; int itunes_metadata; ///< metadata are itunes style + int chapter_track; } MOVContext; +int ff_mp4_read_descr_len(ByteIOContext *pb); +int ff_mov_read_esds(AVFormatContext *fc, ByteIOContext *pb, MOVAtom atom); +enum CodecID ff_mov_get_lpcm_codec_id(int bps, int flags); + #endif /* AVFORMAT_ISOM_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/iss.c b/src/add-ons/media/plugins/ffmpeg/libavformat/iss.c index 891729a2b5..156af976ca 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/iss.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/iss.c @@ -20,7 +20,7 @@ */ /** - * @file libavformat/iss.c + * @file * Funcom ISS file demuxer * @author Jaikrishnan Menon * for more information on the .iss file format, visit: @@ -92,7 +92,7 @@ static av_cold int iss_read_header(AVFormatContext *s, AVFormatParameters *ap) st = av_new_stream(s, 0); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_ADPCM_IMA_ISS; st->codec->channels = stereo ? 2 : 1; st->codec->sample_rate = 44100; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/iv8.c b/src/add-ons/media/plugins/ffmpeg/libavformat/iv8.c new file mode 100644 index 0000000000..00ddcd4f7a --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/iv8.c @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2009 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 + */ + +#include "avformat.h" + + +static int probe(AVProbeData *p) +{ + // the single file i have starts with that, i dont know if others do too + if( p->buf[0] == 1 + && p->buf[1] == 1 + && p->buf[2] == 3 + && p->buf[3] == 0xB8 + && p->buf[4] == 0x80 + && p->buf[5] == 0x60 + ) + return AVPROBE_SCORE_MAX-2; + + return 0; +} + +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_VIDEO; + st->codec->codec_id = CODEC_ID_MPEG4; + st->need_parsing = AVSTREAM_PARSE_FULL; + av_set_pts_info(st, 64, 1, 90000); + + return 0; + +} + +static int read_packet(AVFormatContext *s, AVPacket *pkt) +{ + int ret, size, pts, type; +retry: + type= get_be16(s->pb); // 257 or 258 + size= get_be16(s->pb); + + get_be16(s->pb); //some flags, 0x80 indicates end of frame + get_be16(s->pb); //packet number + pts=get_be32(s->pb); + get_be32(s->pb); //6A 13 E3 88 + + size -= 12; + if(size<1) + return -1; + + if(type==258){ + url_fskip(s->pb, size); + goto retry; + } + + ret= av_get_packet(s->pb, pkt, size); + + pkt->pts= pts; + pkt->pos-=16; + + pkt->stream_index = 0; + + return ret; +} + +AVInputFormat iv8_demuxer = { + "iv8", + NULL_IF_CONFIG_SMALL("A format generated by IndigoVision 8000 video server"), + 0, + probe, + read_header, + read_packet, + .flags= AVFMT_GENERIC_INDEX, + .value = CODEC_ID_MPEG4, +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/libnut.c b/src/add-ons/media/plugins/ffmpeg/libavformat/libnut.c index f23e70dc08..4543df7bd9 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/libnut.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/libnut.c @@ -20,7 +20,7 @@ */ /** - * @file libavformat/libnut.c + * @file * NUT demuxing and muxing via libnut. * @author Oded Shimon */ @@ -77,14 +77,14 @@ static int nut_write_header(AVFormatContext * avf) { int fourcc = 0; int num, denom, ssize; - s[i].type = codec->codec_type == CODEC_TYPE_VIDEO ? NUT_VIDEO_CLASS : NUT_AUDIO_CLASS; + s[i].type = codec->codec_type == AVMEDIA_TYPE_VIDEO ? NUT_VIDEO_CLASS : NUT_AUDIO_CLASS; if (codec->codec_tag) fourcc = codec->codec_tag; else fourcc = ff_codec_get_tag(nut_tags, codec->codec_id); if (!fourcc) { - if (codec->codec_type == CODEC_TYPE_VIDEO) fourcc = ff_codec_get_tag(ff_codec_bmp_tags, codec->codec_id); - if (codec->codec_type == CODEC_TYPE_AUDIO) fourcc = ff_codec_get_tag(ff_codec_wav_tags, codec->codec_id); + if (codec->codec_type == AVMEDIA_TYPE_VIDEO) fourcc = ff_codec_get_tag(ff_codec_bmp_tags, codec->codec_id); + if (codec->codec_type == AVMEDIA_TYPE_AUDIO) fourcc = ff_codec_get_tag(ff_codec_wav_tags, codec->codec_id); } s[i].fourcc_len = 4; @@ -102,7 +102,7 @@ static int nut_write_header(AVFormatContext * avf) { s[i].codec_specific_len = codec->extradata_size; s[i].codec_specific = codec->extradata; - if (codec->codec_type == CODEC_TYPE_VIDEO) { + if (codec->codec_type == AVMEDIA_TYPE_VIDEO) { s[i].width = codec->width; s[i].height = codec->height; s[i].sample_width = 0; @@ -128,7 +128,7 @@ static int nut_write_packet(AVFormatContext * avf, AVPacket * pkt) { p.len = pkt->size; p.stream = pkt->stream_index; p.pts = pkt->pts; - p.flags = pkt->flags & PKT_FLAG_KEY ? NUT_FLAG_KEY : 0; + p.flags = pkt->flags & AV_PKT_FLAG_KEY ? NUT_FLAG_KEY : 0; p.next_pts = 0; nut_write_frame_reorder(priv->nut, &p, pkt->data); @@ -234,14 +234,14 @@ static int nut_read_header(AVFormatContext * avf, AVFormatParameters * ap) { switch(s[i].type) { case NUT_AUDIO_CLASS: - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; if (st->codec->codec_id == CODEC_ID_NONE) st->codec->codec_id = ff_codec_get_id(ff_codec_wav_tags, st->codec->codec_tag); st->codec->channels = s[i].channel_count; st->codec->sample_rate = s[i].samplerate_num / s[i].samplerate_denom; break; case NUT_VIDEO_CLASS: - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; if (st->codec->codec_id == CODEC_ID_NONE) st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, st->codec->codec_tag); st->codec->width = s[i].width; @@ -269,7 +269,7 @@ static int nut_read_packet(AVFormatContext * avf, AVPacket * pkt) { return -1; } - if (pd.flags & NUT_FLAG_KEY) pkt->flags |= PKT_FLAG_KEY; + if (pd.flags & NUT_FLAG_KEY) pkt->flags |= AV_PKT_FLAG_KEY; pkt->pts = pd.pts; pkt->stream_index = pd.stream; pkt->pos = url_ftell(avf->pb); diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/librtmp.c b/src/add-ons/media/plugins/ffmpeg/libavformat/librtmp.c new file mode 100644 index 0000000000..d765102f1b --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/librtmp.c @@ -0,0 +1,226 @@ +/* + * RTMP network protocol + * Copyright (c) 2010 Howard Chu + * + * 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 + * RTMP protocol based on http://rtmpdump.mplayerhq.hu/ librtmp + */ + +#include "avformat.h" + +#include +#include + +static void rtmp_log(int level, const char *fmt, va_list args) +{ + switch (level) { + default: + case RTMP_LOGCRIT: level = AV_LOG_FATAL; break; + case RTMP_LOGERROR: level = AV_LOG_ERROR; break; + case RTMP_LOGWARNING: level = AV_LOG_WARNING; break; + case RTMP_LOGINFO: level = AV_LOG_INFO; break; + case RTMP_LOGDEBUG: level = AV_LOG_VERBOSE; break; + case RTMP_LOGDEBUG2: level = AV_LOG_DEBUG; break; + } + + av_vlog(NULL, level, fmt, args); + av_log(NULL, level, "\n"); +} + +static int rtmp_close(URLContext *s) +{ + RTMP *r = s->priv_data; + + RTMP_Close(r); + av_free(r); + return 0; +} + +/** + * Opens RTMP connection and verifies that the stream can be played. + * + * URL syntax: rtmp://server[:port][/app][/playpath][ keyword=value]... + * where 'app' is first one or two directories in the path + * (e.g. /ondemand/, /flash/live/, etc.) + * and 'playpath' is a file name (the rest of the path, + * may be prefixed with "mp4:") + * + * Additional RTMP library options may be appended as + * space-separated key-value pairs. + */ +static int rtmp_open(URLContext *s, const char *uri, int flags) +{ + RTMP *r; + int rc; + + r = av_mallocz(sizeof(RTMP)); + if (!r) + return AVERROR(ENOMEM); + + switch (av_log_get_level()) { + default: + case AV_LOG_FATAL: rc = RTMP_LOGCRIT; break; + case AV_LOG_ERROR: rc = RTMP_LOGERROR; break; + case AV_LOG_WARNING: rc = RTMP_LOGWARNING; break; + case AV_LOG_INFO: rc = RTMP_LOGINFO; break; + case AV_LOG_VERBOSE: rc = RTMP_LOGDEBUG; break; + case AV_LOG_DEBUG: rc = RTMP_LOGDEBUG2; break; + } + RTMP_LogSetLevel(rc); + RTMP_LogSetCallback(rtmp_log); + + RTMP_Init(r); + if (!RTMP_SetupURL(r, s->filename)) { + rc = -1; + goto fail; + } + + if (flags & URL_WRONLY) + r->Link.protocol |= RTMP_FEATURE_WRITE; + + if (!RTMP_Connect(r, NULL) || !RTMP_ConnectStream(r, 0)) { + rc = -1; + goto fail; + } + + s->priv_data = r; + s->is_streamed = 1; + return 0; +fail: + av_free(r); + return rc; +} + +static int rtmp_write(URLContext *s, uint8_t *buf, int size) +{ + RTMP *r = s->priv_data; + + return RTMP_Write(r, buf, size); +} + +static int rtmp_read(URLContext *s, uint8_t *buf, int size) +{ + RTMP *r = s->priv_data; + + return RTMP_Read(r, buf, size); +} + +static int rtmp_read_pause(URLContext *s, int pause) +{ + RTMP *r = s->priv_data; + + if (pause) + r->m_pauseStamp = + r->m_channelTimestamp[r->m_mediaChannel]; + if (!RTMP_SendPause(r, pause, r->m_pauseStamp)) + return -1; + return 0; +} + +static int64_t rtmp_read_seek(URLContext *s, int stream_index, + int64_t timestamp, int flags) +{ + RTMP *r = s->priv_data; + + if (flags & AVSEEK_FLAG_BYTE) + return AVERROR(ENOSYS); + + /* seeks are in milliseconds */ + if (stream_index < 0) + timestamp = av_rescale_rnd(timestamp, 1000, AV_TIME_BASE, + flags & AVSEEK_FLAG_BACKWARD ? AV_ROUND_DOWN : AV_ROUND_UP); + + if (!RTMP_SendSeek(r, timestamp)) + return -1; + return timestamp; +} + +static int rtmp_get_file_handle(URLContext *s) +{ + RTMP *r = s->priv_data; + + return r->m_sb.sb_socket; +} + +URLProtocol rtmp_protocol = { + "rtmp", + rtmp_open, + rtmp_read, + rtmp_write, + NULL, /* seek */ + rtmp_close, + NULL, /* next */ + rtmp_read_pause, + rtmp_read_seek, + rtmp_get_file_handle +}; + +URLProtocol rtmpt_protocol = { + "rtmpt", + rtmp_open, + rtmp_read, + rtmp_write, + NULL, /* seek */ + rtmp_close, + NULL, /* next */ + rtmp_read_pause, + rtmp_read_seek, + rtmp_get_file_handle +}; + +URLProtocol rtmpe_protocol = { + "rtmpe", + rtmp_open, + rtmp_read, + rtmp_write, + NULL, /* seek */ + rtmp_close, + NULL, /* next */ + rtmp_read_pause, + rtmp_read_seek, + rtmp_get_file_handle +}; + +URLProtocol rtmpte_protocol = { + "rtmpte", + rtmp_open, + rtmp_read, + rtmp_write, + NULL, /* seek */ + rtmp_close, + NULL, /* next */ + rtmp_read_pause, + rtmp_read_seek, + rtmp_get_file_handle +}; + +URLProtocol rtmps_protocol = { + "rtmps", + rtmp_open, + rtmp_read, + rtmp_write, + NULL, /* seek */ + rtmp_close, + NULL, /* next */ + rtmp_read_pause, + rtmp_read_seek, + rtmp_get_file_handle +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/lmlm4.c b/src/add-ons/media/plugins/ffmpeg/libavformat/lmlm4.c index dc0a90125a..c1397fbb45 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/lmlm4.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/lmlm4.c @@ -62,14 +62,14 @@ static int lmlm4_read_header(AVFormatContext *s, AVFormatParameters *ap) { if (!(st = av_new_stream(s, 0))) return AVERROR(ENOMEM); - st->codec->codec_type = CODEC_TYPE_VIDEO; + 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))) return AVERROR(ENOMEM); - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_MP2; st->need_parsing = AVSTREAM_PARSE_HEADERS; @@ -104,7 +104,7 @@ static int lmlm4_read_packet(AVFormatContext *s, AVPacket *pkt) { switch (frame_type) { case LMLM4_I_FRAME: - pkt->flags = PKT_FLAG_KEY; + pkt->flags = AV_PKT_FLAG_KEY; case LMLM4_P_FRAME: case LMLM4_B_FRAME: pkt->stream_index = 0; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/matroska.c b/src/add-ons/media/plugins/ffmpeg/libavformat/matroska.c index f101a000b4..dac4735a50 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/matroska.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/matroska.c @@ -45,7 +45,7 @@ const CodecTags ff_mkv_codec_tags[]={ {"A_REAL/28_8" , CODEC_ID_RA_288}, {"A_REAL/ATRC" , CODEC_ID_ATRAC3}, {"A_REAL/COOK" , CODEC_ID_COOK}, -// {"A_REAL/SIPR" , CODEC_ID_SIPRO}, + {"A_REAL/SIPR" , CODEC_ID_SIPR}, {"A_TRUEHD" , CODEC_ID_TRUEHD}, {"A_TTA1" , CODEC_ID_TTA}, {"A_VORBIS" , CODEC_ID_VORBIS}, @@ -58,6 +58,7 @@ const CodecTags ff_mkv_codec_tags[]={ {"S_ASS" , CODEC_ID_SSA}, {"S_SSA" , CODEC_ID_SSA}, {"S_VOBSUB" , CODEC_ID_DVD_SUBTITLE}, + {"S_HDMV/PGS" , CODEC_ID_HDMV_PGS_SUBTITLE}, {"V_DIRAC" , CODEC_ID_DIRAC}, {"V_MJPEG" , CODEC_ID_MJPEG}, @@ -75,6 +76,7 @@ const CodecTags ff_mkv_codec_tags[]={ {"V_SNOW" , CODEC_ID_SNOW}, {"V_THEORA" , CODEC_ID_THEORA}, {"V_UNCOMPRESSED" , CODEC_ID_RAWVIDEO}, + {"V_VP8" , CODEC_ID_VP8}, {"" , CODEC_ID_NONE} }; @@ -92,8 +94,7 @@ const CodecMime ff_mkv_mime_tags[] = { }; const AVMetadataConv ff_mkv_metadata_conv[] = { - { "ARTIST" , "artist" }, - { "LEAD_PERFORMER", "artist" }, + { "LEAD_PERFORMER", "performer" }, { "PART_NUMBER" , "track" }, { 0 } }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/matroskadec.c b/src/add-ons/media/plugins/ffmpeg/libavformat/matroskadec.c index 25d7341514..e254a31416 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/matroskadec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/matroskadec.c @@ -20,7 +20,7 @@ */ /** - * @file libavformat/matroskadec.c + * @file * Matroska file demuxer * by Ronald Bultje * with a little help from Moritz Bunkus @@ -30,9 +30,11 @@ #include #include "avformat.h" +#include "internal.h" /* For ff_codec_get_id(). */ #include "riff.h" #include "isom.h" +#include "rm.h" #include "matroska.h" #include "libavcodec/mpeg4audio.h" #include "libavutil/intfloat_readwrite.h" @@ -143,6 +145,7 @@ typedef struct { AVStream *stream; int64_t end_timecode; + int ms_compat; } MatroskaTrack; typedef struct { @@ -502,6 +505,8 @@ static EbmlSyntax matroska_clusters[] = { { 0 } }; +static const char *matroska_doctypes[] = { "matroska", "webm" }; + /* * Return: Whether we reached the end of a level in the hierarchy or not. */ @@ -820,8 +825,7 @@ static void ebml_free(EbmlSyntax *syntax, void *data) static int matroska_probe(AVProbeData *p) { uint64_t total = 0; - int len_mask = 0x80, size = 1, n = 1; - static const char probe_data[] = "matroska"; + int len_mask = 0x80, size = 1, n = 1, i; /* EBML header? */ if (AV_RB32(p->buf) != EBML_ID_HEADER) @@ -843,15 +847,19 @@ static int matroska_probe(AVProbeData *p) if (p->buf_size < 4 + size + total) return 0; - /* The header must contain the document type 'matroska'. For now, + /* The header should contain a known document type. For now, * we don't parse the whole header but simply check for the * availability of that array of characters inside the header. * Not fully fool-proof, but good enough. */ - for (n = 4+size; n <= 4+size+total-(sizeof(probe_data)-1); n++) - if (!memcmp(p->buf+n, probe_data, sizeof(probe_data)-1)) - return AVPROBE_SCORE_MAX; + for (i = 0; i < FF_ARRAY_ELEMS(matroska_doctypes); i++) { + int probelen = strlen(matroska_doctypes[i]); + for (n = 4+size; n <= 4+size+total-probelen; n++) + if (!memcmp(p->buf+n, matroska_doctypes[i], probelen)) + return AVPROBE_SCORE_MAX; + } - return 0; + // probably valid EBML header but no recognized doctype + return AVPROBE_SCORE_MAX/2; } static MatroskaTrack *matroska_find_track_by_num(MatroskaDemuxContext *matroska, @@ -998,14 +1006,14 @@ static void matroska_convert_tag(AVFormatContext *s, EbmlList *list, if (prefix) snprintf(key, sizeof(key), "%s/%s", prefix, tags[i].name); else av_strlcpy(key, tags[i].name, sizeof(key)); if (tags[i].def || !lang) { - av_metadata_set(metadata, key, tags[i].string); + av_metadata_set2(metadata, key, tags[i].string, 0); if (tags[i].sub.nb_elem) matroska_convert_tag(s, &tags[i].sub, metadata, key); } if (lang) { av_strlcat(key, "-", sizeof(key)); av_strlcat(key, lang, sizeof(key)); - av_metadata_set(metadata, key, tags[i].string); + av_metadata_set2(metadata, key, tags[i].string, 0); if (tags[i].sub.nb_elem) matroska_convert_tag(s, &tags[i].sub, metadata, key); } @@ -1136,14 +1144,21 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap) /* 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) || strcmp(ebml.doctype, "matroska") - || ebml.doctype_version > 2) { + || ebml.id_length > sizeof(uint32_t) || ebml.doctype_version > 2) { 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); - return AVERROR_NOFMT; + ebml_free(ebml_syntax, &ebml); + return AVERROR_PATCHWELCOME; } + for (i = 0; i < FF_ARRAY_ELEMS(matroska_doctypes); i++) + if (!strcmp(ebml.doctype, matroska_doctypes[i])) + break; + if (i >= FF_ARRAY_ELEMS(matroska_doctypes)) { + av_log(s, AV_LOG_WARNING, "Unknown EBML doctype '%s'\n", ebml.doctype); + } + av_metadata_set2(&s->metadata, "doctype", ebml.doctype, 0); ebml_free(ebml_syntax, &ebml); /* The next thing is a segment. */ @@ -1154,7 +1169,7 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap) if (matroska->duration) matroska->ctx->duration = matroska->duration * matroska->time_scale * 1000 / AV_TIME_BASE; - av_metadata_set(&s->metadata, "title", matroska->title); + av_metadata_set2(&s->metadata, "title", matroska->title, 0); tracks = matroska->tracks.elem; for (i=0; i < matroska->tracks.nb_elem; i++) { @@ -1244,17 +1259,18 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap) if (!strcmp(track->codec_id, "V_MS/VFW/FOURCC") && 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); + extradata_offset = 40; } else if (!strcmp(track->codec_id, "A_MS/ACM") - && track->codec_priv.size >= 18 + && track->codec_priv.size >= 14 && track->codec_priv.data != NULL) { init_put_byte(&b, track->codec_priv.data, track->codec_priv.size, URL_RDONLY, NULL, NULL, NULL, NULL); ff_get_wav_header(&b, st->codec, track->codec_priv.size); codec_id = st->codec->codec_id; - extradata_offset = 18; - track->codec_priv.size -= extradata_offset; + extradata_offset = FFMIN(track->codec_priv.size, 18); } else if (!strcmp(track->codec_id, "V_QUICKTIME") && (track->codec_priv.size >= 86) && (track->codec_priv.data != NULL)) { @@ -1306,15 +1322,16 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap) } else if (codec_id == CODEC_ID_RV10 || codec_id == CODEC_ID_RV20 || codec_id == CODEC_ID_RV30 || codec_id == CODEC_ID_RV40) { extradata_offset = 26; - track->codec_priv.size -= extradata_offset; } else if (codec_id == CODEC_ID_RA_144) { track->audio.out_samplerate = 8000; track->audio.channels = 1; } else if (codec_id == CODEC_ID_RA_288 || codec_id == CODEC_ID_COOK || - codec_id == CODEC_ID_ATRAC3) { + codec_id == CODEC_ID_ATRAC3 || codec_id == CODEC_ID_SIPR) { + int flavor; init_put_byte(&b, track->codec_priv.data,track->codec_priv.size, 0, NULL, NULL, NULL, NULL); - url_fskip(&b, 24); + url_fskip(&b, 22); + flavor = get_be16(&b); track->audio.coded_framesize = get_be32(&b); url_fskip(&b, 12); track->audio.sub_packet_h = get_be16(&b); @@ -1325,11 +1342,16 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap) st->codec->block_align = track->audio.coded_framesize; track->codec_priv.size = 0; } else { + if (codec_id == CODEC_ID_SIPR && flavor < 4) { + const int sipr_bit_rate[4] = { 6504, 8496, 5000, 16000 }; + track->audio.sub_packet_size = ff_sipr_subpk_size[flavor]; + st->codec->bit_rate = sipr_bit_rate[flavor]; + } st->codec->block_align = track->audio.sub_packet_size; extradata_offset = 78; - track->codec_priv.size -= extradata_offset; } } + track->codec_priv.size -= extradata_offset; if (codec_id == CODEC_ID_NONE) av_log(matroska->ctx, AV_LOG_INFO, @@ -1342,8 +1364,8 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap) st->codec->codec_id = codec_id; st->start_time = 0; if (strcmp(track->language, "und")) - av_metadata_set(&st->metadata, "language", track->language); - av_metadata_set(&st->metadata, "description", track->name); + av_metadata_set2(&st->metadata, "language", track->language, 0); + av_metadata_set2(&st->metadata, "title", track->name, 0); if (track->flag_default) st->disposition |= AV_DISPOSITION_DEFAULT; @@ -1352,22 +1374,24 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap) av_reduce(&st->codec->time_base.num, &st->codec->time_base.den, track->default_duration, 1000000000, 30000); - if(extradata){ - st->codec->extradata = extradata; - st->codec->extradata_size = extradata_size; - } else if(track->codec_priv.data && track->codec_priv.size > 0){ - st->codec->extradata = av_mallocz(track->codec_priv.size + - FF_INPUT_BUFFER_PADDING_SIZE); - if(st->codec->extradata == NULL) - return AVERROR(ENOMEM); - st->codec->extradata_size = track->codec_priv.size; - memcpy(st->codec->extradata, - track->codec_priv.data + extradata_offset, - track->codec_priv.size); + if (!st->codec->extradata) { + if(extradata){ + st->codec->extradata = extradata; + st->codec->extradata_size = extradata_size; + } else if(track->codec_priv.data && track->codec_priv.size > 0){ + st->codec->extradata = av_mallocz(track->codec_priv.size + + FF_INPUT_BUFFER_PADDING_SIZE); + if(st->codec->extradata == NULL) + return AVERROR(ENOMEM); + st->codec->extradata_size = track->codec_priv.size; + memcpy(st->codec->extradata, + track->codec_priv.data + extradata_offset, + track->codec_priv.size); + } } if (track->type == MATROSKA_TRACK_TYPE_VIDEO) { - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_tag = track->video.fourcc; st->codec->width = track->video.pixel_width; st->codec->height = track->video.pixel_height; @@ -1378,12 +1402,16 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap) 255); if (st->codec->codec_id != CODEC_ID_H264) st->need_parsing = AVSTREAM_PARSE_HEADERS; + if (track->default_duration) + st->avg_frame_rate = av_d2q(1000000000.0/track->default_duration, INT_MAX); } else if (track->type == MATROSKA_TRACK_TYPE_AUDIO) { - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->sample_rate = track->audio.out_samplerate; st->codec->channels = track->audio.channels; + if (st->codec->codec_id != CODEC_ID_AAC) + st->need_parsing = AVSTREAM_PARSE_HEADERS; } else if (track->type == MATROSKA_TRACK_TYPE_SUBTITLE) { - st->codec->codec_type = CODEC_TYPE_SUBTITLE; + st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; } } @@ -1396,9 +1424,9 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap) AVStream *st = av_new_stream(s, 0); if (st == NULL) break; - av_metadata_set(&st->metadata, "filename",attachements[j].filename); + av_metadata_set2(&st->metadata, "filename",attachements[j].filename, 0); st->codec->codec_id = CODEC_ID_NONE; - st->codec->codec_type = CODEC_TYPE_ATTACHMENT; + st->codec->codec_type = AVMEDIA_TYPE_ATTACHMENT; st->codec->extradata = av_malloc(attachements[j].bin.size); if(st->codec->extradata == NULL) break; @@ -1424,8 +1452,8 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap) ff_new_chapter(s, chapters[i].uid, (AVRational){1, 1000000000}, chapters[i].start, chapters[i].end, chapters[i].title); - av_metadata_set(&chapters[i].chapter->metadata, - "title", chapters[i].title); + av_metadata_set2(&chapters[i].chapter->metadata, + "title", chapters[i].title, 0); max_start = chapters[i].start; } @@ -1536,7 +1564,7 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, flags = *data++; size -= 3; if (is_keyframe == -1) - is_keyframe = flags & 0x80 ? PKT_FLAG_KEY : 0; + is_keyframe = flags & 0x80 ? AV_PKT_FLAG_KEY : 0; if (cluster_time != (uint64_t)-1 && (block_time >= 0 || cluster_time >= -block_time)) { @@ -1633,9 +1661,11 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, if (res == 0) { for (n = 0; n < laces; n++) { - if (st->codec->codec_id == CODEC_ID_RA_288 || - st->codec->codec_id == CODEC_ID_COOK || - st->codec->codec_id == CODEC_ID_ATRAC3) { + if ((st->codec->codec_id == CODEC_ID_RA_288 || + st->codec->codec_id == CODEC_ID_COOK || + st->codec->codec_id == CODEC_ID_SIPR || + st->codec->codec_id == CODEC_ID_ATRAC3) && + st->codec->block_align && track->audio.sub_packet_size) { int a = st->codec->block_align; int sps = track->audio.sub_packet_size; int cfs = track->audio.coded_framesize; @@ -1649,11 +1679,15 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, for (x=0; xaudio.buf+x*2*w+y*cfs, data+x*cfs, cfs); + else if (st->codec->codec_id == CODEC_ID_SIPR) + memcpy(track->audio.buf + y*w, data, w); else for (x=0; xaudio.buf+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), data+x*sps, sps); if (++track->audio.sub_packet_cnt >= h) { + if (st->codec->codec_id == CODEC_ID_SIPR) + ff_rm_reorder_sipr_data(track->audio.buf, h, w); track->audio.sub_packet_cnt = 0; track->audio.pkt_cnt = h*w / a; } @@ -1672,6 +1706,11 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, int offset = 0, pkt_size = lace_size[n]; uint8_t *pkt_data = data; + if (lace_size[n] > size) { + av_log(matroska->ctx, AV_LOG_ERROR, "Invalid packet size\n"); + break; + } + if (encodings && encodings->scope & 1) { offset = matroska_decode_buffer(&pkt_data,&pkt_size, track); if (offset < 0) @@ -1696,7 +1735,10 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, pkt->flags = is_keyframe; pkt->stream_index = st->index; - pkt->pts = timecode; + if (track->ms_compat) + pkt->dts = timecode; + else + pkt->pts = timecode; pkt->pos = pos; if (st->codec->codec_id == CODEC_ID_TEXT) pkt->convergence_duration = duration; @@ -1720,6 +1762,7 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, if (timecode != AV_NOPTS_VALUE) timecode = duration ? timecode + duration : AV_NOPTS_VALUE; data += lace_size[n]; + size -= lace_size[n]; } } diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/matroskaenc.c b/src/add-ons/media/plugins/ffmpeg/libavformat/matroskaenc.c index a03b11bc3e..c004bd6464 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/matroskaenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/matroskaenc.c @@ -61,18 +61,28 @@ typedef struct { int num_entries; } mkv_cues; +typedef struct { + int write_dts; +} mkv_track; + +#define MODE_MATROSKAv2 0x01 +#define MODE_WEBM 0x02 + typedef struct MatroskaMuxContext { + int mode; + ByteIOContext *dyn_bc; ebml_master segment; int64_t segment_offset; int64_t segment_uid; ebml_master cluster; int64_t cluster_pos; ///< file offset of the current cluster - uint64_t cluster_pts; + int64_t cluster_pts; int64_t duration_offset; - uint64_t duration; + int64_t duration; mkv_seekhead *main_seekhead; mkv_seekhead *cluster_seekhead; mkv_cues *cues; + mkv_track *tracks; struct AVMD5 *md5_ctx; } MatroskaMuxContext; @@ -218,11 +228,8 @@ static void end_ebml_master(ByteIOContext *pb, ebml_master master) { int64_t pos = url_ftell(pb); - // leave the unknown size for masters when streaming - if (url_is_streamed(pb)) + if (url_fseek(pb, master.pos - master.sizebytes, SEEK_SET) < 0) return; - - url_fseek(pb, master.pos - master.sizebytes, SEEK_SET); put_ebml_num(pb, pos - master.pos, master.sizebytes); url_fseek(pb, pos, SEEK_SET); } @@ -291,7 +298,8 @@ static int mkv_add_seekhead_entry(mkv_seekhead *seekhead, unsigned int elementid * be written at the location reserved for it. Otherwise, it is written * at the current location in the file. * - * @return The file offset where the seekhead was written. + * @return The file offset where the seekhead was written, + * -1 if an error occurred. */ static int64_t mkv_write_seekhead(ByteIOContext *pb, mkv_seekhead *seekhead) { @@ -302,7 +310,8 @@ static int64_t mkv_write_seekhead(ByteIOContext *pb, mkv_seekhead *seekhead) currentpos = url_ftell(pb); if (seekhead->reserved_size > 0) - url_fseek(pb, seekhead->filepos, SEEK_SET); + if (url_fseek(pb, seekhead->filepos, SEEK_SET) < 0) + return -1; metaseek = start_ebml_master(pb, MATROSKA_ID_SEEKHEAD, seekhead->reserved_size); for (i = 0; i < seekhead->num_entries; i++) { @@ -342,7 +351,7 @@ static mkv_cues * mkv_start_cues(int64_t segment_offset) return cues; } -static int mkv_add_cuepoint(mkv_cues *cues, AVPacket *pkt, int64_t cluster_pos) +static int mkv_add_cuepoint(mkv_cues *cues, int stream, int64_t ts, int64_t cluster_pos) { mkv_cuepoint *entries = cues->entries; @@ -350,8 +359,11 @@ static int mkv_add_cuepoint(mkv_cues *cues, AVPacket *pkt, int64_t cluster_pos) if (entries == NULL) return AVERROR(ENOMEM); - entries[cues->num_entries ].pts = pkt->pts; - entries[cues->num_entries ].tracknum = pkt->stream_index + 1; + if (ts < 0) + return 0; + + entries[cues->num_entries ].pts = ts; + entries[cues->num_entries ].tracknum = stream + 1; entries[cues->num_entries++].cluster_pos = cluster_pos - cues->segment_offset; cues->entries = entries; @@ -462,35 +474,37 @@ static int mkv_write_codecprivate(AVFormatContext *s, ByteIOContext *pb, AVCodec if (codec->codec_id == CODEC_ID_VORBIS || codec->codec_id == CODEC_ID_THEORA) ret = put_xiph_codecpriv(s, dyn_cp, codec); else if (codec->codec_id == CODEC_ID_FLAC) - ret = ff_flac_write_header(dyn_cp, codec); + ret = ff_flac_write_header(dyn_cp, codec, 1); else if (codec->codec_id == CODEC_ID_H264) ret = ff_isom_write_avcc(dyn_cp, codec->extradata, codec->extradata_size); else if (codec->extradata_size) put_buffer(dyn_cp, codec->extradata, codec->extradata_size); - } else if (codec->codec_type == CODEC_TYPE_VIDEO) { + } else if (codec->codec_type == AVMEDIA_TYPE_VIDEO) { if (qt_id) { if (!codec->codec_tag) codec->codec_tag = ff_codec_get_tag(codec_movvideo_tags, codec->codec_id); if (codec->extradata_size) put_buffer(dyn_cp, codec->extradata, codec->extradata_size); } else { - if (!codec->codec_tag) - codec->codec_tag = ff_codec_get_tag(ff_codec_bmp_tags, codec->codec_id); - if (!codec->codec_tag) { - av_log(s, AV_LOG_ERROR, "No bmp codec ID found."); - ret = -1; + if (!codec->codec_tag) + codec->codec_tag = ff_codec_get_tag(ff_codec_bmp_tags, codec->codec_id); + if (!codec->codec_tag) { + av_log(s, AV_LOG_ERROR, "No bmp codec ID found.\n"); + ret = -1; + } + + ff_put_bmp_header(dyn_cp, codec, ff_codec_bmp_tags, 0); } - ff_put_bmp_header(dyn_cp, codec, ff_codec_bmp_tags, 0); - } - - } else if (codec->codec_type == CODEC_TYPE_AUDIO) { - if (!codec->codec_tag) - codec->codec_tag = ff_codec_get_tag(ff_codec_wav_tags, codec->codec_id); - if (!codec->codec_tag) { - av_log(s, AV_LOG_ERROR, "No wav codec ID found."); + } else if (codec->codec_type == AVMEDIA_TYPE_AUDIO) { + unsigned int tag; + tag = ff_codec_get_tag(ff_codec_wav_tags, codec->codec_id); + if (!tag) { + av_log(s, AV_LOG_ERROR, "No wav codec ID found.\n"); ret = -1; } + if (!codec->codec_tag) + codec->codec_tag = tag; ff_put_wav_header(dyn_cp, codec); } @@ -535,7 +549,7 @@ static int mkv_write_tracks(AVFormatContext *s) put_ebml_uint (pb, MATROSKA_ID_TRACKUID , i + 1); put_ebml_uint (pb, MATROSKA_ID_TRACKFLAGLACING , 0); // no lacing (yet) - if ((tag = av_metadata_get(st->metadata, "description", NULL, 0))) + if ((tag = av_metadata_get(st->metadata, "title", NULL, 0))) put_ebml_string(pb, MATROSKA_ID_TRACKNAME, tag->value); tag = av_metadata_get(st->metadata, "language", NULL, 0); put_ebml_string(pb, MATROSKA_ID_TRACKLANGUAGE, tag ? tag->value:"und"); @@ -553,9 +567,17 @@ static int mkv_write_tracks(AVFormatContext *s) } } + if (mkv->mode == MODE_WEBM && !(codec->codec_id == CODEC_ID_VP8 || + codec->codec_id == CODEC_ID_VORBIS)) { + av_log(s, AV_LOG_ERROR, + "Only VP8 video and Vorbis audio are supported for WebM.\n"); + return AVERROR(EINVAL); + } + switch (codec->codec_type) { - case CODEC_TYPE_VIDEO: + case AVMEDIA_TYPE_VIDEO: put_ebml_uint(pb, MATROSKA_ID_TRACKTYPE, MATROSKA_TRACK_TYPE_VIDEO); + put_ebml_uint(pb, MATROSKA_ID_TRACKDEFAULTDURATION, av_q2d(codec->time_base)*1E9); if (!native_id && ff_codec_get_tag(codec_movvideo_tags, codec->codec_id) && @@ -567,9 +589,11 @@ static int mkv_write_tracks(AVFormatContext *s) if (qt_id) put_ebml_string(pb, MATROSKA_ID_CODECID, "V_QUICKTIME"); - else if (!native_id) + else if (!native_id) { // if there is no mkv-specific codec ID, use VFW mode put_ebml_string(pb, MATROSKA_ID_CODECID, "V_MS/VFW/FOURCC"); + mkv->tracks[i].write_dts = 1; + } subinfo = start_ebml_master(pb, MATROSKA_ID_TRACKVIDEO, 0); // XXX: interlace flag? @@ -583,7 +607,7 @@ static int mkv_write_tracks(AVFormatContext *s) end_ebml_master(pb, subinfo); break; - case CODEC_TYPE_AUDIO: + case AVMEDIA_TYPE_AUDIO: put_ebml_uint(pb, MATROSKA_ID_TRACKTYPE, MATROSKA_TRACK_TYPE_AUDIO); if (!native_id) @@ -600,7 +624,7 @@ static int mkv_write_tracks(AVFormatContext *s) end_ebml_master(pb, subinfo); break; - case CODEC_TYPE_SUBTITLE: + case AVMEDIA_TYPE_SUBTITLE: put_ebml_uint(pb, MATROSKA_ID_TRACKTYPE, MATROSKA_TRACK_TYPE_SUBTITLE); break; default: @@ -619,6 +643,50 @@ static int mkv_write_tracks(AVFormatContext *s) return 0; } +static int mkv_write_chapters(AVFormatContext *s) +{ + MatroskaMuxContext *mkv = s->priv_data; + ByteIOContext *pb = s->pb; + ebml_master chapters, editionentry; + AVRational scale = {1, 1E9}; + int i, ret; + + if (!s->nb_chapters) + return 0; + + ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_CHAPTERS, url_ftell(pb)); + if (ret < 0) return ret; + + chapters = start_ebml_master(pb, MATROSKA_ID_CHAPTERS , 0); + editionentry = start_ebml_master(pb, MATROSKA_ID_EDITIONENTRY, 0); + put_ebml_uint(pb, MATROSKA_ID_EDITIONFLAGDEFAULT, 1); + put_ebml_uint(pb, MATROSKA_ID_EDITIONFLAGHIDDEN , 0); + for (i = 0; i < s->nb_chapters; i++) { + ebml_master chapteratom, chapterdisplay; + AVChapter *c = s->chapters[i]; + AVMetadataTag *t = NULL; + + chapteratom = start_ebml_master(pb, MATROSKA_ID_CHAPTERATOM, 0); + put_ebml_uint(pb, MATROSKA_ID_CHAPTERUID, c->id); + put_ebml_uint(pb, MATROSKA_ID_CHAPTERTIMESTART, + av_rescale_q(c->start, c->time_base, scale)); + put_ebml_uint(pb, MATROSKA_ID_CHAPTERTIMEEND, + av_rescale_q(c->end, c->time_base, scale)); + put_ebml_uint(pb, MATROSKA_ID_CHAPTERFLAGHIDDEN , 0); + put_ebml_uint(pb, MATROSKA_ID_CHAPTERFLAGENABLED, 1); + if ((t = av_metadata_get(c->metadata, "title", NULL, 0))) { + chapterdisplay = start_ebml_master(pb, MATROSKA_ID_CHAPTERDISPLAY, 0); + put_ebml_string(pb, MATROSKA_ID_CHAPSTRING, t->value); + put_ebml_string(pb, MATROSKA_ID_CHAPLANG , "und"); + end_ebml_master(pb, chapterdisplay); + } + end_ebml_master(pb, chapteratom); + } + end_ebml_master(pb, editionentry); + end_ebml_master(pb, chapters); + return 0; +} + static int mkv_write_header(AVFormatContext *s) { MatroskaMuxContext *mkv = s->priv_data; @@ -627,15 +695,19 @@ static int mkv_write_header(AVFormatContext *s) AVMetadataTag *tag; int ret; + if (!strcmp(s->oformat->name, "webm")) mkv->mode = MODE_WEBM; + else mkv->mode = MODE_MATROSKAv2; + mkv->md5_ctx = av_mallocz(av_md5_size); av_md5_init(mkv->md5_ctx); + mkv->tracks = av_mallocz(s->nb_streams * sizeof(*mkv->tracks)); ebml_header = start_ebml_master(pb, EBML_ID_HEADER, 0); put_ebml_uint (pb, EBML_ID_EBMLVERSION , 1); put_ebml_uint (pb, EBML_ID_EBMLREADVERSION , 1); put_ebml_uint (pb, EBML_ID_EBMLMAXIDLENGTH , 4); put_ebml_uint (pb, EBML_ID_EBMLMAXSIZELENGTH , 8); - put_ebml_string (pb, EBML_ID_DOCTYPE , "matroska"); + put_ebml_string (pb, EBML_ID_DOCTYPE , s->oformat->name); put_ebml_uint (pb, EBML_ID_DOCTYPEVERSION , 2); put_ebml_uint (pb, EBML_ID_DOCTYPEREADVERSION , 2); end_ebml_master(pb, ebml_header); @@ -678,13 +750,13 @@ static int mkv_write_header(AVFormatContext *s) ret = mkv_write_tracks(s); if (ret < 0) return ret; - ret = mkv_add_seekhead_entry(mkv->cluster_seekhead, MATROSKA_ID_CLUSTER, url_ftell(pb)); - if (ret < 0) return ret; + if (mkv->mode != MODE_WEBM) { + ret = mkv_write_chapters(s); + if (ret < 0) return ret; + } - mkv->cluster_pos = url_ftell(pb); - mkv->cluster = start_ebml_master(pb, MATROSKA_ID_CLUSTER, 0); - put_ebml_uint(pb, MATROSKA_ID_CLUSTERTIMECODE, 0); - mkv->cluster_pts = 0; + if (url_is_streamed(s->pb)) + mkv_write_seekhead(pb, mkv->main_seekhead); mkv->cues = mkv_start_cues(mkv->segment_offset); if (mkv->cues == NULL) @@ -718,10 +790,9 @@ static int ass_get_duration(const uint8_t *p) return end - start; } -static int mkv_write_ass_blocks(AVFormatContext *s, AVPacket *pkt) +static int mkv_write_ass_blocks(AVFormatContext *s, ByteIOContext *pb, AVPacket *pkt) { MatroskaMuxContext *mkv = s->priv_data; - ByteIOContext *pb = s->pb; int i, layer = 0, max_duration = 0, size, line_size, data_size = pkt->size; uint8_t *start, *end, *data = pkt->data; ebml_master blockgroup; @@ -764,13 +835,14 @@ static int mkv_write_ass_blocks(AVFormatContext *s, AVPacket *pkt) return max_duration; } -static void mkv_write_block(AVFormatContext *s, unsigned int blockid, AVPacket *pkt, int flags) +static void mkv_write_block(AVFormatContext *s, ByteIOContext *pb, + unsigned int blockid, AVPacket *pkt, int flags) { MatroskaMuxContext *mkv = s->priv_data; - ByteIOContext *pb = s->pb; AVCodecContext *codec = s->streams[pkt->stream_index]->codec; uint8_t *data = NULL; int size = pkt->size; + int64_t ts = mkv->tracks[pkt->stream_index].write_dts ? pkt->dts : pkt->pts; av_log(s, AV_LOG_DEBUG, "Writing block at offset %" PRIu64 ", size %d, " "pts %" PRId64 ", dts %" PRId64 ", duration %d, flags %d\n", @@ -783,56 +855,89 @@ static void mkv_write_block(AVFormatContext *s, unsigned int blockid, AVPacket * put_ebml_id(pb, blockid); put_ebml_num(pb, size+4, 0); put_byte(pb, 0x80 | (pkt->stream_index + 1)); // this assumes stream_index is less than 126 - put_be16(pb, pkt->pts - mkv->cluster_pts); + put_be16(pb, ts - mkv->cluster_pts); put_byte(pb, flags); put_buffer(pb, data, size); if (data != pkt->data) av_free(data); } +static void mkv_flush_dynbuf(AVFormatContext *s) +{ + MatroskaMuxContext *mkv = s->priv_data; + int bufsize; + uint8_t *dyn_buf; + + if (!mkv->dyn_bc) + return; + + bufsize = url_close_dyn_buf(mkv->dyn_bc, &dyn_buf); + put_buffer(s->pb, dyn_buf, bufsize); + av_free(dyn_buf); + mkv->dyn_bc = NULL; +} + static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt) { MatroskaMuxContext *mkv = s->priv_data; ByteIOContext *pb = s->pb; AVCodecContext *codec = s->streams[pkt->stream_index]->codec; - int keyframe = !!(pkt->flags & PKT_FLAG_KEY); + int keyframe = !!(pkt->flags & AV_PKT_FLAG_KEY); int duration = pkt->duration; int ret; + int64_t ts = mkv->tracks[pkt->stream_index].write_dts ? pkt->dts : pkt->pts; - // start a new cluster every 5 MB or 5 sec - if (url_ftell(pb) > mkv->cluster_pos + 5*1024*1024 || pkt->pts > mkv->cluster_pts + 5000) { - av_log(s, AV_LOG_DEBUG, "Starting new cluster at offset %" PRIu64 - " bytes, pts %" PRIu64 "\n", url_ftell(pb), pkt->pts); - end_ebml_master(pb, mkv->cluster); + if (ts == AV_NOPTS_VALUE) { + av_log(s, AV_LOG_ERROR, "Can't write packet with unknown timestamp\n"); + return AVERROR(EINVAL); + } + if (url_is_streamed(s->pb)) { + if (!mkv->dyn_bc) + url_open_dyn_buf(&mkv->dyn_bc); + pb = mkv->dyn_bc; + } + + if (!mkv->cluster_pos) { ret = mkv_add_seekhead_entry(mkv->cluster_seekhead, MATROSKA_ID_CLUSTER, url_ftell(pb)); if (ret < 0) return ret; - mkv->cluster_pos = url_ftell(pb); + mkv->cluster_pos = url_ftell(s->pb); mkv->cluster = start_ebml_master(pb, MATROSKA_ID_CLUSTER, 0); - put_ebml_uint(pb, MATROSKA_ID_CLUSTERTIMECODE, pkt->pts); - mkv->cluster_pts = pkt->pts; + put_ebml_uint(pb, MATROSKA_ID_CLUSTERTIMECODE, FFMAX(0, ts)); + mkv->cluster_pts = FFMAX(0, ts); av_md5_update(mkv->md5_ctx, pkt->data, FFMIN(200, pkt->size)); } - if (codec->codec_type != CODEC_TYPE_SUBTITLE) { - mkv_write_block(s, MATROSKA_ID_SIMPLEBLOCK, pkt, keyframe << 7); + if (codec->codec_type != AVMEDIA_TYPE_SUBTITLE) { + mkv_write_block(s, pb, MATROSKA_ID_SIMPLEBLOCK, pkt, keyframe << 7); } else if (codec->codec_id == CODEC_ID_SSA) { - duration = mkv_write_ass_blocks(s, pkt); + duration = mkv_write_ass_blocks(s, pb, pkt); } else { ebml_master blockgroup = start_ebml_master(pb, MATROSKA_ID_BLOCKGROUP, mkv_blockgroup_size(pkt->size)); duration = pkt->convergence_duration; - mkv_write_block(s, MATROSKA_ID_BLOCK, pkt, 0); + mkv_write_block(s, pb, MATROSKA_ID_BLOCK, pkt, 0); put_ebml_uint(pb, MATROSKA_ID_BLOCKDURATION, duration); end_ebml_master(pb, blockgroup); } - if (codec->codec_type == CODEC_TYPE_VIDEO && keyframe) { - ret = mkv_add_cuepoint(mkv->cues, pkt, mkv->cluster_pos); + if (codec->codec_type == AVMEDIA_TYPE_VIDEO && keyframe) { + ret = mkv_add_cuepoint(mkv->cues, pkt->stream_index, ts, mkv->cluster_pos); if (ret < 0) return ret; } - mkv->duration = FFMAX(mkv->duration, pkt->pts + duration); + // start a new cluster every 5 MB or 5 sec, or 32k / 1 sec for streaming + if ((url_is_streamed(s->pb) && (url_ftell(pb) > 32*1024 || ts > mkv->cluster_pts + 1000)) + || url_ftell(pb) > mkv->cluster_pos + 5*1024*1024 || ts > mkv->cluster_pts + 5000) { + av_log(s, AV_LOG_DEBUG, "Starting new cluster at offset %" PRIu64 + " bytes, pts %" PRIu64 "\n", url_ftell(pb), ts); + end_ebml_master(pb, mkv->cluster); + mkv->cluster_pos = 0; + if (mkv->dyn_bc) + mkv_flush_dynbuf(s); + } + + mkv->duration = FFMAX(mkv->duration, ts + duration); return 0; } @@ -843,7 +948,12 @@ static int mkv_write_trailer(AVFormatContext *s) int64_t currentpos, second_seekhead, cuespos; int ret; - end_ebml_master(pb, mkv->cluster); + if (mkv->dyn_bc) { + end_ebml_master(mkv->dyn_bc, mkv->cluster); + mkv_flush_dynbuf(s); + } else if (mkv->cluster_pos) { + end_ebml_master(pb, mkv->cluster); + } if (!url_is_streamed(pb)) { cuespos = mkv_write_cues(pb, mkv->cues, s->nb_streams); @@ -851,8 +961,10 @@ static int mkv_write_trailer(AVFormatContext *s) ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_CUES , cuespos); if (ret < 0) return ret; - ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_SEEKHEAD, second_seekhead); - if (ret < 0) return ret; + if (second_seekhead >= 0) { + ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_SEEKHEAD, second_seekhead); + if (ret < 0) return ret; + } mkv_write_seekhead(pb, mkv->main_seekhead); // update the duration @@ -873,10 +985,12 @@ static int mkv_write_trailer(AVFormatContext *s) end_ebml_master(pb, mkv->segment); av_free(mkv->md5_ctx); + av_free(mkv->tracks); put_flush_packet(pb); return 0; } +#if CONFIG_MATROSKA_MUXER AVOutputFormat matroska_muxer = { "matroska", NULL_IF_CONFIG_SMALL("Matroska file format"), @@ -892,7 +1006,25 @@ AVOutputFormat matroska_muxer = { .codec_tag = (const AVCodecTag* const []){ff_codec_bmp_tags, ff_codec_wav_tags, 0}, .subtitle_codec = CODEC_ID_TEXT, }; +#endif +#if CONFIG_WEBM_MUXER +AVOutputFormat 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, +}; +#endif + +#if CONFIG_MATROSKA_AUDIO_MUXER AVOutputFormat matroska_audio_muxer = { "matroska", NULL_IF_CONFIG_SMALL("Matroska file format"), @@ -907,3 +1039,4 @@ AVOutputFormat matroska_audio_muxer = { .flags = AVFMT_GLOBALHEADER, .codec_tag = (const AVCodecTag* const []){ff_codec_wav_tags, 0}, }; +#endif diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/metadata.c b/src/add-ons/media/plugins/ffmpeg/libavformat/metadata.c index 54c66c9d88..ff7ffe9560 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/metadata.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/metadata.c @@ -46,7 +46,7 @@ av_metadata_get(AVMetadata *m, const char *key, const AVMetadataTag *prev, int f return NULL; } -int av_metadata_set(AVMetadata **pm, const char *key, const char *value) +int av_metadata_set2(AVMetadata **pm, const char *key, const char *value, int flags) { AVMetadata *m= *pm; AVMetadataTag *tag= av_metadata_get(m, key, NULL, AV_METADATA_MATCH_CASE); @@ -55,6 +55,8 @@ int av_metadata_set(AVMetadata **pm, const char *key, const char *value) m=*pm= av_mallocz(sizeof(*m)); if(tag){ + if (flags & AV_METADATA_DONT_OVERWRITE) + return 0; av_free(tag->value); av_free(tag->key); *tag= m->elems[--m->count]; @@ -66,7 +68,13 @@ int av_metadata_set(AVMetadata **pm, const char *key, const char *value) return AVERROR(ENOMEM); } if(value){ + if(flags & AV_METADATA_DONT_STRDUP_KEY){ + m->elems[m->count].key = key; + }else m->elems[m->count].key = av_strdup(key ); + if(flags & AV_METADATA_DONT_STRDUP_VAL){ + m->elems[m->count].value= value; + }else m->elems[m->count].value= av_strdup(value); m->count++; } @@ -78,6 +86,13 @@ int av_metadata_set(AVMetadata **pm, const char *key, const char *value) return 0; } +#if LIBAVFORMAT_VERSION_MAJOR == 52 +int av_metadata_set(AVMetadata **pm, const char *key, const char *value) +{ + return av_metadata_set2(pm, key, value, 0); +} +#endif + void av_metadata_free(AVMetadata **pm) { AVMetadata *m= *pm; @@ -92,7 +107,7 @@ void av_metadata_free(AVMetadata **pm) av_freep(pm); } -static void metadata_conv(AVMetadata **pm, const AVMetadataConv *d_conv, +void metadata_conv(AVMetadata **pm, const AVMetadataConv *d_conv, const AVMetadataConv *s_conv) { /* TODO: use binary search to look up the two conversion tables @@ -107,18 +122,18 @@ static void metadata_conv(AVMetadata **pm, const AVMetadataConv *d_conv, if (s_conv != d_conv) { if (s_conv) for (sc=s_conv; sc->native; sc++) - if (!strcasecmp(key, sc->native)) { - key = sc->generic; - break; - } + if (!strcasecmp(key, sc->native)) { + key = sc->generic; + break; + } if (d_conv) for (dc=d_conv; dc->native; dc++) if (!strcasecmp(key, dc->generic)) { - key = dc->native; - break; - } + key = dc->native; + break; + } } - av_metadata_set(&dst, key, mtag->value); + av_metadata_set2(&dst, key, mtag->value, 0); } av_metadata_free(pm); *pm = dst; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/metadata.h b/src/add-ons/media/plugins/ffmpeg/libavformat/metadata.h index 9ec2265a41..fe7130e8a3 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/metadata.h +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/metadata.h @@ -22,7 +22,7 @@ #define AVFORMAT_METADATA_H /** - * @file libavformat/metadata.h + * @file * internal metadata API header * see avformat.h or the public API! */ @@ -45,4 +45,7 @@ void ff_metadata_demux_compat(AVFormatContext *s); void ff_metadata_mux_compat(AVFormatContext *s); #endif +void metadata_conv(AVMetadata **pm, const AVMetadataConv *d_conv, + const AVMetadataConv *s_conv); + #endif /* AVFORMAT_METADATA_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/metadata_compat.c b/src/add-ons/media/plugins/ffmpeg/libavformat/metadata_compat.c index b05fb04bce..ac99c05c60 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/metadata_compat.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/metadata_compat.c @@ -45,8 +45,11 @@ static const struct { { "creator", SIZE_OFFSET(author) }, { "written_by", SIZE_OFFSET(author) }, { "lead_performer", SIZE_OFFSET(author) }, + { "composer", SIZE_OFFSET(author) }, + { "performer", SIZE_OFFSET(author) }, { "description", SIZE_OFFSET(comment) }, { "albumtitle", SIZE_OFFSET(album) }, + { "date", SIZE_OFFSET(year) }, { "date_written", SIZE_OFFSET(year) }, { "date_released", SIZE_OFFSET(year) }, { "tracknumber", SIZE_OFFSET(track) }, @@ -106,7 +109,7 @@ void ff_metadata_demux_compat(AVFormatContext *ctx) #define FILL_METADATA(s, key, value) { \ if (value && *value && !av_metadata_get(s->metadata, #key, NULL, 0)) \ - av_metadata_set(&s->metadata, #key, value); \ + av_metadata_set2(&s->metadata, #key, value, 0); \ } #define FILL_METADATA_STR(s, key) FILL_METADATA(s, key, s->key) #define FILL_METADATA_INT(s, key) { \ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/mm.c b/src/add-ons/media/plugins/ffmpeg/libavformat/mm.c index 6c621ab493..cb0917a7ab 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/mm.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/mm.c @@ -20,9 +20,9 @@ */ /** - * @file libavformat/mm.c + * @file * American Laser Games MM Format Demuxer - * by Peter Ross (suxen_drol at hotmail dot com) + * by Peter Ross (pross@xvid.org) * * The MM format was used by IBM-PC ports of ALG's "arcade shooter" games, * including Mad Dog McCree and Crime Patrol. @@ -56,19 +56,31 @@ typedef struct { unsigned int audio_pts, video_pts; } MmDemuxContext; -static int mm_probe(AVProbeData *p) +static int probe(AVProbeData *p) { + int len, type, fps, w, h; + if (p->buf_size < MM_HEADER_LEN_AV + MM_PREAMBLE_SIZE) + return 0; /* the first chunk is always the header */ if (AV_RL16(&p->buf[0]) != MM_TYPE_HEADER) return 0; - if (AV_RL32(&p->buf[2]) != MM_HEADER_LEN_V && AV_RL32(&p->buf[2]) != MM_HEADER_LEN_AV) + len = AV_RL32(&p->buf[2]); + if (len != MM_HEADER_LEN_V && len != MM_HEADER_LEN_AV) + return 0; + fps = AV_RL16(&p->buf[8]); + w = AV_RL16(&p->buf[12]); + h = AV_RL16(&p->buf[14]); + if (!fps || fps > 60 || !w || w > 2048 || !h || h > 2048) + return 0; + type = AV_RL16(&p->buf[len]); + if (!type || type > 0x31) return 0; /* only return half certainty since this check is a bit sketchy */ return AVPROBE_SCORE_MAX / 2; } -static int mm_read_header(AVFormatContext *s, +static int read_header(AVFormatContext *s, AVFormatParameters *ap) { MmDemuxContext *mm = s->priv_data; @@ -96,7 +108,7 @@ static int mm_read_header(AVFormatContext *s, st = av_new_stream(s, 0); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_MMVIDEO; st->codec->codec_tag = 0; /* no fourcc */ st->codec->width = width; @@ -108,7 +120,7 @@ static int mm_read_header(AVFormatContext *s, st = av_new_stream(s, 0); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_tag = 0; /* no fourcc */ st->codec->codec_id = CODEC_ID_PCM_U8; st->codec->channels = 1; @@ -121,7 +133,7 @@ static int mm_read_header(AVFormatContext *s, return 0; } -static int mm_read_packet(AVFormatContext *s, +static int read_packet(AVFormatContext *s, AVPacket *pkt) { MmDemuxContext *mm = s->priv_data; @@ -180,7 +192,7 @@ AVInputFormat mm_demuxer = { "mm", NULL_IF_CONFIG_SMALL("American Laser Games MM format"), sizeof(MmDemuxContext), - mm_probe, - mm_read_header, - mm_read_packet, + probe, + read_header, + read_packet, }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/mmf.c b/src/add-ons/media/plugins/ffmpeg/libavformat/mmf.c index 75afa0e31c..540407f659 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/mmf.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/mmf.c @@ -244,7 +244,7 @@ static int mmf_read_header(AVFormatContext *s, if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_ADPCM_YAMAHA; st->codec->sample_rate = rate; st->codec->channels = 1; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/mov.c b/src/add-ons/media/plugins/ffmpeg/libavformat/mov.c index 74698e0547..2edd27e440 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/mov.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/mov.c @@ -86,13 +86,50 @@ static int mov_metadata_trkn(MOVContext *c, ByteIOContext *pb, unsigned len) get_be16(pb); // unknown snprintf(buf, sizeof(buf), "%d", get_be16(pb)); - av_metadata_set(&c->fc->metadata, "track", buf); + av_metadata_set2(&c->fc->metadata, "track", buf, 0); get_be16(pb); // total tracks return 0; } +static const uint32_t mac_to_unicode[128] = { + 0x00C4,0x00C5,0x00C7,0x00C9,0x00D1,0x00D6,0x00DC,0x00E1, + 0x00E0,0x00E2,0x00E4,0x00E3,0x00E5,0x00E7,0x00E9,0x00E8, + 0x00EA,0x00EB,0x00ED,0x00EC,0x00EE,0x00EF,0x00F1,0x00F3, + 0x00F2,0x00F4,0x00F6,0x00F5,0x00FA,0x00F9,0x00FB,0x00FC, + 0x2020,0x00B0,0x00A2,0x00A3,0x00A7,0x2022,0x00B6,0x00DF, + 0x00AE,0x00A9,0x2122,0x00B4,0x00A8,0x2260,0x00C6,0x00D8, + 0x221E,0x00B1,0x2264,0x2265,0x00A5,0x00B5,0x2202,0x2211, + 0x220F,0x03C0,0x222B,0x00AA,0x00BA,0x03A9,0x00E6,0x00F8, + 0x00BF,0x00A1,0x00AC,0x221A,0x0192,0x2248,0x2206,0x00AB, + 0x00BB,0x2026,0x00A0,0x00C0,0x00C3,0x00D5,0x0152,0x0153, + 0x2013,0x2014,0x201C,0x201D,0x2018,0x2019,0x00F7,0x25CA, + 0x00FF,0x0178,0x2044,0x20AC,0x2039,0x203A,0xFB01,0xFB02, + 0x2021,0x00B7,0x201A,0x201E,0x2030,0x00C2,0x00CA,0x00C1, + 0x00CB,0x00C8,0x00CD,0x00CE,0x00CF,0x00CC,0x00D3,0x00D4, + 0xF8FF,0x00D2,0x00DA,0x00DB,0x00D9,0x0131,0x02C6,0x02DC, + 0x00AF,0x02D8,0x02D9,0x02DA,0x00B8,0x02DD,0x02DB,0x02C7, +}; + +static int mov_read_mac_string(MOVContext *c, ByteIOContext *pb, int len, + char *dst, int dstlen) +{ + char *p = dst; + char *end = dst+dstlen-1; + int i; + + for (i = 0; i < len; i++) { + uint8_t t, c = get_byte(pb); + if (c < 0x80 && p < end) + *p++ = c; + else + PUT_UTF8(mac_to_unicode[c-0x80], t, if (p < end) *p++ = t;); + } + *p = 0; + return p - dst; +} + static int mov_read_udta_string(MOVContext *c, ByteIOContext *pb, MOVAtom atom) { #ifdef MOV_EXPORT_ALL_METADATA @@ -100,22 +137,29 @@ static int mov_read_udta_string(MOVContext *c, ByteIOContext *pb, MOVAtom atom) #endif char str[1024], key2[16], language[4] = {0}; const char *key = NULL; - uint16_t str_size; + uint16_t str_size, langcode = 0; + uint32_t data_type = 0; int (*parse)(MOVContext*, ByteIOContext*, unsigned) = 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'): - case MKTAG(0xa9,'w','r','t'): key = "author"; break; + case MKTAG(0xa9,'A','R','T'): key = "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,'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 = "year"; break; + case MKTAG(0xa9,'d','a','y'): key = "date"; break; case MKTAG(0xa9,'g','e','n'): key = "genre"; break; case MKTAG(0xa9,'t','o','o'): - case MKTAG(0xa9,'e','n','c'): key = "muxer"; break; + case MKTAG(0xa9,'e','n','c'): key = "encoder"; break; + case MKTAG( 'd','e','s','c'): key = "description";break; + case MKTAG( 'l','d','e','s'): key = "synopsis"; break; + case MKTAG( 't','v','s','h'): key = "show"; break; + 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; } @@ -124,14 +168,15 @@ static int mov_read_udta_string(MOVContext *c, ByteIOContext *pb, MOVAtom atom) int data_size = get_be32(pb); int tag = get_le32(pb); if (tag == MKTAG('d','a','t','a')) { - get_be32(pb); // type + data_type = get_be32(pb); // type get_be32(pb); // unknown str_size = data_size - 16; atom.size -= 16; } else return 0; } else if (atom.size > 4 && key && !c->itunes_metadata) { str_size = get_be16(pb); // string length - ff_mov_lang_to_iso639(get_be16(pb), language); + langcode = get_be16(pb); + ff_mov_lang_to_iso639(langcode, language); atom.size -= 4; } else str_size = atom.size; @@ -153,12 +198,16 @@ static int mov_read_udta_string(MOVContext *c, ByteIOContext *pb, MOVAtom atom) if (parse) parse(c, pb, str_size); else { - get_buffer(pb, str, str_size); - str[str_size] = 0; - av_metadata_set(&c->fc->metadata, key, str); + if (data_type == 3 || (data_type == 0 && langcode < 0x800)) { // MAC Encoded + mov_read_mac_string(c, pb, str_size, str, sizeof(str)); + } else { + get_buffer(pb, str, str_size); + str[str_size] = 0; + } + av_metadata_set2(&c->fc->metadata, key, str, 0); if (*language && strcmp(language, "und")) { snprintf(key2, sizeof(key2), "%s-%s", key, language); - av_metadata_set(&c->fc->metadata, key2, str); + av_metadata_set2(&c->fc->metadata, key2, str, 0); } } #ifdef DEBUG_METADATA @@ -170,18 +219,45 @@ static int mov_read_udta_string(MOVContext *c, ByteIOContext *pb, MOVAtom atom) return 0; } +static int mov_read_chpl(MOVContext *c, ByteIOContext *pb, MOVAtom atom) +{ + int64_t start; + int i, nb_chapters, str_len; + char str[256+1]; + + if ((atom.size -= 5) < 0) + return 0; + + get_be32(pb); // version + flags + get_be32(pb); // ??? + nb_chapters = get_byte(pb); + + for (i = 0; i < nb_chapters; i++) { + if (atom.size < 9) + return 0; + + start = get_be64(pb); + str_len = get_byte(pb); + + if ((atom.size -= 9+str_len) < 0) + return 0; + + get_buffer(pb, str, str_len); + str[str_len] = 0; + ff_new_chapter(c->fc, i, (AVRational){1,10000000}, start, AV_NOPTS_VALUE, str); + } + return 0; +} + static int mov_read_default(MOVContext *c, ByteIOContext *pb, MOVAtom atom) { int64_t total_size = 0; MOVAtom a; int i; - int err = 0; - - a.offset = atom.offset; if (atom.size < 0) atom.size = INT64_MAX; - while(((total_size + 8) < atom.size) && !url_feof(pb) && !err) { + while (total_size + 8 < atom.size && !url_feof(pb)) { int (*parse)(MOVContext*, ByteIOContext*, MOVAtom) = NULL; a.size = atom.size; a.type=0; @@ -190,12 +266,10 @@ static int mov_read_default(MOVContext *c, ByteIOContext *pb, MOVAtom atom) a.type = get_le32(pb); } total_size += 8; - a.offset += 8; dprintf(c->fc, "type: %08x %.4s sz: %"PRIx64" %"PRIx64" %"PRIx64"\n", a.type, (char*)&a.type, a.size, atom.size, total_size); if (a.size == 1) { /* 64 bit extended size */ a.size = get_be64(pb) - 8; - a.offset += 8; total_size += 8; } if (a.size == 0) { @@ -224,22 +298,24 @@ static int mov_read_default(MOVContext *c, ByteIOContext *pb, MOVAtom atom) } else { int64_t start_pos = url_ftell(pb); int64_t left; - err = parse(c, pb, a); - if (url_is_streamed(pb) && c->found_moov && c->found_mdat) - break; + int err = parse(c, pb, a); + if (err < 0) + return err; + if (c->found_moov && c->found_mdat && + (url_is_streamed(pb) || start_pos + a.size == url_fsize(pb))) + return 0; left = a.size - url_ftell(pb) + start_pos; if (left > 0) /* skip garbage at atom end */ url_fskip(pb, left); } - a.offset += a.size; total_size += a.size; } - if (!err && total_size < atom.size && atom.size < 0x7ffff) + if (total_size < atom.size && atom.size < 0x7ffff) url_fskip(pb, atom.size - total_size); - return err; + return 0; } static int mov_read_dref(MOVContext *c, ByteIOContext *pb, MOVAtom atom) @@ -274,18 +350,33 @@ static int mov_read_dref(MOVContext *c, ByteIOContext *pb, MOVAtom atom) if (dref->type == MKTAG('a','l','i','s') && size > 150) { /* macintosh alias record */ uint16_t volume_len, len; - char volume[28]; int16_t type; url_fskip(pb, 10); volume_len = get_byte(pb); volume_len = FFMIN(volume_len, 27); - get_buffer(pb, volume, 27); - volume[volume_len] = 0; - av_log(c->fc, AV_LOG_DEBUG, "volume %s, len %d\n", volume, volume_len); + get_buffer(pb, dref->volume, 27); + dref->volume[volume_len] = 0; + av_log(c->fc, AV_LOG_DEBUG, "volume %s, len %d\n", dref->volume, volume_len); - url_fskip(pb, 112); + url_fskip(pb, 12); + + len = get_byte(pb); + len = FFMIN(len, 63); + get_buffer(pb, dref->filename, 63); + dref->filename[len] = 0; + av_log(c->fc, AV_LOG_DEBUG, "filename %s, len %d\n", dref->filename, len); + + url_fskip(pb, 16); + + /* read next level up_from_alias/down_to_target */ + dref->nlvl_from = get_be16(pb); + dref->nlvl_to = get_be16(pb); + av_log(c->fc, AV_LOG_DEBUG, "nlvl from %d, nlvl to %d\n", + dref->nlvl_from, dref->nlvl_to); + + url_fskip(pb, 16); for (type = 0; type != -1 && url_ftell(pb) < next; ) { type = get_be16(pb); @@ -299,7 +390,7 @@ static int mov_read_dref(MOVContext *c, ByteIOContext *pb, MOVAtom atom) if (!dref->path) return AVERROR(ENOMEM); get_buffer(pb, dref->path, len); - if (len > volume_len && !strncmp(dref->path, volume, volume_len)) { + if (len > volume_len && !strncmp(dref->path, dref->volume, volume_len)) { len -= volume_len; memmove(dref->path, dref->path+volume_len, len); dref->path[len] = 0; @@ -308,6 +399,17 @@ static int mov_read_dref(MOVContext *c, ByteIOContext *pb, MOVAtom atom) if (dref->path[j] == ':') dref->path[j] = '/'; av_log(c->fc, AV_LOG_DEBUG, "path %s\n", dref->path); + } else if (type == 0) { // directory name + av_free(dref->dir); + dref->dir = av_malloc(len+1); + if (!dref->dir) + return AVERROR(ENOMEM); + get_buffer(pb, dref->dir, len); + dref->dir[len] = 0; + for (j = 0; j < len; j++) + if (dref->dir[j] == ':') + dref->dir[j] = '/'; + av_log(c->fc, AV_LOG_DEBUG, "dir %s\n", dref->dir); } else url_fskip(pb, len); } @@ -339,26 +441,22 @@ static int mov_read_hdlr(MOVContext *c, ByteIOContext *pb, MOVAtom atom) dprintf(c->fc, "stype= %.4s\n", (char*)&type); if (type == MKTAG('v','i','d','e')) - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; else if(type == MKTAG('s','o','u','n')) - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; else if(type == MKTAG('m','1','a',' ')) st->codec->codec_id = CODEC_ID_MP2; else if(type == MKTAG('s','u','b','p')) - st->codec->codec_type = CODEC_TYPE_SUBTITLE; + st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; get_be32(pb); /* component manufacture */ get_be32(pb); /* component flags */ get_be32(pb); /* component flags mask */ - if(atom.size <= 24) - return 0; /* nothing left to read */ - - url_fskip(pb, atom.size - (url_ftell(pb) - atom.offset)); return 0; } -static int mp4_read_descr_len(ByteIOContext *pb) +int ff_mp4_read_descr_len(ByteIOContext *pb) { int len = 0; int count = 4; @@ -371,12 +469,12 @@ static int mp4_read_descr_len(ByteIOContext *pb) return len; } -static int mp4_read_descr(MOVContext *c, ByteIOContext *pb, int *tag) +static int mp4_read_descr(AVFormatContext *fc, ByteIOContext *pb, int *tag) { int len; *tag = get_byte(pb); - len = mp4_read_descr_len(pb); - dprintf(c->fc, "MPEG4 description: tag=0x%02x len=%d\n", *tag, len); + len = ff_mp4_read_descr_len(pb); + dprintf(fc, "MPEG4 description: tag=0x%02x len=%d\n", *tag, len); return len; } @@ -393,24 +491,24 @@ static const AVCodecTag mp4_audio_types[] = { { CODEC_ID_NONE, AOT_NULL }, }; -static int mov_read_esds(MOVContext *c, ByteIOContext *pb, MOVAtom atom) +int ff_mov_read_esds(AVFormatContext *fc, ByteIOContext *pb, MOVAtom atom) { AVStream *st; int tag, len; - if (c->fc->nb_streams < 1) + if (fc->nb_streams < 1) return 0; - st = c->fc->streams[c->fc->nb_streams-1]; + st = fc->streams[fc->nb_streams-1]; get_be32(pb); /* version + flags */ - len = mp4_read_descr(c, pb, &tag); + len = mp4_read_descr(fc, pb, &tag); if (tag == MP4ESDescrTag) { get_be16(pb); /* ID */ get_byte(pb); /* priority */ } else get_be16(pb); /* ID */ - len = mp4_read_descr(c, pb, &tag); + len = mp4_read_descr(fc, pb, &tag); if (tag == MP4DecConfigDescrTag) { int object_type_id = get_byte(pb); get_byte(pb); /* stream type */ @@ -419,10 +517,10 @@ static int mov_read_esds(MOVContext *c, ByteIOContext *pb, MOVAtom atom) get_be32(pb); /* avg bitrate */ st->codec->codec_id= ff_codec_get_id(ff_mp4_obj_type, object_type_id); - dprintf(c->fc, "esds object type id %d\n", object_type_id); - len = mp4_read_descr(c, pb, &tag); + dprintf(fc, "esds object type id 0x%02x\n", object_type_id); + len = mp4_read_descr(fc, pb, &tag); if (tag == MP4DecSpecificDescrTag) { - dprintf(c->fc, "Specific MPEG4 header len=%d\n", len); + dprintf(fc, "Specific MPEG4 header len=%d\n", len); if((uint64_t)len > (1<<30)) return -1; st->codec->extradata = av_mallocz(len + FF_INPUT_BUFFER_PADDING_SIZE); @@ -434,14 +532,12 @@ static int mov_read_esds(MOVContext *c, ByteIOContext *pb, MOVAtom atom) MPEG4AudioConfig cfg; ff_mpeg4audio_get_config(&cfg, st->codec->extradata, st->codec->extradata_size); - if (cfg.chan_config > 7) - return -1; - st->codec->channels = ff_mpeg4audio_channels[cfg.chan_config]; + 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]; else st->codec->sample_rate = cfg.sample_rate; // ext sample rate ? - dprintf(c->fc, "mp4a config channels %d obj %d ext obj %d " + dprintf(fc, "mp4a config channels %d obj %d ext obj %d " "sample rate %d ext sample rate %d\n", st->codec->channels, cfg.object_type, cfg.ext_object_type, cfg.sample_rate, cfg.ext_sample_rate); @@ -454,6 +550,11 @@ static int mov_read_esds(MOVContext *c, ByteIOContext *pb, MOVAtom atom) return 0; } +static int mov_read_esds(MOVContext *c, ByteIOContext *pb, MOVAtom atom) +{ + return ff_mov_read_esds(c->fc, pb, atom); +} + static int mov_read_pasp(MOVContext *c, ByteIOContext *pb, MOVAtom atom) { const int num = get_be32(pb); @@ -485,15 +586,35 @@ static int mov_read_mdat(MOVContext *c, ByteIOContext *pb, MOVAtom atom) return 0; /* now go for moov */ } +/* read major brand, minor version and compatible brands and store them as metadata */ static int mov_read_ftyp(MOVContext *c, ByteIOContext *pb, MOVAtom atom) { - uint32_t type = get_le32(pb); + uint32_t minor_ver; + int comp_brand_size; + char minor_ver_str[11]; /* 32 bit integer -> 10 digits + null */ + char* comp_brands_str; + uint8_t type[5] = {0}; - if (type != MKTAG('q','t',' ',' ')) + get_buffer(pb, type, 4); + if (strcmp(type, "qt ")) c->isom = 1; av_log(c->fc, AV_LOG_DEBUG, "ISO: File Type Major Brand: %.4s\n",(char *)&type); - get_be32(pb); /* minor version */ - url_fskip(pb, atom.size - 8); + av_metadata_set2(&c->fc->metadata, "major_brand", type, 0); + minor_ver = get_be32(pb); /* minor version */ + snprintf(minor_ver_str, sizeof(minor_ver_str), "%d", minor_ver); + av_metadata_set2(&c->fc->metadata, "minor_version", minor_ver_str, 0); + + comp_brand_size = atom.size - 8; + if (comp_brand_size < 0) + return -1; + comp_brands_str = av_malloc(comp_brand_size + 1); /* Add null terminator */ + if (!comp_brands_str) + return AVERROR(ENOMEM); + get_buffer(pb, comp_brands_str, comp_brand_size); + comp_brands_str[comp_brand_size] = 0; + av_metadata_set2(&c->fc->metadata, "compatible_brands", comp_brands_str, 0); + av_freep(&comp_brands_str); + return 0; } @@ -546,7 +667,7 @@ static int mov_read_mdhd(MOVContext *c, ByteIOContext *pb, MOVAtom atom) lang = get_be16(pb); /* language */ if (ff_mov_lang_to_iso639(lang, language)) - av_metadata_set(&st->metadata, "language", language); + av_metadata_set2(&st->metadata, "language", language, 0); get_be16(pb); /* quality */ return 0; @@ -720,6 +841,34 @@ static int mov_read_glbl(MOVContext *c, ByteIOContext *pb, MOVAtom atom) return 0; } +/** + * An strf atom is a BITMAPINFOHEADER struct. This struct is 40 bytes itself, + * but can have extradata appended at the end after the 40 bytes belonging + * to the struct. + */ +static int mov_read_strf(MOVContext *c, ByteIOContext *pb, MOVAtom atom) +{ + AVStream *st; + + if (c->fc->nb_streams < 1) + return 0; + if (atom.size <= 40) + return 0; + st = c->fc->streams[c->fc->nb_streams-1]; + + if((uint64_t)atom.size > (1<<30)) + return -1; + + av_free(st->codec->extradata); + st->codec->extradata = av_mallocz(atom.size - 40 + FF_INPUT_BUFFER_PADDING_SIZE); + if (!st->codec->extradata) + return AVERROR(ENOMEM); + st->codec->extradata_size = atom.size - 40; + url_fskip(pb, 40); + get_buffer(pb, st->codec->extradata, atom.size - 40); + return 0; +} + static int mov_read_stco(MOVContext *c, ByteIOContext *pb, MOVAtom atom) { AVStream *st; @@ -760,7 +909,7 @@ static int mov_read_stco(MOVContext *c, ByteIOContext *pb, MOVAtom atom) * Compute codec id for 'lpcm' tag. * See CoreAudioTypes and AudioStreamBasicDescription at Apple. */ -static enum CodecID mov_get_lpcm_codec_id(int bps, int flags) +enum CodecID ff_mov_get_lpcm_codec_id(int bps, int flags) { if (flags & 1) { // floating point if (flags & 2) { // big endian @@ -811,7 +960,7 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOVAtom atom) //Parsing Sample description table enum CodecID id; int dref_id = 1; - MOVAtom a = { 0, 0, 0 }; + MOVAtom a = { 0 }; int64_t start_pos = url_ftell(pb); int size = get_be32(pb); /* size */ uint32_t format = get_le32(pb); /* data format */ @@ -842,19 +991,19 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOVAtom atom) if (id<=0 && ((format&0xFFFF) == 'm'+('s'<<8) || (format&0xFFFF) == 'T'+('S'<<8))) id = ff_codec_get_id(ff_codec_wav_tags, bswap_32(format)&0xFFFF); - if (st->codec->codec_type != CODEC_TYPE_VIDEO && id > 0) { - st->codec->codec_type = CODEC_TYPE_AUDIO; - } else if (st->codec->codec_type != CODEC_TYPE_AUDIO && /* do not overwrite codec type */ + if (st->codec->codec_type != AVMEDIA_TYPE_VIDEO && id > 0) { + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + } else if (st->codec->codec_type != AVMEDIA_TYPE_AUDIO && /* do not overwrite codec type */ format && format != MKTAG('m','p','4','s')) { /* skip old asf mpeg4 tag */ id = ff_codec_get_id(codec_movvideo_tags, format); if (id <= 0) id = ff_codec_get_id(ff_codec_bmp_tags, format); if (id > 0) - st->codec->codec_type = CODEC_TYPE_VIDEO; - else if(st->codec->codec_type == CODEC_TYPE_DATA){ + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + else if(st->codec->codec_type == AVMEDIA_TYPE_DATA){ id = ff_codec_get_id(ff_codec_movsubtitle_tags, format); if(id > 0) - st->codec->codec_type = CODEC_TYPE_SUBTITLE; + st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; } } @@ -862,9 +1011,8 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOVAtom atom) (format >> 0) & 0xff, (format >> 8) & 0xff, (format >> 16) & 0xff, (format >> 24) & 0xff, st->codec->codec_type); - if(st->codec->codec_type==CODEC_TYPE_VIDEO) { - uint8_t codec_name[32]; - unsigned int color_depth; + if(st->codec->codec_type==AVMEDIA_TYPE_VIDEO) { + unsigned int color_depth, len; int color_greyscale; st->codec->codec_id = id; @@ -882,11 +1030,15 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOVAtom atom) get_be32(pb); /* data size, always 0 */ get_be16(pb); /* frames per samples */ - get_buffer(pb, codec_name, 32); /* codec name, pascal string */ - if (codec_name[0] <= 31) { - memcpy(st->codec->codec_name, &codec_name[1],codec_name[0]); - st->codec->codec_name[codec_name[0]] = 0; - } + len = get_byte(pb); /* codec name, pascal string */ + if (len > 31) + len = 31; + mov_read_mac_string(c, pb, len, st->codec->codec_name, 32); + if (len < 31) + url_fskip(pb, 31 - len); + /* codec_tag YV12 triggers an UV swap in rawdec.c */ + if (!memcmp(st->codec->codec_name, "Planar Y'CbCr 8-bit 4:2:0", 25)) + st->codec->codec_tag=MKTAG('I', '4', '2', '0'); st->codec->bits_per_coded_sample = get_be16(pb); /* depth */ st->codec->color_table_id = get_be16(pb); /* colortable id */ @@ -963,7 +1115,7 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOVAtom atom) } st->codec->palctrl->palette_changed = 1; } - } else if(st->codec->codec_type==CODEC_TYPE_AUDIO) { + } else if(st->codec->codec_type==AVMEDIA_TYPE_AUDIO) { int bits_per_sample, flags; uint16_t version = get_be16(pb); @@ -994,11 +1146,11 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOVAtom atom) st->codec->channels = get_be32(pb); get_be32(pb); /* always 0x7F000000 */ st->codec->bits_per_coded_sample = get_be32(pb); /* bits per channel if sound is uncompressed */ - flags = get_be32(pb); /* lcpm format specific flag */ + flags = get_be32(pb); /* lpcm format specific flag */ sc->bytes_per_frame = get_be32(pb); /* bytes per audio packet if constant */ sc->samples_per_frame = get_be32(pb); /* lpcm frames per audio packet if constant */ if (format == MKTAG('l','p','c','m')) - st->codec->codec_id = mov_get_lpcm_codec_id(st->codec->bits_per_coded_sample, flags); + st->codec->codec_id = ff_mov_get_lpcm_codec_id(st->codec->bits_per_coded_sample, flags); } } @@ -1043,7 +1195,7 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOVAtom atom) 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==CODEC_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 - (url_ftell(pb) - start_pos) }; @@ -1065,7 +1217,7 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOVAtom atom) url_fskip(pb, a.size); } - if(st->codec->codec_type==CODEC_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 */ @@ -1102,7 +1254,7 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOVAtom atom) break; case CODEC_ID_MP2: case CODEC_ID_MP3: - st->codec->codec_type = CODEC_TYPE_AUDIO; /* force type after stsd for m1a hdlr */ + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; /* force type after stsd for m1a hdlr */ st->need_parsing = AVSTREAM_PARSE_FULL; break; case CODEC_ID_GSM: @@ -1256,7 +1408,7 @@ static int mov_read_stsz(MOVContext *c, ByteIOContext *pb, MOVAtom atom) return -1; } - if(entries >= UINT_MAX / sizeof(int)) + if (entries >= UINT_MAX / sizeof(int) || entries >= (UINT_MAX - 4) / field_size) return -1; sc->sample_sizes = av_malloc(entries * sizeof(int)); if (!sc->sample_sizes) @@ -1332,29 +1484,6 @@ static int mov_read_stts(MOVContext *c, ByteIOContext *pb, MOVAtom atom) return 0; } -static int mov_read_cslg(MOVContext *c, ByteIOContext *pb, MOVAtom atom) -{ - AVStream *st; - MOVStreamContext *sc; - - if (c->fc->nb_streams < 1) - return 0; - st = c->fc->streams[c->fc->nb_streams-1]; - sc = st->priv_data; - - get_be32(pb); // version + flags - - sc->dts_shift = get_be32(pb); - dprintf(c->fc, "dts shift %d\n", sc->dts_shift); - - get_be32(pb); // least dts to pts delta - get_be32(pb); // greatest dts to pts delta - get_be32(pb); // pts start - get_be32(pb); // pts end - - return 0; -} - static int mov_read_ctts(MOVContext *c, ByteIOContext *pb, MOVAtom atom) { AVStream *st; @@ -1385,7 +1514,12 @@ static int mov_read_ctts(MOVContext *c, ByteIOContext *pb, MOVAtom atom) sc->ctts_data[i].count = count; sc->ctts_data[i].duration= duration; + if (duration < 0) + sc->dts_shift = FFMAX(sc->dts_shift, -duration); } + + dprintf(c->fc, "dts shift %d\n", sc->dts_shift); + return 0; } @@ -1399,6 +1533,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st) unsigned int stss_index = 0; unsigned int stps_index = 0; unsigned int i, j; + uint64_t stream_size = 0; /* adjust first dts according to edit list */ if (sc->time_offset) { @@ -1413,7 +1548,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st) } /* only use old uncompressed audio chunk demuxing when stts specifies it */ - if (!(st->codec->codec_type == CODEC_TYPE_AUDIO && + if (!(st->codec->codec_type == AVMEDIA_TYPE_AUDIO && sc->stts_count == 1 && sc->stts_data[0].duration == 1)) { unsigned int current_sample = 0; unsigned int stts_sample = 0; @@ -1423,7 +1558,13 @@ static void mov_build_index(MOVContext *mov, AVStream *st) current_dts -= sc->dts_shift; - st->nb_frames = sc->sample_count; + if (sc->sample_count >= UINT_MAX / sizeof(*st->index_entries)) + return; + st->index_entries = av_malloc(sc->sample_count*sizeof(*st->index_entries)); + if (!st->index_entries) + return; + st->index_entries_allocated_size = sc->sample_count*sizeof(*st->index_entries); + for (i = 0; i < sc->chunk_count; i++) { current_offset = sc->chunk_offsets[i]; if (stsc_index + 1 < sc->stsc_count && @@ -1450,14 +1591,19 @@ static void mov_build_index(MOVContext *mov, AVStream *st) sample_size = sc->sample_size > 0 ? sc->sample_size : sc->sample_sizes[current_sample]; if(sc->pseudo_stream_id == -1 || sc->stsc_data[stsc_index].id - 1 == sc->pseudo_stream_id) { - av_add_index_entry(st, current_offset, current_dts, sample_size, distance, - keyframe ? AVINDEX_KEYFRAME : 0); + AVIndexEntry *e = &st->index_entries[st->nb_index_entries++]; + e->pos = current_offset; + e->timestamp = current_dts; + e->size = sample_size; + e->min_distance = distance; + e->flags = keyframe ? AVINDEX_KEYFRAME : 0; dprintf(mov->fc, "AVIndex stream %d, sample %d, offset %"PRIx64", dts %"PRId64", " "size %d, distance %d, keyframe %d\n", st->index, current_sample, current_offset, current_dts, sample_size, distance, keyframe); } current_offset += sample_size; + stream_size += sample_size; current_dts += sc->stts_data[stts_index].duration; distance++; stts_sample++; @@ -1468,22 +1614,55 @@ static void mov_build_index(MOVContext *mov, AVStream *st) } } } + if (st->duration > 0) + st->codec->bit_rate = stream_size*8*sc->time_scale/st->duration; } else { - for (i = 0; i < sc->chunk_count; i++) { - unsigned chunk_samples; + unsigned chunk_samples, total = 0; + // compute total chunk count + for (i = 0; i < sc->stsc_count; i++) { + unsigned count, chunk_count; + + chunk_samples = sc->stsc_data[i].count; + if (sc->samples_per_frame && chunk_samples % sc->samples_per_frame) { + av_log(mov->fc, AV_LOG_ERROR, "error unaligned chunk\n"); + return; + } + + if (sc->samples_per_frame >= 160) { // gsm + count = chunk_samples / sc->samples_per_frame; + } else if (sc->samples_per_frame > 1) { + unsigned samples = (1024/sc->samples_per_frame)*sc->samples_per_frame; + count = (chunk_samples+samples-1) / samples; + } else { + count = (chunk_samples+1023) / 1024; + } + + if (i < sc->stsc_count - 1) + chunk_count = sc->stsc_data[i+1].first - sc->stsc_data[i].first; + else + chunk_count = sc->chunk_count - (sc->stsc_data[i].first - 1); + total += chunk_count * count; + } + + dprintf(mov->fc, "chunk count %d\n", total); + if (total >= UINT_MAX / sizeof(*st->index_entries)) + return; + st->index_entries = av_malloc(total*sizeof(*st->index_entries)); + if (!st->index_entries) + return; + st->index_entries_allocated_size = total*sizeof(*st->index_entries); + + // populate index + for (i = 0; i < sc->chunk_count; i++) { current_offset = sc->chunk_offsets[i]; if (stsc_index + 1 < sc->stsc_count && i + 1 == sc->stsc_data[stsc_index + 1].first) stsc_index++; chunk_samples = sc->stsc_data[stsc_index].count; - if (sc->samples_per_frame && chunk_samples % sc->samples_per_frame) { - av_log(mov->fc, AV_LOG_ERROR, "error unaligned chunk\n"); - return; - } - while (chunk_samples > 0) { + AVIndexEntry *e; unsigned size, samples; if (sc->samples_per_frame >= 160) { // gsm @@ -1500,7 +1679,16 @@ static void mov_build_index(MOVContext *mov, AVStream *st) } } - av_add_index_entry(st, current_offset, current_dts, size, 0, AVINDEX_KEYFRAME); + if (st->nb_index_entries >= total) { + av_log(mov->fc, AV_LOG_ERROR, "wrong chunk count %d\n", total); + return; + } + e = &st->index_entries[st->nb_index_entries++]; + e->pos = current_offset; + e->timestamp = current_dts; + e->size = size; + e->min_distance = 0; + e->flags = AVINDEX_KEYFRAME; dprintf(mov->fc, "AVIndex stream %d, chunk %d, offset %"PRIx64", dts %"PRId64", " "size %d, duration %d\n", st->index, i, current_offset, current_dts, size, samples); @@ -1513,6 +1701,49 @@ static void mov_build_index(MOVContext *mov, AVStream *st) } } +static int mov_open_dref(ByteIOContext **pb, 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; + int i, l; + + /* find a source dir */ + src_path = strrchr(src, '/'); + if (src_path) + src_path++; + else + src_path = src; + + /* find a next level down to target */ + for (i = 0, l = strlen(ref->path) - 1; l >= 0; l--) + if (ref->path[l] == '/') { + if (i == ref->nlvl_to - 1) + break; + else + i++; + } + + /* compose filename if next level down to target was found */ + if (i == ref->nlvl_to - 1 && src_path - src < sizeof(filename)) { + memcpy(filename, src, src_path - src); + filename[src_path - src] = 0; + + for (i = 1; i < ref->nlvl_from; i++) + av_strlcat(filename, "../", 1024); + + av_strlcat(filename, ref->path + l + 1, 1024); + + if (!url_fopen(pb, filename, URL_RDONLY)) + return 0; + } + } + + return AVERROR(ENOENT); +}; + static int mov_read_trak(MOVContext *c, ByteIOContext *pb, MOVAtom atom) { AVStream *st; @@ -1525,7 +1756,7 @@ static int mov_read_trak(MOVContext *c, ByteIOContext *pb, MOVAtom atom) if (!sc) return AVERROR(ENOMEM); st->priv_data = sc; - st->codec->codec_type = CODEC_TYPE_DATA; + st->codec->codec_type = AVMEDIA_TYPE_DATA; sc->ffindex = st->index; if ((ret = mov_read_default(c, pb, atom)) < 0) @@ -1539,12 +1770,16 @@ static int mov_read_trak(MOVContext *c, ByteIOContext *pb, MOVAtom atom) return 0; } - if (!sc->time_scale) + if (!sc->time_scale) { + av_log(c->fc, AV_LOG_WARNING, "stream %d, timescale not set\n", st->index); sc->time_scale = c->time_scale; + if (!sc->time_scale) + sc->time_scale = 1; + } av_set_pts_info(st, 64, 1, sc->time_scale); - if (st->codec->codec_type == CODEC_TYPE_AUDIO && + if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && !st->codec->frame_size && sc->stts_count == 1) { st->codec->frame_size = av_rescale(sc->stts_data[0].duration, st->codec->sample_rate, sc->time_scale); @@ -1554,12 +1789,30 @@ static int mov_read_trak(MOVContext *c, ByteIOContext *pb, MOVAtom atom) mov_build_index(c, st); if (sc->dref_id-1 < sc->drefs_count && sc->drefs[sc->dref_id-1].path) { - if (url_fopen(&sc->pb, sc->drefs[sc->dref_id-1].path, URL_RDONLY) < 0) - av_log(c->fc, AV_LOG_ERROR, "stream %d, error opening file %s: %s\n", - st->index, sc->drefs[sc->dref_id-1].path, strerror(errno)); + MOVDref *dref = &sc->drefs[sc->dref_id - 1]; + if (mov_open_dref(&sc->pb, c->fc->filename, dref) < 0) + av_log(c->fc, AV_LOG_ERROR, + "stream %d, error opening alias: path='%s', dir='%s', " + "filename='%s', volume='%s', nlvl_from=%d, nlvl_to=%d\n", + st->index, dref->path, dref->dir, dref->filename, + dref->volume, dref->nlvl_from, dref->nlvl_to); } else sc->pb = c->fc->pb; + if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (st->codec->width != sc->width || st->codec->height != sc->height) { + AVRational r = av_d2q(((double)st->codec->height * sc->width) / + ((double)st->codec->width * sc->height), INT_MAX); + if (st->sample_aspect_ratio.num) + st->sample_aspect_ratio = av_mul_q(st->sample_aspect_ratio, r); + else + st->sample_aspect_ratio = r; + } + + av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den, + sc->time_scale*st->nb_frames, st->duration, INT_MAX); + } + switch (st->codec->codec_id) { #if CONFIG_H261_DECODER case CODEC_ID_H261: @@ -1730,6 +1983,12 @@ static int mov_read_tfhd(MOVContext *c, ByteIOContext *pb, MOVAtom atom) return 0; } +static int mov_read_chap(MOVContext *c, ByteIOContext *pb, MOVAtom atom) +{ + c->chapter_track = get_be32(pb); + return 0; +} + static int mov_read_trex(MOVContext *c, ByteIOContext *pb, MOVAtom atom) { MOVTrackExt *trex; @@ -1809,7 +2068,7 @@ static int mov_read_trun(MOVContext *c, ByteIOContext *pb, MOVAtom atom) sc->ctts_data[sc->ctts_count].duration = get_be32(pb); sc->ctts_count++; } - if ((keyframe = st->codec->codec_type == CODEC_TYPE_AUDIO || + if ((keyframe = st->codec->codec_type == AVMEDIA_TYPE_AUDIO || (flags & 0x004 && !i && !sample_flags) || sample_flags & 0x2000000)) distance = 0; av_add_index_entry(st, offset, dts, sample_size, distance, @@ -1840,7 +2099,6 @@ static int mov_read_wide(MOVContext *c, ByteIOContext *pb, MOVAtom atom) return 0; } atom.type = get_le32(pb); - atom.offset += 8; atom.size -= 8; if (atom.type != MKTAG('m','d','a','t')) { url_fskip(pb, atom.size); @@ -1886,7 +2144,6 @@ static int mov_read_cmov(MOVContext *c, ByteIOContext *pb, MOVAtom atom) if(init_put_byte(&ctx, moov_data, moov_len, 0, NULL, NULL, NULL, NULL) != 0) goto free_and_return; atom.type = MKTAG('m','o','o','v'); - atom.offset = 0; atom.size = moov_len; #ifdef DEBUG // { int fd = open("/tmp/uncompheader.mov", O_WRONLY | O_CREAT); write(fd, moov_data, moov_len); close(fd); } @@ -1905,9 +2162,13 @@ free_and_return: /* edit list atom */ static int mov_read_elst(MOVContext *c, ByteIOContext *pb, MOVAtom atom) { - MOVStreamContext *sc = c->fc->streams[c->fc->nb_streams-1]->priv_data; + MOVStreamContext *sc; int i, edit_count; + if (c->fc->nb_streams < 1) + return 0; + sc = c->fc->streams[c->fc->nb_streams-1]->priv_data; + get_byte(pb); /* version */ get_be24(pb); /* flags */ edit_count = get_be32(pb); /* entries */ @@ -1935,8 +2196,8 @@ static int mov_read_elst(MOVContext *c, ByteIOContext *pb, MOVAtom atom) static const MOVParseTableEntry mov_default_parse_table[] = { { MKTAG('a','v','s','s'), mov_read_extradata }, +{ MKTAG('c','h','p','l'), mov_read_chpl }, { MKTAG('c','o','6','4'), mov_read_stco }, -{ MKTAG('c','s','l','g'), mov_read_cslg }, { MKTAG('c','t','t','s'), mov_read_ctts }, /* composition time to sample */ { MKTAG('d','i','n','f'), mov_read_default }, { MKTAG('d','r','e','f'), mov_read_dref }, @@ -1965,6 +2226,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = { { MKTAG('s','t','b','l'), mov_read_default }, { MKTAG('s','t','c','o'), mov_read_stco }, { MKTAG('s','t','p','s'), mov_read_stps }, +{ MKTAG('s','t','r','f'), mov_read_strf }, { MKTAG('s','t','s','c'), mov_read_stsc }, { MKTAG('s','t','s','d'), mov_read_stsd }, /* sample description */ { MKTAG('s','t','s','s'), mov_read_stss }, /* sync sample */ @@ -1975,6 +2237,8 @@ static const MOVParseTableEntry mov_default_parse_table[] = { { MKTAG('t','f','h','d'), mov_read_tfhd }, /* track fragment header */ { MKTAG('t','r','a','k'), mov_read_trak }, { MKTAG('t','r','a','f'), mov_read_default }, +{ MKTAG('t','r','e','f'), mov_read_default }, +{ MKTAG('c','h','a','p'), mov_read_chap }, { MKTAG('t','r','e','x'), mov_read_trex }, { MKTAG('t','r','u','n'), mov_read_trun }, { MKTAG('u','d','t','a'), mov_read_default }, @@ -2030,12 +2294,79 @@ static int mov_probe(AVProbeData *p) return score; } +// must be done after parsing all trak because there's no order requirement +static void mov_read_chapters(AVFormatContext *s) +{ + MOVContext *mov = s->priv_data; + AVStream *st = NULL; + MOVStreamContext *sc; + int64_t cur_pos; + uint8_t *title = NULL; + int i, len, i8, i16; + + for (i = 0; i < s->nb_streams; i++) + if (s->streams[i]->id == mov->chapter_track) { + st = s->streams[i]; + break; + } + if (!st) { + av_log(s, AV_LOG_ERROR, "Referenced QT chapter track not found\n"); + return; + } + + st->discard = AVDISCARD_ALL; + sc = st->priv_data; + cur_pos = url_ftell(sc->pb); + + for (i = 0; i < st->nb_index_entries; i++) { + AVIndexEntry *sample = &st->index_entries[i]; + int64_t end = i+1 < st->nb_index_entries ? st->index_entries[i+1].timestamp : st->duration; + + if (url_fseek(sc->pb, sample->pos, SEEK_SET) != sample->pos) { + av_log(s, AV_LOG_ERROR, "Chapter %d not found in file\n", i); + goto finish; + } + + title = av_malloc(sample->size+2); + get_buffer(sc->pb, title, sample->size); + + // the first two bytes are the length of the title + len = AV_RB16(title); + if (len > sample->size-2) + continue; + + // 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 + if (AV_RB16(title+2) == 0xfeff) { + uint8_t *utf8 = av_malloc(2*len+3); + + i8 = i16 = 0; + while (i16 < len) { + uint32_t ch; + uint8_t tmp; + GET_UTF16(ch, i16 < len ? AV_RB16(title + (i16+=2)) : 0, break;) + PUT_UTF8(ch, tmp, if (i8 < 2*len) utf8[2+i8++] = tmp;) + } + utf8[2+i8] = 0; + av_freep(&title); + title = utf8; + } + + ff_new_chapter(s, i, st->time_base, sample->timestamp, end, title+2); + av_freep(&title); + } +finish: + av_free(title); + url_fseek(sc->pb, cur_pos, SEEK_SET); +} + static int mov_read_header(AVFormatContext *s, AVFormatParameters *ap) { MOVContext *mov = s->priv_data; ByteIOContext *pb = s->pb; int err; - MOVAtom atom = { 0, 0, 0 }; + MOVAtom atom = { 0 }; mov->fc = s; /* .mov and .mp4 aren't streamable anyway (only progressive download if moov is before mdat) */ @@ -2055,6 +2386,9 @@ static int mov_read_header(AVFormatContext *s, AVFormatParameters *ap) } dprintf(mov->fc, "on_parse_exit_offset=%lld\n", url_ftell(pb)); + if (!url_is_streamed(pb) && mov->chapter_track > 0) + mov_read_chapters(s); + return 0; } @@ -2096,7 +2430,7 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) if (!sample) { mov->found_mdat = 0; if (!url_is_streamed(s->pb) || - mov_read_default(mov, s->pb, (MOVAtom){ 0, 0, INT64_MAX }) < 0 || + mov_read_default(mov, s->pb, (MOVAtom){ 0, INT64_MAX }) < 0 || url_feof(s->pb)) return AVERROR_EOF; dprintf(s, "read fragments, offset 0x%llx\n", url_ftell(s->pb)); @@ -2148,25 +2482,25 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) } if (st->discard == AVDISCARD_ALL) goto retry; - pkt->flags |= sample->flags & AVINDEX_KEYFRAME ? PKT_FLAG_KEY : 0; + pkt->flags |= sample->flags & AVINDEX_KEYFRAME ? AV_PKT_FLAG_KEY : 0; pkt->pos = sample->pos; dprintf(s, "stream %d, pts %"PRId64", dts %"PRId64", pos 0x%"PRIx64", duration %d\n", pkt->stream_index, pkt->pts, pkt->dts, pkt->pos, pkt->duration); return 0; } -static int mov_seek_stream(AVStream *st, int64_t timestamp, int flags) +static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp, int flags) { MOVStreamContext *sc = st->priv_data; int sample, time_sample; int i; sample = av_index_search_timestamp(st, timestamp, flags); - dprintf(st->codec, "stream %d, timestamp %"PRId64", sample %d\n", st->index, timestamp, sample); + dprintf(s, "stream %d, timestamp %"PRId64", sample %d\n", st->index, timestamp, sample); if (sample < 0) /* not sure what to do */ return -1; sc->current_sample = sample; - dprintf(st->codec, "stream %d, found sample %d\n", st->index, sc->current_sample); + dprintf(s, "stream %d, found sample %d\n", st->index, sc->current_sample); /* adjust ctts index */ if (sc->ctts_data) { time_sample = 0; @@ -2196,7 +2530,7 @@ static int mov_read_seek(AVFormatContext *s, int stream_index, int64_t sample_ti sample_time = 0; st = s->streams[stream_index]; - sample = mov_seek_stream(st, sample_time, flags); + sample = mov_seek_stream(s, st, sample_time, flags); if (sample < 0) return -1; @@ -2209,7 +2543,7 @@ static int mov_read_seek(AVFormatContext *s, int stream_index, int64_t sample_ti continue; timestamp = av_rescale_q(seek_timestamp, s->streams[stream_index]->time_base, st->time_base); - mov_seek_stream(st, timestamp, flags); + mov_seek_stream(s, st, timestamp, flags); } return 0; } @@ -2224,8 +2558,10 @@ static int mov_read_close(AVFormatContext *s) MOVStreamContext *sc = st->priv_data; av_freep(&sc->ctts_data); - for (j = 0; j < sc->drefs_count; j++) + for (j = 0; j < sc->drefs_count; j++) { av_freep(&sc->drefs[j].path); + av_freep(&sc->drefs[j].dir); + } av_freep(&sc->drefs); if (sc->pb && sc->pb != s->pb) url_fclose(sc->pb); diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/movenc.c b/src/add-ons/media/plugins/ffmpeg/libavformat/movenc.c index 5cd014d264..00f69902c4 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/movenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/movenc.c @@ -21,6 +21,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "movenc.h" #include "avformat.h" #include "riff.h" #include "avio.h" @@ -28,67 +29,12 @@ #include "avc.h" #include "libavcodec/get_bits.h" #include "libavcodec/put_bits.h" +#include "internal.h" +#include "libavutil/avstring.h" #undef NDEBUG #include -#define MOV_INDEX_CLUSTER_SIZE 16384 -#define globalTimescale 1000 - -#define MODE_MP4 0x01 -#define MODE_MOV 0x02 -#define MODE_3GP 0x04 -#define MODE_PSP 0x08 // example working PSP command line: -// ffmpeg -i testinput.avi -f psp -r 14.985 -s 320x240 -b 768 -ar 24000 -ab 32 M4V00001.MP4 -#define MODE_3G2 0x10 -#define MODE_IPOD 0x20 - -typedef struct MOVIentry { - unsigned int size; - uint64_t pos; - unsigned int samplesInChunk; - unsigned int entries; - int cts; - int64_t dts; -#define MOV_SYNC_SAMPLE 0x0001 -#define MOV_PARTIAL_SYNC_SAMPLE 0x0002 - uint32_t flags; -} MOVIentry; - -typedef struct MOVIndex { - int mode; - int entry; - long timescale; - long time; - int64_t trackDuration; - long sampleCount; - long sampleSize; - int hasKeyframes; -#define MOV_TRACK_CTTS 0x0001 -#define MOV_TRACK_STPS 0x0002 - uint32_t flags; - int language; - int trackID; - int tag; ///< stsd fourcc - AVCodecContext *enc; - - int vosLen; - uint8_t *vosData; - MOVIentry *cluster; - int audio_vbr; - int height; ///< active picture (w/o VBI) height for D-10/IMX -} MOVTrack; - -typedef struct MOVMuxContext { - int mode; - int64_t time; - int nb_streams; - int64_t mdat_pos; - uint64_t mdat_size; - long timescale; - MOVTrack *tracks; -} MOVMuxContext; - //FIXME support 64 bit variant with wide placeholders static int64_t updateSize(ByteIOContext *pb, int64_t pos) { @@ -334,7 +280,7 @@ static int mov_write_esds_tag(ByteIOContext *pb, MOVTrack *track) // Basic // the following fields is made of 6 bits to identify the streamtype (4 for video, 5 for audio) // plus 1 bit to indicate upstream and 1 bit set to 1 (reserved) - if(track->enc->codec_type == CODEC_TYPE_AUDIO) + if(track->enc->codec_type == AVMEDIA_TYPE_AUDIO) put_byte(pb, 0x15); // flags (= Audiostream) else put_byte(pb, 0x11); // flags (= Visualstream) @@ -360,6 +306,14 @@ static int mov_write_esds_tag(ByteIOContext *pb, MOVTrack *track) // Basic return updateSize(pb, pos); } +static int mov_pcm_le_gt16(enum CodecID codec_id) +{ + return codec_id == CODEC_ID_PCM_S24LE || + codec_id == CODEC_ID_PCM_S32LE || + codec_id == CODEC_ID_PCM_F32LE || + codec_id == CODEC_ID_PCM_F64LE; +} + static int mov_write_wave_tag(ByteIOContext *pb, MOVTrack *track) { int64_t pos = url_ftell(pb); @@ -377,8 +331,7 @@ static int mov_write_wave_tag(ByteIOContext *pb, MOVTrack *track) put_tag(pb, "mp4a"); put_be32(pb, 0); mov_write_esds_tag(pb, track); - } else if (track->enc->codec_id == CODEC_ID_PCM_S24LE || - track->enc->codec_id == CODEC_ID_PCM_S32LE) { + } else if (mov_pcm_le_gt16(track->enc->codec_id)) { mov_write_enda_tag(pb); } else if (track->enc->codec_id == CODEC_ID_AMR_NB) { mov_write_amr_tag(pb, track); @@ -402,16 +355,53 @@ static int mov_write_glbl_tag(ByteIOContext *pb, MOVTrack *track) return 8+track->vosLen; } +/** + * Compute flags for 'lpcm' tag. + * See CoreAudioTypes and AudioStreamBasicDescription at Apple. + */ +static int mov_get_lpcm_flags(enum CodecID codec_id) +{ + switch (codec_id) { + case CODEC_ID_PCM_F32BE: + case CODEC_ID_PCM_F64BE: + return 11; + case CODEC_ID_PCM_F32LE: + case CODEC_ID_PCM_F64LE: + return 9; + case CODEC_ID_PCM_U8: + return 10; + case CODEC_ID_PCM_S16BE: + case CODEC_ID_PCM_S24BE: + case CODEC_ID_PCM_S32BE: + return 14; + case CODEC_ID_PCM_S8: + case CODEC_ID_PCM_S16LE: + case CODEC_ID_PCM_S24LE: + case CODEC_ID_PCM_S32LE: + return 12; + default: + return 0; + } +} + static int mov_write_audio_tag(ByteIOContext *pb, MOVTrack *track) { int64_t pos = url_ftell(pb); - int version = track->mode == MODE_MOV && - (track->audio_vbr || - track->enc->codec_id == CODEC_ID_PCM_S32LE || - track->enc->codec_id == CODEC_ID_PCM_S24LE); + int version = 0; + uint32_t tag = track->tag; + + if (track->mode == MODE_MOV) { + if (track->timescale > UINT16_MAX) { + if (mov_get_lpcm_flags(track->enc->codec_id)) + tag = AV_RL32("lpcm"); + version = 2; + } else if (track->audio_vbr || mov_pcm_le_gt16(track->enc->codec_id)) { + version = 1; + } + } put_be32(pb, 0); /* size */ - put_le32(pb, track->tag); // store it byteswapped + put_le32(pb, tag); // store it byteswapped put_be32(pb, 0); /* Reserved */ put_be16(pb, 0); /* Reserved */ put_be16(pb, 1); /* Data-reference index, XXX == 1 */ @@ -421,23 +411,39 @@ static int mov_write_audio_tag(ByteIOContext *pb, MOVTrack *track) put_be16(pb, 0); /* Revision level */ put_be32(pb, 0); /* Reserved */ - if (track->mode == MODE_MOV) { - put_be16(pb, track->enc->channels); - if (track->enc->codec_id == CODEC_ID_PCM_U8 || - track->enc->codec_id == CODEC_ID_PCM_S8) - put_be16(pb, 8); /* bits per sample */ - else - put_be16(pb, 16); - put_be16(pb, track->audio_vbr ? -2 : 0); /* compression ID */ - } else { /* reserved for mp4/3gp */ - put_be16(pb, 2); + if (version == 2) { + put_be16(pb, 3); put_be16(pb, 16); + put_be16(pb, 0xfffe); put_be16(pb, 0); - } + put_be32(pb, 0x00010000); + put_be32(pb, 72); + put_be64(pb, av_dbl2int(track->timescale)); + put_be32(pb, track->enc->channels); + put_be32(pb, 0x7F000000); + put_be32(pb, av_get_bits_per_sample(track->enc->codec_id)); + put_be32(pb, mov_get_lpcm_flags(track->enc->codec_id)); + put_be32(pb, track->sampleSize); + put_be32(pb, track->enc->frame_size); + } else { + if (track->mode == MODE_MOV) { + put_be16(pb, track->enc->channels); + if (track->enc->codec_id == CODEC_ID_PCM_U8 || + track->enc->codec_id == CODEC_ID_PCM_S8) + put_be16(pb, 8); /* bits per sample */ + else + put_be16(pb, 16); + put_be16(pb, track->audio_vbr ? -2 : 0); /* compression ID */ + } else { /* reserved for mp4/3gp */ + put_be16(pb, 2); + put_be16(pb, 16); + put_be16(pb, 0); + } - put_be16(pb, 0); /* packet size (= 0) */ - put_be16(pb, track->timescale); /* Time scale */ - put_be16(pb, 0); /* Reserved */ + put_be16(pb, 0); /* packet size (= 0) */ + put_be16(pb, track->timescale); /* Time scale */ + put_be16(pb, 0); /* Reserved */ + } if(version == 1) { /* SoundDescription V1 extended info */ put_be32(pb, track->enc->frame_size); /* Samples per packet */ @@ -450,9 +456,8 @@ static int mov_write_audio_tag(ByteIOContext *pb, MOVTrack *track) (track->enc->codec_id == CODEC_ID_AAC || track->enc->codec_id == CODEC_ID_AC3 || track->enc->codec_id == CODEC_ID_AMR_NB || - track->enc->codec_id == CODEC_ID_PCM_S24LE || - track->enc->codec_id == CODEC_ID_PCM_S32LE || - track->enc->codec_id == CODEC_ID_ALAC)) + track->enc->codec_id == CODEC_ID_ALAC || + mov_pcm_le_gt16(track->enc->codec_id))) mov_write_wave_tag(pb, track); else if(track->tag == MKTAG('m','p','4','a')) mov_write_esds_tag(pb, track); @@ -562,8 +567,8 @@ static int mp4_get_codec_tag(AVFormatContext *s, MOVTrack *track) else if (track->enc->codec_id == CODEC_ID_AC3) tag = MKTAG('a','c','-','3'); else if (track->enc->codec_id == CODEC_ID_DIRAC) tag = MKTAG('d','r','a','c'); else if (track->enc->codec_id == CODEC_ID_MOV_TEXT) tag = MKTAG('t','x','3','g'); - else if (track->enc->codec_type == CODEC_TYPE_VIDEO) tag = MKTAG('m','p','4','v'); - else if (track->enc->codec_type == CODEC_TYPE_AUDIO) tag = MKTAG('m','p','4','a'); + else if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO) tag = MKTAG('m','p','4','v'); + else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) tag = MKTAG('m','p','4','a'); return tag; } @@ -584,12 +589,12 @@ static int ipod_get_codec_tag(AVFormatContext *s, MOVTrack *track) int tag = track->enc->codec_tag; // keep original tag for subs, ipod supports both formats - if (!(track->enc->codec_type == CODEC_TYPE_SUBTITLE && + if (!(track->enc->codec_type == AVMEDIA_TYPE_SUBTITLE && (tag == MKTAG('t','x','3','g') || tag == MKTAG('t','e','x','t')))) tag = ff_codec_get_tag(codec_ipod_tags, track->enc->codec_id); - if (!match_ext(s->filename, "m4a") && !match_ext(s->filename, "m4v")) + if (!av_match_ext(s->filename, "m4a") && !av_match_ext(s->filename, "m4v")) av_log(s, AV_LOG_WARNING, "Warning, extension is not .m4a nor .m4v " "Quicktime/Ipod might not play the file\n"); @@ -656,7 +661,7 @@ static int mov_get_codec_tag(AVFormatContext *s, MOVTrack *track) tag = mov_get_dv_codec_tag(s, track); else if (track->enc->codec_id == CODEC_ID_RAWVIDEO) tag = mov_get_rawvideo_codec_tag(s, track); - else if (track->enc->codec_type == CODEC_TYPE_VIDEO) { + else if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO) { tag = ff_codec_get_tag(codec_movvideo_tags, track->enc->codec_id); if (!tag) { // if no mac fcc found, try with Microsoft tags tag = ff_codec_get_tag(ff_codec_bmp_tags, track->enc->codec_id); @@ -664,7 +669,7 @@ static int mov_get_codec_tag(AVFormatContext *s, MOVTrack *track) av_log(s, AV_LOG_INFO, "Warning, using MS style video codec tag, " "the file may be unplayable!\n"); } - } else if (track->enc->codec_type == CODEC_TYPE_AUDIO) { + } else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) { tag = ff_codec_get_tag(codec_movaudio_tags, track->enc->codec_id); if (!tag) { // if no mac fcc found, try with Microsoft tags int ms_tag = ff_codec_get_tag(ff_codec_wav_tags, track->enc->codec_id); @@ -674,7 +679,7 @@ static int mov_get_codec_tag(AVFormatContext *s, MOVTrack *track) "the file may be unplayable!\n"); } } - } else if (track->enc->codec_type == CODEC_TYPE_SUBTITLE) + } else if (track->enc->codec_type == AVMEDIA_TYPE_SUBTITLE) tag = ff_codec_get_tag(ff_codec_movsubtitle_tags, track->enc->codec_id); } @@ -803,6 +808,26 @@ static int mov_write_video_tag(ByteIOContext *pb, MOVTrack *track) return updateSize(pb, pos); } +static int mov_write_rtp_tag(ByteIOContext *pb, MOVTrack *track) +{ + int64_t pos = url_ftell(pb); + put_be32(pb, 0); /* size */ + put_tag(pb, "rtp "); + put_be32(pb, 0); /* Reserved */ + put_be16(pb, 0); /* Reserved */ + put_be16(pb, 1); /* Data-reference index */ + + put_be16(pb, 1); /* Hint track version */ + put_be16(pb, 1); /* Highest compatible version */ + put_be32(pb, track->max_packet_size); /* Max packet size */ + + put_be32(pb, 12); /* size */ + put_tag(pb, "tims"); + put_be32(pb, track->timescale); + + return updateSize(pb, pos); +} + static int mov_write_stsd_tag(ByteIOContext *pb, MOVTrack *track) { int64_t pos = url_ftell(pb); @@ -810,12 +835,14 @@ static int mov_write_stsd_tag(ByteIOContext *pb, MOVTrack *track) put_tag(pb, "stsd"); put_be32(pb, 0); /* version & flags */ put_be32(pb, 1); /* entry count */ - if (track->enc->codec_type == CODEC_TYPE_VIDEO) + if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO) mov_write_video_tag(pb, track); - else if (track->enc->codec_type == CODEC_TYPE_AUDIO) + else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) mov_write_audio_tag(pb, track); - else if (track->enc->codec_type == CODEC_TYPE_SUBTITLE) + else if (track->enc->codec_type == AVMEDIA_TYPE_SUBTITLE) mov_write_subtitle_tag(pb, track); + else if (track->enc->codec_tag == MKTAG('r','t','p',' ')) + mov_write_rtp_tag(pb, track); return updateSize(pb, pos); } @@ -860,7 +887,7 @@ static int mov_write_stts_tag(ByteIOContext *pb, MOVTrack *track) uint32_t atom_size; int i; - if (track->enc->codec_type == CODEC_TYPE_AUDIO && !track->audio_vbr) { + if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO && !track->audio_vbr) { stts_entries = av_malloc(sizeof(*stts_entries)); /* one entry */ stts_entries[0].count = track->sampleCount; stts_entries[0].duration = 1; @@ -915,12 +942,13 @@ static int mov_write_stbl_tag(ByteIOContext *pb, MOVTrack *track) put_tag(pb, "stbl"); mov_write_stsd_tag(pb, track); mov_write_stts_tag(pb, track); - if (track->enc->codec_type == CODEC_TYPE_VIDEO && + if ((track->enc->codec_type == AVMEDIA_TYPE_VIDEO || + track->enc->codec_tag == MKTAG('r','t','p',' ')) && track->hasKeyframes && track->hasKeyframes < track->entry) mov_write_stss_tag(pb, track, MOV_SYNC_SAMPLE); if (track->mode == MODE_MOV && track->flags & MOV_TRACK_STPS) mov_write_stss_tag(pb, track, MOV_PARTIAL_SYNC_SAMPLE); - if (track->enc->codec_type == CODEC_TYPE_VIDEO && + if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO && track->flags & MOV_TRACK_CTTS) mov_write_ctts_tag(pb, track); mov_write_stsc_tag(pb, track); @@ -992,16 +1020,19 @@ static int mov_write_hdlr_tag(ByteIOContext *pb, MOVTrack *track) descr = "DataHandler"; } else { hdlr = (track->mode == MODE_MOV) ? "mhlr" : "\0\0\0\0"; - if (track->enc->codec_type == CODEC_TYPE_VIDEO) { + if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO) { hdlr_type = "vide"; descr = "VideoHandler"; - } else if (track->enc->codec_type == CODEC_TYPE_AUDIO) { + } else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) { hdlr_type = "soun"; descr = "SoundHandler"; - } else if (track->enc->codec_type == CODEC_TYPE_SUBTITLE) { + } else if (track->enc->codec_type == AVMEDIA_TYPE_SUBTITLE) { if (track->tag == MKTAG('t','x','3','g')) hdlr_type = "sbtl"; else hdlr_type = "text"; descr = "SubtitleHandler"; + } else if (track->enc->codec_tag == MKTAG('r','t','p',' ')) { + hdlr_type = "hint"; + descr = "HintHandler"; } } @@ -1021,18 +1052,35 @@ static int mov_write_hdlr_tag(ByteIOContext *pb, MOVTrack *track) return updateSize(pb, pos); } +static int mov_write_hmhd_tag(ByteIOContext *pb) +{ + /* This atom must be present, but leaving the values at zero + * seems harmless. */ + put_be32(pb, 28); /* size */ + put_tag(pb, "hmhd"); + put_be32(pb, 0); /* version, flags */ + put_be16(pb, 0); /* maxPDUsize */ + put_be16(pb, 0); /* avgPDUsize */ + put_be32(pb, 0); /* maxbitrate */ + put_be32(pb, 0); /* avgbitrate */ + put_be32(pb, 0); /* reserved */ + return 28; +} + static int mov_write_minf_tag(ByteIOContext *pb, MOVTrack *track) { int64_t pos = url_ftell(pb); put_be32(pb, 0); /* size */ put_tag(pb, "minf"); - if(track->enc->codec_type == CODEC_TYPE_VIDEO) + if(track->enc->codec_type == AVMEDIA_TYPE_VIDEO) mov_write_vmhd_tag(pb); - else if (track->enc->codec_type == CODEC_TYPE_AUDIO) + else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) mov_write_smhd_tag(pb); - else if (track->enc->codec_type == CODEC_TYPE_SUBTITLE) { + else if (track->enc->codec_type == AVMEDIA_TYPE_SUBTITLE) { if (track->tag == MKTAG('t','e','x','t')) mov_write_gmhd_tag(pb); else mov_write_nmhd_tag(pb); + } else if (track->tag == MKTAG('r','t','p',' ')) { + mov_write_hmhd_tag(pb); } if (track->mode == MODE_MOV) /* FIXME: Why do it for MODE_MOV only ? */ mov_write_hdlr_tag(pb, NULL); @@ -1084,7 +1132,8 @@ static int mov_write_mdia_tag(ByteIOContext *pb, MOVTrack *track) static int mov_write_tkhd_tag(ByteIOContext *pb, MOVTrack *track, AVStream *st) { - int64_t duration = av_rescale_rnd(track->trackDuration, globalTimescale, track->timescale, AV_ROUND_UP); + int64_t duration = av_rescale_rnd(track->trackDuration, MOV_TIMESCALE, + track->timescale, AV_ROUND_UP); int version = duration < INT32_MAX ? 0 : 1; (version == 1) ? put_be32(pb, 104) : put_be32(pb, 92); /* size */ @@ -1106,7 +1155,7 @@ static int mov_write_tkhd_tag(ByteIOContext *pb, MOVTrack *track, AVStream *st) put_be32(pb, 0); /* reserved */ put_be32(pb, 0x0); /* reserved (Layer & Alternate group) */ /* Volume, only for audio */ - if(track->enc->codec_type == CODEC_TYPE_AUDIO) + if(track->enc->codec_type == AVMEDIA_TYPE_AUDIO) put_be16(pb, 0x0100); else put_be16(pb, 0); @@ -1124,8 +1173,8 @@ static int mov_write_tkhd_tag(ByteIOContext *pb, MOVTrack *track, AVStream *st) put_be32(pb, 0x40000000); /* reserved */ /* Track width and height, for visual only */ - if(track->enc->codec_type == CODEC_TYPE_VIDEO || - track->enc->codec_type == CODEC_TYPE_SUBTITLE) { + if(st && (track->enc->codec_type == AVMEDIA_TYPE_VIDEO || + track->enc->codec_type == AVMEDIA_TYPE_SUBTITLE)) { double sample_aspect_ratio = av_q2d(st->sample_aspect_ratio); if(!sample_aspect_ratio || track->height != track->enc->height) sample_aspect_ratio = 1; @@ -1149,13 +1198,25 @@ static int mov_write_edts_tag(ByteIOContext *pb, MOVTrack *track) put_be32(pb, 0x0); put_be32(pb, 0x1); - put_be32(pb, av_rescale_rnd(track->trackDuration, globalTimescale, track->timescale, AV_ROUND_UP)); /* duration ... doesn't seem to effect psp */ + /* duration ... doesn't seem to effect psp */ + put_be32(pb, av_rescale_rnd(track->trackDuration, MOV_TIMESCALE, + track->timescale, AV_ROUND_UP)); put_be32(pb, track->cluster[0].cts); /* first pts is cts since dts is 0 */ put_be32(pb, 0x00010000); return 0x24; } +static int mov_write_tref_tag(ByteIOContext *pb, MOVTrack *track) +{ + put_be32(pb, 20); // size + put_tag(pb, "tref"); + put_be32(pb, 12); // size (subatom) + put_le32(pb, track->tref_tag); + put_be32(pb, track->tref_id); + return 20; +} + // goes at the end of each track! ... Critical for PSP playback ("Incompatible data" without it) static int mov_write_uuid_tag_psp(ByteIOContext *pb, MOVTrack *mov) { @@ -1175,6 +1236,25 @@ static int mov_write_uuid_tag_psp(ByteIOContext *pb, MOVTrack *mov) return 0x34; } +static int mov_write_udta_sdp(ByteIOContext *pb, AVCodecContext *ctx, int index) +{ + char buf[1000] = ""; + int len; + + ff_sdp_write_media(buf, sizeof(buf), ctx, NULL, 0, 0); + av_strlcatf(buf, sizeof(buf), "a=control:streamid=%d\r\n", index); + len = strlen(buf); + + put_be32(pb, len + 24); + put_tag (pb, "udta"); + put_be32(pb, len + 16); + put_tag (pb, "hnti"); + put_be32(pb, len + 8); + put_tag (pb, "sdp "); + put_buffer(pb, buf, len); + return len + 24; +} + static int mov_write_trak_tag(ByteIOContext *pb, MOVTrack *track, AVStream *st) { int64_t pos = url_ftell(pb); @@ -1183,9 +1263,13 @@ static int mov_write_trak_tag(ByteIOContext *pb, MOVTrack *track, AVStream *st) mov_write_tkhd_tag(pb, track, st); if (track->mode == MODE_PSP || track->flags & MOV_TRACK_CTTS) mov_write_edts_tag(pb, track); // PSP Movies require edts box + if (track->tref_tag) + mov_write_tref_tag(pb, track); mov_write_mdia_tag(pb, track); if (track->mode == MODE_PSP) mov_write_uuid_tag_psp(pb,track); // PSP Movies require this uuid box + if (track->tag == MKTAG('r','t','p',' ')) + mov_write_udta_sdp(pb, track->rtp_ctx->streams[0]->codec, track->trackID); return updateSize(pb, pos); } @@ -1213,7 +1297,10 @@ static int mov_write_mvhd_tag(ByteIOContext *pb, MOVMuxContext *mov) for (i=0; inb_streams; i++) { if(mov->tracks[i].entry > 0) { - maxTrackLenTemp = av_rescale_rnd(mov->tracks[i].trackDuration, globalTimescale, mov->tracks[i].timescale, AV_ROUND_UP); + maxTrackLenTemp = av_rescale_rnd(mov->tracks[i].trackDuration, + MOV_TIMESCALE, + mov->tracks[i].timescale, + AV_ROUND_UP); if(maxTrackLen < maxTrackLenTemp) maxTrackLen = maxTrackLenTemp; if(maxTrackID < mov->tracks[i].trackID) @@ -1233,7 +1320,7 @@ static int mov_write_mvhd_tag(ByteIOContext *pb, MOVMuxContext *mov) put_be32(pb, mov->time); /* creation time */ put_be32(pb, mov->time); /* modification time */ } - put_be32(pb, mov->timescale); /* timescale */ + put_be32(pb, MOV_TIMESCALE); (version == 1) ? put_be64(pb, maxTrackLen) : put_be32(pb, maxTrackLen); /* duration of longest track */ put_be32(pb, 0x00010000); /* reserved (preferred rate) 1.0 = normal */ @@ -1266,8 +1353,7 @@ static int mov_write_mvhd_tag(ByteIOContext *pb, MOVMuxContext *mov) static int mov_write_itunes_hdlr_tag(ByteIOContext *pb, MOVMuxContext *mov, AVFormatContext *s) { - int64_t pos = url_ftell(pb); - put_be32(pb, 0); /* size */ + put_be32(pb, 33); /* size */ put_tag(pb, "hdlr"); put_be32(pb, 0); put_be32(pb, 0); @@ -1275,22 +1361,24 @@ static int mov_write_itunes_hdlr_tag(ByteIOContext *pb, MOVMuxContext *mov, put_tag(pb, "appl"); put_be32(pb, 0); put_be32(pb, 0); - put_be16(pb, 0); - return updateSize(pb, pos); + put_byte(pb, 0); + return 33; } /* helper function to write a data tag with the specified string as data */ static int mov_write_string_data_tag(ByteIOContext *pb, const char *data, int lang, int long_style) { if(long_style){ - int64_t pos = url_ftell(pb); - put_be32(pb, 0); /* size */ + int size = 16 + strlen(data); + put_be32(pb, size); /* size */ put_tag(pb, "data"); put_be32(pb, 1); put_be32(pb, 0); put_buffer(pb, data, strlen(data)); - return updateSize(pb, pos); + return size; }else{ + if (!lang) + lang = ff_mov_iso639_to_lang("und", 1); put_be16(pb, strlen(data)); /* string length */ put_be16(pb, lang); put_buffer(pb, data, strlen(data)); @@ -1326,7 +1414,7 @@ static int mov_write_string_metadata(AVFormatContext *s, ByteIOContext *pb, while ((t2 = av_metadata_get(s->metadata, tag2, t2, AV_METADATA_IGNORE_SUFFIX))) { len2 = strlen(t2->key); if (len2 == len+4 && !strcmp(t->value, t2->value) - && (l=ff_mov_iso639_to_lang(&t2->key[len2-3], 0)) >= 0) { + && (l=ff_mov_iso639_to_lang(&t2->key[len2-3], 1)) >= 0) { lang = l; break; } @@ -1341,12 +1429,9 @@ static int mov_write_trkn_tag(ByteIOContext *pb, MOVMuxContext *mov, AVMetadataTag *t = av_metadata_get(s->metadata, "track", NULL, 0); int size = 0, track = t ? atoi(t->value) : 0; if (track) { - int64_t pos = url_ftell(pb); - put_be32(pb, 0); /* size */ + put_be32(pb, 32); /* size */ put_tag(pb, "trkn"); - { - int64_t pos = url_ftell(pb); - put_be32(pb, 0); /* size */ + put_be32(pb, 24); /* size */ put_tag(pb, "data"); put_be32(pb, 0); // 8 bytes empty put_be32(pb, 0); @@ -1354,9 +1439,7 @@ static int mov_write_trkn_tag(ByteIOContext *pb, MOVMuxContext *mov, put_be16(pb, track); // track number put_be16(pb, 0); // total track number put_be16(pb, 0); // empty - updateSize(pb, pos); - } - size = updateSize(pb, pos); + size = 32; } return size; } @@ -1369,14 +1452,22 @@ static int mov_write_ilst_tag(ByteIOContext *pb, MOVMuxContext *mov, put_be32(pb, 0); /* size */ put_tag(pb, "ilst"); mov_write_string_metadata(s, pb, "\251nam", "title" , 1); - mov_write_string_metadata(s, pb, "\251ART", "author" , 1); - mov_write_string_metadata(s, pb, "\251wrt", "author" , 1); + mov_write_string_metadata(s, pb, "\251ART", "artist" , 1); + mov_write_string_metadata(s, pb, "aART", "album_artist", 1); + mov_write_string_metadata(s, pb, "\251wrt", "composer" , 1); mov_write_string_metadata(s, pb, "\251alb", "album" , 1); - mov_write_string_metadata(s, pb, "\251day", "year" , 1); + mov_write_string_metadata(s, pb, "\251day", "date" , 1); mov_write_string_tag(pb, "\251too", LIBAVFORMAT_IDENT, 0, 1); mov_write_string_metadata(s, pb, "\251cmt", "comment" , 1); mov_write_string_metadata(s, pb, "\251gen", "genre" , 1); mov_write_string_metadata(s, pb, "\251cpy", "copyright", 1); + mov_write_string_metadata(s, pb, "\251grp", "grouping" , 1); + mov_write_string_metadata(s, pb, "\251lyr", "lyrics" , 1); + mov_write_string_metadata(s, pb, "desc", "description",1); + mov_write_string_metadata(s, pb, "ldes", "synopsis" , 1); + mov_write_string_metadata(s, pb, "tvsh", "show" , 1); + mov_write_string_metadata(s, pb, "tven", "episode_id",1); + mov_write_string_metadata(s, pb, "tvnn", "network" , 1); mov_write_trkn_tag(pb, mov, s); return updateSize(pb, pos); } @@ -1439,12 +1530,38 @@ static int mov_write_3gp_udta_tag(ByteIOContext *pb, AVFormatContext *s, put_be16(pb, language_code("eng")); /* language */ put_buffer(pb, t->value, strlen(t->value)+1); /* UTF8 string value */ if (!strcmp(tag, "albm") && - (t = av_metadata_get(s->metadata, "year", NULL, 0))) + (t = av_metadata_get(s->metadata, "date", NULL, 0))) put_byte(pb, atoi(t->value)); } return updateSize(pb, pos); } +static int mov_write_chpl_tag(ByteIOContext *pb, AVFormatContext *s) +{ + int64_t pos = url_ftell(pb); + int i, nb_chapters = FFMIN(s->nb_chapters, 255); + + put_be32(pb, 0); // size + put_tag (pb, "chpl"); + put_be32(pb, 0x01000000); // version + flags + put_be32(pb, 0); // unknown + put_byte(pb, nb_chapters); + + for (i = 0; i < nb_chapters; i++) { + AVChapter *c = s->chapters[i]; + AVMetadataTag *t; + put_be64(pb, av_rescale_q(c->start, c->time_base, (AVRational){1,10000000})); + + if ((t = av_metadata_get(c->metadata, "title", NULL, 0))) { + int len = FFMIN(strlen(t->value), 255); + put_byte(pb, len); + put_buffer(pb, t->value, len); + } else + put_byte(pb, 0); + } + return updateSize(pb, pos); +} + static int mov_write_udta_tag(ByteIOContext *pb, MOVMuxContext *mov, AVFormatContext *s) { @@ -1462,18 +1579,19 @@ static int mov_write_udta_tag(ByteIOContext *pb, MOVMuxContext *mov, return ret; if (mov->mode & MODE_3GP) { + mov_write_3gp_udta_tag(pb_buf, s, "perf", "artist"); mov_write_3gp_udta_tag(pb_buf, s, "titl", "title"); mov_write_3gp_udta_tag(pb_buf, s, "auth", "author"); mov_write_3gp_udta_tag(pb_buf, s, "gnre", "genre"); mov_write_3gp_udta_tag(pb_buf, s, "dscp", "comment"); mov_write_3gp_udta_tag(pb_buf, s, "albm", "album"); mov_write_3gp_udta_tag(pb_buf, s, "cprt", "copyright"); - mov_write_3gp_udta_tag(pb_buf, s, "yrrc", "year"); + mov_write_3gp_udta_tag(pb_buf, s, "yrrc", "date"); } else if (mov->mode == MODE_MOV) { // the title field breaks gtkpod with mp4 and my suspicion is that stuff is not valid in mp4 mov_write_string_metadata(s, pb_buf, "\251nam", "title" , 0); mov_write_string_metadata(s, pb_buf, "\251aut", "author" , 0); mov_write_string_metadata(s, pb_buf, "\251alb", "album" , 0); - mov_write_string_metadata(s, pb_buf, "\251day", "year" , 0); + mov_write_string_metadata(s, pb_buf, "\251day", "date" , 0); mov_write_string_tag(pb_buf, "\251enc", LIBAVFORMAT_IDENT, 0, 0); mov_write_string_metadata(s, pb_buf, "\251des", "comment" , 0); mov_write_string_metadata(s, pb_buf, "\251gen", "genre" , 0); @@ -1483,6 +1601,9 @@ static int mov_write_udta_tag(ByteIOContext *pb, MOVMuxContext *mov, mov_write_meta_tag(pb_buf, mov, s); } + if (s->nb_chapters) + mov_write_chpl_tag(pb_buf, s); + if ((size = url_close_dyn_buf(pb_buf, &buf)) > 0) { put_be32(pb, size+8); put_tag(pb, "udta"); @@ -1551,7 +1672,6 @@ static int mov_write_moov_tag(ByteIOContext *pb, MOVMuxContext *mov, int64_t pos = url_ftell(pb); put_be32(pb, 0); /* size placeholder*/ put_tag(pb, "moov"); - mov->timescale = globalTimescale; for (i=0; inb_streams; i++) { if(mov->tracks[i].entry <= 0) continue; @@ -1560,11 +1680,24 @@ static int mov_write_moov_tag(ByteIOContext *pb, MOVMuxContext *mov, mov->tracks[i].trackID = i+1; } + if (mov->chapter_track) + for (i=0; inb_streams; i++) { + mov->tracks[i].tref_tag = MKTAG('c','h','a','p'); + mov->tracks[i].tref_id = mov->tracks[mov->chapter_track].trackID; + } + for (i = 0; i < mov->nb_streams; i++) { + if (mov->tracks[i].tag == MKTAG('r','t','p',' ')) { + mov->tracks[i].tref_tag = MKTAG('h','i','n','t'); + mov->tracks[i].tref_id = + mov->tracks[mov->tracks[i].src_track].trackID; + } + } + mov_write_mvhd_tag(pb, mov); //mov_write_iods_tag(pb, mov); for (i=0; inb_streams; i++) { if(mov->tracks[i].entry > 0) { - mov_write_trak_tag(pb, &(mov->tracks[i]), s->streams[i]); + mov_write_trak_tag(pb, &(mov->tracks[i]), i < s->nb_streams ? s->streams[i] : NULL); } } @@ -1598,7 +1731,7 @@ static int mov_write_ftyp_tag(ByteIOContext *pb, AVFormatContext *s) for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - if (st->codec->codec_type == CODEC_TYPE_VIDEO) + if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) has_video = 1; if (st->codec->codec_id == CODEC_ID_H264) has_h264 = 1; @@ -1705,111 +1838,6 @@ static void mov_write_uuidprof_tag(ByteIOContext *pb, AVFormatContext *s) put_be32(pb, 0x010001); /* ? */ } -static int mov_write_header(AVFormatContext *s) -{ - ByteIOContext *pb = s->pb; - MOVMuxContext *mov = s->priv_data; - int i; - - if (url_is_streamed(s->pb)) { - av_log(s, AV_LOG_ERROR, "muxer does not support non seekable output\n"); - return -1; - } - - /* Default mode == MP4 */ - mov->mode = MODE_MP4; - - if (s->oformat != NULL) { - if (!strcmp("3gp", s->oformat->name)) mov->mode = MODE_3GP; - else if (!strcmp("3g2", s->oformat->name)) mov->mode = MODE_3GP|MODE_3G2; - else if (!strcmp("mov", s->oformat->name)) mov->mode = MODE_MOV; - else if (!strcmp("psp", s->oformat->name)) mov->mode = MODE_PSP; - else if (!strcmp("ipod",s->oformat->name)) mov->mode = MODE_IPOD; - - mov_write_ftyp_tag(pb,s); - if (mov->mode == MODE_PSP) { - if (s->nb_streams != 2) { - av_log(s, AV_LOG_ERROR, "PSP mode need one video and one audio stream\n"); - return -1; - } - mov_write_uuidprof_tag(pb,s); - } - } - - mov->tracks = av_mallocz(s->nb_streams*sizeof(*mov->tracks)); - if (!mov->tracks) - return AVERROR(ENOMEM); - - for(i=0; inb_streams; i++){ - AVStream *st= s->streams[i]; - MOVTrack *track= &mov->tracks[i]; - AVMetadataTag *lang = av_metadata_get(st->metadata, "language", NULL,0); - - track->enc = st->codec; - track->language = ff_mov_iso639_to_lang(lang?lang->value:"und", mov->mode!=MODE_MOV); - if (track->language < 0) - track->language = 0; - track->mode = mov->mode; - track->tag = mov_find_codec_tag(s, track); - if (!track->tag) { - av_log(s, AV_LOG_ERROR, "track %d: could not find tag, " - "codec not currently supported in container\n", i); - goto error; - } - if(st->codec->codec_type == CODEC_TYPE_VIDEO){ - if (track->tag == MKTAG('m','x','3','p') || track->tag == MKTAG('m','x','3','n') || - track->tag == MKTAG('m','x','4','p') || track->tag == MKTAG('m','x','4','n') || - track->tag == MKTAG('m','x','5','p') || track->tag == MKTAG('m','x','5','n')) { - if (st->codec->width != 720 || (st->codec->height != 608 && st->codec->height != 512)) { - av_log(s, AV_LOG_ERROR, "D-10/IMX must use 720x608 or 720x512 video resolution\n"); - goto error; - } - track->height = track->tag>>24 == 'n' ? 486 : 576; - } - track->timescale = st->codec->time_base.den; - if (track->mode == MODE_MOV && track->timescale > 100000) - av_log(s, AV_LOG_WARNING, - "WARNING codec timebase is very high. If duration is too long,\n" - "file may not be playable by quicktime. Specify a shorter timebase\n" - "or choose different container.\n"); - }else if(st->codec->codec_type == CODEC_TYPE_AUDIO){ - track->timescale = st->codec->sample_rate; - if(!st->codec->frame_size && !av_get_bits_per_sample(st->codec->codec_id)) { - av_log(s, AV_LOG_ERROR, "track %d: codec frame size is not set\n", i); - goto error; - }else if(st->codec->frame_size > 1){ /* assume compressed audio */ - track->audio_vbr = 1; - }else{ - st->codec->frame_size = 1; - track->sampleSize = (av_get_bits_per_sample(st->codec->codec_id) >> 3) * st->codec->channels; - } - if(track->mode != MODE_MOV && - track->enc->codec_id == CODEC_ID_MP3 && track->enc->sample_rate < 16000){ - av_log(s, AV_LOG_ERROR, "track %d: muxing mp3 at %dhz is not supported\n", - i, track->enc->sample_rate); - goto error; - } - }else if(st->codec->codec_type == CODEC_TYPE_SUBTITLE){ - track->timescale = st->codec->time_base.den; - } - if (!track->height) - track->height = st->codec->height; - - av_set_pts_info(st, 64, 1, track->timescale); - } - - mov_write_mdat_tag(pb, mov); - mov->time = s->timestamp + 0x7C25B080; //1970 based -> 1904 based - mov->nb_streams = s->nb_streams; - - put_flush_packet(pb); - - return 0; - error: - av_freep(&mov->tracks); - return -1; -} - static int mov_parse_mpeg2_frame(AVPacket *pkt, uint32_t *flags) { uint32_t c = -1; @@ -1831,7 +1859,7 @@ static int mov_parse_mpeg2_frame(AVPacket *pkt, uint32_t *flags) return 0; } -static int mov_write_packet(AVFormatContext *s, AVPacket *pkt) +int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) { MOVMuxContext *mov = s->priv_data; ByteIOContext *pb = s->pb; @@ -1908,7 +1936,7 @@ static int mov_write_packet(AVFormatContext *s, AVPacket *pkt) trk->flags |= MOV_TRACK_CTTS; trk->cluster[trk->entry].cts = pkt->pts - pkt->dts; trk->cluster[trk->entry].flags = 0; - if (pkt->flags & PKT_FLAG_KEY) { + if (pkt->flags & AV_PKT_FLAG_KEY) { if (mov->mode == MODE_MOV && enc->codec_id == CODEC_ID_MPEG2VIDEO) { mov_parse_mpeg2_frame(pkt, &trk->cluster[trk->entry].flags); if (trk->cluster[trk->entry].flags & MOV_PARTIAL_SYNC_SAMPLE) @@ -1924,9 +1952,191 @@ static int mov_write_packet(AVFormatContext *s, AVPacket *pkt) mov->mdat_size += size; put_flush_packet(pb); + + if (trk->hint_track >= 0 && trk->hint_track < mov->nb_streams) + ff_mov_add_hinted_packet(s, pkt, trk->hint_track, trk->entry); return 0; } +// QuickTime chapters involve an additional text track with the chapter names +// as samples, and a tref pointing from the other tracks to the chapter one. +static void mov_create_chapter_track(AVFormatContext *s, int tracknum) +{ + MOVMuxContext *mov = s->priv_data; + MOVTrack *track = &mov->tracks[tracknum]; + AVPacket pkt = { .stream_index = tracknum, .flags = AV_PKT_FLAG_KEY }; + int i, len; + + track->mode = mov->mode; + track->tag = MKTAG('t','e','x','t'); + track->timescale = MOV_TIMESCALE; + track->enc = avcodec_alloc_context(); + track->enc->codec_type = AVMEDIA_TYPE_SUBTITLE; + + for (i = 0; i < s->nb_chapters; i++) { + AVChapter *c = s->chapters[i]; + AVMetadataTag *t; + + int64_t end = av_rescale_q(c->end, c->time_base, (AVRational){1,MOV_TIMESCALE}); + pkt.pts = pkt.dts = av_rescale_q(c->start, c->time_base, (AVRational){1,MOV_TIMESCALE}); + pkt.duration = end - pkt.dts; + + if ((t = av_metadata_get(c->metadata, "title", NULL, 0))) { + len = strlen(t->value); + pkt.size = len+2; + pkt.data = av_malloc(pkt.size); + AV_WB16(pkt.data, len); + memcpy(pkt.data+2, t->value, len); + ff_mov_write_packet(s, &pkt); + av_freep(&pkt.data); + } + } +} + +static int mov_write_header(AVFormatContext *s) +{ + ByteIOContext *pb = s->pb; + MOVMuxContext *mov = s->priv_data; + int i, hint_track = 0; + + if (url_is_streamed(s->pb)) { + av_log(s, AV_LOG_ERROR, "muxer does not support non seekable output\n"); + return -1; + } + + /* Default mode == MP4 */ + mov->mode = MODE_MP4; + + if (s->oformat != NULL) { + if (!strcmp("3gp", s->oformat->name)) mov->mode = MODE_3GP; + else if (!strcmp("3g2", s->oformat->name)) mov->mode = MODE_3GP|MODE_3G2; + else if (!strcmp("mov", s->oformat->name)) mov->mode = MODE_MOV; + else if (!strcmp("psp", s->oformat->name)) mov->mode = MODE_PSP; + else if (!strcmp("ipod",s->oformat->name)) mov->mode = MODE_IPOD; + + mov_write_ftyp_tag(pb,s); + if (mov->mode == MODE_PSP) { + if (s->nb_streams != 2) { + av_log(s, AV_LOG_ERROR, "PSP mode need one video and one audio stream\n"); + return -1; + } + mov_write_uuidprof_tag(pb,s); + } + } + + mov->nb_streams = s->nb_streams; + if (mov->mode & (MODE_MOV|MODE_IPOD) && s->nb_chapters) + mov->chapter_track = mov->nb_streams++; + + if (s->flags & AVFMT_FLAG_RTP_HINT) { + /* Add hint tracks for each audio and video stream */ + hint_track = mov->nb_streams; + for (i = 0; i < s->nb_streams; i++) { + AVStream *st = s->streams[i]; + if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO || + st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + mov->nb_streams++; + } + } + } + + mov->tracks = av_mallocz(mov->nb_streams*sizeof(*mov->tracks)); + if (!mov->tracks) + return AVERROR(ENOMEM); + + for(i=0; inb_streams; i++){ + AVStream *st= s->streams[i]; + MOVTrack *track= &mov->tracks[i]; + AVMetadataTag *lang = av_metadata_get(st->metadata, "language", NULL,0); + + track->enc = st->codec; + track->language = ff_mov_iso639_to_lang(lang?lang->value:"und", mov->mode!=MODE_MOV); + if (track->language < 0) + track->language = 0; + track->mode = mov->mode; + track->tag = mov_find_codec_tag(s, track); + if (!track->tag) { + av_log(s, AV_LOG_ERROR, "track %d: could not find tag, " + "codec not currently supported in container\n", i); + goto error; + } + /* If hinting of this track is enabled by a later hint track, + * this is updated. */ + track->hint_track = -1; + if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO){ + if (track->tag == MKTAG('m','x','3','p') || track->tag == MKTAG('m','x','3','n') || + track->tag == MKTAG('m','x','4','p') || track->tag == MKTAG('m','x','4','n') || + track->tag == MKTAG('m','x','5','p') || track->tag == MKTAG('m','x','5','n')) { + if (st->codec->width != 720 || (st->codec->height != 608 && st->codec->height != 512)) { + av_log(s, AV_LOG_ERROR, "D-10/IMX must use 720x608 or 720x512 video resolution\n"); + goto error; + } + track->height = track->tag>>24 == 'n' ? 486 : 576; + } + track->timescale = st->codec->time_base.den; + if (track->mode == MODE_MOV && track->timescale > 100000) + av_log(s, AV_LOG_WARNING, + "WARNING codec timebase is very high. If duration is too long,\n" + "file may not be playable by quicktime. Specify a shorter timebase\n" + "or choose different container.\n"); + }else if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO){ + track->timescale = st->codec->sample_rate; + if(!st->codec->frame_size && !av_get_bits_per_sample(st->codec->codec_id)) { + av_log(s, AV_LOG_ERROR, "track %d: codec frame size is not set\n", i); + goto error; + }else if(st->codec->frame_size > 1){ /* assume compressed audio */ + track->audio_vbr = 1; + }else{ + st->codec->frame_size = 1; + track->sampleSize = (av_get_bits_per_sample(st->codec->codec_id) >> 3) * st->codec->channels; + } + if (track->mode != MODE_MOV) { + if (track->timescale > UINT16_MAX) { + av_log(s, AV_LOG_ERROR, "track %d: output format does not support " + "sample rate %dhz\n", i, track->timescale); + goto error; + } + if (track->enc->codec_id == CODEC_ID_MP3 && track->timescale < 16000) { + av_log(s, AV_LOG_ERROR, "track %d: muxing mp3 at %dhz is not supported\n", + i, track->enc->sample_rate); + goto error; + } + } + }else if(st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE){ + track->timescale = st->codec->time_base.den; + } + if (!track->height) + track->height = st->codec->height; + + av_set_pts_info(st, 64, 1, track->timescale); + } + + mov_write_mdat_tag(pb, mov); + mov->time = s->timestamp + 0x7C25B080; //1970 based -> 1904 based + + if (mov->chapter_track) + mov_create_chapter_track(s, mov->chapter_track); + + if (s->flags & AVFMT_FLAG_RTP_HINT) { + /* Initialize the hint tracks for each audio and video stream */ + for (i = 0; i < s->nb_streams; i++) { + AVStream *st = s->streams[i]; + if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO || + st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + ff_mov_init_hinting(s, hint_track, i); + hint_track++; + } + } + } + + put_flush_packet(pb); + + return 0; + error: + av_freep(&mov->tracks); + return -1; +} + static int mov_write_trailer(AVFormatContext *s) { MOVMuxContext *mov = s->priv_data; @@ -1951,7 +2161,12 @@ static int mov_write_trailer(AVFormatContext *s) mov_write_moov_tag(pb, mov, s); + if (mov->chapter_track) + av_freep(&mov->tracks[mov->chapter_track].enc); + for (i=0; inb_streams; i++) { + if (mov->tracks[i].tag == MKTAG('r','t','p',' ')) + ff_mov_close_hinting(&mov->tracks[i]); av_freep(&mov->tracks[i].cluster); if(mov->tracks[i].vosLen) av_free(mov->tracks[i].vosData); @@ -1975,7 +2190,7 @@ AVOutputFormat mov_muxer = { CODEC_ID_AAC, CODEC_ID_MPEG4, mov_write_header, - mov_write_packet, + ff_mov_write_packet, mov_write_trailer, .flags = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS, .codec_tag = (const AVCodecTag* const []){codec_movvideo_tags, codec_movaudio_tags, 0}, @@ -1991,7 +2206,7 @@ AVOutputFormat tgp_muxer = { CODEC_ID_AMR_NB, CODEC_ID_H263, mov_write_header, - mov_write_packet, + ff_mov_write_packet, mov_write_trailer, .flags = AVFMT_GLOBALHEADER, .codec_tag = (const AVCodecTag* const []){codec_3gp_tags, 0}, @@ -2007,7 +2222,7 @@ AVOutputFormat mp4_muxer = { CODEC_ID_AAC, CODEC_ID_MPEG4, mov_write_header, - mov_write_packet, + ff_mov_write_packet, mov_write_trailer, .flags = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS, .codec_tag = (const AVCodecTag* const []){ff_mp4_obj_type, 0}, @@ -2023,7 +2238,7 @@ AVOutputFormat psp_muxer = { CODEC_ID_AAC, CODEC_ID_MPEG4, mov_write_header, - mov_write_packet, + ff_mov_write_packet, mov_write_trailer, .flags = AVFMT_GLOBALHEADER, .codec_tag = (const AVCodecTag* const []){ff_mp4_obj_type, 0}, @@ -2039,7 +2254,7 @@ AVOutputFormat tg2_muxer = { CODEC_ID_AMR_NB, CODEC_ID_H263, mov_write_header, - mov_write_packet, + ff_mov_write_packet, mov_write_trailer, .flags = AVFMT_GLOBALHEADER, .codec_tag = (const AVCodecTag* const []){codec_3gp_tags, 0}, @@ -2055,7 +2270,7 @@ AVOutputFormat ipod_muxer = { CODEC_ID_AAC, CODEC_ID_H264, mov_write_header, - mov_write_packet, + ff_mov_write_packet, mov_write_trailer, .flags = AVFMT_GLOBALHEADER, .codec_tag = (const AVCodecTag* const []){codec_ipod_tags, 0}, diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/movenc.h b/src/add-ons/media/plugins/ffmpeg/libavformat/movenc.h new file mode 100644 index 0000000000..182c5edc8c --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/movenc.h @@ -0,0 +1,120 @@ +/* + * MOV, 3GP, MP4 muxer + * Copyright (c) 2003 Thomas Raivio + * Copyright (c) 2004 Gildas Bazin + * Copyright (c) 2009 Baptiste Coudurier + * + * 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_MOVENC_H +#define AVFORMAT_MOVENC_H + +#include "avformat.h" + +#define MOV_INDEX_CLUSTER_SIZE 16384 +#define MOV_TIMESCALE 1000 + +#define RTP_MAX_PACKET_SIZE 1450 + +#define MODE_MP4 0x01 +#define MODE_MOV 0x02 +#define MODE_3GP 0x04 +#define MODE_PSP 0x08 // example working PSP command line: +// ffmpeg -i testinput.avi -f psp -r 14.985 -s 320x240 -b 768 -ar 24000 -ab 32 M4V00001.MP4 +#define MODE_3G2 0x10 +#define MODE_IPOD 0x20 + +typedef struct MOVIentry { + unsigned int size; + uint64_t pos; + unsigned int samplesInChunk; + unsigned int entries; + int cts; + int64_t dts; +#define MOV_SYNC_SAMPLE 0x0001 +#define MOV_PARTIAL_SYNC_SAMPLE 0x0002 + uint32_t flags; +} MOVIentry; + +typedef struct HintSample { + uint8_t *data; + int size; + int sample_number; + int offset; + int own_data; +} HintSample; + +typedef struct { + int size; + int len; + HintSample *samples; +} HintSampleQueue; + +typedef struct MOVIndex { + int mode; + int entry; + unsigned timescale; + uint64_t time; + int64_t trackDuration; + long sampleCount; + long sampleSize; + int hasKeyframes; +#define MOV_TRACK_CTTS 0x0001 +#define MOV_TRACK_STPS 0x0002 + uint32_t flags; + int language; + int trackID; + int tag; ///< stsd fourcc + AVCodecContext *enc; + + int vosLen; + uint8_t *vosData; + MOVIentry *cluster; + int audio_vbr; + int height; ///< active picture (w/o VBI) height for D-10/IMX + uint32_t tref_tag; + int tref_id; ///< trackID of the referenced track + + int hint_track; ///< the track that hints this track, -1 if no hint track is set + int src_track; ///< the track that this hint track describes + AVFormatContext *rtp_ctx; ///< the format context for the hinting rtp muxer + uint32_t prev_rtp_ts; + int64_t cur_rtp_ts_unwrapped; + uint32_t max_packet_size; + + HintSampleQueue sample_queue; +} MOVTrack; + +typedef struct MOVMuxContext { + int mode; + int64_t time; + int nb_streams; + int chapter_track; ///< qt chapter track number + int64_t mdat_pos; + uint64_t mdat_size; + MOVTrack *tracks; +} MOVMuxContext; + +int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt); + +int ff_mov_init_hinting(AVFormatContext *s, int index, int src_index); +int ff_mov_add_hinted_packet(AVFormatContext *s, AVPacket *pkt, + int track_index, int sample); +void ff_mov_close_hinting(MOVTrack *track); + +#endif /* AVFORMAT_MOVENC_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/movenchint.c b/src/add-ons/media/plugins/ffmpeg/libavformat/movenchint.c new file mode 100644 index 0000000000..d90ac67911 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/movenchint.c @@ -0,0 +1,504 @@ +/* + * MOV, 3GP, MP4 muxer RTP hinting + * Copyright (c) 2010 Martin Storsjo + * + * 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 "movenc.h" +#include "libavutil/intreadwrite.h" + +int ff_mov_init_hinting(AVFormatContext *s, int index, int src_index) +{ + MOVMuxContext *mov = s->priv_data; + MOVTrack *track = &mov->tracks[index]; + MOVTrack *src_track = &mov->tracks[src_index]; + AVStream *src_st = s->streams[src_index]; + int ret = AVERROR(ENOMEM); + AVOutputFormat *rtp_format = av_guess_format("rtp", NULL, NULL); + + track->tag = MKTAG('r','t','p',' '); + track->src_track = src_index; + + if (!rtp_format) { + ret = AVERROR(ENOENT); + goto fail; + } + + track->enc = avcodec_alloc_context(); + if (!track->enc) + goto fail; + track->enc->codec_type = AVMEDIA_TYPE_DATA; + track->enc->codec_tag = track->tag; + + track->rtp_ctx = avformat_alloc_context(); + if (!track->rtp_ctx) + goto fail; + track->rtp_ctx->oformat = rtp_format; + if (!av_new_stream(track->rtp_ctx, 0)) + goto fail; + + /* Copy stream parameters */ + track->rtp_ctx->streams[0]->sample_aspect_ratio = + src_st->sample_aspect_ratio; + + /* Remove the allocated codec context, link to the original one + * instead, to give the rtp muxer access to codec parameters. */ + av_free(track->rtp_ctx->streams[0]->codec); + track->rtp_ctx->streams[0]->codec = src_st->codec; + + if ((ret = url_open_dyn_packet_buf(&track->rtp_ctx->pb, + RTP_MAX_PACKET_SIZE)) < 0) + goto fail; + ret = av_write_header(track->rtp_ctx); + if (ret) + goto fail; + + /* Copy the RTP AVStream timebase back to the hint AVStream */ + track->timescale = track->rtp_ctx->streams[0]->time_base.den; + + /* Mark the hinted track that packets written to it should be + * sent to this track for hinting. */ + src_track->hint_track = index; + return 0; +fail: + av_log(s, AV_LOG_WARNING, + "Unable to initialize hinting of stream %d\n", src_index); + if (track->rtp_ctx && track->rtp_ctx->pb) { + uint8_t *buf; + url_close_dyn_buf(track->rtp_ctx->pb, &buf); + av_free(buf); + } + if (track->rtp_ctx && track->rtp_ctx->streams[0]) { + av_metadata_free(&track->rtp_ctx->streams[0]->metadata); + av_free(track->rtp_ctx->streams[0]); + } + if (track->rtp_ctx) { + av_metadata_free(&track->rtp_ctx->metadata); + av_free(track->rtp_ctx->priv_data); + av_freep(&track->rtp_ctx); + } + av_freep(&track->enc); + /* Set a default timescale, to avoid crashes in dump_format */ + track->timescale = 90000; + return ret; +} + +/** + * Remove the first sample from the sample queue. + */ +static void sample_queue_pop(HintSampleQueue *queue) +{ + if (queue->len <= 0) + return; + if (queue->samples[0].own_data) + av_free(queue->samples[0].data); + queue->len--; + memmove(queue->samples, queue->samples + 1, sizeof(HintSample)*queue->len); +} + +/** + * Empty the sample queue, releasing all memory. + */ +static void sample_queue_free(HintSampleQueue *queue) +{ + int i; + for (i = 0; i < queue->len; i++) + if (queue->samples[i].own_data) + av_free(queue->samples[i].data); + av_freep(&queue->samples); + queue->len = 0; + queue->size = 0; +} + +/** + * Add a reference to the sample data to the sample queue. The data is + * not copied. sample_queue_retain should be called before pkt->data + * is reused/freed. + */ +static void sample_queue_push(HintSampleQueue *queue, AVPacket *pkt, int sample) +{ + /* No need to keep track of smaller samples, since describing them + * with immediates is more efficient. */ + if (pkt->size <= 14) + return; + if (!queue->samples || queue->len >= queue->size) { + HintSample* samples; + queue->size += 10; + samples = av_realloc(queue->samples, sizeof(HintSample)*queue->size); + if (!samples) + return; + queue->samples = samples; + } + queue->samples[queue->len].data = pkt->data; + queue->samples[queue->len].size = pkt->size; + queue->samples[queue->len].sample_number = sample; + queue->samples[queue->len].offset = 0; + queue->samples[queue->len].own_data = 0; + queue->len++; +} + +/** + * Make local copies of all referenced sample data in the queue. + */ +static void sample_queue_retain(HintSampleQueue *queue) +{ + int i; + for (i = 0; i < queue->len; ) { + HintSample *sample = &queue->samples[i]; + if (!sample->own_data) { + uint8_t* ptr = av_malloc(sample->size); + if (!ptr) { + /* Unable to allocate memory for this one, remove it */ + memmove(queue->samples + i, queue->samples + i + 1, + sizeof(HintSample)*(queue->len - i - 1)); + queue->len--; + continue; + } + memcpy(ptr, sample->data, sample->size); + sample->data = ptr; + sample->own_data = 1; + } + i++; + } +} + +/** + * Find matches of needle[n_pos ->] within haystack. If a sufficiently + * large match is found, matching bytes before n_pos are included + * in the match, too (within the limits of the arrays). + * + * @param haystack buffer that may contain parts of needle + * @param h_len length of the haystack buffer + * @param needle buffer containing source data that have been used to + * construct haystack + * @param n_pos start position in needle used for looking for matches + * @param n_len length of the needle buffer + * @param match_h_offset_ptr offset of the first matching byte within haystack + * @param match_n_offset_ptr offset of the first matching byte within needle + * @param match_len_ptr length of the matched segment + * @return 0 if a match was found, < 0 if no match was found + */ +static int match_segments(const uint8_t *haystack, int h_len, + const uint8_t *needle, int n_pos, int n_len, + int *match_h_offset_ptr, int *match_n_offset_ptr, + int *match_len_ptr) +{ + int h_pos; + for (h_pos = 0; h_pos < h_len; h_pos++) { + int match_len = 0; + int match_h_pos, match_n_pos; + + /* Check how many bytes match at needle[n_pos] and haystack[h_pos] */ + while (h_pos + match_len < h_len && n_pos + match_len < n_len && + needle[n_pos + match_len] == haystack[h_pos + match_len]) + match_len++; + if (match_len <= 8) + continue; + + /* If a sufficiently large match was found, try to expand + * the matched segment backwards. */ + match_h_pos = h_pos; + match_n_pos = n_pos; + while (match_n_pos > 0 && match_h_pos > 0 && + needle[match_n_pos - 1] == haystack[match_h_pos - 1]) { + match_n_pos--; + match_h_pos--; + match_len++; + } + if (match_len <= 14) + continue; + *match_h_offset_ptr = match_h_pos; + *match_n_offset_ptr = match_n_pos; + *match_len_ptr = match_len; + return 0; + } + return -1; +} + +/** + * Look for segments in samples in the sample queue matching the data + * in ptr. Samples not matching are removed from the queue. If a match + * is found, the next time it will look for matches starting from the + * end of the previous matched segment. + * + * @param data data to find matches for in the sample queue + * @param len length of the data buffer + * @param queue samples used for looking for matching segments + * @param pos the offset in data of the matched segment + * @param match_sample the number of the sample that contained the match + * @param match_offset the offset of the matched segment within the sample + * @param match_len the length of the matched segment + * @return 0 if a match was found, < 0 if no match was found + */ +static int find_sample_match(const uint8_t *data, int len, + HintSampleQueue *queue, int *pos, + int *match_sample, int *match_offset, + int *match_len) +{ + while (queue->len > 0) { + HintSample *sample = &queue->samples[0]; + /* If looking for matches in a new sample, skip the first 5 bytes, + * since they often may be modified/removed in the output packet. */ + if (sample->offset == 0 && sample->size > 5) + sample->offset = 5; + + if (match_segments(data, len, sample->data, sample->offset, + sample->size, pos, match_offset, match_len) == 0) { + *match_sample = sample->sample_number; + /* Next time, look for matches at this offset, with a little + * margin to this match. */ + sample->offset = *match_offset + *match_len + 5; + if (sample->offset + 10 >= sample->size) + sample_queue_pop(queue); /* Not enough useful data left */ + return 0; + } + + if (sample->offset < 10 && sample->size > 20) { + /* No match found from the start of the sample, + * try from the middle of the sample instead. */ + sample->offset = sample->size/2; + } else { + /* No match for this sample, remove it */ + sample_queue_pop(queue); + } + } + return -1; +} + +static void output_immediate(const uint8_t *data, int size, + ByteIOContext *out, int *entries) +{ + while (size > 0) { + int len = size; + if (len > 14) + len = 14; + put_byte(out, 1); /* immediate constructor */ + put_byte(out, len); /* amount of valid data */ + put_buffer(out, data, len); + data += len; + size -= len; + + for (; len < 14; len++) + put_byte(out, 0); + + (*entries)++; + } +} + +static void output_match(ByteIOContext *out, int match_sample, + int match_offset, int match_len, int *entries) +{ + put_byte(out, 2); /* sample constructor */ + put_byte(out, 0); /* track reference */ + put_be16(out, match_len); + put_be32(out, match_sample); + put_be32(out, match_offset); + put_be16(out, 1); /* bytes per block */ + put_be16(out, 1); /* samples per block */ + (*entries)++; +} + +static void describe_payload(const uint8_t *data, int size, + ByteIOContext *out, int *entries, + HintSampleQueue *queue) +{ + /* Describe the payload using different constructors */ + while (size > 0) { + int match_sample, match_offset, match_len, pos; + if (find_sample_match(data, size, queue, &pos, &match_sample, + &match_offset, &match_len) < 0) + break; + output_immediate(data, pos, out, entries); + data += pos; + size -= pos; + output_match(out, match_sample, match_offset, match_len, entries); + data += match_len; + size -= match_len; + } + output_immediate(data, size, out, entries); +} + +/** + * Write an RTP hint (that may contain one or more RTP packets) + * for the packets in data. data contains one or more packets with a + * BE32 size header. + * + * @param out buffer where the hints are written + * @param data buffer containing RTP packets + * @param size the size of the data buffer + * @param trk the MOVTrack for the hint track + * @param pts pointer where the timestamp for the written RTP hint is stored + * @return the number of RTP packets in the written hint + */ +static int write_hint_packets(ByteIOContext *out, const uint8_t *data, + int size, MOVTrack *trk, int64_t *pts) +{ + int64_t curpos; + int64_t count_pos, entries_pos; + int count = 0, entries; + + count_pos = url_ftell(out); + /* RTPsample header */ + put_be16(out, 0); /* packet count */ + put_be16(out, 0); /* reserved */ + + while (size > 4) { + uint32_t packet_len = AV_RB32(data); + uint16_t seq; + uint32_t ts; + + data += 4; + size -= 4; + if (packet_len > size || packet_len <= 12) + break; + if (data[1] >= 200 && data[1] <= 204) { + /* RTCP packet, just skip */ + data += packet_len; + size -= packet_len; + continue; + } + + if (packet_len > trk->max_packet_size) + trk->max_packet_size = packet_len; + + seq = AV_RB16(&data[2]); + ts = AV_RB32(&data[4]); + + if (trk->prev_rtp_ts == 0) + trk->prev_rtp_ts = ts; + /* Unwrap the 32-bit RTP timestamp that wraps around often + * into a not (as often) wrapping 64-bit timestamp. */ + trk->cur_rtp_ts_unwrapped += (int32_t) (ts - trk->prev_rtp_ts); + trk->prev_rtp_ts = ts; + if (*pts == AV_NOPTS_VALUE) + *pts = trk->cur_rtp_ts_unwrapped; + + count++; + /* RTPpacket header */ + put_be32(out, 0); /* relative_time */ + put_buffer(out, data, 2); /* RTP header */ + put_be16(out, seq); /* RTPsequenceseed */ + put_be16(out, 0); /* reserved + flags */ + entries_pos = url_ftell(out); + put_be16(out, 0); /* entry count */ + + data += 12; + size -= 12; + packet_len -= 12; + + entries = 0; + /* Write one or more constructors describing the payload data */ + describe_payload(data, packet_len, out, &entries, &trk->sample_queue); + data += packet_len; + size -= packet_len; + + curpos = url_ftell(out); + url_fseek(out, entries_pos, SEEK_SET); + put_be16(out, entries); + url_fseek(out, curpos, SEEK_SET); + } + + curpos = url_ftell(out); + url_fseek(out, count_pos, SEEK_SET); + put_be16(out, count); + url_fseek(out, curpos, SEEK_SET); + return count; +} + +int ff_mov_add_hinted_packet(AVFormatContext *s, AVPacket *pkt, + int track_index, int sample) +{ + MOVMuxContext *mov = s->priv_data; + MOVTrack *trk = &mov->tracks[track_index]; + AVFormatContext *rtp_ctx = trk->rtp_ctx; + uint8_t *buf = NULL; + int size; + ByteIOContext *hintbuf = NULL; + AVPacket hint_pkt; + AVPacket local_pkt; + int ret = 0, count; + + if (!rtp_ctx) + return AVERROR(ENOENT); + if (!rtp_ctx->pb) + return AVERROR(ENOMEM); + + sample_queue_push(&trk->sample_queue, pkt, sample); + + /* Feed the packet to the RTP muxer */ + local_pkt = *pkt; + local_pkt.stream_index = 0; + local_pkt.pts = av_rescale_q(pkt->pts, + s->streams[pkt->stream_index]->time_base, + rtp_ctx->streams[0]->time_base); + local_pkt.dts = av_rescale_q(pkt->dts, + s->streams[pkt->stream_index]->time_base, + rtp_ctx->streams[0]->time_base); + av_write_frame(rtp_ctx, &local_pkt); + + /* Fetch the output from the RTP muxer, open a new output buffer + * for next time. */ + size = url_close_dyn_buf(rtp_ctx->pb, &buf); + if ((ret = url_open_dyn_packet_buf(&rtp_ctx->pb, + RTP_MAX_PACKET_SIZE)) < 0) + goto done; + + if (size <= 0) + goto done; + + /* Open a buffer for writing the hint */ + if ((ret = url_open_dyn_buf(&hintbuf)) < 0) + goto done; + av_init_packet(&hint_pkt); + count = write_hint_packets(hintbuf, buf, size, trk, &hint_pkt.dts); + av_freep(&buf); + + /* Write the hint data into the hint track */ + hint_pkt.size = size = url_close_dyn_buf(hintbuf, &buf); + hint_pkt.data = buf; + hint_pkt.pts = hint_pkt.dts; + hint_pkt.stream_index = track_index; + if (pkt->flags & AV_PKT_FLAG_KEY) + hint_pkt.flags |= AV_PKT_FLAG_KEY; + if (count > 0) + ff_mov_write_packet(s, &hint_pkt); +done: + av_free(buf); + sample_queue_retain(&trk->sample_queue); + return ret; +} + +void ff_mov_close_hinting(MOVTrack *track) { + AVFormatContext* rtp_ctx = track->rtp_ctx; + uint8_t *ptr; + + av_freep(&track->enc); + sample_queue_free(&track->sample_queue); + if (!rtp_ctx) + return; + if (rtp_ctx->pb) { + av_write_trailer(rtp_ctx); + url_close_dyn_buf(rtp_ctx->pb, &ptr); + av_free(ptr); + } + av_metadata_free(&rtp_ctx->streams[0]->metadata); + av_metadata_free(&rtp_ctx->metadata); + av_free(rtp_ctx->streams[0]); + av_freep(&rtp_ctx); +} + diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/mp3.c b/src/add-ons/media/plugins/ffmpeg/libavformat/mp3.c index c80b5d44f5..dcb59e8417 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/mp3.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/mp3.c @@ -21,12 +21,16 @@ #include #include "libavutil/avstring.h" -#include "libavcodec/mpegaudio.h" -#include "libavcodec/mpegaudiodecheader.h" +#include "libavutil/intreadwrite.h" #include "avformat.h" #include "id3v2.h" #include "id3v1.h" +#if CONFIG_MP3_DEMUXER + +#include "libavcodec/mpegaudio.h" +#include "libavcodec/mpegaudiodecheader.h" + /* mp3 read */ static int mp3_read_probe(AVProbeData *p) @@ -41,10 +45,12 @@ static int mp3_read_probe(AVProbeData *p) if(ff_id3v2_match(buf0)) { buf0 += ff_id3v2_tag_len(buf0); } + end = p->buf + p->buf_size - sizeof(uint32_t); + while(buf0 < end && !*buf0) + buf0++; max_frames = 0; buf = buf0; - end = p->buf + p->buf_size - sizeof(uint32_t); for(; buf < end; buf= buf2+1) { buf2 = buf; @@ -60,7 +66,9 @@ static int mp3_read_probe(AVProbeData *p) if(buf == buf0) first_frames= frames; } - if (first_frames>=3) return AVPROBE_SCORE_MAX/2+1; + // keep this in sync with ac3 probe, both need to avoid + // issues with MPEG-files! + if (first_frames>=4) return AVPROBE_SCORE_MAX/2+1; else if(max_frames>500)return AVPROBE_SCORE_MAX/2; else if(max_frames>=4) return AVPROBE_SCORE_MAX/4; else if(buf0!=p->buf) return AVPROBE_SCORE_MAX/4-1; @@ -132,15 +140,20 @@ static int mp3_read_header(AVFormatContext *s, if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_MP3; st->need_parsing = AVSTREAM_PARSE_FULL; st->start_time = 0; - ff_id3v1_read(s); - ff_id3v2_read(s); + // lcm of all mp3 sample rates + av_set_pts_info(st, 64, 1, 14112000); + ff_id3v2_read(s); off = url_ftell(s->pb); + + if (!av_metadata_get(s->metadata, "", NULL, AV_METADATA_IGNORE_SUFFIX)) + ff_id3v1_read(s); + if (mp3_parse_vbr_tags(s, st, off) < 0) url_fseek(s->pb, off, SEEK_SET); @@ -169,6 +182,19 @@ static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt) return ret; } +AVInputFormat mp3_demuxer = { + "mp3", + NULL_IF_CONFIG_SMALL("MPEG audio layer 2/3"), + 0, + mp3_read_probe, + mp3_read_header, + mp3_read_packet, + .flags= AVFMT_GENERIC_INDEX, + .extensions = "mp2,mp3,m2a", /* XXX: use probe */ + .metadata_conv = ff_id3v2_metadata_conv, +}; +#endif + #if CONFIG_MP2_MUXER || CONFIG_MP3_MUXER static int id3v1_set_string(AVFormatContext *s, const char *key, uint8_t *buf, int buf_size) @@ -191,13 +217,14 @@ static int id3v1_create_tag(AVFormatContext *s, uint8_t *buf) count += id3v1_set_string(s, "title", buf + 3, 30); count += id3v1_set_string(s, "author", buf + 33, 30); count += id3v1_set_string(s, "album", buf + 63, 30); - count += id3v1_set_string(s, "year", buf + 93, 4); + count += id3v1_set_string(s, "date", buf + 93, 4); count += id3v1_set_string(s, "comment", buf + 97, 30); if ((tag = av_metadata_get(s->metadata, "track", NULL, 0))) { buf[125] = 0; buf[126] = atoi(tag->value); count++; } + buf[127] = 0xFF; /* default to unknown genre */ if ((tag = av_metadata_get(s->metadata, "genre", NULL, 0))) { for(i = 0; i <= ID3v1_GENRE_MAX; i++) { if (!strcasecmp(tag->value, ff_id3v1_genre_str[i])) { @@ -220,65 +247,17 @@ static void id3v2_put_size(AVFormatContext *s, int size) put_byte(s->pb, size & 0x7f); } -static void id3v2_put_ttag(AVFormatContext *s, const char *string, uint32_t tag) +static void id3v2_put_ttag(AVFormatContext *s, const char *buf, int len, + uint32_t tag) { - int len = strlen(string); put_be32(s->pb, tag); id3v2_put_size(s, len + 1); put_be16(s->pb, 0); put_byte(s->pb, 3); /* UTF-8 */ - put_buffer(s->pb, string, len); + put_buffer(s->pb, buf, len); } -/** - * Write an ID3v2.4 header at beginning of stream - */ - -static int mp3_write_header(struct AVFormatContext *s) -{ - AVMetadataTag *title, *author, *album, *genre, *copyright, *track, *year; - int totlen = 0; - - title = av_metadata_get(s->metadata, "title", NULL, 0); - author = av_metadata_get(s->metadata, "author", NULL, 0); - album = av_metadata_get(s->metadata, "album", NULL, 0); - genre = av_metadata_get(s->metadata, "genre", NULL, 0); - copyright = av_metadata_get(s->metadata, "copyright", NULL, 0); - track = av_metadata_get(s->metadata, "track", NULL, 0); - year = av_metadata_get(s->metadata, "year", NULL, 0); - - if(title) totlen += 11 + strlen(title->value); - if(author) totlen += 11 + strlen(author->value); - if(album) totlen += 11 + strlen(album->value); - if(genre) totlen += 11 + strlen(genre->value); - if(copyright) totlen += 11 + strlen(copyright->value); - if(track) totlen += 11 + strlen(track->value); - if(year) totlen += 11 + strlen(year->value); - if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) - totlen += strlen(LIBAVFORMAT_IDENT) + 11; - - if(totlen == 0) - return 0; - - put_be32(s->pb, MKBETAG('I', 'D', '3', 0x04)); /* ID3v2.4 */ - put_byte(s->pb, 0); - put_byte(s->pb, 0); /* flags */ - - id3v2_put_size(s, totlen); - - if(title) id3v2_put_ttag(s, title->value, MKBETAG('T', 'I', 'T', '2')); - if(author) id3v2_put_ttag(s, author->value, MKBETAG('T', 'P', 'E', '1')); - if(album) id3v2_put_ttag(s, album->value, MKBETAG('T', 'A', 'L', 'B')); - if(genre) id3v2_put_ttag(s, genre->value, MKBETAG('T', 'C', 'O', 'N')); - if(copyright) id3v2_put_ttag(s, copyright->value, MKBETAG('T', 'C', 'O', 'P')); - if(track) id3v2_put_ttag(s, track->value, MKBETAG('T', 'R', 'C', 'K')); - if(year) id3v2_put_ttag(s, year->value, MKBETAG('T', 'Y', 'E', 'R')); - if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) - id3v2_put_ttag(s, LIBAVFORMAT_IDENT, MKBETAG('T', 'E', 'N', 'C')); - return 0; -} - static int mp3_write_packet(struct AVFormatContext *s, AVPacket *pkt) { put_buffer(s->pb, pkt->data, pkt->size); @@ -299,18 +278,6 @@ static int mp3_write_trailer(struct AVFormatContext *s) } #endif /* CONFIG_MP2_MUXER || CONFIG_MP3_MUXER */ -#if CONFIG_MP3_DEMUXER -AVInputFormat mp3_demuxer = { - "mp3", - NULL_IF_CONFIG_SMALL("MPEG audio layer 2/3"), - 0, - mp3_read_probe, - mp3_read_header, - mp3_read_packet, - .flags= AVFMT_GENERIC_INDEX, - .extensions = "mp2,mp3,m2a", /* XXX: use probe */ -}; -#endif #if CONFIG_MP2_MUXER AVOutputFormat mp2_muxer = { "mp2", @@ -325,7 +292,63 @@ AVOutputFormat mp2_muxer = { mp3_write_trailer, }; #endif + #if CONFIG_MP3_MUXER +/** + * Write an ID3v2.4 header at beginning of stream + */ + +static int mp3_write_header(struct AVFormatContext *s) +{ + AVMetadataTag *t = NULL; + int totlen = 0; + int64_t size_pos, cur_pos; + + put_be32(s->pb, MKBETAG('I', 'D', '3', 0x04)); /* ID3v2.4 */ + put_byte(s->pb, 0); + put_byte(s->pb, 0); /* flags */ + + /* reserve space for size */ + size_pos = url_ftell(s->pb); + put_be32(s->pb, 0); + + while ((t = av_metadata_get(s->metadata, "", t, AV_METADATA_IGNORE_SUFFIX))) { + uint32_t tag = 0; + + if (t->key[0] == 'T' && strlen(t->key) == 4) { + int i; + for (i = 0; *ff_id3v2_tags[i]; i++) + if (AV_RB32(t->key) == AV_RB32(ff_id3v2_tags[i])) { + int len = strlen(t->value); + tag = AV_RB32(t->key); + totlen += len + ID3v2_HEADER_SIZE + 2; + id3v2_put_ttag(s, t->value, len + 1, tag); + break; + } + } + + if (!tag) { /* unknown tag, write as TXXX frame */ + int len = strlen(t->key), len1 = strlen(t->value); + char *buf = av_malloc(len + len1 + 2); + if (!buf) + return AVERROR(ENOMEM); + tag = MKBETAG('T', 'X', 'X', 'X'); + strcpy(buf, t->key); + strcpy(buf + len + 1, t->value); + id3v2_put_ttag(s, buf, len + len1 + 2, tag); + totlen += len + len1 + ID3v2_HEADER_SIZE + 3; + av_free(buf); + } + } + + cur_pos = url_ftell(s->pb); + url_fseek(s->pb, size_pos, SEEK_SET); + id3v2_put_size(s, totlen); + url_fseek(s->pb, cur_pos, SEEK_SET); + + return 0; +} + AVOutputFormat mp3_muxer = { "mp3", NULL_IF_CONFIG_SMALL("MPEG audio layer 3"), @@ -337,5 +360,7 @@ AVOutputFormat mp3_muxer = { mp3_write_header, mp3_write_packet, mp3_write_trailer, + AVFMT_NOTIMESTAMPS, + .metadata_conv = ff_id3v2_metadata_conv, }; #endif diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/mpc.c b/src/add-ons/media/plugins/ffmpeg/libavformat/mpc.c index ea6e3c6460..4dda65dbca 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/mpc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/mpc.c @@ -104,7 +104,7 @@ static int mpc_read_header(AVFormatContext *s, AVFormatParameters *ap) st = av_new_stream(s, 0); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_MUSEPACK7; st->codec->channels = 2; st->codec->bits_per_coded_sample = 16; @@ -115,8 +115,8 @@ static int mpc_read_header(AVFormatContext *s, AVFormatParameters *ap) st->codec->sample_rate = mpc_rate[st->codec->extradata[2] & 3]; av_set_pts_info(st, 32, MPC_FRAMESIZE, st->codec->sample_rate); /* scan for seekpoints */ - s->start_time = 0; - s->duration = (int64_t)c->fcount * MPC_FRAMESIZE * AV_TIME_BASE / st->codec->sample_rate; + st->start_time = 0; + st->duration = c->fcount; /* try to read APE tags */ if (!url_is_streamed(s->pb)) { @@ -170,6 +170,8 @@ static int mpc_read_packet(AVFormatContext *s, AVPacket *pkt) pkt->data[0] = curbits; pkt->data[1] = (c->curframe > c->fcount); + pkt->data[2] = 0; + pkt->data[3] = 0; pkt->stream_index = 0; pkt->pts = cur; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/mpc8.c b/src/add-ons/media/plugins/ffmpeg/libavformat/mpc8.c index 687853bcde..92e996c29c 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/mpc8.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/mpc8.c @@ -51,10 +51,54 @@ typedef struct { int64_t samples; } MPCContext; +static inline int64_t bs_get_v(uint8_t **bs) +{ + int64_t v = 0; + int br = 0; + int c; + + do { + c = **bs; (*bs)++; + v <<= 7; + v |= c & 0x7F; + br++; + if (br > 10) + return -1; + } while (c & 0x80); + + return v - br; +} + static int mpc8_probe(AVProbeData *p) { - if (AV_RL32(p->buf) == TAG_MPCK) - return AVPROBE_SCORE_MAX; + uint8_t *bs = p->buf + 4; + uint8_t *bs_end = bs + p->buf_size; + int64_t size; + + if (p->buf_size < 16) + return 0; + if (AV_RL32(p->buf) != TAG_MPCK) + return 0; + while (bs < bs_end + 3) { + int header_found = (bs[0] == 'S' && bs[1] == 'H'); + if (bs[0] < 'A' || bs[0] > 'Z' || bs[1] < 'A' || bs[1] > 'Z') + return 0; + bs += 2; + size = bs_get_v(&bs); + if (size < 2) + return 0; + if (bs + size - 2 >= bs_end) + return AVPROBE_SCORE_MAX / 4 - 1; //seems to be valid MPC but no header yet + if (header_found) { + if (size < 11 || size > 28) + return 0; + if (!AV_RL32(bs)) //zero CRC is invalid + return 0; + return AVPROBE_SCORE_MAX; + } else { + bs += size - 2; + } + } return 0; } @@ -180,7 +224,7 @@ static int mpc8_read_header(AVFormatContext *s, AVFormatParameters *ap) st = av_new_stream(s, 0); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_MUSEPACK8; st->codec->bits_per_coded_sample = 16; @@ -206,6 +250,8 @@ static int mpc8_read_packet(AVFormatContext *s, AVPacket *pkt) while(!url_feof(s->pb)){ pos = url_ftell(s->pb); mpc8_get_chunk_header(s->pb, &tag, &size); + if (size < 0) + return -1; if(tag == TAG_AUDIOPACKET){ if(av_get_packet(s->pb, pkt, size) < 0) return AVERROR(ENOMEM); diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/mpeg.c b/src/add-ons/media/plugins/ffmpeg/libavformat/mpeg.c index 40202e0652..4224a04b37 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/mpeg.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/mpeg.c @@ -76,15 +76,16 @@ static int mpegps_probe(AVProbeData *p) if(vid+audio > invalid) /* invalid VDR files nd short PES streams */ score= AVPROBE_SCORE_MAX/4; -//av_log(NULL, AV_LOG_ERROR, "%d %d %d %d %d len:%d\n", sys, priv1, pspack,vid, audio, p->buf_size); +//av_log(NULL, AV_LOG_ERROR, "%d %d %d %d %d %d len:%d\n", sys, priv1, pspack,vid, audio, invalid, p->buf_size); if(sys>invalid && sys*9 <= pspack*10) - return AVPROBE_SCORE_MAX/2+2; // +1 for .mpg - if(priv1 + vid + audio > invalid && (priv1+vid+audio)*9 <= pspack*10) - return AVPROBE_SCORE_MAX/2+2; // +1 for .mpg - if((!!vid ^ !!audio) && (audio > 4 || vid > 1) && !sys && !pspack && p->buf_size>2048) /* PES stream */ - return AVPROBE_SCORE_MAX/2+2; + return pspack > 2 ? AVPROBE_SCORE_MAX/2+2 : AVPROBE_SCORE_MAX/4; // +1 for .mpg + if(pspack > invalid && (priv1+vid+audio)*10 >= pspack*9) + return pspack > 2 ? AVPROBE_SCORE_MAX/2+2 : AVPROBE_SCORE_MAX/4; // +1 for .mpg + if((!!vid ^ !!audio) && (audio > 4 || vid > 1) && !sys && !pspack && p->buf_size>2048 && vid + audio > invalid) /* PES stream */ + return (audio > 12 || vid > 3) ? AVPROBE_SCORE_MAX/2+2 : AVPROBE_SCORE_MAX/4; //02-Penguin.flac has sys:0 priv1:0 pspack:0 vid:0 audio:1 + //mp3_misidentified_2.mp3 has sys:0 priv1:0 pspack:0 vid:0 audio:6 return score; } @@ -112,6 +113,8 @@ static int mpegps_read_header(AVFormatContext *s, m->sofdec++; } while (v == sofdec[i] && i++ < 6); + m->sofdec = (m->sofdec == 6) ? 1 : 0; + /* no need to do more */ return 0; } @@ -244,8 +247,13 @@ static int mpegps_read_pes_header(AVFormatContext *s, startcode = find_next_start_code(s->pb, &size, &m->header_state); last_sync = url_ftell(s->pb); //printf("startcode=%x pos=0x%"PRIx64"\n", startcode, url_ftell(s->pb)); - if (startcode < 0) - return AVERROR(EIO); + if (startcode < 0){ + if(url_feof(s->pb)) + return AVERROR_EOF; + //FIXME we should remember header_state + return AVERROR(EAGAIN); + } + if (startcode == PACK_START_CODE) goto redo; if (startcode == SYSTEM_HEADER_START_CODE) @@ -409,7 +417,7 @@ static int mpegps_read_packet(AVFormatContext *s, AVStream *st; int len, startcode, i, es_type; enum CodecID codec_id = CODEC_ID_NONE; - enum CodecType type; + enum AVMediaType type; int64_t pts, dts, dummy_pos; //dummy_pos is needed for the index building to work uint8_t av_uninit(dvdaudio_substream_type); @@ -435,26 +443,26 @@ static int mpegps_read_packet(AVFormatContext *s, if(es_type > 0 && es_type != STREAM_TYPE_PRIVATE_DATA){ if(es_type == STREAM_TYPE_VIDEO_MPEG1){ codec_id = CODEC_ID_MPEG2VIDEO; - type = CODEC_TYPE_VIDEO; + type = AVMEDIA_TYPE_VIDEO; } else if(es_type == STREAM_TYPE_VIDEO_MPEG2){ codec_id = CODEC_ID_MPEG2VIDEO; - type = CODEC_TYPE_VIDEO; + type = AVMEDIA_TYPE_VIDEO; } else if(es_type == STREAM_TYPE_AUDIO_MPEG1 || es_type == STREAM_TYPE_AUDIO_MPEG2){ codec_id = CODEC_ID_MP3; - type = CODEC_TYPE_AUDIO; + type = AVMEDIA_TYPE_AUDIO; } else if(es_type == STREAM_TYPE_AUDIO_AAC){ codec_id = CODEC_ID_AAC; - type = CODEC_TYPE_AUDIO; + type = AVMEDIA_TYPE_AUDIO; } else if(es_type == STREAM_TYPE_VIDEO_MPEG4){ codec_id = CODEC_ID_MPEG4; - type = CODEC_TYPE_VIDEO; + type = AVMEDIA_TYPE_VIDEO; } else if(es_type == STREAM_TYPE_VIDEO_H264){ codec_id = CODEC_ID_H264; - type = CODEC_TYPE_VIDEO; + type = AVMEDIA_TYPE_VIDEO; } else if(es_type == STREAM_TYPE_AUDIO_AC3){ codec_id = CODEC_ID_AC3; - type = CODEC_TYPE_AUDIO; + type = AVMEDIA_TYPE_AUDIO; } else { goto skip; } @@ -467,38 +475,38 @@ static int mpegps_read_packet(AVFormatContext *s, codec_id = CODEC_ID_CAVS; else codec_id = CODEC_ID_PROBE; - type = CODEC_TYPE_VIDEO; + type = AVMEDIA_TYPE_VIDEO; } else if (startcode >= 0x1c0 && startcode <= 0x1df) { - type = CODEC_TYPE_AUDIO; + type = AVMEDIA_TYPE_AUDIO; codec_id = m->sofdec > 0 ? CODEC_ID_ADPCM_ADX : CODEC_ID_MP2; } else if (startcode >= 0x80 && startcode <= 0x87) { - type = CODEC_TYPE_AUDIO; + type = AVMEDIA_TYPE_AUDIO; codec_id = CODEC_ID_AC3; } else if ( ( startcode >= 0x88 && startcode <= 0x8f) ||( startcode >= 0x98 && startcode <= 0x9f)) { /* 0x90 - 0x97 is reserved for SDDS in DVD specs */ - type = CODEC_TYPE_AUDIO; + type = AVMEDIA_TYPE_AUDIO; codec_id = CODEC_ID_DTS; } else if (startcode >= 0xa0 && startcode <= 0xaf) { - type = CODEC_TYPE_AUDIO; + type = AVMEDIA_TYPE_AUDIO; /* 16 bit form will be handled as CODEC_ID_PCM_S16BE */ codec_id = CODEC_ID_PCM_DVD; } else if (startcode >= 0xb0 && startcode <= 0xbf) { - type = CODEC_TYPE_AUDIO; + type = AVMEDIA_TYPE_AUDIO; codec_id = CODEC_ID_TRUEHD; } else if (startcode >= 0xc0 && startcode <= 0xcf) { /* Used for both AC-3 and E-AC-3 in EVOB files */ - type = CODEC_TYPE_AUDIO; + type = AVMEDIA_TYPE_AUDIO; codec_id = CODEC_ID_AC3; } else if (startcode >= 0x20 && startcode <= 0x3f) { - type = CODEC_TYPE_SUBTITLE; + type = AVMEDIA_TYPE_SUBTITLE; codec_id = CODEC_ID_DVD_SUBTITLE; } else if (startcode >= 0xfd55 && startcode <= 0xfd5f) { - type = CODEC_TYPE_VIDEO; + type = AVMEDIA_TYPE_VIDEO; codec_id = CODEC_ID_VC1; } else if (startcode == 0x1bd) { // check dvd audio substream type - type = CODEC_TYPE_AUDIO; + type = AVMEDIA_TYPE_AUDIO; switch(dvdaudio_substream_type & 0xe0) { case 0xa0: codec_id = CODEC_ID_PCM_DVD; break; @@ -554,6 +562,7 @@ static int mpegps_read_packet(AVFormatContext *s, get_buffer(s->pb, pkt->data, pkt->size); pkt->pts = pts; pkt->dts = dts; + pkt->pos = dummy_pos; pkt->stream_index = st->index; #if 0 av_log(s, AV_LOG_DEBUG, "%d: pts=%0.3f dts=%0.3f size=%d\n", diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/mpegenc.c b/src/add-ons/media/plugins/ffmpeg/libavformat/mpegenc.c index df4c9919a4..b37a774295 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/mpegenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/mpegenc.c @@ -89,7 +89,7 @@ static int put_pack_header(AVFormatContext *ctx, init_put_bits(&pb, buf, 128); - put_bits(&pb, 32, PACK_START_CODE); + put_bits32(&pb, PACK_START_CODE); if (s->is_mpeg2) { put_bits(&pb, 2, 0x1); } else { @@ -125,7 +125,7 @@ static int put_system_header(AVFormatContext *ctx, uint8_t *buf,int only_for_str init_put_bits(&pb, buf, 128); - put_bits(&pb, 32, SYSTEM_HEADER_START_CODE); + put_bits32(&pb, SYSTEM_HEADER_START_CODE); put_bits(&pb, 16, 0); put_bits(&pb, 1, 1); @@ -335,7 +335,7 @@ static int mpeg_mux_init(AVFormatContext *ctx) av_set_pts_info(st, 64, 1, 90000); switch(st->codec->codec_type) { - case CODEC_TYPE_AUDIO: + case AVMEDIA_TYPE_AUDIO: if (st->codec->codec_id == CODEC_ID_AC3) { stream->id = ac3_id++; } else if (st->codec->codec_id == CODEC_ID_DTS) { @@ -363,7 +363,7 @@ static int mpeg_mux_init(AVFormatContext *ctx) stream->max_buffer_size = 4 * 1024; s->audio_bound++; break; - case CODEC_TYPE_VIDEO: + case AVMEDIA_TYPE_VIDEO: stream->id = mpv_id++; if (st->codec->rc_buffer_size) stream->max_buffer_size = 6*1024 + st->codec->rc_buffer_size/8; @@ -379,7 +379,7 @@ static int mpeg_mux_init(AVFormatContext *ctx) #endif s->video_bound++; break; - case CODEC_TYPE_SUBTITLE: + case AVMEDIA_TYPE_SUBTITLE: stream->id = mps_id++; stream->max_buffer_size = 16 * 1024; break; @@ -1046,7 +1046,7 @@ retry: /* for subtitle, a single PES packet must be generated, so we flush after every single subtitle packet */ if(s->packet_size > avail_data && !flush - && st->codec->codec_type != CODEC_TYPE_SUBTITLE) + && st->codec->codec_type != AVMEDIA_TYPE_SUBTITLE) return 0; if(avail_data==0) continue; @@ -1156,7 +1156,7 @@ static int mpeg_mux_write_packet(AVFormatContext *ctx, AVPacket *pkt) int64_t pts, dts; PacketDesc *pkt_desc; const int preload= av_rescale(ctx->preload, 90000, AV_TIME_BASE); - const int is_iframe = st->codec->codec_type == CODEC_TYPE_VIDEO && (pkt->flags & PKT_FLAG_KEY); + const int is_iframe = st->codec->codec_type == AVMEDIA_TYPE_VIDEO && (pkt->flags & AV_PKT_FLAG_KEY); pts= pkt->pts; dts= pkt->dts; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/mpegts.c b/src/add-ons/media/plugins/ffmpeg/libavformat/mpegts.c index 6c0c314f42..59603384d2 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/mpegts.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/mpegts.c @@ -21,6 +21,7 @@ //#define DEBUG //#define DEBUG_SEEK +//#define USE_SYNCPOINT_SEARCH #include "libavutil/crc.h" #include "libavutil/intreadwrite.h" @@ -28,20 +29,17 @@ #include "avformat.h" #include "mpegts.h" #include "internal.h" +#include "seek.h" /* 1.0 second at 24Mbit/s */ #define MAX_SCAN_PACKETS 32000 /* maximum size in which we look for synchronisation if synchronisation is lost */ -#define MAX_RESYNC_SIZE 4096 +#define MAX_RESYNC_SIZE 65536 #define MAX_PES_PAYLOAD 200*1024 -typedef struct PESContext PESContext; - -static PESContext* add_pes_stream(MpegTSContext *ts, int pid, int pcr_pid, int stream_type); - enum MpegTSFilterType { MPEGTS_PES, MPEGTS_SECTION, @@ -139,23 +137,25 @@ enum MpegTSState { #define PES_HEADER_SIZE 9 #define MAX_PES_HEADER_SIZE (9 + 255) -struct PESContext { +typedef struct PESContext { int pid; int pcr_pid; /**< if -1 then all packets containing PCR are considered */ int stream_type; MpegTSContext *ts; AVFormatContext *stream; AVStream *st; + AVStream *sub_st; /**< stream for the embedded AC3 stream in HDMV TrueHD */ enum MpegTSState state; /* used to get the format */ int data_index; int total_size; int pes_header_size; + int extended_stream_id; int64_t pts, dts; int64_t ts_packet_pos; /**< position of first TS packet of this PES packet */ uint8_t header[MAX_PES_HEADER_SIZE]; uint8_t *buffer; -}; +} PESContext; extern AVInputFormat mpegts_demuxer; @@ -355,7 +355,7 @@ static void mpegts_close_filter(MpegTSContext *ts, MpegTSFilter *filter) } static int analyze(const uint8_t *buf, int size, int packet_size, int *index){ - int stat[packet_size]; + int stat[TS_MAX_PACKET_SIZE]; int i; int x=0; int best_score=0; @@ -486,48 +486,54 @@ static int parse_section_header(SectionHeader *h, typedef struct { uint32_t stream_type; - enum CodecType codec_type; + enum AVMediaType codec_type; enum CodecID codec_id; } StreamType; static const StreamType ISO_types[] = { - { 0x01, CODEC_TYPE_VIDEO, CODEC_ID_MPEG2VIDEO }, - { 0x02, CODEC_TYPE_VIDEO, CODEC_ID_MPEG2VIDEO }, - { 0x03, CODEC_TYPE_AUDIO, CODEC_ID_MP3 }, - { 0x04, CODEC_TYPE_AUDIO, CODEC_ID_MP3 }, - { 0x0f, CODEC_TYPE_AUDIO, CODEC_ID_AAC }, - { 0x10, CODEC_TYPE_VIDEO, CODEC_ID_MPEG4 }, - { 0x1b, CODEC_TYPE_VIDEO, CODEC_ID_H264 }, - { 0xd1, CODEC_TYPE_VIDEO, CODEC_ID_DIRAC }, - { 0xea, CODEC_TYPE_VIDEO, CODEC_ID_VC1 }, + { 0x01, AVMEDIA_TYPE_VIDEO, CODEC_ID_MPEG2VIDEO }, + { 0x02, AVMEDIA_TYPE_VIDEO, CODEC_ID_MPEG2VIDEO }, + { 0x03, AVMEDIA_TYPE_AUDIO, CODEC_ID_MP3 }, + { 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 syntax */ + { 0x1b, AVMEDIA_TYPE_VIDEO, CODEC_ID_H264 }, + { 0xd1, AVMEDIA_TYPE_VIDEO, CODEC_ID_DIRAC }, + { 0xea, AVMEDIA_TYPE_VIDEO, CODEC_ID_VC1 }, { 0 }, }; static const StreamType HDMV_types[] = { - { 0x81, CODEC_TYPE_AUDIO, CODEC_ID_AC3 }, - { 0x82, CODEC_TYPE_AUDIO, CODEC_ID_DTS }, + { 0x80, AVMEDIA_TYPE_AUDIO, CODEC_ID_PCM_BLURAY }, + { 0x81, AVMEDIA_TYPE_AUDIO, CODEC_ID_AC3 }, + { 0x82, AVMEDIA_TYPE_AUDIO, CODEC_ID_DTS }, + { 0x83, AVMEDIA_TYPE_AUDIO, CODEC_ID_TRUEHD }, + { 0x84, AVMEDIA_TYPE_AUDIO, CODEC_ID_EAC3 }, + { 0x90, AVMEDIA_TYPE_SUBTITLE, CODEC_ID_HDMV_PGS_SUBTITLE }, { 0 }, }; /* ATSC ? */ static const StreamType MISC_types[] = { - { 0x81, CODEC_TYPE_AUDIO, CODEC_ID_AC3 }, - { 0x8a, CODEC_TYPE_AUDIO, CODEC_ID_DTS }, + { 0x81, AVMEDIA_TYPE_AUDIO, CODEC_ID_AC3 }, + { 0x8a, AVMEDIA_TYPE_AUDIO, CODEC_ID_DTS }, { 0 }, }; static const StreamType REGD_types[] = { - { MKTAG('d','r','a','c'), CODEC_TYPE_VIDEO, CODEC_ID_DIRAC }, - { MKTAG('A','C','-','3'), CODEC_TYPE_AUDIO, CODEC_ID_AC3 }, + { MKTAG('d','r','a','c'), AVMEDIA_TYPE_VIDEO, CODEC_ID_DIRAC }, + { MKTAG('A','C','-','3'), AVMEDIA_TYPE_AUDIO, CODEC_ID_AC3 }, { 0 }, }; /* descriptor present */ static const StreamType DESC_types[] = { - { 0x6a, CODEC_TYPE_AUDIO, CODEC_ID_AC3 }, /* AC-3 descriptor */ - { 0x7a, CODEC_TYPE_AUDIO, CODEC_ID_EAC3 }, /* E-AC-3 descriptor */ - { 0x7b, CODEC_TYPE_AUDIO, CODEC_ID_DTS }, - { 0x59, CODEC_TYPE_SUBTITLE, CODEC_ID_DVB_SUBTITLE }, /* subtitling descriptor */ + { 0x6a, AVMEDIA_TYPE_AUDIO, CODEC_ID_AC3 }, /* AC-3 descriptor */ + { 0x7a, AVMEDIA_TYPE_AUDIO, CODEC_ID_EAC3 }, /* E-AC-3 descriptor */ + { 0x7b, AVMEDIA_TYPE_AUDIO, CODEC_ID_DTS }, + { 0x56, AVMEDIA_TYPE_SUBTITLE, CODEC_ID_DVB_TELETEXT }, + { 0x59, AVMEDIA_TYPE_SUBTITLE, CODEC_ID_DVB_SUBTITLE }, /* subtitling descriptor */ { 0 }, }; @@ -543,44 +549,306 @@ static void mpegts_find_stream_type(AVStream *st, } } -static AVStream *new_pes_av_stream(PESContext *pes, uint32_t prog_reg_desc, uint32_t code) +static int mpegts_set_stream_info(AVStream *st, PESContext *pes, + uint32_t stream_type, uint32_t prog_reg_desc) { - AVStream *st = av_new_stream(pes->stream, pes->pid); - - if (!st) - return NULL; - av_set_pts_info(st, 33, 1, 90000); st->priv_data = pes; - st->codec->codec_type = CODEC_TYPE_DATA; + st->codec->codec_type = AVMEDIA_TYPE_DATA; st->codec->codec_id = CODEC_ID_NONE; st->need_parsing = AVSTREAM_PARSE_FULL; pes->st = st; + pes->stream_type = stream_type; - dprintf(pes->stream, "stream_type=%x pid=%x prog_reg_desc=%.4s\n", - pes->stream_type, pes->pid, (char*)&prog_reg_desc); + av_log(pes->stream, AV_LOG_DEBUG, + "stream=%d stream_type=%x pid=%x prog_reg_desc=%.4s\n", + st->index, pes->stream_type, pes->pid, (char*)&prog_reg_desc); st->codec->codec_tag = pes->stream_type; mpegts_find_stream_type(st, pes->stream_type, ISO_types); if (prog_reg_desc == AV_RL32("HDMV") && - st->codec->codec_id == CODEC_ID_NONE) + st->codec->codec_id == CODEC_ID_NONE) { mpegts_find_stream_type(st, pes->stream_type, HDMV_types); + if (pes->stream_type == 0x83) { + // HDMV TrueHD streams also contain an AC3 coded version of the + // audio track - add a second stream for this + AVStream *sub_st; + // priv_data cannot be shared between streams + PESContext *sub_pes = av_malloc(sizeof(*sub_pes)); + if (!sub_pes) + return AVERROR(ENOMEM); + memcpy(sub_pes, pes, sizeof(*sub_pes)); + + sub_st = av_new_stream(pes->stream, pes->pid); + if (!sub_st) { + av_free(sub_pes); + return AVERROR(ENOMEM); + } + + av_set_pts_info(sub_st, 33, 1, 90000); + sub_st->priv_data = sub_pes; + sub_st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + sub_st->codec->codec_id = CODEC_ID_AC3; + sub_st->need_parsing = AVSTREAM_PARSE_FULL; + sub_pes->sub_st = pes->sub_st = sub_st; + } + } + if (pes->stream_type == 0x11) + av_log(pes->stream, AV_LOG_WARNING, + "AAC LATM not currently supported, patch welcome\n"); if (st->codec->codec_id == CODEC_ID_NONE) mpegts_find_stream_type(st, pes->stream_type, MISC_types); - /* stream was not present in PMT, guess based on PES start code */ - if (st->codec->codec_id == CODEC_ID_NONE) { - if (code >= 0x1c0 && code <= 0x1df) { - st->codec->codec_type = CODEC_TYPE_AUDIO; - st->codec->codec_id = CODEC_ID_MP2; - } else if (code == 0x1bd) { - st->codec->codec_type = CODEC_TYPE_AUDIO; - st->codec->codec_id = CODEC_ID_AC3; + return 0; +} + +static int64_t get_pts(const uint8_t *p) +{ + int64_t pts = (int64_t)((p[0] >> 1) & 0x07) << 30; + pts |= (AV_RB16(p + 1) >> 1) << 15; + pts |= AV_RB16(p + 3) >> 1; + return pts; +} + +static void new_pes_packet(PESContext *pes, AVPacket *pkt) +{ + av_init_packet(pkt); + + pkt->destruct = av_destruct_packet; + pkt->data = pes->buffer; + pkt->size = pes->data_index; + memset(pkt->data+pkt->size, 0, FF_INPUT_BUFFER_PADDING_SIZE); + + // Separate out the AC3 substream from an HDMV combined TrueHD/AC3 PID + if (pes->sub_st && pes->stream_type == 0x83 && pes->extended_stream_id == 0x76) + pkt->stream_index = pes->sub_st->index; + else + pkt->stream_index = pes->st->index; + pkt->pts = pes->pts; + pkt->dts = pes->dts; + /* store position of first TS packet of this PES packet */ + pkt->pos = pes->ts_packet_pos; + + /* reset pts values */ + pes->pts = AV_NOPTS_VALUE; + pes->dts = AV_NOPTS_VALUE; + pes->buffer = NULL; + pes->data_index = 0; +} + +/* return non zero if a packet could be constructed */ +static int mpegts_push_data(MpegTSFilter *filter, + const uint8_t *buf, int buf_size, int is_start, + int64_t pos) +{ + PESContext *pes = filter->u.pes_filter.opaque; + MpegTSContext *ts = pes->ts; + const uint8_t *p; + int len, code; + + if(!ts->pkt) + return 0; + + if (is_start) { + if (pes->state == MPEGTS_PAYLOAD && pes->data_index > 0) { + new_pes_packet(pes, ts->pkt); + ts->stop_parse = 1; + } + pes->state = MPEGTS_HEADER; + pes->data_index = 0; + pes->ts_packet_pos = pos; + } + p = buf; + while (buf_size > 0) { + switch(pes->state) { + case MPEGTS_HEADER: + len = PES_START_SIZE - pes->data_index; + if (len > buf_size) + len = buf_size; + memcpy(pes->header + pes->data_index, p, len); + pes->data_index += len; + p += len; + buf_size -= len; + if (pes->data_index == PES_START_SIZE) { + /* we got all the PES or section header. We can now + decide */ +#if 0 + av_hex_dump_log(pes->stream, AV_LOG_DEBUG, pes->header, pes->data_index); +#endif + if (pes->header[0] == 0x00 && pes->header[1] == 0x00 && + pes->header[2] == 0x01) { + /* it must be an mpeg2 PES stream */ + code = pes->header[3] | 0x100; + dprintf(pes->stream, "pid=%x pes_code=%#x\n", pes->pid, code); + + if ((!pes->st && pes->stream->nb_streams == MAX_STREAMS) || + (pes->st && pes->st->discard == AVDISCARD_ALL) || + code == 0x1be) /* padding_stream */ + goto skip; + + /* stream not present in PMT */ + if (!pes->st) { + pes->st = av_new_stream(ts->stream, pes->pid); + if (!pes->st) + return AVERROR(ENOMEM); + mpegts_set_stream_info(pes->st, pes, 0, 0); + } + + pes->total_size = AV_RB16(pes->header + 4); + /* NOTE: a zero total size means the PES size is + unbounded */ + if (!pes->total_size) + pes->total_size = MAX_PES_PAYLOAD; + + /* allocate pes buffer */ + pes->buffer = av_malloc(pes->total_size+FF_INPUT_BUFFER_PADDING_SIZE); + if (!pes->buffer) + return AVERROR(ENOMEM); + + if (code != 0x1bc && code != 0x1bf && /* program_stream_map, private_stream_2 */ + code != 0x1f0 && code != 0x1f1 && /* ECM, EMM */ + 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) { + dprintf(pes->stream, "pid=%x stream_type=%x probing\n", + pes->pid, pes->stream_type); + pes->st->codec->codec_id = CODEC_ID_PROBE; + } + } else { + pes->state = MPEGTS_PAYLOAD; + pes->data_index = 0; + } + } else { + /* otherwise, it should be a table */ + /* skip packet */ + skip: + pes->state = MPEGTS_SKIP; + continue; + } + } + break; + /**********************************************/ + /* PES packing parsing */ + case MPEGTS_PESHEADER: + len = PES_HEADER_SIZE - pes->data_index; + if (len < 0) + return -1; + if (len > buf_size) + len = buf_size; + memcpy(pes->header + pes->data_index, p, len); + pes->data_index += len; + p += len; + buf_size -= len; + if (pes->data_index == PES_HEADER_SIZE) { + pes->pes_header_size = pes->header[8] + 9; + pes->state = MPEGTS_PESHEADER_FILL; + } + break; + case MPEGTS_PESHEADER_FILL: + len = pes->pes_header_size - pes->data_index; + if (len < 0) + return -1; + if (len > buf_size) + len = buf_size; + memcpy(pes->header + pes->data_index, p, len); + pes->data_index += len; + p += len; + buf_size -= len; + if (pes->data_index == pes->pes_header_size) { + const uint8_t *r; + unsigned int flags, pes_ext, skip; + + flags = pes->header[7]; + r = pes->header + 9; + pes->pts = AV_NOPTS_VALUE; + pes->dts = AV_NOPTS_VALUE; + if ((flags & 0xc0) == 0x80) { + pes->dts = pes->pts = get_pts(r); + r += 5; + } else if ((flags & 0xc0) == 0xc0) { + pes->pts = get_pts(r); + r += 5; + pes->dts = get_pts(r); + r += 5; + } + pes->extended_stream_id = -1; + if (flags & 0x01) { /* PES extension */ + pes_ext = *r++; + /* Skip PES private data, program packet sequence counter and P-STD buffer */ + skip = (pes_ext >> 4) & 0xb; + skip += skip & 0x9; + r += skip; + if ((pes_ext & 0x41) == 0x01 && + (r + 2) <= (pes->header + pes->pes_header_size)) { + /* PES extension 2 */ + if ((r[0] & 0x7f) > 0 && (r[1] & 0x80) == 0) + pes->extended_stream_id = r[1]; + } + } + + /* we got the full header. We parse it and get the payload */ + pes->state = MPEGTS_PAYLOAD; + pes->data_index = 0; + } + break; + case MPEGTS_PAYLOAD: + if (buf_size > 0 && pes->buffer) { + if (pes->data_index+buf_size > pes->total_size) { + new_pes_packet(pes, ts->pkt); + pes->total_size = MAX_PES_PAYLOAD; + pes->buffer = av_malloc(pes->total_size+FF_INPUT_BUFFER_PADDING_SIZE); + if (!pes->buffer) + return AVERROR(ENOMEM); + ts->stop_parse = 1; + } + memcpy(pes->buffer+pes->data_index, p, buf_size); + pes->data_index += buf_size; + } + buf_size = 0; + /* emit complete packets with known packet size + * decreases demuxer delay for infrequent packets like subtitles from + * a couple of seconds to milliseconds for properly muxed files. + * total_size is the number of bytes following pes_packet_length + * in the pes header, i.e. not counting the first 6 bytes */ + if (pes->total_size < MAX_PES_PAYLOAD && + pes->pes_header_size + pes->data_index == pes->total_size + 6) { + ts->stop_parse = 1; + new_pes_packet(pes, ts->pkt); + } + break; + case MPEGTS_SKIP: + buf_size = 0; + break; } } - return st; + return 0; +} + +static PESContext *add_pes_stream(MpegTSContext *ts, int pid, int pcr_pid) +{ + MpegTSFilter *tss; + PESContext *pes; + + /* if no pid found, then add a pid context */ + pes = av_mallocz(sizeof(PESContext)); + if (!pes) + return 0; + pes->ts = ts; + pes->stream = ts->stream; + pes->pid = pid; + pes->pcr_pid = pcr_pid; + pes->state = MPEGTS_SKIP; + pes->pts = AV_NOPTS_VALUE; + pes->dts = AV_NOPTS_VALUE; + tss = mpegts_open_pes_filter(ts, pid, mpegts_push_data, pes); + if (!tss) { + av_free(pes); + return 0; + } + return pes; } static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len) @@ -660,17 +928,20 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len 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, stream_type); + pes = add_pes_stream(ts, pid, pcr_pid); if (pes) - st = new_pes_av_stream(pes, prog_reg_desc, 0); + st = av_new_stream(pes->stream, pes->pid); } if (!st) return; + if (!pes->stream_type) + mpegts_set_stream_info(st, pes, stream_type, prog_reg_desc); + add_pid_to_pmt(ts, h->id, pid); - av_program_add_stream_index(ts->stream, h->id, st->index); + ff_program_add_stream_index(ts->stream, h->id, st->index); desc_list_len = get16(&p, p_end) & 0xfff; if (desc_list_len < 0) @@ -697,6 +968,13 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len mpegts_find_stream_type(st, desc_tag, DESC_types); switch(desc_tag) { + case 0x56: /* DVB teletext descriptor */ + language[0] = get8(&p, desc_end); + language[1] = get8(&p, desc_end); + language[2] = get8(&p, desc_end); + language[3] = 0; + av_metadata_set2(&st->metadata, "language", language, 0); + break; case 0x59: /* subtitling descriptor */ language[0] = get8(&p, desc_end); language[1] = get8(&p, desc_end); @@ -706,14 +984,14 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len comp_page = get16(&p, desc_end); anc_page = get16(&p, desc_end); st->codec->sub_id = (anc_page << 16) | comp_page; - av_metadata_set(&st->metadata, "language", language); + av_metadata_set2(&st->metadata, "language", language, 0); break; case 0x0a: /* ISO 639 language descriptor */ language[0] = get8(&p, desc_end); language[1] = get8(&p, desc_end); language[2] = get8(&p, desc_end); language[3] = 0; - av_metadata_set(&st->metadata, "language", language); + av_metadata_set2(&st->metadata, "language", language, 0); break; case 0x05: /* registration descriptor */ st->codec->codec_tag = bytestream_get_le32(&p); @@ -726,6 +1004,11 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len break; } p = desc_end; + + if (prog_reg_desc == AV_RL32("HDMV") && stream_type == 0x83 && pes->sub_st) { + ff_program_add_stream_index(ts->stream, h->id, pes->sub_st->index); + pes->sub_st->codec->codec_tag = st->codec->codec_tag; + } } p = desc_list_end; } @@ -836,8 +1119,8 @@ static void sdt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len if (name) { AVProgram *program = av_new_program(ts->stream, sid); if(program) { - av_metadata_set(&program->metadata, "name", name); - av_metadata_set(&program->metadata, "provider_name", provider_name); + av_metadata_set2(&program->metadata, "name", name, 0); + av_metadata_set2(&program->metadata, "provider_name", provider_name, 0); } } av_free(name); @@ -852,225 +1135,6 @@ static void sdt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len } } -static int64_t get_pts(const uint8_t *p) -{ - int64_t pts = (int64_t)((p[0] >> 1) & 0x07) << 30; - pts |= (AV_RB16(p + 1) >> 1) << 15; - pts |= AV_RB16(p + 3) >> 1; - return pts; -} - -static void new_pes_packet(PESContext *pes, AVPacket *pkt) -{ - av_init_packet(pkt); - - pkt->destruct = av_destruct_packet; - pkt->data = pes->buffer; - pkt->size = pes->data_index; - memset(pkt->data+pkt->size, 0, FF_INPUT_BUFFER_PADDING_SIZE); - - pkt->stream_index = pes->st->index; - pkt->pts = pes->pts; - pkt->dts = pes->dts; - /* store position of first TS packet of this PES packet */ - pkt->pos = pes->ts_packet_pos; - - /* reset pts values */ - pes->pts = AV_NOPTS_VALUE; - pes->dts = AV_NOPTS_VALUE; - pes->buffer = NULL; - pes->data_index = 0; -} - -/* return non zero if a packet could be constructed */ -static int mpegts_push_data(MpegTSFilter *filter, - const uint8_t *buf, int buf_size, int is_start, - int64_t pos) -{ - PESContext *pes = filter->u.pes_filter.opaque; - MpegTSContext *ts = pes->ts; - const uint8_t *p; - int len, code; - - if(!ts->pkt) - return 0; - - if (is_start) { - if (pes->state == MPEGTS_PAYLOAD && pes->data_index > 0) { - new_pes_packet(pes, ts->pkt); - ts->stop_parse = 1; - } - pes->state = MPEGTS_HEADER; - pes->data_index = 0; - pes->ts_packet_pos = pos; - } - p = buf; - while (buf_size > 0) { - switch(pes->state) { - case MPEGTS_HEADER: - len = PES_START_SIZE - pes->data_index; - if (len > buf_size) - len = buf_size; - memcpy(pes->header + pes->data_index, p, len); - pes->data_index += len; - p += len; - buf_size -= len; - if (pes->data_index == PES_START_SIZE) { - /* we got all the PES or section header. We can now - decide */ -#if 0 - av_hex_dump_log(pes->stream, AV_LOG_DEBUG, pes->header, pes->data_index); -#endif - if (pes->header[0] == 0x00 && pes->header[1] == 0x00 && - pes->header[2] == 0x01) { - /* it must be an mpeg2 PES stream */ - code = pes->header[3] | 0x100; - dprintf(pes->stream, "pid=%x pes_code=%#x\n", pes->pid, code); - - if ((!pes->st && pes->stream->nb_streams == MAX_STREAMS) || - (pes->st && pes->st->discard == AVDISCARD_ALL) || - code == 0x1be) /* padding_stream */ - goto skip; - - /* stream not present in PMT */ - if (!pes->st) - pes->st = new_pes_av_stream(pes, 0, code); - if (!pes->st) - return AVERROR(ENOMEM); - - pes->total_size = AV_RB16(pes->header + 4); - /* NOTE: a zero total size means the PES size is - unbounded */ - if (!pes->total_size) - pes->total_size = MAX_PES_PAYLOAD; - - /* allocate pes buffer */ - pes->buffer = av_malloc(pes->total_size+FF_INPUT_BUFFER_PADDING_SIZE); - if (!pes->buffer) - return AVERROR(ENOMEM); - - if (code != 0x1bc && code != 0x1bf && /* program_stream_map, private_stream_2 */ - code != 0x1f0 && code != 0x1f1 && /* ECM, EMM */ - 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) { - dprintf(pes->stream, "pid=%x stream_type=%x probing\n", - pes->pid, pes->stream_type); - pes->st->codec->codec_id = CODEC_ID_PROBE; - } - } else { - pes->state = MPEGTS_PAYLOAD; - pes->data_index = 0; - } - } else { - /* otherwise, it should be a table */ - /* skip packet */ - skip: - pes->state = MPEGTS_SKIP; - continue; - } - } - break; - /**********************************************/ - /* PES packing parsing */ - case MPEGTS_PESHEADER: - len = PES_HEADER_SIZE - pes->data_index; - if (len < 0) - return -1; - if (len > buf_size) - len = buf_size; - memcpy(pes->header + pes->data_index, p, len); - pes->data_index += len; - p += len; - buf_size -= len; - if (pes->data_index == PES_HEADER_SIZE) { - pes->pes_header_size = pes->header[8] + 9; - pes->state = MPEGTS_PESHEADER_FILL; - } - break; - case MPEGTS_PESHEADER_FILL: - len = pes->pes_header_size - pes->data_index; - if (len < 0) - return -1; - if (len > buf_size) - len = buf_size; - memcpy(pes->header + pes->data_index, p, len); - pes->data_index += len; - p += len; - buf_size -= len; - if (pes->data_index == pes->pes_header_size) { - const uint8_t *r; - unsigned int flags; - - flags = pes->header[7]; - r = pes->header + 9; - pes->pts = AV_NOPTS_VALUE; - pes->dts = AV_NOPTS_VALUE; - if ((flags & 0xc0) == 0x80) { - pes->dts = pes->pts = get_pts(r); - r += 5; - } else if ((flags & 0xc0) == 0xc0) { - pes->pts = get_pts(r); - r += 5; - pes->dts = get_pts(r); - r += 5; - } - - /* we got the full header. We parse it and get the payload */ - pes->state = MPEGTS_PAYLOAD; - pes->data_index = 0; - } - break; - case MPEGTS_PAYLOAD: - if (buf_size > 0) { - if (pes->data_index+buf_size > pes->total_size) { - new_pes_packet(pes, ts->pkt); - pes->total_size = MAX_PES_PAYLOAD; - pes->buffer = av_malloc(pes->total_size+FF_INPUT_BUFFER_PADDING_SIZE); - if (!pes->buffer) - return AVERROR(ENOMEM); - ts->stop_parse = 1; - } - memcpy(pes->buffer+pes->data_index, p, buf_size); - pes->data_index += buf_size; - } - buf_size = 0; - break; - case MPEGTS_SKIP: - buf_size = 0; - break; - } - } - - return 0; -} - -static PESContext *add_pes_stream(MpegTSContext *ts, int pid, int pcr_pid, int stream_type) -{ - MpegTSFilter *tss; - PESContext *pes; - - /* if no pid found, then add a pid context */ - pes = av_mallocz(sizeof(PESContext)); - if (!pes) - return 0; - pes->ts = ts; - pes->stream = ts->stream; - pes->pid = pid; - pes->pcr_pid = pcr_pid; - pes->stream_type = stream_type; - pes->state = MPEGTS_SKIP; - pes->pts = AV_NOPTS_VALUE; - pes->dts = AV_NOPTS_VALUE; - tss = mpegts_open_pes_filter(ts, pid, mpegts_push_data, pes); - if (!tss) { - av_free(pes); - return 0; - } - return pes; -} - /* handle one TS packet */ static int handle_packet(MpegTSContext *ts, const uint8_t *packet) { @@ -1086,7 +1150,7 @@ static int handle_packet(MpegTSContext *ts, const uint8_t *packet) is_start = packet[1] & 0x40; tss = ts->pids[pid]; if (ts->auto_guess && tss == NULL && is_start) { - add_pes_stream(ts, pid, -1, 0); + add_pes_stream(ts, pid, -1); tss = ts->pids[pid]; } if (!tss) @@ -1154,8 +1218,9 @@ static int handle_packet(MpegTSContext *ts, const uint8_t *packet) /* XXX: try to find a better synchro over several packets (use get_packet_size() ?) */ -static int mpegts_resync(ByteIOContext *pb) +static int mpegts_resync(AVFormatContext *s) { + ByteIOContext *pb = s->pb; int c, i; for(i = 0;i < MAX_RESYNC_SIZE; i++) { @@ -1167,13 +1232,15 @@ static int mpegts_resync(ByteIOContext *pb) return 0; } } + av_log(s, AV_LOG_ERROR, "max resync size reached, could not find sync byte\n"); /* no sync found */ return -1; } /* return -1 if error or EOF. Return 0 if OK. */ -static int read_packet(ByteIOContext *pb, uint8_t *buf, int raw_packet_size) +static int read_packet(AVFormatContext *s, uint8_t *buf, int raw_packet_size) { + ByteIOContext *pb = s->pb; int skip, len; for(;;) { @@ -1184,8 +1251,8 @@ static int read_packet(ByteIOContext *pb, uint8_t *buf, int raw_packet_size) if (buf[0] != 0x47) { /* find a new packet start */ url_fseek(pb, -TS_PACKET_SIZE, SEEK_CUR); - if (mpegts_resync(pb) < 0) - return AVERROR_INVALIDDATA; + if (mpegts_resync(s) < 0) + return AVERROR(EAGAIN); else continue; } else { @@ -1201,7 +1268,6 @@ static int read_packet(ByteIOContext *pb, uint8_t *buf, int raw_packet_size) static int handle_packets(MpegTSContext *ts, int nb_packets) { AVFormatContext *s = ts->stream; - ByteIOContext *pb = s->pb; uint8_t packet[TS_PACKET_SIZE]; int packet_num, ret; @@ -1213,7 +1279,7 @@ static int handle_packets(MpegTSContext *ts, int nb_packets) packet_num++; if (nb_packets != 0 && packet_num >= nb_packets) break; - ret = read_packet(pb, packet, ts->raw_packet_size); + ret = read_packet(s, packet, ts->raw_packet_size); if (ret != 0) return ret; ret = handle_packet(ts, packet); @@ -1246,7 +1312,7 @@ static int mpegts_probe(AVProbeData *p) else return -1; #else /* only use the extension for safer guess */ - if (match_ext(p->filename, "ts")) + if (av_match_ext(p->filename, "ts")) return AVPROBE_SCORE_MAX; else return 0; @@ -1320,7 +1386,7 @@ static int mpegts_read_header(AVFormatContext *s, mpegts_open_section_filter(ts, PAT_PID, pat_cb, ts, 1); - handle_packets(ts, s->probesize); + handle_packets(ts, s->probesize / ts->raw_packet_size); /* if could not find service, enable auto_guess */ ts->auto_guess = 1; @@ -1341,7 +1407,7 @@ static int mpegts_read_header(AVFormatContext *s, if (!st) goto fail; av_set_pts_info(st, 60, 1, 27000000); - st->codec->codec_type = CODEC_TYPE_DATA; + st->codec->codec_type = AVMEDIA_TYPE_DATA; st->codec->codec_id = CODEC_ID_MPEG2TS; /* we iterate until we find two PCRs to estimate the bitrate */ @@ -1349,7 +1415,7 @@ static int mpegts_read_header(AVFormatContext *s, nb_pcrs = 0; nb_packets = 0; for(;;) { - ret = read_packet(s->pb, packet, ts->raw_packet_size); + ret = read_packet(s, packet, ts->raw_packet_size); if (ret < 0) return -1; pid = AV_RB16(packet + 1) & 0x1fff; @@ -1398,7 +1464,7 @@ static int mpegts_raw_read_packet(AVFormatContext *s, if (av_new_packet(pkt, TS_PACKET_SIZE) < 0) return AVERROR(ENOMEM); pkt->pos= url_ftell(s->pb); - ret = read_packet(s->pb, pkt->data, ts->raw_packet_size); + ret = read_packet(s, pkt->data, ts->raw_packet_size); if (ret < 0) { av_free_packet(pkt); return ret; @@ -1457,6 +1523,7 @@ static int mpegts_read_packet(AVFormatContext *s, PESContext *pes = ts->pids[i]->u.pes_filter.opaque; if (pes->state == MPEGTS_PAYLOAD && pes->data_index > 0) { new_pes_packet(pes, pkt); + pes->state = MPEGTS_SKIP; ret = 0; break; } @@ -1521,6 +1588,92 @@ static int64_t mpegts_get_pcr(AVFormatContext *s, int stream_index, return timestamp; } +#ifdef USE_SYNCPOINT_SEARCH + +static int read_seek2(AVFormatContext *s, + int stream_index, + int64_t min_ts, + int64_t target_ts, + int64_t max_ts, + int flags) +{ + int64_t pos; + + int64_t ts_ret, ts_adj; + int stream_index_gen_search; + AVStream *st; + AVParserState *backup; + + backup = ff_store_parser_state(s); + + // detect direction of seeking for search purposes + flags |= (target_ts - min_ts > (uint64_t)(max_ts - target_ts)) ? + AVSEEK_FLAG_BACKWARD : 0; + + if (flags & AVSEEK_FLAG_BYTE) { + // use position directly, we will search starting from it + pos = target_ts; + } else { + // search for some position with good timestamp match + if (stream_index < 0) { + stream_index_gen_search = av_find_default_stream_index(s); + if (stream_index_gen_search < 0) { + ff_restore_parser_state(s, backup); + return -1; + } + + st = s->streams[stream_index_gen_search]; + // timestamp for default must be expressed in AV_TIME_BASE units + ts_adj = av_rescale(target_ts, + st->time_base.den, + AV_TIME_BASE * (int64_t)st->time_base.num); + } else { + ts_adj = target_ts; + stream_index_gen_search = stream_index; + } + pos = av_gen_search(s, stream_index_gen_search, ts_adj, + 0, INT64_MAX, -1, + AV_NOPTS_VALUE, + AV_NOPTS_VALUE, + flags, &ts_ret, mpegts_get_pcr); + if (pos < 0) { + ff_restore_parser_state(s, backup); + return -1; + } + } + + // search for actual matching keyframe/starting position for all streams + if (ff_gen_syncpoint_search(s, stream_index, pos, + min_ts, target_ts, max_ts, + flags) < 0) { + ff_restore_parser_state(s, backup); + return -1; + } + + ff_free_parser_state(s, backup); + return 0; +} + +static int read_seek(AVFormatContext *s, int stream_index, int64_t target_ts, int flags) +{ + int ret; + if (flags & AVSEEK_FLAG_BACKWARD) { + flags &= ~AVSEEK_FLAG_BACKWARD; + ret = read_seek2(s, stream_index, INT64_MIN, target_ts, target_ts, flags); + if (ret < 0) + // for compatibility reasons, seek to the best-fitting timestamp + ret = read_seek2(s, stream_index, INT64_MIN, target_ts, INT64_MAX, flags); + } else { + ret = read_seek2(s, stream_index, target_ts, target_ts, INT64_MAX, flags); + if (ret < 0) + // for compatibility reasons, seek to the best-fitting timestamp + ret = read_seek2(s, stream_index, INT64_MIN, target_ts, INT64_MAX, flags); + } + 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]; @@ -1544,10 +1697,12 @@ static int read_seek(AVFormatContext *s, int stream_index, int64_t target_ts, in return 0; } +#endif + /**************************************************************/ /* parsing functions - called from other demuxers such as RTP */ -MpegTSContext *mpegts_parse_open(AVFormatContext *s) +MpegTSContext *ff_mpegts_parse_open(AVFormatContext *s) { MpegTSContext *ts; @@ -1563,7 +1718,7 @@ MpegTSContext *mpegts_parse_open(AVFormatContext *s) /* return the consumed length if a packet was output, or -1 if no packet is output */ -int mpegts_parse_packet(MpegTSContext *ts, AVPacket *pkt, +int ff_mpegts_parse_packet(MpegTSContext *ts, AVPacket *pkt, const uint8_t *buf, int len) { int len1; @@ -1588,7 +1743,7 @@ int mpegts_parse_packet(MpegTSContext *ts, AVPacket *pkt, return len1 - len; } -void mpegts_parse_close(MpegTSContext *ts) +void ff_mpegts_parse_close(MpegTSContext *ts) { int i; @@ -1608,6 +1763,9 @@ AVInputFormat mpegts_demuxer = { read_seek, mpegts_get_pcr, .flags = AVFMT_SHOW_IDS|AVFMT_TS_DISCONT, +#ifdef USE_SYNCPOINT_SEARCH + .read_seek2 = read_seek2, +#endif }; AVInputFormat mpegtsraw_demuxer = { @@ -1621,4 +1779,7 @@ AVInputFormat mpegtsraw_demuxer = { read_seek, mpegts_get_pcr, .flags = AVFMT_SHOW_IDS|AVFMT_TS_DISCONT, +#ifdef USE_SYNCPOINT_SEARCH + .read_seek2 = read_seek2, +#endif }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/mpegts.h b/src/add-ons/media/plugins/ffmpeg/libavformat/mpegts.h index e5df071255..6be9b73f06 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/mpegts.h +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/mpegts.h @@ -27,6 +27,8 @@ #define TS_FEC_PACKET_SIZE 204 #define TS_DVHS_PACKET_SIZE 192 #define TS_PACKET_SIZE 188 +#define TS_MAX_PACKET_SIZE 204 + #define NB_PID_MAX 8192 #define MAX_SECTION_SIZE 4096 @@ -56,9 +58,9 @@ typedef struct MpegTSContext MpegTSContext; -MpegTSContext *mpegts_parse_open(AVFormatContext *s); -int mpegts_parse_packet(MpegTSContext *ts, AVPacket *pkt, - const uint8_t *buf, int len); -void mpegts_parse_close(MpegTSContext *ts); +MpegTSContext *ff_mpegts_parse_open(AVFormatContext *s); +int ff_mpegts_parse_packet(MpegTSContext *ts, AVPacket *pkt, + const uint8_t *buf, int len); +void ff_mpegts_parse_close(MpegTSContext *ts); #endif /* AVFORMAT_MPEGTS_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/mpegtsenc.c b/src/add-ons/media/plugins/ffmpeg/libavformat/mpegtsenc.c index 7138009716..3fc6dc195f 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/mpegtsenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/mpegtsenc.c @@ -23,7 +23,9 @@ #include "libavutil/crc.h" #include "libavcodec/mpegvideo.h" #include "avformat.h" +#include "internal.h" #include "mpegts.h" +#include "adts.h" /* write DVB SI sections */ @@ -59,7 +61,7 @@ typedef struct MpegTSWrite { int onid; int tsid; uint64_t cur_pcr; - int mux_rate; + int mux_rate; ///< set to 1 when VBR } MpegTSWrite; /* NOTE: 4 bytes must be left at the end for the crc32 */ @@ -89,8 +91,8 @@ static void mpegts_write_section(MpegTSSection *s, uint8_t *buf, int len) b |= 0x40; *q++ = b; *q++ = s->pid; - *q++ = 0x10 | s->cc; s->cc = (s->cc + 1) & 0xf; + *q++ = 0x10 | s->cc; if (first) *q++ = 0; /* 0 offset */ len1 = TS_PACKET_SIZE - (q - packet); @@ -177,6 +179,7 @@ typedef struct MpegTSWriteStream { int64_t payload_pts; int64_t payload_dts; uint8_t payload[DEFAULT_PES_PAYLOAD_SIZE]; + ADTSContext *adts; } MpegTSWriteStream; static void mpegts_write_pat(AVFormatContext *s) @@ -253,7 +256,7 @@ static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) /* write optional descriptors here */ switch(st->codec->codec_type) { - case CODEC_TYPE_AUDIO: + case AVMEDIA_TYPE_AUDIO: if (lang && strlen(lang->value) == 3) { *q++ = 0x0a; /* ISO 639 language descriptor */ *q++ = 4; @@ -263,7 +266,7 @@ static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) *q++ = 0; /* undefined type */ } break; - case CODEC_TYPE_SUBTITLE: + case AVMEDIA_TYPE_SUBTITLE: { const char *language; language = lang && strlen(lang->value)==3 ? lang->value : "eng"; @@ -277,7 +280,7 @@ static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) put16(&q, 1); /* ancillary page id */ } break; - case CODEC_TYPE_VIDEO: + case AVMEDIA_TYPE_VIDEO: if (stream_type == STREAM_TYPE_VIDEO_DIRAC) { *q++ = 0x05; /*MPEG-2 registration descriptor*/ *q++ = 4; @@ -382,11 +385,10 @@ static int mpegts_write_header(AVFormatContext *s) MpegTSWrite *ts = s->priv_data; MpegTSWriteStream *ts_st; MpegTSService *service; - AVStream *st; + AVStream *st, *pcr_st = NULL; AVMetadataTag *title; - int i, total_bit_rate; + int i; const char *service_name; - uint64_t sdt_size, pat_pmt_size, pos; ts->tsid = DEFAULT_TSID; ts->onid = DEFAULT_ONID; @@ -397,19 +399,19 @@ static int mpegts_write_header(AVFormatContext *s) DEFAULT_PROVIDER_NAME, service_name); service->pmt.write_packet = section_write_packet; service->pmt.opaque = s; + service->pmt.cc = 15; ts->pat.pid = PAT_PID; - ts->pat.cc = 0; + ts->pat.cc = 15; // Initialize at 15 so that it wraps and be equal to 0 for the first packet we write ts->pat.write_packet = section_write_packet; ts->pat.opaque = s; ts->sdt.pid = SDT_PID; - ts->sdt.cc = 0; + ts->sdt.cc = 15; ts->sdt.write_packet = section_write_packet; ts->sdt.opaque = s; /* assign pids to each stream */ - total_bit_rate = 0; for(i = 0;i < s->nb_streams; i++) { st = s->streams[i]; ts_st = av_mallocz(sizeof(MpegTSWriteStream)); @@ -421,64 +423,73 @@ static int mpegts_write_header(AVFormatContext *s) ts_st->payload_pts = AV_NOPTS_VALUE; ts_st->payload_dts = AV_NOPTS_VALUE; ts_st->first_pts_check = 1; + ts_st->cc = 15; /* update PCR pid by using the first video stream */ - if (st->codec->codec_type == CODEC_TYPE_VIDEO && - service->pcr_pid == 0x1fff) + if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && + service->pcr_pid == 0x1fff) { service->pcr_pid = ts_st->pid; - total_bit_rate += st->codec->bit_rate; - /* PES header size */ - if (st->codec->codec_type == CODEC_TYPE_VIDEO || - st->codec->codec_type == CODEC_TYPE_SUBTITLE) - total_bit_rate += 25 * 8 / av_q2d(st->codec->time_base); - else - total_bit_rate += total_bit_rate * 25 / DEFAULT_PES_PAYLOAD_SIZE; + pcr_st = st; + } + if (st->codec->codec_id == CODEC_ID_AAC && + st->codec->extradata_size > 0) { + ts_st->adts = av_mallocz(sizeof(*ts_st->adts)); + if (!ts_st->adts) + return AVERROR(ENOMEM); + if (ff_adts_decode_extradata(s, ts_st->adts, st->codec->extradata, + st->codec->extradata_size) < 0) + return -1; + } } /* if no video stream, use the first stream as PCR */ if (service->pcr_pid == 0x1fff && s->nb_streams > 0) { - ts_st = s->streams[0]->priv_data; + pcr_st = s->streams[0]; + ts_st = pcr_st->priv_data; service->pcr_pid = ts_st->pid; } - if (total_bit_rate <= 8 * 1024) - total_bit_rate = 8 * 1024; - service->pcr_packet_period = (total_bit_rate * PCR_RETRANS_TIME) / - (TS_PACKET_SIZE * 8 * 1000); - ts->sdt_packet_period = (total_bit_rate * SDT_RETRANS_TIME) / - (TS_PACKET_SIZE * 8 * 1000); - ts->pat_packet_period = (total_bit_rate * PAT_RETRANS_TIME) / - (TS_PACKET_SIZE * 8 * 1000); + ts->mux_rate = s->mux_rate ? s->mux_rate : 1; - ts->mux_rate = 1; // avoid div by 0 + if (ts->mux_rate > 1) { + service->pcr_packet_period = (ts->mux_rate * PCR_RETRANS_TIME) / + (TS_PACKET_SIZE * 8 * 1000); + ts->sdt_packet_period = (ts->mux_rate * SDT_RETRANS_TIME) / + (TS_PACKET_SIZE * 8 * 1000); + ts->pat_packet_period = (ts->mux_rate * PAT_RETRANS_TIME) / + (TS_PACKET_SIZE * 8 * 1000); - /* write info at the start of the file, so that it will be fast to - find them */ - pos = url_ftell(s->pb); - mpegts_write_sdt(s); - sdt_size = url_ftell(s->pb) - pos; - pos = url_ftell(s->pb); - mpegts_write_pat(s); - for(i = 0; i < ts->nb_services; i++) { - mpegts_write_pmt(s, ts->services[i]); + ts->cur_pcr = av_rescale(s->max_delay, 90000, AV_TIME_BASE); + } else { + /* Arbitrary values, PAT/PMT could be written on key frames */ + ts->sdt_packet_period = 200; + ts->pat_packet_period = 40; + if (pcr_st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + if (!pcr_st->codec->frame_size) { + av_log(s, AV_LOG_WARNING, "frame size not set\n"); + service->pcr_packet_period = + pcr_st->codec->sample_rate/(10*512); + } else { + service->pcr_packet_period = + pcr_st->codec->sample_rate/(10*pcr_st->codec->frame_size); + } + } else { + // max delta PCR 0.1s + service->pcr_packet_period = + pcr_st->codec->time_base.den/(10*pcr_st->codec->time_base.num); + } } - pat_pmt_size = url_ftell(s->pb) - pos; - total_bit_rate += - total_bit_rate * 4 / TS_PACKET_SIZE + /* TS header size */ - SDT_RETRANS_TIME * 8 * sdt_size / 1000 + /* SDT size */ - PAT_RETRANS_TIME * 8 * pat_pmt_size / 1000 + /* PAT+PMT size */ - PCR_RETRANS_TIME * 8 * 8 / 1000; /* PCR size */ + // output a PCR as soon as possible + service->pcr_packet_count = service->pcr_packet_period; + ts->pat_packet_count = ts->pat_packet_period-1; + ts->sdt_packet_count = ts->sdt_packet_period-1; - av_log(s, AV_LOG_DEBUG, "muxrate %d freq sdt %d pat %d\n", - total_bit_rate, ts->sdt_packet_period, ts->pat_packet_period); + av_log(s, AV_LOG_INFO, + "muxrate %d bps, pcr every %d pkts, " + "sdt every %d, pat/pmt every %d pkts\n", + ts->mux_rate, service->pcr_packet_period, + ts->sdt_packet_period, ts->pat_packet_period); - if (s->mux_rate) - ts->mux_rate = s->mux_rate; - else - ts->mux_rate = total_bit_rate; - - // adjust pcr - ts->cur_pcr /= ts->mux_rate; put_flush_packet(s->pb); @@ -511,6 +522,55 @@ static void retransmit_si_info(AVFormatContext *s) } } +/* Write a single null transport stream packet */ +static void mpegts_insert_null_packet(AVFormatContext *s) +{ + MpegTSWrite *ts = s->priv_data; + uint8_t *q; + uint8_t buf[TS_PACKET_SIZE]; + + q = buf; + *q++ = 0x47; + *q++ = 0x00 | 0x1f; + *q++ = 0xff; + *q++ = 0x10; + memset(q, 0x0FF, TS_PACKET_SIZE - (q - buf)); + put_buffer(s->pb, buf, TS_PACKET_SIZE); + ts->cur_pcr += TS_PACKET_SIZE*8*90000LL/ts->mux_rate; +} + +/* Write a single transport stream packet with a PCR and no payload */ +static void mpegts_insert_pcr_only(AVFormatContext *s, AVStream *st) +{ + MpegTSWrite *ts = s->priv_data; + MpegTSWriteStream *ts_st = st->priv_data; + uint8_t *q; + uint64_t pcr = ts->cur_pcr; + uint8_t buf[TS_PACKET_SIZE]; + + q = buf; + *q++ = 0x47; + *q++ = ts_st->pid >> 8; + *q++ = ts_st->pid; + *q++ = 0x20 | ts_st->cc; /* Adaptation only */ + /* Continuity Count field does not increment (see 13818-1 section 2.4.3.3) */ + *q++ = TS_PACKET_SIZE - 5; /* Adaptation Field Length */ + *q++ = 0x10; /* Adaptation flags: PCR present */ + + /* PCR coded into 6 bytes */ + *q++ = pcr >> 25; + *q++ = pcr >> 17; + *q++ = pcr >> 9; + *q++ = pcr >> 1; + *q++ = (pcr & 1) << 7; + *q++ = 0; + + /* stuffing bytes */ + memset(q, 0xFF, TS_PACKET_SIZE - (q - buf)); + put_buffer(s->pb, buf, TS_PACKET_SIZE); + ts->cur_pcr += TS_PACKET_SIZE*8*90000LL/ts->mux_rate; +} + static void write_pts(uint8_t *q, int fourbits, int64_t pts) { int val; @@ -525,7 +585,11 @@ static void write_pts(uint8_t *q, int fourbits, int64_t pts) *q++ = val; } -/* NOTE: pes_data contains all the PES packet */ +/* 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. + * NOTE: 'payload' contains a complete PES payload. + */ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, const uint8_t *payload, int payload_size, int64_t pts, int64_t dts) @@ -537,6 +601,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, int val, is_start, len, header_len, write_pcr, private_code, flags; int afc_len, stuffing_len; int64_t pcr = -1; /* avoid warning */ + int64_t delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE); is_start = 1; while (payload_size > 0) { @@ -544,7 +609,8 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, write_pcr = 0; if (ts_st->pid == ts_st->service->pcr_pid) { - ts_st->service->pcr_packet_count++; + if (ts->mux_rate > 1 || is_start) // VBR pcr period is based on frames + ts_st->service->pcr_packet_count++; if (ts_st->service->pcr_packet_count >= ts_st->service->pcr_packet_period) { ts_st->service->pcr_packet_count = 0; @@ -552,6 +618,16 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, } } + if (ts->mux_rate > 1 && dts != AV_NOPTS_VALUE && + (dts - (int64_t)ts->cur_pcr) > delay) { + /* pcr insert gets priority over null packet insert */ + if (write_pcr) + mpegts_insert_pcr_only(s, st); + else + mpegts_insert_null_packet(s); + continue; /* recalculate write_pcr and possibly retransmit si_info */ + } + /* prepare packet header */ q = buf; *q++ = 0x47; @@ -560,11 +636,14 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, val |= 0x40; *q++ = val; *q++ = ts_st->pid; - *q++ = 0x10 | ts_st->cc | (write_pcr ? 0x20 : 0); ts_st->cc = (ts_st->cc + 1) & 0xf; + *q++ = 0x10 | ts_st->cc | (write_pcr ? 0x20 : 0); if (write_pcr) { // add 11, pcr references the last byte of program clock reference base - pcr = ts->cur_pcr + (4+7)*8*90000LL / ts->mux_rate; + if (ts->mux_rate > 1) + pcr = ts->cur_pcr + (4+7)*8*90000LL / ts->mux_rate; + else + pcr = dts - delay; if (dts != AV_NOPTS_VALUE && dts < pcr) av_log(s, AV_LOG_WARNING, "dts < pcr, TS is invalid\n"); *q++ = 7; /* AFC length */ @@ -583,18 +662,18 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, *q++ = 0x00; *q++ = 0x01; private_code = 0; - if (st->codec->codec_type == CODEC_TYPE_VIDEO) { + if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { if (st->codec->codec_id == CODEC_ID_DIRAC) { *q++ = 0xfd; } else *q++ = 0xe0; - } else if (st->codec->codec_type == CODEC_TYPE_AUDIO && + } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && (st->codec->codec_id == CODEC_ID_MP2 || st->codec->codec_id == CODEC_ID_MP3)) { *q++ = 0xc0; } else { *q++ = 0xbd; - if (st->codec->codec_type == CODEC_TYPE_SUBTITLE) { + if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) { private_code = 0x20; } } @@ -608,7 +687,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, header_len += 5; flags |= 0x40; } - if (st->codec->codec_type == CODEC_TYPE_VIDEO && + if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && st->codec->codec_id == CODEC_ID_DIRAC) { /* set PES_extension_flag */ pes_extension = 1; @@ -630,7 +709,7 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, *q++ = len; val = 0x80; /* data alignment indicator is required for subtitle data */ - if (st->codec->codec_type == CODEC_TYPE_SUBTITLE) + if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) val |= 0x04; *q++ = val; *q++ = flags; @@ -697,11 +776,11 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, static int mpegts_write_packet(AVFormatContext *s, AVPacket *pkt) { AVStream *st = s->streams[pkt->stream_index]; - int len, size = pkt->size; + int size = pkt->size; uint8_t *buf= pkt->data; uint8_t *data= NULL; MpegTSWriteStream *ts_st = st->priv_data; - const uint64_t delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE); + const uint64_t delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE)*2; int64_t dts = AV_NOPTS_VALUE, pts = AV_NOPTS_VALUE; if (pkt->pts != AV_NOPTS_VALUE) @@ -716,11 +795,22 @@ static int mpegts_write_packet(AVFormatContext *s, AVPacket *pkt) ts_st->first_pts_check = 0; if (st->codec->codec_id == CODEC_ID_H264) { + const uint8_t *p = buf, *buf_end = p+size; + uint32_t state = -1; + if (pkt->size < 5 || AV_RB32(pkt->data) != 0x0000001) { - av_log(s, AV_LOG_ERROR, "h264 bitstream malformated\n"); + av_log(s, AV_LOG_ERROR, "h264 bitstream malformated, " + "no startcode found, use -vbsf h264_mp4toannexb\n"); return -1; } - if (pkt->data[4] != 0x09) { // AUD NAL + + do { + p = ff_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); + + if ((state & 0x1f) != 9) { // AUD NAL data = av_malloc(pkt->size+6); if (!data) return -1; @@ -731,39 +821,57 @@ static int mpegts_write_packet(AVFormatContext *s, AVPacket *pkt) buf = data; size = pkt->size+6; } + } else if (st->codec->codec_id == CODEC_ID_AAC) { + if (pkt->size < 2) + return -1; + if ((AV_RB16(pkt->data) & 0xfff0) != 0xfff0) { + ADTSContext *adts = ts_st->adts; + int new_size; + if (!adts) { + av_log(s, AV_LOG_ERROR, "aac bitstream not in adts format " + "and extradata missing\n"); + return -1; + } + new_size = ADTS_HEADER_SIZE+adts->pce_size+pkt->size; + if ((unsigned)new_size >= INT_MAX) + return -1; + data = av_malloc(new_size); + if (!data) + return AVERROR(ENOMEM); + ff_adts_write_frame_header(adts, data, pkt->size, adts->pce_size); + if (adts->pce_size) { + memcpy(data+ADTS_HEADER_SIZE, adts->pce_data, adts->pce_size); + adts->pce_size = 0; + } + memcpy(data+ADTS_HEADER_SIZE+adts->pce_size, pkt->data, pkt->size); + buf = data; + size = new_size; + } } - if (st->codec->codec_type == CODEC_TYPE_SUBTITLE || - st->codec->codec_type == CODEC_TYPE_VIDEO) { + if (st->codec->codec_type != AVMEDIA_TYPE_AUDIO) { // for video and subtitle, write a single pes packet mpegts_write_pes(s, st, buf, size, pts, dts); av_free(data); return 0; } - if (ts_st->payload_pts == AV_NOPTS_VALUE) { - ts_st->payload_dts = dts; - ts_st->payload_pts = pts; + 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; } - // audio - while (size > 0) { - len = DEFAULT_PES_PAYLOAD_SIZE - ts_st->payload_index; - if (len > size) - len = size; - memcpy(ts_st->payload + ts_st->payload_index, buf, len); - buf += len; - size -= len; - ts_st->payload_index += len; - if (ts_st->payload_index >= 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_pts = AV_NOPTS_VALUE; - ts_st->payload_dts = AV_NOPTS_VALUE; - ts_st->payload_index = 0; - } + if (!ts_st->payload_index) { + ts_st->payload_pts = pts; + ts_st->payload_dts = dts; } + memcpy(ts_st->payload + ts_st->payload_index, buf, size); + ts_st->payload_index += size; + + av_free(data); + return 0; } @@ -783,6 +891,7 @@ static int mpegts_write_end(AVFormatContext *s) mpegts_write_pes(s, st, ts_st->payload, ts_st->payload_index, ts_st->payload_pts, ts_st->payload_dts); } + av_freep(&ts_st->adts); } put_flush_packet(s->pb); diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/msnwc_tcp.c b/src/add-ons/media/plugins/ffmpeg/libavformat/msnwc_tcp.c index 34ab9d94bb..e5488718bc 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/msnwc_tcp.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/msnwc_tcp.c @@ -77,10 +77,10 @@ static int msnwc_tcp_read_header(AVFormatContext *ctx, AVFormatParameters *ap) st = av_new_stream(ctx, 0); if(!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); codec = st->codec; - codec->codec_type = CODEC_TYPE_VIDEO; + codec->codec_type = AVMEDIA_TYPE_VIDEO; codec->codec_id = CODEC_ID_MIMIC; codec->codec_tag = MKTAG('M', 'L', '2', '0'); @@ -125,7 +125,7 @@ static int msnwc_tcp_read_packet(AVFormatContext *ctx, AVPacket *pkt) /* Some aMsn generated videos (or was it Mercury Messenger?) don't set * this bit and rely on the codec to get keyframe information */ if(keyframe&1) - pkt->flags |= PKT_FLAG_KEY; + pkt->flags |= AV_PKT_FLAG_KEY; return HEADER_SIZE + size; } diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/mtv.c b/src/add-ons/media/plugins/ffmpeg/libavformat/mtv.c index 1ebeaee8a9..4eae1a19e6 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/mtv.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/mtv.c @@ -20,11 +20,12 @@ */ /** - * @file libavformat/mtv.c + * @file * MTV demuxer. */ #include "libavutil/bswap.h" +#include "libavutil/intreadwrite.h" #include "avformat.h" #define MTV_ASUBCHUNK_DATA_SIZE 500 @@ -39,7 +40,7 @@ typedef struct MTVDemuxContext { unsigned int file_size; ///< filesize, not always right unsigned int segments; ///< number of 512 byte segments unsigned int audio_identifier; ///< 'MP3' on all files I have seen - unsigned int audio_br; ///< bitrate of audio chanel (mp3) + unsigned int audio_br; ///< bitrate of audio channel (mp3) unsigned int img_colorfmt; ///< frame colorfmt rgb 565/555 unsigned int img_bpp; ///< frame bits per pixel unsigned int img_width; // @@ -56,6 +57,22 @@ static int mtv_probe(AVProbeData *p) if(*(p->buf) != 'A' || *(p->buf+1) != 'M' || *(p->buf+2) != 'V') return 0; + /* Check for nonzero in bpp and (width|height) header fields */ + if(!(p->buf[51] && AV_RL16(&p->buf[52]) | AV_RL16(&p->buf[54]))) + return 0; + + /* If width or height are 0 then imagesize header field should not */ + if(!AV_RL16(&p->buf[52]) || !AV_RL16(&p->buf[54])) + { + if(!!AV_RL16(&p->buf[56])) + return AVPROBE_SCORE_MAX/2; + else + return 0; + } + + if(p->buf[51] != 16) + return AVPROBE_SCORE_MAX/4; // But we are going to assume 16bpp anyway .. + return AVPROBE_SCORE_MAX; } @@ -77,6 +94,17 @@ static int mtv_read_header(AVFormatContext *s, AVFormatParameters *ap) mtv->img_width = get_le16(pb); mtv->img_height = get_le16(pb); mtv->img_segment_size = get_le16(pb); + + /* Calculate width and height if missing from header */ + + if(!mtv->img_width) + mtv->img_width=mtv->img_segment_size / (mtv->img_bpp>>3) + / mtv->img_height; + + if(!mtv->img_height) + mtv->img_height=mtv->img_segment_size / (mtv->img_bpp>>3) + / mtv->img_width; + url_fskip(pb, 4); audio_subsegments = get_le16(pb); mtv->full_segment_size = @@ -95,13 +123,14 @@ static int mtv_read_header(AVFormatContext *s, AVFormatParameters *ap) return AVERROR(ENOMEM); av_set_pts_info(st, 64, 1, mtv->video_fps); - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_RAWVIDEO; - st->codec->codec_tag = MKTAG('R', 'G', 'B', mtv->img_bpp); + st->codec->pix_fmt = PIX_FMT_RGB565; st->codec->width = mtv->img_width; st->codec->height = mtv->img_height; - st->codec->bits_per_coded_sample = mtv->img_bpp; st->codec->sample_rate = mtv->video_fps; + st->codec->extradata = av_strdup("BottomUp"); + st->codec->extradata_size = 9; // audio - mp3 @@ -110,7 +139,7 @@ static int mtv_read_header(AVFormatContext *s, AVFormatParameters *ap) return AVERROR(ENOMEM); av_set_pts_info(st, 64, 1, AUDIO_SAMPLING_RATE); - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_MP3; st->codec->bit_rate = mtv->audio_br; st->need_parsing = AVSTREAM_PARSE_FULL; @@ -138,8 +167,8 @@ static int mtv_read_packet(AVFormatContext *s, AVPacket *pkt) url_fskip(pb, MTV_AUDIO_PADDING_SIZE); ret = av_get_packet(pb, pkt, MTV_ASUBCHUNK_DATA_SIZE); - if(ret != MTV_ASUBCHUNK_DATA_SIZE) - return AVERROR(EIO); + if(ret < 0) + return ret; pkt->pos -= MTV_AUDIO_PADDING_SIZE; pkt->stream_index = AUDIO_SID; @@ -147,8 +176,8 @@ static int mtv_read_packet(AVFormatContext *s, AVPacket *pkt) }else { ret = av_get_packet(pb, pkt, mtv->img_segment_size); - if(ret != mtv->img_segment_size) - return AVERROR(EIO); + if(ret < 0) + return ret; #if !HAVE_BIGENDIAN diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/mvi.c b/src/add-ons/media/plugins/ffmpeg/libavformat/mvi.c index 2dc4667a68..506976df43 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/mvi.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/mvi.c @@ -77,16 +77,15 @@ static int read_header(AVFormatContext *s, AVFormatParameters *ap) } av_set_pts_info(ast, 64, 1, ast->codec->sample_rate); - ast->codec->codec_type = CODEC_TYPE_AUDIO; + ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; ast->codec->codec_id = CODEC_ID_PCM_U8; ast->codec->channels = 1; ast->codec->bits_per_coded_sample = 8; ast->codec->bit_rate = ast->codec->sample_rate * 8; av_set_pts_info(vst, 64, msecs_per_frame, 1000000); - vst->codec->codec_type = CODEC_TYPE_VIDEO; + vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; vst->codec->codec_id = CODEC_ID_MOTIONPIXELS; - vst->codec->pix_fmt = PIX_FMT_RGB555; mvi->get_int = (vst->codec->width * vst->codec->height < (1 << 16)) ? get_le16 : get_le24; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/mxf.c b/src/add-ons/media/plugins/ffmpeg/libavformat/mxf.c index 05cb173ac3..452ee6ddfe 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/mxf.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/mxf.c @@ -25,9 +25,9 @@ * SMPTE RP224 http://www.smpte-ra.org/mdd/index.html */ const MXFCodecUL ff_mxf_data_definition_uls[] = { - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x01,0x03,0x02,0x02,0x01,0x00,0x00,0x00 }, 13, CODEC_TYPE_VIDEO }, - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x01,0x03,0x02,0x02,0x02,0x00,0x00,0x00 }, 13, CODEC_TYPE_AUDIO }, - { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, 0, CODEC_TYPE_DATA }, + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x01,0x03,0x02,0x02,0x01,0x00,0x00,0x00 }, 13, AVMEDIA_TYPE_VIDEO }, + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x01,0x03,0x02,0x02,0x02,0x00,0x00,0x00 }, 13, AVMEDIA_TYPE_AUDIO }, + { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, 0, AVMEDIA_TYPE_DATA }, }; const MXFCodecUL ff_mxf_codec_uls[] = { diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/mxfdec.c b/src/add-ons/media/plugins/ffmpeg/libavformat/mxfdec.c index 7f6d439d39..168fd8d69f 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/mxfdec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/mxfdec.c @@ -214,18 +214,17 @@ static int mxf_get_stream_index(AVFormatContext *s, KLVPacket *klv) /* XXX: use AVBitStreamFilter */ static int mxf_get_d10_aes3_packet(ByteIOContext *pb, AVStream *st, AVPacket *pkt, int64_t length) { - uint8_t buffer[61444]; const uint8_t *buf_ptr, *end_ptr; uint8_t *data_ptr; int i; if (length > 61444) /* worst case PAL 1920 samples 8 channels */ return -1; - get_buffer(pb, buffer, length); av_new_packet(pkt, length); + get_buffer(pb, pkt->data, length); data_ptr = pkt->data; - end_ptr = buffer + length; - buf_ptr = buffer + 4; /* skip SMPTE 331M header */ + end_ptr = pkt->data + length; + buf_ptr = pkt->data + 4; /* skip SMPTE 331M header */ for (; buf_ptr < end_ptr; ) { for (i = 0; i < st->codec->channels; i++) { uint32_t sample = bytestream_get_le32(&buf_ptr); @@ -690,7 +689,7 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) if (!(material_track->sequence = mxf_resolve_strong_ref(mxf, &material_track->sequence_ref, Sequence))) { av_log(mxf->fc, AV_LOG_ERROR, "could not resolve material track sequence strong ref\n"); - return -1; + continue; } /* TODO: handle multiple source clips */ @@ -796,7 +795,7 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) st->codec->extradata = descriptor->extradata; st->codec->extradata_size = descriptor->extradata_size; } - if (st->codec->codec_type == CODEC_TYPE_VIDEO) { + if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { container_ul = mxf_get_codec_ul(mxf_essence_container_uls, essence_container_ul); if (st->codec->codec_id == CODEC_ID_NONE) st->codec->codec_id = container_ul->id; @@ -804,7 +803,7 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) st->codec->height = descriptor->height; st->codec->bits_per_coded_sample = descriptor->bits_per_sample; /* Uncompressed */ st->need_parsing = AVSTREAM_PARSE_HEADERS; - } else if (st->codec->codec_type == CODEC_TYPE_AUDIO) { + } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { container_ul = mxf_get_codec_ul(mxf_essence_container_uls, essence_container_ul); if (st->codec->codec_id == CODEC_ID_NONE) st->codec->codec_id = container_ul->id; @@ -826,7 +825,7 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) st->need_parsing = AVSTREAM_PARSE_FULL; } } - if (st->codec->codec_type != CODEC_TYPE_DATA && (*essence_container_ul)[15] > 0x01) { + if (st->codec->codec_type != AVMEDIA_TYPE_DATA && (*essence_container_ul)[15] > 0x01) { av_log(mxf->fc, AV_LOG_WARNING, "only frame wrapped mappings are correctly supported\n"); st->need_parsing = AVSTREAM_PARSE_FULL; } diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/mxfenc.c b/src/add-ons/media/plugins/ffmpeg/libavformat/mxfenc.c index 0a44b12e09..ab381189c9 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/mxfenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/mxfenc.c @@ -86,7 +86,7 @@ static const struct { { CODEC_ID_MPEG2VIDEO, 0 }, { CODEC_ID_PCM_S24LE, 1 }, { CODEC_ID_PCM_S16LE, 1 }, - { 0 } + { CODEC_ID_NONE } }; static void mxf_write_wav_desc(AVFormatContext *s, AVStream *st); @@ -1415,7 +1415,7 @@ static int mxf_write_header(AVFormatContext *s) return AVERROR(ENOMEM); st->priv_data = sc; - if (st->codec->codec_type == CODEC_TYPE_VIDEO) { + if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { if (i != 0) { av_log(s, AV_LOG_ERROR, "video stream must be first track\n"); return -1; @@ -1455,7 +1455,7 @@ static int mxf_write_header(AVFormatContext *s) mxf->edit_unit_byte_count += 16 + 4 + 4 + samples_per_frame[0]*8*4; mxf->edit_unit_byte_count += klv_fill_size(mxf->edit_unit_byte_count); } - } else if (st->codec->codec_type == CODEC_TYPE_AUDIO) { + } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { if (st->codec->sample_rate != 48000) { av_log(s, AV_LOG_ERROR, "only 48khz is implemented\n"); return -1; @@ -1717,7 +1717,7 @@ static int mxf_write_packet(AVFormatContext *s, AVPacket *pkt) mxf_write_klv_fill(s); put_buffer(pb, sc->track_essence_element_key, 16); // write key if (s->oformat == &mxf_d10_muxer) { - if (st->codec->codec_type == CODEC_TYPE_VIDEO) + if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) mxf_write_d10_video_packet(s, st, pkt); else mxf_write_d10_audio_packet(s, st, pkt); @@ -1807,22 +1807,13 @@ static int mxf_write_footer(AVFormatContext *s) static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush) { - AVPacketList *pktl; - int stream_count = 0; - int streams[MAX_STREAMS]; + int i, stream_count = 0; - memset(streams, 0, sizeof(streams)); - pktl = s->packet_buffer; - while (pktl) { - //av_log(s, AV_LOG_DEBUG, "show st:%d dts:%lld\n", pktl->pkt.stream_index, pktl->pkt.dts); - if (!streams[pktl->pkt.stream_index]) - stream_count++; - streams[pktl->pkt.stream_index]++; - pktl = pktl->next; - } + for (i = 0; i < s->nb_streams; i++) + stream_count += !!s->streams[i]->last_in_packet_buffer; if (stream_count && (s->nb_streams == stream_count || flush)) { - pktl = s->packet_buffer; + AVPacketList *pktl = s->packet_buffer; if (s->nb_streams != stream_count) { AVPacketList *last = NULL; // find last packet in edit unit @@ -1836,6 +1827,9 @@ static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, AVPacket // purge packet queue while (pktl) { AVPacketList *next = pktl->next; + + if(s->streams[pktl->pkt.stream_index]->last_in_packet_buffer == pktl) + s->streams[pktl->pkt.stream_index]->last_in_packet_buffer= NULL; av_free_packet(&pktl->pkt); av_freep(&pktl); pktl = next; @@ -1844,6 +1838,7 @@ static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, AVPacket last->next = NULL; else { s->packet_buffer = NULL; + s->packet_buffer_end= NULL; goto out; } pktl = s->packet_buffer; @@ -1852,6 +1847,10 @@ static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, AVPacket *out = pktl->pkt; //av_log(s, AV_LOG_DEBUG, "out st:%d dts:%lld\n", (*out).stream_index, (*out).dts); s->packet_buffer = pktl->next; + if(s->streams[pktl->pkt.stream_index]->last_in_packet_buffer == pktl) + s->streams[pktl->pkt.stream_index]->last_in_packet_buffer= NULL; + if(!s->packet_buffer) + s->packet_buffer_end= NULL; av_freep(&pktl); return 1; } else { diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/ncdec.c b/src/add-ons/media/plugins/ffmpeg/libavformat/ncdec.c index 056381b1c2..6d99a049e6 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/ncdec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/ncdec.c @@ -35,7 +35,7 @@ static int nc_probe(AVProbeData *probe_packet) size = AV_RL16(probe_packet->buf + 5); if (size + 20 > probe_packet->buf_size) - return 3*AVPROBE_SCORE_MAX/2; + return AVPROBE_SCORE_MAX/4; if (AV_RB32(probe_packet->buf+16+size) == NC_VIDEO_FLAG) return AVPROBE_SCORE_MAX; @@ -50,7 +50,7 @@ static int nc_read_header(AVFormatContext *s, AVFormatParameters *ap) if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_MPEG4; st->need_parsing = AVSTREAM_PARSE_FULL; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/network.h b/src/add-ons/media/plugins/ffmpeg/libavformat/network.h index 7af77991d4..0fbcbbb227 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/network.h +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/network.h @@ -27,8 +27,8 @@ #include #include -#define ff_neterrno() WSAGetLastError() -#define FF_NETERROR(err) WSA##err +#define ff_neterrno() (-WSAGetLastError()) +#define FF_NETERROR(err) (-WSA##err) #define WSAEAGAIN WSAEWOULDBLOCK #else #include @@ -36,8 +36,8 @@ #include #include -#define ff_neterrno() errno -#define FF_NETERROR(err) err +#define ff_neterrno() AVERROR(errno) +#define FF_NETERROR(err) AVERROR(err) #endif #if HAVE_ARPA_INET_H @@ -63,9 +63,92 @@ static inline void ff_network_close(void) #endif } -#if !HAVE_INET_ATON -/* in os_support.c */ -int inet_aton (const char * str, struct in_addr * add); +int ff_inet_aton (const char * str, struct in_addr * add); + +#if !HAVE_STRUCT_SOCKADDR_STORAGE +struct sockaddr_storage { +#if HAVE_STRUCT_SOCKADDR_SA_LEN + uint8_t ss_len; + uint8_t ss_family; +#else + uint16_t ss_family; +#endif + char ss_pad1[6]; + int64_t ss_align; + char ss_pad2[112]; +}; +#endif + +#if !HAVE_STRUCT_ADDRINFO +struct addrinfo { + int ai_flags; + int ai_family; + int ai_socktype; + int ai_protocol; + int ai_addrlen; + struct sockaddr *ai_addr; + char *ai_canonname; + struct addrinfo *ai_next; +}; +#endif + +/* getaddrinfo constants */ +#ifndef EAI_FAIL +#define EAI_FAIL 4 +#endif + +#ifndef EAI_FAMILY +#define EAI_FAMILY 5 +#endif + +#ifndef EAI_NONAME +#define EAI_NONAME 8 +#endif + +#ifndef AI_PASSIVE +#define AI_PASSIVE 1 +#endif + +#ifndef AI_CANONNAME +#define AI_CANONNAME 2 +#endif + +#ifndef AI_NUMERICHOST +#define AI_NUMERICHOST 4 +#endif + +#ifndef NI_NOFQDN +#define NI_NOFQDN 1 +#endif + +#ifndef NI_NUMERICHOST +#define NI_NUMERICHOST 2 +#endif + +#ifndef NI_NAMERQD +#define NI_NAMERQD 4 +#endif + +#ifndef NI_NUMERICSERV +#define NI_NUMERICSERV 8 +#endif + +#ifndef NI_DGRAM +#define NI_DGRAM 16 +#endif + +#if !HAVE_GETADDRINFO +int ff_getaddrinfo(const char *node, const char *service, + const struct addrinfo *hints, struct addrinfo **res); +void ff_freeaddrinfo(struct addrinfo *res); +int ff_getnameinfo(const struct sockaddr *sa, int salen, + char *host, int hostlen, + char *serv, int servlen, int flags); +const char *ff_gai_strerror(int ecode); +#define getaddrinfo ff_getaddrinfo +#define freeaddrinfo ff_freeaddrinfo +#define getnameinfo ff_getnameinfo +#define gai_strerror ff_gai_strerror #endif #endif /* AVFORMAT_NETWORK_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/nsvdec.c b/src/add-ons/media/plugins/ffmpeg/libavformat/nsvdec.c index 61a21ae178..44e5097d59 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/nsvdec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/nsvdec.c @@ -201,7 +201,7 @@ static const AVCodecTag nsv_codec_video_tags[] = { */ { CODEC_ID_MPEG4, MKTAG('X', 'V', 'I', 'D') }, /* cf sample xvid decoder from nsv_codec_sdk.zip */ { CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', '3') }, - { 0, 0 }, + { CODEC_ID_NONE, 0 }, }; static const AVCodecTag nsv_codec_audio_tags[] = { @@ -210,7 +210,7 @@ static const AVCodecTag nsv_codec_audio_tags[] = { { CODEC_ID_AAC, MKTAG('A', 'A', 'C', 'P') }, { CODEC_ID_SPEEX, MKTAG('S', 'P', 'X', ' ') }, { CODEC_ID_PCM_U16LE, MKTAG('P', 'C', 'M', ' ') }, - { 0, 0 }, + { CODEC_ID_NONE, 0 }, }; //static int nsv_load_index(AVFormatContext *s); @@ -339,7 +339,7 @@ static int nsv_parse_NSVf_header(AVFormatContext *s, AVFormatParameters *ap) break; *p++ = '\0'; PRINT(("NSV NSVf INFO: %s='%s'\n", token, value)); - av_metadata_set(&s->metadata, token, value); + av_metadata_set2(&s->metadata, token, value, 0); } av_free(strings); } @@ -456,7 +456,7 @@ static int nsv_parse_NSVs_header(AVFormatContext *s, AVFormatParameters *ap) if (!nst) goto fail; st->priv_data = nst; - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_tag = vtag; st->codec->codec_id = ff_codec_get_id(nsv_codec_video_tags, vtag); st->codec->width = vwidth; @@ -487,7 +487,7 @@ static int nsv_parse_NSVs_header(AVFormatContext *s, AVFormatParameters *ap) if (!nst) goto fail; st->priv_data = nst; - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_tag = atag; st->codec->codec_id = ff_codec_get_id(nsv_codec_audio_tags, atag); @@ -620,7 +620,7 @@ null_chunk_retry: av_get_packet(pb, pkt, vsize); pkt->stream_index = st[NSV_ST_VIDEO]->index;//NSV_ST_VIDEO; pkt->dts = nst->frame_offset; - pkt->flags |= nsv->state == NSV_HAS_READ_NSVS ? PKT_FLAG_KEY : 0; /* keyframe only likely on a sync frame */ + pkt->flags |= nsv->state == NSV_HAS_READ_NSVS ? AV_PKT_FLAG_KEY : 0; /* keyframe only likely on a sync frame */ /* for (i = 0; i < MIN(8, vsize); i++) PRINT(("NSV video: [%d] = %02x\n", i, pkt->data[i])); @@ -660,7 +660,7 @@ null_chunk_retry: } av_get_packet(pb, pkt, asize); pkt->stream_index = st[NSV_ST_AUDIO]->index;//NSV_ST_AUDIO; - pkt->flags |= nsv->state == NSV_HAS_READ_NSVS ? PKT_FLAG_KEY : 0; /* keyframe only likely on a sync frame */ + pkt->flags |= nsv->state == NSV_HAS_READ_NSVS ? AV_PKT_FLAG_KEY : 0; /* keyframe only likely on a sync frame */ if( nsv->state == NSV_HAS_READ_NSVS && st[NSV_ST_VIDEO] ) { /* on a nsvs frame we have new information on a/v sync */ pkt->dts = (((NSVStream*)st[NSV_ST_VIDEO]->priv_data)->frame_offset-1); @@ -728,6 +728,10 @@ static int nsv_read_close(AVFormatContext *s) av_freep(&nsv->nsvs_file_offset); av_freep(&nsv->nsvs_timestamps); + if (nsv->ahead[0].data) + av_free_packet(&nsv->ahead[0]); + if (nsv->ahead[1].data) + av_free_packet(&nsv->ahead[1]); #if 0 @@ -764,7 +768,7 @@ static int nsv_probe(AVProbeData *p) return AVPROBE_SCORE_MAX-20; } /* so we'll have more luck on extension... */ - if (match_ext(p->filename, "nsv")) + if (av_match_ext(p->filename, "nsv")) return AVPROBE_SCORE_MAX/2; /* FIXME: add mime-type check */ return 0; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/nut.c b/src/add-ons/media/plugins/ffmpeg/libavformat/nut.c index 6fdc298f8e..9a6a41b21f 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/nut.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/nut.c @@ -47,11 +47,11 @@ int64_t ff_lsb2full(StreamContext *stream, int64_t lsb){ return ((lsb - delta)&mask) + delta; } -int ff_nut_sp_pos_cmp(Syncpoint *a, Syncpoint *b){ +int ff_nut_sp_pos_cmp(const Syncpoint *a, const Syncpoint *b){ return ((a->pos - b->pos) >> 32) - ((b->pos - a->pos) >> 32); } -int ff_nut_sp_pts_cmp(Syncpoint *a, Syncpoint *b){ +int ff_nut_sp_pts_cmp(const Syncpoint *a, const Syncpoint *b){ return ((a->ts - b->ts) >> 32) - ((b->ts - a->ts) >> 32); } @@ -62,13 +62,25 @@ void ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts){ sp->pos= pos; sp->back_ptr= back_ptr; sp->ts= ts; - av_tree_insert(&nut->syncpoints, sp, ff_nut_sp_pos_cmp, &node); + av_tree_insert(&nut->syncpoints, sp, (void *) ff_nut_sp_pos_cmp, &node); if(node){ av_free(sp); av_free(node); } } +static int enu_free(void *opaque, void *elem) +{ + av_free(elem); + return 0; +} + +void ff_nut_free_sp(NUTContext *nut) +{ + av_tree_enumerate(nut->syncpoints, NULL, NULL, enu_free); + av_tree_destroy(nut->syncpoints); +} + const Dispositions ff_nut_dispositions[] = { {"default" , AV_DISPOSITION_DEFAULT}, {"dub" , AV_DISPOSITION_DUB}, @@ -79,3 +91,16 @@ const Dispositions ff_nut_dispositions[] = { {"" , 0} }; +const AVMetadataConv ff_nut_metadata_conv[] = { + { "Author", "artist" }, + { "X-CreationTime", "date" }, + { "CreationTime", "date" }, + { "SourceFilename", "filename" }, + { "X-Language", "language" }, + { "X-Disposition", "disposition" }, + { "X-Replaces", "replaces" }, + { "X-Depends", "depends" }, + { "X-Uses", "uses" }, + { "X-UsesFont", "usesfont" }, + { 0 }, +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/nut.h b/src/add-ons/media/plugins/ffmpeg/libavformat/nut.h index a1081ed34c..ce052dfedf 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/nut.h +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/nut.h @@ -27,6 +27,7 @@ //#include "libavcodec/mpegaudio.h" #include "avformat.h" #include "riff.h" +#include "metadata.h" #define MAIN_STARTCODE (0x7A561F5F04ADULL + (((uint64_t)('N'<<8) + 'M')<<48)) #define STREAM_STARTCODE (0x11405BF2F9DBULL + (((uint64_t)('N'<<8) + 'S')<<48)) @@ -106,10 +107,13 @@ typedef struct { void ff_nut_reset_ts(NUTContext *nut, AVRational time_base, int64_t val); int64_t ff_lsb2full(StreamContext *stream, int64_t lsb); -int ff_nut_sp_pos_cmp(Syncpoint *a, Syncpoint *b); -int ff_nut_sp_pts_cmp(Syncpoint *a, Syncpoint *b); +int ff_nut_sp_pos_cmp(const Syncpoint *a, const Syncpoint *b); +int ff_nut_sp_pts_cmp(const Syncpoint *a, const Syncpoint *b); void ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts); +void ff_nut_free_sp(NUTContext *nut); extern const Dispositions ff_nut_dispositions[]; +extern const AVMetadataConv ff_nut_metadata_conv[]; + #endif /* AVFORMAT_NUT_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/nutdec.c b/src/add-ons/media/plugins/ffmpeg/libavformat/nutdec.c index 564faf2030..5d5cd557b3 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/nutdec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/nutdec.c @@ -136,7 +136,7 @@ static uint64_t find_any_startcode(ByteIOContext *bc, int64_t pos){ * Find the given startcode. * @param code the startcode * @param pos the start position of the search, or -1 if the current position - * @returns the position of the startcode or -1 if not found + * @return the position of the startcode or -1 if not found */ static int64_t find_startcode(ByteIOContext *bc, uint64_t code, int64_t pos){ for(;;){ @@ -315,26 +315,27 @@ static int decode_stream_header(NUTContext *nut){ switch(class) { case 0: - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tmp); break; case 1: - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = ff_codec_get_id(ff_codec_wav_tags, tmp); break; case 2: - st->codec->codec_type = CODEC_TYPE_SUBTITLE; + st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; st->codec->codec_id = ff_codec_get_id(ff_nut_subtitle_tags, tmp); break; case 3: - st->codec->codec_type = CODEC_TYPE_DATA; + st->codec->codec_type = AVMEDIA_TYPE_DATA; break; default: av_log(s, AV_LOG_ERROR, "unknown stream class (%d)\n", class); return -1; } if(class<3 && st->codec->codec_id == CODEC_ID_NONE) - av_log(s, AV_LOG_ERROR, "Unknown codec?!\n"); + av_log(s, AV_LOG_ERROR, "Unknown codec tag '0x%04x' for stream number %d\n", + (unsigned int)tmp, stream_id); GET_V(stc->time_base_id , tmp < nut->time_base_count); GET_V(stc->msb_pts_shift , tmp < 16); @@ -349,7 +350,7 @@ static int decode_stream_header(NUTContext *nut){ get_buffer(bc, st->codec->extradata, st->codec->extradata_size); } - if (st->codec->codec_type == CODEC_TYPE_VIDEO){ + if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO){ GET_V(st->codec->width , tmp > 0) GET_V(st->codec->height, tmp > 0) st->sample_aspect_ratio.num= ff_get_v(bc); @@ -359,7 +360,7 @@ static int decode_stream_header(NUTContext *nut){ return -1; } ff_get_v(bc); /* csp type */ - }else if (st->codec->codec_type == CODEC_TYPE_AUDIO){ + }else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO){ GET_V(st->codec->sample_rate , tmp > 0) ff_get_v(bc); // samplerate_den GET_V(st->codec->channels, tmp > 0) @@ -389,8 +390,8 @@ static void set_disposition_bits(AVFormatContext* avf, char* value, int stream_i static int decode_info_header(NUTContext *nut){ AVFormatContext *s= nut->avf; ByteIOContext *bc = s->pb; - uint64_t tmp; - unsigned int stream_id_plus1, chapter_start, chapter_len, count; + uint64_t tmp, chapter_start, chapter_len; + unsigned int stream_id_plus1, count; int chapter_id, i; int64_t value, end; char name[256], str_value[1024], type_str[256]; @@ -452,7 +453,7 @@ static int decode_info_header(NUTContext *nut){ else metadata= &s->metadata; if(metadata && strcasecmp(name,"Uses") && strcasecmp(name,"Depends") && strcasecmp(name,"Replaces")) - av_metadata_set(metadata, name, str_value); + av_metadata_set2(metadata, name, str_value, 0); } } @@ -754,7 +755,7 @@ static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code){ pkt->stream_index = stream_id; if (stc->last_flags & FLAG_KEY) - pkt->flags |= PKT_FLAG_KEY; + pkt->flags |= AV_PKT_FLAG_KEY; pkt->pts = pts; return 0; @@ -859,7 +860,8 @@ static int read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flag pos2= st->index_entries[index].pos; ts = st->index_entries[index].timestamp; }else{ - av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pts_cmp, next_node); + av_tree_find(nut->syncpoints, &dummy, (void *) ff_nut_sp_pts_cmp, + (void **) next_node); av_log(s, AV_LOG_DEBUG, "%"PRIu64"-%"PRIu64" %"PRId64"-%"PRId64"\n", next_node[0]->pos, next_node[1]->pos, next_node[0]->ts , next_node[1]->ts); pos= av_gen_search(s, -1, dummy.ts, next_node[0]->pos, next_node[1]->pos, next_node[1]->pos, @@ -868,7 +870,8 @@ static int read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flag if(!(flags & AVSEEK_FLAG_BACKWARD)){ dummy.pos= pos+16; next_node[1]= &nopts_sp; - av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pos_cmp, next_node); + av_tree_find(nut->syncpoints, &dummy, (void *) ff_nut_sp_pos_cmp, + (void **) next_node); pos2= av_gen_search(s, -2, dummy.pos, next_node[0]->pos , next_node[1]->pos, next_node[1]->pos, next_node[0]->back_ptr, next_node[1]->back_ptr, flags, &ts, nut_read_timestamp); if(pos2>=0) @@ -876,7 +879,8 @@ static int read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flag //FIXME dir but I think it does not matter } dummy.pos= pos; - sp= av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pos_cmp, NULL); + sp= av_tree_find(nut->syncpoints, &dummy, (void *) ff_nut_sp_pos_cmp, + NULL); assert(sp); pos2= sp->back_ptr - 15; @@ -897,9 +901,13 @@ static int read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flag static int nut_read_close(AVFormatContext *s) { NUTContext *nut = s->priv_data; + int i; av_freep(&nut->time_base); av_freep(&nut->stream); + ff_nut_free_sp(nut); + for(i = 1; i < nut->header_count; i++) + av_freep(&nut->header[i]); return 0; } @@ -915,5 +923,6 @@ AVInputFormat nut_demuxer = { nut_read_close, read_seek, .extensions = "nut", + .metadata_conv = ff_nut_metadata_conv, }; #endif diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/nutenc.c b/src/add-ons/media/plugins/ffmpeg/libavformat/nutenc.c index 47d2dc5f3d..dfda3cae88 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/nutenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/nutenc.c @@ -152,7 +152,7 @@ static void build_frame_code(AVFormatContext *s){ int start2= start + (end-start)*stream_id / s->nb_streams; int end2 = start + (end-start)*(stream_id+1) / s->nb_streams; AVCodecContext *codec = s->streams[stream_id]->codec; - int is_audio= codec->codec_type == CODEC_TYPE_AUDIO; + int is_audio= codec->codec_type == AVMEDIA_TYPE_AUDIO; int intra_only= /*codec->intra_only || */is_audio; int pred_count; @@ -394,9 +394,9 @@ static int write_streamheader(NUTContext *nut, ByteIOContext *bc, AVStream *st, AVCodecContext *codec = st->codec; put_v(bc, i); switch(codec->codec_type){ - case CODEC_TYPE_VIDEO: put_v(bc, 0); break; - case CODEC_TYPE_AUDIO: put_v(bc, 1); break; - case CODEC_TYPE_SUBTITLE: put_v(bc, 2); break; + case AVMEDIA_TYPE_VIDEO: put_v(bc, 0); break; + case AVMEDIA_TYPE_AUDIO: put_v(bc, 1); break; + case AVMEDIA_TYPE_SUBTITLE: put_v(bc, 2); break; default : put_v(bc, 3); break; } put_v(bc, 4); @@ -415,12 +415,12 @@ static int write_streamheader(NUTContext *nut, ByteIOContext *bc, AVStream *st, put_buffer(bc, codec->extradata, codec->extradata_size); switch(codec->codec_type){ - case CODEC_TYPE_AUDIO: + case AVMEDIA_TYPE_AUDIO: put_v(bc, codec->sample_rate); put_v(bc, 1); put_v(bc, codec->channels); break; - case CODEC_TYPE_VIDEO: + case AVMEDIA_TYPE_VIDEO: put_v(bc, codec->width); put_v(bc, codec->height); @@ -448,7 +448,7 @@ static int add_info(ByteIOContext *bc, const char *type, const char *value){ static int write_globalinfo(NUTContext *nut, ByteIOContext *bc){ AVFormatContext *s= nut->avf; - AVMetadataTag *title, *author, *copyright; + AVMetadataTag *t = NULL; ByteIOContext *dyn_bc; uint8_t *dyn_buf=NULL; int count=0, dyn_size; @@ -456,15 +456,8 @@ static int write_globalinfo(NUTContext *nut, ByteIOContext *bc){ if(ret < 0) return ret; - title = av_metadata_get(s->metadata, "Title" , NULL, 0); - author = av_metadata_get(s->metadata, "Author" , NULL, 0); - copyright = av_metadata_get(s->metadata, "Copyright", NULL, 0); - - if(title ) count+= add_info(dyn_bc, "Title" , title->value); - if(author ) count+= add_info(dyn_bc, "Author" , author->value); - if(copyright) count+= add_info(dyn_bc, "Copyright", copyright->value); - if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) - count+= add_info(dyn_bc, "Encoder" , LIBAVFORMAT_IDENT); + while ((t = av_metadata_get(s->metadata, "", t, AV_METADATA_IGNORE_SUFFIX))) + count += add_info(dyn_bc, t->key, t->value); put_v(bc, 0); //stream_if_plus1 put_v(bc, 0); //chapter_id @@ -610,7 +603,7 @@ static int write_header(AVFormatContext *s){ static int get_needed_flags(NUTContext *nut, StreamContext *nus, FrameCode *fc, AVPacket *pkt){ int flags= 0; - if(pkt->flags & PKT_FLAG_KEY ) flags |= FLAG_KEY; + if(pkt->flags & AV_PKT_FLAG_KEY ) flags |= FLAG_KEY; if(pkt->stream_index != fc->stream_id ) flags |= FLAG_STREAM_ID; if(pkt->size / fc->size_mul ) flags |= FLAG_SIZE_MSB; if(pkt->pts - nus->last_pts != fc->pts_delta) flags |= FLAG_CODED_PTS; @@ -651,7 +644,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt){ FrameCode *fc; int64_t coded_pts; int best_length, frame_code, flags, needed_flags, i, header_idx, best_header_idx; - int key_frame = !!(pkt->flags & PKT_FLAG_KEY); + int key_frame = !!(pkt->flags & AV_PKT_FLAG_KEY); int store_sp=0; int ret; @@ -684,7 +677,8 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt){ } if(dummy.pos == INT64_MAX) dummy.pos= 0; - sp= av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pos_cmp, NULL); + sp= av_tree_find(nut->syncpoints, &dummy, (void *) ff_nut_sp_pos_cmp, + NULL); nut->last_syncpoint_pos= url_ftell(bc); ret = url_open_dyn_buf(&dyn_bc); @@ -804,6 +798,9 @@ static int write_trailer(AVFormatContext *s){ while(nut->header_count<3) write_headers(nut, bc); put_flush_packet(bc); + ff_nut_free_sp(nut); + av_freep(&nut->stream); + av_freep(&nut->time_base); return 0; } @@ -827,4 +824,5 @@ AVOutputFormat nut_muxer = { write_trailer, .flags = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS, .codec_tag= (const AVCodecTag* const []){ff_codec_bmp_tags, ff_codec_wav_tags, ff_nut_subtitle_tags, 0}, + .metadata_conv = ff_nut_metadata_conv, }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/nuv.c b/src/add-ons/media/plugins/ffmpeg/libavformat/nuv.c index 4abe54fd6e..f0eacd5f8a 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/nuv.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/nuv.c @@ -155,7 +155,7 @@ static int nuv_header(AVFormatContext *s, AVFormatParameters *ap) { vst = av_new_stream(s, ctx->v_id); if (!vst) return AVERROR(ENOMEM); - vst->codec->codec_type = CODEC_TYPE_VIDEO; + vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; vst->codec->codec_id = CODEC_ID_NUV; vst->codec->width = width; vst->codec->height = height; @@ -171,7 +171,7 @@ static int nuv_header(AVFormatContext *s, AVFormatParameters *ap) { ast = av_new_stream(s, ctx->a_id); if (!ast) return AVERROR(ENOMEM); - ast->codec->codec_type = CODEC_TYPE_AUDIO; + ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; ast->codec->codec_id = CODEC_ID_PCM_S16LE; ast->codec->channels = 2; ast->codec->sample_rate = 44100; @@ -220,7 +220,7 @@ static int nuv_packet(AVFormatContext *s, AVPacket *pkt) { 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 |= PKT_FLAG_KEY; + pkt->flags |= AV_PKT_FLAG_KEY; pkt->pos = pos; pkt->pts = AV_RL32(&hdr[4]); pkt->stream_index = ctx->v_id; @@ -240,7 +240,7 @@ static int nuv_packet(AVFormatContext *s, AVPacket *pkt) { break; } ret = av_get_packet(pb, pkt, size); - pkt->flags |= PKT_FLAG_KEY; + pkt->flags |= AV_PKT_FLAG_KEY; pkt->pos = pos; pkt->pts = AV_RL32(&hdr[4]); pkt->stream_index = ctx->a_id; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/oggdec.c b/src/add-ons/media/plugins/ffmpeg/libavformat/oggdec.c index 5d42db765c..3161e68c6c 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/oggdec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/oggdec.c @@ -33,15 +33,19 @@ #include #include "oggdec.h" #include "avformat.h" +#include "vorbiscomment.h" #define MAX_PAGE_SIZE 65307 #define DECODER_BUFFER_SIZE MAX_PAGE_SIZE static const struct ogg_codec * const ogg_codecs[] = { + &ff_skeleton_codec, + &ff_dirac_codec, &ff_speex_codec, &ff_vorbis_codec, &ff_theora_codec, &ff_flac_codec, + &ff_old_dirac_codec, &ff_old_flac_codec, &ff_ogm_video_codec, &ff_ogm_audio_codec, @@ -116,9 +120,13 @@ ogg_reset (struct ogg * ogg) os->pstart = 0; os->psize = 0; os->granule = -1; - os->lastgp = -1; + os->lastpts = AV_NOPTS_VALUE; + os->lastdts = AV_NOPTS_VALUE; + os->sync_pos = -1; + os->page_pos = 0; os->nsegs = 0; os->segp = 0; + os->incomplete = 0; } ogg->curidx = -1; @@ -139,18 +147,6 @@ ogg_find_codec (uint8_t * buf, int size) return NULL; } -static int -ogg_find_stream (struct ogg * ogg, int serial) -{ - int i; - - for (i = 0; i < ogg->nstreams; i++) - if (ogg->streams[i].serial == serial) - return i; - - return -1; -} - static int ogg_new_stream (AVFormatContext * s, uint32_t serial) { @@ -251,6 +247,7 @@ ogg_read_page (AVFormatContext * s, int *str) } os = ogg->streams + idx; + os->page_pos = url_ftell(bc) - 27; if(os->psize > 0) ogg_new_buf(ogg, idx); @@ -265,7 +262,7 @@ ogg_read_page (AVFormatContext * s, int *str) for (i = 0; i < nsegs; i++) size += os->segments[i]; - if (flags & OGG_FLAG_CONT){ + if (flags & OGG_FLAG_CONT || os->incomplete){ if (!os->psize){ while (os->segp < os->nsegs){ int seg = os->segments[os->segp++]; @@ -273,9 +270,11 @@ ogg_read_page (AVFormatContext * s, int *str) if (seg < 255) break; } + os->sync_pos = os->page_pos; } }else{ os->psize = 0; + os->sync_pos = os->page_pos; } if (os->bufsize - os->bufpos < size){ @@ -288,7 +287,6 @@ ogg_read_page (AVFormatContext * s, int *str) if (get_buffer (bc, os->buf + os->bufpos, size) < size) return -1; - os->lastgp = os->granule; os->bufpos += size; os->granule = gp; os->flags = flags; @@ -300,10 +298,10 @@ ogg_read_page (AVFormatContext * s, int *str) } static int -ogg_packet (AVFormatContext * s, int *str, int *dstart, int *dsize) +ogg_packet (AVFormatContext * s, int *str, int *dstart, int *dsize, int64_t *fpos) { struct ogg *ogg = s->priv_data; - int idx; + int idx, i; struct ogg_stream *os; int complete = 0; int segp = 0, psize = 0; @@ -354,6 +352,7 @@ ogg_packet (AVFormatContext * s, int *str, int *dstart, int *dsize) if (!complete && os->segp == os->nsegs){ ogg->curidx = -1; + os->incomplete = 1; } }while (!complete); @@ -363,23 +362,27 @@ ogg_packet (AVFormatContext * s, int *str, int *dstart, int *dsize) idx, os->psize, os->pstart); #endif - ogg->curidx = idx; + if (os->granule == -1) + av_log(s, AV_LOG_WARNING, "Page at %lld is missing granule\n", os->page_pos); - if (os->header < 0){ - int hdr = os->codec->header (s, idx); - if (!hdr){ - os->header = os->seq; + ogg->curidx = idx; + os->incomplete = 0; + + if (os->header) { + os->header = os->codec->header (s, idx); + if (!os->header){ os->segp = segp; os->psize = psize; + if (!ogg->headers) + s->data_offset = os->sync_pos; ogg->headers = 1; }else{ os->pstart += os->psize; os->psize = 0; } - } - - if (os->header > -1 && os->seq > os->header){ + } else { os->pflags = 0; + os->pduration = 0; if (os->codec && os->codec->packet) os->codec->packet (s, idx); if (str) @@ -388,11 +391,22 @@ ogg_packet (AVFormatContext * s, int *str, int *dstart, int *dsize) *dstart = os->pstart; if (dsize) *dsize = os->psize; + if (fpos) + *fpos = os->sync_pos; os->pstart += os->psize; os->psize = 0; + os->sync_pos = os->page_pos; } - os->seq++; + // determine whether there are more complete packets in this page + // if not, the page's granule will apply to this packet + os->page_end = 1; + for (i = os->segp; i < os->nsegs; i++) + if (os->segments[i] < 255) { + os->page_end = 0; + break; + } + if (os->segp == os->nsegs) ogg->curidx = -1; @@ -405,7 +419,7 @@ ogg_get_headers (AVFormatContext * s) struct ogg *ogg = s->priv_data; do{ - if (ogg_packet (s, NULL, NULL, NULL) < 0) + if (ogg_packet (s, NULL, NULL, NULL, NULL) < 0) return -1; }while (!ogg->headers); @@ -416,28 +430,11 @@ ogg_get_headers (AVFormatContext * s) return 0; } -static uint64_t -ogg_gptopts (AVFormatContext * s, int i, uint64_t gp) -{ - struct ogg *ogg = s->priv_data; - struct ogg_stream *os = ogg->streams + i; - uint64_t pts = AV_NOPTS_VALUE; - - if(os->codec->gptopts){ - pts = os->codec->gptopts(s, i, gp); - } else { - pts = gp; - } - - return pts; -} - - static int ogg_get_length (AVFormatContext * s) { struct ogg *ogg = s->priv_data; - int idx = -1, i; + int i; int64_t size, end; if(url_is_streamed(s->pb)) @@ -457,16 +454,14 @@ ogg_get_length (AVFormatContext * s) while (!ogg_read_page (s, &i)){ if (ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0 && - ogg->streams[i].codec) - idx = i; + 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) + s->streams[i]->duration -= s->streams[i]->start_time; + } } - if (idx != -1){ - s->streams[idx]->duration = - ogg_gptopts (s, idx, ogg->streams[idx].granule); - } - - ogg->size = size; ogg_restore (s, 0); return 0; @@ -477,12 +472,17 @@ static int ogg_read_header (AVFormatContext * s, AVFormatParameters * ap) { struct ogg *ogg = s->priv_data; + int i; ogg->curidx = -1; //linear headers seek from start if (ogg_get_headers (s) < 0){ return -1; } + for (i = 0; i < ogg->nstreams; i++) + if (ogg->streams[i].header < 0) + ogg->streams[i].codec = NULL; + //linear granulepos seek from end ogg_get_length (s); @@ -490,6 +490,35 @@ ogg_read_header (AVFormatContext * s, AVFormatParameters * ap) return 0; } +static int64_t ogg_calc_pts(AVFormatContext *s, int idx, int64_t *dts) +{ + struct ogg *ogg = s->priv_data; + struct ogg_stream *os = ogg->streams + idx; + int64_t pts = AV_NOPTS_VALUE; + + if (dts) + *dts = AV_NOPTS_VALUE; + + if (os->lastpts != AV_NOPTS_VALUE) { + pts = os->lastpts; + os->lastpts = AV_NOPTS_VALUE; + } + if (os->lastdts != AV_NOPTS_VALUE) { + if (dts) + *dts = os->lastdts; + os->lastdts = AV_NOPTS_VALUE; + } + if (os->page_end) { + if (os->granule != -1LL) { + if (os->codec && os->codec->granule_is_start) + pts = ogg_gptopts(s, idx, os->granule, dts); + else + os->lastpts = ogg_gptopts(s, idx, os->granule, &os->lastdts); + os->granule = -1LL; + } + } + return pts; +} static int ogg_read_packet (AVFormatContext * s, AVPacket * pkt) @@ -498,27 +527,36 @@ ogg_read_packet (AVFormatContext * s, AVPacket * pkt) struct ogg_stream *os; int idx = -1; int pstart, psize; + int64_t fpos, pts, dts; //Get an ogg packet +retry: do{ - if (ogg_packet (s, &idx, &pstart, &psize) < 0) + if (ogg_packet (s, &idx, &pstart, &psize, &fpos) < 0) return AVERROR(EIO); }while (idx < 0 || !s->streams[idx]); ogg = s->priv_data; os = ogg->streams + idx; + // pflags might not be set until after this + pts = ogg_calc_pts(s, idx, &dts); + + if (os->keyframe_seek && !(os->pflags & AV_PKT_FLAG_KEY)) + goto retry; + os->keyframe_seek = 0; + //Alloc a pkt if (av_new_packet (pkt, psize) < 0) return AVERROR(EIO); pkt->stream_index = idx; memcpy (pkt->data, os->buf + pstart, psize); - if (os->lastgp != -1LL){ - pkt->pts = ogg_gptopts (s, idx, os->lastgp); - os->lastgp = -1; - } + pkt->pts = pts; + pkt->dts = dts; pkt->flags = os->pflags; + pkt->duration = os->pduration; + pkt->pos = fpos; return psize; } @@ -544,24 +582,44 @@ 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; ByteIOContext *bc = s->pb; int64_t pts = AV_NOPTS_VALUE; int i; url_fseek(bc, *pos_arg, SEEK_SET); - while (url_ftell(bc) < pos_limit && !ogg_read_page (s, &i)) { - if (ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0 && - ogg->streams[i].codec && i == stream_index) { - pts = ogg_gptopts(s, i, ogg->streams[i].granule); - // FIXME: this is the position of the packet after the one with above - // pts. - *pos_arg = url_ftell(bc); - break; + ogg_reset(ogg); + + while (url_ftell(bc) < pos_limit && !ogg_packet(s, &i, NULL, NULL, pos_arg)) { + if (i == stream_index) { + pts = ogg_calc_pts(s, i, NULL); + if (os->keyframe_seek && !(os->pflags & AV_PKT_FLAG_KEY)) + pts = AV_NOPTS_VALUE; } + if (pts != AV_NOPTS_VALUE) + break; } ogg_reset(ogg); return pts; } +static int ogg_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) +{ + struct ogg *ogg = s->priv_data; + struct ogg_stream *os = ogg->streams + stream_index; + int ret; + + // Try seeking to a keyframe first. If this fails (very possible), + // av_seek_frame will fall back to ignoring keyframes + if (s->streams[stream_index]->codec->codec_type == AVMEDIA_TYPE_VIDEO + && !(flags & AVSEEK_FLAG_ANY)) + os->keyframe_seek = 1; + + ret = av_seek_frame_binary(s, stream_index, timestamp, flags); + if (ret < 0) + os->keyframe_seek = 0; + return ret; +} + static int ogg_probe(AVProbeData *p) { if (p->buf[0] == 'O' && p->buf[1] == 'g' && @@ -580,8 +638,9 @@ AVInputFormat ogg_demuxer = { ogg_read_header, ogg_read_packet, ogg_read_close, - NULL, + ogg_read_seek, ogg_read_timestamp, .extensions = "ogg", .metadata_conv = ff_vorbiscomment_metadata_conv, + .flags = AVFMT_GENERIC_INDEX, }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/oggdec.h b/src/add-ons/media/plugins/ffmpeg/libavformat/oggdec.h index 91a59742ff..7d66cd5638 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/oggdec.h +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/oggdec.h @@ -40,7 +40,17 @@ struct ogg_codec { */ int (*header)(AVFormatContext *, int); int (*packet)(AVFormatContext *, int); - uint64_t (*gptopts)(AVFormatContext *, int, uint64_t); + /** + * Translate a granule into a timestamp. + * Will set dts if non-null and known. + * @return pts + */ + uint64_t (*gptopts)(AVFormatContext *, int, uint64_t, int64_t *dts); + /** + * 1 if granule is the start time of the associated packet. + * 0 if granule is the end time of the associated packet. + */ + int granule_is_start; }; struct ogg_stream { @@ -50,14 +60,21 @@ struct ogg_stream { unsigned int pstart; unsigned int psize; unsigned int pflags; + unsigned int pduration; uint32_t serial; - uint32_t seq; - uint64_t granule, lastgp; + uint64_t granule; + int64_t lastpts; + int64_t lastdts; + int64_t sync_pos; ///< file offset of the first page needed to reconstruct the current packet + int64_t page_pos; ///< file offset of the current page int flags; const struct ogg_codec *codec; int header; int nsegs, segp; uint8_t segments[255]; + 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; void *private; }; @@ -74,7 +91,6 @@ struct ogg { int nstreams; int headers; int curidx; - uint64_t size; struct ogg_state *state; }; @@ -82,18 +98,49 @@ struct ogg { #define OGG_FLAG_BOS 2 #define OGG_FLAG_EOS 4 +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; extern const struct ogg_codec ff_ogm_old_codec; extern const struct ogg_codec ff_ogm_text_codec; extern const struct ogg_codec ff_ogm_video_codec; +extern const struct ogg_codec ff_old_dirac_codec; extern const struct ogg_codec ff_old_flac_codec; +extern const struct ogg_codec ff_skeleton_codec; extern const struct ogg_codec ff_speex_codec; extern const struct ogg_codec ff_theora_codec; extern const struct ogg_codec ff_vorbis_codec; -extern const AVMetadataConv ff_vorbiscomment_metadata_conv[]; +int ff_vorbis_comment(AVFormatContext *ms, AVMetadata **m, const uint8_t *buf, int size); -int vorbis_comment(AVFormatContext *ms, uint8_t *buf, int size); +static inline int +ogg_find_stream (struct ogg * ogg, int serial) +{ + int i; + + for (i = 0; i < ogg->nstreams; i++) + if (ogg->streams[i].serial == serial) + return i; + + return -1; +} + +static inline uint64_t +ogg_gptopts (AVFormatContext * s, int i, uint64_t gp, int64_t *dts) +{ + struct ogg *ogg = s->priv_data; + struct ogg_stream *os = ogg->streams + i; + uint64_t pts = AV_NOPTS_VALUE; + + if(os->codec && os->codec->gptopts){ + pts = os->codec->gptopts(s, i, gp, dts); + } else { + pts = gp; + if (dts) + *dts = pts; + } + + return pts; +} #endif /* AVFORMAT_OGGDEC_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/oggenc.c b/src/add-ons/media/plugins/ffmpeg/libavformat/oggenc.c index 2bd8e0d49f..70264a4383 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/oggenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/oggenc.c @@ -25,6 +25,19 @@ #include "libavcodec/flac.h" #include "avformat.h" #include "internal.h" +#include "vorbiscomment.h" + +#define MAX_PAGE_SIZE 65025 + +typedef struct { + int64_t granule; + int stream_index; + uint8_t flags; + uint8_t segments_count; + uint8_t segments[255]; + uint8_t data[MAX_PAGE_SIZE]; + uint16_t size; +} OGGPage; typedef struct { int64_t duration; @@ -36,8 +49,19 @@ typedef struct { int64_t last_kf_pts; int vrev; int eos; + unsigned page_count; ///< number of page buffered + OGGPage page; ///< current page } OGGStreamContext; +typedef struct OGGPageList { + OGGPage page; + struct OGGPageList *next; +} OGGPageList; + +typedef struct { + OGGPageList *page_list; +} OGGContext; + static void ogg_update_checksum(AVFormatContext *s, int64_t crc_offset) { int64_t pos = url_ftell(s->pb); @@ -47,46 +71,149 @@ static void ogg_update_checksum(AVFormatContext *s, int64_t crc_offset) url_fseek(s->pb, pos, SEEK_SET); } -static int ogg_write_page(AVFormatContext *s, const uint8_t *data, int size, - int64_t granule, int stream_index, int flags) +static void ogg_write_page(AVFormatContext *s, OGGPage *page, int extra_flags) { - OGGStreamContext *oggstream = s->streams[stream_index]->priv_data; + OGGStreamContext *oggstream = s->streams[page->stream_index]->priv_data; int64_t crc_offset; - int page_segments, i; - - if (size >= 255*255) { - granule = -1; - size = 255*255; - } else if (oggstream->eos) - flags |= 4; - - page_segments = FFMIN((size/255)+!!size, 255); init_checksum(s->pb, ff_crc04C11DB7_update, 0); put_tag(s->pb, "OggS"); put_byte(s->pb, 0); - put_byte(s->pb, flags); - put_le64(s->pb, granule); - put_le32(s->pb, stream_index); + put_byte(s->pb, page->flags | extra_flags); + put_le64(s->pb, page->granule); + put_le32(s->pb, page->stream_index); put_le32(s->pb, oggstream->page_counter++); crc_offset = url_ftell(s->pb); put_le32(s->pb, 0); // crc - put_byte(s->pb, page_segments); - for (i = 0; i < page_segments-1; i++) - put_byte(s->pb, 255); - if (size) { - put_byte(s->pb, size - (page_segments-1)*255); - put_buffer(s->pb, data, size); - } + put_byte(s->pb, page->segments_count); + put_buffer(s->pb, page->segments, page->segments_count); + put_buffer(s->pb, page->data, page->size); + ogg_update_checksum(s, crc_offset); put_flush_packet(s->pb); - return size; + oggstream->page_count--; +} + +static int64_t ogg_granule_to_timestamp(OGGStreamContext *oggstream, OGGPage *page) +{ + if (oggstream->kfgshift) + return (page->granule>>oggstream->kfgshift) + + (page->granule & ((1<kfgshift)-1)); + else + return page->granule; +} + +static int ogg_compare_granule(AVFormatContext *s, OGGPage *next, OGGPage *page) +{ + AVStream *st2 = s->streams[next->stream_index]; + AVStream *st = s->streams[page->stream_index]; + int64_t next_granule, cur_granule; + + if (next->granule == -1 || page->granule == -1) + return 0; + + next_granule = av_rescale_q(ogg_granule_to_timestamp(st2->priv_data, next), + st2->time_base, AV_TIME_BASE_Q); + cur_granule = av_rescale_q(ogg_granule_to_timestamp(st->priv_data, page), + st ->time_base, AV_TIME_BASE_Q); + return next_granule > cur_granule; +} + +static int ogg_reset_cur_page(OGGStreamContext *oggstream) +{ + oggstream->page.granule = -1; + oggstream->page.flags = 0; + oggstream->page.segments_count = 0; + oggstream->page.size = 0; + return 0; +} + +static int ogg_buffer_page(AVFormatContext *s, OGGStreamContext *oggstream) +{ + OGGContext *ogg = s->priv_data; + OGGPageList **p = &ogg->page_list; + OGGPageList *l = av_mallocz(sizeof(*l)); + + if (!l) + return AVERROR(ENOMEM); + l->page = oggstream->page; + + oggstream->page_count++; + ogg_reset_cur_page(oggstream); + + while (*p) { + if (ogg_compare_granule(s, &(*p)->page, &l->page)) + break; + p = &(*p)->next; + } + l->next = *p; + *p = l; + + return 0; +} + +static int ogg_buffer_data(AVFormatContext *s, AVStream *st, + uint8_t *data, unsigned size, int64_t granule) +{ + OGGStreamContext *oggstream = st->priv_data; + int total_segments = size / 255 + 1; + uint8_t *p = data; + int i, segments, len; + + for (i = 0; i < total_segments; ) { + OGGPage *page = &oggstream->page; + + segments = FFMIN(total_segments - i, 255 - page->segments_count); + + if (i && !page->segments_count) + page->flags |= 1; // continued packet + + memset(page->segments+page->segments_count, 255, segments - 1); + page->segments_count += segments - 1; + + len = FFMIN(size, segments*255); + page->segments[page->segments_count++] = len - (segments-1)*255; + memcpy(page->data+page->size, p, len); + p += len; + size -= len; + i += segments; + page->size += len; + + if (i == total_segments) + page->granule = granule; + + if (page->segments_count == 255) { + ogg_buffer_page(s, oggstream); + } + } + return 0; +} + +static uint8_t *ogg_write_vorbiscomment(int offset, int bitexact, + int *header_len, AVMetadata *m) +{ + const char *vendor = bitexact ? "ffmpeg" : LIBAVFORMAT_IDENT; + int size; + uint8_t *p, *p0; + unsigned int count; + + size = offset + ff_vorbiscomment_length(m, vendor, &count); + p = av_mallocz(size); + if (!p) + return NULL; + p0 = p; + + p += offset; + ff_vorbiscomment_write(&p, m, vendor, count); + + *header_len = size; + return p0; } static int ogg_build_flac_headers(AVCodecContext *avctx, - OGGStreamContext *oggstream, int bitexact) + OGGStreamContext *oggstream, int bitexact, + AVMetadata *m) { - const char *vendor = bitexact ? "ffmpeg" : LIBAVFORMAT_IDENT; enum FLACExtradataFormat format; uint8_t *streaminfo; uint8_t *p; @@ -99,7 +226,7 @@ static int ogg_build_flac_headers(AVCodecContext *avctx, oggstream->header[0] = av_mallocz(51); // per ogg flac specs p = oggstream->header[0]; if (!p) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); bytestream_put_byte(&p, 0x7F); bytestream_put_buffer(&p, "FLAC", 4); bytestream_put_byte(&p, 1); // major version @@ -111,16 +238,41 @@ static int ogg_build_flac_headers(AVCodecContext *avctx, bytestream_put_buffer(&p, streaminfo, FLAC_STREAMINFO_SIZE); // second packet: VorbisComment - oggstream->header_len[1] = 1+3+4+strlen(vendor)+4; - oggstream->header[1] = av_mallocz(oggstream->header_len[1]); - p = oggstream->header[1]; + p = ogg_write_vorbiscomment(4, bitexact, &oggstream->header_len[1], m); if (!p) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); + oggstream->header[1] = p; bytestream_put_byte(&p, 0x84); // last metadata block and vorbis comment bytestream_put_be24(&p, oggstream->header_len[1] - 4); - bytestream_put_le32(&p, strlen(vendor)); - bytestream_put_buffer(&p, vendor, strlen(vendor)); - bytestream_put_le32(&p, 0); // user comment list length + + return 0; +} + +#define SPEEX_HEADER_SIZE 80 + +static int ogg_build_speex_headers(AVCodecContext *avctx, + OGGStreamContext *oggstream, int bitexact, + AVMetadata *m) +{ + uint8_t *p; + + if (avctx->extradata_size < SPEEX_HEADER_SIZE) + return -1; + + // first packet: Speex header + p = av_mallocz(SPEEX_HEADER_SIZE); + if (!p) + return AVERROR(ENOMEM); + oggstream->header[0] = p; + oggstream->header_len[0] = SPEEX_HEADER_SIZE; + bytestream_put_buffer(&p, avctx->extradata, SPEEX_HEADER_SIZE); + AV_WL32(&oggstream->header[0][68], 0); // set extra_headers to 0 + + // second packet: VorbisComment + p = ogg_write_vorbiscomment(0, bitexact, &oggstream->header_len[1], m); + if (!p) + return AVERROR(ENOMEM); + oggstream->header[1] = p; return 0; } @@ -131,12 +283,13 @@ static int ogg_write_header(AVFormatContext *s) int i, j; for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; - if (st->codec->codec_type == CODEC_TYPE_AUDIO) + if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) av_set_pts_info(st, 64, 1, st->codec->sample_rate); - else if (st->codec->codec_type == CODEC_TYPE_VIDEO) + else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) av_set_pts_info(st, 64, st->codec->time_base.num, st->codec->time_base.den); if (st->codec->codec_id != CODEC_ID_VORBIS && st->codec->codec_id != CODEC_ID_THEORA && + st->codec->codec_id != CODEC_ID_SPEEX && st->codec->codec_id != CODEC_ID_FLAC) { av_log(s, AV_LOG_ERROR, "Unsupported codec id in stream %d\n", i); return -1; @@ -147,15 +300,26 @@ static int ogg_write_header(AVFormatContext *s) return -1; } oggstream = av_mallocz(sizeof(*oggstream)); + oggstream->page.stream_index = i; st->priv_data = oggstream; if (st->codec->codec_id == CODEC_ID_FLAC) { int err = ogg_build_flac_headers(st->codec, oggstream, - st->codec->flags & CODEC_FLAG_BITEXACT); + st->codec->flags & CODEC_FLAG_BITEXACT, + s->metadata); if (err) { av_log(s, AV_LOG_ERROR, "Error writing FLAC headers\n"); av_freep(&st->priv_data); return err; } + } else if (st->codec->codec_id == CODEC_ID_SPEEX) { + int err = ogg_build_speex_headers(st->codec, oggstream, + st->codec->flags & CODEC_FLAG_BITEXACT, + s->metadata); + if (err) { + av_log(s, AV_LOG_ERROR, "Error writing Speex headers\n"); + av_freep(&st->priv_data); + return err; + } } else { if (ff_split_xiph_headers(st->codec->extradata, st->codec->extradata_size, st->codec->codec_id == CODEC_ID_VORBIS ? 30 : 42, @@ -174,31 +338,60 @@ static int ogg_write_header(AVFormatContext *s) } } } - for (i = 0; i < 3; i++) { - for (j = 0; j < s->nb_streams; j++) { - AVStream *st = s->streams[j]; - OGGStreamContext *oggstream = st->priv_data; - if (oggstream && oggstream->header_len[i]) { - ogg_write_page(s, oggstream->header[i], oggstream->header_len[i], - 0, st->index, i ? 0 : 2); // bos - } + + for (j = 0; j < s->nb_streams; j++) { + OGGStreamContext *oggstream = s->streams[j]->priv_data; + ogg_buffer_data(s, s->streams[j], oggstream->header[0], + oggstream->header_len[0], 0); + oggstream->page.flags |= 2; // bos + ogg_buffer_page(s, oggstream); + } + for (j = 0; j < s->nb_streams; j++) { + AVStream *st = s->streams[j]; + OGGStreamContext *oggstream = st->priv_data; + for (i = 1; i < 3; i++) { + if (oggstream && oggstream->header_len[i]) + ogg_buffer_data(s, st, oggstream->header[i], + oggstream->header_len[i], 0); } + ogg_buffer_page(s, oggstream); } return 0; } +static void ogg_write_pages(AVFormatContext *s, int flush) +{ + OGGContext *ogg = s->priv_data; + OGGPageList *next, *p; + + if (!ogg->page_list) + return; + + for (p = ogg->page_list; p; ) { + OGGStreamContext *oggstream = + s->streams[p->page.stream_index]->priv_data; + if (oggstream->page_count < 2 && !flush) + break; + ogg_write_page(s, &p->page, + flush && oggstream->page_count == 1 ? 4 : 0); // eos + next = p->next; + av_freep(&p); + p = next; + } + ogg->page_list = p; +} + static int ogg_write_packet(AVFormatContext *s, AVPacket *pkt) { AVStream *st = s->streams[pkt->stream_index]; OGGStreamContext *oggstream = st->priv_data; - uint8_t *ptr = pkt->data; - int ret, size = pkt->size; + int ret; int64_t granule; if (st->codec->codec_id == CODEC_ID_THEORA) { int64_t pts = oggstream->vrev < 1 ? pkt->pts : pkt->pts + pkt->duration; int pframe_count; - if (pkt->flags & PKT_FLAG_KEY) + if (pkt->flags & AV_PKT_FLAG_KEY) oggstream->last_kf_pts = pts; pframe_count = pts - oggstream->last_kf_pts; // prevent frame count from overflow if key frame flag is not set @@ -210,72 +403,31 @@ static int ogg_write_packet(AVFormatContext *s, AVPacket *pkt) } else granule = pkt->pts + pkt->duration; oggstream->duration = granule; - do { - ret = ogg_write_page(s, ptr, size, granule, pkt->stream_index, ptr != pkt->data); - ptr += ret; size -= ret; - } while (size > 0 || ret == 255*255); // need to output a last nil page + + ret = ogg_buffer_data(s, st, pkt->data, pkt->size, granule); + if (ret < 0) + return ret; + + ogg_write_pages(s, 0); return 0; } -static int ogg_compare_granule(AVFormatContext *s, AVPacket *next, AVPacket *pkt) -{ - AVStream *st2 = s->streams[next->stream_index]; - AVStream *st = s->streams[pkt ->stream_index]; - - int64_t next_granule = av_rescale_q(next->pts + next->duration, - st2->time_base, AV_TIME_BASE_Q); - int64_t cur_granule = av_rescale_q(pkt ->pts + pkt ->duration, - st ->time_base, AV_TIME_BASE_Q); - return next_granule > cur_granule; -} - -static int ogg_interleave_per_granule(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush) -{ - AVPacketList *pktl; - int stream_count = 0; - int streams[MAX_STREAMS] = {0}; - int interleaved = 0; - - if (pkt) { - ff_interleave_add_packet(s, pkt, ogg_compare_granule); - } - - pktl = s->packet_buffer; - while (pktl) { - if (streams[pktl->pkt.stream_index] == 0) - stream_count++; - streams[pktl->pkt.stream_index]++; - // need to buffer at least one packet to set eos flag - if (streams[pktl->pkt.stream_index] == 2) - interleaved++; - pktl = pktl->next; - } - - if ((s->nb_streams == stream_count && interleaved == stream_count) || - (flush && stream_count)) { - pktl= s->packet_buffer; - *out= pktl->pkt; - s->packet_buffer = pktl->next; - if (flush && streams[out->stream_index] == 1) { - OGGStreamContext *ogg = s->streams[out->stream_index]->priv_data; - ogg->eos = 1; - } - av_freep(&pktl); - return 1; - } else { - av_init_packet(out); - return 0; - } -} - static int ogg_write_trailer(AVFormatContext *s) { int i; + + /* flush current page */ + for (i = 0; i < s->nb_streams; i++) + ogg_buffer_page(s, s->streams[i]->priv_data); + + ogg_write_pages(s, 1); + for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; OGGStreamContext *oggstream = st->priv_data; - if (st->codec->codec_id == CODEC_ID_FLAC) { + 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]); } @@ -288,12 +440,12 @@ AVOutputFormat ogg_muxer = { "ogg", NULL_IF_CONFIG_SMALL("Ogg"), "application/ogg", - "ogg,ogv", - 0, + "ogg,ogv,spx", + sizeof(OGGContext), CODEC_ID_FLAC, CODEC_ID_THEORA, ogg_write_header, ogg_write_packet, ogg_write_trailer, - .interleave_packet = ogg_interleave_per_granule, + .metadata_conv = ff_vorbiscomment_metadata_conv, }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/oggparsedirac.c b/src/add-ons/media/plugins/ffmpeg/libavformat/oggparsedirac.c new file mode 100644 index 0000000000..a7f0401f29 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/oggparsedirac.c @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2008 David Conrad + * + * 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 "libavcodec/get_bits.h" +#include "libavcodec/dirac.h" +#include "avformat.h" +#include "oggdec.h" + +static int dirac_header(AVFormatContext *s, int idx) +{ + struct ogg *ogg = s->priv_data; + struct ogg_stream *os = ogg->streams + idx; + AVStream *st = s->streams[idx]; + dirac_source_params source; + GetBitContext gb; + + // already parsed the header + if (st->codec->codec_id == CODEC_ID_DIRAC) + 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) + return -1; + + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_DIRAC; + // dirac in ogg always stores timestamps as though the video were interlaced + st->time_base = (AVRational){st->codec->time_base.num, 2*st->codec->time_base.den}; + return 1; +} + +// various undocument things: granule is signed (only for dirac!) +static uint64_t dirac_gptopts(AVFormatContext *s, int idx, uint64_t granule, + int64_t *dts_out) +{ + int64_t gp = granule; + struct ogg *ogg = s->priv_data; + struct ogg_stream *os = ogg->streams + idx; + + unsigned dist = ((gp >> 14) & 0xff00) | (gp & 0xff); + int64_t dts = (gp >> 31); + int64_t pts = dts + ((gp >> 9) & 0x1fff); + + if (!dist) + os->pflags |= AV_PKT_FLAG_KEY; + + if (dts_out) + *dts_out = dts; + + return pts; +} + +static int old_dirac_header(AVFormatContext *s, int idx) +{ + struct ogg *ogg = s->priv_data; + struct ogg_stream *os = ogg->streams + idx; + AVStream *st = s->streams[idx]; + uint8_t *buf = os->buf + os->pstart; + + if (buf[0] != 'K') + return 0; + + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_DIRAC; + st->time_base.den = AV_RB32(buf+8); + st->time_base.num = AV_RB32(buf+12); + return 1; +} + +static uint64_t old_dirac_gptopts(AVFormatContext *s, int idx, uint64_t gp, + int64_t *dts) +{ + struct ogg *ogg = s->priv_data; + struct ogg_stream *os = ogg->streams + idx; + uint64_t iframe = gp >> 30; + uint64_t pframe = gp & 0x3fffffff; + + if (!pframe) + os->pflags |= AV_PKT_FLAG_KEY; + + return iframe + pframe; +} + +const struct ogg_codec ff_dirac_codec = { + .magic = "BBCD\0", + .magicsize = 5, + .header = dirac_header, + .gptopts = dirac_gptopts, + .granule_is_start = 1, +}; + +const struct ogg_codec ff_old_dirac_codec = { + .magic = "KW-DIRAC", + .magicsize = 8, + .header = old_dirac_header, + .gptopts = old_dirac_gptopts, + .granule_is_start = 1, +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/oggparseflac.c b/src/add-ons/media/plugins/ffmpeg/libavformat/oggparseflac.c index b524da17ee..e5034af3a0 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/oggparseflac.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/oggparseflac.c @@ -57,7 +57,7 @@ flac_header (AVFormatContext * s, int idx) ff_flac_parse_streaminfo(st->codec, &si, streaminfo_start); - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_FLAC; st->codec->extradata = @@ -68,7 +68,7 @@ flac_header (AVFormatContext * s, int idx) st->time_base.num = 1; st->time_base.den = st->codec->sample_rate; } else if (mdt == FLAC_METADATA_TYPE_VORBIS_COMMENT) { - vorbis_comment (s, os->buf + os->pstart + 4, os->psize - 4); + ff_vorbis_comment (s, &st->metadata, os->buf + os->pstart + 4, os->psize - 4); } return 1; @@ -78,7 +78,7 @@ static int old_flac_header (AVFormatContext * s, int idx) { AVStream *st = s->streams[idx]; - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_FLAC; return 0; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/oggparseogm.c b/src/add-ons/media/plugins/ffmpeg/libavformat/oggparseogm.c index f13f8c5242..e1d046f28f 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/oggparseogm.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/oggparseogm.c @@ -43,55 +43,58 @@ ogm_header(AVFormatContext *s, int idx) if(!(*p & 1)) return 0; - if(*p != 1) - return 1; - p++; + if(*p == 1) { + p++; - if(*p == 'v'){ - int tag; - st->codec->codec_type = CODEC_TYPE_VIDEO; - p += 8; - tag = bytestream_get_le32(&p); - st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tag); - st->codec->codec_tag = tag; - } else if (*p == 't') { - st->codec->codec_type = CODEC_TYPE_SUBTITLE; - st->codec->codec_id = CODEC_ID_TEXT; - p += 12; - } else { - uint8_t acid[5]; - int cid; - st->codec->codec_type = CODEC_TYPE_AUDIO; - p += 8; - bytestream_get_buffer(&p, acid, 4); - acid[4] = 0; - cid = strtol(acid, NULL, 16); - st->codec->codec_id = ff_codec_get_id(ff_codec_wav_tags, cid); - st->need_parsing = AVSTREAM_PARSE_FULL; - } + if(*p == 'v'){ + int tag; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + p += 8; + tag = bytestream_get_le32(&p); + st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tag); + st->codec->codec_tag = tag; + } else if (*p == 't') { + st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; + st->codec->codec_id = CODEC_ID_TEXT; + p += 12; + } else { + uint8_t acid[5]; + int cid; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + p += 8; + bytestream_get_buffer(&p, acid, 4); + acid[4] = 0; + cid = strtol(acid, NULL, 16); + st->codec->codec_id = ff_codec_get_id(ff_codec_wav_tags, cid); + st->need_parsing = AVSTREAM_PARSE_FULL; + } - p += 4; /* useless size field */ + p += 4; /* useless size field */ - time_unit = bytestream_get_le64(&p); - spu = bytestream_get_le64(&p); - default_len = bytestream_get_le32(&p); + time_unit = bytestream_get_le64(&p); + spu = bytestream_get_le64(&p); + default_len = bytestream_get_le32(&p); - p += 8; /* buffersize + bits_per_sample */ + p += 8; /* buffersize + bits_per_sample */ - if(st->codec->codec_type == CODEC_TYPE_VIDEO){ - st->codec->width = bytestream_get_le32(&p); - st->codec->height = bytestream_get_le32(&p); - st->codec->time_base.den = spu * 10000000; - st->codec->time_base.num = time_unit; - st->time_base = st->codec->time_base; - } else { - st->codec->channels = bytestream_get_le16(&p); - p += 2; /* block_align */ - st->codec->bit_rate = bytestream_get_le32(&p) * 8; - st->codec->sample_rate = spu * 10000000 / time_unit; - st->time_base.num = 1; - st->time_base.den = st->codec->sample_rate; + if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO){ + st->codec->width = bytestream_get_le32(&p); + st->codec->height = bytestream_get_le32(&p); + st->codec->time_base.den = spu * 10000000; + st->codec->time_base.num = time_unit; + st->time_base = st->codec->time_base; + } else { + st->codec->channels = bytestream_get_le16(&p); + p += 2; /* block_align */ + st->codec->bit_rate = bytestream_get_le32(&p) * 8; + st->codec->sample_rate = spu * 10000000 / time_unit; + st->time_base.num = 1; + st->time_base.den = st->codec->sample_rate; + } + } else if (*p == 3) { + if (os->psize > 8) + ff_vorbis_comment(s, &st->metadata, p+7, os->psize-8); } return 1; @@ -114,14 +117,14 @@ ogm_dshow_header(AVFormatContext *s, int idx) t = AV_RL32(p + 96); if(t == 0x05589f80){ - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, AV_RL32(p + 68)); st->codec->time_base.den = 10000000; st->codec->time_base.num = AV_RL64(p + 164); st->codec->width = AV_RL32(p + 176); st->codec->height = AV_RL32(p + 180); } else if(t == 0x05589f81){ - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = ff_codec_get_id(ff_codec_wav_tags, AV_RL16(p + 124)); st->codec->channels = AV_RL16(p + 126); st->codec->sample_rate = AV_RL32(p + 128); @@ -140,12 +143,15 @@ ogm_packet(AVFormatContext *s, int idx) int lb; if(*p & 8) - os->pflags |= PKT_FLAG_KEY; + os->pflags |= AV_PKT_FLAG_KEY; lb = ((*p & 2) << 1) | ((*p >> 6) & 3); os->pstart += lb + 1; os->psize -= lb + 1; + while (lb--) + os->pduration += p[lb+1] << (lb*8); + return 0; } @@ -153,26 +159,30 @@ const struct ogg_codec ff_ogm_video_codec = { .magic = "\001video", .magicsize = 6, .header = ogm_header, - .packet = ogm_packet + .packet = ogm_packet, + .granule_is_start = 1, }; const struct ogg_codec ff_ogm_audio_codec = { .magic = "\001audio", .magicsize = 6, .header = ogm_header, - .packet = ogm_packet + .packet = ogm_packet, + .granule_is_start = 1, }; const struct ogg_codec ff_ogm_text_codec = { .magic = "\001text", .magicsize = 5, .header = ogm_header, - .packet = ogm_packet + .packet = ogm_packet, + .granule_is_start = 1, }; const struct ogg_codec ff_ogm_old_codec = { .magic = "\001Direct Show Samples embedded in Ogg", .magicsize = 35, .header = ogm_dshow_header, - .packet = ogm_packet + .packet = ogm_packet, + .granule_is_start = 1, }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/oggparseskeleton.c b/src/add-ons/media/plugins/ffmpeg/libavformat/oggparseskeleton.c new file mode 100644 index 0000000000..ad0dded0d7 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/oggparseskeleton.c @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2010 David Conrad + * + * 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 "libavcodec/bytestream.h" +#include "avformat.h" +#include "oggdec.h" + +static int skeleton_header(AVFormatContext *s, int idx) +{ + struct ogg *ogg = s->priv_data; + struct ogg_stream *os = ogg->streams + idx; + AVStream *st = s->streams[idx]; + uint8_t *buf = os->buf + os->pstart; + int version_major, version_minor; + int64_t start_num, start_den, start_granule; + int target_idx, start_time; + + strcpy(st->codec->codec_name, "skeleton"); + st->codec->codec_type = AVMEDIA_TYPE_DATA; + + if (os->psize < 8) + return -1; + + if (!strncmp(buf, "fishead", 8)) { + if (os->psize < 64) + return -1; + + version_major = AV_RL16(buf+8); + version_minor = AV_RL16(buf+10); + + if (version_major != 3) { + av_log(s, AV_LOG_WARNING, "Unknown skeleton version %d.%d\n", + version_major, version_minor); + return -1; + } + + // This is the overall start time. We use it for the start time of + // of the skeleton stream since if left unset lavf assumes 0, + // which we don't want since skeleton is timeless + // FIXME: the real meaning of this field is "start playback at + // this time which can be in the middle of a packet + start_num = AV_RL64(buf+12); + start_den = AV_RL64(buf+20); + + if (start_den) { + av_reduce(&start_time, &st->time_base.den, start_num, start_den, INT_MAX); + st->time_base.num = 1; + os->lastpts = + st->start_time = start_time; + } + } else if (!strncmp(buf, "fisbone", 8)) { + if (os->psize < 52) + return -1; + + target_idx = ogg_find_stream(ogg, AV_RL32(buf+12)); + start_granule = AV_RL64(buf+36); + if (target_idx >= 0 && start_granule != -1) { + ogg->streams[target_idx].lastpts = + s->streams[target_idx]->start_time = ogg_gptopts(s, target_idx, start_granule, NULL); + } + } + + return 1; +} + +const struct ogg_codec ff_skeleton_codec = { + .magic = "fishead", + .magicsize = 8, + .header = skeleton_header, +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/oggparsespeex.c b/src/add-ons/media/plugins/ffmpeg/libavformat/oggparsespeex.c index 140a58a9eb..936b37e952 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/oggparsespeex.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/oggparsespeex.c @@ -30,22 +30,43 @@ #include "avformat.h" #include "oggdec.h" +struct speex_params { + int final_packet_duration; + int seq; +}; + static int speex_header(AVFormatContext *s, int idx) { struct ogg *ogg = s->priv_data; struct ogg_stream *os = ogg->streams + idx; + struct speex_params *spxp = os->private; AVStream *st = s->streams[idx]; uint8_t *p = os->buf + os->pstart; - if (os->seq > 1) + if (!spxp) { + spxp = av_mallocz(sizeof(*spxp)); + os->private = spxp; + } + + if (spxp->seq > 1) return 0; - if (os->seq == 0) { - st->codec->codec_type = CODEC_TYPE_AUDIO; + if (spxp->seq == 0) { + int frames_per_packet; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_SPEEX; 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 FFmpeg. 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); + if (frames_per_packet) + st->codec->frame_size *= frames_per_packet; + st->codec->extradata_size = os->psize; st->codec->extradata = av_malloc(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); @@ -54,13 +75,54 @@ static int speex_header(AVFormatContext *s, int idx) { st->time_base.num = 1; st->time_base.den = st->codec->sample_rate; } else - vorbis_comment(s, p, os->psize); + ff_vorbis_comment(s, &st->metadata, p, os->psize); + spxp->seq++; return 1; } +static int ogg_page_packets(struct ogg_stream *os) +{ + int i; + int packets = 0; + for (i = 0; i < os->nsegs; i++) + if (os->segments[i] < 255) + packets++; + return packets; +} + +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; + + if (os->flags & OGG_FLAG_EOS && os->lastpts != AV_NOPTS_VALUE && + os->granule > 0) { + /* first packet of final page. we have to calculate the final packet + duration here because it is the only place we know the next-to-last + granule position. */ + spxp->final_packet_duration = os->granule - os->lastpts - + packet_size * (ogg_page_packets(os) - 1); + } + + 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) + /* final packet */ + os->pduration = spxp->final_packet_duration; + else + os->pduration = packet_size; + + return 0; +} + const struct ogg_codec ff_speex_codec = { .magic = "Speex ", .magicsize = 8, - .header = speex_header + .header = speex_header, + .packet = speex_packet }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/oggparsetheora.c b/src/add-ons/media/plugins/ffmpeg/libavformat/oggparsetheora.c index 0d74116d17..2299f5507c 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/oggparsetheora.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/oggparsetheora.c @@ -104,11 +104,12 @@ theora_header (AVFormatContext * s, int idx) thp->gpshift = get_bits(&gb, 5); thp->gpmask = (1 << thp->gpshift) - 1; - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_THEORA; + st->need_parsing = AVSTREAM_PARSE_HEADERS; } else if (os->buf[os->pstart] == 0x83) { - vorbis_comment (s, os->buf + os->pstart + 7, os->psize - 8); + ff_vorbis_comment (s, &st->metadata, os->buf + os->pstart + 7, os->psize - 8); } st->codec->extradata = av_realloc (st->codec->extradata, @@ -123,7 +124,7 @@ theora_header (AVFormatContext * s, int idx) } static uint64_t -theora_gptopts(AVFormatContext *ctx, int idx, uint64_t gp) +theora_gptopts(AVFormatContext *ctx, int idx, uint64_t gp, int64_t *dts) { struct ogg *ogg = ctx->priv_data; struct ogg_stream *os = ogg->streams + idx; @@ -135,7 +136,10 @@ theora_gptopts(AVFormatContext *ctx, int idx, uint64_t gp) iframe++; if(!pframe) - os->pflags |= PKT_FLAG_KEY; + os->pflags |= AV_PKT_FLAG_KEY; + + if (dts) + *dts = iframe + pframe; return iframe + pframe; } diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/oggparsevorbis.c b/src/add-ons/media/plugins/ffmpeg/libavformat/oggparsevorbis.c index 5b45631ab6..886ef522b5 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/oggparsevorbis.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/oggparsevorbis.c @@ -30,47 +30,67 @@ #include "avformat.h" #include "oggdec.h" -/** - * VorbisComment metadata conversion mapping. - * from Ogg Vorbis I format specification: comment field and header specification - * http://xiph.org/vorbis/doc/v-comment.html - */ -const AVMetadataConv ff_vorbiscomment_metadata_conv[] = { - { "ARTIST" , "author" }, - { "TITLE" , "title" }, - { "ALBUM" , "album" }, - { "DATE" , "year" }, - { "TRACKNUMBER", "track" }, - { "GENRE" , "genre" }, - { 0 } -}; +static int ogm_chapter(AVFormatContext *as, uint8_t *key, uint8_t *val) +{ + int i, cnum, h, m, s, ms, keylen = strlen(key); + AVChapter *chapter = NULL; + + if (keylen < 9 || sscanf(key, "CHAPTER%02d", &cnum) != 1) + return 0; + + if (keylen == 9) { + if (sscanf(val, "%02d:%02d:%02d.%03d", &h, &m, &s, &ms) < 4) + return 0; + + ff_new_chapter(as, cnum, (AVRational){1,1000}, + ms + 1000*(s + 60*(m + 60*h)), + AV_NOPTS_VALUE, NULL); + av_free(val); + } else if (!strcmp(key+9, "NAME")) { + for(i = 0; i < as->nb_chapters; i++) + if (as->chapters[i]->id == cnum) { + chapter = as->chapters[i]; + break; + } + if (!chapter) + return 0; + + av_metadata_set2(&chapter->metadata, "title", val, + AV_METADATA_DONT_STRDUP_VAL); + } else + return 0; + + av_free(key); + return 1; +} int -vorbis_comment(AVFormatContext * as, uint8_t *buf, int size) +ff_vorbis_comment(AVFormatContext * as, AVMetadata **m, const uint8_t *buf, int size) { const uint8_t *p = buf; const uint8_t *end = buf + size; - unsigned s, n, j; + unsigned n, j; + int s; if (size < 8) /* must have vendor_length and user_comment_list_length */ return -1; s = bytestream_get_le32(&p); - if (end - p < s) + if (end - p - 4 < s || s < 0) return -1; p += s; n = bytestream_get_le32(&p); - while (p < end && n > 0) { + while (end - p >= 4 && n > 0) { const char *t, *v; int tl, vl; s = bytestream_get_le32(&p); - if (end - p < s) + if (end - p < s || s < 0) break; t = p; @@ -104,15 +124,15 @@ vorbis_comment(AVFormatContext * as, uint8_t *buf, int size) memcpy(ct, v, vl); ct[vl] = 0; - av_metadata_set(&as->metadata, tt, ct); - - av_freep(&tt); - av_freep(&ct); + if (!ogm_chapter(as, tt, ct)) + av_metadata_set2(m, tt, ct, + AV_METADATA_DONT_STRDUP_KEY | + AV_METADATA_DONT_STRDUP_VAL); } } if (p != end) - av_log(as, AV_LOG_INFO, "%ti bytes of comment header remain\n", p-end); + av_log(as, AV_LOG_INFO, "%ti bytes of comment header remain\n", end-p); if (n > 0) av_log(as, AV_LOG_INFO, "truncated comment header, %i comments not found\n", n); @@ -157,6 +177,7 @@ fixup_vorbis_headers(AVFormatContext * as, struct oggvorbis_private *priv, for (i = 0; i < 3; i++) { memcpy(&ptr[offset], priv->packet[i], priv->len[i]); offset += priv->len[i]; + av_freep(&priv->packet[i]); } *buf = av_realloc(*buf, offset + FF_INPUT_BUFFER_PADDING_SIZE); return offset; @@ -170,23 +191,24 @@ vorbis_header (AVFormatContext * s, int idx) struct ogg_stream *os = ogg->streams + idx; AVStream *st = s->streams[idx]; struct oggvorbis_private *priv; + int pkt_type = os->buf[os->pstart]; - if (os->seq > 2) + if (!(pkt_type & 1)) return 0; - if (os->seq == 0) { + if (!os->private) { os->private = av_mallocz(sizeof(struct oggvorbis_private)); if (!os->private) return 0; } - if (os->psize < 1) + if (os->psize < 1 || pkt_type > 5) return -1; priv = os->private; - priv->len[os->seq] = os->psize; - priv->packet[os->seq] = av_mallocz(os->psize); - memcpy(priv->packet[os->seq], os->buf + os->pstart, os->psize); + priv->len[pkt_type >> 1] = os->psize; + priv->packet[pkt_type >> 1] = av_mallocz(os->psize); + memcpy(priv->packet[pkt_type >> 1], os->buf + os->pstart, os->psize); if (os->buf[os->pstart] == 1) { const uint8_t *p = os->buf + os->pstart + 7; /* skip "\001vorbis" tag */ unsigned blocksize, bs0, bs1; @@ -215,20 +237,20 @@ vorbis_header (AVFormatContext * s, int idx) if (bytestream_get_byte(&p) != 1) /* framing_flag */ return -1; - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_VORBIS; st->time_base.num = 1; st->time_base.den = st->codec->sample_rate; } else if (os->buf[os->pstart] == 3) { if (os->psize > 8) - vorbis_comment (s, os->buf + os->pstart + 7, os->psize - 8); + ff_vorbis_comment (s, &st->metadata, os->buf + os->pstart + 7, os->psize - 8); } else { st->codec->extradata_size = fixup_vorbis_headers(s, priv, &st->codec->extradata); } - return os->seq < 3; + return 1; } const struct ogg_codec ff_vorbis_codec = { diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/oma.c b/src/add-ons/media/plugins/ffmpeg/libavformat/oma.c index cc512cae76..c12365e10c 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/oma.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/oma.c @@ -22,7 +22,7 @@ */ /** - * @file libavformat/oma.c + * @file * This is a demuxer for Sony OpenMG Music files * * Known file extensions: ".oma", "aa3" @@ -78,16 +78,21 @@ static int oma_read_header(AVFormatContext *s, if (ret != 10) return -1; - ea3_taglen = ((buf[6] & 0x7f) << 21) | ((buf[7] & 0x7f) << 14) | ((buf[8] & 0x7f) << 7) | (buf[9] & 0x7f); + if(!memcmp(buf, "ea3", 3)) { + ea3_taglen = ((buf[6] & 0x7f) << 21) | ((buf[7] & 0x7f) << 14) | ((buf[8] & 0x7f) << 7) | (buf[9] & 0x7f); - EA3_pos = ea3_taglen + 10; - if (buf[5] & 0x10) - EA3_pos += 10; + EA3_pos = ea3_taglen + 10; + if (buf[5] & 0x10) + EA3_pos += 10; - url_fseek(s->pb, EA3_pos, SEEK_SET); - ret = get_buffer(s->pb, buf, EA3_HEADER_SIZE); - if (ret != EA3_HEADER_SIZE) - return -1; + url_fseek(s->pb, EA3_pos, SEEK_SET); + ret = get_buffer(s->pb, buf, EA3_HEADER_SIZE); + if (ret != EA3_HEADER_SIZE) + return -1; + } else { + ret = get_buffer(s->pb, buf + 10, EA3_HEADER_SIZE - 10); + EA3_pos = 0; + } if (memcmp(buf, ((const uint8_t[]){'E', 'A', '3'}),3) || buf[4] != 0 || buf[5] != EA3_HEADER_SIZE) { av_log(s, AV_LOG_ERROR, "Couldn't find the EA3 header !\n"); @@ -107,7 +112,7 @@ static int oma_read_header(AVFormatContext *s, return AVERROR(ENOMEM); st->start_time = 0; - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_tag = buf[32]; st->codec->codec_id = ff_codec_get_id(codec_oma_tags, st->codec->codec_tag); @@ -177,7 +182,9 @@ static int oma_read_packet(AVFormatContext *s, AVPacket *pkt) static int oma_read_probe(AVProbeData *p) { - if (!memcmp(p->buf, ((const uint8_t[]){'e', 'a', '3', 3, 0}),5)) + if (!memcmp(p->buf, ((const uint8_t[]){'e', 'a', '3', 3, 0}), 5) || + (!memcmp(p->buf, "EA3", 3) && + !p->buf[4] && p->buf[5] == EA3_HEADER_SIZE)) return AVPROBE_SCORE_MAX; else return 0; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/options.c b/src/add-ons/media/plugins/ffmpeg/libavformat/options.c index 795d02b73d..0c1ac2d866 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/options.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/options.c @@ -21,7 +21,7 @@ #include "libavcodec/opt.h" /** - * @file libavformat/options.c + * @file * Options definition for AVFormatContext. */ @@ -46,11 +46,15 @@ static const AVOption options[]={ {"fflags", NULL, OFFSET(flags), FF_OPT_TYPE_FLAGS, DEFAULT, INT_MIN, INT_MAX, D|E, "fflags"}, {"ignidx", "ignore index", 0, FF_OPT_TYPE_CONST, AVFMT_FLAG_IGNIDX, INT_MIN, INT_MAX, D, "fflags"}, {"genpts", "generate pts", 0, FF_OPT_TYPE_CONST, 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, AVFMT_FLAG_NOFILLIN, INT_MIN, INT_MAX, D, "fflags"}, +{"noparse", "disable AVParsers, this needs nofillin too", 0, FF_OPT_TYPE_CONST, AVFMT_FLAG_NOPARSE, INT_MIN, INT_MAX, D, "fflags"}, +{"igndts", "ingore dts", 0, FF_OPT_TYPE_CONST, AVFMT_FLAG_IGNDTS, INT_MIN, INT_MAX, D, "fflags"}, +{"rtphint", "add rtp hinting", 0, FF_OPT_TYPE_CONST, AVFMT_FLAG_RTP_HINT, INT_MIN, INT_MAX, E, "fflags"}, #if LIBAVFORMAT_VERSION_INT < (53<<16) {"track", " set the track number", OFFSET(track), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, E}, {"year", "set the year", OFFSET(year), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, E}, #endif -{"analyzeduration", "how many microseconds are analyzed to estimate duration", OFFSET(max_analyze_duration), FF_OPT_TYPE_INT, 3*AV_TIME_BASE, 0, INT_MAX, D}, +{"analyzeduration", "how many microseconds are analyzed to estimate duration", OFFSET(max_analyze_duration), FF_OPT_TYPE_INT, 5*AV_TIME_BASE, 0, INT_MAX, D}, {"cryptokey", "decryption key", OFFSET(key), FF_OPT_TYPE_BINARY, 0, 0, 0, D}, {"indexmem", "max memory used for timestamp index (per stream)", OFFSET(max_index_size), FF_OPT_TYPE_INT, 1<<20, 0, INT_MAX, D}, {"rtbufsize", "max memory used for buffering real-time frames", OFFSET(max_picture_buffer), FF_OPT_TYPE_INT, 3041280, 0, INT_MAX, D}, /* defaults to 1s of 15fps 352x288 YUYV422 video */ @@ -63,7 +67,7 @@ static const AVOption options[]={ #undef D #undef DEFAULT -static const AVClass av_format_context_class = { "AVFormatContext", format_to_name, options }; +static const AVClass av_format_context_class = { "AVFormatContext", format_to_name, options, LIBAVUTIL_VERSION_INT }; static void avformat_get_context_defaults(AVFormatContext *s) { diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/os_support.c b/src/add-ons/media/plugins/ffmpeg/libavformat/os_support.c index 6763e39cf9..27863031d1 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/os_support.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/os_support.c @@ -22,6 +22,7 @@ /* needed by inet_aton() */ #define _SVID_SOURCE +#define _DARWIN_C_SOURCE #include "config.h" #include "avformat.h" @@ -45,7 +46,7 @@ #include #include -int inet_aton (const char * str, struct in_addr * add) +int ff_inet_aton (const char * str, struct in_addr * add) { unsigned int add1 = 0, add2 = 0, add3 = 0, add4 = 0; @@ -54,26 +55,174 @@ int inet_aton (const char * str, struct in_addr * add) if (!add1 || (add1|add2|add3|add4) > 255) return 0; - add->s_addr=(add4<<24)+(add3<<16)+(add2<<8)+add1; + add->s_addr = htonl((add1 << 24) + (add2 << 16) + (add3 << 8) + add4); return 1; } +#else +int ff_inet_aton (const char * str, struct in_addr * add) +{ + return inet_aton(str, add); +} #endif /* !HAVE_INET_ATON */ -/* resolve host with also IP address parsing */ -int resolve_host(struct in_addr *sin_addr, const char *hostname) +#if !HAVE_GETADDRINFO +int ff_getaddrinfo(const char *node, const char *service, + const struct addrinfo *hints, struct addrinfo **res) { - struct hostent *hp; + struct hostent *h = NULL; + struct addrinfo *ai; + struct sockaddr_in *sin; - if (!inet_aton(hostname, sin_addr)) { - hp = gethostbyname(hostname); - if (!hp) - return -1; - memcpy(sin_addr, hp->h_addr_list[0], sizeof(struct in_addr)); +#if HAVE_WINSOCK2_H + int (WSAAPI *win_getaddrinfo)(const char *node, const char *service, + const struct addrinfo *hints, + struct addrinfo **res); + HMODULE ws2mod = GetModuleHandle("ws2_32.dll"); + win_getaddrinfo = GetProcAddress(ws2mod, "getaddrinfo"); + if (win_getaddrinfo) + return win_getaddrinfo(node, service, hints, res); +#endif + + *res = NULL; + sin = av_mallocz(sizeof(struct sockaddr_in)); + if (!sin) + return EAI_FAIL; + sin->sin_family = AF_INET; + + if (node) { + if (!ff_inet_aton(node, &sin->sin_addr)) { + if (hints && (hints->ai_flags & AI_NUMERICHOST)) { + av_free(sin); + return EAI_FAIL; + } + h = gethostbyname(node); + if (!h) { + av_free(sin); + return EAI_FAIL; + } + memcpy(&sin->sin_addr, h->h_addr_list[0], sizeof(struct in_addr)); + } + } else { + if (hints && (hints->ai_flags & AI_PASSIVE)) { + sin->sin_addr.s_addr = INADDR_ANY; + } else + sin->sin_addr.s_addr = INADDR_LOOPBACK; } + + /* Note: getaddrinfo allows service to be a string, which + * should be looked up using getservbyname. */ + if (service) + sin->sin_port = htons(atoi(service)); + + ai = av_mallocz(sizeof(struct addrinfo)); + if (!ai) { + av_free(sin); + return EAI_FAIL; + } + + *res = ai; + ai->ai_family = AF_INET; + ai->ai_socktype = hints ? hints->ai_socktype : 0; + switch (ai->ai_socktype) { + case SOCK_STREAM: ai->ai_protocol = IPPROTO_TCP; break; + case SOCK_DGRAM: ai->ai_protocol = IPPROTO_UDP; break; + default: ai->ai_protocol = 0; break; + } + + ai->ai_addr = (struct sockaddr *)sin; + ai->ai_addrlen = sizeof(struct sockaddr_in); + if (hints && (hints->ai_flags & AI_CANONNAME)) + ai->ai_canonname = h ? av_strdup(h->h_name) : NULL; + + ai->ai_next = NULL; return 0; } +void ff_freeaddrinfo(struct addrinfo *res) +{ +#if HAVE_WINSOCK2_H + void (WSAAPI *win_freeaddrinfo)(struct addrinfo *res); + HMODULE ws2mod = GetModuleHandle("ws2_32.dll"); + win_freeaddrinfo = (void (WSAAPI *)(struct addrinfo *res)) + GetProcAddress(ws2mod, "freeaddrinfo"); + if (win_freeaddrinfo) { + win_freeaddrinfo(res); + return; + } +#endif + + av_free(res->ai_canonname); + av_free(res->ai_addr); + av_free(res); +} + +int ff_getnameinfo(const struct sockaddr *sa, int salen, + char *host, int hostlen, + char *serv, int servlen, int flags) +{ + const struct sockaddr_in *sin = (const struct sockaddr_in *)sa; + +#if HAVE_WINSOCK2_H + int (WSAAPI *win_getnameinfo)(const struct sockaddr *sa, socklen_t salen, + char *host, DWORD hostlen, + char *serv, DWORD servlen, int flags); + HMODULE ws2mod = GetModuleHandle("ws2_32.dll"); + win_getnameinfo = GetProcAddress(ws2mod, "getnameinfo"); + if (win_getnameinfo) + return win_getnameinfo(sa, salen, host, hostlen, serv, servlen, flags); +#endif + + if (sa->sa_family != AF_INET) + return EAI_FAMILY; + if (!host && !serv) + return EAI_NONAME; + + if (host && hostlen > 0) { + struct hostent *ent = NULL; + uint32_t a; + if (!(flags & NI_NUMERICHOST)) + ent = gethostbyaddr((const char *)&sin->sin_addr, + sizeof(sin->sin_addr), AF_INET); + + if (ent) { + snprintf(host, hostlen, "%s", ent->h_name); + } else if (flags & NI_NAMERQD) { + return EAI_NONAME; + } else { + a = ntohl(sin->sin_addr.s_addr); + snprintf(host, hostlen, "%d.%d.%d.%d", + ((a >> 24) & 0xff), ((a >> 16) & 0xff), + ((a >> 8) & 0xff), ( a & 0xff)); + } + } + + if (serv && servlen > 0) { + struct servent *ent = NULL; + if (!(flags & NI_NUMERICSERV)) + ent = getservbyport(sin->sin_port, flags & NI_DGRAM ? "udp" : "tcp"); + + if (ent) { + snprintf(serv, servlen, "%s", ent->s_name); + } else + snprintf(serv, servlen, "%d", ntohs(sin->sin_port)); + } + + return 0; +} + +const char *ff_gai_strerror(int ecode) +{ + switch(ecode) { + case EAI_FAIL : return "A non-recoverable error occurred"; + case EAI_FAMILY : return "The address family was not recognized or the address length was invalid for the specified family"; + case EAI_NONAME : return "The name does not resolve for the supplied parameters"; + } + + return "Unknown error"; +} +#endif + int ff_socket_nonblock(int socket, int enable) { #if HAVE_WINSOCK2_H diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/os_support.h b/src/add-ons/media/plugins/ffmpeg/libavformat/os_support.h index d4603632f7..e90f2c244f 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/os_support.h +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/os_support.h @@ -23,7 +23,7 @@ #define AVFORMAT_OS_SUPPORT_H /** - * @file libavformat/os_support.h + * @file * miscellaneous OS support macros and functions. */ @@ -32,7 +32,7 @@ #if defined(__MINGW32__) && !defined(__MINGW32CE__) # include # define lseek(f,p,w) _lseeki64((f), (p), (w)) -#endif +#endif /* defined(__MINGW32__) && !defined(__MINGW32CE__) */ static inline int is_dos_path(const char *path) { diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/output-example.c b/src/add-ons/media/plugins/ffmpeg/libavformat/output-example.c index 17c97f79db..dd61cfe088 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/output-example.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/output-example.c @@ -27,10 +27,6 @@ #include #include -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - #include "libavformat/avformat.h" #include "libswscale/swscale.h" @@ -69,12 +65,17 @@ static AVStream *add_audio_stream(AVFormatContext *oc, enum CodecID codec_id) c = st->codec; c->codec_id = codec_id; - c->codec_type = CODEC_TYPE_AUDIO; + c->codec_type = AVMEDIA_TYPE_AUDIO; /* put sample parameters */ c->bit_rate = 64000; c->sample_rate = 44100; c->channels = 2; + + // some formats want stream headers to be separate + if(oc->oformat->flags & AVFMT_GLOBALHEADER) + c->flags |= CODEC_FLAG_GLOBAL_HEADER; + return st; } @@ -156,9 +157,9 @@ static void write_audio_frame(AVFormatContext *oc, AVStream *st) pkt.size= avcodec_encode_audio(c, audio_outbuf, audio_outbuf_size, samples); - if (c->coded_frame->pts != AV_NOPTS_VALUE) + 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 |= PKT_FLAG_KEY; + pkt.flags |= AV_PKT_FLAG_KEY; pkt.stream_index= st->index; pkt.data= audio_outbuf; @@ -198,7 +199,7 @@ static AVStream *add_video_stream(AVFormatContext *oc, enum CodecID codec_id) c = st->codec; c->codec_id = codec_id; - c->codec_type = CODEC_TYPE_VIDEO; + c->codec_type = AVMEDIA_TYPE_VIDEO; /* put sample parameters */ c->bit_rate = 400000; @@ -367,7 +368,7 @@ static void write_video_frame(AVFormatContext *oc, AVStream *st) AVPacket pkt; av_init_packet(&pkt); - pkt.flags |= PKT_FLAG_KEY; + pkt.flags |= AV_PKT_FLAG_KEY; pkt.stream_index= st->index; pkt.data= (uint8_t *)picture; pkt.size= sizeof(AVPicture); @@ -384,7 +385,7 @@ static void write_video_frame(AVFormatContext *oc, AVStream *st) if (c->coded_frame->pts != AV_NOPTS_VALUE) pkt.pts= av_rescale_q(c->coded_frame->pts, c->time_base, st->time_base); if(c->coded_frame->key_frame) - pkt.flags |= PKT_FLAG_KEY; + pkt.flags |= AV_PKT_FLAG_KEY; pkt.stream_index= st->index; pkt.data= video_outbuf; pkt.size= out_size; @@ -442,10 +443,10 @@ int main(int argc, char **argv) /* auto detect the output format from the name. default is mpeg. */ - fmt = guess_format(NULL, filename, NULL); + fmt = av_guess_format(NULL, filename, NULL); if (!fmt) { printf("Could not deduce output format from file extension: using MPEG.\n"); - fmt = guess_format("mpeg", NULL, NULL); + fmt = av_guess_format("mpeg", NULL, NULL); } if (!fmt) { fprintf(stderr, "Could not find suitable output format\n"); diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/psxstr.c b/src/add-ons/media/plugins/ffmpeg/libavformat/psxstr.c index f5fea95cd6..347c26e401 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/psxstr.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/psxstr.c @@ -20,7 +20,7 @@ */ /** - * @file libavformat/psxstr.c + * @file * PSX STR file demuxer * by Mike Melanson (melanson@pcisys.net) * This module handles streams that have been ripped from Sony Playstation @@ -169,7 +169,7 @@ static int str_read_packet(AVFormatContext *s, str->channels[channel].video_stream_index = st->index; - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_MDEC; st->codec->codec_tag = 0; /* no fourcc */ st->codec->width = AV_RL16(§or[0x28]); @@ -216,7 +216,7 @@ static int str_read_packet(AVFormatContext *s, str->channels[channel].audio_stream_index = st->index; - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_ADPCM_XA; st->codec->codec_tag = 0; /* no fourcc */ st->codec->channels = (fmt&1)?2:1; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/pva.c b/src/add-ons/media/plugins/ffmpeg/libavformat/pva.c index 4255f8a71c..abbc6f1c60 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/pva.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/pva.c @@ -45,7 +45,7 @@ static int pva_read_header(AVFormatContext *s, AVFormatParameters *ap) { if (!(st = av_new_stream(s, 0))) return AVERROR(ENOMEM); - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_MPEG2VIDEO; st->need_parsing = AVSTREAM_PARSE_FULL; av_set_pts_info(st, 32, 1, 90000); @@ -53,7 +53,7 @@ static int pva_read_header(AVFormatContext *s, AVFormatParameters *ap) { if (!(st = av_new_stream(s, 1))) return AVERROR(ENOMEM); - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_MP2; st->need_parsing = AVSTREAM_PARSE_FULL; av_set_pts_info(st, 33, 1, 90000); diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/qcp.c b/src/add-ons/media/plugins/ffmpeg/libavformat/qcp.c index 2aadb2d79b..676e9c7c57 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/qcp.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/qcp.c @@ -20,7 +20,7 @@ */ /** - * @file libavformat/qcp.c + * @file * QCP format (.qcp) demuxer * @author Kenan Gillet * @sa RFC 3625: "The QCP File Format and Media Types for Speech Data" @@ -95,7 +95,7 @@ static int qcp_read_header(AVFormatContext *s, AVFormatParameters *ap) s->file_size = get_le32(pb) + 8; url_fskip(pb, 8 + 4 + 1 + 1); // "QLCMfmt " + chunk-size + major-version + minor-version - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->channels = 1; get_buffer(pb, buf, 16); if (is_qcelp_13k_guid(buf)) { diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/r3d.c b/src/add-ons/media/plugins/ffmpeg/libavformat/r3d.c index b645d928a0..556a32b20e 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/r3d.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/r3d.c @@ -55,8 +55,8 @@ static int r3d_read_red1(AVFormatContext *s) int tmp, tmp2; if (!st) - return -1; - st->codec->codec_type = CODEC_TYPE_VIDEO; + return AVERROR(ENOMEM); + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_JPEG2000; tmp = get_byte(s->pb); // major version @@ -87,7 +87,9 @@ static int r3d_read_red1(AVFormatContext *s) dprintf(s, "audio channels %d\n", tmp); if (tmp > 0) { AVStream *ast = av_new_stream(s, 1); - ast->codec->codec_type = CODEC_TYPE_AUDIO; + if (!ast) + return AVERROR(ENOMEM); + ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; ast->codec->codec_id = CODEC_ID_PCM_S32BE; ast->codec->channels = tmp; av_set_pts_info(ast, 32, 1, st->time_base.den); @@ -95,7 +97,7 @@ static int r3d_read_red1(AVFormatContext *s) get_buffer(s->pb, filename, 257); filename[sizeof(filename)-1] = 0; - av_metadata_set(&st->metadata, "filename", filename); + av_metadata_set2(&st->metadata, "filename", filename, 0); dprintf(s, "filename %s\n", filename); dprintf(s, "resolution %dx%d\n", st->codec->width, st->codec->height); @@ -210,6 +212,7 @@ static int r3d_read_redv(AVFormatContext *s, AVPacket *pkt, Atom *atom) int tmp, tmp2; uint64_t pos = url_ftell(s->pb); unsigned dts; + int ret; dts = get_be32(s->pb); @@ -241,8 +244,8 @@ static int r3d_read_redv(AVFormatContext *s, AVPacket *pkt, Atom *atom) tmp = atom->size - 8 - (url_ftell(s->pb) - pos); if (tmp < 0) return -1; - - if (av_get_packet(s->pb, pkt, tmp) != tmp) { + ret = av_get_packet(s->pb, pkt, tmp); + if (ret < 0) { av_log(s, AV_LOG_ERROR, "error reading video packet\n"); return -1; } @@ -263,6 +266,7 @@ static int r3d_read_reda(AVFormatContext *s, AVPacket *pkt, Atom *atom) int tmp, tmp2, samples, size; uint64_t pos = url_ftell(s->pb); unsigned dts; + int ret; dts = get_be32(s->pb); @@ -286,9 +290,10 @@ static int r3d_read_reda(AVFormatContext *s, AVPacket *pkt, Atom *atom) size = atom->size - 8 - (url_ftell(s->pb) - pos); if (size < 0) return -1; - if (av_get_packet(s->pb, pkt, size) != size) { - av_log(s, AV_LOG_ERROR, "error reading video packet\n"); - return -1; + ret = av_get_packet(s->pb, pkt, size); + if (ret < 0) { + av_log(s, AV_LOG_ERROR, "error reading audio packet\n"); + return ret; } pkt->stream_index = 1; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/raw.c b/src/add-ons/media/plugins/ffmpeg/libavformat/raw.c index 9c109eaac9..7837de842a 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/raw.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/raw.c @@ -66,7 +66,7 @@ static int raw_write_packet(struct AVFormatContext *s, AVPacket *pkt) static int raw_read_header(AVFormatContext *s, AVFormatParameters *ap) { AVStream *st; - int id; + enum CodecID id; st = av_new_stream(s, 0); if (!st) @@ -74,14 +74,14 @@ static int raw_read_header(AVFormatContext *s, AVFormatParameters *ap) id = s->iformat->value; if (id == CODEC_ID_RAWVIDEO) { - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; } else { - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; } st->codec->codec_id = id; switch(st->codec->codec_type) { - case CODEC_TYPE_AUDIO: + case AVMEDIA_TYPE_AUDIO: st->codec->sample_rate = ap->sample_rate; if(ap->channels) st->codec->channels = ap->channels; else st->codec->channels = 1; @@ -90,7 +90,7 @@ static int raw_read_header(AVFormatContext *s, AVFormatParameters *ap) st->codec->block_align = st->codec->bits_per_coded_sample*st->codec->channels/8; av_set_pts_info(st, 64, 1, st->codec->sample_rate); break; - case CODEC_TYPE_VIDEO: + case AVMEDIA_TYPE_VIDEO: if(ap->time_base.num) av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den); else @@ -120,12 +120,8 @@ static int raw_read_packet(AVFormatContext *s, AVPacket *pkt) ret= av_get_packet(s->pb, pkt, size); pkt->stream_index = 0; - if (ret <= 0) { - return AVERROR(EIO); - } - /* note: we need to modify the packet size here to handle the last - packet */ - pkt->size = ret; + if (ret < 0) + return ret; bps= av_get_bits_per_sample(s->streams[0]->codec->codec_id); assert(bps); // if false there IS a bug elsewhere (NOT in this function) @@ -142,14 +138,14 @@ int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt) size = RAW_PACKET_SIZE; if (av_new_packet(pkt, size) < 0) - return AVERROR(EIO); + return AVERROR(ENOMEM); pkt->pos= url_ftell(s->pb); pkt->stream_index = 0; ret = get_partial_buffer(s->pb, pkt->data, size); - if (ret <= 0) { + if (ret < 0) { av_free_packet(pkt); - return AVERROR(EIO); + return ret; } pkt->size = ret; return ret; @@ -174,11 +170,9 @@ static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt) pkt->dts= pkt->pos / packet_size; pkt->stream_index = 0; - if (ret != packet_size) { - return AVERROR(EIO); - } else { - return 0; - } + if (ret < 0) + return ret; + return 0; } #endif @@ -206,14 +200,14 @@ static int ingenient_read_packet(AVFormatContext *s, AVPacket *pkt) size, w, h, unk1, unk2); if (av_new_packet(pkt, size) < 0) - return AVERROR(EIO); + return AVERROR(ENOMEM); pkt->pos = url_ftell(s->pb); pkt->stream_index = 0; ret = get_buffer(s->pb, pkt->data, size); - if (ret <= 0) { + if (ret < 0) { av_free_packet(pkt); - return AVERROR(EIO); + return ret; } pkt->size = ret; return ret; @@ -225,8 +219,8 @@ int pcm_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) { AVStream *st; - int block_align, byte_rate, ret; - int64_t pos; + int block_align, byte_rate; + int64_t pos, ret; st = s->streams[0]; @@ -259,7 +253,7 @@ static int audio_read_header(AVFormatContext *s, AVStream *st = av_new_stream(s, 0); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = s->iformat->value; st->need_parsing = AVSTREAM_PARSE_FULL; /* the parameters will be extracted from the compressed bitstream */ @@ -277,7 +271,7 @@ static int video_read_header(AVFormatContext *s, if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = s->iformat->value; st->need_parsing = AVSTREAM_PARSE_FULL; @@ -288,6 +282,7 @@ static int video_read_header(AVFormatContext *s, } else if ( st->codec->codec_id == CODEC_ID_MJPEG || st->codec->codec_id == CODEC_ID_MPEG4 || st->codec->codec_id == CODEC_ID_DIRAC || + st->codec->codec_id == CODEC_ID_DNXHD || st->codec->codec_id == CODEC_ID_H264) { st->codec->time_base= (AVRational){1,25}; } @@ -326,7 +321,7 @@ static int mpegvideo_probe(AVProbeData *p) } } if(seq && seq*9<=pic*10 && pic*9<=slice*10 && !pspack && !pes) - return AVPROBE_SCORE_MAX/2+1; // +1 for .mpg + return pic>1 ? AVPROBE_SCORE_MAX/2+1 : AVPROBE_SCORE_MAX/4; // +1 for .mpg return 0; } #endif @@ -455,14 +450,35 @@ static int h264_probe(AVProbeData *p) #if CONFIG_H263_DEMUXER static int h263_probe(AVProbeData *p) { - int code; - const uint8_t *d; + uint64_t code= -1; + int i; + int valid_psc=0; + int invalid_psc=0; + int res_change=0; + int src_fmt, last_src_fmt=-1; - d = p->buf; - code = (d[0] << 14) | (d[1] << 6) | (d[2] >> 2); - if (code == 0x20) { - return 50; + for(i=0; ibuf_size; i++){ + code = (code<<8) + p->buf[i]; + if ((code & 0xfffffc0000) == 0x800000) { + src_fmt= (code>>2)&3; + if( src_fmt != last_src_fmt + && last_src_fmt>0 && last_src_fmt<6 + && src_fmt<6) + res_change++; + + if((code&0x300)==0x200 && src_fmt){ + valid_psc++; + }else + invalid_psc++; + last_src_fmt= src_fmt; + } } +//av_log(NULL, AV_LOG_ERROR, "h263_probe: psc:%d invalid:%d res_change:%d\n", valid_psc, invalid_psc, res_change); +//h263_probe: psc:3 invalid:0 res_change:0 (1588/recent_ffmpeg_parses_mpg_incorrectly.mpg) + if(valid_psc > 2*invalid_psc + 2*res_change + 3){ + return 50; + }else if(valid_psc > 2*invalid_psc) + return 25; return 0; } #endif @@ -470,14 +486,40 @@ static int h263_probe(AVProbeData *p) #if CONFIG_H261_DEMUXER static int h261_probe(AVProbeData *p) { - int code; - const uint8_t *d; + uint32_t code= -1; + int i; + int valid_psc=0; + int invalid_psc=0; + int next_gn=0; + int src_fmt=0; + GetBitContext gb; - d = p->buf; - code = (d[0] << 12) | (d[1] << 4) | (d[2] >> 4); - if (code == 0x10) { - return 50; + init_get_bits(&gb, p->buf, p->buf_size*8); + + for(i=0; ibuf_size*8; i++){ + if ((code & 0x01ff0000) || !(code & 0xff00)) { + code = (code<<8) + get_bits(&gb, 8); + i += 7; + } else + code = (code<<1) + get_bits1(&gb); + if ((code & 0xffff0000) == 0x10000) { + int gn= (code>>12)&0xf; + if(!gn) + src_fmt= code&8; + if(gn != next_gn) invalid_psc++; + else valid_psc++; + + if(src_fmt){ // CIF + next_gn= (gn+1 )%13; + }else{ //QCIF + next_gn= (gn+1+!!gn)% 7; + } + } } + if(valid_psc > 2*invalid_psc + 6){ + return 50; + }else if(valid_psc > 2*invalid_psc + 2) + return 25; return 0; } #endif @@ -491,6 +533,8 @@ static int dts_probe(AVProbeData *p) { const uint8_t *buf, *bufp; uint32_t state = -1; + int markers[3] = {0}; + int sum, max; buf = p->buf; @@ -500,18 +544,24 @@ static int dts_probe(AVProbeData *p) /* regular bitstream */ if (state == DCA_MARKER_RAW_BE || state == DCA_MARKER_RAW_LE) - return AVPROBE_SCORE_MAX/2+1; + markers[0]++; /* 14 bits big-endian bitstream */ if (state == DCA_MARKER_14B_BE) if ((bytestream_get_be16(&bufp) & 0xFFF0) == 0x07F0) - return AVPROBE_SCORE_MAX/2+1; + markers[1]++; /* 14 bits little-endian bitstream */ if (state == DCA_MARKER_14B_LE) if ((bytestream_get_be16(&bufp) & 0xF0FF) == 0xF007) - return AVPROBE_SCORE_MAX/2+1; + markers[2]++; } + sum = markers[0] + markers[1] + markers[2]; + max = markers[1] > markers[0]; + max = markers[2] > markers[max] ? 2 : max; + if (markers[max] > 3 && p->buf_size / markers[max] < 32*1024 && + markers[max] * 4 > sum * 3) + return AVPROBE_SCORE_MAX/2+1; return 0; } @@ -531,10 +581,19 @@ static int dirac_probe(AVProbeData *p) static int dnxhd_probe(AVProbeData *p) { static const uint8_t header[] = {0x00,0x00,0x02,0x80,0x01}; - if (!memcmp(p->buf, header, 5)) - return AVPROBE_SCORE_MAX; - else + int w, h, compression_id; + if (p->buf_size < 0x2c) return 0; + if (memcmp(p->buf, header, 5)) + return 0; + h = AV_RB16(p->buf + 0x18); + w = AV_RB16(p->buf + 0x1a); + if (!w || !h) + return 0; + compression_id = AV_RB32(p->buf + 0x28); + if (compression_id < 1237 || compression_id > 1253) + return 0; + return AVPROBE_SCORE_MAX; } #endif @@ -570,13 +629,11 @@ static int ac3_eac3_probe(AVProbeData *p, enum CodecID expected_codec_id) first_frames = frames; } if(codec_id != expected_codec_id) return 0; - if (first_frames>=3) return AVPROBE_SCORE_MAX * 3 / 4; -#ifdef __HAIKU__ -/* for typical buffer size 2048, we can't detect more than 1 full frame sized of 1792 */ - else if(max_frames>=1) return AVPROBE_SCORE_MAX / 2; -#else - else if(max_frames>=3) return AVPROBE_SCORE_MAX / 2; -#endif + // keep this in sync with mp3 probe, both need to avoid + // issues with MPEG-files! + if (first_frames>=4) return AVPROBE_SCORE_MAX/2+1; + else if(max_frames>500)return AVPROBE_SCORE_MAX/2; + else if(max_frames>=4) return AVPROBE_SCORE_MAX/4; else if(max_frames>=1) return 1; else return 0; } @@ -643,7 +700,7 @@ static int adts_aac_read_header(AVFormatContext *s, if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = s->iformat->value; st->need_parsing = AVSTREAM_PARSE_FULL; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rdt.c b/src/add-ons/media/plugins/ffmpeg/libavformat/rdt.c index 24ee6a993d..7dda3f3d75 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/rdt.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rdt.c @@ -20,7 +20,7 @@ */ /** - * @file libavformat/rdt.c + * @file * @brief Realmedia RTSP protocol (RDT) support * @author Ronald S. Bultje */ @@ -67,7 +67,7 @@ ff_rdt_parse_open(AVFormatContext *ic, int first_stream_of_set_idx, s->prev_set_id = -1; s->prev_stream_id = -1; s->prev_timestamp = -1; - s->parse_packet = handler->parse_packet; + s->parse_packet = handler ? handler->parse_packet : NULL; s->dynamic_protocol_context = priv_data; return s; @@ -120,8 +120,7 @@ ff_rdt_calc_response_and_checksum(char response[41], char chksum[9], buf[8 + i] ^= xor_table[i]; av_md5_sum(zres, buf, 64); - ff_data_to_hex(response, zres, 16); - for (i=0;i<32;i++) response[i] = tolower(response[i]); + ff_data_to_hex(response, zres, 16, 1); /* add tail */ strcpy (response + 32, "01d0a8e3"); @@ -418,7 +417,7 @@ rdt_parse_sdp_line (AVFormatContext *s, int st_index, } else if (av_strstart(p, "StartTime:integer;", &p)) stream->first_dts = atoi(p); else if (av_strstart(p, "ASMRuleBook:string;", &p)) { - int n = st_index, first = -1; + int n, first = -1; for (n = 0; n < s->nb_streams; n++) if (s->streams[n]->priv_data == stream->priv_data) { @@ -547,10 +546,10 @@ static RTPDynamicProtocolHandler ff_rdt_ ## n ## _handler = { \ .parse_packet = rdt_parse_packet \ }; -RDT_HANDLER(live_video, "x-pn-multirate-realvideo-live", CODEC_TYPE_VIDEO); -RDT_HANDLER(live_audio, "x-pn-multirate-realaudio-live", CODEC_TYPE_AUDIO); -RDT_HANDLER(video, "x-pn-realvideo", CODEC_TYPE_VIDEO); -RDT_HANDLER(audio, "x-pn-realaudio", CODEC_TYPE_AUDIO); +RDT_HANDLER(live_video, "x-pn-multirate-realvideo-live", AVMEDIA_TYPE_VIDEO); +RDT_HANDLER(live_audio, "x-pn-multirate-realaudio-live", AVMEDIA_TYPE_AUDIO); +RDT_HANDLER(video, "x-pn-realvideo", AVMEDIA_TYPE_VIDEO); +RDT_HANDLER(audio, "x-pn-realaudio", AVMEDIA_TYPE_AUDIO); void av_register_rdt_dynamic_payload_handlers(void) { diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/riff.c b/src/add-ons/media/plugins/ffmpeg/libavformat/riff.c index 43121afd7c..04b710854a 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/riff.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/riff.c @@ -77,6 +77,10 @@ const AVCodecTag ff_codec_bmp_tags[] = { { CODEC_ID_MPEG4, MKTAG('E', 'M', '4', 'A') }, { CODEC_ID_MPEG4, MKTAG('M', '4', 'C', 'C') }, /* Divio MPEG-4 */ { CODEC_ID_MPEG4, MKTAG('S', 'N', '4', '0') }, + { CODEC_ID_MPEG4, MKTAG('V', 'S', 'P', 'X') }, + { CODEC_ID_MPEG4, MKTAG('U', 'L', 'D', 'X') }, + { CODEC_ID_MPEG4, MKTAG('G', 'E', 'O', 'V') }, + { CODEC_ID_MPEG4, MKTAG('S', 'I', 'P', 'P') }, /* Samsung SHR-6040 */ { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '3') }, /* default signature when using MSMPEG4 */ { CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', '4', '3') }, { CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', 'G', '3') }, @@ -102,6 +106,7 @@ const AVCodecTag ff_codec_bmp_tags[] = { { CODEC_ID_DVVIDEO, MKTAG('c', 'd', 'v', 'c') }, /* Canopus DV */ { CODEC_ID_DVVIDEO, MKTAG('C', 'D', 'V', 'H') }, /* Canopus DV */ { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'c', ' ') }, + { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'c', 's') }, { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'h', '1') }, { CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'g', '1') }, { CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'g', '2') }, @@ -116,9 +121,12 @@ const AVCodecTag ff_codec_bmp_tags[] = { { CODEC_ID_MPEG2VIDEO, MKTAG('D', 'V', 'R', ' ') }, { CODEC_ID_MPEG2VIDEO, MKTAG('M', 'M', 'E', 'S') }, { CODEC_ID_MPEG2VIDEO, MKTAG('L', 'M', 'P', '2') }, /* Lead MPEG2 in avi */ + { CODEC_ID_MPEG2VIDEO, MKTAG('s', 'l', 'i', 'f') }, + { CODEC_ID_MPEG2VIDEO, MKTAG('E', 'M', '2', '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') }, + { CODEC_ID_MJPEG, MKTAG('m', 'j', 'p', 'a') }, { CODEC_ID_LJPEG, MKTAG('L', 'J', 'P', 'G') }, { CODEC_ID_MJPEG, MKTAG('J', 'P', 'G', 'L') }, /* Pegasus lossless JPEG */ { CODEC_ID_JPEGLS, MKTAG('M', 'J', 'L', 'S') }, /* JPEG-LS custom FOURCC for avi - encoder */ @@ -130,6 +138,12 @@ const AVCodecTag ff_codec_bmp_tags[] = { { CODEC_ID_MJPEG, MKTAG('Q', 'I', 'V', 'G') }, { CODEC_ID_MJPEG, MKTAG('S', 'L', 'M', 'J') }, /* SL M-JPEG */ { CODEC_ID_MJPEG, MKTAG('C', 'J', 'P', 'G') }, /* Creative Webcam JPEG */ + { CODEC_ID_MJPEG, MKTAG('I', 'J', 'L', 'V') }, /* Intel JPEG Library Video Codec */ + { CODEC_ID_MJPEG, MKTAG('M', 'V', 'J', 'P') }, /* Midvid JPEG Video Codec */ + { CODEC_ID_MJPEG, MKTAG('A', 'V', 'I', '1') }, + { CODEC_ID_MJPEG, MKTAG('A', 'V', 'I', '2') }, + { CODEC_ID_MJPEG, MKTAG('M', 'T', 'S', 'J') }, + { CODEC_ID_MJPEG, MKTAG('Z', 'J', 'P', 'G') }, /* Paradigm Matrix M-JPEG Codec */ { CODEC_ID_HUFFYUV, MKTAG('H', 'F', 'Y', 'U') }, { CODEC_ID_FFVHUFF, MKTAG('F', 'F', 'V', 'H') }, { CODEC_ID_CYUV, MKTAG('C', 'Y', 'U', 'V') }, @@ -138,12 +152,24 @@ const AVCodecTag ff_codec_bmp_tags[] = { { CODEC_ID_RAWVIDEO, MKTAG('I', '4', '2', '0') }, { CODEC_ID_RAWVIDEO, MKTAG('Y', 'U', 'Y', '2') }, { CODEC_ID_RAWVIDEO, MKTAG('Y', '4', '2', '2') }, + { CODEC_ID_RAWVIDEO, MKTAG('V', '4', '2', '2') }, + { CODEC_ID_RAWVIDEO, MKTAG('Y', 'U', 'N', 'V') }, + { CODEC_ID_RAWVIDEO, MKTAG('U', 'Y', 'N', 'V') }, + { CODEC_ID_RAWVIDEO, MKTAG('U', 'Y', 'N', 'Y') }, + { CODEC_ID_RAWVIDEO, MKTAG('u', 'y', 'v', '1') }, + { CODEC_ID_RAWVIDEO, MKTAG('2', 'V', 'u', '1') }, + { CODEC_ID_RAWVIDEO, MKTAG('2', 'v', 'u', 'y') }, + { CODEC_ID_RAWVIDEO, MKTAG('P', '4', '2', '2') }, { CODEC_ID_RAWVIDEO, MKTAG('Y', 'V', '1', '2') }, { 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('H', 'D', 'Y', 'C') }, { CODEC_ID_RAWVIDEO, MKTAG('Y', 'V', 'U', '9') }, + { CODEC_ID_RAWVIDEO, MKTAG('V', 'D', 'T', 'Z') }, /* SoftLab-NSK VideoTizer */ + { CODEC_ID_FRWU, MKTAG('F', 'R', 'W', 'U') }, + { CODEC_ID_R210, MKTAG('r', '2', '1', '0') }, { CODEC_ID_V210, MKTAG('v', '2', '1', '0') }, { CODEC_ID_INDEO3, MKTAG('I', 'V', '3', '1') }, { CODEC_ID_INDEO3, MKTAG('I', 'V', '3', '2') }, @@ -155,6 +181,8 @@ const AVCodecTag ff_codec_bmp_tags[] = { { CODEC_ID_VP6, MKTAG('V', 'P', '6', '0') }, { CODEC_ID_VP6, MKTAG('V', 'P', '6', '1') }, { CODEC_ID_VP6, MKTAG('V', 'P', '6', '2') }, + { CODEC_ID_VP6F, MKTAG('V', 'P', '6', 'F') }, + { CODEC_ID_VP6F, MKTAG('F', 'L', 'V', '4') }, { CODEC_ID_ASV1, MKTAG('A', 'S', 'V', '1') }, { CODEC_ID_ASV2, MKTAG('A', 'S', 'V', '2') }, { CODEC_ID_VCR1, MKTAG('V', 'C', 'R', '1') }, @@ -179,7 +207,6 @@ const AVCodecTag ff_codec_bmp_tags[] = { { CODEC_ID_4XM, MKTAG('4', 'X', 'M', 'V') }, { CODEC_ID_FLV1, MKTAG('F', 'L', 'V', '1') }, { CODEC_ID_FLASHSV, MKTAG('F', 'S', 'V', '1') }, - { CODEC_ID_VP6F, MKTAG('V', 'P', '6', 'F') }, { CODEC_ID_SVQ1, MKTAG('s', 'v', 'q', '1') }, { CODEC_ID_TSCC, MKTAG('t', 's', 'c', 'c') }, { CODEC_ID_ULTI, MKTAG('U', 'L', 'T', 'I') }, @@ -215,6 +242,7 @@ const AVCodecTag ff_codec_bmp_tags[] = { { CODEC_ID_AURA, MKTAG('A', 'U', 'R', 'A') }, { CODEC_ID_AURA2, MKTAG('A', 'U', 'R', '2') }, { CODEC_ID_DPX, MKTAG('d', 'p', 'x', ' ') }, + { CODEC_ID_KGV1, MKTAG('K', 'G', 'V', '1') }, { CODEC_ID_NONE, 0 } }; @@ -252,6 +280,8 @@ const AVCodecTag ff_codec_wav_tags[] = { { CODEC_ID_ADPCM_CT, 0x0200 }, { CODEC_ID_ATRAC3, 0x0270 }, { CODEC_ID_IMC, 0x0401 }, + { CODEC_ID_GSM_MS, 0x1500 }, + { CODEC_ID_TRUESPEECH, 0x1501 }, { CODEC_ID_AC3, 0x2000 }, { CODEC_ID_DTS, 0x2001 }, { CODEC_ID_SONIC, 0x2048 }, @@ -268,7 +298,7 @@ const AVCodecTag ff_codec_wav_tags[] = { { CODEC_ID_PCM_S16LE, MKTAG('R', 'A', 'W', 'A') }, { CODEC_ID_MP3, MKTAG('L', 'A', 'M', 'E') }, { CODEC_ID_MP3, MKTAG('M', 'P', '3', ' ') }, - { 0, 0 }, + { CODEC_ID_NONE, 0 }, }; #if CONFIG_MUXERS @@ -302,7 +332,9 @@ int ff_put_wav_header(ByteIOContext *pb, AVCodecContext *enc) if(!enc->codec_tag || enc->codec_tag > 0xffff) return -1; - waveformatextensible = enc->channels > 2 && enc->channel_layout; + waveformatextensible = (enc->channels > 2 && enc->channel_layout) + || enc->sample_rate > 48000 + || av_get_bits_per_sample(enc->codec_id) > 16; if (waveformatextensible) { put_le16(pb, 0xfffe); @@ -313,7 +345,7 @@ int ff_put_wav_header(ByteIOContext *pb, AVCodecContext *enc) put_le32(pb, enc->sample_rate); if (enc->codec_id == CODEC_ID_MP2 || enc->codec_id == CODEC_ID_MP3 || enc->codec_id == CODEC_ID_GSM_MS) { bps = 0; - } else if (enc->codec_id == CODEC_ID_ADPCM_IMA_WAV || enc->codec_id == CODEC_ID_ADPCM_MS || enc->codec_id == CODEC_ID_ADPCM_G726 || enc->codec_id == CODEC_ID_ADPCM_YAMAHA) { // + } else if (enc->codec_id == CODEC_ID_ADPCM_G726) { bps = 4; } else { if (!(bps = av_get_bits_per_sample(enc->codec_id))) @@ -413,7 +445,7 @@ void ff_put_bmp_header(ByteIOContext *pb, AVCodecContext *enc, const AVCodecTag put_buffer(pb, enc->extradata, enc->extradata_size); - if (enc->extradata_size & 1) + if (!for_asf && enc->extradata_size & 1) put_byte(pb, 0); } #endif //CONFIG_MUXERS @@ -431,7 +463,7 @@ void ff_get_wav_header(ByteIOContext *pb, AVCodecContext *codec, int size) int id; id = get_le16(pb); - codec->codec_type = CODEC_TYPE_AUDIO; + codec->codec_type = AVMEDIA_TYPE_AUDIO; codec->codec_tag = id; codec->channels = get_le16(pb); codec->sample_rate = get_le32(pb); @@ -497,8 +529,8 @@ void ff_parse_specific_params(AVCodecContext *stream, int *au_rate, int *au_ssiz if(stream->frame_size && stream->sample_rate){ *au_scale=stream->frame_size; *au_rate= stream->sample_rate; - }else if(stream->codec_type == CODEC_TYPE_VIDEO || - stream->codec_type == CODEC_TYPE_SUBTITLE){ + }else if(stream->codec_type == AVMEDIA_TYPE_VIDEO || + stream->codec_type == AVMEDIA_TYPE_SUBTITLE){ *au_scale= stream->time_base.num; *au_rate = stream->time_base.den; }else{ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/riff.h b/src/add-ons/media/plugins/ffmpeg/libavformat/riff.h index eac0d25470..2696a0b3c9 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/riff.h +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/riff.h @@ -20,7 +20,7 @@ */ /** - * @file libavformat/riff.h + * @file * internal header for RIFF based (de)muxers * do NOT include this in end user applications */ @@ -35,7 +35,7 @@ int64_t ff_start_tag(ByteIOContext *pb, const char *tag); void ff_end_tag(ByteIOContext *pb, int64_t start); typedef struct AVCodecTag { - int id; + enum CodecID id; unsigned int tag; } AVCodecTag; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rl2.c b/src/add-ons/media/plugins/ffmpeg/libavformat/rl2.c index 1b193b002a..1b7edce824 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/rl2.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rl2.c @@ -21,7 +21,7 @@ /** * RL2 file demuxer - * @file libavformat/rl2.c + * @file * @author Sascha Sommer (saschasommer@freenet.de) * For more information regarding the RL2 file format, visit: * http://wiki.multimedia.cx/index.php?title=RL2 @@ -116,7 +116,7 @@ static av_cold int rl2_read_header(AVFormatContext *s, if(!st) return AVERROR(ENOMEM); - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_RL2; st->codec->codec_tag = 0; /* no fourcc */ st->codec->width = 320; @@ -145,7 +145,7 @@ static av_cold int rl2_read_header(AVFormatContext *s, st = av_new_stream(s, 0); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_PCM_U8; st->codec->codec_tag = 1; st->codec->channels = channels; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rm.c b/src/add-ons/media/plugins/ffmpeg/libavformat/rm.c index 9911aac91e..29a6e408e0 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/rm.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rm.c @@ -21,7 +21,7 @@ #include "rm.h" -const char *ff_rm_metadata[4] = { +const char * const ff_rm_metadata[4] = { "title", "author", "copyright", diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rm.h b/src/add-ons/media/plugins/ffmpeg/libavformat/rm.h index a60004883a..4e63114a11 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/rm.h +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rm.h @@ -24,7 +24,8 @@ #include "avformat.h" -extern const char *ff_rm_metadata[4]; +extern const char * const ff_rm_metadata[4]; +extern const unsigned char ff_sipr_subpk_size[4]; typedef struct RMStream RMStream; @@ -84,10 +85,17 @@ int ff_rm_parse_packet (AVFormatContext *s, ByteIOContext *pb, * @param st stream that this packet belongs to * @param rst Real-specific stream information * @param pkt location to store the packet data - * @returns the number of samples left for subsequent calls to this same + * @return the number of samples left for subsequent calls to this same * function, or 0 if all samples have been retrieved. */ int ff_rm_retrieve_cache (AVFormatContext *s, ByteIOContext *pb, AVStream *st, RMStream *rst, AVPacket *pkt); +/** + * Perform 4-bit block reordering for SIPR data. + * + * @param buf SIPR data + */ +void ff_rm_reorder_sipr_data(uint8_t *buf, int sub_packet_h, int framesize); + #endif /* AVFORMAT_RM_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rmdec.c b/src/add-ons/media/plugins/ffmpeg/libavformat/rmdec.c index 10e7c2a3df..bba94bd72c 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/rmdec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rmdec.c @@ -22,6 +22,7 @@ #include "libavutil/avstring.h" #include "libavutil/intreadwrite.h" #include "avformat.h" +#include "riff.h" #include "rm.h" struct RMStream { @@ -48,6 +49,23 @@ typedef struct { int audio_pkt_cnt; ///< Output packet counter } RMDemuxContext; +static const AVCodecTag rm_codec_tags[] = { + { CODEC_ID_RV10, MKTAG('R','V','1','0') }, + { CODEC_ID_RV20, MKTAG('R','V','2','0') }, + { CODEC_ID_RV20, MKTAG('R','V','T','R') }, + { CODEC_ID_RV30, MKTAG('R','V','3','0') }, + { CODEC_ID_RV40, MKTAG('R','V','4','0') }, + { CODEC_ID_AC3, MKTAG('d','n','e','t') }, + { CODEC_ID_RA_144, MKTAG('l','p','c','J') }, + { CODEC_ID_RA_288, MKTAG('2','8','_','8') }, + { CODEC_ID_COOK, MKTAG('c','o','o','k') }, + { CODEC_ID_ATRAC3, MKTAG('a','t','r','c') }, + { CODEC_ID_SIPR, MKTAG('s','i','p','r') }, + { CODEC_ID_AAC, MKTAG('r','a','a','c') }, + { CODEC_ID_AAC, MKTAG('r','a','c','p') }, + { CODEC_ID_NONE }, +}; + static const unsigned char sipr_swaps[38][2] = { { 0, 63 }, { 1, 22 }, { 2, 44 }, { 3, 90 }, { 5, 81 }, { 7, 31 }, { 8, 86 }, { 9, 58 }, @@ -61,7 +79,7 @@ static const unsigned char sipr_swaps[38][2] = { { 67, 83 }, { 77, 80 } }; -static const unsigned char sipr_subpk_size[4] = { 29, 19, 37, 20 }; +const unsigned char ff_sipr_subpk_size[4] = { 29, 19, 37, 20 }; static inline void get_strl(ByteIOContext *pb, char *buf, int buf_size, int len) { @@ -82,6 +100,20 @@ static void get_str8(ByteIOContext *pb, char *buf, int buf_size) get_strl(pb, buf, buf_size, get_byte(pb)); } +static int rm_read_extradata(ByteIOContext *pb, AVCodecContext *avctx, unsigned size) +{ + if (size >= 1<<24) + return -1; + avctx->extradata = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); + if (!avctx->extradata) + return AVERROR(ENOMEM); + avctx->extradata_size = get_buffer(pb, avctx->extradata, size); + memset(avctx->extradata + avctx->extradata_size, 0, FF_INPUT_BUFFER_PADDING_SIZE); + if (avctx->extradata_size != size) + return AVERROR(EIO); + return 0; +} + static void rm_read_metadata(AVFormatContext *s, int wide) { char buf[1024]; @@ -89,7 +121,7 @@ static void rm_read_metadata(AVFormatContext *s, int wide) for (i=0; ipb) : get_byte(s->pb); get_strl(s->pb, buf, sizeof(buf), len); - av_metadata_set(&s->metadata, ff_rm_metadata[i], buf); + av_metadata_set2(&s->metadata, ff_rm_metadata[i], buf, 0); } } @@ -110,28 +142,32 @@ static int rm_read_audio_stream_info(AVFormatContext *s, ByteIOContext *pb, { char buf[256]; uint32_t version; + int ret; /* ra type header */ - version = get_be32(pb); /* version */ - if (((version >> 16) & 0xff) == 3) { + version = get_be16(pb); /* version */ + if (version == 3) { + int header_size = get_be16(pb); int64_t startpos = url_ftell(pb); url_fskip(pb, 14); rm_read_metadata(s, 0); - if ((startpos + (version & 0xffff)) >= url_ftell(pb) + 2) { + if ((startpos + header_size) >= url_ftell(pb) + 2) { // fourcc (should always be "lpcJ") get_byte(pb); get_str8(pb, buf, sizeof(buf)); } // Skip extra header crap (this should never happen) - if ((startpos + (version & 0xffff)) > url_ftell(pb)) - url_fskip(pb, (version & 0xffff) + startpos - url_ftell(pb)); + if ((startpos + header_size) > url_ftell(pb)) + url_fskip(pb, header_size + startpos - url_ftell(pb)); st->codec->sample_rate = 8000; st->codec->channels = 1; - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_RA_144; } else { int flavor, sub_packet_h, coded_framesize, sub_packet_size; + int codecdata_length; /* old version (4) */ + url_fskip(pb, 2); /* unused */ get_be32(pb); /* .ra4 */ get_be32(pb); /* data size */ get_be16(pb); /* version2 */ @@ -145,13 +181,13 @@ static int rm_read_audio_stream_info(AVFormatContext *s, ByteIOContext *pb, st->codec->block_align= get_be16(pb); /* frame size */ ast->sub_packet_size = sub_packet_size = get_be16(pb); /* sub packet size */ get_be16(pb); /* ??? */ - if (((version >> 16) & 0xff) == 5) { + if (version == 5) { get_be16(pb); get_be16(pb); get_be16(pb); } st->codec->sample_rate = get_be16(pb); get_be32(pb); st->codec->channels = get_be16(pb); - if (((version >> 16) & 0xff) == 5) { + if (version == 5) { get_be32(pb); get_buffer(pb, buf, 4); buf[4] = 0; @@ -159,12 +195,14 @@ static int rm_read_audio_stream_info(AVFormatContext *s, ByteIOContext *pb, get_str8(pb, buf, sizeof(buf)); /* desc */ get_str8(pb, buf, sizeof(buf)); /* desc */ } - st->codec->codec_type = CODEC_TYPE_AUDIO; - if (!strcmp(buf, "dnet")) { - st->codec->codec_id = CODEC_ID_AC3; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codec->codec_tag = AV_RL32(buf); + st->codec->codec_id = ff_codec_get_id(rm_codec_tags, st->codec->codec_tag); + switch (st->codec->codec_id) { + case CODEC_ID_AC3: st->need_parsing = AVSTREAM_PARSE_FULL; - } else if (!strcmp(buf, "28_8")) { - st->codec->codec_id = CODEC_ID_RA_288; + break; + case CODEC_ID_RA_288: st->codec->extradata_size= 0; ast->audio_framesize = st->codec->block_align; st->codec->block_align = coded_framesize; @@ -175,10 +213,12 @@ static int rm_read_audio_stream_info(AVFormatContext *s, ByteIOContext *pb, } av_new_packet(&ast->pkt, ast->audio_framesize * sub_packet_h); - } else if ((!strcmp(buf, "cook")) || (!strcmp(buf, "atrc")) || (!strcmp(buf, "sipr"))) { - int codecdata_length; + break; + case CODEC_ID_COOK: + case CODEC_ID_ATRAC3: + case CODEC_ID_SIPR: get_be16(pb); get_byte(pb); - if (((version >> 16) & 0xff) == 5) + if (version == 5) get_byte(pb); codecdata_length = get_be32(pb); if(codecdata_length + FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)codecdata_length){ @@ -197,7 +237,7 @@ static int rm_read_audio_stream_info(AVFormatContext *s, ByteIOContext *pb, flavor); return -1; } - st->codec->block_align = sipr_subpk_size[flavor]; + st->codec->block_align = ff_sipr_subpk_size[flavor]; } else { if(sub_packet_size <= 0){ av_log(s, AV_LOG_ERROR, "sub_packet_size is invalid\n"); @@ -205,9 +245,8 @@ static int rm_read_audio_stream_info(AVFormatContext *s, ByteIOContext *pb, } st->codec->block_align = ast->sub_packet_size; } - st->codec->extradata_size= codecdata_length; - st->codec->extradata= av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); - get_buffer(pb, st->codec->extradata, st->codec->extradata_size); + 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"); @@ -215,10 +254,10 @@ static int rm_read_audio_stream_info(AVFormatContext *s, ByteIOContext *pb, } av_new_packet(&ast->pkt, ast->audio_framesize * sub_packet_h); - } else if (!strcmp(buf, "raac") || !strcmp(buf, "racp")) { - int codecdata_length; + break; + case CODEC_ID_AAC: get_be16(pb); get_byte(pb); - if (((version >> 16) & 0xff) == 5) + if (version == 5) get_byte(pb); st->codec->codec_id = CODEC_ID_AAC; codecdata_length = get_be32(pb); @@ -227,13 +266,12 @@ static int rm_read_audio_stream_info(AVFormatContext *s, ByteIOContext *pb, return -1; } if (codecdata_length >= 1) { - st->codec->extradata_size = codecdata_length - 1; - st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); get_byte(pb); - get_buffer(pb, st->codec->extradata, st->codec->extradata_size); + if ((ret = rm_read_extradata(pb, st->codec, codecdata_length - 1)) < 0) + return ret; } - } else { - st->codec->codec_id = CODEC_ID_NONE; + break; + default: av_strlcpy(st->codec->codec_name, buf, sizeof(st->codec->codec_name)); } if (read_all) { @@ -253,6 +291,7 @@ ff_rm_read_mdpr_codecdata (AVFormatContext *s, ByteIOContext *pb, unsigned int v; int size; int64_t codec_pos; + int ret; av_set_pts_info(st, 64, 1, 1000); codec_pos = url_ftell(pb); @@ -269,42 +308,33 @@ ff_rm_read_mdpr_codecdata (AVFormatContext *s, ByteIOContext *pb, goto skip; } st->codec->codec_tag = get_le32(pb); + st->codec->codec_id = ff_codec_get_id(rm_codec_tags, st->codec->codec_tag); // av_log(s, AV_LOG_DEBUG, "%X %X\n", st->codec->codec_tag, MKTAG('R', 'V', '2', '0')); - if ( st->codec->codec_tag != MKTAG('R', 'V', '1', '0') - && st->codec->codec_tag != MKTAG('R', 'V', '2', '0') - && st->codec->codec_tag != MKTAG('R', 'V', '3', '0') - && st->codec->codec_tag != MKTAG('R', 'V', '4', '0') - && st->codec->codec_tag != MKTAG('R', 'V', 'T', 'R')) + if (st->codec->codec_id == CODEC_ID_NONE) goto fail1; st->codec->width = get_be16(pb); st->codec->height = get_be16(pb); st->codec->time_base.num= 1; fps= get_be16(pb); - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; get_be32(pb); fps2= get_be16(pb); get_be16(pb); - st->codec->extradata_size= codec_data_size - (url_ftell(pb) - codec_pos); - - if(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)st->codec->extradata_size){ - //check is redundant as get_buffer() will catch this - av_log(s, AV_LOG_ERROR, "st->codec->extradata_size too large\n"); - return -1; - } - st->codec->extradata= av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); - if (!st->codec->extradata) - return AVERROR(ENOMEM); - get_buffer(pb, st->codec->extradata, st->codec->extradata_size); + if ((ret = rm_read_extradata(pb, st->codec, codec_data_size - (url_ftell(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; - switch(((uint8_t*)st->codec->extradata)[4]>>4){ + //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: goto fail1; + 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; } } @@ -449,7 +479,7 @@ static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap) st->duration = duration; get_str8(pb, buf, sizeof(buf)); /* desc */ get_str8(pb, buf, sizeof(buf)); /* mimetype */ - st->codec->codec_type = CODEC_TYPE_DATA; + st->codec->codec_type = AVMEDIA_TYPE_DATA; st->priv_data = ff_rm_alloc_rmstream(); if (ff_rm_read_mdpr_codecdata(s, s->pb, st, st->priv_data, get_be32(pb)) < 0) @@ -498,14 +528,14 @@ static int get_num(ByteIOContext *pb, int *len) /* multiple of 20 bytes for ra144 (ugly) */ #define RAW_PACKET_SIZE 1000 -static int sync(AVFormatContext *s, int64_t *timestamp, int *flags, int *stream_index, int64_t *pos){ +static int sync_context(AVFormatContext *s, int64_t *timestamp, int *flags, int *stream_index, int64_t *pos){ RMDemuxContext *rm = s->priv_data; ByteIOContext *pb = s->pb; AVStream *st; uint32_t state=0xFFFFFFFF; while(!url_feof(pb)){ - int len, num, res, i; + int len, num, i; *pos= url_ftell(pb) - 3; if(rm->remaining_len > 0){ num= rm->current_stream; @@ -532,6 +562,9 @@ static int sync(AVFormatContext *s, int64_t *timestamp, int *flags, int *stream_ if(len<0) continue; goto skip; + } else if (state == MKBETAG('D','A','T','A')) { + av_log(s, AV_LOG_WARNING, + "DATA tag in middle of chunk, file may be broken.\n"); } if(state > (unsigned)0xFFFF || state <= 12) @@ -541,7 +574,7 @@ static int sync(AVFormatContext *s, int64_t *timestamp, int *flags, int *stream_ num = get_be16(pb); *timestamp = get_be32(pb); - res= get_byte(pb); /* reserved */ + get_byte(pb); /* reserved */ *flags = get_byte(pb); /* flags */ } for(i=0;inb_streams;i++) { @@ -637,6 +670,7 @@ static int rm_assemble_video_frame(AVFormatContext *s, ByteIOContext *pb, pkt->size = vst->videobufpos + 8*(vst->cur_slice - vst->slices); pkt->pts = AV_NOPTS_VALUE; pkt->pos = vst->pktpos; + vst->slices = 0; return 0; } @@ -662,16 +696,14 @@ rm_ac3_swap_bytes (AVStream *st, AVPacket *pkt) * Perform 4-bit block reordering for SIPR data. * @todo This can be optimized, e.g. use memcpy() if data blocks are aligned */ -static void -rm_reorder_sipr_data (RMStream *ast) +void ff_rm_reorder_sipr_data(uint8_t *buf, int sub_packet_h, int framesize) { - int n, bs = ast->sub_packet_h * ast->audio_framesize * 2 / 96; // nibbles per subpacket + int n, bs = sub_packet_h * framesize * 2 / 96; // nibbles per subpacket for (n = 0; n < 38; n++) { int j; int i = bs * sipr_swaps[n][0]; int o = bs * sipr_swaps[n][1]; - uint8_t *buf = ast->pkt.data; /* swap 4bit-nibbles of block 'i' with 'o' */ for (j = 0; j < bs; j++, i++, o++) { @@ -693,11 +725,11 @@ ff_rm_parse_packet (AVFormatContext *s, ByteIOContext *pb, { RMDemuxContext *rm = s->priv_data; - if (st->codec->codec_type == CODEC_TYPE_VIDEO) { + 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)) return -1; //got partial frame - } else if (st->codec->codec_type == CODEC_TYPE_AUDIO) { + } 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) || @@ -732,7 +764,7 @@ ff_rm_parse_packet (AVFormatContext *s, ByteIOContext *pb, if (++(ast->sub_packet_cnt) < h) return -1; if (st->codec->codec_id == CODEC_ID_SIPR) - rm_reorder_sipr_data(ast); + ff_rm_reorder_sipr_data(ast->pkt.data, h, w); ast->sub_packet_cnt = 0; rm->audio_stream_num = st->index; @@ -758,7 +790,7 @@ ff_rm_parse_packet (AVFormatContext *s, ByteIOContext *pb, pkt->stream_index = st->index; #if 0 - if (st->codec->codec_type == CODEC_TYPE_VIDEO) { + if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { if(st->codec->codec_id == CODEC_ID_RV20){ int seq= 128*(pkt->data[2]&0x7F) + (pkt->data[3]>>1); av_log(s, AV_LOG_DEBUG, "%d %"PRId64" %d\n", *timestamp, *timestamp*512LL/25, seq); @@ -772,9 +804,9 @@ ff_rm_parse_packet (AVFormatContext *s, ByteIOContext *pb, pkt->pts= timestamp; if (flags & 2) - pkt->flags |= PKT_FLAG_KEY; + pkt->flags |= AV_PKT_FLAG_KEY; - return st->codec->codec_type == CODEC_TYPE_AUDIO ? rm->audio_pkt_cnt : 0; + return st->codec->codec_type == AVMEDIA_TYPE_AUDIO ? rm->audio_pkt_cnt : 0; } int @@ -796,7 +828,7 @@ ff_rm_retrieve_cache (AVFormatContext *s, ByteIOContext *pb, rm->audio_pkt_cnt--; if ((pkt->pts = ast->audiotimestamp) != AV_NOPTS_VALUE) { ast->audiotimestamp = AV_NOPTS_VALUE; - pkt->flags = PKT_FLAG_KEY; + pkt->flags = AV_PKT_FLAG_KEY; } else pkt->flags = 0; pkt->stream_index = st->index; @@ -817,6 +849,7 @@ static int rm_read_packet(AVFormatContext *s, AVPacket *pkt) // If there are queued audio packet return them first st = s->streams[rm->audio_stream_num]; ff_rm_retrieve_cache(s, s->pb, st, st->priv_data, pkt); + flags = 0; } else { if (rm->old_format) { RMStream *ast; @@ -827,8 +860,9 @@ static int rm_read_packet(AVFormatContext *s, AVPacket *pkt) len = !ast->audio_framesize ? RAW_PACKET_SIZE : ast->coded_framesize * ast->sub_packet_h / 2; flags = (seq++ == 1) ? 2 : 0; + pos = url_ftell(s->pb); } else { - len=sync(s, ×tamp, &flags, &i, &pos); + len=sync_context(s, ×tamp, &flags, &i, &pos); if (len > 0) st = s->streams[i]; } @@ -895,12 +929,12 @@ static int64_t rm_read_dts(AVFormatContext *s, int stream_index, int seq=1; AVStream *st; - len=sync(s, &dts, &flags, &stream_index2, &pos); + len=sync_context(s, &dts, &flags, &stream_index2, &pos); if(len<0) return AV_NOPTS_VALUE; st = s->streams[stream_index2]; - if (st->codec->codec_type == CODEC_TYPE_VIDEO) { + if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { h= get_byte(s->pb); len--; if(!(h & 0x40)){ seq = get_byte(s->pb); len--; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rmenc.c b/src/add-ons/media/plugins/ffmpeg/libavformat/rmenc.c index 21748d5d52..03db3ce5b8 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/rmenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rmenc.c @@ -141,7 +141,7 @@ static void rv10_write_header(AVFormatContext *ctx, stream = &rm->streams[i]; - if (stream->enc->codec_type == CODEC_TYPE_AUDIO) { + if (stream->enc->codec_type == AVMEDIA_TYPE_AUDIO) { desc = "The Audio Stream"; mimetype = "audio/x-pn-realaudio"; codec_data_size = 73; @@ -177,7 +177,7 @@ static void rv10_write_header(AVFormatContext *ctx, put_str8(s, mimetype); put_be32(s, codec_data_size); - if (stream->enc->codec_type == CODEC_TYPE_AUDIO) { + if (stream->enc->codec_type == AVMEDIA_TYPE_AUDIO) { int coded_frame_size, fscode, sample_rate; sample_rate = stream->enc->sample_rate; coded_frame_size = (stream->enc->bit_rate * @@ -309,7 +309,7 @@ static int rm_write_header(AVFormatContext *s) stream->enc = codec; switch(codec->codec_type) { - case CODEC_TYPE_AUDIO: + case AVMEDIA_TYPE_AUDIO: rm->audio_stream = stream; stream->frame_rate = (float)codec->sample_rate / (float)codec->frame_size; /* XXX: dummy values */ @@ -317,7 +317,7 @@ static int rm_write_header(AVFormatContext *s) stream->nb_packets = 0; stream->total_frames = stream->nb_packets; break; - case CODEC_TYPE_VIDEO: + case AVMEDIA_TYPE_VIDEO: rm->video_stream = stream; stream->frame_rate = (float)codec->time_base.den / (float)codec->time_base.num; /* XXX: dummy values */ @@ -346,7 +346,7 @@ static int rm_write_audio(AVFormatContext *s, const uint8_t *buf, int size, int /* XXX: suppress this malloc */ buf1= (uint8_t*) av_malloc( size * sizeof(uint8_t) ); - write_packet_header(s, stream, size, !!(flags & PKT_FLAG_KEY)); + write_packet_header(s, stream, size, !!(flags & AV_PKT_FLAG_KEY)); /* for AC-3, the words seem to be reversed */ for(i=0;ipriv_data; ByteIOContext *pb = s->pb; StreamInfo *stream = rm->video_stream; - int key_frame = !!(flags & PKT_FLAG_KEY); + int key_frame = !!(flags & AV_PKT_FLAG_KEY); /* XXX: this is incorrect: should be a parameter */ @@ -408,7 +408,7 @@ static int rm_write_video(AVFormatContext *s, const uint8_t *buf, int size, int static int rm_write_packet(AVFormatContext *s, AVPacket *pkt) { if (s->streams[pkt->stream_index]->codec->codec_type == - CODEC_TYPE_AUDIO) + AVMEDIA_TYPE_AUDIO) return rm_write_audio(s, pkt->data, pkt->size, pkt->flags); else return rm_write_video(s, pkt->data, pkt->size, pkt->flags); diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rpl.c b/src/add-ons/media/plugins/ffmpeg/libavformat/rpl.c index ad713ffada..f0fba3e66f 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/rpl.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rpl.c @@ -131,17 +131,17 @@ static int rpl_read_header(AVFormatContext *s, AVFormatParameters *ap) // for the text in a few cases; samples needed.) error |= read_line(pb, line, sizeof(line)); // ARMovie error |= read_line(pb, line, sizeof(line)); // movie name - av_metadata_set(&s->metadata, "title" , line); + av_metadata_set2(&s->metadata, "title" , line, 0); error |= read_line(pb, line, sizeof(line)); // date/copyright - av_metadata_set(&s->metadata, "copyright", line); + av_metadata_set2(&s->metadata, "copyright", line, 0); error |= read_line(pb, line, sizeof(line)); // author and other - av_metadata_set(&s->metadata, "author" , line); + av_metadata_set2(&s->metadata, "author" , line, 0); // video headers vst = av_new_stream(s, 0); if (!vst) return AVERROR(ENOMEM); - vst->codec->codec_type = CODEC_TYPE_VIDEO; + vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; vst->codec->codec_tag = read_line_and_int(pb, &error); // video format vst->codec->width = read_line_and_int(pb, &error); // video width vst->codec->height = read_line_and_int(pb, &error); // video height @@ -183,7 +183,7 @@ static int rpl_read_header(AVFormatContext *s, AVFormatParameters *ap) ast = av_new_stream(s, 0); if (!ast) return AVERROR(ENOMEM); - ast->codec->codec_type = CODEC_TYPE_AUDIO; + ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; ast->codec->codec_tag = audio_format; ast->codec->sample_rate = read_line_and_int(pb, &error); // audio bitrate ast->codec->channels = read_line_and_int(pb, &error); // number of audio channels @@ -295,7 +295,7 @@ static int rpl_read_packet(AVFormatContext *s, AVPacket *pkt) if (url_fseek(pb, index_entry->pos, SEEK_SET) < 0) return AVERROR(EIO); - if (stream->codec->codec_type == CODEC_TYPE_VIDEO && + if (stream->codec->codec_type == AVMEDIA_TYPE_VIDEO && stream->codec->codec_tag == 124) { // We have to split Escape 124 frames because there are // multiple frames per chunk in Escape 124 samples. @@ -327,7 +327,7 @@ static int rpl_read_packet(AVFormatContext *s, AVPacket *pkt) return AVERROR(EIO); } - if (stream->codec->codec_type == CODEC_TYPE_VIDEO) { + if (stream->codec->codec_type == AVMEDIA_TYPE_VIDEO) { // frames_per_chunk should always be one here; the header // parsing will warn if it isn't. pkt->duration = rpl->frames_per_chunk; @@ -344,7 +344,7 @@ static int rpl_read_packet(AVFormatContext *s, AVPacket *pkt) // None of the Escape formats have keyframes, and the ADPCM // format used doesn't have keyframes. if (rpl->chunk_number == 0 && rpl->frame_in_part == 0) - pkt->flags |= PKT_FLAG_KEY; + pkt->flags |= AV_PKT_FLAG_KEY; return ret; } diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rtmppkt.c b/src/add-ons/media/plugins/ffmpeg/libavformat/rtmppkt.c index af416a4f1f..58c3abe345 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/rtmppkt.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rtmppkt.c @@ -75,37 +75,58 @@ int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p, uint8_t hdr, t, buf[16]; int channel_id, timestamp, data_size, offset = 0; uint32_t extra = 0; - uint8_t type; + enum RTMPPacketType type; + int size = 0; if (url_read(h, &hdr, 1) != 1) return AVERROR(EIO); + size++; channel_id = hdr & 0x3F; + if (channel_id < 2) { //special case for channel number >= 64 + buf[1] = 0; + if (url_read_complete(h, buf, channel_id + 1) != channel_id + 1) + return AVERROR(EIO); + size += channel_id + 1; + channel_id = AV_RL16(buf) + 64; + } data_size = prev_pkt[channel_id].data_size; type = prev_pkt[channel_id].type; extra = prev_pkt[channel_id].extra; hdr >>= 6; if (hdr == RTMP_PS_ONEBYTE) { - //todo - return -1; + timestamp = prev_pkt[channel_id].ts_delta; } else { if (url_read_complete(h, buf, 3) != 3) return AVERROR(EIO); + size += 3; timestamp = AV_RB24(buf); if (hdr != RTMP_PS_FOURBYTES) { if (url_read_complete(h, buf, 3) != 3) return AVERROR(EIO); + size += 3; data_size = AV_RB24(buf); - if (url_read_complete(h, &type, 1) != 1) + if (url_read_complete(h, buf, 1) != 1) return AVERROR(EIO); + size++; + type = buf[0]; if (hdr == RTMP_PS_TWELVEBYTES) { if (url_read_complete(h, buf, 4) != 4) return AVERROR(EIO); + size += 4; extra = AV_RL32(buf); } } + if (timestamp == 0xFFFFFF) { + if (url_read_complete(h, buf, 4) != 4) + return AVERROR(EIO); + timestamp = AV_RB32(buf); + } } + if (hdr != RTMP_PS_TWELVEBYTES) + timestamp += prev_pkt[channel_id].timestamp; + if (ff_rtmp_packet_create(p, channel_id, type, timestamp, data_size)) return -1; p->extra = extra; @@ -113,6 +134,7 @@ int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p, prev_pkt[channel_id].channel_id = channel_id; prev_pkt[channel_id].type = type; prev_pkt[channel_id].data_size = data_size; + prev_pkt[channel_id].ts_delta = timestamp - prev_pkt[channel_id].timestamp; prev_pkt[channel_id].timestamp = timestamp; prev_pkt[channel_id].extra = extra; while (data_size > 0) { @@ -123,13 +145,15 @@ int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p, } data_size -= chunk_size; offset += chunk_size; + size += chunk_size; if (data_size > 0) { url_read_complete(h, &t, 1); //marker + size++; if (t != (0xC0 + channel_id)) return -1; } } - return 0; + return size; } int ff_rtmp_packet_write(URLContext *h, RTMPPacket *pkt, @@ -138,19 +162,60 @@ int ff_rtmp_packet_write(URLContext *h, RTMPPacket *pkt, uint8_t pkt_hdr[16], *p = pkt_hdr; int mode = RTMP_PS_TWELVEBYTES; int off = 0; + int size = 0; - //TODO: header compression - bytestream_put_byte(&p, pkt->channel_id | (mode << 6)); + pkt->ts_delta = pkt->timestamp - prev_pkt[pkt->channel_id].timestamp; + + //if channel_id = 0, this is first presentation of prev_pkt, send full hdr. + if (prev_pkt[pkt->channel_id].channel_id && + pkt->extra == prev_pkt[pkt->channel_id].extra) { + if (pkt->type == prev_pkt[pkt->channel_id].type && + pkt->data_size == prev_pkt[pkt->channel_id].data_size) { + mode = RTMP_PS_FOURBYTES; + if (pkt->ts_delta == prev_pkt[pkt->channel_id].ts_delta) + mode = RTMP_PS_ONEBYTE; + } else { + mode = RTMP_PS_EIGHTBYTES; + } + } + + if (pkt->channel_id < 64) { + bytestream_put_byte(&p, pkt->channel_id | (mode << 6)); + } else if (pkt->channel_id < 64 + 256) { + bytestream_put_byte(&p, 0 | (mode << 6)); + bytestream_put_byte(&p, pkt->channel_id - 64); + } else { + bytestream_put_byte(&p, 1 | (mode << 6)); + bytestream_put_le16(&p, pkt->channel_id - 64); + } if (mode != RTMP_PS_ONEBYTE) { - bytestream_put_be24(&p, pkt->timestamp); + uint32_t timestamp = pkt->timestamp; + if (mode != RTMP_PS_TWELVEBYTES) + timestamp = pkt->ts_delta; + bytestream_put_be24(&p, timestamp >= 0xFFFFFF ? 0xFFFFFF : timestamp); if (mode != RTMP_PS_FOURBYTES) { bytestream_put_be24(&p, pkt->data_size); bytestream_put_byte(&p, pkt->type); if (mode == RTMP_PS_TWELVEBYTES) bytestream_put_le32(&p, pkt->extra); } + if (timestamp >= 0xFFFFFF) + bytestream_put_be32(&p, timestamp); } + // save history + prev_pkt[pkt->channel_id].channel_id = pkt->channel_id; + prev_pkt[pkt->channel_id].type = pkt->type; + prev_pkt[pkt->channel_id].data_size = pkt->data_size; + prev_pkt[pkt->channel_id].timestamp = pkt->timestamp; + if (mode != RTMP_PS_TWELVEBYTES) { + prev_pkt[pkt->channel_id].ts_delta = pkt->ts_delta; + } else { + prev_pkt[pkt->channel_id].ts_delta = pkt->timestamp; + } + prev_pkt[pkt->channel_id].extra = pkt->extra; + url_write(h, pkt_hdr, p-pkt_hdr); + size = p - pkt_hdr + pkt->data_size; while (off < pkt->data_size) { int towrite = FFMIN(chunk_size, pkt->data_size - off); url_write(h, pkt->data + off, towrite); @@ -158,9 +223,10 @@ int ff_rtmp_packet_write(URLContext *h, RTMPPacket *pkt, if (off < pkt->data_size) { uint8_t marker = 0xC0 | pkt->channel_id; url_write(h, &marker, 1); + size++; } } - return 0; + return size; } int ff_rtmp_packet_create(RTMPPacket *pkt, int channel_id, RTMPPacketType type, @@ -174,6 +240,7 @@ int ff_rtmp_packet_create(RTMPPacket *pkt, int channel_id, RTMPPacketType type, pkt->type = type; pkt->timestamp = timestamp; pkt->extra = 0; + pkt->ts_delta = 0; return 0; } @@ -228,10 +295,15 @@ int ff_amf_get_field_value(const uint8_t *data, const uint8_t *data_end, int namelen = strlen(name); int len; + while (*data != AMF_DATA_TYPE_OBJECT && data < data_end) { + len = ff_amf_tag_size(data, data_end); + if (len < 0) + len = data_end - data; + data += len; + } if (data_end - data < 3) return -1; - if (*data++ != AMF_DATA_TYPE_OBJECT) - return -1; + data++; for (;;) { int size = bytestream_get_be16(&data); if (!size) @@ -263,3 +335,112 @@ int ff_amf_get_field_value(const uint8_t *data, const uint8_t *data_end, } return -1; } + +static const char* rtmp_packet_type(int type) +{ + switch (type) { + case RTMP_PT_CHUNK_SIZE: return "chunk size"; + case RTMP_PT_BYTES_READ: return "bytes read"; + case RTMP_PT_PING: return "ping"; + case RTMP_PT_SERVER_BW: return "server bandwidth"; + case RTMP_PT_CLIENT_BW: return "client bandwidth"; + case RTMP_PT_AUDIO: return "audio packet"; + case RTMP_PT_VIDEO: return "video packet"; + case RTMP_PT_FLEX_STREAM: return "Flex shared stream"; + case RTMP_PT_FLEX_OBJECT: return "Flex shared object"; + case RTMP_PT_FLEX_MESSAGE: return "Flex shared message"; + case RTMP_PT_NOTIFY: return "notification"; + case RTMP_PT_SHARED_OBJ: return "shared object"; + case RTMP_PT_INVOKE: return "invoke"; + case RTMP_PT_METADATA: return "metadata"; + default: return "unknown"; + } +} + +static void ff_amf_tag_contents(void *ctx, const uint8_t *data, const uint8_t *data_end) +{ + int size; + char buf[1024]; + + if (data >= data_end) + return; + switch (*data++) { + case AMF_DATA_TYPE_NUMBER: + av_log(ctx, AV_LOG_DEBUG, " number %g\n", av_int2dbl(AV_RB64(data))); + return; + case AMF_DATA_TYPE_BOOL: + av_log(ctx, AV_LOG_DEBUG, " bool %d\n", *data); + return; + case AMF_DATA_TYPE_STRING: + case AMF_DATA_TYPE_LONG_STRING: + if (data[-1] == AMF_DATA_TYPE_STRING) { + size = bytestream_get_be16(&data); + } else { + size = bytestream_get_be32(&data); + } + size = FFMIN(size, 1023); + memcpy(buf, data, size); + buf[size] = 0; + av_log(ctx, AV_LOG_DEBUG, " string '%s'\n", buf); + return; + case AMF_DATA_TYPE_NULL: + av_log(ctx, AV_LOG_DEBUG, " NULL\n"); + return; + case AMF_DATA_TYPE_ARRAY: + data += 4; + case AMF_DATA_TYPE_OBJECT: + av_log(ctx, AV_LOG_DEBUG, " {\n"); + for (;;) { + int size = bytestream_get_be16(&data); + int t; + memcpy(buf, data, size); + buf[size] = 0; + if (!size) { + av_log(ctx, AV_LOG_DEBUG, " }\n"); + data++; + break; + } + if (data + size >= data_end || data + size < data) + return; + data += size; + av_log(ctx, AV_LOG_DEBUG, " %s: ", buf); + ff_amf_tag_contents(ctx, data, data_end); + t = ff_amf_tag_size(data, data_end); + if (t < 0 || data + t >= data_end) + return; + data += t; + } + return; + case AMF_DATA_TYPE_OBJECT_END: + av_log(ctx, AV_LOG_DEBUG, " }\n"); + return; + default: + return; + } +} + +void ff_rtmp_packet_dump(void *ctx, RTMPPacket *p) +{ + av_log(ctx, AV_LOG_DEBUG, "RTMP packet type '%s'(%d) for channel %d, timestamp %d, extra field %d size %d\n", + rtmp_packet_type(p->type), p->type, p->channel_id, p->timestamp, p->extra, p->data_size); + if (p->type == RTMP_PT_INVOKE || p->type == RTMP_PT_NOTIFY) { + uint8_t *src = p->data, *src_end = p->data + p->data_size; + while (src < src_end) { + int sz; + ff_amf_tag_contents(ctx, src, src_end); + sz = ff_amf_tag_size(src, src_end); + if (sz < 0) + break; + src += sz; + } + } else if (p->type == RTMP_PT_SERVER_BW){ + av_log(ctx, AV_LOG_DEBUG, "Server BW = %d\n", AV_RB32(p->data)); + } else if (p->type == RTMP_PT_CLIENT_BW){ + av_log(ctx, AV_LOG_DEBUG, "Client BW = %d\n", AV_RB32(p->data)); + } else if (p->type != RTMP_PT_AUDIO && p->type != RTMP_PT_VIDEO && p->type != RTMP_PT_METADATA) { + int i; + for (i = 0; i < p->data_size; i++) + av_log(ctx, AV_LOG_DEBUG, " %02X", p->data[i]); + av_log(ctx, AV_LOG_DEBUG, "\n"); + } +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rtmppkt.h b/src/add-ons/media/plugins/ffmpeg/libavformat/rtmppkt.h index b40f4fe061..23d4ebcd04 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/rtmppkt.h +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rtmppkt.h @@ -25,7 +25,7 @@ #include "avformat.h" /** maximum possible number of different RTMP channels */ -#define RTMP_CHANNELS 64 +#define RTMP_CHANNELS 65599 /** * channels used to for RTMP packets with different purposes (i.e. data, network @@ -34,6 +34,7 @@ enum RTMPChannel { RTMP_NETWORK_CHANNEL = 2, ///< channel for network-related messages (bandwidth report, ping, etc) RTMP_SYSTEM_CHANNEL, ///< channel for sending server control messages + RTMP_SOURCE_CHANNEL, ///< channel for sending a/v to server RTMP_VIDEO_CHANNEL = 8, ///< channel for video data RTMP_AUDIO_CHANNEL, ///< channel for audio data }; @@ -72,9 +73,10 @@ enum RTMPPacketSize { * structure for holding RTMP packets */ typedef struct RTMPPacket { - uint8_t channel_id; ///< RTMP channel ID (nothing to do with audio/video channels though) + int channel_id; ///< RTMP channel ID (nothing to do with audio/video channels though) RTMPPacketType type; ///< packet payload type - uint32_t timestamp; ///< packet full timestamp or timestamp increment to the previous one in milliseconds (latter only for media packets) + uint32_t timestamp; ///< packet full timestamp + uint32_t ts_delta; ///< timestamp increment to the previous one in milliseconds (latter only for media packets) uint32_t extra; ///< probably an additional channel ID used during streaming data uint8_t *data; ///< packet payload int data_size; ///< packet payload size @@ -108,7 +110,7 @@ void ff_rtmp_packet_destroy(RTMPPacket *pkt); * @param chunk_size current chunk size * @param prev_pkt previously read packet headers for all channels * (may be needed for restoring incomplete packet header) - * @return zero on success, negative value otherwise + * @return number of bytes read on success, negative value otherwise */ int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p, int chunk_size, RTMPPacket *prev_pkt); @@ -121,11 +123,19 @@ int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p, * @param chunk_size current chunk size * @param prev_pkt previously sent packet headers for all channels * (may be used for packet header compressing) - * @return zero on success, negative value otherwise + * @return number of bytes written on success, negative value otherwise */ int ff_rtmp_packet_write(URLContext *h, RTMPPacket *p, int chunk_size, RTMPPacket *prev_pkt); +/** + * Prints information and contents of RTMP packet. + * + * @param h output context + * @param p packet to dump + */ +void ff_rtmp_packet_dump(void *ctx, RTMPPacket *p); + /** * @defgroup amffuncs functions used to work with AMF format (which is also used in .flv) * @see amf_* funcs in libavformat/flvdec.c diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rtmpproto.c b/src/add-ons/media/plugins/ffmpeg/libavformat/rtmpproto.c index 470e6fef87..4edbffab62 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/rtmpproto.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rtmpproto.c @@ -20,7 +20,7 @@ */ /** - * @file libavformat/rtmpproto.c + * @file * RTMP protocol */ @@ -29,6 +29,7 @@ #include "libavutil/lfg.h" #include "libavutil/sha.h" #include "avformat.h" +#include "internal.h" #include "network.h" @@ -43,13 +44,19 @@ #define LOG_CONTEXT s #endif +//#define DEBUG + /** RTMP protocol handler state */ typedef enum { STATE_START, ///< client has not done anything yet STATE_HANDSHAKED, ///< client has performed handshake + STATE_RELEASING, ///< client releasing stream before publish it (for output) + STATE_FCPUBLISH, ///< client FCPublishing stream (for output) STATE_CONNECTING, ///< client connected to server successfully STATE_READY, ///< client has sent all needed commands and waits for server reply STATE_PLAYING, ///< client has started receiving multimedia data from server + STATE_PUBLISHING, ///< client has started sending multimedia data to server (for output) + STATE_STOPPED, ///< the broadcast has been stopped } ClientState; /** protocol handler context */ @@ -57,14 +64,18 @@ typedef struct RTMPContext { URLContext* stream; ///< TCP stream used in interactions with RTMP server RTMPPacket prev_pkt[2][RTMP_CHANNELS]; ///< packet history used when reading and sending packets int chunk_size; ///< size of the chunks RTMP packets are divided into + int is_input; ///< input/output flag char playpath[256]; ///< path to filename to play (with possible "mp4:" prefix) + char app[128]; ///< application ClientState state; ///< current state int main_channel_id; ///< an additional channel ID which is used for some invocations uint8_t* flv_data; ///< buffer with data for demuxer int flv_size; ///< current buffer size int flv_off; ///< number of bytes read from current buffer - uint32_t video_ts; ///< current video timestamp in milliseconds - uint32_t audio_ts; ///< current audio timestamp in milliseconds + RTMPPacket out_pkt; ///< rtmp packet, created from flv a/v or metadata (for output) + 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 } RTMPContext; #define PLAYER_KEY_OPEN_PART_LEN 30 ///< length of partial key used for first client digest signing @@ -94,43 +105,121 @@ static const uint8_t rtmp_server_key[] = { * Generates 'connect' call and sends it to the server. */ static void gen_connect(URLContext *s, RTMPContext *rt, const char *proto, - const char *host, int port, const char *app) + const char *host, int port) { RTMPPacket pkt; - uint8_t ver[32], *p; + uint8_t ver[64], *p; char tcurl[512]; - ff_rtmp_packet_create(&pkt, RTMP_VIDEO_CHANNEL, RTMP_PT_INVOKE, 0, 4096); + ff_rtmp_packet_create(&pkt, RTMP_SYSTEM_CHANNEL, RTMP_PT_INVOKE, 0, 4096); p = pkt.data; - snprintf(tcurl, sizeof(tcurl), "%s://%s:%d/%s", proto, host, port, app); + ff_url_join(tcurl, sizeof(tcurl), proto, NULL, host, port, "/%s", rt->app); ff_amf_write_string(&p, "connect"); ff_amf_write_number(&p, 1.0); ff_amf_write_object_start(&p); ff_amf_write_field_name(&p, "app"); - ff_amf_write_string(&p, app); + ff_amf_write_string(&p, rt->app); - snprintf(ver, sizeof(ver), "%s %d,%d,%d,%d", RTMP_CLIENT_PLATFORM, RTMP_CLIENT_VER1, - RTMP_CLIENT_VER2, RTMP_CLIENT_VER3, RTMP_CLIENT_VER4); + if (rt->is_input) { + snprintf(ver, sizeof(ver), "%s %d,%d,%d,%d", RTMP_CLIENT_PLATFORM, RTMP_CLIENT_VER1, + RTMP_CLIENT_VER2, RTMP_CLIENT_VER3, RTMP_CLIENT_VER4); + } else { + snprintf(ver, sizeof(ver), "FMLE/3.0 (compatible; %s)", LIBAVFORMAT_IDENT); + ff_amf_write_field_name(&p, "type"); + ff_amf_write_string(&p, "nonprivate"); + } ff_amf_write_field_name(&p, "flashVer"); ff_amf_write_string(&p, ver); ff_amf_write_field_name(&p, "tcUrl"); ff_amf_write_string(&p, tcurl); - ff_amf_write_field_name(&p, "fpad"); - ff_amf_write_bool(&p, 0); - ff_amf_write_field_name(&p, "capabilities"); - ff_amf_write_number(&p, 15.0); - ff_amf_write_field_name(&p, "audioCodecs"); - ff_amf_write_number(&p, 1639.0); - ff_amf_write_field_name(&p, "videoCodecs"); - ff_amf_write_number(&p, 252.0); - ff_amf_write_field_name(&p, "videoFunction"); - ff_amf_write_number(&p, 1.0); + if (rt->is_input) { + ff_amf_write_field_name(&p, "fpad"); + ff_amf_write_bool(&p, 0); + ff_amf_write_field_name(&p, "capabilities"); + ff_amf_write_number(&p, 15.0); + ff_amf_write_field_name(&p, "audioCodecs"); + ff_amf_write_number(&p, 1639.0); + ff_amf_write_field_name(&p, "videoCodecs"); + ff_amf_write_number(&p, 252.0); + ff_amf_write_field_name(&p, "videoFunction"); + ff_amf_write_number(&p, 1.0); + } ff_amf_write_object_end(&p); pkt.data_size = p - pkt.data; ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]); + ff_rtmp_packet_destroy(&pkt); +} + +/** + * Generates 'releaseStream' call and sends it to the server. It should make + * the server release some channel for media streams. + */ +static void gen_release_stream(URLContext *s, RTMPContext *rt) +{ + RTMPPacket pkt; + uint8_t *p; + + ff_rtmp_packet_create(&pkt, RTMP_SYSTEM_CHANNEL, RTMP_PT_INVOKE, 0, + 29 + strlen(rt->playpath)); + + av_log(LOG_CONTEXT, AV_LOG_DEBUG, "Releasing stream...\n"); + p = pkt.data; + ff_amf_write_string(&p, "releaseStream"); + ff_amf_write_number(&p, 2.0); + ff_amf_write_null(&p); + ff_amf_write_string(&p, rt->playpath); + + ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]); + ff_rtmp_packet_destroy(&pkt); +} + +/** + * Generates 'FCPublish' call and sends it to the server. It should make + * the server preapare for receiving media streams. + */ +static void gen_fcpublish_stream(URLContext *s, RTMPContext *rt) +{ + RTMPPacket pkt; + uint8_t *p; + + ff_rtmp_packet_create(&pkt, RTMP_SYSTEM_CHANNEL, RTMP_PT_INVOKE, 0, + 25 + strlen(rt->playpath)); + + av_log(LOG_CONTEXT, AV_LOG_DEBUG, "FCPublish stream...\n"); + p = pkt.data; + ff_amf_write_string(&p, "FCPublish"); + ff_amf_write_number(&p, 3.0); + ff_amf_write_null(&p); + ff_amf_write_string(&p, rt->playpath); + + ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]); + ff_rtmp_packet_destroy(&pkt); +} + +/** + * Generates 'FCUnpublish' call and sends it to the server. It should make + * the server destroy stream. + */ +static void gen_fcunpublish_stream(URLContext *s, RTMPContext *rt) +{ + RTMPPacket pkt; + uint8_t *p; + + ff_rtmp_packet_create(&pkt, RTMP_SYSTEM_CHANNEL, RTMP_PT_INVOKE, 0, + 27 + strlen(rt->playpath)); + + av_log(LOG_CONTEXT, AV_LOG_DEBUG, "UnPublishing stream...\n"); + p = pkt.data; + ff_amf_write_string(&p, "FCUnpublish"); + ff_amf_write_number(&p, 5.0); + ff_amf_write_null(&p); + ff_amf_write_string(&p, rt->playpath); + + ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]); + ff_rtmp_packet_destroy(&pkt); } /** @@ -143,17 +232,40 @@ static void gen_create_stream(URLContext *s, RTMPContext *rt) uint8_t *p; av_log(LOG_CONTEXT, AV_LOG_DEBUG, "Creating stream...\n"); - ff_rtmp_packet_create(&pkt, RTMP_VIDEO_CHANNEL, RTMP_PT_INVOKE, 0, 25); + ff_rtmp_packet_create(&pkt, RTMP_SYSTEM_CHANNEL, RTMP_PT_INVOKE, 0, 25); p = pkt.data; ff_amf_write_string(&p, "createStream"); - ff_amf_write_number(&p, 3.0); + ff_amf_write_number(&p, rt->is_input ? 3.0 : 4.0); ff_amf_write_null(&p); ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]); ff_rtmp_packet_destroy(&pkt); } + +/** + * Generates 'deleteStream' call and sends it to the server. It should make + * the server remove some channel for media streams. + */ +static void gen_delete_stream(URLContext *s, RTMPContext *rt) +{ + RTMPPacket pkt; + uint8_t *p; + + av_log(LOG_CONTEXT, AV_LOG_DEBUG, "Deleting stream...\n"); + ff_rtmp_packet_create(&pkt, RTMP_SYSTEM_CHANNEL, RTMP_PT_INVOKE, 0, 34); + + p = pkt.data; + ff_amf_write_string(&p, "deleteStream"); + ff_amf_write_number(&p, 0.0); + ff_amf_write_null(&p); + ff_amf_write_number(&p, rt->main_channel_id); + + ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]); + ff_rtmp_packet_destroy(&pkt); +} + /** * Generates 'play' call and sends it to the server, then pings the server * to start actual playing. @@ -165,7 +277,7 @@ static void gen_play(URLContext *s, RTMPContext *rt) av_log(LOG_CONTEXT, AV_LOG_DEBUG, "Sending play command for '%s'\n", rt->playpath); ff_rtmp_packet_create(&pkt, RTMP_VIDEO_CHANNEL, RTMP_PT_INVOKE, 0, - 29 + strlen(rt->playpath)); + 20 + strlen(rt->playpath)); pkt.extra = rt->main_channel_id; p = pkt.data; @@ -173,7 +285,6 @@ static void gen_play(URLContext *s, RTMPContext *rt) ff_amf_write_number(&p, 0.0); ff_amf_write_null(&p); ff_amf_write_string(&p, rt->playpath); - ff_amf_write_number(&p, 0.0); ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]); ff_rtmp_packet_destroy(&pkt); @@ -190,6 +301,30 @@ static void gen_play(URLContext *s, RTMPContext *rt) ff_rtmp_packet_destroy(&pkt); } +/** + * Generates 'publish' call and sends it to the server. + */ +static void gen_publish(URLContext *s, RTMPContext *rt) +{ + RTMPPacket pkt; + uint8_t *p; + + av_log(LOG_CONTEXT, AV_LOG_DEBUG, "Sending publish command for '%s'\n", rt->playpath); + ff_rtmp_packet_create(&pkt, RTMP_SOURCE_CHANNEL, RTMP_PT_INVOKE, 0, + 30 + strlen(rt->playpath)); + pkt.extra = rt->main_channel_id; + + p = pkt.data; + ff_amf_write_string(&p, "publish"); + ff_amf_write_number(&p, 0.0); + ff_amf_write_null(&p); + ff_amf_write_string(&p, rt->playpath); + ff_amf_write_string(&p, "live"); + + ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]); + ff_rtmp_packet_destroy(&pkt); +} + /** * Generates ping reply and sends it to the server. */ @@ -201,7 +336,22 @@ static void gen_pong(URLContext *s, RTMPContext *rt, RTMPPacket *ppkt) ff_rtmp_packet_create(&pkt, RTMP_NETWORK_CHANNEL, RTMP_PT_PING, ppkt->timestamp + 1, 6); p = pkt.data; bytestream_put_be16(&p, 7); - bytestream_put_be32(&p, AV_RB32(ppkt->data+2) + 1); + bytestream_put_be32(&p, AV_RB32(ppkt->data+2)); + ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]); + ff_rtmp_packet_destroy(&pkt); +} + +/** + * Generates report on bytes read so far and sends it to the server. + */ +static void gen_bytes_read(URLContext *s, RTMPContext *rt, uint32_t ts) +{ + RTMPPacket pkt; + uint8_t *p; + + ff_rtmp_packet_create(&pkt, RTMP_NETWORK_CHANNEL, RTMP_PT_BYTES_READ, ts, 4); + p = pkt.data; + bytestream_put_be32(&p, rt->bytes_read); ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]); ff_rtmp_packet_destroy(&pkt); } @@ -350,37 +500,42 @@ static int rtmp_handshake(URLContext *s, RTMPContext *rt) av_log(LOG_CONTEXT, AV_LOG_DEBUG, "Server version %d.%d.%d.%d\n", serverdata[5], serverdata[6], serverdata[7], serverdata[8]); - server_pos = rtmp_validate_digest(serverdata + 1, 772); - if (!server_pos) { - server_pos = rtmp_validate_digest(serverdata + 1, 8); + if (rt->is_input && serverdata[5] >= 3) { + server_pos = rtmp_validate_digest(serverdata + 1, 772); if (!server_pos) { - av_log(LOG_CONTEXT, AV_LOG_ERROR, "Server response validating failed\n"); + server_pos = rtmp_validate_digest(serverdata + 1, 8); + if (!server_pos) { + av_log(LOG_CONTEXT, AV_LOG_ERROR, "Server response validating failed\n"); + return -1; + } + } + + rtmp_calc_digest(tosend + 1 + client_pos, 32, 0, + rtmp_server_key, sizeof(rtmp_server_key), + digest); + rtmp_calc_digest(clientdata, RTMP_HANDSHAKE_PACKET_SIZE-32, 0, + digest, 32, + digest); + if (memcmp(digest, clientdata + RTMP_HANDSHAKE_PACKET_SIZE - 32, 32)) { + av_log(LOG_CONTEXT, AV_LOG_ERROR, "Signature mismatch\n"); return -1; } + + for (i = 0; i < RTMP_HANDSHAKE_PACKET_SIZE; i++) + tosend[i] = av_lfg_get(&rnd) >> 24; + rtmp_calc_digest(serverdata + 1 + server_pos, 32, 0, + rtmp_player_key, sizeof(rtmp_player_key), + digest); + rtmp_calc_digest(tosend, RTMP_HANDSHAKE_PACKET_SIZE - 32, 0, + digest, 32, + tosend + RTMP_HANDSHAKE_PACKET_SIZE - 32); + + // write reply back to the server + url_write(rt->stream, tosend, RTMP_HANDSHAKE_PACKET_SIZE); + } else { + url_write(rt->stream, serverdata+1, RTMP_HANDSHAKE_PACKET_SIZE); } - rtmp_calc_digest(tosend + 1 + client_pos, 32, 0, - rtmp_server_key, sizeof(rtmp_server_key), - digest); - rtmp_calc_digest(clientdata, RTMP_HANDSHAKE_PACKET_SIZE-32, 0, - digest, 32, - digest); - if (memcmp(digest, clientdata + RTMP_HANDSHAKE_PACKET_SIZE - 32, 32)) { - av_log(LOG_CONTEXT, AV_LOG_ERROR, "Signature mismatch\n"); - return -1; - } - - for (i = 0; i < RTMP_HANDSHAKE_PACKET_SIZE; i++) - tosend[i] = av_lfg_get(&rnd) >> 24; - rtmp_calc_digest(serverdata + 1 + server_pos, 32, 0, - rtmp_player_key, sizeof(rtmp_player_key), - digest); - rtmp_calc_digest(tosend, RTMP_HANDSHAKE_PACKET_SIZE - 32, 0, - digest, 32, - tosend + RTMP_HANDSHAKE_PACKET_SIZE - 32); - - // write reply back to the server - url_write(rt->stream, tosend, RTMP_HANDSHAKE_PACKET_SIZE); return 0; } @@ -395,6 +550,10 @@ static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt) int i, t; const uint8_t *data_end = pkt->data + pkt->data_size; +#ifdef DEBUG + ff_rtmp_packet_dump(LOG_CONTEXT, pkt); +#endif + switch (pkt->type) { case RTMP_PT_CHUNK_SIZE: if (pkt->data_size != 4) { @@ -402,6 +561,8 @@ static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt) "Chunk size change packet is not 4 bytes long (%d)\n", pkt->data_size); return -1; } + if (!rt->is_input) + ff_rtmp_packet_write(rt->stream, pkt, rt->chunk_size, rt->prev_pkt[1]); rt->chunk_size = AV_RB32(pkt->data); if (rt->chunk_size <= 0) { av_log(LOG_CONTEXT, AV_LOG_ERROR, "Incorrect chunk size %d\n", rt->chunk_size); @@ -414,6 +575,16 @@ static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt) if (t == 6) gen_pong(s, rt, pkt); break; + case RTMP_PT_CLIENT_BW: + if (pkt->data_size < 4) { + av_log(LOG_CONTEXT, AV_LOG_ERROR, + "Client bandwidth report packet is less than 4 bytes long (%d)\n", + pkt->data_size); + return -1; + } + av_log(LOG_CONTEXT, AV_LOG_DEBUG, "Client bandwidth = %d\n", AV_RB32(pkt->data)); + rt->client_report_size = AV_RB32(pkt->data) >> 1; + break; case RTMP_PT_INVOKE: //TODO: check for the messages sent for wrong state? if (!memcmp(pkt->data, "\002\000\006_error", 9)) { @@ -426,9 +597,29 @@ static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt) } else if (!memcmp(pkt->data, "\002\000\007_result", 10)) { switch (rt->state) { case STATE_HANDSHAKED: + if (!rt->is_input) { + gen_release_stream(s, rt); + gen_fcpublish_stream(s, rt); + rt->state = STATE_RELEASING; + } else { + rt->state = STATE_CONNECTING; + } gen_create_stream(s, rt); + break; + case STATE_FCPUBLISH: rt->state = STATE_CONNECTING; break; + case STATE_RELEASING: + rt->state = STATE_FCPUBLISH; + /* hack for Wowza Media Server, it does not send result for + * releaseStream and FCPublish calls */ + if (!pkt->data[10]) { + int pkt_id = (int) av_int2dbl(AV_RB64(pkt->data + 11)); + if (pkt_id == 4) + rt->state = STATE_CONNECTING; + } + if (rt->state != STATE_CONNECTING) + break; case STATE_CONNECTING: //extract a number from the result if (pkt->data[10] || pkt->data[19] != 5 || pkt->data[20]) { @@ -436,14 +627,17 @@ static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt) } else { rt->main_channel_id = (int) av_int2dbl(AV_RB64(pkt->data + 21)); } - gen_play(s, rt); + if (rt->is_input) { + gen_play(s, rt); + } else { + gen_publish(s, rt); + } rt->state = STATE_READY; break; } } else if (!memcmp(pkt->data, "\002\000\010onStatus", 11)) { const uint8_t* ptr = pkt->data + 11; uint8_t tmpstr[256]; - int t; for (i = 0; i < 2; i++) { t = ff_amf_tag_size(ptr, data_end); @@ -461,10 +655,10 @@ static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt) } t = ff_amf_get_field_value(ptr, data_end, "code", tmpstr, sizeof(tmpstr)); - if (!t && !strcmp(tmpstr, "NetStream.Play.Start")) { - rt->state = STATE_PLAYING; - return 0; - } + if (!t && !strcmp(tmpstr, "NetStream.Play.Start")) rt->state = STATE_PLAYING; + if (!t && !strcmp(tmpstr, "NetStream.Play.Stop")) rt->state = STATE_STOPPED; + if (!t && !strcmp(tmpstr, "NetStream.Play.UnpublishNotify")) rt->state = STATE_STOPPED; + if (!t && !strcmp(tmpstr, "NetStream.Publish.Start")) rt->state = STATE_PUBLISHING; } break; } @@ -476,50 +670,62 @@ static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt) * there is some significant data (media data or expected status notification). * * @param s reading context - * @param for_header non-zero value tells function to work until it gets notification from the server that playing has been started, otherwise function will work until some media data is received (or an error happens) + * @param for_header non-zero value tells function to work until it + * gets notification from the server that playing has been started, + * otherwise function will work until some media data is received (or + * an error happens) * @return 0 for successful operation, negative value in case of error */ static int get_packet(URLContext *s, int for_header) { RTMPContext *rt = s->priv_data; int ret; + uint8_t *p; + const uint8_t *next; + uint32_t data_size; + uint32_t ts, cts, pts=0; - for(;;) { + if (rt->state == STATE_STOPPED) + return AVERROR_EOF; + + for (;;) { RTMPPacket rpkt; if ((ret = ff_rtmp_packet_read(rt->stream, &rpkt, - rt->chunk_size, rt->prev_pkt[0])) != 0) { - if (ret > 0) { + rt->chunk_size, rt->prev_pkt[0])) <= 0) { + if (ret == 0) { return AVERROR(EAGAIN); } else { return AVERROR(EIO); } } + rt->bytes_read += ret; + if (rt->bytes_read > rt->last_bytes_read + rt->client_report_size) { + av_log(LOG_CONTEXT, AV_LOG_DEBUG, "Sending bytes read report\n"); + gen_bytes_read(s, rt, rpkt.timestamp + 1); + rt->last_bytes_read = rt->bytes_read; + } ret = rtmp_parse_result(s, rt, &rpkt); if (ret < 0) {//serious error in current packet ff_rtmp_packet_destroy(&rpkt); return -1; } - if (for_header && rt->state == STATE_PLAYING) { + if (rt->state == STATE_STOPPED) { + ff_rtmp_packet_destroy(&rpkt); + return AVERROR_EOF; + } + if (for_header && (rt->state == STATE_PLAYING || rt->state == STATE_PUBLISHING)) { ff_rtmp_packet_destroy(&rpkt); return 0; } - if (!rpkt.data_size) { + if (!rpkt.data_size || !rt->is_input) { ff_rtmp_packet_destroy(&rpkt); continue; } if (rpkt.type == RTMP_PT_VIDEO || rpkt.type == RTMP_PT_AUDIO || - rpkt.type == RTMP_PT_NOTIFY) { - uint8_t *p; - uint32_t ts = rpkt.timestamp; + (rpkt.type == RTMP_PT_NOTIFY && !memcmp("\002\000\012onMetaData", rpkt.data, 13))) { + ts = rpkt.timestamp; - if (rpkt.type == RTMP_PT_VIDEO) { - rt->video_ts += rpkt.timestamp; - ts = rt->video_ts; - } else if (rpkt.type == RTMP_PT_AUDIO) { - rt->audio_ts += rpkt.timestamp; - ts = rt->audio_ts; - } // generate packet header and put data into buffer for FLV demuxer rt->flv_off = 0; rt->flv_size = rpkt.data_size + 15; @@ -538,6 +744,23 @@ static int get_packet(URLContext *s, int for_header) rt->flv_off = 0; rt->flv_size = rpkt.data_size; rt->flv_data = av_realloc(rt->flv_data, rt->flv_size); + /* rewrite timestamps */ + next = rpkt.data; + ts = rpkt.timestamp; + while (next - rpkt.data < rpkt.data_size - 11) { + next++; + data_size = bytestream_get_be24(&next); + p=next; + cts = bytestream_get_be24(&next); + cts |= bytestream_get_byte(&next); + if (pts==0) + pts=cts; + ts += cts - pts; + pts = cts; + bytestream_put_be24(&p, ts); + bytestream_put_byte(&p, ts >> 24); + next += data_size + 3 + 4; + } memcpy(rt->flv_data, rpkt.data, rpkt.data_size); ff_rtmp_packet_destroy(&rpkt); return 0; @@ -551,6 +774,16 @@ static int rtmp_close(URLContext *h) { RTMPContext *rt = h->priv_data; + if (!rt->is_input) { + rt->flv_data = NULL; + if (rt->out_pkt.data_size) + ff_rtmp_packet_destroy(&rt->out_pkt); + if (rt->state > STATE_FCPUBLISH) + gen_fcunpublish_stream(h, rt); + } + if (rt->state > STATE_HANDSHAKED) + gen_delete_stream(h, rt); + av_freep(&rt->flv_data); url_close(rt->stream); av_free(rt); @@ -569,80 +802,89 @@ static int rtmp_close(URLContext *h) static int rtmp_open(URLContext *s, const char *uri, int flags) { RTMPContext *rt; - char proto[8], hostname[256], path[1024], app[128], *fname; + char proto[8], hostname[256], path[1024], *fname; uint8_t buf[2048]; - int port, is_input; + int port; int ret; - is_input = !(flags & URL_WRONLY); - rt = av_mallocz(sizeof(RTMPContext)); if (!rt) return AVERROR(ENOMEM); s->priv_data = rt; + rt->is_input = !(flags & URL_WRONLY); - url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname), &port, - path, sizeof(path), s->filename); + ff_url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname), &port, + path, sizeof(path), s->filename); if (port < 0) port = RTMP_DEFAULT_PORT; - snprintf(buf, sizeof(buf), "tcp://%s:%d", hostname, port); + ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL); - if (url_open(&rt->stream, buf, URL_RDWR) < 0) + if (url_open(&rt->stream, buf, URL_RDWR) < 0) { + av_log(LOG_CONTEXT, AV_LOG_ERROR, "Cannot open connection %s\n", buf); goto fail; + } - if (!is_input) { - av_log(LOG_CONTEXT, AV_LOG_ERROR, "RTMP output is not supported yet.\n"); - goto fail; + rt->state = STATE_START; + if (rtmp_handshake(s, rt)) + return -1; + + rt->chunk_size = 128; + rt->state = STATE_HANDSHAKED; + //extract "app" part from path + if (!strncmp(path, "/ondemand/", 10)) { + fname = path + 10; + memcpy(rt->app, "ondemand", 9); } else { - rt->state = STATE_START; - if (rtmp_handshake(s, rt)) - return -1; - - rt->chunk_size = 128; - rt->state = STATE_HANDSHAKED; - //extract "app" part from path - if (!strncmp(path, "/ondemand/", 10)) { - fname = path + 10; - memcpy(app, "ondemand", 9); + char *p = strchr(path + 1, '/'); + if (!p) { + fname = path + 1; + rt->app[0] = '\0'; } else { - char *p = strchr(path + 1, '/'); - if (!p) { - fname = path + 1; - app[0] = '\0'; + char *c = strchr(p + 1, ':'); + fname = strchr(p + 1, '/'); + if (!fname || c < fname) { + fname = p + 1; + av_strlcpy(rt->app, path + 1, p - path); } else { - fname = strchr(p + 1, '/'); - if (!fname) { - fname = p + 1; - av_strlcpy(app, path + 1, p - path); - } else { - fname++; - av_strlcpy(app, path + 1, fname - path - 1); - } + fname++; + av_strlcpy(rt->app, path + 1, fname - path - 1); } } - if (!strcmp(fname + strlen(fname) - 4, ".f4v") || - !strcmp(fname + strlen(fname) - 4, ".mp4")) { - memcpy(rt->playpath, "mp4:", 5); - } else { - rt->playpath[0] = 0; - } - strncat(rt->playpath, fname, sizeof(rt->playpath) - 5); + } + if (!strchr(fname, ':') && + (!strcmp(fname + strlen(fname) - 4, ".f4v") || + !strcmp(fname + strlen(fname) - 4, ".mp4"))) { + memcpy(rt->playpath, "mp4:", 5); + } else { + rt->playpath[0] = 0; + } + strncat(rt->playpath, fname, sizeof(rt->playpath) - 5); - av_log(LOG_CONTEXT, AV_LOG_DEBUG, "Proto = %s, path = %s, app = %s, fname = %s\n", - proto, path, app, rt->playpath); - gen_connect(s, rt, proto, hostname, port, app); + rt->client_report_size = 1048576; + rt->bytes_read = 0; + rt->last_bytes_read = 0; - do { - ret = get_packet(s, 1); - } while (ret == EAGAIN); - if (ret < 0) - goto fail; + av_log(LOG_CONTEXT, AV_LOG_DEBUG, "Proto = %s, path = %s, app = %s, fname = %s\n", + proto, path, rt->app, rt->playpath); + gen_connect(s, rt, proto, hostname, port); + + do { + ret = get_packet(s, 1); + } while (ret == EAGAIN); + if (ret < 0) + goto fail; + + if (rt->is_input) { // generate FLV header for demuxer rt->flv_size = 13; rt->flv_data = av_realloc(rt->flv_data, rt->flv_size); rt->flv_off = 0; memcpy(rt->flv_data, "FLV\1\5\0\0\0\011\0\0\0\0", rt->flv_size); + } else { + rt->flv_size = 0; + rt->flv_data = NULL; + rt->flv_off = 0; } s->max_packet_size = url_get_max_packet_size(rt->stream); @@ -682,7 +924,68 @@ static int rtmp_read(URLContext *s, uint8_t *buf, int size) static int rtmp_write(URLContext *h, uint8_t *buf, int size) { - return 0; + RTMPContext *rt = h->priv_data; + int size_temp = size; + int pktsize, pkttype; + uint32_t ts; + const uint8_t *buf_temp = buf; + + if (size < 11) { + av_log(LOG_CONTEXT, 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; + } + + 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; + rt->flv_size = pktsize; + + //force 12bytes header + if (((pkttype == RTMP_PT_VIDEO || pkttype == RTMP_PT_AUDIO) && ts == 0) || + pkttype == RTMP_PT_NOTIFY) { + if (pkttype == RTMP_PT_NOTIFY) + pktsize += 16; + rt->prev_pkt[1][RTMP_SOURCE_CHANNEL].channel_id = 0; + } + + //this can be a big packet, it's better to send it right here + ff_rtmp_packet_create(&rt->out_pkt, RTMP_SOURCE_CHANNEL, pkttype, ts, pktsize); + rt->out_pkt.extra = rt->main_channel_id; + rt->flv_data = rt->out_pkt.data; + + if (pkttype == RTMP_PT_NOTIFY) + ff_amf_write_string(&rt->flv_data, "@setDataFrame"); + } + + 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; + } else { + bytestream_get_buffer(&buf_temp, rt->flv_data + rt->flv_off, 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); + + 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; + } + } while (buf_temp - buf < size_temp); + return size; } URLProtocol rtmp_protocol = { diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rtp.c b/src/add-ons/media/plugins/ffmpeg/libavformat/rtp.c index c4fb24a16f..a8dcfd79de 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/rtp.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rtp.c @@ -19,12 +19,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libavcodec/get_bits.h" #include "avformat.h" -#include -#include "network.h" - #include "rtp.h" //#define DEBUG @@ -39,39 +35,39 @@ static const struct { int pt; const char enc_name[6]; - enum CodecType codec_type; + enum AVMediaType codec_type; enum CodecID codec_id; int clock_rate; int audio_channels; } AVRtpPayloadTypes[]= { - {0, "PCMU", CODEC_TYPE_AUDIO, CODEC_ID_PCM_MULAW, 8000, 1}, - {3, "GSM", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1}, - {4, "G723", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1}, - {5, "DVI4", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1}, - {6, "DVI4", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 16000, 1}, - {7, "LPC", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1}, - {8, "PCMA", CODEC_TYPE_AUDIO, CODEC_ID_PCM_ALAW, 8000, 1}, - {9, "G722", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1}, - {10, "L16", CODEC_TYPE_AUDIO, CODEC_ID_PCM_S16BE, 44100, 2}, - {11, "L16", CODEC_TYPE_AUDIO, CODEC_ID_PCM_S16BE, 44100, 1}, - {12, "QCELP", CODEC_TYPE_AUDIO, CODEC_ID_QCELP, 8000, 1}, - {13, "CN", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1}, - {14, "MPA", CODEC_TYPE_AUDIO, CODEC_ID_MP2, -1, -1}, - {14, "MPA", CODEC_TYPE_AUDIO, CODEC_ID_MP3, -1, -1}, - {15, "G728", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1}, - {16, "DVI4", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 11025, 1}, - {17, "DVI4", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 22050, 1}, - {18, "G729", CODEC_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1}, - {25, "CelB", CODEC_TYPE_VIDEO, CODEC_ID_NONE, 90000, -1}, - {26, "JPEG", CODEC_TYPE_VIDEO, CODEC_ID_MJPEG, 90000, -1}, - {28, "nv", CODEC_TYPE_VIDEO, CODEC_ID_NONE, 90000, -1}, - {31, "H261", CODEC_TYPE_VIDEO, CODEC_ID_H261, 90000, -1}, - {32, "MPV", CODEC_TYPE_VIDEO, CODEC_ID_MPEG1VIDEO, 90000, -1}, - {32, "MPV", CODEC_TYPE_VIDEO, CODEC_ID_MPEG2VIDEO, 90000, -1}, - {33, "MP2T", CODEC_TYPE_DATA, CODEC_ID_MPEG2TS, 90000, -1}, - {34, "H263", CODEC_TYPE_VIDEO, CODEC_ID_H263, 90000, -1}, - {-1, "", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1} + {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}, + {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}, + {8, "PCMA", AVMEDIA_TYPE_AUDIO, CODEC_ID_PCM_ALAW, 8000, 1}, + {9, "G722", AVMEDIA_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1}, + {10, "L16", AVMEDIA_TYPE_AUDIO, CODEC_ID_PCM_S16BE, 44100, 2}, + {11, "L16", AVMEDIA_TYPE_AUDIO, CODEC_ID_PCM_S16BE, 44100, 1}, + {12, "QCELP", AVMEDIA_TYPE_AUDIO, CODEC_ID_QCELP, 8000, 1}, + {13, "CN", AVMEDIA_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1}, + {14, "MPA", AVMEDIA_TYPE_AUDIO, CODEC_ID_MP2, -1, -1}, + {14, "MPA", AVMEDIA_TYPE_AUDIO, CODEC_ID_MP3, -1, -1}, + {15, "G728", AVMEDIA_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1}, + {16, "DVI4", AVMEDIA_TYPE_AUDIO, CODEC_ID_NONE, 11025, 1}, + {17, "DVI4", AVMEDIA_TYPE_AUDIO, CODEC_ID_NONE, 22050, 1}, + {18, "G729", AVMEDIA_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1}, + {25, "CelB", AVMEDIA_TYPE_VIDEO, CODEC_ID_NONE, 90000, -1}, + {26, "JPEG", AVMEDIA_TYPE_VIDEO, CODEC_ID_MJPEG, 90000, -1}, + {28, "nv", AVMEDIA_TYPE_VIDEO, CODEC_ID_NONE, 90000, -1}, + {31, "H261", AVMEDIA_TYPE_VIDEO, CODEC_ID_H261, 90000, -1}, + {32, "MPV", AVMEDIA_TYPE_VIDEO, CODEC_ID_MPEG1VIDEO, 90000, -1}, + {32, "MPV", AVMEDIA_TYPE_VIDEO, CODEC_ID_MPEG2VIDEO, 90000, -1}, + {33, "MP2T", AVMEDIA_TYPE_DATA, CODEC_ID_MPEG2TS, 90000, -1}, + {34, "H263", AVMEDIA_TYPE_VIDEO, CODEC_ID_H263, 90000, -1}, + {-1, "", AVMEDIA_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1} }; int ff_rtp_get_codec_info(AVCodecContext *codec, int payload_type) @@ -122,7 +118,7 @@ const char *ff_rtp_enc_name(int payload_type) return ""; } -enum CodecID ff_rtp_codec_id(const char *buf, enum CodecType codec_type) +enum CodecID ff_rtp_codec_id(const char *buf, enum AVMediaType codec_type) { int i; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rtp.h b/src/add-ons/media/plugins/ffmpeg/libavformat/rtp.h index 80081ac9eb..7834f9deb8 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/rtp.h +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rtp.h @@ -66,7 +66,7 @@ const char *ff_rtp_enc_name(int payload_type); * @return In case of unknown encoding name, CODEC_ID_NONE is returned; * otherwise, the codec id is returned */ -enum CodecID ff_rtp_codec_id(const char *buf, enum CodecType codec_type); +enum CodecID ff_rtp_codec_id(const char *buf, enum AVMediaType codec_type); #define RTP_PT_PRIVATE 96 #define RTP_VERSION 2 diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec.c b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec.c index 48995e7de4..0d2df59a75 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec.c @@ -30,9 +30,11 @@ #include "network.h" #include "rtpdec.h" -#include "rtp_asf.h" -#include "rtp_h264.h" -#include "rtp_vorbis.h" +#include "rtpdec_amr.h" +#include "rtpdec_asf.h" +#include "rtpdec_h263.h" +#include "rtpdec_h264.h" +#include "rtpdec_xiph.h" //#define DEBUG @@ -48,8 +50,8 @@ /* statistics functions */ RTPDynamicProtocolHandler *RTPFirstDynamicPayloadHandler= NULL; -static RTPDynamicProtocolHandler mp4v_es_handler= {"MP4V-ES", CODEC_TYPE_VIDEO, CODEC_ID_MPEG4}; -static RTPDynamicProtocolHandler mpeg4_generic_handler= {"mpeg4-generic", CODEC_TYPE_AUDIO, CODEC_ID_AAC}; +static RTPDynamicProtocolHandler mp4v_es_handler= {"MP4V-ES", AVMEDIA_TYPE_VIDEO, CODEC_ID_MPEG4}; +static RTPDynamicProtocolHandler mpeg4_generic_handler= {"mpeg4-generic", AVMEDIA_TYPE_AUDIO, CODEC_ID_AAC}; void ff_register_dynamic_payload_handler(RTPDynamicProtocolHandler *handler) { @@ -61,8 +63,13 @@ void av_register_rtp_dynamic_payload_handlers(void) { ff_register_dynamic_payload_handler(&mp4v_es_handler); ff_register_dynamic_payload_handler(&mpeg4_generic_handler); + ff_register_dynamic_payload_handler(&ff_amr_nb_dynamic_handler); + ff_register_dynamic_payload_handler(&ff_amr_wb_dynamic_handler); + ff_register_dynamic_payload_handler(&ff_h263_1998_dynamic_handler); + ff_register_dynamic_payload_handler(&ff_h263_2000_dynamic_handler); ff_register_dynamic_payload_handler(&ff_h264_dynamic_handler); ff_register_dynamic_payload_handler(&ff_vorbis_dynamic_handler); + ff_register_dynamic_payload_handler(&ff_theora_dynamic_handler); ff_register_dynamic_payload_handler(&ff_ms_rtp_asf_pfv_handler); ff_register_dynamic_payload_handler(&ff_ms_rtp_asf_pfa_handler); @@ -267,6 +274,45 @@ int rtp_check_and_send_back_rr(RTPDemuxContext *s, int count) return 0; } +void rtp_send_punch_packets(URLContext* rtp_handle) +{ + ByteIOContext *pb; + uint8_t *buf; + int len; + + /* Send a small RTP packet */ + if (url_open_dyn_buf(&pb) < 0) + return; + + put_byte(pb, (RTP_VERSION << 6)); + put_byte(pb, 0); /* Payload type */ + put_be16(pb, 0); /* Seq */ + put_be32(pb, 0); /* Timestamp */ + put_be32(pb, 0); /* SSRC */ + + put_flush_packet(pb); + len = url_close_dyn_buf(pb, &buf); + if ((len > 0) && buf) + url_write(rtp_handle, buf, len); + av_free(buf); + + /* Send a minimal RTCP RR */ + if (url_open_dyn_buf(&pb) < 0) + return; + + put_byte(pb, (RTP_VERSION << 6)); + put_byte(pb, 201); /* receiver report */ + put_be16(pb, 1); /* length in words - 1 */ + put_be32(pb, 0); /* our own SSRC */ + + put_flush_packet(pb); + len = url_close_dyn_buf(pb, &buf); + if ((len > 0) && buf) + url_write(rtp_handle, buf, len); + av_free(buf); +} + + /** * open a new RTP parse context for stream 'st'. 'st' can be NULL for * MPEG2TS streams to indicate that they should be demuxed inside the @@ -288,7 +334,7 @@ RTPDemuxContext *rtp_parse_open(AVFormatContext *s1, AVStream *st, URLContext *r s->rtp_payload_data = rtp_payload_data; rtp_init_statistics(&s->statistics, 0); // do we know the initial sequence from sdp? if (!strcmp(ff_rtp_enc_name(payload_type), "MP2T")) { - s->ts = mpegts_parse_open(s->ic); + s->ts = ff_mpegts_parse_open(s->ic); if (s->ts == NULL) { av_free(s); return NULL; @@ -301,11 +347,12 @@ RTPDemuxContext *rtp_parse_open(AVFormatContext *s1, AVStream *st, URLContext *r case CODEC_ID_MP2: case CODEC_ID_MP3: case CODEC_ID_MPEG4: + case CODEC_ID_H263: case CODEC_ID_H264: st->need_parsing = AVSTREAM_PARSE_FULL; break; default: - if (st->codec->codec_type == CODEC_TYPE_AUDIO) { + if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { av_set_pts_info(st, 32, 1, st->codec->sample_rate); } break; @@ -356,7 +403,11 @@ static int rtp_parse_mp4_au(RTPDemuxContext *s, const uint8_t *buf) return -1; infos->nb_au_headers = au_headers_length / au_header_size; - infos->au_headers = av_malloc(sizeof(struct AUHeaders) * infos->nb_au_headers); + if (!infos->au_headers || infos->au_headers_allocated < infos->nb_au_headers) { + av_free(infos->au_headers); + infos->au_headers = av_malloc(sizeof(struct AUHeaders) * infos->nb_au_headers); + infos->au_headers_allocated = infos->nb_au_headers; + } /* XXX: We handle multiple AU Section as only one (need to fix this for interleaving) In my test, the FAAD decoder does not behave correctly when sending each AU one by one @@ -386,7 +437,7 @@ static void finalize_packet(RTPDemuxContext *s, AVPacket *pkt, uint32_t timestam delta_timestamp = timestamp - s->last_rtcp_timestamp; /* convert to the PTS timebase */ addend = av_rescale(s->last_rtcp_ntp_time - s->first_rtcp_ntp_time, s->st->time_base.den, (uint64_t)s->st->time_base.num << 32); - pkt->pts = addend + delta_timestamp; + pkt->pts = s->range_start_offset + addend + delta_timestamp; } } @@ -420,7 +471,7 @@ int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt, // TODO: Move to a dynamic packet handler (like above) if (s->read_buf_index >= s->read_buf_size) return -1; - ret = mpegts_parse_packet(s->ts, pkt, s->buf + s->read_buf_index, + ret = ff_mpegts_parse_packet(s->ts, pkt, s->buf + s->read_buf_index, s->read_buf_size - s->read_buf_index); if (ret < 0) return -1; @@ -469,7 +520,7 @@ int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt, if (!st) { /* specific MPEG2TS demux support */ - ret = mpegts_parse_packet(s->ts, pkt, buf, len); + ret = ff_mpegts_parse_packet(s->ts, pkt, buf, len); if (ret < 0) return -1; if (ret < len) { @@ -486,6 +537,7 @@ int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt, // at this point, the RTP header has been stripped; This is ASSUMING that there is only 1 CSRC, which in't wise. switch(st->codec->codec_id) { case CODEC_ID_MP2: + case CODEC_ID_MP3: /* better than nothing: skip mpeg audio RTP header */ if (len <= 4) return -1; @@ -554,8 +606,10 @@ int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt, void rtp_parse_close(RTPDemuxContext *s) { // TODO: fold this into the protocol specific data fields. + av_free(s->rtp_payload_data->mode); + av_free(s->rtp_payload_data->au_headers); if (!strcmp(ff_rtp_enc_name(s->payload_type), "MP2T")) { - mpegts_parse_close(s->ts); + ff_mpegts_parse_close(s->ts); } av_free(s); } diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec.h b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec.h index 1a243f89c8..477ab723f4 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec.h +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec.h @@ -48,6 +48,7 @@ typedef struct rtp_payload_data int rap_flag; int streamstate; } *au_headers; + int au_headers_allocated; int nb_au_headers; int au_headers_length_bytes; int cur_au_index; @@ -66,13 +67,30 @@ void rtp_parse_set_dynamic_protocol(RTPDemuxContext *s, PayloadContext *ctx, int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt, const uint8_t *buf, int len); void rtp_parse_close(RTPDemuxContext *s); - +#if (LIBAVFORMAT_VERSION_MAJOR <= 53) int rtp_get_local_port(URLContext *h); +#endif +int rtp_get_local_rtp_port(URLContext *h); +int rtp_get_local_rtcp_port(URLContext *h); + int rtp_set_remote_url(URLContext *h, const char *uri); #if (LIBAVFORMAT_VERSION_MAJOR <= 52) void rtp_get_file_handles(URLContext *h, int *prtp_fd, int *prtcp_fd); #endif +/** + * Send a dummy packet on both port pairs to set up the connection + * state in potential NAT routers, so that we're able to receive + * packets. + * + * Note, this only works if the NAT router doesn't remap ports. This + * isn't a standardized procedure, but it works in many cases in practice. + * + * 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); + /** * 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 @@ -119,7 +137,7 @@ typedef int (*DynamicPayloadPacketHandlerProc) (AVFormatContext *ctx, struct RTPDynamicProtocolHandler_s { // fields from AVRtpDynamicPayloadType_s const char enc_name[50]; /* XXX: still why 50 ? ;-) */ - enum CodecType codec_type; + enum AVMediaType codec_type; enum CodecID codec_id; // may be null @@ -127,7 +145,7 @@ struct RTPDynamicProtocolHandler_s { int st_index, PayloadContext *priv_data, const char *line); ///< Parse the a= line from the sdp field - PayloadContext *(*open) (); ///< allocate any data needed by the rtp parsing for this dynamic data. + PayloadContext *(*open) (void); ///< allocate any data needed by the rtp parsing for this dynamic data. void (*close)(PayloadContext *protocol_data); ///< free any data needed by the rtp parsing for this dynamic data. DynamicPayloadPacketHandlerProc parse_packet; ///< parse handler for this dynamic packet. @@ -144,6 +162,7 @@ struct RTPDemuxContext { uint32_t timestamp; uint32_t base_timestamp; uint32_t cur_timestamp; + int64_t range_start_offset; int max_payload_size; struct MpegTSContext *ts; /* only used for MP2T payloads */ int read_buf_index; @@ -180,7 +199,7 @@ struct RTPDemuxContext { extern RTPDynamicProtocolHandler *RTPFirstDynamicPayloadHandler; void ff_register_dynamic_payload_handler(RTPDynamicProtocolHandler *handler); -int rtsp_next_attr_and_value(const char **p, char *attr, int attr_size, char *value, int value_size); ///< from rtsp.c, but used by rtp dynamic protocol handlers. +int ff_rtsp_next_attr_and_value(const char **p, char *attr, int attr_size, char *value, int value_size); ///< from rtsp.c, but used by rtp dynamic protocol handlers. void av_register_rtp_dynamic_payload_handlers(void); diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_amr.c b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_amr.c new file mode 100644 index 0000000000..a7b36c7ab7 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_amr.c @@ -0,0 +1,186 @@ +/* + * RTP AMR Depacketizer, RFC 3267 + * Copyright (c) 2010 Martin Storsjo + * + * 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 "rtpdec_amr.h" +#include "libavutil/avstring.h" + +static const uint8_t frame_sizes_nb[16] = { + 12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0 +}; +static const uint8_t frame_sizes_wb[16] = { + 17, 23, 32, 36, 40, 46, 50, 58, 60, 5, 5, 0, 0, 0, 0, 0 +}; + +static int amr_handle_packet(AVFormatContext *ctx, + PayloadContext *data, + AVStream *st, + AVPacket * pkt, + uint32_t * timestamp, + const uint8_t * buf, + int len, int flags) +{ + const uint8_t *frame_sizes = NULL; + int frames; + int i; + const uint8_t *speech_data; + uint8_t *ptr; + + if (st->codec->codec_id == CODEC_ID_AMR_NB) { + frame_sizes = frame_sizes_nb; + } else if (st->codec->codec_id == CODEC_ID_AMR_WB) { + frame_sizes = frame_sizes_wb; + } else { + av_log(ctx, AV_LOG_ERROR, "Bad codec ID\n"); + return AVERROR_INVALIDDATA; + } + + if (st->codec->channels != 1) { + av_log(ctx, AV_LOG_ERROR, "Only mono AMR is supported\n"); + return AVERROR_INVALIDDATA; + } + + /* The AMR RTP packet consists of one header byte, followed + * by one TOC byte for each AMR frame in the packet, followed + * by the speech data for all the AMR frames. + * + * The header byte contains only a codec mode request, for + * requesting what kind of AMR data the sender wants to + * receive. Not used at the moment. + */ + + /* Count the number of frames in the packet. The highest bit + * is set in a TOC byte if there are more frames following. + */ + for (frames = 1; frames < len && (buf[frames] & 0x80); frames++) ; + + if (1 + frames >= len) { + /* We hit the end of the packet while counting frames. */ + av_log(ctx, AV_LOG_ERROR, "No speech data found\n"); + return AVERROR_INVALIDDATA; + } + + speech_data = buf + 1 + frames; + + /* Everything except the codec mode request byte should be output. */ + if (av_new_packet(pkt, len - 1)) { + av_log(ctx, AV_LOG_ERROR, "Out of memory\n"); + return AVERROR(ENOMEM); + } + pkt->stream_index = st->index; + ptr = pkt->data; + + for (i = 0; i < frames; i++) { + uint8_t toc = buf[1 + i]; + int frame_size = frame_sizes[(toc >> 3) & 0x0f]; + + if (speech_data + frame_size > buf + len) { + /* Too little speech data */ + av_log(ctx, AV_LOG_WARNING, "Too little speech data in the RTP packet\n"); + /* Set the unwritten part of the packet to zero. */ + memset(ptr, 0, pkt->data + pkt->size - ptr); + pkt->size = ptr - pkt->data; + return 0; + } + + /* Extract the AMR frame mode from the TOC byte */ + *ptr++ = toc & 0x7C; + + /* Copy the speech data */ + memcpy(ptr, speech_data, frame_size); + speech_data += frame_size; + ptr += frame_size; + } + + if (speech_data < buf + len) { + av_log(ctx, AV_LOG_WARNING, "Too much speech data in the RTP packet?\n"); + /* Set the unwritten part of the packet to zero. */ + memset(ptr, 0, pkt->data + pkt->size - ptr); + pkt->size = ptr - pkt->data; + } + + return 0; +} + +static int amr_parse_sdp_line(AVFormatContext *s, int st_index, + PayloadContext *data, const char *line) +{ + const char *p; + char attr[25], value[25]; + + /* Parse an fmtp line this one: + * a=fmtp:97 octet-align=1; interleaving=0 + * That is, a normal fmtp: line followed by semicolon & space + * separated key/value pairs. + */ + if (av_strstart(line, "fmtp:", &p)) { + int octet_align = 0; + int crc = 0; + int interleaving = 0; + int channels = 1; + + while (*p && *p == ' ') p++; /* strip spaces */ + while (*p && *p != ' ') p++; /* eat protocol identifier */ + while (*p && *p == ' ') p++; /* strip trailing spaces */ + + while (ff_rtsp_next_attr_and_value(&p, attr, sizeof(attr), value, sizeof(value))) { + /* Some AMR SDP configurations contain "octet-align", without + * the trailing =1. Therefore, if the value is empty, + * interpret it as "1". + */ + if (!strcmp(value, "")) { + av_log(s, AV_LOG_WARNING, "AMR fmtp attribute %s had " + "nonstandard empty value\n", attr); + strcpy(value, "1"); + } + if (!strcmp(attr, "octet-align")) + octet_align = atoi(value); + else if (!strcmp(attr, "crc")) + crc = atoi(value); + else if (!strcmp(attr, "interleaving")) + interleaving = atoi(value); + else if (!strcmp(attr, "channels")) + channels = atoi(value); + } + if (!octet_align || crc || interleaving || channels != 1) { + av_log(s, AV_LOG_ERROR, "Unsupported RTP/AMR configuration!\n"); + return -1; + } + } + return 0; +} + +RTPDynamicProtocolHandler ff_amr_nb_dynamic_handler = { + .enc_name = "AMR", + .codec_type = AVMEDIA_TYPE_AUDIO, + .codec_id = CODEC_ID_AMR_NB, + .parse_sdp_a_line = amr_parse_sdp_line, + .parse_packet = amr_handle_packet, +}; + +RTPDynamicProtocolHandler ff_amr_wb_dynamic_handler = { + .enc_name = "AMR-WB", + .codec_type = AVMEDIA_TYPE_AUDIO, + .codec_id = CODEC_ID_AMR_WB, + .parse_sdp_a_line = amr_parse_sdp_line, + .parse_packet = amr_handle_packet, +}; + diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_amr.h b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_amr.h new file mode 100644 index 0000000000..3cd9dd17a0 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_amr.h @@ -0,0 +1,30 @@ +/* + * RTP AMR Depacketizer, RFC 3267 + * Copyright (c) 2010 Martin Storsjo + * + * 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_RTPDEC_AMR_H +#define AVFORMAT_RTPDEC_AMR_H + +#include "rtpdec.h" + +extern RTPDynamicProtocolHandler ff_amr_nb_dynamic_handler; +extern RTPDynamicProtocolHandler ff_amr_wb_dynamic_handler; + +#endif /* AVFORMAT_RTPDEC_AMR_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_asf.c b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_asf.c new file mode 100644 index 0000000000..e227e31e43 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_asf.c @@ -0,0 +1,281 @@ +/* + * Microsoft RTP/ASF support. + * Copyright (c) 2008 Ronald S. Bultje + * + * 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 + * @brief Microsoft RTP/ASF support + * @author Ronald S. Bultje + */ + +#include "libavutil/base64.h" +#include "libavutil/avstring.h" +#include "libavutil/intreadwrite.h" +#include "rtp.h" +#include "rtpdec_asf.h" +#include "rtsp.h" +#include "asf.h" + +/** + * From MSDN 2.2.1.4, we learn that ASF data packets over RTP should not + * contain any padding. Unfortunately, the header min/max_pktsize are not + * updated (thus making min_pktsize invalid). Here, we "fix" these faulty + * min_pktsize values in the ASF file header. + * @return 0 on success, <0 on failure (currently -1). + */ +static int rtp_asf_fix_header(uint8_t *buf, int len) +{ + uint8_t *p = buf, *end = buf + len; + + if (len < sizeof(ff_asf_guid) * 2 + 22 || + memcmp(p, ff_asf_header, sizeof(ff_asf_guid))) { + return -1; + } + p += sizeof(ff_asf_guid) + 14; + do { + uint64_t chunksize = AV_RL64(p + sizeof(ff_asf_guid)); + if (memcmp(p, ff_asf_file_header, sizeof(ff_asf_guid))) { + if (chunksize > end - p) + return -1; + p += chunksize; + continue; + } + + /* skip most of the file header, to min_pktsize */ + p += 6 * 8 + 3 * 4 + sizeof(ff_asf_guid) * 2; + if (p + 8 <= end && AV_RL32(p) == AV_RL32(p + 4)) { + /* and set that to zero */ + AV_WL32(p, 0); + return 0; + } + break; + } while (end - p >= sizeof(ff_asf_guid) + 8); + + return -1; +} + +/** + * The following code is basically a buffered ByteIOContext, + * with the added benefit of returning -EAGAIN (instead of 0) + * on packet boundaries, such that the ASF demuxer can return + * safely and resume business at the next packet. + */ +static int packetizer_read(void *opaque, uint8_t *buf, int buf_size) +{ + return AVERROR(EAGAIN); +} + +static void init_packetizer(ByteIOContext *pb, uint8_t *buf, int len) +{ + init_put_byte(pb, buf, len, 0, NULL, packetizer_read, NULL, NULL); + + /* this "fills" the buffer with its current content */ + pb->pos = len; + pb->buf_end = buf + len; +} + +void ff_wms_parse_sdp_a_line(AVFormatContext *s, const char *p) +{ + if (av_strstart(p, "pgmpu:data:application/vnd.ms.wms-hdr.asfv1;base64,", &p)) { + ByteIOContext pb; + RTSPState *rt = s->priv_data; + int len = strlen(p) * 6 / 8; + char *buf = av_mallocz(len); + av_base64_decode(buf, p, len); + + if (rtp_asf_fix_header(buf, len) < 0) + av_log(s, AV_LOG_ERROR, + "Failed to fix invalid RTSP-MS/ASF min_pktsize\n"); + init_packetizer(&pb, buf, len); + if (rt->asf_ctx) { + av_close_input_stream(rt->asf_ctx); + rt->asf_ctx = NULL; + } + av_open_input_stream(&rt->asf_ctx, &pb, "", &asf_demuxer, NULL); + rt->asf_pb_pos = url_ftell(&pb); + av_free(buf); + rt->asf_ctx->pb = NULL; + } +} + +static int asfrtp_parse_sdp_line(AVFormatContext *s, int stream_index, + PayloadContext *asf, const char *line) +{ + if (av_strstart(line, "stream:", &line)) { + RTSPState *rt = s->priv_data; + + s->streams[stream_index]->id = strtol(line, NULL, 10); + + if (rt->asf_ctx) { + int i; + + for (i = 0; i < rt->asf_ctx->nb_streams; i++) { + if (s->streams[stream_index]->id == rt->asf_ctx->streams[i]->id) { + *s->streams[stream_index]->codec = + *rt->asf_ctx->streams[i]->codec; + rt->asf_ctx->streams[i]->codec->extradata_size = 0; + rt->asf_ctx->streams[i]->codec->extradata = NULL; + av_set_pts_info(s->streams[stream_index], 32, 1, 1000); + } + } + } + } + + return 0; +} + +struct PayloadContext { + ByteIOContext *pktbuf, pb; + char *buf; +}; + +/** + * @return 0 when a packet was written into /p pkt, and no more data is left; + * 1 when a packet was written into /p pkt, and more packets might be left; + * <0 when not enough data was provided to return a full packet, or on error. + */ +static int asfrtp_parse_packet(AVFormatContext *s, PayloadContext *asf, + AVStream *st, AVPacket *pkt, + uint32_t *timestamp, + const uint8_t *buf, int len, int flags) +{ + ByteIOContext *pb = &asf->pb; + int res, mflags, len_off; + RTSPState *rt = s->priv_data; + + if (!rt->asf_ctx) + return -1; + + if (len > 0) { + int off, out_len; + + if (len < 4) + return -1; + + init_put_byte(pb, buf, len, 0, NULL, NULL, NULL, NULL); + mflags = get_byte(pb); + if (mflags & 0x80) + flags |= RTP_FLAG_KEY; + len_off = get_be24(pb); + if (mflags & 0x20) /**< relative timestamp */ + url_fskip(pb, 4); + if (mflags & 0x10) /**< has duration */ + url_fskip(pb, 4); + if (mflags & 0x8) /**< has location ID */ + url_fskip(pb, 4); + off = url_ftell(pb); + + av_freep(&asf->buf); + if (!(mflags & 0x40)) { + /** + * If 0x40 is not set, the len_off field specifies an offset of this + * packet's payload data in the complete (reassembled) ASF packet. + * This is used to spread one ASF packet over multiple RTP packets. + */ + if (asf->pktbuf && len_off != url_ftell(asf->pktbuf)) { + uint8_t *p; + url_close_dyn_buf(asf->pktbuf, &p); + asf->pktbuf = NULL; + av_free(p); + } + if (!len_off && !asf->pktbuf && + (res = url_open_dyn_buf(&asf->pktbuf)) < 0) + return res; + if (!asf->pktbuf) + return AVERROR(EIO); + + put_buffer(asf->pktbuf, buf + off, len - off); + if (!(flags & RTP_FLAG_MARKER)) + return -1; + out_len = url_close_dyn_buf(asf->pktbuf, &asf->buf); + asf->pktbuf = NULL; + } else { + /** + * If 0x40 is set, the len_off field specifies the length of the + * next ASF packet that can be read from this payload data alone. + * This is commonly the same as the payload size, but could be + * less in case of packet splitting (i.e. multiple ASF packets in + * one RTP packet). + */ + if (len_off != len) { + av_log_missing_feature(s, + "RTSP-MS packet splitting", 1); + return -1; + } + asf->buf = av_malloc(len - off); + out_len = len - off; + memcpy(asf->buf, buf + off, len - off); + } + + init_packetizer(pb, asf->buf, out_len); + pb->pos += rt->asf_pb_pos; + pb->eof_reached = 0; + rt->asf_ctx->pb = pb; + } + + for (;;) { + int i; + + res = av_read_packet(rt->asf_ctx, pkt); + rt->asf_pb_pos = url_ftell(pb); + if (res != 0) + break; + for (i = 0; i < s->nb_streams; i++) { + if (s->streams[i]->id == rt->asf_ctx->streams[pkt->stream_index]->id) { + pkt->stream_index = i; + return 1; // FIXME: return 0 if last packet + } + } + av_free_packet(pkt); + } + + return res == 1 ? -1 : res; +} + +static PayloadContext *asfrtp_new_context(void) +{ + return av_mallocz(sizeof(PayloadContext)); +} + +static void asfrtp_free_context(PayloadContext *asf) +{ + if (asf->pktbuf) { + uint8_t *p = NULL; + url_close_dyn_buf(asf->pktbuf, &p); + asf->pktbuf = NULL; + av_free(p); + } + av_freep(&asf->buf); + av_free(asf); +} + +#define RTP_ASF_HANDLER(n, s, t) \ +RTPDynamicProtocolHandler ff_ms_rtp_ ## n ## _handler = { \ + .enc_name = s, \ + .codec_type = t, \ + .codec_id = CODEC_ID_NONE, \ + .parse_sdp_a_line = asfrtp_parse_sdp_line, \ + .open = asfrtp_new_context, \ + .close = asfrtp_free_context, \ + .parse_packet = asfrtp_parse_packet, \ +}; + +RTP_ASF_HANDLER(asf_pfv, "x-asf-pf", AVMEDIA_TYPE_VIDEO); +RTP_ASF_HANDLER(asf_pfa, "x-asf-pf", AVMEDIA_TYPE_AUDIO); diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_asf.h b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_asf.h new file mode 100644 index 0000000000..5d60a14354 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_asf.h @@ -0,0 +1,43 @@ +/* + * Microsoft RTP/ASF support. + * Copyright (c) 2008 Ronald S. Bultje + * + * 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_RTPDEC_ASF_H +#define AVFORMAT_RTPDEC_ASF_H + +#include "avformat.h" +#include "rtpdec.h" + +/** + * Parse a Windows Media Server-specific SDP line + * + * @param s RTSP demux context + * @param line the SDP line to be parsed + */ +void ff_wms_parse_sdp_a_line(AVFormatContext *s, const char *p); + +/** + * Handlers for the x-asf-pf payloads (the payload ID for RTP/ASF). + * Defined and implemented in rtp_asf.c, registered in rtpdec.c. + */ +extern RTPDynamicProtocolHandler ff_ms_rtp_asf_pfv_handler, + ff_ms_rtp_asf_pfa_handler; + +#endif /* AVFORMAT_RTPDEC_ASF_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_h263.c b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_h263.c new file mode 100644 index 0000000000..19de6eca26 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_h263.c @@ -0,0 +1,108 @@ +/* + * RTP H.263 Depacketizer, RFC 4629 + * Copyright (c) 2010 Martin Storsjo + * + * 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 "rtpdec_h263.h" +#include "libavutil/intreadwrite.h" + +static int h263_handle_packet(AVFormatContext *ctx, + PayloadContext *data, + AVStream *st, + AVPacket * pkt, + uint32_t * timestamp, + const uint8_t * buf, + int len, int flags) +{ + uint8_t *ptr; + uint16_t header; + int startcode, vrc, picture_header; + + if (len < 2) { + av_log(ctx, AV_LOG_ERROR, "Too short H.263 RTP packet\n"); + return AVERROR_INVALIDDATA; + } + + /* Decode the 16 bit H.263+ payload header, as described in section + * 5.1 of RFC 4629. The fields of this header are: + * - 5 reserved bits, should be ignored. + * - One bit (P, startcode), indicating a picture start, picture segment + * start or video sequence end. If set, two zero bytes should be + * prepended to the payload. + * - One bit (V, vrc), indicating the presence of an 8 bit Video + * Redundancy Coding field after this 16 bit header. + * - 6 bits (PLEN, picture_header), the length (in bytes) of an extra + * picture header, following the VRC field. + * - 3 bits (PEBIT), the number of bits to ignore of the last byte + * of the extra picture header. (Not used at the moment.) + */ + header = AV_RB16(buf); + startcode = (header & 0x0400) >> 9; + vrc = header & 0x0200; + picture_header = (header & 0x01f8) >> 3; + buf += 2; + len -= 2; + + if (vrc) { + /* Skip VRC header if present, not used at the moment. */ + buf += 1; + len -= 1; + } + if (picture_header) { + /* Skip extra picture header if present, not used at the moment. */ + buf += picture_header; + len -= picture_header; + } + + if (len < 0) { + av_log(ctx, AV_LOG_ERROR, "Too short H.263 RTP packet\n"); + return AVERROR_INVALIDDATA; + } + + if (av_new_packet(pkt, len + startcode)) { + av_log(ctx, AV_LOG_ERROR, "Out of memory\n"); + return AVERROR(ENOMEM); + } + pkt->stream_index = st->index; + ptr = pkt->data; + + if (startcode) { + *ptr++ = 0; + *ptr++ = 0; + } + memcpy(ptr, buf, len); + + return 0; +} + +RTPDynamicProtocolHandler ff_h263_1998_dynamic_handler = { + .enc_name = "H263-1998", + .codec_type = AVMEDIA_TYPE_VIDEO, + .codec_id = CODEC_ID_H263, + .parse_packet = h263_handle_packet, +}; + +RTPDynamicProtocolHandler ff_h263_2000_dynamic_handler = { + .enc_name = "H263-2000", + .codec_type = AVMEDIA_TYPE_VIDEO, + .codec_id = CODEC_ID_H263, + .parse_packet = h263_handle_packet, +}; + diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_h263.h b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_h263.h new file mode 100644 index 0000000000..5b51128680 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_h263.h @@ -0,0 +1,30 @@ +/* + * RTP H.263 Depacketizer, RFC 4629 + * Copyright (c) 2010 Martin Storsjo + * + * 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_RTPDEC_H263_H +#define AVFORMAT_RTPDEC_H263_H + +#include "rtpdec.h" + +extern RTPDynamicProtocolHandler ff_h263_1998_dynamic_handler; +extern RTPDynamicProtocolHandler ff_h263_2000_dynamic_handler; + +#endif /* AVFORMAT_RTPDEC_H263_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_h264.c b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_h264.c new file mode 100644 index 0000000000..d690173229 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_h264.c @@ -0,0 +1,420 @@ +/* + * RTP H264 Protocol (RFC3984) + * Copyright (c) 2006 Ryan Martell + * + * 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 + * @brief H.264 / RTP Code (RFC3984) + * @author Ryan Martell + * + * @note Notes: + * Notes: + * This currently supports packetization mode: + * Single Nal Unit Mode (0), or + * Non-Interleaved Mode (1). It currently does not support + * Interleaved Mode (2). (This requires implementing STAP-B, MTAP16, MTAP24, FU-B packet types) + * + * @note TODO: + * 1) RTCP sender reports for udp streams are required.. + * + */ + +#include "libavutil/base64.h" +#include "libavutil/avstring.h" +#include "libavcodec/get_bits.h" +#include "avformat.h" +#include "mpegts.h" + +#include +#include "network.h" +#include + +#include "rtpdec.h" +#include "rtpdec_h264.h" + +/** + RTP/H264 specific private data. +*/ +struct PayloadContext { + unsigned long cookie; ///< sanity check, to make sure we get the pointer we're expecting. + + //sdp setup parameters + uint8_t profile_idc; ///< from the sdp setup parameters. + uint8_t profile_iop; ///< from the sdp setup parameters. + uint8_t level_idc; ///< from the sdp setup parameters. + int packetization_mode; ///< from the sdp setup parameters. +#ifdef DEBUG + int packet_types_received[32]; +#endif +}; + +#define MAGIC_COOKIE (0xdeadbeef) ///< Cookie for the extradata; to verify we are what we think we are, and that we haven't been freed. +#define DEAD_COOKIE (0xdeaddead) ///< Cookie for the extradata; once it is freed. + +/* ---------------- private code */ +static void sdp_parse_fmtp_config_h264(AVStream * stream, + PayloadContext * h264_data, + char *attr, char *value) +{ + AVCodecContext *codec = stream->codec; + assert(codec->codec_id == CODEC_ID_H264); + assert(h264_data != NULL); + + if (!strcmp(attr, "packetization-mode")) { + av_log(codec, AV_LOG_DEBUG, "RTP Packetization Mode: %d\n", atoi(value)); + h264_data->packetization_mode = atoi(value); + /* + Packetization Mode: + 0 or not present: Single NAL mode (Only nals from 1-23 are allowed) + 1: Non-interleaved Mode: 1-23, 24 (STAP-A), 28 (FU-A) are allowed. + 2: Interleaved Mode: 25 (STAP-B), 26 (MTAP16), 27 (MTAP24), 28 (FU-A), and 29 (FU-B) are allowed. + */ + if (h264_data->packetization_mode > 1) + av_log(codec, AV_LOG_ERROR, + "Interleaved RTP mode is not supported yet."); + } else if (!strcmp(attr, "profile-level-id")) { + if (strlen(value) == 6) { + char buffer[3]; + // 6 characters=3 bytes, in hex. + uint8_t profile_idc; + uint8_t profile_iop; + uint8_t level_idc; + + buffer[0] = value[0]; buffer[1] = value[1]; buffer[2] = '\0'; + profile_idc = strtol(buffer, NULL, 16); + buffer[0] = value[2]; buffer[1] = value[3]; + profile_iop = strtol(buffer, NULL, 16); + buffer[0] = value[4]; buffer[1] = value[5]; + level_idc = strtol(buffer, NULL, 16); + + // set the parameters... + av_log(codec, AV_LOG_DEBUG, + "RTP Profile IDC: %x Profile IOP: %x Level: %x\n", + profile_idc, profile_iop, level_idc); + h264_data->profile_idc = profile_idc; + h264_data->profile_iop = profile_iop; + h264_data->level_idc = level_idc; + } + } else if (!strcmp(attr, "sprop-parameter-sets")) { + uint8_t start_sequence[]= { 0, 0, 1 }; + codec->extradata_size= 0; + codec->extradata= NULL; + + while (*value) { + char base64packet[1024]; + uint8_t decoded_packet[1024]; + uint32_t packet_size; + char *dst = base64packet; + + while (*value && *value != ',' + && (dst - base64packet) < sizeof(base64packet) - 1) { + *dst++ = *value++; + } + *dst++ = '\0'; + + if (*value == ',') + value++; + + packet_size= av_base64_decode(decoded_packet, base64packet, sizeof(decoded_packet)); + if (packet_size) { + uint8_t *dest = av_malloc(packet_size + sizeof(start_sequence) + + codec->extradata_size + + FF_INPUT_BUFFER_PADDING_SIZE); + if(dest) + { + if(codec->extradata_size) + { + // av_realloc? + memcpy(dest, codec->extradata, codec->extradata_size); + av_free(codec->extradata); + } + + memcpy(dest+codec->extradata_size, start_sequence, sizeof(start_sequence)); + memcpy(dest+codec->extradata_size+sizeof(start_sequence), decoded_packet, packet_size); + memset(dest+codec->extradata_size+sizeof(start_sequence)+ + packet_size, 0, FF_INPUT_BUFFER_PADDING_SIZE); + + codec->extradata= dest; + codec->extradata_size+= sizeof(start_sequence)+packet_size; + } else { + av_log(codec, AV_LOG_ERROR, "Unable to allocate memory for extradata!"); + } + } + } + av_log(codec, AV_LOG_DEBUG, "Extradata set to %p (size: %d)!", codec->extradata, codec->extradata_size); + } +} + +// return 0 on packet, no more left, 1 on packet, 1 on partial packet... +static int h264_handle_packet(AVFormatContext *ctx, + PayloadContext *data, + AVStream *st, + AVPacket * pkt, + uint32_t * timestamp, + const uint8_t * buf, + int len, int flags) +{ + uint8_t nal = buf[0]; + uint8_t type = (nal & 0x1f); + int result= 0; + uint8_t start_sequence[]= {0, 0, 1}; + +#ifdef DEBUG + assert(data); + assert(data->cookie == MAGIC_COOKIE); +#endif + assert(buf); + + if (type >= 1 && type <= 23) + type = 1; // simplify the case. (these are all the nal types used internally by the h264 codec) + switch (type) { + case 0: // undefined; + result= -1; + break; + + case 1: + av_new_packet(pkt, len+sizeof(start_sequence)); + memcpy(pkt->data, start_sequence, sizeof(start_sequence)); + memcpy(pkt->data+sizeof(start_sequence), buf, len); +#ifdef DEBUG + data->packet_types_received[nal & 0x1f]++; +#endif + break; + + case 24: // STAP-A (one packet, multiple nals) + // consume the STAP-A NAL + buf++; + len--; + // first we are going to figure out the total size.... + { + int pass= 0; + int total_length= 0; + uint8_t *dst= NULL; + + for(pass= 0; pass<2; pass++) { + const uint8_t *src= buf; + int src_len= len; + + do { + uint16_t nal_size = AV_RB16(src); // this going to be a problem if unaligned (can it be?) + + // consume the length of the aggregate... + src += 2; + src_len -= 2; + + if (nal_size <= src_len) { + if(pass==0) { + // counting... + total_length+= sizeof(start_sequence)+nal_size; + } else { + // copying + assert(dst); + memcpy(dst, start_sequence, sizeof(start_sequence)); + dst+= sizeof(start_sequence); + memcpy(dst, src, nal_size); +#ifdef DEBUG + data->packet_types_received[*src & 0x1f]++; +#endif + dst+= nal_size; + } + } else { + av_log(ctx, AV_LOG_ERROR, + "nal size exceeds length: %d %d\n", nal_size, src_len); + } + + // eat what we handled... + src += nal_size; + src_len -= nal_size; + + if (src_len < 0) + av_log(ctx, AV_LOG_ERROR, + "Consumed more bytes than we got! (%d)\n", src_len); + } while (src_len > 2); // because there could be rtp padding.. + + if(pass==0) { + // now we know the total size of the packet (with the start sequences added) + av_new_packet(pkt, total_length); + dst= pkt->data; + } else { + assert(dst-pkt->data==total_length); + } + } + } + break; + + case 25: // STAP-B + case 26: // MTAP-16 + case 27: // MTAP-24 + case 29: // FU-B + av_log(ctx, AV_LOG_ERROR, + "Unhandled type (%d) (See RFC for implementation details\n", + type); + result= -1; + break; + + case 28: // FU-A (fragmented nal) + buf++; + len--; // skip the fu_indicator + { + // these are the same as above, we just redo them here for clarity... + uint8_t fu_indicator = nal; + uint8_t fu_header = *buf; // read the fu_header. + uint8_t start_bit = fu_header >> 7; +// uint8_t end_bit = (fu_header & 0x40) >> 6; + uint8_t nal_type = (fu_header & 0x1f); + uint8_t reconstructed_nal; + + // reconstruct this packet's true nal; only the data follows.. + reconstructed_nal = fu_indicator & (0xe0); // the original nal forbidden bit and NRI are stored in this packet's nal; + reconstructed_nal |= nal_type; + + // skip the fu_header... + buf++; + len--; + +#ifdef DEBUG + if (start_bit) + data->packet_types_received[nal_type]++; +#endif + if(start_bit) { + // copy in the start sequence, and the reconstructed nal.... + av_new_packet(pkt, sizeof(start_sequence)+sizeof(nal)+len); + memcpy(pkt->data, start_sequence, sizeof(start_sequence)); + pkt->data[sizeof(start_sequence)]= reconstructed_nal; + memcpy(pkt->data+sizeof(start_sequence)+sizeof(nal), buf, len); + } else { + av_new_packet(pkt, len); + memcpy(pkt->data, buf, len); + } + } + break; + + case 30: // undefined + case 31: // undefined + default: + av_log(ctx, AV_LOG_ERROR, "Undefined type (%d)", type); + result= -1; + break; + } + + pkt->stream_index = st->index; + + return result; +} + +/* ---------------- public code */ +static PayloadContext *h264_new_context(void) +{ + PayloadContext *data = + av_mallocz(sizeof(PayloadContext) + + FF_INPUT_BUFFER_PADDING_SIZE); + + if (data) { + data->cookie = MAGIC_COOKIE; + } + + return data; +} + +static void h264_free_context(PayloadContext *data) +{ +#ifdef DEBUG + int ii; + + for (ii = 0; ii < 32; ii++) { + if (data->packet_types_received[ii]) + av_log(NULL, AV_LOG_DEBUG, "Received %d packets of type %d\n", + data->packet_types_received[ii], ii); + } +#endif + + assert(data); + assert(data->cookie == MAGIC_COOKIE); + + // avoid stale pointers (assert) + data->cookie = DEAD_COOKIE; + + // and clear out this... + av_free(data); +} + +static int parse_h264_sdp_line(AVFormatContext *s, int st_index, + PayloadContext *h264_data, const char *line) +{ + AVStream *stream = s->streams[st_index]; + AVCodecContext *codec = stream->codec; + const char *p = line; + + assert(h264_data->cookie == MAGIC_COOKIE); + + if (av_strstart(p, "framesize:", &p)) { + char buf1[50]; + char *dst = buf1; + + // remove the protocol identifier.. + while (*p && *p == ' ') p++; // strip spaces. + while (*p && *p != ' ') p++; // eat protocol identifier + while (*p && *p == ' ') p++; // strip trailing spaces. + while (*p && *p != '-' && (dst - buf1) < sizeof(buf1) - 1) { + *dst++ = *p++; + } + *dst = '\0'; + + // a='framesize:96 320-240' + // set our parameters.. + codec->width = atoi(buf1); + codec->height = atoi(p + 1); // skip the - + codec->pix_fmt = PIX_FMT_YUV420P; + } else if (av_strstart(p, "fmtp:", &p)) { + char attr[256]; + char value[4096]; + + // remove the protocol identifier.. + while (*p && *p == ' ') p++; // strip spaces. + while (*p && *p != ' ') p++; // eat protocol identifier + while (*p && *p == ' ') p++; // strip trailing spaces. + + /* loop on each attribute */ + while (ff_rtsp_next_attr_and_value + (&p, attr, sizeof(attr), value, sizeof(value))) { + /* grab the codec extra_data from the config parameter of the fmtp line */ + sdp_parse_fmtp_config_h264(stream, h264_data, attr, value); + } + } else if (av_strstart(p, "cliprect:", &p)) { + // could use this if we wanted. + } + + av_set_pts_info(stream, 33, 1, 90000); // 33 should be right, because the pts is 64 bit? (done elsewhere; this is a one time thing) + + return 0; // keep processing it the normal way... +} + +/** +This is the structure for expanding on the dynamic rtp protocols (makes everything static. yay!) +*/ +RTPDynamicProtocolHandler ff_h264_dynamic_handler = { + .enc_name = "H264", + .codec_type = AVMEDIA_TYPE_VIDEO, + .codec_id = CODEC_ID_H264, + .parse_sdp_a_line = parse_h264_sdp_line, + .open = h264_new_context, + .close = h264_free_context, + .parse_packet = h264_handle_packet +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_h264.h b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_h264.h new file mode 100644 index 0000000000..b4d54de214 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_h264.h @@ -0,0 +1,29 @@ +/* + * RTP H264 Protocol (RFC3984) + * Copyright (c) 2006 Ryan Martell + * + * 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_RTPDEC_H264_H +#define AVFORMAT_RTPDEC_H264_H + +#include "rtpdec.h" + +extern RTPDynamicProtocolHandler ff_h264_dynamic_handler; + +#endif /* AVFORMAT_RTPDEC_H264_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_xiph.c b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_xiph.c new file mode 100644 index 0000000000..9a1f33d531 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_xiph.c @@ -0,0 +1,398 @@ +/* + * Xiph RTP Protocols + * Copyright (c) 2009 Colin McQuillian + * Copyright (c) 2010 Josh Allmann + * + * 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 + * @brief Xiph / RTP Code + * @author Colin McQuillan + * @author Josh Allmann + */ + +#include "libavutil/avstring.h" +#include "libavutil/base64.h" +#include "libavcodec/bytestream.h" + +#include + +#include "rtpdec.h" +#include "rtpdec_xiph.h" + +/** + * RTP/Xiph specific private data. + */ +struct PayloadContext { + unsigned ident; ///< 24-bit stream configuration identifier + uint32_t timestamp; + ByteIOContext* fragment; ///< buffer for split payloads +}; + +static PayloadContext *xiph_new_context(void) +{ + return av_mallocz(sizeof(PayloadContext)); +} + +static inline void free_fragment_if_needed(PayloadContext * data) +{ + if (data->fragment) { + uint8_t* p; + url_close_dyn_buf(data->fragment, &p); + av_free(p); + data->fragment = NULL; + } +} + +static void xiph_free_context(PayloadContext * data) +{ + free_fragment_if_needed(data); + av_free(data); +} + +static int xiph_handle_packet(AVFormatContext * ctx, + PayloadContext * data, + AVStream * st, + AVPacket * pkt, + uint32_t * timestamp, + const uint8_t * buf, int len, int flags) +{ + + int ident, fragmented, tdt, num_pkts, pkt_len; + + if (len < 6) { + av_log(ctx, AV_LOG_ERROR, "Invalid %d byte packet\n", len); + return AVERROR_INVALIDDATA; + } + + // read xiph rtp headers + ident = AV_RB24(buf); + fragmented = buf[3] >> 6; + tdt = (buf[3] >> 4) & 3; + num_pkts = buf[3] & 7; + pkt_len = AV_RB16(buf + 4); + + if (pkt_len > len - 6) { + av_log(ctx, AV_LOG_ERROR, + "Invalid packet length %d in %d byte packet\n", pkt_len, + len); + return AVERROR_INVALIDDATA; + } + + if (ident != data->ident) { + av_log(ctx, AV_LOG_ERROR, + "Unimplemented Xiph SDP configuration change detected\n"); + return AVERROR_PATCHWELCOME; + } + + if (tdt) { + av_log(ctx, AV_LOG_ERROR, + "Unimplemented RTP Xiph packet settings (%d,%d,%d)\n", + fragmented, tdt, num_pkts); + return AVERROR_PATCHWELCOME; + } + + buf += 6; // move past header bits + len -= 6; + + if (fragmented == 0) { + // whole frame(s) + int i, data_len, write_len; + buf -= 2; + len += 2; + + // fast first pass to calculate total length + for (i = 0, data_len = 0; (i < num_pkts) && (len >= 2); i++) { + int off = data_len + (i << 1); + pkt_len = AV_RB16(buf + off); + data_len += pkt_len; + len -= pkt_len + 2; + } + + if (len < 0 || i < num_pkts) { + av_log(ctx, AV_LOG_ERROR, + "Bad packet: %d bytes left at frame %d of %d\n", + len, i, num_pkts); + return AVERROR_INVALIDDATA; + } + + if (av_new_packet(pkt, data_len)) { + av_log(ctx, AV_LOG_ERROR, "Out of memory.\n"); + return AVERROR(ENOMEM); + } + pkt->stream_index = st->index; + + // concatenate frames + for (i = 0, write_len = 0; write_len < data_len; i++) { + pkt_len = AV_RB16(buf); + buf += 2; + memcpy(pkt->data + write_len, buf, pkt_len); + write_len += pkt_len; + buf += pkt_len; + } + assert(write_len == data_len); + + return 0; + + } else if (fragmented == 1) { + // start of xiph data fragment + int res; + + // end packet has been lost somewhere, so drop buffered data + free_fragment_if_needed(data); + + if((res = url_open_dyn_buf(&data->fragment)) < 0) + return res; + + put_buffer(data->fragment, buf, pkt_len); + data->timestamp = *timestamp; + + } else { + assert(fragmented < 4); + if (data->timestamp != *timestamp) { + // skip if fragmented timestamp is incorrect; + // a start packet has been lost somewhere + free_fragment_if_needed(data); + av_log(ctx, AV_LOG_ERROR, "RTP timestamps don't match!\n"); + return AVERROR_INVALIDDATA; + } + + // copy data to fragment buffer + put_buffer(data->fragment, buf, pkt_len); + + if (fragmented == 3) { + // end of xiph data packet + uint8_t* xiph_data; + int frame_size = url_close_dyn_buf(data->fragment, &xiph_data); + + if (frame_size < 0) { + av_log(ctx, AV_LOG_ERROR, + "Error occurred when getting fragment buffer."); + return frame_size; + } + + if (av_new_packet(pkt, frame_size)) { + av_log(ctx, AV_LOG_ERROR, "Out of memory.\n"); + return AVERROR(ENOMEM); + } + + memcpy(pkt->data, xiph_data, frame_size); + pkt->stream_index = st->index; + + av_free(xiph_data); + data->fragment = NULL; + + return 0; + } + } + + return AVERROR(EAGAIN); +} + +/** + * Length encoding described in RFC5215 section 3.1.1. + */ +static int get_base128(const uint8_t ** buf, const uint8_t * buf_end) +{ + int n = 0; + for (; *buf < buf_end; ++*buf) { + n <<= 7; + n += **buf & 0x7f; + if (!(**buf & 0x80)) { + ++*buf; + return n; + } + } + return 0; +} + +/** + * Based off parse_packed_headers in Vorbis RTP + */ +static unsigned int +parse_packed_headers(const uint8_t * packed_headers, + const uint8_t * packed_headers_end, + AVCodecContext * codec, PayloadContext * xiph_data) +{ + + unsigned num_packed, num_headers, length, length1, length2, extradata_alloc; + uint8_t *ptr; + + if (packed_headers_end - packed_headers < 9) { + av_log(codec, AV_LOG_ERROR, + "Invalid %d byte packed header.", + packed_headers_end - packed_headers); + return AVERROR_INVALIDDATA; + } + + num_packed = bytestream_get_be32(&packed_headers); + xiph_data->ident = bytestream_get_be24(&packed_headers); + length = bytestream_get_be16(&packed_headers); + num_headers = get_base128(&packed_headers, packed_headers_end); + length1 = get_base128(&packed_headers, packed_headers_end); + length2 = get_base128(&packed_headers, packed_headers_end); + + if (num_packed != 1 || num_headers > 3) { + av_log(codec, AV_LOG_ERROR, + "Unimplemented number of headers: %d packed headers, %d headers\n", + num_packed, num_headers); + return AVERROR_PATCHWELCOME; + } + + if (packed_headers_end - packed_headers != length || + length1 > length || length2 > length - length1) { + av_log(codec, AV_LOG_ERROR, + "Bad packed header lengths (%d,%d,%d,%d)\n", length1, + length2, packed_headers_end - packed_headers, length); + return AVERROR_INVALIDDATA; + } + + /* allocate extra space: + * -- length/255 +2 for xiphlacing + * -- one for the '2' marker + * -- FF_INPUT_BUFFER_PADDING_SIZE required */ + extradata_alloc = length + length/255 + 3 + FF_INPUT_BUFFER_PADDING_SIZE; + + ptr = codec->extradata = av_malloc(extradata_alloc); + if (!ptr) { + av_log(codec, AV_LOG_ERROR, "Out of memory\n"); + return AVERROR(ENOMEM); + } + *ptr++ = 2; + ptr += av_xiphlacing(ptr, length1); + ptr += av_xiphlacing(ptr, length2); + memcpy(ptr, packed_headers, length); + ptr += length; + codec->extradata_size = ptr - codec->extradata; + // clear out remaining parts of the buffer + memset(ptr, 0, extradata_alloc - codec->extradata_size); + + return 0; +} + +static int xiph_parse_fmtp_pair(AVCodecContext * codec, + PayloadContext *xiph_data, + char *attr, char *value) +{ + int result = 0; + + if (!strcmp(attr, "sampling")) { + return AVERROR_PATCHWELCOME; + } else if (!strcmp(attr, "width")) { + /* This is an integer between 1 and 1048561 + * and MUST be in multiples of 16. */ + codec->width = atoi(value); + return 0; + } else if (!strcmp(attr, "height")) { + /* This is an integer between 1 and 1048561 + * and MUST be in multiples of 16. */ + codec->height = atoi(value); + return 0; + } else if (!strcmp(attr, "delivery-method")) { + /* Possible values are: inline, in_band, out_band/specific_name. */ + return AVERROR_PATCHWELCOME; + } else if (!strcmp(attr, "configuration-uri")) { + /* NOTE: configuration-uri is supported only under 2 conditions: + *--after the delivery-method tag + * --with a delivery-method value of out_band */ + return AVERROR_PATCHWELCOME; + } else if (!strcmp(attr, "configuration")) { + /* NOTE: configuration is supported only AFTER the delivery-method tag + * The configuration value is a base64 encoded packed header */ + uint8_t *decoded_packet = NULL; + int packet_size; + size_t decoded_alloc = strlen(value) / 4 * 3 + 4; + + if (decoded_alloc <= INT_MAX) { + decoded_packet = av_malloc(decoded_alloc); + if (decoded_packet) { + packet_size = + av_base64_decode(decoded_packet, value, decoded_alloc); + + result = parse_packed_headers + (decoded_packet, decoded_packet + packet_size, codec, + xiph_data); + } else { + av_log(codec, AV_LOG_ERROR, + "Out of memory while decoding SDP configuration.\n"); + result = AVERROR(ENOMEM); + } + } else { + av_log(codec, AV_LOG_ERROR, "Packet too large\n"); + result = AVERROR_INVALIDDATA; + } + av_free(decoded_packet); + } + return result; +} + +static int xiph_parse_sdp_line(AVFormatContext *s, int st_index, + PayloadContext *data, const char *line) +{ + const char *p; + char *value; + char attr[25]; + int value_size = strlen(line), attr_size = sizeof(attr), res = 0; + AVCodecContext* codec = s->streams[st_index]->codec; + + assert(data); + + if (!(value = av_malloc(value_size))) { + av_log(codec, AV_LOG_ERROR, "Out of memory\n"); + return AVERROR(ENOMEM); + } + + if (av_strstart(line, "fmtp:", &p)) { + // remove protocol identifier + while (*p && *p == ' ') p++; // strip spaces + while (*p && *p != ' ') p++; // eat protocol identifier + while (*p && *p == ' ') p++; // strip trailing spaces + + while (ff_rtsp_next_attr_and_value(&p, + attr, attr_size, + value, value_size)) { + res = xiph_parse_fmtp_pair(codec, data, attr, value); + if (res < 0 && res != AVERROR_PATCHWELCOME) + return res; + } + } + + av_free(value); + return 0; +} + +RTPDynamicProtocolHandler ff_theora_dynamic_handler = { + .enc_name = "theora", + .codec_type = AVMEDIA_TYPE_VIDEO, + .codec_id = CODEC_ID_THEORA, + .parse_sdp_a_line = xiph_parse_sdp_line, + .open = xiph_new_context, + .close = xiph_free_context, + .parse_packet = xiph_handle_packet +}; + +RTPDynamicProtocolHandler ff_vorbis_dynamic_handler = { + .enc_name = "vorbis", + .codec_type = AVMEDIA_TYPE_AUDIO, + .codec_id = CODEC_ID_VORBIS, + .parse_sdp_a_line = xiph_parse_sdp_line, + .open = xiph_new_context, + .close = xiph_free_context, + .parse_packet = xiph_handle_packet +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_xiph.h b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_xiph.h new file mode 100644 index 0000000000..50aa77fb27 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpdec_xiph.h @@ -0,0 +1,40 @@ +/* + * Xiph RTP Protocols + * Based off RFC 5215 (Vorbis RTP) and the Theora RTP draft. + * Copyright (c) 2009 Colin McQuillian + * Copyright (c) 2010 Josh Allmann + * + * 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_RTPDEC_XIPH_H +#define AVFORMAT_RTPDEC_XIPH_H + +#include "libavcodec/avcodec.h" +#include "rtpdec.h" + +/** + * Theora RTP callbacks. + */ +extern RTPDynamicProtocolHandler ff_theora_dynamic_handler; + +/** + * Vorbis RTP callbacks. + */ +extern RTPDynamicProtocolHandler ff_vorbis_dynamic_handler; + +#endif /* AVFORMAT_RTPDEC_XIPH_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rtpenc.c b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpenc.c index 2a0770e300..5df101eb04 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/rtpenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpenc.c @@ -19,25 +19,18 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libavcodec/get_bits.h" #include "avformat.h" #include "mpegts.h" +#include "internal.h" +#include "libavutil/random_seed.h" #include -#include "network.h" #include "rtpenc.h" //#define DEBUG #define RTCP_SR_SIZE 28 -#define NTP_OFFSET 2208988800ULL -#define NTP_OFFSET_US (NTP_OFFSET * 1000000ULL) - -static uint64_t ntp_time(void) -{ - return (av_gettime() / 1000) * 1000 + NTP_OFFSET_US; -} static int is_supported(enum CodecID id) { @@ -71,7 +64,7 @@ static int is_supported(enum CodecID id) static int rtp_write_header(AVFormatContext *s1) { RTPMuxContext *s = s1->priv_data; - int payload_type, max_packet_size, n; + int max_packet_size, n; AVStream *st; if (s1->nb_streams != 1) @@ -83,18 +76,20 @@ static int rtp_write_header(AVFormatContext *s1) return -1; } - payload_type = ff_rtp_get_payload_type(st->codec); - if (payload_type < 0) - payload_type = RTP_PT_PRIVATE; /* private payload type */ - s->payload_type = payload_type; + 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); -// following 2 FIXMEs could be set based on the current time, there is normally no info leak, as RTP will likely be transmitted immediately - s->base_timestamp = 0; /* FIXME: was random(), what should this be? */ + s->base_timestamp = ff_random_get_seed(); s->timestamp = s->base_timestamp; s->cur_timestamp = 0; - s->ssrc = 0; /* FIXME: was random(), what should this be? */ + s->ssrc = ff_random_get_seed(); s->first_packet = 1; - s->first_rtcp_ntp_time = AV_NOPTS_VALUE; + s->first_rtcp_ntp_time = ff_ntp_time(); + if (s1->start_time_realtime) + /* Round the NTP time to whole milliseconds. */ + s->first_rtcp_ntp_time = (s1->start_time_realtime / 1000) * 1000 + + NTP_OFFSET_US; max_packet_size = url_fget_max_packet_size(s1->pb); if (max_packet_size <= 12) @@ -107,14 +102,14 @@ static int rtp_write_header(AVFormatContext *s1) s->max_frames_per_packet = 0; if (s1->max_delay) { - if (st->codec->codec_type == CODEC_TYPE_AUDIO) { + if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { if (st->codec->frame_size == 0) { av_log(s1, AV_LOG_ERROR, "Cannot respect max delay: frame size = 0\n"); } else { s->max_frames_per_packet = av_rescale_rnd(s1->max_delay, st->codec->sample_rate, AV_TIME_BASE * st->codec->frame_size, AV_ROUND_DOWN); } } - if (st->codec->codec_type == CODEC_TYPE_VIDEO) { + if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { /* FIXME: We should round down here... */ s->max_frames_per_packet = av_rescale_q(s1->max_delay, (AVRational){1, 1000000}, st->codec->time_base); } @@ -156,7 +151,7 @@ static int rtp_write_header(AVFormatContext *s1) case CODEC_ID_AAC: s->num_frames = 0; default: - if (st->codec->codec_type == CODEC_TYPE_AUDIO) { + if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { av_set_pts_info(st, 32, 1, st->codec->sample_rate); } s->buf_ptr = s->buf; @@ -174,7 +169,6 @@ static void rtcp_send_sr(AVFormatContext *s1, int64_t ntp_time) dprintf(s1, "RTCP: %02x %"PRIx64" %x\n", s->payload_type, ntp_time, s->timestamp); - if (s->first_rtcp_ntp_time == AV_NOPTS_VALUE) s->first_rtcp_ntp_time = ntp_time; s->last_rtcp_ntp_time = ntp_time; rtp_ts = av_rescale_q(ntp_time - s->first_rtcp_ntp_time, (AVRational){1, 1000000}, s1->streams[0]->time_base) + s->base_timestamp; @@ -241,8 +235,6 @@ static void rtp_send_samples(AVFormatContext *s1, } } -/* NOTE: we suppose that exactly one frame is given as argument here */ -/* XXX: test it */ static void rtp_send_mpegaudio(AVFormatContext *s1, const uint8_t *buf1, int size) { @@ -340,22 +332,20 @@ static void rtp_send_mpegts_raw(AVFormatContext *s1, } } -/* write an RTP packet. 'buf1' must contain a single specific frame. */ static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt) { RTPMuxContext *s = s1->priv_data; AVStream *st = s1->streams[0]; int rtcp_bytes; int size= pkt->size; - uint8_t *buf1= pkt->data; dprintf(s1, "%d: write len=%d\n", pkt->stream_index, size); rtcp_bytes = ((s->octet_count - s->last_octet_count) * RTCP_TX_RATIO_NUM) / RTCP_TX_RATIO_DEN; if (s->first_packet || ((rtcp_bytes >= RTCP_SR_SIZE) && - (ntp_time() - s->last_rtcp_ntp_time > 5000000))) { - rtcp_send_sr(s1, ntp_time()); + (ff_ntp_time() - s->last_rtcp_ntp_time > 5000000))) { + rtcp_send_sr(s1, ff_ntp_time()); s->last_octet_count = s->octet_count; s->first_packet = 0; } @@ -366,42 +356,42 @@ static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt) case CODEC_ID_PCM_ALAW: case CODEC_ID_PCM_U8: case CODEC_ID_PCM_S8: - rtp_send_samples(s1, buf1, size, 1 * st->codec->channels); + rtp_send_samples(s1, pkt->data, size, 1 * st->codec->channels); break; case CODEC_ID_PCM_U16BE: case CODEC_ID_PCM_U16LE: case CODEC_ID_PCM_S16BE: case CODEC_ID_PCM_S16LE: - rtp_send_samples(s1, buf1, size, 2 * st->codec->channels); + rtp_send_samples(s1, pkt->data, size, 2 * st->codec->channels); break; case CODEC_ID_MP2: case CODEC_ID_MP3: - rtp_send_mpegaudio(s1, buf1, size); + rtp_send_mpegaudio(s1, pkt->data, size); break; case CODEC_ID_MPEG1VIDEO: case CODEC_ID_MPEG2VIDEO: - ff_rtp_send_mpegvideo(s1, buf1, size); + ff_rtp_send_mpegvideo(s1, pkt->data, size); break; case CODEC_ID_AAC: - ff_rtp_send_aac(s1, buf1, size); + ff_rtp_send_aac(s1, pkt->data, size); break; case CODEC_ID_AMR_NB: case CODEC_ID_AMR_WB: - ff_rtp_send_amr(s1, buf1, size); + ff_rtp_send_amr(s1, pkt->data, size); break; case CODEC_ID_MPEG2TS: - rtp_send_mpegts_raw(s1, buf1, size); + rtp_send_mpegts_raw(s1, pkt->data, size); break; case CODEC_ID_H264: - ff_rtp_send_h264(s1, buf1, size); + ff_rtp_send_h264(s1, pkt->data, size); break; case CODEC_ID_H263: case CODEC_ID_H263P: - ff_rtp_send_h263(s1, buf1, size); + ff_rtp_send_h263(s1, pkt->data, size); break; default: /* better than nothing : send the codec raw data */ - rtp_send_raw(s1, buf1, size); + rtp_send_raw(s1, pkt->data, size); break; } return 0; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rtpenc_aac.c b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpenc_aac.c new file mode 100644 index 0000000000..e19b28697e --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpenc_aac.c @@ -0,0 +1,85 @@ +/* + * copyright (c) 2007 Luca Abeni + * + * 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 "rtpenc.h" + + +void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size) +{ + RTPMuxContext *s = s1->priv_data; + int len, max_packet_size; + uint8_t *p; + const int max_frames_per_packet = s->max_frames_per_packet ? s->max_frames_per_packet : 5; + const int max_au_headers_size = 2 + 2 * max_frames_per_packet; + + /* skip ADTS header, if present */ + if ((s1->streams[0]->codec->extradata_size) == 0) { + size -= 7; + buff += 7; + } + max_packet_size = s->max_payload_size - max_au_headers_size; + + /* test if the packet must be sent */ + len = (s->buf_ptr - s->buf); + if ((s->num_frames == max_frames_per_packet) || (len && (len + size) > s->max_payload_size)) { + int au_size = s->num_frames * 2; + + p = s->buf + max_au_headers_size - au_size - 2; + if (p != s->buf) { + memmove(p + 2, s->buf + 2, au_size); + } + /* Write the AU header size */ + p[0] = ((au_size * 8) & 0xFF) >> 8; + p[1] = (au_size * 8) & 0xFF; + + ff_rtp_send_data(s1, p, s->buf_ptr - p, 1); + + s->num_frames = 0; + } + if (s->num_frames == 0) { + s->buf_ptr = s->buf + max_au_headers_size; + s->timestamp = s->cur_timestamp; + } + + if (size <= max_packet_size) { + p = s->buf + s->num_frames++ * 2 + 2; + *p++ = size >> 5; + *p = (size & 0x1F) << 3; + memcpy(s->buf_ptr, buff, size); + s->buf_ptr += size; + } else { + int au_size = size; + + max_packet_size = s->max_payload_size - 4; + p = s->buf; + p[0] = 0; + p[1] = 16; + while (size > 0) { + len = FFMIN(size, max_packet_size); + p[2] = au_size >> 5; + p[3] = (au_size & 0x1F) << 3; + memcpy(p + 4, buff, len); + ff_rtp_send_data(s1, p, len + 4, len == size); + size -= len; + buff += len; + } + } +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rtpenc_amr.c b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpenc_amr.c new file mode 100644 index 0000000000..367789fccd --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpenc_amr.c @@ -0,0 +1,66 @@ +/* + * RTP packetization for AMR audio + * Copyright (c) 2007 Luca Abeni + * Copyright (c) 2009 Martin Storsjo + * + * 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 "rtpenc.h" + +/** + * Packetize AMR frames into RTP packets according to RFC 3267, + * in octet-aligned mode. + */ +void ff_rtp_send_amr(AVFormatContext *s1, const uint8_t *buff, int size) +{ + RTPMuxContext *s = s1->priv_data; + int max_header_toc_size = 1 + s->max_frames_per_packet; + uint8_t *p; + int len; + + /* Test if the packet must be sent. */ + len = s->buf_ptr - s->buf; + if (s->num_frames == s->max_frames_per_packet || (len && len + size - 1 > s->max_payload_size)) { + int header_size = s->num_frames + 1; + p = s->buf + max_header_toc_size - header_size; + if (p != s->buf) + memmove(p, s->buf, header_size); + + ff_rtp_send_data(s1, p, s->buf_ptr - p, 1); + + s->num_frames = 0; + } + + if (!s->num_frames) { + s->buf[0] = 0xf0; + s->buf_ptr = s->buf + max_header_toc_size; + s->timestamp = s->cur_timestamp; + } else { + /* Mark the previous TOC entry as having more entries following. */ + s->buf[1 + s->num_frames - 1] |= 0x80; + } + + /* Copy the frame type and quality bits. */ + s->buf[1 + s->num_frames++] = buff[0] & 0x7C; + buff++; + size--; + memcpy(s->buf_ptr, buff, size); + s->buf_ptr += size; +} + diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rtpenc_h263.c b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpenc_h263.c new file mode 100644 index 0000000000..84403a1069 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpenc_h263.c @@ -0,0 +1,80 @@ +/* + * RTP packetization for H.263 video + * Copyright (c) 2009 Luca Abeni + * Copyright (c) 2009 Martin Storsjo + * + * 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 "rtpenc.h" + +static const uint8_t *find_resync_marker_reverse(const uint8_t *restrict start, + const uint8_t *restrict end) +{ + const uint8_t *p = end - 1; + start += 1; /* Make sure we never return the original start. */ + for (; p > start; p -= 2) { + if (!*p) { + if (!p[ 1] && p[2]) return p; + else if (!p[-1] && p[1]) return p - 1; + } + } + return end; +} + +/** + * Packetize H.263 frames into RTP packets according to RFC 4629 + */ +void ff_rtp_send_h263(AVFormatContext *s1, const uint8_t *buf1, int size) +{ + RTPMuxContext *s = s1->priv_data; + int len, max_packet_size; + uint8_t *q; + + max_packet_size = s->max_payload_size; + + while (size > 0) { + q = s->buf; + if (size >= 2 && (buf1[0] == 0) && (buf1[1] == 0)) { + *q++ = 0x04; + buf1 += 2; + size -= 2; + } else { + *q++ = 0; + } + *q++ = 0; + + len = FFMIN(max_packet_size - 2, size); + + /* Look for a better place to split the frame into packets. */ + if (len < size) { + const uint8_t *end = find_resync_marker_reverse(buf1, buf1 + len); + len = end - buf1; + } + + memcpy(q, buf1, len); + q += len; + + /* 90 KHz time stamp */ + s->timestamp = s->cur_timestamp; + ff_rtp_send_data(s1, s->buf, q - s->buf, (len == size)); + + buf1 += len; + size -= len; + } +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rtpenc_h264.c b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpenc_h264.c index 2ba0771a97..697def61c2 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/rtpenc_h264.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpenc_h264.c @@ -20,7 +20,7 @@ */ /** - * @file libavformat/rtpenc_h264.c + * @file * @brief H.264 packetization * @author Luca Abeni */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rtpenc_mpv.c b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpenc_mpv.c new file mode 100644 index 0000000000..b23c8f86e8 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpenc_mpv.c @@ -0,0 +1,119 @@ +/* + * RTP packetization for MPEG video + * Copyright (c) 2002 Fabrice Bellard + * Copyright (c) 2007 Luca Abeni + * + * 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 "libavcodec/mpegvideo.h" +#include "avformat.h" +#include "rtpenc.h" + +/* NOTE: a single frame must be passed with sequence header if + needed. XXX: use slices. */ +void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size) +{ + RTPMuxContext *s = s1->priv_data; + int len, h, max_packet_size; + uint8_t *q; + const uint8_t *end = buf1 + size; + int begin_of_slice, end_of_slice, frame_type, temporal_reference; + + max_packet_size = s->max_payload_size; + begin_of_slice = 1; + end_of_slice = 0; + frame_type = 0; + temporal_reference = 0; + + while (size > 0) { + int begin_of_sequence; + + begin_of_sequence = 0; + len = max_packet_size - 4; + + if (len >= size) { + len = size; + end_of_slice = 1; + } else { + const uint8_t *r, *r1; + int start_code; + + r1 = buf1; + while (1) { + start_code = -1; + r = ff_find_start_code(r1, end, &start_code); + if((start_code & 0xFFFFFF00) == 0x100) { + /* New start code found */ + if (start_code == 0x100) { + frame_type = (r[1] & 0x38) >> 3; + temporal_reference = (int)r[0] << 2 | r[1] >> 6; + } + if (start_code == 0x1B8) { + begin_of_sequence = 1; + } + + if (r - buf1 - 4 <= len) { + /* The current slice fits in the packet */ + if (begin_of_slice == 0) { + /* no slice at the beginning of the packet... */ + end_of_slice = 1; + len = r - buf1 - 4; + break; + } + r1 = r; + } else { + if ((r1 - buf1 > 4) && (r - r1 < max_packet_size)) { + len = r1 - buf1 - 4; + end_of_slice = 1; + } + break; + } + } else { + break; + } + } + } + + h = 0; + h |= temporal_reference << 16; + h |= begin_of_sequence << 13; + h |= begin_of_slice << 12; + h |= end_of_slice << 11; + h |= frame_type << 8; + + q = s->buf; + *q++ = h >> 24; + *q++ = h >> 16; + *q++ = h >> 8; + *q++ = h; + + memcpy(q, buf1, len); + q += len; + + /* 90kHz time stamp */ + s->timestamp = s->cur_timestamp; + ff_rtp_send_data(s1, s->buf, q - s->buf, (len == size)); + + buf1 += len; + size -= len; + begin_of_slice = end_of_slice; + end_of_slice = 0; + } +} + + diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rtpproto.c b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpproto.c index 9d80ddf0a7..754908cc0b 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/rtpproto.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rtpproto.c @@ -20,21 +20,24 @@ */ /** - * @file libavformat/rtpproto.c + * @file * RTP protocol */ #include "libavutil/avstring.h" #include "avformat.h" +#include "rtpdec.h" #include #include +#include "internal.h" #include "network.h" #include "os_support.h" #include #if HAVE_SYS_SELECT_H #include #endif +#include #define RTP_TX_BUF_SIZE (64 * 1024) #define RTP_RX_BUF_SIZE (128 * 1024) @@ -63,13 +66,13 @@ int rtp_set_remote_url(URLContext *h, const char *uri) char buf[1024]; char path[1024]; - url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, - path, sizeof(path), uri); + ff_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, + path, sizeof(path), uri); - snprintf(buf, sizeof(buf), "udp://%s:%d%s", hostname, port, path); + ff_url_join(buf, sizeof(buf), "udp", NULL, hostname, port, "%s", path); udp_set_remote_url(s->rtp_hd, buf); - snprintf(buf, sizeof(buf), "udp://%s:%d%s", hostname, port + 1, path); + ff_url_join(buf, sizeof(buf), "udp", NULL, hostname, port + 1, "%s", path); udp_set_remote_url(s->rtcp_hd, buf); return 0; } @@ -100,7 +103,7 @@ static void build_udp_url(char *buf, int buf_size, int local_port, int ttl, int max_packet_size) { - snprintf(buf, buf_size, "udp://%s:%d", hostname, port); + ff_url_join(buf, buf_size, "udp", NULL, hostname, port, NULL); if (local_port >= 0) url_add_option(buf, buf_size, "localport=%d", local_port); if (ttl >= 0) @@ -111,16 +114,26 @@ static void build_udp_url(char *buf, int buf_size, /** * url syntax: rtp://host:port[?option=val...] - * option: 'ttl=n' : set the ttl value (for multicast only) - * 'localport=n' : set the local port to n - * 'pkt_size=n' : set max packet size + * option: 'ttl=n' : set the ttl value (for multicast only) + * 'rtcpport=n' : set the remote rtcp port to n + * 'localrtpport=n' : set the local rtp port to n + * 'localrtcpport=n' : set the local rtcp port to n + * 'pkt_size=n' : set max packet size + * deprecated option: + * 'localport=n' : set the local port to n * + * if rtcpport isn't set the rtcp port will be the rtp port + 1 + * if local rtp port isn't set any available port will be used for the local + * rtp and rtcp ports + * if the local rtcp port is not set it will be the local rtp port + 1 */ static int rtp_open(URLContext *h, const char *uri, int flags) { RTPContext *s; - int port, is_output, ttl, local_port, max_packet_size; + int rtp_port, rtcp_port, + is_output, ttl, + local_rtp_port, local_rtcp_port, max_packet_size; char hostname[256]; char buf[1024]; char path[1024]; @@ -133,11 +146,13 @@ static int rtp_open(URLContext *h, const char *uri, int flags) return AVERROR(ENOMEM); h->priv_data = s; - url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, - path, sizeof(path), uri); + ff_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &rtp_port, + path, sizeof(path), uri); /* extract parameters */ ttl = -1; - local_port = -1; + rtcp_port = rtp_port+1; + local_rtp_port = -1; + local_rtcp_port = -1; max_packet_size = -1; p = strchr(uri, '?'); @@ -145,8 +160,17 @@ static int rtp_open(URLContext *h, const char *uri, int flags) if (find_info_tag(buf, sizeof(buf), "ttl", p)) { ttl = strtol(buf, NULL, 10); } + if (find_info_tag(buf, sizeof(buf), "rtcpport", p)) { + rtcp_port = strtol(buf, NULL, 10); + } if (find_info_tag(buf, sizeof(buf), "localport", p)) { - local_port = strtol(buf, NULL, 10); + local_rtp_port = strtol(buf, NULL, 10); + } + if (find_info_tag(buf, sizeof(buf), "localrtpport", p)) { + local_rtp_port = strtol(buf, NULL, 10); + } + if (find_info_tag(buf, sizeof(buf), "localrtcpport", p)) { + local_rtcp_port = strtol(buf, NULL, 10); } if (find_info_tag(buf, sizeof(buf), "pkt_size", p)) { max_packet_size = strtol(buf, NULL, 10); @@ -154,16 +178,14 @@ static int rtp_open(URLContext *h, const char *uri, int flags) } build_udp_url(buf, sizeof(buf), - hostname, port, local_port, ttl, max_packet_size); + hostname, rtp_port, local_rtp_port, ttl, max_packet_size); if (url_open(&s->rtp_hd, buf, flags) < 0) goto fail; - local_port = udp_get_local_port(s->rtp_hd); - /* XXX: need to open another connection if the port is not even */ - - /* well, should suppress localport in path */ + if (local_rtp_port>=0 && local_rtcp_port<0) + local_rtcp_port = udp_get_local_port(s->rtp_hd) + 1; build_udp_url(buf, sizeof(buf), - hostname, port + 1, local_port + 1, ttl, max_packet_size); + hostname, rtcp_port, local_rtcp_port, ttl, max_packet_size); if (url_open(&s->rtcp_hd, buf, flags) < 0) goto fail; @@ -192,6 +214,7 @@ static int rtp_read(URLContext *h, uint8_t *buf, int size) socklen_t from_len; int len, fd_max, n; fd_set rfds; + struct timeval tv; #if 0 for(;;) { from_len = sizeof(from); @@ -207,6 +230,8 @@ static int rtp_read(URLContext *h, uint8_t *buf, int size) } #else for(;;) { + if (url_interrupt_cb()) + return AVERROR(EINTR); /* build fdset to listen to RTP and RTCP packets */ FD_ZERO(&rfds); fd_max = s->rtp_fd; @@ -214,7 +239,9 @@ static int rtp_read(URLContext *h, uint8_t *buf, int size) if (s->rtcp_fd > fd_max) fd_max = s->rtcp_fd; FD_SET(s->rtcp_fd, &rfds); - n = select(fd_max + 1, &rfds, NULL, NULL, NULL); + tv.tv_sec = 0; + tv.tv_usec = 100 * 1000; + n = select(fd_max + 1, &rfds, NULL, NULL, &tv); if (n > 0) { /* first try RTCP */ if (FD_ISSET(s->rtcp_fd, &rfds)) { @@ -242,6 +269,10 @@ static int rtp_read(URLContext *h, uint8_t *buf, int size) } break; } + } else if (n < 0) { + if (ff_neterrno() == FF_NETERROR(EINTR)) + continue; + return AVERROR(EIO); } } #endif @@ -285,7 +316,19 @@ static int rtp_close(URLContext *h) } /** - * Return the local port used by the RTP connection + * Return the local rtp port used by the RTP connection + * @param s1 media file context + * @return the local port number + */ + +int rtp_get_local_rtp_port(URLContext *h) +{ + RTPContext *s = h->priv_data; + return udp_get_local_port(s->rtp_hd); +} + +/** + * Return the local rtp port used by the RTP connection * @param s1 media file context * @return the local port number */ @@ -296,6 +339,18 @@ int rtp_get_local_port(URLContext *h) return udp_get_local_port(s->rtp_hd); } +/** + * Return the local rtcp port used by the RTP connection + * @param s1 media file context + * @return the local port number + */ + +int rtp_get_local_rtcp_port(URLContext *h) +{ + RTPContext *s = h->priv_data; + return udp_get_local_port(s->rtcp_hd); +} + #if (LIBAVFORMAT_VERSION_MAJOR <= 52) /** * Return the rtp and rtcp file handles for select() usage to wait for diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rtsp.c b/src/add-ons/media/plugins/ffmpeg/libavformat/rtsp.c index 320d45ce7f..6dbd796d31 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/rtsp.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rtsp.c @@ -19,9 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/* needed by inet_aton() */ -#define _SVID_SOURCE - +#include "libavutil/base64.h" #include "libavutil/avstring.h" #include "libavutil/intreadwrite.h" #include "avformat.h" @@ -31,29 +29,27 @@ #include #endif #include +#include "internal.h" #include "network.h" +#include "os_support.h" #include "rtsp.h" #include "rtpdec.h" #include "rdt.h" -#include "rtp_asf.h" -#include "rtp_vorbis.h" +#include "rtpdec_asf.h" //#define DEBUG //#define DEBUG_RTP_TCP -static int rtsp_read_play(AVFormatContext *s); - #if LIBAVFORMAT_VERSION_INT < (53 << 16) int rtsp_default_protocols = (1 << RTSP_LOWER_TRANSPORT_UDP); #endif -static int rtsp_probe(AVProbeData *p) -{ - if (av_strstart(p->filename, "rtsp:", NULL)) - return AVPROBE_SCORE_MAX; - return 0; -} +/* Timeout values for socket select, in ms, + * and read_packet(), in seconds */ +#define SELECT_TIMEOUT_MS 100 +#define READ_PACKET_TIMEOUT_S 10 +#define MAX_TIMEOUTS READ_PACKET_TIMEOUT_S * 1000 / SELECT_TIMEOUT_MS #define SPACE_CHARS " \t\r\n" /* we use memchr() instead of strchr() here because strchr() will return @@ -99,9 +95,10 @@ static void get_word(char *buf, int buf_size, const char **pp) get_word_until_chars(buf, buf_size, SPACE_CHARS, pp); } -/* parse the rtpmap description: /[/] */ -static int sdp_parse_rtpmap(AVCodecContext *codec, RTSPStream *rtsp_st, int payload_type, const char *p) +/* parse the rtpmap description: /[/] */ +static int sdp_parse_rtpmap(AVFormatContext *s, + AVCodecContext *codec, RTSPStream *rtsp_st, + int payload_type, const char *p) { char buf[256]; int i; @@ -109,23 +106,27 @@ static int sdp_parse_rtpmap(AVCodecContext *codec, RTSPStream *rtsp_st, int payl const char *c_name; /* Loop into AVRtpDynamicPayloadTypes[] and AVRtpPayloadTypes[] and - see if we can handle this kind of payload */ - get_word_sep(buf, sizeof(buf), "/", &p); + * see if we can handle this kind of payload. + * The space should normally not be there but some Real streams or + * particular servers ("RealServer Version 6.1.3.970", see issue 1658) + * have a trailing space. */ + get_word_sep(buf, sizeof(buf), "/ ", &p); if (payload_type >= RTP_PT_PRIVATE) { - RTPDynamicProtocolHandler *handler= RTPFirstDynamicPayloadHandler; - while(handler) { - if (!strcasecmp(buf, handler->enc_name) && (codec->codec_type == handler->codec_type)) { - codec->codec_id = handler->codec_id; - rtsp_st->dynamic_handler= handler; - if(handler->open) { - rtsp_st->dynamic_protocol_context= handler->open(); - } + RTPDynamicProtocolHandler *handler; + for (handler = RTPFirstDynamicPayloadHandler; + handler; handler = handler->next) { + if (!strcasecmp(buf, handler->enc_name) && + codec->codec_type == handler->codec_type) { + codec->codec_id = handler->codec_id; + rtsp_st->dynamic_handler = handler; + if (handler->open) + rtsp_st->dynamic_protocol_context = handler->open(); break; } - handler= handler->next; } } else { - /* We are in a standard case ( from http://www.iana.org/assignments/rtp-parameters) */ + /* We are in a standard case + * (from http://www.iana.org/assignments/rtp-parameters). */ /* search into AVRtpPayloadTypes[] */ codec->codec_id = ff_rtp_codec_id(buf, codec->codec_type); } @@ -134,52 +135,52 @@ static int sdp_parse_rtpmap(AVCodecContext *codec, RTSPStream *rtsp_st, int payl if (c && c->name) c_name = c->name; else - c_name = (char *)NULL; + c_name = "(null)"; - if (c_name) { - get_word_sep(buf, sizeof(buf), "/", &p); - i = atoi(buf); - switch (codec->codec_type) { - case CODEC_TYPE_AUDIO: - av_log(codec, AV_LOG_DEBUG, " audio codec set to : %s\n", c_name); - codec->sample_rate = RTSP_DEFAULT_AUDIO_SAMPLERATE; - codec->channels = RTSP_DEFAULT_NB_AUDIO_CHANNELS; - if (i > 0) { - codec->sample_rate = i; - get_word_sep(buf, sizeof(buf), "/", &p); - i = atoi(buf); - if (i > 0) - codec->channels = i; - // TODO: there is a bug here; if it is a mono stream, and less than 22000Hz, faad upconverts to stereo and twice the - // frequency. No problem, but the sample rate is being set here by the sdp line. Upcoming patch forthcoming. (rdm) - } - av_log(codec, AV_LOG_DEBUG, " audio samplerate set to : %i\n", codec->sample_rate); - av_log(codec, AV_LOG_DEBUG, " audio channels set to : %i\n", codec->channels); - break; - case CODEC_TYPE_VIDEO: - av_log(codec, AV_LOG_DEBUG, " video codec set to : %s\n", c_name); - break; - default: - break; + get_word_sep(buf, sizeof(buf), "/", &p); + i = atoi(buf); + switch (codec->codec_type) { + case AVMEDIA_TYPE_AUDIO: + av_log(s, AV_LOG_DEBUG, "audio codec set to: %s\n", c_name); + codec->sample_rate = RTSP_DEFAULT_AUDIO_SAMPLERATE; + codec->channels = RTSP_DEFAULT_NB_AUDIO_CHANNELS; + if (i > 0) { + codec->sample_rate = i; + get_word_sep(buf, sizeof(buf), "/", &p); + i = atoi(buf); + if (i > 0) + codec->channels = i; + // TODO: there is a bug here; if it is a mono stream, and + // less than 22000Hz, faad upconverts to stereo and twice + // the frequency. No problem, but the sample rate is being + // set here by the sdp line. Patch on its way. (rdm) } - return 0; + av_log(s, AV_LOG_DEBUG, "audio samplerate set to: %i\n", + codec->sample_rate); + av_log(s, AV_LOG_DEBUG, "audio channels set to: %i\n", + codec->channels); + break; + case AVMEDIA_TYPE_VIDEO: + av_log(s, AV_LOG_DEBUG, "video codec set to: %s\n", c_name); + break; + default: + break; } - - return -1; + return 0; } -/* return the length and optionnaly the data */ +/* return the length and optionally the data */ static int hex_to_data(uint8_t *data, const char *p) { int c, len, v; len = 0; v = 1; - for(;;) { + for (;;) { skip_spaces(&p); if (*p == '\0') break; - c = toupper((unsigned char)*p++); + c = toupper((unsigned char) *p++); if (c >= '0' && c <= '9') c = c - '0'; else if (c >= 'A' && c <= 'F') @@ -201,56 +202,60 @@ static void sdp_parse_fmtp_config(AVCodecContext * codec, void *ctx, char *attr, char *value) { switch (codec->codec_id) { - case CODEC_ID_MPEG4: - case CODEC_ID_AAC: - if (!strcmp(attr, "config")) { - /* decode the hexa encoded parameter */ - int len = hex_to_data(NULL, value); - if (codec->extradata) - av_free(codec->extradata); - codec->extradata = av_mallocz(len + FF_INPUT_BUFFER_PADDING_SIZE); - if (!codec->extradata) - return; - codec->extradata_size = len; - hex_to_data(codec->extradata, value); - } - break; - case CODEC_ID_VORBIS: - ff_vorbis_parse_fmtp_config(codec, ctx, attr, value); - break; - default: - break; + case CODEC_ID_MPEG4: + case CODEC_ID_AAC: + if (!strcmp(attr, "config")) { + /* decode the hexa encoded parameter */ + int len = hex_to_data(NULL, value); + if (codec->extradata) + av_free(codec->extradata); + codec->extradata = av_mallocz(len + FF_INPUT_BUFFER_PADDING_SIZE); + if (!codec->extradata) + return; + codec->extradata_size = len; + hex_to_data(codec->extradata, value); + } + break; + default: + break; } return; } typedef struct { const char *str; - uint16_t type; - uint32_t offset; + uint16_t type; + uint32_t offset; } AttrNameMap; -/* All known fmtp parmeters and the corresping RTPAttrTypeEnum */ +/* All known fmtp parameters and the corresponding RTPAttrTypeEnum */ #define ATTR_NAME_TYPE_INT 0 #define ATTR_NAME_TYPE_STR 1 static const AttrNameMap attr_names[]= { - {"SizeLength", ATTR_NAME_TYPE_INT, offsetof(RTPPayloadData, sizelength)}, - {"IndexLength", ATTR_NAME_TYPE_INT, offsetof(RTPPayloadData, indexlength)}, - {"IndexDeltaLength", ATTR_NAME_TYPE_INT, offsetof(RTPPayloadData, indexdeltalength)}, - {"profile-level-id", ATTR_NAME_TYPE_INT, offsetof(RTPPayloadData, profile_level_id)}, - {"StreamType", ATTR_NAME_TYPE_INT, offsetof(RTPPayloadData, streamtype)}, - {"mode", ATTR_NAME_TYPE_STR, offsetof(RTPPayloadData, mode)}, - {NULL, -1, -1}, + { "SizeLength", ATTR_NAME_TYPE_INT, + offsetof(RTPPayloadData, sizelength) }, + { "IndexLength", ATTR_NAME_TYPE_INT, + offsetof(RTPPayloadData, indexlength) }, + { "IndexDeltaLength", ATTR_NAME_TYPE_INT, + offsetof(RTPPayloadData, indexdeltalength) }, + { "profile-level-id", ATTR_NAME_TYPE_INT, + offsetof(RTPPayloadData, profile_level_id) }, + { "StreamType", ATTR_NAME_TYPE_INT, + offsetof(RTPPayloadData, streamtype) }, + { "mode", ATTR_NAME_TYPE_STR, + offsetof(RTPPayloadData, mode) }, + { NULL, -1, -1 }, }; -/** parse the attribute line from the fmtp a line of an sdp resonse. This is broken out as a function -* because it is used in rtp_h264.c, which is forthcoming. -*/ -int rtsp_next_attr_and_value(const char **p, char *attr, int attr_size, char *value, int value_size) +/* parse the attribute line from the fmtp a line of an sdp response. This + * is broken out as a function because it is used in rtp_h264.c, which is + * forthcoming. */ +int ff_rtsp_next_attr_and_value(const char **p, char *attr, int attr_size, + char *value, int value_size) { skip_spaces(p); - if(**p) { + if (**p) { get_word_sep(attr, attr_size, "=", p); if (**p == '=') (*p)++; @@ -270,30 +275,32 @@ static void sdp_parse_fmtp(AVStream *st, const char *p) * encoded, giving a 12KB * (4/3) = 16KB FMTP line. */ char value[16384]; int i; - RTSPStream *rtsp_st = st->priv_data; AVCodecContext *codec = st->codec; RTPPayloadData *rtp_payload_data = &rtsp_st->rtp_payload_data; /* loop on each attribute */ - while(rtsp_next_attr_and_value(&p, attr, sizeof(attr), value, sizeof(value))) - { - /* grab the codec extra_data from the config parameter of the fmtp line */ + while (ff_rtsp_next_attr_and_value(&p, attr, sizeof(attr), + value, sizeof(value))) { + /* grab the codec extra_data from the config parameter of the fmtp + * line */ sdp_parse_fmtp_config(codec, rtsp_st->dynamic_protocol_context, attr, value); /* Looking for a known attribute */ for (i = 0; attr_names[i].str; ++i) { if (!strcasecmp(attr, attr_names[i].str)) { - if (attr_names[i].type == ATTR_NAME_TYPE_INT) - *(int *)((char *)rtp_payload_data + attr_names[i].offset) = atoi(value); - else if (attr_names[i].type == ATTR_NAME_TYPE_STR) - *(char **)((char *)rtp_payload_data + attr_names[i].offset) = av_strdup(value); + if (attr_names[i].type == ATTR_NAME_TYPE_INT) { + *(int *)((char *)rtp_payload_data + + attr_names[i].offset) = atoi(value); + } else if (attr_names[i].type == ATTR_NAME_TYPE_STR) + *(char **)((char *)rtp_payload_data + + attr_names[i].offset) = av_strdup(value); } } } } -/** Parse a string \p in the form of Range:npt=xx-xx, and determine the start +/** Parse a string p in the form of Range:npt=xx-xx, and determine the start * and end time. * Used for seeking in the rtp stream. */ @@ -322,8 +329,8 @@ static void rtsp_parse_range_npt(const char *p, int64_t *start, int64_t *end) typedef struct SDPParseState { /* SDP only */ struct in_addr default_ip; - int default_ttl; - int skip_media; ///< set if an unknown m= line occurs + int default_ttl; + int skip_media; ///< set if an unknown m= line occurs } SDPParseState; static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, @@ -332,7 +339,7 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, RTSPState *rt = s->priv_data; char buf1[64], st_type[64]; const char *p; - enum CodecType codec_type; + enum AVMediaType codec_type; int payload_type, i; AVStream *st; RTSPStream *rtsp_st; @@ -344,7 +351,7 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, p = buf; if (s1->skip_media && letter != 'm') return; - switch(letter) { + switch (letter) { case 'c': get_word(buf1, sizeof(buf1), &p); if (strcmp(buf1, "IN") != 0) @@ -353,7 +360,7 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, if (strcmp(buf1, "IP4") != 0) return; get_word_sep(buf1, sizeof(buf1), "/", &p); - if (inet_aton(buf1, &sdp_ip) == 0) + if (ff_inet_aton(buf1, &sdp_ip) == 0) return; ttl = 16; if (*p == '/') { @@ -372,11 +379,11 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, } break; case 's': - av_metadata_set(&s->metadata, "title", p); + av_metadata_set2(&s->metadata, "title", p, 0); break; case 'i': if (s->nb_streams == 0) { - av_metadata_set(&s->metadata, "comment", p); + av_metadata_set2(&s->metadata, "comment", p, 0); break; } break; @@ -385,11 +392,11 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, s1->skip_media = 0; get_word(st_type, sizeof(st_type), &p); if (!strcmp(st_type, "audio")) { - codec_type = CODEC_TYPE_AUDIO; + codec_type = AVMEDIA_TYPE_AUDIO; } else if (!strcmp(st_type, "video")) { - codec_type = CODEC_TYPE_VIDEO; + codec_type = AVMEDIA_TYPE_VIDEO; } else if (!strcmp(st_type, "application")) { - codec_type = CODEC_TYPE_DATA; + codec_type = AVMEDIA_TYPE_DATA; } else { s1->skip_media = 1; return; @@ -427,23 +434,34 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, } } /* put a default control url */ - av_strlcpy(rtsp_st->control_url, s->filename, sizeof(rtsp_st->control_url)); + av_strlcpy(rtsp_st->control_url, rt->control_uri, + sizeof(rtsp_st->control_url)); break; case 'a': - if (av_strstart(p, "control:", &p) && s->nb_streams > 0) { + if (av_strstart(p, "control:", &p)) { + if (s->nb_streams == 0) { + if (!strncmp(p, "rtsp://", 7)) + av_strlcpy(rt->control_uri, p, + sizeof(rt->control_uri)); + } else { char proto[32]; /* get the control url */ st = s->streams[s->nb_streams - 1]; rtsp_st = st->priv_data; /* XXX: may need to add full url resolution */ - url_split(proto, sizeof(proto), NULL, 0, NULL, 0, NULL, NULL, 0, p); + ff_url_split(proto, sizeof(proto), NULL, 0, NULL, 0, + NULL, NULL, 0, p); if (proto[0] == '\0') { /* relative control URL */ - av_strlcat(rtsp_st->control_url, "/", sizeof(rtsp_st->control_url)); - av_strlcat(rtsp_st->control_url, p, sizeof(rtsp_st->control_url)); - } else { - av_strlcpy(rtsp_st->control_url, p, sizeof(rtsp_st->control_url)); + if (rtsp_st->control_url[strlen(rtsp_st->control_url)-1]!='/') + av_strlcat(rtsp_st->control_url, "/", + sizeof(rtsp_st->control_url)); + av_strlcat(rtsp_st->control_url, p, + sizeof(rtsp_st->control_url)); + } else + av_strlcpy(rtsp_st->control_url, p, + sizeof(rtsp_st->control_url)); } } else if (av_strstart(p, "rtpmap:", &p) && s->nb_streams > 0) { /* NOTE: rtpmap is only supported AFTER the 'm=' tag */ @@ -451,44 +469,44 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, payload_type = atoi(buf1); st = s->streams[s->nb_streams - 1]; rtsp_st = st->priv_data; - sdp_parse_rtpmap(st->codec, rtsp_st, payload_type, p); + sdp_parse_rtpmap(s, st->codec, rtsp_st, payload_type, p); } else if (av_strstart(p, "fmtp:", &p)) { /* NOTE: fmtp is only supported AFTER the 'a=rtpmap:xxx' tag */ get_word(buf1, sizeof(buf1), &p); payload_type = atoi(buf1); - for(i = 0; i < s->nb_streams;i++) { - st = s->streams[i]; + for (i = 0; i < s->nb_streams; i++) { + st = s->streams[i]; rtsp_st = st->priv_data; if (rtsp_st->sdp_payload_type == payload_type) { - if(rtsp_st->dynamic_handler && rtsp_st->dynamic_handler->parse_sdp_a_line) { - if(!rtsp_st->dynamic_handler->parse_sdp_a_line(s, i, rtsp_st->dynamic_protocol_context, buf)) { - sdp_parse_fmtp(st, p); - } - } else { + if (!(rtsp_st->dynamic_handler && + rtsp_st->dynamic_handler->parse_sdp_a_line && + rtsp_st->dynamic_handler->parse_sdp_a_line(s, + i, rtsp_st->dynamic_protocol_context, buf))) sdp_parse_fmtp(st, p); - } } } - } else if(av_strstart(p, "framesize:", &p)) { + } else if (av_strstart(p, "framesize:", &p)) { // let dynamic protocol handlers have a stab at the line. get_word(buf1, sizeof(buf1), &p); payload_type = atoi(buf1); - for(i = 0; i < s->nb_streams;i++) { - st = s->streams[i]; + for (i = 0; i < s->nb_streams; i++) { + st = s->streams[i]; rtsp_st = st->priv_data; - if (rtsp_st->sdp_payload_type == payload_type) { - if(rtsp_st->dynamic_handler && rtsp_st->dynamic_handler->parse_sdp_a_line) { - rtsp_st->dynamic_handler->parse_sdp_a_line(s, i, rtsp_st->dynamic_protocol_context, buf); - } - } + if (rtsp_st->sdp_payload_type == payload_type && + rtsp_st->dynamic_handler && + rtsp_st->dynamic_handler->parse_sdp_a_line) + rtsp_st->dynamic_handler->parse_sdp_a_line(s, i, + rtsp_st->dynamic_protocol_context, buf); } - } else if(av_strstart(p, "range:", &p)) { + } else if (av_strstart(p, "range:", &p)) { int64_t start, end; // this is so that seeking on a streamed file can work. rtsp_parse_range_npt(p, &start, &end); - s->start_time= start; - s->duration= (end==AV_NOPTS_VALUE)?AV_NOPTS_VALUE:end-start; // AV_NOPTS_VALUE means live broadcast (and can't seek) + s->start_time = start; + /* AV_NOPTS_VALUE means live broadcast (and can't seek) */ + s->duration = (end == AV_NOPTS_VALUE) ? + AV_NOPTS_VALUE : end - start; } else if (av_strstart(p, "IsRealDataType:integer;",&p)) { if (atoi(p) == 1) rt->transport = RTSP_TRANSPORT_RDT; @@ -502,7 +520,8 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, rtsp_st = s->streams[s->nb_streams - 1]->priv_data; if (rtsp_st->dynamic_handler && rtsp_st->dynamic_handler->parse_sdp_a_line) - rtsp_st->dynamic_handler->parse_sdp_a_line(s, s->nb_streams - 1, + rtsp_st->dynamic_handler->parse_sdp_a_line(s, + s->nb_streams - 1, rtsp_st->dynamic_protocol_context, buf); } } @@ -526,7 +545,7 @@ static int sdp_parse(AVFormatContext *s, const char *content) memset(s1, 0, sizeof(SDPParseState)); p = content; - for(;;) { + for (;;) { skip_spaces(&p); letter = *p; if (letter == '\0') @@ -553,6 +572,154 @@ static int sdp_parse(AVFormatContext *s, const char *content) return 0; } +/* close and free RTSP streams */ +void ff_rtsp_close_streams(AVFormatContext *s) +{ + RTSPState *rt = s->priv_data; + int i; + RTSPStream *rtsp_st; + + for (i = 0; i < rt->nb_rtsp_streams; i++) { + rtsp_st = rt->rtsp_streams[i]; + if (rtsp_st) { + if (rtsp_st->transport_priv) { + if (s->oformat) { + AVFormatContext *rtpctx = rtsp_st->transport_priv; + av_write_trailer(rtpctx); + if (rt->lower_transport == RTSP_LOWER_TRANSPORT_TCP) { + uint8_t *ptr; + url_close_dyn_buf(rtpctx->pb, &ptr); + av_free(ptr); + } else { + url_fclose(rtpctx->pb); + } + av_metadata_free(&rtpctx->streams[0]->metadata); + av_metadata_free(&rtpctx->metadata); + av_free(rtpctx->streams[0]); + av_free(rtpctx); + } else if (rt->transport == RTSP_TRANSPORT_RDT) + ff_rdt_parse_close(rtsp_st->transport_priv); + else + rtp_parse_close(rtsp_st->transport_priv); + } + if (rtsp_st->rtp_handle) + url_close(rtsp_st->rtp_handle); + if (rtsp_st->dynamic_handler && rtsp_st->dynamic_protocol_context) + rtsp_st->dynamic_handler->close( + rtsp_st->dynamic_protocol_context); + } + } + av_free(rt->rtsp_streams); + if (rt->asf_ctx) { + av_close_input_stream (rt->asf_ctx); + rt->asf_ctx = NULL; + } +} + +static void *rtsp_rtp_mux_open(AVFormatContext *s, AVStream *st, + URLContext *handle) +{ + RTSPState *rt = s->priv_data; + AVFormatContext *rtpctx; + int ret; + AVOutputFormat *rtp_format = av_guess_format("rtp", NULL, NULL); + + if (!rtp_format) + return NULL; + + /* Allocate an AVFormatContext for each output stream */ + rtpctx = avformat_alloc_context(); + if (!rtpctx) + return NULL; + + rtpctx->oformat = rtp_format; + if (!av_new_stream(rtpctx, 0)) { + av_free(rtpctx); + return NULL; + } + /* Copy the max delay setting; the rtp muxer reads this. */ + rtpctx->max_delay = s->max_delay; + /* Copy other stream parameters. */ + rtpctx->streams[0]->sample_aspect_ratio = st->sample_aspect_ratio; + + /* Set the synchronized start time. */ + rtpctx->start_time_realtime = rt->start_time; + + /* Remove the local codec, link to the original codec + * context instead, to give the rtp muxer access to + * codec parameters. */ + av_free(rtpctx->streams[0]->codec); + rtpctx->streams[0]->codec = st->codec; + + if (handle) { + url_fdopen(&rtpctx->pb, handle); + } else + url_open_dyn_packet_buf(&rtpctx->pb, RTSP_TCP_MAX_PACKET_SIZE); + ret = av_write_header(rtpctx); + + if (ret) { + if (handle) { + url_fclose(rtpctx->pb); + } else { + uint8_t *ptr; + url_close_dyn_buf(rtpctx->pb, &ptr); + av_free(ptr); + } + av_free(rtpctx->streams[0]); + av_free(rtpctx); + return NULL; + } + + /* Copy the RTP AVStream timebase back to the original AVStream */ + st->time_base = rtpctx->streams[0]->time_base; + return rtpctx; +} + +static int rtsp_open_transport_ctx(AVFormatContext *s, RTSPStream *rtsp_st) +{ + RTSPState *rt = s->priv_data; + AVStream *st = NULL; + + /* open the RTP context */ + if (rtsp_st->stream_index >= 0) + st = s->streams[rtsp_st->stream_index]; + if (!st) + s->ctx_flags |= AVFMTCTX_NOHEADER; + + if (s->oformat) { + rtsp_st->transport_priv = rtsp_rtp_mux_open(s, st, rtsp_st->rtp_handle); + /* Ownership of rtp_handle is passed to the rtp mux context */ + rtsp_st->rtp_handle = NULL; + } else if (rt->transport == RTSP_TRANSPORT_RDT) + rtsp_st->transport_priv = ff_rdt_parse_open(s, st->index, + rtsp_st->dynamic_protocol_context, + rtsp_st->dynamic_handler); + else + rtsp_st->transport_priv = rtp_parse_open(s, st, rtsp_st->rtp_handle, + rtsp_st->sdp_payload_type, + &rtsp_st->rtp_payload_data); + + if (!rtsp_st->transport_priv) { + return AVERROR(ENOMEM); + } else if (rt->transport != RTSP_TRANSPORT_RDT) { + if (rtsp_st->dynamic_handler) { + rtp_parse_set_dynamic_protocol(rtsp_st->transport_priv, + rtsp_st->dynamic_protocol_context, + rtsp_st->dynamic_handler); + } + } + + return 0; +} + +#if CONFIG_RTSP_DEMUXER || CONFIG_RTSP_MUXER +static int rtsp_probe(AVProbeData *p) +{ + if (av_strstart(p->filename, "rtsp:", NULL)) + return AVPROBE_SCORE_MAX; + return 0; +} + static void rtsp_parse_range(int *min_ptr, int *max_ptr, const char **pp) { const char *p; @@ -585,7 +752,7 @@ static void rtsp_parse_transport(RTSPMessageHeader *reply, const char *p) reply->nb_transports = 0; - for(;;) { + for (;;) { skip_spaces(&p); if (*p == '\0') break; @@ -657,7 +824,7 @@ static void rtsp_parse_transport(RTSPMessageHeader *reply, const char *p) if (*p == '=') { p++; get_word_sep(buf, sizeof(buf), ";,", &p); - if (inet_aton(buf, &ipaddr)) + if (ff_inet_aton(buf, &ipaddr)) th->destination = ntohl(ipaddr.s_addr); } } @@ -673,7 +840,8 @@ static void rtsp_parse_transport(RTSPMessageHeader *reply, const char *p) } } -void rtsp_parse_line(RTSPMessageHeader *reply, const char *buf) +void ff_rtsp_parse_line(RTSPMessageHeader *reply, const char *buf, + HTTPAuthState *auth_state) { const char *p; @@ -703,11 +871,20 @@ void rtsp_parse_line(RTSPMessageHeader *reply, const char *buf) } else if (av_stristart(p, "Notice:", &p) || av_stristart(p, "X-Notice:", &p)) { reply->notice = strtol(p, NULL, 10); + } else if (av_stristart(p, "Location:", &p)) { + skip_spaces(&p); + av_strlcpy(reply->location, p , sizeof(reply->location)); + } else if (av_stristart(p, "WWW-Authenticate:", &p) && auth_state) { + skip_spaces(&p); + ff_http_auth_handle_header(auth_state, "WWW-Authenticate", p); + } else if (av_stristart(p, "Authentication-Info:", &p) && auth_state) { + skip_spaces(&p); + ff_http_auth_handle_header(auth_state, "Authentication-Info", p); } } /* skip a RTP/TCP interleaved packet */ -static void rtsp_skip_packet(AVFormatContext *s) +void ff_rtsp_skip_packet(AVFormatContext *s) { RTSPState *rt = s->priv_data; int ret, len, len1; @@ -732,30 +909,9 @@ static void rtsp_skip_packet(AVFormatContext *s) } } -/** - * Read a RTSP message from the server, or prepare to read data - * packets if we're reading data interleaved over the TCP/RTSP - * connection as well. - * - * @param s RTSP demuxer context - * @param reply pointer where the RTSP message header will be stored - * @param content_ptr pointer where the RTSP message body, if any, will - * be stored (length is in \p reply) - * @param return_on_interleaved_data whether the function may return if we - * encounter a data marker ('$'), which precedes data - * packets over interleaved TCP/RTSP connections. If this - * is set, this function will return 1 after encountering - * a '$'. If it is not set, the function will skip any - * data packets (if they are encountered), until a reply - * has been fully parsed. If no more data is available - * without parsing a reply, it will return an error. - * - * @returns 1 if a data packets is ready to be received, -1 on error, - * and 0 on success. - */ -static int -rtsp_read_reply (AVFormatContext *s, RTSPMessageHeader *reply, - unsigned char **content_ptr, int return_on_interleaved_data) +int ff_rtsp_read_reply(AVFormatContext *s, RTSPMessageHeader *reply, + unsigned char **content_ptr, + int return_on_interleaved_data) { RTSPState *rt = s->priv_data; char buf[4096], buf1[1024], *q; @@ -768,9 +924,9 @@ rtsp_read_reply (AVFormatContext *s, RTSPMessageHeader *reply, /* parse reply (XXX: use buffers) */ rt->last_reply[0] = '\0'; - for(;;) { + for (;;) { q = buf; - for(;;) { + for (;;) { ret = url_read_complete(rt->rtsp_hd, &ch, 1); #ifdef DEBUG_RTP_TCP dprintf(s, "ret=%d c=%02x [%c]\n", ret, ch, ch); @@ -784,7 +940,7 @@ rtsp_read_reply (AVFormatContext *s, RTSPMessageHeader *reply, if (return_on_interleaved_data) { return 1; } else - rtsp_skip_packet(s); + ff_rtsp_skip_packet(s); } else if (ch != '\r') { if ((q - buf) < sizeof(buf) - 1) *q++ = ch; @@ -804,7 +960,7 @@ rtsp_read_reply (AVFormatContext *s, RTSPMessageHeader *reply, get_word(buf1, sizeof(buf1), &p); reply->status_code = atoi(buf1); } else { - rtsp_parse_line(reply, p); + ff_rtsp_parse_line(reply, p, &rt->auth_state); av_strlcat(rt->last_reply, p, sizeof(rt->last_reply)); av_strlcat(rt->last_reply, "\n", sizeof(rt->last_reply)); } @@ -826,121 +982,104 @@ rtsp_read_reply (AVFormatContext *s, RTSPMessageHeader *reply, else av_free(content); + if (rt->seq != reply->seq) { + av_log(s, AV_LOG_WARNING, "CSeq %d expected, %d received.\n", + rt->seq, reply->seq); + } + /* EOS */ if (reply->notice == 2101 /* End-of-Stream Reached */ || reply->notice == 2104 /* Start-of-Stream Reached */ || - reply->notice == 2306 /* Continuous Feed Terminated */) + reply->notice == 2306 /* Continuous Feed Terminated */) { rt->state = RTSP_STATE_IDLE; - else if (reply->notice >= 4400 && reply->notice < 5500) + } else if (reply->notice >= 4400 && reply->notice < 5500) { return AVERROR(EIO); /* data or server error */ - else if (reply->notice == 2401 /* Ticket Expired */ || + } else if (reply->notice == 2401 /* Ticket Expired */ || (reply->notice >= 5500 && reply->notice < 5600) /* end of term */ ) return AVERROR(EPERM); return 0; } -static void rtsp_send_cmd_async (AVFormatContext *s, - const char *cmd, RTSPMessageHeader *reply, - unsigned char **content_ptr) +void ff_rtsp_send_cmd_with_content_async(AVFormatContext *s, + const char *method, const char *url, + const char *headers, + const unsigned char *send_content, + int send_content_length) { RTSPState *rt = s->priv_data; - char buf[4096], buf1[1024]; + char buf[4096]; rt->seq++; - av_strlcpy(buf, cmd, sizeof(buf)); - snprintf(buf1, sizeof(buf1), "CSeq: %d\r\n", rt->seq); - av_strlcat(buf, buf1, sizeof(buf)); - if (rt->session_id[0] != '\0' && !strstr(cmd, "\nIf-Match:")) { - snprintf(buf1, sizeof(buf1), "Session: %s\r\n", rt->session_id); - av_strlcat(buf, buf1, sizeof(buf)); + snprintf(buf, sizeof(buf), "%s %s RTSP/1.0\r\n", method, url); + if (headers) + av_strlcat(buf, headers, sizeof(buf)); + av_strlcatf(buf, sizeof(buf), "CSeq: %d\r\n", rt->seq); + if (rt->session_id[0] != '\0' && (!headers || + !strstr(headers, "\nIf-Match:"))) { + av_strlcatf(buf, sizeof(buf), "Session: %s\r\n", rt->session_id); } + if (rt->auth[0]) { + char *str = ff_http_auth_create_response(&rt->auth_state, + rt->auth, url, method); + if (str) + av_strlcat(buf, str, sizeof(buf)); + av_free(str); + } + if (send_content_length > 0 && send_content) + av_strlcatf(buf, sizeof(buf), "Content-Length: %d\r\n", send_content_length); av_strlcat(buf, "\r\n", sizeof(buf)); dprintf(s, "Sending:\n%s--\n", buf); url_write(rt->rtsp_hd, buf, strlen(buf)); + if (send_content_length > 0 && send_content) + url_write(rt->rtsp_hd, send_content, send_content_length); rt->last_cmd_time = av_gettime(); } -static void rtsp_send_cmd (AVFormatContext *s, - const char *cmd, RTSPMessageHeader *reply, - unsigned char **content_ptr) +void ff_rtsp_send_cmd_async(AVFormatContext *s, const char *method, + const char *url, const char *headers) { - rtsp_send_cmd_async(s, cmd, reply, content_ptr); - - rtsp_read_reply(s, reply, content_ptr, 0); + ff_rtsp_send_cmd_with_content_async(s, method, url, headers, NULL, 0); } - -/* close and free RTSP streams */ -static void rtsp_close_streams(RTSPState *rt) +void ff_rtsp_send_cmd(AVFormatContext *s, const char *method, const char *url, + const char *headers, RTSPMessageHeader *reply, + unsigned char **content_ptr) { - int i; - RTSPStream *rtsp_st; - - for(i=0;inb_rtsp_streams;i++) { - rtsp_st = rt->rtsp_streams[i]; - if (rtsp_st) { - if (rtsp_st->transport_priv) { - if (rt->transport == RTSP_TRANSPORT_RDT) - ff_rdt_parse_close(rtsp_st->transport_priv); - else - rtp_parse_close(rtsp_st->transport_priv); - } - if (rtsp_st->rtp_handle) - url_close(rtsp_st->rtp_handle); - if (rtsp_st->dynamic_handler && rtsp_st->dynamic_protocol_context) - rtsp_st->dynamic_handler->close(rtsp_st->dynamic_protocol_context); - } - } - av_free(rt->rtsp_streams); - if (rt->asf_ctx) { - av_close_input_stream (rt->asf_ctx); - rt->asf_ctx = NULL; - } + ff_rtsp_send_cmd_with_content(s, method, url, headers, reply, + content_ptr, NULL, 0); } -static int -rtsp_open_transport_ctx(AVFormatContext *s, RTSPStream *rtsp_st) +void ff_rtsp_send_cmd_with_content(AVFormatContext *s, + const char *method, const char *url, + const char *header, + RTSPMessageHeader *reply, + unsigned char **content_ptr, + const unsigned char *send_content, + int send_content_length) { RTSPState *rt = s->priv_data; - AVStream *st = NULL; + HTTPAuthType cur_auth_type; - /* open the RTP context */ - if (rtsp_st->stream_index >= 0) - st = s->streams[rtsp_st->stream_index]; - if (!st) - s->ctx_flags |= AVFMTCTX_NOHEADER; +retry: + cur_auth_type = rt->auth_state.auth_type; + ff_rtsp_send_cmd_with_content_async(s, method, url, header, + send_content, send_content_length); - if (rt->transport == RTSP_TRANSPORT_RDT) - rtsp_st->transport_priv = ff_rdt_parse_open(s, st->index, - rtsp_st->dynamic_protocol_context, - rtsp_st->dynamic_handler); - else - rtsp_st->transport_priv = rtp_parse_open(s, st, rtsp_st->rtp_handle, - rtsp_st->sdp_payload_type, - &rtsp_st->rtp_payload_data); + ff_rtsp_read_reply(s, reply, content_ptr, 0); - if (!rtsp_st->transport_priv) { - return AVERROR(ENOMEM); - } else if (rt->transport != RTSP_TRANSPORT_RDT) { - if(rtsp_st->dynamic_handler) { - rtp_parse_set_dynamic_protocol(rtsp_st->transport_priv, - rtsp_st->dynamic_protocol_context, - rtsp_st->dynamic_handler); - } - } - - return 0; + if (reply->status_code == 401 && cur_auth_type == HTTP_AUTH_NONE && + rt->auth_state.auth_type != HTTP_AUTH_NONE) + goto retry; } /** - * @returns 0 on success, <0 on error, 1 if protocol is unavailable. + * @return 0 on success, <0 on error, 1 if protocol is unavailable. */ -static int -make_setup_request (AVFormatContext *s, const char *host, int port, - int lower_transport, const char *real_challenge) +static int make_setup_request(AVFormatContext *s, const char *host, int port, + int lower_transport, const char *real_challenge) { RTSPState *rt = s->priv_data; int rtx, j, i, err, interleave = 0; @@ -959,9 +1098,9 @@ make_setup_request (AVFormatContext *s, const char *host, int port, /* for each stream, make the setup request */ /* XXX: we assume the same server is used for the control of each - RTSP stream */ + * RTSP stream */ - for(j = RTSP_RTP_PORT_MIN, i = 0; i < rt->nb_rtsp_streams; ++i) { + for (j = RTSP_RTP_PORT_MIN, i = 0; i < rt->nb_rtsp_streams; ++i) { char transport[2048]; /** @@ -976,7 +1115,8 @@ make_setup_request (AVFormatContext *s, const char *host, int port, for (rtx = 0; rtx < rt->nb_rtsp_streams; rtx++) { int len = strlen(rt->rtsp_streams[rtx]->control_url); if (len >= 4 && - !strcmp(rt->rtsp_streams[rtx]->control_url + len - 4, "/rtx")) + !strcmp(rt->rtsp_streams[rtx]->control_url + len - 4, + "/rtx")) break; } if (rtx == rt->nb_rtsp_streams) @@ -998,21 +1138,23 @@ make_setup_request (AVFormatContext *s, const char *host, int port, /* first try in specified port range */ if (RTSP_RTP_PORT_MIN != 0) { - while(j <= RTSP_RTP_PORT_MAX) { - snprintf(buf, sizeof(buf), "rtp://%s?localport=%d", host, j); - j += 2; /* we will use two port by rtp stream (rtp and rtcp) */ - if (url_open(&rtsp_st->rtp_handle, buf, URL_RDWR) == 0) { + while (j <= RTSP_RTP_PORT_MAX) { + ff_url_join(buf, sizeof(buf), "rtp", NULL, host, -1, + "?localport=%d", j); + /* we will use two ports per rtp stream (rtp and rtcp) */ + j += 2; + if (url_open(&rtsp_st->rtp_handle, buf, URL_RDWR) == 0) goto rtp_opened; - } } } -/* then try on any port -** if (url_open(&rtsp_st->rtp_handle, "rtp://", URL_RDONLY) < 0) { -** err = AVERROR_INVALIDDATA; -** goto fail; -** } -*/ +#if 0 + /* then try on any port */ + if (url_open(&rtsp_st->rtp_handle, "rtp://", URL_RDONLY) < 0) { + err = AVERROR_INVALIDDATA; + goto fail; + } +#endif rtp_opened: port = rtp_get_local_port(rtsp_st->rtp_handle); @@ -1034,7 +1176,8 @@ make_setup_request (AVFormatContext *s, const char *host, int port, * UDP. When trying to set it up for TCP streams, the server * will return an error. Therefore, we skip those streams. */ if (rt->server_type == RTSP_SERVER_WMS && - s->streams[rtsp_st->stream_index]->codec->codec_type == CODEC_TYPE_DATA) + s->streams[rtsp_st->stream_index]->codec->codec_type == + AVMEDIA_TYPE_DATA) continue; snprintf(transport, sizeof(transport) - 1, "%s/TCP;", trans_pref); @@ -1050,13 +1193,14 @@ make_setup_request (AVFormatContext *s, const char *host, int port, snprintf(transport, sizeof(transport) - 1, "%s/UDP;multicast", trans_pref); } - if (rt->server_type == RTSP_SERVER_REAL || - rt->server_type == RTSP_SERVER_WMS) + if (s->oformat) { + av_strlcat(transport, ";mode=receive", sizeof(transport)); + } else if (rt->server_type == RTSP_SERVER_REAL || + rt->server_type == RTSP_SERVER_WMS) av_strlcat(transport, ";mode=play", sizeof(transport)); snprintf(cmd, sizeof(cmd), - "SETUP %s RTSP/1.0\r\n" "Transport: %s\r\n", - rtsp_st->control_url, transport); + transport); if (i == 0 && rt->server_type == RTSP_SERVER_REAL) { char real_res[41], real_csum[9]; ff_rdt_calc_response_and_checksum(real_res, real_csum, @@ -1066,7 +1210,7 @@ make_setup_request (AVFormatContext *s, const char *host, int port, "RealChallenge2: %s, sd=%s\r\n", rt->session_id, real_res, real_csum); } - rtsp_send_cmd(s, cmd, reply, NULL); + ff_rtsp_send_cmd(s, "SETUP", rtsp_st->control_url, cmd, reply, NULL); if (reply->status_code == 461 /* Unsupported protocol */ && i == 0) { err = 1; goto fail; @@ -1101,37 +1245,48 @@ make_setup_request (AVFormatContext *s, const char *host, int port, rtsp_st->interleaved_max = reply->transports[0].interleaved_max; break; - case RTSP_LOWER_TRANSPORT_UDP: - { - char url[1024]; + case RTSP_LOWER_TRANSPORT_UDP: { + char url[1024]; - /* XXX: also use address if specified */ - snprintf(url, sizeof(url), "rtp://%s:%d", - host, reply->transports[0].server_port_min); - if (!(rt->server_type == RTSP_SERVER_WMS && i > 1) && - rtp_set_remote_url(rtsp_st->rtp_handle, url) < 0) { - err = AVERROR_INVALIDDATA; - goto fail; - } + /* XXX: also use address if specified */ + ff_url_join(url, sizeof(url), "rtp", NULL, host, + reply->transports[0].server_port_min, NULL); + if (!(rt->server_type == RTSP_SERVER_WMS && i > 1) && + rtp_set_remote_url(rtsp_st->rtp_handle, url) < 0) { + err = AVERROR_INVALIDDATA; + goto fail; } + /* Try to initialize the connection state in a + * potential NAT router by sending dummy packets. + * RTP/RTCP dummy packets are used for RDT, too. + */ + if (!(rt->server_type == RTSP_SERVER_WMS && i > 1) && s->iformat) + rtp_send_punch_packets(rtsp_st->rtp_handle); break; - case RTSP_LOWER_TRANSPORT_UDP_MULTICAST: - { - char url[1024]; - struct in_addr in; + } + case RTSP_LOWER_TRANSPORT_UDP_MULTICAST: { + char url[1024]; + struct in_addr in; + int port, ttl; + if (reply->transports[0].destination) { in.s_addr = htonl(reply->transports[0].destination); - snprintf(url, sizeof(url), "rtp://%s:%d?ttl=%d", - inet_ntoa(in), - reply->transports[0].port_min, - reply->transports[0].ttl); - if (url_open(&rtsp_st->rtp_handle, url, URL_RDWR) < 0) { - err = AVERROR_INVALIDDATA; - goto fail; - } + port = reply->transports[0].port_min; + ttl = reply->transports[0].ttl; + } else { + in = rtsp_st->sdp_ip; + port = rtsp_st->sdp_port; + ttl = rtsp_st->sdp_ttl; + } + ff_url_join(url, sizeof(url), "rtp", NULL, inet_ntoa(in), + port, "?ttl=%d", ttl); + if (url_open(&rtsp_st->rtp_handle, url, URL_RDWR) < 0) { + err = AVERROR_INVALIDDATA; + goto fail; } break; } + } if ((err = rtsp_open_transport_ctx(s, rtsp_st))) goto fail; @@ -1146,7 +1301,7 @@ make_setup_request (AVFormatContext *s, const char *host, int port, return 0; fail: - for (i=0; inb_rtsp_streams; i++) { + for (i = 0; i < rt->nb_rtsp_streams; i++) { if (rt->rtsp_streams[i]->rtp_handle) { url_close(rt->rtsp_streams[i]->rtp_handle); rt->rtsp_streams[i]->rtp_handle = NULL; @@ -1155,59 +1310,247 @@ fail: return err; } -static int rtsp_read_header(AVFormatContext *s, - AVFormatParameters *ap) +static int rtsp_read_play(AVFormatContext *s) { RTSPState *rt = s->priv_data; - char host[1024], path[1024], tcpname[1024], cmd[2048], *option_list, *option; - URLContext *rtsp_hd; - int port, ret, err; RTSPMessageHeader reply1, *reply = &reply1; + int i; + char cmd[1024]; + + av_log(s, AV_LOG_DEBUG, "hello state=%d\n", rt->state); + + if (!(rt->server_type == RTSP_SERVER_REAL && rt->need_subscription)) { + if (rt->state == RTSP_STATE_PAUSED) { + cmd[0] = 0; + } else { + snprintf(cmd, sizeof(cmd), + "Range: npt=%0.3f-\r\n", + (double)rt->seek_timestamp / AV_TIME_BASE); + } + ff_rtsp_send_cmd(s, "PLAY", rt->control_uri, cmd, reply, NULL); + if (reply->status_code != RTSP_STATUS_OK) { + return -1; + } + if (reply->range_start != AV_NOPTS_VALUE && + rt->transport == RTSP_TRANSPORT_RTP) { + for (i = 0; i < rt->nb_rtsp_streams; i++) { + RTSPStream *rtsp_st = rt->rtsp_streams[i]; + RTPDemuxContext *rtpctx = rtsp_st->transport_priv; + AVStream *st = NULL; + if (!rtpctx) + continue; + if (rtsp_st->stream_index >= 0) + st = s->streams[rtsp_st->stream_index]; + rtpctx->last_rtcp_ntp_time = AV_NOPTS_VALUE; + rtpctx->first_rtcp_ntp_time = AV_NOPTS_VALUE; + if (st) + rtpctx->range_start_offset = av_rescale_q(reply->range_start, + AV_TIME_BASE_Q, + st->time_base); + } + } + } + rt->state = RTSP_STATE_STREAMING; + return 0; +} + +static int rtsp_setup_input_streams(AVFormatContext *s, RTSPMessageHeader *reply) +{ + RTSPState *rt = s->priv_data; + char cmd[1024]; unsigned char *content = NULL; + int ret; + + /* describe the stream */ + snprintf(cmd, sizeof(cmd), + "Accept: application/sdp\r\n"); + if (rt->server_type == RTSP_SERVER_REAL) { + /** + * The Require: attribute is needed for proper streaming from + * Realmedia servers. + */ + av_strlcat(cmd, + "Require: com.real.retain-entity-for-setup\r\n", + sizeof(cmd)); + } + ff_rtsp_send_cmd(s, "DESCRIBE", rt->control_uri, cmd, reply, &content); + if (!content) + return AVERROR_INVALIDDATA; + if (reply->status_code != RTSP_STATUS_OK) { + av_freep(&content); + return AVERROR_INVALIDDATA; + } + + /* now we got the SDP description, we parse it */ + ret = sdp_parse(s, (const char *)content); + av_freep(&content); + if (ret < 0) + return AVERROR_INVALIDDATA; + + return 0; +} + +static int rtsp_setup_output_streams(AVFormatContext *s, const char *addr) +{ + RTSPState *rt = s->priv_data; + RTSPMessageHeader reply1, *reply = &reply1; + int i; + char *sdp; + AVFormatContext sdp_ctx, *ctx_array[1]; + + rt->start_time = av_gettime(); + + /* Announce the stream */ + sdp = av_mallocz(8192); + if (sdp == NULL) + return AVERROR(ENOMEM); + /* We create the SDP based on the RTSP AVFormatContext where we + * aren't allowed to change the filename field. (We create the SDP + * based on the RTSP context since the contexts for the RTP streams + * don't exist yet.) In order to specify a custom URL with the actual + * peer IP instead of the originally specified hostname, we create + * a temporary copy of the AVFormatContext, where the custom URL is set. + * + * FIXME: Create the SDP without copying the AVFormatContext. + * This either requires setting up the RTP stream AVFormatContexts + * already here (complicating things immensely) or getting a more + * flexible SDP creation interface. + */ + sdp_ctx = *s; + ff_url_join(sdp_ctx.filename, sizeof(sdp_ctx.filename), + "rtsp", NULL, addr, -1, NULL); + ctx_array[0] = &sdp_ctx; + if (avf_sdp_create(ctx_array, 1, sdp, 8192)) { + av_free(sdp); + return AVERROR_INVALIDDATA; + } + av_log(s, AV_LOG_INFO, "SDP:\n%s\n", sdp); + ff_rtsp_send_cmd_with_content(s, "ANNOUNCE", rt->control_uri, + "Content-Type: application/sdp\r\n", + reply, NULL, sdp, strlen(sdp)); + av_free(sdp); + if (reply->status_code != RTSP_STATUS_OK) + return AVERROR_INVALIDDATA; + + /* Set up the RTSPStreams for each AVStream */ + for (i = 0; i < s->nb_streams; i++) { + RTSPStream *rtsp_st; + AVStream *st = s->streams[i]; + + rtsp_st = av_mallocz(sizeof(RTSPStream)); + if (!rtsp_st) + return AVERROR(ENOMEM); + dynarray_add(&rt->rtsp_streams, &rt->nb_rtsp_streams, rtsp_st); + + st->priv_data = rtsp_st; + rtsp_st->stream_index = i; + + av_strlcpy(rtsp_st->control_url, rt->control_uri, sizeof(rtsp_st->control_url)); + /* Note, this must match the relative uri set in the sdp content */ + av_strlcatf(rtsp_st->control_url, sizeof(rtsp_st->control_url), + "/streamid=%d", i); + } + + return 0; +} + +int ff_rtsp_connect(AVFormatContext *s) +{ + RTSPState *rt = s->priv_data; + char host[1024], path[1024], tcpname[1024], cmd[2048], auth[128]; + char *option_list, *option, *filename; + URLContext *rtsp_hd; + int port, err, tcp_fd; + RTSPMessageHeader reply1 = {}, *reply = &reply1; int lower_transport_mask = 0; char real_challenge[64]; + struct sockaddr_storage peer; + socklen_t peer_len = sizeof(peer); + if (!ff_network_init()) + return AVERROR(EIO); +redirect: /* extract hostname and port */ - url_split(NULL, 0, NULL, 0, - host, sizeof(host), &port, path, sizeof(path), s->filename); + ff_url_split(NULL, 0, auth, sizeof(auth), + host, sizeof(host), &port, path, sizeof(path), s->filename); + if (*auth) { + av_strlcpy(rt->auth, auth, sizeof(rt->auth)); + } if (port < 0) port = RTSP_DEFAULT_PORT; /* search for options */ - option_list = strchr(path, '?'); + option_list = strrchr(path, '?'); if (option_list) { - /* remove the options from the path */ - *option_list++ = 0; - while(option_list) { + /* Strip out the RTSP specific options, write out the rest of + * the options back into the same string. */ + filename = option_list; + while (option_list) { /* move the option pointer */ - option = option_list; + option = ++option_list; option_list = strchr(option_list, '&'); if (option_list) - *(option_list++) = 0; + *option_list = 0; + /* handle the options */ - if (strcmp(option, "udp") == 0) - lower_transport_mask = (1<< RTSP_LOWER_TRANSPORT_UDP); - else if (strcmp(option, "multicast") == 0) - lower_transport_mask = (1<< RTSP_LOWER_TRANSPORT_UDP_MULTICAST); - else if (strcmp(option, "tcp") == 0) - lower_transport_mask = (1<< RTSP_LOWER_TRANSPORT_TCP); + if (!strcmp(option, "udp")) { + lower_transport_mask |= (1<< RTSP_LOWER_TRANSPORT_UDP); + } else if (!strcmp(option, "multicast")) { + lower_transport_mask |= (1<< RTSP_LOWER_TRANSPORT_UDP_MULTICAST); + } else if (!strcmp(option, "tcp")) { + lower_transport_mask |= (1<< RTSP_LOWER_TRANSPORT_TCP); + } else { + /* Write options back into the buffer, using memmove instead + * of strcpy since the strings may overlap. */ + int len = strlen(option); + memmove(++filename, option, len); + filename += len; + if (option_list) *filename = '&'; + } } + *filename = 0; } if (!lower_transport_mask) lower_transport_mask = (1 << RTSP_LOWER_TRANSPORT_NB) - 1; + if (s->oformat) { + /* Only UDP or TCP - UDP multicast isn't supported. */ + lower_transport_mask &= (1 << RTSP_LOWER_TRANSPORT_UDP) | + (1 << RTSP_LOWER_TRANSPORT_TCP); + if (!lower_transport_mask) { + av_log(s, AV_LOG_ERROR, "Unsupported lower transport method, " + "only UDP and TCP are supported for output.\n"); + err = AVERROR(EINVAL); + goto fail; + } + } + + /* Construct the URI used in request; this is similar to s->filename, + * but with authentication credentials removed and RTSP specific options + * stripped out. */ + ff_url_join(rt->control_uri, sizeof(rt->control_uri), "rtsp", NULL, + host, port, "%s", path); + /* open the tcp connexion */ - snprintf(tcpname, sizeof(tcpname), "tcp://%s:%d", host, port); - if (url_open(&rtsp_hd, tcpname, URL_RDWR) < 0) - return AVERROR(EIO); + ff_url_join(tcpname, sizeof(tcpname), "tcp", NULL, host, port, NULL); + if (url_open(&rtsp_hd, tcpname, URL_RDWR) < 0) { + err = AVERROR(EIO); + goto fail; + } rt->rtsp_hd = rtsp_hd; rt->seq = 0; - /* request options supported by the server; this also detects server type */ + tcp_fd = url_get_file_handle(rtsp_hd); + if (!getpeername(tcp_fd, (struct sockaddr*) &peer, &peer_len)) { + getnameinfo((struct sockaddr*) &peer, peer_len, host, sizeof(host), + NULL, 0, NI_NUMERICHOST); + } + + /* request options supported by the server; this also detects server + * type */ for (rt->server_type = RTSP_SERVER_RTP;;) { - snprintf(cmd, sizeof(cmd), - "OPTIONS %s RTSP/1.0\r\n", s->filename); + cmd[0] = 0; if (rt->server_type == RTSP_SERVER_REAL) av_strlcat(cmd, /** @@ -1224,7 +1567,7 @@ static int rtsp_read_header(AVFormatContext *s, "CompanyID: KnKV4M4I/B2FjJ1TToLycw==\r\n" "GUID: 00000000-0000-0000-0000-000000000000\r\n", sizeof(cmd)); - rtsp_send_cmd(s, cmd, reply, NULL); + ff_rtsp_send_cmd(s, "OPTIONS", rt->control_uri, cmd, reply, NULL); if (reply->status_code != RTSP_STATUS_OK) { err = AVERROR_INVALIDDATA; goto fail; @@ -1236,46 +1579,21 @@ static int rtsp_read_header(AVFormatContext *s, continue; } else if (!strncasecmp(reply->server, "WMServer/", 9)) { rt->server_type = RTSP_SERVER_WMS; - } else if (rt->server_type == RTSP_SERVER_REAL) { + } else if (rt->server_type == RTSP_SERVER_REAL) strcpy(real_challenge, reply->real_challenge); - } break; } - /* describe the stream */ - snprintf(cmd, sizeof(cmd), - "DESCRIBE %s RTSP/1.0\r\n" - "Accept: application/sdp\r\n", - s->filename); - if (rt->server_type == RTSP_SERVER_REAL) { - /** - * The Require: attribute is needed for proper streaming from - * Realmedia servers. - */ - av_strlcat(cmd, - "Require: com.real.retain-entity-for-setup\r\n", - sizeof(cmd)); - } - rtsp_send_cmd(s, cmd, reply, &content); - if (!content) { - err = AVERROR_INVALIDDATA; + if (s->iformat) + err = rtsp_setup_input_streams(s, reply); + else + err = rtsp_setup_output_streams(s, host); + if (err) goto fail; - } - if (reply->status_code != RTSP_STATUS_OK) { - err = AVERROR_INVALIDDATA; - goto fail; - } - - /* now we got the SDP description, we parse it */ - ret = sdp_parse(s, (const char *)content); - av_freep(&content); - if (ret < 0) { - err = AVERROR_INVALIDDATA; - goto fail; - } do { - int lower_transport = ff_log2_tab[lower_transport_mask & ~(lower_transport_mask - 1)]; + int lower_transport = ff_log2_tab[lower_transport_mask & + ~(lower_transport_mask - 1)]; err = make_setup_request(s, host, port, lower_transport, rt->server_type == RTSP_SERVER_REAL ? @@ -1284,29 +1602,120 @@ static int rtsp_read_header(AVFormatContext *s, goto fail; lower_transport_mask &= ~(1 << lower_transport); if (lower_transport_mask == 0 && err == 1) { - err = AVERROR(FF_NETERROR(EPROTONOSUPPORT)); + err = FF_NETERROR(EPROTONOSUPPORT); goto fail; } } while (err); rt->state = RTSP_STATE_IDLE; - rt->seek_timestamp = 0; /* default is to start stream at position - zero */ - if (ap->initial_pause) { - /* do not start immediately */ - } else { - if (rtsp_read_play(s) < 0) { - err = AVERROR_INVALIDDATA; - goto fail; - } - } + rt->seek_timestamp = 0; /* default is to start stream at position zero */ return 0; fail: - rtsp_close_streams(rt); - av_freep(&content); + ff_rtsp_close_streams(s); url_close(rt->rtsp_hd); + if (reply->status_code >=300 && reply->status_code < 400 && s->iformat) { + av_strlcpy(s->filename, reply->location, sizeof(s->filename)); + av_log(s, AV_LOG_INFO, "Status %d: Redirecting to %s\n", + reply->status_code, + s->filename); + goto redirect; + } + ff_network_close(); return err; } +#endif + +#if CONFIG_RTSP_DEMUXER +static int rtsp_read_header(AVFormatContext *s, + AVFormatParameters *ap) +{ + RTSPState *rt = s->priv_data; + int ret; + + ret = ff_rtsp_connect(s); + if (ret) + return ret; + + if (ap->initial_pause) { + /* do not start immediately */ + } else { + if (rtsp_read_play(s) < 0) { + ff_rtsp_close_streams(s); + url_close(rt->rtsp_hd); + return AVERROR_INVALIDDATA; + } + } + + return 0; +} + +static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st, + uint8_t *buf, int buf_size) +{ + RTSPState *rt = s->priv_data; + RTSPStream *rtsp_st; + fd_set rfds; + int fd, fd_max, n, i, ret, tcp_fd, timeout_cnt = 0; + struct timeval tv; + + for (;;) { + if (url_interrupt_cb()) + return AVERROR(EINTR); + FD_ZERO(&rfds); + if (rt->rtsp_hd) { + tcp_fd = fd_max = url_get_file_handle(rt->rtsp_hd); + FD_SET(tcp_fd, &rfds); + } else { + fd_max = 0; + tcp_fd = -1; + } + for (i = 0; i < rt->nb_rtsp_streams; i++) { + rtsp_st = rt->rtsp_streams[i]; + if (rtsp_st->rtp_handle) { + /* currently, we cannot probe RTCP handle because of + * blocking restrictions */ + fd = url_get_file_handle(rtsp_st->rtp_handle); + if (fd > fd_max) + fd_max = fd; + FD_SET(fd, &rfds); + } + } + tv.tv_sec = 0; + tv.tv_usec = SELECT_TIMEOUT_MS * 1000; + n = select(fd_max + 1, &rfds, NULL, NULL, &tv); + if (n > 0) { + timeout_cnt = 0; + for (i = 0; i < rt->nb_rtsp_streams; i++) { + rtsp_st = rt->rtsp_streams[i]; + if (rtsp_st->rtp_handle) { + fd = url_get_file_handle(rtsp_st->rtp_handle); + if (FD_ISSET(fd, &rfds)) { + ret = url_read(rtsp_st->rtp_handle, buf, buf_size); + if (ret > 0) { + *prtsp_st = rtsp_st; + return ret; + } + } + } + } +#if CONFIG_RTSP_DEMUXER + if (tcp_fd != -1 && FD_ISSET(tcp_fd, &rfds)) { + RTSPMessageHeader reply; + + ret = ff_rtsp_read_reply(s, &reply, NULL, 0); + if (ret < 0) + return ret; + /* XXX: parse message */ + if (rt->state != RTSP_STATE_STREAMING) + return 0; + } +#endif + } else if (n == 0 && ++timeout_cnt >= MAX_TIMEOUTS) { + return FF_NETERROR(ETIMEDOUT); + } else if (n < 0 && errno != EINTR) + return AVERROR(errno); + } +} static int tcp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st, uint8_t *buf, int buf_size) @@ -1318,23 +1727,23 @@ static int tcp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st, #ifdef DEBUG_RTP_TCP dprintf(s, "tcp_read_packet:\n"); #endif - redo: - for(;;) { +redo: + for (;;) { RTSPMessageHeader reply; - ret = rtsp_read_reply(s, &reply, NULL, 1); + ret = ff_rtsp_read_reply(s, &reply, NULL, 1); if (ret == -1) return -1; if (ret == 1) /* received '$' */ break; /* XXX: parse message */ - if (rt->state != RTSP_STATE_PLAYING) + if (rt->state != RTSP_STATE_STREAMING) return 0; } ret = url_read_complete(rt->rtsp_hd, buf, 3); if (ret != 3) return -1; - id = buf[0]; + id = buf[0]; len = AV_RB16(buf + 1); #ifdef DEBUG_RTP_TCP dprintf(s, "id=%d len=%d\n", id, len); @@ -1350,85 +1759,96 @@ static int tcp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st, return -1; /* find the matching stream */ - for(i = 0; i < rt->nb_rtsp_streams; i++) { + for (i = 0; i < rt->nb_rtsp_streams; i++) { rtsp_st = rt->rtsp_streams[i]; if (id >= rtsp_st->interleaved_min && id <= rtsp_st->interleaved_max) goto found; } goto redo; - found: +found: *prtsp_st = rtsp_st; return len; } -static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st, - uint8_t *buf, int buf_size) +static int rtsp_fetch_packet(AVFormatContext *s, AVPacket *pkt) { RTSPState *rt = s->priv_data; + int ret, len; + uint8_t buf[10 * RTP_MAX_PACKET_LENGTH]; RTSPStream *rtsp_st; - fd_set rfds; - int fd, fd_max, n, i, ret, tcp_fd; - struct timeval tv; - for(;;) { - if (url_interrupt_cb()) - return AVERROR(EINTR); - FD_ZERO(&rfds); - if (rt->rtsp_hd) { - tcp_fd = fd_max = url_get_file_handle(rt->rtsp_hd); - FD_SET(tcp_fd, &rfds); - } else { - fd_max = 0; - tcp_fd = -1; - } - for(i = 0; i < rt->nb_rtsp_streams; i++) { - rtsp_st = rt->rtsp_streams[i]; - if (rtsp_st->rtp_handle) { - /* currently, we cannot probe RTCP handle because of - * blocking restrictions */ - fd = url_get_file_handle(rtsp_st->rtp_handle); - if (fd > fd_max) - fd_max = fd; - FD_SET(fd, &rfds); - } - } - tv.tv_sec = 0; - tv.tv_usec = 100 * 1000; - n = select(fd_max + 1, &rfds, NULL, NULL, &tv); - if (n > 0) { - for(i = 0; i < rt->nb_rtsp_streams; i++) { - rtsp_st = rt->rtsp_streams[i]; - if (rtsp_st->rtp_handle) { - fd = url_get_file_handle(rtsp_st->rtp_handle); - if (FD_ISSET(fd, &rfds)) { - ret = url_read(rtsp_st->rtp_handle, buf, buf_size); - if (ret > 0) { - *prtsp_st = rtsp_st; - return ret; - } - } + /* get next frames from the same RTP packet */ + if (rt->cur_transport_priv) { + 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); + if (ret == 0) { + rt->cur_transport_priv = NULL; + return 0; + } else if (ret == 1) { + return 0; + } else + rt->cur_transport_priv = NULL; + } + + /* read next RTP packet */ + redo: + switch(rt->lower_transport) { + default: +#if CONFIG_RTSP_DEMUXER + case RTSP_LOWER_TRANSPORT_TCP: + len = tcp_read_packet(s, &rtsp_st, buf, sizeof(buf)); + break; +#endif + case RTSP_LOWER_TRANSPORT_UDP: + case RTSP_LOWER_TRANSPORT_UDP_MULTICAST: + len = udp_read_packet(s, &rtsp_st, buf, sizeof(buf)); + if (len >=0 && rtsp_st->transport_priv && rt->transport == RTSP_TRANSPORT_RTP) + rtp_check_and_send_back_rr(rtsp_st->transport_priv, len); + break; + } + if (len < 0) + return len; + if (len == 0) + return AVERROR_EOF; + if (rt->transport == RTSP_TRANSPORT_RDT) { + ret = ff_rdt_parse_packet(rtsp_st->transport_priv, pkt, buf, len); + } else { + ret = rtp_parse_packet(rtsp_st->transport_priv, pkt, buf, len); + if (ret < 0) { + /* Either bad packet, or a RTCP packet. Check if the + * first_rtcp_ntp_time field was initialized. */ + RTPDemuxContext *rtpctx = rtsp_st->transport_priv; + if (rtpctx->first_rtcp_ntp_time != AV_NOPTS_VALUE) { + /* first_rtcp_ntp_time has been initialized for this stream, + * copy the same value to all other uninitialized streams, + * in order to map their timestamp origin to the same ntp time + * as this one. */ + int i; + for (i = 0; i < rt->nb_rtsp_streams; i++) { + RTPDemuxContext *rtpctx2 = rtsp_st->transport_priv; + if (rtpctx2 && + rtpctx2->first_rtcp_ntp_time == AV_NOPTS_VALUE) + rtpctx2->first_rtcp_ntp_time = rtpctx->first_rtcp_ntp_time; } } - if (FD_ISSET(tcp_fd, &rfds)) { - RTSPMessageHeader reply; - - rtsp_read_reply(s, &reply, NULL, 0); - /* XXX: parse message */ - if (rt->state != RTSP_STATE_PLAYING) - return 0; - } } } + if (ret < 0) + goto redo; + if (ret == 1) + /* more packets may follow, so we save the RTP context */ + rt->cur_transport_priv = rtsp_st->transport_priv; + + return ret; } -static int rtsp_read_packet(AVFormatContext *s, - AVPacket *pkt) +static int rtsp_read_packet(AVFormatContext *s, AVPacket *pkt) { RTSPState *rt = s->priv_data; - RTSPStream *rtsp_st; - int ret, len; - uint8_t buf[10 * RTP_MAX_PACKET_LENGTH]; + int ret; RTSPMessageHeader reply1, *reply = &reply1; char cmd[1024]; @@ -1442,11 +1862,11 @@ static int rtsp_read_packet(AVFormatContext *s, if (!rt->need_subscription) { if (memcmp (cache, rt->real_setup_cache, sizeof(enum AVDiscard) * s->nb_streams)) { - av_strlcatf(cmd, sizeof(cmd), - "SET_PARAMETER %s RTSP/1.0\r\n" - "Unsubscribe: %s\r\n", - s->filename, rt->last_subscription); - rtsp_send_cmd(s, cmd, reply, NULL); + snprintf(cmd, sizeof(cmd), + "Unsubscribe: %s\r\n", + rt->last_subscription); + ff_rtsp_send_cmd(s, "SET_PARAMETER", rt->control_uri, + cmd, reply, NULL); if (reply->status_code != RTSP_STATUS_OK) return AVERROR_INVALIDDATA; rt->need_subscription = 1; @@ -1461,9 +1881,7 @@ static int rtsp_read_packet(AVFormatContext *s, rt->last_subscription[0] = 0; snprintf(cmd, sizeof(cmd), - "SET_PARAMETER %s RTSP/1.0\r\n" - "Subscribe: ", - s->filename); + "Subscribe: "); for (i = 0; i < rt->nb_rtsp_streams; i++) { rule_nr = 0; for (r = 0; r < s->nb_streams; r++) { @@ -1482,124 +1900,45 @@ static int rtsp_read_packet(AVFormatContext *s, } } av_strlcatf(cmd, sizeof(cmd), "%s\r\n", rt->last_subscription); - rtsp_send_cmd(s, cmd, reply, NULL); + ff_rtsp_send_cmd(s, "SET_PARAMETER", rt->control_uri, + cmd, reply, NULL); if (reply->status_code != RTSP_STATUS_OK) return AVERROR_INVALIDDATA; rt->need_subscription = 0; - if (rt->state == RTSP_STATE_PLAYING) + if (rt->state == RTSP_STATE_STREAMING) rtsp_read_play (s); } } - /* get next frames from the same RTP packet */ - if (rt->cur_transport_priv) { - 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); - if (ret == 0) { - rt->cur_transport_priv = NULL; - return 0; - } else if (ret == 1) { - return 0; - } else { - rt->cur_transport_priv = NULL; - } - } - - /* read next RTP packet */ - redo: - switch(rt->lower_transport) { - default: - case RTSP_LOWER_TRANSPORT_TCP: - len = tcp_read_packet(s, &rtsp_st, buf, sizeof(buf)); - break; - case RTSP_LOWER_TRANSPORT_UDP: - case RTSP_LOWER_TRANSPORT_UDP_MULTICAST: - len = udp_read_packet(s, &rtsp_st, buf, sizeof(buf)); - if (len >=0 && rtsp_st->transport_priv && rt->transport == RTSP_TRANSPORT_RTP) - rtp_check_and_send_back_rr(rtsp_st->transport_priv, len); - break; - } - if (len < 0) - return len; - if (len == 0) - return AVERROR_EOF; - if (rt->transport == RTSP_TRANSPORT_RDT) - ret = ff_rdt_parse_packet(rtsp_st->transport_priv, pkt, buf, len); - else - ret = rtp_parse_packet(rtsp_st->transport_priv, pkt, buf, len); + ret = rtsp_fetch_packet(s, pkt); if (ret < 0) - goto redo; - if (ret == 1) { - /* more packets may follow, so we save the RTP context */ - rt->cur_transport_priv = rtsp_st->transport_priv; - } + return ret; /* send dummy request to keep TCP connection alive */ if ((rt->server_type == RTSP_SERVER_WMS || rt->server_type == RTSP_SERVER_REAL) && (av_gettime() - rt->last_cmd_time) / 1000000 >= rt->timeout / 2) { if (rt->server_type == RTSP_SERVER_WMS) { - snprintf(cmd, sizeof(cmd) - 1, - "GET_PARAMETER %s RTSP/1.0\r\n", - s->filename); - rtsp_send_cmd_async(s, cmd, reply, NULL); + ff_rtsp_send_cmd_async(s, "GET_PARAMETER", rt->control_uri, NULL); } else { - rtsp_send_cmd_async(s, "OPTIONS * RTSP/1.0\r\n", - reply, NULL); + ff_rtsp_send_cmd_async(s, "OPTIONS", "*", NULL); } } return 0; } -static int rtsp_read_play(AVFormatContext *s) -{ - RTSPState *rt = s->priv_data; - RTSPMessageHeader reply1, *reply = &reply1; - char cmd[1024]; - - av_log(s, AV_LOG_DEBUG, "hello state=%d\n", rt->state); - - if (!(rt->server_type == RTSP_SERVER_REAL && rt->need_subscription)) { - if (rt->state == RTSP_STATE_PAUSED) { - snprintf(cmd, sizeof(cmd), - "PLAY %s RTSP/1.0\r\n", - s->filename); - } else { - snprintf(cmd, sizeof(cmd), - "PLAY %s RTSP/1.0\r\n" - "Range: npt=%0.3f-\r\n", - s->filename, - (double)rt->seek_timestamp / AV_TIME_BASE); - } - rtsp_send_cmd(s, cmd, reply, NULL); - if (reply->status_code != RTSP_STATUS_OK) { - return -1; - } - } - rt->state = RTSP_STATE_PLAYING; - return 0; -} - /* pause the stream */ static int rtsp_read_pause(AVFormatContext *s) { RTSPState *rt = s->priv_data; RTSPMessageHeader reply1, *reply = &reply1; - char cmd[1024]; - rt = s->priv_data; - - if (rt->state != RTSP_STATE_PLAYING) + if (rt->state != RTSP_STATE_STREAMING) return 0; else if (!(rt->server_type == RTSP_SERVER_REAL && rt->need_subscription)) { - snprintf(cmd, sizeof(cmd), - "PAUSE %s RTSP/1.0\r\n", - s->filename); - rtsp_send_cmd(s, cmd, reply, NULL); + ff_rtsp_send_cmd(s, "PAUSE", rt->control_uri, NULL, reply, NULL); if (reply->status_code != RTSP_STATUS_OK) { return -1; } @@ -1613,12 +1952,14 @@ static int rtsp_read_seek(AVFormatContext *s, int stream_index, { RTSPState *rt = s->priv_data; - rt->seek_timestamp = av_rescale_q(timestamp, s->streams[stream_index]->time_base, AV_TIME_BASE_Q); + rt->seek_timestamp = av_rescale_q(timestamp, + s->streams[stream_index]->time_base, + AV_TIME_BASE_Q); switch(rt->state) { default: case RTSP_STATE_IDLE: break; - case RTSP_STATE_PLAYING: + case RTSP_STATE_STREAMING: if (rtsp_read_pause(s) != 0) return -1; rt->state = RTSP_STATE_SEEKING; @@ -1635,8 +1976,6 @@ static int rtsp_read_seek(AVFormatContext *s, int stream_index, static int rtsp_read_close(AVFormatContext *s) { RTSPState *rt = s->priv_data; - RTSPMessageHeader reply1, *reply = &reply1; - char cmd[1024]; #if 0 /* NOTE: it is valid to flush the buffer here */ @@ -1644,17 +1983,14 @@ static int rtsp_read_close(AVFormatContext *s) url_fclose(&rt->rtsp_gb); } #endif - snprintf(cmd, sizeof(cmd), - "TEARDOWN %s RTSP/1.0\r\n", - s->filename); - rtsp_send_cmd(s, cmd, reply, NULL); + ff_rtsp_send_cmd_async(s, "TEARDOWN", rt->control_uri, NULL); - rtsp_close_streams(rt); + ff_rtsp_close_streams(s); url_close(rt->rtsp_hd); + ff_network_close(); return 0; } -#if CONFIG_RTSP_DEMUXER AVInputFormat rtsp_demuxer = { "rtsp", NULL_IF_CONFIG_SMALL("RTSP input format"), @@ -1676,10 +2012,11 @@ static int sdp_probe(AVProbeData *p1) /* we look for a line beginning "c=IN IP4" */ while (p < p_end && *p != '\0') { - if (p + sizeof("c=IN IP4") - 1 < p_end && av_strstart(p, "c=IN IP4", NULL)) + if (p + sizeof("c=IN IP4") - 1 < p_end && + av_strstart(p, "c=IN IP4", NULL)) return AVPROBE_SCORE_MAX / 2; - while(p < p_end - 1 && *p != '\n') p++; + while (p < p_end - 1 && *p != '\n') p++; if (++p >= p_end) break; if (*p == '\r') @@ -1690,8 +2027,7 @@ static int sdp_probe(AVProbeData *p1) #define SDP_MAX_SIZE 8192 -static int sdp_read_header(AVFormatContext *s, - AVFormatParameters *ap) +static int sdp_read_header(AVFormatContext *s, AVFormatParameters *ap) { RTSPState *rt = s->priv_data; RTSPStream *rtsp_st; @@ -1699,6 +2035,9 @@ static int sdp_read_header(AVFormatContext *s, char *content; char url[1024]; + if (!ff_network_init()) + return AVERROR(EIO); + /* read the whole sdp file */ /* XXX: better loading */ content = av_malloc(SDP_MAX_SIZE); @@ -1713,14 +2052,13 @@ static int sdp_read_header(AVFormatContext *s, av_free(content); /* open each RTP stream */ - for(i=0;inb_rtsp_streams;i++) { + for (i = 0; i < rt->nb_rtsp_streams; i++) { rtsp_st = rt->rtsp_streams[i]; - snprintf(url, sizeof(url), "rtp://%s:%d?localport=%d&ttl=%d", - inet_ntoa(rtsp_st->sdp_ip), - rtsp_st->sdp_port, - rtsp_st->sdp_port, - rtsp_st->sdp_ttl); + ff_url_join(url, sizeof(url), "rtp", NULL, + inet_ntoa(rtsp_st->sdp_ip), rtsp_st->sdp_port, + "?localport=%d&ttl=%d", rtsp_st->sdp_port, + rtsp_st->sdp_ttl); if (url_open(&rtsp_st->rtp_handle, url, URL_RDWR) < 0) { err = AVERROR_INVALIDDATA; goto fail; @@ -1729,98 +2067,25 @@ static int sdp_read_header(AVFormatContext *s, goto fail; } return 0; - fail: - rtsp_close_streams(rt); +fail: + ff_rtsp_close_streams(s); + ff_network_close(); return err; } -static int sdp_read_packet(AVFormatContext *s, - AVPacket *pkt) -{ - return rtsp_read_packet(s, pkt); -} - static int sdp_read_close(AVFormatContext *s) { - RTSPState *rt = s->priv_data; - rtsp_close_streams(rt); + ff_rtsp_close_streams(s); + ff_network_close(); return 0; } -#if CONFIG_SDP_DEMUXER AVInputFormat sdp_demuxer = { "sdp", NULL_IF_CONFIG_SMALL("SDP"), sizeof(RTSPState), sdp_probe, sdp_read_header, - sdp_read_packet, + rtsp_fetch_packet, sdp_read_close, }; -#endif - -#if CONFIG_REDIR_DEMUXER -/* dummy redirector format (used directly in av_open_input_file now) */ -static int redir_probe(AVProbeData *pd) -{ - const char *p; - p = pd->buf; - skip_spaces(&p); - if (av_strstart(p, "http://", NULL) || - av_strstart(p, "rtsp://", NULL)) - return AVPROBE_SCORE_MAX; - return 0; -} - -static int redir_read_header(AVFormatContext *s, AVFormatParameters *ap) -{ - char buf[4096], *q; - int c; - AVFormatContext *ic = NULL; - ByteIOContext *f = s->pb; - - /* parse each URL and try to open it */ - c = url_fgetc(f); - while (c != URL_EOF) { - /* skip spaces */ - for(;;) { - if (!redir_isspace(c)) - break; - c = url_fgetc(f); - } - if (c == URL_EOF) - break; - /* record url */ - q = buf; - for(;;) { - if (c == URL_EOF || redir_isspace(c)) - break; - if ((q - buf) < sizeof(buf) - 1) - *q++ = c; - c = url_fgetc(f); - } - *q = '\0'; - //printf("URL='%s'\n", buf); - /* try to open the media file */ - if (av_open_input_file(&ic, buf, NULL, 0, NULL) == 0) - break; - } - if (!ic) - return AVERROR(EIO); - - *s = *ic; - url_fclose(f); - - return 0; -} - -AVInputFormat redir_demuxer = { - "redir", - NULL_IF_CONFIG_SMALL("Redirector format"), - 0, - redir_probe, - redir_read_header, - NULL, - NULL, -}; -#endif diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rtsp.h b/src/add-ons/media/plugins/ffmpeg/libavformat/rtsp.h index e88d365a10..357d3bfc0c 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/rtsp.h +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rtsp.h @@ -26,6 +26,7 @@ #include "rtspcodes.h" #include "rtpdec.h" #include "network.h" +#include "httpauth.h" /** * Network layer over which RTP/etc packet data will be transported. @@ -121,6 +122,10 @@ typedef struct RTSPMessageHeader { * should be re-transmitted by the client in every RTSP command. */ char session_id[512]; + /** the "Location:" field. This value is used to handle redirection. + */ + char location[4096]; + /** the "RealChallenge1:" field from the server */ char real_challenge[64]; @@ -154,7 +159,7 @@ typedef struct RTSPMessageHeader { */ enum RTSPClientState { RTSP_STATE_IDLE, /**< not initialized */ - RTSP_STATE_PLAYING, /**< initialized and receiving data */ + RTSP_STATE_STREAMING, /**< initialized and sending/receiving data */ RTSP_STATE_PAUSED, /**< initialized, but not receiving data */ RTSP_STATE_SEEKING, /**< initialized, requesting a seek */ }; @@ -228,6 +233,12 @@ typedef struct RTSPState { * of RTSPMessageHeader->real_challenge */ enum RTSPServerType server_type; + /** plaintext authorization line (username:password) */ + char auth[128]; + + /** authentication state */ + HTTPAuthState auth_state; + /** The last reply of the server to a RTSP command */ char last_reply[2048]; /* XXX: allocate ? */ @@ -259,6 +270,14 @@ typedef struct RTSPState { * data packet in the bytecontext for each incoming RTSP packet. */ uint64_t asf_pb_pos; //@} + + /** some MS RTSP streams contain a URL in the SDP that we need to use + * for all subsequent RTSP requests, rather than the input URI; in + * other cases, this is a copy of AVFormatContext->filename. */ + char control_uri[1024]; + + /** The synchronized start time of the output streams. */ + int64_t start_time; } RTSPState; /** @@ -269,7 +288,7 @@ typedef struct RTSPState { */ typedef struct RTSPStream { URLContext *rtp_handle; /**< RTP stream handle (if UDP) */ - void *transport_priv; /**< RTP/RDT parse context */ + void *transport_priv; /**< RTP/RDT parse context if input, RTP AVFormatContext if output */ /** corresponding stream index, if any. -1 if none (MPEG2TS case) */ int stream_index; @@ -303,8 +322,8 @@ typedef struct RTSPStream { //@} } RTSPStream; -int rtsp_init(void); -void rtsp_parse_line(RTSPMessageHeader *reply, const char *buf); +void ff_rtsp_parse_line(RTSPMessageHeader *reply, const char *buf, + HTTPAuthState *auth_state); #if LIBAVFORMAT_VERSION_INT < (53 << 16) extern int rtsp_default_protocols; @@ -312,7 +331,107 @@ extern int rtsp_default_protocols; extern int rtsp_rtp_port_min; extern int rtsp_rtp_port_max; -int rtsp_pause(AVFormatContext *s); -int rtsp_resume(AVFormatContext *s); +/** + * Send a command to the RTSP server without waiting for the reply. + * + * @param s RTSP (de)muxer context + * @param method the method for the request + * @param url the target url for the request + * @param headers extra header lines to include in the request + * @param send_content if non-null, the data to send as request body content + * @param send_content_length the length of the send_content data, or 0 if + * send_content is null + */ +void ff_rtsp_send_cmd_with_content_async(AVFormatContext *s, + const char *method, const char *url, + const char *headers, + const unsigned char *send_content, + int send_content_length); +/** + * Send a command to the RTSP server without waiting for the reply. + * + * @see rtsp_send_cmd_with_content_async + */ +void ff_rtsp_send_cmd_async(AVFormatContext *s, const char *method, + const char *url, const char *headers); + +/** + * Send a command to the RTSP server and wait for the reply. + * + * @param s RTSP (de)muxer context + * @param method the method for the request + * @param url the target url for the request + * @param headers extra header lines to include in the request + * @param reply pointer where the RTSP message header will be stored + * @param content_ptr pointer where the RTSP message body, if any, will + * be stored (length is in reply) + * @param send_content if non-null, the data to send as request body content + * @param send_content_length the length of the send_content data, or 0 if + * send_content is null + */ +void ff_rtsp_send_cmd_with_content(AVFormatContext *s, + const char *method, const char *url, + const char *headers, + RTSPMessageHeader *reply, + unsigned char **content_ptr, + const unsigned char *send_content, + int send_content_length); + +/** + * Send a command to the RTSP server and wait for the reply. + * + * @see rtsp_send_cmd_with_content + */ +void ff_rtsp_send_cmd(AVFormatContext *s, const char *method, + const char *url, const char *headers, + RTSPMessageHeader *reply, unsigned char **content_ptr); + +/** + * Read a RTSP message from the server, or prepare to read data + * packets if we're reading data interleaved over the TCP/RTSP + * connection as well. + * + * @param s RTSP (de)muxer context + * @param reply pointer where the RTSP message header will be stored + * @param content_ptr pointer where the RTSP message body, if any, will + * be stored (length is in reply) + * @param return_on_interleaved_data whether the function may return if we + * encounter a data marker ('$'), which precedes data + * packets over interleaved TCP/RTSP connections. If this + * is set, this function will return 1 after encountering + * a '$'. If it is not set, the function will skip any + * data packets (if they are encountered), until a reply + * has been fully parsed. If no more data is available + * without parsing a reply, it will return an error. + * + * @return 1 if a data packets is ready to be received, -1 on error, + * and 0 on success. + */ +int ff_rtsp_read_reply(AVFormatContext *s, RTSPMessageHeader *reply, + unsigned char **content_ptr, + int return_on_interleaved_data); + +/** + * Skip a RTP/TCP interleaved packet. + */ +void ff_rtsp_skip_packet(AVFormatContext *s); + +/** + * Connect to the RTSP server and set up the individual media streams. + * This can be used for both muxers and demuxers. + * + * @param s RTSP (de)muxer context + * + * @return 0 on success, < 0 on error. Cleans up all allocations done + * within the function on error. + */ +int ff_rtsp_connect(AVFormatContext *s); + +/** + * Close and free all streams within the RTSP (de)muxer + * + * @param s RTSP (de)muxer context + */ +void ff_rtsp_close_streams(AVFormatContext *s); #endif /* AVFORMAT_RTSP_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/rtspenc.c b/src/add-ons/media/plugins/ffmpeg/libavformat/rtspenc.c new file mode 100644 index 0000000000..f7aadd6e41 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/rtspenc.c @@ -0,0 +1,182 @@ +/* + * RTSP muxer + * Copyright (c) 2010 Martin Storsjo + * + * 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 +#if HAVE_SYS_SELECT_H +#include +#endif +#include "network.h" +#include "rtsp.h" +#include + +static int rtsp_write_record(AVFormatContext *s) +{ + RTSPState *rt = s->priv_data; + RTSPMessageHeader reply1, *reply = &reply1; + char cmd[1024]; + + snprintf(cmd, sizeof(cmd), + "Range: npt=%0.3f-\r\n", + (double) 0); + ff_rtsp_send_cmd(s, "RECORD", rt->control_uri, cmd, reply, NULL); + if (reply->status_code != RTSP_STATUS_OK) + return -1; + rt->state = RTSP_STATE_STREAMING; + return 0; +} + +static int rtsp_write_header(AVFormatContext *s) +{ + RTSPState *rt = s->priv_data; + int ret; + + ret = ff_rtsp_connect(s); + if (ret) + return ret; + + if (rtsp_write_record(s) < 0) { + ff_rtsp_close_streams(s); + url_close(rt->rtsp_hd); + return AVERROR_INVALIDDATA; + } + return 0; +} + +static int tcp_write_packet(AVFormatContext *s, RTSPStream *rtsp_st) +{ + RTSPState *rt = s->priv_data; + AVFormatContext *rtpctx = rtsp_st->transport_priv; + uint8_t *buf, *ptr; + int size; + uint8_t interleave_header[4]; + + size = url_close_dyn_buf(rtpctx->pb, &buf); + ptr = buf; + while (size > 4) { + uint32_t packet_len = AV_RB32(ptr); + int id; + ptr += 4; + size -= 4; + if (packet_len > size || packet_len < 2) + break; + if (ptr[1] >= 200 && ptr[1] <= 204) + id = rtsp_st->interleaved_max; /* RTCP */ + else + id = rtsp_st->interleaved_min; /* RTP */ + interleave_header[0] = '$'; + interleave_header[1] = id; + AV_WB16(interleave_header + 2, packet_len); + url_write(rt->rtsp_hd, interleave_header, 4); + url_write(rt->rtsp_hd, ptr, packet_len); + ptr += packet_len; + size -= packet_len; + } + av_free(buf); + url_open_dyn_packet_buf(&rtpctx->pb, RTSP_TCP_MAX_PACKET_SIZE); + return 0; +} + +static int rtsp_write_packet(AVFormatContext *s, AVPacket *pkt) +{ + RTSPState *rt = s->priv_data; + RTSPStream *rtsp_st; + fd_set rfds; + int n, tcp_fd; + struct timeval tv; + AVFormatContext *rtpctx; + AVPacket local_pkt; + int ret; + + tcp_fd = url_get_file_handle(rt->rtsp_hd); + + while (1) { + FD_ZERO(&rfds); + FD_SET(tcp_fd, &rfds); + tv.tv_sec = 0; + tv.tv_usec = 0; + n = select(tcp_fd + 1, &rfds, NULL, NULL, &tv); + if (n <= 0) + break; + if (FD_ISSET(tcp_fd, &rfds)) { + RTSPMessageHeader reply; + + /* Don't let ff_rtsp_read_reply handle interleaved packets, + * since it would block and wait for an RTSP reply on the socket + * (which may not be coming any time soon) if it handles + * interleaved packets internally. */ + ret = ff_rtsp_read_reply(s, &reply, NULL, 1); + if (ret < 0) + return AVERROR(EPIPE); + if (ret == 1) + ff_rtsp_skip_packet(s); + /* XXX: parse message */ + if (rt->state != RTSP_STATE_STREAMING) + return AVERROR(EPIPE); + } + } + + if (pkt->stream_index < 0 || pkt->stream_index >= rt->nb_rtsp_streams) + return AVERROR_INVALIDDATA; + rtsp_st = rt->rtsp_streams[pkt->stream_index]; + rtpctx = rtsp_st->transport_priv; + + /* Use a local packet for writing to the chained muxer, otherwise + * the internal stream_index = 0 becomes visible to the muxer user. */ + local_pkt = *pkt; + local_pkt.stream_index = 0; + ret = av_write_frame(rtpctx, &local_pkt); + /* av_write_frame does all the RTP packetization. If using TCP as + * transport, rtpctx->pb is only a dyn_packet_buf that queues up the + * packets, so we need to send them out on the TCP connection separately. + */ + if (!ret && rt->lower_transport == RTSP_LOWER_TRANSPORT_TCP) + ret = tcp_write_packet(s, rtsp_st); + return ret; +} + +static int rtsp_write_close(AVFormatContext *s) +{ + RTSPState *rt = s->priv_data; + + ff_rtsp_send_cmd_async(s, "TEARDOWN", rt->control_uri, NULL); + + ff_rtsp_close_streams(s); + url_close(rt->rtsp_hd); + ff_network_close(); + return 0; +} + +AVOutputFormat rtsp_muxer = { + "rtsp", + NULL_IF_CONFIG_SMALL("RTSP output format"), + NULL, + NULL, + sizeof(RTSPState), + CODEC_ID_PCM_MULAW, + CODEC_ID_NONE, + rtsp_write_header, + rtsp_write_packet, + rtsp_write_close, + .flags = AVFMT_NOFILE | AVFMT_GLOBALHEADER, +}; + diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/sdp.c b/src/add-ons/media/plugins/ffmpeg/libavformat/sdp.c index 67b10a21fe..6bf05dbe39 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/sdp.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/sdp.c @@ -18,12 +18,16 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include #include "libavutil/avstring.h" #include "libavutil/base64.h" #include "avformat.h" #include "internal.h" #include "avc.h" #include "rtp.h" +#if CONFIG_NETWORK +#include "network.h" +#endif #if CONFIG_RTP_MUXER #define MAX_EXTRADATA_SIZE ((INT_MAX - 10) / 2) @@ -58,24 +62,64 @@ static void sdp_write_header(char *buff, int size, struct sdp_session_level *s) { av_strlcatf(buff, size, "v=%d\r\n" "o=- %d %d IN IP4 %s\r\n" - "t=%d %d\r\n" - "s=%s\r\n" - "a=tool:libavformat " AV_STRINGIFY(LIBAVFORMAT_VERSION) "\r\n", + "s=%s\r\n", s->sdp_version, s->id, s->version, s->src_addr, - s->start_time, s->end_time, s->name); sdp_write_address(buff, size, s->dst_addr, s->ttl); + av_strlcatf(buff, size, "t=%d %d\r\n" + "a=tool:libavformat " AV_STRINGIFY(LIBAVFORMAT_VERSION) "\r\n", + s->start_time, s->end_time); } +#if CONFIG_NETWORK +static void resolve_destination(char *dest_addr, int size) +{ + struct addrinfo hints, *ai, *cur; + + if (!dest_addr[0]) + return; + + /* Resolve the destination, since it must be written + * as a numeric IP address in the SDP. */ + + memset(&hints, 0, sizeof(hints)); + /* We only support IPv4 addresses in the SDP at the moment. */ + hints.ai_family = AF_INET; + if (getaddrinfo(dest_addr, NULL, &hints, &ai)) + return; + for (cur = ai; cur; cur = cur->ai_next) { + if (cur->ai_family == AF_INET) { + getnameinfo(cur->ai_addr, cur->ai_addrlen, dest_addr, size, + NULL, 0, NI_NUMERICHOST); + break; + } + } + freeaddrinfo(ai); +} +#else +static void resolve_destination(char *dest_addr, int size) +{ +} +#endif + static int sdp_get_address(char *dest_addr, int size, int *ttl, const char *url) { int port; const char *p; + char proto[32]; - url_split(NULL, 0, NULL, 0, dest_addr, size, &port, NULL, 0, url); + ff_url_split(proto, sizeof(proto), NULL, 0, dest_addr, size, &port, NULL, 0, url); *ttl = 0; + + if (strcmp(proto, "rtp")) { + /* The url isn't for the actual rtp sessions, + * don't parse out anything else than the destination. + */ + return 0; + } + p = strchr(url, '?'); if (p) { char buff[64]; @@ -157,7 +201,7 @@ static char *extradata2config(AVCodecContext *c) return NULL; } memcpy(config, "; config=", 9); - ff_data_to_hex(config + 9, c->extradata, c->extradata_size); + ff_data_to_hex(config + 9, c->extradata, c->extradata_size, 0); config[9 + c->extradata_size * 2] = 0; return config; @@ -211,19 +255,19 @@ static char *sdp_write_media_attributes(char *buff, int size, AVCodecContext *c, payload_type, config); break; case CODEC_ID_PCM_S16BE: - if (payload_type >= 96) + if (payload_type >= RTP_PT_PRIVATE) av_strlcatf(buff, size, "a=rtpmap:%d L16/%d/%d\r\n", payload_type, c->sample_rate, c->channels); break; case CODEC_ID_PCM_MULAW: - if (payload_type >= 96) + if (payload_type >= RTP_PT_PRIVATE) av_strlcatf(buff, size, "a=rtpmap:%d PCMU/%d/%d\r\n", payload_type, c->sample_rate, c->channels); break; case CODEC_ID_PCM_ALAW: - if (payload_type >= 96) + if (payload_type >= RTP_PT_PRIVATE) av_strlcatf(buff, size, "a=rtpmap:%d PCMA/%d/%d\r\n", payload_type, c->sample_rate, c->channels); @@ -250,20 +294,20 @@ static char *sdp_write_media_attributes(char *buff, int size, AVCodecContext *c, return buff; } -static void sdp_write_media(char *buff, int size, AVCodecContext *c, const char *dest_addr, int port, int ttl) +void ff_sdp_write_media(char *buff, int size, AVCodecContext *c, const char *dest_addr, int port, int ttl) { const char *type; int payload_type; payload_type = ff_rtp_get_payload_type(c); if (payload_type < 0) { - payload_type = 96; /* FIXME: how to assign a private pt? rtp.c is broken too */ + payload_type = RTP_PT_PRIVATE + (c->codec_type == AVMEDIA_TYPE_AUDIO); } switch (c->codec_type) { - case CODEC_TYPE_VIDEO : type = "video" ; break; - case CODEC_TYPE_AUDIO : type = "audio" ; break; - case CODEC_TYPE_SUBTITLE: type = "text" ; break; + case AVMEDIA_TYPE_VIDEO : type = "video" ; break; + case AVMEDIA_TYPE_AUDIO : type = "audio" ; break; + case AVMEDIA_TYPE_SUBTITLE: type = "text" ; break; default : type = "application"; break; } @@ -293,7 +337,8 @@ int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size) ttl = 0; if (n_files == 1) { port = sdp_get_address(dst, sizeof(dst), &ttl, ac[0]->filename); - if (port > 0) { + resolve_destination(dst, sizeof(dst)); + if (dst[0]) { s.dst_addr = dst; s.ttl = ttl; } @@ -304,9 +349,10 @@ int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size) for (i = 0; i < n_files; i++) { if (n_files != 1) { port = sdp_get_address(dst, sizeof(dst), &ttl, ac[i]->filename); + resolve_destination(dst, sizeof(dst)); } for (j = 0; j < ac[i]->nb_streams; j++) { - sdp_write_media(buff, size, + ff_sdp_write_media(buff, size, ac[i]->streams[j]->codec, dst[0] ? dst : NULL, (port > 0) ? port + j * 2 : 0, ttl); if (port <= 0) { @@ -323,4 +369,9 @@ int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size) { return AVERROR(ENOSYS); } + +void ff_sdp_write_media(char *buff, int size, AVCodecContext *c, + const char *dest_addr, int port, int ttl) +{ +} #endif diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/seek.c b/src/add-ons/media/plugins/ffmpeg/libavformat/seek.c new file mode 100644 index 0000000000..26b622f035 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/seek.c @@ -0,0 +1,518 @@ +/* + * seek utility functions for use within format handlers + * + * Copyright (c) 2009 Ivan Schreter + * + * 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 "seek.h" +#include "libavutil/mem.h" +#include "internal.h" + +// NOTE: implementation should be moved here in another patch, to keep patches +// separated. + +/** + * helper structure describing keyframe search state of one stream + */ +typedef struct { + int64_t pos_lo; ///< position of the frame with low timestamp in file or INT64_MAX if not found (yet) + int64_t ts_lo; ///< frame presentation timestamp or same as pos_lo for byte seeking + + int64_t pos_hi; ///< position of the frame with high timestamp in file or INT64_MAX if not found (yet) + int64_t ts_hi; ///< frame presentation timestamp or same as pos_hi for byte seeking + + int64_t last_pos; ///< last known position of a frame, for multi-frame packets + + int64_t term_ts; ///< termination timestamp (which TS we already read) + AVRational term_ts_tb; ///< timebase for term_ts + int64_t first_ts; ///< first packet timestamp in this iteration (to fill term_ts later) + AVRational first_ts_tb; ///< timebase for first_ts + + int terminated; ///< termination flag for the current iteration +} AVSyncPoint; + +/** + * Compute a distance between timestamps. + * + * Distances are only comparable, if same time bases are used for computing + * distances. + * + * @param ts_hi high timestamp + * @param tb_hi high timestamp time base + * @param ts_lo low timestamp + * @param tb_lo low timestamp time base + * @return representation of distance between high and low timestamps + */ +static int64_t ts_distance(int64_t ts_hi, + AVRational tb_hi, + int64_t ts_lo, + AVRational tb_lo) +{ + int64_t hi, lo; + + hi = ts_hi * tb_hi.num * tb_lo.den; + lo = ts_lo * tb_lo.num * tb_hi.den; + + return hi - lo; +} + +/** + * Partial search for keyframes in multiple streams. + * + * This routine searches in each stream for the next lower and the next higher + * timestamp compared to the given target timestamp. The search starts at the current + * file position and ends at the file position, where all streams have already been + * examined (or when all higher key frames are found in the first iteration). + * + * This routine is called iteratively with an exponential backoff to find the lower + * timestamp. + * + * @param s format context + * @param timestamp target timestamp (or position, if AVSEEK_FLAG_BYTE) + * @param timebase time base for timestamps + * @param flags seeking flags + * @param sync array with information per stream + * @param keyframes_to_find count of keyframes to find in total + * @param found_lo ptr to the count of already found low timestamp keyframes + * @param found_hi ptr to the count of already found high timestamp keyframes + * @param first_iter flag for first iteration + */ +static void search_hi_lo_keyframes(AVFormatContext *s, + int64_t timestamp, + AVRational timebase, + int flags, + AVSyncPoint *sync, + int keyframes_to_find, + int *found_lo, + int *found_hi, + int first_iter) +{ + AVPacket pkt; + AVSyncPoint *sp; + AVStream *st; + int idx; + int flg; + int terminated_count = 0; + int64_t pos; + int64_t pts, dts; // PTS/DTS from stream + int64_t ts; // PTS in stream-local time base or position for byte seeking + AVRational ts_tb; // Time base of the stream or 1:1 for byte seeking + + for (;;) { + if (av_read_frame(s, &pkt) < 0) { + // EOF or error, make sure high flags are set + for (idx = 0; idx < s->nb_streams; ++idx) { + if (s->streams[idx]->discard < AVDISCARD_ALL) { + sp = &sync[idx]; + if (sp->pos_hi == INT64_MAX) { + // no high frame exists for this stream + (*found_hi)++; + sp->ts_hi = INT64_MAX; + sp->pos_hi = INT64_MAX - 1; + } + } + } + break; + } + + idx = pkt.stream_index; + st = s->streams[idx]; + if (st->discard >= AVDISCARD_ALL) + // this stream is not active, skip packet + continue; + + sp = &sync[idx]; + + flg = pkt.flags; + pos = pkt.pos; + pts = pkt.pts; + dts = pkt.dts; + if (pts == AV_NOPTS_VALUE) + // some formats don't provide PTS, only DTS + pts = dts; + + av_free_packet(&pkt); + + // Multi-frame packets only return position for the very first frame. + // Other frames are read with position == -1. Therefore, we note down + // last known position of a frame and use it if a frame without + // position arrives. In this way, it's possible to seek to proper + // position. Additionally, for parsers not providing position at all, + // an approximation will be used (starting position of this iteration). + if (pos < 0) + pos = sp->last_pos; + else + sp->last_pos = pos; + + // Evaluate key frames with known TS (or any frames, if AVSEEK_FLAG_ANY set). + if (pts != AV_NOPTS_VALUE && + ((flg & AV_PKT_FLAG_KEY) || (flags & AVSEEK_FLAG_ANY))) { + if (flags & AVSEEK_FLAG_BYTE) { + // for byte seeking, use position as timestamp + ts = pos; + ts_tb.num = 1; + ts_tb.den = 1; + } else { + // otherwise, get stream time_base + ts = pts; + ts_tb = st->time_base; + } + + if (sp->first_ts == AV_NOPTS_VALUE) { + // Note down termination timestamp for the next iteration - when + // we encounter a packet with the same timestamp, we will ignore + // any further packets for this stream in next iteration (as they + // are already evaluated). + sp->first_ts = ts; + sp->first_ts_tb = ts_tb; + } + + if (sp->term_ts != AV_NOPTS_VALUE && + av_compare_ts(ts, ts_tb, sp->term_ts, sp->term_ts_tb) > 0) { + // past the end position from last iteration, ignore packet + if (!sp->terminated) { + sp->terminated = 1; + ++terminated_count; + if (sp->pos_hi == INT64_MAX) { + // no high frame exists for this stream + (*found_hi)++; + sp->ts_hi = INT64_MAX; + sp->pos_hi = INT64_MAX - 1; + } + if (terminated_count == keyframes_to_find) + break; // all terminated, iteration done + } + continue; + } + + if (av_compare_ts(ts, ts_tb, timestamp, timebase) <= 0) { + // keyframe found before target timestamp + if (sp->pos_lo == INT64_MAX) { + // found first keyframe lower than target timestamp + (*found_lo)++; + sp->ts_lo = ts; + sp->pos_lo = pos; + } else if (sp->ts_lo < ts) { + // found a better match (closer to target timestamp) + sp->ts_lo = ts; + sp->pos_lo = pos; + } + } + if (av_compare_ts(ts, ts_tb, timestamp, timebase) >= 0) { + // keyframe found after target timestamp + if (sp->pos_hi == INT64_MAX) { + // found first keyframe higher than target timestamp + (*found_hi)++; + sp->ts_hi = ts; + sp->pos_hi = pos; + if (*found_hi >= keyframes_to_find && first_iter) { + // We found high frame for all. They may get updated + // to TS closer to target TS in later iterations (which + // will stop at start position of previous iteration). + break; + } + } else if (sp->ts_hi > ts) { + // found a better match (actually, shouldn't happen) + sp->ts_hi = ts; + sp->pos_hi = pos; + } + } + } + } + + // Clean up the parser. + ff_read_frame_flush(s); +} + +int64_t ff_gen_syncpoint_search(AVFormatContext *s, + int stream_index, + int64_t pos, + int64_t ts_min, + int64_t ts, + int64_t ts_max, + int flags) +{ + AVSyncPoint *sync, *sp; + AVStream *st; + int i; + int keyframes_to_find = 0; + int64_t curpos; + int64_t step; + int found_lo = 0, found_hi = 0; + int64_t min_distance, distance; + int64_t min_pos = 0; + int first_iter = 1; + AVRational time_base; + + if (flags & AVSEEK_FLAG_BYTE) { + // for byte seeking, we have exact 1:1 "timestamps" - positions + time_base.num = 1; + time_base.den = 1; + } else { + if (stream_index >= 0) { + // we have a reference stream, which time base we use + st = s->streams[stream_index]; + time_base = st->time_base; + } else { + // no reference stream, use AV_TIME_BASE as reference time base + time_base.num = 1; + time_base.den = AV_TIME_BASE; + } + } + + // Initialize syncpoint structures for each stream. + sync = av_malloc(s->nb_streams * sizeof(AVSyncPoint)); + if (!sync) + // cannot allocate helper structure + return -1; + + for (i = 0; i < s->nb_streams; ++i) { + st = s->streams[i]; + sp = &sync[i]; + + sp->pos_lo = INT64_MAX; + sp->ts_lo = INT64_MAX; + sp->pos_hi = INT64_MAX; + sp->ts_hi = INT64_MAX; + sp->terminated = 0; + sp->first_ts = AV_NOPTS_VALUE; + sp->term_ts = ts_max; + sp->term_ts_tb = time_base; + sp->last_pos = pos; + + st->cur_dts = AV_NOPTS_VALUE; + + if (st->discard < AVDISCARD_ALL) + ++keyframes_to_find; + } + + if (!keyframes_to_find) { + // no stream active, error + av_free(sync); + return -1; + } + + // Find keyframes in all active streams with timestamp/position just before + // and just after requested timestamp/position. + step = s->pb->buffer_size; + curpos = FFMAX(pos - step / 2, 0); + for (;;) { + url_fseek(s->pb, curpos, SEEK_SET); + search_hi_lo_keyframes(s, + ts, time_base, + flags, + sync, + keyframes_to_find, + &found_lo, &found_hi, + first_iter); + if (found_lo == keyframes_to_find && found_hi == keyframes_to_find) + break; // have all keyframes we wanted + if (!curpos) + break; // cannot go back anymore + + curpos = pos - step; + if (curpos < 0) + curpos = 0; + step *= 2; + + // switch termination positions + for (i = 0; i < s->nb_streams; ++i) { + st = s->streams[i]; + st->cur_dts = AV_NOPTS_VALUE; + + sp = &sync[i]; + if (sp->first_ts != AV_NOPTS_VALUE) { + sp->term_ts = sp->first_ts; + sp->term_ts_tb = sp->first_ts_tb; + sp->first_ts = AV_NOPTS_VALUE; + } + sp->terminated = 0; + sp->last_pos = curpos; + } + first_iter = 0; + } + + // Find actual position to start decoding so that decoder synchronizes + // closest to ts and between ts_min and ts_max. + pos = INT64_MAX; + + for (i = 0; i < s->nb_streams; ++i) { + st = s->streams[i]; + if (st->discard < AVDISCARD_ALL) { + sp = &sync[i]; + min_distance = INT64_MAX; + // Find timestamp closest to requested timestamp within min/max limits. + if (sp->pos_lo != INT64_MAX + && av_compare_ts(ts_min, time_base, sp->ts_lo, st->time_base) <= 0 + && av_compare_ts(sp->ts_lo, st->time_base, ts_max, time_base) <= 0) { + // low timestamp is in range + min_distance = ts_distance(ts, time_base, sp->ts_lo, st->time_base); + min_pos = sp->pos_lo; + } + if (sp->pos_hi != INT64_MAX + && av_compare_ts(ts_min, time_base, sp->ts_hi, st->time_base) <= 0 + && av_compare_ts(sp->ts_hi, st->time_base, ts_max, time_base) <= 0) { + // high timestamp is in range, check distance + distance = ts_distance(sp->ts_hi, st->time_base, ts, time_base); + if (distance < min_distance) { + min_distance = distance; + min_pos = sp->pos_hi; + } + } + if (min_distance == INT64_MAX) { + // no timestamp is in range, cannot seek + av_free(sync); + return -1; + } + if (min_pos < pos) + pos = min_pos; + } + } + + url_fseek(s->pb, pos, SEEK_SET); + av_free(sync); + return pos; +} + +AVParserState *ff_store_parser_state(AVFormatContext *s) +{ + int i; + AVStream *st; + AVParserStreamState *ss; + AVParserState *state = av_malloc(sizeof(AVParserState)); + if (!state) + return NULL; + + state->stream_states = av_malloc(sizeof(AVParserStreamState) * s->nb_streams); + if (!state->stream_states) { + av_free(state); + return NULL; + } + + state->fpos = url_ftell(s->pb); + + // copy context structures + state->cur_st = s->cur_st; + state->packet_buffer = s->packet_buffer; + state->raw_packet_buffer = s->raw_packet_buffer; + state->raw_packet_buffer_remaining_size = s->raw_packet_buffer_remaining_size; + + s->cur_st = NULL; + s->packet_buffer = NULL; + s->raw_packet_buffer = NULL; + s->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE; + + // copy stream structures + state->nb_streams = s->nb_streams; + for (i = 0; i < s->nb_streams; i++) { + st = s->streams[i]; + ss = &state->stream_states[i]; + + ss->parser = st->parser; + ss->last_IP_pts = st->last_IP_pts; + ss->cur_dts = st->cur_dts; + ss->reference_dts = st->reference_dts; + ss->cur_ptr = st->cur_ptr; + ss->cur_len = st->cur_len; + ss->probe_packets = st->probe_packets; + ss->cur_pkt = st->cur_pkt; + + st->parser = NULL; + st->last_IP_pts = AV_NOPTS_VALUE; + st->cur_dts = AV_NOPTS_VALUE; + st->reference_dts = AV_NOPTS_VALUE; + st->cur_ptr = NULL; + st->cur_len = 0; + st->probe_packets = MAX_PROBE_PACKETS; + av_init_packet(&st->cur_pkt); + } + + return state; +} + +void ff_restore_parser_state(AVFormatContext *s, AVParserState *state) +{ + int i; + AVStream *st; + AVParserStreamState *ss; + ff_read_frame_flush(s); + + if (!state) + return; + + url_fseek(s->pb, state->fpos, SEEK_SET); + + // copy context structures + s->cur_st = state->cur_st; + s->packet_buffer = state->packet_buffer; + s->raw_packet_buffer = state->raw_packet_buffer; + s->raw_packet_buffer_remaining_size = state->raw_packet_buffer_remaining_size; + + // copy stream structures + for (i = 0; i < state->nb_streams; i++) { + st = s->streams[i]; + ss = &state->stream_states[i]; + + st->parser = ss->parser; + st->last_IP_pts = ss->last_IP_pts; + st->cur_dts = ss->cur_dts; + st->reference_dts = ss->reference_dts; + st->cur_ptr = ss->cur_ptr; + st->cur_len = ss->cur_len; + st->probe_packets = ss->probe_packets; + st->cur_pkt = ss->cur_pkt; + } + + av_free(state->stream_states); + av_free(state); +} + +static void free_packet_list(AVPacketList *pktl) +{ + AVPacketList *cur; + while (pktl) { + cur = pktl; + pktl = cur->next; + av_free_packet(&cur->pkt); + av_free(cur); + } +} + +void ff_free_parser_state(AVFormatContext *s, AVParserState *state) +{ + int i; + AVParserStreamState *ss; + + if (!state) + return; + + for (i = 0; i < state->nb_streams; i++) { + ss = &state->stream_states[i]; + if (ss->parser) + av_parser_close(ss->parser); + av_free_packet(&ss->cur_pkt); + } + + free_packet_list(state->packet_buffer); + free_packet_list(state->raw_packet_buffer); + + av_free(state->stream_states); + av_free(state); +} + diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/seek.h b/src/add-ons/media/plugins/ffmpeg/libavformat/seek.h new file mode 100644 index 0000000000..408f7d6ac7 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/seek.h @@ -0,0 +1,126 @@ +/* + * seek utility functions for use within format handlers + * + * Copyright (c) 2009 Ivan Schreter + * + * 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_SEEK_H +#define AVFORMAT_SEEK_H + +#include "avformat.h" + +/** + * structure to store parser state of one AVStream + */ +typedef struct AVParserStreamState { + // saved members of AVStream + AVCodecParserContext *parser; + AVPacket cur_pkt; + int64_t last_IP_pts; + int64_t cur_dts; + int64_t reference_dts; + const uint8_t *cur_ptr; + int cur_len; + int probe_packets; +} AVParserStreamState; + +/** + * structure to store parser state of AVFormat + */ +typedef struct AVParserState { + int64_t fpos; ///< file position at the time of call + + // saved members of AVFormatContext + AVStream *cur_st; ///< current stream. + AVPacketList *packet_buffer; ///< packet buffer of original state + AVPacketList *raw_packet_buffer; ///< raw packet buffer of original state + int raw_packet_buffer_remaining_size; ///< remaining space in raw_packet_buffer + + // saved info for streams + int nb_streams; ///< number of streams with stored state + AVParserStreamState *stream_states; ///< states of individual streams (array) +} AVParserState; + +/** + * Search for the sync point of all active streams. + * + * This routine is not supposed to be called directly by a user application, + * but by demuxers. + * + * A sync point is defined as a point in stream, such that, when decoding start + * from this point, the decoded output of all streams synchronizes closest + * to the given timestamp ts. This routine also takes timestamp limits into account. + * Thus, the output will synchronize no sooner than ts_min and no later than ts_max. + * + * @param stream_index stream index for time base reference of timestamps + * @param pos approximate position where to start searching for key frames + * @param min_ts minimum allowed timestamp (position, if AVSEEK_FLAG_BYTE set) + * @param ts target timestamp (or position, if AVSEEK_FLAG_BYTE set in flags) + * @param max_ts maximum allowed timestamp (position, if AVSEEK_FLAG_BYTE set) + * @param flags if AVSEEK_FLAG_ANY is set, seek to any frame, otherwise only + * to a keyframe. If AVSEEK_FLAG_BYTE is set, search by + * position, not by timestamp. + * @return -1 if no such sync point could be found, otherwise stream position + * (stream is repositioned to this position) + */ +int64_t ff_gen_syncpoint_search(AVFormatContext *s, + int stream_index, + int64_t pos, + int64_t min_ts, + int64_t ts, + int64_t max_ts, + int flags); + +/** + * Store current parser state and file position. + * + * This function can be used by demuxers before a destructive seeking algorithm + * to store the parser state. Depending on the outcome of the seek, either the original + * state can be restored or the new state kept and the original state freed. + * + * @note As a side effect, the original parser state is reset, since structures + * are relinked to the stored state instead of being deeply-copied (for + * performance reasons and to keep the code simple). + * + * @param s context from which to save state + * @return parser state object or NULL if memory could not be allocated + */ +AVParserState *ff_store_parser_state(AVFormatContext *s); + +/** + * Restore previously saved parser state and file position. + * + * Saved state will be invalidated and freed by this call, since internal + * structures will be relinked back to the stored state instead of being + * deeply-copied. + * + * @param s context to which to restore state (same as used for storing state) + * @param state state to restore + */ +void ff_restore_parser_state(AVFormatContext *s, AVParserState *state); + +/** + * Free previously saved parser state. + * + * @param s context to which the state belongs (same as used for storing state) + * @param state state to free + */ +void ff_free_parser_state(AVFormatContext *s, AVParserState *state); + +#endif /* AVFORMAT_SEEK_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/segafilm.c b/src/add-ons/media/plugins/ffmpeg/libavformat/segafilm.c index ae1263cf98..6274041892 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/segafilm.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/segafilm.c @@ -20,7 +20,7 @@ */ /** - * @file libavformat/segafilm.c + * @file * Sega FILM (.cpk) file demuxer * by Mike Melanson (melanson@pcisys.net) * For more information regarding the Sega FILM file format, visit: @@ -133,7 +133,7 @@ static int film_read_header(AVFormatContext *s, if (!st) return AVERROR(ENOMEM); film->video_stream_index = st->index; - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = film->video_type; st->codec->codec_tag = 0; /* no fourcc */ st->codec->width = AV_RB32(&scratch[16]); @@ -145,7 +145,7 @@ static int film_read_header(AVFormatContext *s, if (!st) return AVERROR(ENOMEM); film->audio_stream_index = st->index; - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = film->audio_type; st->codec->codec_tag = 1; st->codec->channels = film->audio_channels; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/sierravmd.c b/src/add-ons/media/plugins/ffmpeg/libavformat/sierravmd.c index 52f05826d5..c239f5c66c 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/sierravmd.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/sierravmd.c @@ -20,7 +20,7 @@ */ /** - * @file libavformat/sierravmd.c + * @file * Sierra VMD file demuxer * by Vladimir "VAG" Gneushev (vagsoft at mail.ru) * for more information on the Sierra VMD file format, visit: @@ -61,10 +61,17 @@ typedef struct VmdDemuxContext { static int vmd_probe(AVProbeData *p) { + int w, h; + if (p->buf_size < 16) + return 0; /* check if the first 2 bytes of the file contain the appropriate size * of a VMD header chunk */ if (AV_RL16(&p->buf[0]) != VMD_HEADER_SIZE - 2) return 0; + w = AV_RL16(&p->buf[12]); + h = AV_RL16(&p->buf[14]); + if (!w || w > 2048 || !h || h > 2048) + return 0; /* only return half certainty since this check is a bit sketchy */ return AVPROBE_SCORE_MAX / 2; @@ -102,7 +109,7 @@ static int vmd_read_header(AVFormatContext *s, return AVERROR(ENOMEM); av_set_pts_info(vst, 33, 1, 10); vmd->video_stream_index = vst->index; - vst->codec->codec_type = CODEC_TYPE_VIDEO; + vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; vst->codec->codec_id = vmd->is_indeo3 ? CODEC_ID_INDEO3 : CODEC_ID_VMDVIDEO; vst->codec->codec_tag = 0; /* no fourcc */ vst->codec->width = AV_RL16(&vmd->vmd_header[12]); @@ -122,7 +129,7 @@ static int vmd_read_header(AVFormatContext *s, if (!st) return AVERROR(ENOMEM); vmd->audio_stream_index = st->index; - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_VMDAUDIO; st->codec->codec_tag = 0; /* no fourcc */ st->codec->channels = (vmd->vmd_header[811] & 0x80) ? 2 : 1; @@ -154,7 +161,7 @@ static int vmd_read_header(AVFormatContext *s, vmd->frame_table = NULL; sound_buffers = AV_RL16(&vmd->vmd_header[808]); raw_frame_table_size = vmd->frame_count * 6; - if(vmd->frame_count * vmd->frames_per_block >= UINT_MAX / sizeof(vmd_frame)){ + if(vmd->frame_count * vmd->frames_per_block >= UINT_MAX / sizeof(vmd_frame) - sound_buffers){ av_log(s, AV_LOG_ERROR, "vmd->frame_count * vmd->frames_per_block too large\n"); return -1; } diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/siff.c b/src/add-ons/media/plugins/ffmpeg/libavformat/siff.c index 63fc0d6fac..3a0b9bb377 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/siff.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/siff.c @@ -60,11 +60,12 @@ typedef struct SIFFContext{ static int siff_probe(AVProbeData *p) { + uint32_t tag = AV_RL32(p->buf + 8); /* check file header */ - if (AV_RL32(p->buf) == TAG_SIFF) - return AVPROBE_SCORE_MAX; - else + if (AV_RL32(p->buf) != TAG_SIFF || + (tag != TAG_VBV1 && tag != TAG_SOUN)) return 0; + return AVPROBE_SCORE_MAX; } static int create_audio_stream(AVFormatContext *s, SIFFContext *c) @@ -73,7 +74,7 @@ static int create_audio_stream(AVFormatContext *s, SIFFContext *c) ast = av_new_stream(s, 0); if (!ast) return -1; - ast->codec->codec_type = CODEC_TYPE_AUDIO; + ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; ast->codec->codec_id = CODEC_ID_PCM_U8; ast->codec->channels = 1; ast->codec->bits_per_coded_sample = c->bits; @@ -117,7 +118,7 @@ static int siff_parse_vbv1(AVFormatContext *s, SIFFContext *c, ByteIOContext *pb st = av_new_stream(s, 0); if (!st) return -1; - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_VB; st->codec->codec_tag = MKTAG('V', 'B', 'V', '1'); st->codec->width = width; @@ -215,7 +216,7 @@ static int siff_read_packet(AVFormatContext *s, AVPacket *pkt) c->curstrm = 0; } if(!c->cur_frame || c->curstrm) - pkt->flags |= PKT_FLAG_KEY; + pkt->flags |= AV_PKT_FLAG_KEY; if (c->curstrm == -1) c->cur_frame++; }else{ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/smacker.c b/src/add-ons/media/plugins/ffmpeg/libavformat/smacker.c index 7d0a8d59d4..0dcc286556 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/smacker.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/smacker.c @@ -158,7 +158,7 @@ static int smacker_read_header(AVFormatContext *s, AVFormatParameters *ap) st->codec->width = smk->width; st->codec->height = smk->height; st->codec->pix_fmt = PIX_FMT_PAL8; - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_SMACKVIDEO; st->codec->codec_tag = smk->magic; /* Smacker uses 100000 as internal timebase */ @@ -169,21 +169,29 @@ static int smacker_read_header(AVFormatContext *s, AVFormatParameters *ap) tbase = 100000; av_reduce(&tbase, &smk->pts_inc, tbase, smk->pts_inc, (1UL<<31)-1); av_set_pts_info(st, 33, smk->pts_inc, tbase); + st->duration = smk->frames; /* handle possible audio streams */ for(i = 0; i < 7; i++) { smk->indexes[i] = -1; - if((smk->rates[i] & 0xFFFFFF) && !(smk->rates[i] & SMK_AUD_BINKAUD)){ + if(smk->rates[i] & 0xFFFFFF){ ast[i] = av_new_stream(s, 0); smk->indexes[i] = ast[i]->index; - ast[i]->codec->codec_type = CODEC_TYPE_AUDIO; - ast[i]->codec->codec_id = (smk->rates[i] & SMK_AUD_PACKED) ? CODEC_ID_SMACKAUDIO : CODEC_ID_PCM_U8; - ast[i]->codec->codec_tag = MKTAG('S', 'M', 'K', 'A'); + ast[i]->codec->codec_type = AVMEDIA_TYPE_AUDIO; + if (smk->rates[i] & SMK_AUD_BINKAUD) { + ast[i]->codec->codec_id = CODEC_ID_BINKAUDIO_RDFT; + } else if (smk->rates[i] & SMK_AUD_USEDCT) { + ast[i]->codec->codec_id = CODEC_ID_BINKAUDIO_DCT; + } else if (smk->rates[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; 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; - ast[i]->codec->sample_fmt = ast[i]->codec->bits_per_coded_sample == 8 ? SAMPLE_FMT_U8 : SAMPLE_FMT_S16; av_set_pts_info(ast[i], 64, 1, ast[i]->codec->sample_rate * ast[i]->codec->channels * ast[i]->codec->bits_per_coded_sample / 8); } diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/sol.c b/src/add-ons/media/plugins/ffmpeg/libavformat/sol.c index aa566647bb..3ae2d04bb3 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/sol.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/sol.c @@ -114,7 +114,7 @@ static int sol_read_header(AVFormatContext *s, st = av_new_stream(s, 0); if (!st) return -1; - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_tag = id; st->codec->codec_id = codec; st->codec->channels = channels; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/soxdec.c b/src/add-ons/media/plugins/ffmpeg/libavformat/soxdec.c index f6389caec9..42fa53e430 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/soxdec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/soxdec.c @@ -24,7 +24,7 @@ /** * SoX native format demuxer - * @file libavformat/soxdec.c + * @file * @author Daniel Verkamp * @sa http://wiki.multimedia.cx/index.php?title=SoX_native_intermediate_format */ @@ -53,7 +53,7 @@ static int sox_read_header(AVFormatContext *s, if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; if (get_le32(pb) == SOX_TAG) { st->codec->codec_id = CODEC_ID_PCM_S32LE; @@ -93,21 +93,21 @@ static int sox_read_header(AVFormatContext *s, return -1; } - if (comment_size && - comment_size + FF_INPUT_BUFFER_PADDING_SIZE >= comment_size) { - char *comment = av_mallocz(comment_size + FF_INPUT_BUFFER_PADDING_SIZE); + if (comment_size && comment_size < UINT_MAX) { + char *comment = av_malloc(comment_size+1); if (get_buffer(pb, comment, comment_size) != comment_size) { av_freep(&comment); - return AVERROR_IO; + return AVERROR(EIO); } - av_metadata_set(&s->metadata, "comment", comment); - av_freep(&comment); + comment[comment_size] = 0; + + av_metadata_set2(&s->metadata, "comment", comment, + AV_METADATA_DONT_STRDUP_VAL); } url_fskip(pb, header_size - SOX_FIXED_HDR - comment_size); st->codec->sample_rate = sample_rate; - st->codec->sample_fmt = SAMPLE_FMT_S32; st->codec->bits_per_coded_sample = 32; st->codec->bit_rate = st->codec->sample_rate * st->codec->bits_per_coded_sample * diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/soxenc.c b/src/add-ons/media/plugins/ffmpeg/libavformat/soxenc.c index 1a04b2b661..918bfad9ec 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/soxenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/soxenc.c @@ -24,7 +24,7 @@ /** * SoX native format muxer - * @file libavformat/soxenc.c + * @file * @author Daniel Verkamp * @sa http://wiki.multimedia.cx/index.php?title=SoX_native_intermediate_format */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/spdif.c b/src/add-ons/media/plugins/ffmpeg/libavformat/spdif.c index 95d2e206fa..1c53f736c7 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/spdif.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/spdif.c @@ -20,7 +20,7 @@ */ /** - * @file libavformat/spdif.c + * @file * IEC-61937 encapsulation of various formats, used by S/PDIF * @author Bartlomiej Wolowiec */ @@ -238,10 +238,6 @@ static int spdif_write_header(AVFormatContext *s) av_log(s, AV_LOG_ERROR, "codec not supported\n"); return -1; } - put_le16(s->pb, 0); - put_le16(s->pb, 0); - put_le16(s->pb, 0); - put_le16(s->pb, 0); return 0; } diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/swf.h b/src/add-ons/media/plugins/ffmpeg/libavformat/swf.h index 69064a281c..affebe9c73 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/swf.h +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/swf.h @@ -81,7 +81,7 @@ typedef struct { static const AVCodecTag swf_codec_tags[] = { {CODEC_ID_FLV1, 0x02}, {CODEC_ID_VP6F, 0x04}, - {0, 0}, + {CODEC_ID_NONE, 0}, }; static const AVCodecTag swf_audio_codec_tags[] = { @@ -90,7 +90,7 @@ static const AVCodecTag swf_audio_codec_tags[] = { {CODEC_ID_MP3, 0x02}, {CODEC_ID_PCM_S16LE, 0x03}, //{CODEC_ID_NELLYMOSER, 0x06}, - {0, 0}, + {CODEC_ID_NONE, 0}, }; #endif /* AVFORMAT_SWF_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/swfdec.c b/src/add-ons/media/plugins/ffmpeg/libavformat/swfdec.c index 3a60fab702..64f775f783 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/swfdec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/swfdec.c @@ -97,7 +97,7 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt) for (i=0; inb_streams; i++) { st = s->streams[i]; - if (st->codec->codec_type == CODEC_TYPE_VIDEO && st->id == ch_id) + if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && st->id == ch_id) goto skip; } @@ -109,7 +109,7 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt) vst = av_new_stream(s, ch_id); if (!vst) return -1; - vst->codec->codec_type = CODEC_TYPE_VIDEO; + vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; vst->codec->codec_id = ff_codec_get_id(swf_codec_tags, get_byte(pb)); av_set_pts_info(vst, 16, 256, swf->frame_rate); vst->codec->time_base = (AVRational){ 256, swf->frame_rate }; @@ -120,7 +120,7 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt) for (i=0; inb_streams; i++) { st = s->streams[i]; - if (st->codec->codec_type == CODEC_TYPE_AUDIO && st->id == -1) + if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && st->id == -1) goto skip; } @@ -131,7 +131,7 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt) if (!ast) return -1; ast->codec->channels = 1 + (v&1); - ast->codec->codec_type = CODEC_TYPE_AUDIO; + 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; @@ -145,7 +145,7 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt) len -= 2; for(i=0; inb_streams; i++) { st = s->streams[i]; - if (st->codec->codec_type == CODEC_TYPE_VIDEO && st->id == ch_id) { + if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && st->id == ch_id) { frame = get_le16(pb); av_get_packet(pb, pkt, len-2); pkt->pos = pos; @@ -157,7 +157,7 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt) } else if (tag == TAG_STREAMBLOCK) { for (i = 0; i < s->nb_streams; i++) { st = s->streams[i]; - if (st->codec->codec_type == CODEC_TYPE_AUDIO && st->id == -1) { + if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && st->id == -1) { if (st->codec->codec_id == CODEC_ID_MP3) { url_fskip(pb, 4); av_get_packet(pb, pkt, len-4); @@ -179,7 +179,7 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt) vst = av_new_stream(s, -2); /* -2 to avoid clash with video stream and audio stream */ if (!vst) return -1; - vst->codec->codec_type = CODEC_TYPE_VIDEO; + vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; vst->codec->codec_id = CODEC_ID_MJPEG; av_set_pts_info(vst, 64, 256, swf->frame_rate); vst->codec->time_base = (AVRational){ 256, swf->frame_rate }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/swfenc.c b/src/add-ons/media/plugins/ffmpeg/libavformat/swfenc.c index 60b7171cc9..1a1a9ab808 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/swfenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/swfenc.c @@ -185,7 +185,7 @@ static int swf_write_header(AVFormatContext *s) for(i=0;inb_streams;i++) { AVCodecContext *enc = s->streams[i]->codec; - if (enc->codec_type == CODEC_TYPE_AUDIO) { + if (enc->codec_type == AVMEDIA_TYPE_AUDIO) { if (enc->codec_id == CODEC_ID_MP3) { if (!enc->frame_size) { av_log(s, AV_LOG_ERROR, "audio frame size not set\n"); @@ -464,7 +464,7 @@ static int swf_write_audio(AVFormatContext *s, static int swf_write_packet(AVFormatContext *s, AVPacket *pkt) { AVCodecContext *codec = s->streams[pkt->stream_index]->codec; - if (codec->codec_type == CODEC_TYPE_AUDIO) + if (codec->codec_type == AVMEDIA_TYPE_AUDIO) return swf_write_audio(s, codec, pkt->data, pkt->size); else return swf_write_video(s, codec, pkt->data, pkt->size); @@ -480,7 +480,7 @@ static int swf_write_trailer(AVFormatContext *s) video_enc = NULL; for(i=0;inb_streams;i++) { enc = s->streams[i]->codec; - if (enc->codec_type == CODEC_TYPE_VIDEO) + if (enc->codec_type == AVMEDIA_TYPE_VIDEO) video_enc = enc; else av_fifo_free(swf->audio_fifo); diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/tcp.c b/src/add-ons/media/plugins/ffmpeg/libavformat/tcp.c index 05676eb83d..79cabdfe90 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/tcp.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/tcp.c @@ -20,6 +20,7 @@ */ #include "avformat.h" #include +#include "internal.h" #include "network.h" #include "os_support.h" #if HAVE_SYS_SELECT_H @@ -34,7 +35,7 @@ typedef struct TCPContext { /* return non zero if error */ static int tcp_open(URLContext *h, const char *uri, int flags) { - struct sockaddr_in dest_addr; + struct addrinfo hints, *ai, *cur_ai; int port, fd = -1; TCPContext *s = NULL; fd_set wfds; @@ -42,28 +43,30 @@ static int tcp_open(URLContext *h, const char *uri, int flags) struct timeval tv; socklen_t optlen; char hostname[1024],proto[1024],path[1024]; + char portstr[10]; - if(!ff_network_init()) - return AVERROR(EIO); - - url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname), + ff_url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname), &port, path, sizeof(path), uri); if (strcmp(proto,"tcp") || port <= 0 || port >= 65536) return AVERROR(EINVAL); - dest_addr.sin_family = AF_INET; - dest_addr.sin_port = htons(port); - if (resolve_host(&dest_addr.sin_addr, hostname) < 0) + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + snprintf(portstr, sizeof(portstr), "%d", port); + if (getaddrinfo(hostname, portstr, &hints, &ai)) return AVERROR(EIO); - fd = socket(AF_INET, SOCK_STREAM, 0); + cur_ai = ai; + + restart: + fd = socket(cur_ai->ai_family, cur_ai->ai_socktype, cur_ai->ai_protocol); if (fd < 0) - return AVERROR(EIO); + goto fail; ff_socket_nonblock(fd, 1); redo: - ret = connect(fd, (struct sockaddr *)&dest_addr, - sizeof(dest_addr)); + ret = connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen); if (ret < 0) { if (ff_neterrno() == FF_NETERROR(EINTR)) goto redo; @@ -94,18 +97,29 @@ static int tcp_open(URLContext *h, const char *uri, int flags) goto fail; } s = av_malloc(sizeof(TCPContext)); - if (!s) + if (!s) { + freeaddrinfo(ai); return AVERROR(ENOMEM); + } h->priv_data = s; h->is_streamed = 1; s->fd = fd; + freeaddrinfo(ai); return 0; fail: + if (cur_ai->ai_next) { + /* Retry with the next sockaddr */ + cur_ai = cur_ai->ai_next; + if (fd >= 0) + closesocket(fd); + goto restart; + } ret = AVERROR(EIO); fail1: if (fd >= 0) closesocket(fd); + freeaddrinfo(ai); return ret; } @@ -133,6 +147,8 @@ static int tcp_read(URLContext *h, uint8_t *buf, int size) return AVERROR(ff_neterrno()); } else return len; } else if (ret < 0) { + if (ff_neterrno() == FF_NETERROR(EINTR)) + continue; return -1; } } @@ -166,6 +182,8 @@ static int tcp_write(URLContext *h, uint8_t *buf, int size) size -= len; buf += len; } else if (ret < 0) { + if (ff_neterrno() == FF_NETERROR(EINTR)) + continue; return -1; } } @@ -176,7 +194,6 @@ static int tcp_close(URLContext *h) { TCPContext *s = h->priv_data; closesocket(s->fd); - ff_network_close(); av_free(s); return 0; } diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/thp.c b/src/add-ons/media/plugins/ffmpeg/libavformat/thp.c index a5c9476d1a..82966dde7e 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/thp.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/thp.c @@ -100,7 +100,7 @@ static int thp_read_header(AVFormatContext *s, /* The denominator and numerator are switched because 1/fps is required. */ av_set_pts_info(st, 64, thp->fps.den, thp->fps.num); - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_THP; st->codec->codec_tag = 0; /* no fourcc */ st->codec->width = get_be32(pb); @@ -120,7 +120,7 @@ static int thp_read_header(AVFormatContext *s, if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_ADPCM_THP; st->codec->codec_tag = 0; /* no fourcc */ st->codec->channels = get_be32(pb); /* numChannels. */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/tiertexseq.c b/src/add-ons/media/plugins/ffmpeg/libavformat/tiertexseq.c index 43ee6b1e21..938eea59e5 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/tiertexseq.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/tiertexseq.c @@ -20,7 +20,7 @@ */ /** - * @file libavformat/tiertexseq.c + * @file * Tiertex Limited SEQ file demuxer */ @@ -212,7 +212,7 @@ static int seq_read_header(AVFormatContext *s, AVFormatParameters *ap) av_set_pts_info(st, 32, 1, SEQ_FRAME_RATE); seq->video_stream_index = st->index; - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_TIERTEXSEQVIDEO; st->codec->codec_tag = 0; /* no fourcc */ st->codec->width = SEQ_FRAME_W; @@ -225,7 +225,7 @@ static int seq_read_header(AVFormatContext *s, AVFormatParameters *ap) av_set_pts_info(st, 32, 1, SEQ_SAMPLE_RATE); seq->audio_stream_index = st->index; - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_PCM_S16BE; st->codec->codec_tag = 0; /* no tag */ st->codec->channels = 1; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/tmv.c b/src/add-ons/media/plugins/ffmpeg/libavformat/tmv.c index 566f562810..4be2f32568 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/tmv.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/tmv.c @@ -21,7 +21,7 @@ /** * 8088flex TMV file demuxer - * @file libavformat/tmv.c + * @file * @author Daniel Verkamp * @sa http://www.oldskool.org/pc/8088_Corruption */ @@ -43,10 +43,22 @@ typedef struct TMVContext { unsigned stream_index; } TMVContext; +#define TMV_HEADER_SIZE 12 + +#define PROBE_MIN_SAMPLE_RATE 5000 +#define PROBE_MAX_FPS 120 +#define PROBE_MIN_AUDIO_SIZE (PROBE_MIN_SAMPLE_RATE / PROBE_MAX_FPS) + static int tmv_probe(AVProbeData *p) { - if (AV_RL32(p->buf) == TMV_TAG) - return AVPROBE_SCORE_MAX; + if (AV_RL32(p->buf) == TMV_TAG && + AV_RL16(p->buf+4) >= PROBE_MIN_SAMPLE_RATE && + AV_RL16(p->buf+6) >= PROBE_MIN_AUDIO_SIZE && + !p->buf[8] && // compression method + p->buf[9] && // char cols + p->buf[10]) // char rows + return AVPROBE_SCORE_MAX / + ((p->buf[9] == 40 && p->buf[10] == 25) ? 1 : 4); return 0; } @@ -68,6 +80,11 @@ static int tmv_read_header(AVFormatContext *s, AVFormatParameters *ap) return AVERROR(ENOMEM); ast->codec->sample_rate = get_le16(pb); + if (!ast->codec->sample_rate) { + av_log(s, AV_LOG_ERROR, "invalid sample rate\n"); + return -1; + } + tmv->audio_chunk_size = get_le16(pb); if (!tmv->audio_chunk_size) { av_log(s, AV_LOG_ERROR, "invalid audio chunk size\n"); @@ -92,9 +109,8 @@ static int tmv_read_header(AVFormatContext *s, AVFormatParameters *ap) return -1; } - ast->codec->codec_type = CODEC_TYPE_AUDIO; + ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; ast->codec->codec_id = CODEC_ID_PCM_U8; - ast->codec->sample_fmt = SAMPLE_FMT_U8; ast->codec->channels = features & TMV_STEREO ? 2 : 1; ast->codec->bits_per_coded_sample = 8; ast->codec->bit_rate = ast->codec->sample_rate * @@ -105,7 +121,7 @@ static int tmv_read_header(AVFormatContext *s, AVFormatParameters *ap) fps.den = tmv->audio_chunk_size; av_reduce(&fps.num, &fps.den, fps.num, fps.den, 0xFFFFFFFFLL); - vst->codec->codec_type = CODEC_TYPE_VIDEO; + vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; vst->codec->codec_id = CODEC_ID_TMV; vst->codec->pix_fmt = PIX_FMT_PAL8; vst->codec->width = char_cols * 8; @@ -140,11 +156,28 @@ static int tmv_read_packet(AVFormatContext *s, AVPacket *pkt) pkt->stream_index = tmv->stream_index; tmv->stream_index ^= 1; - pkt->flags |= PKT_FLAG_KEY; + pkt->flags |= AV_PKT_FLAG_KEY; return ret; } +static int tmv_read_seek(AVFormatContext *s, int stream_index, + int64_t timestamp, int flags) +{ + TMVContext *tmv = s->priv_data; + int64_t pos; + + if (stream_index) + return -1; + + pos = timestamp * + (tmv->audio_chunk_size + tmv->video_chunk_size + tmv->padding); + + url_fseek(s->pb, pos + TMV_HEADER_SIZE, SEEK_SET); + tmv->stream_index = 0; + return 0; +} + AVInputFormat tmv_demuxer = { "tmv", NULL_IF_CONFIG_SMALL("8088flex TMV"), @@ -152,5 +185,7 @@ AVInputFormat tmv_demuxer = { tmv_probe, tmv_read_header, tmv_read_packet, + NULL, + tmv_read_seek, .flags = AVFMT_GENERIC_INDEX, }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/tta.c b/src/add-ons/media/plugins/ffmpeg/libavformat/tta.c index da6c04e703..66d3bad904 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/tta.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/tta.c @@ -21,6 +21,8 @@ #include "libavcodec/get_bits.h" #include "avformat.h" +#include "id3v2.h" +#include "id3v1.h" typedef struct { int totalframes, currentframe; @@ -29,6 +31,13 @@ typedef struct { static int tta_probe(AVProbeData *p) { const uint8_t *d = p->buf; + + if (ff_id3v2_match(d)) + d += ff_id3v2_tag_len(d); + + if (d - p->buf >= p->buf_size) + return 0; + if (d[0] == 'T' && d[1] == 'T' && d[2] == 'A' && d[3] == '1') return 80; return 0; @@ -39,8 +48,13 @@ static int tta_read_header(AVFormatContext *s, AVFormatParameters *ap) TTAContext *c = s->priv_data; AVStream *st; int i, channels, bps, samplerate, datalen, framelen; - uint64_t framepos; + uint64_t framepos, start_offset; + ff_id3v2_read(s); + if (!av_metadata_get(s->metadata, "", NULL, AV_METADATA_IGNORE_SUFFIX)) + ff_id3v1_read(s); + + start_offset = url_ftell(s->pb); if (get_le32(s->pb) != AV_RL32("TTA1")) return -1; // not tta file @@ -87,20 +101,20 @@ static int tta_read_header(AVFormatContext *s, AVFormatParameters *ap) } url_fskip(s->pb, 4); // seektable crc - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_TTA; st->codec->channels = channels; st->codec->sample_rate = samplerate; st->codec->bits_per_coded_sample = bps; - st->codec->extradata_size = url_ftell(s->pb); + st->codec->extradata_size = url_ftell(s->pb) - start_offset; if(st->codec->extradata_size+FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)st->codec->extradata_size){ //this check is redundant as get_buffer should fail av_log(s, AV_LOG_ERROR, "extradata_size too large\n"); return -1; } st->codec->extradata = av_mallocz(st->codec->extradata_size+FF_INPUT_BUFFER_PADDING_SIZE); - url_fseek(s->pb, 0, SEEK_SET); + url_fseek(s->pb, start_offset, SEEK_SET); get_buffer(s->pb, st->codec->extradata, st->codec->extradata_size); return 0; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/txd.c b/src/add-ons/media/plugins/ffmpeg/libavformat/txd.c index 0fd33e600d..38bdb1ba94 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/txd.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/txd.c @@ -43,7 +43,7 @@ static int txd_read_header(AVFormatContext *s, AVFormatParameters *ap) { st = av_new_stream(s, 0); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_TXD; st->codec->time_base.den = 5; st->codec->time_base.num = 1; @@ -62,10 +62,10 @@ next_chunk: marker = get_le32(pb); if (url_feof(s->pb)) - return AVERROR(EIO); + return AVERROR_EOF; if (marker != TXD_MARKER && marker != TXD_MARKER2) { av_log(s, AV_LOG_ERROR, "marker does not match\n"); - return AVERROR(EIO); + return AVERROR_INVALIDDATA; } switch (id) { @@ -79,13 +79,15 @@ next_chunk: goto next_chunk; default: av_log(s, AV_LOG_ERROR, "unknown chunk id %i\n", id); - return AVERROR(EIO); + return AVERROR_INVALIDDATA; } ret = av_get_packet(s->pb, pkt, chunk_size); + if (ret < 0) + return ret; pkt->stream_index = 0; - return ret <= 0 ? AVERROR(EIO) : ret; + return 0; } AVInputFormat txd_demuxer = diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/udp.c b/src/add-ons/media/plugins/ffmpeg/libavformat/udp.c index a89de0080a..a11f4c37d8 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/udp.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/udp.c @@ -20,13 +20,14 @@ */ /** - * @file libavformat/udp.c + * @file * UDP protocol */ #define _BSD_SOURCE /* Needed for using struct ip_mreq with recent glibc */ #include "avformat.h" #include +#include "internal.h" #include "network.h" #include "os_support.h" #if HAVE_SYS_SELECT_H @@ -52,18 +53,16 @@ typedef struct { int is_multicast; int local_port; int reuse_socket; -#if !CONFIG_IPV6 - struct sockaddr_in dest_addr; -#else struct sockaddr_storage dest_addr; -#endif int dest_addr_len; } UDPContext; #define UDP_TX_BUF_SIZE 32768 #define UDP_MAX_PKT_SIZE 65536 -static int udp_set_multicast_ttl(int sockfd, int mcastTTL, struct sockaddr *addr) { +static int udp_set_multicast_ttl(int sockfd, int mcastTTL, + struct sockaddr *addr) +{ #ifdef IP_MULTICAST_TTL if (addr->sa_family == AF_INET) { if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, &mcastTTL, sizeof(mcastTTL)) < 0) { @@ -72,7 +71,7 @@ static int udp_set_multicast_ttl(int sockfd, int mcastTTL, struct sockaddr *addr } } #endif -#if CONFIG_IPV6 +#if defined(IPPROTO_IPV6) && defined(IPV6_MULTICAST_HOPS) if (addr->sa_family == AF_INET6) { if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &mcastTTL, sizeof(mcastTTL)) < 0) { av_log(NULL, AV_LOG_ERROR, "setsockopt(IPV6_MULTICAST_HOPS): %s\n", strerror(errno)); @@ -83,7 +82,8 @@ static int udp_set_multicast_ttl(int sockfd, int mcastTTL, struct sockaddr *addr return 0; } -static int udp_join_multicast_group(int sockfd, struct sockaddr *addr) { +static int udp_join_multicast_group(int sockfd, struct sockaddr *addr) +{ #ifdef IP_ADD_MEMBERSHIP if (addr->sa_family == AF_INET) { struct ip_mreq mreq; @@ -96,7 +96,7 @@ static int udp_join_multicast_group(int sockfd, struct sockaddr *addr) { } } #endif -#if CONFIG_IPV6 +#if HAVE_STRUCT_IPV6_MREQ if (addr->sa_family == AF_INET6) { struct ipv6_mreq mreq6; @@ -111,7 +111,8 @@ static int udp_join_multicast_group(int sockfd, struct sockaddr *addr) { return 0; } -static int udp_leave_multicast_group(int sockfd, struct sockaddr *addr) { +static int udp_leave_multicast_group(int sockfd, struct sockaddr *addr) +{ #ifdef IP_DROP_MEMBERSHIP if (addr->sa_family == AF_INET) { struct ip_mreq mreq; @@ -124,7 +125,7 @@ static int udp_leave_multicast_group(int sockfd, struct sockaddr *addr) { } } #endif -#if CONFIG_IPV6 +#if HAVE_STRUCT_IPV6_MREQ if (addr->sa_family == AF_INET6) { struct ipv6_mreq mreq6; @@ -139,8 +140,9 @@ static int udp_leave_multicast_group(int sockfd, struct sockaddr *addr) { return 0; } -#if CONFIG_IPV6 -static struct addrinfo* udp_ipv6_resolve_host(const char *hostname, int port, int type, int family, int flags) { +static struct addrinfo* udp_resolve_host(const char *hostname, int port, + int type, int family, int flags) +{ struct addrinfo hints, *res = 0; int error; char sport[16]; @@ -158,17 +160,20 @@ static struct addrinfo* udp_ipv6_resolve_host(const char *hostname, int port, in hints.ai_family = family; hints.ai_flags = flags; if ((error = getaddrinfo(node, service, &hints, &res))) { - av_log(NULL, AV_LOG_ERROR, "udp_ipv6_resolve_host: %s\n", gai_strerror(error)); + res = NULL; + av_log(NULL, AV_LOG_ERROR, "udp_resolve_host: %s\n", gai_strerror(error)); } return res; } -static int udp_set_url(struct sockaddr_storage *addr, const char *hostname, int port) { +static int udp_set_url(struct sockaddr_storage *addr, + const char *hostname, int port) +{ struct addrinfo *res0; int addr_len; - res0 = udp_ipv6_resolve_host(hostname, port, SOCK_DGRAM, AF_UNSPEC, 0); + res0 = udp_resolve_host(hostname, port, SOCK_DGRAM, AF_UNSPEC, 0); if (res0 == 0) return AVERROR(EIO); memcpy(addr, res0->ai_addr, res0->ai_addrlen); addr_len = res0->ai_addrlen; @@ -182,14 +187,17 @@ static int is_multicast_address(struct sockaddr_storage *addr) if (addr->ss_family == AF_INET) { return IN_MULTICAST(ntohl(((struct sockaddr_in *)addr)->sin_addr.s_addr)); } +#if HAVE_STRUCT_SOCKADDR_IN6 if (addr->ss_family == AF_INET6) { return IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6 *)addr)->sin6_addr); } +#endif return 0; } -static int udp_socket_create(UDPContext *s, struct sockaddr_storage *addr, int *addr_len) +static int udp_socket_create(UDPContext *s, + struct sockaddr_storage *addr, int *addr_len) { int udp_fd = -1; struct addrinfo *res0 = NULL, *res = NULL; @@ -197,7 +205,7 @@ static int udp_socket_create(UDPContext *s, struct sockaddr_storage *addr, int * if (((struct sockaddr *) &s->dest_addr)->sa_family) family = ((struct sockaddr *) &s->dest_addr)->sa_family; - res0 = udp_ipv6_resolve_host(0, s->local_port, SOCK_DGRAM, family, AI_PASSIVE); + res0 = udp_resolve_host(0, s->local_port, SOCK_DGRAM, family, AI_PASSIVE); if (res0 == 0) goto fail; for (res = res0; res; res=res->ai_next) { @@ -236,46 +244,6 @@ static int udp_port(struct sockaddr_storage *addr, int addr_len) return strtol(sbuf, NULL, 10); } -#else - -static int udp_set_url(struct sockaddr_in *addr, const char *hostname, int port) -{ - /* set the destination address */ - if (resolve_host(&addr->sin_addr, hostname) < 0) - return AVERROR(EIO); - addr->sin_family = AF_INET; - addr->sin_port = htons(port); - - return sizeof(struct sockaddr_in); -} - -static int is_multicast_address(struct sockaddr_in *addr) -{ - return IN_MULTICAST(ntohl(addr->sin_addr.s_addr)); -} - -static int udp_socket_create(UDPContext *s, struct sockaddr_in *addr, int *addr_len) -{ - int fd; - - fd = socket(AF_INET, SOCK_DGRAM, 0); - if (fd < 0) - return -1; - - addr->sin_family = AF_INET; - addr->sin_addr.s_addr = htonl (INADDR_ANY); - addr->sin_port = htons(s->local_port); - *addr_len = sizeof(struct sockaddr_in); - - return fd; -} - -static int udp_port(struct sockaddr_in *addr, int len) -{ - return ntohs(addr->sin_port); -} -#endif /* CONFIG_IPV6 */ - /** * If no filename is given to av_open_input_file because you want to @@ -298,7 +266,7 @@ int udp_set_remote_url(URLContext *h, const char *uri) char hostname[256]; int port; - url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri); + ff_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri); /* set the destination address */ s->dest_addr_len = udp_set_url(&s->dest_addr, hostname, port); @@ -345,11 +313,7 @@ static int udp_open(URLContext *h, const char *uri, int flags) int is_output; const char *p; char buf[256]; -#if !CONFIG_IPV6 - struct sockaddr_in my_addr; -#else struct sockaddr_storage my_addr; -#endif int len; h->is_streamed = 1; @@ -357,9 +321,6 @@ static int udp_open(URLContext *h, const char *uri, int flags) is_output = (flags & URL_WRONLY); - if(!ff_network_init()) - return AVERROR(EIO); - s = av_mallocz(sizeof(UDPContext)); if (!s) return AVERROR(ENOMEM); @@ -386,9 +347,9 @@ static int udp_open(URLContext *h, const char *uri, int flags) } /* fill the dest addr */ - url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri); + ff_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri); - /* XXX: fix url_split */ + /* XXX: fix ff_url_split */ if (hostname[0] == '\0' || hostname[0] == '?') { /* only accepts null hostname if input */ if (flags & URL_WRONLY) @@ -476,8 +437,11 @@ static int udp_read(URLContext *h, uint8_t *buf, int size) tv.tv_sec = 0; tv.tv_usec = 100 * 1000; ret = select(s->udp_fd + 1, &rfds, NULL, NULL, &tv); - if (ret < 0) + if (ret < 0) { + if (ff_neterrno() == FF_NETERROR(EINTR)) + continue; return AVERROR(EIO); + } if (!(ret > 0 && FD_ISSET(s->udp_fd, &rfds))) continue; len = recv(s->udp_fd, buf, size, 0); @@ -519,7 +483,6 @@ static int udp_close(URLContext *h) if (s->is_multicast && !(h->flags & URL_WRONLY)) udp_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr); closesocket(s->udp_fd); - ff_network_close(); av_free(s); return 0; } diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/utils.c b/src/add-ons/media/plugins/ffmpeg/libavformat/utils.c index b9f6c004c9..6224a35d4d 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/utils.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/utils.c @@ -24,15 +24,20 @@ #include "metadata.h" #include "libavutil/avstring.h" #include "riff.h" +#include "audiointerleave.h" #include #include #include +#include +#if CONFIG_NETWORK +#include "network.h" +#endif #undef NDEBUG #include /** - * @file libavformat/utils.c + * @file * various utility functions for use within FFmpeg */ @@ -41,6 +46,17 @@ unsigned avformat_version(void) return LIBAVFORMAT_VERSION_INT; } +const char *avformat_configuration(void) +{ + return FFMPEG_CONFIGURATION; +} + +const char *avformat_license(void) +{ +#define LICENSE_PREFIX "libavformat license: " + return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1; +} + /* fraction handling */ /** @@ -126,7 +142,7 @@ void av_register_output_format(AVOutputFormat *format) format->next = NULL; } -int match_ext(const char *filename, const char *extensions) +int av_match_ext(const char *filename, const char *extensions) { const char *ext, *p; char ext1[32], *q; @@ -171,8 +187,16 @@ static int match_format(const char *name, const char *names) return !strcasecmp(name, names); } +#if LIBAVFORMAT_VERSION_MAJOR < 53 AVOutputFormat *guess_format(const char *short_name, const char *filename, const char *mime_type) +{ + return av_guess_format(short_name, filename, mime_type); +} +#endif + +AVOutputFormat *av_guess_format(const char *short_name, const char *filename, + const char *mime_type) { AVOutputFormat *fmt, *fmt_found; int score_max, score; @@ -182,7 +206,7 @@ AVOutputFormat *guess_format(const char *short_name, const char *filename, if (!short_name && filename && av_filename_number_test(filename) && av_guess_image2_codec(filename) != CODEC_ID_NONE) { - return guess_format("image2", NULL, NULL); + return av_guess_format("image2", NULL, NULL); } #endif /* Find the proper file type. */ @@ -196,7 +220,7 @@ AVOutputFormat *guess_format(const char *short_name, const char *filename, if (fmt->mime_type && mime_type && !strcmp(fmt->mime_type, mime_type)) score += 10; if (filename && fmt->extensions && - match_ext(filename, fmt->extensions)) { + av_match_ext(filename, fmt->extensions)) { score += 5; } if (score > score_max) { @@ -208,17 +232,18 @@ AVOutputFormat *guess_format(const char *short_name, const char *filename, return fmt_found; } +#if LIBAVFORMAT_VERSION_MAJOR < 53 AVOutputFormat *guess_stream_format(const char *short_name, const char *filename, const char *mime_type) { - AVOutputFormat *fmt = guess_format(short_name, filename, mime_type); + AVOutputFormat *fmt = av_guess_format(short_name, filename, mime_type); if (fmt) { AVOutputFormat *stream_fmt; char stream_format_name[64]; snprintf(stream_format_name, sizeof(stream_format_name), "%s_stream", fmt->name); - stream_fmt = guess_format(stream_format_name, NULL, NULL); + stream_fmt = av_guess_format(stream_format_name, NULL, NULL); if (stream_fmt) fmt = stream_fmt; @@ -226,10 +251,11 @@ AVOutputFormat *guess_stream_format(const char *short_name, const char *filename return fmt; } +#endif enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name, - const char *filename, const char *mime_type, enum CodecType type){ - if(type == CODEC_TYPE_VIDEO){ + const char *filename, const char *mime_type, enum AVMediaType type){ + if(type == AVMEDIA_TYPE_VIDEO){ enum CodecID codec_id= CODEC_ID_NONE; #if CONFIG_IMAGE2_MUXER @@ -240,7 +266,7 @@ enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name, if(codec_id == CODEC_ID_NONE) codec_id= fmt->video_codec; return codec_id; - }else if(type == CODEC_TYPE_AUDIO) + }else if(type == AVMEDIA_TYPE_AUDIO) return fmt->audio_codec; else return CODEC_ID_NONE; @@ -256,8 +282,38 @@ AVInputFormat *av_find_input_format(const char *short_name) return NULL; } -/* memory handling */ +#if LIBAVFORMAT_VERSION_MAJOR < 53 && CONFIG_SHARED && HAVE_SYMVER +FF_SYMVER(void, av_destruct_packet_nofree, (AVPacket *pkt), "LIBAVFORMAT_52") +{ + av_destruct_packet_nofree(pkt); +} +FF_SYMVER(void, av_destruct_packet, (AVPacket *pkt), "LIBAVFORMAT_52") +{ + av_destruct_packet(pkt); +} + +FF_SYMVER(int, av_new_packet, (AVPacket *pkt, int size), "LIBAVFORMAT_52") +{ + return av_new_packet(pkt, size); +} + +FF_SYMVER(int, av_dup_packet, (AVPacket *pkt), "LIBAVFORMAT_52") +{ + return av_dup_packet(pkt); +} + +FF_SYMVER(void, av_free_packet, (AVPacket *pkt), "LIBAVFORMAT_52") +{ + av_free_packet(pkt); +} + +FF_SYMVER(void, av_init_packet, (AVPacket *pkt), "LIBAVFORMAT_52") +{ + av_log(NULL, AV_LOG_WARNING, "Diverting av_*_packet function calls to libavcodec. Recompile to improve performance\n"); + av_init_packet(pkt); +} +#endif int av_get_packet(ByteIOContext *s, AVPacket *pkt, int size) { @@ -284,7 +340,7 @@ int av_filename_number_test(const char *filename) return filename && (av_get_frame_filename(buf, sizeof(buf), filename, 1)>=0); } -static AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max) +AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max) { AVInputFormat *fmt1, *fmt; int score; @@ -297,7 +353,7 @@ static AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int if (fmt1->read_probe) { score = fmt1->read_probe(pd); } else if (fmt1->extensions) { - if (match_ext(pd->filename, fmt1->extensions)) { + if (av_match_ext(pd->filename, fmt1->extensions)) { score = 50; } } @@ -315,30 +371,38 @@ AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened){ return av_probe_input_format2(pd, is_opened, &score); } -static int set_codec_from_probe_data(AVStream *st, AVProbeData *pd, int score) +static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, AVProbeData *pd, int score) { AVInputFormat *fmt; fmt = av_probe_input_format2(pd, 1, &score); if (fmt) { + av_log(s, AV_LOG_DEBUG, "Probe with size=%d, packets=%d detected %s with score=%d\n", + pd->buf_size, MAX_PROBE_PACKETS - st->probe_packets, fmt->name, score); if (!strcmp(fmt->name, "mp3")) { st->codec->codec_id = CODEC_ID_MP3; - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; } else if (!strcmp(fmt->name, "ac3")) { st->codec->codec_id = CODEC_ID_AC3; - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + } else if (!strcmp(fmt->name, "eac3")) { + st->codec->codec_id = CODEC_ID_EAC3; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; } else if (!strcmp(fmt->name, "mpegvideo")) { st->codec->codec_id = CODEC_ID_MPEG2VIDEO; - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; } else if (!strcmp(fmt->name, "m4v")) { st->codec->codec_id = CODEC_ID_MPEG4; - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; } else if (!strcmp(fmt->name, "h264")) { st->codec->codec_id = CODEC_ID_H264; - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; } else if (!strcmp(fmt->name, "dts")) { st->codec->codec_id = CODEC_ID_DTS; - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + } else if (!strcmp(fmt->name, "aac")) { + st->codec->codec_id = CODEC_ID_AAC; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; } } return !!fmt; @@ -427,14 +491,82 @@ int av_open_input_stream(AVFormatContext **ic_ptr, #define PROBE_BUF_MIN 2048 #define PROBE_BUF_MAX (1<<20) +int ff_probe_input_buffer(ByteIOContext **pb, AVInputFormat **fmt, + const char *filename, void *logctx, + unsigned int offset, unsigned int max_probe_size) +{ + AVProbeData pd = { filename ? filename : "", NULL, -offset }; + unsigned char *buf = NULL; + int ret = 0, probe_size; + + if (!max_probe_size) { + max_probe_size = PROBE_BUF_MAX; + } else if (max_probe_size > PROBE_BUF_MAX) { + max_probe_size = PROBE_BUF_MAX; + } else if (max_probe_size < PROBE_BUF_MIN) { + return AVERROR(EINVAL); + } + + if (offset >= max_probe_size) { + return AVERROR(EINVAL); + } + + for(probe_size= PROBE_BUF_MIN; probe_size<=max_probe_size && !*fmt && ret >= 0; + 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 buf_offset = (probe_size == PROBE_BUF_MIN) ? 0 : probe_size>>1; + + if (probe_size < offset) { + continue; + } + + /* read probe data */ + buf = av_realloc(buf, probe_size + AVPROBE_PADDING_SIZE); + if ((ret = get_buffer(*pb, buf + buf_offset, probe_size - buf_offset)) < 0) { + /* fail if error was not end of file, otherwise, lower score */ + if (ret != AVERROR_EOF) { + av_free(buf); + return ret; + } + score = 0; + ret = 0; /* error was end of file, nothing read */ + } + pd.buf_size += ret; + pd.buf = &buf[offset]; + + memset(pd.buf + pd.buf_size, 0, AVPROBE_PADDING_SIZE); + + /* guess file format */ + *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); + }else + av_log(logctx, AV_LOG_DEBUG, "Probed with size=%d and score=%d\n", probe_size, score); + } + } + + if (!*fmt) { + av_free(buf); + return AVERROR_INVALIDDATA; + } + + /* rewind. reuse probe buffer to avoid seeking */ + if ((ret = ff_rewind_with_probe_data(*pb, buf, pd.buf_size)) < 0) + av_free(buf); + + return ret; +} + int av_open_input_file(AVFormatContext **ic_ptr, const char *filename, AVInputFormat *fmt, int buf_size, AVFormatParameters *ap) { - int err, probe_size; + int err; AVProbeData probe_data, *pd = &probe_data; ByteIOContext *pb = NULL; + void *logctx= ap && ap->prealloced_context ? *ic_ptr : NULL; pd->filename = ""; if (filename) @@ -457,30 +589,14 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename, if (buf_size > 0) { url_setbufsize(pb, buf_size); } - - for(probe_size= PROBE_BUF_MIN; probe_size<=PROBE_BUF_MAX && !fmt; probe_size<<=1){ - int score= probe_size < PROBE_BUF_MAX ? AVPROBE_SCORE_MAX/4 : 0; - /* read probe data */ - pd->buf= av_realloc(pd->buf, probe_size + AVPROBE_PADDING_SIZE); - pd->buf_size = get_buffer(pb, pd->buf, probe_size); - memset(pd->buf+pd->buf_size, 0, AVPROBE_PADDING_SIZE); - if (url_fseek(pb, 0, SEEK_SET) < 0) { - url_fclose(pb); - if (url_fopen(&pb, filename, URL_RDONLY) < 0) { - pb = NULL; - err = AVERROR(EIO); - goto fail; - } - } - /* guess file format */ - fmt = av_probe_input_format2(pd, 1, &score); + if (!fmt && (err = ff_probe_input_buffer(&pb, &fmt, filename, logctx, 0, logctx ? (*ic_ptr)->probesize : 0)) < 0) { + goto fail; } - av_freep(&pd->buf); } /* if still no format found, error */ if (!fmt) { - err = AVERROR_NOFMT; + err = AVERROR_INVALIDDATA; goto fail; } @@ -560,13 +676,13 @@ int av_read_packet(AVFormatContext *s, AVPacket *pkt) st= s->streams[pkt->stream_index]; switch(st->codec->codec_type){ - case CODEC_TYPE_VIDEO: + case AVMEDIA_TYPE_VIDEO: if(s->video_codec_id) st->codec->codec_id= s->video_codec_id; break; - case CODEC_TYPE_AUDIO: + case AVMEDIA_TYPE_AUDIO: if(s->audio_codec_id) st->codec->codec_id= s->audio_codec_id; break; - case CODEC_TYPE_SUBTITLE: + case AVMEDIA_TYPE_SUBTITLE: if(s->subtitle_codec_id)st->codec->codec_id= s->subtitle_codec_id; break; } @@ -580,7 +696,7 @@ int av_read_packet(AVFormatContext *s, AVPacket *pkt) if(st->codec->codec_id == CODEC_ID_PROBE){ AVProbeData *pd = &st->probe_data; - + av_log(s, AV_LOG_DEBUG, "probing stream %d\n", st->index); --st->probe_packets; pd->buf = av_realloc(pd->buf, pd->buf_size+pkt->size+AVPROBE_PADDING_SIZE); @@ -589,10 +705,12 @@ int av_read_packet(AVFormatContext *s, AVPacket *pkt) memset(pd->buf+pd->buf_size, 0, AVPROBE_PADDING_SIZE); if(av_log2(pd->buf_size) != av_log2(pd->buf_size - pkt->size)){ - set_codec_from_probe_data(st, pd, 1); + //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){ pd->buf_size=0; av_freep(&pd->buf); + av_log(s, AV_LOG_DEBUG, "probed stream %d\n", st->index); } } } @@ -642,7 +760,7 @@ static void compute_frame_duration(int *pnum, int *pden, AVStream *st, *pnum = 0; *pden = 0; switch(st->codec->codec_type) { - case CODEC_TYPE_VIDEO: + case AVMEDIA_TYPE_VIDEO: if(st->time_base.num*1000LL > st->time_base.den){ *pnum = st->time_base.num; *pden = st->time_base.den; @@ -652,9 +770,14 @@ static void compute_frame_duration(int *pnum, int *pden, AVStream *st, if (pc && pc->repeat_pict) { *pnum = (*pnum) * (1 + pc->repeat_pict); } + //If this codec can be interlaced or progressive then we need a parser to compute duration of a packet + //Thus if we have no parser in such case leave duration undefined. + if(st->codec->ticks_per_frame>1 && !pc){ + *pnum = *pden = 0; + } } break; - case CODEC_TYPE_AUDIO: + case AVMEDIA_TYPE_AUDIO: frame_size = get_audio_frame_size(st->codec, pkt->size); if (frame_size < 0) break; @@ -667,9 +790,9 @@ static void compute_frame_duration(int *pnum, int *pden, AVStream *st, } static int is_intra_only(AVCodecContext *enc){ - if(enc->codec_type == CODEC_TYPE_AUDIO){ + if(enc->codec_type == AVMEDIA_TYPE_AUDIO){ return 1; - }else if(enc->codec_type == CODEC_TYPE_VIDEO){ + }else if(enc->codec_type == AVMEDIA_TYPE_VIDEO){ switch(enc->codec_id){ case CODEC_ID_MJPEG: case CODEC_ID_MJPEGB: @@ -761,7 +884,14 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, int num, den, presentation_delayed, delay, i; int64_t offset; - if (pc && pc->pict_type == FF_B_TYPE) + if (s->flags & AVFMT_FLAG_NOFILLIN) + return; + + if((s->flags & AVFMT_FLAG_IGNDTS) && pkt->pts != AV_NOPTS_VALUE) + pkt->dts= AV_NOPTS_VALUE; + + if (st->codec->codec_id != CODEC_ID_H264 && pc && pc->pict_type == FF_B_TYPE) + //FIXME Set low_delay = 0 when has_b_frames = 1 st->codec->has_b_frames = 1; /* do we have a video B-frame ? */ @@ -789,7 +919,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, if (pkt->duration == 0) { compute_frame_duration(&num, &den, st, pc, pkt); if (den && num) { - pkt->duration = av_rescale(1, num * (int64_t)st->time_base.den, den * (int64_t)st->time_base.num); + pkt->duration = av_rescale_rnd(1, num * (int64_t)st->time_base.den, den * (int64_t)st->time_base.num, AV_ROUND_DOWN); if(pkt->duration != 0 && s->packet_buffer) update_initial_durations(s, st, pkt); @@ -892,14 +1022,14 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, /* update flags */ if(is_intra_only(st->codec)) - pkt->flags |= PKT_FLAG_KEY; + pkt->flags |= AV_PKT_FLAG_KEY; else if (pc) { pkt->flags = 0; /* keyframe computation */ if (pc->key_frame == 1) - pkt->flags |= PKT_FLAG_KEY; + pkt->flags |= AV_PKT_FLAG_KEY; else if (pc->key_frame == -1 && pc->pict_type == FF_I_TYPE) - pkt->flags |= PKT_FLAG_KEY; + pkt->flags |= AV_PKT_FLAG_KEY; } if (pc) pkt->convergence_duration = pc->convergence_duration; @@ -924,7 +1054,7 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt) compute_pkt_fields(s, st, NULL, pkt); s->cur_st = NULL; if ((s->iformat->flags & AVFMT_GENERIC_INDEX) && - (pkt->flags & PKT_FLAG_KEY) && pkt->dts != AV_NOPTS_VALUE) { + (pkt->flags & AV_PKT_FLAG_KEY) && pkt->dts != AV_NOPTS_VALUE) { ff_reduce_index(s, st->index); av_add_index_entry(st, pkt->pos, pkt->dts, 0, 0, AVINDEX_KEYFRAME); } @@ -951,7 +1081,7 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt) pkt->destruct = NULL; compute_pkt_fields(s, st, st->parser, pkt); - if((s->iformat->flags & AVFMT_GENERIC_INDEX) && pkt->flags & PKT_FLAG_KEY){ + if((s->iformat->flags & AVFMT_GENERIC_INDEX) && pkt->flags & AV_PKT_FLAG_KEY){ ff_reduce_index(s, st->index); av_add_index_entry(st, st->parser->frame_offset, pkt->dts, 0, 0, AVINDEX_KEYFRAME); @@ -1003,17 +1133,18 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt) } if(s->debug & FF_FDEBUG_TS) - av_log(s, AV_LOG_DEBUG, "av_read_packet stream=%d, pts=%"PRId64", dts=%"PRId64", size=%d, flags=%d\n", + av_log(s, AV_LOG_DEBUG, "av_read_packet stream=%d, pts=%"PRId64", dts=%"PRId64", size=%d, duration=%d, flags=%d\n", st->cur_pkt.stream_index, st->cur_pkt.pts, st->cur_pkt.dts, st->cur_pkt.size, + st->cur_pkt.duration, st->cur_pkt.flags); s->cur_st = st; st->cur_ptr = st->cur_pkt.data; st->cur_len = st->cur_pkt.size; - if (st->need_parsing && !st->parser) { + if (st->need_parsing && !st->parser && !(s->flags & AVFMT_FLAG_NOPARSE)) { st->parser = av_parser_init(st->codec->codec_id); if (!st->parser) { /* no parser available: just output the raw packets */ @@ -1029,11 +1160,12 @@ 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, flags=%d\n", + av_log(s, AV_LOG_DEBUG, "av_read_frame_internal stream=%d, pts=%"PRId64", dts=%"PRId64", size=%d, duration=%d, flags=%d\n", pkt->stream_index, pkt->pts, pkt->dts, pkt->size, + pkt->duration, pkt->flags); return 0; @@ -1112,6 +1244,8 @@ static void flush_packet_queue(AVFormatContext *s) av_free_packet(&pktl->pkt); av_free(pktl); } + s->packet_buffer_end= + s->raw_packet_buffer_end= NULL; s->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE; } @@ -1128,10 +1262,10 @@ int av_find_default_stream_index(AVFormatContext *s) return -1; for(i = 0; i < s->nb_streams; i++) { st = s->streams[i]; - if (st->codec->codec_type == CODEC_TYPE_VIDEO) { + if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { return i; } - if (first_audio_index < 0 && st->codec->codec_type == CODEC_TYPE_AUDIO) + if (first_audio_index < 0 && st->codec->codec_type == AVMEDIA_TYPE_AUDIO) first_audio_index = i; } return first_audio_index >= 0 ? first_audio_index : 0; @@ -1140,10 +1274,10 @@ int av_find_default_stream_index(AVFormatContext *s) /** * Flush the frame reader. */ -static void av_read_frame_flush(AVFormatContext *s) +void ff_read_frame_flush(AVFormatContext *s) { AVStream *st; - int i; + int i, j; flush_packet_queue(s); @@ -1166,6 +1300,9 @@ static void av_read_frame_flush(AVFormatContext *s) st->cur_len = 0; st->probe_packets = MAX_PROBE_PACKETS; + + for(j=0; jpts_buffer[j]= AV_NOPTS_VALUE; } } @@ -1249,6 +1386,10 @@ int av_index_search_timestamp(AVStream *st, int64_t wanted_timestamp, a = - 1; b = nb_entries; + //optimize appending index entries at the end + if(b && entries[b-1].timestamp < wanted_timestamp) + a= b-1; + while (b - a > 1) { m = (a + b) >> 1; timestamp = entries[m].timestamp; @@ -1277,6 +1418,7 @@ int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts int64_t av_uninit(pos_min), av_uninit(pos_max), pos, pos_limit; int64_t ts_min, ts_max, ts; int index; + int64_t ret; AVStream *st; if (stream_index < 0) @@ -1329,7 +1471,8 @@ int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts return -1; /* do the seek */ - url_fseek(s->pb, pos, SEEK_SET); + if ((ret = url_fseek(s->pb, pos, SEEK_SET)) < 0) + return ret; av_update_cur_dts(s, st, ts); @@ -1479,7 +1622,8 @@ static int av_seek_frame_byte(AVFormatContext *s, int stream_index, int64_t pos, static int av_seek_frame_generic(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) { - int index, ret; + int index; + int64_t ret; AVStream *st; AVIndexEntry *ie; @@ -1487,6 +1631,9 @@ static int av_seek_frame_generic(AVFormatContext *s, index = av_index_search_timestamp(st, timestamp, flags); + if(index < 0 && st->nb_index_entries && timestamp < st->index_entries[0].timestamp) + return -1; + if(index < 0 || index==st->nb_index_entries-1){ int i; AVPacket pkt; @@ -1510,7 +1657,7 @@ static int av_seek_frame_generic(AVFormatContext *s, break; av_free_packet(&pkt); if(stream_index == pkt.stream_index){ - if((pkt.flags & PKT_FLAG_KEY) && pkt.dts > timestamp) + if((pkt.flags & AV_PKT_FLAG_KEY) && pkt.dts > timestamp) break; } } @@ -1519,7 +1666,7 @@ static int av_seek_frame_generic(AVFormatContext *s, if (index < 0) return -1; - av_read_frame_flush(s); + ff_read_frame_flush(s); if (s->iformat->read_seek){ if(s->iformat->read_seek(s, stream_index, timestamp, flags) >= 0) return 0; @@ -1537,7 +1684,7 @@ int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int f int ret; AVStream *st; - av_read_frame_flush(s); + ff_read_frame_flush(s); if(flags & AVSEEK_FLAG_BYTE) return av_seek_frame_byte(s, stream_index, timestamp, flags); @@ -1572,7 +1719,7 @@ int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int if(min_ts > ts || max_ts < ts) return -1; - av_read_frame_flush(s); + ff_read_frame_flush(s); if (s->iformat->read_seek2) return s->iformat->read_seek2(s, stream_index, min_ts, ts, max_ts, flags); @@ -1710,6 +1857,7 @@ static void av_estimate_timings_from_bit_rate(AVFormatContext *ic) } #define DURATION_MAX_READ_SIZE 250000 +#define DURATION_MAX_RETRY 3 /* only usable for MPEG-PS streams */ static void av_estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) @@ -1717,8 +1865,9 @@ static void av_estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset AVPacket pkt1, *pkt = &pkt1; AVStream *st; int read_size, i, ret; - int64_t end_time; + int64_t end_time, start_time[MAX_STREAMS]; int64_t filesize, offset, duration; + int retry=0; ic->cur_st = NULL; @@ -1727,6 +1876,13 @@ static void av_estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset for(i=0;inb_streams;i++) { st = ic->streams[i]; + if(st->start_time != AV_NOPTS_VALUE){ + start_time[i]= st->start_time; + }else if(st->first_dts != AV_NOPTS_VALUE){ + start_time[i]= st->first_dts; + }else + av_log(st->codec, AV_LOG_WARNING, "start time is not set in av_estimate_timings_from_pts\n"); + if (st->parser) { av_parser_close(st->parser); st->parser= NULL; @@ -1734,47 +1890,19 @@ static void av_estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset } } - /* we read the first packets to get the first PTS (not fully - accurate, but it is enough now) */ - url_fseek(ic->pb, 0, SEEK_SET); - read_size = 0; - for(;;) { - if (read_size >= DURATION_MAX_READ_SIZE) - break; - /* if all info is available, we can stop */ - for(i = 0;i < ic->nb_streams; i++) { - st = ic->streams[i]; - if (st->start_time == AV_NOPTS_VALUE) - break; - } - if (i == ic->nb_streams) - 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) { - if (st->start_time == AV_NOPTS_VALUE) - st->start_time = pkt->pts; - } - av_free_packet(pkt); - } - /* estimate the end time (duration) */ /* XXX: may need to support wrapping */ filesize = ic->file_size; - offset = filesize - DURATION_MAX_READ_SIZE; + end_time = AV_NOPTS_VALUE; + do{ + offset = filesize - (DURATION_MAX_READ_SIZE<pb, offset, SEEK_SET); read_size = 0; for(;;) { - if (read_size >= DURATION_MAX_READ_SIZE) + if (read_size >= DURATION_MAX_READ_SIZE<<(FFMAX(retry-1,0))) break; do{ @@ -1785,9 +1913,11 @@ static void av_estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset read_size += pkt->size; st = ic->streams[pkt->stream_index]; if (pkt->pts != AV_NOPTS_VALUE && - st->start_time != AV_NOPTS_VALUE) { + start_time[pkt->stream_index] != AV_NOPTS_VALUE) { end_time = pkt->pts; - duration = end_time - st->start_time; + duration = end_time - start_time[pkt->stream_index]; + if (duration < 0) + duration += 1LL<pts_wrap_bits; if (duration > 0) { if (st->duration == AV_NOPTS_VALUE || st->duration < duration) @@ -1796,6 +1926,9 @@ static void av_estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset } av_free_packet(pkt); } + }while( end_time==AV_NOPTS_VALUE + && filesize > (DURATION_MAX_READ_SIZE<codec_type) { - case CODEC_TYPE_AUDIO: + case AVMEDIA_TYPE_AUDIO: val = enc->sample_rate && enc->channels && enc->sample_fmt != SAMPLE_FMT_NONE; if(!enc->frame_size && (enc->codec_id == CODEC_ID_VORBIS || - enc->codec_id == CODEC_ID_AAC)) + 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)) return 0; break; - case CODEC_TYPE_VIDEO: + case AVMEDIA_TYPE_VIDEO: val = enc->width && enc->pix_fmt != PIX_FMT_NONE; break; default: @@ -1893,12 +2031,12 @@ static int try_decode_frame(AVStream *st, AVPacket *avpkt) if(!has_codec_parameters(st->codec)){ switch(st->codec->codec_type) { - case CODEC_TYPE_VIDEO: + case AVMEDIA_TYPE_VIDEO: avcodec_get_frame_defaults(&picture); ret = avcodec_decode_video2(st->codec, &picture, &got_picture, avpkt); break; - case CODEC_TYPE_AUDIO: + case AVMEDIA_TYPE_AUDIO: data_size = FFMAX(avpkt->size, AVCODEC_MAX_AUDIO_FRAME_SIZE); samples = av_malloc(data_size); if (!samples) @@ -2019,26 +2157,37 @@ int av_find_stream_info(AVFormatContext *ic) double (*duration_error)[MAX_STD_TIMEBASES]; int64_t old_offset = url_ftell(ic->pb); int64_t codec_info_duration[MAX_STREAMS]={0}; - int codec_info_nb_frames[MAX_STREAMS]={0}; duration_error = av_mallocz(MAX_STREAMS * sizeof(*duration_error)); if (!duration_error) return AVERROR(ENOMEM); for(i=0;inb_streams;i++) { st = ic->streams[i]; - if(st->codec->codec_type == CODEC_TYPE_VIDEO){ + if (st->codec->codec_id == CODEC_ID_AAC) { + st->codec->sample_rate = 0; + st->codec->frame_size = 0; + st->codec->channels = 0; + } + if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO){ /* if(!st->time_base.num) st->time_base= */ if(!st->codec->time_base.num) st->codec->time_base= st->time_base; } //only for the split stuff - if (!st->parser) { + if (!st->parser && !(ic->flags & AVFMT_FLAG_NOPARSE)) { st->parser = av_parser_init(st->codec->codec_id); if(st->need_parsing == AVSTREAM_PARSE_HEADERS && st->parser){ st->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES; } } + assert(!st->codec->codec); + //try to just open decoders, in case this is enough to get parameters + if(!has_codec_parameters(st->codec)){ + AVCodec *codec = avcodec_find_decoder(st->codec->codec_id); + if (codec) + avcodec_open(st->codec, codec); + } } for(i=0;icodec)) break; /* variable fps and no guess at the real fps */ - if( tb_unreliable(st->codec) - && duration_count[i]<20 && st->codec->codec_type == CODEC_TYPE_VIDEO) + if( tb_unreliable(st->codec) && !(st->r_frame_rate.num && st->avg_frame_rate.num) + && duration_count[i]<20 && st->codec->codec_type == AVMEDIA_TYPE_VIDEO) break; if(st->parser && st->parser->parser->split && !st->codec->extradata) break; @@ -2082,7 +2231,7 @@ int av_find_stream_info(AVFormatContext *ic) /* we did not get all the codec info, but we read too much data */ if (read_size >= ic->probesize) { ret = count; - av_log(ic, AV_LOG_DEBUG, "MAX_READ_SIZE:%d reached\n", ic->probesize); + av_log(ic, AV_LOG_DEBUG, "Probe buffer size limit %d reached\n", ic->probesize); break; } @@ -2099,7 +2248,7 @@ int av_find_stream_info(AVFormatContext *ic) if (!has_codec_parameters(st->codec)){ char buf[256]; avcodec_string(buf, sizeof(buf), st->codec, 0); - av_log(ic, AV_LOG_INFO, "Could not find codec parameters (%s)\n", buf); + av_log(ic, AV_LOG_WARNING, "Could not find codec parameters (%s)\n", buf); } else { ret = 0; } @@ -2116,15 +2265,14 @@ int av_find_stream_info(AVFormatContext *ic) read_size += pkt->size; st = ic->streams[pkt->stream_index]; - if(codec_info_nb_frames[st->index]>1) { + if(st->codec_info_nb_frames>1) { if (st->time_base.den > 0 && av_rescale_q(codec_info_duration[st->index], st->time_base, AV_TIME_BASE_Q) >= ic->max_analyze_duration){ - av_log(ic, AV_LOG_DEBUG, "max_analyze_duration reached\n"); + av_log(ic, AV_LOG_WARNING, "max_analyze_duration reached\n"); break; } codec_info_duration[st->index] += pkt->duration; } - if (pkt->duration != 0) - codec_info_nb_frames[st->index]++; + st->codec_info_nb_frames++; { int index= pkt->stream_index; @@ -2134,7 +2282,7 @@ int av_find_stream_info(AVFormatContext *ic) if(pkt->dts != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && duration>0){ double dur= duration * av_q2d(st->time_base); -// if(st->codec->codec_type == CODEC_TYPE_VIDEO) +// if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO) // av_log(NULL, AV_LOG_ERROR, "%f\n", dur); if(duration_count[index] < 2) memset(duration_error[index], 0, sizeof(*duration_error)); @@ -2166,21 +2314,7 @@ int av_find_stream_info(AVFormatContext *ic) decompress the frame. We try to avoid that in most cases as it takes longer and uses more memory. For MPEG-4, we need to decompress for QuickTime. */ - if (!has_codec_parameters(st->codec) /*&& - (st->codec->codec_id == CODEC_ID_FLV1 || - st->codec->codec_id == CODEC_ID_H264 || - st->codec->codec_id == CODEC_ID_H263 || - st->codec->codec_id == CODEC_ID_H261 || - st->codec->codec_id == CODEC_ID_VORBIS || - st->codec->codec_id == CODEC_ID_MJPEG || - st->codec->codec_id == CODEC_ID_PNG || - st->codec->codec_id == CODEC_ID_PAM || - st->codec->codec_id == CODEC_ID_PGM || - st->codec->codec_id == CODEC_ID_PGMYUV || - st->codec->codec_id == CODEC_ID_PBM || - st->codec->codec_id == CODEC_ID_PPM || - st->codec->codec_id == CODEC_ID_SHORTEN || - (st->codec->codec_id == CODEC_ID_MPEG4 && !st->need_parsing))*/) + if (!has_codec_parameters(st->codec)) try_decode_frame(st, pkt); count++; @@ -2194,16 +2328,20 @@ int av_find_stream_info(AVFormatContext *ic) } for(i=0;inb_streams;i++) { st = ic->streams[i]; - if (st->codec->codec_type == CODEC_TYPE_VIDEO) { + if(st->codec_info_nb_frames>2 && !st->avg_frame_rate.num && codec_info_duration[i]) + av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den, + (st->codec_info_nb_frames-2)*(int64_t)st->time_base.den, + codec_info_duration[i] *(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); // 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) && duration_count[i] > 15 && duration_gcd[i] > 1) + if (tb_unreliable(st->codec) && duration_count[i] > 15 && duration_gcd[i] > 1 && !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 * duration_gcd[i], INT_MAX); - if(duration_count[i] + if(duration_count[i] && !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]/duration_count[i]*101LL > st->time_base.den*/){ @@ -2213,7 +2351,7 @@ int av_find_stream_info(AVFormatContext *ic) for(j=1; jcodec->codec_type == CODEC_TYPE_VIDEO) +// 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; @@ -2235,7 +2373,7 @@ int av_find_stream_info(AVFormatContext *ic) st->r_frame_rate.den = st->time_base.num; } } - }else if(st->codec->codec_type == CODEC_TYPE_AUDIO) { + }else if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { if(!st->codec->bits_per_coded_sample) st->codec->bits_per_coded_sample= av_get_bits_per_sample(st->codec->codec_id); } @@ -2249,7 +2387,7 @@ int av_find_stream_info(AVFormatContext *ic) /* correct DTS for B-frame streams with no timestamps */ for(i=0;inb_streams;i++) { st = ic->streams[i]; - if (st->codec->codec_type == CODEC_TYPE_VIDEO) { + if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { if(b-frames){ ppktl = &ic->packet_buffer; while(ppkt1){ @@ -2436,7 +2574,7 @@ AVChapter *ff_new_chapter(AVFormatContext *s, int id, AVRational time_base, int6 #if LIBAVFORMAT_VERSION_INT < (53<<16) av_free(chapter->title); #endif - av_metadata_set(&chapter->metadata, "title", title); + av_metadata_set2(&chapter->metadata, "title", title, 0); chapter->id = id; chapter->time_base= time_base; chapter->start = start; @@ -2473,11 +2611,16 @@ int av_write_header(AVFormatContext *s) AVStream *st; // some sanity checks + if (s->nb_streams == 0) { + av_log(s, AV_LOG_ERROR, "no streams\n"); + return -1; + } + for(i=0;inb_streams;i++) { st = s->streams[i]; switch (st->codec->codec_type) { - case CODEC_TYPE_AUDIO: + case AVMEDIA_TYPE_AUDIO: if(st->codec->sample_rate<=0){ av_log(s, AV_LOG_ERROR, "sample rate not set\n"); return -1; @@ -2486,12 +2629,12 @@ int av_write_header(AVFormatContext *s) st->codec->block_align = st->codec->channels * av_get_bits_per_sample(st->codec->codec_id) >> 3; break; - case CODEC_TYPE_VIDEO: + case AVMEDIA_TYPE_VIDEO: if(st->codec->time_base.num<=0 || st->codec->time_base.den<=0){ //FIXME audio too? av_log(s, AV_LOG_ERROR, "time base not set\n"); return -1; } - if(st->codec->width<=0 || st->codec->height<=0){ + if((st->codec->width<=0 || st->codec->height<=0) && !(s->oformat->flags & AVFMT_NODIMENSIONS)){ av_log(s, AV_LOG_ERROR, "dimensions not set\n"); return -1; } @@ -2528,6 +2671,20 @@ int av_write_header(AVFormatContext *s) ff_metadata_mux_compat(s); #endif + /* set muxer identification string */ + if (!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) { + AVMetadata *m; + AVMetadataTag *t; + + if (!(m = av_mallocz(sizeof(AVMetadata)))) + return AVERROR(ENOMEM); + av_metadata_set2(&m, "encoder", LIBAVFORMAT_IDENT, 0); + metadata_conv(&m, s->oformat->metadata_conv, NULL); + if ((t = av_metadata_get(m, "", NULL, AV_METADATA_IGNORE_SUFFIX))) + av_metadata_set2(&s->metadata, t->key, t->value, 0); + av_metadata_free(&m); + } + if(s->oformat->write_header){ ret = s->oformat->write_header(s); if (ret < 0) @@ -2540,10 +2697,10 @@ int av_write_header(AVFormatContext *s) st = s->streams[i]; switch (st->codec->codec_type) { - case CODEC_TYPE_AUDIO: + case AVMEDIA_TYPE_AUDIO: den = (int64_t)st->time_base.num * st->codec->sample_rate; break; - case CODEC_TYPE_VIDEO: + case AVMEDIA_TYPE_VIDEO: den = (int64_t)st->time_base.num * st->codec->time_base.den; break; default: @@ -2559,11 +2716,11 @@ int av_write_header(AVFormatContext *s) } //FIXME merge with compute_pkt_fields -static int compute_pkt_fields2(AVStream *st, AVPacket *pkt){ +static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt){ int delay = FFMAX(st->codec->has_b_frames, !!st->codec->max_b_frames); int num, den, frame_size, i; -// av_log(st->codec, AV_LOG_DEBUG, "av_write_frame: pts:%"PRId64" dts:%"PRId64" cur_dts:%"PRId64" b:%d size:%d st:%d\n", pkt->pts, pkt->dts, st->cur_dts, delay, pkt->size, pkt->stream_index); +// av_log(s, AV_LOG_DEBUG, "av_write_frame: pts:%"PRId64" dts:%"PRId64" cur_dts:%"PRId64" b:%d size:%d st:%d\n", pkt->pts, pkt->dts, st->cur_dts, delay, pkt->size, pkt->stream_index); /* if(pkt->pts == AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE) return -1;*/ @@ -2590,7 +2747,7 @@ static int compute_pkt_fields2(AVStream *st, AVPacket *pkt){ if(pkt->pts != AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE && delay <= MAX_REORDER_DELAY){ st->pts_buffer[0]= pkt->pts; for(i=1; ipts_buffer[i] == AV_NOPTS_VALUE; i++) - st->pts_buffer[i]= (i-delay-1) * pkt->duration; + st->pts_buffer[i]= pkt->pts + (i-delay-1) * pkt->duration; for(i=0; ipts_buffer[i] > st->pts_buffer[i+1]; i++) FFSWAP(int64_t, st->pts_buffer[i], st->pts_buffer[i+1]); @@ -2598,21 +2755,23 @@ static int compute_pkt_fields2(AVStream *st, AVPacket *pkt){ } if(st->cur_dts && st->cur_dts != AV_NOPTS_VALUE && st->cur_dts >= pkt->dts){ - av_log(st->codec, AV_LOG_ERROR, "error, non monotone timestamps %"PRId64" >= %"PRId64"\n", st->cur_dts, pkt->dts); + av_log(s, AV_LOG_ERROR, + "st:%d error, non monotone timestamps %"PRId64" >= %"PRId64"\n", + st->index, st->cur_dts, pkt->dts); return -1; } if(pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE && pkt->pts < pkt->dts){ - av_log(st->codec, AV_LOG_ERROR, "error, pts < dts\n"); + av_log(s, AV_LOG_ERROR, "st:%d error, pts < dts\n", st->index); return -1; } -// av_log(NULL, AV_LOG_DEBUG, "av_write_frame: pts2:%"PRId64" dts2:%"PRId64"\n", pkt->pts, pkt->dts); +// av_log(s, AV_LOG_DEBUG, "av_write_frame: pts2:%"PRId64" dts2:%"PRId64"\n", pkt->pts, pkt->dts); st->cur_dts= pkt->dts; st->pts.val= pkt->dts; /* update pts */ switch (st->codec->codec_type) { - case CODEC_TYPE_AUDIO: + case AVMEDIA_TYPE_AUDIO: frame_size = get_audio_frame_size(st->codec, pkt->size); /* HACK/FIXME, we skip the initial 0 size packets as they are most @@ -2622,7 +2781,7 @@ static int compute_pkt_fields2(AVStream *st, AVPacket *pkt){ av_frac_add(&st->pts, (int64_t)st->time_base.den * frame_size); } break; - case CODEC_TYPE_VIDEO: + case AVMEDIA_TYPE_VIDEO: av_frac_add(&st->pts, (int64_t)st->time_base.den * st->codec->time_base.num); break; default: @@ -2633,7 +2792,7 @@ static int compute_pkt_fields2(AVStream *st, AVPacket *pkt){ int av_write_frame(AVFormatContext *s, AVPacket *pkt) { - int ret = compute_pkt_fields2(s->streams[pkt->stream_index], pkt); + int ret = compute_pkt_fields2(s, s->streams[pkt->stream_index], pkt); if(ret<0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS)) return ret; @@ -2654,13 +2813,29 @@ void ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, pkt->destruct= NULL; // do not free original but only the copy av_dup_packet(&this_pktl->pkt); // duplicate the packet if it uses non-alloced memory - next_point = &s->packet_buffer; - while(*next_point){ - if(compare(s, &(*next_point)->pkt, pkt)) - break; - next_point= &(*next_point)->next; + if(s->streams[pkt->stream_index]->last_in_packet_buffer){ + next_point = &(s->streams[pkt->stream_index]->last_in_packet_buffer->next); + }else + next_point = &s->packet_buffer; + + if(*next_point){ + if(compare(s, &s->packet_buffer_end->pkt, pkt)){ + while(!compare(s, &(*next_point)->pkt, pkt)){ + next_point= &(*next_point)->next; + } + goto next_non_null; + }else{ + next_point = &(s->packet_buffer_end->next); + } } + assert(!*next_point); + + s->packet_buffer_end= this_pktl; +next_non_null: + this_pktl->next= *next_point; + + s->streams[pkt->stream_index]->last_in_packet_buffer= *next_point= this_pktl; } @@ -2668,39 +2843,33 @@ int ff_interleave_compare_dts(AVFormatContext *s, AVPacket *next, AVPacket *pkt) { AVStream *st = s->streams[ pkt ->stream_index]; AVStream *st2= s->streams[ next->stream_index]; - int64_t left = st2->time_base.num * (int64_t)st ->time_base.den; - int64_t right= st ->time_base.num * (int64_t)st2->time_base.den; - - if (pkt->dts == AV_NOPTS_VALUE) - return 0; - - return next->dts * left > pkt->dts * right; //FIXME this can overflow + int64_t a= st2->time_base.num * (int64_t)st ->time_base.den; + int64_t b= st ->time_base.num * (int64_t)st2->time_base.den; + return av_rescale_rnd(pkt->dts, b, a, AV_ROUND_DOWN) < next->dts; } int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush){ AVPacketList *pktl; int stream_count=0; - int streams[MAX_STREAMS]; + int i; if(pkt){ ff_interleave_add_packet(s, pkt, ff_interleave_compare_dts); } - memset(streams, 0, sizeof(streams)); - pktl= s->packet_buffer; - while(pktl){ -//av_log(s, AV_LOG_DEBUG, "show st:%d dts:%"PRId64"\n", pktl->pkt.stream_index, pktl->pkt.dts); - if(streams[ pktl->pkt.stream_index ] == 0) - stream_count++; - streams[ pktl->pkt.stream_index ]++; - pktl= pktl->next; - } + for(i=0; i < s->nb_streams; i++) + stream_count+= !!s->streams[i]->last_in_packet_buffer; if(stream_count && (s->nb_streams == stream_count || flush)){ pktl= s->packet_buffer; *out= pktl->pkt; s->packet_buffer= pktl->next; + if(!s->packet_buffer) + s->packet_buffer_end= NULL; + + if(s->streams[out->stream_index]->last_in_packet_buffer == pktl) + s->streams[out->stream_index]->last_in_packet_buffer= NULL; av_freep(&pktl); return 1; }else{ @@ -2729,11 +2898,11 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt){ AVStream *st= s->streams[ pkt->stream_index]; //FIXME/XXX/HACK drop zero sized packets - if(st->codec->codec_type == CODEC_TYPE_AUDIO && pkt->size==0) + if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO && pkt->size==0) return 0; //av_log(NULL, AV_LOG_DEBUG, "av_interleaved_write_frame %d %"PRId64" %"PRId64"\n", pkt->size, pkt->dts, pkt->pts); - if(compute_pkt_fields2(st, pkt) < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS)) + if(compute_pkt_fields2(s, st, pkt) < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS)) return -1; if(pkt->dts == AV_NOPTS_VALUE && !(s->oformat->flags & AVFMT_NOTIMESTAMPS)) @@ -2784,18 +2953,25 @@ int av_write_trailer(AVFormatContext *s) fail: if(ret == 0) ret=url_ferror(s->pb); - for(i=0;inb_streams;i++) + for(i=0;inb_streams;i++) { av_freep(&s->streams[i]->priv_data); + av_freep(&s->streams[i]->index_entries); + } av_freep(&s->priv_data); return ret; } -void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned int idx) +void ff_program_add_stream_index(AVFormatContext *ac, int progid, unsigned int idx) { int i, j; AVProgram *program=NULL; void *tmp; + if (idx >= ac->nb_streams) { + av_log(ac, AV_LOG_ERROR, "stream index %d is not valid\n", idx); + return; + } + for(i=0; inb_programs; i++){ if(ac->programs[i]->id != progid) continue; @@ -2820,6 +2996,19 @@ static void print_fps(double d, const char *postfix){ else av_log(NULL, AV_LOG_INFO, ", %1.0fk %s", d/1000, postfix); } +static void dump_metadata(void *ctx, AVMetadata *m, const char *indent) +{ + if(m && !(m->count == 1 && av_metadata_get(m, "language", NULL, 0))){ + AVMetadataTag *tag=NULL; + + av_log(ctx, AV_LOG_INFO, "%sMetadata:\n", indent); + while((tag=av_metadata_get(m, "", tag, AV_METADATA_IGNORE_SUFFIX))) { + if(strcmp("language", tag->key)) + av_log(ctx, AV_LOG_INFO, "%s %-16s: %s\n", indent, tag->key, tag->value); + } + } +} + /* "user interface" functions */ static void dump_stream_format(AVFormatContext *ic, int i, int index, int is_output) { @@ -2836,7 +3025,7 @@ static void dump_stream_format(AVFormatContext *ic, int i, int index, int is_out av_log(NULL, AV_LOG_INFO, "[0x%x]", st->id); if (lang) av_log(NULL, AV_LOG_INFO, "(%s)", lang->value); - av_log(NULL, AV_LOG_DEBUG, ", %d/%d", st->time_base.num/g, st->time_base.den/g); + av_log(NULL, AV_LOG_DEBUG, ", %d, %d/%d", st->codec_info_nb_frames, st->time_base.num/g, st->time_base.den/g); av_log(NULL, AV_LOG_INFO, ": %s", buf); if (st->sample_aspect_ratio.num && // default av_cmp_q(st->sample_aspect_ratio, st->codec->sample_aspect_ratio)) { @@ -2849,7 +3038,9 @@ static void dump_stream_format(AVFormatContext *ic, int i, int index, int is_out st->sample_aspect_ratio.num, st->sample_aspect_ratio.den, display_aspect_ratio.num, display_aspect_ratio.den); } - if(st->codec->codec_type == CODEC_TYPE_VIDEO){ + if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO){ + if(st->avg_frame_rate.den && st->avg_frame_rate.num) + print_fps(av_q2d(st->avg_frame_rate), "fps"); if(st->r_frame_rate.den && st->r_frame_rate.num) print_fps(av_q2d(st->r_frame_rate), "tbr"); if(st->time_base.den && st->time_base.num) @@ -2858,6 +3049,7 @@ static void dump_stream_format(AVFormatContext *ic, int i, int index, int is_out print_fps(1/av_q2d(st->codec->time_base), "tbc"); } av_log(NULL, AV_LOG_INFO, "\n"); + dump_metadata(NULL, st->metadata, " "); } void dump_format(AVFormatContext *ic, @@ -2866,12 +3058,16 @@ void dump_format(AVFormatContext *ic, int is_output) { int i; + uint8_t *printed = av_mallocz(ic->nb_streams); + if (ic->nb_streams && !printed) + return; av_log(NULL, AV_LOG_INFO, "%s #%d, %s, %s '%s':\n", is_output ? "Output" : "Input", index, is_output ? ic->oformat->name : ic->iformat->name, is_output ? "to" : "from", url); + dump_metadata(NULL, ic->metadata, " "); if (!is_output) { av_log(NULL, AV_LOG_INFO, " Duration: "); if (ic->duration != AV_NOPTS_VALUE) { @@ -2903,27 +3099,36 @@ void dump_format(AVFormatContext *ic, } av_log(NULL, AV_LOG_INFO, "\n"); } + for (i = 0; i < ic->nb_chapters; i++) { + AVChapter *ch = ic->chapters[i]; + av_log(NULL, AV_LOG_INFO, " Chapter #%d.%d: ", index, i); + av_log(NULL, AV_LOG_INFO, "start %f, ", ch->start * av_q2d(ch->time_base)); + av_log(NULL, AV_LOG_INFO, "end %f\n", ch->end * av_q2d(ch->time_base)); + + dump_metadata(NULL, ch->metadata, " "); + } if(ic->nb_programs) { - int j, k; + int j, k, total = 0; for(j=0; jnb_programs; j++) { AVMetadataTag *name = av_metadata_get(ic->programs[j]->metadata, "name", NULL, 0); av_log(NULL, AV_LOG_INFO, " Program %d %s\n", ic->programs[j]->id, name ? name->value : ""); - for(k=0; kprograms[j]->nb_stream_indexes; k++) + dump_metadata(NULL, ic->programs[j]->metadata, " "); + for(k=0; kprograms[j]->nb_stream_indexes; k++) { dump_stream_format(ic, ic->programs[j]->stream_index[k], index, is_output); - } - } else - for(i=0;inb_streams;i++) - dump_stream_format(ic, i, index, is_output); - if (ic->metadata) { - AVMetadataTag *tag=NULL; - av_log(NULL, AV_LOG_INFO, " Metadata\n"); - while((tag=av_metadata_get(ic->metadata, "", tag, AV_METADATA_IGNORE_SUFFIX))) { - av_log(NULL, AV_LOG_INFO, " %-16s: %s\n", tag->key, tag->value); + printed[ic->programs[j]->stream_index[k]] = 1; + } + total += ic->programs[j]->nb_stream_indexes; } + if (total < ic->nb_streams) + av_log(NULL, AV_LOG_INFO, " No Program\n"); } + for(i=0;inb_streams;i++) + if (!printed[i]) + dump_stream_format(ic, i, index, is_output); + av_free(printed); } #if LIBAVFORMAT_VERSION_MAJOR < 53 @@ -2949,6 +3154,11 @@ int64_t av_gettime(void) return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec; } +uint64_t ff_ntp_time(void) +{ + return (av_gettime() / 1000) * 1000 + NTP_OFFSET_US; +} + int64_t parse_date(const char *datestr, int duration) { const char *p; @@ -3165,6 +3375,7 @@ int av_get_frame_filename(char *buf, int buf_size, static void hex_dump_internal(void *avcl, FILE *f, int level, uint8_t *buf, int size) { int len, i, j, c; +#undef fprintf #define PRINT(...) do { if (!f) av_log(avcl, level, __VA_ARGS__); else fprintf(f, __VA_ARGS__); } while(0) for(i=0;istream_index); - PRINT(" keyframe=%d\n", ((pkt->flags & PKT_FLAG_KEY) != 0)); + PRINT(" keyframe=%d\n", ((pkt->flags & AV_PKT_FLAG_KEY) != 0)); PRINT(" duration=%0.3f\n", (double)pkt->duration / AV_TIME_BASE); /* DTS is _always_ valid after av_read_frame() */ PRINT(" dts="); @@ -3236,12 +3448,12 @@ void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload) pkt_dump_internal(avcl, NULL, level, pkt, dump_payload); } -void url_split(char *proto, int proto_size, - char *authorization, int authorization_size, - char *hostname, int hostname_size, - int *port_ptr, - char *path, int path_size, - const char *url) +void ff_url_split(char *proto, int proto_size, + char *authorization, int authorization_size, + char *hostname, int hostname_size, + int *port_ptr, + char *path, int path_size, + const char *url) { const char *p, *ls, *at, *col, *brk; @@ -3297,13 +3509,18 @@ void url_split(char *proto, int proto_size, } } -char *ff_data_to_hex(char *buff, const uint8_t *src, int s) +char *ff_data_to_hex(char *buff, const uint8_t *src, int s, int lowercase) { int i; - static const char hex_table[16] = { '0', '1', '2', '3', - '4', '5', '6', '7', - '8', '9', 'A', 'B', - 'C', 'D', 'E', 'F' }; + static const char hex_table_uc[16] = { '0', '1', '2', '3', + '4', '5', '6', '7', + '8', '9', 'A', 'B', + 'C', 'D', 'E', 'F' }; + static const char hex_table_lc[16] = { '0', '1', '2', '3', + '4', '5', '6', '7', + '8', '9', 'a', 'b', + 'c', 'd', 'e', 'f' }; + const char *hex_table = lowercase ? hex_table_lc : hex_table_uc; for(i = 0; i < s; i++) { buff[i * 2] = hex_table[src[i] >> 4]; @@ -3327,3 +3544,48 @@ void av_set_pts_info(AVStream *s, int pts_wrap_bits, if(!s->time_base.num || !s->time_base.den) s->time_base.num= s->time_base.den= 0; } + +int ff_url_join(char *str, int size, const char *proto, + const char *authorization, const char *hostname, + int port, const char *fmt, ...) +{ +#if CONFIG_NETWORK + struct addrinfo hints, *ai; +#endif + + str[0] = '\0'; + if (proto) + av_strlcatf(str, size, "%s://", proto); + if (authorization) + av_strlcatf(str, size, "%s@", authorization); +#if CONFIG_NETWORK && defined(AF_INET6) + /* Determine if hostname is a numerical IPv6 address, + * properly escape it within [] in that case. */ + memset(&hints, 0, sizeof(hints)); + hints.ai_flags = AI_NUMERICHOST; + if (!getaddrinfo(hostname, NULL, &hints, &ai)) { + if (ai->ai_family == AF_INET6) { + av_strlcat(str, "[", size); + av_strlcat(str, hostname, size); + av_strlcat(str, "]", size); + } else { + av_strlcat(str, hostname, size); + } + freeaddrinfo(ai); + } else +#endif + /* Not an IPv6 address, just output the plain string. */ + av_strlcat(str, hostname, size); + + if (port >= 0) + av_strlcatf(str, size, ":%d", port); + if (fmt) { + va_list vl; + int len = strlen(str); + + va_start(vl, fmt); + vsnprintf(str + len, size > len ? size - len : 0, fmt, vl); + va_end(vl); + } + return strlen(str); +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/vc1test.c b/src/add-ons/media/plugins/ffmpeg/libavformat/vc1test.c index 007c3a1a1e..7a006f2b26 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/vc1test.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/vc1test.c @@ -20,7 +20,7 @@ */ /** - * @file libavformat/vc1test.c + * @file * VC1 test bitstream file demuxer * by Konstantin Shishkov * Format specified in SMPTE standard 421 Annex L @@ -33,7 +33,9 @@ static int vc1t_probe(AVProbeData *p) { - if (p->buf[3] != 0xC5 && AV_RL32(&p->buf[4]) != 4) + if (p->buf_size < 24) + return 0; + if (p->buf[3] != 0xC5 || AV_RL32(&p->buf[4]) != 4 || AV_RL32(&p->buf[20]) != 0xC) return 0; return AVPROBE_SCORE_MAX/2; @@ -44,7 +46,8 @@ static int vc1t_read_header(AVFormatContext *s, { ByteIOContext *pb = s->pb; AVStream *st; - int fps, frames; + int frames; + uint32_t fps; frames = get_le24(pb); if(get_byte(pb) != 0xC5 || get_le32(pb) != 4) @@ -55,7 +58,7 @@ static int vc1t_read_header(AVFormatContext *s, if (!st) return -1; - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_WMV3; st->codec->extradata = av_malloc(VC1_EXTRADATA_SIZE); @@ -67,9 +70,13 @@ static int vc1t_read_header(AVFormatContext *s, return -1; url_fskip(pb, 8); fps = get_le32(pb); - if(fps == -1) + if(fps == 0xFFFFFFFF) av_set_pts_info(st, 32, 1, 1000); else{ + if (!fps) { + av_log(s, AV_LOG_ERROR, "Zero FPS specified, defaulting to 1 FPS\n"); + fps = 1; + } av_set_pts_info(st, 24, 1, fps); st->duration = frames; } @@ -96,7 +103,7 @@ static int vc1t_read_packet(AVFormatContext *s, return AVERROR(EIO); if(s->streams[0]->time_base.den == 1000) pkt->pts = pts; - pkt->flags |= keyframe ? PKT_FLAG_KEY : 0; + pkt->flags |= keyframe ? AV_PKT_FLAG_KEY : 0; pkt->pos -= 8; return pkt->size; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/vc1testenc.c b/src/add-ons/media/plugins/ffmpeg/libavformat/vc1testenc.c index c871da9d0b..b4b1e024dc 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/vc1testenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/vc1testenc.c @@ -58,7 +58,7 @@ static int vc1test_write_packet(AVFormatContext *s, AVPacket *pkt) if (!pkt->size) return 0; - put_le32(pb, pkt->size | ((pkt->flags & PKT_FLAG_KEY) ? 0x80000000 : 0)); + put_le32(pb, pkt->size | ((pkt->flags & AV_PKT_FLAG_KEY) ? 0x80000000 : 0)); put_le32(pb, pkt->pts); put_buffer(pb, pkt->data, pkt->size); put_flush_packet(pb); diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/voc.c b/src/add-ons/media/plugins/ffmpeg/libavformat/voc.c index 7ebfa711c9..eed8db8cc7 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/voc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/voc.c @@ -32,5 +32,5 @@ const AVCodecTag ff_voc_codec_tags[] = { {CODEC_ID_PCM_ALAW, 0x06}, {CODEC_ID_PCM_MULAW, 0x07}, {CODEC_ID_ADPCM_CT, 0x0200}, - {0, 0}, + {CODEC_ID_NONE, 0}, }; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/voc.h b/src/add-ons/media/plugins/ffmpeg/libavformat/voc.h index 7993146f47..3f995ad31f 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/voc.h +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/voc.h @@ -26,7 +26,7 @@ #include "riff.h" /* for CodecTag */ typedef struct voc_dec_context { - int remaining_size; + int64_t remaining_size; } VocDecContext; typedef enum voc_type { diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/vocdec.c b/src/add-ons/media/plugins/ffmpeg/libavformat/vocdec.c index 94fbd7b9bf..13d48f7397 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/vocdec.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/vocdec.c @@ -54,7 +54,7 @@ static int voc_read_header(AVFormatContext *s, AVFormatParameters *ap) st = av_new_stream(s, 0); if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; voc->remaining_size = 0; return 0; @@ -76,6 +76,11 @@ voc_get_packet(AVFormatContext *s, AVPacket *pkt, AVStream *st, int max_size) if (type == VOC_TYPE_EOF) return AVERROR(EIO); voc->remaining_size = get_le24(pb); + if (!voc->remaining_size) { + if (url_is_streamed(s->pb)) + return AVERROR(EIO); + voc->remaining_size = url_fsize(pb) - url_ftell(pb); + } max_size -= 4; switch (type) { diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/vocenc.c b/src/add-ons/media/plugins/ffmpeg/libavformat/vocenc.c index 744b2337a0..f127c7e826 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/vocenc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/vocenc.c @@ -33,7 +33,7 @@ static int voc_write_header(AVFormatContext *s) const int version = 0x0114; if (s->nb_streams != 1 - || s->streams[0]->codec->codec_type != CODEC_TYPE_AUDIO) + || s->streams[0]->codec->codec_type != AVMEDIA_TYPE_AUDIO) return AVERROR_PATCHWELCOME; put_buffer(pb, ff_voc_magic, sizeof(ff_voc_magic) - 1); diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/vorbiscomment.c b/src/add-ons/media/plugins/ffmpeg/libavformat/vorbiscomment.c new file mode 100644 index 0000000000..d23c66d7f0 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/vorbiscomment.c @@ -0,0 +1,73 @@ +/* + * VorbisComment writer + * Copyright (c) 2009 James Darnley + * + * 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 "metadata.h" +#include "vorbiscomment.h" +#include "libavcodec/bytestream.h" + +/** + * VorbisComment metadata conversion mapping. + * from Ogg Vorbis I format specification: comment field and header specification + * http://xiph.org/vorbis/doc/v-comment.html + */ +const AVMetadataConv ff_vorbiscomment_metadata_conv[] = { + { "ALBUMARTIST", "album_artist"}, + { "TRACKNUMBER", "track" }, + { 0 } +}; + +int ff_vorbiscomment_length(AVMetadata *m, const char *vendor_string, + unsigned *count) +{ + int len = 8; + len += strlen(vendor_string); + *count = 0; + if (m) { + AVMetadataTag *tag = NULL; + while ( (tag = av_metadata_get(m, "", tag, AV_METADATA_IGNORE_SUFFIX) ) ) { + len += 4 +strlen(tag->key) + 1 + strlen(tag->value); + (*count)++; + } + } + return len; +} + +int ff_vorbiscomment_write(uint8_t **p, AVMetadata *m, + const char *vendor_string, const unsigned count) +{ + bytestream_put_le32(p, strlen(vendor_string)); + bytestream_put_buffer(p, vendor_string, strlen(vendor_string)); + if (m) { + AVMetadataTag *tag = NULL; + bytestream_put_le32(p, count); + while ( (tag = av_metadata_get(m, "", tag, AV_METADATA_IGNORE_SUFFIX) ) ) { + unsigned int len1 = strlen(tag->key); + unsigned int len2 = strlen(tag->value); + bytestream_put_le32(p, len1+1+len2); + bytestream_put_buffer(p, tag->key, len1); + bytestream_put_byte(p, '='); + bytestream_put_buffer(p, tag->value, len2); + } + } else + bytestream_put_le32(p, 0); + return 0; +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/vorbiscomment.h b/src/add-ons/media/plugins/ffmpeg/libavformat/vorbiscomment.h new file mode 100644 index 0000000000..714f1f2b96 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/vorbiscomment.h @@ -0,0 +1,57 @@ +/* + * VorbisComment writer + * Copyright (c) 2009 James Darnley + * + * 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_VORBISCOMMENT_H +#define AVFORMAT_VORBISCOMMENT_H + +#include "avformat.h" +#include "metadata.h" + +/** + * Calculates the length in bytes of a VorbisComment. This is the minimum + * size required by ff_vorbiscomment_write(). + * + * @param m The metadata structure to be parsed. For no metadata, set to NULL. + * @param vendor_string The vendor string to be added into the VorbisComment. + * For no string, set to an empty string. + * @param count Pointer to store the number of tags in m because m->count is "not allowed" + * @return The length in bytes. + */ +int ff_vorbiscomment_length(AVMetadata *m, const char *vendor_string, + unsigned *count); + +/** + * Writes a VorbisComment into a buffer. The buffer, p, must have enough + * data to hold the whole VorbisComment. The minimum size required can be + * obtained by passing the same AVMetadata and vendor_string to + * ff_vorbiscomment_length() + * + * @param p The buffer in which to write. + * @param m The metadata struct to write. + * @param vendor_string The vendor string to write. + * @param count The number of tags in m because m->count is "not allowed" + */ +int ff_vorbiscomment_write(uint8_t **p, AVMetadata *m, + const char *vendor_string, const unsigned count); + +extern const AVMetadataConv ff_vorbiscomment_metadata_conv[]; + +#endif /* AVFORMAT_VORBISCOMMENT_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/vqf.c b/src/add-ons/media/plugins/ffmpeg/libavformat/vqf.c index d2b48dda04..b0ec020511 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/vqf.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/vqf.c @@ -45,15 +45,18 @@ static int vqf_probe(AVProbeData *probe_packet) static void add_metadata(AVFormatContext *s, const char *tag, unsigned int tag_len, unsigned int remaining) { - char buf[2048]; - int len = FFMIN3(tag_len, remaining, sizeof(buf) - 1); + int len = FFMIN(tag_len, remaining); + char *buf; - if (len != tag_len) - av_log(s, AV_LOG_ERROR, "Warning: truncating metadata!\n"); + if (len == UINT_MAX) + return; + buf = av_malloc(len+1); + if (!buf) + return; get_buffer(s->pb, buf, len); buf[len] = 0; - av_metadata_set(&s->metadata, tag, buf); + av_metadata_set2(&s->metadata, tag, buf, AV_METADATA_DONT_STRDUP_VAL); } static int vqf_read_header(AVFormatContext *s, AVFormatParameters *ap) @@ -73,7 +76,7 @@ static int vqf_read_header(AVFormatContext *s, AVFormatParameters *ap) header_size = get_be32(s->pb); - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_TWINVQ; st->start_time = 0; @@ -186,6 +189,7 @@ static int vqf_read_header(AVFormatContext *s, AVFormatParameters *ap) return -1; } c->frame_bit_len = st->codec->bit_rate*size/st->codec->sample_rate; + av_set_pts_info(st, 64, 1, st->codec->sample_rate); return 0; } diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/wav.c b/src/add-ons/media/plugins/ffmpeg/libavformat/wav.c index fc470eb7da..da08558c78 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/wav.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/wav.c @@ -3,6 +3,7 @@ * Copyright (c) 2001, 2002 Fabrice Bellard * * Sony Wave64 demuxer + * RF64 demuxer * Copyright (c) 2009 Daniel Verkamp * * This file is part of FFmpeg. @@ -119,8 +120,24 @@ static int wav_write_trailer(AVFormatContext *s) } return 0; } + +AVOutputFormat 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, + .codec_tag= (const AVCodecTag* const []){ff_codec_wav_tags, 0}, +}; #endif /* CONFIG_WAV_MUXER */ + +#if CONFIG_WAV_DEMUXER /* return the size of the found tag */ static int64_t find_tag(ByteIOContext *pb, uint32_t tag1) { @@ -144,25 +161,27 @@ static int wav_probe(AVProbeData *p) /* check file header */ if (p->buf_size <= 32) return 0; - if (p->buf[ 0] == 'R' && p->buf[ 1] == 'I' && - p->buf[ 2] == 'F' && p->buf[ 3] == 'F' && - p->buf[ 8] == 'W' && p->buf[ 9] == 'A' && - p->buf[10] == 'V' && p->buf[11] == 'E') - /* - Since ACT demuxer has standard WAV header at top of it's own, - returning score is decreased to avoid probe conflict - between ACT and WAV. - */ - return AVPROBE_SCORE_MAX - 1; - else - return 0; + if (!memcmp(p->buf + 8, "WAVE", 4)) { + if (!memcmp(p->buf, "RIFF", 4)) + /* + Since ACT demuxer has standard WAV header at top of it's own, + returning score is decreased to avoid probe conflict + between ACT and WAV. + */ + return AVPROBE_SCORE_MAX - 1; + else if (!memcmp(p->buf, "RF64", 4) && + !memcmp(p->buf + 12, "ds64", 4)) + return AVPROBE_SCORE_MAX; + } + return 0; } /* wav input */ static int wav_read_header(AVFormatContext *s, AVFormatParameters *ap) { - int64_t size; + int64_t size, av_uninit(data_size); + int rf64; unsigned int tag; ByteIOContext *pb = s->pb; AVStream *st; @@ -171,13 +190,25 @@ static int wav_read_header(AVFormatContext *s, /* check RIFF header */ tag = get_le32(pb); - if (tag != MKTAG('R', 'I', 'F', 'F')) + rf64 = tag == MKTAG('R', 'F', '6', '4'); + if (!rf64 && tag != MKTAG('R', 'I', 'F', 'F')) return -1; get_le32(pb); /* file size */ tag = get_le32(pb); if (tag != MKTAG('W', 'A', 'V', 'E')) return -1; + if (rf64) { + if (get_le32(pb) != MKTAG('d', 's', '6', '4')) + return -1; + size = get_le32(pb); + if (size < 16) + return -1; + get_le64(pb); /* RIFF size */ + data_size = get_le64(pb); + url_fskip(pb, size - 16); /* skip rest of ds64 chunk */ + } + /* parse fmt header */ size = find_tag(pb, MKTAG('f', 'm', 't', ' ')); if (size < 0) @@ -192,37 +223,17 @@ static int wav_read_header(AVFormatContext *s, av_set_pts_info(st, 64, 1, st->codec->sample_rate); size = find_tag(pb, MKTAG('d', 'a', 't', 'a')); + if (rf64) + size = data_size; if (size < 0) return -1; - wav->data_end= url_ftell(pb) + size; + if (!size) { + wav->data_end = INT64_MAX; + } else + wav->data_end= url_ftell(pb) + size; return 0; } -#if CONFIG_W64_DEMUXER - -static const uint8_t guid_riff[16] = { 'r', 'i', 'f', 'f', - 0x2E, 0x91, 0xCF, 0x11, 0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00 }; - -static const uint8_t guid_wave[16] = { 'w', 'a', 'v', 'e', - 0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A }; - -static const uint8_t guid_fmt [16] = { 'f', 'm', 't', ' ', - 0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A }; - -static const uint8_t guid_data[16] = { 'd', 'a', 't', 'a', - 0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A }; - -static int w64_probe(AVProbeData *p) -{ - if (p->buf_size <= 40) - return 0; - if (!memcmp(p->buf, guid_riff, 16) && - !memcmp(p->buf + 24, guid_wave, 16)) - return AVPROBE_SCORE_MAX; - else - return 0; -} - /** Find chunk with w64 GUID by skipping over other chunks * @return the size of the found chunk */ @@ -243,6 +254,102 @@ static int64_t find_guid(ByteIOContext *pb, const uint8_t guid1[16]) return -1; } +static const uint8_t guid_data[16] = { 'd', 'a', 't', 'a', + 0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A }; + +#define MAX_SIZE 4096 + +static int wav_read_packet(AVFormatContext *s, + AVPacket *pkt) +{ + int ret, size; + int64_t left; + AVStream *st; + WAVContext *wav = s->priv_data; + + st = s->streams[0]; + + left = wav->data_end - url_ftell(s->pb); + if (left <= 0){ + if (CONFIG_W64_DEMUXER && wav->w64) + left = find_guid(s->pb, guid_data) - 24; + else + left = find_tag(s->pb, MKTAG('d', 'a', 't', 'a')); + if (left < 0) + return AVERROR_EOF; + wav->data_end= url_ftell(s->pb) + left; + } + + size = MAX_SIZE; + if (st->codec->block_align > 1) { + if (size < st->codec->block_align) + size = st->codec->block_align; + size = (size / st->codec->block_align) * st->codec->block_align; + } + size = FFMIN(size, left); + ret = av_get_packet(s->pb, pkt, size); + if (ret < 0) + return ret; + pkt->stream_index = 0; + + return ret; +} + +static int wav_read_seek(AVFormatContext *s, + int stream_index, int64_t timestamp, int flags) +{ + AVStream *st; + + st = s->streams[0]; + switch (st->codec->codec_id) { + case CODEC_ID_MP2: + case CODEC_ID_MP3: + case CODEC_ID_AC3: + case CODEC_ID_DTS: + /* use generic seeking with dynamically generated indexes */ + return -1; + default: + break; + } + return pcm_read_seek(s, stream_index, timestamp, flags); +} + +AVInputFormat wav_demuxer = { + "wav", + NULL_IF_CONFIG_SMALL("WAV format"), + sizeof(WAVContext), + wav_probe, + wav_read_header, + wav_read_packet, + NULL, + wav_read_seek, + .flags= AVFMT_GENERIC_INDEX, + .codec_tag= (const AVCodecTag* const []){ff_codec_wav_tags, 0}, +}; +#endif /* CONFIG_WAV_DEMUXER */ + + +#if CONFIG_W64_DEMUXER +static const uint8_t guid_riff[16] = { 'r', 'i', 'f', 'f', + 0x2E, 0x91, 0xCF, 0x11, 0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00 }; + +static const uint8_t guid_wave[16] = { 'w', 'a', 'v', 'e', + 0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A }; + +static const uint8_t guid_fmt [16] = { 'f', 'm', 't', ' ', + 0xF3, 0xAC, 0xD3, 0x11, 0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A }; + +static int w64_probe(AVProbeData *p) +{ + if (p->buf_size <= 40) + return 0; + if (!memcmp(p->buf, guid_riff, 16) && + !memcmp(p->buf + 24, guid_wave, 16)) + return AVPROBE_SCORE_MAX; + else + return 0; +} + static int w64_read_header(AVFormatContext *s, AVFormatParameters *ap) { int64_t size; @@ -292,102 +399,7 @@ static int w64_read_header(AVFormatContext *s, AVFormatParameters *ap) return 0; } -#endif /* CONFIG_W64_DEMUXER */ -#define MAX_SIZE 4096 - -static int wav_read_packet(AVFormatContext *s, - AVPacket *pkt) -{ - int ret, size; - int64_t left; - AVStream *st; - WAVContext *wav = s->priv_data; - - if (url_feof(s->pb)) - return AVERROR(EIO); - st = s->streams[0]; - - left = wav->data_end - url_ftell(s->pb); - if (left <= 0){ - if (CONFIG_W64_DEMUXER && wav->w64) - left = find_guid(s->pb, guid_data) - 24; - else - left = find_tag(s->pb, MKTAG('d', 'a', 't', 'a')); - if (left < 0) - return AVERROR(EIO); - wav->data_end= url_ftell(s->pb) + left; - } - - size = MAX_SIZE; - if (st->codec->block_align > 1) { - if (size < st->codec->block_align) - size = st->codec->block_align; - size = (size / st->codec->block_align) * st->codec->block_align; - } - size = FFMIN(size, left); - ret = av_get_packet(s->pb, pkt, size); - if (ret <= 0) - return AVERROR(EIO); - pkt->stream_index = 0; - - /* note: we need to modify the packet size here to handle the last - packet */ - pkt->size = ret; - return ret; -} - -static int wav_read_seek(AVFormatContext *s, - int stream_index, int64_t timestamp, int flags) -{ - AVStream *st; - - st = s->streams[0]; - switch (st->codec->codec_id) { - case CODEC_ID_MP2: - case CODEC_ID_MP3: - case CODEC_ID_AC3: - case CODEC_ID_DTS: - /* use generic seeking with dynamically generated indexes */ - return -1; - default: - break; - } - return pcm_read_seek(s, stream_index, timestamp, flags); -} - -#if CONFIG_WAV_DEMUXER -AVInputFormat wav_demuxer = { - "wav", - NULL_IF_CONFIG_SMALL("WAV format"), - sizeof(WAVContext), - wav_probe, - wav_read_header, - wav_read_packet, - NULL, - wav_read_seek, - .flags= AVFMT_GENERIC_INDEX, - .codec_tag= (const AVCodecTag* const []){ff_codec_wav_tags, 0}, -}; -#endif - -#if CONFIG_WAV_MUXER -AVOutputFormat 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, - .codec_tag= (const AVCodecTag* const []){ff_codec_wav_tags, 0}, -}; -#endif - -#if CONFIG_W64_DEMUXER AVInputFormat w64_demuxer = { "w64", NULL_IF_CONFIG_SMALL("Sony Wave64 format"), @@ -400,4 +412,4 @@ AVInputFormat w64_demuxer = { .flags = AVFMT_GENERIC_INDEX, .codec_tag = (const AVCodecTag* const []){ff_codec_wav_tags, 0}, }; -#endif +#endif /* CONFIG_W64_DEMUXER */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/wc3movie.c b/src/add-ons/media/plugins/ffmpeg/libavformat/wc3movie.c index 5369057dd4..d5f0863e71 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/wc3movie.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/wc3movie.c @@ -20,7 +20,7 @@ */ /** - * @file libavformat/wc3movie.c + * @file * Wing Commander III Movie file demuxer * by Mike Melanson (melanson@pcisys.net) * for more information on the WC3 .mve file format, visit: @@ -140,10 +140,9 @@ static int wc3_read_header(AVFormatContext *s, unsigned int fourcc_tag; unsigned int size; AVStream *st; - char buffer[513]; int ret = 0; int current_palette = 0; - int bytes_to_read; + char *buffer; int i; unsigned char rotate; @@ -185,14 +184,14 @@ static int wc3_read_header(AVFormatContext *s, case BNAM_TAG: /* load up the name */ - if ((unsigned)size < 512) - bytes_to_read = size; - else - bytes_to_read = 512; - if ((ret = get_buffer(pb, buffer, bytes_to_read)) != bytes_to_read) + buffer = av_malloc(size+1); + if (!buffer) + return AVERROR(ENOMEM); + if ((ret = get_buffer(pb, buffer, size)) != size) return AVERROR(EIO); - buffer[bytes_to_read] = 0; - av_metadata_set(&s->metadata, "title", buffer); + buffer[size] = 0; + av_metadata_set2(&s->metadata, "title", buffer, + AV_METADATA_DONT_STRDUP_VAL); break; case SIZE_TAG: @@ -244,7 +243,7 @@ static int wc3_read_header(AVFormatContext *s, return AVERROR(ENOMEM); av_set_pts_info(st, 33, 1, WC3_FRAME_FPS); wc3->video_stream_index = st->index; - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_XAN_WC3; st->codec->codec_tag = 0; /* no fourcc */ st->codec->width = wc3->width; @@ -258,7 +257,7 @@ static int wc3_read_header(AVFormatContext *s, return AVERROR(ENOMEM); av_set_pts_info(st, 33, 1, WC3_FRAME_FPS); wc3->audio_stream_index = st->index; - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_PCM_S16LE; st->codec->codec_tag = 1; st->codec->channels = WC3_AUDIO_CHANNELS; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/westwood.c b/src/add-ons/media/plugins/ffmpeg/libavformat/westwood.c index 7b016fdeda..10d5798035 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/westwood.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/westwood.c @@ -20,7 +20,7 @@ */ /** - * @file libavformat/westwood.c + * @file * Westwood Studios VQA & AUD file demuxers * by Mike Melanson (melanson@pcisys.net) * for more information on the Westwood file formats, visit: @@ -148,7 +148,7 @@ static int wsaud_read_header(AVFormatContext *s, if (!st) return AVERROR(ENOMEM); av_set_pts_info(st, 33, 1, wsaud->audio_samplerate); - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = wsaud->audio_type; st->codec->codec_tag = 0; /* no tag */ st->codec->channels = wsaud->audio_channels; @@ -226,7 +226,7 @@ static int wsvqa_read_header(AVFormatContext *s, return AVERROR(ENOMEM); av_set_pts_info(st, 33, 1, VQA_FRAMERATE); wsvqa->video_stream_index = st->index; - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_WS_VQA; st->codec->codec_tag = 0; /* no fourcc */ @@ -251,7 +251,7 @@ static int wsvqa_read_header(AVFormatContext *s, if (!st) return AVERROR(ENOMEM); av_set_pts_info(st, 33, 1, VQA_FRAMERATE); - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; if (AV_RL16(&header[0]) == 1) st->codec->codec_id = CODEC_ID_WESTWOOD_SND1; else diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/wv.c b/src/add-ons/media/plugins/ffmpeg/libavformat/wv.c index d46f90d78b..03b864bdaf 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/wv.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/wv.c @@ -21,6 +21,8 @@ #include "libavutil/intreadwrite.h" #include "avformat.h" +#include "apetag.h" +#include "id3v1.h" // specs say that maximum block size is 1Mb #define WV_BLOCK_LIMIT 1047576 @@ -99,9 +101,31 @@ static int wv_read_block_header(AVFormatContext *ctx, ByteIOContext *pb) bpp = ((wc->flags & 3) + 1) << 3; chan = 1 + !(wc->flags & WV_MONO); rate = wv_rates[(wc->flags >> 23) & 0xF]; - if(rate == -1){ - av_log(ctx, AV_LOG_ERROR, "Unknown sampling rate\n"); - return -1; + if(rate == -1 && !wc->block_parsed){ + int64_t block_end = url_ftell(pb) + wc->blksize - 24; + if(url_is_streamed(pb)){ + av_log(ctx, AV_LOG_ERROR, "Cannot determine custom sampling rate\n"); + return -1; + } + while(url_ftell(pb) < block_end){ + int id, size; + id = get_byte(pb); + size = (id & 0x80) ? get_le24(pb) : get_byte(pb); + size <<= 1; + if(id&0x40) + size--; + if((id&0x3F) == 0x27){ + rate = get_le24(pb); + break; + }else{ + url_fskip(pb, size); + } + } + if(rate == -1){ + av_log(ctx, AV_LOG_ERROR, "Cannot determine custom sampling rate\n"); + return -1; + } + url_fseek(pb, block_end - wc->blksize + 24, SEEK_SET); } if(!wc->bpp) wc->bpp = bpp; if(!wc->chan) wc->chan = chan; @@ -115,7 +139,7 @@ static int wv_read_block_header(AVFormatContext *ctx, ByteIOContext *pb) av_log(ctx, AV_LOG_ERROR, "Channels differ, this block: %i, header block: %i\n", chan, wc->chan); return -1; } - if(wc->flags && rate != wc->rate){ + if(wc->flags && rate != -1 && rate != wc->rate){ av_log(ctx, AV_LOG_ERROR, "Sampling rate differ, this block: %i, header block: %i\n", rate, wc->rate); return -1; } @@ -130,22 +154,31 @@ static int wv_read_header(AVFormatContext *s, WVContext *wc = s->priv_data; AVStream *st; + wc->block_parsed = 0; if(wv_read_block_header(s, pb) < 0) return -1; - wc->block_parsed = 0; /* now we are ready: build format streams */ st = av_new_stream(s, 0); if (!st) return -1; - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_WAVPACK; st->codec->channels = wc->chan; st->codec->sample_rate = wc->rate; st->codec->bits_per_coded_sample = wc->bpp; av_set_pts_info(st, 64, 1, wc->rate); - s->start_time = 0; - s->duration = (int64_t)wc->samples * AV_TIME_BASE / st->codec->sample_rate; + st->start_time = 0; + st->duration = wc->samples; + + if(!url_is_streamed(s->pb)) { + int64_t cur = url_ftell(s->pb); + ff_ape_parse_tag(s); + if(!av_metadata_get(s->metadata, "", NULL, AV_METADATA_IGNORE_SUFFIX)) + ff_id3v1_read(s); + url_fseek(s->pb, cur, SEEK_SET); + } + return 0; } diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/xa.c b/src/add-ons/media/plugins/ffmpeg/libavformat/xa.c index 2f547106ea..3a866b992f 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/xa.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/xa.c @@ -20,7 +20,7 @@ */ /** - * @file libavformat/xa.c + * @file * Maxis XA File Demuxer * by Robert Marston (rmarston@gmail.com) * for more information on the XA audio format see @@ -42,13 +42,24 @@ typedef struct MaxisXADemuxContext { static int xa_probe(AVProbeData *p) { + int channels, srate, bits_per_sample; + if (p->buf_size < 24) + return 0; switch(AV_RL32(p->buf)) { case XA00_TAG: case XAI0_TAG: case XAJ0_TAG: - return AVPROBE_SCORE_MAX; + break; + default: + return 0; } - return 0; + channels = AV_RL16(p->buf + 10); + srate = AV_RL32(p->buf + 12); + bits_per_sample = AV_RL16(p->buf + 22); + if (!channels || channels > 8 || !srate || srate > 192000 || + bits_per_sample < 4 || bits_per_sample > 32) + return 0; + return AVPROBE_SCORE_MAX/2; } static int xa_read_header(AVFormatContext *s, @@ -63,7 +74,7 @@ static int xa_read_header(AVFormatContext *s, if (!st) return AVERROR(ENOMEM); - st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_ADPCM_EA_MAXIS_XA; url_fskip(pb, 4); /* Skip the XA ID */ xa->out_size = get_le32(pb); @@ -95,8 +106,8 @@ static int xa_read_packet(AVFormatContext *s, packet_size = 15*st->codec->channels; ret = av_get_packet(pb, pkt, packet_size); - if(ret != packet_size) - return AVERROR(EIO); + if(ret < 0) + return ret; pkt->stream_index = st->index; xa->sent_bytes += packet_size; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/yop.c b/src/add-ons/media/plugins/ffmpeg/libavformat/yop.c new file mode 100644 index 0000000000..54d38454a1 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/yop.c @@ -0,0 +1,216 @@ +/** + * @file + * Psygnosis YOP demuxer + * + * Copyright (C) 2010 Mohamed Naufal Basheer + * derived from the code by + * Copyright (C) 2009 Thomas P. Higdon + * + * 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 yop_dec_context { + AVPacket video_packet; + + int odd_frame; + int frame_size; + int audio_block_length; + int palette_size; +} YopDecContext; + +static int yop_probe(AVProbeData *probe_packet) +{ + if (AV_RB16(probe_packet->buf) == AV_RB16("YO") && + probe_packet->buf[6] && + probe_packet->buf[7] && + !(probe_packet->buf[8] & 1) && + !(probe_packet->buf[10] & 1)) + return AVPROBE_SCORE_MAX * 3 / 4; + + return 0; +} + +static int yop_read_header(AVFormatContext *s, AVFormatParameters *ap) +{ + YopDecContext *yop = s->priv_data; + ByteIOContext *pb = s->pb; + + AVCodecContext *audio_dec, *video_dec; + AVStream *audio_stream, *video_stream; + + int frame_rate, ret; + + audio_stream = av_new_stream(s, 0); + video_stream = av_new_stream(s, 1); + + // Extra data that will be passed to the decoder + video_stream->codec->extradata_size = 8; + + video_stream->codec->extradata = av_mallocz(video_stream->codec->extradata_size + + FF_INPUT_BUFFER_PADDING_SIZE); + + if (!video_stream->codec->extradata) + return AVERROR(ENOMEM); + + // Audio + audio_dec = audio_stream->codec; + audio_dec->codec_type = AVMEDIA_TYPE_AUDIO; + audio_dec->codec_id = CODEC_ID_ADPCM_IMA_WS; + audio_dec->channels = 1; + audio_dec->sample_rate = 22050; + + // Video + video_dec = video_stream->codec; + video_dec->codec_type = AVMEDIA_TYPE_VIDEO; + video_dec->codec_id = CODEC_ID_YOP; + + url_fskip(pb, 6); + + frame_rate = get_byte(pb); + yop->frame_size = get_byte(pb) * 2048; + video_dec->width = get_le16(pb); + video_dec->height = get_le16(pb); + + video_stream->sample_aspect_ratio = (AVRational){1, 2}; + + ret = get_buffer(pb, video_dec->extradata, 8); + if (ret < 8) + return ret < 0 ? ret : AVERROR_EOF; + + yop->palette_size = video_dec->extradata[0] * 3 + 4; + yop->audio_block_length = AV_RL16(video_dec->extradata + 6); + + // 1840 samples per frame, 1 nibble per sample; hence 1840/2 = 920 + if (yop->audio_block_length < 920 || + yop->audio_block_length + yop->palette_size >= yop->frame_size) { + av_log(s, AV_LOG_ERROR, "YOP has invalid header\n"); + return AVERROR_INVALIDDATA; + } + + url_fseek(pb, 2048, SEEK_SET); + + av_set_pts_info(video_stream, 32, 1, frame_rate); + + return 0; +} + +static int yop_read_packet(AVFormatContext *s, AVPacket *pkt) +{ + YopDecContext *yop = s->priv_data; + ByteIOContext *pb = s->pb; + + int ret; + int actual_video_data_size = yop->frame_size - + yop->audio_block_length - yop->palette_size; + + yop->video_packet.stream_index = 1; + + if (yop->video_packet.data) { + *pkt = yop->video_packet; + yop->video_packet.data = NULL; + yop->video_packet.size = 0; + pkt->data[0] = yop->odd_frame; + pkt->flags |= AV_PKT_FLAG_KEY; + yop->odd_frame ^= 1; + return pkt->size; + } + ret = av_new_packet(&yop->video_packet, + yop->frame_size - yop->audio_block_length); + if (ret < 0) + return ret; + + yop->video_packet.pos = url_ftell(pb); + + ret = get_buffer(pb, yop->video_packet.data, yop->palette_size); + if (ret < 0) { + goto err_out; + }else if (ret < yop->palette_size) { + ret = AVERROR_EOF; + goto err_out; + } + + ret = av_get_packet(pb, pkt, 920); + if (ret < 0) + goto err_out; + + // Set position to the start of the frame + pkt->pos = yop->video_packet.pos; + + url_fskip(pb, yop->audio_block_length - ret); + + ret = get_buffer(pb, yop->video_packet.data + yop->palette_size, + actual_video_data_size); + if (ret < 0) + goto err_out; + else if (ret < actual_video_data_size) + av_shrink_packet(&yop->video_packet, yop->palette_size + ret); + + // Arbitrarily return the audio data first + return yop->audio_block_length; + +err_out: + av_free_packet(&yop->video_packet); + return ret; +} + +static int yop_read_close(AVFormatContext *s) +{ + YopDecContext *yop = s->priv_data; + av_free_packet(&yop->video_packet); + return 0; +} + +static int yop_read_seek(AVFormatContext *s, int stream_index, + int64_t timestamp, int flags) +{ + YopDecContext *yop = s->priv_data; + int64_t frame_pos, pos_min, pos_max; + int frame_count; + + av_free_packet(&yop->video_packet); + + if (!stream_index) + return -1; + + pos_min = s->data_offset; + pos_max = url_fsize(s->pb) - yop->frame_size; + frame_count = (pos_max - pos_min) / yop->frame_size; + + timestamp = FFMAX(0, FFMIN(frame_count, timestamp)); + + frame_pos = timestamp * yop->frame_size + pos_min; + yop->odd_frame = timestamp & 1; + + url_fseek(s->pb, frame_pos, SEEK_SET); + return 0; +} + +AVInputFormat 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, + .extensions = "yop", + .flags = AVFMT_GENERIC_INDEX, +}; diff --git a/src/add-ons/media/plugins/ffmpeg/libavformat/yuv4mpeg.c b/src/add-ons/media/plugins/ffmpeg/libavformat/yuv4mpeg.c index 8e7acebe71..99a1ce2f38 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavformat/yuv4mpeg.c +++ b/src/add-ons/media/plugins/ffmpeg/libavformat/yuv4mpeg.c @@ -335,7 +335,7 @@ static int yuv4_read_header(AVFormatContext *s, AVFormatParameters *ap) av_reduce(&raten, &rated, raten, rated, (1UL<<31)-1); av_set_pts_info(st, 64, rated, raten); st->codec->pix_fmt = pix_fmt; - st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_RAWVIDEO; st->sample_aspect_ratio= (AVRational){aspectn, aspectd}; st->codec->chroma_sample_location = chroma_sample_location; diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/Jamfile b/src/add-ons/media/plugins/ffmpeg/libavutil/Jamfile index 93e79802c9..606fafc164 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/Jamfile +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/Jamfile @@ -22,6 +22,7 @@ StaticLibrary libavutil.a : base64.c crc.c des.c + error.c fifo.c integer.c intfloat_readwrite.c @@ -33,6 +34,7 @@ StaticLibrary libavutil.a : md5.c mem.c pca.c + pixdesc.c random_seed.c rational.c rc4.c diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/adler32.c b/src/add-ons/media/plugins/ffmpeg/libavutil/adler32.c index de793160a0..4f2001025b 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/adler32.c +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/adler32.c @@ -21,7 +21,7 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include "common.h" +#include "config.h" #include "adler32.h" #define BASE 65521L /* largest prime smaller than 65536 */ @@ -53,6 +53,7 @@ unsigned long av_adler32_update(unsigned long adler, const uint8_t *buf, unsigne #ifdef TEST #include "log.h" +#include "timer.h" #define LEN 7001 volatile int checksum; int main(void){ diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/adler32.h b/src/add-ons/media/plugins/ffmpeg/libavutil/adler32.h index 34f2b53e7d..9626c80567 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/adler32.h +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/adler32.h @@ -22,7 +22,7 @@ #define AVUTIL_ADLER32_H #include -#include "common.h" +#include "attributes.h" unsigned long av_adler32_update(unsigned long adler, const uint8_t *buf, unsigned int len) av_pure; diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/attributes.h b/src/add-ons/media/plugins/ffmpeg/libavutil/attributes.h new file mode 100644 index 0000000000..da45234c6a --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/attributes.h @@ -0,0 +1,113 @@ +/* + * copyright (c) 2006 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 + */ + +/** + * @file + * Macro definitions for various function/variable attributes + */ + +#ifndef AVUTIL_ATTRIBUTES_H +#define AVUTIL_ATTRIBUTES_H + +#ifdef __GNUC__ +# define AV_GCC_VERSION_AT_LEAST(x,y) (__GNUC__ > x || __GNUC__ == x && __GNUC_MINOR__ >= y) +#else +# define AV_GCC_VERSION_AT_LEAST(x,y) 0 +#endif + +#ifndef av_always_inline +#if AV_GCC_VERSION_AT_LEAST(3,1) +# define av_always_inline __attribute__((always_inline)) inline +#else +# define av_always_inline inline +#endif +#endif + +#ifndef av_noinline +#if AV_GCC_VERSION_AT_LEAST(3,1) +# define av_noinline __attribute__((noinline)) +#else +# define av_noinline +#endif +#endif + +#ifndef av_pure +#if AV_GCC_VERSION_AT_LEAST(3,1) +# define av_pure __attribute__((pure)) +#else +# define av_pure +#endif +#endif + +#ifndef av_const +#if AV_GCC_VERSION_AT_LEAST(2,6) +# define av_const __attribute__((const)) +#else +# define av_const +#endif +#endif + +#ifndef av_cold +#if (!defined(__ICC) || __ICC > 1110) && AV_GCC_VERSION_AT_LEAST(4,3) +# define av_cold __attribute__((cold)) +#else +# define av_cold +#endif +#endif + +#ifndef av_flatten +#if (!defined(__ICC) || __ICC > 1110) && AV_GCC_VERSION_AT_LEAST(4,1) +# define av_flatten __attribute__((flatten)) +#else +# define av_flatten +#endif +#endif + +#ifndef attribute_deprecated +#if AV_GCC_VERSION_AT_LEAST(3,1) +# define attribute_deprecated __attribute__((deprecated)) +#else +# define attribute_deprecated +#endif +#endif + +#ifndef av_unused +#if defined(__GNUC__) +# define av_unused __attribute__((unused)) +#else +# define av_unused +#endif +#endif + +#ifndef av_uninit +#if defined(__GNUC__) && !defined(__ICC) +# define av_uninit(x) x=x +#else +# define av_uninit(x) x +#endif +#endif + +#ifdef __GNUC__ +# define av_builtin_constant_p __builtin_constant_p +#else +# define av_builtin_constant_p(x) 0 +#endif + +#endif /* AVUTIL_ATTRIBUTES_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/avconfig.h b/src/add-ons/media/plugins/ffmpeg/libavutil/avconfig.h new file mode 100644 index 0000000000..3b3afec51f --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/avconfig.h @@ -0,0 +1,9 @@ +#ifndef AVUTIL_AVCONFIG_H +#define AVUTIL_AVCONFIG_H +#include +#ifdef __PPC__ +# define AV_HAVE_BIGENDIAN 1 +#else +# define AV_HAVE_BIGENDIAN 0 +#endif +#endif /* AVUTIL_AVCONFIG_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/avstring.c b/src/add-ons/media/plugins/ffmpeg/libavutil/avstring.c index 8ee2a6b12f..4844e28db2 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/avstring.c +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/avstring.c @@ -24,6 +24,7 @@ #include #include #include "avstring.h" +#include "mem.h" int av_strstart(const char *str, const char *pfx, const char **ptr) { @@ -47,6 +48,19 @@ int av_stristart(const char *str, const char *pfx, const char **ptr) return !*pfx; } +char *av_stristr(const char *s1, const char *s2) +{ + if (!*s2) + return s1; + + do { + if (av_stristart(s1, s2, NULL)) + return s1; + } while (*s1++); + + return NULL; +} + size_t av_strlcpy(char *dst, const char *src, size_t size) { size_t len = 0; @@ -76,3 +90,10 @@ size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...) return len; } + +char *av_d2str(double d) +{ + char *str= av_malloc(16); + if(str) snprintf(str, 16, "%f", d); + return str; +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/avstring.h b/src/add-ons/media/plugins/ffmpeg/libavutil/avstring.h index 97c2f38715..01c2391b5f 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/avstring.h +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/avstring.h @@ -46,6 +46,20 @@ int av_strstart(const char *str, const char *pfx, const char **ptr); */ int av_stristart(const char *str, const char *pfx, const char **ptr); +/** + * Locate the first case-independent occurrence in the string haystack + * of the string needle. A zero-length string needle is considered to + * match at the start of haystack. + * + * This function is a case-insensitive version of the standard strstr(). + * + * @param haystack string to search in + * @param needle string to search for + * @return pointer to the located match within haystack + * or a null pointer if no match + */ +char *av_stristr(const char *haystack, const char *needle); + /** * Copy the string src to dst, but no more than size - 1 bytes, and * null-terminate dst. @@ -56,6 +70,10 @@ int av_stristart(const char *str, const char *pfx, const char **ptr); * @param src source string * @param size size of destination buffer * @return the length of src + * + * WARNING: since the return value is the length of src, src absolutely + * _must_ be a properly 0-terminated string, otherwise this will read beyond + * the end of the buffer and possibly crash. */ size_t av_strlcpy(char *dst, const char *src, size_t size); @@ -70,12 +88,16 @@ size_t av_strlcpy(char *dst, const char *src, size_t size); * @param src source string * @param size size of destination buffer * @return the total length of src and dst + * + * WARNING: since the return value use the length of src and dst, these absolutely + * _must_ be a properly 0-terminated strings, otherwise this will read beyond + * the end of the buffer and possibly crash. */ size_t av_strlcat(char *dst, const char *src, size_t size); /** * Append output to a string, according to a format. Never write out of - * the destination buffer, and and always put a terminating 0 within + * the destination buffer, and always put a terminating 0 within * the buffer. * @param dst destination buffer (string to which the output is * appended) @@ -87,4 +109,9 @@ size_t av_strlcat(char *dst, const char *src, size_t size); */ size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...); +/** + * Convert a number to a av_malloced string. + */ +char *av_d2str(double d); + #endif /* AVUTIL_AVSTRING_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/avutil.h b/src/add-ons/media/plugins/ffmpeg/libavutil/avutil.h index fac1f5e2dd..e9e07b92fd 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/avutil.h +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/avutil.h @@ -22,7 +22,7 @@ #define AVUTIL_AVUTIL_H /** - * @file libavutil/avutil.h + * @file * external API header */ @@ -30,13 +30,18 @@ #define AV_STRINGIFY(s) AV_TOSTRING(s) #define AV_TOSTRING(s) #s +#define AV_GLUE(a, b) a ## b +#define AV_JOIN(a, b) AV_GLUE(a, b) + +#define AV_PRAGMA(s) _Pragma(#s) + #define AV_VERSION_INT(a, b, c) (a<<16 | b<<8 | c) #define AV_VERSION_DOT(a, b, c) a ##.## b ##.## c #define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c) #define LIBAVUTIL_VERSION_MAJOR 50 -#define LIBAVUTIL_VERSION_MINOR 3 -#define LIBAVUTIL_VERSION_MICRO 0 +#define LIBAVUTIL_VERSION_MINOR 15 +#define LIBAVUTIL_VERSION_MICRO 1 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ LIBAVUTIL_VERSION_MINOR, \ @@ -53,7 +58,28 @@ */ unsigned avutil_version(void); +/** + * Returns the libavutil build-time configuration. + */ +const char *avutil_configuration(void); + +/** + * Returns the libavutil license. + */ +const char *avutil_license(void); + +enum AVMediaType { + AVMEDIA_TYPE_UNKNOWN = -1, + AVMEDIA_TYPE_VIDEO, + AVMEDIA_TYPE_AUDIO, + AVMEDIA_TYPE_DATA, + AVMEDIA_TYPE_SUBTITLE, + AVMEDIA_TYPE_ATTACHMENT, + AVMEDIA_TYPE_NB +}; + #include "common.h" +#include "error.h" #include "mathematics.h" #include "rational.h" #include "intfloat_readwrite.h" diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/base64.c b/src/add-ons/media/plugins/ffmpeg/libavutil/base64.c index 60e35a81b3..d84ca36984 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/base64.c +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/base64.c @@ -19,7 +19,7 @@ */ /** - * @file libavutil/base64.c + * @file * @brief Base64 encode/decode * @author Ryan Martell (with lots of Michael) */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/bswap.h b/src/add-ons/media/plugins/ffmpeg/libavutil/bswap.h index 52811e74a3..6dd2a3511a 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/bswap.h +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/bswap.h @@ -19,7 +19,7 @@ */ /** - * @file libavutil/bswap.h + * @file * byte swapping routines */ @@ -28,7 +28,7 @@ #include #include "config.h" -#include "common.h" +#include "attributes.h" #if ARCH_ARM # include "arm/bswap.h" @@ -42,6 +42,12 @@ # include "x86/bswap.h" #endif +#define AV_BSWAP16C(x) (((x) << 8 & 0xff00) | ((x) >> 8 & 0x00ff)) +#define AV_BSWAP32C(x) (AV_BSWAP16C(x) << 16 | AV_BSWAP16C((x) >> 16)) +#define AV_BSWAP64C(x) (AV_BSWAP32C(x) << 32 | AV_BSWAP32C((x) >> 32)) + +#define AV_BSWAPC(s, x) AV_BSWAP##s##C(x) + #ifndef bswap_16 static av_always_inline av_const uint16_t bswap_16(uint16_t x) { @@ -89,6 +95,8 @@ static inline uint64_t av_const bswap_64(uint64_t x) #define le2me_16(x) bswap_16(x) #define le2me_32(x) bswap_32(x) #define le2me_64(x) bswap_64(x) +#define AV_BE2MEC(s, x) (x) +#define AV_LE2MEC(s, x) AV_BSWAPC(s, x) #else #define be2me_16(x) bswap_16(x) #define be2me_32(x) bswap_32(x) @@ -96,6 +104,15 @@ static inline uint64_t av_const bswap_64(uint64_t x) #define le2me_16(x) (x) #define le2me_32(x) (x) #define le2me_64(x) (x) +#define AV_BE2MEC(s, x) AV_BSWAPC(s, x) +#define AV_LE2MEC(s, x) (x) #endif +#define AV_BE2ME16C(x) AV_BE2MEC(16, x) +#define AV_BE2ME32C(x) AV_BE2MEC(32, x) +#define AV_BE2ME64C(x) AV_BE2MEC(64, x) +#define AV_LE2ME16C(x) AV_LE2MEC(16, x) +#define AV_LE2ME32C(x) AV_LE2MEC(32, x) +#define AV_LE2ME64C(x) AV_LE2MEC(64, x) + #endif /* AVUTIL_BSWAP_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/common.h b/src/add-ons/media/plugins/ffmpeg/libavutil/common.h index 330f228ee3..42a4c31eae 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/common.h +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/common.h @@ -19,7 +19,7 @@ */ /** - * @file libavutil/common.h + * @file * common internal and external API header */ @@ -34,88 +34,7 @@ #include #include #include - -#ifdef HAVE_AV_CONFIG_H -#include "config.h" -#endif - -#ifdef __GNUC__ -# define AV_GCC_VERSION_AT_LEAST(x,y) (__GNUC__ > x || __GNUC__ == x && __GNUC_MINOR__ >= y) -#else -# define AV_GCC_VERSION_AT_LEAST(x,y) 0 -#endif - -#ifndef av_always_inline -#if AV_GCC_VERSION_AT_LEAST(3,1) -# define av_always_inline __attribute__((always_inline)) inline -#else -# define av_always_inline inline -#endif -#endif - -#ifndef av_noinline -#if AV_GCC_VERSION_AT_LEAST(3,1) -# define av_noinline __attribute__((noinline)) -#else -# define av_noinline -#endif -#endif - -#ifndef av_pure -#if AV_GCC_VERSION_AT_LEAST(3,1) -# define av_pure __attribute__((pure)) -#else -# define av_pure -#endif -#endif - -#ifndef av_const -#if AV_GCC_VERSION_AT_LEAST(2,6) -# define av_const __attribute__((const)) -#else -# define av_const -#endif -#endif - -#ifndef av_cold -#if (!defined(__ICC) || __ICC > 1110) && AV_GCC_VERSION_AT_LEAST(4,3) -# define av_cold __attribute__((cold)) -#else -# define av_cold -#endif -#endif - -#ifndef av_flatten -#if (!defined(__ICC) || __ICC > 1110) && AV_GCC_VERSION_AT_LEAST(4,1) -# define av_flatten __attribute__((flatten)) -#else -# define av_flatten -#endif -#endif - -#ifndef attribute_deprecated -#if AV_GCC_VERSION_AT_LEAST(3,1) -# define attribute_deprecated __attribute__((deprecated)) -#else -# define attribute_deprecated -#endif -#endif - -#ifndef av_unused -#if defined(__GNUC__) -# define av_unused __attribute__((unused)) -#else -# define av_unused -#endif -#endif - -#ifndef av_uninit -#if defined(__GNUC__) && !defined(__ICC) -# define av_uninit(x) x=x -#else -# define av_uninit(x) x -#endif -#endif +#include "attributes.h" //rounded division & shift #define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b)) @@ -136,7 +55,9 @@ /* misc math functions */ extern const uint8_t ff_log2_tab[256]; -static inline av_const int av_log2(unsigned int v) +extern const uint8_t av_reverse[256]; + +static inline av_const int av_log2_c(unsigned int v) { int n = 0; if (v & 0xffff0000) { @@ -152,7 +73,7 @@ static inline av_const int av_log2(unsigned int v) return n; } -static inline av_const int av_log2_16bit(unsigned int v) +static inline av_const int av_log2_16bit_c(unsigned int v) { int n = 0; if (v & 0xff00) { @@ -164,6 +85,18 @@ static inline av_const int av_log2_16bit(unsigned int v) return n; } +#ifdef HAVE_AV_CONFIG_H +# include "config.h" +# include "intmath.h" +#endif + +#ifndef av_log2 +# define av_log2 av_log2_c +#endif +#ifndef av_log2_16bit +# define av_log2_16bit av_log2_16bit_c +#endif + /** * Clips a signed integer value into the amin-amax range. * @param a value to clip @@ -185,8 +118,8 @@ static inline av_const int av_clip(int a, int amin, int amax) */ static inline av_const uint8_t av_clip_uint8(int a) { - if (a&(~255)) return (-a)>>31; - else return a; + if (a&(~0xFF)) return (-a)>>31; + else return a; } /** @@ -196,8 +129,8 @@ static inline av_const uint8_t av_clip_uint8(int a) */ static inline av_const uint16_t av_clip_uint16(int a) { - if (a&(~65535)) return (-a)>>31; - else return a; + if (a&(~0xFFFF)) return (-a)>>31; + else return a; } /** @@ -207,8 +140,19 @@ static inline av_const uint16_t av_clip_uint16(int a) */ static inline av_const int16_t av_clip_int16(int a) { - if ((a+32768) & ~65535) return (a>>31) ^ 32767; - else return a; + if ((a+0x8000) & ~0xFFFF) return (a>>31) ^ 0x7FFF; + else return a; +} + +/** + * Clips a signed 64-bit integer value into the -2147483648,2147483647 range. + * @param a value to clip + * @return clipped value + */ +static inline av_const int32_t av_clipl_int32(int64_t a) +{ + if ((a+0x80000000u) & ~(0xFFFFFFFFULL)) return (a>>63) ^ 0x7FFFFFFF; + else return a; } /** @@ -225,6 +169,15 @@ static inline av_const float av_clipf(float a, float amin, float amax) else return a; } +/** Computes ceil(log2(x)). + * @param x value used to compute ceil(log2(x)) + * @return computed ceiling of log2(x) + */ +static inline av_const int av_ceil_log2(int x) +{ + return av_log2((x - 1) << 1); +} + #define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24)) #define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24)) @@ -256,6 +209,30 @@ static inline av_const float av_clipf(float a, float amin, float amax) }\ } +/*! + * \def GET_UTF16(val, GET_16BIT, ERROR) + * Converts a UTF-16 character (2 or 4 bytes) to its 32-bit UCS-4 encoded form + * \param val is the output and should be of type uint32_t. It holds the converted + * UCS-4 character and should be a left value. + * \param GET_16BIT gets two bytes of UTF-16 encoded data converted to native endianness. + * It can be a function or a statement whose return value or evaluated value is of type + * uint16_t. It will be executed up to 2 times. + * \param ERROR action that should be taken when an invalid UTF-16 surrogate is + * returned from GET_BYTE. It should be a statement that jumps out of the macro, + * like exit(), goto, return, break, or continue. + */ +#define GET_UTF16(val, GET_16BIT, ERROR)\ + val = GET_16BIT;\ + {\ + unsigned int hi = val - 0xD800;\ + if (hi < 0x800) {\ + val = GET_16BIT - 0xDC00;\ + if (val > 0x3FFU || hi > 0x3FFU)\ + ERROR\ + val += (hi<<10) + 0x10000;\ + }\ + }\ + /*! * \def PUT_UTF8(val, tmp, PUT_BYTE) * Converts a 32-bit Unicode character to its UTF-8 encoded form (up to 4 bytes long). @@ -292,10 +269,40 @@ static inline av_const float av_clipf(float a, float amin, float amax) }\ } +/*! + * \def PUT_UTF16(val, tmp, PUT_16BIT) + * Converts a 32-bit Unicode character to its UTF-16 encoded form (2 or 4 bytes). + * \param val is an input-only argument and should be of type uint32_t. It holds + * a UCS-4 encoded Unicode character that is to be converted to UTF-16. If + * val is given as a function it is executed only once. + * \param tmp is a temporary variable and should be of type uint16_t. It + * represents an intermediate value during conversion that is to be + * output by PUT_16BIT. + * \param PUT_16BIT writes the converted UTF-16 data to any proper destination + * in desired endianness. It could be a function or a statement, and uses tmp + * as the input byte. For example, PUT_BYTE could be "*output++ = tmp;" + * PUT_BYTE will be executed 1 or 2 times depending on input character. + */ +#define PUT_UTF16(val, tmp, PUT_16BIT)\ + {\ + uint32_t in = val;\ + if (in < 0x10000) {\ + tmp = in;\ + PUT_16BIT\ + } else {\ + tmp = 0xD800 | ((in - 0x10000) >> 10);\ + PUT_16BIT\ + tmp = 0xDC00 | ((in - 0x10000) & 0x3FF);\ + PUT_16BIT\ + }\ + }\ + + + #include "mem.h" #ifdef HAVE_AV_CONFIG_H -# include "libavutil/internal.h" +# include "internal.h" #endif /* HAVE_AV_CONFIG_H */ #endif /* AVUTIL_COMMON_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/crc.c b/src/add-ons/media/plugins/ffmpeg/libavutil/crc.c index 6fa14fcc58..2719baeefd 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/crc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/crc.c @@ -19,6 +19,7 @@ */ #include "config.h" +#include "common.h" #include "bswap.h" #include "crc.h" diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/crc.h b/src/add-ons/media/plugins/ffmpeg/libavutil/crc.h index fa34059278..6c0baab5ac 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/crc.h +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/crc.h @@ -23,7 +23,7 @@ #include #include -#include "common.h" +#include "attributes.h" typedef uint32_t AVCRC; diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/des.c b/src/add-ons/media/plugins/ffmpeg/libavutil/des.c index 6ba7702252..ab66a0b59d 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/des.c +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/des.c @@ -339,10 +339,10 @@ static uint64_t rand64(void) { } static const uint8_t test_key[] = {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0}; -static const DECLARE_ALIGNED(8, uint8_t, plain[]) = {0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10}; -static const DECLARE_ALIGNED(8, uint8_t, crypt[]) = {0x4a, 0xb6, 0x5b, 0x3d, 0x4b, 0x06, 0x15, 0x18}; -static DECLARE_ALIGNED(8, uint8_t, tmp[8]); -static DECLARE_ALIGNED(8, uint8_t, large_buffer[10002][8]); +static const DECLARE_ALIGNED(8, uint8_t, plain)[] = {0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10}; +static const DECLARE_ALIGNED(8, uint8_t, crypt)[] = {0x4a, 0xb6, 0x5b, 0x3d, 0x4b, 0x06, 0x15, 0x18}; +static DECLARE_ALIGNED(8, uint8_t, tmp)[8]; +static DECLARE_ALIGNED(8, uint8_t, large_buffer)[10002][8]; static const uint8_t cbc_key[] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/error.c b/src/add-ons/media/plugins/ffmpeg/libavutil/error.c new file mode 100644 index 0000000000..b6d6019061 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/error.c @@ -0,0 +1,47 @@ +/* + * 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 "avutil.h" +#include "avstring.h" + +int av_strerror(int errnum, char *errbuf, size_t errbuf_size) +{ + int ret = 0; + const char *errstr = NULL; + + switch (errnum) { + case AVERROR_EOF: errstr = "End of file"; break; + case AVERROR_INVALIDDATA: errstr = "Invalid data found when processing input"; break; + case AVERROR_NUMEXPECTED: errstr = "Number syntax expected in filename"; break; + case AVERROR_PATCHWELCOME: errstr = "Not yet implemented in FFmpeg, patches welcome"; break; + } + + if (errstr) { + av_strlcpy(errbuf, errstr, errbuf_size); + } else { +#if HAVE_STRERROR_R + ret = strerror_r(AVUNERROR(errnum), errbuf, errbuf_size); +#else + ret = -1; +#endif + if (ret < 0) + snprintf(errbuf, errbuf_size, "Error number %d occurred", errnum); + } + + return ret; +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/error.h b/src/add-ons/media/plugins/ffmpeg/libavutil/error.h new file mode 100644 index 0000000000..13a9a35930 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/error.h @@ -0,0 +1,72 @@ +/* + * 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 + * error code definitions + */ + +#ifndef AVUTIL_ERROR_H +#define AVUTIL_ERROR_H + +#include +#include "avutil.h" + +/* error handling */ +#if EDOM > 0 +#define AVERROR(e) (-(e)) ///< Returns a negative error code from a POSIX error code, to return from library functions. +#define AVUNERROR(e) (-(e)) ///< Returns a POSIX error code from a library function error return value. +#else +/* Some platforms have E* and errno already negated. */ +#define AVERROR(e) (e) +#define AVUNERROR(e) (e) +#endif + +#if LIBAVUTIL_VERSION_MAJOR < 51 +#define AVERROR_INVALIDDATA AVERROR(EINVAL) ///< Invalid data found when processing input +#define AVERROR_IO AVERROR(EIO) ///< I/O error +#define AVERROR_NOENT AVERROR(ENOENT) ///< No such file or directory +#define AVERROR_NOFMT AVERROR(EILSEQ) ///< Unknown format +#define AVERROR_NOMEM AVERROR(ENOMEM) ///< Not enough memory +#define AVERROR_NOTSUPP AVERROR(ENOSYS) ///< Operation not supported +#define AVERROR_NUMEXPECTED AVERROR(EDOM) ///< Number syntax expected in filename +#define AVERROR_UNKNOWN AVERROR(EINVAL) ///< Unknown error +#endif + +#define AVERROR_EOF AVERROR(EPIPE) ///< End of file + +#define AVERROR_PATCHWELCOME (-MKTAG('P','A','W','E')) ///< Not yet implemented in FFmpeg, patches welcome + +#if LIBAVUTIL_VERSION_MAJOR > 50 +#define AVERROR_INVALIDDATA (-MKTAG('I','N','D','A')) ///< Invalid data found when processing input +#define AVERROR_NUMEXPECTED (-MKTAG('N','U','E','X')) ///< Number syntax expected in filename +#endif + +/** + * Puts a description of the AVERROR code errnum in errbuf. + * In case of failure the global variable errno is set to indicate the + * error. Even in case of failure av_strerror() will print a generic + * error message indicating the errnum provided to errbuf. + * + * @param errbuf_size the size in bytes of errbuf + * @return 0 on success, a negative value if a description for errnum + * cannot be found + */ +int av_strerror(int errnum, char *errbuf, size_t errbuf_size); + +#endif /* AVUTIL_ERROR_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/fifo.c b/src/add-ons/media/plugins/ffmpeg/libavutil/fifo.c index 840b73a57b..cfb716e53b 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/fifo.c +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/fifo.c @@ -78,6 +78,7 @@ int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size) { return 0; } +// src must NOT be const as it can be a context for func that may need updating (like a pointer or byte counter) int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void*, void*, int)) { int total = size; diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/fifo.h b/src/add-ons/media/plugins/ffmpeg/libavutil/fifo.h index a904dfd02e..fb1ed47ff1 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/fifo.h +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/fifo.h @@ -17,7 +17,7 @@ */ /** - * @file libavutil/fifo.h + * @file * a very simple circular buffer FIFO implementation */ @@ -25,8 +25,6 @@ #define AVUTIL_FIFO_H #include -#include "avutil.h" -#include "common.h" typedef struct AVFifoBuffer { uint8_t *buffer; @@ -37,7 +35,7 @@ typedef struct AVFifoBuffer { /** * Initializes an AVFifoBuffer. * @param size of FIFO - * @return AVFifoBuffer or NULL if mem allocation failure + * @return AVFifoBuffer or NULL in case of memory allocation failure */ AVFifoBuffer *av_fifo_alloc(unsigned int size); @@ -81,7 +79,8 @@ int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size, void (*func) /** * Feeds data from a user-supplied callback to an AVFifoBuffer. * @param *f AVFifoBuffer to write to - * @param *src data source + * @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, * the second is dest_buf, the third is dest_buf_size. diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/integer.c b/src/add-ons/media/plugins/ffmpeg/libavutil/integer.c index 3dfbcdf695..67456080d5 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/integer.c +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/integer.c @@ -20,7 +20,7 @@ */ /** - * @file libavutil/integer.c + * @file * arbitrary precision integers * @author Michael Niedermayer */ @@ -110,8 +110,8 @@ AVInteger av_mod_i(AVInteger *quot, AVInteger a, AVInteger b){ AVInteger quot_temp; if(!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); +// 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); diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/integer.h b/src/add-ons/media/plugins/ffmpeg/libavutil/integer.h index d4d0201db4..fb46acbe0f 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/integer.h +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/integer.h @@ -20,7 +20,7 @@ */ /** - * @file libavutil/integer.h + * @file * arbitrary precision integers * @author Michael Niedermayer */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/internal.h b/src/add-ons/media/plugins/ffmpeg/libavutil/internal.h index 1012f1c690..fe8a6fa6b5 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/internal.h +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/internal.h @@ -19,7 +19,7 @@ */ /** - * @file libavutil/internal.h + * @file * common internal API header */ @@ -35,8 +35,7 @@ #include #include #include "config.h" -#include "common.h" -#include "mem.h" +#include "attributes.h" #include "timer.h" #ifndef attribute_align_arg @@ -55,8 +54,16 @@ #endif #endif +#ifndef av_alias +#if HAVE_ATTRIBUTE_MAY_ALIAS && (!defined(__ICC) || __ICC > 1110) && AV_GCC_VERSION_AT_LEAST(3,3) +# define av_alias __attribute__((may_alias)) +#else +# define av_alias +#endif +#endif + #ifndef INT16_MIN -#define INT16_MIN (-0x7fff-1) +#define INT16_MIN (-0x7fff - 1) #endif #ifndef INT16_MAX @@ -64,7 +71,7 @@ #endif #ifndef INT32_MIN -#define INT32_MIN (-0x7fffffff-1) +#define INT32_MIN (-0x7fffffff - 1) #endif #ifndef INT32_MAX @@ -76,7 +83,7 @@ #endif #ifndef INT64_MIN -#define INT64_MIN (-0x7fffffffffffffffLL-1) +#define INT64_MIN (-0x7fffffffffffffffLL - 1) #endif #ifndef INT64_MAX @@ -91,12 +98,8 @@ # define INT_BIT (CHAR_BIT * sizeof(int)) #endif -#if ( defined(__PIC__) || defined(__pic__) ) && ! defined(PIC) -# define PIC -#endif - #ifndef offsetof -# define offsetof(T,F) ((unsigned int)((char *)&((T *)0)->F)) +# define offsetof(T, F) ((unsigned int)((char *)&((T *)0)->F)) #endif /* Use to export labels from asm. */ @@ -124,66 +127,6 @@ /* math */ -extern const uint32_t ff_inverse[256]; - -#if ARCH_X86 -# define FASTDIV(a,b) \ - ({\ - int ret,dmy;\ - __asm__ volatile(\ - "mull %3"\ - :"=d"(ret),"=a"(dmy)\ - :"1"(a),"g"(ff_inverse[b])\ - );\ - ret;\ - }) -#elif HAVE_ARMV6 && HAVE_INLINE_ASM -static inline av_const int FASTDIV(int a, int b) -{ - int r, t; - __asm__ volatile("cmp %3, #2 \n\t" - "ldr %1, [%4, %3, lsl #2] \n\t" - "lsrle %0, %2, #1 \n\t" - "smmulgt %0, %1, %2 \n\t" - : "=&r"(r), "=&r"(t) : "r"(a), "r"(b), "r"(ff_inverse)); - return r; -} -#elif ARCH_ARM && HAVE_INLINE_ASM -static inline av_const int FASTDIV(int a, int b) -{ - int r, t; - __asm__ volatile ("umull %1, %0, %2, %3" - : "=&r"(r), "=&r"(t) : "r"(a), "r"(ff_inverse[b])); - return r; -} -#elif CONFIG_FASTDIV -# define FASTDIV(a,b) ((uint32_t)((((uint64_t)a)*ff_inverse[b])>>32)) -#else -# define FASTDIV(a,b) ((a)/(b)) -#endif - -extern const uint8_t ff_sqrt_tab[256]; - -static inline av_const unsigned int ff_sqrt(unsigned int a) -{ - unsigned int b; - - if(a<255) return (ff_sqrt_tab[a+1]-1)>>4; - else if(a<(1<<12)) b= ff_sqrt_tab[a>>4 ]>>2; -#if !CONFIG_SMALL - else if(a<(1<<14)) b= ff_sqrt_tab[a>>6 ]>>1; - else if(a<(1<<16)) b= ff_sqrt_tab[a>>8 ] ; -#endif - else{ - int s= av_log2_16bit(a>>16)>>1; - unsigned int c= a>>(s+2); - b= ff_sqrt_tab[c>>(s+8)]; - b= FASTDIV(c,b) + (b<>31;\ - level= (level^mask)-mask; -#endif - -#if HAVE_CMOV -#define COPY3_IF_LT(x,y,a,b,c,d)\ -__asm__ volatile (\ - "cmpl %0, %3 \n\t"\ - "cmovl %3, %0 \n\t"\ - "cmovl %4, %1 \n\t"\ - "cmovl %5, %2 \n\t"\ - : "+&r" (x), "+&r" (a), "+r" (c)\ - : "r" (y), "r" (b), "r" (d)\ -); -#else -#define COPY3_IF_LT(x,y,a,b,c,d)\ -if((y)<(x)){\ - (x)=(y);\ - (a)=(b);\ - (c)=(d);\ -} + mask = level >> 31;\ + level = (level ^ mask) - mask; #endif /* avoid usage of dangerous/inappropriate system functions */ @@ -249,63 +173,25 @@ if((y)<(x)){\ #define perror please_use_av_log_instead_of_perror #endif -#define CHECKED_ALLOCZ(p, size)\ +#define FF_ALLOC_OR_GOTO(ctx, p, size, label)\ {\ - p= av_mallocz(size);\ - if(p==NULL && (size)!=0){\ - av_log(NULL, AV_LOG_ERROR, "Cannot allocate memory.");\ - goto fail;\ + p = av_malloc(size);\ + if (p == NULL && (size) != 0) {\ + av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\ + goto label;\ }\ } -#if !HAVE_LLRINT -static av_always_inline av_const long long llrint(double x) -{ - return rint(x); +#define FF_ALLOCZ_OR_GOTO(ctx, p, size, label)\ +{\ + p = av_mallocz(size);\ + if (p == NULL && (size) != 0) {\ + av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\ + goto label;\ + }\ } -#endif /* HAVE_LLRINT */ -#if !HAVE_LOG2 -static av_always_inline av_const double log2(double x) -{ - return log(x) * 1.44269504088896340736; -} -#endif /* HAVE_LOG2 */ - -#if !HAVE_LRINT -static av_always_inline av_const long int lrint(double x) -{ - return rint(x); -} -#endif /* HAVE_LRINT */ - -#if !HAVE_LRINTF -static av_always_inline av_const long int lrintf(float x) -{ - return (int)(rint(x)); -} -#endif /* HAVE_LRINTF */ - -#if !HAVE_ROUND -static av_always_inline av_const double round(double x) -{ - return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5); -} -#endif /* HAVE_ROUND */ - -#if !HAVE_ROUNDF -static av_always_inline av_const float roundf(float x) -{ - return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5); -} -#endif /* HAVE_ROUNDF */ - -#if !HAVE_TRUNCF -static av_always_inline av_const float truncf(float x) -{ - return (x > 0) ? floor(x) : ceil(x); -} -#endif /* HAVE_TRUNCF */ +#include "libm.h" /** * Returns NULL if CONFIG_SMALL is true, otherwise the argument @@ -318,4 +204,15 @@ static av_always_inline av_const float truncf(float x) # define NULL_IF_CONFIG_SMALL(x) x #endif +#if HAVE_SYMVER_ASM_LABEL +# define FF_SYMVER(type, name, args, ver) \ + type ff_##name args __asm__ (EXTERN_PREFIX #name "@" ver); \ + type ff_##name args +#elif HAVE_SYMVER_GNU_ASM +# define FF_SYMVER(type, name, args, ver) \ + __asm__ (".symver ff_" #name "," EXTERN_PREFIX #name "@" ver); \ + type ff_##name args; \ + type ff_##name args +#endif + #endif /* AVUTIL_INTERNAL_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/intfloat_readwrite.c b/src/add-ons/media/plugins/ffmpeg/libavutil/intfloat_readwrite.c index bfe36a641a..79fe18671e 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/intfloat_readwrite.c +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/intfloat_readwrite.c @@ -21,11 +21,12 @@ */ /** - * @file libavutil/intfloat_readwrite.c + * @file * portable IEEE float/double read/write functions */ -#include "common.h" +#include +#include #include "intfloat_readwrite.h" double av_int2dbl(int64_t v){ diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/intfloat_readwrite.h b/src/add-ons/media/plugins/ffmpeg/libavutil/intfloat_readwrite.h index e2d5d5be0e..1b80fc6e95 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/intfloat_readwrite.h +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/intfloat_readwrite.h @@ -22,7 +22,7 @@ #define AVUTIL_INTFLOAT_READWRITE_H #include -#include "common.h" +#include "attributes.h" /* IEEE 80 bits extended float */ typedef struct AVExtFloat { diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/intmath.h b/src/add-ons/media/plugins/ffmpeg/libavutil/intmath.h new file mode 100644 index 0000000000..95ee1ff65c --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/intmath.h @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2010 Mans Rullgard + * + * 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_INTMATH_H +#define AVUTIL_INTMATH_H + +#include +#include "config.h" +#include "attributes.h" + +extern const uint32_t ff_inverse[257]; + +#if ARCH_ARM +# include "arm/intmath.h" +#elif ARCH_X86 +# include "x86/intmath.h" +#endif + +#if HAVE_FAST_CLZ && AV_GCC_VERSION_AT_LEAST(3,4) + +#ifndef av_log2 + +#define av_log2(x) (31 - __builtin_clz((x)|1)) + +#ifndef av_log2_16bit +#define av_log2_16bit av_log2 +#endif + +#endif /* av_log2 */ + +#endif /* AV_GCC_VERSION_AT_LEAST(3,4) */ + +#ifndef FASTDIV + +#if CONFIG_FASTDIV +# define FASTDIV(a,b) ((uint32_t)((((uint64_t)a) * ff_inverse[b]) >> 32)) +#else +# define FASTDIV(a,b) ((a) / (b)) +#endif + +#endif /* FASTDIV */ + +/* + * Get definition of av_log2_c from common.h. In the event we got + * here through common.h including this file, including it again will + * be a no-op due to multi-inclusion guards, so we must duplicate the + * fallback defines here. + */ + +#include "common.h" + +#ifndef av_log2 +# define av_log2 av_log2_c +#endif +#ifndef av_log2_16bit +# define av_log2_16bit av_log2_16bit_c +#endif + +extern const uint8_t ff_sqrt_tab[256]; + +static inline av_const unsigned int ff_sqrt(unsigned int a) +{ + unsigned int b; + + if (a < 255) return (ff_sqrt_tab[a + 1] - 1) >> 4; + else if (a < (1 << 12)) b = ff_sqrt_tab[a >> 4] >> 2; +#if !CONFIG_SMALL + else if (a < (1 << 14)) b = ff_sqrt_tab[a >> 6] >> 1; + else if (a < (1 << 16)) b = ff_sqrt_tab[a >> 8] ; +#endif + else { + int s = av_log2_16bit(a >> 16) >> 1; + unsigned int c = a >> (s + 2); + b = ff_sqrt_tab[c >> (s + 8)]; + b = FASTDIV(c,b) + (b << s); + } + + return b - (a < b * b); +} + +#endif /* AVUTIL_INTMATH_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/intreadwrite.h b/src/add-ons/media/plugins/ffmpeg/libavutil/intreadwrite.h index 933732c365..c8026f0872 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/intreadwrite.h +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/intreadwrite.h @@ -22,11 +22,34 @@ #include #include "config.h" #include "bswap.h" +#include "common.h" + +typedef union { + uint64_t u64; + uint32_t u32[2]; + uint16_t u16[4]; + uint8_t u8 [8]; + double f64; + float f32[2]; +} av_alias av_alias64; + +typedef union { + uint32_t u32; + uint16_t u16[2]; + uint8_t u8 [4]; + float f32; +} av_alias av_alias32; + +typedef union { + uint16_t u16; + uint8_t u8 [2]; +} av_alias av_alias16; /* * Arch-specific headers can provide any combination of - * AV_[RW][BLN](16|24|32|64) macros. Preprocessor symbols must be - * defined, even if these are implemented as inline functions. + * AV_[RW][BLN](16|24|32|64) and AV_(COPY|SWAP|ZERO)(64|128) macros. + * Preprocessor symbols must be defined, even if these are implemented + * as inline functions. */ #if ARCH_ARM @@ -37,6 +60,10 @@ # include "mips/intreadwrite.h" #elif ARCH_PPC # include "ppc/intreadwrite.h" +#elif ARCH_TOMI +# include "tomi/intreadwrite.h" +#elif ARCH_X86 +# include "x86/intreadwrite.h" #endif /* @@ -152,22 +179,22 @@ #if HAVE_ATTRIBUTE_PACKED -struct unaligned_64 { uint64_t l; } __attribute__((packed)); -struct unaligned_32 { uint32_t l; } __attribute__((packed)); -struct unaligned_16 { uint16_t l; } __attribute__((packed)); +union unaligned_64 { uint64_t l; } __attribute__((packed)) av_alias; +union unaligned_32 { uint32_t l; } __attribute__((packed)) av_alias; +union unaligned_16 { uint16_t l; } __attribute__((packed)) av_alias; -# define AV_RN(s, p) (((const struct unaligned_##s *) (p))->l) -# define AV_WN(s, p, v) (((struct unaligned_##s *) (p))->l) = (v) +# define AV_RN(s, p) (((const union unaligned_##s *) (p))->l) +# define AV_WN(s, p, v) ((((union unaligned_##s *) (p))->l) = (v)) #elif defined(__DECC) # define AV_RN(s, p) (*((const __unaligned uint##s##_t*)(p))) -# define AV_WN(s, p, v) *((__unaligned uint##s##_t*)(p)) = (v) +# define AV_WN(s, p, v) (*((__unaligned uint##s##_t*)(p)) = (v)) #elif HAVE_FAST_UNALIGNED -# define AV_RN(s, p) (*((const uint##s##_t*)(p))) -# define AV_WN(s, p, v) *((uint##s##_t*)(p)) = (v) +# define AV_RN(s, p) (((const av_alias##s*)(p))->u##s) +# define AV_WN(s, p, v) (((av_alias##s*)(p))->u##s = (v)) #else @@ -397,4 +424,93 @@ struct unaligned_16 { uint16_t l; } __attribute__((packed)); } while(0) #endif +/* + * The AV_[RW]NA macros access naturally aligned data + * in a type-safe way. + */ + +#define AV_RNA(s, p) (((const av_alias##s*)(p))->u##s) +#define AV_WNA(s, p, v) (((av_alias##s*)(p))->u##s = (v)) + +#ifndef AV_RN16A +# define AV_RN16A(p) AV_RNA(16, p) +#endif + +#ifndef AV_RN32A +# define AV_RN32A(p) AV_RNA(32, p) +#endif + +#ifndef AV_RN64A +# define AV_RN64A(p) AV_RNA(64, p) +#endif + +#ifndef AV_WN16A +# define AV_WN16A(p, v) AV_WNA(16, p, v) +#endif + +#ifndef AV_WN32A +# define AV_WN32A(p, v) AV_WNA(32, p, v) +#endif + +#ifndef AV_WN64A +# define AV_WN64A(p, v) AV_WNA(64, p, v) +#endif + +/* Parameters for AV_COPY*, AV_SWAP*, AV_ZERO* must be + * naturally aligned. They may be implemented using MMX, + * so emms_c() must be called before using any float code + * afterwards. + */ + +#define AV_COPY(n, d, s) \ + (((av_alias##n*)(d))->u##n = ((const av_alias##n*)(s))->u##n) + +#ifndef AV_COPY16 +# define AV_COPY16(d, s) AV_COPY(16, d, s) +#endif + +#ifndef AV_COPY32 +# define AV_COPY32(d, s) AV_COPY(32, d, s) +#endif + +#ifndef AV_COPY64 +# define AV_COPY64(d, s) AV_COPY(64, d, s) +#endif + +#ifndef AV_COPY128 +# define AV_COPY128(d, s) \ + do { \ + AV_COPY64(d, s); \ + AV_COPY64((char*)(d)+8, (char*)(s)+8); \ + } while(0) +#endif + +#define AV_SWAP(n, a, b) FFSWAP(av_alias##n, *(av_alias##n*)(a), *(av_alias##n*)(b)) + +#ifndef AV_SWAP64 +# define AV_SWAP64(a, b) AV_SWAP(64, a, b) +#endif + +#define AV_ZERO(n, d) (((av_alias##n*)(d))->u##n = 0) + +#ifndef AV_ZERO16 +# define AV_ZERO16(d) AV_ZERO(16, d) +#endif + +#ifndef AV_ZERO32 +# define AV_ZERO32(d) AV_ZERO(32, d) +#endif + +#ifndef AV_ZERO64 +# define AV_ZERO64(d) AV_ZERO(64, d) +#endif + +#ifndef AV_ZERO128 +# define AV_ZERO128(d) \ + do { \ + AV_ZERO64(d); \ + AV_ZERO64((char*)(d)+8); \ + } while(0) +#endif + #endif /* AVUTIL_INTREADWRITE_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/lfg.c b/src/add-ons/media/plugins/ffmpeg/libavutil/lfg.c index e876d18fef..1dad4e442c 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/lfg.c +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/lfg.c @@ -23,6 +23,7 @@ #include "lfg.h" #include "md5.h" #include "intreadwrite.h" +#include "attributes.h" void av_cold av_lfg_init(AVLFG *c, unsigned int seed){ uint8_t tmp[16]={0}; @@ -39,9 +40,24 @@ void av_cold av_lfg_init(AVLFG *c, unsigned int seed){ c->index=0; } +void av_bmg_get(AVLFG *lfg, double out[2]) +{ + double x1, x2, w; + + do { + x1 = 2.0/UINT_MAX*av_lfg_get(lfg) - 1.0; + x2 = 2.0/UINT_MAX*av_lfg_get(lfg) - 1.0; + w = x1*x1 + x2*x2; + } while (w >= 1.0); + + w = sqrt((-2.0 * log(w)) / w); + out[0] = x1 * w; + out[1] = x2 * w; +} + #ifdef TEST #include "log.h" -#include "common.h" +#include "timer.h" int main(void) { @@ -59,6 +75,24 @@ int main(void) STOP_TIMER("624 calls of av_lfg_get"); } av_log(NULL, AV_LOG_ERROR, "final value:%X\n", x); + + /* BMG usage example */ + { + double mean = 1000; + double stddev = 53; + + av_lfg_init(&state, 42); + + for (i = 0; i < 1000; i += 2) { + double bmg_out[2]; + av_bmg_get(&state, bmg_out); + av_log(NULL, AV_LOG_INFO, + "%f\n%f\n", + bmg_out[0] * stddev + mean, + bmg_out[1] * stddev + mean); + } + } + return 0; } #endif diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/lfg.h b/src/add-ons/media/plugins/ffmpeg/libavutil/lfg.h index 3250c18e79..ac89d120d5 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/lfg.h +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/lfg.h @@ -51,4 +51,12 @@ static inline unsigned int av_mlfg_get(AVLFG *c){ return c->state[c->index++ & 63] = 2*a*b+a+b; } +/** + * Gets the next two numbers generated by a Box-Muller Gaussian + * generator using the random numbers issued by lfg. + * + * @param out[2] array where are placed the two generated numbers + */ +void av_bmg_get(AVLFG *lfg, double out[2]); + #endif /* AVUTIL_LFG_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/libm.h b/src/add-ons/media/plugins/ffmpeg/libavutil/libm.h new file mode 100644 index 0000000000..c7c28ac27c --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/libm.h @@ -0,0 +1,96 @@ +/* + * 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 + * Replacements for frequently missing libm functions + */ + +#ifndef AVUTIL_LIBM_H +#define AVUTIL_LIBM_H + +#include +#include "config.h" +#include "attributes.h" + +#if !HAVE_EXP2 +#undef exp2 +#define exp2(x) exp((x) * 0.693147180559945) +#endif /* HAVE_EXP2 */ + +#if !HAVE_EXP2F +#undef exp2f +#define exp2f(x) ((float)exp2(x)) +#endif /* HAVE_EXP2F */ + +#if !HAVE_LLRINT +#undef llrint +#define llrint(x) ((long long)rint(x)) +#endif /* HAVE_LLRINT */ + +#if !HAVE_LLRINTF +#undef llrintf +#define llrintf(x) ((long long)rint(x)) +#endif /* HAVE_LLRINT */ + +#if !HAVE_LOG2 +#undef log2 +#define log2(x) (log(x) * 1.44269504088896340736) +#endif /* HAVE_LOG2 */ + +#if !HAVE_LOG2F +#undef log2f +#define log2f(x) ((float)log2(x)) +#endif /* HAVE_LOG2F */ + +#if !HAVE_LRINT +static av_always_inline av_const long int lrint(double x) +{ + return rint(x); +} +#endif /* HAVE_LRINT */ + +#if !HAVE_LRINTF +static av_always_inline av_const long int lrintf(float x) +{ + return (int)(rint(x)); +} +#endif /* HAVE_LRINTF */ + +#if !HAVE_ROUND +static av_always_inline av_const double round(double x) +{ + return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5); +} +#endif /* HAVE_ROUND */ + +#if !HAVE_ROUNDF +static av_always_inline av_const float roundf(float x) +{ + return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5); +} +#endif /* HAVE_ROUNDF */ + +#if !HAVE_TRUNCF +static av_always_inline av_const float truncf(float x) +{ + return (x > 0) ? floor(x) : ceil(x); +} +#endif /* HAVE_TRUNCF */ + +#endif /* AVUTIL_LIBM_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/lls.c b/src/add-ons/media/plugins/ffmpeg/libavutil/lls.c index 047f976c3f..3855792760 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/lls.c +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/lls.c @@ -21,7 +21,7 @@ */ /** - * @file libavutil/lls.c + * @file * linear least squares model */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/log.c b/src/add-ons/media/plugins/ffmpeg/libavutil/log.c index 4bb9652c2c..9a8b66ee4d 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/log.c +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/log.c @@ -20,20 +20,47 @@ */ /** - * @file libavutil/log.c + * @file * logging functions */ +#include +#include #include "avutil.h" #include "log.h" +#if LIBAVUTIL_VERSION_MAJOR > 50 +static +#endif int av_log_level = AV_LOG_INFO; +static int use_ansi_color=-1; + +#undef fprintf +static void colored_fputs(int color, const char *str){ + if(use_ansi_color<0){ +#if HAVE_ISATTY && !defined(_WIN32) + use_ansi_color= getenv("TERM") && !getenv("NO_COLOR") && isatty(2); +#else + use_ansi_color= 0; +#endif + } + + if(use_ansi_color){ + fprintf(stderr, "\033[%d;3%dm", color>>4, color&15); + } + fputs(str, stderr); + if(use_ansi_color){ + fprintf(stderr, "\033[0m"); + } +} + void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) { static int print_prefix=1; static int count; static char line[1024], prev[1024]; + static const uint8_t color[]={0x41,0x41,0x11,0x03,9,9,9}; AVClass* avc= ptr ? *(AVClass**)ptr : NULL; if(level>av_log_level) return; @@ -54,7 +81,7 @@ 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; } - fputs(line, stderr); + colored_fputs(color[av_clip(level>>3, 0, 6)], line); strcpy(prev, line); } diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/log.h b/src/add-ons/media/plugins/ffmpeg/libavutil/log.h index b0a1493607..1c3e490139 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/log.h +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/log.h @@ -48,6 +48,14 @@ typedef struct { * @see av_set_default_options() */ const struct AVOption *option; + + /** + * LIBAVUTIL_VERSION with which this structure was created. + * This is used to allow fields to be added without requiring major + * version bumps everywhere. + */ + + int version; } AVClass; /* av_log API */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/mathematics.c b/src/add-ons/media/plugins/ffmpeg/libavutil/mathematics.c index f57cf8e4b6..c06cb16165 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/mathematics.c +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/mathematics.c @@ -19,13 +19,13 @@ */ /** - * @file libavutil/mathematics.c + * @file * miscellaneous math routines and tables */ #include -#include "avutil.h" -#include "common.h" +#include +#include #include "mathematics.h" const uint8_t ff_sqrt_tab[256]={ @@ -50,6 +50,25 @@ const uint8_t ff_log2_tab[256]={ 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 }; +const uint8_t av_reverse[256]={ +0x00,0x80,0x40,0xC0,0x20,0xA0,0x60,0xE0,0x10,0x90,0x50,0xD0,0x30,0xB0,0x70,0xF0, +0x08,0x88,0x48,0xC8,0x28,0xA8,0x68,0xE8,0x18,0x98,0x58,0xD8,0x38,0xB8,0x78,0xF8, +0x04,0x84,0x44,0xC4,0x24,0xA4,0x64,0xE4,0x14,0x94,0x54,0xD4,0x34,0xB4,0x74,0xF4, +0x0C,0x8C,0x4C,0xCC,0x2C,0xAC,0x6C,0xEC,0x1C,0x9C,0x5C,0xDC,0x3C,0xBC,0x7C,0xFC, +0x02,0x82,0x42,0xC2,0x22,0xA2,0x62,0xE2,0x12,0x92,0x52,0xD2,0x32,0xB2,0x72,0xF2, +0x0A,0x8A,0x4A,0xCA,0x2A,0xAA,0x6A,0xEA,0x1A,0x9A,0x5A,0xDA,0x3A,0xBA,0x7A,0xFA, +0x06,0x86,0x46,0xC6,0x26,0xA6,0x66,0xE6,0x16,0x96,0x56,0xD6,0x36,0xB6,0x76,0xF6, +0x0E,0x8E,0x4E,0xCE,0x2E,0xAE,0x6E,0xEE,0x1E,0x9E,0x5E,0xDE,0x3E,0xBE,0x7E,0xFE, +0x01,0x81,0x41,0xC1,0x21,0xA1,0x61,0xE1,0x11,0x91,0x51,0xD1,0x31,0xB1,0x71,0xF1, +0x09,0x89,0x49,0xC9,0x29,0xA9,0x69,0xE9,0x19,0x99,0x59,0xD9,0x39,0xB9,0x79,0xF9, +0x05,0x85,0x45,0xC5,0x25,0xA5,0x65,0xE5,0x15,0x95,0x55,0xD5,0x35,0xB5,0x75,0xF5, +0x0D,0x8D,0x4D,0xCD,0x2D,0xAD,0x6D,0xED,0x1D,0x9D,0x5D,0xDD,0x3D,0xBD,0x7D,0xFD, +0x03,0x83,0x43,0xC3,0x23,0xA3,0x63,0xE3,0x13,0x93,0x53,0xD3,0x33,0xB3,0x73,0xF3, +0x0B,0x8B,0x4B,0xCB,0x2B,0xAB,0x6B,0xEB,0x1B,0x9B,0x5B,0xDB,0x3B,0xBB,0x7B,0xFB, +0x07,0x87,0x47,0xC7,0x27,0xA7,0x67,0xE7,0x17,0x97,0x57,0xD7,0x37,0xB7,0x77,0xF7, +0x0F,0x8F,0x4F,0xCF,0x2F,0xAF,0x6F,0xEF,0x1F,0x9F,0x5F,0xDF,0x3F,0xBF,0x7F,0xFF, +}; + int64_t av_gcd(int64_t a, int64_t b){ if(b) return av_gcd(b, a%b); else return a; @@ -117,6 +136,14 @@ int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq){ return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF); } +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 (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; +} + #ifdef TEST #include "integer.h" #undef printf diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/mathematics.h b/src/add-ons/media/plugins/ffmpeg/libavutil/mathematics.h index cb3591051a..e198aef8cb 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/mathematics.h +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/mathematics.h @@ -23,7 +23,7 @@ #include #include -#include "common.h" +#include "attributes.h" #include "rational.h" #ifndef M_E @@ -35,12 +35,18 @@ #ifndef M_LN10 #define M_LN10 2.30258509299404568402 /* log_e 10 */ #endif +#ifndef M_LOG2_10 +#define M_LOG2_10 3.32192809488736234787 /* log_2 10 */ +#endif #ifndef M_PI #define M_PI 3.14159265358979323846 /* pi */ #endif #ifndef M_SQRT1_2 #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ #endif +#ifndef M_SQRT2 +#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ +#endif #ifndef NAN #define NAN (0.0/0.0) #endif @@ -56,6 +62,11 @@ enum AVRounding { AV_ROUND_NEAR_INF = 5, ///< Round to nearest and halfway cases away from zero. }; +/** + * Returns the greatest common divisor of a and b. + * If both a and b are 0 or either or both are <0 then behavior is + * undefined. + */ int64_t av_const av_gcd(int64_t a, int64_t b); /** @@ -75,4 +86,13 @@ int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding) av_cons */ int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const; +/** + * Compares 2 timestamps each in its own timebases. + * The result of the function is undefined if one of the timestamps + * is outside the int64_t range when represented in the others timebase. + * @return -1 if ts_a is before ts_b, 1 if ts_a is after ts_b or 0 if they represent the same position + */ +int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b); + + #endif /* AVUTIL_MATHEMATICS_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/md5.c b/src/add-ons/media/plugins/ffmpeg/libavutil/md5.c index d3e3e9816e..39ee6242e5 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/md5.c +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/md5.c @@ -163,6 +163,7 @@ void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len){ #ifdef TEST #include +#include #undef printf int main(void){ uint64_t md5val; diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/mem.c b/src/add-ons/media/plugins/ffmpeg/libavutil/mem.c index 741450b53f..8cad089a7d 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/mem.c +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/mem.c @@ -20,7 +20,7 @@ */ /** - * @file libavutil/mem.c + * @file * default memory allocator for libavutil */ @@ -33,6 +33,7 @@ #include #endif +#include "avutil.h" #include "mem.h" /* here we can use OS-dependent allocation functions */ @@ -40,6 +41,22 @@ #undef malloc #undef realloc +#ifdef MALLOC_PREFIX + +#define malloc AV_JOIN(MALLOC_PREFIX, malloc) +#define memalign AV_JOIN(MALLOC_PREFIX, memalign) +#define posix_memalign AV_JOIN(MALLOC_PREFIX, posix_memalign) +#define realloc AV_JOIN(MALLOC_PREFIX, realloc) +#define free AV_JOIN(MALLOC_PREFIX, free) + +void *malloc(size_t size); +void *memalign(size_t align, size_t size); +int posix_memalign(void **ptr, size_t align, size_t size); +void *realloc(void *ptr, size_t size); +void free(void *ptr); + +#endif /* MALLOC_PREFIX */ + /* 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. */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/mem.h b/src/add-ons/media/plugins/ffmpeg/libavutil/mem.h index 37ba276d08..1488792706 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/mem.h +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/mem.h @@ -19,21 +19,28 @@ */ /** - * @file libavutil/mem.h + * @file * memory handling functions */ #ifndef AVUTIL_MEM_H #define AVUTIL_MEM_H -#include "common.h" +#include "attributes.h" #if defined(__ICC) || defined(__SUNPRO_C) - #define DECLARE_ALIGNED(n,t,v) t v __attribute__ ((aligned (n))) + #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__) + #define DECLARE_ALIGNED(n,t,v) \ + AV_PRAGMA(DATA_ALIGN(v,n)) \ + t __attribute__((aligned(n))) v + #define DECLARE_ASM_CONST(n,t,v) \ + AV_PRAGMA(DATA_ALIGN(v,n)) \ + static const t __attribute__((aligned(n))) v #elif defined(__GNUC__) - #define DECLARE_ALIGNED(n,t,v) t v __attribute__ ((aligned (n))) - #define DECLARE_ASM_CONST(n,t,v) static const t v attribute_used __attribute__ ((aligned (n))) + #define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v + #define DECLARE_ASM_CONST(n,t,v) static const t attribute_used __attribute__ ((aligned (n))) v #elif defined(_MSC_VER) #define DECLARE_ALIGNED(n,t,v) __declspec(align(n)) t v #define DECLARE_ASM_CONST(n,t,v) __declspec(align(n)) static const t v @@ -42,7 +49,6 @@ #define DECLARE_ASM_CONST(n,t,v) static const t v #endif - #if AV_GCC_VERSION_AT_LEAST(3,1) #define av_malloc_attrib __attribute__((__malloc__)) #else @@ -67,7 +73,7 @@ void *av_malloc(unsigned int size) av_malloc_attrib av_alloc_size(1); /** * Allocates or reallocates a block of memory. - * If ptr is NULL and size > 0, allocates a new block. If \p + * If ptr is NULL and size > 0, allocates a new block. If * size is zero, frees the memory block pointed to by ptr. * @param size Size in bytes for the memory block to be allocated or * reallocated. diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/pca.c b/src/add-ons/media/plugins/ffmpeg/libavutil/pca.c index 6891026a5b..ce08e9ccb4 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/pca.c +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/pca.c @@ -20,7 +20,7 @@ */ /** - * @file libavutil/pca.c + * @file * principal component analysis (PCA) */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/pca.h b/src/add-ons/media/plugins/ffmpeg/libavutil/pca.h index f339f2b5d6..00ddd60c7e 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/pca.h +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/pca.h @@ -20,7 +20,7 @@ */ /** - * @file libavutil/pca.h + * @file * principal component analysis (PCA) */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/pixdesc.c b/src/add-ons/media/plugins/ffmpeg/libavutil/pixdesc.c similarity index 62% rename from src/add-ons/media/plugins/ffmpeg/libavcodec/pixdesc.c rename to src/add-ons/media/plugins/ffmpeg/libavutil/pixdesc.c index a313c95cf1..82b3631e4a 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/pixdesc.c +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/pixdesc.c @@ -19,13 +19,93 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libavutil/pixfmt.h" +#include "pixfmt.h" #include "pixdesc.h" +#include "intreadwrite.h" + +void read_line(uint16_t *dst, const uint8_t *data[4], const int linesize[4], + const AVPixFmtDescriptor *desc, int x, int y, int c, int w, int read_pal_component) +{ + AVComponentDescriptor comp= desc->comp[c]; + int plane= comp.plane; + int depth= comp.depth_minus1+1; + int mask = (1<flags; + + if (flags & PIX_FMT_BITSTREAM){ + int skip = x*step + comp.offset_plus1-1; + const uint8_t *p = data[plane] + y*linesize[plane] + (skip>>3); + int shift = 8 - depth - (skip&7); + + while(w--){ + int val = (*p >> shift) & mask; + if(read_pal_component) + val= data[1][4*val + c]; + shift -= step; + p -= shift>>3; + shift &= 7; + *dst++= val; + } + } else { + const uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1-1; + + while(w--){ + int val; + if(flags & PIX_FMT_BE) val= AV_RB16(p); + else val= AV_RL16(p); + val = (val>>shift) & mask; + if(read_pal_component) + val= data[1][4*val + c]; + p+= step; + *dst++= val; + } + } +} + +void write_line(const uint16_t *src, uint8_t *data[4], const int linesize[4], + const AVPixFmtDescriptor *desc, int x, int y, int c, int w) +{ + AVComponentDescriptor comp = desc->comp[c]; + int plane = comp.plane; + int depth = comp.depth_minus1+1; + int step = comp.step_minus1+1; + int flags = desc->flags; + + if (flags & PIX_FMT_BITSTREAM) { + int skip = x*step + comp.offset_plus1-1; + uint8_t *p = data[plane] + y*linesize[plane] + (skip>>3); + int shift = 8 - depth - (skip&7); + + while (w--) { + *p |= *src++ << shift; + shift -= step; + p -= shift>>3; + shift &= 7; + } + } else { + int shift = comp.shift; + uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1-1; + + while (w--) { + if (flags & PIX_FMT_BE) { + uint16_t val = AV_RB16(p) | (*src++<log2_chroma_w + pixdesc->log2_chroma_h; - for (c = 0; c < pixdesc->nb_channels; c++) { + for (c = 0; c < pixdesc->nb_components; c++) { int s = c==1 || c==2 ? 0 : log2_pixels; bits += (pixdesc->comp[c].depth_minus1+1) << s; } diff --git a/src/add-ons/media/plugins/ffmpeg/libavcodec/pixdesc.h b/src/add-ons/media/plugins/ffmpeg/libavutil/pixdesc.h similarity index 60% rename from src/add-ons/media/plugins/ffmpeg/libavcodec/pixdesc.h rename to src/add-ons/media/plugins/ffmpeg/libavutil/pixdesc.h index e6d2dcd0df..8e4c85d715 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavcodec/pixdesc.h +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/pixdesc.h @@ -19,13 +19,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef AVCODEC_PIXDESC_H -#define AVCODEC_PIXDESC_H +#ifndef AVUTIL_PIXDESC_H +#define AVUTIL_PIXDESC_H #include -#include "libavutil/intreadwrite.h" - typedef struct AVComponentDescriptor{ uint16_t plane :2; ///< which of the 4 planes contains the component @@ -55,13 +53,14 @@ typedef struct AVComponentDescriptor{ */ typedef struct AVPixFmtDescriptor{ const char *name; - uint8_t nb_channels; ///< The number of components each pixel has, (1-4) + uint8_t nb_components; ///< The number of components each pixel has, (1-4) /** * Amount to shift the luma width right to find the chroma width. * For YV12 this is 1 for example. * chroma_width = -((-luma_width) >> log2_chroma_w) * The note above is needed to ensure rounding up. + * This value only refers to the chroma components. */ uint8_t log2_chroma_w; ///< chroma_width = -((-luma_width )>>log2_chroma_w) @@ -70,15 +69,23 @@ typedef struct AVPixFmtDescriptor{ * For YV12 this is 1 for example. * chroma_height= -((-luma_height) >> log2_chroma_h) * The note above is needed to ensure rounding up. + * This value only refers to the chroma components. */ uint8_t log2_chroma_h; uint8_t flags; - AVComponentDescriptor comp[4]; ///< parameters that describe how pixels are packed + + /** + * Parameters that describe how pixels are packed. If the format + * has chroma components, they must be stored in comp[1] and + * comp[2]. + */ + AVComponentDescriptor comp[4]; }AVPixFmtDescriptor; -#define PIX_FMT_BE 1 ///< big-endian +#define PIX_FMT_BE 1 ///< Pixel format is big-endian. #define PIX_FMT_PAL 2 ///< Pixel format has a palette in data[1], values are indexes in this palette. #define PIX_FMT_BITSTREAM 4 ///< All values of a component are bit-wise packed end to end. +#define PIX_FMT_HWACCEL 8 ///< Pixel format is an HW accelerated format. /** * The array of all the pixel format descriptors. @@ -86,8 +93,8 @@ typedef struct AVPixFmtDescriptor{ extern const AVPixFmtDescriptor av_pix_fmt_descriptors[]; /** - * Reads a line from an image, and writes to dst the values of the - * pixel format component c. + * Reads a line from an image, and writes the values of the + * pixel format component c to dst. * * @param data the array containing the pointers to the planes of the image * @param linesizes the array containing the linesizes of the image @@ -97,50 +104,12 @@ extern const AVPixFmtDescriptor av_pix_fmt_descriptors[]; * @param w the width of the line to read, that is the number of * values to write to dst * @param read_pal_component if not zero and the format is a paletted - * format writes to dst the values corresponding to the palette - * component c in data[1], rather than the palette indexes in + * format writes the values corresponding to the palette + * component c in data[1] to dst, rather than the palette indexes in * data[0]. The behavior is undefined if the format is not paletted. */ -static inline void read_line(uint16_t *dst, const uint8_t *data[4], const int linesize[4], - const AVPixFmtDescriptor *desc, int x, int y, int c, int w, int read_pal_component) -{ - AVComponentDescriptor comp= desc->comp[c]; - int plane= comp.plane; - int depth= comp.depth_minus1+1; - int mask = (1<flags; - - if (flags & PIX_FMT_BITSTREAM){ - int skip = x*step + comp.offset_plus1-1; - const uint8_t *p = data[plane] + y*linesize[plane] + (skip>>3); - int shift = 8 - depth - (skip&7); - - while(w--){ - int val = (*p >> shift) & mask; - if(read_pal_component) - val= data[1][4*val + c]; - shift -= step; - p -= shift>>3; - shift &= 7; - *dst++= val; - } - } else { - const uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1-1; - - while(w--){ - int val; - if(flags & PIX_FMT_BE) val= AV_RB16(p); - else val= AV_RL16(p); - val = (val>>shift) & mask; - if(read_pal_component) - val= data[1][4*val + c]; - p+= step; - *dst++= val; - } - } -} +void read_line(uint16_t *dst, const uint8_t *data[4], const int linesize[4], + const AVPixFmtDescriptor *desc, int x, int y, int c, int w, int read_pal_component); /** * Writes the values from src to the pixel format component c of an @@ -156,42 +125,21 @@ static inline void read_line(uint16_t *dst, const uint8_t *data[4], const int li * @param w the width of the line to write, that is the number of * values to write to the image line */ -static inline void write_line(const uint16_t *src, uint8_t *data[4], const int linesize[4], - const AVPixFmtDescriptor *desc, int x, int y, int c, int w) -{ - AVComponentDescriptor comp = desc->comp[c]; - int plane = comp.plane; - int depth = comp.depth_minus1+1; - int step = comp.step_minus1+1; - int flags = desc->flags; +void write_line(const uint16_t *src, uint8_t *data[4], const int linesize[4], + const AVPixFmtDescriptor *desc, int x, int y, int c, int w); - if (flags & PIX_FMT_BITSTREAM) { - int skip = x*step + comp.offset_plus1-1; - uint8_t *p = data[plane] + y*linesize[plane] + (skip>>3); - int shift = 8 - depth - (skip&7); - - while (w--) { - *p |= *src++ << shift; - shift -= step; - p -= shift>>3; - shift &= 7; - } - } else { - int shift = comp.shift; - uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1-1; - - while (w--) { - if (flags & PIX_FMT_BE) { - uint16_t val = AV_RB16(p) | (*src++< */ @@ -98,6 +98,8 @@ AVRational av_d2q(double d, int max){ #define LOG2 0.69314718055994530941723212145817656807550013436025 int exponent= FFMAX( (int)(log(fabs(d) + 1e-20)/LOG2), 0); int64_t den= 1LL << (61 - exponent); + if (isnan(d)) + return (AVRational){0,0}; av_reduce(&a.num, &a.den, (int64_t)(d * den + 0.5), den, max); return a; diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/rational.h b/src/add-ons/media/plugins/ffmpeg/libavutil/rational.h index 0f415edf94..4d91f7baee 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/rational.h +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/rational.h @@ -20,7 +20,7 @@ */ /** - * @file libavutil/rational.h + * @file * rational numbers * @author Michael Niedermayer */ @@ -29,7 +29,7 @@ #define AVUTIL_RATIONAL_H #include -#include "common.h" +#include "attributes.h" /** * rational number numerator/denominator diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/sha.c b/src/add-ons/media/plugins/ffmpeg/libavutil/sha.c index 3107deeffe..5a3b57535f 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/sha.c +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/sha.c @@ -21,10 +21,12 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "common.h" +#include #include "avutil.h" #include "bswap.h" #include "sha.h" +#include "sha1.h" +#include "intreadwrite.h" /** hash context */ typedef struct AVSHA { @@ -319,7 +321,7 @@ void av_sha_final(AVSHA* ctx, uint8_t *digest) av_sha_update(ctx, "", 1); av_sha_update(ctx, (uint8_t *)&finalcount, 8); /* Should cause a transform() */ for (i = 0; i < ctx->digest_len; i++) - ((uint32_t*)digest)[i] = be2me_32(ctx->state[i]); + AV_WB32(digest + i*4, ctx->state[i]); } #if LIBAVUTIL_VERSION_MAJOR < 51 diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/timer.h b/src/add-ons/media/plugins/ffmpeg/libavutil/timer.h index db0abaec68..cd8fba8ded 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/timer.h +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/timer.h @@ -1,5 +1,5 @@ /** - * @file libavutil/timer.h + * @file * high precision timer, useful to profile code * * copyright (c) 2006 Michael Niedermayer diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/tree.c b/src/add-ons/media/plugins/ffmpeg/libavutil/tree.c index cce1d31090..8769c76b0f 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/tree.c +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/tree.c @@ -18,7 +18,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "common.h" #include "log.h" #include "tree.h" @@ -135,13 +134,14 @@ void av_tree_destroy(AVTreeNode *t){ } } -#if 0 -void av_tree_enumerate(AVTreeNode *t, void *opaque, int (*f)(void *opaque, void *elem)){ - int v= f(opaque, t->elem); - if(v>=0) av_tree_enumerate(t->child[0], opaque, f); - if(v<=0) av_tree_enumerate(t->child[1], opaque, f); +void av_tree_enumerate(AVTreeNode *t, void *opaque, int (*cmp)(void *opaque, void *elem), int (*enu)(void *opaque, void *elem)){ + if(t){ + int v= cmp ? cmp(opaque, t->elem) : 0; + if(v>=0) av_tree_enumerate(t->child[0], opaque, cmp, enu); + if(v==0) enu(opaque, t->elem); + if(v<=0) av_tree_enumerate(t->child[1], opaque, cmp, enu); + } } -#endif #ifdef TEST diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/tree.h b/src/add-ons/media/plugins/ffmpeg/libavutil/tree.h index e96d1fa12e..dde2f10565 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/tree.h +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/tree.h @@ -19,7 +19,7 @@ */ /** - * @file libavutil/tree.h + * @file * A tree container. * Insertion, removal, finding equal, largest which is smaller than and * smallest which is larger than, all have O(log n) worst case complexity. @@ -79,4 +79,17 @@ void *av_tree_find(const struct AVTreeNode *root, void *key, int (*cmp)(void *ke void *av_tree_insert(struct AVTreeNode **rootp, void *key, int (*cmp)(void *key, const void *b), struct AVTreeNode **next); void av_tree_destroy(struct AVTreeNode *t); +/** + * Applies enu(opaque, &elem) to all the elements in the tree in a given range. + * + * @param cmp a comparison function that returns < 0 for a element below the + * range, > 0 for a element above the range and == 0 for a + * element inside the range + * + * @note The cmp function should use the same ordering used to construct the + * tree. + */ +void av_tree_enumerate(struct AVTreeNode *t, void *opaque, int (*cmp)(void *opaque, void *elem), int (*enu)(void *opaque, void *elem)); + + #endif /* AVUTIL_TREE_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/utils.c b/src/add-ons/media/plugins/ffmpeg/libavutil/utils.c index 2521d3401e..8a1d32e167 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/utils.c +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/utils.c @@ -16,10 +16,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "config.h" #include "avutil.h" /** - * @file libavutil/utils.c + * @file * various utility functions */ @@ -27,3 +28,14 @@ unsigned avutil_version(void) { return LIBAVUTIL_VERSION_INT; } + +const char *avutil_configuration(void) +{ + return FFMPEG_CONFIGURATION; +} + +const char *avutil_license(void) +{ +#define LICENSE_PREFIX "libavutil license: " + return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1; +} diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/x86/bswap.h b/src/add-ons/media/plugins/ffmpeg/libavutil/x86/bswap.h index 3eeb5a4697..26dc4e2bfe 100644 --- a/src/add-ons/media/plugins/ffmpeg/libavutil/x86/bswap.h +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/x86/bswap.h @@ -17,7 +17,7 @@ */ /** - * @file libavutil/x86/bswap.h + * @file * byte swapping routines */ @@ -26,7 +26,7 @@ #include #include "config.h" -#include "libavutil/common.h" +#include "libavutil/attributes.h" #define bswap_16 bswap_16 static av_always_inline av_const uint16_t bswap_16(uint16_t x) diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/x86/intmath.h b/src/add-ons/media/plugins/ffmpeg/libavutil/x86/intmath.h new file mode 100644 index 0000000000..f3acddc0e3 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/x86/intmath.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2010 Mans Rullgard + * + * 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_X86_INTMATH_H +#define AVUTIL_X86_INTMATH_H + +#define FASTDIV(a,b) \ + ({\ + int ret, dmy;\ + __asm__ volatile(\ + "mull %3"\ + :"=d"(ret), "=a"(dmy)\ + :"1"(a), "g"(ff_inverse[b])\ + );\ + ret;\ + }) + +#endif /* AVUTIL_X86_INTMATH_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libavutil/x86/intreadwrite.h b/src/add-ons/media/plugins/ffmpeg/libavutil/x86/intreadwrite.h new file mode 100644 index 0000000000..4061d19231 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libavutil/x86/intreadwrite.h @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2010 Alexander Strange + * + * 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_X86_INTREADWRITE_H +#define AVUTIL_X86_INTREADWRITE_H + +#include +#include "config.h" +#include "libavutil/attributes.h" + +#if HAVE_MMX + +#if !HAVE_FAST_64BIT && defined(__MMX__) + +#define AV_COPY64 AV_COPY64 +static av_always_inline void AV_COPY64(void *d, const void *s) +{ + __asm__("movq %1, %%mm0 \n\t" + "movq %%mm0, %0 \n\t" + : "=m"(*(uint64_t*)d) + : "m" (*(const uint64_t*)s) + : "mm0"); +} + +#define AV_SWAP64 AV_SWAP64 +static av_always_inline void AV_SWAP64(void *a, void *b) +{ + __asm__("movq %1, %%mm0 \n\t" + "movq %0, %%mm1 \n\t" + "movq %%mm0, %0 \n\t" + "movq %%mm1, %1 \n\t" + : "+m"(*(uint64_t*)a), "+m"(*(uint64_t*)b) + ::"mm0", "mm1"); +} + +#define AV_ZERO64 AV_ZERO64 +static av_always_inline void AV_ZERO64(void *d) +{ + __asm__("pxor %%mm0, %%mm0 \n\t" + "movq %%mm0, %0 \n\t" + : "=m"(*(uint64_t*)d) + :: "mm0"); +} + +#endif /* !HAVE_FAST_64BIT && defined(__MMX__) */ + +#ifdef __SSE__ + +#define AV_COPY128 AV_COPY128 +static av_always_inline void AV_COPY128(void *d, const void *s) +{ + struct v {uint64_t v[2];}; + + __asm__("movaps %1, %%xmm0 \n\t" + "movaps %%xmm0, %0 \n\t" + : "=m"(*(struct v*)d) + : "m" (*(const struct v*)s) + : "xmm0"); +} + +#endif /* __SSE__ */ + +#ifdef __SSE2__ + +#define AV_ZERO128 AV_ZERO128 +static av_always_inline void AV_ZERO128(void *d) +{ + struct v {uint64_t v[2];}; + + __asm__("pxor %%xmm0, %%xmm0 \n\t" + "movdqa %%xmm0, %0 \n\t" + : "=m"(*(struct v*)d) + :: "xmm0"); +} + +#endif /* __SSE2__ */ + +#endif /* HAVE_MMX */ + +#endif /* AVUTIL_X86_INTREADWRITE_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libswscale/Jamfile b/src/add-ons/media/plugins/ffmpeg/libswscale/Jamfile index e8a65761fa..d52c89e35a 100644 --- a/src/add-ons/media/plugins/ffmpeg/libswscale/Jamfile +++ b/src/add-ons/media/plugins/ffmpeg/libswscale/Jamfile @@ -30,6 +30,7 @@ StaticLibrary libswscale.a : options.c rgb2rgb.c swscale.c + utils.c yuv2rgb.c $(archSources) diff --git a/src/add-ons/media/plugins/ffmpeg/libswscale/bfin/internal_bfin.S b/src/add-ons/media/plugins/ffmpeg/libswscale/bfin/internal_bfin.S new file mode 100644 index 0000000000..5af46540a8 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libswscale/bfin/internal_bfin.S @@ -0,0 +1,613 @@ +/* + * Copyright (C) 2007 Marc Hoffman + * April 20, 2007 + * + * Blackfin video color space converter operations + * convert I420 YV12 to RGB in various formats + * + * 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 + */ + + +/* +YUV420 to RGB565 conversion. This routine takes a YUV 420 planar macroblock +and converts it to RGB565. R:5 bits, G:6 bits, B:5 bits.. packed into shorts. + + +The following calculation is used for the conversion: + + r = clipz((y-oy)*cy + crv*(v-128)) + g = clipz((y-oy)*cy + cgv*(v-128) + cgu*(u-128)) + b = clipz((y-oy)*cy + cbu*(u-128)) + +y,u,v are prescaled by a factor of 4 i.e. left-shifted to gain precision. + + +New factorization to eliminate the truncation error which was +occurring due to the byteop3p. + + +1) Use the bytop16m to subtract quad bytes we use this in U8 this + then so the offsets need to be renormalized to 8bits. + +2) Scale operands up by a factor of 4 not 8 because Blackfin + multiplies include a shift. + +3) Compute into the accumulators cy*yx0, cy*yx1. + +4) Compute each of the linear equations: + r = clipz((y - oy) * cy + crv * (v - 128)) + + g = clipz((y - oy) * cy + cgv * (v - 128) + cgu * (u - 128)) + + b = clipz((y - oy) * cy + cbu * (u - 128)) + + Reuse of the accumulators requires that we actually multiply + twice once with addition and the second time with a subtraction. + + Because of this we need to compute the equations in the order R B + then G saving the writes for B in the case of 24/32 bit color + formats. + + API: yuv2rgb_kind (uint8_t *Y, uint8_t *U, uint8_t *V, int *out, + int dW, uint32_t *coeffs); + + A B + --- --- + i2 = cb i3 = cr + i1 = coeff i0 = y + +Where coeffs have the following layout in memory. + +uint32_t oy,oc,zero,cy,crv,rmask,cbu,bmask,cgu,cgv; + +coeffs is a pointer to oy. + +The {rgb} masks are only utilized by the 565 packing algorithm. Note the data +replication is used to simplify the internal algorithms for the dual Mac +architecture of BlackFin. + +All routines are exported with _ff_bfin_ as a symbol prefix. + +Rough performance gain compared against -O3: + +2779809/1484290 187.28% + +which translates to ~33c/pel to ~57c/pel for the reference vs 17.5 +c/pel for the optimized implementations. Not sure why there is such a +huge variation on the reference codes on Blackfin I guess it must have +to do with the memory system. +*/ + +#define mL3 .text +#if defined(__FDPIC__) && CONFIG_SRAM +#define mL1 .l1.text +#else +#define mL1 mL3 +#endif +#define MEM mL1 + +#define DEFUN(fname,where,interface) \ + .section where; \ + .global _ff_bfin_ ## fname; \ + .type _ff_bfin_ ## fname, STT_FUNC; \ + .align 8; \ + _ff_bfin_ ## fname + +#define DEFUN_END(fname) \ + .size _ff_bfin_ ## fname, . - _ff_bfin_ ## fname + + +.text + +#define COEFF_LEN 11*4 +#define COEFF_REL_CY_OFF 4*4 + +#define ARG_OUT 20 +#define ARG_W 24 +#define ARG_COEFF 28 + +DEFUN(yuv2rgb565_line,MEM, + (uint8_t *Y, uint8_t *U, uint8_t *V, int *out, int dW, uint32_t *coeffs)): + link 0; + [--sp] = (r7:4); + p1 = [fp+ARG_OUT]; + r3 = [fp+ARG_W]; + + i0 = r0; + i2 = r1; + i3 = r2; + + r0 = [fp+ARG_COEFF]; + i1 = r0; + b1 = i1; + l1 = COEFF_LEN; + m0 = COEFF_REL_CY_OFF; + p0 = r3; + + r0 = [i0++]; // 2Y + r1.l = w[i2++]; // 2u + r1.h = w[i3++]; // 2v + p0 = p0>>2; + + lsetup (.L0565, .L1565) lc0 = p0; + + /* + uint32_t oy,oc,zero,cy,crv,rmask,cbu,bmask,cgu,cgv + r0 -- used to load 4ys + r1 -- used to load 2us,2vs + r4 -- y3,y2 + r5 -- y1,y0 + r6 -- u1,u0 + r7 -- v1,v0 + */ + r2=[i1++]; // oy +.L0565: + /* + rrrrrrrr gggggggg bbbbbbbb + 5432109876543210 + bbbbb >>3 + gggggggg <<3 + rrrrrrrr <<8 + rrrrrggggggbbbbb + */ + (r4,r5) = byteop16m (r1:0, r3:2) || r3=[i1++]; // oc + (r7,r6) = byteop16m (r1:0, r3:2) (r); + r5 = r5 << 2 (v); // y1,y0 + r4 = r4 << 2 (v); // y3,y2 + r6 = r6 << 2 (v) || r0=[i1++]; // u1,u0, r0=zero + r7 = r7 << 2 (v) || r1=[i1++]; // v1,v0 r1=cy + /* Y' = y*cy */ + a1 = r1.h*r5.h, a0 = r1.l*r5.l || r1=[i1++]; // crv + + /* R = Y+ crv*(Cr-128) */ + r2.h = (a1 += r1.h*r7.l), r2.l = (a0 += r1.l*r7.l); + a1 -= r1.h*r7.l, a0 -= r1.l*r7.l || r5=[i1++]; // rmask + r2 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cbu + r2 = r2 >> 3 (v); + r3 = r2 & r5; + + /* B = Y+ cbu*(Cb-128) */ + r2.h = (a1 += r1.h*r6.l), r2.l = (a0 += r1.l*r6.l); + a1 -= r1.h*r6.l, a0 -= r1.l*r6.l || r5=[i1++]; // bmask + r2 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cgu + r2 = r2 << 8 (v); + r2 = r2 & r5; + r3 = r3 | r2; + + /* G = Y+ cgu*(Cb-128)+cgv*(Cr-128) */ + a1 += r1.h*r6.l, a0 += r1.l*r6.l || r1=[i1++]; // cgv + r2.h = (a1 += r1.h*r7.l), r2.l = (a0 += r1.l*r7.l); + r2 = byteop3p(r3:2, r1:0)(LO) || r5=[i1++m0]; // gmask + r2 = r2 << 3 (v); + r2 = r2 & r5; + r3 = r3 | r2; + [p1++]=r3 || r1=[i1++]; // cy + + /* Y' = y*cy */ + + a1 = r1.h*r4.h, a0 = r1.l*r4.l || r1=[i1++]; // crv + + /* R = Y+ crv*(Cr-128) */ + r2.h = (a1 += r1.h*r7.h), r2.l = (a0 += r1.l*r7.h); + a1 -= r1.h*r7.h, a0 -= r1.l*r7.h || r5=[i1++]; // rmask + r2 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cbu + r2 = r2 >> 3 (v); + r3 = r2 & r5; + + /* B = Y+ cbu*(Cb-128) */ + r2.h = (a1 += r1.h*r6.h), r2.l = (a0 += r1.l*r6.h); + a1 -= r1.h*r6.h, a0 -= r1.l*r6.h || r5=[i1++]; // bmask + r2 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cgu + r2 = r2 << 8 (v); + r2 = r2 & r5; + r3 = r3 | r2; + + /* G = Y+ cgu*(Cb-128)+cgv*(Cr-128) */ + a1 += r1.h*r6.h, a0 += r1.l*r6.h || r1=[i1++]; // cgv + r2.h = (a1 += r1.h*r7.h), r2.l = (a0 += r1.l*r7.h) || r5=[i1++]; // gmask + r2 = byteop3p(r3:2, r1:0)(LO) || r0 = [i0++]; // 2Y + r2 = r2 << 3 (v) || r1.l = w[i2++]; // 2u + r2 = r2 & r5; + r3 = r3 | r2; + [p1++]=r3 || r1.h = w[i3++]; // 2v +.L1565: r2=[i1++]; // oy + + l1 = 0; + + (r7:4) = [sp++]; + unlink; + rts; +DEFUN_END(yuv2rgb565_line) + +DEFUN(yuv2rgb555_line,MEM, + (uint8_t *Y, uint8_t *U, uint8_t *V, int *out, int dW, uint32_t *coeffs)): + link 0; + [--sp] = (r7:4); + p1 = [fp+ARG_OUT]; + r3 = [fp+ARG_W]; + + i0 = r0; + i2 = r1; + i3 = r2; + + r0 = [fp+ARG_COEFF]; + i1 = r0; + b1 = i1; + l1 = COEFF_LEN; + m0 = COEFF_REL_CY_OFF; + p0 = r3; + + r0 = [i0++]; // 2Y + r1.l = w[i2++]; // 2u + r1.h = w[i3++]; // 2v + p0 = p0>>2; + + lsetup (.L0555, .L1555) lc0 = p0; + + /* + uint32_t oy,oc,zero,cy,crv,rmask,cbu,bmask,cgu,cgv + r0 -- used to load 4ys + r1 -- used to load 2us,2vs + r4 -- y3,y2 + r5 -- y1,y0 + r6 -- u1,u0 + r7 -- v1,v0 + */ + r2=[i1++]; // oy +.L0555: + /* + rrrrrrrr gggggggg bbbbbbbb + 5432109876543210 + bbbbb >>3 + gggggggg <<2 + rrrrrrrr <<7 + xrrrrrgggggbbbbb + */ + + (r4,r5) = byteop16m (r1:0, r3:2) || r3=[i1++]; // oc + (r7,r6) = byteop16m (r1:0, r3:2) (r); + r5 = r5 << 2 (v); // y1,y0 + r4 = r4 << 2 (v); // y3,y2 + r6 = r6 << 2 (v) || r0=[i1++]; // u1,u0, r0=zero + r7 = r7 << 2 (v) || r1=[i1++]; // v1,v0 r1=cy + /* Y' = y*cy */ + a1 = r1.h*r5.h, a0 = r1.l*r5.l || r1=[i1++]; // crv + + /* R = Y+ crv*(Cr-128) */ + r2.h = (a1 += r1.h*r7.l), r2.l = (a0 += r1.l*r7.l); + a1 -= r1.h*r7.l, a0 -= r1.l*r7.l || r5=[i1++]; // rmask + r2 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cbu + r2 = r2 >> 3 (v); + r3 = r2 & r5; + + /* B = Y+ cbu*(Cb-128) */ + r2.h = (a1 += r1.h*r6.l), r2.l = (a0 += r1.l*r6.l); + a1 -= r1.h*r6.l, a0 -= r1.l*r6.l || r5=[i1++]; // bmask + r2 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cgu + r2 = r2 << 7 (v); + r2 = r2 & r5; + r3 = r3 | r2; + + /* G = Y+ cgu*(Cb-128)+cgv*(Cr-128) */ + a1 += r1.h*r6.l, a0 += r1.l*r6.l || r1=[i1++]; // cgv + r2.h = (a1 += r1.h*r7.l), r2.l = (a0 += r1.l*r7.l); + r2 = byteop3p(r3:2, r1:0)(LO) || r5=[i1++m0]; // gmask + r2 = r2 << 2 (v); + r2 = r2 & r5; + r3 = r3 | r2; + [p1++]=r3 || r1=[i1++]; // cy + + /* Y' = y*cy */ + + a1 = r1.h*r4.h, a0 = r1.l*r4.l || r1=[i1++]; // crv + + /* R = Y+ crv*(Cr-128) */ + r2.h = (a1 += r1.h*r7.h), r2.l = (a0 += r1.l*r7.h); + a1 -= r1.h*r7.h, a0 -= r1.l*r7.h || r5=[i1++]; // rmask + r2 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cbu + r2 = r2 >> 3 (v); + r3 = r2 & r5; + + /* B = Y+ cbu*(Cb-128) */ + r2.h = (a1 += r1.h*r6.h), r2.l = (a0 += r1.l*r6.h); + a1 -= r1.h*r6.h, a0 -= r1.l*r6.h || r5=[i1++]; // bmask + r2 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cgu + r2 = r2 << 7 (v); + r2 = r2 & r5; + r3 = r3 | r2; + + /* G = Y+ cgu*(Cb-128)+cgv*(Cr-128) */ + a1 += r1.h*r6.h, a0 += r1.l*r6.h || r1=[i1++]; // cgv + r2.h = (a1 += r1.h*r7.h), r2.l = (a0 += r1.l*r7.h) || r5=[i1++]; // gmask + r2 = byteop3p(r3:2, r1:0)(LO) || r0=[i0++]; // 4Y + r2 = r2 << 2 (v) || r1.l=w[i2++]; // 2u + r2 = r2 & r5; + r3 = r3 | r2; + [p1++]=r3 || r1.h=w[i3++]; // 2v + +.L1555: r2=[i1++]; // oy + + l1 = 0; + + (r7:4) = [sp++]; + unlink; + rts; +DEFUN_END(yuv2rgb555_line) + +DEFUN(yuv2rgb24_line,MEM, + (uint8_t *Y, uint8_t *U, uint8_t *V, int *out, int dW, uint32_t *coeffs)): + link 0; + [--sp] = (r7:4); + p1 = [fp+ARG_OUT]; + r3 = [fp+ARG_W]; + p2 = p1; + p2 += 3; + + i0 = r0; + i2 = r1; + i3 = r2; + + r0 = [fp+ARG_COEFF]; // coeff buffer + i1 = r0; + b1 = i1; + l1 = COEFF_LEN; + m0 = COEFF_REL_CY_OFF; + p0 = r3; + + r0 = [i0++]; // 2Y + r1.l = w[i2++]; // 2u + r1.h = w[i3++]; // 2v + p0 = p0>>2; + + lsetup (.L0888, .L1888) lc0 = p0; + + /* + uint32_t oy,oc,zero,cy,crv,rmask,cbu,bmask,cgu,cgv + r0 -- used to load 4ys + r1 -- used to load 2us,2vs + r4 -- y3,y2 + r5 -- y1,y0 + r6 -- u1,u0 + r7 -- v1,v0 + */ + r2=[i1++]; // oy +.L0888: + (r4,r5) = byteop16m (r1:0, r3:2) || r3=[i1++]; // oc + (r7,r6) = byteop16m (r1:0, r3:2) (r); + r5 = r5 << 2 (v); // y1,y0 + r4 = r4 << 2 (v); // y3,y2 + r6 = r6 << 2 (v) || r0=[i1++]; // u1,u0, r0=zero + r7 = r7 << 2 (v) || r1=[i1++]; // v1,v0 r1=cy + + /* Y' = y*cy */ + a1 = r1.h*r5.h, a0 = r1.l*r5.l || r1=[i1++]; // crv + + /* R = Y+ crv*(Cr-128) */ + r2.h = (a1 += r1.h*r7.l), r2.l = (a0 += r1.l*r7.l); + a1 -= r1.h*r7.l, a0 -= r1.l*r7.l || r5=[i1++]; // rmask + r2 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cbu + r2=r2>>16 || B[p1++]=r2; + B[p2++]=r2; + + /* B = Y+ cbu*(Cb-128) */ + r2.h = (a1 += r1.h*r6.l), r2.l = (a0 += r1.l*r6.l); + a1 -= r1.h*r6.l, a0 -= r1.l*r6.l || r5=[i1++]; // bmask + r3 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cgu + + /* G = Y+ cgu*(Cb-128)+cgv*(Cr-128) */ + a1 += r1.h*r6.l, a0 += r1.l*r6.l || r1=[i1++]; // cgv + r2.h = (a1 += r1.h*r7.l), r2.l = (a0 += r1.l*r7.l); + r2 = byteop3p(r3:2, r1:0)(LO) || r5=[i1++m0]; // gmask, oy,cy,zero + + r2=r2>>16 || B[p1++]=r2; + B[p2++]=r2; + + r3=r3>>16 || B[p1++]=r3; + B[p2++]=r3 || r1=[i1++]; // cy + + p1+=3; + p2+=3; + /* Y' = y*cy */ + a1 = r1.h*r4.h, a0 = r1.l*r4.l || r1=[i1++]; // crv + + /* R = Y+ crv*(Cr-128) */ + r2.h = (a1 += r1.h*r7.h), r2.l = (a0 += r1.l*r7.h); + a1 -= r1.h*r7.h, a0 -= r1.l*r7.h || r5=[i1++]; // rmask + r2 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cbu + r2=r2>>16 || B[p1++]=r2; + B[p2++]=r2; + + /* B = Y+ cbu*(Cb-128) */ + r2.h = (a1 += r1.h*r6.h), r2.l = (a0 += r1.l*r6.h); + a1 -= r1.h*r6.h, a0 -= r1.l*r6.h || r5=[i1++]; // bmask + r3 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cgu + + /* G = Y+ cgu*(Cb-128)+cgv*(Cr-128) */ + a1 += r1.h*r6.h, a0 += r1.l*r6.h || r1=[i1++]; // cgv + r2.h = (a1 += r1.h*r7.h), r2.l = (a0 += r1.l*r7.h); + r2 = byteop3p(r3:2, r1:0)(LO) || r5=[i1++]; // gmask + r2=r2>>16 || B[p1++]=r2 || r0 = [i0++]; // 4y + B[p2++]=r2 || r1.l = w[i2++]; // 2u + r3=r3>>16 || B[p1++]=r3 || r1.h = w[i3++]; // 2v + B[p2++]=r3 || r2=[i1++]; // oy + + p1+=3; +.L1888: p2+=3; + + l1 = 0; + + (r7:4) = [sp++]; + unlink; + rts; +DEFUN_END(yuv2rgb24_line) + + + +#define ARG_vdst 20 +#define ARG_width 24 +#define ARG_height 28 +#define ARG_lumStride 32 +#define ARG_chromStride 36 +#define ARG_srcStride 40 + +DEFUN(uyvytoyv12, mL3, (const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, + long width, long height, + long lumStride, long chromStride, long srcStride)): + link 0; + [--sp] = (r7:4,p5:4); + + p0 = r1; // Y top even + + i2 = r2; // *u + r2 = [fp + ARG_vdst]; + i3 = r2; // *v + + r1 = [fp + ARG_srcStride]; + r2 = r0 + r1; + i0 = r0; // uyvy_T even + i1 = r2; // uyvy_B odd + + p2 = [fp + ARG_lumStride]; + p1 = p0 + p2; // Y bot odd + + p5 = [fp + ARG_width]; + p4 = [fp + ARG_height]; + r0 = p5; + p4 = p4 >> 1; + p5 = p5 >> 2; + + r2 = r0 << 1; + r1 = r1 << 1; + r1 = r1 - r2; // srcStride + (srcStride - 2*width) + r1 += -8; // i0,i1 is pre read need to correct + m0 = r1; + + r2 = [fp + ARG_chromStride]; + r0 = r0 >> 1; + r2 = r2 - r0; + m1 = r2; + + /* I0,I1 - src input line pointers + * p0,p1 - luma output line pointers + * I2 - dstU + * I3 - dstV + */ + + lsetup (0f, 1f) lc1 = p4; // H/2 +0: r0 = [i0++] || r2 = [i1++]; + r1 = [i0++] || r3 = [i1++]; + r4 = byteop1p(r1:0, r3:2); + r5 = byteop1p(r1:0, r3:2) (r); + lsetup (2f, 3f) lc0 = p5; // W/4 +2: r0 = r0 >> 8(v); + r1 = r1 >> 8(v); + r2 = r2 >> 8(v); + r3 = r3 >> 8(v); + r0 = bytepack(r0, r1); + r2 = bytepack(r2, r3) || [p0++] = r0; // yyyy + r6 = pack(r5.l, r4.l) || [p1++] = r2; // yyyy + r7 = pack(r5.h, r4.h) || r0 = [i0++] || r2 = [i1++]; + r6 = bytepack(r6, r7) || r1 = [i0++] || r3 = [i1++]; + r4 = byteop1p(r1:0, r3:2) || w[i2++] = r6.l; // uu +3: r5 = byteop1p(r1:0, r3:2) (r) || w[i3++] = r6.h; // vv + + i0 += m0; + i1 += m0; + i2 += m1; + i3 += m1; + p0 = p0 + p2; +1: p1 = p1 + p2; + + (r7:4,p5:4) = [sp++]; + unlink; + rts; +DEFUN_END(uyvytoyv12) + +DEFUN(yuyvtoyv12, mL3, (const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, + long width, long height, + long lumStride, long chromStride, long srcStride)): + link 0; + [--sp] = (r7:4,p5:4); + + p0 = r1; // Y top even + + i2 = r2; // *u + r2 = [fp + ARG_vdst]; + i3 = r2; // *v + + r1 = [fp + ARG_srcStride]; + r2 = r0 + r1; + + i0 = r0; // uyvy_T even + i1 = r2; // uyvy_B odd + + p2 = [fp + ARG_lumStride]; + p1 = p0 + p2; // Y bot odd + + p5 = [fp + ARG_width]; + p4 = [fp + ARG_height]; + r0 = p5; + p4 = p4 >> 1; + p5 = p5 >> 2; + + r2 = r0 << 1; + r1 = r1 << 1; + r1 = r1 - r2; // srcStride + (srcStride - 2*width) + r1 += -8; // i0,i1 is pre read need to correct + m0 = r1; + + r2 = [fp + ARG_chromStride]; + r0 = r0 >> 1; + r2 = r2 - r0; + m1 = r2; + + /* I0,I1 - src input line pointers + * p0,p1 - luma output line pointers + * I2 - dstU + * I3 - dstV + */ + + lsetup (0f, 1f) lc1 = p4; // H/2 +0: r0 = [i0++] || r2 = [i1++]; + r1 = [i0++] || r3 = [i1++]; + r4 = bytepack(r0, r1); + r5 = bytepack(r2, r3); + lsetup (2f, 3f) lc0 = p5; // W/4 +2: r0 = r0 >> 8(v) || [p0++] = r4; // yyyy-even + r1 = r1 >> 8(v) || [p1++] = r5; // yyyy-odd + r2 = r2 >> 8(v); + r3 = r3 >> 8(v); + r4 = byteop1p(r1:0, r3:2); + r5 = byteop1p(r1:0, r3:2) (r); + r6 = pack(r5.l, r4.l); + r7 = pack(r5.h, r4.h) || r0 = [i0++] || r2 = [i1++]; + r6 = bytepack(r6, r7) || r1 = [i0++] || r3 = [i1++]; + r4 = bytepack(r0, r1) || w[i2++] = r6.l; // uu +3: r5 = bytepack(r2, r3) || w[i3++] = r6.h; // vv + + i0 += m0; + i1 += m0; + i2 += m1; + i3 += m1; + p0 = p0 + p2; +1: p1 = p1 + p2; + + (r7:4,p5:4) = [sp++]; + unlink; + rts; +DEFUN_END(yuyvtoyv12) diff --git a/src/add-ons/media/plugins/ffmpeg/libswscale/bfin/swscale_bfin.c b/src/add-ons/media/plugins/ffmpeg/libswscale/bfin/swscale_bfin.c new file mode 100644 index 0000000000..ce2f1720dd --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libswscale/bfin/swscale_bfin.c @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2007 Marc Hoffman + * + * Blackfin software video scaler operations + * + * 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 +#include +#include +#include +#include +#include "config.h" +#include +#include "libswscale/rgb2rgb.h" +#include "libswscale/swscale.h" +#include "libswscale/swscale_internal.h" + +#if defined (__FDPIC__) && CONFIG_SRAM +#define L1CODE __attribute__ ((l1_text)) +#else +#define L1CODE +#endif + +int ff_bfin_uyvytoyv12(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, + long width, long height, + long lumStride, long chromStride, long srcStride) L1CODE; + +int ff_bfin_yuyvtoyv12(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, + long width, long height, + long lumStride, long chromStride, long srcStride) L1CODE; + +static int uyvytoyv12_unscaled(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, + int srcSliceH, uint8_t* dst[], int dstStride[]) +{ + uint8_t *dsty = dst[0] + dstStride[0]*srcSliceY; + uint8_t *dstu = dst[1] + dstStride[1]*srcSliceY/2; + uint8_t *dstv = dst[2] + dstStride[2]*srcSliceY/2; + uint8_t *ip = src[0] + srcStride[0]*srcSliceY; + int w = dstStride[0]; + + ff_bfin_uyvytoyv12(ip, dsty, dstu, dstv, w, srcSliceH, + dstStride[0], dstStride[1], srcStride[0]); + + return srcSliceH; +} + +static int yuyvtoyv12_unscaled(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, + int srcSliceH, uint8_t* dst[], int dstStride[]) +{ + uint8_t *dsty = dst[0] + dstStride[0]*srcSliceY; + uint8_t *dstu = dst[1] + dstStride[1]*srcSliceY/2; + uint8_t *dstv = dst[2] + dstStride[2]*srcSliceY/2; + uint8_t *ip = src[0] + srcStride[0]*srcSliceY; + int w = dstStride[0]; + + ff_bfin_yuyvtoyv12(ip, dsty, dstu, dstv, w, srcSliceH, + dstStride[0], dstStride[1], srcStride[0]); + + return srcSliceH; +} + + +void ff_bfin_get_unscaled_swscale(SwsContext *c) +{ + SwsFunc swScale = c->swScale; + if (c->flags & SWS_CPU_CAPS_BFIN) + if (c->dstFormat == PIX_FMT_YUV420P) + if (c->srcFormat == PIX_FMT_UYVY422) { + av_log (NULL, AV_LOG_VERBOSE, "selecting Blackfin optimized uyvytoyv12_unscaled\n"); + c->swScale = uyvytoyv12_unscaled; + } + if (c->dstFormat == PIX_FMT_YUV420P) + if (c->srcFormat == PIX_FMT_YUYV422) { + av_log (NULL, AV_LOG_VERBOSE, "selecting Blackfin optimized yuyvtoyv12_unscaled\n"); + c->swScale = yuyvtoyv12_unscaled; + } +} diff --git a/src/add-ons/media/plugins/ffmpeg/libswscale/bfin/yuv2rgb_bfin.c b/src/add-ons/media/plugins/ffmpeg/libswscale/bfin/yuv2rgb_bfin.c new file mode 100644 index 0000000000..eaa83eaf3b --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libswscale/bfin/yuv2rgb_bfin.c @@ -0,0 +1,203 @@ +/* + * Copyright (C) 2007 Marc Hoffman + * + * Blackfin video color space converter operations + * convert I420 YV12 to RGB in various formats + * + * 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 +#include +#include +#include +#include +#include "config.h" +#include +#include "libswscale/rgb2rgb.h" +#include "libswscale/swscale.h" +#include "libswscale/swscale_internal.h" + +#if defined(__FDPIC__) && CONFIG_SRAM +#define L1CODE __attribute__ ((l1_text)) +#else +#define L1CODE +#endif + +void ff_bfin_yuv2rgb555_line(uint8_t *Y, uint8_t *U, uint8_t *V, uint8_t *out, + int w, uint32_t *coeffs) L1CODE; + +void ff_bfin_yuv2rgb565_line(uint8_t *Y, uint8_t *U, uint8_t *V, uint8_t *out, + int w, uint32_t *coeffs) L1CODE; + +void ff_bfin_yuv2rgb24_line(uint8_t *Y, uint8_t *U, uint8_t *V, uint8_t *out, + int w, uint32_t *coeffs) L1CODE; + +typedef void (* ltransform)(uint8_t *Y, uint8_t *U, uint8_t *V, uint8_t *out, + int w, uint32_t *coeffs); + + +static void bfin_prepare_coefficients(SwsContext *c, int rgb, int masks) +{ + int oy; + oy = c->yOffset&0xffff; + oy = oy >> 3; // keep everything U8.0 for offset calculation + + c->oc = 128*0x01010101U; + c->oy = oy*0x01010101U; + + /* copy 64bit vector coeffs down to 32bit vector coeffs */ + c->cy = c->yCoeff; + c->zero = 0; + + if (rgb) { + c->crv = c->vrCoeff; + c->cbu = c->ubCoeff; + c->cgu = c->ugCoeff; + c->cgv = c->vgCoeff; + } else { + c->crv = c->ubCoeff; + c->cbu = c->vrCoeff; + c->cgu = c->vgCoeff; + c->cgv = c->ugCoeff; + } + + + if (masks == 555) { + c->rmask = 0x001f * 0x00010001U; + c->gmask = 0x03e0 * 0x00010001U; + c->bmask = 0x7c00 * 0x00010001U; + } else if (masks == 565) { + c->rmask = 0x001f * 0x00010001U; + c->gmask = 0x07e0 * 0x00010001U; + c->bmask = 0xf800 * 0x00010001U; + } +} + +static int core_yuv420_rgb(SwsContext *c, + uint8_t **in, int *instrides, + int srcSliceY, int srcSliceH, + uint8_t **oplanes, int *outstrides, + ltransform lcscf, int rgb, int masks) +{ + uint8_t *py,*pu,*pv,*op; + int w = instrides[0]; + int h2 = srcSliceH>>1; + int i; + + bfin_prepare_coefficients(c, rgb, masks); + + py = in[0]; + pu = in[1+(1^rgb)]; + pv = in[1+(0^rgb)]; + + op = oplanes[0] + srcSliceY*outstrides[0]; + + for (i=0;ioy); + + py += instrides[0]; + op += outstrides[0]; + + lcscf(py, pu, pv, op, w, &c->oy); + + py += instrides[0]; + pu += instrides[1]; + pv += instrides[2]; + op += outstrides[0]; + } + + return srcSliceH; +} + + +static int bfin_yuv420_rgb555(SwsContext *c, + uint8_t **in, int *instrides, + int srcSliceY, int srcSliceH, + uint8_t **oplanes, int *outstrides) +{ + return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes, + outstrides, ff_bfin_yuv2rgb555_line, 1, 555); +} + +static int bfin_yuv420_bgr555(SwsContext *c, + uint8_t **in, int *instrides, + int srcSliceY, int srcSliceH, + uint8_t **oplanes, int *outstrides) +{ + return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes, + outstrides, ff_bfin_yuv2rgb555_line, 0, 555); +} + +static int bfin_yuv420_rgb24(SwsContext *c, + uint8_t **in, int *instrides, + int srcSliceY, int srcSliceH, + uint8_t **oplanes, int *outstrides) +{ + return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes, + outstrides, ff_bfin_yuv2rgb24_line, 1, 888); +} + +static int bfin_yuv420_bgr24(SwsContext *c, + uint8_t **in, int *instrides, + int srcSliceY, int srcSliceH, + uint8_t **oplanes, int *outstrides) +{ + return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes, + outstrides, ff_bfin_yuv2rgb24_line, 0, 888); +} + +static int bfin_yuv420_rgb565(SwsContext *c, + uint8_t **in, int *instrides, + int srcSliceY, int srcSliceH, + uint8_t **oplanes, int *outstrides) +{ + return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes, + outstrides, ff_bfin_yuv2rgb565_line, 1, 565); +} + +static int bfin_yuv420_bgr565(SwsContext *c, + uint8_t **in, int *instrides, + int srcSliceY, int srcSliceH, + uint8_t **oplanes, int *outstrides) +{ + return core_yuv420_rgb(c, in, instrides, srcSliceY, srcSliceH, oplanes, + outstrides, ff_bfin_yuv2rgb565_line, 0, 565); +} + + +SwsFunc ff_yuv2rgb_get_func_ptr_bfin(SwsContext *c) +{ + SwsFunc f; + + switch(c->dstFormat) { + case PIX_FMT_RGB555: f = bfin_yuv420_rgb555; break; + case PIX_FMT_BGR555: f = bfin_yuv420_bgr555; break; + case PIX_FMT_RGB565: f = bfin_yuv420_rgb565; break; + case PIX_FMT_BGR565: f = bfin_yuv420_bgr565; break; + case PIX_FMT_RGB24: f = bfin_yuv420_rgb24; break; + case PIX_FMT_BGR24: f = bfin_yuv420_bgr24; break; + default: + return 0; + } + + av_log(c, AV_LOG_INFO, "BlackFin accelerated color space converter %s\n", + sws_format_name (c->dstFormat)); + + return f; +} diff --git a/src/add-ons/media/plugins/ffmpeg/libswscale/mlib/yuv2rgb_mlib.c b/src/add-ons/media/plugins/ffmpeg/libswscale/mlib/yuv2rgb_mlib.c new file mode 100644 index 0000000000..011b0ef5cb --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libswscale/mlib/yuv2rgb_mlib.c @@ -0,0 +1,88 @@ +/* + * software YUV to RGB converter using mediaLib + * + * Copyright (C) 2003 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 + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "libswscale/swscale.h" + +static int mlib_YUV2ARGB420_32(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, + int srcSliceH, uint8_t* dst[], int dstStride[]) +{ + if(c->srcFormat == PIX_FMT_YUV422P) { + srcStride[1] *= 2; + srcStride[2] *= 2; + } + + assert(srcStride[1] == srcStride[2]); + + mlib_VideoColorYUV2ARGB420(dst[0]+srcSliceY*dstStride[0], src[0], src[1], src[2], c->dstW, + srcSliceH, dstStride[0], srcStride[0], srcStride[1]); + return srcSliceH; +} + +static int mlib_YUV2ABGR420_32(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, + int srcSliceH, uint8_t* dst[], int dstStride[]) +{ + if(c->srcFormat == PIX_FMT_YUV422P) { + srcStride[1] *= 2; + srcStride[2] *= 2; + } + + assert(srcStride[1] == srcStride[2]); + + mlib_VideoColorYUV2ABGR420(dst[0]+srcSliceY*dstStride[0], src[0], src[1], src[2], c->dstW, + srcSliceH, dstStride[0], srcStride[0], srcStride[1]); + return srcSliceH; +} + +static int mlib_YUV2RGB420_24(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, + int srcSliceH, uint8_t* dst[], int dstStride[]) +{ + if(c->srcFormat == PIX_FMT_YUV422P) { + srcStride[1] *= 2; + srcStride[2] *= 2; + } + + assert(srcStride[1] == srcStride[2]); + + mlib_VideoColorYUV2RGB420(dst[0]+srcSliceY*dstStride[0], src[0], src[1], src[2], c->dstW, + srcSliceH, dstStride[0], srcStride[0], srcStride[1]); + return srcSliceH; +} + + +SwsFunc ff_yuv2rgb_init_mlib(SwsContext *c) +{ + switch(c->dstFormat) { + case PIX_FMT_RGB24: return mlib_YUV2RGB420_24; + case PIX_FMT_BGR32: return mlib_YUV2ARGB420_32; + case PIX_FMT_RGB32: return mlib_YUV2ABGR420_32; + default: return NULL; + } +} + diff --git a/src/add-ons/media/plugins/ffmpeg/libswscale/ppc/swscale_altivec_template.c b/src/add-ons/media/plugins/ffmpeg/libswscale/ppc/swscale_altivec_template.c index 23da6b0178..a438e4cb37 100644 --- a/src/add-ons/media/plugins/ffmpeg/libswscale/ppc/swscale_altivec_template.c +++ b/src/add-ons/media/plugins/ffmpeg/libswscale/ppc/swscale_altivec_template.c @@ -93,7 +93,7 @@ yuv2yuvX_altivec_real(const int16_t *lumFilter, int16_t **lumSrc, int lumFilterS const vector signed int vini = {(1 << 18), (1 << 18), (1 << 18), (1 << 18)}; register int i, j; { - DECLARE_ALIGNED(16, int, val[dstW]); + DECLARE_ALIGNED(16, int, val)[dstW]; for (i = 0; i < (dstW -7); i+=4) { vec_st(vini, i << 2, val); @@ -141,8 +141,8 @@ yuv2yuvX_altivec_real(const int16_t *lumFilter, int16_t **lumSrc, int lumFilterS altivec_packIntArrayToCharArray(val, dest, dstW); } if (uDest != 0) { - DECLARE_ALIGNED(16, int, u[chrDstW]); - DECLARE_ALIGNED(16, int, v[chrDstW]); + 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); @@ -215,7 +215,7 @@ static inline void hScale_altivec_real(int16_t *dst, int dstW, const int16_t *filterPos, int filterSize) { register int i; - DECLARE_ALIGNED(16, int, tempo[4]); + DECLARE_ALIGNED(16, int, tempo)[4]; if (filterSize % 4) { for (i=0; i #include "config.h" @@ -74,7 +71,7 @@ void (*rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *v long lumStride, long chromStride, long srcStride); void (*planar2x)(const uint8_t *src, uint8_t *dst, long width, long height, long srcStride, long dstStride); -void (*interleaveBytes)(uint8_t *src1, uint8_t *src2, uint8_t *dst, +void (*interleaveBytes)(const uint8_t *src1, const uint8_t *src2, uint8_t *dst, long width, long height, long src1Stride, long src2Stride, long dstStride); void (*vu9_to_vu12)(const uint8_t *src1, const uint8_t *src2, @@ -101,7 +98,7 @@ void (*yuyvtoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t long lumStride, long chromStride, long srcStride); -#if ARCH_X86 && CONFIG_GPL +#if ARCH_X86 DECLARE_ASM_CONST(8, uint64_t, mmx_null) = 0x0000000000000000ULL; DECLARE_ASM_CONST(8, uint64_t, mmx_one) = 0xFFFFFFFFFFFFFFFFULL; DECLARE_ASM_CONST(8, uint64_t, mask32b) = 0x000000FF000000FFULL; @@ -162,7 +159,7 @@ DECLARE_ASM_CONST(8, uint64_t, blue_15mask) = 0x0000001f0000001fULL; #define RENAME(a) a ## _C #include "rgb2rgb_template.c" -#if ARCH_X86 && CONFIG_GPL +#if ARCH_X86 //MMX versions #undef RENAME @@ -198,7 +195,7 @@ DECLARE_ASM_CONST(8, uint64_t, blue_15mask) = 0x0000001f0000001fULL; void sws_rgb2rgb_init(int flags) { -#if (HAVE_MMX2 || HAVE_AMD3DNOW || HAVE_MMX) && CONFIG_GPL +#if HAVE_MMX2 || HAVE_AMD3DNOW || HAVE_MMX if (flags & SWS_CPU_CAPS_MMX2) rgb2rgb_init_MMX2(); else if (flags & SWS_CPU_CAPS_3DNOW) @@ -210,31 +207,15 @@ void sws_rgb2rgb_init(int flags) rgb2rgb_init_C(); } -/** - * Convert the palette to the same packet 32-bit format as the palette - */ +#if LIBSWSCALE_VERSION_MAJOR < 1 void palette8topacked32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette) { - long i; - - for (i=0; i dst format: ABC - */ void palette8topacked24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette) { - long i; - - for (i=0; i> 2; for (i=0; i BGR24 (= B,G,R) */ - dst[3*i + 0] = src[4*i + 1]; - dst[3*i + 1] = src[4*i + 2]; - dst[3*i + 2] = src[4*i + 3]; - #else - dst[3*i + 0] = src[4*i + 2]; - dst[3*i + 1] = src[4*i + 1]; - dst[3*i + 2] = src[4*i + 0]; - #endif +#if HAVE_BIGENDIAN + /* RGB32 (= A,B,G,R) -> BGR24 (= B,G,R) */ + dst[3*i + 0] = src[4*i + 1]; + dst[3*i + 1] = src[4*i + 2]; + dst[3*i + 2] = src[4*i + 3]; +#else + dst[3*i + 0] = src[4*i + 2]; + dst[3*i + 1] = src[4*i + 1]; + dst[3*i + 2] = src[4*i + 0]; +#endif } } @@ -291,18 +258,18 @@ void rgb24to32(const uint8_t *src, uint8_t *dst, long src_size) { long i; for (i=0; 3*i BGR32 (= A,R,G,B) */ - dst[4*i + 0] = 255; - dst[4*i + 1] = src[3*i + 0]; - dst[4*i + 2] = src[3*i + 1]; - dst[4*i + 3] = src[3*i + 2]; - #else - dst[4*i + 0] = src[3*i + 2]; - dst[4*i + 1] = src[3*i + 1]; - dst[4*i + 2] = src[3*i + 0]; - dst[4*i + 3] = 255; - #endif +#if HAVE_BIGENDIAN + /* RGB24 (= R,G,B) -> BGR32 (= A,R,G,B) */ + dst[4*i + 0] = 255; + dst[4*i + 1] = src[3*i + 0]; + dst[4*i + 2] = src[3*i + 1]; + dst[4*i + 3] = src[3*i + 2]; +#else + dst[4*i + 0] = src[3*i + 2]; + dst[4*i + 1] = src[3*i + 1]; + dst[4*i + 2] = src[3*i + 0]; + dst[4*i + 3] = 255; +#endif } } @@ -315,17 +282,17 @@ void rgb16tobgr32(const uint8_t *src, uint8_t *dst, long src_size) while (s < end) { register uint16_t bgr; bgr = *s++; - #if HAVE_BIGENDIAN - *d++ = 255; - *d++ = (bgr&0x1F)<<3; - *d++ = (bgr&0x7E0)>>3; - *d++ = (bgr&0xF800)>>8; - #else - *d++ = (bgr&0xF800)>>8; - *d++ = (bgr&0x7E0)>>3; - *d++ = (bgr&0x1F)<<3; - *d++ = 255; - #endif +#if HAVE_BIGENDIAN + *d++ = 255; + *d++ = (bgr&0x1F)<<3; + *d++ = (bgr&0x7E0)>>3; + *d++ = (bgr&0xF800)>>8; +#else + *d++ = (bgr&0xF800)>>8; + *d++ = (bgr&0x7E0)>>3; + *d++ = (bgr&0x1F)<<3; + *d++ = 255; +#endif } } @@ -375,17 +342,17 @@ void rgb15tobgr32(const uint8_t *src, uint8_t *dst, long src_size) while (s < end) { register uint16_t bgr; bgr = *s++; - #if HAVE_BIGENDIAN - *d++ = 255; - *d++ = (bgr&0x1F)<<3; - *d++ = (bgr&0x3E0)>>2; - *d++ = (bgr&0x7C00)>>7; - #else - *d++ = (bgr&0x7C00)>>7; - *d++ = (bgr&0x3E0)>>2; - *d++ = (bgr&0x1F)<<3; - *d++ = 255; - #endif +#if HAVE_BIGENDIAN + *d++ = 255; + *d++ = (bgr&0x1F)<<3; + *d++ = (bgr&0x3E0)>>2; + *d++ = (bgr&0x7C00)>>7; +#else + *d++ = (bgr&0x7C00)>>7; + *d++ = (bgr&0x3E0)>>2; + *d++ = (bgr&0x1F)<<3; + *d++ = 255; +#endif } } @@ -442,3 +409,23 @@ void bgr8torgb8(const uint8_t *src, uint8_t *dst, long src_size) dst[i] = ((b<<1)&0x07) | ((g&0x07)<<3) | ((r&0x03)<<6); } } + +#define DEFINE_SHUFFLE_BYTES(a, b, c, d) \ +void shuffle_bytes_##a##b##c##d(const uint8_t *src, uint8_t *dst, long src_size) \ +{ \ + long i; \ + \ + for (i = 0; i < src_size; i+=4) { \ + dst[i + 0] = src[i + a]; \ + dst[i + 1] = src[i + b]; \ + dst[i + 2] = src[i + c]; \ + dst[i + 3] = src[i + d]; \ + } \ +} + +DEFINE_SHUFFLE_BYTES(0, 3, 2, 1); +DEFINE_SHUFFLE_BYTES(1, 2, 3, 0); +DEFINE_SHUFFLE_BYTES(2, 1, 0, 3); +DEFINE_SHUFFLE_BYTES(3, 0, 1, 2); +DEFINE_SHUFFLE_BYTES(3, 2, 1, 0); + diff --git a/src/add-ons/media/plugins/ffmpeg/libswscale/rgb2rgb.h b/src/add-ons/media/plugins/ffmpeg/libswscale/rgb2rgb.h index 9d6e6df415..2e182dd163 100644 --- a/src/add-ons/media/plugins/ffmpeg/libswscale/rgb2rgb.h +++ b/src/add-ons/media/plugins/ffmpeg/libswscale/rgb2rgb.h @@ -4,7 +4,7 @@ * Software YUV to YUV converter * Software YUV to RGB converter * Written by Nick Kurshev. - * palette & YUV & runtime CPU stuff by Michael (michaelni@gmx.at) + * YUV & runtime CPU stuff by Michael (michaelni@gmx.at) * * This file is part of FFmpeg. * @@ -28,6 +28,9 @@ #include +#include "libswscale/swscale.h" +#include "libavutil/avutil.h" + /* A full collection of RGB to RGB(BGR) converters */ extern void (*rgb24tobgr32)(const uint8_t *src, uint8_t *dst, long src_size); extern void (*rgb24tobgr16)(const uint8_t *src, uint8_t *dst, long src_size); @@ -60,13 +63,21 @@ void rgb15tobgr16(const uint8_t *src, uint8_t *dst, long src_size); void rgb15tobgr15(const uint8_t *src, uint8_t *dst, long src_size); void bgr8torgb8 (const uint8_t *src, uint8_t *dst, long src_size); +void shuffle_bytes_0321(const uint8_t *src, uint8_t *dst, long src_size); +void shuffle_bytes_1230(const uint8_t *src, uint8_t *dst, long src_size); +void shuffle_bytes_2103(const uint8_t *src, uint8_t *dst, long src_size); +void shuffle_bytes_3012(const uint8_t *src, uint8_t *dst, long src_size); +void shuffle_bytes_3210(const uint8_t *src, uint8_t *dst, long src_size); -void palette8topacked32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette); -void palette8topacked24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette); -void palette8torgb16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette); -void palette8tobgr16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette); -void palette8torgb15(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette); -void palette8tobgr15(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette); +#if LIBSWSCALE_VERSION_MAJOR < 1 +/* deprecated, use the public versions in swscale.h */ +attribute_deprecated void palette8topacked32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette); +attribute_deprecated void palette8topacked24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette); + +/* totally deprecated, please fix code that uses this */ +attribute_deprecated void palette8torgb16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette); +attribute_deprecated void palette8tobgr16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette); +#endif /** * Height should be a multiple of 2 and width should be a multiple of 16. @@ -126,7 +137,7 @@ extern void (*rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uin extern void (*planar2x)(const uint8_t *src, uint8_t *dst, long width, long height, long srcStride, long dstStride); -extern void (*interleaveBytes)(uint8_t *src1, uint8_t *src2, uint8_t *dst, +extern void (*interleaveBytes)(const uint8_t *src1, const uint8_t *src2, uint8_t *dst, long width, long height, long src1Stride, long src2Stride, long dstStride); diff --git a/src/add-ons/media/plugins/ffmpeg/libswscale/rgb2rgb_template.c b/src/add-ons/media/plugins/ffmpeg/libswscale/rgb2rgb_template.c index 8b5a504da6..d86cafc24a 100644 --- a/src/add-ons/media/plugins/ffmpeg/libswscale/rgb2rgb_template.c +++ b/src/add-ons/media/plugins/ffmpeg/libswscale/rgb2rgb_template.c @@ -9,22 +9,19 @@ * * 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 free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser 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 General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with FFmpeg; if not, write to the Free Software + * 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 - * - * The C code (not assembly, MMX, ...) of this file can be used - * under the LGPL license. */ #include @@ -34,7 +31,6 @@ #undef EMMS #undef SFENCE #undef MMREG_SIZE -#undef PREFETCHW #undef PAVGB #if HAVE_SSE2 @@ -45,15 +41,12 @@ #if HAVE_AMD3DNOW #define PREFETCH "prefetch" -#define PREFETCHW "prefetchw" #define PAVGB "pavgusb" #elif HAVE_MMX2 #define PREFETCH "prefetchnta" -#define PREFETCHW "prefetcht0" #define PAVGB "pavgb" #else #define PREFETCH " # nop" -#define PREFETCHW " # nop" #endif #if HAVE_AMD3DNOW @@ -76,11 +69,11 @@ static inline void RENAME(rgb24tobgr32)(const uint8_t *src, uint8_t *dst, long s uint8_t *dest = dst; const uint8_t *s = src; const uint8_t *end; - #if HAVE_MMX +#if HAVE_MMX const uint8_t *mm_end; - #endif +#endif end = s + src_size; - #if HAVE_MMX +#if HAVE_MMX __asm__ volatile(PREFETCH" %0"::"m"(*s):"memory"); mm_end = end - 23; __asm__ volatile("movq %0, %%mm7"::"m"(mask32a):"memory"); @@ -111,24 +104,61 @@ static inline void RENAME(rgb24tobgr32)(const uint8_t *src, uint8_t *dst, long s } __asm__ volatile(SFENCE:::"memory"); __asm__ volatile(EMMS:::"memory"); - #endif +#endif while (s < end) { - #if HAVE_BIGENDIAN +#if HAVE_BIGENDIAN /* RGB24 (= R,G,B) -> RGB32 (= A,B,G,R) */ *dest++ = 255; *dest++ = s[2]; *dest++ = s[1]; *dest++ = s[0]; s+=3; - #else +#else *dest++ = *s++; *dest++ = *s++; *dest++ = *s++; *dest++ = 255; - #endif +#endif } } +#define STORE_BGR24_MMX \ + "psrlq $8, %%mm2 \n\t" \ + "psrlq $8, %%mm3 \n\t" \ + "psrlq $8, %%mm6 \n\t" \ + "psrlq $8, %%mm7 \n\t" \ + "pand "MANGLE(mask24l)", %%mm0\n\t" \ + "pand "MANGLE(mask24l)", %%mm1\n\t" \ + "pand "MANGLE(mask24l)", %%mm4\n\t" \ + "pand "MANGLE(mask24l)", %%mm5\n\t" \ + "pand "MANGLE(mask24h)", %%mm2\n\t" \ + "pand "MANGLE(mask24h)", %%mm3\n\t" \ + "pand "MANGLE(mask24h)", %%mm6\n\t" \ + "pand "MANGLE(mask24h)", %%mm7\n\t" \ + "por %%mm2, %%mm0 \n\t" \ + "por %%mm3, %%mm1 \n\t" \ + "por %%mm6, %%mm4 \n\t" \ + "por %%mm7, %%mm5 \n\t" \ + \ + "movq %%mm1, %%mm2 \n\t" \ + "movq %%mm4, %%mm3 \n\t" \ + "psllq $48, %%mm2 \n\t" \ + "psllq $32, %%mm3 \n\t" \ + "pand "MANGLE(mask24hh)", %%mm2\n\t" \ + "pand "MANGLE(mask24hhh)", %%mm3\n\t" \ + "por %%mm2, %%mm0 \n\t" \ + "psrlq $16, %%mm1 \n\t" \ + "psrlq $32, %%mm4 \n\t" \ + "psllq $16, %%mm5 \n\t" \ + "por %%mm3, %%mm1 \n\t" \ + "pand "MANGLE(mask24hhhh)", %%mm5\n\t" \ + "por %%mm5, %%mm4 \n\t" \ + \ + MOVNTQ" %%mm0, %0 \n\t" \ + MOVNTQ" %%mm1, 8%0 \n\t" \ + MOVNTQ" %%mm4, 16%0" + + static inline void RENAME(rgb32tobgr24)(const uint8_t *src, uint8_t *dst, long src_size) { uint8_t *dest = dst; @@ -152,43 +182,9 @@ static inline void RENAME(rgb32tobgr24)(const uint8_t *src, uint8_t *dst, long s "movq %%mm1, %%mm3 \n\t" "movq %%mm4, %%mm6 \n\t" "movq %%mm5, %%mm7 \n\t" - "psrlq $8, %%mm2 \n\t" - "psrlq $8, %%mm3 \n\t" - "psrlq $8, %%mm6 \n\t" - "psrlq $8, %%mm7 \n\t" - "pand %2, %%mm0 \n\t" - "pand %2, %%mm1 \n\t" - "pand %2, %%mm4 \n\t" - "pand %2, %%mm5 \n\t" - "pand %3, %%mm2 \n\t" - "pand %3, %%mm3 \n\t" - "pand %3, %%mm6 \n\t" - "pand %3, %%mm7 \n\t" - "por %%mm2, %%mm0 \n\t" - "por %%mm3, %%mm1 \n\t" - "por %%mm6, %%mm4 \n\t" - "por %%mm7, %%mm5 \n\t" - - "movq %%mm1, %%mm2 \n\t" - "movq %%mm4, %%mm3 \n\t" - "psllq $48, %%mm2 \n\t" - "psllq $32, %%mm3 \n\t" - "pand %4, %%mm2 \n\t" - "pand %5, %%mm3 \n\t" - "por %%mm2, %%mm0 \n\t" - "psrlq $16, %%mm1 \n\t" - "psrlq $32, %%mm4 \n\t" - "psllq $16, %%mm5 \n\t" - "por %%mm3, %%mm1 \n\t" - "pand %6, %%mm5 \n\t" - "por %%mm5, %%mm4 \n\t" - - MOVNTQ" %%mm0, %0 \n\t" - MOVNTQ" %%mm1, 8%0 \n\t" - MOVNTQ" %%mm4, 16%0" + STORE_BGR24_MMX :"=m"(*dest) - :"m"(*s),"m"(mask24l), - "m"(mask24h),"m"(mask24hh),"m"(mask24hhh),"m"(mask24hhhh) + :"m"(*s) :"memory"); dest += 24; s += 32; @@ -978,43 +974,10 @@ static inline void RENAME(rgb15tobgr24)(const uint8_t *src, uint8_t *dst, long s "movq %%mm0, %%mm2 \n\t" "movq %%mm1, %%mm3 \n\t" - "psrlq $8, %%mm2 \n\t" - "psrlq $8, %%mm3 \n\t" - "psrlq $8, %%mm6 \n\t" - "psrlq $8, %%mm7 \n\t" - "pand %2, %%mm0 \n\t" - "pand %2, %%mm1 \n\t" - "pand %2, %%mm4 \n\t" - "pand %2, %%mm5 \n\t" - "pand %3, %%mm2 \n\t" - "pand %3, %%mm3 \n\t" - "pand %3, %%mm6 \n\t" - "pand %3, %%mm7 \n\t" - "por %%mm2, %%mm0 \n\t" - "por %%mm3, %%mm1 \n\t" - "por %%mm6, %%mm4 \n\t" - "por %%mm7, %%mm5 \n\t" - - "movq %%mm1, %%mm2 \n\t" - "movq %%mm4, %%mm3 \n\t" - "psllq $48, %%mm2 \n\t" - "psllq $32, %%mm3 \n\t" - "pand %4, %%mm2 \n\t" - "pand %5, %%mm3 \n\t" - "por %%mm2, %%mm0 \n\t" - "psrlq $16, %%mm1 \n\t" - "psrlq $32, %%mm4 \n\t" - "psllq $16, %%mm5 \n\t" - "por %%mm3, %%mm1 \n\t" - "pand %6, %%mm5 \n\t" - "por %%mm5, %%mm4 \n\t" - - MOVNTQ" %%mm0, %0 \n\t" - MOVNTQ" %%mm1, 8%0 \n\t" - MOVNTQ" %%mm4, 16%0" + STORE_BGR24_MMX :"=m"(*d) - :"m"(*s),"m"(mask24l),"m"(mask24h),"m"(mask24hh),"m"(mask24hhh),"m"(mask24hhhh) + :"m"(*s) :"memory"); d += 24; s += 8; @@ -1117,43 +1080,10 @@ static inline void RENAME(rgb16tobgr24)(const uint8_t *src, uint8_t *dst, long s "movq %%mm0, %%mm2 \n\t" "movq %%mm1, %%mm3 \n\t" - "psrlq $8, %%mm2 \n\t" - "psrlq $8, %%mm3 \n\t" - "psrlq $8, %%mm6 \n\t" - "psrlq $8, %%mm7 \n\t" - "pand %2, %%mm0 \n\t" - "pand %2, %%mm1 \n\t" - "pand %2, %%mm4 \n\t" - "pand %2, %%mm5 \n\t" - "pand %3, %%mm2 \n\t" - "pand %3, %%mm3 \n\t" - "pand %3, %%mm6 \n\t" - "pand %3, %%mm7 \n\t" - "por %%mm2, %%mm0 \n\t" - "por %%mm3, %%mm1 \n\t" - "por %%mm6, %%mm4 \n\t" - "por %%mm7, %%mm5 \n\t" - - "movq %%mm1, %%mm2 \n\t" - "movq %%mm4, %%mm3 \n\t" - "psllq $48, %%mm2 \n\t" - "psllq $32, %%mm3 \n\t" - "pand %4, %%mm2 \n\t" - "pand %5, %%mm3 \n\t" - "por %%mm2, %%mm0 \n\t" - "psrlq $16, %%mm1 \n\t" - "psrlq $32, %%mm4 \n\t" - "psllq $16, %%mm5 \n\t" - "por %%mm3, %%mm1 \n\t" - "pand %6, %%mm5 \n\t" - "por %%mm5, %%mm4 \n\t" - - MOVNTQ" %%mm0, %0 \n\t" - MOVNTQ" %%mm1, 8%0 \n\t" - MOVNTQ" %%mm4, 16%0" + STORE_BGR24_MMX :"=m"(*d) - :"m"(*s),"m"(mask24l),"m"(mask24h),"m"(mask24hh),"m"(mask24hhh),"m"(mask24hhhh) + :"m"(*s) :"memory"); d += 24; s += 8; @@ -1436,7 +1366,7 @@ static inline void RENAME(yuvPlanartoyuy2)(const uint8_t *ysrc, const uint8_t *u const x86_reg chromWidth= width>>1; for (y=0; y>1; for (y=0; y {BGR,RGB}{1,4,8,15,16,24,32} + YV12 -> {BGR,RGB}{1,4,8,12,15,16,24,32} x -> x YUV9 -> YV12 YUV9/YV12 -> Y800 @@ -39,7 +36,7 @@ /* tested special converters (most are tested actually, but I did not write it down ...) - YV12 -> BGR16 + YV12 -> BGR12/BGR16 YV12 -> YV12 BGR15 -> BGR16 BGR16 -> BGR16 @@ -54,34 +51,20 @@ untested special converters BGR24 -> YV12 */ -#define _SVID_SOURCE //needed for MAP_ANONYMOUS #include #include #include #include #include "config.h" #include -#if HAVE_SYS_MMAN_H -#include -#if defined(MAP_ANON) && !defined(MAP_ANONYMOUS) -#define MAP_ANONYMOUS MAP_ANON -#endif -#endif -#if HAVE_VIRTUALALLOC -#define WIN32_LEAN_AND_MEAN -#include -#endif #include "swscale.h" #include "swscale_internal.h" #include "rgb2rgb.h" #include "libavutil/intreadwrite.h" #include "libavutil/x86_cpu.h" +#include "libavutil/avutil.h" #include "libavutil/bswap.h" - -unsigned swscale_version(void) -{ - return LIBSWSCALE_VERSION_INT; -} +#include "libavutil/pixdesc.h" #undef MOVNTQ #undef PAVGB @@ -94,91 +77,17 @@ unsigned swscale_version(void) #define FAST_BGR2YV12 // use 7 bit coefficients instead of 15 bit -#define RET 0xC3 //near return opcode for x86 - #ifdef M_PI #define PI M_PI #else #define PI 3.14159265358979323846 #endif -#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_BGR24 \ - || (x)==PIX_FMT_BGR565 \ - || (x)==PIX_FMT_BGR555 \ - || (x)==PIX_FMT_BGR32 \ - || (x)==PIX_FMT_BGR32_1 \ - || (x)==PIX_FMT_RGB24 \ - || (x)==PIX_FMT_RGB565 \ - || (x)==PIX_FMT_RGB555 \ - || (x)==PIX_FMT_GRAY8 \ - || (x)==PIX_FMT_YUV410P \ - || (x)==PIX_FMT_YUV440P \ - || (x)==PIX_FMT_GRAY16BE \ - || (x)==PIX_FMT_GRAY16LE \ - || (x)==PIX_FMT_YUV444P \ - || (x)==PIX_FMT_YUV422P \ - || (x)==PIX_FMT_YUV411P \ - || (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_YUV420PLE \ - || (x)==PIX_FMT_YUV422PLE \ - || (x)==PIX_FMT_YUV444PLE \ - || (x)==PIX_FMT_YUV420PBE \ - || (x)==PIX_FMT_YUV422PBE \ - || (x)==PIX_FMT_YUV444PBE \ - ) -#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 \ - || isRGB(x) \ - || isBGR(x) \ - || (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_YUV420PLE \ - || (x)==PIX_FMT_YUV422PLE \ - || (x)==PIX_FMT_YUV444PLE \ - || (x)==PIX_FMT_YUV420PBE \ - || (x)==PIX_FMT_YUV422PBE \ - || (x)==PIX_FMT_YUV444PBE \ - ) #define isPacked(x) ( \ (x)==PIX_FMT_PAL8 \ || (x)==PIX_FMT_YUYV422 \ || (x)==PIX_FMT_UYVY422 \ - || isRGB(x) \ - || isBGR(x) \ - ) -#define usePal(x) ( \ - (x)==PIX_FMT_PAL8 \ - || (x)==PIX_FMT_BGR4_BYTE \ - || (x)==PIX_FMT_RGB4_BYTE \ - || (x)==PIX_FMT_BGR8 \ - || (x)==PIX_FMT_RGB8 \ + || isAnyRGB(x) \ ) #define RGB2YUV_SHIFT 15 @@ -192,8 +101,6 @@ unsigned swscale_version(void) #define RV ( (int)(0.500*224/255*(1<BGR scaler */ -#if ARCH_X86 && CONFIG_GPL +#if ARCH_X86 DECLARE_ASM_CONST(8, uint64_t, bF8)= 0xF8F8F8F8F8F8F8F8LL; DECLARE_ASM_CONST(8, uint64_t, bFC)= 0xFCFCFCFCFCFCFCFCLL; DECLARE_ASM_CONST(8, uint64_t, w10)= 0x0010001000100010LL; @@ -230,11 +137,11 @@ DECLARE_ASM_CONST(8, uint64_t, bm00000111)=0x0000000000FFFFFFLL; DECLARE_ASM_CONST(8, uint64_t, bm11111000)=0xFFFFFFFFFF000000LL; DECLARE_ASM_CONST(8, uint64_t, bm01010101)=0x00FF00FF00FF00FFLL; -const DECLARE_ALIGNED(8, uint64_t, ff_dither4[2]) = { +const DECLARE_ALIGNED(8, uint64_t, ff_dither4)[2] = { 0x0103010301030103LL, 0x0200020002000200LL,}; -const DECLARE_ALIGNED(8, uint64_t, ff_dither8[2]) = { +const DECLARE_ALIGNED(8, uint64_t, ff_dither8)[2] = { 0x0602060206020602LL, 0x0004000400040004LL,}; @@ -268,31 +175,33 @@ 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_bgr24toUV[2][4]) = { +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; -#endif /* ARCH_X86 && CONFIG_GPL */ +#endif /* ARCH_X86 */ -// clipping helper table for C implementations: -static unsigned char clip_table[768]; - -static SwsVector *sws_getConvVec(SwsVector *a, SwsVector *b); - -DECLARE_ALIGNED(8, static const uint8_t, dither_2x2_4[2][8])={ +DECLARE_ALIGNED(8, static const uint8_t, dither_2x2_4)[2][8]={ { 1, 3, 1, 3, 1, 3, 1, 3, }, { 2, 0, 2, 0, 2, 0, 2, 0, }, }; -DECLARE_ALIGNED(8, static const uint8_t, dither_2x2_8[2][8])={ +DECLARE_ALIGNED(8, static const uint8_t, dither_2x2_8)[2][8]={ { 6, 2, 6, 2, 6, 2, 6, 2, }, { 0, 4, 0, 4, 0, 4, 0, 4, }, }; -DECLARE_ALIGNED(8, const uint8_t, dither_8x8_32[8][8])={ +DECLARE_ALIGNED(8, const uint8_t, dither_4x4_16)[4][8]={ +{ 8, 4, 11, 7, 8, 4, 11, 7, }, +{ 2, 14, 1, 13, 2, 14, 1, 13, }, +{ 10, 6, 9, 5, 10, 6, 9, 5, }, +{ 0, 12, 3, 15, 0, 12, 3, 15, }, +}; + +DECLARE_ALIGNED(8, const uint8_t, dither_8x8_32)[8][8]={ { 17, 9, 23, 15, 16, 8, 22, 14, }, { 5, 29, 3, 27, 4, 28, 2, 26, }, { 21, 13, 19, 11, 20, 12, 18, 10, }, @@ -303,7 +212,7 @@ DECLARE_ALIGNED(8, const uint8_t, dither_8x8_32[8][8])={ { 1, 25, 7, 31, 0, 24, 6, 30, }, }; -DECLARE_ALIGNED(8, const uint8_t, dither_8x8_73[8][8])={ +DECLARE_ALIGNED(8, const uint8_t, dither_8x8_73)[8][8]={ { 0, 55, 14, 68, 3, 58, 17, 72, }, { 37, 18, 50, 32, 40, 22, 54, 35, }, { 9, 64, 5, 59, 13, 67, 8, 63, }, @@ -315,7 +224,7 @@ DECLARE_ALIGNED(8, const uint8_t, dither_8x8_73[8][8])={ }; #if 1 -DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220[8][8])={ +DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220)[8][8]={ {117, 62, 158, 103, 113, 58, 155, 100, }, { 34, 199, 21, 186, 31, 196, 17, 182, }, {144, 89, 131, 76, 141, 86, 127, 72, }, @@ -327,7 +236,7 @@ DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220[8][8])={ }; #elif 1 // tries to correct a gamma of 1.5 -DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220[8][8])={ +DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220)[8][8]={ { 0, 143, 18, 200, 2, 156, 25, 215, }, { 78, 28, 125, 64, 89, 36, 138, 74, }, { 10, 180, 3, 161, 16, 195, 8, 175, }, @@ -339,7 +248,7 @@ DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220[8][8])={ }; #elif 1 // tries to correct a gamma of 2.0 -DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220[8][8])={ +DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220)[8][8]={ { 0, 124, 8, 193, 0, 140, 12, 213, }, { 55, 14, 104, 42, 66, 19, 119, 52, }, { 3, 168, 1, 145, 6, 187, 3, 162, }, @@ -351,7 +260,7 @@ DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220[8][8])={ }; #else // tries to correct a gamma of 2.5 -DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220[8][8])={ +DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220)[8][8]={ { 0, 107, 3, 187, 0, 125, 6, 212, }, { 39, 7, 86, 28, 49, 11, 102, 36, }, { 1, 158, 0, 131, 3, 180, 1, 151, }, @@ -363,118 +272,6 @@ DECLARE_ALIGNED(8, const uint8_t, dither_8x8_220[8][8])={ }; #endif -const char *sws_format_name(enum PixelFormat format) -{ - switch (format) { - case PIX_FMT_YUV420P: - return "yuv420p"; - case PIX_FMT_YUVA420P: - return "yuva420p"; - case PIX_FMT_YUYV422: - return "yuyv422"; - case PIX_FMT_RGB24: - return "rgb24"; - case PIX_FMT_BGR24: - return "bgr24"; - case PIX_FMT_YUV422P: - return "yuv422p"; - case PIX_FMT_YUV444P: - return "yuv444p"; - case PIX_FMT_RGB32: - return "rgb32"; - case PIX_FMT_YUV410P: - return "yuv410p"; - case PIX_FMT_YUV411P: - return "yuv411p"; - case PIX_FMT_RGB565: - return "rgb565"; - case PIX_FMT_RGB555: - return "rgb555"; - case PIX_FMT_GRAY16BE: - return "gray16be"; - case PIX_FMT_GRAY16LE: - return "gray16le"; - case PIX_FMT_GRAY8: - return "gray8"; - case PIX_FMT_MONOWHITE: - return "mono white"; - case PIX_FMT_MONOBLACK: - return "mono black"; - case PIX_FMT_PAL8: - return "Palette"; - case PIX_FMT_YUVJ420P: - return "yuvj420p"; - case PIX_FMT_YUVJ422P: - return "yuvj422p"; - case PIX_FMT_YUVJ444P: - return "yuvj444p"; - case PIX_FMT_XVMC_MPEG2_MC: - return "xvmc_mpeg2_mc"; - case PIX_FMT_XVMC_MPEG2_IDCT: - return "xvmc_mpeg2_idct"; - case PIX_FMT_UYVY422: - return "uyvy422"; - case PIX_FMT_UYYVYY411: - return "uyyvyy411"; - case PIX_FMT_RGB32_1: - return "rgb32x"; - case PIX_FMT_BGR32_1: - return "bgr32x"; - case PIX_FMT_BGR32: - return "bgr32"; - case PIX_FMT_BGR565: - return "bgr565"; - case PIX_FMT_BGR555: - return "bgr555"; - case PIX_FMT_BGR8: - return "bgr8"; - case PIX_FMT_BGR4: - return "bgr4"; - case PIX_FMT_BGR4_BYTE: - return "bgr4 byte"; - case PIX_FMT_RGB8: - return "rgb8"; - case PIX_FMT_RGB4: - return "rgb4"; - case PIX_FMT_RGB4_BYTE: - return "rgb4 byte"; - case PIX_FMT_RGB48BE: - return "rgb48be"; - case PIX_FMT_RGB48LE: - return "rgb48le"; - case PIX_FMT_NV12: - return "nv12"; - case PIX_FMT_NV21: - return "nv21"; - case PIX_FMT_YUV440P: - return "yuv440p"; - case PIX_FMT_VDPAU_H264: - return "vdpau_h264"; - case PIX_FMT_VDPAU_MPEG1: - return "vdpau_mpeg1"; - case PIX_FMT_VDPAU_MPEG2: - return "vdpau_mpeg2"; - case PIX_FMT_VDPAU_WMV3: - return "vdpau_wmv3"; - case PIX_FMT_VDPAU_VC1: - return "vdpau_vc1"; - case PIX_FMT_YUV420PLE: - return "yuv420ple"; - case PIX_FMT_YUV422PLE: - return "yuv422ple"; - case PIX_FMT_YUV444PLE: - return "yuv444ple"; - case PIX_FMT_YUV420PBE: - return "yuv420pbe"; - case PIX_FMT_YUV422PBE: - return "yuv422pbe"; - case PIX_FMT_YUV444PBE: - return "yuv444pbe"; - default: - return "Unknown format"; - } -} - static av_always_inline void yuv2yuvX16inC_template(const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize, const int16_t **alpSrc, uint16_t *dest, uint16_t *uDest, uint16_t *vDest, uint16_t *aDest, @@ -674,7 +471,7 @@ static inline void yuv2nv12XinC(const int16_t *lumFilter, const int16_t **lumSrc }\ A1>>=19;\ A2>>=19;\ - }\ + } #define YSCALE_YUV_2_PACKEDX_C(type,alpha) \ YSCALE_YUV_2_PACKEDX_NOCLIP_C(type,alpha)\ @@ -719,7 +516,7 @@ static inline void yuv2nv12XinC(const int16_t *lumFilter, const int16_t **lumSrc A >>=19;\ if (A&256)\ A = av_clip_uint8(A);\ - }\ + } #define YSCALE_YUV_2_RGBX_FULL_C(rnd,alpha) \ YSCALE_YUV_2_PACKEDX_FULL_C(rnd>>3,alpha)\ @@ -736,8 +533,7 @@ static inline void yuv2nv12XinC(const int16_t *lumFilter, const int16_t **lumSrc else if (G<0)G=0; \ if (B>=(256<<22)) B=(256<<22)-1; \ else if (B<0)B=0; \ - }\ - + } #define YSCALE_YUV_2_GRAY16_C \ for (i=0; i<(dstW>>1); i++) {\ @@ -766,7 +562,7 @@ static inline void yuv2nv12XinC(const int16_t *lumFilter, const int16_t **lumSrc YSCALE_YUV_2_PACKEDX_C(type,alpha) /* FIXME fix tables so that clipping is not needed and then use _NOCLIP*/\ r = (type *)c->table_rV[V]; \ g = (type *)(c->table_gU[U] + c->table_gV[V]); \ - b = (type *)c->table_bU[U]; \ + b = (type *)c->table_bU[U]; #define YSCALE_YUV_2_PACKED2_C(type,alpha) \ for (i=0; i<(dstW>>1); i++) { \ @@ -780,19 +576,19 @@ static inline void yuv2nv12XinC(const int16_t *lumFilter, const int16_t **lumSrc if (alpha) {\ A1= (abuf0[i2 ]*yalpha1+abuf1[i2 ]*yalpha)>>19; \ A2= (abuf0[i2+1]*yalpha1+abuf1[i2+1]*yalpha)>>19; \ - }\ + } #define YSCALE_YUV_2_GRAY16_2_C \ for (i=0; i<(dstW>>1); i++) { \ const int i2= 2*i; \ int Y1= (buf0[i2 ]*yalpha1+buf1[i2 ]*yalpha)>>11; \ - int Y2= (buf0[i2+1]*yalpha1+buf1[i2+1]*yalpha)>>11; \ + int Y2= (buf0[i2+1]*yalpha1+buf1[i2+1]*yalpha)>>11; #define YSCALE_YUV_2_RGB2_C(type,alpha) \ YSCALE_YUV_2_PACKED2_C(type,alpha)\ r = (type *)c->table_rV[V];\ g = (type *)(c->table_gU[U] + c->table_gV[V]);\ - b = (type *)c->table_bU[U];\ + b = (type *)c->table_bU[U]; #define YSCALE_YUV_2_PACKED1_C(type,alpha) \ for (i=0; i<(dstW>>1); i++) {\ @@ -806,19 +602,19 @@ static inline void yuv2nv12XinC(const int16_t *lumFilter, const int16_t **lumSrc if (alpha) {\ A1= abuf0[i2 ]>>7;\ A2= abuf0[i2+1]>>7;\ - }\ + } #define YSCALE_YUV_2_GRAY16_1_C \ for (i=0; i<(dstW>>1); i++) {\ const int i2= 2*i;\ int Y1= buf0[i2 ]<<1;\ - int Y2= buf0[i2+1]<<1;\ + int Y2= buf0[i2+1]<<1; #define YSCALE_YUV_2_RGB1_C(type,alpha) \ YSCALE_YUV_2_PACKED1_C(type,alpha)\ r = (type *)c->table_rV[V];\ g = (type *)(c->table_gU[U] + c->table_gV[V]);\ - b = (type *)c->table_bU[U];\ + b = (type *)c->table_bU[U]; #define YSCALE_YUV_2_PACKED1B_C(type,alpha) \ for (i=0; i<(dstW>>1); i++) {\ @@ -832,13 +628,13 @@ static inline void yuv2nv12XinC(const int16_t *lumFilter, const int16_t **lumSrc if (alpha) {\ A1= abuf0[i2 ]>>7;\ A2= abuf0[i2+1]>>7;\ - }\ + } #define YSCALE_YUV_2_RGB1B_C(type,alpha) \ YSCALE_YUV_2_PACKED1B_C(type,alpha)\ r = (type *)c->table_rV[V];\ g = (type *)(c->table_gU[U] + c->table_gV[V]);\ - b = (type *)c->table_bU[U];\ + b = (type *)c->table_bU[U]; #define YSCALE_YUV_2_MONO2_C \ const uint8_t * const d128=dither_8x8_220[y&7];\ @@ -855,8 +651,7 @@ static inline void yuv2nv12XinC(const int16_t *lumFilter, const int16_t **lumSrc acc+= acc + g[((buf0[i+7]*yalpha1+buf1[i+7]*yalpha)>>19) + d128[7]];\ ((uint8_t*)dest)[0]= c->dstFormat == PIX_FMT_MONOBLACK ? acc : ~acc;\ dest++;\ - }\ - + } #define YSCALE_YUV_2_MONOX_C \ const uint8_t * const d128=dither_8x8_220[y&7];\ @@ -887,7 +682,6 @@ static inline void yuv2nv12XinC(const int16_t *lumFilter, const int16_t **lumSrc }\ } - #define YSCALE_YUV_2_ANYRGB_C(func, func2, func_g16, func_monoblack)\ switch(c->dstFormat) {\ case PIX_FMT_RGB48BE:\ @@ -974,8 +768,10 @@ static inline void yuv2nv12XinC(const int16_t *lumFilter, const int16_t **lumSrc dest+=6;\ }\ break;\ - case PIX_FMT_RGB565:\ - case PIX_FMT_BGR565:\ + case PIX_FMT_RGB565BE:\ + case PIX_FMT_RGB565LE:\ + case PIX_FMT_BGR565BE:\ + case PIX_FMT_BGR565LE:\ {\ const int dr1= dither_2x2_8[y&1 ][0];\ const int dg1= dither_2x2_4[y&1 ][0];\ @@ -989,8 +785,10 @@ static inline void yuv2nv12XinC(const int16_t *lumFilter, const int16_t **lumSrc }\ }\ break;\ - case PIX_FMT_RGB555:\ - case PIX_FMT_BGR555:\ + case PIX_FMT_RGB555BE:\ + case PIX_FMT_RGB555LE:\ + case PIX_FMT_BGR555BE:\ + case PIX_FMT_BGR555LE:\ {\ const int dr1= dither_2x2_8[y&1 ][0];\ const int dg1= dither_2x2_8[y&1 ][1];\ @@ -1004,6 +802,23 @@ static inline void yuv2nv12XinC(const int16_t *lumFilter, const int16_t **lumSrc }\ }\ break;\ + case PIX_FMT_RGB444BE:\ + case PIX_FMT_RGB444LE:\ + case PIX_FMT_BGR444BE:\ + case PIX_FMT_BGR444LE:\ + {\ + const int dr1= dither_4x4_16[y&3 ][0];\ + const int dg1= dither_4x4_16[y&3 ][1];\ + const int db1= dither_4x4_16[(y&3)^3][0];\ + const int dr2= dither_4x4_16[y&3 ][1];\ + const int dg2= dither_4x4_16[y&3 ][0];\ + const int db2= dither_4x4_16[(y&3)^3][1];\ + func(uint16_t,0)\ + ((uint16_t*)dest)[i2+0]= r[Y1+dr1] + g[Y1+dg1] + b[Y1+db1];\ + ((uint16_t*)dest)[i2+1]= r[Y2+dr2] + g[Y2+dg2] + b[Y2+db2];\ + }\ + }\ + break;\ case PIX_FMT_RGB8:\ case PIX_FMT_BGR8:\ {\ @@ -1075,8 +890,7 @@ static inline void yuv2nv12XinC(const int16_t *lumFilter, const int16_t **lumSrc ((uint8_t*)dest)[2*i2+3]= Y2>>8;\ } \ break;\ - }\ - + } static inline void yuv2packedXinC(SwsContext *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize, @@ -1091,7 +905,7 @@ static inline void yuv2rgbXinC_full(SwsContext *c, const int16_t *lumFilter, con const int16_t **alpSrc, uint8_t *dest, int dstW, int y) { int i; - int step= fmt_depth(c->dstFormat)/8; + int step= c->dstFormatBpp/8; int aidx= 3; switch(c->dstFormat) { @@ -1180,7 +994,8 @@ static void fillPlane(uint8_t* plane, int stride, int width, int height, int y, } } -static inline void rgb48ToY(uint8_t *dst, const uint8_t *src, int width) +static inline void rgb48ToY(uint8_t *dst, const uint8_t *src, int width, + uint32_t *unused) { int i; for (i = 0; i < width; i++) { @@ -1193,7 +1008,8 @@ static inline void rgb48ToY(uint8_t *dst, const uint8_t *src, int width) } static inline void rgb48ToUV(uint8_t *dstU, uint8_t *dstV, - uint8_t *src1, uint8_t *src2, int width) + const uint8_t *src1, const uint8_t *src2, + int width, uint32_t *unused) { int i; assert(src1==src2); @@ -1208,7 +1024,8 @@ static inline void rgb48ToUV(uint8_t *dstU, uint8_t *dstV, } static inline void rgb48ToUV_half(uint8_t *dstU, uint8_t *dstV, - uint8_t *src1, uint8_t *src2, int width) + const uint8_t *src1, const uint8_t *src2, + int width, uint32_t *unused) { int i; assert(src1==src2); @@ -1332,30 +1149,29 @@ static inline void monoblack2Y(uint8_t *dst, const uint8_t *src, long width, uin } } - //Note: we have C, MMX, MMX2, 3DNOW versions, there is no 3DNOW+MMX2 one //Plain C versions -#if ((!HAVE_MMX || !CONFIG_GPL) && !HAVE_ALTIVEC) || CONFIG_RUNTIME_CPUDETECT +#if (!HAVE_MMX && !HAVE_ALTIVEC) || CONFIG_RUNTIME_CPUDETECT #define COMPILE_C #endif #if ARCH_PPC -#if HAVE_ALTIVEC || CONFIG_RUNTIME_CPUDETECT +#if HAVE_ALTIVEC #define COMPILE_ALTIVEC #endif #endif //ARCH_PPC #if ARCH_X86 -#if ((HAVE_MMX && !HAVE_AMD3DNOW && !HAVE_MMX2) || CONFIG_RUNTIME_CPUDETECT) && CONFIG_GPL +#if (HAVE_MMX && !HAVE_AMD3DNOW && !HAVE_MMX2) || CONFIG_RUNTIME_CPUDETECT #define COMPILE_MMX #endif -#if (HAVE_MMX2 || CONFIG_RUNTIME_CPUDETECT) && CONFIG_GPL +#if HAVE_MMX2 || CONFIG_RUNTIME_CPUDETECT #define COMPILE_MMX2 #endif -#if ((HAVE_AMD3DNOW && !HAVE_MMX2) || CONFIG_RUNTIME_CPUDETECT) && CONFIG_GPL +#if (HAVE_AMD3DNOW && !HAVE_MMX2) || CONFIG_RUNTIME_CPUDETECT #define COMPILE_3DNOW #endif #endif //ARCH_X86 @@ -1421,525 +1237,12 @@ static inline void monoblack2Y(uint8_t *dst, const uint8_t *src, long width, uin #endif //ARCH_X86 -static double getSplineCoeff(double a, double b, double c, double d, double dist) -{ -// printf("%f %f %f %f %f\n", a,b,c,d,dist); - if (dist<=1.0) return ((d*dist + c)*dist + b)*dist +a; - else return getSplineCoeff( 0.0, - b+ 2.0*c + 3.0*d, - c + 3.0*d, - -b- 3.0*c - 6.0*d, - dist-1.0); -} - -static inline int initFilter(int16_t **outFilter, int16_t **filterPos, int *outFilterSize, int xInc, - int srcW, int dstW, int filterAlign, int one, int flags, - SwsVector *srcFilter, SwsVector *dstFilter, double param[2]) -{ - int i; - int filterSize; - int filter2Size; - int minFilterSize; - int64_t *filter=NULL; - int64_t *filter2=NULL; - const int64_t fone= 1LL<<54; - int ret= -1; -#if ARCH_X86 - if (flags & SWS_CPU_CAPS_MMX) - __asm__ volatile("emms\n\t"::: "memory"); //FIXME this should not be required but it IS (even for non-MMX versions) -#endif - - // NOTE: the +1 is for the MMX scaler which reads over the end - *filterPos = av_malloc((dstW+1)*sizeof(int16_t)); - - if (FFABS(xInc - 0x10000) <10) { // unscaled - int i; - filterSize= 1; - filter= av_mallocz(dstW*sizeof(*filter)*filterSize); - - for (i=0; i>16; - - (*filterPos)[i]= xx; - filter[i]= fone; - xDstInSrc+= xInc; - } - } else if ((xInc <= (1<<16) && (flags&SWS_AREA)) || (flags&SWS_FAST_BILINEAR)) { // bilinear upscale - int i; - int xDstInSrc; - filterSize= 2; - filter= av_malloc(dstW*sizeof(*filter)*filterSize); - - xDstInSrc= xInc/2 - 0x8000; - for (i=0; i>16; - int j; - - (*filterPos)[i]= xx; - //bilinear upscale / linear interpolate / area averaging - for (j=0; j>16); - if (coeff<0) coeff=0; - filter[i*filterSize + j]= coeff; - xx++; - } - xDstInSrc+= xInc; - } - } else { - int xDstInSrc; - int sizeFactor; - - if (flags&SWS_BICUBIC) sizeFactor= 4; - else if (flags&SWS_X) sizeFactor= 8; - else if (flags&SWS_AREA) sizeFactor= 1; //downscale only, for upscale it is bilinear - else if (flags&SWS_GAUSS) sizeFactor= 8; // infinite ;) - else if (flags&SWS_LANCZOS) sizeFactor= param[0] != SWS_PARAM_DEFAULT ? ceil(2*param[0]) : 6; - else if (flags&SWS_SINC) sizeFactor= 20; // infinite ;) - else if (flags&SWS_SPLINE) sizeFactor= 20; // infinite ;) - else if (flags&SWS_BILINEAR) sizeFactor= 2; - else { - sizeFactor= 0; //GCC warning killer - assert(0); - } - - if (xInc <= 1<<16) filterSize= 1 + sizeFactor; // upscale - else filterSize= 1 + (sizeFactor*srcW + dstW - 1)/ dstW; - - if (filterSize > srcW-2) filterSize=srcW-2; - - filter= av_malloc(dstW*sizeof(*filter)*filterSize); - - xDstInSrc= xInc - 0x10000; - for (i=0; i 1<<16) - d= d*dstW/srcW; - floatd= d * (1.0/(1<<30)); - - 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; - coeff *= fone>>(30+24); - } -/* else if (flags & SWS_X) { - double p= param ? param*0.01 : 0.3; - coeff = d ? sin(d*PI)/(d*PI) : 1.0; - coeff*= pow(2.0, - p*d*d); - }*/ - else if (flags & SWS_X) { - double A= param[0] != SWS_PARAM_DEFAULT ? param[0] : 1.0; - double c; - - if (floatd<1.0) - c = cos(floatd*PI); - else - c=-1.0; - if (c<0.0) c= -pow(-c, A); - else c= pow( c, A); - coeff= (c*0.5 + 0.5)*fone; - } else if (flags & SWS_AREA) { - int64_t d2= d - (1<<29); - if (d2*xInc < -(1LL<<(29+16))) coeff= 1.0 * (1LL<<(30+16)); - else if (d2*xInc < (1LL<<(29+16))) coeff= -d2*xInc + (1LL<<(29+16)); - else coeff=0.0; - coeff *= fone>>(30+16); - } else if (flags & SWS_GAUSS) { - double p= param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0; - coeff = (pow(2.0, - p*floatd*floatd))*fone; - } else if (flags & SWS_SINC) { - coeff = (d ? sin(floatd*PI)/(floatd*PI) : 1.0)*fone; - } else if (flags & SWS_LANCZOS) { - double p= param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0; - coeff = (d ? sin(floatd*PI)*sin(floatd*PI/p)/(floatd*floatd*PI*PI/p) : 1.0)*fone; - if (floatd>p) coeff=0; - } else if (flags & SWS_BILINEAR) { - coeff= (1<<30) - d; - if (coeff<0) coeff=0; - coeff *= fone >> 30; - } else if (flags & SWS_SPLINE) { - double p=-2.196152422706632; - coeff = getSplineCoeff(1.0, 0.0, p, -p-1.0, floatd) * fone; - } else { - coeff= 0.0; //GCC warning killer - assert(0); - } - - filter[i*filterSize + j]= coeff; - xx++; - } - xDstInSrc+= 2*xInc; - } - } - - /* apply src & dst Filter to filter -> filter2 - av_free(filter); - */ - assert(filterSize>0); - filter2Size= filterSize; - if (srcFilter) filter2Size+= srcFilter->length - 1; - if (dstFilter) filter2Size+= dstFilter->length - 1; - assert(filter2Size>0); - filter2= av_mallocz(filter2Size*dstW*sizeof(*filter2)); - - for (i=0; ilength; k++) { - for (j=0; jcoeff[k]*filter[i*filterSize + j]; - } - } else { - for (j=0; j=0; i--) { - int min= filter2Size; - int j; - int64_t cutOff=0.0; - - /* get rid off near zero elements on the left by shifting left */ - for (j=0; j SWS_MAX_REDUCE_CUTOFF*fone) break; - - /* preserve monotonicity because the core can't handle the filter otherwise */ - if (i= (*filterPos)[i+1]) break; - - // move filter coefficients left - for (k=1; k0; j--) { - cutOff += FFABS(filter2[i*filter2Size + j]); - - if (cutOff > SWS_MAX_REDUCE_CUTOFF*fone) break; - min--; - } - - if (min>minFilterSize) minFilterSize= min; - } - - if (flags & SWS_CPU_CAPS_ALTIVEC) { - // we can handle the special case 4, - // so we don't want to go to the full 8 - if (minFilterSize < 5) - filterAlign = 4; - - // We really don't want to waste our time - // doing useless computation, so fall back on - // the scalar C code for very small filters. - // Vectorizing is worth it only if you have a - // decent-sized vector. - if (minFilterSize < 3) - filterAlign = 1; - } - - if (flags & SWS_CPU_CAPS_MMX) { - // special case for unscaled vertical filtering - if (minFilterSize == 1 && filterAlign == 2) - filterAlign= 1; - } - - assert(minFilterSize > 0); - filterSize= (minFilterSize +(filterAlign-1)) & (~(filterAlign-1)); - assert(filterSize > 0); - filter= av_malloc(filterSize*dstW*sizeof(*filter)); - if (filterSize >= MAX_FILTER_SIZE*16/((flags&SWS_ACCURATE_RND) ? APCK_SIZE : 16) || !filter) - goto error; - *outFilterSize= filterSize; - - if (flags&SWS_PRINT_INFO) - av_log(NULL, AV_LOG_VERBOSE, "SwScaler: reducing / aligning filtersize %d -> %d\n", filter2Size, filterSize); - /* try to reduce the filter-size (step2 reduce it) */ - for (i=0; i=filter2Size) filter[i*filterSize + j]= 0; - else filter[i*filterSize + j]= filter2[i*filter2Size + j]; - if((flags & SWS_BITEXACT) && j>=minFilterSize) - filter[i*filterSize + j]= 0; - } - } - - - //FIXME try to align filterPos if possible - - //fix borders - for (i=0; i srcW) { - int shift= (*filterPos)[i] + filterSize - srcW; - // move filter coefficients right to compensate for filterPos - for (j=filterSize-2; j>=0; j--) { - int right= FFMIN(j + shift, filterSize-1); - filter[i*filterSize +right] += filter[i*filterSize +j]; - filter[i*filterSize +j]=0; - } - (*filterPos)[i]= srcW - filterSize; - } - } - - // Note the +1 is for the MMX scaler which reads over the end - /* align at 16 for AltiVec (needed by hScale_altivec_real) */ - *outFilter= av_mallocz(*outFilterSize*(dstW+1)*sizeof(int16_t)); - - /* normalize & store in outFilter */ - for (i=0; i>16; - - if ((i&3) == 0) { - int a=0; - int b=((xpos+xInc)>>16) - xx; - int c=((xpos+xInc*2)>>16) - xx; - int d=((xpos+xInc*3)>>16) - xx; - int inc = (d+1<4); - uint8_t *fragment = (d+1<4) ? fragmentB : fragmentA; - x86_reg imm8OfPShufW1 = (d+1<4) ? imm8OfPShufW1B : imm8OfPShufW1A; - x86_reg imm8OfPShufW2 = (d+1<4) ? imm8OfPShufW2B : imm8OfPShufW2A; - x86_reg fragmentLength = (d+1<4) ? fragmentLengthB : fragmentLengthA; - int maxShift= 3-(d+inc); - int shift=0; - - if (filterCode) { - filter[i ] = (( xpos & 0xFFFF) ^ 0xFFFF)>>9; - filter[i+1] = (((xpos+xInc ) & 0xFFFF) ^ 0xFFFF)>>9; - filter[i+2] = (((xpos+xInc*2) & 0xFFFF) ^ 0xFFFF)>>9; - filter[i+3] = (((xpos+xInc*3) & 0xFFFF) ^ 0xFFFF)>>9; - filterPos[i/2]= xx; - - memcpy(filterCode + fragmentPos, fragment, fragmentLength); - - filterCode[fragmentPos + imm8OfPShufW1]= - (a+inc) | ((b+inc)<<2) | ((c+inc)<<4) | ((d+inc)<<6); - filterCode[fragmentPos + imm8OfPShufW2]= - a | (b<<2) | (c<<4) | (d<<6); - - if (i+4-inc>=dstW) shift=maxShift; //avoid overread - else if ((filterPos[i/2]&3) <= maxShift) shift=filterPos[i/2]&3; //Align - - if (shift && i>=shift) { - filterCode[fragmentPos + imm8OfPShufW1]+= 0x55*shift; - filterCode[fragmentPos + imm8OfPShufW2]+= 0x55*shift; - filterPos[i/2]-=shift; - } - } - - fragmentPos+= fragmentLength; - - if (filterCode) - filterCode[fragmentPos]= RET; - } - xpos+=xInc; - } - if (filterCode) - filterPos[((i/2)+1)&(~1)]= xpos>>16; // needed to jump to the next part - - return fragmentPos + 1; -} -#endif /* COMPILE_MMX2 */ - -static void globalInit(void) -{ - // generating tables: - int i; - for (i=0; i<768; i++) { - int c= av_clip_uint8(i-256); - clip_table[i]=c; - } -} - -static SwsFunc getSwsFunc(SwsContext *c) +SwsFunc ff_getSwsFunc(SwsContext *c) { #if CONFIG_RUNTIME_CPUDETECT int flags = c->flags; -#if ARCH_X86 && CONFIG_GPL +#if ARCH_X86 // ordered per speed fastest first if (flags & SWS_CPU_CAPS_MMX2) { sws_init_swScale_MMX2(c); @@ -1956,7 +1259,7 @@ static SwsFunc getSwsFunc(SwsContext *c) } #else -#if ARCH_PPC +#ifdef COMPILE_ALTIVEC if (flags & SWS_CPU_CAPS_ALTIVEC) { sws_init_swScale_altivec(c); return swScale_altivec; @@ -1967,7 +1270,7 @@ static SwsFunc getSwsFunc(SwsContext *c) #endif sws_init_swScale_C(c); return swScale_C; -#endif /* ARCH_X86 && CONFIG_GPL */ +#endif /* ARCH_X86 */ #else //CONFIG_RUNTIME_CPUDETECT #if COMPILE_TEMPLATE_MMX2 sws_init_swScale_MMX2(c); @@ -1988,7 +1291,7 @@ static SwsFunc getSwsFunc(SwsContext *c) #endif //!CONFIG_RUNTIME_CPUDETECT } -static int PlanarToNV12Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, +static int planarToNv12Wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t* dstParam[], int dstStride[]) { uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY; @@ -2014,7 +1317,7 @@ static int PlanarToNV12Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], i return srcSliceH; } -static int PlanarToYuy2Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, +static int planarToYuy2Wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t* dstParam[], int dstStride[]) { uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY; @@ -2024,7 +1327,7 @@ static int PlanarToYuy2Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], i return srcSliceH; } -static int PlanarToUyvyWrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, +static int planarToUyvyWrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t* dstParam[], int dstStride[]) { uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY; @@ -2034,7 +1337,7 @@ static int PlanarToUyvyWrapper(SwsContext *c, uint8_t* src[], int srcStride[], i return srcSliceH; } -static int YUV422PToYuy2Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, +static int yuv422pToYuy2Wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t* dstParam[], int dstStride[]) { uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY; @@ -2044,7 +1347,7 @@ static int YUV422PToYuy2Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], return srcSliceH; } -static int YUV422PToUyvyWrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, +static int yuv422pToUyvyWrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t* dstParam[], int dstStride[]) { uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY; @@ -2054,7 +1357,7 @@ static int YUV422PToUyvyWrapper(SwsContext *c, uint8_t* src[], int srcStride[], return srcSliceH; } -static int YUYV2YUV420Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, +static int yuyvToYuv420Wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t* dstParam[], int dstStride[]) { uint8_t *ydst=dstParam[0] + dstStride[0]*srcSliceY; @@ -2069,7 +1372,7 @@ static int YUYV2YUV420Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], in return srcSliceH; } -static int YUYV2YUV422Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, +static int yuyvToYuv422Wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t* dstParam[], int dstStride[]) { uint8_t *ydst=dstParam[0] + dstStride[0]*srcSliceY; @@ -2081,7 +1384,7 @@ static int YUYV2YUV422Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], in return srcSliceH; } -static int UYVY2YUV420Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, +static int uyvyToYuv420Wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t* dstParam[], int dstStride[]) { uint8_t *ydst=dstParam[0] + dstStride[0]*srcSliceY; @@ -2096,7 +1399,7 @@ static int UYVY2YUV420Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], in return srcSliceH; } -static int UYVY2YUV422Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, +static int uyvyToYuv422Wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t* dstParam[], int dstStride[]) { uint8_t *ydst=dstParam[0] + dstStride[0]*srcSliceY; @@ -2108,8 +1411,8 @@ static int UYVY2YUV422Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], in return srcSliceH; } -static int pal2rgbWrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, - int srcSliceH, uint8_t* dst[], int dstStride[]) +static int palToRgbWrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, + int srcSliceH, uint8_t* dst[], int dstStride[]) { const enum PixelFormat srcFormat= c->srcFormat; const enum PixelFormat dstFormat= c->dstFormat; @@ -2117,48 +1420,71 @@ static int pal2rgbWrapper(SwsContext *c, uint8_t* src[], int srcStride[], int sr const uint8_t *palette)=NULL; int i; uint8_t *dstPtr= dst[0] + dstStride[0]*srcSliceY; - uint8_t *srcPtr= src[0]; + const uint8_t *srcPtr= src[0]; - if (!usePal(srcFormat)) - av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n", - sws_format_name(srcFormat), sws_format_name(dstFormat)); - - switch(dstFormat) { - case PIX_FMT_RGB32 : conv = palette8topacked32; break; - case PIX_FMT_BGR32 : conv = palette8topacked32; break; - case PIX_FMT_BGR32_1: conv = palette8topacked32; break; - case PIX_FMT_RGB32_1: conv = palette8topacked32; break; - case PIX_FMT_RGB24 : conv = palette8topacked24; break; - case PIX_FMT_BGR24 : conv = palette8topacked24; break; - default: av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n", - sws_format_name(srcFormat), sws_format_name(dstFormat)); break; + if (usePal(srcFormat)) { + switch (dstFormat) { + case PIX_FMT_RGB32 : conv = sws_convertPalette8ToPacked32; break; + case PIX_FMT_BGR32 : conv = sws_convertPalette8ToPacked32; break; + case PIX_FMT_BGR32_1: conv = sws_convertPalette8ToPacked32; break; + case PIX_FMT_RGB32_1: conv = sws_convertPalette8ToPacked32; break; + case PIX_FMT_RGB24 : conv = sws_convertPalette8ToPacked24; break; + case PIX_FMT_BGR24 : conv = sws_convertPalette8ToPacked24; break; + } } - - for (i=0; isrcW, (uint8_t *) c->pal_rgb); - srcPtr+= srcStride[0]; - dstPtr+= dstStride[0]; + if (!conv) + av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n", + sws_format_name(srcFormat), sws_format_name(dstFormat)); + else { + for (i=0; isrcW, (uint8_t *) c->pal_rgb); + srcPtr+= srcStride[0]; + dstPtr+= dstStride[0]; + } } return srcSliceH; } +#define isRGBA32(x) ( \ + (x) == PIX_FMT_ARGB \ + || (x) == PIX_FMT_RGBA \ + || (x) == PIX_FMT_BGRA \ + || (x) == PIX_FMT_ABGR \ + ) + /* {RGB,BGR}{15,16,24,32,32_1} -> {RGB,BGR}{15,16,24,32} */ -static int rgb2rgbWrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, - int srcSliceH, uint8_t* dst[], int dstStride[]) +static int rgbToRgbWrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, + int srcSliceH, uint8_t* dst[], int dstStride[]) { const enum PixelFormat srcFormat= c->srcFormat; const enum PixelFormat dstFormat= c->dstFormat; - const int srcBpp= (fmt_depth(srcFormat) + 7) >> 3; - const int dstBpp= (fmt_depth(dstFormat) + 7) >> 3; - const int srcId= fmt_depth(srcFormat) >> 2; /* 1:0, 4:1, 8:2, 15:3, 16:4, 24:6, 32:8 */ - const int dstId= fmt_depth(dstFormat) >> 2; + const int srcBpp= (c->srcFormatBpp + 7) >> 3; + const int dstBpp= (c->dstFormatBpp + 7) >> 3; + const int srcId= c->srcFormatBpp >> 2; /* 1:0, 4:1, 8:2, 15:3, 16:4, 24:6, 32:8 */ + const int dstId= c->dstFormatBpp >> 2; void (*conv)(const uint8_t *src, uint8_t *dst, long src_size)=NULL; +#define CONV_IS(src, dst) (srcFormat == PIX_FMT_##src && dstFormat == PIX_FMT_##dst) + + if (isRGBA32(srcFormat) && isRGBA32(dstFormat)) { + if ( CONV_IS(ABGR, RGBA) + || CONV_IS(ARGB, BGRA) + || CONV_IS(BGRA, ARGB) + || CONV_IS(RGBA, ABGR)) conv = shuffle_bytes_3210; + else if (CONV_IS(ABGR, ARGB) + || CONV_IS(ARGB, ABGR)) conv = shuffle_bytes_0321; + else if (CONV_IS(ABGR, BGRA) + || CONV_IS(ARGB, RGBA)) conv = shuffle_bytes_1230; + else if (CONV_IS(BGRA, RGBA) + || CONV_IS(RGBA, BGRA)) conv = shuffle_bytes_2103; + else if (CONV_IS(BGRA, ABGR) + || CONV_IS(RGBA, ARGB)) conv = shuffle_bytes_3012; + } else /* BGR -> BGR */ - if ( (isBGR(srcFormat) && isBGR(dstFormat)) - || (isRGB(srcFormat) && isRGB(dstFormat))) { + if ( (isBGRinInt(srcFormat) && isBGRinInt(dstFormat)) + || (isRGBinInt(srcFormat) && isRGBinInt(dstFormat))) { switch(srcId | (dstId<<4)) { case 0x34: conv= rgb16to15; break; case 0x36: conv= rgb24to15; break; @@ -2172,11 +1498,9 @@ static int rgb2rgbWrapper(SwsContext *c, uint8_t* src[], int srcStride[], int sr case 0x83: conv= rgb15to32; break; case 0x84: conv= rgb16to32; break; case 0x86: conv= rgb24to32; break; - default: av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n", - sws_format_name(srcFormat), sws_format_name(dstFormat)); break; } - } else if ( (isBGR(srcFormat) && isRGB(dstFormat)) - || (isRGB(srcFormat) && isBGR(dstFormat))) { + } else if ( (isBGRinInt(srcFormat) && isRGBinInt(dstFormat)) + || (isRGBinInt(srcFormat) && isBGRinInt(dstFormat))) { switch(srcId | (dstId<<4)) { case 0x33: conv= rgb15tobgr15; break; case 0x34: conv= rgb16tobgr15; break; @@ -2193,25 +1517,26 @@ static int rgb2rgbWrapper(SwsContext *c, uint8_t* src[], int srcStride[], int sr case 0x83: conv= rgb15tobgr32; break; case 0x84: conv= rgb16tobgr32; break; case 0x86: conv= rgb24tobgr32; break; - case 0x88: conv= rgb32tobgr32; break; - default: av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n", - sws_format_name(srcFormat), sws_format_name(dstFormat)); break; } - } else { - av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n", - sws_format_name(srcFormat), sws_format_name(dstFormat)); } - if(conv) { - uint8_t *srcPtr= src[0]; - if(srcFormat == PIX_FMT_RGB32_1 || srcFormat == PIX_FMT_BGR32_1) + if (!conv) { + av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n", + sws_format_name(srcFormat), sws_format_name(dstFormat)); + } else { + const uint8_t *srcPtr= src[0]; + uint8_t *dstPtr= dst[0]; + if ((srcFormat == PIX_FMT_RGB32_1 || srcFormat == PIX_FMT_BGR32_1) && !isRGBA32(dstFormat)) srcPtr += ALT32_CORR; + 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) - conv(srcPtr, dst[0] + dstStride[0]*srcSliceY, srcSliceH*srcStride[0]); + conv(srcPtr, dstPtr + dstStride[0]*srcSliceY, srcSliceH*srcStride[0]); else { int i; - uint8_t *dstPtr= dst[0] + dstStride[0]*srcSliceY; + dstPtr += dstStride[0]*srcSliceY; for (i=0; isrcW*srcBpp); @@ -2223,10 +1548,9 @@ static int rgb2rgbWrapper(SwsContext *c, uint8_t* src[], int srcStride[], int sr return srcSliceH; } -static int bgr24toyv12Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, +static int bgr24ToYv12Wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t* dst[], int dstStride[]) { - rgb24toyv12( src[0], dst[0]+ srcSliceY *dstStride[0], @@ -2239,7 +1563,7 @@ static int bgr24toyv12Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], in return srcSliceH; } -static int yvu9toyv12Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, +static int yvu9ToYv12Wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t* dst[], int dstStride[]) { int i; @@ -2248,7 +1572,7 @@ static int yvu9toyv12Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int if (srcStride[0]==dstStride[0] && srcStride[0] > 0) memcpy(dst[0]+ srcSliceY*dstStride[0], src[0], srcStride[0]*srcSliceH); else { - uint8_t *srcPtr= src[0]; + const uint8_t *srcPtr= src[0]; uint8_t *dstPtr= dst[0] + dstStride[0]*srcSliceY; for (i=0; i 0) memcpy(dst[0] + dstStride[0]*srcSliceY, src[0], srcSliceH*dstStride[0]); else { int i; - uint8_t *srcPtr= src[0]; + const uint8_t *srcPtr= src[0]; uint8_t *dstPtr= dst[0] + dstStride[0]*srcSliceY; int length=0; @@ -2300,15 +1624,15 @@ static int packedCopy(SwsContext *c, uint8_t* src[], int srcStride[], int srcSli return srcSliceH; } -static int planarCopy(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, - int srcSliceH, uint8_t* dst[], int dstStride[]) +static int planarCopyWrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, + int srcSliceH, uint8_t* dst[], int dstStride[]) { int plane, i, j; for (plane=0; plane<4; plane++) { int length= (plane==0 || plane==3) ? c->srcW : -((-c->srcW )>>c->chrDstHSubSample); int y= (plane==0 || plane==3) ? srcSliceY: -((-srcSliceY)>>c->chrDstVSubSample); int height= (plane==0 || plane==3) ? srcSliceH: -((-srcSliceH)>>c->chrDstVSubSample); - uint8_t *srcPtr= src[plane]; + const uint8_t *srcPtr= src[plane]; uint8_t *dstPtr= dst[plane] + dstStride[plane]*y; if (!dst[plane]) continue; @@ -2340,7 +1664,7 @@ static int planarCopy(SwsContext *c, uint8_t* src[], int srcStride[], int srcSli for (i=0; i>16; - if (r<-0x7FFF) return 0x8000; - else if (r> 0x7FFF) return 0x7FFF; - else return r; -} - -int sws_setColorspaceDetails(SwsContext *c, const int inv_table[4], int srcRange, const int table[4], int dstRange, int brightness, int contrast, int saturation) -{ - int64_t crv = inv_table[0]; - int64_t cbu = inv_table[1]; - int64_t cgu = -inv_table[2]; - int64_t cgv = -inv_table[3]; - int64_t cy = 1<<16; - int64_t oy = 0; - - memcpy(c->srcColorspaceTable, inv_table, sizeof(int)*4); - memcpy(c->dstColorspaceTable, table, sizeof(int)*4); - - c->brightness= brightness; - c->contrast = contrast; - c->saturation= saturation; - c->srcRange = srcRange; - c->dstRange = dstRange; - if (isYUV(c->dstFormat) || isGray(c->dstFormat)) return -1; - - c->uOffset= 0x0400040004000400LL; - c->vOffset= 0x0400040004000400LL; - - if (!srcRange) { - cy= (cy*255) / 219; - oy= 16<<16; - } else { - crv= (crv*224) / 255; - cbu= (cbu*224) / 255; - cgu= (cgu*224) / 255; - cgv= (cgv*224) / 255; - } - - cy = (cy *contrast )>>16; - crv= (crv*contrast * saturation)>>32; - cbu= (cbu*contrast * saturation)>>32; - cgu= (cgu*contrast * saturation)>>32; - cgv= (cgv*contrast * saturation)>>32; - - oy -= 256*brightness; - - c->yCoeff= roundToInt16(cy *8192) * 0x0001000100010001ULL; - c->vrCoeff= roundToInt16(crv*8192) * 0x0001000100010001ULL; - c->ubCoeff= roundToInt16(cbu*8192) * 0x0001000100010001ULL; - c->vgCoeff= roundToInt16(cgv*8192) * 0x0001000100010001ULL; - c->ugCoeff= roundToInt16(cgu*8192) * 0x0001000100010001ULL; - c->yOffset= roundToInt16(oy * 8) * 0x0001000100010001ULL; - - c->yuv2rgb_y_coeff = (int16_t)roundToInt16(cy <<13); - c->yuv2rgb_y_offset = (int16_t)roundToInt16(oy << 9); - c->yuv2rgb_v2r_coeff= (int16_t)roundToInt16(crv<<13); - c->yuv2rgb_v2g_coeff= (int16_t)roundToInt16(cgv<<13); - c->yuv2rgb_u2g_coeff= (int16_t)roundToInt16(cgu<<13); - c->yuv2rgb_u2b_coeff= (int16_t)roundToInt16(cbu<<13); - - ff_yuv2rgb_c_init_tables(c, inv_table, srcRange, brightness, contrast, saturation); - //FIXME factorize - -#ifdef COMPILE_ALTIVEC - if (c->flags & SWS_CPU_CAPS_ALTIVEC) - ff_yuv2rgb_init_tables_altivec(c, inv_table, brightness, contrast, saturation); -#endif - return 0; -} - -int sws_getColorspaceDetails(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; - - *inv_table = c->srcColorspaceTable; - *table = c->dstColorspaceTable; - *srcRange = c->srcRange; - *dstRange = c->dstRange; - *brightness= c->brightness; - *contrast = c->contrast; - *saturation= c->saturation; - - return 0; -} - -static int handle_jpeg(enum PixelFormat *format) -{ - switch (*format) { - case PIX_FMT_YUVJ420P: - *format = PIX_FMT_YUV420P; - return 1; - case PIX_FMT_YUVJ422P: - *format = PIX_FMT_YUV422P; - return 1; - case PIX_FMT_YUVJ444P: - *format = PIX_FMT_YUV444P; - return 1; - case PIX_FMT_YUVJ440P: - *format = PIX_FMT_YUV440P; - return 1; - default: - return 0; - } -} - -SwsContext *sws_getContext(int srcW, int srcH, enum PixelFormat srcFormat, int dstW, int dstH, enum PixelFormat dstFormat, int flags, - SwsFilter *srcFilter, SwsFilter *dstFilter, const double *param) -{ - - SwsContext *c; - int i; - int usesVFilter, usesHFilter; - int unscaled, needsDither; - int srcRange, dstRange; - SwsFilter dummyFilter= {NULL, NULL, NULL, NULL}; -#if ARCH_X86 - if (flags & SWS_CPU_CAPS_MMX) - __asm__ volatile("emms\n\t"::: "memory"); -#endif - -#if !CONFIG_RUNTIME_CPUDETECT //ensure that the flags match the compiled variant if cpudetect is off - flags &= ~(SWS_CPU_CAPS_MMX|SWS_CPU_CAPS_MMX2|SWS_CPU_CAPS_3DNOW|SWS_CPU_CAPS_ALTIVEC|SWS_CPU_CAPS_BFIN); + int flags = 0; #if COMPILE_TEMPLATE_MMX2 flags |= SWS_CPU_CAPS_MMX|SWS_CPU_CAPS_MMX2; #elif COMPILE_TEMPLATE_AMD3DNOW @@ -2547,517 +1698,134 @@ SwsContext *sws_getContext(int srcW, int srcH, enum PixelFormat srcFormat, int d #elif ARCH_BFIN flags |= SWS_CPU_CAPS_BFIN; #endif -#endif /* CONFIG_RUNTIME_CPUDETECT */ - if (clip_table[512] != 255) globalInit(); - if (!rgb15to16) sws_rgb2rgb_init(flags); - - unscaled = (srcW == dstW && srcH == dstH); - needsDither= (isBGR(dstFormat) || isRGB(dstFormat)) - && (fmt_depth(dstFormat))<24 - && ((fmt_depth(dstFormat))<(fmt_depth(srcFormat)) || (!(isRGB(srcFormat) || isBGR(srcFormat)))); - - srcRange = handle_jpeg(&srcFormat); - dstRange = handle_jpeg(&dstFormat); - - if (!isSupportedIn(srcFormat)) { - av_log(NULL, AV_LOG_ERROR, "swScaler: %s is not supported as input pixel format\n", sws_format_name(srcFormat)); - return NULL; - } - if (!isSupportedOut(dstFormat)) { - av_log(NULL, AV_LOG_ERROR, "swScaler: %s is not supported as output pixel format\n", sws_format_name(dstFormat)); - return NULL; - } - - i= flags & ( SWS_POINT - |SWS_AREA - |SWS_BILINEAR - |SWS_FAST_BILINEAR - |SWS_BICUBIC - |SWS_X - |SWS_GAUSS - |SWS_LANCZOS - |SWS_SINC - |SWS_SPLINE - |SWS_BICUBLIN); - if(!i || (i & (i-1))) { - av_log(NULL, AV_LOG_ERROR, "swScaler: Exactly one scaler algorithm must be chosen\n"); - return NULL; - } - - /* sanity check */ - if (srcW<4 || srcH<1 || dstW<8 || dstH<1) { //FIXME check if these are enough and try to lowwer them after fixing the relevant parts of the code - av_log(NULL, AV_LOG_ERROR, "swScaler: %dx%d -> %dx%d is invalid scaling dimension\n", - srcW, srcH, dstW, dstH); - return NULL; - } - if(srcW > VOFW || dstW > VOFW) { - av_log(NULL, AV_LOG_ERROR, "swScaler: Compile-time maximum width is "AV_STRINGIFY(VOFW)" change VOF/VOFW and recompile\n"); - return NULL; - } - - if (!dstFilter) dstFilter= &dummyFilter; - if (!srcFilter) srcFilter= &dummyFilter; - - c= av_mallocz(sizeof(SwsContext)); - - c->av_class = &sws_context_class; - c->srcW= srcW; - c->srcH= srcH; - c->dstW= dstW; - c->dstH= dstH; - c->lumXInc= ((srcW<<16) + (dstW>>1))/dstW; - c->lumYInc= ((srcH<<16) + (dstH>>1))/dstH; - c->flags= flags; - c->dstFormat= dstFormat; - c->srcFormat= srcFormat; - c->vRounder= 4* 0x0001000100010001ULL; - - usesHFilter= usesVFilter= 0; - if (dstFilter->lumV && dstFilter->lumV->length>1) usesVFilter=1; - if (dstFilter->lumH && dstFilter->lumH->length>1) usesHFilter=1; - if (dstFilter->chrV && dstFilter->chrV->length>1) usesVFilter=1; - if (dstFilter->chrH && dstFilter->chrH->length>1) usesHFilter=1; - if (srcFilter->lumV && srcFilter->lumV->length>1) usesVFilter=1; - if (srcFilter->lumH && srcFilter->lumH->length>1) usesHFilter=1; - if (srcFilter->chrV && srcFilter->chrV->length>1) usesVFilter=1; - if (srcFilter->chrH && srcFilter->chrH->length>1) usesHFilter=1; - - getSubSampleFactors(&c->chrSrcHSubSample, &c->chrSrcVSubSample, srcFormat); - getSubSampleFactors(&c->chrDstHSubSample, &c->chrDstVSubSample, dstFormat); - - // reuse chroma for 2 pixels RGB/BGR unless user wants full chroma interpolation - if ((isBGR(dstFormat) || isRGB(dstFormat)) && !(flags&SWS_FULL_CHR_H_INT)) c->chrDstHSubSample=1; - - // drop some chroma lines if the user wants it - c->vChrDrop= (flags&SWS_SRC_V_CHR_DROP_MASK)>>SWS_SRC_V_CHR_DROP_SHIFT; - c->chrSrcVSubSample+= c->vChrDrop; - - // drop every other pixel for chroma calculation unless user wants full chroma - if ((isBGR(srcFormat) || isRGB(srcFormat)) && !(flags&SWS_FULL_CHR_H_INP) - && srcFormat!=PIX_FMT_RGB8 && srcFormat!=PIX_FMT_BGR8 - && srcFormat!=PIX_FMT_RGB4 && srcFormat!=PIX_FMT_BGR4 - && srcFormat!=PIX_FMT_RGB4_BYTE && srcFormat!=PIX_FMT_BGR4_BYTE - && ((dstW>>c->chrDstHSubSample) <= (srcW>>1) || (flags&(SWS_FAST_BILINEAR|SWS_POINT)))) - c->chrSrcHSubSample=1; - - if (param) { - c->param[0] = param[0]; - c->param[1] = param[1]; - } else { - c->param[0] = - c->param[1] = SWS_PARAM_DEFAULT; - } - - // Note the -((-x)>>y) is so that we always round toward +inf. - c->chrSrcW= -((-srcW) >> c->chrSrcHSubSample); - c->chrSrcH= -((-srcH) >> c->chrSrcVSubSample); - c->chrDstW= -((-dstW) >> c->chrDstHSubSample); - c->chrDstH= -((-dstH) >> c->chrDstVSubSample); - - sws_setColorspaceDetails(c, ff_yuv2rgb_coeffs[SWS_CS_DEFAULT], srcRange, ff_yuv2rgb_coeffs[SWS_CS_DEFAULT] /* FIXME*/, dstRange, 0, 1<<16, 1<<16); - - /* unscaled special cases */ - if (unscaled && !usesHFilter && !usesVFilter && (srcRange == dstRange || isBGR(dstFormat) || isRGB(dstFormat))) { - /* yv12_to_nv12 */ - if ((srcFormat == PIX_FMT_YUV420P || srcFormat == PIX_FMT_YUVA420P) && (dstFormat == PIX_FMT_NV12 || dstFormat == PIX_FMT_NV21)) { - c->swScale= PlanarToNV12Wrapper; - } - /* yuv2bgr */ - if ((srcFormat==PIX_FMT_YUV420P || srcFormat==PIX_FMT_YUV422P || srcFormat==PIX_FMT_YUVA420P) && (isBGR(dstFormat) || isRGB(dstFormat)) - && !(flags & SWS_ACCURATE_RND) && !(dstH&1)) { - c->swScale= ff_yuv2rgb_get_func_ptr(c); - } - - if (srcFormat==PIX_FMT_YUV410P && (dstFormat==PIX_FMT_YUV420P || dstFormat==PIX_FMT_YUVA420P) && !(flags & SWS_BITEXACT)) { - c->swScale= yvu9toyv12Wrapper; - } - - /* bgr24toYV12 */ - if (srcFormat==PIX_FMT_BGR24 && (dstFormat==PIX_FMT_YUV420P || dstFormat==PIX_FMT_YUVA420P) && !(flags & SWS_ACCURATE_RND)) - c->swScale= bgr24toyv12Wrapper; - - /* RGB/BGR -> RGB/BGR (no dither needed forms) */ - if ( (isBGR(srcFormat) || isRGB(srcFormat)) - && (isBGR(dstFormat) || isRGB(dstFormat)) - && srcFormat != PIX_FMT_BGR8 && dstFormat != PIX_FMT_BGR8 - && srcFormat != PIX_FMT_RGB8 && dstFormat != PIX_FMT_RGB8 - && srcFormat != PIX_FMT_BGR4 && dstFormat != PIX_FMT_BGR4 - && srcFormat != PIX_FMT_RGB4 && dstFormat != PIX_FMT_RGB4 - && srcFormat != PIX_FMT_BGR4_BYTE && dstFormat != PIX_FMT_BGR4_BYTE - && srcFormat != PIX_FMT_RGB4_BYTE && dstFormat != PIX_FMT_RGB4_BYTE - && srcFormat != PIX_FMT_MONOBLACK && dstFormat != PIX_FMT_MONOBLACK - && srcFormat != PIX_FMT_MONOWHITE && dstFormat != PIX_FMT_MONOWHITE - && dstFormat != PIX_FMT_RGB32_1 - && dstFormat != PIX_FMT_BGR32_1 - && srcFormat != PIX_FMT_RGB48LE && dstFormat != PIX_FMT_RGB48LE - && srcFormat != PIX_FMT_RGB48BE && dstFormat != PIX_FMT_RGB48BE - && (!needsDither || (c->flags&(SWS_FAST_BILINEAR|SWS_POINT)))) - c->swScale= rgb2rgbWrapper; - - if ((usePal(srcFormat) && ( - dstFormat == PIX_FMT_RGB32 || - dstFormat == PIX_FMT_RGB32_1 || - dstFormat == PIX_FMT_RGB24 || - dstFormat == PIX_FMT_BGR32 || - dstFormat == PIX_FMT_BGR32_1 || - dstFormat == PIX_FMT_BGR24))) - c->swScale= pal2rgbWrapper; - - if (srcFormat == PIX_FMT_YUV422P) { - if (dstFormat == PIX_FMT_YUYV422) - c->swScale= YUV422PToYuy2Wrapper; - else if (dstFormat == PIX_FMT_UYVY422) - c->swScale= YUV422PToUyvyWrapper; - } - - /* LQ converters if -sws 0 or -sws 4*/ - if (c->flags&(SWS_FAST_BILINEAR|SWS_POINT)) { - /* yv12_to_yuy2 */ - if (srcFormat == PIX_FMT_YUV420P || srcFormat == PIX_FMT_YUVA420P) { - if (dstFormat == PIX_FMT_YUYV422) - c->swScale= PlanarToYuy2Wrapper; - else if (dstFormat == PIX_FMT_UYVY422) - c->swScale= PlanarToUyvyWrapper; - } - } - if(srcFormat == PIX_FMT_YUYV422 && (dstFormat == PIX_FMT_YUV420P || dstFormat == PIX_FMT_YUVA420P)) - c->swScale= YUYV2YUV420Wrapper; - if(srcFormat == PIX_FMT_UYVY422 && (dstFormat == PIX_FMT_YUV420P || dstFormat == PIX_FMT_YUVA420P)) - c->swScale= UYVY2YUV420Wrapper; - if(srcFormat == PIX_FMT_YUYV422 && dstFormat == PIX_FMT_YUV422P) - c->swScale= YUYV2YUV422Wrapper; - if(srcFormat == PIX_FMT_UYVY422 && dstFormat == PIX_FMT_YUV422P) - c->swScale= UYVY2YUV422Wrapper; - -#ifdef COMPILE_ALTIVEC - if ((c->flags & SWS_CPU_CAPS_ALTIVEC) && - !(c->flags & SWS_BITEXACT) && - srcFormat == PIX_FMT_YUV420P) { - // unscaled YV12 -> packed YUV, we want speed - if (dstFormat == PIX_FMT_YUYV422) - c->swScale= yv12toyuy2_unscaled_altivec; - else if (dstFormat == PIX_FMT_UYVY422) - c->swScale= yv12touyvy_unscaled_altivec; - } -#endif - - /* simple copy */ - if ( srcFormat == dstFormat - || (srcFormat == PIX_FMT_YUVA420P && dstFormat == PIX_FMT_YUV420P) - || (srcFormat == PIX_FMT_YUV420P && dstFormat == PIX_FMT_YUVA420P) - || (isPlanarYUV(srcFormat) && isGray(dstFormat)) - || (isPlanarYUV(dstFormat) && isGray(srcFormat)) - || (isGray(dstFormat) && isGray(srcFormat)) - || (isPlanarYUV(srcFormat) && isPlanarYUV(dstFormat) - && c->chrDstHSubSample == c->chrSrcHSubSample - && c->chrDstVSubSample == c->chrSrcVSubSample - && dstFormat != PIX_FMT_NV12 && dstFormat != PIX_FMT_NV21 - && srcFormat != PIX_FMT_NV12 && srcFormat != PIX_FMT_NV21)) - { - if (isPacked(c->srcFormat)) - c->swScale= packedCopy; - else /* Planar YUV or gray */ - c->swScale= planarCopy; - } -#if ARCH_BFIN - if (flags & SWS_CPU_CAPS_BFIN) - ff_bfin_get_unscaled_swscale (c); -#endif - - 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)); - return c; - } - } - - if (flags & SWS_CPU_CAPS_MMX2) { - 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; - } - else - c->canMMX2BeUsed=0; - - c->chrXInc= ((c->chrSrcW<<16) + (c->chrDstW>>1))/c->chrDstW; - c->chrYInc= ((c->chrSrcH<<16) + (c->chrDstH>>1))/c->chrDstH; - - // match pixel 0 of the src to pixel 0 of dst and match pixel n-2 of src to pixel n-2 of dst - // but only for the FAST_BILINEAR mode otherwise do correct scaling - // n-2 is the last chrominance sample available - // this is not perfect, but no one should notice the difference, the more correct variant - // would be like the vertical one, but that would require some special code for the - // first and last pixel - if (flags&SWS_FAST_BILINEAR) { - if (c->canMMX2BeUsed) { - c->lumXInc+= 20; - c->chrXInc+= 20; - } - //we don't use the x86 asm scaler if MMX is available - else if (flags & SWS_CPU_CAPS_MMX) { - c->lumXInc = ((srcW-2)<<16)/(dstW-2) - 20; - c->chrXInc = ((c->chrSrcW-2)<<16)/(c->chrDstW-2) - 20; - } - } - - /* precalculate horizontal scaler filter coefficients */ - { - const int filterAlign= - (flags & SWS_CPU_CAPS_MMX) ? 4 : - (flags & SWS_CPU_CAPS_ALTIVEC) ? 8 : - 1; - - initFilter(&c->hLumFilter, &c->hLumFilterPos, &c->hLumFilterSize, c->lumXInc, - srcW , dstW, filterAlign, 1<<14, - (flags&SWS_BICUBLIN) ? (flags|SWS_BICUBIC) : flags, - srcFilter->lumH, dstFilter->lumH, c->param); - initFilter(&c->hChrFilter, &c->hChrFilterPos, &c->hChrFilterSize, c->chrXInc, - c->chrSrcW, c->chrDstW, filterAlign, 1<<14, - (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags, - srcFilter->chrH, dstFilter->chrH, c->param); - -#if defined(COMPILE_MMX2) -// can't downscale !!! - if (c->canMMX2BeUsed && (flags & SWS_FAST_BILINEAR)) { - c->lumMmx2FilterCodeSize = initMMX2HScaler( dstW, c->lumXInc, NULL, NULL, NULL, 8); - c->chrMmx2FilterCodeSize = initMMX2HScaler(c->chrDstW, c->chrXInc, NULL, NULL, NULL, 4); - -#ifdef MAP_ANONYMOUS - c->lumMmx2FilterCode = mmap(NULL, c->lumMmx2FilterCodeSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); - c->chrMmx2FilterCode = mmap(NULL, c->chrMmx2FilterCodeSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); -#elif HAVE_VIRTUALALLOC - c->lumMmx2FilterCode = VirtualAlloc(NULL, c->lumMmx2FilterCodeSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE); - c->chrMmx2FilterCode = VirtualAlloc(NULL, c->chrMmx2FilterCodeSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE); -#else - c->lumMmx2FilterCode = av_malloc(c->lumMmx2FilterCodeSize); - c->chrMmx2FilterCode = av_malloc(c->chrMmx2FilterCodeSize); -#endif - - c->lumMmx2Filter = av_malloc((dstW /8+8)*sizeof(int16_t)); - c->chrMmx2Filter = av_malloc((c->chrDstW /4+8)*sizeof(int16_t)); - c->lumMmx2FilterPos= av_malloc((dstW /2/8+8)*sizeof(int32_t)); - c->chrMmx2FilterPos= av_malloc((c->chrDstW/2/4+8)*sizeof(int32_t)); - - initMMX2HScaler( dstW, c->lumXInc, c->lumMmx2FilterCode, c->lumMmx2Filter, c->lumMmx2FilterPos, 8); - initMMX2HScaler(c->chrDstW, c->chrXInc, c->chrMmx2FilterCode, c->chrMmx2Filter, c->chrMmx2FilterPos, 4); - -#ifdef MAP_ANONYMOUS - mprotect(c->lumMmx2FilterCode, c->lumMmx2FilterCodeSize, PROT_EXEC | PROT_READ); - mprotect(c->chrMmx2FilterCode, c->chrMmx2FilterCodeSize, PROT_EXEC | PROT_READ); -#endif - } -#endif /* defined(COMPILE_MMX2) */ - } // initialize horizontal stuff - - - - /* precalculate vertical scaler filter coefficients */ - { - const int filterAlign= - (flags & SWS_CPU_CAPS_MMX) && (flags & SWS_ACCURATE_RND) ? 2 : - (flags & SWS_CPU_CAPS_ALTIVEC) ? 8 : - 1; - - initFilter(&c->vLumFilter, &c->vLumFilterPos, &c->vLumFilterSize, c->lumYInc, - srcH , dstH, filterAlign, (1<<12), - (flags&SWS_BICUBLIN) ? (flags|SWS_BICUBIC) : flags, - srcFilter->lumV, dstFilter->lumV, c->param); - initFilter(&c->vChrFilter, &c->vChrFilterPos, &c->vChrFilterSize, c->chrYInc, - c->chrSrcH, c->chrDstH, filterAlign, (1<<12), - (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags, - srcFilter->chrV, dstFilter->chrV, c->param); - -#ifdef COMPILE_ALTIVEC - c->vYCoeffsBank = av_malloc(sizeof (vector signed short)*c->vLumFilterSize*c->dstH); - c->vCCoeffsBank = av_malloc(sizeof (vector signed short)*c->vChrFilterSize*c->chrDstH); - - for (i=0;ivLumFilterSize*c->dstH;i++) { - int j; - short *p = (short *)&c->vYCoeffsBank[i]; - for (j=0;j<8;j++) - p[j] = c->vLumFilter[i]; - } - - for (i=0;ivChrFilterSize*c->chrDstH;i++) { - int j; - short *p = (short *)&c->vCCoeffsBank[i]; - for (j=0;j<8;j++) - p[j] = c->vChrFilter[i]; - } -#endif - } - - // calculate buffer sizes so that they won't run out while handling these damn slices - c->vLumBufSize= c->vLumFilterSize; - c->vChrBufSize= c->vChrFilterSize; - for (i=0; ichrDstH / dstH; - int nextSlice= FFMAX(c->vLumFilterPos[i ] + c->vLumFilterSize - 1, - ((c->vChrFilterPos[chrI] + c->vChrFilterSize - 1)<chrSrcVSubSample)); - - nextSlice>>= c->chrSrcVSubSample; - nextSlice<<= c->chrSrcVSubSample; - if (c->vLumFilterPos[i ] + c->vLumBufSize < nextSlice) - c->vLumBufSize= nextSlice - c->vLumFilterPos[i]; - if (c->vChrFilterPos[chrI] + c->vChrBufSize < (nextSlice>>c->chrSrcVSubSample)) - c->vChrBufSize= (nextSlice>>c->chrSrcVSubSample) - c->vChrFilterPos[chrI]; - } - - // allocate pixbufs (we use dynamic allocation because otherwise we would need to - c->lumPixBuf= av_malloc(c->vLumBufSize*2*sizeof(int16_t*)); - c->chrPixBuf= av_malloc(c->vChrBufSize*2*sizeof(int16_t*)); - if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat) && isALPHA(c->dstFormat)) - c->alpPixBuf= av_malloc(c->vLumBufSize*2*sizeof(int16_t*)); - //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; ivLumBufSize; i++) - c->lumPixBuf[i]= c->lumPixBuf[i+c->vLumBufSize]= av_mallocz(VOF+1); - for (i=0; ivChrBufSize; i++) - c->chrPixBuf[i]= c->chrPixBuf[i+c->vChrBufSize]= av_malloc((VOF+1)*2); - if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) - for (i=0; ivLumBufSize; i++) - c->alpPixBuf[i]= c->alpPixBuf[i+c->vLumBufSize]= av_mallocz(VOF+1); - - //try to avoid drawing green stuff between the right end and the stride end - for (i=0; ivChrBufSize; i++) memset(c->chrPixBuf[i], 64, (VOF+1)*2); - - assert(2*VOFW == VOF); - - assert(c->chrDstH <= dstH); - - if (flags&SWS_PRINT_INFO) { -#ifdef DITHER1XBPP - const char *dither= " dithered"; -#else - const char *dither= ""; -#endif - if (flags&SWS_FAST_BILINEAR) - av_log(c, AV_LOG_INFO, "FAST_BILINEAR scaler, "); - else if (flags&SWS_BILINEAR) - av_log(c, AV_LOG_INFO, "BILINEAR scaler, "); - else if (flags&SWS_BICUBIC) - av_log(c, AV_LOG_INFO, "BICUBIC scaler, "); - else if (flags&SWS_X) - av_log(c, AV_LOG_INFO, "Experimental scaler, "); - else if (flags&SWS_POINT) - av_log(c, AV_LOG_INFO, "Nearest Neighbor / POINT scaler, "); - else if (flags&SWS_AREA) - av_log(c, AV_LOG_INFO, "Area Averageing scaler, "); - else if (flags&SWS_BICUBLIN) - av_log(c, AV_LOG_INFO, "luma BICUBIC / chroma BILINEAR scaler, "); - else if (flags&SWS_GAUSS) - av_log(c, AV_LOG_INFO, "Gaussian scaler, "); - else if (flags&SWS_SINC) - av_log(c, AV_LOG_INFO, "Sinc scaler, "); - else if (flags&SWS_LANCZOS) - av_log(c, AV_LOG_INFO, "Lanczos scaler, "); - else if (flags&SWS_SPLINE) - av_log(c, AV_LOG_INFO, "Bicubic spline scaler, "); - else - av_log(c, AV_LOG_INFO, "ehh flags invalid?! "); - - if (dstFormat==PIX_FMT_BGR555 || dstFormat==PIX_FMT_BGR565) - av_log(c, AV_LOG_INFO, "from %s to%s %s ", - sws_format_name(srcFormat), dither, sws_format_name(dstFormat)); - else - av_log(c, AV_LOG_INFO, "from %s to %s ", - sws_format_name(srcFormat), sws_format_name(dstFormat)); - - if (flags & SWS_CPU_CAPS_MMX2) - av_log(c, AV_LOG_INFO, "using MMX2\n"); - else if (flags & SWS_CPU_CAPS_3DNOW) - av_log(c, AV_LOG_INFO, "using 3DNOW\n"); - else if (flags & SWS_CPU_CAPS_MMX) - av_log(c, AV_LOG_INFO, "using MMX\n"); - else if (flags & SWS_CPU_CAPS_ALTIVEC) - av_log(c, AV_LOG_INFO, "using AltiVec\n"); - else - av_log(c, AV_LOG_INFO, "using C\n"); - } - - if (flags & SWS_PRINT_INFO) { - if (flags & SWS_CPU_CAPS_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 ARCH_X86 - 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", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); - else - av_log(c, AV_LOG_VERBOSE, "using n-tap %s scaler for vertical scaling (YV12 like)\n", (flags & SWS_CPU_CAPS_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", (flags & SWS_CPU_CAPS_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", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); - else - av_log(c, AV_LOG_VERBOSE, "using n-tap %s scaler for vertical scaling (BGR)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); - } - - if (dstFormat==PIX_FMT_BGR24) - av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR24 converter\n", - (flags & SWS_CPU_CAPS_MMX2) ? "MMX2" : ((flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C")); - else if (dstFormat==PIX_FMT_RGB32) - av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR32 converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); - else if (dstFormat==PIX_FMT_BGR565) - av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR16 converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); - else if (dstFormat==PIX_FMT_BGR555) - av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR15 converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); - - av_log(c, AV_LOG_VERBOSE, "%dx%d -> %dx%d\n", srcW, srcH, dstW, dstH); - } - if (flags & SWS_PRINT_INFO) { - 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); - av_log(c, AV_LOG_DEBUG, "chr srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n", - c->chrSrcW, c->chrSrcH, c->chrDstW, c->chrDstH, c->chrXInc, c->chrYInc); - } - - c->swScale= getSwsFunc(c); - return c; + return flags; } -static void reset_ptr(uint8_t* src[], int format) +void ff_get_unscaled_swscale(SwsContext *c) +{ + const enum PixelFormat srcFormat = c->srcFormat; + const enum PixelFormat dstFormat = c->dstFormat; + const int flags = c->flags; + const int dstH = c->dstH; + int needsDither; + + needsDither= isAnyRGB(dstFormat) + && c->dstFormatBpp < 24 + && (c->dstFormatBpp < c->srcFormatBpp || (!isAnyRGB(srcFormat))); + + /* yv12_to_nv12 */ + if ((srcFormat == PIX_FMT_YUV420P || srcFormat == PIX_FMT_YUVA420P) && (dstFormat == PIX_FMT_NV12 || dstFormat == PIX_FMT_NV21)) { + c->swScale= planarToNv12Wrapper; + } + /* yuv2bgr */ + if ((srcFormat==PIX_FMT_YUV420P || srcFormat==PIX_FMT_YUV422P || srcFormat==PIX_FMT_YUVA420P) && isAnyRGB(dstFormat) + && !(flags & SWS_ACCURATE_RND) && !(dstH&1)) { + c->swScale= ff_yuv2rgb_get_func_ptr(c); + } + + if (srcFormat==PIX_FMT_YUV410P && (dstFormat==PIX_FMT_YUV420P || dstFormat==PIX_FMT_YUVA420P) && !(flags & SWS_BITEXACT)) { + c->swScale= yvu9ToYv12Wrapper; + } + + /* bgr24toYV12 */ + if (srcFormat==PIX_FMT_BGR24 && (dstFormat==PIX_FMT_YUV420P || dstFormat==PIX_FMT_YUVA420P) && !(flags & SWS_ACCURATE_RND)) + c->swScale= bgr24ToYv12Wrapper; + + /* RGB/BGR -> RGB/BGR (no dither needed forms) */ + if ( isAnyRGB(srcFormat) + && isAnyRGB(dstFormat) + && srcFormat != PIX_FMT_BGR8 && dstFormat != PIX_FMT_BGR8 + && srcFormat != PIX_FMT_RGB8 && dstFormat != PIX_FMT_RGB8 + && srcFormat != PIX_FMT_BGR4 && dstFormat != PIX_FMT_BGR4 + && srcFormat != PIX_FMT_RGB4 && dstFormat != PIX_FMT_RGB4 + && srcFormat != PIX_FMT_BGR4_BYTE && dstFormat != PIX_FMT_BGR4_BYTE + && srcFormat != PIX_FMT_RGB4_BYTE && dstFormat != PIX_FMT_RGB4_BYTE + && srcFormat != PIX_FMT_MONOBLACK && dstFormat != PIX_FMT_MONOBLACK + && srcFormat != PIX_FMT_MONOWHITE && dstFormat != PIX_FMT_MONOWHITE + && srcFormat != PIX_FMT_RGB48LE && dstFormat != PIX_FMT_RGB48LE + && srcFormat != PIX_FMT_RGB48BE && dstFormat != PIX_FMT_RGB48BE + && (!needsDither || (c->flags&(SWS_FAST_BILINEAR|SWS_POINT)))) + c->swScale= rgbToRgbWrapper; + + if ((usePal(srcFormat) && ( + dstFormat == PIX_FMT_RGB32 || + dstFormat == PIX_FMT_RGB32_1 || + dstFormat == PIX_FMT_RGB24 || + dstFormat == PIX_FMT_BGR32 || + dstFormat == PIX_FMT_BGR32_1 || + dstFormat == PIX_FMT_BGR24))) + c->swScale= palToRgbWrapper; + + if (srcFormat == PIX_FMT_YUV422P) { + if (dstFormat == PIX_FMT_YUYV422) + c->swScale= yuv422pToYuy2Wrapper; + else if (dstFormat == PIX_FMT_UYVY422) + c->swScale= yuv422pToUyvyWrapper; + } + + /* LQ converters if -sws 0 or -sws 4*/ + if (c->flags&(SWS_FAST_BILINEAR|SWS_POINT)) { + /* yv12_to_yuy2 */ + if (srcFormat == PIX_FMT_YUV420P || srcFormat == PIX_FMT_YUVA420P) { + if (dstFormat == PIX_FMT_YUYV422) + c->swScale= planarToYuy2Wrapper; + else if (dstFormat == PIX_FMT_UYVY422) + c->swScale= planarToUyvyWrapper; + } + } + if(srcFormat == PIX_FMT_YUYV422 && (dstFormat == PIX_FMT_YUV420P || dstFormat == PIX_FMT_YUVA420P)) + c->swScale= yuyvToYuv420Wrapper; + if(srcFormat == PIX_FMT_UYVY422 && (dstFormat == PIX_FMT_YUV420P || dstFormat == PIX_FMT_YUVA420P)) + c->swScale= uyvyToYuv420Wrapper; + if(srcFormat == PIX_FMT_YUYV422 && dstFormat == PIX_FMT_YUV422P) + c->swScale= yuyvToYuv422Wrapper; + if(srcFormat == PIX_FMT_UYVY422 && dstFormat == PIX_FMT_YUV422P) + c->swScale= uyvyToYuv422Wrapper; + +#ifdef COMPILE_ALTIVEC + if ((c->flags & SWS_CPU_CAPS_ALTIVEC) && + !(c->flags & SWS_BITEXACT) && + srcFormat == PIX_FMT_YUV420P) { + // unscaled YV12 -> packed YUV, we want speed + if (dstFormat == PIX_FMT_YUYV422) + c->swScale= yv12toyuy2_unscaled_altivec; + else if (dstFormat == PIX_FMT_UYVY422) + c->swScale= yv12touyvy_unscaled_altivec; + } +#endif + + /* simple copy */ + if ( srcFormat == dstFormat + || (srcFormat == PIX_FMT_YUVA420P && dstFormat == PIX_FMT_YUV420P) + || (srcFormat == PIX_FMT_YUV420P && dstFormat == PIX_FMT_YUVA420P) + || (isPlanarYUV(srcFormat) && isGray(dstFormat)) + || (isPlanarYUV(dstFormat) && isGray(srcFormat)) + || (isGray(dstFormat) && isGray(srcFormat)) + || (isPlanarYUV(srcFormat) && isPlanarYUV(dstFormat) + && c->chrDstHSubSample == c->chrSrcHSubSample + && c->chrDstVSubSample == c->chrSrcVSubSample + && dstFormat != PIX_FMT_NV12 && dstFormat != PIX_FMT_NV21 + && srcFormat != PIX_FMT_NV12 && srcFormat != PIX_FMT_NV21)) + { + if (isPacked(c->srcFormat)) + c->swScale= packedCopyWrapper; + else /* Planar YUV or gray */ + c->swScale= planarCopyWrapper; + } +#if ARCH_BFIN + if (flags & SWS_CPU_CAPS_BFIN) + ff_bfin_get_unscaled_swscale (c); +#endif +} + +static void reset_ptr(const uint8_t* src[], int format) { if(!isALPHA(format)) src[3]=NULL; if(!isPlanarYUV(format)) { src[3]=src[2]=NULL; - if( format != PIX_FMT_PAL8 - && format != PIX_FMT_RGB8 - && format != PIX_FMT_BGR8 - && format != PIX_FMT_RGB4_BYTE - && format != PIX_FMT_BGR4_BYTE - ) + + if (!usePal(format)) src[1]= NULL; } } @@ -3066,13 +1834,17 @@ static void reset_ptr(uint8_t* src[], int format) * 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, uint8_t* src[], int srcStride[], int srcSliceY, - int srcSliceH, uint8_t* dst[], int dstStride[]) +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 i; - uint8_t* src2[4]= {src[0], src[1], src[2], src[3]}; + const uint8_t* src2[4]= {src[0], src[1], src[2], src[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 (c->sliceDir == 0 && srcSliceY != 0 && srcSliceY + srcSliceH != c->srcH) { av_log(c, AV_LOG_ERROR, "Slices start in the middle!\n"); return 0; @@ -3085,7 +1857,7 @@ int sws_scale(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, for (i=0; i<256; i++) { int p, r, g, b,y,u,v; if(c->srcFormat == PIX_FMT_PAL8) { - p=((uint32_t*)(src[1]))[i]; + p=((const uint32_t*)(src[1]))[i]; r= (p>>16)&0xFF; g= (p>> 8)&0xFF; b= p &0xFF; @@ -3101,6 +1873,8 @@ int sws_scale(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, r= (i>>3 )*255; g= ((i>>1)&3)*85; b= (i&1 )*255; + } else if(c->srcFormat == PIX_FMT_GRAY8) { + r = g = b = i; } else { assert(c->srcFormat == PIX_FMT_BGR4_BYTE); b= (i>>3 )*255; @@ -3112,7 +1886,6 @@ int sws_scale(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, 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); - switch(c->dstFormat) { case PIX_FMT_BGR32: #if !HAVE_BIGENDIAN @@ -3149,7 +1922,11 @@ int sws_scale(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, int dstStride2[4]= {dstStride[0], dstStride[1], dstStride[2], dstStride[3]}; reset_ptr(src2, c->srcFormat); - reset_ptr(dst2, c->dstFormat); + reset_ptr((const uint8_t**)dst2, c->dstFormat); + + /* reset slice direction at end of frame */ + if (srcSliceY + srcSliceH == c->srcH) + c->sliceDir = 0; return c->swScale(c, src2, srcStride2, srcSliceY, srcSliceH, dst2, dstStride2); } else { @@ -3168,405 +1945,43 @@ int sws_scale(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, dst2[3] += ( c->dstH -1)*dstStride[3]; reset_ptr(src2, c->srcFormat); - reset_ptr(dst2, c->dstFormat); + reset_ptr((const uint8_t**)dst2, c->dstFormat); + + /* reset slice direction at end of frame */ + if (!srcSliceY) + c->sliceDir = 0; return c->swScale(c, src2, srcStride2, c->srcH-srcSliceY-srcSliceH, srcSliceH, dst2, dstStride2); } } #if LIBSWSCALE_VERSION_MAJOR < 1 -int sws_scale_ordered(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, +int sws_scale_ordered(SwsContext *c, const uint8_t* const src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t* dst[], int dstStride[]) { return sws_scale(c, src, srcStride, srcSliceY, srcSliceH, dst, dstStride); } #endif -SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur, - float lumaSharpen, float chromaSharpen, - float chromaHShift, float chromaVShift, - int verbose) +/* Convert the palette to the same packed 32-bit format as the palette */ +void sws_convertPalette8ToPacked32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette) { - SwsFilter *filter= av_malloc(sizeof(SwsFilter)); + long i; - if (lumaGBlur!=0.0) { - filter->lumH= sws_getGaussianVec(lumaGBlur, 3.0); - filter->lumV= sws_getGaussianVec(lumaGBlur, 3.0); - } else { - filter->lumH= sws_getIdentityVec(); - filter->lumV= sws_getIdentityVec(); - } - - if (chromaGBlur!=0.0) { - filter->chrH= sws_getGaussianVec(chromaGBlur, 3.0); - filter->chrV= sws_getGaussianVec(chromaGBlur, 3.0); - } else { - filter->chrH= sws_getIdentityVec(); - filter->chrV= sws_getIdentityVec(); - } - - if (chromaSharpen!=0.0) { - SwsVector *id= sws_getIdentityVec(); - sws_scaleVec(filter->chrH, -chromaSharpen); - sws_scaleVec(filter->chrV, -chromaSharpen); - sws_addVec(filter->chrH, id); - sws_addVec(filter->chrV, id); - sws_freeVec(id); - } - - if (lumaSharpen!=0.0) { - SwsVector *id= sws_getIdentityVec(); - sws_scaleVec(filter->lumH, -lumaSharpen); - sws_scaleVec(filter->lumV, -lumaSharpen); - sws_addVec(filter->lumH, id); - sws_addVec(filter->lumV, id); - sws_freeVec(id); - } - - if (chromaHShift != 0.0) - sws_shiftVec(filter->chrH, (int)(chromaHShift+0.5)); - - if (chromaVShift != 0.0) - sws_shiftVec(filter->chrV, (int)(chromaVShift+0.5)); - - sws_normalizeVec(filter->chrH, 1.0); - sws_normalizeVec(filter->chrV, 1.0); - sws_normalizeVec(filter->lumH, 1.0); - sws_normalizeVec(filter->lumV, 1.0); - - if (verbose) sws_printVec2(filter->chrH, NULL, AV_LOG_DEBUG); - if (verbose) sws_printVec2(filter->lumH, NULL, AV_LOG_DEBUG); - - return filter; + for (i=0; i dst format: ABC */ +void sws_convertPalette8ToPacked24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette) { - SwsVector *vec = av_malloc(sizeof(SwsVector)); - if (!vec) - return NULL; - vec->length = length; - vec->coeff = av_malloc(sizeof(double) * length); - if (!vec->coeff) - av_freep(&vec); - return vec; -} + long i; -SwsVector *sws_getGaussianVec(double variance, double quality) -{ - const int length= (int)(variance*quality + 0.5) | 1; - int i; - double middle= (length-1)*0.5; - SwsVector *vec= sws_allocVec(length); - - if (!vec) - return NULL; - - for (i=0; icoeff[i]= exp(-dist*dist/(2*variance*variance)) / sqrt(2*variance*PI); - } - - sws_normalizeVec(vec, 1.0); - - return vec; -} - -SwsVector *sws_getConstVec(double c, int length) -{ - int i; - SwsVector *vec= sws_allocVec(length); - - if (!vec) - return NULL; - - for (i=0; icoeff[i]= c; - - return vec; -} - - -SwsVector *sws_getIdentityVec(void) -{ - return sws_getConstVec(1.0, 1); -} - -double sws_dcVec(SwsVector *a) -{ - int i; - double sum=0; - - for (i=0; ilength; i++) - sum+= a->coeff[i]; - - return sum; -} - -void sws_scaleVec(SwsVector *a, double scalar) -{ - int i; - - for (i=0; ilength; i++) - a->coeff[i]*= scalar; -} - -void sws_normalizeVec(SwsVector *a, double height) -{ - sws_scaleVec(a, height/sws_dcVec(a)); -} - -static SwsVector *sws_getConvVec(SwsVector *a, SwsVector *b) -{ - int length= a->length + b->length - 1; - int i, j; - SwsVector *vec= sws_getConstVec(0.0, length); - - if (!vec) - return NULL; - - for (i=0; ilength; i++) { - for (j=0; jlength; j++) { - vec->coeff[i+j]+= a->coeff[i]*b->coeff[j]; - } - } - - return vec; -} - -static SwsVector *sws_sumVec(SwsVector *a, SwsVector *b) -{ - int length= FFMAX(a->length, b->length); - int i; - SwsVector *vec= sws_getConstVec(0.0, length); - - if (!vec) - return NULL; - - for (i=0; ilength; i++) vec->coeff[i + (length-1)/2 - (a->length-1)/2]+= a->coeff[i]; - for (i=0; ilength; i++) vec->coeff[i + (length-1)/2 - (b->length-1)/2]+= b->coeff[i]; - - return vec; -} - -static SwsVector *sws_diffVec(SwsVector *a, SwsVector *b) -{ - int length= FFMAX(a->length, b->length); - int i; - SwsVector *vec= sws_getConstVec(0.0, length); - - if (!vec) - return NULL; - - for (i=0; ilength; i++) vec->coeff[i + (length-1)/2 - (a->length-1)/2]+= a->coeff[i]; - for (i=0; ilength; i++) vec->coeff[i + (length-1)/2 - (b->length-1)/2]-= b->coeff[i]; - - return vec; -} - -/* shift left / or right if "shift" is negative */ -static SwsVector *sws_getShiftedVec(SwsVector *a, int shift) -{ - int length= a->length + FFABS(shift)*2; - int i; - SwsVector *vec= sws_getConstVec(0.0, length); - - if (!vec) - return NULL; - - for (i=0; ilength; i++) { - vec->coeff[i + (length-1)/2 - (a->length-1)/2 - shift]= a->coeff[i]; - } - - return vec; -} - -void sws_shiftVec(SwsVector *a, int shift) -{ - SwsVector *shifted= sws_getShiftedVec(a, shift); - av_free(a->coeff); - a->coeff= shifted->coeff; - a->length= shifted->length; - av_free(shifted); -} - -void sws_addVec(SwsVector *a, SwsVector *b) -{ - SwsVector *sum= sws_sumVec(a, b); - av_free(a->coeff); - a->coeff= sum->coeff; - a->length= sum->length; - av_free(sum); -} - -void sws_subVec(SwsVector *a, SwsVector *b) -{ - SwsVector *diff= sws_diffVec(a, b); - av_free(a->coeff); - a->coeff= diff->coeff; - a->length= diff->length; - av_free(diff); -} - -void sws_convVec(SwsVector *a, SwsVector *b) -{ - SwsVector *conv= sws_getConvVec(a, b); - av_free(a->coeff); - a->coeff= conv->coeff; - a->length= conv->length; - av_free(conv); -} - -SwsVector *sws_cloneVec(SwsVector *a) -{ - int i; - SwsVector *vec= sws_allocVec(a->length); - - if (!vec) - return NULL; - - for (i=0; ilength; i++) vec->coeff[i]= a->coeff[i]; - - return vec; -} - -void sws_printVec2(SwsVector *a, AVClass *log_ctx, int log_level) -{ - int i; - double max=0; - double min=0; - double range; - - for (i=0; ilength; i++) - if (a->coeff[i]>max) max= a->coeff[i]; - - for (i=0; ilength; i++) - if (a->coeff[i]coeff[i]; - - range= max - min; - - for (i=0; ilength; i++) { - int x= (int)((a->coeff[i]-min)*60.0/range +0.5); - av_log(log_ctx, log_level, "%1.3f ", a->coeff[i]); - for (;x>0; x--) av_log(log_ctx, log_level, " "); - av_log(log_ctx, log_level, "|\n"); + for (i=0; icoeff); - a->length=0; - av_free(a); -} - -void sws_freeFilter(SwsFilter *filter) -{ - if (!filter) return; - - if (filter->lumH) sws_freeVec(filter->lumH); - if (filter->lumV) sws_freeVec(filter->lumV); - if (filter->chrH) sws_freeVec(filter->chrH); - if (filter->chrV) sws_freeVec(filter->chrV); - av_free(filter); -} - - -void sws_freeContext(SwsContext *c) -{ - int i; - if (!c) return; - - if (c->lumPixBuf) { - for (i=0; ivLumBufSize; i++) - av_freep(&c->lumPixBuf[i]); - av_freep(&c->lumPixBuf); - } - - if (c->chrPixBuf) { - for (i=0; ivChrBufSize; i++) - av_freep(&c->chrPixBuf[i]); - av_freep(&c->chrPixBuf); - } - - if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) { - for (i=0; ivLumBufSize; i++) - av_freep(&c->alpPixBuf[i]); - av_freep(&c->alpPixBuf); - } - - av_freep(&c->vLumFilter); - av_freep(&c->vChrFilter); - av_freep(&c->hLumFilter); - av_freep(&c->hChrFilter); -#ifdef COMPILE_ALTIVEC - av_freep(&c->vYCoeffsBank); - av_freep(&c->vCCoeffsBank); -#endif - - av_freep(&c->vLumFilterPos); - av_freep(&c->vChrFilterPos); - av_freep(&c->hLumFilterPos); - av_freep(&c->hChrFilterPos); - -#if ARCH_X86 && CONFIG_GPL -#ifdef MAP_ANONYMOUS - if (c->lumMmx2FilterCode) munmap(c->lumMmx2FilterCode, c->lumMmx2FilterCodeSize); - if (c->chrMmx2FilterCode) munmap(c->chrMmx2FilterCode, c->chrMmx2FilterCodeSize); -#elif HAVE_VIRTUALALLOC - if (c->lumMmx2FilterCode) VirtualFree(c->lumMmx2FilterCode, c->lumMmx2FilterCodeSize, MEM_RELEASE); - if (c->chrMmx2FilterCode) VirtualFree(c->chrMmx2FilterCode, c->chrMmx2FilterCodeSize, MEM_RELEASE); -#else - av_free(c->lumMmx2FilterCode); - av_free(c->chrMmx2FilterCode); -#endif - c->lumMmx2FilterCode=NULL; - c->chrMmx2FilterCode=NULL; -#endif /* ARCH_X86 && CONFIG_GPL */ - - av_freep(&c->lumMmx2Filter); - av_freep(&c->chrMmx2Filter); - av_freep(&c->lumMmx2FilterPos); - av_freep(&c->chrMmx2FilterPos); - av_freep(&c->yuvTable); - - av_free(c); -} - -struct SwsContext *sws_getCachedContext(struct SwsContext *context, - int srcW, int srcH, enum PixelFormat srcFormat, - int dstW, int dstH, enum PixelFormat dstFormat, int flags, - SwsFilter *srcFilter, SwsFilter *dstFilter, const double *param) -{ - static const double default_param[2] = {SWS_PARAM_DEFAULT, SWS_PARAM_DEFAULT}; - - if (!param) - param = default_param; - - if (context) { - if (context->srcW != srcW || context->srcH != srcH || - context->srcFormat != srcFormat || - context->dstW != dstW || context->dstH != dstH || - context->dstFormat != dstFormat || context->flags != flags || - context->param[0] != param[0] || context->param[1] != param[1]) - { - sws_freeContext(context); - context = NULL; - } - } - if (!context) { - return sws_getContext(srcW, srcH, srcFormat, - dstW, dstH, dstFormat, flags, - srcFilter, dstFilter, param); - } - return context; -} - diff --git a/src/add-ons/media/plugins/ffmpeg/libswscale/swscale.h b/src/add-ons/media/plugins/ffmpeg/libswscale/swscale.h index 43ff7e20f5..1e7af3a4e8 100644 --- a/src/add-ons/media/plugins/ffmpeg/libswscale/swscale.h +++ b/src/add-ons/media/plugins/ffmpeg/libswscale/swscale.h @@ -22,7 +22,7 @@ #define SWSCALE_SWSCALE_H /** - * @file libswscale/swscale.h + * @file * @brief * external api for the swscale stuff */ @@ -30,8 +30,8 @@ #include "libavutil/avutil.h" #define LIBSWSCALE_VERSION_MAJOR 0 -#define LIBSWSCALE_VERSION_MINOR 7 -#define LIBSWSCALE_VERSION_MICRO 1 +#define LIBSWSCALE_VERSION_MINOR 11 +#define LIBSWSCALE_VERSION_MICRO 0 #define LIBSWSCALE_VERSION_INT AV_VERSION_INT(LIBSWSCALE_VERSION_MAJOR, \ LIBSWSCALE_VERSION_MINOR, \ @@ -48,6 +48,16 @@ */ unsigned swscale_version(void); +/** + * Returns the libswscale build-time configuration. + */ +const char *swscale_configuration(void); + +/** + * Returns the libswscale license. + */ +const char *swscale_license(void); + /* values for the flags, the stuff on the command line is different */ #define SWS_FAST_BILINEAR 1 #define SWS_BILINEAR 2 @@ -93,6 +103,14 @@ unsigned swscale_version(void); #define SWS_CS_SMPTE240M 7 #define SWS_CS_DEFAULT 5 +/** + * Returns a pointer to yuv<->rgb coefficients for the given colorspace + * suitable for sws_setColorspaceDetails(). + * + * @param colorspace One of the SWS_CS_* macros. If invalid, + * SWS_CS_DEFAULT is used. + */ +const int *sws_getCoefficients(int colorspace); // when used for filters they must have an odd number of elements @@ -112,6 +130,22 @@ typedef struct { struct SwsContext; +/** + * Returns a positive value if pix_fmt is a supported input format, 0 + * otherwise. + */ +int sws_isSupportedInput(enum PixelFormat pix_fmt); + +/** + * Returns a positive value if pix_fmt is a supported output format, 0 + * otherwise. + */ +int sws_isSupportedOutput(enum PixelFormat pix_fmt); + +/** + * Frees the swscaler context swsContext. + * If swsContext is NULL, then does nothing. + */ void sws_freeContext(struct SwsContext *swsContext); /** @@ -137,6 +171,10 @@ struct SwsContext *sws_getContext(int srcW, int srcH, enum PixelFormat srcFormat * slice in the image in dst. A slice is a sequence of consecutive * rows in an image. * + * Slices have to be provided in sequential order, either in + * 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 * sws_getContext() * @param srcSlice the array containing the pointers to the planes of @@ -154,13 +192,13 @@ 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, uint8_t* srcSlice[], int srcStride[], - int srcSliceY, int srcSliceH, uint8_t* dst[], int dstStride[]); +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[]); #if LIBSWSCALE_VERSION_MAJOR < 1 /** * @deprecated Use sws_scale() instead. */ -int sws_scale_ordered(struct SwsContext *context, uint8_t* src[], +int sws_scale_ordered(struct SwsContext *context, const uint8_t* const src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t* dst[], int dstStride[]) attribute_deprecated; #endif @@ -264,4 +302,29 @@ struct SwsContext *sws_getCachedContext(struct SwsContext *context, int flags, SwsFilter *srcFilter, SwsFilter *dstFilter, const double *param); +/** + * Converts an 8bit paletted frame into a frame with a color depth of 32-bits. + * + * The output frame will have the same packed format as the palette. + * + * @param src source frame buffer + * @param dst destination frame buffer + * @param num_pixels number of pixels to convert + * @param palette array with [256] entries, which must match color arrangement (RGB or BGR) of src + */ +void sws_convertPalette8ToPacked32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette); + +/** + * Converts an 8bit paletted frame into a frame with a color depth of 24 bits. + * + * With the palette format "ABCD", the destination frame ends up with the format "ABC". + * + * @param src source frame buffer + * @param dst destination frame buffer + * @param num_pixels number of pixels to convert + * @param palette array with [256] entries, which must match color arrangement (RGB or BGR) of src + */ +void sws_convertPalette8ToPacked24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette); + + #endif /* SWSCALE_SWSCALE_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libswscale/swscale_internal.h b/src/add-ons/media/plugins/ffmpeg/libswscale/swscale_internal.h index 48843ec274..5be17d4abb 100644 --- a/src/add-ons/media/plugins/ffmpeg/libswscale/swscale_internal.h +++ b/src/add-ons/media/plugins/ffmpeg/libswscale/swscale_internal.h @@ -59,7 +59,7 @@ struct SwsContext; -typedef int (*SwsFunc)(struct SwsContext *context, uint8_t* src[], +typedef int (*SwsFunc)(struct SwsContext *context, const uint8_t* src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t* dst[], int dstStride[]); @@ -75,59 +75,90 @@ typedef struct SwsContext { * sws_scale() wrapper so they can be freely modified here. */ SwsFunc swScale; - int srcW, srcH, dstH; - int chrSrcW, chrSrcH, chrDstW, chrDstH; + int srcW; ///< Width of source luma/alpha planes. + int srcH; ///< Height of source luma/alpha planes. + int dstH; ///< Height of destination luma/alpha planes. + int chrSrcW; ///< Width of source chroma planes. + int chrSrcH; ///< Height of source chroma planes. + int chrDstW; ///< Width of destination chroma planes. + int chrDstH; ///< Height of destination chroma planes. int lumXInc, chrXInc; int lumYInc, chrYInc; - enum PixelFormat dstFormat, srcFormat; ///< format 4:2:0 type is always YV12 - int origDstFormat, origSrcFormat; ///< format - int chrSrcHSubSample, chrSrcVSubSample; - int chrDstHSubSample, chrDstVSubSample; - int vChrDrop; - int sliceDir; - double param[2]; + enum PixelFormat dstFormat; ///< Destination pixel format. + 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 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. + int chrDstVSubSample; ///< Binary logarithm of vertical subsampling factor between luma/alpha and chroma planes in destination image. + int vChrDrop; ///< Binary logarithm of extra vertical subsampling factor in source image chroma planes specified by user. + int sliceDir; ///< Direction that slices are fed to the scaler (1 = top-to-bottom, -1 = bottom-to-top). + double param[2]; ///< Input parameters for scaling algorithms that need them. uint32_t pal_yuv[256]; uint32_t pal_rgb[256]; - int16_t **lumPixBuf; - int16_t **chrPixBuf; - int16_t **alpPixBuf; - int16_t *hLumFilter; - int16_t *hLumFilterPos; - int16_t *hChrFilter; - int16_t *hChrFilterPos; - int16_t *vLumFilter; - int16_t *vLumFilterPos; - int16_t *vChrFilter; - int16_t *vChrFilterPos; + /** + * @name Scaled horizontal lines ring buffer. + * The horizontal scaler keeps just enough scaled lines in a ring buffer + * so they may be passed to the vertical scaler. The pointers to the + * allocated buffers for each line are duplicated in sequence in the ring + * buffer to simplify indexing and avoid wrapping around between lines + * inside the vertical scaler code. The wrapping is done before the + * vertical scaler is called. + */ + //@{ + int16_t **lumPixBuf; ///< Ring buffer for scaled horizontal luma plane lines to be fed to the vertical scaler. + int16_t **chrPixBuf; ///< Ring buffer for scaled horizontal chroma plane lines to be fed to the vertical scaler. + int16_t **alpPixBuf; ///< Ring buffer for scaled horizontal alpha plane lines to be fed to the vertical scaler. + int vLumBufSize; ///< Number of vertical luma/alpha lines allocated in the ring buffer. + int vChrBufSize; ///< Number of vertical chroma lines allocated in the ring buffer. + int lastInLumBuf; ///< Last scaled horizontal luma/alpha line from source in the ring buffer. + int lastInChrBuf; ///< Last scaled horizontal chroma line from source in the ring buffer. + int lumBufIndex; ///< Index in ring buffer of the last scaled horizontal luma/alpha line from source. + int chrBufIndex; ///< Index in ring buffer of the last scaled horizontal chroma line from source. + //@} uint8_t formatConvBuffer[VOF]; //FIXME dynamic allocation, but we have to change a lot of code for this to be useful - int hLumFilterSize; - int hChrFilterSize; - int vLumFilterSize; - int vChrFilterSize; - int vLumBufSize; - int vChrBufSize; + /** + * @name Horizontal and vertical filters. + * To better understand the following fields, here is a pseudo-code of + * their usage in filtering a horizontal line: + * @code + * for (i = 0; i < width; i++) { + * dst[i] = 0; + * for (j = 0; j < filterSize; j++) + * dst[i] += src[ filterPos[i] + j ] * filter[ filterSize * i + j ]; + * dst[i] >>= FRAC_BITS; // The actual implementation is fixed-point. + * } + * @endcode + */ + //@{ + int16_t *hLumFilter; ///< Array of horizontal filter coefficients for luma/alpha planes. + int16_t *hChrFilter; ///< Array of horizontal filter coefficients for chroma planes. + int16_t *vLumFilter; ///< Array of vertical filter coefficients for luma/alpha planes. + int16_t *vChrFilter; ///< Array of vertical filter coefficients for chroma planes. + int16_t *hLumFilterPos; ///< Array of horizontal filter starting positions for each dst[i] for luma/alpha planes. + int16_t *hChrFilterPos; ///< Array of horizontal filter starting positions for each dst[i] for chroma planes. + int16_t *vLumFilterPos; ///< Array of vertical filter starting positions for each dst[i] for luma/alpha planes. + int16_t *vChrFilterPos; ///< Array of vertical filter starting positions for each dst[i] for chroma planes. + int hLumFilterSize; ///< Horizontal filter size for luma/alpha pixels. + int hChrFilterSize; ///< Horizontal filter size for chroma pixels. + int vLumFilterSize; ///< Vertical filter size for luma/alpha pixels. + int vChrFilterSize; ///< Vertical filter size for chroma pixels. + //@} - int lumMmx2FilterCodeSize; - int chrMmx2FilterCodeSize; - uint8_t *lumMmx2FilterCode; - uint8_t *chrMmx2FilterCode; - int32_t *lumMmx2FilterPos; - int32_t *chrMmx2FilterPos; - int16_t *lumMmx2Filter; - int16_t *chrMmx2Filter; + int lumMmx2FilterCodeSize; ///< Runtime-generated MMX2 horizontal fast bilinear scaler code size for luma/alpha planes. + int chrMmx2FilterCodeSize; ///< Runtime-generated MMX2 horizontal fast bilinear scaler code size for chroma planes. + uint8_t *lumMmx2FilterCode; ///< Runtime-generated MMX2 horizontal fast bilinear scaler code for luma/alpha planes. + uint8_t *chrMmx2FilterCode; ///< Runtime-generated MMX2 horizontal fast bilinear scaler code for chroma planes. int canMMX2BeUsed; - int lastInLumBuf; - int lastInChrBuf; - int lumBufIndex; - int chrBufIndex; - int dstY; - int flags; + int dstY; ///< Last destination vertical line output from last slice. + int flags; ///< Flags passed by the user to select scaler algorithm, optimizations, subsampling, etc... void * yuvTable; // pointer to the yuv->rgb table start so it can be freed() uint8_t * table_rV[256]; uint8_t * table_gU[256]; @@ -138,7 +169,8 @@ typedef struct SwsContext { int contrast, brightness, saturation; // for sws_getColorspaceDetails int srcColorspaceTable[4]; int dstColorspaceTable[4]; - int srcRange, dstRange; + int srcRange; ///< 0 = MPG YUV range, 1 = JPG YUV range (source image). + int dstRange; ///< 0 = MPG YUV range, 1 = JPG YUV range (destination image). int yuv2rgb_y_offset; int yuv2rgb_y_coeff; int yuv2rgb_v2r_coeff; @@ -181,7 +213,7 @@ typedef struct SwsContext { DECLARE_ALIGNED(8, uint64_t, vOffset); int32_t lumMmxFilter[4*MAX_FILTER_SIZE]; int32_t chrMmxFilter[4*MAX_FILTER_SIZE]; - int dstW; + int dstW; ///< Width of destination luma/alpha planes. DECLARE_ALIGNED(8, uint64_t, esp); DECLARE_ALIGNED(8, uint64_t, vRounder); DECLARE_ALIGNED(8, uint64_t, u_temp); @@ -190,14 +222,14 @@ typedef struct SwsContext { int32_t alpMmxFilter[4*MAX_FILTER_SIZE]; #if HAVE_ALTIVEC - vector signed short CY; - vector signed short CRV; - vector signed short CBU; - vector signed short CGU; - vector signed short CGV; - vector signed short OY; - vector unsigned short CSHIFT; - vector signed short *vYCoeffsBank, *vCCoeffsBank; + vector signed short CY; + vector signed short CRV; + vector signed short CBU; + vector signed short CGU; + vector signed short CGV; + vector signed short OY; + vector unsigned short CSHIFT; + vector signed short *vYCoeffsBank, *vCCoeffsBank; #endif #if ARCH_BFIN @@ -215,7 +247,7 @@ typedef struct SwsContext { #endif #if HAVE_VIS - DECLARE_ALIGNED(8, uint64_t, sparc_coeffs[10]); + DECLARE_ALIGNED(8, uint64_t, sparc_coeffs)[10]; #endif /* function pointers for swScale() */ @@ -254,18 +286,18 @@ typedef struct SwsContext { const int16_t **alpSrc, uint8_t *dest, long dstW, long dstY); - void (*hyscale_internal)(uint8_t *dst, const uint8_t *src, - long width, uint32_t *pal); - void (*hascale_internal)(uint8_t *dst, const uint8_t *src, - long width, uint32_t *pal); - void (*hcscale_internal)(uint8_t *dstU, uint8_t *dstV, - const uint8_t *src1, const uint8_t *src2, - long width, uint32_t *pal); + void (*lumToYV12)(uint8_t *dst, const uint8_t *src, + long width, uint32_t *pal); ///< Unscaled conversion of luma plane to YV12 for horizontal scaler. + void (*alpToYV12)(uint8_t *dst, const uint8_t *src, + long 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, + long width, uint32_t *pal); ///< Unscaled conversion of chroma planes to YV12 for horizontal scaler. void (*hyscale_fast)(struct SwsContext *c, - int16_t *dst, int dstWidth, + int16_t *dst, long dstWidth, const uint8_t *src, int srcW, int xInc); void (*hcscale_fast)(struct SwsContext *c, - int16_t *dst, int dstWidth, + int16_t *dst, long dstWidth, const uint8_t *src1, const uint8_t *src2, int srcW, int xInc); @@ -273,6 +305,15 @@ typedef struct SwsContext { int xInc, const int16_t *filter, const int16_t *filterPos, long filterSize); + void (*lumConvertRange)(uint16_t *dst, int width); ///< Color range conversion function for luma plane if needed. + void (*chrConvertRange)(uint16_t *dst, int width); ///< Color range conversion function for chroma planes if needed. + + int lumSrcOffset; ///< Offset given to luma src pointers passed to horizontal input functions. + int chrSrcOffset; ///< Offset given to chroma src pointers passed to horizontal input functions. + int alpSrcOffset; ///< Offset given to alpha src pointers passed to horizontal input functions. + + int needs_hcscale; ///< Set if there are chroma planes to be converted. + } SwsContext; //FIXME check init (where 0) @@ -302,12 +343,12 @@ const char *sws_format_name(enum PixelFormat format); || (x)==PIX_FMT_GRAY16LE \ || (x)==PIX_FMT_RGB48BE \ || (x)==PIX_FMT_RGB48LE \ - || (x)==PIX_FMT_YUV420PLE \ - || (x)==PIX_FMT_YUV422PLE \ - || (x)==PIX_FMT_YUV444PLE \ - || (x)==PIX_FMT_YUV420PBE \ - || (x)==PIX_FMT_YUV422PBE \ - || (x)==PIX_FMT_YUV444PBE \ + || (x)==PIX_FMT_YUV420P16LE \ + || (x)==PIX_FMT_YUV422P16LE \ + || (x)==PIX_FMT_YUV444P16LE \ + || (x)==PIX_FMT_YUV420P16BE \ + || (x)==PIX_FMT_YUV422P16BE \ + || (x)==PIX_FMT_YUV444P16BE \ ) #define isBE(x) ((x)&1) #define isPlanar8YUV(x) ( \ @@ -323,12 +364,12 @@ const char *sws_format_name(enum PixelFormat format); ) #define isPlanarYUV(x) ( \ isPlanar8YUV(x) \ - || (x)==PIX_FMT_YUV420PLE \ - || (x)==PIX_FMT_YUV422PLE \ - || (x)==PIX_FMT_YUV444PLE \ - || (x)==PIX_FMT_YUV420PBE \ - || (x)==PIX_FMT_YUV422PBE \ - || (x)==PIX_FMT_YUV444PBE \ + || (x)==PIX_FMT_YUV420P16LE \ + || (x)==PIX_FMT_YUV422P16LE \ + || (x)==PIX_FMT_YUV444P16LE \ + || (x)==PIX_FMT_YUV420P16BE \ + || (x)==PIX_FMT_YUV422P16BE \ + || (x)==PIX_FMT_YUV444P16BE \ ) #define isYUV(x) ( \ (x)==PIX_FMT_UYVY422 \ @@ -344,32 +385,56 @@ const char *sws_format_name(enum PixelFormat format); (x)==PIX_FMT_GRAY16BE \ || (x)==PIX_FMT_GRAY16LE \ ) -#define isRGB(x) ( \ +#define isRGBinInt(x) ( \ (x)==PIX_FMT_RGB48BE \ || (x)==PIX_FMT_RGB48LE \ || (x)==PIX_FMT_RGB32 \ || (x)==PIX_FMT_RGB32_1 \ || (x)==PIX_FMT_RGB24 \ - || (x)==PIX_FMT_RGB565 \ - || (x)==PIX_FMT_RGB555 \ + || (x)==PIX_FMT_RGB565BE \ + || (x)==PIX_FMT_RGB565LE \ + || (x)==PIX_FMT_RGB555BE \ + || (x)==PIX_FMT_RGB555LE \ + || (x)==PIX_FMT_RGB444BE \ + || (x)==PIX_FMT_RGB444LE \ || (x)==PIX_FMT_RGB8 \ || (x)==PIX_FMT_RGB4 \ || (x)==PIX_FMT_RGB4_BYTE \ || (x)==PIX_FMT_MONOBLACK \ || (x)==PIX_FMT_MONOWHITE \ ) -#define isBGR(x) ( \ +#define isBGRinInt(x) ( \ (x)==PIX_FMT_BGR32 \ || (x)==PIX_FMT_BGR32_1 \ || (x)==PIX_FMT_BGR24 \ - || (x)==PIX_FMT_BGR565 \ - || (x)==PIX_FMT_BGR555 \ + || (x)==PIX_FMT_BGR565BE \ + || (x)==PIX_FMT_BGR565LE \ + || (x)==PIX_FMT_BGR555BE \ + || (x)==PIX_FMT_BGR555LE \ + || (x)==PIX_FMT_BGR444BE \ + || (x)==PIX_FMT_BGR444LE \ || (x)==PIX_FMT_BGR8 \ || (x)==PIX_FMT_BGR4 \ || (x)==PIX_FMT_BGR4_BYTE \ || (x)==PIX_FMT_MONOBLACK \ || (x)==PIX_FMT_MONOWHITE \ ) +#define isRGBinBytes(x) ( \ + (x)==PIX_FMT_RGB48BE \ + || (x)==PIX_FMT_RGB48LE \ + || (x)==PIX_FMT_RGBA \ + || (x)==PIX_FMT_ARGB \ + || (x)==PIX_FMT_RGB24 \ + ) +#define isBGRinBytes(x) ( \ + (x)==PIX_FMT_BGRA \ + || (x)==PIX_FMT_ABGR \ + || (x)==PIX_FMT_BGR24 \ + ) +#define isAnyRGB(x) ( \ + isRGBinInt(x) \ + || isBGRinInt(x) \ + ) #define isALPHA(x) ( \ (x)==PIX_FMT_BGR32 \ || (x)==PIX_FMT_BGR32_1 \ @@ -377,48 +442,28 @@ const char *sws_format_name(enum PixelFormat format); || (x)==PIX_FMT_RGB32_1 \ || (x)==PIX_FMT_YUVA420P \ ) - -static inline int fmt_depth(int fmt) -{ - switch(fmt) { - case PIX_FMT_RGB48BE: - case PIX_FMT_RGB48LE: - return 48; - case PIX_FMT_BGRA: - case PIX_FMT_ABGR: - case PIX_FMT_RGBA: - case PIX_FMT_ARGB: - return 32; - case PIX_FMT_BGR24: - case PIX_FMT_RGB24: - return 24; - case PIX_FMT_BGR565: - case PIX_FMT_RGB565: - case PIX_FMT_GRAY16BE: - case PIX_FMT_GRAY16LE: - return 16; - case PIX_FMT_BGR555: - case PIX_FMT_RGB555: - return 15; - case PIX_FMT_BGR8: - case PIX_FMT_RGB8: - return 8; - case PIX_FMT_BGR4: - case PIX_FMT_RGB4: - case PIX_FMT_BGR4_BYTE: - case PIX_FMT_RGB4_BYTE: - return 4; - case PIX_FMT_MONOBLACK: - case PIX_FMT_MONOWHITE: - return 1; - default: - return 0; - } -} +#define usePal(x) (av_pix_fmt_descriptors[x].flags & PIX_FMT_PAL) extern const uint64_t ff_dither4[2]; extern const uint64_t ff_dither8[2]; extern const AVClass sws_context_class; +/** + * Sets c->swScale to an unscaled converter if one exists for the specific + * source and destination formats, bit depths, flags, etc. + */ +void ff_get_unscaled_swscale(SwsContext *c); + +/** + * Returns the SWS_CPU_CAPS for the optimized code compiled into swscale. + */ +int ff_hardcodedcpuflags(void); + +/** + * Returns function pointer to fastest main scaler path function depending + * on architecture and available optimizations. + */ +SwsFunc ff_getSwsFunc(SwsContext *c); + #endif /* SWSCALE_SWSCALE_INTERNAL_H */ diff --git a/src/add-ons/media/plugins/ffmpeg/libswscale/swscale_template.c b/src/add-ons/media/plugins/ffmpeg/libswscale/swscale_template.c index c985dfb3ea..0d259ed1a0 100644 --- a/src/add-ons/media/plugins/ffmpeg/libswscale/swscale_template.c +++ b/src/add-ons/media/plugins/ffmpeg/libswscale/swscale_template.c @@ -3,39 +3,32 @@ * * 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 free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser 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 General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with FFmpeg; if not, write to the Free Software + * 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 - * - * The C code (not assembly, MMX, ...) of this file can be used - * under the LGPL license. */ #undef REAL_MOVNTQ #undef MOVNTQ #undef PAVGB #undef PREFETCH -#undef PREFETCHW #if COMPILE_TEMPLATE_AMD3DNOW #define PREFETCH "prefetch" -#define PREFETCHW "prefetchw" #elif COMPILE_TEMPLATE_MMX2 #define PREFETCH "prefetchnta" -#define PREFETCHW "prefetcht0" #else #define PREFETCH " # nop" -#define PREFETCHW " # nop" #endif #if COMPILE_TEMPLATE_MMX2 @@ -944,7 +937,7 @@ static inline void RENAME(yuv2yuvX)(SwsContext *c, const int16_t *lumFilter, con static inline void RENAME(yuv2nv12X)(SwsContext *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize, - uint8_t *dest, uint8_t *uDest, int dstW, int chrDstW, int dstFormat) + uint8_t *dest, uint8_t *uDest, int dstW, int chrDstW, enum PixelFormat dstFormat) { yuv2nv12XinC(lumFilter, lumSrc, lumFilterSize, chrFilter, chrSrc, chrFilterSize, @@ -958,7 +951,7 @@ static inline void RENAME(yuv2yuv1)(SwsContext *c, const int16_t *lumSrc, const #if COMPILE_TEMPLATE_MMX if(!(c->flags & SWS_BITEXACT)) { long p= 4; - uint8_t *src[4]= {alpSrc + dstW, lumSrc + dstW, chrSrc + chrDstW, chrSrc + VOFW + chrDstW}; + const uint8_t *src[4]= {alpSrc + dstW, lumSrc + dstW, chrSrc + chrDstW, chrSrc + VOFW + chrDstW}; uint8_t *dst[4]= {aDest, dest, uDest, vDest}; x86_reg counter[4]= {dstW, dstW, chrDstW, chrDstW}; @@ -1226,21 +1219,21 @@ static inline void RENAME(yuv2packed2)(SwsContext *c, const uint16_t *buf0, cons if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) { #if ARCH_X86_64 __asm__ volatile( - YSCALEYUV2RGB(%%REGBP, %5) - YSCALEYUV2RGB_YA(%%REGBP, %5, %6, %7) + YSCALEYUV2RGB(%%r8, %5) + YSCALEYUV2RGB_YA(%%r8, %5, %6, %7) "psraw $3, %%mm1 \n\t" /* abuf0[eax] - abuf1[eax] >>7*/ "psraw $3, %%mm7 \n\t" /* abuf0[eax] - abuf1[eax] >>7*/ "packuswb %%mm7, %%mm1 \n\t" - WRITEBGR32(%4, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm1, %%mm0, %%mm7, %%mm3, %%mm6) + WRITEBGR32(%4, 8280(%5), %%r8, %%mm2, %%mm4, %%mm5, %%mm1, %%mm0, %%mm7, %%mm3, %%mm6) :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "r" (dest), "a" (&c->redDither) ,"r" (abuf0), "r" (abuf1) - : "%"REG_BP + : "%r8" ); #else - *(uint16_t **)(&c->u_temp)=abuf0; - *(uint16_t **)(&c->v_temp)=abuf1; + *(const uint16_t **)(&c->u_temp)=abuf0; + *(const uint16_t **)(&c->v_temp)=abuf1; __asm__ volatile( "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" @@ -1361,7 +1354,7 @@ static inline void RENAME(yuv2packed2)(SwsContext *c, const uint16_t *buf0, cons * YV12 to RGB without scaling or interpolating */ static inline void RENAME(yuv2packed1)(SwsContext *c, const uint16_t *buf0, const uint16_t *uvbuf0, const uint16_t *uvbuf1, - const uint16_t *abuf0, uint8_t *dest, int dstW, int uvalpha, int dstFormat, int flags, int y) + const uint16_t *abuf0, uint8_t *dest, int dstW, int uvalpha, enum PixelFormat dstFormat, int flags, int y) { const int yalpha1=0; int i; @@ -1784,8 +1777,56 @@ static inline void RENAME(BEToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *s #endif } +static inline void RENAME(nvXXtoUV)(uint8_t *dst1, uint8_t *dst2, + const uint8_t *src, long width) +{ #if COMPILE_TEMPLATE_MMX -static inline void RENAME(bgr24ToY_mmx)(uint8_t *dst, const uint8_t *src, long width, int srcFormat) + __asm__ volatile( + "movq "MANGLE(bm01010101)", %%mm4 \n\t" + "mov %0, %%"REG_a" \n\t" + "1: \n\t" + "movq (%1, %%"REG_a",2), %%mm0 \n\t" + "movq 8(%1, %%"REG_a",2), %%mm1 \n\t" + "movq %%mm0, %%mm2 \n\t" + "movq %%mm1, %%mm3 \n\t" + "pand %%mm4, %%mm0 \n\t" + "pand %%mm4, %%mm1 \n\t" + "psrlw $8, %%mm2 \n\t" + "psrlw $8, %%mm3 \n\t" + "packuswb %%mm1, %%mm0 \n\t" + "packuswb %%mm3, %%mm2 \n\t" + "movq %%mm0, (%2, %%"REG_a") \n\t" + "movq %%mm2, (%3, %%"REG_a") \n\t" + "add $8, %%"REG_a" \n\t" + " js 1b \n\t" + : : "g" ((x86_reg)-width), "r" (src+width*2), "r" (dst1+width), "r" (dst2+width) + : "%"REG_a + ); +#else + int i; + for (i = 0; i < width; i++) { + dst1[i] = src[2*i+0]; + dst2[i] = src[2*i+1]; + } +#endif +} + +static inline void RENAME(nv12ToUV)(uint8_t *dstU, uint8_t *dstV, + const uint8_t *src1, const uint8_t *src2, + long width, uint32_t *unused) +{ + RENAME(nvXXtoUV)(dstU, dstV, src1, width); +} + +static inline void RENAME(nv21ToUV)(uint8_t *dstU, uint8_t *dstV, + const uint8_t *src1, const uint8_t *src2, + long width, uint32_t *unused) +{ + RENAME(nvXXtoUV)(dstV, dstU, src1, width); +} + +#if COMPILE_TEMPLATE_MMX +static inline void RENAME(bgr24ToY_mmx)(uint8_t *dst, const uint8_t *src, long width, enum PixelFormat srcFormat) { if(srcFormat == PIX_FMT_BGR24) { @@ -1838,7 +1879,7 @@ static inline void RENAME(bgr24ToY_mmx)(uint8_t *dst, const uint8_t *src, long w ); } -static inline void RENAME(bgr24ToUV_mmx)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src, long width, int srcFormat) +static inline void RENAME(bgr24ToUV_mmx)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src, long width, enum PixelFormat srcFormat) { __asm__ volatile( "movq 24+%4, %%mm6 \n\t" @@ -2101,7 +2142,7 @@ static inline void RENAME(hScale)(int16_t *dst, int dstW, const uint8_t *src, in #endif ); } else { - uint8_t *offset = src+filterSize; + const uint8_t *offset = src+filterSize; x86_reg counter= -2*dstW; //filter-= counter*filterSize/2; filterPos-= counter/2; @@ -2167,10 +2208,41 @@ static inline void RENAME(hScale)(int16_t *dst, int dstW, const uint8_t *src, in dst[i] = FFMIN(val>>7, (1<<15)-1); // the cubic equation does overflow ... //dst[i] = val>>7; } -#endif /* COMPILE_ALTIVEC */ +#endif /* COMPILE_TEMPLATE_ALTIVEC */ #endif /* COMPILE_MMX */ } +//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 RENAME(chrRangeToJpeg)(uint16_t *dst, int width) +{ + int i; + for (i = 0; i < width; i++) { + dst[i ] = (FFMIN(dst[i ],30775)*4663 - 9289992)>>12; //-264 + dst[i+VOFW] = (FFMIN(dst[i+VOFW],30775)*4663 - 9289992)>>12; //-264 + } +} +static void RENAME(chrRangeFromJpeg)(uint16_t *dst, int width) +{ + int i; + for (i = 0; i < width; i++) { + dst[i ] = (dst[i ]*1799 + 4081085)>>11; //1469 + dst[i+VOFW] = (dst[i+VOFW]*1799 + 4081085)>>11; //1469 + } +} +static void RENAME(lumRangeToJpeg)(uint16_t *dst, int width) +{ + int i; + for (i = 0; i < width; i++) + dst[i] = (FFMIN(dst[i],30189)*19077 - 39057361)>>14; +} +static void RENAME(lumRangeFromJpeg)(uint16_t *dst, int width) +{ + int i; + for (i = 0; i < width; i++) + dst[i] = (dst[i]*14071 + 33561947)>>14; +} + #define FAST_BILINEAR_X86 \ "subl %%edi, %%esi \n\t" /* src[xx+1] - src[xx] */ \ "imull %%ecx, %%esi \n\t" /* (src[xx+1] - src[xx])*xalpha */ \ @@ -2180,9 +2252,116 @@ static inline void RENAME(hScale)(int16_t *dst, int dstW, const uint8_t *src, in "shrl $9, %%esi \n\t" \ static inline void RENAME(hyscale_fast)(SwsContext *c, int16_t *dst, - int dstWidth, const uint8_t *src, int srcW, + long dstWidth, const uint8_t *src, int srcW, int xInc) { +#if ARCH_X86 +#if COMPILE_TEMPLATE_MMX2 + int32_t *filterPos = c->hLumFilterPos; + int16_t *filter = c->hLumFilter; + int canMMX2BeUsed = c->canMMX2BeUsed; + void *mmx2FilterCode= c->lumMmx2FilterCode; + int i; +#if defined(PIC) + DECLARE_ALIGNED(8, uint64_t, ebxsave); +#endif + if (canMMX2BeUsed) { + __asm__ volatile( +#if defined(PIC) + "mov %%"REG_b", %5 \n\t" +#endif + "pxor %%mm7, %%mm7 \n\t" + "mov %0, %%"REG_c" \n\t" + "mov %1, %%"REG_D" \n\t" + "mov %2, %%"REG_d" \n\t" + "mov %3, %%"REG_b" \n\t" + "xor %%"REG_a", %%"REG_a" \n\t" // i + PREFETCH" (%%"REG_c") \n\t" + PREFETCH" 32(%%"REG_c") \n\t" + PREFETCH" 64(%%"REG_c") \n\t" + +#if ARCH_X86_64 + +#define CALL_MMX2_FILTER_CODE \ + "movl (%%"REG_b"), %%esi \n\t"\ + "call *%4 \n\t"\ + "movl (%%"REG_b", %%"REG_a"), %%esi \n\t"\ + "add %%"REG_S", %%"REG_c" \n\t"\ + "add %%"REG_a", %%"REG_D" \n\t"\ + "xor %%"REG_a", %%"REG_a" \n\t"\ + +#else + +#define CALL_MMX2_FILTER_CODE \ + "movl (%%"REG_b"), %%esi \n\t"\ + "call *%4 \n\t"\ + "addl (%%"REG_b", %%"REG_a"), %%"REG_c" \n\t"\ + "add %%"REG_a", %%"REG_D" \n\t"\ + "xor %%"REG_a", %%"REG_a" \n\t"\ + +#endif /* ARCH_X86_64 */ + + CALL_MMX2_FILTER_CODE + CALL_MMX2_FILTER_CODE + CALL_MMX2_FILTER_CODE + CALL_MMX2_FILTER_CODE + CALL_MMX2_FILTER_CODE + CALL_MMX2_FILTER_CODE + CALL_MMX2_FILTER_CODE + CALL_MMX2_FILTER_CODE + +#if defined(PIC) + "mov %5, %%"REG_b" \n\t" +#endif + :: "m" (src), "m" (dst), "m" (filter), "m" (filterPos), + "m" (mmx2FilterCode) +#if defined(PIC) + ,"m" (ebxsave) +#endif + : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D +#if !defined(PIC) + ,"%"REG_b +#endif + ); + for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--) dst[i] = src[srcW-1]*128; + } else { +#endif /* COMPILE_TEMPLATE_MMX2 */ + x86_reg xInc_shr16 = xInc >> 16; + uint16_t xInc_mask = xInc & 0xffff; + //NO MMX just normal asm ... + __asm__ volatile( + "xor %%"REG_a", %%"REG_a" \n\t" // i + "xor %%"REG_d", %%"REG_d" \n\t" // xx + "xorl %%ecx, %%ecx \n\t" // xalpha + ASMALIGN(4) + "1: \n\t" + "movzbl (%0, %%"REG_d"), %%edi \n\t" //src[xx] + "movzbl 1(%0, %%"REG_d"), %%esi \n\t" //src[xx+1] + FAST_BILINEAR_X86 + "movw %%si, (%%"REG_D", %%"REG_a", 2) \n\t" + "addw %4, %%cx \n\t" //xalpha += xInc&0xFFFF + "adc %3, %%"REG_d" \n\t" //xx+= xInc>>16 + carry + + "movzbl (%0, %%"REG_d"), %%edi \n\t" //src[xx] + "movzbl 1(%0, %%"REG_d"), %%esi \n\t" //src[xx+1] + FAST_BILINEAR_X86 + "movw %%si, 2(%%"REG_D", %%"REG_a", 2) \n\t" + "addw %4, %%cx \n\t" //xalpha += xInc&0xFFFF + "adc %3, %%"REG_d" \n\t" //xx+= xInc>>16 + carry + + + "add $2, %%"REG_a" \n\t" + "cmp %2, %%"REG_a" \n\t" + " jb 1b \n\t" + + + :: "r" (src), "m" (dst), "m" (dstWidth), "m" (xInc_shr16), "m" (xInc_mask) + : "%"REG_a, "%"REG_d, "%ecx", "%"REG_D, "%esi" + ); +#if COMPILE_TEMPLATE_MMX2 + } //if MMX2 can't be used +#endif +#else int i; unsigned int xpos=0; for (i=0;ilumMmx2FilterPos; - int16_t av_unused *mmx2Filter = c->lumMmx2Filter; - int av_unused canMMX2BeUsed = c->canMMX2BeUsed; - void av_unused *mmx2FilterCode= c->lumMmx2FilterCode; - void (*internal_func)(uint8_t *, const uint8_t *, long, uint32_t *) = isAlpha ? c->hascale_internal : c->hyscale_internal; + void (*toYV12)(uint8_t *, const uint8_t *, long, uint32_t *) = isAlpha ? c->alpToYV12 : c->lumToYV12; + void (*convertRange)(uint16_t *, int) = isAlpha ? NULL : c->lumConvertRange; - if (isAlpha) { - if (srcFormat == PIX_FMT_RGB32 || srcFormat == PIX_FMT_BGR32 ) - src += 3; - } else { - if (srcFormat == PIX_FMT_RGB32_1 || srcFormat == PIX_FMT_BGR32_1) - src += ALT32_CORR; - } + src += isAlpha ? c->alpSrcOffset : c->lumSrcOffset; - if (srcFormat == PIX_FMT_RGB48LE) - src++; - - if (internal_func) { - internal_func(formatConvBuffer, src, srcW, pal); + if (toYV12) { + toYV12(formatConvBuffer, src, srcW, pal); src= formatConvBuffer; } -#if COMPILE_TEMPLATE_MMX - // Use the new MMX scaler if the MMX2 one can't be used (it is faster than the x86 ASM one). - if (!(flags&SWS_FAST_BILINEAR) || (!canMMX2BeUsed)) -#else - if (!(flags&SWS_FAST_BILINEAR)) -#endif - { + if (!c->hyscale_fast) { c->hScale(dst, dstWidth, src, srcW, xInc, hLumFilter, hLumFilterPos, hLumFilterSize); } else { // fast bilinear upscale / crap downscale -#if ARCH_X86 && CONFIG_GPL -#if COMPILE_TEMPLATE_MMX2 - int i; -#if defined(PIC) - DECLARE_ALIGNED(8, uint64_t, ebxsave); -#endif - if (canMMX2BeUsed) { - __asm__ volatile( -#if defined(PIC) - "mov %%"REG_b", %5 \n\t" -#endif - "pxor %%mm7, %%mm7 \n\t" - "mov %0, %%"REG_c" \n\t" - "mov %1, %%"REG_D" \n\t" - "mov %2, %%"REG_d" \n\t" - "mov %3, %%"REG_b" \n\t" - "xor %%"REG_a", %%"REG_a" \n\t" // i - PREFETCH" (%%"REG_c") \n\t" - PREFETCH" 32(%%"REG_c") \n\t" - PREFETCH" 64(%%"REG_c") \n\t" - -#if ARCH_X86_64 - -#define CALL_MMX2_FILTER_CODE \ - "movl (%%"REG_b"), %%esi \n\t"\ - "call *%4 \n\t"\ - "movl (%%"REG_b", %%"REG_a"), %%esi \n\t"\ - "add %%"REG_S", %%"REG_c" \n\t"\ - "add %%"REG_a", %%"REG_D" \n\t"\ - "xor %%"REG_a", %%"REG_a" \n\t"\ - -#else - -#define CALL_MMX2_FILTER_CODE \ - "movl (%%"REG_b"), %%esi \n\t"\ - "call *%4 \n\t"\ - "addl (%%"REG_b", %%"REG_a"), %%"REG_c" \n\t"\ - "add %%"REG_a", %%"REG_D" \n\t"\ - "xor %%"REG_a", %%"REG_a" \n\t"\ - -#endif /* ARCH_X86_64 */ - - CALL_MMX2_FILTER_CODE - CALL_MMX2_FILTER_CODE - CALL_MMX2_FILTER_CODE - CALL_MMX2_FILTER_CODE - CALL_MMX2_FILTER_CODE - CALL_MMX2_FILTER_CODE - CALL_MMX2_FILTER_CODE - CALL_MMX2_FILTER_CODE - -#if defined(PIC) - "mov %5, %%"REG_b" \n\t" -#endif - :: "m" (src), "m" (dst), "m" (mmx2Filter), "m" (mmx2FilterPos), - "m" (mmx2FilterCode) -#if defined(PIC) - ,"m" (ebxsave) -#endif - : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D -#if !defined(PIC) - ,"%"REG_b -#endif - ); - for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--) dst[i] = src[srcW-1]*128; - } else { -#endif /* COMPILE_TEMPLATE_MMX2 */ - x86_reg xInc_shr16 = xInc >> 16; - uint16_t xInc_mask = xInc & 0xffff; - //NO MMX just normal asm ... - __asm__ volatile( - "xor %%"REG_a", %%"REG_a" \n\t" // i - "xor %%"REG_d", %%"REG_d" \n\t" // xx - "xorl %%ecx, %%ecx \n\t" // xalpha - ASMALIGN(4) - "1: \n\t" - "movzbl (%0, %%"REG_d"), %%edi \n\t" //src[xx] - "movzbl 1(%0, %%"REG_d"), %%esi \n\t" //src[xx+1] - FAST_BILINEAR_X86 - "movw %%si, (%%"REG_D", %%"REG_a", 2) \n\t" - "addw %4, %%cx \n\t" //xalpha += xInc&0xFFFF - "adc %3, %%"REG_d" \n\t" //xx+= xInc>>16 + carry - - "movzbl (%0, %%"REG_d"), %%edi \n\t" //src[xx] - "movzbl 1(%0, %%"REG_d"), %%esi \n\t" //src[xx+1] - FAST_BILINEAR_X86 - "movw %%si, 2(%%"REG_D", %%"REG_a", 2) \n\t" - "addw %4, %%cx \n\t" //xalpha += xInc&0xFFFF - "adc %3, %%"REG_d" \n\t" //xx+= xInc>>16 + carry - - - "add $2, %%"REG_a" \n\t" - "cmp %2, %%"REG_a" \n\t" - " jb 1b \n\t" - - - :: "r" (src), "m" (dst), "m" (dstWidth), "m" (xInc_shr16), "m" (xInc_mask) - : "%"REG_a, "%"REG_d, "%ecx", "%"REG_D, "%esi" - ); -#if COMPILE_TEMPLATE_MMX2 - } //if MMX2 can't be used -#endif -#else c->hyscale_fast(c, dst, dstWidth, src, srcW, xInc); -#endif /* ARCH_X86 */ } - if(!isAlpha && c->srcRange != c->dstRange && !(isRGB(c->dstFormat) || isBGR(c->dstFormat))) { - int i; - //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 - if(c->srcRange) { - for (i=0; i>14; - } else { - for (i=0; i>14; - } - } + if (convertRange) + convertRange(dst, dstWidth); } static inline void RENAME(hcscale_fast)(SwsContext *c, int16_t *dst, - int dstWidth, const uint8_t *src1, + long dstWidth, const uint8_t *src1, const uint8_t *src2, int srcW, int xInc) { +#if ARCH_X86 +#if COMPILE_TEMPLATE_MMX2 + int32_t *filterPos = c->hChrFilterPos; + int16_t *filter = c->hChrFilter; + int canMMX2BeUsed = c->canMMX2BeUsed; + void *mmx2FilterCode= c->chrMmx2FilterCode; + int i; +#if defined(PIC) + DECLARE_ALIGNED(8, uint64_t, ebxsave); +#endif + if (canMMX2BeUsed) { + __asm__ volatile( +#if defined(PIC) + "mov %%"REG_b", %6 \n\t" +#endif + "pxor %%mm7, %%mm7 \n\t" + "mov %0, %%"REG_c" \n\t" + "mov %1, %%"REG_D" \n\t" + "mov %2, %%"REG_d" \n\t" + "mov %3, %%"REG_b" \n\t" + "xor %%"REG_a", %%"REG_a" \n\t" // i + PREFETCH" (%%"REG_c") \n\t" + PREFETCH" 32(%%"REG_c") \n\t" + PREFETCH" 64(%%"REG_c") \n\t" + + CALL_MMX2_FILTER_CODE + CALL_MMX2_FILTER_CODE + CALL_MMX2_FILTER_CODE + CALL_MMX2_FILTER_CODE + "xor %%"REG_a", %%"REG_a" \n\t" // i + "mov %5, %%"REG_c" \n\t" // src + "mov %1, %%"REG_D" \n\t" // buf1 + "add $"AV_STRINGIFY(VOF)", %%"REG_D" \n\t" + PREFETCH" (%%"REG_c") \n\t" + PREFETCH" 32(%%"REG_c") \n\t" + PREFETCH" 64(%%"REG_c") \n\t" + + CALL_MMX2_FILTER_CODE + CALL_MMX2_FILTER_CODE + CALL_MMX2_FILTER_CODE + CALL_MMX2_FILTER_CODE + +#if defined(PIC) + "mov %6, %%"REG_b" \n\t" +#endif + :: "m" (src1), "m" (dst), "m" (filter), "m" (filterPos), + "m" (mmx2FilterCode), "m" (src2) +#if defined(PIC) + ,"m" (ebxsave) +#endif + : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D +#if !defined(PIC) + ,"%"REG_b +#endif + ); + for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--) { + //printf("%d %d %d\n", dstWidth, i, srcW); + dst[i] = src1[srcW-1]*128; + dst[i+VOFW] = src2[srcW-1]*128; + } + } else { +#endif /* COMPILE_TEMPLATE_MMX2 */ + x86_reg xInc_shr16 = (x86_reg) (xInc >> 16); + uint16_t xInc_mask = xInc & 0xffff; + __asm__ volatile( + "xor %%"REG_a", %%"REG_a" \n\t" // i + "xor %%"REG_d", %%"REG_d" \n\t" // xx + "xorl %%ecx, %%ecx \n\t" // xalpha + ASMALIGN(4) + "1: \n\t" + "mov %0, %%"REG_S" \n\t" + "movzbl (%%"REG_S", %%"REG_d"), %%edi \n\t" //src[xx] + "movzbl 1(%%"REG_S", %%"REG_d"), %%esi \n\t" //src[xx+1] + FAST_BILINEAR_X86 + "movw %%si, (%%"REG_D", %%"REG_a", 2) \n\t" + + "movzbl (%5, %%"REG_d"), %%edi \n\t" //src[xx] + "movzbl 1(%5, %%"REG_d"), %%esi \n\t" //src[xx+1] + FAST_BILINEAR_X86 + "movw %%si, "AV_STRINGIFY(VOF)"(%%"REG_D", %%"REG_a", 2) \n\t" + + "addw %4, %%cx \n\t" //xalpha += xInc&0xFFFF + "adc %3, %%"REG_d" \n\t" //xx+= xInc>>16 + carry + "add $1, %%"REG_a" \n\t" + "cmp %2, %%"REG_a" \n\t" + " jb 1b \n\t" + +/* GCC 3.3 makes MPlayer crash on IA-32 machines when using "g" operand here, +which is needed to support GCC 4.0. */ +#if ARCH_X86_64 && AV_GCC_VERSION_AT_LEAST(3,4) + :: "m" (src1), "m" (dst), "g" (dstWidth), "m" (xInc_shr16), "m" (xInc_mask), +#else + :: "m" (src1), "m" (dst), "m" (dstWidth), "m" (xInc_shr16), "m" (xInc_mask), +#endif + "r" (src2) + : "%"REG_a, "%"REG_d, "%ecx", "%"REG_D, "%esi" + ); +#if COMPILE_TEMPLATE_MMX2 + } //if MMX2 can't be used +#endif +#else int i; unsigned int xpos=0; for (i=0;ichrMmx2FilterPos; - int16_t av_unused *mmx2Filter = c->chrMmx2Filter; - int av_unused canMMX2BeUsed = c->canMMX2BeUsed; - void av_unused *mmx2FilterCode= c->chrMmx2FilterCode; - if (isGray(srcFormat) || srcFormat==PIX_FMT_MONOBLACK || srcFormat==PIX_FMT_MONOWHITE) - return; + src1 += c->chrSrcOffset; + src2 += c->chrSrcOffset; - if (srcFormat==PIX_FMT_RGB32_1 || srcFormat==PIX_FMT_BGR32_1) { - src1 += ALT32_CORR; - src2 += ALT32_CORR; - } - - if (srcFormat==PIX_FMT_RGB48LE) { - src1++; - src2++; - } - - if (c->hcscale_internal) { - c->hcscale_internal(formatConvBuffer, formatConvBuffer+VOFW, src1, src2, srcW, pal); + if (c->chrToYV12) { + c->chrToYV12(formatConvBuffer, formatConvBuffer+VOFW, src1, src2, srcW, pal); src1= formatConvBuffer; src2= formatConvBuffer+VOFW; } -#if COMPILE_TEMPLATE_MMX - // Use the new MMX scaler if the MMX2 one can't be used (it is faster than the x86 ASM one). - if (!(flags&SWS_FAST_BILINEAR) || (!canMMX2BeUsed)) -#else - if (!(flags&SWS_FAST_BILINEAR)) -#endif - { + if (!c->hcscale_fast) { c->hScale(dst , dstWidth, src1, srcW, xInc, hChrFilter, hChrFilterPos, hChrFilterSize); c->hScale(dst+VOFW, dstWidth, src2, srcW, xInc, hChrFilter, hChrFilterPos, hChrFilterSize); } else { // fast bilinear upscale / crap downscale -#if ARCH_X86 && CONFIG_GPL -#if COMPILE_TEMPLATE_MMX2 - int i; -#if defined(PIC) - DECLARE_ALIGNED(8, uint64_t, ebxsave); -#endif - if (canMMX2BeUsed) { - __asm__ volatile( -#if defined(PIC) - "mov %%"REG_b", %6 \n\t" -#endif - "pxor %%mm7, %%mm7 \n\t" - "mov %0, %%"REG_c" \n\t" - "mov %1, %%"REG_D" \n\t" - "mov %2, %%"REG_d" \n\t" - "mov %3, %%"REG_b" \n\t" - "xor %%"REG_a", %%"REG_a" \n\t" // i - PREFETCH" (%%"REG_c") \n\t" - PREFETCH" 32(%%"REG_c") \n\t" - PREFETCH" 64(%%"REG_c") \n\t" - - CALL_MMX2_FILTER_CODE - CALL_MMX2_FILTER_CODE - CALL_MMX2_FILTER_CODE - CALL_MMX2_FILTER_CODE - "xor %%"REG_a", %%"REG_a" \n\t" // i - "mov %5, %%"REG_c" \n\t" // src - "mov %1, %%"REG_D" \n\t" // buf1 - "add $"AV_STRINGIFY(VOF)", %%"REG_D" \n\t" - PREFETCH" (%%"REG_c") \n\t" - PREFETCH" 32(%%"REG_c") \n\t" - PREFETCH" 64(%%"REG_c") \n\t" - - CALL_MMX2_FILTER_CODE - CALL_MMX2_FILTER_CODE - CALL_MMX2_FILTER_CODE - CALL_MMX2_FILTER_CODE - -#if defined(PIC) - "mov %6, %%"REG_b" \n\t" -#endif - :: "m" (src1), "m" (dst), "m" (mmx2Filter), "m" (mmx2FilterPos), - "m" (mmx2FilterCode), "m" (src2) -#if defined(PIC) - ,"m" (ebxsave) -#endif - : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D -#if !defined(PIC) - ,"%"REG_b -#endif - ); - for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--) { - //printf("%d %d %d\n", dstWidth, i, srcW); - dst[i] = src1[srcW-1]*128; - dst[i+VOFW] = src2[srcW-1]*128; - } - } else { -#endif /* COMPILE_TEMPLATE_MMX2 */ - x86_reg xInc_shr16 = (x86_reg) (xInc >> 16); - uint16_t xInc_mask = xInc & 0xffff; - __asm__ volatile( - "xor %%"REG_a", %%"REG_a" \n\t" // i - "xor %%"REG_d", %%"REG_d" \n\t" // xx - "xorl %%ecx, %%ecx \n\t" // xalpha - ASMALIGN(4) - "1: \n\t" - "mov %0, %%"REG_S" \n\t" - "movzbl (%%"REG_S", %%"REG_d"), %%edi \n\t" //src[xx] - "movzbl 1(%%"REG_S", %%"REG_d"), %%esi \n\t" //src[xx+1] - FAST_BILINEAR_X86 - "movw %%si, (%%"REG_D", %%"REG_a", 2) \n\t" - - "movzbl (%5, %%"REG_d"), %%edi \n\t" //src[xx] - "movzbl 1(%5, %%"REG_d"), %%esi \n\t" //src[xx+1] - FAST_BILINEAR_X86 - "movw %%si, "AV_STRINGIFY(VOF)"(%%"REG_D", %%"REG_a", 2) \n\t" - - "addw %4, %%cx \n\t" //xalpha += xInc&0xFFFF - "adc %3, %%"REG_d" \n\t" //xx+= xInc>>16 + carry - "add $1, %%"REG_a" \n\t" - "cmp %2, %%"REG_a" \n\t" - " jb 1b \n\t" - -/* GCC 3.3 makes MPlayer crash on IA-32 machines when using "g" operand here, - which is needed to support GCC 4.0. */ -#if ARCH_X86_64 && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) - :: "m" (src1), "m" (dst), "g" (dstWidth), "m" (xInc_shr16), "m" (xInc_mask), -#else - :: "m" (src1), "m" (dst), "m" (dstWidth), "m" (xInc_shr16), "m" (xInc_mask), -#endif - "r" (src2) - : "%"REG_a, "%"REG_d, "%ecx", "%"REG_D, "%esi" - ); -#if COMPILE_TEMPLATE_MMX2 - } //if MMX2 can't be used -#endif -#else c->hcscale_fast(c, dst, dstWidth, src1, src2, srcW, xInc); -#endif /* ARCH_X86 */ - } - if(c->srcRange != c->dstRange && !(isRGB(c->dstFormat) || isBGR(c->dstFormat))) { - int i; - //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 - if(c->srcRange) { - for (i=0; i>11; //1469 - dst[i+VOFW]= (dst[i+VOFW]*1799 + 4081085)>>11; //1469 - } - } else { - for (i=0; i>12; //-264 - dst[i+VOFW]= (FFMIN(dst[i+VOFW],30775)*4663 - 9289992)>>12; //-264 - } - } } + + if (c->chrConvertRange) + c->chrConvertRange(dst, dstWidth); } -static int RENAME(swScale)(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, +#define DEBUG_SWSCALE_BUFFERS 0 +#define DEBUG_BUFFERS(...) if (DEBUG_SWSCALE_BUFFERS) av_log(c, AV_LOG_DEBUG, __VA_ARGS__) + +static int RENAME(swScale)(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t* dst[], int dstStride[]) { /* load a few things into local vars to make the code more readable? and faster */ @@ -2540,8 +2562,7 @@ static int RENAME(swScale)(SwsContext *c, uint8_t* src[], int srcStride[], int s const int chrSrcW= c->chrSrcW; const int lumXInc= c->lumXInc; const int chrXInc= c->chrXInc; - const int dstFormat= c->dstFormat; - const int srcFormat= c->srcFormat; + const enum PixelFormat dstFormat= c->dstFormat; const int flags= c->flags; int16_t *vLumFilterPos= c->vLumFilterPos; int16_t *vChrFilterPos= c->vChrFilterPos; @@ -2553,7 +2574,7 @@ static int RENAME(swScale)(SwsContext *c, uint8_t* src[], int srcStride[], int s int16_t *hChrFilter= c->hChrFilter; int32_t *lumMmxFilter= c->lumMmxFilter; int32_t *chrMmxFilter= c->chrMmxFilter; - int32_t *alpMmxFilter= c->alpMmxFilter; + int32_t av_unused *alpMmxFilter= c->alpMmxFilter; const int vLumFilterSize= c->vLumFilterSize; const int vChrFilterSize= c->vChrFilterSize; const int hLumFilterSize= c->hLumFilterSize; @@ -2589,11 +2610,13 @@ static int RENAME(swScale)(SwsContext *c, uint8_t* src[], int srcStride[], int s srcStride[1]<<= c->vChrDrop; srcStride[2]<<= c->vChrDrop; - //printf("swscale %X %X %X -> %X %X %X\n", (int)src[0], (int)src[1], (int)src[2], - // (int)dst[0], (int)dst[1], (int)dst[2]); - - //printf("sws Strides:%d %d %d -> %d %d %d\n", srcStride[0],srcStride[1],srcStride[2], - //dstStride[0],dstStride[1],dstStride[2]); + DEBUG_BUFFERS("swScale() %p[%d] %p[%d] %p[%d] %p[%d] -> %p[%d] %p[%d] %p[%d] %p[%d]\n", + src[0], srcStride[0], src[1], srcStride[1], src[2], srcStride[2], src[3], srcStride[3], + dst[0], dstStride[0], dst[1], dstStride[1], dst[2], dstStride[2], dst[3], dstStride[3]); + DEBUG_BUFFERS("srcSliceY: %d srcSliceH: %d dstY: %d dstH: %d\n", + srcSliceY, srcSliceH, dstY, dstH); + DEBUG_BUFFERS("vLumFilterSize: %d vLumBufSize: %d vChrFilterSize: %d vChrBufSize: %d\n", + vLumFilterSize, vLumBufSize, vChrFilterSize, vChrBufSize); if (dstStride[0]%8 !=0 || dstStride[1]%8 !=0 || dstStride[2]%8 !=0 || dstStride[3]%8 != 0) { static int warnedAlready=0; //FIXME move this into the context perhaps @@ -2608,8 +2631,8 @@ static int RENAME(swScale)(SwsContext *c, uint8_t* src[], int srcStride[], int s will not get executed. This is not really intended but works currently, so people might do it. */ if (srcSliceY ==0) { - lumBufIndex=0; - chrBufIndex=0; + lumBufIndex=-1; + chrBufIndex=-1; dstY=0; lastInLumBuf= -1; lastInChrBuf= -1; @@ -2625,68 +2648,73 @@ static int RENAME(swScale)(SwsContext *c, uint8_t* src[], int srcStride[], int s unsigned char *aDest=(CONFIG_SWSCALE_ALPHA && alpPixBuf) ? dst[3]+dstStride[3]*dstY : NULL; const int firstLumSrcY= vLumFilterPos[dstY]; //First line needed as input + const int firstLumSrcY2= vLumFilterPos[FFMIN(dstY | ((1<chrDstVSubSample) - 1), dstH-1)]; const int firstChrSrcY= vChrFilterPos[chrDstY]; //First line needed as input int lastLumSrcY= firstLumSrcY + vLumFilterSize -1; // Last line needed as input + int lastLumSrcY2=firstLumSrcY2+ vLumFilterSize -1; // Last line needed as input int lastChrSrcY= firstChrSrcY + vChrFilterSize -1; // Last line needed as input int enough_lines; - //printf("dstY:%d dstH:%d firstLumSrcY:%d lastInLumBuf:%d vLumBufSize: %d vChrBufSize: %d slice: %d %d vLumFilterSize: %d firstChrSrcY: %d vChrFilterSize: %d c->chrSrcVSubSample: %d\n", - // dstY, dstH, firstLumSrcY, lastInLumBuf, vLumBufSize, vChrBufSize, srcSliceY, srcSliceH, vLumFilterSize, firstChrSrcY, vChrFilterSize, c->chrSrcVSubSample); //handle holes (FAST_BILINEAR & weird filters) if (firstLumSrcY > lastInLumBuf) lastInLumBuf= firstLumSrcY-1; if (firstChrSrcY > lastInChrBuf) lastInChrBuf= firstChrSrcY-1; - //printf("%d %d %d\n", firstChrSrcY, lastInChrBuf, vChrBufSize); assert(firstLumSrcY >= lastInLumBuf - vLumBufSize + 1); assert(firstChrSrcY >= lastInChrBuf - vChrBufSize + 1); + DEBUG_BUFFERS("dstY: %d\n", dstY); + DEBUG_BUFFERS("\tfirstLumSrcY: %d lastLumSrcY: %d lastInLumBuf: %d\n", + firstLumSrcY, lastLumSrcY, lastInLumBuf); + DEBUG_BUFFERS("\tfirstChrSrcY: %d lastChrSrcY: %d lastInChrBuf: %d\n", + firstChrSrcY, lastChrSrcY, lastInChrBuf); + // Do we have enough lines in this slice to output the dstY line - enough_lines = lastLumSrcY < srcSliceY + srcSliceH && lastChrSrcY < -((-srcSliceY - srcSliceH)>>c->chrSrcVSubSample); + enough_lines = lastLumSrcY2 < srcSliceY + srcSliceH && lastChrSrcY < -((-srcSliceY - srcSliceH)>>c->chrSrcVSubSample); + if (!enough_lines) { lastLumSrcY = srcSliceY + srcSliceH - 1; lastChrSrcY = chrSrcSliceY + chrSrcSliceH - 1; + DEBUG_BUFFERS("buffering slice: lastLumSrcY %d lastChrSrcY %d\n", + lastLumSrcY, lastChrSrcY); } - /* printf("%d %d Last:%d %d LastInBuf:%d %d Index:%d %d Y:%d FSize: %d %d BSize: %d %d\n", - firstChrSrcY,firstLumSrcY,lastChrSrcY,lastLumSrcY, - lastInChrBuf,lastInLumBuf,chrBufIndex,lumBufIndex,dstY,vChrFilterSize,vLumFilterSize, - vChrBufSize, vLumBufSize);*/ - //Do horizontal scaling while(lastInLumBuf < lastLumSrcY) { - uint8_t *src1= src[0]+(lastInLumBuf + 1 - srcSliceY)*srcStride[0]; - uint8_t *src2= src[3]+(lastInLumBuf + 1 - srcSliceY)*srcStride[3]; + const uint8_t *src1= src[0]+(lastInLumBuf + 1 - srcSliceY)*srcStride[0]; + const uint8_t *src2= src[3]+(lastInLumBuf + 1 - srcSliceY)*srcStride[3]; lumBufIndex++; - //printf("%d %d %d %d\n", lumBufIndex, vLumBufSize, lastInLumBuf, lastLumSrcY); assert(lumBufIndex < 2*vLumBufSize); assert(lastInLumBuf + 1 - srcSliceY < srcSliceH); assert(lastInLumBuf + 1 - srcSliceY >= 0); - //printf("%d %d\n", lumBufIndex, vLumBufSize); RENAME(hyscale)(c, lumPixBuf[ lumBufIndex ], dstW, src1, srcW, lumXInc, - flags, hLumFilter, hLumFilterPos, hLumFilterSize, - c->srcFormat, formatConvBuffer, + hLumFilter, hLumFilterPos, hLumFilterSize, + formatConvBuffer, pal, 0); if (CONFIG_SWSCALE_ALPHA && alpPixBuf) RENAME(hyscale)(c, alpPixBuf[ lumBufIndex ], dstW, src2, srcW, lumXInc, - flags, hLumFilter, hLumFilterPos, hLumFilterSize, - c->srcFormat, formatConvBuffer, + hLumFilter, hLumFilterPos, hLumFilterSize, + formatConvBuffer, pal, 1); lastInLumBuf++; + DEBUG_BUFFERS("\t\tlumBufIndex %d: lastInLumBuf: %d\n", + lumBufIndex, lastInLumBuf); } while(lastInChrBuf < lastChrSrcY) { - uint8_t *src1= src[1]+(lastInChrBuf + 1 - chrSrcSliceY)*srcStride[1]; - uint8_t *src2= src[2]+(lastInChrBuf + 1 - chrSrcSliceY)*srcStride[2]; + const uint8_t *src1= src[1]+(lastInChrBuf + 1 - chrSrcSliceY)*srcStride[1]; + const uint8_t *src2= src[2]+(lastInChrBuf + 1 - chrSrcSliceY)*srcStride[2]; chrBufIndex++; assert(chrBufIndex < 2*vChrBufSize); assert(lastInChrBuf + 1 - chrSrcSliceY < (chrSrcSliceH)); assert(lastInChrBuf + 1 - chrSrcSliceY >= 0); //FIXME replace parameters through context struct (some at least) - if (!(isGray(srcFormat) || isGray(dstFormat))) + if (c->needs_hcscale) RENAME(hcscale)(c, chrPixBuf[ chrBufIndex ], chrDstW, src1, src2, chrSrcW, chrXInc, - flags, hChrFilter, hChrFilterPos, hChrFilterSize, - c->srcFormat, formatConvBuffer, + hChrFilter, hChrFilterPos, hChrFilterSize, + formatConvBuffer, pal); lastInChrBuf++; + DEBUG_BUFFERS("\t\tchrBufIndex %d: lastInChrBuf: %d\n", + chrBufIndex, lastInChrBuf); } //wrap buf index around to stay inside the ring buffer if (lumBufIndex >= vLumBufSize) lumBufIndex-= vLumBufSize; @@ -2711,21 +2739,21 @@ static int RENAME(swScale)(SwsContext *c, uint8_t* src[], int srcStride[], int s if (flags & SWS_ACCURATE_RND) { int s= APCK_SIZE / 8; for (i=0; i1)]; + *(const void**)&lumMmxFilter[s*i ]= lumSrcPtr[i ]; + *(const void**)&lumMmxFilter[s*i+APCK_PTR2/4 ]= lumSrcPtr[i+(vLumFilterSize>1)]; lumMmxFilter[s*i+APCK_COEF/4 ]= lumMmxFilter[s*i+APCK_COEF/4+1]= vLumFilter[dstY*vLumFilterSize + i ] + (vLumFilterSize>1 ? vLumFilter[dstY*vLumFilterSize + i + 1]<<16 : 0); if (CONFIG_SWSCALE_ALPHA && alpPixBuf) { - *(void**)&alpMmxFilter[s*i ]= alpSrcPtr[i ]; - *(void**)&alpMmxFilter[s*i+APCK_PTR2/4 ]= alpSrcPtr[i+(vLumFilterSize>1)]; + *(const void**)&alpMmxFilter[s*i ]= alpSrcPtr[i ]; + *(const void**)&alpMmxFilter[s*i+APCK_PTR2/4 ]= alpSrcPtr[i+(vLumFilterSize>1)]; alpMmxFilter[s*i+APCK_COEF/4 ]= alpMmxFilter[s*i+APCK_COEF/4+1]= lumMmxFilter[s*i+APCK_COEF/4 ]; } } for (i=0; i1)]; + *(const void**)&chrMmxFilter[s*i ]= chrSrcPtr[i ]; + *(const void**)&chrMmxFilter[s*i+APCK_PTR2/4 ]= chrSrcPtr[i+(vChrFilterSize>1)]; chrMmxFilter[s*i+APCK_COEF/4 ]= chrMmxFilter[s*i+APCK_COEF/4+1]= vChrFilter[chrDstY*vChrFilterSize + i ] + (vChrFilterSize>1 ? vChrFilter[chrDstY*vChrFilterSize + i + 1]<<16 : 0); @@ -2770,9 +2798,9 @@ static int RENAME(swScale)(SwsContext *c, uint8_t* src[], int srcStride[], int s alpSrcPtr, (uint16_t *) dest, (uint16_t *) uDest, (uint16_t *) vDest, (uint16_t *) aDest, dstW, chrDstW, dstFormat); } else if (vLumFilterSize == 1 && vChrFilterSize == 1) { // unscaled YV12 - int16_t *lumBuf = lumPixBuf[0]; - int16_t *chrBuf= chrPixBuf[0]; - int16_t *alpBuf= (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? alpPixBuf[0] : NULL; + const int16_t *lumBuf = lumSrcPtr[0]; + const int16_t *chrBuf= chrSrcPtr[0]; + const int16_t *alpBuf= (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? alpSrcPtr[0] : NULL; c->yuv2yuv1(c, lumBuf, chrBuf, alpBuf, dest, uDest, vDest, aDest, dstW, chrDstW); } else { //General YV12 c->yuv2yuvX(c, @@ -2902,96 +2930,137 @@ static void RENAME(sws_init_swScale)(SwsContext *c) c->hScale = RENAME(hScale ); - c->hyscale_fast = RENAME(hyscale_fast); - c->hcscale_fast = RENAME(hcscale_fast); +#if COMPILE_TEMPLATE_MMX + // Use the new MMX scaler if the MMX2 one can't be used (it is faster than the x86 ASM one). + if (c->flags & SWS_FAST_BILINEAR && c->canMMX2BeUsed) +#else + if (c->flags & SWS_FAST_BILINEAR) +#endif + { + c->hyscale_fast = RENAME(hyscale_fast); + c->hcscale_fast = RENAME(hcscale_fast); + } - c->hcscale_internal = NULL; + c->chrToYV12 = NULL; switch(srcFormat) { - case PIX_FMT_YUYV422 : c->hcscale_internal = RENAME(yuy2ToUV); break; - case PIX_FMT_UYVY422 : c->hcscale_internal = RENAME(uyvyToUV); break; + case PIX_FMT_YUYV422 : c->chrToYV12 = RENAME(yuy2ToUV); break; + case PIX_FMT_UYVY422 : c->chrToYV12 = RENAME(uyvyToUV); break; + case PIX_FMT_NV12 : c->chrToYV12 = RENAME(nv12ToUV); break; + case PIX_FMT_NV21 : c->chrToYV12 = RENAME(nv21ToUV); break; case PIX_FMT_RGB8 : case PIX_FMT_BGR8 : case PIX_FMT_PAL8 : case PIX_FMT_BGR4_BYTE: - case PIX_FMT_RGB4_BYTE: c->hcscale_internal = palToUV; break; - case PIX_FMT_YUV420PBE: - case PIX_FMT_YUV422PBE: - case PIX_FMT_YUV444PBE: c->hcscale_internal = RENAME(BEToUV); break; - case PIX_FMT_YUV420PLE: - case PIX_FMT_YUV422PLE: - case PIX_FMT_YUV444PLE: c->hcscale_internal = RENAME(LEToUV); break; + case PIX_FMT_RGB4_BYTE: c->chrToYV12 = palToUV; break; + case PIX_FMT_YUV420P16BE: + case PIX_FMT_YUV422P16BE: + case PIX_FMT_YUV444P16BE: c->chrToYV12 = RENAME(BEToUV); break; + case PIX_FMT_YUV420P16LE: + case PIX_FMT_YUV422P16LE: + case PIX_FMT_YUV444P16LE: c->chrToYV12 = RENAME(LEToUV); break; } if (c->chrSrcHSubSample) { switch(srcFormat) { case PIX_FMT_RGB48BE: - case PIX_FMT_RGB48LE: c->hcscale_internal = rgb48ToUV_half; break; + case PIX_FMT_RGB48LE: c->chrToYV12 = rgb48ToUV_half; break; case PIX_FMT_RGB32 : - case PIX_FMT_RGB32_1: c->hcscale_internal = bgr32ToUV_half; break; - case PIX_FMT_BGR24 : c->hcscale_internal = RENAME(bgr24ToUV_half); break; - case PIX_FMT_BGR565 : c->hcscale_internal = bgr16ToUV_half; break; - case PIX_FMT_BGR555 : c->hcscale_internal = bgr15ToUV_half; break; + case PIX_FMT_RGB32_1: c->chrToYV12 = bgr32ToUV_half; break; + case PIX_FMT_BGR24 : c->chrToYV12 = RENAME(bgr24ToUV_half); break; + case PIX_FMT_BGR565 : c->chrToYV12 = bgr16ToUV_half; break; + case PIX_FMT_BGR555 : c->chrToYV12 = bgr15ToUV_half; break; case PIX_FMT_BGR32 : - case PIX_FMT_BGR32_1: c->hcscale_internal = rgb32ToUV_half; break; - case PIX_FMT_RGB24 : c->hcscale_internal = RENAME(rgb24ToUV_half); break; - case PIX_FMT_RGB565 : c->hcscale_internal = rgb16ToUV_half; break; - case PIX_FMT_RGB555 : c->hcscale_internal = rgb15ToUV_half; break; + case PIX_FMT_BGR32_1: c->chrToYV12 = rgb32ToUV_half; break; + case PIX_FMT_RGB24 : c->chrToYV12 = RENAME(rgb24ToUV_half); break; + case PIX_FMT_RGB565 : c->chrToYV12 = rgb16ToUV_half; break; + case PIX_FMT_RGB555 : c->chrToYV12 = rgb15ToUV_half; break; } } else { switch(srcFormat) { case PIX_FMT_RGB48BE: - case PIX_FMT_RGB48LE: c->hcscale_internal = rgb48ToUV; break; + case PIX_FMT_RGB48LE: c->chrToYV12 = rgb48ToUV; break; case PIX_FMT_RGB32 : - case PIX_FMT_RGB32_1: c->hcscale_internal = bgr32ToUV; break; - case PIX_FMT_BGR24 : c->hcscale_internal = RENAME(bgr24ToUV); break; - case PIX_FMT_BGR565 : c->hcscale_internal = bgr16ToUV; break; - case PIX_FMT_BGR555 : c->hcscale_internal = bgr15ToUV; break; + case PIX_FMT_RGB32_1: c->chrToYV12 = bgr32ToUV; break; + case PIX_FMT_BGR24 : c->chrToYV12 = RENAME(bgr24ToUV); break; + case PIX_FMT_BGR565 : c->chrToYV12 = bgr16ToUV; break; + case PIX_FMT_BGR555 : c->chrToYV12 = bgr15ToUV; break; case PIX_FMT_BGR32 : - case PIX_FMT_BGR32_1: c->hcscale_internal = rgb32ToUV; break; - case PIX_FMT_RGB24 : c->hcscale_internal = RENAME(rgb24ToUV); break; - case PIX_FMT_RGB565 : c->hcscale_internal = rgb16ToUV; break; - case PIX_FMT_RGB555 : c->hcscale_internal = rgb15ToUV; break; + case PIX_FMT_BGR32_1: c->chrToYV12 = rgb32ToUV; break; + case PIX_FMT_RGB24 : c->chrToYV12 = RENAME(rgb24ToUV); break; + case PIX_FMT_RGB565 : c->chrToYV12 = rgb16ToUV; break; + case PIX_FMT_RGB555 : c->chrToYV12 = rgb15ToUV; break; } } - c->hyscale_internal = NULL; - c->hascale_internal = NULL; + c->lumToYV12 = NULL; + c->alpToYV12 = NULL; switch (srcFormat) { case PIX_FMT_YUYV422 : - case PIX_FMT_YUV420PBE: - case PIX_FMT_YUV422PBE: - case PIX_FMT_YUV444PBE: - case PIX_FMT_GRAY16BE : c->hyscale_internal = RENAME(yuy2ToY); break; + case PIX_FMT_YUV420P16BE: + case PIX_FMT_YUV422P16BE: + case PIX_FMT_YUV444P16BE: + case PIX_FMT_GRAY16BE : c->lumToYV12 = RENAME(yuy2ToY); break; case PIX_FMT_UYVY422 : - case PIX_FMT_YUV420PLE: - case PIX_FMT_YUV422PLE: - case PIX_FMT_YUV444PLE: - case PIX_FMT_GRAY16LE : c->hyscale_internal = RENAME(uyvyToY); break; - case PIX_FMT_BGR24 : c->hyscale_internal = RENAME(bgr24ToY); break; - case PIX_FMT_BGR565 : c->hyscale_internal = bgr16ToY; break; - case PIX_FMT_BGR555 : c->hyscale_internal = bgr15ToY; break; - case PIX_FMT_RGB24 : c->hyscale_internal = RENAME(rgb24ToY); break; - case PIX_FMT_RGB565 : c->hyscale_internal = rgb16ToY; break; - case PIX_FMT_RGB555 : c->hyscale_internal = rgb15ToY; break; + case PIX_FMT_YUV420P16LE: + case PIX_FMT_YUV422P16LE: + case PIX_FMT_YUV444P16LE: + case PIX_FMT_GRAY16LE : c->lumToYV12 = RENAME(uyvyToY); break; + case PIX_FMT_BGR24 : c->lumToYV12 = RENAME(bgr24ToY); break; + case PIX_FMT_BGR565 : c->lumToYV12 = bgr16ToY; break; + case PIX_FMT_BGR555 : c->lumToYV12 = bgr15ToY; break; + case PIX_FMT_RGB24 : c->lumToYV12 = RENAME(rgb24ToY); break; + case PIX_FMT_RGB565 : c->lumToYV12 = rgb16ToY; break; + case PIX_FMT_RGB555 : c->lumToYV12 = rgb15ToY; break; case PIX_FMT_RGB8 : case PIX_FMT_BGR8 : case PIX_FMT_PAL8 : case PIX_FMT_BGR4_BYTE: - case PIX_FMT_RGB4_BYTE: c->hyscale_internal = palToY; break; - case PIX_FMT_MONOBLACK: c->hyscale_internal = monoblack2Y; break; - case PIX_FMT_MONOWHITE: c->hyscale_internal = monowhite2Y; break; + case PIX_FMT_RGB4_BYTE: c->lumToYV12 = palToY; break; + case PIX_FMT_MONOBLACK: c->lumToYV12 = monoblack2Y; break; + case PIX_FMT_MONOWHITE: c->lumToYV12 = monowhite2Y; break; case PIX_FMT_RGB32 : - case PIX_FMT_RGB32_1: c->hyscale_internal = bgr32ToY; break; + case PIX_FMT_RGB32_1: c->lumToYV12 = bgr32ToY; break; case PIX_FMT_BGR32 : - case PIX_FMT_BGR32_1: c->hyscale_internal = rgb32ToY; break; + case PIX_FMT_BGR32_1: c->lumToYV12 = rgb32ToY; break; case PIX_FMT_RGB48BE: - case PIX_FMT_RGB48LE: c->hyscale_internal = rgb48ToY; break; + case PIX_FMT_RGB48LE: c->lumToYV12 = rgb48ToY; break; } if (c->alpPixBuf) { switch (srcFormat) { case PIX_FMT_RGB32 : case PIX_FMT_RGB32_1: case PIX_FMT_BGR32 : - case PIX_FMT_BGR32_1: c->hascale_internal = abgrToA; break; + case PIX_FMT_BGR32_1: c->alpToYV12 = abgrToA; break; } } + + switch (srcFormat) { + case PIX_FMT_RGB32 : + case PIX_FMT_BGR32 : + c->alpSrcOffset = 3; + break; + case PIX_FMT_RGB32_1: + case PIX_FMT_BGR32_1: + c->lumSrcOffset = ALT32_CORR; + c->chrSrcOffset = ALT32_CORR; + break; + case PIX_FMT_RGB48LE: + c->lumSrcOffset = 1; + c->chrSrcOffset = 1; + c->alpSrcOffset = 1; + break; + } + + if (c->srcRange != c->dstRange && !isAnyRGB(c->dstFormat)) { + if (c->srcRange) { + c->lumConvertRange = RENAME(lumRangeFromJpeg); + c->chrConvertRange = RENAME(chrRangeFromJpeg); + } else { + c->lumConvertRange = RENAME(lumRangeToJpeg); + c->chrConvertRange = RENAME(chrRangeToJpeg); + } + } + + if (!(isGray(srcFormat) || isGray(c->dstFormat) || + srcFormat == PIX_FMT_MONOBLACK || srcFormat == PIX_FMT_MONOWHITE)) + c->needs_hcscale = 1; } diff --git a/src/add-ons/media/plugins/ffmpeg/libswscale/utils.c b/src/add-ons/media/plugins/ffmpeg/libswscale/utils.c new file mode 100644 index 0000000000..d7a6ea25b0 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libswscale/utils.c @@ -0,0 +1,1591 @@ +/* + * Copyright (C) 2001-2003 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 + */ + +#define _SVID_SOURCE //needed for MAP_ANONYMOUS +#include +#include +#include +#include +#include "config.h" +#include +#if HAVE_SYS_MMAN_H +#include +#if defined(MAP_ANON) && !defined(MAP_ANONYMOUS) +#define MAP_ANONYMOUS MAP_ANON +#endif +#endif +#if HAVE_VIRTUALALLOC +#define WIN32_LEAN_AND_MEAN +#include +#endif +#include "swscale.h" +#include "swscale_internal.h" +#include "rgb2rgb.h" +#include "libavutil/intreadwrite.h" +#include "libavutil/x86_cpu.h" +#include "libavutil/avutil.h" +#include "libavutil/bswap.h" +#include "libavutil/pixdesc.h" + +unsigned swscale_version(void) +{ + return LIBSWSCALE_VERSION_INT; +} + +const char *swscale_configuration(void) +{ + return FFMPEG_CONFIGURATION; +} + +const char *swscale_license(void) +{ +#define LICENSE_PREFIX "libswscale license: " + 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_BGR24 \ + || (x)==PIX_FMT_BGR565 \ + || (x)==PIX_FMT_BGR555 \ + || (x)==PIX_FMT_BGR32 \ + || (x)==PIX_FMT_BGR32_1 \ + || (x)==PIX_FMT_RGB24 \ + || (x)==PIX_FMT_RGB565 \ + || (x)==PIX_FMT_RGB555 \ + || (x)==PIX_FMT_GRAY8 \ + || (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_YUV420P16LE \ + || (x)==PIX_FMT_YUV422P16LE \ + || (x)==PIX_FMT_YUV444P16LE \ + || (x)==PIX_FMT_YUV420P16BE \ + || (x)==PIX_FMT_YUV422P16BE \ + || (x)==PIX_FMT_YUV444P16BE \ + ) + +int sws_isSupportedInput(enum PixelFormat pix_fmt) +{ + return isSupportedIn(pix_fmt); +} + +#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 \ + || isAnyRGB(x) \ + || (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_YUV420P16LE \ + || (x)==PIX_FMT_YUV422P16LE \ + || (x)==PIX_FMT_YUV444P16LE \ + || (x)==PIX_FMT_YUV420P16BE \ + || (x)==PIX_FMT_YUV422P16BE \ + || (x)==PIX_FMT_YUV444P16BE \ + ) + +int sws_isSupportedOutput(enum PixelFormat pix_fmt) +{ + return isSupportedOut(pix_fmt); +} + +extern const int32_t ff_yuv2rgb_coeffs[8][4]; + +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"; +} + +static double getSplineCoeff(double a, double b, double c, double d, double dist) +{ +// printf("%f %f %f %f %f\n", a,b,c,d,dist); + if (dist<=1.0) return ((d*dist + c)*dist + b)*dist +a; + else return getSplineCoeff( 0.0, + b+ 2.0*c + 3.0*d, + c + 3.0*d, + -b- 3.0*c - 6.0*d, + dist-1.0); +} + +static int initFilter(int16_t **outFilter, int16_t **filterPos, int *outFilterSize, int xInc, + int srcW, int dstW, int filterAlign, int one, int flags, + SwsVector *srcFilter, SwsVector *dstFilter, double param[2]) +{ + int i; + int filterSize; + int filter2Size; + int minFilterSize; + int64_t *filter=NULL; + int64_t *filter2=NULL; + const int64_t fone= 1LL<<54; + int ret= -1; +#if ARCH_X86 + if (flags & SWS_CPU_CAPS_MMX) + __asm__ volatile("emms\n\t"::: "memory"); //FIXME this should not be required but it IS (even for non-MMX versions) +#endif + + // 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); + + if (FFABS(xInc - 0x10000) <10) { // unscaled + int i; + filterSize= 1; + FF_ALLOCZ_OR_GOTO(NULL, filter, dstW*sizeof(*filter)*filterSize, fail); + + for (i=0; i>16; + + (*filterPos)[i]= xx; + filter[i]= fone; + xDstInSrc+= xInc; + } + } else if ((xInc <= (1<<16) && (flags&SWS_AREA)) || (flags&SWS_FAST_BILINEAR)) { // bilinear upscale + int i; + int xDstInSrc; + filterSize= 2; + FF_ALLOC_OR_GOTO(NULL, filter, dstW*sizeof(*filter)*filterSize, fail); + + xDstInSrc= xInc/2 - 0x8000; + for (i=0; i>16; + int j; + + (*filterPos)[i]= xx; + //bilinear upscale / linear interpolate / area averaging + for (j=0; j>16); + if (coeff<0) coeff=0; + filter[i*filterSize + j]= coeff; + xx++; + } + xDstInSrc+= xInc; + } + } else { + int xDstInSrc; + int sizeFactor; + + if (flags&SWS_BICUBIC) sizeFactor= 4; + else if (flags&SWS_X) sizeFactor= 8; + else if (flags&SWS_AREA) sizeFactor= 1; //downscale only, for upscale it is bilinear + else if (flags&SWS_GAUSS) sizeFactor= 8; // infinite ;) + else if (flags&SWS_LANCZOS) sizeFactor= param[0] != SWS_PARAM_DEFAULT ? ceil(2*param[0]) : 6; + else if (flags&SWS_SINC) sizeFactor= 20; // infinite ;) + else if (flags&SWS_SPLINE) sizeFactor= 20; // infinite ;) + else if (flags&SWS_BILINEAR) sizeFactor= 2; + else { + sizeFactor= 0; //GCC warning killer + assert(0); + } + + if (xInc <= 1<<16) filterSize= 1 + sizeFactor; // upscale + else filterSize= 1 + (sizeFactor*srcW + dstW - 1)/ dstW; + + if (filterSize > srcW-2) filterSize=srcW-2; + + FF_ALLOC_OR_GOTO(NULL, filter, dstW*sizeof(*filter)*filterSize, fail); + + xDstInSrc= xInc - 0x10000; + for (i=0; i 1<<16) + d= d*dstW/srcW; + floatd= d * (1.0/(1<<30)); + + 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; + coeff *= fone>>(30+24); + } +/* else if (flags & SWS_X) { + double p= param ? param*0.01 : 0.3; + coeff = d ? sin(d*PI)/(d*PI) : 1.0; + coeff*= pow(2.0, - p*d*d); + }*/ + else if (flags & SWS_X) { + double A= param[0] != SWS_PARAM_DEFAULT ? param[0] : 1.0; + double c; + + if (floatd<1.0) + c = cos(floatd*M_PI); + else + c=-1.0; + if (c<0.0) c= -pow(-c, A); + else c= pow( c, A); + coeff= (c*0.5 + 0.5)*fone; + } else if (flags & SWS_AREA) { + int64_t d2= d - (1<<29); + if (d2*xInc < -(1LL<<(29+16))) coeff= 1.0 * (1LL<<(30+16)); + else if (d2*xInc < (1LL<<(29+16))) coeff= -d2*xInc + (1LL<<(29+16)); + else coeff=0.0; + coeff *= fone>>(30+16); + } else if (flags & SWS_GAUSS) { + double p= param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0; + coeff = (pow(2.0, - p*floatd*floatd))*fone; + } else if (flags & SWS_SINC) { + coeff = (d ? sin(floatd*M_PI)/(floatd*M_PI) : 1.0)*fone; + } else if (flags & SWS_LANCZOS) { + double p= param[0] != SWS_PARAM_DEFAULT ? param[0] : 3.0; + coeff = (d ? sin(floatd*M_PI)*sin(floatd*M_PI/p)/(floatd*floatd*M_PI*M_PI/p) : 1.0)*fone; + if (floatd>p) coeff=0; + } else if (flags & SWS_BILINEAR) { + coeff= (1<<30) - d; + if (coeff<0) coeff=0; + coeff *= fone >> 30; + } else if (flags & SWS_SPLINE) { + double p=-2.196152422706632; + coeff = getSplineCoeff(1.0, 0.0, p, -p-1.0, floatd) * fone; + } else { + coeff= 0.0; //GCC warning killer + assert(0); + } + + filter[i*filterSize + j]= coeff; + xx++; + } + xDstInSrc+= 2*xInc; + } + } + + /* apply src & dst Filter to filter -> filter2 + av_free(filter); + */ + assert(filterSize>0); + filter2Size= filterSize; + if (srcFilter) filter2Size+= srcFilter->length - 1; + if (dstFilter) filter2Size+= dstFilter->length - 1; + assert(filter2Size>0); + FF_ALLOCZ_OR_GOTO(NULL, filter2, filter2Size*dstW*sizeof(*filter2), fail); + + for (i=0; ilength; k++) { + for (j=0; jcoeff[k]*filter[i*filterSize + j]; + } + } else { + for (j=0; j=0; i--) { + int min= filter2Size; + int j; + int64_t cutOff=0.0; + + /* get rid of near zero elements on the left by shifting left */ + for (j=0; j SWS_MAX_REDUCE_CUTOFF*fone) break; + + /* preserve monotonicity because the core can't handle the filter otherwise */ + if (i= (*filterPos)[i+1]) break; + + // move filter coefficients left + for (k=1; k0; j--) { + cutOff += FFABS(filter2[i*filter2Size + j]); + + if (cutOff > SWS_MAX_REDUCE_CUTOFF*fone) break; + min--; + } + + if (min>minFilterSize) minFilterSize= min; + } + + if (flags & SWS_CPU_CAPS_ALTIVEC) { + // we can handle the special case 4, + // so we don't want to go to the full 8 + if (minFilterSize < 5) + filterAlign = 4; + + // We really don't want to waste our time + // doing useless computation, so fall back on + // the scalar C code for very small filters. + // Vectorizing is worth it only if you have a + // decent-sized vector. + if (minFilterSize < 3) + filterAlign = 1; + } + + if (flags & SWS_CPU_CAPS_MMX) { + // special case for unscaled vertical filtering + if (minFilterSize == 1 && filterAlign == 2) + filterAlign= 1; + } + + assert(minFilterSize > 0); + filterSize= (minFilterSize +(filterAlign-1)) & (~(filterAlign-1)); + assert(filterSize > 0); + filter= av_malloc(filterSize*dstW*sizeof(*filter)); + if (filterSize >= MAX_FILTER_SIZE*16/((flags&SWS_ACCURATE_RND) ? APCK_SIZE : 16) || !filter) + goto fail; + *outFilterSize= filterSize; + + if (flags&SWS_PRINT_INFO) + av_log(NULL, AV_LOG_VERBOSE, "SwScaler: reducing / aligning filtersize %d -> %d\n", filter2Size, filterSize); + /* try to reduce the filter-size (step2 reduce it) */ + for (i=0; i=filter2Size) filter[i*filterSize + j]= 0; + else filter[i*filterSize + j]= filter2[i*filter2Size + j]; + if((flags & SWS_BITEXACT) && j>=minFilterSize) + filter[i*filterSize + j]= 0; + } + } + + //FIXME try to align filterPos if possible + + //fix borders + for (i=0; i srcW) { + int shift= (*filterPos)[i] + filterSize - srcW; + // move filter coefficients right to compensate for filterPos + for (j=filterSize-2; j>=0; j--) { + int right= FFMIN(j + shift, filterSize-1); + filter[i*filterSize +right] += filter[i*filterSize +j]; + filter[i*filterSize +j]=0; + } + (*filterPos)[i]= srcW - filterSize; + } + } + + // 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); + + /* normalize & store in outFilter */ + for (i=0; i>16; + + if ((i&3) == 0) { + int a=0; + int b=((xpos+xInc)>>16) - xx; + int c=((xpos+xInc*2)>>16) - xx; + int d=((xpos+xInc*3)>>16) - xx; + int inc = (d+1<4); + uint8_t *fragment = (d+1<4) ? fragmentB : fragmentA; + x86_reg imm8OfPShufW1 = (d+1<4) ? imm8OfPShufW1B : imm8OfPShufW1A; + x86_reg imm8OfPShufW2 = (d+1<4) ? imm8OfPShufW2B : imm8OfPShufW2A; + x86_reg fragmentLength = (d+1<4) ? fragmentLengthB : fragmentLengthA; + int maxShift= 3-(d+inc); + int shift=0; + + if (filterCode) { + filter[i ] = (( xpos & 0xFFFF) ^ 0xFFFF)>>9; + filter[i+1] = (((xpos+xInc ) & 0xFFFF) ^ 0xFFFF)>>9; + filter[i+2] = (((xpos+xInc*2) & 0xFFFF) ^ 0xFFFF)>>9; + filter[i+3] = (((xpos+xInc*3) & 0xFFFF) ^ 0xFFFF)>>9; + filterPos[i/2]= xx; + + memcpy(filterCode + fragmentPos, fragment, fragmentLength); + + filterCode[fragmentPos + imm8OfPShufW1]= + (a+inc) | ((b+inc)<<2) | ((c+inc)<<4) | ((d+inc)<<6); + filterCode[fragmentPos + imm8OfPShufW2]= + a | (b<<2) | (c<<4) | (d<<6); + + if (i+4-inc>=dstW) shift=maxShift; //avoid overread + else if ((filterPos[i/2]&3) <= maxShift) shift=filterPos[i/2]&3; //Align + + if (shift && i>=shift) { + filterCode[fragmentPos + imm8OfPShufW1]+= 0x55*shift; + filterCode[fragmentPos + imm8OfPShufW2]+= 0x55*shift; + filterPos[i/2]-=shift; + } + } + + fragmentPos+= fragmentLength; + + if (filterCode) + filterCode[fragmentPos]= RET; + } + xpos+=xInc; + } + if (filterCode) + filterPos[((i/2)+1)&(~1)]= xpos>>16; // needed to jump to the next part + + return fragmentPos + 1; +} +#endif /* ARCH_X86 && (HAVE_MMX2 || CONFIG_RUNTIME_CPUDETECT) */ + +static void getSubSampleFactors(int *h, int *v, enum PixelFormat format) +{ + *h = av_pix_fmt_descriptors[format].log2_chroma_w; + *v = av_pix_fmt_descriptors[format].log2_chroma_h; +} + +static uint16_t roundToInt16(int64_t f) +{ + int r= (f + (1<<15))>>16; + if (r<-0x7FFF) return 0x8000; + else if (r> 0x7FFF) return 0x7FFF; + else return r; +} + +int sws_setColorspaceDetails(SwsContext *c, const int inv_table[4], int srcRange, const int table[4], int dstRange, int brightness, int contrast, int saturation) +{ + int64_t crv = inv_table[0]; + int64_t cbu = inv_table[1]; + int64_t cgu = -inv_table[2]; + int64_t cgv = -inv_table[3]; + int64_t cy = 1<<16; + int64_t oy = 0; + + memcpy(c->srcColorspaceTable, inv_table, sizeof(int)*4); + memcpy(c->dstColorspaceTable, table, sizeof(int)*4); + + c->brightness= brightness; + c->contrast = contrast; + c->saturation= saturation; + c->srcRange = srcRange; + c->dstRange = dstRange; + if (isYUV(c->dstFormat) || isGray(c->dstFormat)) return -1; + + c->uOffset= 0x0400040004000400LL; + c->vOffset= 0x0400040004000400LL; + + if (!srcRange) { + cy= (cy*255) / 219; + oy= 16<<16; + } else { + crv= (crv*224) / 255; + cbu= (cbu*224) / 255; + cgu= (cgu*224) / 255; + cgv= (cgv*224) / 255; + } + + cy = (cy *contrast )>>16; + crv= (crv*contrast * saturation)>>32; + cbu= (cbu*contrast * saturation)>>32; + cgu= (cgu*contrast * saturation)>>32; + cgv= (cgv*contrast * saturation)>>32; + + oy -= 256*brightness; + + c->yCoeff= roundToInt16(cy *8192) * 0x0001000100010001ULL; + c->vrCoeff= roundToInt16(crv*8192) * 0x0001000100010001ULL; + c->ubCoeff= roundToInt16(cbu*8192) * 0x0001000100010001ULL; + c->vgCoeff= roundToInt16(cgv*8192) * 0x0001000100010001ULL; + c->ugCoeff= roundToInt16(cgu*8192) * 0x0001000100010001ULL; + c->yOffset= roundToInt16(oy * 8) * 0x0001000100010001ULL; + + c->yuv2rgb_y_coeff = (int16_t)roundToInt16(cy <<13); + c->yuv2rgb_y_offset = (int16_t)roundToInt16(oy << 9); + c->yuv2rgb_v2r_coeff= (int16_t)roundToInt16(crv<<13); + c->yuv2rgb_v2g_coeff= (int16_t)roundToInt16(cgv<<13); + c->yuv2rgb_u2g_coeff= (int16_t)roundToInt16(cgu<<13); + c->yuv2rgb_u2b_coeff= (int16_t)roundToInt16(cbu<<13); + + ff_yuv2rgb_c_init_tables(c, inv_table, srcRange, brightness, contrast, saturation); + //FIXME factorize + +#if HAVE_ALTIVEC + if (c->flags & SWS_CPU_CAPS_ALTIVEC) + ff_yuv2rgb_init_tables_altivec(c, inv_table, brightness, contrast, saturation); +#endif + return 0; +} + +int sws_getColorspaceDetails(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; + + *inv_table = c->srcColorspaceTable; + *table = c->dstColorspaceTable; + *srcRange = c->srcRange; + *dstRange = c->dstRange; + *brightness= c->brightness; + *contrast = c->contrast; + *saturation= c->saturation; + + return 0; +} + +static int handle_jpeg(enum PixelFormat *format) +{ + switch (*format) { + case PIX_FMT_YUVJ420P: + *format = PIX_FMT_YUV420P; + return 1; + case PIX_FMT_YUVJ422P: + *format = PIX_FMT_YUV422P; + return 1; + case PIX_FMT_YUVJ444P: + *format = PIX_FMT_YUV444P; + return 1; + case PIX_FMT_YUVJ440P: + *format = PIX_FMT_YUV440P; + return 1; + default: + return 0; + } +} + +SwsContext *sws_getContext(int srcW, int srcH, enum PixelFormat srcFormat, + int dstW, int dstH, enum PixelFormat dstFormat, int flags, + SwsFilter *srcFilter, SwsFilter *dstFilter, const double *param) +{ + SwsContext *c; + int i; + int usesVFilter, usesHFilter; + int unscaled; + int srcRange, dstRange; + SwsFilter dummyFilter= {NULL, NULL, NULL, NULL}; +#if ARCH_X86 + if (flags & SWS_CPU_CAPS_MMX) + __asm__ volatile("emms\n\t"::: "memory"); +#endif + +#if !CONFIG_RUNTIME_CPUDETECT //ensure that the flags match the compiled variant if cpudetect is off + flags &= ~(SWS_CPU_CAPS_MMX|SWS_CPU_CAPS_MMX2|SWS_CPU_CAPS_3DNOW|SWS_CPU_CAPS_ALTIVEC|SWS_CPU_CAPS_BFIN); + flags |= ff_hardcodedcpuflags(); +#endif /* CONFIG_RUNTIME_CPUDETECT */ + if (!rgb15to16) sws_rgb2rgb_init(flags); + + unscaled = (srcW == dstW && srcH == dstH); + + srcRange = handle_jpeg(&srcFormat); + dstRange = handle_jpeg(&dstFormat); + + if (!isSupportedIn(srcFormat)) { + av_log(NULL, AV_LOG_ERROR, "swScaler: %s is not supported as input pixel format\n", sws_format_name(srcFormat)); + return NULL; + } + if (!isSupportedOut(dstFormat)) { + av_log(NULL, AV_LOG_ERROR, "swScaler: %s is not supported as output pixel format\n", sws_format_name(dstFormat)); + return NULL; + } + + i= flags & ( SWS_POINT + |SWS_AREA + |SWS_BILINEAR + |SWS_FAST_BILINEAR + |SWS_BICUBIC + |SWS_X + |SWS_GAUSS + |SWS_LANCZOS + |SWS_SINC + |SWS_SPLINE + |SWS_BICUBLIN); + if(!i || (i & (i-1))) { + av_log(NULL, AV_LOG_ERROR, "swScaler: Exactly one scaler algorithm must be chosen\n"); + return NULL; + } + + /* sanity check */ + if (srcW<4 || srcH<1 || dstW<8 || dstH<1) { //FIXME check if these are enough and try to lowwer them after fixing the relevant parts of the code + av_log(NULL, AV_LOG_ERROR, "swScaler: %dx%d -> %dx%d is invalid scaling dimension\n", + srcW, srcH, dstW, dstH); + return NULL; + } + if(srcW > VOFW || dstW > VOFW) { + av_log(NULL, AV_LOG_ERROR, "swScaler: Compile-time maximum width is "AV_STRINGIFY(VOFW)" change VOF/VOFW and recompile\n"); + return NULL; + } + + if (!dstFilter) dstFilter= &dummyFilter; + if (!srcFilter) srcFilter= &dummyFilter; + + FF_ALLOCZ_OR_GOTO(NULL, c, sizeof(SwsContext), fail); + + c->av_class = &sws_context_class; + c->srcW= srcW; + c->srcH= srcH; + c->dstW= dstW; + c->dstH= dstH; + c->lumXInc= ((srcW<<16) + (dstW>>1))/dstW; + c->lumYInc= ((srcH<<16) + (dstH>>1))/dstH; + c->flags= flags; + c->dstFormat= dstFormat; + c->srcFormat= srcFormat; + c->dstFormatBpp = av_get_bits_per_pixel(&av_pix_fmt_descriptors[dstFormat]); + c->srcFormatBpp = av_get_bits_per_pixel(&av_pix_fmt_descriptors[srcFormat]); + c->vRounder= 4* 0x0001000100010001ULL; + + usesVFilter = (srcFilter->lumV && srcFilter->lumV->length>1) || + (srcFilter->chrV && srcFilter->chrV->length>1) || + (dstFilter->lumV && dstFilter->lumV->length>1) || + (dstFilter->chrV && dstFilter->chrV->length>1); + usesHFilter = (srcFilter->lumH && srcFilter->lumH->length>1) || + (srcFilter->chrH && srcFilter->chrH->length>1) || + (dstFilter->lumH && dstFilter->lumH->length>1) || + (dstFilter->chrH && dstFilter->chrH->length>1); + + getSubSampleFactors(&c->chrSrcHSubSample, &c->chrSrcVSubSample, srcFormat); + getSubSampleFactors(&c->chrDstHSubSample, &c->chrDstVSubSample, dstFormat); + + // reuse chroma for 2 pixels RGB/BGR unless user wants full chroma interpolation + if (isAnyRGB(dstFormat) && !(flags&SWS_FULL_CHR_H_INT)) c->chrDstHSubSample=1; + + // drop some chroma lines if the user wants it + c->vChrDrop= (flags&SWS_SRC_V_CHR_DROP_MASK)>>SWS_SRC_V_CHR_DROP_SHIFT; + c->chrSrcVSubSample+= c->vChrDrop; + + // drop every other pixel for chroma calculation unless user wants full chroma + if (isAnyRGB(srcFormat) && !(flags&SWS_FULL_CHR_H_INP) + && srcFormat!=PIX_FMT_RGB8 && srcFormat!=PIX_FMT_BGR8 + && srcFormat!=PIX_FMT_RGB4 && srcFormat!=PIX_FMT_BGR4 + && srcFormat!=PIX_FMT_RGB4_BYTE && srcFormat!=PIX_FMT_BGR4_BYTE + && ((dstW>>c->chrDstHSubSample) <= (srcW>>1) || (flags&(SWS_FAST_BILINEAR|SWS_POINT)))) + c->chrSrcHSubSample=1; + + if (param) { + c->param[0] = param[0]; + c->param[1] = param[1]; + } else { + c->param[0] = + c->param[1] = SWS_PARAM_DEFAULT; + } + + // Note the -((-x)>>y) is so that we always round toward +inf. + c->chrSrcW= -((-srcW) >> c->chrSrcHSubSample); + c->chrSrcH= -((-srcH) >> c->chrSrcVSubSample); + c->chrDstW= -((-dstW) >> c->chrDstHSubSample); + c->chrDstH= -((-dstH) >> c->chrDstVSubSample); + + sws_setColorspaceDetails(c, ff_yuv2rgb_coeffs[SWS_CS_DEFAULT], srcRange, ff_yuv2rgb_coeffs[SWS_CS_DEFAULT] /* FIXME*/, dstRange, 0, 1<<16, 1<<16); + + /* unscaled special cases */ + if (unscaled && !usesHFilter && !usesVFilter && (srcRange == dstRange || isAnyRGB(dstFormat))) { + ff_get_unscaled_swscale(c); + + 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)); + return c; + } + } + + if (flags & SWS_CPU_CAPS_MMX2) { + 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; + } + else + c->canMMX2BeUsed=0; + + c->chrXInc= ((c->chrSrcW<<16) + (c->chrDstW>>1))/c->chrDstW; + c->chrYInc= ((c->chrSrcH<<16) + (c->chrDstH>>1))/c->chrDstH; + + // match pixel 0 of the src to pixel 0 of dst and match pixel n-2 of src to pixel n-2 of dst + // but only for the FAST_BILINEAR mode otherwise do correct scaling + // n-2 is the last chrominance sample available + // this is not perfect, but no one should notice the difference, the more correct variant + // would be like the vertical one, but that would require some special code for the + // first and last pixel + if (flags&SWS_FAST_BILINEAR) { + if (c->canMMX2BeUsed) { + c->lumXInc+= 20; + c->chrXInc+= 20; + } + //we don't use the x86 asm scaler if MMX is available + else if (flags & SWS_CPU_CAPS_MMX) { + c->lumXInc = ((srcW-2)<<16)/(dstW-2) - 20; + c->chrXInc = ((c->chrSrcW-2)<<16)/(c->chrDstW-2) - 20; + } + } + + /* precalculate horizontal scaler filter coefficients */ + { +#if ARCH_X86 && (HAVE_MMX2 || CONFIG_RUNTIME_CPUDETECT) +// can't downscale !!! + if (c->canMMX2BeUsed && (flags & SWS_FAST_BILINEAR)) { + c->lumMmx2FilterCodeSize = initMMX2HScaler( dstW, c->lumXInc, NULL, NULL, NULL, 8); + c->chrMmx2FilterCodeSize = initMMX2HScaler(c->chrDstW, c->chrXInc, NULL, NULL, NULL, 4); + +#ifdef MAP_ANONYMOUS + c->lumMmx2FilterCode = mmap(NULL, c->lumMmx2FilterCodeSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); + c->chrMmx2FilterCode = mmap(NULL, c->chrMmx2FilterCodeSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); +#elif HAVE_VIRTUALALLOC + c->lumMmx2FilterCode = VirtualAlloc(NULL, c->lumMmx2FilterCodeSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE); + c->chrMmx2FilterCode = VirtualAlloc(NULL, c->chrMmx2FilterCodeSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE); +#else + c->lumMmx2FilterCode = av_malloc(c->lumMmx2FilterCodeSize); + c->chrMmx2FilterCode = av_malloc(c->chrMmx2FilterCodeSize); +#endif + + if (!c->lumMmx2FilterCode || !c->chrMmx2FilterCode) + goto fail; + 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); + FF_ALLOCZ_OR_GOTO(c, c->hLumFilterPos, (dstW /2/8+8)*sizeof(int32_t), fail); + FF_ALLOCZ_OR_GOTO(c, c->hChrFilterPos, (c->chrDstW/2/4+8)*sizeof(int32_t), fail); + + initMMX2HScaler( dstW, c->lumXInc, c->lumMmx2FilterCode, c->hLumFilter, c->hLumFilterPos, 8); + initMMX2HScaler(c->chrDstW, c->chrXInc, c->chrMmx2FilterCode, c->hChrFilter, c->hChrFilterPos, 4); + +#ifdef MAP_ANONYMOUS + mprotect(c->lumMmx2FilterCode, c->lumMmx2FilterCodeSize, PROT_EXEC | PROT_READ); + mprotect(c->chrMmx2FilterCode, c->chrMmx2FilterCodeSize, PROT_EXEC | PROT_READ); +#endif + } else +#endif /* ARCH_X86 && (HAVE_MMX2 || CONFIG_RUNTIME_CPUDETECT) */ + { + const int filterAlign= + (flags & SWS_CPU_CAPS_MMX) ? 4 : + (flags & SWS_CPU_CAPS_ALTIVEC) ? 8 : + 1; + + if (initFilter(&c->hLumFilter, &c->hLumFilterPos, &c->hLumFilterSize, c->lumXInc, + srcW , dstW, filterAlign, 1<<14, + (flags&SWS_BICUBLIN) ? (flags|SWS_BICUBIC) : flags, + srcFilter->lumH, dstFilter->lumH, c->param) < 0) + goto fail; + if (initFilter(&c->hChrFilter, &c->hChrFilterPos, &c->hChrFilterSize, c->chrXInc, + c->chrSrcW, c->chrDstW, filterAlign, 1<<14, + (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags, + srcFilter->chrH, dstFilter->chrH, c->param) < 0) + goto fail; + } + } // initialize horizontal stuff + + /* precalculate vertical scaler filter coefficients */ + { + const int filterAlign= + (flags & SWS_CPU_CAPS_MMX) && (flags & SWS_ACCURATE_RND) ? 2 : + (flags & SWS_CPU_CAPS_ALTIVEC) ? 8 : + 1; + + if (initFilter(&c->vLumFilter, &c->vLumFilterPos, &c->vLumFilterSize, c->lumYInc, + srcH , dstH, filterAlign, (1<<12), + (flags&SWS_BICUBLIN) ? (flags|SWS_BICUBIC) : flags, + srcFilter->lumV, dstFilter->lumV, c->param) < 0) + goto fail; + if (initFilter(&c->vChrFilter, &c->vChrFilterPos, &c->vChrFilterSize, c->chrYInc, + c->chrSrcH, c->chrDstH, filterAlign, (1<<12), + (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags, + srcFilter->chrV, dstFilter->chrV, c->param) < 0) + goto fail; + +#if HAVE_ALTIVEC + FF_ALLOC_OR_GOTO(c, c->vYCoeffsBank, sizeof (vector signed short)*c->vLumFilterSize*c->dstH, fail); + FF_ALLOC_OR_GOTO(c, c->vCCoeffsBank, sizeof (vector signed short)*c->vChrFilterSize*c->chrDstH, fail); + + for (i=0;ivLumFilterSize*c->dstH;i++) { + int j; + short *p = (short *)&c->vYCoeffsBank[i]; + for (j=0;j<8;j++) + p[j] = c->vLumFilter[i]; + } + + for (i=0;ivChrFilterSize*c->chrDstH;i++) { + int j; + short *p = (short *)&c->vCCoeffsBank[i]; + for (j=0;j<8;j++) + p[j] = c->vChrFilter[i]; + } +#endif + } + + // calculate buffer sizes so that they won't run out while handling these damn slices + c->vLumBufSize= c->vLumFilterSize; + c->vChrBufSize= c->vChrFilterSize; + for (i=0; ichrDstH / dstH; + int nextSlice= FFMAX(c->vLumFilterPos[i ] + c->vLumFilterSize - 1, + ((c->vChrFilterPos[chrI] + c->vChrFilterSize - 1)<chrSrcVSubSample)); + + nextSlice>>= c->chrSrcVSubSample; + nextSlice<<= c->chrSrcVSubSample; + if (c->vLumFilterPos[i ] + c->vLumBufSize < nextSlice) + c->vLumBufSize= nextSlice - c->vLumFilterPos[i]; + if (c->vChrFilterPos[chrI] + c->vChrBufSize < (nextSlice>>c->chrSrcVSubSample)) + c->vChrBufSize= (nextSlice>>c->chrSrcVSubSample) - c->vChrFilterPos[chrI]; + } + + // allocate pixbufs (we use dynamic allocation because otherwise we would need to + // allocate several megabytes to handle all possible cases) + FF_ALLOC_OR_GOTO(c, c->lumPixBuf, c->vLumBufSize*2*sizeof(int16_t*), fail); + FF_ALLOC_OR_GOTO(c, c->chrPixBuf, c->vChrBufSize*2*sizeof(int16_t*), fail); + if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat) && isALPHA(c->dstFormat)) + FF_ALLOCZ_OR_GOTO(c, c->alpPixBuf, c->vLumBufSize*2*sizeof(int16_t*), fail); + //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; ivLumBufSize; i++) { + FF_ALLOCZ_OR_GOTO(c, c->lumPixBuf[i+c->vLumBufSize], VOF+1, fail); + c->lumPixBuf[i] = c->lumPixBuf[i+c->vLumBufSize]; + } + for (i=0; ivChrBufSize; i++) { + FF_ALLOC_OR_GOTO(c, c->chrPixBuf[i+c->vChrBufSize], (VOF+1)*2, fail); + c->chrPixBuf[i] = c->chrPixBuf[i+c->vChrBufSize]; + } + if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) + for (i=0; ivLumBufSize; i++) { + FF_ALLOCZ_OR_GOTO(c, c->alpPixBuf[i+c->vLumBufSize], VOF+1, 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; ivChrBufSize; i++) memset(c->chrPixBuf[i], 64, (VOF+1)*2); + + assert(2*VOFW == VOF); + + assert(c->chrDstH <= dstH); + + if (flags&SWS_PRINT_INFO) { + if (flags&SWS_FAST_BILINEAR) + av_log(c, AV_LOG_INFO, "FAST_BILINEAR scaler, "); + else if (flags&SWS_BILINEAR) + av_log(c, AV_LOG_INFO, "BILINEAR scaler, "); + else if (flags&SWS_BICUBIC) + av_log(c, AV_LOG_INFO, "BICUBIC scaler, "); + else if (flags&SWS_X) + av_log(c, AV_LOG_INFO, "Experimental scaler, "); + else if (flags&SWS_POINT) + av_log(c, AV_LOG_INFO, "Nearest Neighbor / POINT scaler, "); + else if (flags&SWS_AREA) + av_log(c, AV_LOG_INFO, "Area Averaging scaler, "); + else if (flags&SWS_BICUBLIN) + av_log(c, AV_LOG_INFO, "luma BICUBIC / chroma BILINEAR scaler, "); + else if (flags&SWS_GAUSS) + av_log(c, AV_LOG_INFO, "Gaussian scaler, "); + else if (flags&SWS_SINC) + av_log(c, AV_LOG_INFO, "Sinc scaler, "); + else if (flags&SWS_LANCZOS) + av_log(c, AV_LOG_INFO, "Lanczos scaler, "); + else if (flags&SWS_SPLINE) + av_log(c, AV_LOG_INFO, "Bicubic spline scaler, "); + 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), +#ifdef DITHER1XBPP + dstFormat == PIX_FMT_BGR555 || dstFormat == PIX_FMT_BGR565 || + dstFormat == PIX_FMT_RGB444BE || dstFormat == PIX_FMT_RGB444LE || + dstFormat == PIX_FMT_BGR444BE || dstFormat == PIX_FMT_BGR444LE ? "dithered " : "", +#else + "", +#endif + sws_format_name(dstFormat)); + + if (flags & SWS_CPU_CAPS_MMX2) + av_log(c, AV_LOG_INFO, "using MMX2\n"); + else if (flags & SWS_CPU_CAPS_3DNOW) + av_log(c, AV_LOG_INFO, "using 3DNOW\n"); + else if (flags & SWS_CPU_CAPS_MMX) + av_log(c, AV_LOG_INFO, "using MMX\n"); + else if (flags & SWS_CPU_CAPS_ALTIVEC) + av_log(c, AV_LOG_INFO, "using AltiVec\n"); + else + av_log(c, AV_LOG_INFO, "using C\n"); + + if (flags & SWS_CPU_CAPS_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 ARCH_X86 + 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", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); + else + av_log(c, AV_LOG_VERBOSE, "using n-tap %s scaler for vertical scaling (YV12 like)\n", (flags & SWS_CPU_CAPS_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", (flags & SWS_CPU_CAPS_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", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); + else + av_log(c, AV_LOG_VERBOSE, "using n-tap %s scaler for vertical scaling (BGR)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); + } + + if (dstFormat==PIX_FMT_BGR24) + av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR24 converter\n", + (flags & SWS_CPU_CAPS_MMX2) ? "MMX2" : ((flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C")); + else if (dstFormat==PIX_FMT_RGB32) + av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR32 converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); + else if (dstFormat==PIX_FMT_BGR565) + av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR16 converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); + else if (dstFormat==PIX_FMT_BGR555) + av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR15 converter\n", (flags & SWS_CPU_CAPS_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", (flags & SWS_CPU_CAPS_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); + av_log(c, AV_LOG_DEBUG, "chr srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n", + c->chrSrcW, c->chrSrcH, c->chrDstW, c->chrDstH, c->chrXInc, c->chrYInc); + } + + c->swScale= ff_getSwsFunc(c); + return c; + +fail: + sws_freeContext(c); + return NULL; +} + +SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur, + float lumaSharpen, float chromaSharpen, + float chromaHShift, float chromaVShift, + int verbose) +{ + SwsFilter *filter= av_malloc(sizeof(SwsFilter)); + if (!filter) + return NULL; + + if (lumaGBlur!=0.0) { + filter->lumH= sws_getGaussianVec(lumaGBlur, 3.0); + filter->lumV= sws_getGaussianVec(lumaGBlur, 3.0); + } else { + filter->lumH= sws_getIdentityVec(); + filter->lumV= sws_getIdentityVec(); + } + + if (chromaGBlur!=0.0) { + filter->chrH= sws_getGaussianVec(chromaGBlur, 3.0); + filter->chrV= sws_getGaussianVec(chromaGBlur, 3.0); + } else { + filter->chrH= sws_getIdentityVec(); + filter->chrV= sws_getIdentityVec(); + } + + if (chromaSharpen!=0.0) { + SwsVector *id= sws_getIdentityVec(); + sws_scaleVec(filter->chrH, -chromaSharpen); + sws_scaleVec(filter->chrV, -chromaSharpen); + sws_addVec(filter->chrH, id); + sws_addVec(filter->chrV, id); + sws_freeVec(id); + } + + if (lumaSharpen!=0.0) { + SwsVector *id= sws_getIdentityVec(); + sws_scaleVec(filter->lumH, -lumaSharpen); + sws_scaleVec(filter->lumV, -lumaSharpen); + sws_addVec(filter->lumH, id); + sws_addVec(filter->lumV, id); + sws_freeVec(id); + } + + if (chromaHShift != 0.0) + sws_shiftVec(filter->chrH, (int)(chromaHShift+0.5)); + + if (chromaVShift != 0.0) + sws_shiftVec(filter->chrV, (int)(chromaVShift+0.5)); + + sws_normalizeVec(filter->chrH, 1.0); + sws_normalizeVec(filter->chrV, 1.0); + sws_normalizeVec(filter->lumH, 1.0); + sws_normalizeVec(filter->lumV, 1.0); + + if (verbose) sws_printVec2(filter->chrH, NULL, AV_LOG_DEBUG); + if (verbose) sws_printVec2(filter->lumH, NULL, AV_LOG_DEBUG); + + return filter; +} + +SwsVector *sws_allocVec(int length) +{ + SwsVector *vec = av_malloc(sizeof(SwsVector)); + if (!vec) + return NULL; + vec->length = length; + vec->coeff = av_malloc(sizeof(double) * length); + if (!vec->coeff) + av_freep(&vec); + return vec; +} + +SwsVector *sws_getGaussianVec(double variance, double quality) +{ + const int length= (int)(variance*quality + 0.5) | 1; + int i; + double middle= (length-1)*0.5; + SwsVector *vec= sws_allocVec(length); + + if (!vec) + return NULL; + + for (i=0; icoeff[i]= exp(-dist*dist/(2*variance*variance)) / sqrt(2*variance*M_PI); + } + + sws_normalizeVec(vec, 1.0); + + return vec; +} + +SwsVector *sws_getConstVec(double c, int length) +{ + int i; + SwsVector *vec= sws_allocVec(length); + + if (!vec) + return NULL; + + for (i=0; icoeff[i]= c; + + return vec; +} + +SwsVector *sws_getIdentityVec(void) +{ + return sws_getConstVec(1.0, 1); +} + +static double sws_dcVec(SwsVector *a) +{ + int i; + double sum=0; + + for (i=0; ilength; i++) + sum+= a->coeff[i]; + + return sum; +} + +void sws_scaleVec(SwsVector *a, double scalar) +{ + int i; + + for (i=0; ilength; i++) + a->coeff[i]*= scalar; +} + +void sws_normalizeVec(SwsVector *a, double height) +{ + sws_scaleVec(a, height/sws_dcVec(a)); +} + +static SwsVector *sws_getConvVec(SwsVector *a, SwsVector *b) +{ + int length= a->length + b->length - 1; + int i, j; + SwsVector *vec= sws_getConstVec(0.0, length); + + if (!vec) + return NULL; + + for (i=0; ilength; i++) { + for (j=0; jlength; j++) { + vec->coeff[i+j]+= a->coeff[i]*b->coeff[j]; + } + } + + return vec; +} + +static SwsVector *sws_sumVec(SwsVector *a, SwsVector *b) +{ + int length= FFMAX(a->length, b->length); + int i; + SwsVector *vec= sws_getConstVec(0.0, length); + + if (!vec) + return NULL; + + for (i=0; ilength; i++) vec->coeff[i + (length-1)/2 - (a->length-1)/2]+= a->coeff[i]; + for (i=0; ilength; i++) vec->coeff[i + (length-1)/2 - (b->length-1)/2]+= b->coeff[i]; + + return vec; +} + +static SwsVector *sws_diffVec(SwsVector *a, SwsVector *b) +{ + int length= FFMAX(a->length, b->length); + int i; + SwsVector *vec= sws_getConstVec(0.0, length); + + if (!vec) + return NULL; + + for (i=0; ilength; i++) vec->coeff[i + (length-1)/2 - (a->length-1)/2]+= a->coeff[i]; + for (i=0; ilength; i++) vec->coeff[i + (length-1)/2 - (b->length-1)/2]-= b->coeff[i]; + + return vec; +} + +/* shift left / or right if "shift" is negative */ +static SwsVector *sws_getShiftedVec(SwsVector *a, int shift) +{ + int length= a->length + FFABS(shift)*2; + int i; + SwsVector *vec= sws_getConstVec(0.0, length); + + if (!vec) + return NULL; + + for (i=0; ilength; i++) { + vec->coeff[i + (length-1)/2 - (a->length-1)/2 - shift]= a->coeff[i]; + } + + return vec; +} + +void sws_shiftVec(SwsVector *a, int shift) +{ + SwsVector *shifted= sws_getShiftedVec(a, shift); + av_free(a->coeff); + a->coeff= shifted->coeff; + a->length= shifted->length; + av_free(shifted); +} + +void sws_addVec(SwsVector *a, SwsVector *b) +{ + SwsVector *sum= sws_sumVec(a, b); + av_free(a->coeff); + a->coeff= sum->coeff; + a->length= sum->length; + av_free(sum); +} + +void sws_subVec(SwsVector *a, SwsVector *b) +{ + SwsVector *diff= sws_diffVec(a, b); + av_free(a->coeff); + a->coeff= diff->coeff; + a->length= diff->length; + av_free(diff); +} + +void sws_convVec(SwsVector *a, SwsVector *b) +{ + SwsVector *conv= sws_getConvVec(a, b); + av_free(a->coeff); + a->coeff= conv->coeff; + a->length= conv->length; + av_free(conv); +} + +SwsVector *sws_cloneVec(SwsVector *a) +{ + int i; + SwsVector *vec= sws_allocVec(a->length); + + if (!vec) + return NULL; + + for (i=0; ilength; i++) vec->coeff[i]= a->coeff[i]; + + return vec; +} + +void sws_printVec2(SwsVector *a, AVClass *log_ctx, int log_level) +{ + int i; + double max=0; + double min=0; + double range; + + for (i=0; ilength; i++) + if (a->coeff[i]>max) max= a->coeff[i]; + + for (i=0; ilength; i++) + if (a->coeff[i]coeff[i]; + + range= max - min; + + for (i=0; ilength; i++) { + int x= (int)((a->coeff[i]-min)*60.0/range +0.5); + av_log(log_ctx, log_level, "%1.3f ", a->coeff[i]); + for (;x>0; x--) av_log(log_ctx, log_level, " "); + av_log(log_ctx, log_level, "|\n"); + } +} + +#if LIBSWSCALE_VERSION_MAJOR < 1 +void sws_printVec(SwsVector *a) +{ + sws_printVec2(a, NULL, AV_LOG_DEBUG); +} +#endif + +void sws_freeVec(SwsVector *a) +{ + if (!a) return; + av_freep(&a->coeff); + a->length=0; + av_free(a); +} + +void sws_freeFilter(SwsFilter *filter) +{ + if (!filter) return; + + if (filter->lumH) sws_freeVec(filter->lumH); + if (filter->lumV) sws_freeVec(filter->lumV); + if (filter->chrH) sws_freeVec(filter->chrH); + if (filter->chrV) sws_freeVec(filter->chrV); + av_free(filter); +} + +void sws_freeContext(SwsContext *c) +{ + int i; + if (!c) return; + + if (c->lumPixBuf) { + for (i=0; ivLumBufSize; i++) + av_freep(&c->lumPixBuf[i]); + av_freep(&c->lumPixBuf); + } + + if (c->chrPixBuf) { + for (i=0; ivChrBufSize; i++) + av_freep(&c->chrPixBuf[i]); + av_freep(&c->chrPixBuf); + } + + if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) { + for (i=0; ivLumBufSize; i++) + av_freep(&c->alpPixBuf[i]); + av_freep(&c->alpPixBuf); + } + + av_freep(&c->vLumFilter); + av_freep(&c->vChrFilter); + av_freep(&c->hLumFilter); + av_freep(&c->hChrFilter); +#if HAVE_ALTIVEC + av_freep(&c->vYCoeffsBank); + av_freep(&c->vCCoeffsBank); +#endif + + av_freep(&c->vLumFilterPos); + av_freep(&c->vChrFilterPos); + av_freep(&c->hLumFilterPos); + av_freep(&c->hChrFilterPos); + +#if ARCH_X86 +#ifdef MAP_ANONYMOUS + if (c->lumMmx2FilterCode) munmap(c->lumMmx2FilterCode, c->lumMmx2FilterCodeSize); + if (c->chrMmx2FilterCode) munmap(c->chrMmx2FilterCode, c->chrMmx2FilterCodeSize); +#elif HAVE_VIRTUALALLOC + if (c->lumMmx2FilterCode) VirtualFree(c->lumMmx2FilterCode, 0, MEM_RELEASE); + if (c->chrMmx2FilterCode) VirtualFree(c->chrMmx2FilterCode, 0, MEM_RELEASE); +#else + av_free(c->lumMmx2FilterCode); + av_free(c->chrMmx2FilterCode); +#endif + c->lumMmx2FilterCode=NULL; + c->chrMmx2FilterCode=NULL; +#endif /* ARCH_X86 */ + + av_freep(&c->yuvTable); + + av_free(c); +} + +struct SwsContext *sws_getCachedContext(struct SwsContext *context, + int srcW, int srcH, enum PixelFormat srcFormat, + int dstW, int dstH, enum PixelFormat dstFormat, int flags, + SwsFilter *srcFilter, SwsFilter *dstFilter, const double *param) +{ + static const double default_param[2] = {SWS_PARAM_DEFAULT, SWS_PARAM_DEFAULT}; + + if (!param) + param = default_param; + + if (context && + (context->srcW != srcW || + context->srcH != srcH || + context->srcFormat != srcFormat || + context->dstW != dstW || + context->dstH != dstH || + context->dstFormat != dstFormat || + context->flags != flags || + context->param[0] != param[0] || + context->param[1] != param[1])) { + sws_freeContext(context); + context = NULL; + } + + if (!context) { + return sws_getContext(srcW, srcH, srcFormat, + dstW, dstH, dstFormat, flags, + srcFilter, dstFilter, param); + } + return context; +} + diff --git a/src/add-ons/media/plugins/ffmpeg/libswscale/x86/yuv2rgb_mmx.c b/src/add-ons/media/plugins/ffmpeg/libswscale/x86/yuv2rgb_mmx.c index b03cce2ae7..d042421ff7 100644 --- a/src/add-ons/media/plugins/ffmpeg/libswscale/x86/yuv2rgb_mmx.c +++ b/src/add-ons/media/plugins/ffmpeg/libswscale/x86/yuv2rgb_mmx.c @@ -49,14 +49,22 @@ DECLARE_ASM_CONST(8, uint64_t, mmx_grnmask) = 0xfcfcfcfcfcfcfcfcULL; #define HAVE_MMX2 0 #define HAVE_AMD3DNOW 0 #define RENAME(a) a ## _MMX +#if CONFIG_GPL #include "yuv2rgb_template.c" +#else +#include "yuv2rgb_template2.c" +#endif //MMX2 versions #undef RENAME #undef HAVE_MMX2 #define HAVE_MMX2 1 #define RENAME(a) a ## _MMX2 +#if CONFIG_GPL #include "yuv2rgb_template.c" +#else +#include "yuv2rgb_template2.c" +#endif SwsFunc ff_yuv2rgb_init_mmx(SwsContext *c) { @@ -72,7 +80,8 @@ SwsFunc ff_yuv2rgb_init_mmx(SwsContext *c) if (HAVE_7REGS) return yuva420_bgr32_MMX2; break; } else return yuv420_bgr32_MMX2; - case PIX_FMT_BGR24: return yuv420_rgb24_MMX2; + case PIX_FMT_RGB24: return yuv420_rgb24_MMX2; + case PIX_FMT_BGR24: return yuv420_bgr24_MMX2; case PIX_FMT_RGB565: return yuv420_rgb16_MMX2; case PIX_FMT_RGB555: return yuv420_rgb15_MMX2; } @@ -89,7 +98,8 @@ SwsFunc ff_yuv2rgb_init_mmx(SwsContext *c) if (HAVE_7REGS) return yuva420_bgr32_MMX; break; } else return yuv420_bgr32_MMX; - case PIX_FMT_BGR24: return yuv420_rgb24_MMX; + case PIX_FMT_RGB24: return yuv420_rgb24_MMX; + case PIX_FMT_BGR24: return yuv420_bgr24_MMX; case PIX_FMT_RGB565: return yuv420_rgb16_MMX; case PIX_FMT_RGB555: return yuv420_rgb15_MMX; } diff --git a/src/add-ons/media/plugins/ffmpeg/libswscale/x86/yuv2rgb_template.c b/src/add-ons/media/plugins/ffmpeg/libswscale/x86/yuv2rgb_template.c index e4a1a9809b..ba906899f0 100644 --- a/src/add-ons/media/plugins/ffmpeg/libswscale/x86/yuv2rgb_template.c +++ b/src/add-ons/media/plugins/ffmpeg/libswscale/x86/yuv2rgb_template.c @@ -42,7 +42,7 @@ #define SFENCE "sfence" #else #define MOVNTQ "movq" -#define SFENCE "/nop" +#define SFENCE " # nop" #endif #define YUV2RGB \ @@ -134,9 +134,9 @@ __asm__ volatile ("pxor %mm4, %mm4;" /* zero mm4 */ ); \ for (y= 0; y>1)*srcStride[1]; \ - uint8_t *pv = src[2] + (y>>1)*srcStride[2]; \ + 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]; \ x86_reg index= -h_size/2; \ #define YUV2RGB_INIT \ @@ -168,7 +168,7 @@ : "r" (pu - index), "r" (pv - index), "r"(&c->redDither), "r" (py - 2*index) \ ); \ } \ - __asm__ volatile (EMMS); \ + __asm__ volatile (SFENCE"\n\t"EMMS); \ return srcSliceH; \ #define YUV2RGB_OPERANDS_ALPHA \ @@ -176,10 +176,10 @@ : "r" (pu - index), "r" (pv - index), "r"(&c->redDither), "r" (py - 2*index), "r" (pa - 2*index) \ ); \ } \ - __asm__ volatile (EMMS); \ + __asm__ volatile (SFENCE"\n\t"EMMS); \ return srcSliceH; \ -static inline int RENAME(yuv420_rgb16)(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, +static inline int RENAME(yuv420_rgb16)(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t* dst[], int dstStride[]) { int y, h_size; @@ -236,7 +236,7 @@ static inline int RENAME(yuv420_rgb16)(SwsContext *c, uint8_t* src[], int srcStr YUV2RGB_OPERANDS } -static inline int RENAME(yuv420_rgb15)(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, +static inline int RENAME(yuv420_rgb15)(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t* dst[], int dstStride[]) { int y, h_size; @@ -295,7 +295,108 @@ static inline int RENAME(yuv420_rgb15)(SwsContext *c, uint8_t* src[], int srcStr YUV2RGB_OPERANDS } -static inline int RENAME(yuv420_rgb24)(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, +#undef RGB_PLANAR2PACKED24 +#if HAVE_MMX2 +#define RGB_PLANAR2PACKED24(red, blue)\ + "movq "MANGLE(ff_M24A)", %%mm4 \n\t"\ + "movq "MANGLE(ff_M24C)", %%mm7 \n\t"\ + "pshufw $0x50, %%mm"blue", %%mm5 \n\t" /* B3 B2 B3 B2 B1 B0 B1 B0 */\ + "pshufw $0x50, %%mm2, %%mm3 \n\t" /* G3 G2 G3 G2 G1 G0 G1 G0 */\ + "pshufw $0x00, %%mm"red", %%mm6 \n\t" /* R1 R0 R1 R0 R1 R0 R1 R0 */\ +\ + "pand %%mm4, %%mm5 \n\t" /* B2 B1 B0 */\ + "pand %%mm4, %%mm3 \n\t" /* G2 G1 G0 */\ + "pand %%mm7, %%mm6 \n\t" /* R1 R0 */\ +\ + "psllq $8, %%mm3 \n\t" /* G2 G1 G0 */\ + "por %%mm5, %%mm6 \n\t"\ + "por %%mm3, %%mm6 \n\t"\ + MOVNTQ" %%mm6, (%1) \n\t"\ +\ + "psrlq $8, %%mm2 \n\t" /* 00 G7 G6 G5 G4 G3 G2 G1 */\ + "pshufw $0xA5, %%mm"blue", %%mm5\n\t" /* B5 B4 B5 B4 B3 B2 B3 B2 */\ + "pshufw $0x55, %%mm2, %%mm3 \n\t" /* G4 G3 G4 G3 G4 G3 G4 G3 */\ + "pshufw $0xA5, %%mm"red", %%mm6 \n\t" /* R5 R4 R5 R4 R3 R2 R3 R2 */\ +\ + "pand "MANGLE(ff_M24B)", %%mm5 \n\t" /* B5 B4 B3 */\ + "pand %%mm7, %%mm3 \n\t" /* G4 G3 */\ + "pand %%mm4, %%mm6 \n\t" /* R4 R3 R2 */\ +\ + "por %%mm5, %%mm3 \n\t" /* B5 G4 B4 G3 B3 */\ + "por %%mm3, %%mm6 \n\t"\ + MOVNTQ" %%mm6, 8(%1) \n\t"\ +\ + "pshufw $0xFF, %%mm"blue", %%mm5\n\t" /* B7 B6 B7 B6 B7 B6 B6 B7 */\ + "pshufw $0xFA, %%mm2, %%mm3 \n\t" /* 00 G7 00 G7 G6 G5 G6 G5 */\ + "pshufw $0xFA, %%mm"red", %%mm6 \n\t" /* R7 R6 R7 R6 R5 R4 R5 R4 */\ + "movd 4 (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */\ +\ + "pand %%mm7, %%mm5 \n\t" /* B7 B6 */\ + "pand %%mm4, %%mm3 \n\t" /* G7 G6 G5 */\ + "pand "MANGLE(ff_M24B)", %%mm6 \n\t" /* R7 R6 R5 */\ + "movd 4 (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */\ +\ + "por %%mm5, %%mm3 \n\t"\ + "por %%mm3, %%mm6 \n\t"\ + MOVNTQ" %%mm6, 16(%1) \n\t"\ + "movq 8 (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */\ + "pxor %%mm4, %%mm4 \n\t" +#else +#define RGB_PLANAR2PACKED24(red, blue)\ + "pxor %%mm4, %%mm4 \n\t"\ + "movq %%mm"blue", %%mm5\n\t" /* B */\ + "movq %%mm"red", %%mm6 \n\t" /* R */\ + "punpcklbw %%mm2, %%mm"blue"\n\t" /* GBGBGBGB 0 */\ + "punpcklbw %%mm4, %%mm"red" \n\t" /* 0R0R0R0R 0 */\ + "punpckhbw %%mm2, %%mm5 \n\t" /* GBGBGBGB 2 */\ + "punpckhbw %%mm4, %%mm6 \n\t" /* 0R0R0R0R 2 */\ + "movq %%mm"blue", %%mm7\n\t" /* GBGBGBGB 0 */\ + "movq %%mm5, %%mm3 \n\t" /* GBGBGBGB 2 */\ + "punpcklwd %%mm"red", %%mm7 \n\t" /* 0RGB0RGB 0 */\ + "punpckhwd %%mm"red", %%mm"blue"\n\t" /* 0RGB0RGB 1 */\ + "punpcklwd %%mm6, %%mm5 \n\t" /* 0RGB0RGB 2 */\ + "punpckhwd %%mm6, %%mm3 \n\t" /* 0RGB0RGB 3 */\ +\ + "movq %%mm7, %%mm2 \n\t" /* 0RGB0RGB 0 */\ + "movq %%mm"blue", %%mm6\n\t" /* 0RGB0RGB 1 */\ + "movq %%mm5, %%mm"red" \n\t" /* 0RGB0RGB 2 */\ + "movq %%mm3, %%mm4 \n\t" /* 0RGB0RGB 3 */\ +\ + "psllq $40, %%mm7 \n\t" /* RGB00000 0 */\ + "psllq $40, %%mm"blue"\n\t" /* RGB00000 1 */\ + "psllq $40, %%mm5 \n\t" /* RGB00000 2 */\ + "psllq $40, %%mm3 \n\t" /* RGB00000 3 */\ +\ + "punpckhdq %%mm2, %%mm7 \n\t" /* 0RGBRGB0 0 */\ + "punpckhdq %%mm6, %%mm"blue"\n\t" /* 0RGBRGB0 1 */\ + "punpckhdq %%mm"red", %%mm5 \n\t" /* 0RGBRGB0 2 */\ + "punpckhdq %%mm4, %%mm3 \n\t" /* 0RGBRGB0 3 */\ +\ + "psrlq $8, %%mm7 \n\t" /* 00RGBRGB 0 */\ + "movq %%mm"blue", %%mm6\n\t" /* 0RGBRGB0 1 */\ + "psllq $40, %%mm"blue"\n\t" /* GB000000 1 */\ + "por %%mm"blue", %%mm7\n\t" /* GBRGBRGB 0 */\ + MOVNTQ" %%mm7, (%1) \n\t"\ +\ + "psrlq $24, %%mm6 \n\t" /* 0000RGBR 1 */\ + "movq %%mm5, %%mm"red" \n\t" /* 0RGBRGB0 2 */\ + "psllq $24, %%mm5 \n\t" /* BRGB0000 2 */\ + "por %%mm5, %%mm6 \n\t" /* BRGBRGBR 1 */\ + MOVNTQ" %%mm6, 8(%1) \n\t"\ +\ + "movq 8 (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */\ +\ + "psrlq $40, %%mm"red" \n\t" /* 000000RG 2 */\ + "psllq $8, %%mm3 \n\t" /* RGBRGB00 3 */\ + "por %%mm3, %%mm"red" \n\t" /* RGBRGBRG 2 */\ + MOVNTQ" %%mm"red", 16(%1)\n\t"\ +\ + "movd 4 (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */\ + "movd 4 (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */\ + "pxor %%mm4, %%mm4 \n\t" +#endif + +static inline int RENAME(yuv420_rgb24)(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t* dst[], int dstStride[]) { int y, h_size; @@ -306,106 +407,24 @@ static inline int RENAME(yuv420_rgb24)(SwsContext *c, uint8_t* src[], int srcStr YUV2RGB_INIT YUV2RGB /* mm0=B, %%mm2=G, %%mm1=R */ -#if HAVE_MMX2 - "movq "MANGLE(ff_M24A)", %%mm4 \n\t" - "movq "MANGLE(ff_M24C)", %%mm7 \n\t" - "pshufw $0x50, %%mm0, %%mm5 \n\t" /* B3 B2 B3 B2 B1 B0 B1 B0 */ - "pshufw $0x50, %%mm2, %%mm3 \n\t" /* G3 G2 G3 G2 G1 G0 G1 G0 */ - "pshufw $0x00, %%mm1, %%mm6 \n\t" /* R1 R0 R1 R0 R1 R0 R1 R0 */ + RGB_PLANAR2PACKED24("0", "1") - "pand %%mm4, %%mm5 \n\t" /* B2 B1 B0 */ - "pand %%mm4, %%mm3 \n\t" /* G2 G1 G0 */ - "pand %%mm7, %%mm6 \n\t" /* R1 R0 */ + YUV2RGB_ENDLOOP(3) + YUV2RGB_OPERANDS +} - "psllq $8, %%mm3 \n\t" /* G2 G1 G0 */ - "por %%mm5, %%mm6 \n\t" - "por %%mm3, %%mm6 \n\t" - MOVNTQ" %%mm6, (%1) \n\t" +static inline int RENAME(yuv420_bgr24)(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, + int srcSliceH, uint8_t* dst[], int dstStride[]) +{ + int y, h_size; - "psrlq $8, %%mm2 \n\t" /* 00 G7 G6 G5 G4 G3 G2 G1 */ - "pshufw $0xA5, %%mm0, %%mm5 \n\t" /* B5 B4 B5 B4 B3 B2 B3 B2 */ - "pshufw $0x55, %%mm2, %%mm3 \n\t" /* G4 G3 G4 G3 G4 G3 G4 G3 */ - "pshufw $0xA5, %%mm1, %%mm6 \n\t" /* R5 R4 R5 R4 R3 R2 R3 R2 */ + YUV422_UNSHIFT + YUV2RGB_LOOP(3) - "pand "MANGLE(ff_M24B)", %%mm5 \n\t" /* B5 B4 B3 */ - "pand %%mm7, %%mm3 \n\t" /* G4 G3 */ - "pand %%mm4, %%mm6 \n\t" /* R4 R3 R2 */ - - "por %%mm5, %%mm3 \n\t" /* B5 G4 B4 G3 B3 */ - "por %%mm3, %%mm6 \n\t" - MOVNTQ" %%mm6, 8(%1) \n\t" - - "pshufw $0xFF, %%mm0, %%mm5 \n\t" /* B7 B6 B7 B6 B7 B6 B6 B7 */ - "pshufw $0xFA, %%mm2, %%mm3 \n\t" /* 00 G7 00 G7 G6 G5 G6 G5 */ - "pshufw $0xFA, %%mm1, %%mm6 \n\t" /* R7 R6 R7 R6 R5 R4 R5 R4 */ - "movd 4 (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ - - "pand %%mm7, %%mm5 \n\t" /* B7 B6 */ - "pand %%mm4, %%mm3 \n\t" /* G7 G6 G5 */ - "pand "MANGLE(ff_M24B)", %%mm6 \n\t" /* R7 R6 R5 */ - "movd 4 (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ -\ - "por %%mm5, %%mm3 \n\t" - "por %%mm3, %%mm6 \n\t" - MOVNTQ" %%mm6, 16(%1) \n\t" - "movq 8 (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ - "pxor %%mm4, %%mm4 \n\t" - -#else - - "pxor %%mm4, %%mm4 \n\t" - "movq %%mm0, %%mm5 \n\t" /* B */ - "movq %%mm1, %%mm6 \n\t" /* R */ - "punpcklbw %%mm2, %%mm0 \n\t" /* GBGBGBGB 0 */ - "punpcklbw %%mm4, %%mm1 \n\t" /* 0R0R0R0R 0 */ - "punpckhbw %%mm2, %%mm5 \n\t" /* GBGBGBGB 2 */ - "punpckhbw %%mm4, %%mm6 \n\t" /* 0R0R0R0R 2 */ - "movq %%mm0, %%mm7 \n\t" /* GBGBGBGB 0 */ - "movq %%mm5, %%mm3 \n\t" /* GBGBGBGB 2 */ - "punpcklwd %%mm1, %%mm7 \n\t" /* 0RGB0RGB 0 */ - "punpckhwd %%mm1, %%mm0 \n\t" /* 0RGB0RGB 1 */ - "punpcklwd %%mm6, %%mm5 \n\t" /* 0RGB0RGB 2 */ - "punpckhwd %%mm6, %%mm3 \n\t" /* 0RGB0RGB 3 */ - - "movq %%mm7, %%mm2 \n\t" /* 0RGB0RGB 0 */ - "movq %%mm0, %%mm6 \n\t" /* 0RGB0RGB 1 */ - "movq %%mm5, %%mm1 \n\t" /* 0RGB0RGB 2 */ - "movq %%mm3, %%mm4 \n\t" /* 0RGB0RGB 3 */ - - "psllq $40, %%mm7 \n\t" /* RGB00000 0 */ - "psllq $40, %%mm0 \n\t" /* RGB00000 1 */ - "psllq $40, %%mm5 \n\t" /* RGB00000 2 */ - "psllq $40, %%mm3 \n\t" /* RGB00000 3 */ - - "punpckhdq %%mm2, %%mm7 \n\t" /* 0RGBRGB0 0 */ - "punpckhdq %%mm6, %%mm0 \n\t" /* 0RGBRGB0 1 */ - "punpckhdq %%mm1, %%mm5 \n\t" /* 0RGBRGB0 2 */ - "punpckhdq %%mm4, %%mm3 \n\t" /* 0RGBRGB0 3 */ - - "psrlq $8, %%mm7 \n\t" /* 00RGBRGB 0 */ - "movq %%mm0, %%mm6 \n\t" /* 0RGBRGB0 1 */ - "psllq $40, %%mm0 \n\t" /* GB000000 1 */ - "por %%mm0, %%mm7 \n\t" /* GBRGBRGB 0 */ - MOVNTQ" %%mm7, (%1) \n\t" - - "movd 4 (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ - - "psrlq $24, %%mm6 \n\t" /* 0000RGBR 1 */ - "movq %%mm5, %%mm1 \n\t" /* 0RGBRGB0 2 */ - "psllq $24, %%mm5 \n\t" /* BRGB0000 2 */ - "por %%mm5, %%mm6 \n\t" /* BRGBRGBR 1 */ - MOVNTQ" %%mm6, 8(%1) \n\t" - - "movq 8 (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ - - "psrlq $40, %%mm1 \n\t" /* 000000RG 2 */ - "psllq $8, %%mm3 \n\t" /* RGBRGB00 3 */ - "por %%mm3, %%mm1 \n\t" /* RGBRGBRG 2 */ - MOVNTQ" %%mm1, 16(%1) \n\t" - - "movd 4 (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ - "pxor %%mm4, %%mm4 \n\t" -#endif + YUV2RGB_INIT + YUV2RGB + /* mm0=B, %%mm2=G, %%mm1=R */ + RGB_PLANAR2PACKED24("1", "0") YUV2RGB_ENDLOOP(3) YUV2RGB_OPERANDS @@ -472,7 +491,7 @@ etc. "pxor %%mm4, %%mm4;" /* zero mm4 */ \ "movq 8 (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ \ -static inline int RENAME(yuv420_rgb32)(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, +static inline int RENAME(yuv420_rgb32)(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t* dst[], int dstStride[]) { int y, h_size; @@ -489,7 +508,7 @@ static inline int RENAME(yuv420_rgb32)(SwsContext *c, uint8_t* src[], int srcStr YUV2RGB_OPERANDS } -static inline int RENAME(yuva420_rgb32)(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, +static inline int RENAME(yuva420_rgb32)(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t* dst[], int dstStride[]) { #if HAVE_7REGS @@ -497,7 +516,7 @@ static inline int RENAME(yuva420_rgb32)(SwsContext *c, uint8_t* src[], int srcSt YUV2RGB_LOOP(4) - uint8_t *pa = src[3] + y*srcStride[3]; + const uint8_t *pa = src[3] + y*srcStride[3]; YUV2RGB_INIT YUV2RGB "movq (%6, %0, 2), %%mm3;" /* Load 8 A A7 A6 A5 A4 A3 A2 A1 A0 */ @@ -533,7 +552,7 @@ static inline int RENAME(yuva420_bgr32)(SwsContext *c, const uint8_t* src[], int YUV2RGB_LOOP(4) - uint8_t *pa = src[3] + y*srcStride[3]; + const uint8_t *pa = src[3] + y*srcStride[3]; YUV2RGB_INIT YUV2RGB "movq (%6, %0, 2), %%mm3;" /* Load 8 A A7 A6 A5 A4 A3 A2 A1 A0 */ diff --git a/src/add-ons/media/plugins/ffmpeg/libswscale/x86/yuv2rgb_template2.c b/src/add-ons/media/plugins/ffmpeg/libswscale/x86/yuv2rgb_template2.c new file mode 100644 index 0000000000..f391cde1b1 --- /dev/null +++ b/src/add-ons/media/plugins/ffmpeg/libswscale/x86/yuv2rgb_template2.c @@ -0,0 +1,459 @@ +/* + * software YUV to RGB converter + * + * Copyright (C) 2001-2007 Michael Niedermayer + * (c) 2010 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 + */ + +#undef MOVNTQ +#undef EMMS +#undef SFENCE + +#if HAVE_AMD3DNOW +/* On K6 femms is faster than emms. On K7 femms is directly mapped to emms. */ +#define EMMS "femms" +#else +#define EMMS "emms" +#endif + +#if HAVE_MMX2 +#define MOVNTQ "movntq" +#define SFENCE "sfence" +#else +#define MOVNTQ "movq" +#define SFENCE " # nop" +#endif + +#define REG_BLUE "0" +#define REG_RED "1" +#define REG_GREEN "2" +#define REG_ALPHA "3" + +#define YUV2RGB_LOOP(depth) \ + h_size = (c->dstW + 7) & ~7; \ + if (h_size * depth > FFABS(dstStride[0])) \ + h_size -= 8; \ + \ + if (c->srcFormat == PIX_FMT_YUV422P) { \ + srcStride[1] *= 2; \ + srcStride[2] *= 2; \ + } \ + \ + __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]; \ + x86_reg index = -h_size / 2; \ + +#define YUV2RGB_INITIAL_LOAD \ + __asm__ volatile ( \ + "movq (%5, %0, 2), %%mm6\n\t" \ + "movd (%2, %0), %%mm0\n\t" \ + "movd (%3, %0), %%mm1\n\t" \ + "1: \n\t" \ + +/* YUV2RGB core + * Conversion is performed in usual way: + * R = Y' * Ycoef + Vred * V' + * G = Y' * Ycoef + Vgreen * V' + Ugreen * U' + * B = Y' * Ycoef + Ublue * U' + * + * where X' = X * 8 - Xoffset (multiplication is performed to increase + * precision a bit). + * Since it operates in YUV420 colorspace, Y component is additionally + * split into Y1 and Y2 for even and odd pixels. + * + * Input: + * mm0 - U (4 elems), mm1 - V (4 elems), mm6 - Y (8 elems), mm4 - zero register + * Output: + * mm1 - R, mm2 - G, mm0 - B + */ +#define YUV2RGB \ + /* convert Y, U, V into Y1', Y2', U', V' */ \ + "movq %%mm6, %%mm7\n\t" \ + "punpcklbw %%mm4, %%mm0\n\t" \ + "punpcklbw %%mm4, %%mm1\n\t" \ + "pand "MANGLE(mmx_00ffw)", %%mm6\n\t" \ + "psrlw $8, %%mm7\n\t" \ + "psllw $3, %%mm0\n\t" \ + "psllw $3, %%mm1\n\t" \ + "psllw $3, %%mm6\n\t" \ + "psllw $3, %%mm7\n\t" \ + "psubsw "U_OFFSET"(%4), %%mm0\n\t" \ + "psubsw "V_OFFSET"(%4), %%mm1\n\t" \ + "psubw "Y_OFFSET"(%4), %%mm6\n\t" \ + "psubw "Y_OFFSET"(%4), %%mm7\n\t" \ +\ + /* multiply by coefficients */ \ + "movq %%mm0, %%mm2\n\t" \ + "movq %%mm1, %%mm3\n\t" \ + "pmulhw "UG_COEFF"(%4), %%mm2\n\t" \ + "pmulhw "VG_COEFF"(%4), %%mm3\n\t" \ + "pmulhw "Y_COEFF" (%4), %%mm6\n\t" \ + "pmulhw "Y_COEFF" (%4), %%mm7\n\t" \ + "pmulhw "UB_COEFF"(%4), %%mm0\n\t" \ + "pmulhw "VR_COEFF"(%4), %%mm1\n\t" \ + "paddsw %%mm3, %%mm2\n\t" \ + /* now: mm0 = UB, mm1 = VR, mm2 = CG */ \ + /* mm6 = Y1, mm7 = Y2 */ \ +\ + /* produce RGB */ \ + "movq %%mm7, %%mm3\n\t" \ + "movq %%mm7, %%mm5\n\t" \ + "paddsw %%mm0, %%mm3\n\t" \ + "paddsw %%mm1, %%mm5\n\t" \ + "paddsw %%mm2, %%mm7\n\t" \ + "paddsw %%mm6, %%mm0\n\t" \ + "paddsw %%mm6, %%mm1\n\t" \ + "paddsw %%mm6, %%mm2\n\t" \ +\ + /* pack and interleave even/odd pixels */ \ + "packuswb %%mm0, %%mm0\n\t" \ + "packuswb %%mm1, %%mm1\n\t" \ + "packuswb %%mm2, %%mm2\n\t" \ + "packuswb %%mm3, %%mm3\n\t" \ + "packuswb %%mm5, %%mm5\n\t" \ + "packuswb %%mm7, %%mm7\n\t" \ + "punpcklbw %%mm3, %%mm0\n\t" \ + "punpcklbw %%mm5, %%mm1\n\t" \ + "punpcklbw %%mm7, %%mm2\n\t" \ + +#define YUV2RGB_ENDLOOP(depth) \ + "movq 8 (%5, %0, 2), %%mm6\n\t" \ + "movd 4 (%3, %0), %%mm1\n\t" \ + "movd 4 (%2, %0), %%mm0\n\t" \ + "add $"AV_STRINGIFY(depth * 8)", %1\n\t" \ + "add $4, %0\n\t" \ + "js 1b\n\t" \ + +#define YUV2RGB_OPERANDS \ + : "+r" (index), "+r" (image) \ + : "r" (pu - index), "r" (pv - index), "r"(&c->redDither), \ + "r" (py - 2*index) \ + ); \ + } \ + +#define YUV2RGB_OPERANDS_ALPHA \ + : "+r" (index), "+r" (image) \ + : "r" (pu - index), "r" (pv - index), "r"(&c->redDither), \ + "r" (py - 2*index), "r" (pa - 2*index) \ + ); \ + } \ + +#define YUV2RGB_ENDFUNC \ + __asm__ volatile (SFENCE"\n\t"EMMS); \ + return srcSliceH; \ + + +#define RGB_PACK16(gmask, gshift, rshift) \ + "pand "MANGLE(mmx_redmask)", %%mm0\n\t" \ + "pand "MANGLE(mmx_redmask)", %%mm1\n\t" \ + "psrlw $3, %%mm0\n\t" \ + "pand "MANGLE(gmask)", %%mm2\n\t" \ + "movq %%mm0, %%mm5\n\t" \ + "movq %%mm1, %%mm6\n\t" \ + "movq %%mm2, %%mm7\n\t" \ + "punpcklbw %%mm4, %%mm0\n\t" \ + "punpcklbw %%mm4, %%mm1\n\t" \ + "punpcklbw %%mm4, %%mm2\n\t" \ + "punpckhbw %%mm4, %%mm5\n\t" \ + "punpckhbw %%mm4, %%mm6\n\t" \ + "punpckhbw %%mm4, %%mm7\n\t" \ + "psllw $"rshift", %%mm1\n\t" \ + "psllw $"rshift", %%mm6\n\t" \ + "psllw $"gshift", %%mm2\n\t" \ + "psllw $"gshift", %%mm7\n\t" \ + "por %%mm1, %%mm0\n\t" \ + "por %%mm6, %%mm5\n\t" \ + "por %%mm2, %%mm0\n\t" \ + "por %%mm7, %%mm5\n\t" \ + MOVNTQ " %%mm0, (%1)\n\t" \ + MOVNTQ " %%mm5, 8(%1)\n\t" \ + +#define DITHER_RGB \ + "paddusb "BLUE_DITHER"(%4), %%mm0\n\t" \ + "paddusb "GREEN_DITHER"(%4), %%mm2\n\t" \ + "paddusb "RED_DITHER"(%4), %%mm1\n\t" \ + +static inline int RENAME(yuv420_rgb15)(SwsContext *c, const uint8_t *src[], + int srcStride[], + int srcSliceY, int srcSliceH, + uint8_t *dst[], int dstStride[]) +{ + int y, h_size; + + YUV2RGB_LOOP(2) + +#ifdef DITHER1XBPP + c->blueDither = ff_dither8[y & 1]; + c->greenDither = ff_dither8[y & 1]; + c->redDither = ff_dither8[(y + 1) & 1]; +#endif + + YUV2RGB_INITIAL_LOAD + YUV2RGB +#ifdef DITHER1XBPP + DITHER_RGB +#endif + RGB_PACK16(mmx_redmask, "2", "7") + + YUV2RGB_ENDLOOP(2) + YUV2RGB_OPERANDS + YUV2RGB_ENDFUNC +} + +static inline int RENAME(yuv420_rgb16)(SwsContext *c, const uint8_t *src[], + int srcStride[], + int srcSliceY, int srcSliceH, + uint8_t *dst[], int dstStride[]) +{ + int y, h_size; + + YUV2RGB_LOOP(2) + +#ifdef DITHER1XBPP + c->blueDither = ff_dither8[y & 1]; + c->greenDither = ff_dither4[y & 1]; + c->redDither = ff_dither8[(y + 1) & 1]; +#endif + + YUV2RGB_INITIAL_LOAD + YUV2RGB +#ifdef DITHER1XBPP + DITHER_RGB +#endif + RGB_PACK16(mmx_grnmask, "3", "8") + + YUV2RGB_ENDLOOP(2) + YUV2RGB_OPERANDS + YUV2RGB_ENDFUNC +} + + +#define RGB_PACK24(red, blue) \ + /* generate first packed RGB octet */ \ + "movq %%mm2, %%mm5\n\t" \ + "movq %%mm"blue", %%mm6\n\t" \ + "movq %%mm"red", %%mm7\n\t" \ + "punpcklbw %%mm5, %%mm6\n\t" \ + "punpcklbw %%mm4, %%mm7\n\t" \ + "movq %%mm6, %%mm3\n\t" \ + "punpcklwd %%mm7, %%mm6\n\t" \ + "psrlq $32, %%mm3\n\t" \ + "movq %%mm6, %%mm5\n\t" \ + "psllq $40, %%mm6\n\t" \ + "psllq $48, %%mm3\n\t" \ + "psrlq $32, %%mm5\n\t" \ + "psrlq $40, %%mm6\n\t" \ + "psllq $24, %%mm5\n\t" \ + "por %%mm3, %%mm6\n\t" \ + "por %%mm5, %%mm6\n\t" \ + MOVNTQ " %%mm6, (%1)\n\t" \ +\ + /* generate second packed RGB octet */ \ + "movq %%mm"red", %%mm7\n\t" \ + "movq %%mm2, %%mm5\n\t" \ + "movq %%mm"blue", %%mm6\n\t" \ + "punpcklbw %%mm4, %%mm7\n\t" \ + "punpcklbw %%mm5, %%mm6\n\t" \ + "movq %%mm7, %%mm3\n\t" \ + "punpckhwd %%mm7, %%mm6\n\t" \ + "psllq $16, %%mm3\n\t" \ + "psrlq $32, %%mm6\n\t" \ + "psrlq $48, %%mm3\n\t" \ + "psllq $8, %%mm6\n\t" \ + "movq %%mm"red", %%mm7\n\t" \ + "por %%mm6, %%mm3\n\t" \ + "movq %%mm"blue", %%mm6\n\t" \ + "movq %%mm2, %%mm5\n\t" \ + "punpckhbw %%mm4, %%mm7\n\t" \ + "punpckhbw %%mm5, %%mm6\n\t" \ + "movq %%mm6, %%mm5\n\t" \ + "punpcklwd %%mm7, %%mm6\n\t" \ + "psrlq $16, %%mm5\n\t" \ + "psllq $56, %%mm5\n\t" \ + "por %%mm5, %%mm3\n\t" \ + "psllq $32, %%mm6\n\t" \ + "por %%mm6, %%mm3\n\t" \ + MOVNTQ " %%mm3, 8(%1)\n\t" \ +\ + /* generate third packed RGB octet */ \ + "movq %%mm"red", %%mm7\n\t" \ + "movq %%mm2, %%mm5\n\t" \ + "movq %%mm2, %%mm3\n\t" \ + "movq %%mm"blue", %%mm6\n\t" \ + "punpckhbw %%mm"red", %%mm3\n\t" \ + "punpckhbw %%mm4, %%mm7\n\t" \ + "psllq $32, %%mm3\n\t" \ + "punpckhbw %%mm5, %%mm6\n\t" \ + "psrlq $48, %%mm3\n\t" \ + "punpckhwd %%mm7, %%mm6\n\t" \ + "movq %%mm6, %%mm7\n\t" \ + "psrlq $32, %%mm6\n\t" \ + "psllq $32, %%mm7\n\t" \ + "psllq $40, %%mm6\n\t" \ + "psrlq $16, %%mm7\n\t" \ + "por %%mm6, %%mm3\n\t" \ + "por %%mm7, %%mm3\n\t" \ + MOVNTQ " %%mm3, 16(%1)\n\t" \ + +static inline int RENAME(yuv420_rgb24)(SwsContext *c, const uint8_t *src[], + int srcStride[], + int srcSliceY, int srcSliceH, + uint8_t *dst[], int dstStride[]) +{ + int y, h_size; + + YUV2RGB_LOOP(3) + + YUV2RGB_INITIAL_LOAD + YUV2RGB + RGB_PACK24(REG_BLUE, REG_RED) + + YUV2RGB_ENDLOOP(3) + YUV2RGB_OPERANDS + YUV2RGB_ENDFUNC +} + +static inline int RENAME(yuv420_bgr24)(SwsContext *c, const uint8_t *src[], + int srcStride[], + int srcSliceY, int srcSliceH, + uint8_t *dst[], int dstStride[]) +{ + int y, h_size; + + YUV2RGB_LOOP(3) + + YUV2RGB_INITIAL_LOAD + YUV2RGB + RGB_PACK24(REG_RED, REG_BLUE) + + YUV2RGB_ENDLOOP(3) + YUV2RGB_OPERANDS + YUV2RGB_ENDFUNC +} + + +#define SET_EMPTY_ALPHA \ + "pcmpeqd %%mm"REG_ALPHA", %%mm"REG_ALPHA"\n\t" /* set alpha to 0xFF */ \ + +#define LOAD_ALPHA \ + "movq (%6, %0, 2), %%mm"REG_ALPHA"\n\t" \ + +#define RGB_PACK32(red, green, blue, alpha) \ + "movq %%mm"blue", %%mm5\n\t" \ + "movq %%mm"red", %%mm6\n\t" \ + "punpckhbw %%mm"green", %%mm5\n\t" \ + "punpcklbw %%mm"green", %%mm"blue"\n\t" \ + "punpckhbw %%mm"alpha", %%mm6\n\t" \ + "punpcklbw %%mm"alpha", %%mm"red"\n\t" \ + "movq %%mm"blue", %%mm"green"\n\t" \ + "movq %%mm5, %%mm"alpha"\n\t" \ + "punpcklwd %%mm"red", %%mm"blue"\n\t" \ + "punpckhwd %%mm"red", %%mm"green"\n\t" \ + "punpcklwd %%mm6, %%mm5\n\t" \ + "punpckhwd %%mm6, %%mm"alpha"\n\t" \ + MOVNTQ " %%mm"blue", 0(%1)\n\t" \ + MOVNTQ " %%mm"green", 8(%1)\n\t" \ + MOVNTQ " %%mm5, 16(%1)\n\t" \ + MOVNTQ " %%mm"alpha", 24(%1)\n\t" \ + +static inline int RENAME(yuv420_rgb32)(SwsContext *c, const uint8_t *src[], + int srcStride[], + int srcSliceY, int srcSliceH, + uint8_t *dst[], int dstStride[]) +{ + int y, h_size; + + YUV2RGB_LOOP(4) + + YUV2RGB_INITIAL_LOAD + YUV2RGB + SET_EMPTY_ALPHA + RGB_PACK32(REG_RED, REG_GREEN, REG_BLUE, REG_ALPHA) + + YUV2RGB_ENDLOOP(4) + YUV2RGB_OPERANDS + YUV2RGB_ENDFUNC +} + +static inline int RENAME(yuva420_rgb32)(SwsContext *c, const uint8_t *src[], + int srcStride[], + int srcSliceY, int srcSliceH, + uint8_t *dst[], int dstStride[]) +{ +#if HAVE_7REGS + int y, h_size; + + YUV2RGB_LOOP(4) + + const uint8_t *pa = src[3] + y * srcStride[3]; + YUV2RGB_INITIAL_LOAD + YUV2RGB + LOAD_ALPHA + RGB_PACK32(REG_RED, REG_GREEN, REG_BLUE, REG_ALPHA) + + YUV2RGB_ENDLOOP(4) + YUV2RGB_OPERANDS_ALPHA + YUV2RGB_ENDFUNC +#endif +} + +static inline int RENAME(yuv420_bgr32)(SwsContext *c, const uint8_t *src[], + int srcStride[], + int srcSliceY, int srcSliceH, + uint8_t *dst[], int dstStride[]) +{ + int y, h_size; + + YUV2RGB_LOOP(4) + + YUV2RGB_INITIAL_LOAD + YUV2RGB + SET_EMPTY_ALPHA + RGB_PACK32(REG_BLUE, REG_GREEN, REG_RED, REG_ALPHA) + + YUV2RGB_ENDLOOP(4) + YUV2RGB_OPERANDS + YUV2RGB_ENDFUNC +} + +static inline int RENAME(yuva420_bgr32)(SwsContext *c, const uint8_t *src[], + int srcStride[], + int srcSliceY, int srcSliceH, + uint8_t *dst[], int dstStride[]) +{ +#if HAVE_7REGS + int y, h_size; + + YUV2RGB_LOOP(4) + + const uint8_t *pa = src[3] + y * srcStride[3]; + YUV2RGB_INITIAL_LOAD + YUV2RGB + LOAD_ALPHA + RGB_PACK32(REG_BLUE, REG_GREEN, REG_RED, REG_ALPHA) + + YUV2RGB_ENDLOOP(4) + YUV2RGB_OPERANDS_ALPHA + YUV2RGB_ENDFUNC +#endif +} diff --git a/src/add-ons/media/plugins/ffmpeg/libswscale/yuv2rgb.c b/src/add-ons/media/plugins/ffmpeg/libswscale/yuv2rgb.c index 2d53a5f4e6..f47b15d6ee 100644 --- a/src/add-ons/media/plugins/ffmpeg/libswscale/yuv2rgb.c +++ b/src/add-ons/media/plugins/ffmpeg/libswscale/yuv2rgb.c @@ -33,7 +33,9 @@ #include "swscale.h" #include "swscale_internal.h" #include "libavutil/x86_cpu.h" +#include "libavutil/bswap.h" +extern const uint8_t dither_4x4_16[4][8]; extern const uint8_t dither_8x8_32[8][8]; extern const uint8_t dither_8x8_73[8][8]; extern const uint8_t dither_8x8_220[8][8]; @@ -49,6 +51,13 @@ const int32_t ff_yuv2rgb_coeffs[8][4] = { {117579, 136230, 16907, 35559} /* SMPTE 240M (1987) */ }; +const int *sws_getCoefficients(int colorspace) +{ + if (colorspace > 7 || colorspace < 0) + colorspace = SWS_CS_DEFAULT; + return ff_yuv2rgb_coeffs[colorspace]; +} + #define LOADCHROMA(i) \ U = pu[i]; \ V = pv[i]; \ @@ -91,7 +100,7 @@ const int32_t ff_yuv2rgb_coeffs[8][4] = { dst[12*i+10] = dst[12*i+11] = b[Y]; #define YUV2RGBFUNC(func_name, dst_type, alpha) \ -static int func_name(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, \ +static int func_name(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, \ int srcSliceH, uint8_t* dst[], int dstStride[]) \ {\ int y;\ @@ -105,11 +114,11 @@ static int func_name(SwsContext *c, uint8_t* src[], int srcStride[], int srcSlic dst_type *dst_2 = (dst_type*)(dst[0] + (y+srcSliceY+1)*dstStride[0]);\ dst_type av_unused *r, *b;\ dst_type *g;\ - uint8_t *py_1 = src[0] + y*srcStride[0];\ - uint8_t *py_2 = py_1 + srcStride[0];\ - uint8_t *pu = src[1] + (y>>1)*srcStride[1];\ - uint8_t *pv = src[2] + (y>>1)*srcStride[2];\ - uint8_t av_unused *pa_1, *pa_2;\ + const uint8_t *py_1 = src[0] + y*srcStride[0];\ + const uint8_t *py_2 = py_1 + 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 av_unused *pa_1, *pa_2;\ unsigned int h_size = c->dstW>>3;\ if (alpha) {\ pa_1 = src[3] + y*srcStride[3];\ @@ -321,6 +330,7 @@ YUV2RGBFUNC(yuv2rgb_c_16, uint16_t, 0) PUTRGB(dst_1,py_1,3); CLOSEYUV2RGBFUNC(8) +#if 0 // Currently unused // This is exactly the same code as yuv2rgb_c_32 except for the types of // r, g, b, dst_1, dst_2 YUV2RGBFUNC(yuv2rgb_c_8, uint8_t, 0) @@ -340,6 +350,33 @@ YUV2RGBFUNC(yuv2rgb_c_8, uint8_t, 0) PUTRGB(dst_2,py_2,3); PUTRGB(dst_1,py_1,3); CLOSEYUV2RGBFUNC(8) +#endif + +// r, g, b, dst_1, dst_2 +YUV2RGBFUNC(yuv2rgb_c_12_ordered_dither, uint16_t, 0) + const uint8_t *d16 = dither_4x4_16[y&3]; +#define PUTRGB12(dst,src,i,o) \ + Y = src[2*i]; \ + dst[2*i] = r[Y+d16[0+o]] + g[Y+d16[0+o]] + b[Y+d16[0+o]]; \ + Y = src[2*i+1]; \ + dst[2*i+1] = r[Y+d16[1+o]] + g[Y+d16[1+o]] + b[Y+d16[1+o]]; + + LOADCHROMA(0); + PUTRGB12(dst_1,py_1,0,0); + PUTRGB12(dst_2,py_2,0,0+8); + + LOADCHROMA(1); + PUTRGB12(dst_2,py_2,1,2+8); + PUTRGB12(dst_1,py_1,1,2); + + LOADCHROMA(2); + PUTRGB12(dst_1,py_1,2,4); + PUTRGB12(dst_2,py_2,2,4+8); + + LOADCHROMA(3); + PUTRGB12(dst_2,py_2,3,6+8); + PUTRGB12(dst_1,py_1,3,6); +CLOSEYUV2RGBFUNC(8) // r, g, b, dst_1, dst_2 YUV2RGBFUNC(yuv2rgb_c_8_ordered_dither, uint8_t, 0) @@ -368,7 +405,7 @@ YUV2RGBFUNC(yuv2rgb_c_8_ordered_dither, uint8_t, 0) PUTRGB8(dst_1,py_1,3,6); CLOSEYUV2RGBFUNC(8) - +#if 0 // Currently unused // This is exactly the same code as yuv2rgb_c_32 except for the types of // r, g, b, dst_1, dst_2 YUV2RGBFUNC(yuv2rgb_c_4, uint8_t, 0) @@ -396,6 +433,7 @@ YUV2RGBFUNC(yuv2rgb_c_4, uint8_t, 0) PUTRGB4(dst_2,py_2,3); PUTRGB4(dst_1,py_1,3); CLOSEYUV2RGBFUNC(4) +#endif YUV2RGBFUNC(yuv2rgb_c_4_ordered_dither, uint8_t, 0) const uint8_t *d64 = dither_8x8_73[y&7]; @@ -426,6 +464,7 @@ YUV2RGBFUNC(yuv2rgb_c_4_ordered_dither, uint8_t, 0) PUTRGB4D(dst_1,py_1,3,6); CLOSEYUV2RGBFUNC(4) +#if 0 // Currently unused // This is exactly the same code as yuv2rgb_c_32 except for the types of // r, g, b, dst_1, dst_2 YUV2RGBFUNC(yuv2rgb_c_4b, uint8_t, 0) @@ -445,6 +484,7 @@ YUV2RGBFUNC(yuv2rgb_c_4b, uint8_t, 0) PUTRGB(dst_2,py_2,3); PUTRGB(dst_1,py_1,3); CLOSEYUV2RGBFUNC(8) +#endif YUV2RGBFUNC(yuv2rgb_c_4b_ordered_dither, uint8_t, 0) const uint8_t *d64 = dither_8x8_73[y&7]; @@ -503,7 +543,7 @@ CLOSEYUV2RGBFUNC(1) SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c) { SwsFunc t = NULL; -#if (HAVE_MMX2 || HAVE_MMX) && CONFIG_GPL +#if HAVE_MMX t = ff_yuv2rgb_init_mmx(c); #endif #if HAVE_VIS @@ -525,7 +565,7 @@ SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c) if (t) return t; - av_log(c, AV_LOG_WARNING, "No accelerated colorspace conversion found.\n"); + 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)); switch (c->dstFormat) { case PIX_FMT_RGB48BE: @@ -540,6 +580,8 @@ SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c) case PIX_FMT_BGR565: case PIX_FMT_RGB555: case PIX_FMT_BGR555: return yuv2rgb_c_16; + case PIX_FMT_RGB444: + case PIX_FMT_BGR444: return yuv2rgb_c_12_ordered_dither; case PIX_FMT_RGB8: case PIX_FMT_BGR8: return yuv2rgb_c_8_ordered_dither; case PIX_FMT_RGB4: @@ -584,13 +626,23 @@ av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], int const int isRgb = c->dstFormat==PIX_FMT_RGB32 || c->dstFormat==PIX_FMT_RGB32_1 || c->dstFormat==PIX_FMT_BGR24 - || c->dstFormat==PIX_FMT_RGB565 - || c->dstFormat==PIX_FMT_RGB555 + || c->dstFormat==PIX_FMT_RGB565BE + || c->dstFormat==PIX_FMT_RGB565LE + || c->dstFormat==PIX_FMT_RGB555BE + || c->dstFormat==PIX_FMT_RGB555LE + || c->dstFormat==PIX_FMT_RGB444BE + || c->dstFormat==PIX_FMT_RGB444LE || c->dstFormat==PIX_FMT_RGB8 || c->dstFormat==PIX_FMT_RGB4 || c->dstFormat==PIX_FMT_RGB4_BYTE || c->dstFormat==PIX_FMT_MONOBLACK; - const int bpp = fmt_depth(c->dstFormat); + const int isNotNe = c->dstFormat==PIX_FMT_NE(RGB565LE,RGB565BE) + || c->dstFormat==PIX_FMT_NE(RGB555LE,RGB555BE) + || c->dstFormat==PIX_FMT_NE(RGB444LE,RGB444BE) + || c->dstFormat==PIX_FMT_NE(BGR565LE,BGR565BE) + || c->dstFormat==PIX_FMT_NE(BGR555LE,BGR555BE) + || c->dstFormat==PIX_FMT_NE(BGR444LE,BGR444BE); + const int bpp = c->dstFormatBpp; uint8_t *y_table; uint16_t *y_table16; uint32_t *y_table32; @@ -682,6 +734,28 @@ av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], int fill_table(c->table_bU, 1, cbu, y_table + yoffs + 2048); fill_gv_table(c->table_gV, 1, cgv); break; + case 12: + rbase = isRgb ? 8 : 0; + gbase = 4; + bbase = isRgb ? 0 : 8; + c->yuvTable = av_malloc(1024*3*2); + y_table16 = c->yuvTable; + yb = -(384<<16) - oy; + for (i = 0; i < 1024; i++) { + uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16); + y_table16[i ] = (yval >> 4) << rbase; + y_table16[i+1024] = (yval >> 4) << gbase; + y_table16[i+2048] = (yval >> 4) << bbase; + yb += cy; + } + if (isNotNe) + for (i = 0; i < 1024*3; i++) + y_table16[i] = bswap_16(y_table16[i]); + fill_table(c->table_rV, 2, crv, y_table16 + yoffs); + fill_table(c->table_gU, 2, cgu, y_table16 + yoffs + 1024); + fill_table(c->table_bU, 2, cbu, y_table16 + yoffs + 2048); + fill_gv_table(c->table_gV, 2, cgv); + break; case 15: case 16: rbase = isRgb ? bpp - 5 : 0; @@ -697,6 +771,9 @@ av_cold int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], int y_table16[i+2048] = (yval >> 3) << bbase; yb += cy; } + if(isNotNe) + for (i = 0; i < 1024*3; i++) + y_table16[i] = bswap_16(y_table16[i]); fill_table(c->table_rV, 2, crv, y_table16 + yoffs); fill_table(c->table_gU, 2, cgu, y_table16 + yoffs + 1024); fill_table(c->table_bU, 2, cbu, y_table16 + yoffs + 2048);